diff --git a/src/mapleall/maple_driver/defs/phases.def b/src/mapleall/maple_driver/defs/phases.def index 3324de9f182fc8d8825591c5d1ca10188c9a7765..7f23a7cbca31943278488fd9900703203d4ed0d7 100644 --- a/src/mapleall/maple_driver/defs/phases.def +++ b/src/mapleall/maple_driver/defs/phases.def @@ -23,7 +23,7 @@ ADD_PHASE("GenNativeStubFunc", JAVALANG) ADD_PHASE("gencheckcast", JAVALANG) ADD_PHASE("javaintrnlowering", JAVALANG) // mephase begin -ADD_PHASE("bypatheh", MeOption::optLevel == 2) +ADD_PHASE("bypatheh", JAVALANG && MeOption::optLevel == 2) ADD_PHASE("loopcanon", MeOption::optLevel == 2) ADD_PHASE("splitcriticaledge", MeOption::optLevel == 2) ADD_PHASE("ssatab", MeOption::optLevel == 2 || JAVALANG) @@ -31,15 +31,15 @@ ADD_PHASE("aliasclass", MeOption::optLevel == 2 || JAVALANG) ADD_PHASE("ssa", MeOption::optLevel == 2 || JAVALANG) ADD_PHASE("dse", MeOption::optLevel == 2) ADD_PHASE("analyzector", JAVALANG) -ADD_PHASE("abcopt", MeOption::optLevel == 2) -ADD_PHASE("ssadevirt", MeOption::optLevel == 2) +ADD_PHASE("abcopt", JAVALANG && MeOption::optLevel == 2) +ADD_PHASE("ssadevirt", JAVALANG && MeOption::optLevel == 2) ADD_PHASE("hprop", MeOption::optLevel == 2) ADD_PHASE("hdse", MeOption::optLevel == 2) -ADD_PHASE("may2dassign", MeOption::optLevel == 2) -ADD_PHASE("condbasednpc", MeOption::optLevel == 2) +ADD_PHASE("may2dassign", JAVALANG && MeOption::optLevel == 2) +ADD_PHASE("condbasednpc", JAVALANG && MeOption::optLevel == 2) ADD_PHASE("epre", MeOption::optLevel == 2) -ADD_PHASE("stmtpre", MeOption::optLevel == 2) -ADD_PHASE("analyzerc", MeOption::optLevel == 2) +ADD_PHASE("stmtpre", JAVALANG && MeOption::optLevel == 2) +ADD_PHASE("analyzerc", JAVALANG && MeOption::optLevel == 2) ADD_PHASE("rclowering", JAVALANG) ADD_PHASE("rename2preg", MeOption::optLevel == 2) //ADD_PHASE("lpre", MeOption::optLevel == 2) diff --git a/src/mapleall/maple_driver/include/compiler.h b/src/mapleall/maple_driver/include/compiler.h index e33f59b9aa6a4180433af5bd020f2465ef195223..58502442d04536952c643f0d85ded540ce19a049 100644 --- a/src/mapleall/maple_driver/include/compiler.h +++ b/src/mapleall/maple_driver/include/compiler.h @@ -23,6 +23,7 @@ #include "option.h" #include "mir_module.h" #include "mir_parser.h" +#include "bin_mplt.h" namespace maple { const std::string kBinNameNone = ""; diff --git a/src/mapleall/maple_driver/include/driver_runner.h b/src/mapleall/maple_driver/include/driver_runner.h index 087c311d14992591c1c17726771970f4490a4a5e..39204e134722b0ac33f62475733e5a92ed0aad42 100644 --- a/src/mapleall/maple_driver/include/driver_runner.h +++ b/src/mapleall/maple_driver/include/driver_runner.h @@ -32,7 +32,7 @@ extern const std::string mplME; class DriverRunner final { public: - DriverRunner(MIRModule *theModule, const std::vector &exeNames, Options *mpl2mplOptions, + DriverRunner(MIRModule *theModule, const std::vector &exeNames, InputFileType inpFileType, Options *mpl2mplOptions, std::string mpl2mplInput, MeOption *meOptions, const std::string &meInput, std::string actualInput, MemPool *optMp, bool fileParsed = false, bool timePhases = false, bool genVtableImpl = false, bool genMeMpl = false) @@ -47,11 +47,12 @@ class DriverRunner final { fileParsed(fileParsed), timePhases(timePhases), genVtableImpl(genVtableImpl), - genMeMpl(genMeMpl) {} + genMeMpl(genMeMpl), + inputFileType(inpFileType) {} - DriverRunner(MIRModule *theModule, const std::vector &exeNames, std::string actualInput, MemPool *optMp, + DriverRunner(MIRModule *theModule, const std::vector &exeNames, InputFileType inpFileType, std::string actualInput, MemPool *optMp, bool fileParsed = false, bool timePhases = false, bool genVtableImpl = false, bool genMeMpl = false) - : DriverRunner(theModule, exeNames, nullptr, "", nullptr, "", actualInput, optMp, fileParsed, timePhases, + : DriverRunner(theModule, exeNames, inpFileType, nullptr, "", nullptr, "", actualInput, optMp, fileParsed, timePhases, genVtableImpl, genMeMpl) {} ~DriverRunner() = default; @@ -93,6 +94,7 @@ class DriverRunner final { bool timePhases = false; bool genVtableImpl = false; bool genMeMpl = false; + InputFileType inputFileType; std::string printOutExe; }; } // namespace maple diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index ffde19a3b3d8ba0bb240d4c039c55a17515457f3..c8973eafb73910284b5f668c17e8c293fc419a39 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -35,6 +35,7 @@ enum InputFileType { kFileTypeMpl, kFileTypeVtableImplMpl, kFileTypeS, + kFileTypeBpl, }; enum OptimizationLevel { diff --git a/src/mapleall/maple_driver/src/driver_runner.cpp b/src/mapleall/maple_driver/src/driver_runner.cpp index 0d0553b56d999a75ea5a15279e2a8bc71eacb2c1..90a5a7573193489cd4f6ced3f98956edcc7806ed 100644 --- a/src/mapleall/maple_driver/src/driver_runner.cpp +++ b/src/mapleall/maple_driver/src/driver_runner.cpp @@ -12,6 +12,7 @@ * FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. */ +#include "compiler.h" #include "driver_runner.h" #include #include @@ -129,19 +130,34 @@ ErrorCode DriverRunner::ParseInput(const std::string &outputFile, const std::str MPLTimer timer; timer.Start(); - MIRParser parser(*theModule); ErrorCode ret = kErrorNoError; - bool parsed; if (!fileParsed) { - MPLTimer parseMirTimer; - parseMirTimer.Start(); - parsed = parser.ParseMIR(0, 0, false, true); - parseMirTimer.Stop(); - InterleavedManager::interleavedTimer.emplace_back( - std::pair("parseMpl", parseMirTimer.ElapsedMicroseconds())); - if (!parsed) { - ret = kErrorExit; - parser.EmitError(outputFile); + if (inputFileType != kFileTypeBpl) { + MIRParser parser(*theModule); + MPLTimer parseMirTimer; + parseMirTimer.Start(); + bool parsed = parser.ParseMIR(0, 0, false, true); + parseMirTimer.Stop(); + InterleavedManager::interleavedTimer.emplace_back( + std::pair("parseMpl", parseMirTimer.ElapsedMicroseconds())); + if (!parsed) { + ret = kErrorExit; + parser.EmitError(outputFile); + } + } else { + BinaryMplImport binMplt(*theModule); + binMplt.SetImported(false); + std::string modid = theModule->GetFileName(); + MPLTimer importMirTimer; + importMirTimer.Start(); + bool imported = binMplt.Import(modid, true); + importMirTimer.Stop(); + InterleavedManager::interleavedTimer.emplace_back( + std::pair("parseMpl", importMirTimer.ElapsedMicroseconds())); + if (!imported) { + ret = kErrorExit; + LogInfo::MapleLogger() << "Cannot open .bpl file: %s" << modid << '\n'; + } } } timer.Stop(); @@ -340,7 +356,9 @@ void DriverRunner::RunCGFunctions(CG &cg, CgFuncPhaseManager &cgfpm, std::vector mirLowerer.Init(); CGLowerer theLowerer(*theModule, *beCommon, cg.GenerateExceptionHandlingCode(), cg.GenerateVerboseCG()); theLowerer.RegisterBuiltIns(); - theLowerer.InitArrayClassCacheTableIndex(); + if (JAVALANG) { + theLowerer.InitArrayClassCacheTableIndex(); + } theLowerer.RegisterExternalLibraryFunctions(); theLowerer.SetCheckLoadStore(CGOptions::IsCheckArrayStore()); timer.Stop(); diff --git a/src/mapleall/maple_driver/src/maple_comb_compiler.cpp b/src/mapleall/maple_driver/src/maple_comb_compiler.cpp index 0e4eafc6e7cb8ce43515f4d1a44f325f5d9cebd5..eeee8c07a864b990b0fed7f193c4a0622a36ed62 100644 --- a/src/mapleall/maple_driver/src/maple_comb_compiler.cpp +++ b/src/mapleall/maple_driver/src/maple_comb_compiler.cpp @@ -154,7 +154,7 @@ ErrorCode MapleCombCompiler::Compile(const MplOptions &options, std::unique_ptr< LogInfo::MapleLogger() << "Starting mpl2mpl&mplme\n"; PrintCommand(options); - DriverRunner runner(theModule.get(), options.GetRunningExes(), &mpl2mplOptions, fileName, &meOptions, + DriverRunner runner(theModule.get(), options.GetRunningExes(), options.GetInputFileType(), &mpl2mplOptions, fileName, &meOptions, fileName, fileName, optMp, fileParsed, options.HasSetTimePhases(), options.HasSetGenVtableImpl(), options.HasSetGenMeMpl()); ErrorCode nErr = runner.Run(); diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index 90edc6ea41691908ce1b233ab4ee5e1cdac5a3a8..501241837922d92cfb995dcd918a7fae09f48f69 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -342,9 +342,9 @@ bool MplOptions::Init(const std::string &inputFile) { } else if (extensionName == "jar") { inputFileType = InputFileType::kFileTypeJar; - } else if (extensionName == "mpl") { + } else if (extensionName == "mpl" || extensionName == "bpl") { if (firstInputFile.find("VtableImpl") == std::string::npos) { - inputFileType = InputFileType::kFileTypeMpl; + inputFileType = extensionName == "mpl" ? InputFileType::kFileTypeMpl : InputFileType::kFileTypeBpl; } else { inputFileType = InputFileType::kFileTypeVtableImplMpl; } diff --git a/src/mapleall/maple_driver/src/mplcg_compiler.cpp b/src/mapleall/maple_driver/src/mplcg_compiler.cpp index 7b82094eecf1c31ac7737009128e1fd933a869ff..7b3e188f39d60e787d8dada12ff2677505b50d51 100644 --- a/src/mapleall/maple_driver/src/mplcg_compiler.cpp +++ b/src/mapleall/maple_driver/src/mplcg_compiler.cpp @@ -107,29 +107,39 @@ ErrorCode MplcgCompiler::Compile(const MplOptions &options, std::unique_ptr theParser; - bool fileparsed = true; + bool fileread = true; if (theModule == nullptr) { MPLTimer timer; timer.Start(); - fileparsed = false; + fileread = false; theModule = std::make_unique(fileName); theModule->SetWithMe( std::find(options.GetRunningExes().begin(), options.GetRunningExes().end(), kBinNameMe) != options.GetRunningExes().end()); - theParser.reset(new MIRParser(*theModule)); - parsed = theParser->ParseMIR(0, cgOption.GetParserOption()); - if (parsed) { - if (!cgOption.IsQuiet() && theParser->GetWarning().size()) { - theParser->EmitWarning(fileName); + if (options.GetInputFileType() != kFileTypeBpl) { + std::unique_ptr theParser; + theParser.reset(new MIRParser(*theModule)); + bool parsed = theParser->ParseMIR(0, cgOption.GetParserOption()); + if (parsed) { + if (!cgOption.IsQuiet() && theParser->GetWarning().size()) { + theParser->EmitWarning(fileName); + } + } else { + if (theParser != nullptr) { + theParser->EmitError(fileName); + } + memPoolCtrler.DeleteMemPool(optMp); + return kErrorCompileFail; } } else { - if (theParser != nullptr) { - theParser->EmitError(fileName); + BinaryMplImport binMplt(*theModule); + binMplt.SetImported(false); + std::string modid = theModule->GetFileName(); + bool imported = binMplt.Import(modid, true); + if (!imported) { + memPoolCtrler.DeleteMemPool(optMp); + return kErrorCompileFail; } - memPoolCtrler.DeleteMemPool(optMp); - return kErrorCompileFail; } timer.Stop(); LogInfo::MapleLogger() << "Mplcg Parser consumed " << timer.ElapsedMilliseconds() << "ms\n"; @@ -137,8 +147,8 @@ ErrorCode MplcgCompiler::Compile(const MplOptions &options, std::unique_ptrNew(lexer.GetTheIntVal(), type, fieldID); + stype = GlobalTables::GetIntConstTable().GetOrCreateIntConst(lexer.GetTheIntVal(), type, fieldID); } else if (ptp == PTY_f32) { if (lexer.GetTokenKind() != TK_floatconst) { Error("constant value incompatible with single-precision float type at "); diff --git a/src/mapleall/maple_me/include/me_ssa_epre.h b/src/mapleall/maple_me/include/me_ssa_epre.h index ae239f75b980f234373c12e89a47a370710f576d..ec63b055e886c0e86e84fb1f6cf9bd6edb34c779 100644 --- a/src/mapleall/maple_me/include/me_ssa_epre.h +++ b/src/mapleall/maple_me/include/me_ssa_epre.h @@ -26,7 +26,7 @@ class MeSSAEPre : public SSAEPre { public: // a symbol is a candidate for ssaupdate if its ostidx key exists in the map; // the mapped set gives bbs where dassign's are inserted by ssa_epre for the symbol - explicit MeSSAEPre(MeFunction &func, IRMap &map, Dominance &dom, KlassHierarchy &kh, MemPool &memPool, MemPool &mp2, + explicit MeSSAEPre(MeFunction &func, IRMap &map, Dominance &dom, KlassHierarchy *kh, MemPool &memPool, MemPool &mp2, uint32 limit, bool includeRef, bool epreLocalRefVar, bool lhsIvar) : SSAEPre(map, dom, memPool, mp2, kExprPre, limit, includeRef, lhsIvar), candsForSSAUpdate(std::less(), ssaPreAllocator.Adapter()), @@ -48,7 +48,7 @@ class MeSSAEPre : public SSAEPre { MapleMap*> candsForSSAUpdate; MeFunction *func; bool epreLocalRefVar; - KlassHierarchy &klassHierarchy; + KlassHierarchy *klassHierarchy; private: void BuildWorkList() override; diff --git a/src/mapleall/maple_me/src/me_alias_class.cpp b/src/mapleall/maple_me/src/me_alias_class.cpp index edfa716fabb0ac93d4500e9a3b26a063cf980bf7..9d1ad4f7ea015846bc492dc80d11ef4c2bec221c 100644 --- a/src/mapleall/maple_me/src/me_alias_class.cpp +++ b/src/mapleall/maple_me/src/me_alias_class.cpp @@ -86,15 +86,14 @@ AnalysisResult *MeDoAliasClass::Run(MeFunction *func, MeFuncResultMgr *funcResMg timer.Start(); (void)funcResMgr->GetAnalysisResult(MeFuncPhase_SSATAB, func); MemPool *aliasClassMp = NewMemPool(); - auto *kh = static_cast(moduleResMgr->GetAnalysisResult( + KlassHierarchy *kh = nullptr; + if (func->GetMIRModule().IsJavaModule()) { + kh = static_cast(moduleResMgr->GetAnalysisResult( MoPhase_CHA, &func->GetMIRModule())); - auto *aliasClass = aliasClassMp->New( + } + MeAliasClass *aliasClass = aliasClassMp->New( *aliasClassMp, func->GetMIRModule(), *func->GetMeSSATab(), *func, MeOption::lessThrowAlias, MeOption::ignoreIPA, DEBUGFUNC(func), MeOption::setCalleeHasSideEffect, kh); - // pass 1 through the program statements - if (DEBUGFUNC(func)) { - LogInfo::MapleLogger() << "\n============ Alias Classification Pass 1 ============" << '\n'; - } aliasClass->DoAliasAnalysis(); timer.Stop(); if (DEBUGFUNC(func)) { diff --git a/src/mapleall/maple_me/src/me_ssa_epre.cpp b/src/mapleall/maple_me/src/me_ssa_epre.cpp index b887891a06b121cb3c2f613ddfe153e209316f60..7542be0b87637e7b1096b8ea38a02ad2338328e4 100644 --- a/src/mapleall/maple_me/src/me_ssa_epre.cpp +++ b/src/mapleall/maple_me/src/me_ssa_epre.cpp @@ -50,12 +50,15 @@ void MeSSAEPre::BuildWorkList() { } bool MeSSAEPre::IsThreadObjField(const IvarMeExpr &expr) const { + if (klassHierarchy == nullptr) { + return false; + } if (expr.GetFieldID() == 0) { return false; } auto *type = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(expr.GetTyIdx())); - TyIdx runnableInterface = klassHierarchy.GetKlassFromLiteral("Ljava_2Flang_2FRunnable_3B")->GetTypeIdx(); - Klass *klass = klassHierarchy.GetKlassFromTyIdx(type->GetPointedTyIdx()); + TyIdx runnableInterface = klassHierarchy->GetKlassFromLiteral("Ljava_2Flang_2FRunnable_3B")->GetTypeIdx(); + Klass *klass = klassHierarchy->GetKlassFromTyIdx(type->GetPointedTyIdx()); if (klass == nullptr) { return false; } @@ -77,8 +80,11 @@ AnalysisResult *MeDoSSAEPre::Run(MeFunction *func, MeFuncResultMgr *m, ModuleRes ASSERT(dom != nullptr, "dominance phase has problem"); auto *irMap = static_cast(m->GetAnalysisResult(MeFuncPhase_IRMAPBUILD, func)); ASSERT(irMap != nullptr, "irMap phase has problem"); - KlassHierarchy *kh = static_cast(mrm->GetAnalysisResult(MoPhase_CHA, &func->GetMIRModule())); - CHECK_FATAL(kh != nullptr, "KlassHierarchy phase has problem"); + KlassHierarchy *kh = nullptr; + if (func->GetMIRModule().IsJavaModule()) { + kh = static_cast(mrm->GetAnalysisResult(MoPhase_CHA, &func->GetMIRModule())); + CHECK_FATAL(kh != nullptr, "KlassHierarchy phase has problem"); + } bool eprePULimitSpecified = MeOption::eprePULimit != UINT32_MAX; uint32 epreLimitUsed = (eprePULimitSpecified && puCount != MeOption::eprePULimit) ? UINT32_MAX : MeOption::epreLimit; @@ -87,7 +93,7 @@ AnalysisResult *MeDoSSAEPre::Run(MeFunction *func, MeFuncResultMgr *m, ModuleRes if (!MeOption::gcOnly && propWhiteList.find(func->GetName()) != propWhiteList.end()) { epreIncludeRef = false; } - MeSSAEPre ssaPre(*func, *irMap, *dom, *kh, *ssaPreMemPool, *NewMemPool(), epreLimitUsed, epreIncludeRef, + MeSSAEPre ssaPre(*func, *irMap, *dom, kh, *ssaPreMemPool, *NewMemPool(), epreLimitUsed, epreIncludeRef, MeOption::epreLocalRefVar, MeOption::epreLHSIvar); ssaPre.SetSpillAtCatch(MeOption::spillAtCatch); if (func->GetHints() & kPlacementRCed) {