diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index aa47e275e146f8ed0b5ea9810140c78dd36ba70f..5b1fa08c7a2df0178e65946b9662091aa5f72c7b 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 018bb9422754068d146501f377f70b369af50ac4..cba45b7576a3e395e6d52d351220308af11eba9a 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index 8574dce4d6150d78f205d8f4cd31d466187134ff..a13aa431a59f5c35cb6a906174dbc23f04c987a6 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index 02fa626330d35878ef13f701d14ed16782b29f8a..15308b0c21471021b6d88163dfb6b1700b9fb8ac 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/maple_driver/defs/phases.def b/src/maple_driver/defs/phases.def index aee8262f48b43f003d52f386026c659c0681fc8b..65fc2ad077bfd0cea80c968ec6593d4d4baf27f0 100644 --- a/src/maple_driver/defs/phases.def +++ b/src/maple_driver/defs/phases.def @@ -25,6 +25,7 @@ ADD_PHASE("aliasclass", true) ADD_PHASE("ssa", true) ADD_PHASE("analyzerc", true) ADD_PHASE("rclowering", true) +ADD_PHASE("gclowering", true) ADD_PHASE("emit", true) // mephase end ADD_PHASE("GenNativeStubFunc", true) diff --git a/src/maple_driver/include/mpl_options.h b/src/maple_driver/include/mpl_options.h index ef1719089dc981c7e5d2671be37724fe9c5d8f98..679797e064ddef11c34fc5e68ddfcaa9550fed08 100644 --- a/src/maple_driver/include/mpl_options.h +++ b/src/maple_driver/include/mpl_options.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include "file_utils.h" @@ -37,6 +38,7 @@ enum InputFileType { }; enum OptimizationLevel { kO0, kO1, kO2 }; +enum RunMode { kAutoRun, kCustomRun, kUnkownRun }; class MplOption { public: @@ -73,7 +75,7 @@ struct DefaultOption { class MplOptions { public: - mapleOption::OptionParser *optionParser; + std::unique_ptr optionParser; std::map> options; std::map> exeOptions; std::string inputFiles; @@ -81,9 +83,9 @@ class MplOptions { std::string outputFolder; std::string outputName; std::string exeFolder; - std::string optLevelStr; InputFileType inputFileType; OptimizationLevel optimizationLevel; + RunMode runMode; bool setDefaultLevel; bool isSaveTmps; std::vector saveFiles; @@ -106,9 +108,9 @@ class MplOptions { outputFolder(""), outputName("maple"), exeFolder(""), - optLevelStr(""), inputFileType(InputFileType::kNone), - optimizationLevel(OptimizationLevel::kO2), + optimizationLevel(OptimizationLevel::kO0), + runMode(RunMode::kUnkownRun), setDefaultLevel(false), isSaveTmps(false), saveFiles({}), @@ -122,12 +124,7 @@ class MplOptions { genMemPl(false), genVtableImpl(false), verify(false) {} - ~MplOptions() { - if (optionParser != nullptr) { - delete optionParser; - optionParser = nullptr; - } - } + ~MplOptions() = default; int Parse(int argc, char **argv); const std::string OptimizationLevelStr() const; @@ -138,12 +135,14 @@ class MplOptions { ErrorCode DecideRunType(); ErrorCode DecideRunningPhases(); ErrorCode CheckInputFileValidity(); - ErrorCode CheckOptLevel(const std::string &inputOpt, const std::string &filterOpt); + ErrorCode CheckRunMode(RunMode mode); ErrorCode CheckFileExits(); void AddOption(const mapleOption::Option &option); void UpdateOptLevel(OptimizationLevel level); ErrorCode UpdatePhaseOption(const std::string &args, const std::string &exeName); ErrorCode UpdateExtraOptionOpt(const std::string &args); + ErrorCode AppendDefaultCombOptions(); + ErrorCode AppendDefaultCgOptions(); ErrorCode AppendDefaultOptions(const std::string &exeName, MplOption mplOptions[], unsigned int length); void UpdateRunningExe(const std::string &args); }; diff --git a/src/maple_driver/src/mpl_options.cpp b/src/maple_driver/src/mpl_options.cpp index 96dd47f2f55cc6e18a17846b936d4861b902b963..d7ac623110dce28c897ca80ff55f418617cfba8f 100644 --- a/src/maple_driver/src/mpl_options.cpp +++ b/src/maple_driver/src/mpl_options.cpp @@ -31,7 +31,7 @@ namespace maple { const std::string kMapleDriverVersion = "mapledriver " + std::to_string(Version::kMajorMplVersion) + "." + std::to_string(Version::kMinorCompilerVersion) + " 20190712"; int MplOptions::Parse(int argc, char **argv) { - this->optionParser = new OptionParser(USAGES); + this->optionParser.reset(new OptionParser(USAGES)); exeFolder = FileUtils::GetFileFolder(*argv); int ret = optionParser->Parse(argc, argv); if (ret != ErrorCode::kErrorNoError) { @@ -44,18 +44,18 @@ int MplOptions::Parse(int argc, char **argv) { } // Set default as O0 - if (optLevelStr == "") { - optLevelStr = "O0"; + if (runMode == RunMode::kUnkownRun) { + optimizationLevel = kO0; } - // Check whether the input files are Valid + // Check whether the input files were valid ret = CheckInputFileValidity(); if (ret != ErrorCode::kErrorNoError) { return ret; } // Decide runningExes for default options(O0, O2) by input files - if (optLevelStr != "run") { + if (runMode != RunMode::kCustomRun) { ret = DecideRunningPhases(); if (ret != ErrorCode::kErrorNoError) { return ret; @@ -67,6 +67,8 @@ int MplOptions::Parse(int argc, char **argv) { if (ret != ErrorCode::kErrorNoError) { return ret; } + // Check whether the file was readable + ret = CheckFileExits(); return ret; } @@ -95,10 +97,10 @@ ErrorCode MplOptions::HandleGeneralOptions() { } break; case kMeHelp: - optionParser->PrintUsage("me"); + optionParser->PrintUsage(kBinNameMe); return ErrorCode::kErrorExitHelp; case kMpl2MplHelp: - optionParser->PrintUsage("mpl2mpl"); + optionParser->PrintUsage(kBinNameMpl2mpl); return ErrorCode::kErrorExitHelp; case kCombTimePhases: this->timePhases = true; @@ -145,33 +147,24 @@ ErrorCode MplOptions::DecideRunType() { for (auto opt : optionParser->GetOptions()) { switch (opt.Index()) { case kOptimization0: - ret = CheckOptLevel("O0", "run"); // O0 and run should not appear at the same time + ret = CheckRunMode(RunMode::kCustomRun); // O0 and run should not appear at the same time if (ret != ErrorCode::kErrorNoError) { return ErrorCode::kErrorInvalidParameter; } - optLevelStr = "O0"; + runMode = RunMode::kAutoRun; + optimizationLevel = kO0; break; case kRun: - ret = CheckOptLevel("run", "O0"); // O0(O2) and run should not appear at the same time + ret = CheckRunMode(RunMode::kAutoRun); // O0(O2) and run should not appear at the same time if (ret != ErrorCode::kErrorNoError) { return ErrorCode::kErrorInvalidParameter; } - ret = CheckOptLevel("run", "O2"); - if (ret != ErrorCode::kErrorNoError) { - return ErrorCode::kErrorInvalidParameter; - } - optLevelStr = "run"; + runMode = RunMode::kCustomRun; this->UpdateRunningExe(opt.Args()); break; case kInFile: { if (!Init(opt.Args())) { return ErrorCode::kErrorInitFail; - } else { - // Check whether the file was readable - ret = CheckFileExits(); - if (ret != ErrorCode::kErrorNoError) { - return ret; - } } break; } @@ -189,7 +182,7 @@ ErrorCode MplOptions::DecideRunningPhases() { switch (inputFileType) { case InputFileType::kJar: case InputFileType::kClass: - this->UpdateRunningExe("jbc2mpl"); + this->UpdateRunningExe(kBinNameJbc2mpl); break; case InputFileType::kMpl: break; @@ -205,21 +198,15 @@ ErrorCode MplOptions::DecideRunningPhases() { break; } if (isNeedMapleComb) { - if (optLevelStr == "O0") { - ret = AppendDefaultOptions(kBinNameMe, kMeDefaultOptionsO0, sizeof(kMeDefaultOptionsO0) / sizeof(MplOption)); - if (ret != ErrorCode::kErrorNoError) { - return ret; - } - ret = AppendDefaultOptions(kBinNameMpl2mpl, kMpl2MplDefaultOptionsO0, - sizeof(kMpl2MplDefaultOptionsO0) / sizeof(MplOption)); - if (ret != ErrorCode::kErrorNoError) { - return ret; - } + ret = AppendDefaultCombOptions(); + if (ret != ErrorCode::kErrorNoError) { + return ret; } } if (isNeedMplcg) { - if (optLevelStr == "O0") { - this->UpdateRunningExe("mplcg"); + ret = AppendDefaultCgOptions(); + if (ret != ErrorCode::kErrorNoError) { + return ret; } } return ret; @@ -240,22 +227,14 @@ ErrorCode MplOptions::CheckInputFileValidity() { } if (!Init(optionString)) { ret = ErrorCode::kErrorInitFail; - } else { - // Check whether the file was readable - ret = CheckFileExits(); } } - if (this->inputFiles == "") { - LogInfo::MapleLogger(kLlErr) << "Forget to input file? " << "\n"; - return ErrorCode::kErrorInitFail; - } return ret; } -ErrorCode MplOptions::CheckOptLevel(const std::string &inputOpt, const std::string &filterOpt) { - if (optLevelStr == filterOpt) { - LogInfo::MapleLogger(kLlErr) << "Cannot Set " << inputOpt << " and " - << filterOpt << "at the same time!" << "\n"; +ErrorCode MplOptions::CheckRunMode(RunMode mode) { + if (runMode == mode) { + LogInfo::MapleLogger(kLlErr) << "Cannot set auto mode and run mode at the same time!\n"; return ErrorCode::kErrorInvalidParameter; } return ErrorCode::kErrorNoError; @@ -263,6 +242,10 @@ ErrorCode MplOptions::CheckOptLevel(const std::string &inputOpt, const std::stri ErrorCode MplOptions::CheckFileExits() { ErrorCode ret = ErrorCode::kErrorNoError; + if (inputFiles == "") { + LogInfo::MapleLogger(kLlErr) << "Forgot to input files?\n"; + return ErrorCode::kErrorFileNotFound; + } for (auto fileName : splitsInputFiles) { std::ifstream infile; infile.open(fileName); @@ -335,6 +318,30 @@ void MplOptions::UpdateOptLevel(OptimizationLevel level) { this->optimizationLevel = level; } +ErrorCode MplOptions::AppendDefaultCombOptions() { + ErrorCode ret = ErrorCode::kErrorNoError; + if (optimizationLevel == kO0) { + ret = AppendDefaultOptions(kBinNameMe, kMeDefaultOptionsO0, sizeof(kMeDefaultOptionsO0) / sizeof(MplOption)); + if (ret != ErrorCode::kErrorNoError) { + return ret; + } + ret = AppendDefaultOptions(kBinNameMpl2mpl, kMpl2MplDefaultOptionsO0, + sizeof(kMpl2MplDefaultOptionsO0) / sizeof(MplOption)); + if (ret != ErrorCode::kErrorNoError) { + return ret; + } + } + return ret; +} + +ErrorCode MplOptions::AppendDefaultCgOptions() { + ErrorCode ret = ErrorCode::kErrorNoError; + if (optimizationLevel == kO0) { + this->UpdateRunningExe(kBinNameMplcg); + } + return ret; +} + ErrorCode MplOptions::AppendDefaultOptions(const std::string &exeName, MplOption mplOptions[], unsigned int length) { bool ret = true; auto &exeOption = exeOptions[exeName]; @@ -352,6 +359,11 @@ ErrorCode MplOptions::AppendDefaultOptions(const std::string &exeName, MplOption } ErrorCode MplOptions::UpdatePhaseOption(const std::string &args, const std::string &exeName) { + auto iter = std::find(this->runningExes.begin(), this->runningExes.end(), exeName.c_str()); + if (iter == this->runningExes.end()) { + LogInfo::MapleLogger(kLlErr) << "Cannot find phase " << exeName << std::endl; + return ErrorCode::kErrorExit; + } std::vector tmpArgs; // Split options with ' ' StringUtils::Split(args, tmpArgs, ' '); diff --git a/src/maple_ipa/include/module_phase_manager.h b/src/maple_ipa/include/module_phase_manager.h index 35eb2eb8176cdc2ee5d6e699cafd05524ce2c1ab..e0c977dfed7a6715c3d99da4b837a1fba61974fd 100644 --- a/src/maple_ipa/include/module_phase_manager.h +++ b/src/maple_ipa/include/module_phase_manager.h @@ -30,7 +30,7 @@ class DoKlassHierarchy : public ModulePhase { return "classhierarchy"; } - virtual ~DoKlassHierarchy(){}; + virtual ~DoKlassHierarchy() {}; }; class ModulePhaseManager : public PhaseManager { diff --git a/src/maple_ir/include/mir_const.h b/src/maple_ir/include/mir_const.h index c1d05fe9ae0e17e3ce38a54ae60c7800c54c21ca..f594de91448cd42dca03576a1693e6c24cbec9b7 100644 --- a/src/maple_ir/include/mir_const.h +++ b/src/maple_ir/include/mir_const.h @@ -470,20 +470,30 @@ class MIRAggConst : public MIRConst { return nullptr; } + const MapleVector &GetConstVec() const { + return constVec; + } + MapleVector &GetConstVec() { return constVec; } + const MIRConstPtr &GetConstVecItem(size_t index) const { + CHECK_FATAL(index < constVec.size(), "index out of range"); + return constVec[index]; + } + MIRConstPtr &GetConstVecItem(size_t index) { CHECK_FATAL(index < constVec.size(), "index out of range"); return constVec[index]; } + void SetConstVecItem(uint32 index, MIRConst &mirConst) { CHECK_FATAL(index < constVec.size(), "index out of range"); constVec[index] = &mirConst; } - void PushBack(MIRConst &elem) { - constVec.push_back(&elem); + void PushBack(MIRConst *elem) { + constVec.push_back(elem); } void Dump() const; diff --git a/src/maple_ir/include/mir_function.h b/src/maple_ir/include/mir_function.h index 3d1466d5aaf7bad6f01e1ced708a8c6f8d3c849b..30c366b62063fe62f3eb6223a80b1a31aa92008c 100644 --- a/src/maple_ir/include/mir_function.h +++ b/src/maple_ir/include/mir_function.h @@ -208,7 +208,7 @@ class MIRFunction { return funcType->GetParamTypeList().size(); } - std::vector &GetParamTypes() const { + const std::vector &GetParamTypes() const { return funcType->GetParamTypeList(); } diff --git a/src/maple_ir/include/mir_pragma.h b/src/maple_ir/include/mir_pragma.h index a37727ec29798a877894b92a7fe8484909c04564..96f7953c82b4cf5132e22af10b39b25dab438c1d 100644 --- a/src/maple_ir/include/mir_pragma.h +++ b/src/maple_ir/include/mir_pragma.h @@ -77,7 +77,7 @@ class MIRPragmaElement { } ~MIRPragmaElement() = default; - void Dump(int indent); + void Dump(int indent) const; void PushSubElemVec(MIRPragmaElement &elem) { subElemVec.push_back(&elem); } @@ -187,7 +187,7 @@ class MIRPragma { ~MIRPragma() = default; MIRPragmaElement *GetPragmaElemFromSignature(const std::string &signature); - void Dump(int indent); + void Dump(int indent) const; void PushElementVector(MIRPragmaElement &elem) { elementVec.push_back(&elem); } diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index feefc4d60df07d37ce3486a9084ce5758e9d83a8..bf6b972ba2d1d4af2f1fb079e28aa0d2a9f2b95e 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -1373,31 +1373,45 @@ class MIRFuncType : public MIRType { TyIdx GetRetTyIdx() const { return retTyIdx; } + void SetRetTyIdx(TyIdx idx) { retTyIdx = idx; } + const std::vector &GetParamTypeList() const { + return paramTypeList; + } + std::vector &GetParamTypeList() { return paramTypeList; } + TyIdx GetNthParamType(size_t i) const { ASSERT(i < paramTypeList.size(), "array index out of range"); return paramTypeList[i]; } + void SetParamTypeList(std::vector &list) { paramTypeList = list; } + const std::vector &GetParamAttrsList() const { + return paramAttrsList; + } + std::vector &GetParamAttrsList() { return paramAttrsList; } + const TypeAttrs &GetNthParamAttrs(size_t i) const { ASSERT(i < paramAttrsList.size(), "array index out of range"); return paramAttrsList[i]; } + void SetParamAttrsList(const std::vector &list) { paramAttrsList = list; } + void SetNthParamAttrs(size_t i, const TypeAttrs &attrs) { ASSERT(i < paramAttrsList.size(), "array index out of range"); paramAttrsList[i] = attrs; @@ -1406,6 +1420,7 @@ class MIRFuncType : public MIRType { bool IsVarargs() const { return isVarArgs; } + void SetVarArgs(bool flag) { isVarArgs = flag; } diff --git a/src/maple_ir/src/bin_mpl_export.cpp b/src/maple_ir/src/bin_mpl_export.cpp index 5f93c1f5b4aa3e279cc12a003a6851562718546d..1a8a8cdb1e12c2c91b5c02686c096cce4c9b54c8 100644 --- a/src/maple_ir/src/bin_mpl_export.cpp +++ b/src/maple_ir/src/bin_mpl_export.cpp @@ -29,43 +29,43 @@ using namespace maple; using OutputConstFactory = FunctionFactory; using OutputTypeFactory = FunctionFactory; -void OutputConstInt(MIRConst &constVal, BinaryMplExport &mplExport) { +void OutputConstInt(const MIRConst &constVal, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindConstInt); mplExport.OutputConstBase(constVal); - mplExport.WriteNum(static_cast(&constVal)->GetValue()); + mplExport.WriteNum(static_cast(constVal).GetValue()); } -void OutputConstAddrof(MIRConst &constVal, BinaryMplExport &mplExport) { +void OutputConstAddrof(const MIRConst &constVal, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindConstAddrof); mplExport.OutputConstBase(constVal); - MIRAddrofConst *addrof = static_cast(&constVal); - mplExport.OutputSymbol(mplExport.GetMIRModule().CurFunction()->GetLocalOrGlobalSymbol(addrof->GetSymbolIndex())); - mplExport.WriteNum(addrof->GetFieldID()); + const auto &addrof = static_cast(constVal); + mplExport.OutputSymbol(mplExport.GetMIRModule().CurFunction()->GetLocalOrGlobalSymbol(addrof.GetSymbolIndex())); + mplExport.WriteNum(addrof.GetFieldID()); } -void OutputConstAddrofFunc(MIRConst &constVal, BinaryMplExport &mplExport) { +void OutputConstAddrofFunc(const MIRConst &constVal, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindConstAddrofFunc); mplExport.OutputConstBase(constVal); - MIRAddroffuncConst *addrfunc = static_cast(&constVal); - mplExport.OutputFunction(addrfunc->GetValue()); + const auto &addrfunc = static_cast(constVal); + mplExport.OutputFunction(addrfunc.GetValue()); } -void OutputConstLbl(MIRConst &constVal, BinaryMplExport &mplExport) { +void OutputConstLbl(const MIRConst &constVal, BinaryMplExport &mplExport) { ASSERT(false, "NYI"); } -void OutputConstStr(MIRConst &constVal, BinaryMplExport &mplExport) { +void OutputConstStr(const MIRConst &constVal, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindConstStr); mplExport.OutputConstBase(constVal); - MIRStrConst *strc = static_cast(&constVal); - mplExport.OutputUsrStr(strc->GetValue()); + const auto &strc = static_cast(constVal); + mplExport.OutputUsrStr(strc.GetValue()); } -void OutputConstStr16(MIRConst &constVal, BinaryMplExport &mplExport) { +void OutputConstStr16(const MIRConst &constVal, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindConstStr16); mplExport.OutputConstBase(constVal); - MIRStr16Const *mirStr16 = static_cast(&constVal); - std::u16string str16 = GlobalTables::GetU16StrTable().GetStringFromStrIdx(mirStr16->GetValue()); + const auto &mirStr16 = static_cast(constVal); + std::u16string str16 = GlobalTables::GetU16StrTable().GetStringFromStrIdx(mirStr16.GetValue()); std::string str; NameMangler::UTF16ToUTF8(str, str16); mplExport.WriteNum(str.length()); @@ -74,42 +74,42 @@ void OutputConstStr16(MIRConst &constVal, BinaryMplExport &mplExport) { } } -void OutputConstFloat(MIRConst &constVal, BinaryMplExport &mplExport) { +void OutputConstFloat(const MIRConst &constVal, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindConstFloat); - MIRFloatConst *fconst = static_cast(&constVal); - mplExport.WriteNum(fconst->GetIntValue()); + const auto &fconst = static_cast(constVal); + mplExport.WriteNum(fconst.GetIntValue()); } -void OutputConstDouble(MIRConst &constVal, BinaryMplExport &mplExport) { +void OutputConstDouble(const MIRConst &constVal, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindConstDouble); - MIRDoubleConst *dconst = static_cast(&constVal); - mplExport.WriteNum(dconst->GetIntValue()); + const auto &dconst = static_cast(constVal); + mplExport.WriteNum(dconst.GetIntValue()); } -void OutputConstAgg(MIRConst &constVal, BinaryMplExport &mplExport) { +void OutputConstAgg(const MIRConst &constVal, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindConstAgg); mplExport.OutputConstBase(constVal); - MIRAggConst *aggConst = static_cast(&constVal); - size_t size = aggConst->GetConstVec().size(); + const auto &aggConst = static_cast(constVal); + size_t size = aggConst.GetConstVec().size(); mplExport.WriteNum(size); for (size_t i = 0; i < size; i++) { - mplExport.OutputConst(aggConst->GetConstVecItem(i)); + mplExport.OutputConst(aggConst.GetConstVecItem(i)); } } -void OutputConstSt(MIRConst &constVal, BinaryMplExport &mplExport) { +void OutputConstSt(const MIRConst &constVal, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindConstSt); mplExport.OutputConstBase(constVal); - MIRStConst *stConst = static_cast(&constVal); - size_t size = stConst->GetStVec().size(); + const auto &stConst = static_cast(constVal); + size_t size = stConst.GetStVec().size(); mplExport.WriteNum(size); for (size_t i = 0; i < size; i++) { - mplExport.OutputSymbol(stConst->GetStVecItem(i)); + mplExport.OutputSymbol(stConst.GetStVecItem(i)); } - size = stConst->GetStOffsetVec().size(); + size = stConst.GetStOffsetVec().size(); mplExport.WriteNum(size); for (size_t i = 0; i < size; i++) { - mplExport.WriteNum(stConst->GetStOffsetVecItem(i)); + mplExport.WriteNum(stConst.GetStOffsetVecItem(i)); } } @@ -126,71 +126,71 @@ void InitOutputConstFactory() { RegisterFactoryFunction(kConstStConst, OutputConstSt); } -void OutputTypeScalar(MIRType &ty, BinaryMplExport &mplExport) { +void OutputTypeScalar(const MIRType &ty, BinaryMplExport &mplExport) { mplExport.WriteNum(kBinKindTypeScalar); mplExport.OutputTypeBase(ty); } -void OutputTypePointer(MIRType &ty, BinaryMplExport &mplExport) { - MIRPtrType *type = static_cast(&ty); +void OutputTypePointer(const MIRType &ty, BinaryMplExport &mplExport) { + const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypePointer); - mplExport.OutputTypeBase(*type); - mplExport.OutputType(type->GetPointedTyIdx()); + mplExport.OutputTypeBase(type); + mplExport.OutputType(type.GetPointedTyIdx()); } -void OutputTypeByName(MIRType &ty, BinaryMplExport &mplExport) { - MIRTypeByName *type = static_cast(&ty); +void OutputTypeByName(const MIRType &ty, BinaryMplExport &mplExport) { + const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeByName); - mplExport.OutputTypeBase(*type); + mplExport.OutputTypeBase(type); } -void OutputTypeFArray(MIRType &ty, BinaryMplExport &mplExport) { - MIRFarrayType *type = static_cast(&ty); +void OutputTypeFArray(const MIRType &ty, BinaryMplExport &mplExport) { + const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeFArray); - mplExport.OutputTypeBase(*type); - mplExport.OutputType(type->GetElemTyIdx()); + mplExport.OutputTypeBase(type); + mplExport.OutputType(type.GetElemTyIdx()); } -void OutputTypeJArray(MIRType &ty, BinaryMplExport &mplExport) { - MIRJarrayType *type = static_cast(&ty); +void OutputTypeJArray(const MIRType &ty, BinaryMplExport &mplExport) { + const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeJarray); - mplExport.OutputTypeBase(*type); - mplExport.OutputType(type->GetElemTyIdx()); + mplExport.OutputTypeBase(type); + mplExport.OutputType(type.GetElemTyIdx()); } -void OutputTypeArray(MIRType &ty, BinaryMplExport &mplExport) { - MIRArrayType *type = static_cast(&ty); +void OutputTypeArray(const MIRType &ty, BinaryMplExport &mplExport) { + const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeArray); - mplExport.OutputTypeBase(*type); - mplExport.WriteNum(type->GetDim()); - for (int i = 0; i < type->GetDim(); i++) { - mplExport.WriteNum(type->GetSizeArrayItem(i)); + mplExport.OutputTypeBase(type); + mplExport.WriteNum(type.GetDim()); + for (int i = 0; i < type.GetDim(); i++) { + mplExport.WriteNum(type.GetSizeArrayItem(i)); } - mplExport.OutputType(type->GetElemTyIdx()); + mplExport.OutputType(type.GetElemTyIdx()); } -void OutputTypeFunction(MIRType &ty, BinaryMplExport &mplExport) { - MIRFuncType *type = static_cast(&ty); +void OutputTypeFunction(const MIRType &ty, BinaryMplExport &mplExport) { + const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeFunction); - mplExport.OutputTypeBase(*type); - mplExport.OutputType(type->GetRetTyIdx()); - mplExport.WriteNum(type->IsVarargs()); - size_t size = type->GetParamTypeList().size(); + mplExport.OutputTypeBase(type); + mplExport.OutputType(type.GetRetTyIdx()); + mplExport.WriteNum(type.IsVarargs()); + size_t size = type.GetParamTypeList().size(); mplExport.WriteNum(size); for (size_t i = 0; i < size; i++) { - mplExport.OutputType(type->GetParamTypeList()[i]); + mplExport.OutputType(type.GetParamTypeList()[i]); } - size = type->GetParamAttrsList().size(); + size = type.GetParamAttrsList().size(); mplExport.WriteNum(size); for (size_t i = 0; i < size; i++) { - mplExport.OutputTypeAttrs(type->GetParamAttrsList()[i]); + mplExport.OutputTypeAttrs(type.GetParamAttrsList()[i]); } } -void OutputTypeParam(MIRType &ty, BinaryMplExport &mplExport) { - MIRTypeParam *type = static_cast(&ty); +void OutputTypeParam(const MIRType &ty, BinaryMplExport &mplExport) { + const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeParam); - mplExport.OutputTypeBase(*type); + mplExport.OutputTypeBase(type); } void OutputTypeInstantVector(MIRType &ty, BinaryMplExport &mplExport) { @@ -209,56 +209,56 @@ void OutputTypeGenericInstant(MIRType &ty, BinaryMplExport &mplExport) { mplExport.OutputType(type->GetGenericTyIdx()); } -void OutputTypeBitField(MIRType &ty, BinaryMplExport &mplExport) { - MIRBitFieldType *type = static_cast(&ty); +void OutputTypeBitField(const MIRType &ty, BinaryMplExport &mplExport) { + const auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeBitField); - mplExport.OutputTypeBase(*type); - mplExport.WriteNum(type->GetFieldSize()); + mplExport.OutputTypeBase(type); + mplExport.WriteNum(type.GetFieldSize()); } // for Struct/StructIncomplete/Union void OutputTypeStruct(MIRType &ty, BinaryMplExport &mplExport) { - MIRStructType *type = static_cast(&ty); + auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeStruct); - mplExport.OutputTypeBase(*type); + mplExport.OutputTypeBase(type); MIRTypeKind kind = ty.GetKind(); - if (type->IsImported()) { + if (type.IsImported()) { CHECK_FATAL(ty.GetKind() != kTypeUnion, "must be"); kind = kTypeStructIncomplete; } mplExport.WriteNum(kind); if (kind != kTypeStructIncomplete) { - mplExport.OutputStructTypeData(*type); + mplExport.OutputStructTypeData(type); } } void OutputTypeClass(MIRType &ty, BinaryMplExport &mplExport) { - MIRClassType *type = static_cast(&ty); + auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeClass); - mplExport.OutputTypeBase(*type); + mplExport.OutputTypeBase(type); MIRTypeKind kind = ty.GetKind(); - if (type->IsImported()) { + if (type.IsImported()) { kind = kTypeClassIncomplete; } mplExport.WriteNum(kind); if (kind != kTypeClassIncomplete) { - mplExport.OutputStructTypeData(*type); - mplExport.OutputClassTypeData(*type); + mplExport.OutputStructTypeData(type); + mplExport.OutputClassTypeData(type); } } void OutputTypeInterface(MIRType &ty, BinaryMplExport &mplExport) { - MIRInterfaceType *type = static_cast(&ty); + auto &type = static_cast(ty); mplExport.WriteNum(kBinKindTypeInterface); - mplExport.OutputTypeBase(*type); + mplExport.OutputTypeBase(type); MIRTypeKind kind = ty.GetKind(); - if (type->IsImported()) { + if (type.IsImported()) { kind = kTypeInterfaceIncomplete; } mplExport.WriteNum(kind); if (kind != kTypeInterfaceIncomplete) { - mplExport.OutputStructTypeData(*type); - mplExport.OutputInterfaceTypeData(*type); + mplExport.OutputStructTypeData(type); + mplExport.OutputInterfaceTypeData(type); } } @@ -697,10 +697,10 @@ void BinaryMplExport::WriteContentField(int fieldNum, uint64 &fieldStartP) { } void BinaryMplExport::Export(const std::string &fname) { - constexpr int kFieldNum = 3; - uint64 fieldStartPoint[kFieldNum]; + constexpr int fieldNum = 3; + uint64 fieldStartPoint[fieldNum]; WriteInt(kMpltMagicNumber); - WriteContentField(kFieldNum, *fieldStartPoint); + WriteContentField(fieldNum, *fieldStartPoint); WriteStrField(fieldStartPoint[0]); WriteTypeField(fieldStartPoint[1]); WriteNum(kBinFinish); diff --git a/src/maple_ir/src/bin_mpl_import.cpp b/src/maple_ir/src/bin_mpl_import.cpp index 22e8549d5270b79b39f3fd0286adfe7fcc0857fa..2d34eea7c158660cca387ae6b716661b2fd5394d 100644 --- a/src/maple_ir/src/bin_mpl_import.cpp +++ b/src/maple_ir/src/bin_mpl_import.cpp @@ -115,7 +115,7 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { } else if (tag == kBinKindConstAddrof) { ImportConstBase(kind, type, fieldID); MIRSymbol *sym = InSymbol(func); - ASSERT(sym, "null ptr check"); + ASSERT(sym != nullptr, "null ptr check"); FieldID fi = ReadNum(); return memPool->New(sym->GetStIdx(), fi, *type); } else if (tag == kBinKindConstAddrofFunc) { @@ -161,7 +161,7 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { MIRAggConst *aggConst = mod.GetMemPool()->New(mod, *type); int64 size = ReadNum(); for (int64 i = 0; i < size; i++) { - aggConst->GetConstVec().push_back(ImportConst(func)); + aggConst->PushBack(ImportConst(func)); } return aggConst; } else if (tag == kBinKindConstSt) { @@ -783,7 +783,7 @@ PUIdx BinaryMplImport::ImportFunction() { } ASSERT(tag == kBinFunction, "expecting kBinFunction"); MIRSymbol *funcSt = InSymbol(nullptr); - ASSERT(funcSt, "null ptr check"); + ASSERT(funcSt != nullptr, "null ptr check"); MIRFunction *func = nullptr; if (funcSt->GetFunction() == nullptr) { maple::MIRBuilder builder(&mod); @@ -814,22 +814,26 @@ inline void BinaryMplImport::SkipTotalSize() { void BinaryMplImport::ReadStrField() { SkipTotalSize(); + int64 tag = 0; int32 size = ReadInt(); for (int64 i = 0; i < size; i++) { GStrIdx stridx = ImportStr(); GlobalTables::GetConstPool().PutLiteralNameAsImported(stridx); } - ASSERT(ReadNum() == ~kBinStrStart, "pattern mismatch in Read STR"); + tag = ReadNum(); + ASSERT(tag == ~kBinStrStart, "pattern mismatch in Read STR"); } void BinaryMplImport::ReadTypeField() { SkipTotalSize(); + int64 tag = 0; int32 size = ReadInt(); for (int64 i = 0; i < size; i++) { ImportType(); } - ASSERT(ReadNum() == ~kBinTypeStart, "pattern mismatch in Read TYPE"); + tag = ReadNum(); + ASSERT(tag == ~kBinTypeStart, "pattern mismatch in Read TYPE"); } void BinaryMplImport::ReadContentField() { diff --git a/src/maple_ir/src/mir_builder.cpp b/src/maple_ir/src/mir_builder.cpp index 255a1ee8ebc641769619c8758bdde47397e7fe47..3f882d71a96902db17e4272073d1818f9509c46d 100644 --- a/src/maple_ir/src/mir_builder.cpp +++ b/src/maple_ir/src/mir_builder.cpp @@ -22,7 +22,7 @@ namespace maple { void MIRBuilder::AddIntFieldConst(const MIRStructType &sType, MIRAggConst &newConst, uint32 fieldID, int64 constValue) { MIRConst *fieldConst = mirModule->GetMemPool()->New(constValue, *sType.GetElemType(fieldID - 1), fieldID); - newConst.GetConstVec().push_back(fieldConst); + newConst.PushBack(fieldConst); } // This is for compiler-generated metadata 1-level struct @@ -32,7 +32,7 @@ void MIRBuilder::AddAddrofFieldConst(const MIRStructType &structType, MIRAggCons MIRConst *fieldConst = mirModule->GetMemPool()->New(fieldExpr->GetStIdx(), fieldExpr->GetFieldID(), *structType.GetElemType(fieldID - 1)); fieldConst->SetFieldID(fieldID); - newConst.GetConstVec().push_back(fieldConst); + newConst.PushBack(fieldConst); } // This is for compiler-generated metadata 1-level struct @@ -48,7 +48,7 @@ void MIRBuilder::AddAddroffuncFieldConst(const MIRStructType &structType, MIRAgg fieldConst = mirModule->GetMemPool()->New(addrofFuncExpr->GetPUIdx(), *structType.GetElemType(fieldID - 1), fieldID); } - newConst.GetConstVec().push_back(fieldConst); + newConst.PushBack(fieldConst); } // fieldID is continuously being updated during traversal; diff --git a/src/maple_ir/src/mir_pragma.cpp b/src/maple_ir/src/mir_pragma.cpp index 17074c4047308ecf18f52529d4d6bebd69e8aebf..39c1271088a1f3f66d23b4163e7a02df73a0ab8f 100644 --- a/src/maple_ir/src/mir_pragma.cpp +++ b/src/maple_ir/src/mir_pragma.cpp @@ -202,10 +202,10 @@ MIRPragmaElement *MIRPragma::GetPragmaElemFromSignature(const std::string &signa return elem; } -void MIRPragmaElement::Dump(int indent) { - constexpr int kIndentOffset = 2; - constexpr int kFloatPrec = 7; - constexpr int kDoublePrec = 16; +void MIRPragmaElement::Dump(int indent) const { + constexpr int indentOffset = 2; + constexpr int floatPrec = 7; + constexpr int doublePrec = 16; GStrIdx gStrIdx; std::string str = GetKind(valueType); switch (valueType) { @@ -226,11 +226,11 @@ void MIRPragmaElement::Dump(int indent) { break; case kValueFloat: LogInfo::MapleLogger() << std::setiosflags(std::ios::scientific) << str.c_str() << " " - << std::setprecision(kFloatPrec) << val.f << "f"; + << std::setprecision(floatPrec) << val.f << "f"; break; case kValueDouble: LogInfo::MapleLogger() << std::setiosflags(std::ios::scientific) << str.c_str() << " " - << std::setprecision(kDoublePrec) << val.d; + << std::setprecision(doublePrec) << val.d; break; case kValueMethodType: LogInfo::MapleLogger() << str.c_str() << " $" << std::hex << "0x" << val.u << std::dec; @@ -272,9 +272,9 @@ void MIRPragmaElement::Dump(int indent) { size_t i = 0; while (i < num) { if (num > 1) { - PrintIndentation(indent + kIndentOffset); + PrintIndentation(indent + indentOffset); } - subElemVec[i]->Dump(indent + kIndentOffset); + subElemVec[i]->Dump(indent + indentOffset); if (i != num - 1) { LogInfo::MapleLogger() << "," << std::endl; } @@ -297,12 +297,12 @@ void MIRPragmaElement::Dump(int indent) { size_t i = 0; while (i < num) { if (num > 1) { - PrintIndentation(indent + kIndentOffset); + PrintIndentation(indent + indentOffset); } LogInfo::MapleLogger() << "@" << GlobalTables::GetStrTable().GetStringFromStrIdx(subElemVec[i]->nameStrIdx).c_str() << " "; - subElemVec[i]->Dump(indent + kIndentOffset); + subElemVec[i]->Dump(indent + indentOffset); if (i != num - 1) { LogInfo::MapleLogger() << "," << std::endl; } @@ -321,7 +321,7 @@ void MIRPragmaElement::Dump(int indent) { } } -void MIRPragma::Dump(int indent) { +void MIRPragma::Dump(int indent) const { LogInfo::MapleLogger() << std::endl; PrintIndentation(indent); LogInfo::MapleLogger() << "pragma " << static_cast(visibility) << " "; diff --git a/src/maple_ir/src/parser.cpp b/src/maple_ir/src/parser.cpp index 1aceae9718407733078d4fc776201569c82c6537..50c96cfea7fef5f0932fadd5012aa616470ceca7 100644 --- a/src/maple_ir/src/parser.cpp +++ b/src/maple_ir/src/parser.cpp @@ -1969,7 +1969,6 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { MIRType *elemType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(arrayType.GetElemTyIdx()); MIRAggConst *newConst = mod.GetMemPool()->New(mod, type); theConst = newConst; - MapleVector &constVec = newConst->GetConstVec(); tokenKind = lexer.NextToken(); if (tokenKind == kTkRbrack) { Error("illegal empty initialization for array at "); @@ -2012,7 +2011,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { Error("expect const value or group of const values but get "); return false; } - constVec.push_back(subConst); + newConst->PushBack(subConst); // parse comma or rbrack tokenKind = lexer.GetTokenKind(); if (tokenKind == kTkComa) { @@ -2029,7 +2028,6 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { uint32 theFieldID; TyIdx fieldTyIdx; theConst = newConst; - MapleVector &constVec = newConst->GetConstVec(); tokenKind = lexer.NextToken(); if (tokenKind == kTkRbrack) { Error("illegal empty initialization for struct at "); @@ -2074,7 +2072,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { } ASSERT(subConst != nullptr, "subConst is null in MIRParser::ParseInitValue"); subConst->SetFieldID(theFieldID); - constVec.push_back(subConst); + newConst->PushBack(subConst); tokenKind = lexer.GetTokenKind(); // parse comma or rbrack if (tokenKind == kTkComa) { diff --git a/src/maple_phase/include/phase_impl.h b/src/maple_phase/include/phase_impl.h index e31e47e14b9b8453991b599635b2deb6fe6fc15e..ec380741aaec0dc2267f06784a31ed15f4c85f76 100644 --- a/src/maple_phase/include/phase_impl.h +++ b/src/maple_phase/include/phase_impl.h @@ -16,9 +16,10 @@ #define MAPLE_PHASE_INCLUDE_PHASE_IMPL_H #include "class_hierarchy.h" #include "mir_builder.h" +#include "mpl_scheduler.h" namespace maple { -class FuncOptimizeImpl { +class FuncOptimizeImpl : public MplTaskParam { public: explicit FuncOptimizeImpl(MIRModule *mod, KlassHierarchy *kh = nullptr, bool trace = false); virtual ~FuncOptimizeImpl(); diff --git a/src/maple_phase/include/phase_manager.h b/src/maple_phase/include/phase_manager.h index 575be72887858b47cccc36ca4161332b9c71714b..bfa2a9f1343803a01c4e6984504e6679279c99ad 100644 --- a/src/maple_phase/include/phase_manager.h +++ b/src/maple_phase/include/phase_manager.h @@ -21,7 +21,7 @@ namespace maple { class PhaseManager { public: - PhaseManager(MemPool *memPool, const char *name) + PhaseManager(MemPool *memPool, const std::string &name) : managerName(name), allocator(memPool), registeredPhases(std::less(), allocator.Adapter()), diff --git a/src/maple_util/include/mpl_scheduler.h b/src/maple_util/include/mpl_scheduler.h new file mode 100644 index 0000000000000000000000000000000000000000..7953c870ec6f63d9897b7352e100cf6fe13bcaae --- /dev/null +++ b/src/maple_util/include/mpl_scheduler.h @@ -0,0 +1,152 @@ +/* + * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + */ +#ifndef MAPLE_UTIL_INCLUDE_MPL_SCHEDULER_H +#define MAPLE_UTIL_INCLUDE_MPL_SCHEDULER_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "types_def.h" + +namespace maple { +#define MP_SYNC \ + (stmt) GlobalLock(); \ + stmt GlobalUnlock(); + +class MplTaskParam { + public: + MplTaskParam() = default; + virtual ~MplTaskParam() = default; +}; + +class MplTask { + public: + MplTask() : taskId(0) {} + + virtual ~MplTask() {} + + virtual int Run(MplTaskParam *param = nullptr) { + return 0; + } + + virtual int Finish(MplTaskParam *param = nullptr) { + return 0; + } + + void SetTaskId(uint32 id) { + taskId = id; + } + + uint32 GetTaskId() const { + return taskId; + } + + protected: + uint32 taskId; +}; + +class MplSchedulerParam { + public: + MplSchedulerParam() = default; + virtual ~MplSchedulerParam() = default; +}; + +class MplScheduler { + public: + explicit MplScheduler(const std::string &name); + virtual ~MplScheduler() {} + + virtual void AddTask(MplTask *task); + virtual int RunTask(uint32 nthreads, bool seq = false); + virtual MplSchedulerParam *EncodeThreadMainEnvironment(uint32 threadId) { + return nullptr; + } + + virtual void DecodeThreadMainEnvironment(MplSchedulerParam *env) {} + + virtual MplSchedulerParam *EncodeThreadFinishEnvironment() { + return nullptr; + } + + virtual void DecodeThreadFinishEnvironment(MplSchedulerParam *env) {} + + void GlobalLock() { + pthread_mutex_lock(&mutexGlobal); + } + + void GlobalUnlock() { + pthread_mutex_unlock(&mutexGlobal); + } + + void Reset(); + + protected: + std::string schedulerName; + std::vector tbTasks; + std::set tbTaskIdsToFinish; + uint32 taskIdForAdd; + uint32 taskIdToRun; + uint32 taskIdExpected; + uint32 numberTasks; + uint32 numberTasksFinish; + pthread_mutex_t mutexTaskIdsToRun; + pthread_mutex_t mutexTaskIdsToFinish; + pthread_mutex_t mutexTaskFinishProcess; + pthread_mutex_t mutexGlobal; + pthread_cond_t conditionFinishProcess; + bool isSchedulerSeq; + bool dumpTime; + + enum THREAD_STATUS { kThreadStop, kThreadRun, kThreadPause }; + + THREAD_STATUS statusFinish; + virtual int FinishTask(MplTask *task); + virtual MplTask *GetTaskToRun(); + virtual uint32 GetTaskIdsFinishSize(); + virtual MplTask *GetTaskFinishFirst(); + virtual void RemoveTaskFinish(uint32 id); + virtual void TaskIdFinish(uint32 id); + void ThreadMain(uint32 threadID, MplSchedulerParam *env); + void ThreadFinishNoSequence(MplSchedulerParam *env); + void ThreadFinishSequence(MplSchedulerParam *env); + void ThreadFinish(MplSchedulerParam *env); + // Callback Function + virtual void CallbackThreadMainStart() {} + + virtual void CallbackThreadMainEnd() {} + + virtual void CallbackThreadFinishStart() {} + + virtual void CallbackThreadFinishEnd() {} + + virtual MplTaskParam *CallbackGetTaskRunParam() { + return nullptr; + } + + virtual MplTaskParam *CallbackGetTaskFinishParam() { + return nullptr; + } +}; + +} // namespace maple + +#endif // MAPLE_UTIL_INCLUDE_MPLSCHEDULER_H diff --git a/src/maple_util/include/name_mangler.h b/src/maple_util/include/name_mangler.h index b12fcb7fe43315570f41840c6b4b5f7e8b4fbb92..9af40f21fea64375c4698aafa172f216b929bc56 100644 --- a/src/maple_util/include/name_mangler.h +++ b/src/maple_util/include/name_mangler.h @@ -73,7 +73,7 @@ static constexpr const char kMuidSuperclassPrefixStr[] = "__muid_superclass"; static constexpr const char kMuidGlobalRootlistPrefixStr[] = "__muid_globalrootlist"; static constexpr const char kMuidClassMetadataPrefixStr[] = "__muid_classmetadata"; static constexpr const char kMuidClassMetadataBucketPrefixStr[] = "__muid_classmetadata_bucket"; -static constexpr const char kMuidJavatextPrefixStr[] = "__muid_java_text"; +static constexpr const char kMuidJavatextPrefixStr[] = "java_text"; static constexpr const char kMuidRangeTabPrefixStr[] = "__muid_range_tab"; static constexpr const char kMuidConststrPrefixStr[] = "__muid_conststr"; static constexpr const char kVtabOffsetTabStr[] = "__vtable_offset_table"; diff --git a/src/mpl2mpl/src/muid_replacement.cpp b/src/mpl2mpl/src/muid_replacement.cpp index 7b1b580be7230294c158d700bdf02095d49de3a6..3064d9b80b2e67e474828bf616527e627e4342b0 100644 --- a/src/mpl2mpl/src/muid_replacement.cpp +++ b/src/mpl2mpl/src/muid_replacement.cpp @@ -264,7 +264,7 @@ void MUIDReplacement::GenericFuncDefTable() { // Use the muid index for now. It will be back-filled once we have the whole vector. MIRIntConst *indexConst = GetMIRModule().GetMemPool()->New(keyVal.second.second, *GlobalTables::GetTypeTable().GetUInt32()); - muidIdxTabConst->GetConstVec().push_back(indexConst); + muidIdxTabConst->PushBack(indexConst); } FieldVector parentFields; FieldVector fields; @@ -344,15 +344,15 @@ void MUIDReplacement::GenericFuncDefTable() { uint32 muidFieldID = 1; // To be processed by runtime builder->AddAddroffuncFieldConst(*funcDefTabEntryType, *entryConst, fieldID++, *funcSymbol); - funcDefTabConst->GetConstVec().push_back(entryConst); + funcDefTabConst->PushBack(entryConst); // To be emitted as method size by CG builder->AddAddroffuncFieldConst(*funcInfTabEntryType, *funcInfEntryConst, funcInfFieldID++, *funcSymbol); // To be emitted as method name by CG builder->AddAddroffuncFieldConst(*funcInfTabEntryType, *funcInfEntryConst, funcInfFieldID++, *funcSymbol); - funcInfTabConst->GetConstVec().push_back(funcInfEntryConst); + funcInfTabConst->PushBack(funcInfEntryConst); builder->AddIntFieldConst(*funcDefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[0]); builder->AddIntFieldConst(*funcDefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[1]); - funcDefMuidTabConst->GetConstVec().push_back(muidEntryConst); + funcDefMuidTabConst->PushBack(muidEntryConst); mplMuidStr += muid.ToStr(); } if (!funcDefTabConst->GetConstVec().empty()) { @@ -429,10 +429,10 @@ void MUIDReplacement::GenericDataDefTable() { uint32 muidFieldID = 1; // Will be emitted as 0 and processed by runtime builder->AddAddrofFieldConst(*dataDefTabEntryType, *entryConst, fieldID++, *mirSymbol); - dataDefTabConst->GetConstVec().push_back(entryConst); + dataDefTabConst->PushBack(entryConst); builder->AddIntFieldConst(*dataDefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[0]); builder->AddIntFieldConst(*dataDefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[1]); - dataDefMuidTabConst->GetConstVec().push_back(muidEntryConst); + dataDefMuidTabConst->PushBack(muidEntryConst); mplMuidStr += muid.ToStr(); if (trace) { LogInfo::MapleLogger() << "dataDefMap, MUID: " << muid.ToStr() << ", Variable Name: " << mirSymbol->GetName() @@ -518,10 +518,10 @@ void MUIDReplacement::GenericUnifiedUndefTable() { uint32 muidFieldID = 1; // to be filled by runtime builder->AddIntFieldConst(*unifiedUndefTabEntryType, *entryConst, fieldID++, 0); - funcUndefTabConst->GetConstVec().push_back(entryConst); + funcUndefTabConst->PushBack(entryConst); builder->AddIntFieldConst(*unifiedUndefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[0]); builder->AddIntFieldConst(*unifiedUndefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[1]); - funcUndefMuidTabConst->GetConstVec().push_back(muidEntryConst); + funcUndefMuidTabConst->PushBack(muidEntryConst); } if (!funcUndefTabConst->GetConstVec().empty()) { std::string funcUndefTabName = NameMangler::kMuidFuncUndefTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); @@ -554,10 +554,10 @@ void MUIDReplacement::GenericUnifiedUndefTable() { uint32 muidFieldID = 1; // Will be emitted as 0 and filled by runtime builder->AddAddrofFieldConst(*unifiedUndefTabEntryType, *entryConst, fieldID++, *mirSymbol); - dataUndefTabConst->GetConstVec().push_back(entryConst); + dataUndefTabConst->PushBack(entryConst); builder->AddIntFieldConst(*unifiedUndefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[0]); builder->AddIntFieldConst(*unifiedUndefMuidTabEntryType, *muidEntryConst, muidFieldID++, muid.data.words[1]); - dataUndefMuidTabConst->GetConstVec().push_back(muidEntryConst); + dataUndefMuidTabConst->PushBack(muidEntryConst); mplMuidStr += muid.ToStr(); if (trace) { LogInfo::MapleLogger() << "dataUndefMap, MUID: " << muid.ToStr() << ", Variable Name: " << mirSymbol->GetName() @@ -599,7 +599,7 @@ void MUIDReplacement::GenericRangeTable() { MUID mplMd5 = GetMUID(item); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, mplMd5.data.words[0]); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, mplMd5.data.words[1]); - rangeTabConst->GetConstVec().push_back(entryConst); + rangeTabConst->PushBack(entryConst); } for (uint32 i = RangeIdx::kVtab; i < RangeIdx::kMaxNum; i++) { // Use an integer to mark which entry is for which table @@ -610,13 +610,13 @@ void MUIDReplacement::GenericRangeTable() { if (st == nullptr) { builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); - rangeTabConst->GetConstVec().push_back(entryConst); + rangeTabConst->PushBack(entryConst); continue; } } builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, i); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, i); - rangeTabConst->GetConstVec().push_back(entryConst); + rangeTabConst->PushBack(entryConst); } // Please refer to mrt/compiler-rt/include/mpl_linker.h for the layout std::vector workList = { @@ -644,7 +644,7 @@ void MUIDReplacement::GenericRangeTable() { builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); } - rangeTabConst->GetConstVec().push_back(entryConst); + rangeTabConst->PushBack(entryConst); } if (!rangeTabConst->GetConstVec().empty()) { rangeArrayType.SetSizeArrayItem(0, rangeTabConst->GetConstVec().size()); @@ -1131,7 +1131,7 @@ void MUIDReplacement::GenericGlobalRootList() { ASSERT(PTY_ptr < GlobalTables::GetTypeTable().GetTypeTable().size(), "index out of bound"); MIRType &ptrType = *GlobalTables::GetTypeTable().GetTypeTable()[PTY_ptr]; MIRConst *constNode = GetMIRModule().GetMemPool()->New(symbol->GetStIdx(), 0, ptrType); - newConst->GetConstVec().push_back(constNode); + newConst->PushBack(constNode); } std::string gcRootsName = NameMangler::kGcRootList; if (!newConst->GetConstVec().empty()) { @@ -1149,8 +1149,8 @@ void MUIDReplacement::GenericCompilerVersionNum() { MIRType &type = *GlobalTables::GetTypeTable().GetInt32(); MIRConst *firstConst = GetMIRModule().GetMemPool()->New(Version::kMajorMplVersion, type); MIRConst *secondConst = GetMIRModule().GetMemPool()->New(Version::kMinorCompilerVersion, type); - newConst->GetConstVec().push_back(firstConst); - newConst->GetConstVec().push_back(secondConst); + newConst->PushBack(firstConst); + newConst->PushBack(secondConst); std::string symName = NameMangler::kCompilerVersionNum + GetMIRModule().GetFileNameAsPostfix(); MIRSymbol *versionNum = builder->CreateGlobalDecl(symName.c_str(), arrayType); versionNum->SetKonst(newConst); diff --git a/src/mpl2mpl/src/native_stub_func.cpp b/src/mpl2mpl/src/native_stub_func.cpp index 68f2678fc2db9014c84e45b93f5c835e813dfa58..e54f8e40cd94f3c40d2ce46ca8908dd3cd82a99e 100644 --- a/src/mpl2mpl/src/native_stub_func.cpp +++ b/src/mpl2mpl/src/native_stub_func.cpp @@ -302,7 +302,7 @@ void GenericNativeStubFunc::GenericRegFuncTabEntry() { MIRConst *newConst = GetMIRModule().GetMemPool()->New(static_cast((locIdx << locIdxShift) | locIdxMask), *GlobalTables::GetTypeTable().GetVoidPtr()); - regFuncTabConst->GetConstVec().push_back(newConst); + regFuncTabConst->PushBack(newConst); } void GenericNativeStubFunc::GenericRegFuncTab() { @@ -324,10 +324,10 @@ void GenericNativeStubFunc::GenericRegTabEntry(const MIRFunction &func) { // Using MIRIntConst instead of MIRStruct for RegTable. MIRConst *baseConst = GetMIRModule().GetMemPool()->New(classIdx, *GlobalTables::GetTypeTable().GetVoidPtr()); - regTableConst->GetConstVec().push_back(baseConst); + regTableConst->PushBack(baseConst); MIRConst *newConst = GetMIRModule().GetMemPool()->New(nameIdx, *GlobalTables::GetTypeTable().GetVoidPtr()); - regTableConst->GetConstVec().push_back(newConst); + regTableConst->PushBack(newConst); } void GenericNativeStubFunc::GenericRegisteredNativeFuncCall(MIRFunction &func, const MIRFunction &nativeFunc, diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index 4f9c8dccc22badaba5c361c8b93b9fad9169050c..f3eaede166c5e948f8ecaf9a22d5b638146618cf 100644 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -732,7 +732,7 @@ MIRSymbol *ReflectionAnalysis::GenMethodsMetaData(const Klass &klass) { // @padding mirBuilder.AddIntFieldConst(methodsInfoType, *newconst, fieldID++, 0); #endif - aggconst->GetConstVec().push_back(newconst); + aggconst->PushBack(newconst); } MIRSymbol *methodsArraySt = GetOrCreateSymbol(NameMangler::kMethodsInfoPrefixStr + klass.GetKlassName(), arraytype.GetTypeIndex(), true); @@ -752,7 +752,7 @@ MIRSymbol *ReflectionAnalysis::GenSuperClassMetaData(const Klass &klass, std::li MIRSymbol *dklassSt = GetOrCreateSymbol(CLASSINFO_PREFIX_STR + (*it)->GetKlassName(), classMetadataTyIdx); MIRAggConst *newconst = module.GetMemPool()->New(module, superclassMetadataType); mirBuilder.AddAddrofFieldConst(superclassMetadataType, *newconst, 1, *dklassSt); - aggconst->GetConstVec().push_back(newconst); + aggconst->PushBack(newconst); } MIRSymbol *superclassArraySt = GetOrCreateSymbol(SUPERCLASSINFO_PREFIX_STR + klass.GetKlassName(), arrayType.GetTypeIndex(), true); @@ -893,7 +893,7 @@ MIRSymbol *ReflectionAnalysis::GenFieldsMetaData(const Klass &klass) { // @declaring class MIRSymbol *dklassSt = GetOrCreateSymbol(CLASSINFO_PREFIX_STR + klass.GetKlassName(), classMetadataTyIdx); mirBuilder.AddAddrofFieldConst(fieldsInfoType, *newconst, fieldID++, *dklassSt); - aggconst->GetConstVec().push_back(newconst); + aggconst->PushBack(newconst); idx++; } MIRSymbol *fieldsArraySt = @@ -1598,7 +1598,7 @@ void ReflectionAnalysis::GenClassHashMetaData() { MIRType &ptrType = *GlobalTables::GetTypeTable().GetTypeTable()[PTY_ptr]; MIRConst *classConst = module.GetMemPool()->New(classExpr->GetStIdx(), classExpr->GetFieldID(), ptrType); - bucketAggconst->GetConstVec().push_back(classConst); + bucketAggconst->PushBack(classConst); } bucketSt->SetKonst(bucketAggconst); } @@ -1620,7 +1620,7 @@ static void ReflectionAnalysisGenStrTab(MIRModule &mirModule, const std::string strtabSt->SetStorageClass(kScFstatic); for (const char &c : strTab) { MIRConst *newconst = mirModule.GetMemPool()->New(c, *GlobalTables::GetTypeTable().GetUInt8()); - strtabAggconst->GetConstVec().push_back(newconst); + strtabAggconst->PushBack(newconst); } strtabSt->SetKonst(strtabAggconst); } diff --git a/src/mpl2mpl/src/vtable_analysis.cpp b/src/mpl2mpl/src/vtable_analysis.cpp index 58776900aad024582c27ff8b7e201e187033dc46..8c338609c1e0551b7707e3f06abce294e000c5a4 100644 --- a/src/mpl2mpl/src/vtable_analysis.cpp +++ b/src/mpl2mpl/src/vtable_analysis.cpp @@ -169,7 +169,7 @@ void VtableAnalysis::GenVtableDefinition(const Klass &klass) { AddroffuncNode *addrofFuncNode = builder->CreateExprAddroffunc(vtabMethod->GetPuidx(), GetMIRModule().GetMemPool()); MIRConst *constNode = GetMIRModule().GetMemPool()->New(addrofFuncNode->GetPUIdx(), *voidPtrType); - newconst->GetConstVec().push_back(constNode); + newconst->PushBack(constNode); } // We also need to generate vtable and itable even if the class does not // have any virtual method, or does not implement any interface. Such a @@ -180,7 +180,7 @@ void VtableAnalysis::GenVtableDefinition(const Klass &klass) { // postpone this step to mplcg, where mplcg discovers all classes that does // not have any vtable or itable. if (newconst->GetConstVec().empty()) { - newconst->GetConstVec().push_back(zeroConst); + newconst->PushBack(zeroConst); } GenTableSymbol(VTAB_PREFIX_STR, klass.GetKlassName(), *newconst); } @@ -280,29 +280,29 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { ASSERT(firstItabEmitArray != nullptr, "null ptr check!"); for (MIRFunction *func : firstItabVec) { if (func != nullptr) { - firstItabEmitArray->GetConstVec().push_back( + firstItabEmitArray->PushBack( GetMIRModule().GetMemPool()->New(func->GetPuidx(), *voidPtrType)); } else { - firstItabEmitArray->GetConstVec().push_back(zeroConst); + firstItabEmitArray->PushBack(zeroConst); } } // initialize conflict solution array if (count != 0) { MIRAggConst *secondItabEmitArray = GetMIRModule().GetMemPool()->New(GetMIRModule(), *voidPtrType); // remember count in secondItabVec - secondItabEmitArray->GetConstVec().push_back(GetMIRModule().GetMemPool()->New(count, *voidPtrType)); - secondItabEmitArray->GetConstVec().push_back(oneConst); // padding + secondItabEmitArray->PushBack(GetMIRModule().GetMemPool()->New(count, *voidPtrType)); + secondItabEmitArray->PushBack(oneConst); // padding for (uint32 i = 0; i < kItabSecondHashSize; i++) { if (!secondItab[i] && !secondConflictFlag[i]) { continue; } else { - secondItabEmitArray->GetConstVec().push_back(GetMIRModule().GetMemPool()->New(i, *voidPtrType)); + secondItabEmitArray->PushBack(GetMIRModule().GetMemPool()->New(i, *voidPtrType)); if (secondItab[i]) { - secondItabEmitArray->GetConstVec().push_back( + secondItabEmitArray->PushBack( GetMIRModule().GetMemPool()->New(secondItab[i]->GetPuidx(), *voidPtrType)); } else { // it measn it was conflict again in the second hash - secondItabEmitArray->GetConstVec().push_back(oneConst); + secondItabEmitArray->PushBack(oneConst); } } } @@ -310,9 +310,8 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { ASSERT(func != nullptr, "null ptr check!"); const std::string &signatureName = DecodeBaseNameWithType(*func); uint32 nameIdx = ReflectionAnalysis::FindOrInsertRepeatString(signatureName); - secondItabEmitArray->GetConstVec().push_back(GetMIRModule().GetMemPool()->New(nameIdx, - *voidPtrType)); - secondItabEmitArray->GetConstVec().push_back( + secondItabEmitArray->PushBack(GetMIRModule().GetMemPool()->New(nameIdx, *voidPtrType)); + secondItabEmitArray->PushBack( GetMIRModule().GetMemPool()->New(func->GetPuidx(), *voidPtrType)); } // Create the second-level itable, in which hashcode is looked up by binary searching @@ -320,8 +319,7 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { // push the conflict symbol to the first-level itable StIdx symIdx = GlobalTables::GetGsymTable().GetStIdxFromStrIdx( GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(ITAB_CONFLICT_PREFIX_STR + klass.GetKlassName())); - firstItabEmitArray->GetConstVec().push_back(GetMIRModule().GetMemPool()->New(symIdx, 0, - *voidPtrType)); + firstItabEmitArray->PushBack(GetMIRModule().GetMemPool()->New(symIdx, 0, *voidPtrType)); } GenTableSymbol(ITAB_PREFIX_STR, klass.GetKlassName(), *firstItabEmitArray); }