diff --git a/ecmascript/compiler/BUILD.gn b/ecmascript/compiler/BUILD.gn index 162ecd49752c6318d9b4b2138b0308f8cb666448..7d9f4fd7a9fb70bcb5e7697214bbf5f3eb6184bb 100644 --- a/ecmascript/compiler/BUILD.gn +++ b/ecmascript/compiler/BUILD.gn @@ -14,11 +14,23 @@ import("//ark/js_runtime/js_runtime_config.gni") import("//build/ohos.gni") +# llvm_debug 0:llvm lib compile; 1: llvm source debug version; 2: llvm source release version +declare_args() { + llvm_debug = 0 +} + +if (llvm_debug != 0) { action("build_llvm_libs") { - script = "build_llvm.sh" - sources = [ "//ark/js_runtime/ecmascript/compiler/build_llvm.sh" ] +if (llvm_debug == 1) { + script = "compile_llvm_debug_lib.sh" + sources = [ "//ark/js_runtime/ecmascript/compiler/compile_llvm_debug_lib.sh" ] +} else if (llvm_debug == 2) { + script = "compile_llvm_release_lib.sh" + sources = [ "//ark/js_runtime/ecmascript/compiler/compile_llvm_release_lib.sh" ] +} outputs = [ "${root_out_dir}/llvm" ] } +} config("include_llvm") { include_dirs = [ @@ -71,7 +83,6 @@ ohos_shared_library("libark_jsoptimizer") { "LLVMExecutionEngine", "LLVMInterpreter", "LLVMMCJIT", - "LLVMExegesis", "LLVMRuntimeDyld", "LLVMInstCombine", "LLVMAnalysis", @@ -172,7 +183,6 @@ ohos_shared_library("libark_jsoptimizer") { "LLVMTransformUtils", "LLVMAArch64Utils", "LLVMARMUtils", - "LLVMX86Utils", ] deps = [ diff --git a/ecmascript/compiler/compile_llvm_debug_lib.sh b/ecmascript/compiler/compile_llvm_debug_lib.sh new file mode 100755 index 0000000000000000000000000000000000000000..89139d0ef272a59ecd66e97a0db76d3c090bad15 --- /dev/null +++ b/ecmascript/compiler/compile_llvm_debug_lib.sh @@ -0,0 +1,51 @@ +# 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. + +#! /bin/bash + +set -e +echo "++++++++++++++++++++++++++++++++++" +echo "build llvm" +time=`date +'%Y%m%d%H%M%S'` +echo $time + +BIN_PATH=$(cd $(dirname $0);pwd) +JSRUNTIME_HOME=$(dirname $(dirname ${BIN_PATH})) +BASE_HOME=${JSRUNTIME_HOME}/../.. + +echo ${BIN_PATH} +echo ${BASE_HOME} + +if [ ! -d "${BASE_HOME}/third_party/llvm-project" ]; then + echo ${BASE_HOME}/third_party/llvm-project + cd ${BASE_HOME}/third_party/ + git clone https://gitee.com/github-repos/llvm-project.git +fi + +cd ${BASE_HOME}/third_party/llvm-project +if [ ! -d "build" ];then + dd if=/dev/zero of=/tmp/mem.swap bs=1M count=4096 + mkdir build && cd build + cmake -GNinja -DCMAKE_BUILD_TYPE=Debug ../llvm + ninja -j4 +else + cd build + if [ ! -d "lib" ]; then + rm -rf * + dd if=/dev/zero of=/tmp/mem.swap bs=1M count=4096 + cmake -GNinja -DCMAKE_BUILD_TYPE=Debug ../llvm + ninja -j4 + fi +fi + +echo "++++++++++++++++++++++++++++++++++" \ No newline at end of file diff --git a/ecmascript/compiler/compile_llvm_release_lib.sh b/ecmascript/compiler/compile_llvm_release_lib.sh new file mode 100755 index 0000000000000000000000000000000000000000..264bdb1b70e186a4248827f10a5f2be4b50705e2 --- /dev/null +++ b/ecmascript/compiler/compile_llvm_release_lib.sh @@ -0,0 +1,52 @@ +# 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. + +#! /bin/bash + +set -e +echo "++++++++++++++++++++++++++++++++++" +echo "build llvm" +#date +%F ' '%H:%M:%S +time=`date +'%Y%m%d%H%M%S'` +echo $time + +BIN_PATH=$(cd $(dirname $0);pwd) +JSRUNTIME_HOME=$(dirname $(dirname ${BIN_PATH})) +BASE_HOME=${JSRUNTIME_HOME}/../.. + +echo ${BIN_PATH} +echo ${BASE_HOME} + +if [ ! -d "${BASE_HOME}/third_party/llvm-project" ]; then + echo ${BASE_HOME}/third_party/llvm-project + cd ${BASE_HOME}/third_party/ + git clone https://gitee.com/github-repos/llvm-project.git +fi + +cd ${BASE_HOME}/third_party/llvm-project +if [ ! -d "build" ];then + dd if=/dev/zero of=/tmp/mem.swap bs=1M count=4096 + mkdir build && cd build + cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../llvm + ninja +else + cd build + if [ ! -d "lib" ]; then + rm -rf * + dd if=/dev/zero of=/tmp/mem.swap bs=1M count=4096 + cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../llvm + ninja + fi +fi + +echo "++++++++++++++++++++++++++++++++++" \ No newline at end of file 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..44c3e10180ead76b5d24fa83f438efae67a37d78 100644 --- a/ecmascript/compiler/llvm_stackmap_parse.h +++ b/ecmascript/compiler/llvm_stackmap_parse.h @@ -18,6 +18,7 @@ #include #include #include +#include namespace kungfu { using OffsetType = int32_t; @@ -205,7 +206,10 @@ private: const uint8_t *stackMapAddr_; struct LLVMStackMap llvmStackMap_; std::vector callSiteInfos_; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-private-field" std::unique_ptr dataInfo_; +#pragma clang diagnostic pop }; } // 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..3d3ced634e3d5fdc781474de721fb97173f9e320 100644 --- a/ecmascript/compiler/tests/BUILD.gn +++ b/ecmascript/compiler/tests/BUILD.gn @@ -55,7 +55,6 @@ host_unittest_action("StubOptimizerTest") { "LLVMExecutionEngine", "LLVMInterpreter", "LLVMMCJIT", - "LLVMExegesis", "LLVMRuntimeDyld", "LLVMInstCombine", "LLVMAnalysis", @@ -156,15 +155,14 @@ host_unittest_action("StubOptimizerTest") { "LLVMTransformUtils", "LLVMAArch64Utils", "LLVMARMUtils", - "LLVMX86Utils", "LLVMIRReader", ] deps = [ "$ark_root/libpandabase:libarkbase", "$ark_root/runtime:libarkruntime", - "//ark/js_runtime:libark_jsruntime_test", - "//ark/js_runtime/ecmascript/compiler:libark_jsoptimizer(${host_toolchain})", + "//ark/js_runtime/ecmascript/compiler:libark_jsoptimizer", + "//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..15dd41ec4fb87d621447dc583555e6a1ed14ee89 100644 --- a/ecmascript/compiler/tests/stub_optimizer_tests.cpp +++ b/ecmascript/compiler/tests/stub_optimizer_tests.cpp @@ -31,6 +31,9 @@ #include "llvm/IR/Instructions.h" #include "llvm/Support/Host.h" +#include "ecmascript/compiler/llvm_stackmap_parse.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/IRReader/IRReader.h" namespace panda::test { using namespace panda::coretypes; diff --git a/ecmascript/compiler/verifier.cpp b/ecmascript/compiler/verifier.cpp index ef13d9f3fefb45d2c9fcb846ec393c6d4c4b5c8c..53d5b0fe0b148f38753a417f56502c5d1efdc5be 100644 --- a/ecmascript/compiler/verifier.cpp +++ b/ecmascript/compiler/verifier.cpp @@ -19,6 +19,8 @@ #include "ecmascript/compiler/scheduler.h" +#include + namespace kungfu { bool Verifier::RunDataIntegrityCheck(const Circuit *circuit) {