mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-06 23:54:03 +00:00
回退 'Pull Request !8360 : Use multiple threads to compile stub.an'
This commit is contained in:
parent
5ff7ebbefc
commit
5cade79900
@ -82,37 +82,28 @@ void Module::CollectAnStackMapDes(ModuleSectionDes& des, uint64_t textOffset,
|
||||
des.EraseSec(ElfSecName::LLVM_STACKMAP);
|
||||
}
|
||||
|
||||
std::vector<uintptr_t> Module::GetFuncEntryPoints()
|
||||
void Module::CollectFuncEntryInfo(std::map<uintptr_t, std::string> &addr2name, StubFileInfo &stubInfo,
|
||||
uint32_t moduleIndex, const CompilerLog &log)
|
||||
{
|
||||
std::vector<uintptr_t> entrys;
|
||||
if (irModule_->GetModuleKind() != MODULE_LLVM) {
|
||||
std::cout << "GetFuncEntryPoints is not supported for litecg currently" << std::endl;
|
||||
return entrys;
|
||||
std::cout << "CollectFuncEntryInfo is not supported for litecg currently" << std::endl;
|
||||
return;
|
||||
}
|
||||
LLVMModule *llvmModule = static_cast<LLVMModule *>(irModule_);
|
||||
LLVMAssembler *assembler = static_cast<LLVMAssembler *>(assembler_);
|
||||
LLVMModule *llvmModule = static_cast<LLVMModule*>(irModule_);
|
||||
LLVMAssembler *assembler = static_cast<LLVMAssembler*>(assembler_);
|
||||
auto engine = assembler->GetEngine();
|
||||
|
||||
auto callSigns = llvmModule->GetCSigns();
|
||||
std::vector<uintptr_t> entrys;
|
||||
for (size_t j = 0; j < llvmModule->GetFuncCount(); j++) {
|
||||
LLVMValueRef func = llvmModule->GetFunction(j);
|
||||
ASSERT(func != nullptr);
|
||||
uintptr_t entry = reinterpret_cast<uintptr_t>(LLVMGetPointerToGlobal(engine, func));
|
||||
entrys.push_back(entry);
|
||||
}
|
||||
return entrys;
|
||||
}
|
||||
|
||||
void Module::CollectFuncEntryInfo(const std::vector<uintptr_t>& entrys, std::map<uintptr_t, std::string> &addr2name,
|
||||
StubFileInfo &stubInfo, uint32_t moduleIndex, const CompilerLog &log)
|
||||
{
|
||||
LLVMModule *llvmModule = static_cast<LLVMModule*>(irModule_);
|
||||
LLVMAssembler *assembler = static_cast<LLVMAssembler*>(assembler_);
|
||||
auto codeBuff = assembler->GetSectionAddr(ElfSecName::TEXT);
|
||||
auto callSigns = llvmModule->GetCSigns();
|
||||
const size_t funcCount = entrys.size();
|
||||
const size_t funcCount = llvmModule->GetFuncCount();
|
||||
funcCount_ = funcCount;
|
||||
startIndex_ = stubInfo.GetEntrySize();
|
||||
|
||||
for (size_t j = 0; j < funcCount; j++) {
|
||||
auto cs = callSigns[j];
|
||||
LLVMValueRef func = llvmModule->GetFunction(j);
|
||||
@ -366,31 +357,8 @@ void StubFileGenerator::CollectAsmStubCodeInfo(std::map<uintptr_t, std::string>
|
||||
void StubFileGenerator::CollectCodeInfo()
|
||||
{
|
||||
std::map<uintptr_t, std::string> stubAddr2Name;
|
||||
std::vector<std::vector<uintptr_t>> entryPoints(modulePackage_.size());
|
||||
|
||||
if (!concurrentCompile_) {
|
||||
for (size_t i = 0; i < modulePackage_.size(); ++i) {
|
||||
entryPoints[i] = modulePackage_[i].GetFuncEntryPoints();
|
||||
}
|
||||
} else if (!modulePackage_.empty()) {
|
||||
// For first module, run it in current thread.
|
||||
// For others, run them in child threads and wait for finish.
|
||||
std::vector<std::thread> threads;
|
||||
for (size_t i = 1; i < modulePackage_.size(); ++i) {
|
||||
threads.emplace_back([&, i]() {
|
||||
entryPoints[i] = modulePackage_[i].GetFuncEntryPoints();
|
||||
});
|
||||
}
|
||||
entryPoints[0] = modulePackage_[0].GetFuncEntryPoints();
|
||||
for (auto& t : threads) {
|
||||
if (t.joinable()) {
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < modulePackage_.size(); ++i) {
|
||||
modulePackage_[i].CollectFuncEntryInfo(entryPoints[i], stubAddr2Name, stubInfo_, i, GetLog());
|
||||
for (size_t i = 0; i < modulePackage_.size(); i++) {
|
||||
modulePackage_[i].CollectFuncEntryInfo(stubAddr2Name, stubInfo_, i, GetLog());
|
||||
ModuleSectionDes des;
|
||||
modulePackage_[i].CollectModuleSectionDes(des);
|
||||
stubInfo_.AddModuleDes(des);
|
||||
@ -518,31 +486,6 @@ Module* StubFileGenerator::AddModule(NativeAreaAllocator *allocator, const std::
|
||||
return &modulePackage_.back();
|
||||
}
|
||||
|
||||
void StubFileGenerator::RunLLVMAssembler()
|
||||
{
|
||||
if (!concurrentCompile_) {
|
||||
for (auto &m: modulePackage_) {
|
||||
m.RunAssembler(*(this->log_), false);
|
||||
}
|
||||
} else if (!modulePackage_.empty()) {
|
||||
// For first module, run it in current thread.
|
||||
// For others, run them in child threads and wait for finish.
|
||||
std::vector<std::thread> threads;
|
||||
for (size_t i = 1; i < modulePackage_.size(); ++i) {
|
||||
const CompilerLog &log = *(this->log_);
|
||||
threads.emplace_back([&, i] {
|
||||
modulePackage_[i].RunAssembler(log, false);
|
||||
});
|
||||
}
|
||||
modulePackage_[0].RunAssembler(*(this->log_), false);
|
||||
for (auto& t : threads) {
|
||||
if (t.joinable()) {
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StubFileGenerator::RunAsmAssembler()
|
||||
{
|
||||
NativeAreaAllocator allocator;
|
||||
|
@ -37,10 +37,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<uintptr_t> GetFuncEntryPoints();
|
||||
|
||||
void CollectFuncEntryInfo(const std::vector<uintptr_t>& entrys, std::map<uintptr_t, std::string> &addr2name,
|
||||
StubFileInfo &stubInfo, uint32_t moduleIndex, const CompilerLog &log);
|
||||
void CollectFuncEntryInfo(std::map<uintptr_t, std::string> &addr2name, StubFileInfo &stubInfo,
|
||||
uint32_t moduleIndex, const CompilerLog &log);
|
||||
|
||||
void CollectFuncEntryInfo(std::map<uintptr_t, std::string> &addr2name, AnFileInfo &aotInfo, uint32_t fileIndex,
|
||||
uint32_t moduleIndex, const CompilerLog &log);
|
||||
@ -161,7 +159,7 @@ protected:
|
||||
const MethodLogList *logList_ {nullptr};
|
||||
std::ostringstream codeStream_;
|
||||
|
||||
virtual void RunLLVMAssembler()
|
||||
void RunLLVMAssembler()
|
||||
{
|
||||
for (auto m : modulePackage_) {
|
||||
m.RunAssembler(*(log_), false);
|
||||
@ -245,11 +243,9 @@ enum class StubFileKind {
|
||||
|
||||
class StubFileGenerator : public FileGenerator {
|
||||
public:
|
||||
StubFileGenerator(const CompilerLog* log, const MethodLogList* logList, const std::string& triple,
|
||||
bool concurrentCompile)
|
||||
StubFileGenerator(const CompilerLog *log, const MethodLogList *logList, const std::string &triple)
|
||||
: FileGenerator(log, logList),
|
||||
cfg_(triple),
|
||||
concurrentCompile_(concurrentCompile)
|
||||
cfg_(triple)
|
||||
{
|
||||
}
|
||||
~StubFileGenerator() override = default;
|
||||
@ -268,8 +264,7 @@ public:
|
||||
void DisassembleAsmStubs(std::map<uintptr_t, std::string> &addr2name);
|
||||
// save function funcs for aot files containing stubs
|
||||
void SaveStubFile(const std::string &filename);
|
||||
protected:
|
||||
void RunLLVMAssembler() override;
|
||||
|
||||
private:
|
||||
void RunAsmAssembler();
|
||||
void CollectAsmStubCodeInfo(std::map<uintptr_t, std::string> &addr2name, uint32_t bridgeModuleIdx);
|
||||
@ -279,7 +274,6 @@ private:
|
||||
AssemblerModule asmModule_;
|
||||
CompilationConfig cfg_;
|
||||
CodeInfo::CodeSpaceOnDemand jitCodeSpace_ {};
|
||||
bool concurrentCompile_ {false};
|
||||
};
|
||||
} // namespace panda::ecmascript::kungfu
|
||||
#endif // ECMASCRIPT_COMPILER_FILE_GENERATORS_H
|
||||
|
@ -136,7 +136,7 @@ bool StubCompiler::BuildStubModuleAndSave() const
|
||||
MethodLogList *logList = GetLogList();
|
||||
|
||||
NativeAreaAllocator allocator;
|
||||
StubFileGenerator generator(log, logList, triple_, concurrentCompile_);
|
||||
StubFileGenerator generator(log, logList, triple_);
|
||||
|
||||
LOG_COMPILER(INFO) << "=============== compiling bytecode handler stubs ===============";
|
||||
LOptions stubOp(optLevel_, FPFlag::ELIM_FP, relocMode_);
|
||||
@ -205,12 +205,10 @@ int main(const int argc, const char **argv)
|
||||
size_t relocMode = runtimeOptions.GetRelocMode();
|
||||
std::string logOption = runtimeOptions.GetCompilerLogOption();
|
||||
std::string methodsList = runtimeOptions.GetMethodsListForLog();
|
||||
bool concurrentCompile = runtimeOptions.IsConcurrentCompile();
|
||||
|
||||
panda::ecmascript::kungfu::CompilerLog logOpt(logOption);
|
||||
panda::ecmascript::kungfu::MethodLogList logList(methodsList);
|
||||
panda::ecmascript::kungfu::StubCompiler compiler(triple, stubFile, optLevel, relocMode, &logOpt, &logList,
|
||||
concurrentCompile);
|
||||
panda::ecmascript::kungfu::StubCompiler compiler(triple, stubFile, optLevel, relocMode, &logOpt, &logList);
|
||||
|
||||
bool res = compiler.BuildStubModuleAndSave();
|
||||
LOG_COMPILER(INFO) << "stub compiler run finish, result condition(T/F):" << std::boolalpha << res;
|
||||
|
@ -25,14 +25,13 @@ namespace panda::ecmascript::kungfu {
|
||||
class StubCompiler {
|
||||
public:
|
||||
StubCompiler(std::string &triple, std::string &filePath, size_t optLevel, size_t relocMode,
|
||||
CompilerLog *log, MethodLogList *logList, bool concurrentCompile)
|
||||
CompilerLog *log, MethodLogList *logList)
|
||||
: triple_(triple),
|
||||
filePath_(filePath),
|
||||
optLevel_(optLevel),
|
||||
relocMode_(relocMode),
|
||||
log_(log),
|
||||
logList_(logList),
|
||||
concurrentCompile_(concurrentCompile)
|
||||
logList_(logList)
|
||||
{
|
||||
}
|
||||
|
||||
@ -58,7 +57,6 @@ private:
|
||||
size_t relocMode_ {2}; // 2 : default relocation mode-- PIC
|
||||
CompilerLog *log_ {nullptr};
|
||||
MethodLogList *logList_ {nullptr};
|
||||
bool concurrentCompile_ {false};
|
||||
};
|
||||
} // namespace panda::ecmascript::kungfu
|
||||
#endif // ECMASCRIPT_COMPILER_STUB_COMPILER_H
|
||||
|
@ -192,9 +192,7 @@ const std::string PUBLIC_API HELP_OPTION_MSG =
|
||||
"--compiler-enable-async-copytofort: Enable jit fort allocation and code copy in Jit thread. Default: 'true'\n"
|
||||
"--compiler-pgo-force-dump: Enable pgo dump not interrupted by GC. Default: 'true'\n"
|
||||
"--async-load-abc: Enable asynchronous load abc. Default: 'true'\n"
|
||||
"--async-load-abc-test: Enable asynchronous load abc test. Default: 'false'\n"
|
||||
"--compiler-enable-concurrent: Enable concurrent compile(only support in ark_stub_compiler). "
|
||||
" Default: 'true'\n\n";
|
||||
"--async-load-abc-test: Enable asynchronous load abc test. Default: 'false'\n\n";
|
||||
|
||||
bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
|
||||
{
|
||||
@ -328,7 +326,6 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
|
||||
{"compiler-pgo-force-dump", required_argument, nullptr, OPTION_COMPILER_PGO_FORCE_DUMP},
|
||||
{"async-load-abc", required_argument, nullptr, OPTION_ASYNC_LOAD_ABC},
|
||||
{"async-load-abc-test", required_argument, nullptr, OPTION_ASYNC_LOAD_ABC_TEST},
|
||||
{"compiler-enable-concurrent", required_argument, nullptr, OPTION_COMPILER_ENABLE_CONCURRENT},
|
||||
{nullptr, 0, nullptr, 0},
|
||||
};
|
||||
|
||||
@ -1253,14 +1250,6 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPTION_COMPILER_ENABLE_CONCURRENT:
|
||||
ret = ParseBoolParam(&argBool);
|
||||
if (ret) {
|
||||
SetConcurrentCompile(argBool);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPTION_COMPILER_PGO_FORCE_DUMP:
|
||||
ret = ParseBoolParam(&argBool);
|
||||
if (ret) {
|
||||
|
@ -204,7 +204,6 @@ enum CommandValues {
|
||||
OPTION_ASYNC_LOAD_ABC_TEST,
|
||||
OPTION_PGO_TRACE,
|
||||
OPTION_COMPILER_PGO_FORCE_DUMP,
|
||||
OPTION_COMPILER_ENABLE_CONCURRENT,
|
||||
};
|
||||
static_assert(OPTION_SPLIT_ONE == 64); // add new option at the bottom, DO NOT modify this value
|
||||
|
||||
@ -1868,15 +1867,6 @@ public:
|
||||
forceDump_ = value;
|
||||
}
|
||||
|
||||
void SetConcurrentCompile(bool value)
|
||||
{
|
||||
concurrentCompile = value;
|
||||
}
|
||||
|
||||
bool IsConcurrentCompile() const
|
||||
{
|
||||
return concurrentCompile;
|
||||
}
|
||||
public:
|
||||
static constexpr int32_t MAX_APP_COMPILE_METHOD_SIZE = 4_KB;
|
||||
|
||||
@ -2049,7 +2039,6 @@ private:
|
||||
bool asyncLoadAbc_ {true};
|
||||
bool asyncLoadAbcTest_ {false};
|
||||
bool forceDump_ {true};
|
||||
bool concurrentCompile {true};
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user