Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (252309 => 252310)
--- trunk/Source/_javascript_Core/ChangeLog 2019-11-09 20:14:37 UTC (rev 252309)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-11-09 23:35:11 UTC (rev 252310)
@@ -1,3 +1,57 @@
+2019-11-09 Tadeu Zagallo <[email protected]>
+
+ [WebAssembly] Improve bytecode dumping
+ https://bugs.webkit.org/show_bug.cgi?id=204051
+
+ Reviewed by Keith Miller.
+
+ This patch improves the bytecode dumping for Wasm by:
+ - Adding a new option that dumps only the Wasm bytecode. It can be quite hard to find
+ the Wasm bytecode in the middle of a ton of JS bytecode dumps.
+ - Adding a header with name of the function and stats, similar to the JS dump.
+ - Using Wasm types to properly print constants, and including the type in constants
+ table at the end of the dump.
+
+ Here's an example of the updated bytecode dump:
+
+ <?>.wasm-function[26] : (I32) -> [I32]
+ wasm size: 4 bytes
+ bytecode: 6 instructions (0 16-bit instructions, 0 32-bit instructions); 14 bytes; 1 parameter(s); 18 local(s); 22 callee register(s)
+ [ 0] enter
+ [ 1] mov loc18, null(const0)
+ [ 4] mov loc20, loc4
+ [ 7] mov loc19, loc20
+ [ 10] mov loc4, loc19
+ [ 13] ret
+
+ Constants:
+ const0 : Anyref = null
+
+ * _javascript_Core.xcodeproj/project.pbxproj:
+ * bytecode/BytecodeDumper.cpp:
+ (JSC::Wasm::BytecodeDumper::dumpBlock):
+ (JSC::Wasm::BytecodeDumper::dumpConstants):
+ (JSC::Wasm::BytecodeDumper::constantName const):
+ (JSC::Wasm::BytecodeDumper::formatConstant const):
+ * bytecode/BytecodeDumper.h:
+ (JSC::BytecodeDumper::~BytecodeDumper):
+ * runtime/OptionsList.h:
+ * wasm/WasmFunctionCodeBlock.cpp:
+ * wasm/WasmFunctionCodeBlock.h:
+ (JSC::Wasm::FunctionCodeBlock::functionIndex const):
+ (JSC::Wasm::FunctionCodeBlock::numVars const):
+ (JSC::Wasm::FunctionCodeBlock::numCalleeLocals const):
+ (JSC::Wasm::FunctionCodeBlock::numArguments const):
+ (JSC::Wasm::FunctionCodeBlock::constantTypes const):
+ (JSC::Wasm::FunctionCodeBlock::constants const):
+ (JSC::Wasm::FunctionCodeBlock::instructions const):
+ (JSC::Wasm::FunctionCodeBlock::getConstantType const):
+ * wasm/WasmGeneratorTraits.h: Added.
+ * wasm/WasmLLIntGenerator.cpp:
+ (JSC::Wasm::LLIntGenerator::addConstant):
+ * wasm/WasmLLIntPlan.cpp:
+ (JSC::Wasm::LLIntPlan::didCompleteCompilation):
+
2019-11-08 Tadeu Zagallo <[email protected]>
[WebAssembly] LLIntGenerator should not retain VirtualRegisters used for constants
Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (252309 => 252310)
--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2019-11-09 20:14:37 UTC (rev 252309)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj 2019-11-09 23:35:11 UTC (rev 252310)
@@ -3361,6 +3361,7 @@
1482B7E20A43076000517CFC /* JSObjectRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSObjectRef.cpp; sourceTree = "<group>"; };
14874AE115EBDE4A002E3587 /* JSScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScope.cpp; sourceTree = "<group>"; };
14874AE215EBDE4A002E3587 /* JSScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScope.h; sourceTree = "<group>"; };
+ 1487CE16237741000044429C /* WasmGeneratorTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmGeneratorTraits.h; sourceTree = "<group>"; };
148A7BED1B82975A002D9157 /* InlineCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InlineCallFrame.cpp; sourceTree = "<group>"; };
148A7BEE1B82975A002D9157 /* InlineCallFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineCallFrame.h; sourceTree = "<group>"; };
148B1416225DD1D700D6E998 /* CachePayload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachePayload.h; sourceTree = "<group>"; };
@@ -6787,6 +6788,7 @@
14C5AD6722F33FBF00F1FB83 /* WasmFunctionCodeBlock.cpp */,
14C5AD6B22F33FC000F1FB83 /* WasmFunctionCodeBlock.h */,
53F40E8A1D5901BB0099A1B6 /* WasmFunctionParser.h */,
+ 1487CE16237741000044429C /* WasmGeneratorTraits.h */,
AD8FF3961EB5BD850087FF82 /* WasmIndexOrName.cpp */,
AD8FF3951EB5BD850087FF82 /* WasmIndexOrName.h */,
AD5C36DE1F699EB6000BCAAF /* WasmInstance.cpp */,
Modified: trunk/Source/_javascript_Core/bytecode/BytecodeDumper.cpp (252309 => 252310)
--- trunk/Source/_javascript_Core/bytecode/BytecodeDumper.cpp 2019-11-09 20:14:37 UTC (rev 252309)
+++ trunk/Source/_javascript_Core/bytecode/BytecodeDumper.cpp 2019-11-09 23:35:11 UTC (rev 252310)
@@ -28,6 +28,7 @@
#include "BytecodeDumper.h"
#include "ArithProfile.h"
+#include "B3Type.h"
#include "BytecodeGenerator.h"
#include "BytecodeStructs.h"
#include "CallLinkStatus.h"
@@ -42,6 +43,10 @@
#include "UnlinkedCodeBlock.h"
#include "UnlinkedMetadataTableInlines.h"
#include "WasmFunctionCodeBlock.h"
+#include "WasmGeneratorTraits.h"
+#include "WasmModuleInformation.h"
+#include "WasmOps.h"
+#include "WasmSignatureInlines.h"
namespace JSC {
@@ -245,10 +250,103 @@
}
template class BytecodeDumper<CodeBlock>;
-#if ENABLE(WEBASSEMBLY)
-template class BytecodeDumper<Wasm::FunctionCodeBlock>;
-#endif
template class CodeBlockBytecodeDumper<UnlinkedCodeBlock>;
template class CodeBlockBytecodeDumper<CodeBlock>;
+#if ENABLE(WEBASSEMBLY)
+
+namespace Wasm {
+
+void BytecodeDumper::dumpBlock(FunctionCodeBlock* block, const ModuleInformation& moduleInformation, PrintStream& out)
+{
+ size_t instructionCount = 0;
+ size_t wide16InstructionCount = 0;
+ size_t wide32InstructionCount = 0;
+
+ for (auto it = block->instructions().begin(); it != block->instructions().end(); it += it->size<WasmOpcodeTraits>()) {
+ if (it->isWide16())
+ ++wide16InstructionCount;
+ else if (it->isWide32())
+ ++wide32InstructionCount;
+ ++instructionCount;
+ }
+
+ size_t functionIndexSpace = moduleInformation.importFunctionCount() + block->functionIndex();
+ out.print(makeString(IndexOrName(functionIndexSpace, moduleInformation.nameSection->get(functionIndexSpace))));
+
+ const auto& function = moduleInformation.functions[block->functionIndex()];
+ SignatureIndex signatureIndex = moduleInformation.internalFunctionSignatureIndices[block->functionIndex()];
+ const Signature& signature = SignatureInformation::get(signatureIndex);
+ out.print(" : ", signature, "\n");
+ out.print("wasm size: ", function.data.size(), " bytes\n");
+
+ out.printf(
+ "bytecode: %lu instructions (%lu 16-bit instructions, %lu 32-bit instructions); %lu bytes; %d parameter(s); %d local(s); %d callee register(s)\n",
+ static_cast<unsigned long>(instructionCount),
+ static_cast<unsigned long>(wide16InstructionCount),
+ static_cast<unsigned long>(wide32InstructionCount),
+ static_cast<unsigned long>(block->instructions().sizeInBytes()),
+ block->numArguments(),
+ block->numVars(),
+ block->numCalleeLocals());
+
+ BytecodeDumper dumper(block, out);
+ for (auto it = block->instructions().begin(); it != block->instructions().end(); it += it->size<WasmOpcodeTraits>()) {
+ dumpWasm(&dumper, it.offset(), it.ptr());
+ out.print("\n");
+ }
+
+ dumper.dumpConstants();
+
+ out.printf("\n");
}
+
+void BytecodeDumper::dumpConstants()
+{
+ FunctionCodeBlock* block = this->block();
+ if (!block->constants().isEmpty()) {
+ this->m_out.printf("\nConstants:\n");
+ unsigned i = 0;
+ for (const auto& constant : block->constants()) {
+ Type type = block->constantTypes()[i];
+ this->m_out.print(" const", i, " : ", type, " = ", formatConstant(type, constant), "\n");
+ ++i;
+ }
+ }
+}
+
+CString BytecodeDumper::constantName(int index) const
+{
+ FunctionCodeBlock* block = this->block();
+ auto value = formatConstant(block->getConstantType(index), block->getConstant(index));
+ return toCString(value, "(", VirtualRegister(index), ")");
+}
+
+CString BytecodeDumper::formatConstant(Type type, uint64_t constant) const
+{
+ switch (type) {
+ case Type::I32:
+ return toCString(static_cast<int32_t>(constant));
+ case Type::I64:
+ return toCString(constant);
+ case Type::F32:
+ return toCString(bitwise_cast<float>(static_cast<int32_t>(constant)));
+ break;
+ case Type::F64:
+ return toCString(bitwise_cast<double>(constant));
+ break;
+ case Type::Anyref:
+ case Type::Funcref:
+ if (JSValue::decode(constant) == jsNull())
+ return "null";
+ return toCString(RawPointer(bitwise_cast<void*>(constant)));
+ default:
+ RELEASE_ASSERT_NOT_REACHED();
+ return "";
+ }
+}
+
+} // namespace Wasm
+
+#endif // ENABLE(WEBASSEMBLY)
+}
Modified: trunk/Source/_javascript_Core/bytecode/BytecodeDumper.h (252309 => 252310)
--- trunk/Source/_javascript_Core/bytecode/BytecodeDumper.h 2019-11-09 20:14:37 UTC (rev 252309)
+++ trunk/Source/_javascript_Core/bytecode/BytecodeDumper.h 2019-11-09 23:35:11 UTC (rev 252310)
@@ -70,6 +70,8 @@
{
}
+ virtual ~BytecodeDumper() { }
+
protected:
Block* block() const { return m_block; }
@@ -79,7 +81,7 @@
private:
CString registerName(int r) const;
- CString constantName(int index) const;
+ virtual CString constantName(int index) const;
Block* m_block;
InstructionStream::Offset m_currentLocation { 0 };
@@ -104,4 +106,28 @@
void dumpStringSwitchJumpTables();
};
+#if ENABLE(WEBASSEMBLY)
+
+namespace Wasm {
+
+class FunctionCodeBlock;
+struct ModuleInformation;
+enum Type : int8_t;
+
+class BytecodeDumper : public JSC::BytecodeDumper<FunctionCodeBlock> {
+public:
+ static void dumpBlock(FunctionCodeBlock*, const ModuleInformation&, PrintStream& out);
+
+private:
+ using JSC::BytecodeDumper<FunctionCodeBlock>::BytecodeDumper;
+
+ void dumpConstants();
+ CString constantName(int index) const override;
+ CString formatConstant(Type, uint64_t) const;
+};
+
+} // namespace Wasm
+
+#endif // ENABLE(WEBASSEMBLY)
+
}
Modified: trunk/Source/_javascript_Core/runtime/OptionsList.h (252309 => 252310)
--- trunk/Source/_javascript_Core/runtime/OptionsList.h 2019-11-09 20:14:37 UTC (rev 252309)
+++ trunk/Source/_javascript_Core/runtime/OptionsList.h 2019-11-09 23:35:11 UTC (rev 252310)
@@ -86,6 +86,7 @@
v(Unsigned, repatchBufferingCountdown, 8, Normal, nullptr) \
\
v(Bool, dumpGeneratedBytecodes, false, Normal, nullptr) \
+ v(Bool, dumpGeneratedWasmBytecodes, false, Normal, nullptr) \
v(Bool, dumpBytecodeLivenessResults, false, Normal, nullptr) \
v(Bool, validateBytecode, false, Normal, nullptr) \
v(Bool, forceDebuggerBytecodeGeneration, false, Normal, nullptr) \
Modified: trunk/Source/_javascript_Core/wasm/WasmFunctionCodeBlock.cpp (252309 => 252310)
--- trunk/Source/_javascript_Core/wasm/WasmFunctionCodeBlock.cpp 2019-11-09 20:14:37 UTC (rev 252309)
+++ trunk/Source/_javascript_Core/wasm/WasmFunctionCodeBlock.cpp 2019-11-09 23:35:11 UTC (rev 252310)
@@ -42,15 +42,6 @@
m_instructionsRawPointer = m_instructions->rawPointer();
}
-void FunctionCodeBlock::dumpBytecode()
-{
- BytecodeDumper<FunctionCodeBlock> dumper(this, WTF::dataFile());
- for (auto it = m_instructions->begin(); it != m_instructions->end(); it += it->size<WasmOpcodeTraits>()) {
- dumpWasm(&dumper, it.offset(), it.ptr());
- dataLogLn();
- }
-}
-
void FunctionCodeBlock::addOutOfLineJumpTarget(InstructionStream::Offset bytecodeOffset, int target)
{
RELEASE_ASSERT(target);
Modified: trunk/Source/_javascript_Core/wasm/WasmFunctionCodeBlock.h (252309 => 252310)
--- trunk/Source/_javascript_Core/wasm/WasmFunctionCodeBlock.h 2019-11-09 20:14:37 UTC (rev 252309)
+++ trunk/Source/_javascript_Core/wasm/WasmFunctionCodeBlock.h 2019-11-09 23:35:11 UTC (rev 252310)
@@ -46,6 +46,7 @@
class Signature;
struct GeneratorTraits;
+enum Type : int8_t;
// FIXME: Consider merging this with LLIntCallee
// https://bugs.webkit.org/show_bug.cgi?id=203691
@@ -63,12 +64,22 @@
{
}
+ uint32_t functionIndex() const { return m_functionIndex; }
+ int numVars() const { return m_numVars; }
+ int numCalleeLocals() const { return m_numCalleeLocals; }
+ uint32_t numArguments() const { return m_numArguments; }
+ const Vector<Type>& constantTypes() const { return m_constantTypes; }
+ const Vector<uint64_t>& constants() const { return m_constants; }
+ const InstructionStream& instructions() const { return *m_instructions; }
+
ALWAYS_INLINE uint64_t getConstant(int index) const { return m_constants[index - FirstConstantRegisterIndex]; }
- ALWAYS_INLINE uint32_t functionIndex() const { return m_functionIndex; }
+ ALWAYS_INLINE Type getConstantType(int index) const
+ {
+ ASSERT(Options::dumpGeneratedWasmBytecodes());
+ return m_constantTypes[index - FirstConstantRegisterIndex];
+ }
void setInstructions(std::unique_ptr<InstructionStream>);
- void dumpBytecode();
-
void addJumpTarget(InstructionStream::Offset jumpTarget) { m_jumpTargets.append(jumpTarget); }
InstructionStream::Offset numberOfJumpTargets() { return m_jumpTargets.size(); }
InstructionStream::Offset lastJumpTarget() { return m_jumpTargets.last(); }
@@ -109,6 +120,7 @@
// Number of VirtualRegister. The naming is unfortunate, but has to match UnlinkedCodeBlock
int m_numCalleeLocals { 0 };
uint32_t m_numArguments { 0 };
+ Vector<Type> m_constantTypes;
Vector<uint64_t> m_constants;
std::unique_ptr<InstructionStream> m_instructions;
const void* m_instructionsRawPointer { nullptr };
Added: trunk/Source/_javascript_Core/wasm/WasmGeneratorTraits.h (0 => 252310)
--- trunk/Source/_javascript_Core/wasm/WasmGeneratorTraits.h (rev 0)
+++ trunk/Source/_javascript_Core/wasm/WasmGeneratorTraits.h 2019-11-09 23:35:11 UTC (rev 252310)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "BytecodeStructs.h"
+#include "Instruction.h"
+
+namespace JSC { namespace Wasm {
+
+struct GeneratorTraits {
+ using OpcodeTraits = WasmOpcodeTraits;
+ using OpcodeID = WasmOpcodeID;
+ using OpNop = WasmNop;
+ using CodeBlock = std::unique_ptr<FunctionCodeBlock>;
+ static constexpr OpcodeID opcodeForDisablingOptimizations = wasm_unreachable;
+};
+
+} } // namespace JSC::Wasm
+
+#endif // ENABLE(WEBASSEMBLY)
Modified: trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp (252309 => 252310)
--- trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp 2019-11-09 20:14:37 UTC (rev 252309)
+++ trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp 2019-11-09 23:35:11 UTC (rev 252310)
@@ -37,6 +37,7 @@
#include "WasmContextInlines.h"
#include "WasmFunctionCodeBlock.h"
#include "WasmFunctionParser.h"
+#include "WasmGeneratorTraits.h"
#include "WasmThunks.h"
#include <wtf/RefPtr.h>
#include <wtf/StdUnorderedMap.h>
@@ -44,14 +45,6 @@
namespace JSC { namespace Wasm {
-struct GeneratorTraits {
- using OpcodeTraits = WasmOpcodeTraits;
- using OpcodeID = WasmOpcodeID;
- using OpNop = WasmNop;
- using CodeBlock = std::unique_ptr<FunctionCodeBlock>;
- static constexpr OpcodeID opcodeForDisablingOptimizations = wasm_unreachable;
-};
-
class LLIntGenerator : public BytecodeGeneratorBase<GeneratorTraits> {
public:
using ExpressionType = RefPtr<RegisterID>;
@@ -498,13 +491,15 @@
m_unitializedLocals.clear();
}
-auto LLIntGenerator::addConstant(Type, uint64_t value) -> ExpressionType
+auto LLIntGenerator::addConstant(Type type, uint64_t value) -> ExpressionType
{
VirtualRegister source(FirstConstantRegisterIndex + m_codeBlock->m_constants.size());
auto result = m_constantMap.emplace(value, source);
- if (result.second)
+ if (result.second) {
m_codeBlock->m_constants.append(value);
- else
+ if (UNLIKELY(Options::dumpGeneratedWasmBytecodes()))
+ m_codeBlock->m_constantTypes.append(type);
+ } else
source = result.first->second;
auto target = newTemporary();
WasmMov::emit(this, target, source);
Modified: trunk/Source/_javascript_Core/wasm/WasmLLIntPlan.cpp (252309 => 252310)
--- trunk/Source/_javascript_Core/wasm/WasmLLIntPlan.cpp 2019-11-09 20:14:37 UTC (rev 252309)
+++ trunk/Source/_javascript_Core/wasm/WasmLLIntPlan.cpp 2019-11-09 23:35:11 UTC (rev 252310)
@@ -29,6 +29,7 @@
#if ENABLE(WEBASSEMBLY)
#include "B3Compilation.h"
+#include "BytecodeDumper.h"
#include "CalleeBits.h"
#include "LLIntThunks.h"
#include "LinkBuffer.h"
@@ -90,11 +91,6 @@
void LLIntPlan::didCompleteCompilation(const AbstractLocker& locker)
{
- if (Options::dumpGeneratedBytecodes()) {
- for (const auto& codeBlock : m_wasmInternalFunctions)
- codeBlock->dumpBytecode();
- }
-
for (uint32_t functionIndex = 0; functionIndex < m_moduleInformation->functions.size(); functionIndex++) {
SignatureIndex signatureIndex = m_moduleInformation->internalFunctionSignatureIndices[functionIndex];
const Signature& signature = SignatureInformation::get(signatureIndex);
@@ -121,6 +117,10 @@
Vector<CCallHelpers::Jump> jumps(functionCount);
for (unsigned i = 0; i < functionCount; ++i) {
size_t functionIndexSpace = i + m_moduleInformation->importFunctionCount();
+
+ if (UNLIKELY(Options::dumpGeneratedWasmBytecodes()))
+ BytecodeDumper::dumpBlock(m_wasmInternalFunctions[i].get(), m_moduleInformation, WTF::dataFile());
+
m_callees[i] = Wasm::LLIntCallee::create(WTFMove(m_wasmInternalFunctions[i]), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace));
entrypoints[i] = jit.label();
#if CPU(X86_64)