From c108665b1c075dcabf4b6d7cf7f6cd75dab2b4ff Mon Sep 17 00:00:00 2001 From: getingke Date: Thu, 23 Dec 2021 14:55:22 +0800 Subject: [PATCH 1/2] fixed for add CompilationConfig Class to support all arch Change-Id: Ifd5cbb143350ecb9c496d8c7cbc3ee3745e74399 Signed-off-by: getingke --- ecmascript/compiler/BUILD.gn | 2 - ecmascript/compiler/circuit.cpp | 4 +- ecmascript/compiler/circuit.h | 4 +- ecmascript/compiler/circuit_builder.cpp | 32 +- ecmascript/compiler/circuit_builder.h | 12 +- ecmascript/compiler/code_generator.h | 28 +- ecmascript/compiler/fast_stub.cpp | 831 ++---------------- ecmascript/compiler/fast_stub.h | 237 ++--- ecmascript/compiler/fast_stub_define.h | 22 +- ecmascript/compiler/gate.cpp | 14 +- ecmascript/compiler/gate.h | 8 +- .../compiler/js_thread_offset_table.cpp | 53 -- ecmascript/compiler/js_thread_offset_table.h | 52 -- ecmascript/compiler/llvm_codegen.cpp | 41 +- ecmascript/compiler/llvm_codegen.h | 34 +- ecmascript/compiler/llvm_ir_builder.cpp | 364 ++++---- ecmascript/compiler/llvm_ir_builder.h | 121 ++- ecmascript/compiler/machine_type.h | 4 +- ecmascript/compiler/scheduler.cpp | 4 +- ecmascript/compiler/scheduler.h | 4 +- ecmascript/compiler/stub-inl.h | 55 +- ecmascript/compiler/stub.cpp | 25 +- ecmascript/compiler/stub.h | 149 +++- ecmascript/compiler/stub_aot_compiler.cpp | 137 ++- ecmascript/compiler/stub_aot_compiler.h | 21 +- ecmascript/compiler/stub_descriptor.cpp | 179 +--- ecmascript/compiler/stub_descriptor.h | 4 +- ecmascript/compiler/tests/stub_tests.cpp | 283 +++--- ecmascript/compiler/triple.cpp | 22 - ecmascript/compiler/triple.h | 56 -- ecmascript/compiler/type.cpp | 4 +- ecmascript/compiler/type.h | 4 +- ecmascript/compiler/verifier.cpp | 4 +- ecmascript/compiler/verifier.h | 4 +- ecmascript/interpreter/frame_handler.cpp | 4 +- ecmascript/js_thread.cpp | 2 +- ecmascript/stub_module.cpp | 2 +- 37 files changed, 832 insertions(+), 1994 deletions(-) delete mode 100644 ecmascript/compiler/js_thread_offset_table.cpp delete mode 100644 ecmascript/compiler/js_thread_offset_table.h delete mode 100644 ecmascript/compiler/triple.cpp delete mode 100644 ecmascript/compiler/triple.h diff --git a/ecmascript/compiler/BUILD.gn b/ecmascript/compiler/BUILD.gn index c89b044508..12120aedc4 100644 --- a/ecmascript/compiler/BUILD.gn +++ b/ecmascript/compiler/BUILD.gn @@ -44,13 +44,11 @@ source_set("libark_jsoptimizer_static") { "circuit_builder.cpp", "fast_stub.cpp", "gate.cpp", - "js_thread_offset_table.cpp", "llvm_codegen.cpp", "llvm_ir_builder.cpp", "scheduler.cpp", "stub.cpp", "stub_descriptor.cpp", - "triple.cpp", "type.cpp", "verifier.cpp", ] diff --git a/ecmascript/compiler/circuit.cpp b/ecmascript/compiler/circuit.cpp index f084e5bd07..a1f1fde3fc 100644 --- a/ecmascript/compiler/circuit.cpp +++ b/ecmascript/compiler/circuit.cpp @@ -16,7 +16,7 @@ #include "ecmascript/compiler/circuit.h" #include "ecmascript/compiler/compiler_macros.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { Circuit::Circuit() : space({}), circuitSize(0), gateCounter(0), time(1), dataSection({}) { this->NewGate(OpCode(OpCode::CIRCUIT_ROOT), 0, {}, TypeCode::NOTYPE); // circuit root @@ -384,4 +384,4 @@ void Circuit::SetFrameType(panda::ecmascript::FrameType type) { this->frameType = type; } -} // namespace kungfu +} // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/circuit.h b/ecmascript/compiler/circuit.h index 83a0b6d05d..f70a8d8bf3 100644 --- a/ecmascript/compiler/circuit.h +++ b/ecmascript/compiler/circuit.h @@ -27,7 +27,7 @@ #include "libpandabase/macros.h" #include "securec.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { const size_t INITIAL_SPACE = 1U << 0U; // this should be tuned const size_t MAX_SPACE = 1U << 24U; // this should be tuned const size_t SCALE_RATE = 1U << 1U; // this should be tuned @@ -102,6 +102,6 @@ private: std::vector dataSection; panda::ecmascript::FrameType frameType {panda::ecmascript::FrameType::OPTIMIZED_FRAME}; }; -} // namespace kungfu +} // namespace panda::ecmascript::kungfu #endif // ECMASCRIPT_COMPILER_CIRCUIT_H diff --git a/ecmascript/compiler/circuit_builder.cpp b/ecmascript/compiler/circuit_builder.cpp index 393e2198ef..d4f8472a37 100644 --- a/ecmascript/compiler/circuit_builder.cpp +++ b/ecmascript/compiler/circuit_builder.cpp @@ -15,10 +15,9 @@ #include "ecmascript/compiler/circuit_builder.h" #include "include/coretypes/tagged_value.h" -#include "triple.h" #include "utils/bit_utils.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { using TaggedValue = panda::coretypes::TaggedValue; GateRef CircuitBuilder::NewArguments(size_t index) { @@ -166,7 +165,7 @@ GateRef CircuitBuilder::NewDefaultCase(GateRef switchBranch) return circuit_->NewGate(OpCode(OpCode::DEFAULT_CASE), 0, { switchBranch }, TypeCode::NOTYPE); } -OpCode CircuitBuilder::GetStoreOpCodeFromMachineType(MachineType type, const char *triple) +OpCode CircuitBuilder::GetStoreOpCodeFromMachineType(MachineType type) { switch (type) { case MachineType::INT8: @@ -185,14 +184,6 @@ OpCode CircuitBuilder::GetStoreOpCodeFromMachineType(MachineType type, const cha return OpCode(OpCode::INT16_STORE); case MachineType::UINT32: return OpCode(OpCode::INT32_STORE); - case MachineType::NATIVE_POINTER: - { - if (triple == TripleConst::GetLLVMArm32Triple()) { - return OpCode(OpCode::INT32_STORE); - } else { - return OpCode(OpCode::INT64_STORE); - } - } case MachineType::UINT64: case MachineType::TAGGED: case MachineType::TAGGED_POINTER: @@ -206,7 +197,7 @@ OpCode CircuitBuilder::GetStoreOpCodeFromMachineType(MachineType type, const cha } } -OpCode CircuitBuilder::GetLoadOpCodeFromMachineType(MachineType type, const char *triple) +OpCode CircuitBuilder::GetLoadOpCodeFromMachineType(MachineType type) { switch (type) { case MachineType::INT8: @@ -225,13 +216,6 @@ OpCode CircuitBuilder::GetLoadOpCodeFromMachineType(MachineType type, const char return OpCode(OpCode::INT16_LOAD); case MachineType::UINT32: return OpCode(OpCode::INT32_LOAD); - case MachineType::NATIVE_POINTER: { - if (ArchRelatePtrValueCode(triple) == ValueCode::INT32) { - return OpCode(OpCode::INT32_LOAD); - } else { - return OpCode(OpCode::INT64_LOAD); - } - } case MachineType::UINT64: case MachineType::TAGGED: case MachineType::TAGGED_POINTER: @@ -295,15 +279,15 @@ GateRef CircuitBuilder::NewDependAnd(std::initializer_list args) return circuit_->NewGate(OpCode(OpCode::DEPEND_AND), args.size(), inputs, TypeCode::NOTYPE); } -GateRef CircuitBuilder::NewLoadGate(MachineType type, GateRef val, GateRef depend, const char *triple) +GateRef CircuitBuilder::NewLoadGate(MachineType type, GateRef val, GateRef depend) { - OpCode op = GetLoadOpCodeFromMachineType(type, triple); + OpCode op = GetLoadOpCodeFromMachineType(type); return circuit_->NewGate(op, static_cast(type), { depend, val }, MachineType2TypeCode(type)); } -GateRef CircuitBuilder::NewStoreGate(MachineType type, GateRef ptr, GateRef val, GateRef depend, const char *triple) +GateRef CircuitBuilder::NewStoreGate(MachineType type, GateRef ptr, GateRef val, GateRef depend) { - OpCode op = GetStoreOpCodeFromMachineType(type, triple); + OpCode op = GetStoreOpCodeFromMachineType(type); return circuit_->NewGate(op, static_cast(type), { depend, val, ptr }, MachineType2TypeCode(type)); } @@ -403,4 +387,4 @@ GateRef CircuitBuilder::Alloca(int size, TypeCode type) auto allocaList = Circuit::GetCircuitRoot(OpCode(OpCode::ALLOCA_LIST)); return circuit_->NewGate(OpCode(OpCode::ALLOCA), size, { allocaList }, type); } -} // namespace kungfu +} // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/circuit_builder.h b/ecmascript/compiler/circuit_builder.h index f808be119a..6d2a508fcc 100644 --- a/ecmascript/compiler/circuit_builder.h +++ b/ecmascript/compiler/circuit_builder.h @@ -21,7 +21,7 @@ #include "ecmascript/compiler/machine_type.h" #include "ecmascript/compiler/stub_descriptor.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { class CircuitBuilder { public: explicit CircuitBuilder(Circuit *circuit) : circuit_(circuit) {} @@ -55,8 +55,8 @@ public: GateRef NewIfFalse(GateRef ifBranch); GateRef NewSwitchCase(GateRef switchBranch, int32_t value); GateRef NewDefaultCase(GateRef switchBranch); - GateRef NewLoadGate(MachineType type, GateRef val, GateRef depend, const char *triple); - GateRef NewStoreGate(MachineType type, GateRef ptr, GateRef val, GateRef depend, const char *triple); + GateRef NewLoadGate(MachineType type, GateRef val, GateRef depend); + GateRef NewStoreGate(MachineType type, GateRef ptr, GateRef val, GateRef depend); GateRef NewDependRelay(GateRef state, GateRef depend); GateRef NewDependAnd(std::initializer_list args); GateRef NewArithMeticGate(OpCode opcode, GateRef left, GateRef right); @@ -67,8 +67,8 @@ public: std::initializer_list args); GateRef NewCallGate(StubDescriptor *descriptor, GateRef glue, GateRef target, GateRef depend, std::initializer_list args); - static OpCode GetLoadOpCodeFromMachineType(MachineType type, const char *triple); - static OpCode GetStoreOpCodeFromMachineType(MachineType type, const char *triple); + static OpCode GetLoadOpCodeFromMachineType(MachineType type); + static OpCode GetStoreOpCodeFromMachineType(MachineType type); static OpCode GetSelectOpCodeFromMachineType(MachineType type); static OpCode GetCallOpCodeFromMachineType(MachineType type); @@ -87,6 +87,6 @@ public: private: Circuit *circuit_; }; -} // namespace kungfu +} // namespace panda::ecmascript::kungfu #endif // ECMASCRIPT_COMPILER_CIRCUIT_BUILDER_H \ No newline at end of file diff --git a/ecmascript/compiler/code_generator.h b/ecmascript/compiler/code_generator.h index 94661fb86a..4196eba8f6 100644 --- a/ecmascript/compiler/code_generator.h +++ b/ecmascript/compiler/code_generator.h @@ -17,27 +17,29 @@ #define ECMASCRIPT_COMPILER_CODE_GENERATOR_H #include "circuit.h" +#include "stub.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { using ControlFlowGraph = std::vector>; class CodeGeneratorImpl { public: - CodeGeneratorImpl() = default; - virtual ~CodeGeneratorImpl() = default; - virtual void GenerateCodeForStub(Circuit *circuit, const ControlFlowGraph &graph, int index) = 0; + CodeGeneratorImpl() = default; + virtual ~CodeGeneratorImpl() = default; + virtual void GenerateCodeForStub(Circuit *circuit, const ControlFlowGraph &graph, int index, + const CompilationConfig *cfg) = 0; }; class CodeGenerator { public: - explicit CodeGenerator(std::unique_ptr &impl, const char* triple) : impl_(std::move(impl)) {} - ~CodeGenerator() = default; - void Run(Circuit *circuit, const ControlFlowGraph &graph, int index) - { - impl_->GenerateCodeForStub(circuit, graph, index); - } + explicit CodeGenerator(std::unique_ptr &impl) + : impl_(std::move(impl)) {} + ~CodeGenerator() = default; + void Run(Circuit *circuit, const ControlFlowGraph &graph, int index, const CompilationConfig *cfg) { + impl_->GenerateCodeForStub(circuit, graph, index, cfg); + } private: - std::unique_ptr impl_{nullptr}; + std::unique_ptr impl_{nullptr}; }; -} // namespace kungfu -#endif // ECMASCRIPT_COMPILER_CODE_GENERATOR_H \ No newline at end of file +} // namespace panda::ecmascript::kungfu +#endif // ECMASCRIPT_COMPILER_CODE_GENERATOR_H \ No newline at end of file diff --git a/ecmascript/compiler/fast_stub.cpp b/ecmascript/compiler/fast_stub.cpp index 452334331b..4e4cc727b2 100644 --- a/ecmascript/compiler/fast_stub.cpp +++ b/ecmascript/compiler/fast_stub.cpp @@ -16,19 +16,18 @@ #include "fast_stub.h" #include "ecmascript/base/number_helper.h" -#include "ecmascript/compiler/js_thread_offset_table.h" #include "ecmascript/compiler/llvm_ir_builder.h" #include "ecmascript/compiler/machine_type.h" #include "ecmascript/js_array.h" #include "ecmascript/message_string.h" #include "ecmascript/tagged_hash_table-inl.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { using namespace panda::ecmascript; -#ifdef ECMASCRIPT_ENABLE_SPECIFIC_STUBS -void FastAddStub::GenerateCircuit() +void FastAddStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef x = TaggedArgument(0); GateRef y = TaggedArgument(1); @@ -89,8 +88,9 @@ void FastAddStub::GenerateCircuit() } #ifndef NDEBUG -void FastMulGCTestStub::GenerateCircuit() +void FastMulGCTestStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); env->GetCircuit()->SetFrameType(FrameType::OPTIMIZED_ENTRY_FRAME); GateRef glue = PtrArgument(0); @@ -166,8 +166,9 @@ void FastMulGCTestStub::GenerateCircuit() } #endif -void FastSubStub::GenerateCircuit() +void FastSubStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef x = TaggedArgument(0); GateRef y = TaggedArgument(1); @@ -241,8 +242,9 @@ void FastSubStub::GenerateCircuit() Return(IntBuildTaggedWithNoGC(*intX)); } -void FastMulStub::GenerateCircuit() +void FastMulStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef x = TaggedArgument(0); GateRef y = TaggedArgument(1); @@ -302,8 +304,9 @@ void FastMulStub::GenerateCircuit() Return(DoubleBuildTaggedWithNoGC(*doubleX)); } -void FastDivStub::GenerateCircuit() +void FastDivStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef x = TaggedArgument(0); GateRef y = TaggedArgument(1); @@ -401,8 +404,9 @@ void FastDivStub::GenerateCircuit() } } -void FastModStub::GenerateCircuit() +void FastModStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef glue = PtrArgument(0); GateRef x = TaggedArgument(1); @@ -556,13 +560,14 @@ void FastModStub::GenerateCircuit() } } -void FastTypeOfStub::GenerateCircuit() +void FastTypeOfStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef glue = PtrArgument(0); GateRef obj = TaggedArgument(1); DEFVARIABLE(holder, MachineType::TAGGED, obj); - GateRef gConstOffset = PtrAdd(glue, GetArchRelateConstant(OffsetTable::GetOffset(JSThread::GlueID::GLOBAL_CONST))); + GateRef gConstOffset = PtrAdd(glue, GetArchRelateConstant(env->GetGlueOffset(JSThread::GlueID::GLOBAL_CONST))); GateRef booleanIndex = GetGlobalConstantString(ConstantIndex::UNDEFINED_STRING_INDEX); GateRef gConstUndefindStr = Load(MachineType::TAGGED_POINTER, gConstOffset, booleanIndex); DEFVARIABLE(resultRep, MachineType::TAGGED_POINTER, gConstUndefindStr); @@ -687,8 +692,9 @@ void FastTypeOfStub::GenerateCircuit() Return(*resultRep); } -void FastEqualStub::GenerateCircuit() +void FastEqualStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef x = TaggedArgument(0); GateRef y = TaggedArgument(1); @@ -769,16 +775,18 @@ void FastEqualStub::GenerateCircuit() } } -void GetPropertyByIndexStub::GenerateCircuit() +void GetPropertyByIndexStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); GateRef receiver = TaggedArgument(1); GateRef index = Int32Argument(2); /* 2 : 3rd parameter is index */ Return(GetPropertyByIndex(glue, receiver, index)); } -void SetPropertyByIndexStub::GenerateCircuit() +void SetPropertyByIndexStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); GateRef receiver = TaggedArgument(1); GateRef index = Int32Argument(2); /* 2 : 3rd parameter is index */ @@ -786,682 +794,50 @@ void SetPropertyByIndexStub::GenerateCircuit() Return(SetPropertyByIndex(glue, receiver, index, value)); } -void GetPropertyByNameStub::GenerateCircuit() +void GetPropertyByNameStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); GateRef receiver = TaggedArgument(1); GateRef key = TaggedArgument(2); // 2 : 3rd para Return(GetPropertyByName(glue, receiver, key)); } -#endif - -#ifndef ECMASCRIPT_ENABLE_SPECIFIC_STUBS -void FastAddStub::GenerateCircuit() -{ - auto env = GetEnvironment(); - GateRef x = TaggedArgument(0); - GateRef y = TaggedArgument(1); - DEFVARIABLE(intX, MachineType::INT32, 0); - DEFVARIABLE(intY, MachineType::INT32, 0); - DEFVARIABLE(doubleX, MachineType::FLOAT64, 0); - DEFVARIABLE(doubleY, MachineType::FLOAT64, 0); - Label xIsNumber(env); - Label xNotNumberOryNotNumber(env); - Label xIsNumberAndyIsNumber(env); - Label xIsDoubleAndyIsDouble(env); - Branch(TaggedIsNumber(x), &xIsNumber, &xNotNumberOryNotNumber); - Bind(&xIsNumber); - { - Label yIsNumber(env); - // if right.IsNumber() - Branch(TaggedIsNumber(y), &yIsNumber, &xNotNumberOryNotNumber); - Bind(&yIsNumber); - { - Label xIsInt(env); - Label xNotInt(env); - Branch(TaggedIsInt(x), &xIsInt, &xNotInt); - Bind(&xIsInt); - { - intX = TaggedCastToInt32(x); - doubleX = ChangeInt32ToFloat64(*intX); - Jump(&xIsNumberAndyIsNumber); - } - Bind(&xNotInt); - { - doubleX = TaggedCastToDouble(x); - Jump(&xIsNumberAndyIsNumber); - } - } - } - Bind(&xNotNumberOryNotNumber); - Return(GetHoleConstant(MachineType::UINT64)); - Label yIsInt(env); - Label yNotInt(env); - Bind(&xIsNumberAndyIsNumber); - { - Branch(TaggedIsInt(y), &yIsInt, &yNotInt); - Bind(&yIsInt); - { - intY = TaggedCastToInt32(y); - doubleY = ChangeInt32ToFloat64(*intY); - Jump(&xIsDoubleAndyIsDouble); - } - Bind(&yNotInt); - { - doubleY = TaggedCastToDouble(y); - Jump(&xIsDoubleAndyIsDouble); - } - } - Bind(&xIsDoubleAndyIsDouble); - doubleX = DoubleAdd(*doubleX, *doubleY); - Return(DoubleBuildTaggedWithNoGC(*doubleX)); -} - -void FastSubStub::GenerateCircuit() -{ - auto env = GetEnvironment(); - GateRef x = TaggedArgument(0); - GateRef y = TaggedArgument(1); - DEFVARIABLE(intX, MachineType::INT32, GetInt32Constant(0)); - DEFVARIABLE(intY, MachineType::INT32, GetInt32Constant(0)); - DEFVARIABLE(doubleX, MachineType::FLOAT64, GetDoubleConstant(0)); - DEFVARIABLE(doubleY, MachineType::FLOAT64, GetDoubleConstant(0)); - Label xIsNumber(env); - Label xNotNumberOryNotNumber(env); - Label xNotIntOryNotInt(env); - Label xIsIntAndyIsInt(env); - // if x is number - Branch(TaggedIsNumber(x), &xIsNumber, &xNotNumberOryNotNumber); - Bind(&xIsNumber); - { - Label yIsNumber(env); - // if y is number - Branch(TaggedIsNumber(y), &yIsNumber, &xNotNumberOryNotNumber); - { - Bind(&yIsNumber); - { - Label xIsInt(env); - Label xNotInt(env); - Branch(TaggedIsInt(x), &xIsInt, &xNotInt); - Bind(&xIsInt); - { - intX = TaggedCastToInt32(x); - Label yIsInt(env); - Label yNotInt(env); - Branch(TaggedIsInt(y), &yIsInt, &yNotInt); - Bind(&yIsInt); - { - intY = TaggedCastToInt32(y); - intX = Int32Sub(*intX, *intY); - Jump(&xIsIntAndyIsInt); - } - Bind(&yNotInt); - { - doubleY = TaggedCastToDouble(y); - doubleX = ChangeInt32ToFloat64(*intX); - Jump(&xNotIntOryNotInt); - } - } - Bind(&xNotInt); - { - Label yIsInt(env); - Label yNotInt(env); - doubleX = TaggedCastToDouble(x); - Branch(TaggedIsInt(y), &yIsInt, &yNotInt); - Bind(&yIsInt); - { - intY = TaggedCastToInt32(y); - doubleY = ChangeInt32ToFloat64(*intY); - Jump(&xNotIntOryNotInt); - } - Bind(&yNotInt); - { - doubleY = TaggedCastToDouble(y); - Jump(&xNotIntOryNotInt); - } - } - } - } - } - Bind(&xNotNumberOryNotNumber); - Return(GetHoleConstant(MachineType::UINT64)); - Bind(&xNotIntOryNotInt); - doubleX = DoubleSub(*doubleX, *doubleY); - Return(DoubleBuildTaggedWithNoGC(*doubleX)); - Bind(&xIsIntAndyIsInt); - Return(IntBuildTaggedWithNoGC(*intX)); -} - -void FastMulStub::GenerateCircuit() -{ - GateRef x = TaggedArgument(0); - GateRef y = TaggedArgument(1); - - GateRef intX = TaggedCastToInt32(x); - GateRef intY = TaggedCastToInt32(y); - GateRef result = Int32Mul(intX, intY); - Return(IntBuildTaggedWithNoGC(result)); -} - -void FastDivStub::GenerateCircuit() -{ - auto env = GetEnvironment(); - GateRef x = TaggedArgument(0); - GateRef y = TaggedArgument(1); - DEFVARIABLE(intX, MachineType::INT32, GetInt32Constant(0)); - DEFVARIABLE(intY, MachineType::INT32, GetInt32Constant(0)); - DEFVARIABLE(doubleX, MachineType::FLOAT64, GetDoubleConstant(0)); - DEFVARIABLE(doubleY, MachineType::FLOAT64, GetDoubleConstant(0)); - Label xIsNumber(env); - Label xNotNumberOryNotNumber(env); - Label xIsNumberAndyIsNumber(env); - Label xIsDoubleAndyIsDouble(env); - Branch(TaggedIsNumber(x), &xIsNumber, &xNotNumberOryNotNumber); - Bind(&xIsNumber); - { - Label yIsNumber(env); - // if right.IsNumber() - Branch(TaggedIsNumber(y), &yIsNumber, &xNotNumberOryNotNumber); - Bind(&yIsNumber); - { - Label xIsInt(env); - Label xNotInt(env); - Branch(TaggedIsInt(x), &xIsInt, &xNotInt); - Bind(&xIsInt); - { - intX = TaggedCastToInt32(x); - doubleX = ChangeInt32ToFloat64(*intX); - Jump(&xIsNumberAndyIsNumber); - } - Bind(&xNotInt); - { - doubleX = TaggedCastToDouble(x); - Jump(&xIsNumberAndyIsNumber); - } - } - } - Bind(&xNotNumberOryNotNumber); - Return(GetHoleConstant(MachineType::UINT64)); - Label yIsInt(env); - Label yNotInt(env); - Bind(&xIsNumberAndyIsNumber); - Branch(TaggedIsInt(y), &yIsInt, &yNotInt); - Bind(&yIsInt); - { - intY = TaggedCastToInt32(y); - doubleY = ChangeInt32ToFloat64(*intY); - Jump(&xIsDoubleAndyIsDouble); - } - Bind(&yNotInt); - { - doubleY = TaggedCastToDouble(y); - Jump(&xIsDoubleAndyIsDouble); - } - Bind(&xIsDoubleAndyIsDouble); - { - Label divisorIsZero(env); - Label divisorNotZero(env); - Branch(DoubleEqual(*doubleY, GetDoubleConstant(0.0)), &divisorIsZero, &divisorNotZero); - Bind(&divisorIsZero); - { - Label xIsZeroOrNan(env); - Label xNeiZeroOrNan(env); - Label xIsZero(env); - Label xNotZero(env); - // dLeft == 0.0 || std::isnan(dLeft) - Branch(DoubleEqual(*doubleX, GetDoubleConstant(0.0)), &xIsZero, &xNotZero); - Bind(&xIsZero); - Jump(&xIsZeroOrNan); - Bind(&xNotZero); - { - Label xIsNan(env); - Label xNotNan(env); - Branch(DoubleIsNAN(*doubleX), &xIsNan, &xNotNan); - Bind(&xIsNan); - Jump(&xIsZeroOrNan); - Bind(&xNotNan); - Jump(&xNeiZeroOrNan); - } - Bind(&xIsZeroOrNan); - Return(DoubleBuildTaggedWithNoGC(GetDoubleConstant(base::NAN_VALUE))); - Bind(&xNeiZeroOrNan); - { - GateRef intXTmp = CastDoubleToInt64(*doubleX); - GateRef intYtmp = CastDoubleToInt64(*doubleY); - intXTmp = Word64And(Word64Xor(intXTmp, intYtmp), GetWord64Constant(base::DOUBLE_SIGN_MASK)); - intXTmp = Word64Xor(intXTmp, CastDoubleToInt64(GetDoubleConstant(base::POSITIVE_INFINITY))); - doubleX = CastInt64ToFloat64(intXTmp); - Return(DoubleBuildTaggedWithNoGC(*doubleX)); - } - } - Bind(&divisorNotZero); - { - doubleX = DoubleDiv(*doubleX, *doubleY); - Return(DoubleBuildTaggedWithNoGC(*doubleX)); - } - } -} - -void FindOwnElement2Stub::GenerateCircuit() -{ - GateRef glue = PtrArgument(0); - GateRef elements = TaggedArgument(1); - GateRef index = Int32Argument(2); // 2 : 3rd parameter - GateRef isDict = Int32Argument(3); // 3 : 4th parameter - GateRef attr = PtrArgument(4); // 4 : 5th parameter - GateRef indexOrEntry = PtrArgument(5); // 5 : 6rd parameter - Return(FindOwnElement2(glue, elements, index, isDict, attr, indexOrEntry)); -} - -void GetPropertyByIndexStub::GenerateCircuit() -{ - GateRef glue = PtrArgument(0); - GateRef receiver = TaggedArgument(1); - GateRef index = Int32Argument(2); /* 2 : 3rd parameter is index */ - Return(GetPropertyByIndex(glue, receiver, index)); -} - -void SetPropertyByIndexStub::GenerateCircuit() -{ - GateRef glue = PtrArgument(0); - GateRef receiver = TaggedArgument(1); - GateRef index = Int32Argument(2); /* 2 : 3rd parameter is index */ - GateRef value = TaggedArgument(3); /* 3 : 4th parameter is value */ - Return(SetPropertyByIndex(glue, receiver, index, value)); -} - -void GetPropertyByNameStub::GenerateCircuit() -{ - GateRef glue = PtrArgument(0); - GateRef receiver = TaggedArgument(1); - GateRef key = TaggedArgument(2); // 2 : 3rd para - Return(GetPropertyByName(glue, receiver, key)); -} - -void SetPropertyByNameStub::GenerateCircuit() -{ - GateRef glue = PtrArgument(0); - GateRef receiver = TaggedArgument(1); - GateRef key = TaggedArgument(2); // 2 : 3rd para - GateRef value = TaggedArgument(3); // 3 : 4th para - Return(SetPropertyByName(glue, receiver, key, value)); -} - -void SetPropertyByNameWithOwnStub::GenerateCircuit() -{ - GateRef glue = PtrArgument(0); - GateRef receiver = TaggedArgument(1); - GateRef key = TaggedArgument(2); // 2 : 3rd para - GateRef value = TaggedArgument(3); // 3 : 4th para - Return(SetPropertyByNameWithOwn(glue, receiver, key, value)); -} - -void FastModStub::GenerateCircuit() -{ - auto env = GetEnvironment(); - GateRef glue = PtrArgument(0); - GateRef x = TaggedArgument(1); - GateRef y = TaggedArgument(2); // 2: 3rd argument - DEFVARIABLE(intX, MachineType::INT32, GetInt32Constant(0)); - DEFVARIABLE(intY, MachineType::INT32, GetInt32Constant(0)); - DEFVARIABLE(doubleX, MachineType::FLOAT64, GetDoubleConstant(0)); - DEFVARIABLE(doubleY, MachineType::FLOAT64, GetDoubleConstant(0)); - Label xIsInt(env); - Label xNotIntOryNotInt(env); - Branch(TaggedIsInt(x), &xIsInt, &xNotIntOryNotInt); - Bind(&xIsInt); - { - Label yIsInt(env); - Label xIsIntAndyIsInt(env); - // if right.IsInt() - Branch(TaggedIsInt(y), &yIsInt, &xNotIntOryNotInt); - Bind(&yIsInt); - { - intX = TaggedCastToInt32(x); - intY = TaggedCastToInt32(y); - Jump(&xIsIntAndyIsInt); - } - Bind(&xIsIntAndyIsInt); - { - Label xGtZero(env); - Label xGtZeroAndyGtZero(env); - Branch(Int32GreaterThan(*intX, GetInt32Constant(0)), &xGtZero, &xNotIntOryNotInt); - Bind(&xGtZero); - { - Branch(Int32GreaterThan(*intY, GetInt32Constant(0)), &xGtZeroAndyGtZero, &xNotIntOryNotInt); - Bind(&xGtZeroAndyGtZero); - { - intX = Int32Mod(*intX, *intY); - Return(IntBuildTaggedWithNoGC(*intX)); - } - } - } - } - Bind(&xNotIntOryNotInt); - { - Label xIsNumber(env); - Label xNotNumberOryNotNumber(env); - Label xIsNumberAndyIsNumber(env); - Label xIsDoubleAndyIsDouble(env); - Branch(TaggedIsNumber(x), &xIsNumber, &xNotNumberOryNotNumber); - Bind(&xIsNumber); - { - Label yIsNumber(env); - // if right.IsNumber() - Branch(TaggedIsNumber(y), &yIsNumber, &xNotNumberOryNotNumber); - Bind(&yIsNumber); - { - Label xIfInt(env); - Label xIfNotInt(env); - Branch(TaggedIsInt(x), &xIfInt, &xIfNotInt); - Bind(&xIfInt); - { - intX = TaggedCastToInt32(x); - doubleX = ChangeInt32ToFloat64(*intX); - Jump(&xIsNumberAndyIsNumber); - } - Bind(&xIfNotInt); - { - doubleX = TaggedCastToDouble(x); - Jump(&xIsNumberAndyIsNumber); - } - } - } - Bind(&xNotNumberOryNotNumber); - Return(GetHoleConstant(MachineType::UINT64)); - Label yIfInt(env); - Label yIfNotInt(env); - Bind(&xIsNumberAndyIsNumber); - Branch(TaggedIsInt(y), &yIfInt, &yIfNotInt); - Bind(&yIfInt); - { - intY = TaggedCastToInt32(y); - doubleY = ChangeInt32ToFloat64(*intY); - Jump(&xIsDoubleAndyIsDouble); - } - Bind(&yIfNotInt); - { - doubleY = TaggedCastToDouble(y); - Jump(&xIsDoubleAndyIsDouble); - } - Bind(&xIsDoubleAndyIsDouble); - { - Label yIsZero(env); - Label yNotZero(env); - Label yIsZeroOrNanOrxIsNanOrInf(env); - Label yNeiZeroOrNanAndxNeiNanOrInf(env); - // dRight == 0.0 or std::isnan(dRight) or std::isnan(dLeft) or std::isinf(dLeft) - Branch(DoubleEqual(*doubleY, GetDoubleConstant(0.0)), &yIsZero, &yNotZero); - Bind(&yIsZero); - Jump(&yIsZeroOrNanOrxIsNanOrInf); - Bind(&yNotZero); - { - Label yIsNan(env); - Label yNotNan(env); - Branch(DoubleIsNAN(*doubleY), &yIsNan, &yNotNan); - Bind(&yIsNan); - Jump(&yIsZeroOrNanOrxIsNanOrInf); - Bind(&yNotNan); - { - Label xIsNan(env); - Label xNotNan(env); - Branch(DoubleIsNAN(*doubleX), &xIsNan, &xNotNan); - Bind(&xIsNan); - Jump(&yIsZeroOrNanOrxIsNanOrInf); - Bind(&xNotNan); - { - Label xIsInf(env); - Label xNotInf(env); - Branch(DoubleIsINF(*doubleX), &xIsInf, &xNotInf); - Bind(&xIsInf); - Jump(&yIsZeroOrNanOrxIsNanOrInf); - Bind(&xNotInf); - Jump(&yNeiZeroOrNanAndxNeiNanOrInf); - } - } - } - Bind(&yIsZeroOrNanOrxIsNanOrInf); - Return(DoubleBuildTaggedWithNoGC(GetDoubleConstant(base::NAN_VALUE))); - Bind(&yNeiZeroOrNanAndxNeiNanOrInf); - { - Label xIsFloatZero(env); - Label xIsZeroOryIsInf(env); - Label xNotZeroAndyNotInf(env); - Branch(DoubleEqual(*doubleX, GetDoubleConstant(0.0)), &xIsFloatZero, &xNotZeroAndyNotInf); - Bind(&xIsFloatZero); - Jump(&xIsZeroOryIsInf); - Label yIsInf(env); - Label yNotInf(env); - Bind(&xNotZeroAndyNotInf); - Branch(DoubleIsINF(*doubleY), &yIsInf, &yNotInf); - Bind(&yIsInf); - Jump(&xIsZeroOryIsInf); - Bind(&yNotInf); - { - StubDescriptor *floatMod = GET_STUBDESCRIPTOR(FloatMod); - doubleX = CallRuntime(floatMod, glue, GetWord64Constant(FAST_STUB_ID(FloatMod)), { - *doubleX, *doubleY - }); - Return(DoubleBuildTaggedWithNoGC(*doubleX)); - } - Bind(&xIsZeroOryIsInf); - Return(DoubleBuildTaggedWithNoGC(*doubleX)); - } - } - } -} - -#ifndef NDEBUG -void FastMulGCTestStub::GenerateCircuit() -{ - auto env = GetEnvironment(); - env->GetCircuit()->SetFrameType(FrameType::OPTIMIZED_ENTRY_FRAME); - GateRef glue = PtrArgument(0); - GateRef x = Int64Argument(1); - GateRef y = Int64Argument(2); // 2: 3rd argument - - DEFVARIABLE(intX, MachineType::INT64, GetWord64Constant(0)); - DEFVARIABLE(intY, MachineType::INT64, GetWord64Constant(0)); - DEFVARIABLE(valuePtr, MachineType::INT64, GetWord64Constant(0)); - DEFVARIABLE(doubleX, MachineType::FLOAT64, GetDoubleConstant(0)); - DEFVARIABLE(doubleY, MachineType::FLOAT64, GetDoubleConstant(0)); - Label xIsNumber(env); - Label xNotNumberOryNotNumber(env); - Label xIsNumberAndyIsNumber(env); - Label xIsDoubleAndyIsDouble(env); - Branch(TaggedIsNumber(x), &xIsNumber, &xNotNumberOryNotNumber); - Bind(&xIsNumber); - { - Label yIsNumber(env); - // if right.IsNumber() - Branch(TaggedIsNumber(y), &yIsNumber, &xNotNumberOryNotNumber); - Bind(&yIsNumber); - { - Label xIsInt(env); - Label xNotInt(env); - Branch(TaggedIsInt(x), &xIsInt, &xNotInt); - Bind(&xIsInt); - { - intX = TaggedCastToInt64(x); - doubleX = CastInt64ToFloat64(*intX); - Jump(&xIsNumberAndyIsNumber); - } - Bind(&xNotInt); - { - doubleX = TaggedCastToDouble(x); - Jump(&xIsNumberAndyIsNumber); - } - } - } - Bind(&xNotNumberOryNotNumber); - Return(GetHoleConstant(MachineType::UINT64)); - Label yIsInt(env); - Label yNotInt(env); - Bind(&xIsNumberAndyIsNumber); - { - Branch(TaggedIsInt(y), &yIsInt, &yNotInt); - Bind(&yIsInt); - { - intY = TaggedCastToInt64(y); - doubleY = CastInt64ToFloat64(*intY); - Jump(&xIsDoubleAndyIsDouble); - } - Bind(&yNotInt); - { - doubleY = TaggedCastToDouble(y); - Jump(&xIsDoubleAndyIsDouble); - } - } - Bind(&xIsDoubleAndyIsDouble); - doubleX = DoubleMul(*doubleX, *doubleY); - StubDescriptor *getTaggedArrayPtr = GET_STUBDESCRIPTOR(GetTaggedArrayPtrTest); - GateRef ptr1 = CallRuntime(getTaggedArrayPtr, glue, GetWord64Constant(FAST_STUB_ID(GetTaggedArrayPtrTest)), { - glue - }); - GateRef ptr2 = CallRuntime(getTaggedArrayPtr, glue, GetWord64Constant(FAST_STUB_ID(GetTaggedArrayPtrTest)), { - glue - }); - (void)ptr2; - auto value = Load(MachineType::UINT64, ptr1); - GateRef value2 = CastInt64ToFloat64(value); - doubleX = DoubleMul(*doubleX, value2); - Return(DoubleBuildTaggedWithNoGC(*doubleX)); + +void FindOwnElement2Stub::GenerateCircuit(const CompilationConfig *cfg) +{ + Stub::GenerateCircuit(cfg); + GateRef glue = PtrArgument(0); + GateRef elements = TaggedArgument(1); + GateRef index = Int32Argument(2); // 2 : 3rd parameter + GateRef isDict = Int32Argument(3); // 3 : 4th parameter + GateRef attr = PtrArgument(4); // 4 : 5th parameter + GateRef indexOrEntry = PtrArgument(5); // 5 : 6rd parameter + Return(FindOwnElement2(glue, elements, index, isDict, attr, indexOrEntry)); } -#endif -void FastTypeOfStub::GenerateCircuit() +void SetPropertyByNameStub::GenerateCircuit(const CompilationConfig *cfg) { - auto env = GetEnvironment(); + Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); - GateRef obj = TaggedArgument(1); - DEFVARIABLE(holder, MachineType::TAGGED, obj); - GateRef gConstOffset = PtrAdd(glue, GetArchRelateConstant(OffsetTable::GetOffset(JSThread::GlueID::GLOBAL_CONST))); - GateRef booleanIndex = GetGlobalConstantString(ConstantIndex::UNDEFINED_STRING_INDEX); - GateRef gConstUndefindStr = Load(MachineType::TAGGED_POINTER, gConstOffset, booleanIndex); - DEFVARIABLE(resultRep, MachineType::TAGGED_POINTER, gConstUndefindStr); - Label objIsTrue(env); - Label objNotTrue(env); - Label exit(env); - Label defaultLabel(env); - GateRef gConstBooleanStr = Load( - MachineType::TAGGED_POINTER, gConstOffset, GetGlobalConstantString(ConstantIndex::BOOLEAN_STRING_INDEX)); - Branch(Word64Equal(obj, GetWord64Constant(JSTaggedValue::VALUE_TRUE)), &objIsTrue, &objNotTrue); - Bind(&objIsTrue); - { - resultRep = gConstBooleanStr; - Jump(&exit); - } - Bind(&objNotTrue); - { - Label objIsFalse(env); - Label objNotFalse(env); - Branch(Word64Equal(obj, GetWord64Constant(JSTaggedValue::VALUE_FALSE)), &objIsFalse, &objNotFalse); - Bind(&objIsFalse); - { - resultRep = gConstBooleanStr; - Jump(&exit); - } - Bind(&objNotFalse); - { - Label objIsNull(env); - Label objNotNull(env); - Branch(Word64Equal(obj, GetWord64Constant(JSTaggedValue::VALUE_NULL)), &objIsNull, &objNotNull); - Bind(&objIsNull); - { - resultRep = Load( - MachineType::TAGGED_POINTER, gConstOffset, - GetGlobalConstantString(ConstantIndex::OBJECT_STRING_INDEX)); - Jump(&exit); - } - Bind(&objNotNull); - { - Label objIsUndefined(env); - Label objNotUndefined(env); - Branch(Word64Equal(obj, GetWord64Constant(JSTaggedValue::VALUE_UNDEFINED)), &objIsUndefined, - &objNotUndefined); - Bind(&objIsUndefined); - { - resultRep = Load(MachineType::TAGGED_POINTER, gConstOffset, - GetGlobalConstantString(ConstantIndex::UNDEFINED_STRING_INDEX)); - Jump(&exit); - } - Bind(&objNotUndefined); - Jump(&defaultLabel); - } - } - } - Bind(&defaultLabel); - { - Label objIsHeapObject(env); - Label objNotHeapObject(env); - Branch(TaggedIsHeapObject(obj), &objIsHeapObject, &objNotHeapObject); - Bind(&objIsHeapObject); - { - Label objIsString(env); - Label objNotString(env); - Branch(IsString(obj), &objIsString, &objNotString); - Bind(&objIsString); - { - resultRep = Load( - MachineType::TAGGED_POINTER, gConstOffset, - GetGlobalConstantString(ConstantIndex::STRING_STRING_INDEX)); - Jump(&exit); - } - Bind(&objNotString); - { - Label objIsSymbol(env); - Label objNotSymbol(env); - Branch(IsSymbol(obj), &objIsSymbol, &objNotSymbol); - Bind(&objIsSymbol); - { - resultRep = Load(MachineType::TAGGED_POINTER, gConstOffset, - GetGlobalConstantString(ConstantIndex::SYMBOL_STRING_INDEX)); - Jump(&exit); - } - Bind(&objNotSymbol); - { - Label objIsCallable(env); - Label objNotCallable(env); - Branch(IsCallable(obj), &objIsCallable, &objNotCallable); - Bind(&objIsCallable); - { - resultRep = Load( - MachineType::TAGGED_POINTER, gConstOffset, - GetGlobalConstantString(ConstantIndex::FUNCTION_STRING_INDEX)); - Jump(&exit); - } - Bind(&objNotCallable); - { - resultRep = Load( - MachineType::TAGGED_POINTER, gConstOffset, - GetGlobalConstantString(ConstantIndex::OBJECT_STRING_INDEX)); - Jump(&exit); - } - } - } - } - Bind(&objNotHeapObject); - { - Label objIsNum(env); - Label objNotNum(env); - Branch(TaggedIsNumber(obj), &objIsNum, &objNotNum); - Bind(&objIsNum); - { - resultRep = Load( - MachineType::TAGGED_POINTER, gConstOffset, - GetGlobalConstantString(ConstantIndex::NUMBER_STRING_INDEX)); - Jump(&exit); - } - Bind(&objNotNum); - Jump(&exit); - } - } - Bind(&exit); - Return(*resultRep); + GateRef receiver = TaggedArgument(1); + GateRef key = TaggedArgument(2); // 2 : 3rd para + GateRef value = TaggedArgument(3); // 3 : 4th para + Return(SetPropertyByName(glue, receiver, key, value)); +} + +void SetPropertyByNameWithOwnStub::GenerateCircuit(const CompilationConfig *cfg) +{ + Stub::GenerateCircuit(cfg); + GateRef glue = PtrArgument(0); + GateRef receiver = TaggedArgument(1); + GateRef key = TaggedArgument(2); // 2 : 3rd para + GateRef value = TaggedArgument(3); // 3 : 4th para + Return(SetPropertyByNameWithOwn(glue, receiver, key, value)); } -void FunctionCallInternalStub::GenerateCircuit() +void FunctionCallInternalStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef glue = PtrArgument(0); GateRef func = PtrArgument(1, TypeCode::TAGGED_POINTER); @@ -1487,8 +863,9 @@ void FunctionCallInternalStub::GenerateCircuit() })); } -void GetPropertyByValueStub::GenerateCircuit() +void GetPropertyByValueStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef glue = PtrArgument(0); GateRef receiver = TaggedArgument(1); @@ -1559,8 +936,9 @@ void GetPropertyByValueStub::GenerateCircuit() Return(GetHoleConstant()); } -void SetPropertyByValueStub::GenerateCircuit() +void SetPropertyByValueStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef glue = PtrArgument(0); GateRef receiver = TaggedArgument(1); @@ -1632,90 +1010,9 @@ void SetPropertyByValueStub::GenerateCircuit() Return(GetHoleConstant(MachineType::UINT64)); } -void FastEqualStub::GenerateCircuit() -{ - auto env = GetEnvironment(); - GateRef x = TaggedArgument(0); - GateRef y = TaggedArgument(1); - Label xIsEqualy(env); - Label xIsNotEqualy(env); - Branch(Word64Equal(x, y), &xIsEqualy, &xIsNotEqualy); - Bind(&xIsEqualy); - { - Label xIsDouble(env); - Label xNotDoubleOrxNotNan(env); - Branch(TaggedIsDouble(x), &xIsDouble, &xNotDoubleOrxNotNan); - Bind(&xIsDouble); - { - GateRef doubleX = TaggedCastToDouble(x); - Label xIsNan(env); - Branch(DoubleIsNAN(doubleX), &xIsNan, &xNotDoubleOrxNotNan); - Bind(&xIsNan); - Return(TaggedFalse()); - } - Bind(&xNotDoubleOrxNotNan); - Return(TaggedTrue()); - } - Bind(&xIsNotEqualy); - { - Label xIsNumber(env); - Label xNotNumberAndxNotIntAndyNotInt(env); - Branch(TaggedIsNumber(x), &xIsNumber, &xNotNumberAndxNotIntAndyNotInt); - Bind(&xIsNumber); - { - Label xIsInt(env); - Branch(TaggedIsInt(x), &xIsInt, &xNotNumberAndxNotIntAndyNotInt); - Bind(&xIsInt); - { - Label yIsInt(env); - Branch(TaggedIsInt(y), &yIsInt, &xNotNumberAndxNotIntAndyNotInt); - Bind(&yIsInt); - Return(TaggedFalse()); - } - } - Bind(&xNotNumberAndxNotIntAndyNotInt); - { - Label yIsUndefinedOrNull(env); - Label xyNotUndefinedAndNull(env); - Branch(TaggedIsUndefinedOrNull(y), &yIsUndefinedOrNull, &xyNotUndefinedAndNull); - Bind(&yIsUndefinedOrNull); - { - Label xIsHeapObject(env); - Label xNotHeapObject(env); - Branch(TaggedIsHeapObject(x), &xIsHeapObject, &xNotHeapObject); - Bind(&xIsHeapObject); - Return(TaggedFalse()); - Bind(&xNotHeapObject); - { - Label xIsUndefinedOrNull(env); - Branch(TaggedIsUndefinedOrNull(x), &xIsUndefinedOrNull, &xyNotUndefinedAndNull); - Bind(&xIsUndefinedOrNull); - Return(TaggedTrue()); - } - } - Bind(&xyNotUndefinedAndNull); - { - Label xIsBoolean(env); - Label xNotBooleanAndyNotSpecial(env); - Branch(TaggedIsBoolean(x), &xIsBoolean, &xNotBooleanAndyNotSpecial); - Bind(&xIsBoolean); - { - Label yIsSpecial(env); - Branch(TaggedIsSpecial(y), &yIsSpecial, &xNotBooleanAndyNotSpecial); - Bind(&yIsSpecial); - Return(TaggedFalse()); - } - Bind(&xNotBooleanAndyNotSpecial); - { - Return(GetHoleConstant(MachineType::UINT64)); - } - } - } - } -} - -void TryLoadICByNameStub::GenerateCircuit() +void TryLoadICByNameStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef glue = PtrArgument(0); GateRef receiver = TaggedArgument(1); @@ -1753,8 +1050,9 @@ void TryLoadICByNameStub::GenerateCircuit() } } -void TryLoadICByValueStub::GenerateCircuit() +void TryLoadICByValueStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef glue = PtrArgument(0); GateRef receiver = TaggedArgument(1); @@ -1792,8 +1090,9 @@ void TryLoadICByValueStub::GenerateCircuit() Return(GetHoleConstant()); } -void TryStoreICByNameStub::GenerateCircuit() +void TryStoreICByNameStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef glue = PtrArgument(0); GateRef receiver = TaggedArgument(1); @@ -1829,8 +1128,9 @@ void TryStoreICByNameStub::GenerateCircuit() Return(GetHoleConstant(MachineType::UINT64)); } -void TryStoreICByValueStub::GenerateCircuit() +void TryStoreICByValueStub::GenerateCircuit(const CompilationConfig *cfg) { + Stub::GenerateCircuit(cfg); auto env = GetEnvironment(); GateRef glue = PtrArgument(0); GateRef receiver = TaggedArgument(1); @@ -1868,5 +1168,4 @@ void TryStoreICByValueStub::GenerateCircuit() Bind(&receiverNotHeapObject); Return(GetHoleConstant(MachineType::UINT64)); } -#endif } // namespace kungfu diff --git a/ecmascript/compiler/fast_stub.h b/ecmascript/compiler/fast_stub.h index 1a204bc4de..1064eb769d 100644 --- a/ecmascript/compiler/fast_stub.h +++ b/ecmascript/compiler/fast_stub.h @@ -19,388 +19,259 @@ #include "ecmascript/compiler/fast_stub_define.h" #include "ecmascript/compiler/stub-inl.h" -namespace kungfu { -#ifdef ECMASCRIPT_ENABLE_SPECIFIC_STUBS +namespace panda::ecmascript::kungfu { class FastAddStub : public Stub { public: // 2 : 2 means argument counts - explicit FastAddStub(Circuit *circuit, const char* triple) : Stub("FastAdd", 2, circuit, triple) + explicit FastAddStub(Circuit *circuit) : Stub("FastAdd", 2, circuit) { circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_FRAME); } ~FastAddStub() = default; NO_MOVE_SEMANTIC(FastAddStub); NO_COPY_SEMANTIC(FastAddStub); - void GenerateCircuit() override; -}; - -class FastMulGCTestStub : public Stub { -public: - // 3 : 3 means argument counts - explicit FastMulGCTestStub(Circuit *circuit, const char* triple) : Stub("FastMulGCTest", 3, circuit, triple) {} - ~FastMulGCTestStub() = default; - NO_MOVE_SEMANTIC(FastMulGCTestStub); - NO_COPY_SEMANTIC(FastMulGCTestStub); - void GenerateCircuit() override; -}; -class FastSubStub : public Stub { -public: - // 2 : 2 means argument counts - explicit FastSubStub(Circuit *circuit, const char* triple) : Stub("FastSub", 2, circuit, triple) {} - ~FastSubStub() = default; - NO_MOVE_SEMANTIC(FastSubStub); - NO_COPY_SEMANTIC(FastSubStub); - void GenerateCircuit() override; -}; - -class FastMulStub : public Stub { -public: - // 2 : 2 means argument counts - explicit FastMulStub(Circuit *circuit, const char* triple) : Stub("FastMul", 2, circuit, triple) {} - ~FastMulStub() = default; - NO_MOVE_SEMANTIC(FastMulStub); - NO_COPY_SEMANTIC(FastMulStub); - void GenerateCircuit() override; -}; - -class FastDivStub : public Stub { -public: - // 2 : 2 means argument counts - explicit FastDivStub(Circuit *circuit, const char* triple) : Stub("FastDiv", 2, circuit, triple) {} - ~FastDivStub() = default; - NO_MOVE_SEMANTIC(FastDivStub); - NO_COPY_SEMANTIC(FastDivStub); - void GenerateCircuit() override; -}; - -class FastModStub : public Stub { -public: - // 3 means argument counts - explicit FastModStub(Circuit *circuit, const char* triple) : Stub("FastMod", 3, circuit, triple) - { - circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); - } - ~FastModStub() = default; - NO_MOVE_SEMANTIC(FastModStub); - NO_COPY_SEMANTIC(FastModStub); - void GenerateCircuit() override; -}; - -class FastTypeOfStub : public Stub { -public: - // 2 means argument counts - explicit FastTypeOfStub(Circuit *circuit, const char* triple) : Stub("FastTypeOf", 2, circuit, triple) {} - ~FastTypeOfStub() = default; - NO_MOVE_SEMANTIC(FastTypeOfStub); - NO_COPY_SEMANTIC(FastTypeOfStub); - void GenerateCircuit() override; -}; - -class FastEqualStub : public Stub { -public: - // 2 means argument counts - explicit FastEqualStub(Circuit *circuit, const char* triple) : Stub("FastEqual", 2, circuit, triple) {} - ~FastEqualStub() = default; - NO_MOVE_SEMANTIC(FastEqualStub); - NO_COPY_SEMANTIC(FastEqualStub); - void GenerateCircuit() override; -}; - -class GetPropertyByIndexStub : public Stub { -public: - // 3 : 3 means argument counts - explicit GetPropertyByIndexStub(Circuit *circuit, const char* triple) - : Stub("GetPropertyByIndex", 3, circuit, triple) - { - circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); - } - ~GetPropertyByIndexStub() = default; - NO_MOVE_SEMANTIC(GetPropertyByIndexStub); - NO_COPY_SEMANTIC(GetPropertyByIndexStub); - void GenerateCircuit() override; -}; - -class SetPropertyByIndexStub : public Stub { -public: - // 4 : 4 means argument counts - explicit SetPropertyByIndexStub(Circuit *circuit, const char* triple) - : Stub("SetPropertyByIndex", 4, circuit, triple) - { - circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); - } - ~SetPropertyByIndexStub() = default; - NO_MOVE_SEMANTIC(SetPropertyByIndexStub); - NO_COPY_SEMANTIC(SetPropertyByIndexStub); - void GenerateCircuit() override; -}; - -class GetPropertyByNameStub : public Stub { -public: - // 3 : 3 means argument counts - explicit GetPropertyByNameStub(Circuit *circuit, const char* triple) - : Stub("GetPropertyByName", 3, circuit, triple) - { - circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); - } - ~GetPropertyByNameStub() = default; - NO_MOVE_SEMANTIC(GetPropertyByNameStub); - NO_COPY_SEMANTIC(GetPropertyByNameStub); - void GenerateCircuit() override; -}; -#else -class FastAddStub : public Stub { -public: - // 2 : 2 means argument counts - explicit FastAddStub(Circuit *circuit, const char* triple) : Stub("FastAdd", 2, circuit, triple) - { - circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_FRAME); - } - ~FastAddStub() = default; - NO_MOVE_SEMANTIC(FastAddStub); - NO_COPY_SEMANTIC(FastAddStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class FastSubStub : public Stub { public: // 2 : 2 means argument counts - explicit FastSubStub(Circuit *circuit, const char* triple) : Stub("FastSub", 2, circuit, triple) {} + explicit FastSubStub(Circuit *circuit) : Stub("FastSub", 2, circuit) {} ~FastSubStub() = default; NO_MOVE_SEMANTIC(FastSubStub); NO_COPY_SEMANTIC(FastSubStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class FastMulStub : public Stub { public: // 2 : 2 means argument counts - explicit FastMulStub(Circuit *circuit, const char* triple) : Stub("FastMul", 2, circuit, triple) {} + explicit FastMulStub(Circuit *circuit) : Stub("FastMul", 2, circuit) {} ~FastMulStub() = default; NO_MOVE_SEMANTIC(FastMulStub); NO_COPY_SEMANTIC(FastMulStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class FastMulGCTestStub : public Stub { public: // 3 : 3 means argument counts - explicit FastMulGCTestStub(Circuit *circuit, const char* triple) : Stub("FastMulGCTest", 3, circuit, triple) {} + explicit FastMulGCTestStub(Circuit *circuit) : Stub("FastMulGCTest", 3, circuit) {} ~FastMulGCTestStub() = default; NO_MOVE_SEMANTIC(FastMulGCTestStub); NO_COPY_SEMANTIC(FastMulGCTestStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class FastDivStub : public Stub { public: // 2 : 2 means argument counts - explicit FastDivStub(Circuit *circuit, const char* triple) : Stub("FastDiv", 2, circuit, triple) {} + explicit FastDivStub(Circuit *circuit) : Stub("FastDiv", 2, circuit) {} ~FastDivStub() = default; NO_MOVE_SEMANTIC(FastDivStub); NO_COPY_SEMANTIC(FastDivStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class FindOwnElement2Stub : public Stub { public: // 6 : 6 means argument counts - explicit FindOwnElement2Stub(Circuit *circuit, const char* triple) : Stub("FindOwnElement2", 6, circuit, triple) {} + explicit FindOwnElement2Stub(Circuit *circuit) : Stub("FindOwnElement2", 6, circuit) {} ~FindOwnElement2Stub() = default; NO_MOVE_SEMANTIC(FindOwnElement2Stub); NO_COPY_SEMANTIC(FindOwnElement2Stub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class GetPropertyByIndexStub : public Stub { public: // 3 : 3 means argument counts - explicit GetPropertyByIndexStub(Circuit *circuit, const char* triple) - : Stub("GetPropertyByIndex", 3, circuit, triple) + explicit GetPropertyByIndexStub(Circuit *circuit) + : Stub("GetPropertyByIndex", 3, circuit) { circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); } ~GetPropertyByIndexStub() = default; NO_MOVE_SEMANTIC(GetPropertyByIndexStub); NO_COPY_SEMANTIC(GetPropertyByIndexStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class SetPropertyByIndexStub : public Stub { public: // 4 : 4 means argument counts - explicit SetPropertyByIndexStub(Circuit *circuit, const char* triple) - : Stub("SetPropertyByIndex", 4, circuit, triple) + explicit SetPropertyByIndexStub(Circuit *circuit) + : Stub("SetPropertyByIndex", 4, circuit) { circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); } ~SetPropertyByIndexStub() = default; NO_MOVE_SEMANTIC(SetPropertyByIndexStub); NO_COPY_SEMANTIC(SetPropertyByIndexStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class GetPropertyByNameStub : public Stub { public: // 3 : 3 means argument counts - explicit GetPropertyByNameStub(Circuit *circuit, const char* triple) - : Stub("GetPropertyByName", 3, circuit, triple) + explicit GetPropertyByNameStub(Circuit *circuit) + : Stub("GetPropertyByName", 3, circuit) { circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); } ~GetPropertyByNameStub() = default; NO_MOVE_SEMANTIC(GetPropertyByNameStub); NO_COPY_SEMANTIC(GetPropertyByNameStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class SetPropertyByNameStub : public Stub { public: // 4 : 4 means argument counts - explicit SetPropertyByNameStub(Circuit *circuit, const char* triple) - : Stub("SetPropertyByName", 4, circuit, triple) + explicit SetPropertyByNameStub(Circuit *circuit) + : Stub("SetPropertyByName", 4, circuit) { circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); } ~SetPropertyByNameStub() = default; NO_MOVE_SEMANTIC(SetPropertyByNameStub); NO_COPY_SEMANTIC(SetPropertyByNameStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class SetPropertyByNameWithOwnStub : public Stub { public: // 4 : 4 means argument counts - explicit SetPropertyByNameWithOwnStub(Circuit *circuit, const char* triple) - : Stub("SetPropertyByNameWithOwn", 4, circuit, triple) + explicit SetPropertyByNameWithOwnStub(Circuit *circuit) + : Stub("SetPropertyByNameWithOwn", 4, circuit) { circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); } ~SetPropertyByNameWithOwnStub() = default; NO_MOVE_SEMANTIC(SetPropertyByNameWithOwnStub); NO_COPY_SEMANTIC(SetPropertyByNameWithOwnStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class FastModStub : public Stub { public: // 3 means argument counts - explicit FastModStub(Circuit *circuit, const char* triple) : Stub("FastMod", 3, circuit, triple) + explicit FastModStub(Circuit *circuit) : Stub("FastMod", 3, circuit) { circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); } ~FastModStub() = default; NO_MOVE_SEMANTIC(FastModStub); NO_COPY_SEMANTIC(FastModStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class FastTypeOfStub : public Stub { public: // 2 means argument counts - explicit FastTypeOfStub(Circuit *circuit, const char* triple) : Stub("FastTypeOf", 2, circuit, triple) {} + explicit FastTypeOfStub(Circuit *circuit) : Stub("FastTypeOf", 2, circuit) {} ~FastTypeOfStub() = default; NO_MOVE_SEMANTIC(FastTypeOfStub); NO_COPY_SEMANTIC(FastTypeOfStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class FunctionCallInternalStub : public Stub { public: // 5 : 5 means argument counts - explicit FunctionCallInternalStub(Circuit *circuit, const char* triple) - : Stub("FunctionCallInternal", 5, circuit, triple) {} + explicit FunctionCallInternalStub(Circuit *circuit) + : Stub("FunctionCallInternal", 5, circuit) {} ~FunctionCallInternalStub() = default; NO_MOVE_SEMANTIC(FunctionCallInternalStub); NO_COPY_SEMANTIC(FunctionCallInternalStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class GetPropertyByValueStub : public Stub { public: // 3 : 3 means argument counts - explicit GetPropertyByValueStub(Circuit *circuit, const char* triple) - : Stub("FastGetPropertyByValue", 3, circuit, triple) + explicit GetPropertyByValueStub(Circuit *circuit) + : Stub("FastGetPropertyByValue", 3, circuit) { circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); } ~GetPropertyByValueStub() = default; NO_MOVE_SEMANTIC(GetPropertyByValueStub); NO_COPY_SEMANTIC(GetPropertyByValueStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class SetPropertyByValueStub : public Stub { public: // 4 : 4 means argument counts - explicit SetPropertyByValueStub(Circuit *circuit, const char* triple) - : Stub("FastSetPropertyByValue", 4, circuit, triple) + explicit SetPropertyByValueStub(Circuit *circuit) + : Stub("FastSetPropertyByValue", 4, circuit) { circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); } ~SetPropertyByValueStub() = default; NO_MOVE_SEMANTIC(SetPropertyByValueStub); NO_COPY_SEMANTIC(SetPropertyByValueStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class FastEqualStub : public Stub { public: // 2 means argument counts - explicit FastEqualStub(Circuit *circuit, const char* triple) : Stub("FastEqual", 2, circuit, triple) {} + explicit FastEqualStub(Circuit *circuit) : Stub("FastEqual", 2, circuit) {} ~FastEqualStub() = default; NO_MOVE_SEMANTIC(FastEqualStub); NO_COPY_SEMANTIC(FastEqualStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class TryLoadICByNameStub : public Stub { public: // 4 : 4 means argument counts - explicit TryLoadICByNameStub(Circuit *circuit, const char* triple) : Stub("TryLoadICByName", 4, circuit, triple) {} + explicit TryLoadICByNameStub(Circuit *circuit) : Stub("TryLoadICByName", 4, circuit) {} ~TryLoadICByNameStub() = default; NO_MOVE_SEMANTIC(TryLoadICByNameStub); NO_COPY_SEMANTIC(TryLoadICByNameStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class TryLoadICByValueStub : public Stub { public: // 5 : 5 means argument counts - explicit TryLoadICByValueStub(Circuit *circuit, const char* triple) - : Stub("TryLoadICByValue", 5, circuit, triple) {} + explicit TryLoadICByValueStub(Circuit *circuit) + : Stub("TryLoadICByValue", 5, circuit) {} ~TryLoadICByValueStub() = default; NO_MOVE_SEMANTIC(TryLoadICByValueStub); NO_COPY_SEMANTIC(TryLoadICByValueStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class TryStoreICByNameStub : public Stub { public: // 5 : 5 means argument counts - explicit TryStoreICByNameStub(Circuit *circuit, const char* triple) : Stub("TryStoreICByName", 5, circuit, triple) + explicit TryStoreICByNameStub(Circuit *circuit) : Stub("TryStoreICByName", 5, circuit) { circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); } ~TryStoreICByNameStub() = default; NO_MOVE_SEMANTIC(TryStoreICByNameStub); NO_COPY_SEMANTIC(TryStoreICByNameStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; class TryStoreICByValueStub : public Stub { public: // 6 : 6 means argument counts - explicit TryStoreICByValueStub(Circuit *circuit, const char* triple) - : Stub("TryStoreICByValue", 6, circuit, triple) + explicit TryStoreICByValueStub(Circuit *circuit) + : Stub("TryStoreICByValue", 6, circuit) { circuit->SetFrameType(panda::ecmascript::FrameType::OPTIMIZED_ENTRY_FRAME); } ~TryStoreICByValueStub() = default; NO_MOVE_SEMANTIC(TryStoreICByValueStub); NO_COPY_SEMANTIC(TryStoreICByValueStub); - void GenerateCircuit() override; + void GenerateCircuit(const CompilationConfig *cfg) override; }; -#endif -} // namespace kungfu +} // namespace panda::ecmascript::kungfu #endif // ECMASCRIPT_COMPILER_FASTPATH_STUB_H diff --git a/ecmascript/compiler/fast_stub_define.h b/ecmascript/compiler/fast_stub_define.h index 75c43d39fa..3a236c3d80 100644 --- a/ecmascript/compiler/fast_stub_define.h +++ b/ecmascript/compiler/fast_stub_define.h @@ -16,7 +16,7 @@ #ifndef ECMASCRIPT_COMPILER_FASTSTUB_DEFINE_H #define ECMASCRIPT_COMPILER_FASTSTUB_DEFINE_H -namespace kungfu { +namespace panda::ecmascript::kungfu { // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define EXTERNAL_RUNTIMESTUB_LIST(V) \ V(AddElementInternal, 5) \ @@ -46,7 +46,6 @@ namespace kungfu { V(DebugPrint, 1) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#ifdef ECMASCRIPT_ENABLE_SPECIFIC_STUBS #define FAST_RUNTIME_STUB_LIST(V) \ V(FastAdd, 2) \ V(FastSub, 2) \ @@ -80,27 +79,12 @@ namespace kungfu { V(TryLoadICByValue, 5) \ V(TryStoreICByName, 5) \ V(TryStoreICByValue, 6) -#else -#define FAST_RUNTIME_STUB_LIST(V) \ - V(FastAdd, 2) \ - V(FastSub, 2) \ - V(FastMul, 2) \ - V(FastDiv, 2) \ - V(FastMod, 3) \ - V(FastEqual, 2) \ - V(FastTypeOf, 2) \ - V(FastMulGCTest, 3) -#endif -#ifndef ECMASCRIPT_ENABLE_SPECIFIC_STUBS // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define TEST_FUNC_LIST(V) \ V(PhiGateTest, 1) \ V(LoopTest, 1) \ V(LoopTest1, 1) -#else -#define TEST_FUNC_LIST(V) -#endif #define CALL_STUB_LIST(V) \ FAST_RUNTIME_STUB_LIST(V) \ @@ -120,6 +104,6 @@ enum CallStubId { }; // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define FAST_STUB_ID(name) kungfu::CallStubId::NAME_##name -} // namespace kungfu +#define FAST_STUB_ID(name) panda::ecmascript::kungfu::CallStubId::NAME_##name +} // namespace panda::ecmascript::kungfu #endif // ECMASCRIPT_COMPILER_FASTSTUB_DEFINE_H diff --git a/ecmascript/compiler/gate.cpp b/ecmascript/compiler/gate.cpp index eea2a964e3..ecd2aff5fc 100644 --- a/ecmascript/compiler/gate.cpp +++ b/ecmascript/compiler/gate.cpp @@ -14,9 +14,8 @@ */ #include "ecmascript/compiler/gate.h" -#include "triple.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { constexpr size_t ONE_DEPEND = 1; constexpr size_t MANY_DEPEND = 2; constexpr size_t NO_DEPEND = 0; @@ -882,15 +881,6 @@ ValueCode PtrValueCode() #endif } -ValueCode ArchRelatePtrValueCode(const char *triple) -{ - if (triple == TripleConst::GetLLVMArm32Triple()) { - return ValueCode::INT32; - } else { - return ValueCode::INT64; - } -} - size_t GetValueBits(ValueCode valueCode) { switch (valueCode) { @@ -1359,4 +1349,4 @@ bool OpCode::IsNop() const { return (op_ == OpCode::NOP); } -} // namespace kungfu \ No newline at end of file +} // namespace panda::ecmascript::kungfu \ No newline at end of file diff --git a/ecmascript/compiler/gate.h b/ecmascript/compiler/gate.h index 6c9620d03d..3f216682e8 100644 --- a/ecmascript/compiler/gate.h +++ b/ecmascript/compiler/gate.h @@ -29,7 +29,7 @@ #include "libpandabase/macros.h" #include "ecmascript/compiler/type.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { using GateRef = int32_t; // for external users using GateId = uint32_t; using GateOp = uint8_t; @@ -39,6 +39,7 @@ using GateRef = int32_t; using BitField = uint64_t; using OutIdx = uint32_t; class Gate; +struct Properties; enum ValueCode { NOVALUE, @@ -54,8 +55,6 @@ enum ValueCode { std::string ValueCodeToStr(ValueCode valueCode); -using Properties = struct Properties; - class OpCode { public: enum Op : GateOp { @@ -287,7 +286,6 @@ enum MarkCode : GateMark { ValueCode JSValueCode(); ValueCode PtrValueCode(); -ValueCode ArchRelatePtrValueCode(const char *triple); size_t GetValueBits(ValueCode valueCode); class Out { @@ -402,6 +400,6 @@ private: // in(2) // ... }; -} // namespace kungfu +} // namespace panda::ecmascript::kungfu #endif // ECMASCRIPT_COMPILER_GATE_H diff --git a/ecmascript/compiler/js_thread_offset_table.cpp b/ecmascript/compiler/js_thread_offset_table.cpp deleted file mode 100644 index 416d32b31f..0000000000 --- a/ecmascript/compiler/js_thread_offset_table.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ecmascript/compiler/js_thread_offset_table.h" -#include "ecmascript/compiler/triple.h" - -namespace kungfu { -using namespace panda::ecmascript; -OffsetTable *OffsetTable::instance_ = nullptr; -OffsetTable::OffsetTable(const char* triple) -{ - if (triple == TripleConst::GetLLVMArm32Triple()) { - offsetTable_ = { - GLUE_EXCEPTION_OFFSET_32, GLUE_GLOBAL_CONSTANTS_OFFSET_32, GLUE_PROPERTIES_CACHE_OFFSET_32, - GLUE_GLOBAL_STORAGE_OFFSET_32, GLUE_CURRENT_FRAME_OFFSET_32, GLUE_LAST_IFRAME_OFFSET_32, - GLUE_RUNTIME_FUNCTIONS_OFFSET_32, GLUE_FASTSTUB_ENTRIES_OFFSET_32 - }; - } else if (triple == TripleConst::GetLLVMArm64Triple() || triple == TripleConst::GetLLVMAmd64Triple()) { - offsetTable_ = { - GLUE_EXCEPTION_OFFSET_64, GLUE_GLOBAL_CONSTANTS_OFFSET_64, GLUE_PROPERTIES_CACHE_OFFSET_64, - GLUE_GLOBAL_STORAGE_OFFSET_64, GLUE_CURRENT_FRAME_OFFSET_64, GLUE_LAST_IFRAME_OFFSET_64, - GLUE_RUNTIME_FUNCTIONS_OFFSET_64, GLUE_FASTSTUB_ENTRIES_OFFSET_64 - }; - } else { - UNREACHABLE(); - } -} -// static -void OffsetTable::CreateInstance(const char* triple) -{ - instance_ = new OffsetTable(triple); -} -// static -void OffsetTable::Destroy() -{ - if (instance_) { - delete instance_; - instance_ = nullptr; - } -} -} // namespace kungfu diff --git a/ecmascript/compiler/js_thread_offset_table.h b/ecmascript/compiler/js_thread_offset_table.h deleted file mode 100644 index 13f425dad7..0000000000 --- a/ecmascript/compiler/js_thread_offset_table.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ECMASCRIPT_COMPILER_JS_THREAD_OFFSET_TABLE_H -#define ECMASCRIPT_COMPILER_JS_THREAD_OFFSET_TABLE_H - -#include -#include "ecmascript/js_thread.h" - -// this class only use in host compiling -namespace kungfu { -using JSThread = panda::ecmascript::JSThread; -class OffsetTable { -public: - static void CreateInstance(const char* triple); - static void Destroy(); - static OffsetTable *GetInstance() - { - ASSERT(instance_); - return instance_; - } - - static uint32_t GetOffset(JSThread::GlueID id) - { - ASSERT(instance_); - return instance_->offsetTable_[static_cast(id)]; - } - -private: - explicit OffsetTable(const char* triple); - ~OffsetTable() = default; - - static OffsetTable *instance_; - std::array(JSThread::GlueID::NUMBER_OF_GLUE)> offsetTable_ {}; - - NO_COPY_SEMANTIC(OffsetTable); - NO_MOVE_SEMANTIC(OffsetTable); -}; -} // namespace kungfu -#endif // ECMASCRIPT_COMPILER_JS_THREAD_OFFSET_TABLE_H diff --git a/ecmascript/compiler/llvm_codegen.cpp b/ecmascript/compiler/llvm_codegen.cpp index 22f7e8eff3..8c9ebe7aa5 100644 --- a/ecmascript/compiler/llvm_codegen.cpp +++ b/ecmascript/compiler/llvm_codegen.cpp @@ -17,7 +17,7 @@ #include #include #include "ecmascript/compiler/compiler_macros.h" -#include "ecmascript/compiler/triple.h" +#include "ecmascript/compiler/stub-inl.h" #include "ecmascript/ecma_macros.h" #include "ecmascript/object_factory.h" #include "llvm-c/Analysis.h" @@ -53,28 +53,12 @@ #include "stub_descriptor.h" using namespace panda::ecmascript; -namespace kungfu { -void LLVMCodeGeneratorImpl::GenerateCodeForStub(Circuit *circuit, const ControlFlowGraph &graph, int index) +namespace panda::ecmascript::kungfu { +void LLVMCodeGeneratorImpl::GenerateCodeForStub(Circuit *circuit, const ControlFlowGraph &graph, int index, + const CompilationConfig *cfg) { auto function = module_->GetStubFunction(index); - - LLVMIRBuilder builder(&graph, circuit, module_, function, TripleConst::GetLLVMAmd64Triple()); - builder.Build(); -} - -void LLVMAarch64CodeGeneratorImpl::GenerateCodeForStub(Circuit *circuit, const ControlFlowGraph &graph, int index) -{ - auto function = module_->GetStubFunction(index); - - LLVMIRBuilder builder(&graph, circuit, module_, function, TripleConst::GetLLVMArm64Triple()); - builder.Build(); -} - -void LLVMArm32CodeGeneratorImpl::GenerateCodeForStub(Circuit *circuit, const ControlFlowGraph &graph, int index) -{ - auto function = module_->GetStubFunction(index); - - LLVMIRBuilder builder(&graph, circuit, module_, function, TripleConst::GetLLVMArm32Triple()); + LLVMIRBuilder builder(&graph, circuit, module_, function, cfg); builder.Build(); } @@ -184,8 +168,8 @@ void LLVMAssembler::BuildAndRunPasses() const COMPILER_LOG(DEBUG) << "BuildAndRunPasses + "; } -LLVMAssembler::LLVMAssembler(LLVMModuleRef module, const char* triple) - : module_(module), triple_(triple) +LLVMAssembler::LLVMAssembler(LLVMModuleRef module) + : module_(module) { Initialize(); } @@ -229,7 +213,8 @@ void LLVMAssembler::Run() void LLVMAssembler::Initialize() { - if (triple_ == TripleConst::GetLLVMAmd64Triple()) { + std::string triple(LLVMGetTarget(module_)); + if (triple.compare("x86_64-unknown-linux-gnu") == 0) { LLVMInitializeX86TargetInfo(); LLVMInitializeX86TargetMC(); LLVMInitializeX86Disassembler(); @@ -237,14 +222,14 @@ void LLVMAssembler::Initialize() LLVMInitializeX86AsmPrinter(); LLVMInitializeX86AsmParser(); LLVMInitializeX86Target(); - } else if (triple_ == TripleConst::GetLLVMArm64Triple()) { + } else if (triple.compare("aarch64-unknown-linux-gnu") == 0) { LLVMInitializeAArch64TargetInfo(); LLVMInitializeAArch64TargetMC(); LLVMInitializeAArch64Disassembler(); LLVMInitializeAArch64AsmPrinter(); LLVMInitializeAArch64AsmParser(); LLVMInitializeAArch64Target(); - } else if (triple_ == TripleConst::GetLLVMArm32Triple()) { + } else if (triple.compare("arm-unknown-linux-gnu") == 0) { LLVMInitializeARMTargetInfo(); LLVMInitializeARMTargetMC(); LLVMInitializeARMDisassembler(); @@ -274,7 +259,7 @@ static const char *SymbolLookupCallback([[maybe_unused]] void *disInfo, [[maybe_ void LLVMAssembler::Disassemble(std::map addr2name) const { #if ECMASCRIPT_ENABLE_COMPILER_LOG - LLVMDisasmContextRef dcr = LLVMCreateDisasm(triple_, nullptr, 0, nullptr, SymbolLookupCallback); + LLVMDisasmContextRef dcr = LLVMCreateDisasm(LLVMGetTarget(module_), nullptr, 0, nullptr, SymbolLookupCallback); std::cout << "========================================================================" << std::endl; for (auto it : codeInfo_.GetCodeInfo()) { uint8_t *byteSp; @@ -317,4 +302,4 @@ void LLVMAssembler::Disassemble(std::map addr2name) const LLVMDisasmDispose(dcr); #endif } -} // namespace kungfu +} // panda::ecmascript::kungfu diff --git a/ecmascript/compiler/llvm_codegen.h b/ecmascript/compiler/llvm_codegen.h index 9f49a3c56f..cf186f35da 100644 --- a/ecmascript/compiler/llvm_codegen.h +++ b/ecmascript/compiler/llvm_codegen.h @@ -40,7 +40,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/Support/Host.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { struct CodeInfo { using ByteBuffer = std::vector; using BufferList = std::list; @@ -147,7 +147,7 @@ private: class LLVMAssembler { public: - explicit LLVMAssembler(LLVMModuleRef module, const char* triple); + explicit LLVMAssembler(LLVMModuleRef module); virtual ~LLVMAssembler(); void Run(); const LLVMExecutionEngineRef &GetEngine() @@ -188,7 +188,7 @@ private: LLVMMCJITCompilerOptions options_ {}; LLVMModuleRef module_; LLVMExecutionEngineRef engine_ {nullptr}; - const char *triple_; + const CompilationConfig *compCfg_; char *error_ {nullptr}; struct CodeInfo codeInfo_ {}; }; @@ -197,27 +197,7 @@ class LLVMCodeGeneratorImpl : public CodeGeneratorImpl { public: explicit LLVMCodeGeneratorImpl(LLVMStubModule *module) : module_(module) {} ~LLVMCodeGeneratorImpl() = default; - void GenerateCodeForStub(Circuit *circuit, const ControlFlowGraph &graph, int index) override; - -private: - LLVMStubModule *module_; -}; - -class LLVMAarch64CodeGeneratorImpl : public CodeGeneratorImpl { -public: - explicit LLVMAarch64CodeGeneratorImpl(LLVMStubModule *module) : module_(module) {} - ~LLVMAarch64CodeGeneratorImpl() = default; - void GenerateCodeForStub(Circuit *circuit, const ControlFlowGraph &graph, int index) override; - -private: - LLVMStubModule *module_; -}; - -class LLVMArm32CodeGeneratorImpl : public CodeGeneratorImpl { -public: - explicit LLVMArm32CodeGeneratorImpl(LLVMStubModule *module) : module_(module) {} - ~LLVMArm32CodeGeneratorImpl() = default; - void GenerateCodeForStub(Circuit *circuit, const ControlFlowGraph &graph, int index) override; + void GenerateCodeForStub(Circuit *circuit, const ControlFlowGraph &graph, int index, const CompilationConfig *cfg) override; private: LLVMStubModule *module_; @@ -225,8 +205,8 @@ private: class LLVMModuleAssembler { public: - explicit LLVMModuleAssembler(LLVMStubModule *module, const char* triple) - : stubmodule_(module), assembler_(module->GetModule(), triple) {} + explicit LLVMModuleAssembler(LLVMStubModule *module) + : stubmodule_(module), assembler_(module->GetModule()) {} void AssembleModule(); void AssembleStubModule(panda::ecmascript::StubModule *module); int GetCodeSize() const @@ -245,5 +225,5 @@ private: LLVMStubModule *stubmodule_; LLVMAssembler assembler_; }; -} // namespace kungfu +} // namespace panda::ecmascript::kungfu #endif // ECMASCRIPT_COMPILER_LLVM_CODEGEN_H diff --git a/ecmascript/compiler/llvm_ir_builder.cpp b/ecmascript/compiler/llvm_ir_builder.cpp index a5b65f872d..93ee91b873 100644 --- a/ecmascript/compiler/llvm_ir_builder.cpp +++ b/ecmascript/compiler/llvm_ir_builder.cpp @@ -24,9 +24,7 @@ #include "ecmascript/compiler/compiler_macros.h" #include "ecmascript/compiler/fast_stub.h" #include "ecmascript/compiler/gate.h" -#include "ecmascript/compiler/js_thread_offset_table.h" #include "ecmascript/compiler/stub_descriptor.h" -#include "ecmascript/compiler/triple.h" #include "ecmascript/frames.h" #include "ecmascript/js_array.h" #include "ecmascript/js_thread.h" @@ -35,13 +33,11 @@ #include "securec.h" #include "utils/logger.h" -namespace kungfu { -std::unordered_map g_values = {}; - +namespace panda::ecmascript::kungfu { LLVMIRBuilder::LLVMIRBuilder(const std::vector> *schedule, const Circuit *circuit, - LLVMStubModule *module, LLVMValueRef function, const char *triple) - : schedule_(schedule), circuit_(circuit), module_(module->GetModule()), - function_(function), stubModule_(module), triple_(triple) + LLVMStubModule *module, LLVMValueRef function, const CompilationConfig *cfg) + : compCfg_(cfg), schedule_(schedule), circuit_(circuit), module_(module->GetModule()), + function_(function), stubModule_(module) { builder_ = LLVMCreateBuilder(); context_ = LLVMGetGlobalContext(); @@ -216,7 +212,7 @@ void LLVMIRBuilder::Build() End(); } -BasicBlock *LLVMIRBuilder::EnsurBasicBlock(int id) +BasicBlock *LLVMIRBuilder::EnsureBasicBlock(int id) { BasicBlock *bb = nullptr; if (bbIdMapBb_.count(id) == 0) { @@ -229,12 +225,12 @@ BasicBlock *LLVMIRBuilder::EnsurBasicBlock(int id) return bb; } -void LLVMIRBuilder::StartLLVMBuilder(BasicBlock *bb) const +void LLVMIRBuilder::StartBuilder(BasicBlock *bb) const { - EnsureLLVMBB(bb); + EnsureBasicBlock(bb); LLVMTFBuilderBasicBlockImpl *impl = bb->GetImpl(); if ((impl == nullptr) || (impl->llvm_bb_ == nullptr)) { - COMPILER_LOG(ERROR) << "StartLLVMBuilder failed "; + COMPILER_LOG(ERROR) << "StartBuilder failed "; return; } impl->started = true; @@ -253,11 +249,11 @@ void LLVMIRBuilder::ProcessPhiWorkList() COMPILER_LOG(ERROR) << " ProcessPhiWorkList error hav't start "; return; } - LLVMValueRef value = g_values[e.operand]; + LLVMValueRef value = gateToLLVMMaps_[e.operand]; if (LLVMTypeOf(value) != LLVMTypeOf(e.phi)) { COMPILER_LOG(ERROR) << " ProcessPhiWorkList LLVMTypeOf don't match error "; } - LLVMBasicBlockRef llvmBB = EnsureLLVMBB(pred); + LLVMBasicBlockRef llvmBB = EnsureBasicBlock(pred); LLVMAddIncoming(e.phi, &value, &llvmBB, 1); } impl->not_merged_phis.clear(); @@ -281,7 +277,7 @@ void LLVMIRBuilder::End() } } -LLVMTFBuilderBasicBlockImpl *LLVMIRBuilder::EnsureLLVMBBImpl(BasicBlock *bb) const +LLVMTFBuilderBasicBlockImpl *LLVMIRBuilder::EnsureBasicBlockImpl(BasicBlock *bb) const { if (bb->GetImpl()) { return bb->GetImpl(); @@ -309,15 +305,16 @@ void LLVMIRBuilder::PrologueHandle(LLVMModuleRef &module, LLVMBuilderRef &builde */ auto frameType = circuit_->GetFrameType(); LLVMAddTargetDependentFunctionAttr(function_, "frame-pointer", "all"); - LLVMAddTargetDependentFunctionAttr(function_, "target-features", "+vfp2"); - LLVMValueRef llvmFpAddr = LLVMCallingFp(module_, builder_, false); + if (compCfg_->IsArm32()) { + LLVMAddTargetDependentFunctionAttr(function_, "target-features", "+vfp2"); + } + LLVMValueRef llvmFpAddr = CallingFp(module_, builder_, false); int slotSize = 0; LLVMTypeRef llvmSlotType = nullptr; - if ((triple_ == TripleConst::GetLLVMAmd64Triple()) || - (triple_ == TripleConst::GetLLVMArm64Triple())) { + if (compCfg_->IsAmd64() || compCfg_->IsAArch64()) { slotSize = panda::ecmascript::FrameConst::AARCH64_SLOT_SIZE; // 64bit slot size llvmSlotType = LLVMInt64Type(); - } else if (triple_ == TripleConst::GetLLVMArm32Triple()) { + } else if (compCfg_->IsArm32()) { slotSize = panda::ecmascript::FrameConst::ARM32_SLOT_SIZE; // 32bit slot size llvmSlotType = LLVMInt32Type(); return; @@ -350,7 +347,7 @@ void LLVMIRBuilder::PrologueHandle(LLVMModuleRef &module, LLVMBuilderRef &builde LLVMValueRef glue = LLVMGetParam(function_, 0); LLVMTypeRef glue_type = LLVMTypeOf(glue); - LLVMValueRef rtoffset = LLVMConstInt(glue_type, OffsetTable::GetOffset(JSThread::GlueID::CURRENT_FRAME), 0); + LLVMValueRef rtoffset = LLVMConstInt(glue_type, compCfg_->GetGlueOffset(JSThread::GlueID::CURRENT_FRAME), 0); LLVMValueRef rtbaseoffset = LLVMBuildAdd(builder_, glue, rtoffset, ""); LLVMValueRef rtbaseAddr = LLVMBuildIntToPtr(builder_, rtbaseoffset, LLVMPointerType(llvmSlotType, 0), ""); LLVMValueRef threadFpValue = LLVMBuildLoad(builder_, rtbaseAddr, ""); @@ -362,7 +359,7 @@ void LLVMIRBuilder::PrologueHandle(LLVMModuleRef &module, LLVMBuilderRef &builde << "value type" << LLVMTypeOf(value); } -LLVMValueRef LLVMIRBuilder::LLVMCallingFp(LLVMModuleRef &module, LLVMBuilderRef &builder, bool isCaller) +LLVMValueRef LLVMIRBuilder::CallingFp(LLVMModuleRef &module, LLVMBuilderRef &builder, bool isCaller) { /* 0:calling 1:its caller */ std::vector args = {LLVMConstInt(LLVMInt32Type(), 0, isCaller)}; @@ -379,7 +376,7 @@ LLVMValueRef LLVMIRBuilder::LLVMCallingFp(LLVMModuleRef &module, LLVMBuilderRef return fAddrRet; } -LLVMValueRef LLVMIRBuilder::LLVMCallerSp(LLVMModuleRef &module, LLVMBuilderRef &builder, +LLVMValueRef LLVMIRBuilder::CallerSp(LLVMModuleRef &module, LLVMBuilderRef &builder, LLVMMetadataRef meta) { std::vector args = {LLVMMetadataAsValue(context_, meta)}; @@ -397,9 +394,9 @@ LLVMValueRef LLVMIRBuilder::LLVMCallerSp(LLVMModuleRef &module, LLVMBuilderRef & return fAddrRet; } -LLVMBasicBlockRef LLVMIRBuilder::EnsureLLVMBB(BasicBlock *bb) const +LLVMBasicBlockRef LLVMIRBuilder::EnsureBasicBlock(BasicBlock *bb) const { - LLVMTFBuilderBasicBlockImpl *impl = EnsureLLVMBBImpl(bb); + LLVMTFBuilderBasicBlockImpl *impl = EnsureBasicBlockImpl(bb); if (impl->llvm_bb_) { return impl->llvm_bb_; } @@ -436,7 +433,7 @@ LLVMTypeRef LLVMIRBuilder::GetMachineRepType(MachineRep rep) const dstType = LLVMInt64TypeInContext(context_); break; case MachineRep::K_PTR_1: - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (compCfg_->IsArm32()) { dstType = LLVMVectorType(LLVMPointerType(LLVMInt8Type(), 1), 2); // 2: packed vector type } else { dstType = LLVMPointerType(LLVMInt64TypeInContext(context_), 1); @@ -473,10 +470,10 @@ void LLVMIRBuilder::HandleCall(GateRef gate) void LLVMIRBuilder::SaveCallerSp() { - if (triple_ == TripleConst::GetLLVMArm64Triple()) { + if (compCfg_->IsAArch64()) { int slotSize = 8; LLVMTypeRef llvmSlotType = LLVMInt64Type(); - LLVMValueRef llvmFpAddr = LLVMCallingFp(module_, builder_, false); + LLVMValueRef llvmFpAddr = CallingFp(module_, builder_, false); LLVMValueRef frameAddr = LLVMBuildPtrToInt(builder_, llvmFpAddr, llvmSlotType, "cast_int_t"); LLVMValueRef frameSpSlotAddr = LLVMBuildSub(builder_, frameAddr, LLVMConstInt(llvmSlotType, 3 * slotSize, false), ""); // 3: type + threadsp + current sp @@ -484,7 +481,7 @@ void LLVMIRBuilder::SaveCallerSp() LLVMPointerType(llvmSlotType, 0), "frameType.Addr"); LLVMMetadataRef meta = LLVMMDStringInContext2(context_, "sp", 3); // 3 : 3 means len of "sp" LLVMMetadataRef metadataNode = LLVMMDNodeInContext2(context_, &meta, 1); - LLVMValueRef spValue = LLVMCallerSp(module_, builder_, metadataNode); + LLVMValueRef spValue = CallerSp(module_, builder_, metadataNode); LLVMBuildStore(builder_, spValue, addr); } } @@ -500,14 +497,14 @@ void LLVMIRBuilder::VisitCall(GateRef gate, const std::vector &inList) StubDescriptor *callee_descriptor = FastStubDescriptors::GetInstance().GetStubDescriptor(index); LLVMTypeRef rtfuncType = stubModule_->GetStubFunctionType(index); LLVMTypeRef rtfuncTypePtr = LLVMPointerType(rtfuncType, 0); - LLVMValueRef glue = g_values[inList[2]]; // 2 : 2 means skip two input gates (target glue) + LLVMValueRef glue = gateToLLVMMaps_[inList[2]]; // 2 : 2 means skip two input gates (target glue) LLVMTypeRef glue_type = LLVMTypeOf(glue); // runtime case if (callee_descriptor->GetStubKind() == StubDescriptor::CallStubKind::RUNTIME_STUB) { - rtoffset = LLVMConstInt(glue_type, OffsetTable::GetOffset(JSThread::GlueID::RUNTIME_FUNCTIONS) + + rtoffset = LLVMConstInt(glue_type, compCfg_->GetGlueOffset(JSThread::GlueID::RUNTIME_FUNCTIONS) + (index - FAST_STUB_MAXCOUNT) * sizeof(uintptr_t), 0); } else { - rtoffset = LLVMConstInt(glue_type, OffsetTable::GetOffset(JSThread::GlueID::FAST_STUB_ENTIRES) + + rtoffset = LLVMConstInt(glue_type, compCfg_->GetGlueOffset(JSThread::GlueID::FAST_STUB_ENTIRES) + index * sizeof(uintptr_t), 0); } LLVMValueRef rtbaseoffset = LLVMBuildAdd(builder_, glue, rtoffset, ""); @@ -519,14 +516,14 @@ void LLVMIRBuilder::VisitCall(GateRef gate, const std::vector &inList) LLVMValueRef params[16]; for (size_t paraIdx = paraStartIndex; paraIdx < inList.size(); ++paraIdx) { GateRef gateTmp = inList[paraIdx]; - params[paraIdx - paraStartIndex] = g_values[gateTmp]; + params[paraIdx - paraStartIndex] = gateToLLVMMaps_[gateTmp]; } if (callee == nullptr) { COMPILER_LOG(ERROR) << "callee nullptr"; return; } SaveCallerSp(); - g_values[gate] = LLVMBuildCall(builder_, callee, params, inList.size() - paraStartIndex, ""); + gateToLLVMMaps_[gate] = LLVMBuildCall(builder_, callee, params, inList.size() - paraStartIndex, ""); return; } @@ -540,7 +537,7 @@ void LLVMIRBuilder::VisitAlloca(GateRef gate) uint64_t sizeEnum = circuit_->GetBitField(gate); LLVMTypeRef sizeType = GetMachineRepType(static_cast(sizeEnum)); COMPILER_LOG(DEBUG) << LLVMGetTypeKind(sizeType); - g_values[gate] = LLVMBuildPtrToInt(builder_, LLVMBuildAlloca(builder_, sizeType, ""), ConvertLLVMTypeFromGate(gate), + gateToLLVMMaps_[gate] = LLVMBuildPtrToInt(builder_, LLVMBuildAlloca(builder_, sizeType, ""), ConvertLLVMTypeFromGate(gate), ""); // NOTE: pointer val is currently viewed as 64bits return; } @@ -580,8 +577,8 @@ void LLVMIRBuilder::VisitPhi(GateRef gate, const std::vector &srcGates) COMPILER_LOG(ERROR) << "VisitPhi failed impl nullptr"; return; } - LLVMBasicBlockRef llvmBB = EnsureLLVMBB(bb); // The llvm bb - LLVMValueRef value = g_values[srcGates[i]]; + LLVMBasicBlockRef llvmBB = EnsureBasicBlock(bb); // The llvm bb + LLVMValueRef value = gateToLLVMMaps_[srcGates[i]]; if (impl->started) { LLVMAddIncoming(phi, &value, &llvmBB, 1); @@ -600,17 +597,17 @@ void LLVMIRBuilder::VisitPhi(GateRef gate, const std::vector &srcGates) if (addToPhiRebuildList == true) { phiRebuildWorklist_.push_back(currentBb_); } - g_values[gate] = phi; + gateToLLVMMaps_[gate] = phi; } } -void LLVMIRBuilder::VisitReturn(GateRef gate, GateRef popCount, const std::vector &operands) const +void LLVMIRBuilder::VisitReturn(GateRef gate, GateRef popCount, const std::vector &operands) { // [STATE] [DEPEND] [VALUE] [RETURN_LIST] GateRef operand = operands[2]; // 2: skip 2 in gate that are not data gate COMPILER_LOG(DEBUG) << " gate: " << gate << " popCount: " << popCount; COMPILER_LOG(DEBUG) << " return: " << operand << " gateId: " << circuit_->GetId(operand); - LLVMValueRef returnValue = g_values[operand]; + LLVMValueRef returnValue = gateToLLVMMaps_[operand]; COMPILER_LOG(DEBUG) << LLVMValueToString(returnValue); LLVMBuildRet(builder_, returnValue); } @@ -621,7 +618,7 @@ void LLVMIRBuilder::HandleReturn(GateRef gate) VisitReturn(gate, 1, ins); } -void LLVMIRBuilder::VisitReturnVoid(GateRef gate) const +void LLVMIRBuilder::VisitReturnVoid(GateRef gate) { // [STATE] [DEPEND] [VALUE] [RETURN_LIST] COMPILER_LOG(DEBUG) << " gate: " << gate; @@ -636,22 +633,22 @@ void LLVMIRBuilder::HandleReturnVoid(GateRef gate) void LLVMIRBuilder::VisitBlock(int gate, const OperandsVector &predecessors) // NOLINTNEXTLINE(misc-unused-parameters) { COMPILER_LOG(DEBUG) << " BBIdx:" << gate; - BasicBlock *bb = EnsurBasicBlock(gate); + BasicBlock *bb = EnsureBasicBlock(gate); if (bb == nullptr) { COMPILER_LOG(ERROR) << " block create failed "; return; } currentBb_ = bb; - LLVMBasicBlockRef llvmbb = EnsureLLVMBB(bb); - StartLLVMBuilder(bb); + LLVMBasicBlockRef llvmbb = EnsureBasicBlock(bb); + StartBuilder(bb); COMPILER_LOG(DEBUG) << "predecessors :"; for (int predecessor : predecessors) { - BasicBlock *pre = EnsurBasicBlock(predecessor); + BasicBlock *pre = EnsureBasicBlock(predecessor); if (pre == nullptr) { COMPILER_LOG(ERROR) << " block setup failed, predecessor:%d nullptr" << predecessor; return; } - LLVMBasicBlockRef llvmpre = EnsureLLVMBB(pre); + LLVMBasicBlockRef llvmpre = EnsureBasicBlock(pre); COMPILER_LOG(DEBUG) << " " << predecessor; LLVMMoveBasicBlockBefore(llvmpre, llvmbb); } @@ -686,13 +683,13 @@ void LLVMIRBuilder::VisitGoto(int block, int bbOut) if (block == bbOut) { return; } - BasicBlock *bb = EnsurBasicBlock(bbOut); + BasicBlock *bb = EnsureBasicBlock(bbOut); if (bb == nullptr) { COMPILER_LOG(ERROR) << " block is nullptr "; return; } - llvm::BasicBlock *self = llvm::unwrap(EnsureLLVMBB(bbIdMapBb_[block].get())); - llvm::BasicBlock *out = llvm::unwrap(EnsureLLVMBB(bbIdMapBb_[bbOut].get())); + llvm::BasicBlock *self = llvm::unwrap(EnsureBasicBlock(bbIdMapBb_[block].get())); + llvm::BasicBlock *out = llvm::unwrap(EnsureBasicBlock(bbIdMapBb_[bbOut].get())); llvm::BranchInst::Create(out, self); EndCurrentBlock(); } @@ -728,15 +725,15 @@ void LLVMIRBuilder::HandleSExtInt(GateRef gate) VisitSExtInt(gate, ins[0]); } -void LLVMIRBuilder::VisitInt32Constant(GateRef gate, int32_t value) const +void LLVMIRBuilder::VisitInt32Constant(GateRef gate, int32_t value) { LLVMValueRef llvmValue = LLVMConstInt(LLVMInt32Type(), value, 0); - g_values[gate] = llvmValue; + gateToLLVMMaps_[gate] = llvmValue; COMPILER_LOG(DEBUG) << "VisitInt32Constant set gate:" << gate << " value:" << value; COMPILER_LOG(DEBUG) << "VisitInt32Constant " << LLVMValueToString(llvmValue); } -void LLVMIRBuilder::VisitInt64Constant(GateRef gate, int64_t value) const +void LLVMIRBuilder::VisitInt64Constant(GateRef gate, int64_t value) { LLVMValueRef llvmValue = LLVMConstInt(LLVMInt64Type(), value, 0); LLVMTypeRef type = ConvertLLVMTypeFromGate(gate); @@ -756,15 +753,15 @@ void LLVMIRBuilder::VisitInt64Constant(GateRef gate, int64_t value) const } else { abort(); } - g_values[gate] = llvmValue; + gateToLLVMMaps_[gate] = llvmValue; COMPILER_LOG(DEBUG) << "VisitInt64Constant set gate:" << gate << " value:" << value; COMPILER_LOG(DEBUG) << "VisitInt64Constant " << LLVMValueToString(llvmValue); } -void LLVMIRBuilder::VisitFloat64Constant(GateRef gate, double value) const +void LLVMIRBuilder::VisitFloat64Constant(GateRef gate, double value) { LLVMValueRef llvmValue = LLVMConstReal(LLVMDoubleType(), value); - g_values[gate] = llvmValue; + gateToLLVMMaps_[gate] = llvmValue; COMPILER_LOG(DEBUG) << "VisitFloat64Constant set gate:" << gate << " value:" << value; COMPILER_LOG(DEBUG) << "VisitFloat64Constant " << LLVMValueToString(llvmValue); } @@ -774,13 +771,13 @@ void LLVMIRBuilder::HandleParameter(GateRef gate) return VisitParameter(gate); } -void LLVMIRBuilder::VisitParameter(GateRef gate) const +void LLVMIRBuilder::VisitParameter(GateRef gate) { int argth = circuit_->LoadGatePtrConst(gate)->GetBitField(); COMPILER_LOG(DEBUG) << " Parameter value" << argth; LLVMValueRef value = LLVMGetParam(function_, argth); - g_values[gate] = value; + gateToLLVMMaps_[gate] = value; COMPILER_LOG(DEBUG) << "VisitParameter set gate:" << gate << " value:" << value; // NOTE: caller put args, otherwise crash if (value == nullptr) { @@ -807,15 +804,15 @@ void LLVMIRBuilder::HandleIntMod(GateRef gate) VisitIntMod(gate, ins[0], ins[1]); } -void LLVMIRBuilder::VisitIntMod(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitIntMod(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "int mod gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); LLVMValueRef result = LLVMBuildSRem(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } @@ -825,37 +822,37 @@ void LLVMIRBuilder::HandleFloatMod(GateRef gate) VisitFloatMod(gate, ins[0], ins[1]); } -void LLVMIRBuilder::VisitFloatMod(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitFloatMod(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "float mod gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); LLVMValueRef result = LLVMBuildFRem(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } void LLVMIRBuilder::VisitBranch(GateRef gate, GateRef cmp, int btrue, int bfalse) { COMPILER_LOG(DEBUG) << "cmp gate:" << cmp; - if (g_values.count(cmp) == 0) { + if (gateToLLVMMaps_.count(cmp) == 0) { COMPILER_LOG(ERROR) << "Branch condition gate is nullptr!"; return; } - LLVMValueRef cond = g_values[cmp]; + LLVMValueRef cond = gateToLLVMMaps_[cmp]; - BasicBlock *trueBB = EnsurBasicBlock(btrue); - BasicBlock *falseBB = EnsurBasicBlock(bfalse); - EnsureLLVMBB(trueBB); - EnsureLLVMBB(falseBB); + BasicBlock *trueBB = EnsureBasicBlock(btrue); + BasicBlock *falseBB = EnsureBasicBlock(bfalse); + EnsureBasicBlock(trueBB); + EnsureBasicBlock(falseBB); LLVMBasicBlockRef llvmTrueBB = trueBB->GetImpl()->llvm_bb_; LLVMBasicBlockRef llvmFalseBB = falseBB->GetImpl()->llvm_bb_; LLVMValueRef result = LLVMBuildCondBr(builder_, cond, llvmTrueBB, llvmFalseBB); EndCurrentBlock(); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; } void LLVMIRBuilder::HandleSwitch(GateRef gate) @@ -867,13 +864,13 @@ void LLVMIRBuilder::HandleSwitch(GateRef gate) void LLVMIRBuilder::VisitSwitch(GateRef gate, GateRef input, const std::vector &outList) { - LLVMValueRef cond = g_values[input]; + LLVMValueRef cond = gateToLLVMMaps_[input]; unsigned caseNum = outList.size(); BasicBlock *curOutBB = nullptr; LLVMBasicBlockRef llvmDefaultOutBB = nullptr; for (int i = 0; i < static_cast(caseNum); i++) { - curOutBB = EnsurBasicBlock(instIdMapBbId_[circuit_->GetId(outList[i])]); - EnsureLLVMBB(curOutBB); + curOutBB = EnsureBasicBlock(instIdMapBbId_[circuit_->GetId(outList[i])]); + EnsureBasicBlock(curOutBB); if (circuit_->GetOpCode(outList[i]) == OpCode::DEFAULT_CASE) { llvmDefaultOutBB = curOutBB->GetImpl()->llvm_bb_; } @@ -884,18 +881,18 @@ void LLVMIRBuilder::VisitSwitch(GateRef gate, GateRef input, const std::vectorGetOpCode(outList[i]) == OpCode::DEFAULT_CASE) { continue; } - curOutBB = EnsurBasicBlock(instIdMapBbId_[circuit_->GetId(outList[i])]); + curOutBB = EnsureBasicBlock(instIdMapBbId_[circuit_->GetId(outList[i])]); llvmCurOutBB = curOutBB->GetImpl()->llvm_bb_; LLVMAddCase(result, LLVMConstInt(LLVMInt64Type(), circuit_->GetBitField(outList[i]), 0), llvmCurOutBB); } EndCurrentBlock(); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; } -void LLVMIRBuilder::VisitLoad(GateRef gate, GateRef base) const +void LLVMIRBuilder::VisitLoad(GateRef gate, GateRef base) { COMPILER_LOG(DEBUG) << "Load base gate:" << base; - LLVMValueRef baseAddr = g_values[base]; + LLVMValueRef baseAddr = gateToLLVMMaps_[base]; LLVMTypeRef pointerType = ConvertLLVMTypeFromGate(gate); LLVMDumpType(pointerType); LLVMTypeRef returnType; @@ -904,40 +901,40 @@ void LLVMIRBuilder::VisitLoad(GateRef gate, GateRef base) const baseAddr = LLVMBuildPointerCast(builder_, baseAddr, LLVMPointerType(returnType, LLVMGetPointerAddressSpace(ConvertLLVMTypeFromGate(base))), ""); LLVMValueRef result = LLVMBuildLoad(builder_, baseAddr, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; } -void LLVMIRBuilder::VisitStore(GateRef gate, GateRef base, GateRef dataToStore) const +void LLVMIRBuilder::VisitStore(GateRef gate, GateRef base, GateRef dataToStore) { COMPILER_LOG(DEBUG) << "store base gate:" << base; - LLVMValueRef baseAddr = g_values[base]; + LLVMValueRef baseAddr = gateToLLVMMaps_[base]; LLVMDumpValue(baseAddr); std::cout << std::endl; baseAddr = CanonicalizeToPtr(baseAddr); - LLVMValueRef data = g_values[dataToStore]; + LLVMValueRef data = gateToLLVMMaps_[dataToStore]; baseAddr = LLVMBuildPointerCast(builder_, baseAddr, LLVMPointerType(ConvertLLVMTypeFromGate(dataToStore), LLVMGetPointerAddressSpace(ConvertLLVMTypeFromGate(base))), ""); LLVMValueRef value = LLVMBuildStore(builder_, data, baseAddr); - g_values[gate] = value; + gateToLLVMMaps_[gate] = value; COMPILER_LOG(DEBUG) << "store value:" << value << " " << "value type" << LLVMTypeOf(value); } -void LLVMIRBuilder::VisitIntOrUintCmp(GateRef gate, GateRef e1, GateRef e2, LLVMIntPredicate opcode) const +void LLVMIRBuilder::VisitIntOrUintCmp(GateRef gate, GateRef e1, GateRef e2, LLVMIntPredicate opcode) { COMPILER_LOG(DEBUG) << "cmp gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); e1Value = CanonicalizeToInt(e1Value); e2Value = CanonicalizeToInt(e2Value); LLVMValueRef result = LLVMBuildICmp(builder_, opcode, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -LLVMValueRef LLVMIRBuilder::CanonicalizeToInt(LLVMValueRef value) const +LLVMValueRef LLVMIRBuilder::CanonicalizeToInt(LLVMValueRef value) { if (LLVMGetTypeKind(LLVMTypeOf(value)) == LLVMVectorTypeKind) { LLVMValueRef e1Value0 = LLVMBuildExtractElement(builder_, value, LLVMConstInt(LLVMInt32Type(), 0, 1), ""); @@ -958,7 +955,7 @@ LLVMValueRef LLVMIRBuilder::CanonicalizeToInt(LLVMValueRef value) const } } -LLVMValueRef LLVMIRBuilder::CanonicalizeToPtr(LLVMValueRef value) const +LLVMValueRef LLVMIRBuilder::CanonicalizeToPtr(LLVMValueRef value) { if (LLVMGetTypeKind(LLVMTypeOf(value)) == LLVMVectorTypeKind) { LLVMValueRef tmp = LLVMBuildExtractElement(builder_, value, LLVMConstInt(LLVMInt32Type(), 0, 1), ""); @@ -976,15 +973,15 @@ LLVMValueRef LLVMIRBuilder::CanonicalizeToPtr(LLVMValueRef value) const } } -void LLVMIRBuilder::VisitFloatOrDoubleCmp(GateRef gate, GateRef e1, GateRef e2, LLVMRealPredicate opcode) const +void LLVMIRBuilder::VisitFloatOrDoubleCmp(GateRef gate, GateRef e1, GateRef e2, LLVMRealPredicate opcode) { COMPILER_LOG(DEBUG) << "cmp gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); LLVMValueRef result = LLVMBuildFCmp(builder_, opcode, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } @@ -994,13 +991,13 @@ void LLVMIRBuilder::HandleIntRev(GateRef gate) VisitIntRev(gate, ins[0]); } -void LLVMIRBuilder::VisitIntRev(GateRef gate, GateRef e1) const +void LLVMIRBuilder::VisitIntRev(GateRef gate, GateRef e1) { COMPILER_LOG(DEBUG) << "int sign invert gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); LLVMValueRef result = LLVMBuildNot(builder_, e1Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } @@ -1011,7 +1008,7 @@ void LLVMIRBuilder::HandleIntAdd(GateRef gate) VisitIntAdd(gate, ins[0], ins[1]); } -LLVMValueRef LLVMIRBuilder::PointerAdd(LLVMValueRef baseAddr, LLVMValueRef offset, LLVMTypeRef rep) const +LLVMValueRef LLVMIRBuilder::PointerAdd(LLVMValueRef baseAddr, LLVMValueRef offset, LLVMTypeRef rep) { LLVMValueRef ptr = CanonicalizeToPtr(baseAddr); LLVMValueRef dstRef8 = LLVMBuildGEP(builder_, ptr, &offset, 1, ""); @@ -1019,7 +1016,7 @@ LLVMValueRef LLVMIRBuilder::PointerAdd(LLVMValueRef baseAddr, LLVMValueRef offse return result; } -LLVMValueRef LLVMIRBuilder::VectorAdd(LLVMValueRef baseAddr, LLVMValueRef offset, LLVMTypeRef rep) const +LLVMValueRef LLVMIRBuilder::VectorAdd(LLVMValueRef baseAddr, LLVMValueRef offset, LLVMTypeRef rep) { LLVMValueRef ptr = CanonicalizeToPtr(baseAddr); LLVMValueRef dstRef8 = LLVMBuildGEP(builder_, ptr, &offset, 1, ""); @@ -1027,12 +1024,12 @@ LLVMValueRef LLVMIRBuilder::VectorAdd(LLVMValueRef baseAddr, LLVMValueRef offset return result; } -void LLVMIRBuilder::VisitIntAdd(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitIntAdd(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "int add gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); LLVMTypeRef e1Type = ConvertLLVMTypeFromGate(e1); LLVMValueRef result; @@ -1053,14 +1050,14 @@ void LLVMIRBuilder::VisitIntAdd(GateRef gate, GateRef e1, GateRef e2) const ASSERT(LLVMTypeOf(tmp1Value) == LLVMTypeOf(tmp2Value)); } } - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } LLVMTypeRef LLVMIRBuilder::ConvertLLVMTypeFromGate(GateRef gate) const { if (circuit_->GetTypeCode(gate) >= TypeCode::JS_TYPE_OBJECT_START) { - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (compCfg_->IsArm32()) { return LLVMVectorType(LLVMPointerType(LLVMInt8Type(), 1), 2); } else { return LLVMPointerType(LLVMInt64Type(), 1); @@ -1071,7 +1068,7 @@ LLVMTypeRef LLVMIRBuilder::ConvertLLVMTypeFromGate(GateRef gate) const return LLVMVoidType(); case ValueCode::ANYVALUE: { - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (compCfg_->IsArm32()) { return LLVMInt32Type(); } else { return LLVMInt64Type(); @@ -1103,15 +1100,15 @@ void LLVMIRBuilder::HandleFloatAdd(GateRef gate) VisitFloatAdd(gate, ins[0], ins[1]); } -void LLVMIRBuilder::VisitFloatAdd(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitFloatAdd(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "float add gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); LLVMValueRef result = LLVMBuildFAdd(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } @@ -1257,78 +1254,78 @@ void LLVMIRBuilder::HandleChangeTaggedPointerToInt64(GateRef gate) VisitChangeTaggedPointerToInt64(gate, ins[0]); } -void LLVMIRBuilder::VisitFloatSub(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitFloatSub(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "float sub gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); LLVMValueRef result = LLVMBuildFSub(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitFloatMul(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitFloatMul(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "float mul gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); LLVMValueRef result = LLVMBuildFMul(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitFloatDiv(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitFloatDiv(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "float div gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); LLVMValueRef result = LLVMBuildFDiv(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitIntSub(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitIntSub(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "int sub gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); LLVMValueRef result = LLVMBuildSub(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitIntMul(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitIntMul(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "int mul gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); LLVMValueRef result = LLVMBuildMul(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitIntOr(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitIntOr(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "int or gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); e1Value = CanonicalizeToInt(e1Value); e2Value = CanonicalizeToInt(e2Value); LLVMValueRef result = LLVMBuildOr(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } @@ -1338,45 +1335,45 @@ void LLVMIRBuilder::HandleIntAnd(GateRef gate) VisitIntAnd(gate, ins[0], ins[1]); } -void LLVMIRBuilder::VisitIntAnd(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitIntAnd(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "int and gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); e1Value = CanonicalizeToInt(e1Value); e2Value = CanonicalizeToInt(e2Value); LLVMValueRef result = LLVMBuildAnd(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitIntXor(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitIntXor(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "int xor gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); e1Value = CanonicalizeToInt(e1Value); e2Value = CanonicalizeToInt(e2Value); LLVMValueRef result = LLVMBuildXor(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitIntLsr(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitIntLsr(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "int lsr gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); e1Value = CanonicalizeToInt(e1Value); e2Value = CanonicalizeToInt(e2Value); LLVMValueRef result = LLVMBuildLShr(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } @@ -1386,37 +1383,37 @@ void LLVMIRBuilder::HandleIntLsl(GateRef gate) VisitIntLsl(gate, ins[0], ins[1]); } -void LLVMIRBuilder::VisitIntLsl(GateRef gate, GateRef e1, GateRef e2) const +void LLVMIRBuilder::VisitIntLsl(GateRef gate, GateRef e1, GateRef e2) { COMPILER_LOG(DEBUG) << "int lsl gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); - LLVMValueRef e2Value = g_values[e2]; + LLVMValueRef e2Value = gateToLLVMMaps_[e2]; COMPILER_LOG(DEBUG) << "operand 1: " << LLVMValueToString(e2Value); e1Value = CanonicalizeToInt(e1Value); e2Value = CanonicalizeToInt(e2Value); LLVMValueRef result = LLVMBuildShl(builder_, e1Value, e2Value, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitZExtInt(GateRef gate, GateRef e1) const +void LLVMIRBuilder::VisitZExtInt(GateRef gate, GateRef e1) { COMPILER_LOG(DEBUG) << "int zero extension gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); LLVMValueRef result = LLVMBuildZExt(builder_, e1Value, ConvertLLVMTypeFromGate(gate), ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitSExtInt(GateRef gate, GateRef e1) const +void LLVMIRBuilder::VisitSExtInt(GateRef gate, GateRef e1) { COMPILER_LOG(DEBUG) << "int sign extension gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); LLVMValueRef result = LLVMBuildSExt(builder_, e1Value, ConvertLLVMTypeFromGate(gate), ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } @@ -1426,43 +1423,43 @@ void LLVMIRBuilder::HandleCastIntXToIntY(GateRef gate) VisitCastIntXToIntY(gate, ins[0]); } -void LLVMIRBuilder::VisitCastIntXToIntY(GateRef gate, GateRef e1) const +void LLVMIRBuilder::VisitCastIntXToIntY(GateRef gate, GateRef e1) { COMPILER_LOG(DEBUG) << "int cast2 int gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); LLVMValueRef result = LLVMBuildIntCast2(builder_, e1Value, ConvertLLVMTypeFromGate(gate), 1, ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitChangeInt32ToDouble(GateRef gate, GateRef e1) const +void LLVMIRBuilder::VisitChangeInt32ToDouble(GateRef gate, GateRef e1) { COMPILER_LOG(DEBUG) << "int cast2 double gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); LLVMValueRef result = LLVMBuildSIToFP(builder_, e1Value, LLVMDoubleType(), ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitChangeDoubleToInt32(GateRef gate, GateRef e1) const +void LLVMIRBuilder::VisitChangeDoubleToInt32(GateRef gate, GateRef e1) { COMPILER_LOG(DEBUG) << "double cast2 int32 gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); LLVMValueRef result = LLVMBuildFPToSI(builder_, e1Value, LLVMInt32Type(), ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } -void LLVMIRBuilder::VisitChangeTaggedPointerToInt64(GateRef gate, GateRef e1) const +void LLVMIRBuilder::VisitChangeTaggedPointerToInt64(GateRef gate, GateRef e1) { COMPILER_LOG(DEBUG) << "double cast2 int32 gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); LLVMValueRef result = CanonicalizeToInt(e1Value); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } @@ -1472,13 +1469,13 @@ void LLVMIRBuilder::HandleCastInt64ToDouble(GateRef gate) VisitCastInt64ToDouble(gate, ins[0]); } -void LLVMIRBuilder::VisitCastInt64ToDouble(GateRef gate, GateRef e1) const +void LLVMIRBuilder::VisitCastInt64ToDouble(GateRef gate, GateRef e1) { COMPILER_LOG(DEBUG) << "int cast2 double gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); LLVMValueRef result = LLVMBuildBitCast(builder_, e1Value, LLVMDoubleType(), ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } @@ -1488,13 +1485,13 @@ void LLVMIRBuilder::HandleCastDoubleToInt(GateRef gate) VisitCastDoubleToInt(gate, ins[0]); } -void LLVMIRBuilder::VisitCastDoubleToInt(GateRef gate, GateRef e1) const +void LLVMIRBuilder::VisitCastDoubleToInt(GateRef gate, GateRef e1) { COMPILER_LOG(DEBUG) << "double cast2 int gate:" << gate; - LLVMValueRef e1Value = g_values[e1]; + LLVMValueRef e1Value = gateToLLVMMaps_[e1]; COMPILER_LOG(DEBUG) << "operand 0: " << LLVMValueToString(e1Value); LLVMValueRef result = LLVMBuildBitCast(builder_, e1Value, LLVMInt64Type(), ""); - g_values[gate] = result; + gateToLLVMMaps_[gate] = result; COMPILER_LOG(DEBUG) << "result: " << LLVMValueToString(result); } @@ -1510,12 +1507,11 @@ LLVMTypeRef LLVMIRBuilder::ConvertLLVMTypeFromTypeCode(TypeCode type) const return LLVMPointerType(LLVMInt64Type(), 1); } -LLVMStubModule::LLVMStubModule(const char *name, const char *triple) - : triple_(triple) +LLVMStubModule::LLVMStubModule(const std::string &name, const std::string &triple) + : compCfg_(triple) { - module_ = LLVMModuleCreateWithName(name); - triple_ = triple; - LLVMSetTarget(module_, triple); + module_ = LLVMModuleCreateWithName(name.c_str()); + LLVMSetTarget(module_, triple.c_str()); } LLVMStubModule::~LLVMStubModule() @@ -1526,15 +1522,15 @@ LLVMStubModule::~LLVMStubModule() } } -void LLVMStubModule::Initialize() +void LLVMStubModule::Initialize(const std::vector &stubIndices) { - uint32_t i; - for (i = 0; i < FAST_STUB_MAXCOUNT; i++) { - auto stubDescriptor = FastStubDescriptors::GetInstance().GetStubDescriptor(i); + for (auto index : stubIndices) { + auto stubDescriptor = FastStubDescriptors::GetInstance().GetStubDescriptor(index); if (!stubDescriptor->GetName().empty()) { - stubFunctions_[i] = GetLLVMFunctionByStubDescriptor(stubDescriptor); + stubFunctions_[index] = GetLLVMFunctionByStubDescriptor(stubDescriptor); } } + uint32_t i; for (i = 0; i < MAX_STUB_FUNCTION_COUNT; i++) { auto stubDescriptor = FastStubDescriptors::GetInstance().GetStubDescriptor(i); if (!stubDescriptor->GetName().empty()) { @@ -1589,7 +1585,7 @@ LLVMTypeRef LLVMStubModule::ConvertLLVMTypeFromMachineType(MachineType type) {MachineType::TAGGED_POINTER, LLVMPointerType(LLVMInt64Type(), 1)}, {MachineType::TAGGED, LLVMPointerType(LLVMInt64Type(), 1)}, }; - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (compCfg_.IsArm32()) { machineTypeMap[MachineType::NATIVE_POINTER] = LLVMInt32Type(); LLVMTypeRef vectorType = LLVMVectorType(LLVMPointerType(LLVMInt8Type(), 1), 2); // 2: packed vector type machineTypeMap[MachineType::TAGGED_POINTER] = vectorType; diff --git a/ecmascript/compiler/llvm_ir_builder.h b/ecmascript/compiler/llvm_ir_builder.h index ea859be2a0..b11f9f66cd 100644 --- a/ecmascript/compiler/llvm_ir_builder.h +++ b/ecmascript/compiler/llvm_ir_builder.h @@ -23,12 +23,12 @@ #include "ecmascript/compiler/circuit.h" #include "ecmascript/compiler/gate.h" +#include "ecmascript/compiler/stub.h" #include "ecmascript/compiler/stub_descriptor.h" -#include "ecmascript/compiler/triple.h" #include "llvm-c/Core.h" #include "llvm-c/Types.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { using OperandsVector = std::set; class BasicBlock; using BasicBlockMap = std::map>; @@ -108,10 +108,10 @@ struct LLVMTFBuilderBasicBlockImpl { class LLVMStubModule { public: - LLVMStubModule(const char *name, const char *hostTriple); + LLVMStubModule(const std::string &name, const std::string &triple); ~LLVMStubModule(); - void Initialize(); + void Initialize(const std::vector &stubIndices); LLVMModuleRef GetModule() const { @@ -140,25 +140,25 @@ public: #endif } - const char *GetTargetTriple() const + const CompilationConfig *GetCompilationConfig() const { - return triple_; + return &compCfg_; } private: LLVMValueRef GetLLVMFunctionByStubDescriptor(StubDescriptor *stubDescriptor); LLVMTypeRef GetLLVMFunctionTypeStubDescriptor(StubDescriptor *stubDescriptor); LLVMTypeRef ConvertLLVMTypeFromMachineType(MachineType type); - static constexpr uint32_t MAX_STUB_FUNCTION_COUNT = kungfu::EXTERN_RUNTIME_STUB_MAXCOUNT; - static constexpr uint32_t MAX_TEST_FUNCTION_COUNT = kungfu::TEST_FUNC_MAXCOUNT - kungfu::TEST_FUNC_BEGIN - 1; - static constexpr uint32_t TEST_FUNCTION_OFFSET = kungfu::TEST_FUNC_BEGIN + 1; + static constexpr uint32_t MAX_STUB_FUNCTION_COUNT = panda::ecmascript::kungfu::EXTERN_RUNTIME_STUB_MAXCOUNT; + static constexpr uint32_t MAX_TEST_FUNCTION_COUNT = panda::ecmascript::kungfu::TEST_FUNC_MAXCOUNT - panda::ecmascript::kungfu::TEST_FUNC_BEGIN - 1; + static constexpr uint32_t TEST_FUNCTION_OFFSET = panda::ecmascript::kungfu::TEST_FUNC_BEGIN + 1; std::array stubFunctions_ {nullptr}; std::array stubFunctionType_ {nullptr}; #ifndef ECMASCRIPT_ENABLE_SPECIFIC_STUBS std::array testFunctions_ {nullptr}; #endif LLVMModuleRef module_; - const char *triple_; + CompilationConfig compCfg_; }; #define OPCODES(V) \ @@ -166,51 +166,50 @@ private: V(Alloca, (GateRef gate)) \ V(Block, (int id, const OperandsVector &predecessors)) \ V(Goto, (int block, int bbout)) \ - V(Parameter, (GateRef gate) const) \ - V(Int32Constant, (GateRef gate, int32_t value) const) \ - V(Int64Constant, (GateRef gate, int64_t value) const) \ - V(Float64Constant, (GateRef gate, double value) const) \ - V(ZExtInt, (GateRef gate, GateRef e1) const) \ - V(SExtInt, (GateRef gate, GateRef e1) const) \ - V(Load, (GateRef gate, GateRef base) const) \ - V(Store, (GateRef gate, GateRef base, GateRef value) const) \ - V(IntRev, (GateRef gate, GateRef e1) const) \ - V(IntAdd, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(FloatAdd, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(FloatSub, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(FloatMul, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(FloatDiv, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(IntSub, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(IntMul, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(IntOr, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(IntAnd, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(IntXor, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(IntLsr, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(Int32LessThanOrEqual, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(IntOrUintCmp, (GateRef gate, GateRef e1, GateRef e2, LLVMIntPredicate opcode) const) \ - V(FloatOrDoubleCmp, (GateRef gate, GateRef e1, GateRef e2, LLVMRealPredicate opcode) const) \ + V(Parameter, (GateRef gate)) \ + V(Int32Constant, (GateRef gate, int32_t value)) \ + V(Int64Constant, (GateRef gate, int64_t value)) \ + V(Float64Constant, (GateRef gate, double value)) \ + V(ZExtInt, (GateRef gate, GateRef e1)) \ + V(SExtInt, (GateRef gate, GateRef e1)) \ + V(Load, (GateRef gate, GateRef base)) \ + V(Store, (GateRef gate, GateRef base, GateRef value)) \ + V(IntRev, (GateRef gate, GateRef e1)) \ + V(IntAdd, (GateRef gate, GateRef e1, GateRef e2)) \ + V(FloatAdd, (GateRef gate, GateRef e1, GateRef e2)) \ + V(FloatSub, (GateRef gate, GateRef e1, GateRef e2)) \ + V(FloatMul, (GateRef gate, GateRef e1, GateRef e2)) \ + V(FloatDiv, (GateRef gate, GateRef e1, GateRef e2)) \ + V(IntSub, (GateRef gate, GateRef e1, GateRef e2)) \ + V(IntMul, (GateRef gate, GateRef e1, GateRef e2)) \ + V(IntOr, (GateRef gate, GateRef e1, GateRef e2)) \ + V(IntAnd, (GateRef gate, GateRef e1, GateRef e2)) \ + V(IntXor, (GateRef gate, GateRef e1, GateRef e2)) \ + V(IntLsr, (GateRef gate, GateRef e1, GateRef e2)) \ + V(Int32LessThanOrEqual, (GateRef gate, GateRef e1, GateRef e2)) \ + V(IntOrUintCmp, (GateRef gate, GateRef e1, GateRef e2, LLVMIntPredicate opcode)) \ + V(FloatOrDoubleCmp, (GateRef gate, GateRef e1, GateRef e2, LLVMRealPredicate opcode)) \ V(Branch, (GateRef gate, GateRef cmp, GateRef btrue, GateRef bfalse)) \ V(Switch, (GateRef gate, GateRef input, const std::vector &outList)) \ V(SwitchCase, (GateRef gate, GateRef switchBranch, GateRef out)) \ V(Phi, (GateRef gate, const std::vector &srcGates)) \ - V(Return, (GateRef gate, GateRef popCount, const std::vector &operands) const) \ - V(ReturnVoid, (GateRef gate) const) \ - V(CastIntXToIntY, (GateRef gate, GateRef e1) const) \ - V(ChangeInt32ToDouble, (GateRef gate, GateRef e1) const) \ - V(ChangeDoubleToInt32, (GateRef gate, GateRef e1) const) \ - V(CastInt64ToDouble, (GateRef gate, GateRef e1) const) \ - V(CastDoubleToInt, (GateRef gate, GateRef e1) const) \ - V(CastInt64ToPointer, (GateRef gate, GateRef e1) const) \ - V(IntLsl, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(IntMod, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(FloatMod, (GateRef gate, GateRef e1, GateRef e2) const) \ - V(ChangeTaggedPointerToInt64, (GateRef gate, GateRef e1) const) + V(Return, (GateRef gate, GateRef popCount, const std::vector &operands)) \ + V(ReturnVoid, (GateRef gate)) \ + V(CastIntXToIntY, (GateRef gate, GateRef e1)) \ + V(ChangeInt32ToDouble, (GateRef gate, GateRef e1)) \ + V(ChangeDoubleToInt32, (GateRef gate, GateRef e1)) \ + V(CastInt64ToDouble, (GateRef gate, GateRef e1)) \ + V(CastDoubleToInt, (GateRef gate, GateRef e1)) \ + V(CastInt64ToPointer, (GateRef gate, GateRef e1)) \ + V(IntLsl, (GateRef gate, GateRef e1, GateRef e2)) \ + V(IntMod, (GateRef gate, GateRef e1, GateRef e2)) \ + V(FloatMod, (GateRef gate, GateRef e1, GateRef e2)) \ + V(ChangeTaggedPointerToInt64, (GateRef gate, GateRef e1)) class LLVMIRBuilder { public: explicit LLVMIRBuilder(const std::vector> *schedule, const Circuit *circuit, - LLVMStubModule *module, LLVMValueRef function, - const char *hostTriple = TripleConst::GetLLVMAmd64Triple()); + LLVMStubModule *module, LLVMValueRef function, const CompilationConfig *cfg); ~LLVMIRBuilder(); void Build(); @@ -222,15 +221,15 @@ private: OPCODES(DECLAREHANDLEOPCODE) #undef DECLAREHANDLEOPCODE - BasicBlock *EnsurBasicBlock(int id); - LLVMValueRef LLVMCallingFp(LLVMModuleRef &module, LLVMBuilderRef &builder, bool isCaller); + BasicBlock *EnsureBasicBlock(int id); + LLVMValueRef CallingFp(LLVMModuleRef &module, LLVMBuilderRef &builder, bool isCaller); void SaveCallerSp(); - LLVMValueRef LLVMCallerSp(LLVMModuleRef &module, LLVMBuilderRef &builder, + LLVMValueRef CallerSp(LLVMModuleRef &module, LLVMBuilderRef &builder, LLVMMetadataRef meta); void PrologueHandle(LLVMModuleRef &module, LLVMBuilderRef &builder); - LLVMBasicBlockRef EnsureLLVMBB(BasicBlock *bb) const; - LLVMTFBuilderBasicBlockImpl *EnsureLLVMBBImpl(BasicBlock *bb) const; - void StartLLVMBuilder(BasicBlock *bb) const; + LLVMBasicBlockRef EnsureBasicBlock(BasicBlock *bb) const; + LLVMTFBuilderBasicBlockImpl *EnsureBasicBlockImpl(BasicBlock *bb) const; + void StartBuilder(BasicBlock *bb) const; LLVMTypeRef GetMachineRepType(MachineRep rep) const; int FindBasicBlock(GateRef gate) const; @@ -244,20 +243,20 @@ private: LLVMTypeRef GetArchRelate() const { - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (compCfg_->IsArm32()) { return LLVMInt32Type(); } return LLVMInt64Type(); } LLVMTypeRef ConvertLLVMTypeFromGate(GateRef gate) const; - LLVMValueRef PointerAdd(LLVMValueRef baseAddr, LLVMValueRef offset, LLVMTypeRef rep) const; - LLVMValueRef VectorAdd(LLVMValueRef e1Value, LLVMValueRef e2Value, LLVMTypeRef rep) const; - LLVMValueRef CanonicalizeToInt(LLVMValueRef value) const; + LLVMValueRef PointerAdd(LLVMValueRef baseAddr, LLVMValueRef offset, LLVMTypeRef rep); + LLVMValueRef VectorAdd(LLVMValueRef e1Value, LLVMValueRef e2Value, LLVMTypeRef rep); + LLVMValueRef CanonicalizeToInt(LLVMValueRef value); - LLVMValueRef CanonicalizeToPtr(LLVMValueRef value) const; + LLVMValueRef CanonicalizeToPtr(LLVMValueRef value); private: - + const CompilationConfig *compCfg_ {nullptr}; const std::vector> *schedule_ {nullptr}; const Circuit *circuit_ {nullptr}; BasicBlock *currentBb_ {nullptr}; @@ -272,9 +271,9 @@ private: std::vector phiRebuildWorklist_; LLVMStubModule *stubModule_ {nullptr}; + std::unordered_map gateToLLVMMaps_; std::unordered_map opCodeHandleMap_; std::set opCodeHandleIgnore; - const char *triple_; }; -} // namespace kungfu +} // namespace panda::ecmascript::kungfu #endif // PANDA_RUNTIME_ECMASCRIPT_COMPILER_LLVM_IR_BUILDER_H diff --git a/ecmascript/compiler/machine_type.h b/ecmascript/compiler/machine_type.h index f9b9eb35b2..fe0821e210 100644 --- a/ecmascript/compiler/machine_type.h +++ b/ecmascript/compiler/machine_type.h @@ -16,7 +16,7 @@ #ifndef ECMASCRIPT_COMPILER_MACHINE_TYPE_H #define ECMASCRIPT_COMPILER_MACHINE_TYPE_H -namespace kungfu { +namespace panda::ecmascript::kungfu { enum class MachineType { NONE, BOOL, @@ -34,5 +34,5 @@ enum class MachineType { TAGGED, // GC cares TAGGED_POINTER, }; -} // namespace kungfu +} // namespace panda::ecmascript::kungfu #endif // ECMASCRIPT_COMPILER_MACHINE_TYPE_H \ No newline at end of file diff --git a/ecmascript/compiler/scheduler.cpp b/ecmascript/compiler/scheduler.cpp index 9d75e27407..2bf979ab55 100644 --- a/ecmascript/compiler/scheduler.cpp +++ b/ecmascript/compiler/scheduler.cpp @@ -19,7 +19,7 @@ #include "ecmascript/compiler/verifier.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { using DominatorTreeInfo = std::tuple, std::unordered_map, std::vector>; DominatorTreeInfo Scheduler::CalculateDominatorTree(const Circuit *circuit) @@ -328,4 +328,4 @@ void Scheduler::Print(const std::vector> *cfg, const Circui } std::cout << "==========================================================================" << std::endl; } -} // namespace kungfu \ No newline at end of file +} // namespace panda::ecmascript::kungfu \ No newline at end of file diff --git a/ecmascript/compiler/scheduler.h b/ecmascript/compiler/scheduler.h index 94d8a574ae..10ca4b07ec 100644 --- a/ecmascript/compiler/scheduler.h +++ b/ecmascript/compiler/scheduler.h @@ -24,7 +24,7 @@ #include "ecmascript/compiler/circuit.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { using ControlFlowGraph = std::vector>; class Scheduler { public: @@ -39,6 +39,6 @@ public: const std::function &lowestCommonAncestor, std::vector *order = nullptr); static void Print(const ControlFlowGraph *cfg, const Circuit *circuit); }; -}; // namespace kungfu +}; // namespace panda::ecmascript::kungfu #endif // ECMASCRIPT_COMPILER_SCHEDULER_H diff --git a/ecmascript/compiler/stub-inl.h b/ecmascript/compiler/stub-inl.h index 549fa8eb41..5ca208c31d 100644 --- a/ecmascript/compiler/stub-inl.h +++ b/ecmascript/compiler/stub-inl.h @@ -18,7 +18,7 @@ #include "ecmascript/compiler/stub.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { using LabelImpl = Stub::Label::LabelImpl; using JSTaggedValue = JSTaggedValue; using JSFunction = panda::ecmascript::JSFunction; @@ -92,19 +92,19 @@ TypeCode Stub::Environment::GetTypeCode(GateRef gate) const Stub::Label Stub::Environment::GetLabelFromSelector(GateRef sel) { - LabelImpl *rawlabel = phi_to_labels_[sel]; + LabelImpl *rawlabel = phiToLabels_[sel]; return Stub::Label(rawlabel); } void Stub::Environment::AddSelectorToLabel(GateRef sel, Label label) { - phi_to_labels_[sel] = label.GetRawLabel(); + phiToLabels_[sel] = label.GetRawLabel(); } LabelImpl *Stub::Environment::NewLabel(Stub::Environment *env, GateRef control) { auto impl = new LabelImpl(env, control); - rawlabels_.emplace_back(impl); + rawLabels_.emplace_back(impl); return impl; } @@ -154,7 +154,7 @@ GateRef Stub::GetWord64Constant(uint64_t value) GateRef Stub::GetArchRelateConstant(uint64_t value) { - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (env_.IsArm32()) { return GetInt32Constant(value); } return GetWord64Constant(value); @@ -203,7 +203,7 @@ GateRef Stub::GetExceptionConstant(MachineType type) GateRef Stub::ArchRelatePtrMul(GateRef x, GateRef y) { - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (env_.IsArm32()) { return Int32Mul(x, y); } else { return Int64Mul(x, y); @@ -257,9 +257,9 @@ GateRef Stub::PtrArgument(size_t index, TypeCode type) { GateRef argument = Argument(index); env_.GetCircuit()->SetTypeCode(argument, type); - if (ArchRelatePtrValueCode(triple_) == ValueCode::INT64) { + if (env_.IsArch64Bit()) { env_.GetCircuit()->SetOpCode(argument, OpCode(OpCode::INT64_ARG)); - } else if (ArchRelatePtrValueCode(triple_) == ValueCode::INT32) { + } else if (env_.IsArch32Bit()) { env_.GetCircuit()->SetOpCode(argument, OpCode(OpCode::INT32_ARG)); } else { UNREACHABLE(); @@ -349,15 +349,21 @@ void Stub::DebugPrint(GateRef glue, std::initializer_list args) GateRef Stub::Load(MachineType type, GateRef base, GateRef offset) { auto depend = env_.GetCurrentLabel()->GetDepend(); - if (ArchRelatePtrValueCode(triple_) == ValueCode::INT64) { + if (env_.IsArch64Bit()) { GateRef val = Int64Add(base, offset); - GateRef result = env_.GetCircuitBuilder().NewLoadGate(type, val, depend, triple_); + if (type == MachineType::NATIVE_POINTER) { + type = MachineType::INT64; + } + GateRef result = env_.GetCircuitBuilder().NewLoadGate(type, val, depend); env_.GetCurrentLabel()->SetDepend(result); return result; } - if (ArchRelatePtrValueCode(triple_) == ValueCode::INT32) { + if (env_.IsArch32Bit()) { GateRef val = Int32Add(base, offset); - GateRef result = env_.GetCircuitBuilder().NewLoadGate(type, val, depend, triple_); + if (type == MachineType::NATIVE_POINTER) { + type = MachineType::INT32; + } + GateRef result = env_.GetCircuitBuilder().NewLoadGate(type, val, depend); env_.GetCurrentLabel()->SetDepend(result); return result; } @@ -366,8 +372,15 @@ GateRef Stub::Load(MachineType type, GateRef base, GateRef offset) GateRef Stub::Load(MachineType type, GateRef base) { + if (type == MachineType::NATIVE_POINTER) { + if (env_.IsArch64Bit()) { + type = MachineType::INT64; + } else { + type = MachineType::INT32; + } + } auto depend = env_.GetCurrentLabel()->GetDepend(); - GateRef result = env_.GetCircuitBuilder().NewLoadGate(type, base, depend, triple_); + GateRef result = env_.GetCircuitBuilder().NewLoadGate(type, base, depend); env_.GetCurrentLabel()->SetDepend(result); return result; } @@ -390,7 +403,7 @@ GateRef Stub::DoubleAdd(GateRef x, GateRef y) GateRef Stub::ArchRelateAdd(GateRef x, GateRef y) { - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (env_.IsArm32()) { return Int32Add(x, y); } return Int64Add(x, y); @@ -398,7 +411,7 @@ GateRef Stub::ArchRelateAdd(GateRef x, GateRef y) GateRef Stub::ArchRelateSub(GateRef x, GateRef y) { - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (env_.IsArm32()) { return Int32Sub(x, y); } return Int64Sub(x, y); @@ -802,7 +815,7 @@ GateRef Stub::ChangeInt64ToInt32(GateRef val) GateRef Stub::ChangeInt64ToUintPtr(GateRef val) { - if (ArchRelatePtrValueCode(triple_) == ValueCode::INT32) { + if (env_.IsArch32Bit()) { return env_.GetCircuitBuilder().NewArithMeticGate(OpCode(OpCode::TRUNC_INT64_TO_INT32), val); } return val; @@ -810,7 +823,7 @@ GateRef Stub::ChangeInt64ToUintPtr(GateRef val) GateRef Stub::ChangeInt32ToUintPtr(GateRef val) { - if (ArchRelatePtrValueCode(triple_) == ValueCode::INT32) { + if (env_.IsArch32Bit()) { return val; } return ZExtInt32ToInt64(val); @@ -870,7 +883,7 @@ void Stub::StoreHClass(GateRef glue, GateRef object, GateRef hclass) GateRef Stub::GetObjectType(GateRef hClass) { GateRef bitfieldOffset = GetArchRelateConstant(JSHClass::BIT_FIELD_OFFSET); - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (env_.IsArm32()) { GateRef bitfield1 = Load(MachineType::NATIVE_POINTER, hClass, ZExtInt32ToInt64(bitfieldOffset)); return Word32And(bitfield1, ChangeInt64ToInt32(GetWord64Constant((1LLU << JSHClass::ObjectTypeBits::SIZE) - 1))); @@ -1589,7 +1602,7 @@ GateRef Stub::GetGlobalConstantAddr(GateRef index) GateRef Stub::GetGlobalConstantString(ConstantIndex index) { - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (env_.IsArm32()) { return Int32Mul(GetInt32Constant(sizeof(JSTaggedValue)), GetInt32Constant(static_cast(index))); } else { return Int64Mul(GetWord64Constant(sizeof(JSTaggedValue)), GetWord64Constant(static_cast(index))); @@ -1602,7 +1615,7 @@ GateRef Stub::IsCallable(GateRef obj) GateRef bitfieldOffset = GetArchRelateConstant(JSHClass::BIT_FIELD_OFFSET); // decode - if (triple_ == TripleConst::GetLLVMArm32Triple()) { + if (env_.IsArm32()) { GateRef bitfield = Load(MachineType::NATIVE_POINTER, hclass, ZExtInt32ToInt64(bitfieldOffset)); return Word32NotEqual( Word32And(Word32LSR(bitfield, GetInt32Constant(JSHClass::CallableBit::START_BIT)), @@ -1665,5 +1678,5 @@ void Stub::UpdateValueInDict(GateRef glue, GateRef elements, GateRef index, Gate GateRef valueIndex = Int32Add(arrayIndex, GetInt32Constant(NameDictionary::ENTRY_VALUE_INDEX)); SetValueToTaggedArray(MachineType::TAGGED, glue, elements, valueIndex, value); } -} // namespace kungfu +} // namespace panda::ecmascript::kungfu #endif // ECMASCRIPT_COMPILER_STUB_INL_H diff --git a/ecmascript/compiler/stub.cpp b/ecmascript/compiler/stub.cpp index 9233e61848..2a078289cc 100644 --- a/ecmascript/compiler/stub.cpp +++ b/ecmascript/compiler/stub.cpp @@ -14,14 +14,13 @@ */ #include "ecmascript/compiler/stub.h" -#include "ecmascript/compiler/js_thread_offset_table.h" #include "ecmascript/compiler/llvm_ir_builder.h" #include "ecmascript/compiler/stub-inl.h" #include "ecmascript/js_object.h" #include "ecmascript/tagged_hash_table-inl.h" #include "libpandabase/macros.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { Stub::Label::Label(Environment *env) { impl_ = env->NewLabel(env); @@ -58,7 +57,7 @@ GateRef Stub::Variable::TryRemoveTrivialPhi(GateRef phiVal) continue; // unique value or self-reference } if (same != nullptr) { - return phiVal; // the phi merges at least two values: not trivial + return phiVal; // the phi merges at least two valusses: not trivial } same = op; } @@ -275,7 +274,7 @@ Stub::Environment::Environment(size_t arguments, Circuit *circuit) Stub::Environment::~Environment() { - for (auto label : rawlabels_) { + for (auto label : rawLabels_) { delete label; } } @@ -950,7 +949,7 @@ void Stub::JSHClassAddProperty(GateRef glue, GateRef receiver, GateRef key, Gate // keyHandle.GetTaggedValue() == thread->GlobalConstants()->GetConstructorString() GateRef Stub::SetHasConstructorCondition(GateRef glue, GateRef receiver, GateRef key) { - GateRef gConstOffset = PtrAdd(glue, GetArchRelateConstant(OffsetTable::GetOffset(JSThread::GlueID::GLOBAL_CONST))); + GateRef gConstOffset = PtrAdd(glue, GetArchRelateConstant(env_.GetGlueOffset(JSThread::GlueID::GLOBAL_CONST))); GateRef gCtorStr = Load(MachineType::TAGGED, gConstOffset, Int64Mul(GetWord64Constant(sizeof(JSTaggedValue)), @@ -1240,13 +1239,19 @@ GateRef Stub::Store(MachineType type, GateRef glue, GateRef base, GateRef offset { auto depend = env_.GetCurrentLabel()->GetDepend(); GateRef result; - if (ArchRelatePtrValueCode(triple_) == ValueCode::INT64) { + if (env_.IsArch64Bit()) { GateRef ptr = Int64Add(base, offset); - result = env_.GetCircuitBuilder().NewStoreGate(type, ptr, value, depend, triple_); + if (type == MachineType::NATIVE_POINTER) { + type = MachineType::INT64; + } + result = env_.GetCircuitBuilder().NewStoreGate(type, ptr, value, depend); env_.GetCurrentLabel()->SetDepend(result); - } else if (ArchRelatePtrValueCode(triple_) == ValueCode::INT32) { + } else if (env_.IsArch32Bit()) { + if (type == MachineType::NATIVE_POINTER) { + type = MachineType::INT32; + } GateRef ptr = Int32Add(base, offset); - result = env_.GetCircuitBuilder().NewStoreGate(type, ptr, value, depend, triple_); + result = env_.GetCircuitBuilder().NewStoreGate(type, ptr, value, depend); env_.GetCurrentLabel()->SetDepend(result); } else { UNREACHABLE(); @@ -3009,4 +3014,4 @@ void Stub::NotifyHClassChanged(GateRef glue, GateRef oldHClass, GateRef newHClas env->PopCurrentLabel(); return; } -} // namespace kungfu +} // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/stub.h b/ecmascript/compiler/stub.h index 3ec8e38b58..ebe7ff978b 100644 --- a/ecmascript/compiler/stub.h +++ b/ecmascript/compiler/stub.h @@ -23,7 +23,6 @@ #include "ecmascript/compiler/gate.h" #include "ecmascript/compiler/machine_type.h" #include "ecmascript/compiler/stub_descriptor.h" -#include "ecmascript/compiler/triple.h" #include "ecmascript/ic/ic_handler.h" #include "ecmascript/ic/proto_change_details.h" #include "ecmascript/js_array.h" @@ -34,11 +33,106 @@ #include "ecmascript/message_string.h" #include "ecmascript/tagged_dictionary.h" -namespace kungfu { +namespace panda::ecmascript::kungfu { using namespace panda::ecmascript; // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DEFVARIABLE(varname, type, val) Stub::Variable varname(GetEnvironment(), type, NextVariableId(), val) +class CompilationConfig { +public: + enum class Triple { + TRIPLE_AMD64, + TRIPLE_AARCH64, + TRIPLE_ARM32, + }; + + explicit CompilationConfig(const std::string &triple) + : triple_(GetTripleFromString(triple)), + glueTable_(triple_) + { + } + ~CompilationConfig() = default; + + inline bool IsArm32() const + { + return triple_ == Triple::TRIPLE_ARM32; + } + + inline bool IsAArch64() const + { + return triple_ == Triple::TRIPLE_AARCH64; + } + + inline bool IsAmd64() const + { + return triple_ == Triple::TRIPLE_AMD64; + } + + Triple GetTriple() const + { + return triple_; + } + + uint32_t GetGlueOffset(JSThread::GlueID id) const + { + return glueTable_.GetOffset(id); + } + + class GlueTable { + public: + explicit GlueTable(Triple triple) + { + switch (triple) { + case Triple::TRIPLE_AMD64: + case Triple::TRIPLE_AARCH64: + offsetTable_ = { + GLUE_EXCEPTION_OFFSET_64, GLUE_GLOBAL_CONSTANTS_OFFSET_64, GLUE_PROPERTIES_CACHE_OFFSET_64, + GLUE_GLOBAL_STORAGE_OFFSET_64, GLUE_CURRENT_FRAME_OFFSET_64, GLUE_LAST_IFRAME_OFFSET_64, + GLUE_RUNTIME_FUNCTIONS_OFFSET_64, GLUE_FASTSTUB_ENTRIES_OFFSET_64 + }; + break; + case Triple::TRIPLE_ARM32: + offsetTable_ = { + GLUE_EXCEPTION_OFFSET_32, GLUE_GLOBAL_CONSTANTS_OFFSET_32, GLUE_PROPERTIES_CACHE_OFFSET_32, + GLUE_GLOBAL_STORAGE_OFFSET_32, GLUE_CURRENT_FRAME_OFFSET_32, GLUE_LAST_IFRAME_OFFSET_32, + GLUE_RUNTIME_FUNCTIONS_OFFSET_32, GLUE_FASTSTUB_ENTRIES_OFFSET_32 + }; + break; + default: + UNREACHABLE(); + } + } + ~GlueTable() = default; + + uint32_t GetOffset(JSThread::GlueID id) const + { + return offsetTable_[static_cast(id)]; + } + + private: + std::array(JSThread::GlueID::NUMBER_OF_GLUE)> offsetTable_ {}; + }; + +private: + inline Triple GetTripleFromString(const std::string &triple) + { + if (triple.compare("x86_64-unknown-linux-gnu") == 0) { + return Triple::TRIPLE_AMD64; + } + + if (triple.compare("aarch64-unknown-linux-gnu") == 0) { + return Triple::TRIPLE_AARCH64; + } + + if (triple.compare("arm-unknown-linux-gnu") == 0) { + return Triple::TRIPLE_ARM32; + } + UNREACHABLE(); + } + Triple triple_; + GlueTable glueTable_; +}; + class Stub { public: class Environment; @@ -172,6 +266,40 @@ public: { return circuit_; } + void SetCompilationConfig(const CompilationConfig *cfg) + { + compCfg_ = cfg; + } + inline bool IsArm32() const + { + return compCfg_->IsArm32(); + } + + inline bool IsAArch64() const + { + return compCfg_->IsAArch64(); + } + + inline bool IsAmd64() const + { + return compCfg_->IsAmd64(); + } + + inline bool IsArch64Bit() const + { + return compCfg_->IsAmd64() || compCfg_->IsAArch64(); + } + + inline bool IsArch32Bit() const + { + return compCfg_->IsArm32();; + } + + uint32_t GetGlueOffset(JSThread::GlueID id) const + { + return compCfg_->GetGlueOffset(id); + } + inline TypeCode GetTypeCode(GateRef gate) const; inline Label GetLabelFromSelector(GateRef sel); inline void AddSelectorToLabel(GateRef sel, Label label); @@ -181,13 +309,14 @@ public: inline void SetFrameType(FrameType type); inline GateRef GetArgument(size_t index) const; private: + const CompilationConfig *compCfg_; Label *currentLabel_ {nullptr}; Circuit *circuit_; CircuitBuilder builder_; - std::unordered_map phi_to_labels_; + std::unordered_map phiToLabels_; std::vector arguments_; Label entry_; - std::vector rawlabels_; + std::vector rawLabels_; std::stack