From 6a74ec27c8f9c0bd482bba14dd07a17746dd0fa5 Mon Sep 17 00:00:00 2001 From: zhangyinlu <7601995+solaris011@user.noreply.gitee.com> Date: Thu, 8 Feb 2024 16:49:59 +0800 Subject: [PATCH] add methods range and litecg options Signed-off-by: zhangyinlu Change-Id: Id1cd6dbd9b6a831c4586940547228d8f39851810 --- .../compiler/codegen/maple/litecg_codegen.cpp | 5 ++-- .../compiler/codegen/maple/litecg_codegen.h | 3 ++- .../codegen/maple/maple_be/include/cg/cgbb.h | 15 ------------ .../maple/maple_be/include/cg/cgfunc.h | 13 ++++++++-- .../maple/maple_be/include/litecg/litecg.h | 2 +- .../src/cg/aarch64/aarch64_cgfunc.cpp | 1 - .../codegen/maple/maple_be/src/cg/cg_cfg.cpp | 4 ++++ .../maple/maple_be/src/litecg/litecg.cpp | 10 +++++--- ecmascript/compiler/compilation_driver.cpp | 6 +++-- ecmascript/compiler/compilation_driver.h | 23 +++++++++++++----- ecmascript/compiler/file_generators.cpp | 6 ++--- ecmascript/compiler/pass_manager.cpp | 6 +++-- ecmascript/js_runtime_options.cpp | 17 +++++++++++-- ecmascript/js_runtime_options.h | 24 +++++++++++++++++++ 14 files changed, 95 insertions(+), 40 deletions(-) diff --git a/ecmascript/compiler/codegen/maple/litecg_codegen.cpp b/ecmascript/compiler/codegen/maple/litecg_codegen.cpp index 9f8aef571c..d608310e67 100644 --- a/ecmascript/compiler/codegen/maple/litecg_codegen.cpp +++ b/ecmascript/compiler/codegen/maple/litecg_codegen.cpp @@ -39,7 +39,8 @@ class CompilerLog; using namespace panda::ecmascript; -LiteCGAssembler::LiteCGAssembler(LMIRModule &module) : lmirModule(module) {} +LiteCGAssembler::LiteCGAssembler(LMIRModule &module, const std::vector &litecgOptions) + : lmirModule(module), litecgOptions(litecgOptions) {} static uint8_t *AllocateCodeSection(void *object, uint32_t size, [[maybe_unused]] uint32_t alignment, const std::string §ionName) @@ -80,7 +81,7 @@ void SavePC2CallSiteInfo(void *object, uint64_t pc, std::vector callSi void LiteCGAssembler::Run(const CompilerLog &log, [[maybe_unused]] bool fastCompileMode) { - maple::litecg::LiteCG liteCG(*lmirModule.GetModule()); + maple::litecg::LiteCG liteCG(*lmirModule.GetModule(), litecgOptions); if (log.OutputLLIR()) { std::string irFileName = lmirModule.GetModule()->GetFileName() + ".mpl"; liteCG.DumpIRToFile(irFileName); diff --git a/ecmascript/compiler/codegen/maple/litecg_codegen.h b/ecmascript/compiler/codegen/maple/litecg_codegen.h index e23e401985..a93343d997 100644 --- a/ecmascript/compiler/codegen/maple/litecg_codegen.h +++ b/ecmascript/compiler/codegen/maple/litecg_codegen.h @@ -25,13 +25,14 @@ class CompilerLog; class LiteCGAssembler : public Assembler { public: - explicit LiteCGAssembler(LMIRModule &module); + explicit LiteCGAssembler(LMIRModule &module, const std::vector &litecgOptions); virtual ~LiteCGAssembler() = default; void Run(const CompilerLog &log, bool fastCompileMode) override; void CollectAnStackMap(CGStackMapInfo &stackMapInfo); private: LMIRModule &lmirModule; + const std::vector &litecgOptions; }; class LiteCGIRGeneratorImpl : public CodeGeneratorImpl { diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgbb.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgbb.h index 4abe4c0ea4..294c6a8764 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgbb.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgbb.h @@ -279,21 +279,6 @@ public: return static_cast(succs.size()); } - void UniqueSuccs() - { - for (auto i = succs.begin(); i != succs.end(); ++i) { - auto j = ++i; - --i; - while (j != succs.end()) { - if (*i == *j) { - j = succs.erase(j); - } else { - ++j; - } - } - } - } - bool HasCall() const { return hasCall; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgfunc.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgfunc.h index 35dbb1da96..cd02f96421 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgfunc.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgfunc.h @@ -1623,11 +1623,20 @@ public: return exitBBLost; } + void SetHasBuiltCfg(bool hasBuilt) + { + hasBuiltCfg = hasBuilt; + } + + bool HasBuiltCfg() const + { + return hasBuiltCfg; + } + bool GetWithSrc() const { return withSrc; } - protected: uint32 firstMapleIrVRegNO = 200; /* positioned after physical regs */ uint32 firstNonPregVRegNO; @@ -1848,7 +1857,7 @@ private: bool hasAsm = false; bool useFP = true; bool seenFP = true; - + bool hasBuiltCfg = false; bool isStackMapComputed = false; /* save stack protect kinds which can trigger stack protect */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/litecg/litecg.h b/ecmascript/compiler/codegen/maple/maple_be/include/litecg/litecg.h index a1ef1b12dd..16e32c7243 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/litecg/litecg.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/litecg/litecg.h @@ -41,7 +41,7 @@ enum InfoType { kQuiet, kVerbose }; class LiteCG { public: - LiteCG(Module &mirModule); + LiteCG(Module &mirModule, const std::vector &litecgOptions); ~LiteCG() = default; // configurations API. diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 7995dc49b2..caea3c3e04 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -11445,7 +11445,6 @@ void AArch64CGFunc::InsertJumpPad(Insn *insn) if (bb->GetKind() == BB::kBBGoto) { return; } - bb->UniqueSuccs(); DEBUG_ASSERT(bb->NumSuccs() == k2ByteSize, "if bb should have 2 successors"); BB *longBrBB = CreateNewBB(); diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_cfg.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_cfg.cpp index 4980bf208f..408dd34289 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_cfg.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_cfg.cpp @@ -49,6 +49,9 @@ bool CanBBThrow(const BB &bb) namespace maplebe { void CGCFG::BuildCFG() { + if (cgFunc->HasBuiltCfg()) { + return; + } /* * Second Pass: * Link preds/succs in the BBs @@ -161,6 +164,7 @@ void CGCFG::BuildCFG() } } FindAndMarkUnreachable(*cgFunc); + cgFunc->SetHasBuiltCfg(true); } void CGCFG::CheckCFG() diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/litecg/litecg.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/litecg/litecg.cpp index 22f079dac3..a7d3111826 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/litecg/litecg.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/litecg/litecg.cpp @@ -22,7 +22,7 @@ #include "maple_phase.h" #include "cg_phasemanager.h" #include "triple.h" -#include +#include "driver_options.h" namespace maple { @@ -30,11 +30,15 @@ namespace litecg { using namespace maplebe; -LiteCG::LiteCG(Module &mirModule) : module(mirModule) +LiteCG::LiteCG(Module &mirModule, const std::vector &litecgOptions) : module(mirModule) { // Create CGOption: set up default options // should we make CGOptions local? cgOptions = &CGOptions::GetInstance(); + if (!litecgOptions.empty()) { + maplecl::CommandLine::GetCommandLine().Parse(litecgOptions, cgCategory); + cgOptions->SolveOptions(false); + } cgOptions->EnableLiteCG(); cgOptions->SetEmitFileType("obj"); cgOptions->SetQuiet(true); @@ -107,7 +111,7 @@ LiteCG &LiteCG::SetupLiteCGEmitMemoryManager( void LiteCG::DoCG() { - bool timePhases = false; + bool timePhases = cgOptions->IsEnableTimePhases(); MPLTimer timer; if (timePhases) { timer.Start(); diff --git a/ecmascript/compiler/compilation_driver.cpp b/ecmascript/compiler/compilation_driver.cpp index 9aeaa3ad45..31c76ba51a 100644 --- a/ecmascript/compiler/compilation_driver.cpp +++ b/ecmascript/compiler/compilation_driver.cpp @@ -29,7 +29,8 @@ CompilationDriver::CompilationDriver(PGOProfilerDecoder &profilerDecoder, LOptions *lOptions, CompilerLog *log, bool outputAsm, - size_t maxMethodsInModule) + size_t maxMethodsInModule, + const std::pair &compilerMethodsRange) : vm_(collector->GetVM()), jsPandaFile_(collector->GetJSPandaFile()), pfDecoder_(profilerDecoder), @@ -41,7 +42,8 @@ CompilationDriver::CompilationDriver(PGOProfilerDecoder &profilerDecoder, lOptions_(lOptions), log_(log), outputAsm_(outputAsm), - maxMethodsInModule_(maxMethodsInModule) + maxMethodsInModule_(maxMethodsInModule), + optionMethodsRange_(compilerMethodsRange) { vm_->GetJSThread()->GetCurrentEcmaContext()->GetTSManager()->SetCompilationDriver(this); diff --git a/ecmascript/compiler/compilation_driver.h b/ecmascript/compiler/compilation_driver.h index b2439e302b..174a58dd17 100644 --- a/ecmascript/compiler/compilation_driver.h +++ b/ecmascript/compiler/compilation_driver.h @@ -36,7 +36,8 @@ public: LOptions *lOptions, CompilerLog *log, bool outputAsm, - size_t maxMethodsInModule); + size_t maxMethodsInModule, + const std::pair &compilerMethodsRange); virtual ~CompilationDriver(); NO_COPY_SEMANTIC(CompilationDriver); @@ -116,7 +117,8 @@ public: auto &methodPcInfo = methodPcInfos[methodInfo.GetMethodPcInfoIndex()]; auto methodLiteral = jsPandaFile_->FindMethodLiteral(compilingMethod); const std::string methodName(MethodLiteral::GetMethodName(jsPandaFile_, methodLiteral->GetMethodId())); - if (FilterMethod(bytecodeInfo_.GetRecordName(index), methodLiteral, methodPcInfo, methodName)) { + if (FilterMethod(bytecodeInfo_.GetRecordName(index), methodLiteral, methodPcInfo, methodName) || + OutCompiledMethodsRange()) { bytecodeInfo_.AddSkippedMethod(compilingMethod); } else { if (!methodInfo.IsCompiled()) { @@ -334,6 +336,13 @@ protected: UpdateResolveDepends(importNames, needUpdateCompile); } + bool OutCompiledMethodsRange() + { + static uint32_t compiledMethodsCount = 0; + ++compiledMethodsCount; + return compiledMethodsCount < optionMethodsRange_.first || optionMethodsRange_.second <= compiledMethodsCount; + } + bool FilterMethod(const CString &recordName, const MethodLiteral *methodLiteral, const MethodPcInfo &methodPCInfo, const std::string &methodName) const; @@ -365,6 +374,7 @@ protected: CompilerLog *log_ {nullptr}; bool outputAsm_ {false}; size_t maxMethodsInModule_ {0}; + std::pair optionMethodsRange_ {0, UINT32_MAX}; }; class JitCompilationDriver : public CompilationDriver { @@ -379,10 +389,11 @@ public: LOptions *lOptions, CompilerLog *log, bool outputAsm, - size_t maxMethodsInModule) : CompilationDriver(profilerDecoder, collector, - compilemMethodsOption, compileSkipMethodsOption, - fileGenerator, fileName, triple, lOptions, log, - outputAsm, maxMethodsInModule) { }; + size_t maxMethodsInModule, + const std::pair &compilerMethodsRange) + : CompilationDriver(profilerDecoder, collector, compilemMethodsOption, compileSkipMethodsOption, + fileGenerator, fileName, triple, lOptions, log, outputAsm, maxMethodsInModule, + compilerMethodsRange) { }; ~JitCompilationDriver() = default; bool RunCg(); Module *GetModule(); diff --git a/ecmascript/compiler/file_generators.cpp b/ecmascript/compiler/file_generators.cpp index db57885dbf..72f513d666 100644 --- a/ecmascript/compiler/file_generators.cpp +++ b/ecmascript/compiler/file_generators.cpp @@ -437,7 +437,7 @@ Module* AOTFileGenerator::AddModule(const std::string &name, const std::string & #ifdef COMPILE_MAPLE if (useLiteCG_) { LMIRModule *irModule = new LMIRModule(vm_->GetNativeAreaAllocator(), name, logDebug, triple, isJit); - LiteCGAssembler* ass = new LiteCGAssembler(*irModule); + LiteCGAssembler *ass = new LiteCGAssembler(*irModule, vm_->GetJSOptions().GetCompilerCodegenOptions()); modulePackage_.emplace_back(Module(irModule, ass)); if (stackMapInfo_ == nullptr) { stackMapInfo_ = new LiteCGStackMapInfo(); @@ -445,8 +445,8 @@ Module* AOTFileGenerator::AddModule(const std::string &name, const std::string & return &modulePackage_.back(); } #endif - LLVMModule* m = new LLVMModule(vm_->GetNativeAreaAllocator(), name, logDebug, triple); - LLVMAssembler* ass = new LLVMAssembler(m, option); + LLVMModule *m = new LLVMModule(vm_->GetNativeAreaAllocator(), name, logDebug, triple); + LLVMAssembler *ass = new LLVMAssembler(m, option); modulePackage_.emplace_back(Module(m, ass)); if (stackMapInfo_ == nullptr) { stackMapInfo_ = new LLVMStackMapInfo(); diff --git a/ecmascript/compiler/pass_manager.cpp b/ecmascript/compiler/pass_manager.cpp index 3c6c4d5a59..acd8442e62 100644 --- a/ecmascript/compiler/pass_manager.cpp +++ b/ecmascript/compiler/pass_manager.cpp @@ -50,7 +50,8 @@ bool JitPassManager::Compile(JSHandle &jsFunction, AOTFileGenerator lOptions_, log_, log_->OutputASM(), - maxMethodsInModule_); + maxMethodsInModule_, + vm_->GetJSOptions().GetCompilerMethodsRange()); cmpDriver_->CompileMethod(jsFunction, [this, &fileName] (const CString recordName, const std::string &methodName, MethodLiteral *methodLiteral, @@ -211,7 +212,8 @@ bool PassManager::Compile(JSPandaFile *jsPandaFile, const std::string &fileName, &lOptions, log_, log_->OutputASM(), - maxMethodsInModule_); + maxMethodsInModule_, + vm_->GetJSOptions().GetCompilerMethodsRange()); cmpDriver.Run([this, &fileName, &collector](const CString recordName, const std::string &methodName, diff --git a/ecmascript/js_runtime_options.cpp b/ecmascript/js_runtime_options.cpp index 00169cbe2e..f945af67bc 100644 --- a/ecmascript/js_runtime_options.cpp +++ b/ecmascript/js_runtime_options.cpp @@ -163,9 +163,12 @@ const std::string PUBLIC_API HELP_OPTION_MSG = "--compiler-enable-jit: Enable jit: Default: 'false'\n" "--compiler-jit-hotness-threshold: Set hotness threshold for jit. Default: '2'\n" "--compiler-force-jit-compile-main: Enable jit compile main function: Default: 'false'\n" - "--compiler-trace-jit: Enable trace jit: Default: 'false'\n\n" + "--compiler-trace-jit: Enable trace jit: Default: 'false'\n" "--compiler-typed-op-profiler: Enable Typed Opcode Statistics for aot runtime. Default: 'false'\n" - "--compiler-opt-branch-profiling: Enable branch profiling for aot compiler. Default: 'true'\n"; + "--compiler-opt-branch-profiling: Enable branch profiling for aot compiler. Default: 'true'\n" + "--compiler-methods-range: Enable aot compiler to compile only in-range methods." + " Default: '0:4294967295'\n" + "--compiler-codegen-options: Compile options passed to codegen. Default: ''\n\n"; bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv) { @@ -272,6 +275,8 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv) {"compiler-force-jit-compile-main", required_argument, nullptr, OPTION_COMPILER_FORCE_JIT_COMPILE_MAIN}, {"compiler-typed-op-profiler", required_argument, nullptr, OPTION_COMPILER_TYPED_OP_PROFILER}, {"compiler-opt-branch-profiling", required_argument, nullptr, OPTION_COMPILER_OPT_BRANCH_PROFILING}, + {"compiler-methods-range", required_argument, nullptr, OPTION_COMPILER_METHODS_RANGE}, + {"compiler-codegen-options", required_argument, nullptr, OPTION_COMPILER_CODEGEN_OPT}, {nullptr, 0, nullptr, 0}, }; @@ -964,6 +969,14 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv) return false; } break; + case OPTION_COMPILER_METHODS_RANGE: + ParseListArgParam(optarg, &argListStr, COLON); + SetCompilerMethodsRange(&argListStr); + break; + case OPTION_COMPILER_CODEGEN_OPT: + ParseListArgParam(optarg, &argListStr, " "); + SetCompilerCodegenOptions(argListStr); + break; default: LOG_ECMA(ERROR) << "Invalid option\n"; return false; diff --git a/ecmascript/js_runtime_options.h b/ecmascript/js_runtime_options.h index bef3a6c5df..0906ff502f 100644 --- a/ecmascript/js_runtime_options.h +++ b/ecmascript/js_runtime_options.h @@ -163,6 +163,8 @@ enum CommandValues { OPTION_ENABLE_ELEMENTSKIND, OPTION_COMPILER_TYPED_OP_PROFILER, OPTION_COMPILER_OPT_BRANCH_PROFILING, + OPTION_COMPILER_METHODS_RANGE, + OPTION_COMPILER_CODEGEN_OPT, }; class PUBLIC_API JSRuntimeOptions { @@ -1451,6 +1453,26 @@ public: enableBranchProfiling_ = value; } + void SetCompilerMethodsRange(arg_list_t *argListStr) + { + compileMethodsRange_.first = std::stoull((*argListStr)[0]); + compileMethodsRange_.second = std::stoull((*argListStr)[1]); + } + + const std::pair &GetCompilerMethodsRange() const + { + return compileMethodsRange_; + } + + void SetCompilerCodegenOptions(arg_list_t argListStr) + { + compileCodegenOption_ = std::move(argListStr); + } + + const arg_list_t &GetCompilerCodegenOptions() const + { + return compileCodegenOption_; + } private: static bool StartsWith(const std::string &haystack, const std::string &needle) { @@ -1570,6 +1592,8 @@ private: bool enableLiteCG_ {false}; bool enableTypedOpProfiler_ {false}; bool enableBranchProfiling_ {true}; + std::pair compileMethodsRange_ {0, UINT32_MAX}; + arg_list_t compileCodegenOption_ {{""}}; }; } // namespace panda::ecmascript -- Gitee