diff --git a/BUILD.gn b/BUILD.gn index 0f8e7fe84d7bd8d9216411a4bd284f2846d65196..ac7fa0ea9509766d0c4271388f672306b85ca8c6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -31,10 +31,8 @@ group("ark_js_host_linux_tools_packages") { deps += [ "//ark/js_runtime:libark_jsruntime(${host_toolchain})", "//ark/js_runtime/ecmascript/js_vm:ark_js_vm(${host_toolchain})", - - #"//ark/js_runtime/ecmascript/compiler:libark_jsoptimizer(${host_toolchain})", ] - if (current_cpu == "x86_64" || current_cpu == "x64") { + if (is_standard_system) { deps += [ "//ark/js_runtime/ecmascript/compiler:libark_jsoptimizer(${host_toolchain})" ] } } @@ -70,8 +68,8 @@ group("ark_js_host_unittest") { "//ark/js_runtime/ecmascript/tests:host_unittest", "//ark/js_runtime/ecmascript/tooling/test:host_unittest", ] - if (current_cpu == "x86_64" || current_cpu == "x64") { - deps += [ "//ark/js_runtime/ecmascript/compiler:libark_jsoptimizer(${host_toolchain})" ] + if (is_standard_system) { + deps += [ "//ark/js_runtime/ecmascript/compiler/tests:host_unittest" ] } # js bytecode test diff --git a/ecmascript/compiler/BUILD.gn b/ecmascript/compiler/BUILD.gn index 162ecd49752c6318d9b4b2138b0308f8cb666448..4d29631c0471c49d749ad954ddfda304bdacc28a 100644 --- a/ecmascript/compiler/BUILD.gn +++ b/ecmascript/compiler/BUILD.gn @@ -21,11 +21,17 @@ action("build_llvm_libs") { } config("include_llvm") { - include_dirs = [ - "//third_party/llvm-project/llvm/include/", - "//third_party/llvm-project/build/include", - "//third_party/llvm-project/llvm/build/include", - ] + if (compile_llvm_online) { + include_dirs = [ + "//third_party/llvm-project/build/include", + "//third_party/llvm-project/llvm/include/", + ] + } else { + include_dirs = [ + "//prebuilts/ark_js_prebuilts/llvm_prebuilts/llvm/include", + "//prebuilts/ark_js_prebuilts/llvm_prebuilts/build/include", + ] + } } config("ark_jsruntime_compiler_config") { @@ -56,13 +62,15 @@ ohos_shared_library("libark_jsoptimizer") { "$ark_root/runtime:arkruntime_public_config", ] - lib_dirs = [ "//third_party/llvm-project/build/lib" ] + if (compile_llvm_online) { + lib_dirs = [ "//third_party/llvm-project/build/lib" ] + } else { + lib_dirs = [ "//prebuilts/ark_js_prebuilts/llvm_prebuilts/build/lib" ] + } libs = [ "stdc++", "z", - "tinfo", - "LTO", "LLVMTarget", "LLVMObject", "LLVMMC", @@ -83,7 +91,6 @@ ohos_shared_library("libark_jsoptimizer") { "LLVMScalarOpts", "LLVMTransformUtils", "LLVMBitReader", - "LLVMSystemZInfo", "LLVMAsmPrinter", "LLVMProfileData", "LLVMBitstreamReader", @@ -98,89 +105,38 @@ ohos_shared_library("libark_jsoptimizer") { "LLVMDebugInfoCodeView", "LLVMAggressiveInstCombine", "LLVMAsmParser", - "LLVMMipsAsmParser", "LLVMMCParser", "LLVMMIRParser", - "LLVMMSP430AsmParser", "LLVMX86Info", "LLVMAArch64Info", - "LLVMLanaiInfo", - "LLVMAMDGPUInfo", - "LLVMARMInfo", - "LLVMHexagonInfo", - "LLVMNVPTXInfo", - "LLVMRISCVInfo", - "LLVMSparcInfo", - "LLVMMipsInfo", - "LLVMWebAssemblyInfo", - "LLVMBPFInfo", - "LLVMMSP430Info", - "LLVMPowerPCInfo", - "LLVMXCoreInfo", "LLVMARMDesc", "LLVMAArch64Desc", - "LLVMSparcDesc", - "LLVMAMDGPUDesc", - "LLVMXCoreDesc", - "LLVMWebAssemblyDesc", - "LLVMNVPTXDesc", - "LLVMMSP430Desc", - "LLVMPowerPCDesc", - "LLVMMipsDesc", - "LLVMRISCVDesc", - "LLVMLanaiDesc", - "LLVMSystemZDesc", - "LLVMHexagonDesc", "LLVMX86Desc", - "LLVMBPFDesc", - "LLVMSparcDisassembler", - "LLVMRISCVDisassembler", - "LLVMMipsDisassembler", - "LLVMXCoreDisassembler", - "LLVMPowerPCDisassembler", "LLVMX86Disassembler", - "LLVMMSP430Disassembler", "LLVMARMDisassembler", - "LLVMLanaiDisassembler", "LLVMAArch64Disassembler", - "LLVMBPFDisassembler", - "LLVMSystemZDisassembler", "LLVMMCDisassembler", - "LLVMWebAssemblyDisassembler", - "LLVMHexagonDisassembler", - "LLVMAMDGPUDisassembler", - "LLVMXCoreCodeGen", - "LLVMPowerPCCodeGen", - "LLVMNVPTXCodeGen", "LLVMAArch64CodeGen", - "LLVMMSP430CodeGen", "LLVMARMCodeGen", - "LLVMMipsCodeGen", - "LLVMSparcCodeGen", - "LLVMBPFCodeGen", - "LLVMHexagonCodeGen", - "LLVMAMDGPUCodeGen", - "LLVMRISCVCodeGen", - "LLVMWebAssemblyCodeGen", - "LLVMSystemZCodeGen", "LLVMCodeGen", "LLVMX86CodeGen", - "LLVMLanaiCodeGen", "LLVMX86AsmParser", - "LLVMAMDGPUUtils", - "LLVMRISCVUtils", "LLVMTransformUtils", "LLVMAArch64Utils", "LLVMARMUtils", "LLVMX86Utils", + "LLVMIRReader", ] deps = [ - ":build_llvm_libs", "$ark_root/libpandabase:libarkbase", "//ark/js_runtime:libark_jsruntime", ] + if (compile_llvm_online) { + deps += [ ":build_llvm_libs" ] + } + output_extension = "so" relative_install_dir = "ark" subsystem_name = "ark" diff --git a/ecmascript/compiler/llvm_mcjit_compiler.cpp b/ecmascript/compiler/llvm_mcjit_compiler.cpp index 2ad0a094d0fb508643688113086b3e8bbf4b705b..2eaa1f75a3f9ba926ad1e1875f7520df2ad717c8 100644 --- a/ecmascript/compiler/llvm_mcjit_compiler.cpp +++ b/ecmascript/compiler/llvm_mcjit_compiler.cpp @@ -140,13 +140,15 @@ void LLVMMCJITCompiler::Run() void LLVMMCJITCompiler::Initialize() { - LLVMInitializeAllTargetInfos(); - LLVMInitializeAllTargetMCs(); - LLVMInitializeAllDisassemblers(); +#if defined(PANDA_TARGET_AMD64) + LLVMInitializeX86TargetInfo(); + LLVMInitializeX86TargetMC(); + LLVMInitializeX86Disassembler(); /* this method must be called, ohterwise "Target does not support MC emission" */ - LLVMInitializeNativeAsmPrinter(); - LLVMInitializeNativeAsmParser(); - LLVMInitializeAllTargets(); + LLVMInitializeX86AsmPrinter(); + LLVMInitializeX86AsmParser(); + LLVMInitializeX86Target(); +#endif llvm::linkAllBuiltinGCs(); LLVMInitializeMCJITCompilerOptions(&options_, sizeof(options_)); options_.OptLevel = 2; // opt level 2 diff --git a/ecmascript/compiler/llvm_stackmap_parse.h b/ecmascript/compiler/llvm_stackmap_parse.h index 17204129db3881cacc565a950921b9b7ab5b632f..e22e55499681784950a835350311ba45f32d16e8 100644 --- a/ecmascript/compiler/llvm_stackmap_parse.h +++ b/ecmascript/compiler/llvm_stackmap_parse.h @@ -15,9 +15,11 @@ #ifndef ECMASCRIPT_COMPILER_LLVM_LLVMSTACKPARSE_H #define ECMASCRIPT_COMPILER_LLVM_LLVMSTACKPARSE_H -#include -#include + #include +#include +#include +#include namespace kungfu { using OffsetType = int32_t; @@ -205,7 +207,7 @@ private: const uint8_t *stackMapAddr_; struct LLVMStackMap llvmStackMap_; std::vector callSiteInfos_; - std::unique_ptr dataInfo_; + [[maybe_unused]] std::unique_ptr dataInfo_; }; } // namespace kungfu #endif // ECMASCRIPT_COMPILER_LLVM_LLVMSTACKPARSE_H \ No newline at end of file diff --git a/ecmascript/compiler/tests/BUILD.gn b/ecmascript/compiler/tests/BUILD.gn index 4c5845aa3025328a6219ff332c785aca740ed35e..b785d59a0a2bcae1a1883c998449fafff116afc0 100644 --- a/ecmascript/compiler/tests/BUILD.gn +++ b/ecmascript/compiler/tests/BUILD.gn @@ -16,11 +16,17 @@ import("//ark/js_runtime/test/test_helper.gni") import("//build/test.gni") config("include_llvm_config") { - include_dirs = [ - "//third_party/llvm-project/llvm/include/", - "//third_party/llvm-project/build/include", - "//third_party/llvm-project/llvm/build/include", - ] + if (compile_llvm_online) { + include_dirs = [ + "//third_party/llvm-project/build/include", + "//third_party/llvm-project/llvm/include/", + ] + } else { + include_dirs = [ + "//prebuilts/ark_js_prebuilts/llvm_prebuilts/llvm/include", + "//prebuilts/ark_js_prebuilts/llvm_prebuilts/build/include", + ] + } } module_output_path = "ark/js_runtime" @@ -40,13 +46,15 @@ host_unittest_action("StubOptimizerTest") { "$ark_root/runtime:arkruntime_public_config", ] - lib_dirs = [ "//third_party/llvm-project/build/lib" ] + if (compile_llvm_online) { + lib_dirs = [ "//third_party/llvm-project/build/lib" ] + } else { + lib_dirs = [ "//prebuilts/ark_js_prebuilts/llvm_prebuilts/build/lib" ] + } libs = [ "stdc++", "z", - "tinfo", - "LTO", "LLVMTarget", "LLVMObject", "LLVMMC", @@ -67,7 +75,6 @@ host_unittest_action("StubOptimizerTest") { "LLVMScalarOpts", "LLVMTransformUtils", "LLVMBitReader", - "LLVMSystemZInfo", "LLVMAsmPrinter", "LLVMProfileData", "LLVMBitstreamReader", @@ -82,77 +89,22 @@ host_unittest_action("StubOptimizerTest") { "LLVMDebugInfoCodeView", "LLVMAggressiveInstCombine", "LLVMAsmParser", - "LLVMMipsAsmParser", "LLVMMCParser", "LLVMMIRParser", - "LLVMMSP430AsmParser", "LLVMX86Info", "LLVMAArch64Info", - "LLVMLanaiInfo", - "LLVMAMDGPUInfo", - "LLVMARMInfo", - "LLVMHexagonInfo", - "LLVMNVPTXInfo", - "LLVMRISCVInfo", - "LLVMSparcInfo", - "LLVMMipsInfo", - "LLVMWebAssemblyInfo", - "LLVMBPFInfo", - "LLVMMSP430Info", - "LLVMPowerPCInfo", - "LLVMXCoreInfo", "LLVMARMDesc", "LLVMAArch64Desc", - "LLVMSparcDesc", - "LLVMAMDGPUDesc", - "LLVMXCoreDesc", - "LLVMWebAssemblyDesc", - "LLVMNVPTXDesc", - "LLVMMSP430Desc", - "LLVMPowerPCDesc", - "LLVMMipsDesc", - "LLVMRISCVDesc", - "LLVMLanaiDesc", - "LLVMSystemZDesc", - "LLVMHexagonDesc", "LLVMX86Desc", - "LLVMBPFDesc", - "LLVMSparcDisassembler", - "LLVMRISCVDisassembler", - "LLVMMipsDisassembler", - "LLVMXCoreDisassembler", - "LLVMPowerPCDisassembler", "LLVMX86Disassembler", - "LLVMMSP430Disassembler", "LLVMARMDisassembler", - "LLVMLanaiDisassembler", "LLVMAArch64Disassembler", - "LLVMBPFDisassembler", - "LLVMSystemZDisassembler", "LLVMMCDisassembler", - "LLVMWebAssemblyDisassembler", - "LLVMHexagonDisassembler", - "LLVMAMDGPUDisassembler", - "LLVMXCoreCodeGen", - "LLVMPowerPCCodeGen", - "LLVMNVPTXCodeGen", "LLVMAArch64CodeGen", - "LLVMMSP430CodeGen", "LLVMARMCodeGen", - "LLVMMipsCodeGen", - "LLVMSparcCodeGen", - "LLVMBPFCodeGen", - "LLVMHexagonCodeGen", - "LLVMAMDGPUCodeGen", - "LLVMRISCVCodeGen", - "LLVMWebAssemblyCodeGen", - "LLVMSystemZCodeGen", "LLVMCodeGen", "LLVMX86CodeGen", - "LLVMLanaiCodeGen", "LLVMX86AsmParser", - "LLVMAMDGPUUtils", - "LLVMRISCVUtils", "LLVMTransformUtils", "LLVMAArch64Utils", "LLVMARMUtils", @@ -163,8 +115,8 @@ host_unittest_action("StubOptimizerTest") { deps = [ "$ark_root/libpandabase:libarkbase", "$ark_root/runtime:libarkruntime", - "//ark/js_runtime:libark_jsruntime_test", "//ark/js_runtime/ecmascript/compiler:libark_jsoptimizer(${host_toolchain})", + "//third_party/googletest:gtest_main", sdk_libc_secshared_dep, ] } diff --git a/ecmascript/compiler/tests/stub_optimizer_tests.cpp b/ecmascript/compiler/tests/stub_optimizer_tests.cpp index 165e90c9a1b77a86d70770f786f1da9590f776e5..0e56d35c97f012bb054d31b034ff24857fc3f72d 100644 --- a/ecmascript/compiler/tests/stub_optimizer_tests.cpp +++ b/ecmascript/compiler/tests/stub_optimizer_tests.cpp @@ -14,13 +14,13 @@ */ #include -#include #include #include "gtest/gtest.h" #include "ecmascript/compiler/fastpath_optimizer.h" #include "ecmascript/compiler/llvm_ir_builder.h" #include "ecmascript/compiler/llvm_mcjit_compiler.h" +#include "ecmascript/compiler/llvm_stackmap_parse.h" #include "ecmascript/compiler/scheduler.h" #include "ecmascript/compiler/stub_interface.h" #include "ecmascript/ecma_vm.h" @@ -30,7 +30,9 @@ #include "ecmascript/tests/test_helper.h" #include "llvm/IR/Instructions.h" +#include "llvm/IRReader/IRReader.h" #include "llvm/Support/Host.h" +#include "llvm/Support/SourceMgr.h" namespace panda::test { using namespace panda::coretypes; @@ -100,8 +102,8 @@ HWTEST_F_L0(StubOptimizerTest, FastLoadElement) // 6 : size of array auto valUndefine = fn(arr, 6); EXPECT_EQ(valUndefine, 0xa); - std::cout << "valValid = " << std::hex << valValid << std::endl; - std::cout << "valUndefine = " << std::hex << valUndefine << std::endl; + std::cerr << "valValid = " << std::hex << valValid << std::endl; + std::cerr << "valUndefine = " << std::hex << valUndefine << std::endl; } class StubPhiOptimizer : public StubOptimizer { @@ -1089,12 +1091,12 @@ public: void GenerateCircuit() override { auto env = GetEnvironment(); - AddrShift thread = PtrArgument(0); - AddrShift elements = PtrArgument(1); - AddrShift index = Int32Argument(2); - AddrShift isDict = Int32Argument(3); - AddrShift attr = PtrArgument(4); - AddrShift indexOrEntry = PtrArgument(5); + AddrShift thread = PtrArgument(0); // 0 : 1st para + AddrShift elements = PtrArgument(1); // 1 : 2nd para + AddrShift index = Int32Argument(2); // 2 : 3rd para + AddrShift isDict = Int32Argument(3); // 3 : 4th para + AddrShift attr = PtrArgument(4); // 4: 5th para + AddrShift indexOrEntry = PtrArgument(5); // 5: 6th para isDict = ZExtInt1ToInt32(isDict); Label notDictionary(env); Label isDictionary(env); @@ -1449,30 +1451,9 @@ int RuntimeFunc2(struct ThreadTy *fpInfo) auto rbp = reinterpret_cast(fpInfo->fp); std::cout << " RuntimeFunc2 rbp:" << rbp <(*gcFp); - std::cout << std::hex << "frameType :" << *frameType << " gcFp:" << *gcFp << std::endl; - } while (*gcFp != 0); - std::cout << "+++++++++++++++++walkback++++++++++++++++" << std::endl; - std::cout << "call RuntimeFunc2 func ThreadTy fp: " << fpInfo->fp << " magic:" << fpInfo->magic << std::endl; - std::cout << "RuntimeFunc2 +" << std::endl; return 0; } } @@ -1862,18 +1843,18 @@ void DoSafepoint() { uintptr_t *rbp; asm("mov %%rbp, %0" : "=rm" (rbp)); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { // 3: call back depth uintptr_t returnAddr = *(rbp + 1); - uintptr_t *rsp = rbp + 2; + uintptr_t *rsp = rbp + 2; // move 2 steps from rbp to get rsp rbp = reinterpret_cast(*rbp); DwarfRegAndOffsetType info; bool found = LLVMStackMapParse::GetInstance().StackMapByAddr(returnAddr, info); if (found) { uintptr_t **address = nullptr; - if (info.first == 7) { + if (info.first == 7) { // 7: x86_64 dwarf register num, representing rsp address = reinterpret_cast(reinterpret_cast(rsp) + info.second); // rbp - } else if (info.first == 6) { + } else if (info.first == 6) { // 6: x86_64 dwarf register num, representing rbp address = reinterpret_cast(reinterpret_cast(rbp) + info.second); } std::cout << std::hex << "ref addr:" << address; diff --git a/ecmascript/compiler/verifier.cpp b/ecmascript/compiler/verifier.cpp index ef13d9f3fefb45d2c9fcb846ec393c6d4c4b5c8c..66749c8bee4399e67c0d0fafb4af75704736931c 100644 --- a/ecmascript/compiler/verifier.cpp +++ b/ecmascript/compiler/verifier.cpp @@ -15,6 +15,7 @@ #include "ecmascript/compiler/verifier.h" +#include #include #include "ecmascript/compiler/scheduler.h" diff --git a/js_runtime_config.gni b/js_runtime_config.gni index e84b65566cfdab7f623b2c66c703be50a6092046..ea4700b46133793ad282302c26840b97d036cd91 100644 --- a/js_runtime_config.gni +++ b/js_runtime_config.gni @@ -13,6 +13,7 @@ ark_root = "//ark/runtime_core" js_root = "//ark/js_runtime" +compile_llvm_online = false # For OpenHarmony build, always link with the static lib: sdk_libc_secshared_dep = "//utils/native/base:utilsecurec"