mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
Refactor AOT compiler pipeline (part 4)
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IA65AW Signed-off-by: xwcai98 <xwcai98@gmail.com> Change-Id: I21be5d8555510406a73b272a4b1fd72550e3aadd
This commit is contained in:
parent
a5cd9294c5
commit
9d0816a70a
@ -46,22 +46,6 @@ enum ErrCode {
|
||||
ERR_MERGE_AP = (3),
|
||||
};
|
||||
|
||||
void CompileValidFiles(PassManager &passManager, AOTFileGenerator &generator, bool &ret,
|
||||
const CVector<AbcFileInfo> &fileInfos, AotCompilerStats &compilerStats)
|
||||
{
|
||||
for (const AbcFileInfo &fileInfo : fileInfos) {
|
||||
JSPandaFile *jsPandaFile = fileInfo.jsPandaFile_.get();
|
||||
const std::string &extendedFilePath = fileInfo.extendedFilePath_;
|
||||
LOG_COMPILER(INFO) << "AOT compile: " << extendedFilePath;
|
||||
generator.SetCurrentCompileFileName(jsPandaFile->GetNormalizedFileDesc());
|
||||
if (passManager.Compile(jsPandaFile, extendedFilePath, generator, compilerStats) == false) {
|
||||
ret = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool CheckVersion(JSRuntimeOptions& runtimeOptions, AotCompilerStats& compilerStats, bool isPgoMerged)
|
||||
{
|
||||
if (runtimeOptions.IsCheckPgoVersion()) {
|
||||
@ -84,6 +68,7 @@ bool IsExistsPkgInfo(AotCompilerPreprocessor &cPreprocessor)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int Main(const int argc, const char **argv)
|
||||
{
|
||||
@ -156,6 +141,7 @@ int Main(const int argc, const char **argv)
|
||||
profilerDecoder.SetInPath(cOptions.profilerIn_);
|
||||
cPreprocessor.AOTInitialize();
|
||||
uint32_t checksum = cPreprocessor.GenerateAbcFileInfos();
|
||||
ret = cPreprocessor.GetCompilerResult();
|
||||
// Notice: lx move load pandaFileHead and verify before GeneralAbcFileInfos.
|
||||
// need support multiple abc
|
||||
auto isPgoMerged = cPreprocessor.HandleMergedPgoFile(checksum);
|
||||
@ -167,11 +153,7 @@ int Main(const int argc, const char **argv)
|
||||
filesystem::CreateEmptyFile(cOptions.outputFileName_ + AOTFileManager::FILE_EXTENSION_AI);
|
||||
return ERR_MERGE_AP;
|
||||
}
|
||||
cPreprocessor.GeneratePGOTypes(cOptions);
|
||||
cPreprocessor.SnapshotInitialize();
|
||||
ret = cPreprocessor.GetCompilerResult();
|
||||
const auto &fileInfos = cPreprocessor.GetAbcFileInfo();
|
||||
cPreprocessor.GenerateMethodMap(cOptions);
|
||||
cPreprocessor.Process(cOptions);
|
||||
|
||||
PassOptions::Builder optionsBuilder;
|
||||
PassOptions passOptions =
|
||||
@ -207,7 +189,8 @@ int Main(const int argc, const char **argv)
|
||||
profilerDecoder,
|
||||
&passOptions,
|
||||
cPreprocessor.GetCallMethodFlagMap(),
|
||||
fileInfos,
|
||||
cPreprocessor.GetAbcFileInfo(),
|
||||
cPreprocessor.GetBcInfoCollectors(),
|
||||
cOptions.optBCRange_);
|
||||
|
||||
bool isEnableLiteCG = runtimeOptions.IsCompilerEnableLiteCG();
|
||||
@ -219,7 +202,7 @@ int Main(const int argc, const char **argv)
|
||||
|
||||
AOTFileGenerator generator(&log, &logList, &aotCompilationEnv, cOptions.triple_, isEnableLiteCG);
|
||||
|
||||
CompileValidFiles(passManager, generator, ret, fileInfos, compilerStats);
|
||||
passManager.CompileValidFiles(generator, ret, compilerStats);
|
||||
std::string appSignature = cPreprocessor.GetMainPkgArgsAppSignature();
|
||||
generator.SaveAOTFile(cOptions.outputFileName_ + AOTFileManager::FILE_EXTENSION_AN, appSignature);
|
||||
generator.SaveSnapshotFile();
|
||||
|
@ -167,6 +167,14 @@ void AotCompilerPreprocessor::AOTInitialize()
|
||||
RuntimeStubCSigns::Initialize();
|
||||
}
|
||||
|
||||
void AotCompilerPreprocessor::Process(CompilationOptions &cOptions)
|
||||
{
|
||||
GenerateBytecodeInfoCollectors(cOptions);
|
||||
GeneratePGOTypes();
|
||||
SnapshotInitialize();
|
||||
GenerateMethodMap(cOptions);
|
||||
}
|
||||
|
||||
uint32_t AotCompilerPreprocessor::GenerateAbcFileInfos()
|
||||
{
|
||||
size_t size = pandaFileNames_.size();
|
||||
@ -195,6 +203,17 @@ uint32_t AotCompilerPreprocessor::GenerateAbcFileInfos()
|
||||
return checksum;
|
||||
}
|
||||
|
||||
void AotCompilerPreprocessor::GenerateBytecodeInfoCollectors(const CompilationOptions &cOptions)
|
||||
{
|
||||
bcInfoCollectors_.reserve(fileInfos_.size());
|
||||
for (const AbcFileInfo &fileInfo : fileInfos_) {
|
||||
JSPandaFile *jsPandaFile = fileInfo.jsPandaFile_.get();
|
||||
auto collectorPtr = std::make_unique<BytecodeInfoCollector>(&aotCompilationEnv_, jsPandaFile,
|
||||
profilerDecoder_, cOptions.maxAotMethodSize_);
|
||||
bcInfoCollectors_.emplace_back(std::move(collectorPtr));
|
||||
}
|
||||
}
|
||||
|
||||
bool AotCompilerPreprocessor::HandleMergedPgoFile(uint32_t checksum)
|
||||
{
|
||||
return PGOProfilerManager::MergeApFiles(checksum, profilerDecoder_);
|
||||
@ -243,52 +262,46 @@ void AotCompilerPreprocessor::ResolveModule(const JSPandaFile *jsPandaFile, cons
|
||||
}
|
||||
}
|
||||
|
||||
void AotCompilerPreprocessor::RecordArrayElement(const CompilationOptions &cOptions)
|
||||
void AotCompilerPreprocessor::RecordArrayElement(const JSPandaFile* jsPandaFile, BytecodeInfoCollector& collector)
|
||||
{
|
||||
for (const AbcFileInfo &fileInfo : fileInfos_) {
|
||||
JSPandaFile *jsPandaFile = fileInfo.jsPandaFile_.get();
|
||||
PGOTypeManager *ptManager = vm_->GetJSThread()->GetCurrentEcmaContext()->GetPTManager();
|
||||
ptManager->SetCurCompilationFile(jsPandaFile);
|
||||
BytecodeInfoCollector collector(&aotCompilationEnv_, jsPandaFile, profilerDecoder_,
|
||||
cOptions.maxAotMethodSize_);
|
||||
BCInfo &bytecodeInfo = collector.GetBytecodeInfo();
|
||||
const PGOBCInfo *bcInfo = collector.GetPGOBCInfo();
|
||||
auto &methodList = bytecodeInfo.GetMethodList();
|
||||
for (const auto &method : methodList) {
|
||||
uint32_t methodOffset = method.first;
|
||||
CString recordName = MethodLiteral::GetRecordName(jsPandaFile, EntityId(methodOffset));
|
||||
auto callback = [this, ptManager, methodOffset, &recordName]
|
||||
(const uint32_t, const uint32_t, const uint32_t cpIdx) {
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSTaggedValue cp = ptManager->GetConstantPoolByMethodOffset(methodOffset);
|
||||
JSHandle<ConstantPool> constpoolHandle(thread, cp);
|
||||
JSTaggedValue unsharedCp = thread->GetCurrentEcmaContext()
|
||||
->FindOrCreateUnsharedConstpool(constpoolHandle.GetTaggedValue());
|
||||
ASSERT(ConstantPool::CheckUnsharedConstpool(unsharedCp));
|
||||
JSTaggedValue arr = ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(
|
||||
thread, unsharedCp, cpIdx, recordName);
|
||||
JSHandle<JSArray> arrayHandle(thread, arr);
|
||||
panda_file::File::EntityId id =
|
||||
ConstantPool::GetIdFromCache(constpoolHandle.GetTaggedValue(), cpIdx);
|
||||
ptManager->RecordElements(id, arrayHandle->GetElements());
|
||||
};
|
||||
PGOTypeManager *ptManager = vm_->GetJSThread()->GetCurrentEcmaContext()->GetPTManager();
|
||||
ptManager->SetCurCompilationFile(jsPandaFile);
|
||||
BCInfo &bytecodeInfo = collector.GetBytecodeInfo();
|
||||
const PGOBCInfo *bcInfo = collector.GetPGOBCInfo();
|
||||
auto &methodList = bytecodeInfo.GetMethodList();
|
||||
for (const auto &method : methodList) {
|
||||
uint32_t methodOffset = method.first;
|
||||
CString recordName = MethodLiteral::GetRecordName(jsPandaFile, EntityId(methodOffset));
|
||||
auto callback = [this, ptManager, methodOffset, &recordName]
|
||||
(const uint32_t, const uint32_t, const uint32_t cpIdx) {
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSTaggedValue cp = ptManager->GetConstantPoolByMethodOffset(methodOffset);
|
||||
JSHandle<ConstantPool> constpoolHandle(thread, cp);
|
||||
JSTaggedValue unsharedCp = thread->GetCurrentEcmaContext()
|
||||
->FindOrCreateUnsharedConstpool(constpoolHandle.GetTaggedValue());
|
||||
ASSERT(ConstantPool::CheckUnsharedConstpool(unsharedCp));
|
||||
JSTaggedValue arr = ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(
|
||||
thread, unsharedCp, cpIdx, recordName);
|
||||
JSHandle<JSArray> arrayHandle(thread, arr);
|
||||
panda_file::File::EntityId id =
|
||||
ConstantPool::GetIdFromCache(constpoolHandle.GetTaggedValue(), cpIdx);
|
||||
ptManager->RecordElements(id, arrayHandle->GetElements());
|
||||
};
|
||||
|
||||
bcInfo->IterateInfoByType(methodOffset, PGOBCInfo::Type::ARRAY_LITERAL, callback);
|
||||
}
|
||||
bcInfo->IterateInfoByType(methodOffset, PGOBCInfo::Type::ARRAY_LITERAL, callback);
|
||||
}
|
||||
}
|
||||
|
||||
void AotCompilerPreprocessor::GeneratePGOTypes(const CompilationOptions &cOptions)
|
||||
void AotCompilerPreprocessor::GeneratePGOTypes()
|
||||
{
|
||||
PGOTypeManager *ptManager = vm_->GetJSThread()->GetCurrentEcmaContext()->GetPTManager();
|
||||
for (const AbcFileInfo &fileInfo : fileInfos_) {
|
||||
JSPandaFile *jsPandaFile = fileInfo.jsPandaFile_.get();
|
||||
BytecodeInfoCollector collector(&aotCompilationEnv_, jsPandaFile, profilerDecoder_,
|
||||
cOptions.maxAotMethodSize_);
|
||||
for (uint32_t i = 0; i < fileInfos_.size(); ++i) {
|
||||
JSPandaFile *jsPandaFile = fileInfos_[i].jsPandaFile_.get();
|
||||
auto& collector = *bcInfoCollectors_[i];
|
||||
PGOTypeParser parser(profilerDecoder_, ptManager);
|
||||
parser.CreatePGOType(collector);
|
||||
RecordArrayElement(jsPandaFile, collector);
|
||||
}
|
||||
RecordArrayElement(cOptions);
|
||||
}
|
||||
|
||||
void AotCompilerPreprocessor::SnapshotInitialize()
|
||||
@ -378,12 +391,9 @@ bool AotCompilerPreprocessor::IsSkipMethod(const JSPandaFile *jsPandaFile, const
|
||||
|
||||
void AotCompilerPreprocessor::GenerateMethodMap(CompilationOptions &cOptions)
|
||||
{
|
||||
JSPandaFileManager *jsPandaFileManager = JSPandaFileManager::GetInstance();
|
||||
jsPandaFileManager->EnumerateNonVirtualJSPandaFiles(
|
||||
[this, &cOptions] (std::shared_ptr<JSPandaFile> jsPandaFilePtr) {
|
||||
JSPandaFile *jsPandaFile = jsPandaFilePtr.get();
|
||||
BytecodeInfoCollector collector(&aotCompilationEnv_, jsPandaFile, profilerDecoder_,
|
||||
cOptions.maxAotMethodSize_);
|
||||
for (uint32_t i = 0; i < fileInfos_.size(); ++i) {
|
||||
JSPandaFile *jsPandaFile = fileInfos_[i].jsPandaFile_.get();
|
||||
auto& collector = *bcInfoCollectors_[i];
|
||||
BCInfo &bytecodeInfo = collector.GetBytecodeInfo();
|
||||
const auto &methodPcInfos = bytecodeInfo.GetMethodPcInfos();
|
||||
auto &methodList = bytecodeInfo.GetMethodList();
|
||||
@ -403,8 +413,7 @@ void AotCompilerPreprocessor::GenerateMethodMap(CompilationOptions &cOptions)
|
||||
callMethodFlagMap_.SetIsFastCall(fileDesc, offset, isFastCall);
|
||||
LOG_COMPILER(INFO) <<"!!!"<< fileDesc <<" "<< offset << " " << isAotcompile << " " << isFastCall;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
std::string AotCompilerPreprocessor::GetMainPkgArgsAppSignature() const
|
||||
|
@ -112,12 +112,16 @@ public:
|
||||
bool HandlePandaFileNames(const int argc, const char **argv);
|
||||
|
||||
void AOTInitialize();
|
||||
|
||||
void Process(CompilationOptions &cOptions);
|
||||
|
||||
uint32_t GenerateAbcFileInfos();
|
||||
|
||||
void GenerateBytecodeInfoCollectors(const CompilationOptions &cOptions);
|
||||
|
||||
bool HandleMergedPgoFile(uint32_t checksum);
|
||||
|
||||
void GeneratePGOTypes(const CompilationOptions &cOptions);
|
||||
void GeneratePGOTypes();
|
||||
|
||||
void SnapshotInitialize();
|
||||
|
||||
@ -164,6 +168,11 @@ public:
|
||||
return fileInfos_;
|
||||
}
|
||||
|
||||
const CVector<std::unique_ptr<BytecodeInfoCollector>>& GetBcInfoCollectors() const
|
||||
{
|
||||
return bcInfoCollectors_;
|
||||
}
|
||||
|
||||
std::shared_ptr<OhosPkgArgs> GetMainPkgArgs() const
|
||||
{
|
||||
if (pkgsArgs_.empty()) {
|
||||
@ -198,7 +207,7 @@ private:
|
||||
|
||||
void ResolveModule(const JSPandaFile *jsPandaFile, const std::string &fileName);
|
||||
|
||||
void RecordArrayElement(const CompilationOptions &cOptions);
|
||||
void RecordArrayElement(const JSPandaFile* jsPandaFile, BytecodeInfoCollector& collector);
|
||||
|
||||
bool OutCompiledMethodsRange() const
|
||||
{
|
||||
@ -215,6 +224,7 @@ private:
|
||||
PGOProfilerDecoder &profilerDecoder_;
|
||||
arg_list_t &pandaFileNames_;
|
||||
CVector<AbcFileInfo> fileInfos_;
|
||||
CVector<std::unique_ptr<BytecodeInfoCollector>> bcInfoCollectors_;
|
||||
CallMethodFlagMap callMethodFlagMap_;
|
||||
AOTCompilationEnv aotCompilationEnv_;
|
||||
friend class OhosPkgArgs;
|
||||
|
@ -216,12 +216,26 @@ JitPassManager::~JitPassManager()
|
||||
}
|
||||
}
|
||||
|
||||
void PassManager::CompileValidFiles(AOTFileGenerator &generator, bool &ret, AotCompilerStats &compilerStats)
|
||||
{
|
||||
for (uint32_t i = 0 ; i < fileInfos_.size(); ++i) {
|
||||
JSPandaFile *jsPandaFile = fileInfos_[i].jsPandaFile_.get();
|
||||
auto &collector = *bcInfoCollectors_[i];
|
||||
const std::string &extendedFilePath = fileInfos_[i].extendedFilePath_;
|
||||
LOG_COMPILER(INFO) << "AOT compile: " << extendedFilePath;
|
||||
generator.SetCurrentCompileFileName(jsPandaFile->GetNormalizedFileDesc());
|
||||
if (!Compile(jsPandaFile, extendedFilePath, generator, compilerStats, collector)) {
|
||||
ret = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PassManager::Compile(JSPandaFile *jsPandaFile, const std::string &fileName, AOTFileGenerator &gen,
|
||||
AotCompilerStats &compilerStats)
|
||||
AotCompilerStats &compilerStats, BytecodeInfoCollector &collector)
|
||||
{
|
||||
[[maybe_unused]] EcmaHandleScope handleScope(compilationEnv_->GetJSThread());
|
||||
|
||||
BytecodeInfoCollector collector(compilationEnv_, jsPandaFile, profilerDecoder_, maxAotMethodSize_);
|
||||
// Checking released/debuggable pandafile uses method literals, which are initialized in BytecodeInfoCollector,
|
||||
// should after it.
|
||||
if (!IsReleasedPandaFile(jsPandaFile)) {
|
||||
|
@ -132,18 +132,22 @@ class PassManager {
|
||||
public:
|
||||
explicit PassManager(CompilationEnv *env, std::string &triple, size_t optLevel, size_t relocMode,
|
||||
CompilerLog *log, AotMethodLogList *logList, size_t maxAotMethodSize, size_t maxMethodsInModule,
|
||||
PGOProfilerDecoder &profilerDecoder, PassOptions *passOptions,
|
||||
CallMethodFlagMap *callMethodFlagMap, const CVector<AbcFileInfo> &fileInfos, std::string optBCRange)
|
||||
PGOProfilerDecoder &profilerDecoder, PassOptions *passOptions, CallMethodFlagMap *callMethodFlagMap,
|
||||
const CVector<AbcFileInfo> &fileInfos, const CVector<std::unique_ptr<BytecodeInfoCollector>> &bcInfoCollectors,
|
||||
std::string optBCRange)
|
||||
: compilationEnv_(env), triple_(triple), optLevel_(optLevel), relocMode_(relocMode), log_(log),
|
||||
logList_(logList), maxAotMethodSize_(maxAotMethodSize), maxMethodsInModule_(maxMethodsInModule),
|
||||
profilerDecoder_(profilerDecoder), passOptions_(passOptions),
|
||||
callMethodFlagMap_(callMethodFlagMap), fileInfos_(fileInfos), optBCRange_(optBCRange) {
|
||||
profilerDecoder_(profilerDecoder), passOptions_(passOptions), callMethodFlagMap_(callMethodFlagMap),
|
||||
fileInfos_(fileInfos), bcInfoCollectors_(bcInfoCollectors), optBCRange_(optBCRange) {
|
||||
enableJITLog_ = compilationEnv_->GetJSOptions().GetTraceJIT();
|
||||
};
|
||||
|
||||
virtual ~PassManager() = default;
|
||||
|
||||
void CompileValidFiles(AOTFileGenerator &generator, bool &ret, AotCompilerStats &compilerStats);
|
||||
|
||||
bool Compile(JSPandaFile *jsPandaFile, const std::string &fileName, AOTFileGenerator &generator,
|
||||
AotCompilerStats &compilerStats);
|
||||
AotCompilerStats &compilerStats, BytecodeInfoCollector &collector);
|
||||
|
||||
protected:
|
||||
bool IsReleasedPandaFile(const JSPandaFile *jsPandaFile) const;
|
||||
@ -160,6 +164,7 @@ protected:
|
||||
PassOptions *passOptions_ {nullptr};
|
||||
CallMethodFlagMap *callMethodFlagMap_ {nullptr};
|
||||
const CVector<AbcFileInfo> &fileInfos_;
|
||||
const CVector<std::unique_ptr<BytecodeInfoCollector>> &bcInfoCollectors_;
|
||||
std::string optBCRange_ {};
|
||||
bool enableJITLog_ {false};
|
||||
};
|
||||
@ -170,7 +175,7 @@ public:
|
||||
CompilerLog *log, AotMethodLogList *logList,
|
||||
PGOProfilerDecoder &profilerDecoder, PassOptions *passOptions)
|
||||
: PassManager(env, triple, optLevel, relocMode, log, logList, 1, 1, profilerDecoder, passOptions,
|
||||
nullptr, CVector<AbcFileInfo> {}, "") { };
|
||||
nullptr, CVector<AbcFileInfo> {}, CVector<std::unique_ptr<BytecodeInfoCollector>> {}, "") { };
|
||||
|
||||
bool Compile(JSHandle<ProfileTypeInfo> &profileTypeInfo, AOTFileGenerator &gen, int32_t osrOffset = -1);
|
||||
bool RunCg();
|
||||
|
Loading…
Reference in New Issue
Block a user