diff --git a/BUILD.gn b/BUILD.gn index 2a8bc19a8ca8639ae62c11dc24fea6cbe8fb58bb..479351f76b44c8b7ef2dd8263cab403b5ea26e11 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -30,6 +30,12 @@ group("mplfe") { ] } +group("mplfeUT") { + deps = [ + "${MPLFE_ROOT}/test:mplfeUT", + ] +} + group("ast2mpl") { deps = [] if (IS_AST2MPL_EXISTS == "1") { diff --git a/Makefile b/Makefile index dd9312517fcc8f060d60a0b2a53bf372665eb7e4..e34a8a8fc8142d707b6b06ce23395cc85fee737e 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,10 @@ ast2mpl: mplfe: $(call build_gn, ${GN_OPTIONS}, mplfe) +.PHONY: mplfeUT +mplfeUT: + $(call build_gn, ${GN_OPTIONS} COV_CHECK=1, mplfeUT) + .PHONY: install install: maple $(shell mkdir -p $(MAPLE_ROOT)/output/ops/linker/; \ diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index a587a85778bd0435729dab252051b7b9166184b5..e2cc8c3fbceee7a0a0595165f78077c93d0d482a 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -21,6 +21,7 @@ declare_args() { GN_BUILD_TYPE = "" HOST_ARCH = 64 MIR_JAVA = 1 + COV_CHECK = 0 } # Define global args diff --git a/build/envsetup.sh b/build/envsetup.sh index 9536e0a809d798df4a4af65eddd47700d189c0ec..071ab644172e3ef051f75032ca37f9b4e91ba9e3 100644 --- a/build/envsetup.sh +++ b/build/envsetup.sh @@ -26,3 +26,5 @@ if [ -d ${MAPLE_ROOT}/src/ast2mpl ]; then else export IS_AST2MPL_EXISTS=0 fi +export GCOV_PREFIX=${MAPLE_ROOT}/report/gcda +export GCOV_PREFIX_STRIP=7 diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index a43b06066043118a424f99594593b8d23e5121ed..4bba43c9b7cbc1a3a3fe757b2cffd759af6c603a 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 1325a895ee47d3899e033741176b33dd703d7f49..c38af607d42b164ddd0c8f0d72ad6fc4ac2c3bc7 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index 88b01e34d3aa2c7c117f32a89e3671e38d08f322..ee4d005f1d6293fb2bd02c21acb39b5c659a2507 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index bf31a7baec611102050f3e8b51cca6ce0974c064..cbee045db01565b850160591652763d5d734487d 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_driver/include/compiler.h b/src/maple_driver/include/compiler.h index 23376d5009ae062d5400d5d04faf82b2fa753755..ba16aff935aaee766a190e24cbd36be03f53657a 100644 --- a/src/maple_driver/include/compiler.h +++ b/src/maple_driver/include/compiler.h @@ -38,7 +38,7 @@ class Compiler { virtual ~Compiler() = default; - virtual ErrorCode Compile(const MplOptions &options, MIRModulePtr &theModule); + virtual ErrorCode Compile(const MplOptions &options, std::unique_ptr &theModule); virtual void GetTmpFilesToDelete(const MplOptions&, std::vector&) const {} @@ -70,11 +70,13 @@ class Compiler { const std::string name; std::string MakeOption(const MplOptions &options) const; void AppendDefaultOptions(std::map &finalOptions, - const std::map &defaultOptions) const; + const std::map &defaultOptions, + std::ostringstream &strOption, bool isDebug) const; void AppendOptions(std::map &finalOptions, const std::string &key, const std::string &value) const; void AppendExtraOptions(std::map &finalOptions, - const std::map> &extraOptions) const; + const MplOptions &options, + std::ostringstream &strOption, bool isDebug) const; std::map MakeDefaultOptions(const MplOptions &options) const; int Exe(const MplOptions &mplOptions, const std::string &options) const; const std::string &GetName() const { @@ -101,7 +103,7 @@ class MapleCombCompiler : public Compiler { ~MapleCombCompiler() = default; - ErrorCode Compile(const MplOptions &options, MIRModulePtr &theModule) override; + ErrorCode Compile(const MplOptions &options, std::unique_ptr &theModule) override; void PrintCommand(const MplOptions &options) const override; std::string GetInputFileName(const MplOptions &options) const override; @@ -118,7 +120,7 @@ class MplcgCompiler : public Compiler { explicit MplcgCompiler(const std::string &name) : Compiler(name) {} ~MplcgCompiler() = default; - ErrorCode Compile(const MplOptions &options, MIRModulePtr &theModule) override; + ErrorCode Compile(const MplOptions &options, std::unique_ptr &theModule) override; void PrintCommand(const MplOptions &options) const override; private: std::string GetInputFileName(const MplOptions &options) const override; diff --git a/src/maple_driver/include/compiler_factory.h b/src/maple_driver/include/compiler_factory.h index d6dc772338e547173a0108c254356f54ee807343..1d85b92d3ee9196e3df3f76661c34fcc18d6ec14 100644 --- a/src/maple_driver/include/compiler_factory.h +++ b/src/maple_driver/include/compiler_factory.h @@ -40,7 +40,7 @@ class CompilerFactory { const std::unordered_set &finalOutputs) const; SupportedCompilers supportedCompilers; CompilerSelector *compilerSelector; - MIRModule *theModule = nullptr; + std::unique_ptr theModule; }; } // namespace maple #endif // MAPLE_DRIVER_INCLUDE_COMPILER_FACTORY_H diff --git a/src/maple_driver/include/driver_runner.h b/src/maple_driver/include/driver_runner.h index 8ed6b444feb22914178baebcff0af0cf5647f784..77f435f7d82c81be73e513a9bd95c62b5c870776 100644 --- a/src/maple_driver/include/driver_runner.h +++ b/src/maple_driver/include/driver_runner.h @@ -34,7 +34,7 @@ class DriverRunner final { public: DriverRunner(MIRModule *theModule, const std::vector &exeNames, Options *mpl2mplOptions, std::string mpl2mplInput, MeOption *meOptions, const std::string &meInput, std::string actualInput, - MemPool *optMp, bool timePhases = false, + MemPool *optMp, bool fileParsed = false, bool timePhases = false, bool genVtableImpl = false, bool genMeMpl = false) : theModule(theModule), exeNames(exeNames), @@ -44,14 +44,15 @@ class DriverRunner final { meInput(meInput), actualInput(actualInput), optMp(optMp), + fileParsed(fileParsed), timePhases(timePhases), genVtableImpl(genVtableImpl), genMeMpl(genMeMpl) {} DriverRunner(MIRModule *theModule, const std::vector &exeNames, std::string actualInput, MemPool *optMp, - bool timePhases = false, bool genVtableImpl = false, bool genMeMpl = false) - : DriverRunner(theModule, exeNames, nullptr, "", nullptr, "", actualInput, optMp, timePhases, genVtableImpl, - genMeMpl) {} + bool fileParsed = false, bool timePhases = false, bool genVtableImpl = false, bool genMeMpl = false) + : DriverRunner(theModule, exeNames, nullptr, "", nullptr, "", actualInput, optMp, fileParsed, timePhases, + genVtableImpl, genMeMpl) {} ~DriverRunner() = default; @@ -62,8 +63,6 @@ class DriverRunner final { this->cgInput = cgInput; } private: - static bool FuncOrderLessThan(const MIRFunction *left, const MIRFunction *right); - bool IsFramework() const; ErrorCode ParseInput(const std::string &outputFile, const std::string &oriBasename) const; std::string GetPostfix() const; @@ -90,6 +89,7 @@ class DriverRunner final { std::string meInput; std::string actualInput; MemPool *optMp; + bool fileParsed = false; bool timePhases = false; bool genVtableImpl = false; bool genMeMpl = false; diff --git a/src/maple_driver/include/mpl_options.h b/src/maple_driver/include/mpl_options.h index 19a848a83b90deed56320e327cfa4a7379a39be1..be24bb47340dc0080831c054df292fd650c65a42 100644 --- a/src/maple_driver/include/mpl_options.h +++ b/src/maple_driver/include/mpl_options.h @@ -29,12 +29,12 @@ namespace maple { enum InputFileType { - kNone, - kClass, - kJar, - kMpl, - kVtableImplMpl, - kS, + kFileTypeNone, + kFileTypeClass, + kFileTypeJar, + kFileTypeMpl, + kFileTypeVtableImplMpl, + kFileTypeS, }; enum OptimizationLevel { @@ -126,6 +126,10 @@ class MplOptions { return optimizationLevel; } + const std::string &GetMpltFile() const { + return mpltFile; + } + bool HasSetDefaultLevel() const { return setDefaultLevel; } @@ -192,7 +196,8 @@ class MplOptions { std::string outputFolder = ""; std::string outputName = "maple"; std::string exeFolder = ""; - InputFileType inputFileType = InputFileType::kNone; + std::string mpltFile = ""; + InputFileType inputFileType = InputFileType::kFileTypeNone; OptimizationLevel optimizationLevel = OptimizationLevel::kO0; RunMode runMode = RunMode::kUnkownRun; bool setDefaultLevel = false; diff --git a/src/maple_driver/src/compiler.cpp b/src/maple_driver/src/compiler.cpp index 08dbbdb991f539d53f514f27f5cd3a8032e963be..495ba5827acbbc17947eef98e38b6d7db374ac55 100644 --- a/src/maple_driver/src/compiler.cpp +++ b/src/maple_driver/src/compiler.cpp @@ -42,7 +42,7 @@ std::string Compiler::GetBinPath(const MplOptions &mplOptions) const { return binPath; } -ErrorCode Compiler::Compile(const MplOptions &options, MIRModulePtr&) { +ErrorCode Compiler::Compile(const MplOptions &options, std::unique_ptr &) { MPLTimer timer = MPLTimer(); LogInfo::MapleLogger() << "Starting " << GetName() << '\n'; timer.Start(); @@ -61,16 +61,9 @@ ErrorCode Compiler::Compile(const MplOptions &options, MIRModulePtr&) { std::string Compiler::MakeOption(const MplOptions &options) const { std::map finalOptions; std::map defaultOptions = MakeDefaultOptions(options); - AppendDefaultOptions(finalOptions, defaultOptions); - AppendExtraOptions(finalOptions, options.GetExtras()); std::ostringstream strOption; - for (const auto &finalOption : finalOptions) { - strOption << " " << finalOption.first << " " << finalOption.second.GetValue(); - if (options.HasSetDebugFlag()) { - LogInfo::MapleLogger() << Compiler::GetName() << " options: " << finalOption.first << " " - << finalOption.second.GetValue() << '\n'; - } - } + AppendDefaultOptions(finalOptions, defaultOptions, strOption, options.HasSetDebugFlag()); + AppendExtraOptions(finalOptions, options, strOption, options.HasSetDebugFlag()); strOption << " " << this->GetInputFileName(options); if (options.HasSetDebugFlag()) { LogInfo::MapleLogger() << Compiler::GetName() << " input files: " << GetInputFileName(options) << '\n'; @@ -79,21 +72,44 @@ std::string Compiler::MakeOption(const MplOptions &options) const { } void Compiler::AppendDefaultOptions(std::map &finalOptions, - const std::map &defaultOptions) const { + const std::map &defaultOptions, + std::ostringstream &strOption, bool isDebug) const { for (const auto &defaultIt : defaultOptions) { (void)finalOptions.insert(make_pair(defaultIt.first, defaultIt.second)); + strOption << " " << defaultIt.first << " " << defaultIt.second.GetValue(); + if (isDebug) { + LogInfo::MapleLogger() << Compiler::GetName() << " options: " << defaultIt.first << " " + << defaultIt.second.GetValue() << '\n'; + } } } void Compiler::AppendExtraOptions(std::map &finalOptions, - const std::map> &extraOptions) const { + const MplOptions &options, + std::ostringstream &strOption, bool isDebug) const { const std::string &binName = GetBinName(); - auto extras = extraOptions.find(binName); - if (extras == extraOptions.end()) { + auto exeOption = options.GetExeOptions().find(binName); + if (exeOption == options.GetExeOptions().end()) { return; } - for (const auto &secondExtras : extras->second) { + std::map> extraOptions = options.GetExtras(); + auto &extraOption = extraOptions[binName]; + for (size_t i = 0; i < exeOption->second.size(); ++i) { + if (exeOption->second[i].Args() != "") { + MplOption mplOption("-" + exeOption->second[i].OptionKey(), exeOption->second[i].Args()); + extraOption.push_back(mplOption); + } else { + MplOption mplOption("-" + exeOption->second[i].OptionKey(), ""); + extraOption.push_back(mplOption); + } + } + for (const auto &secondExtras : extraOption) { AppendOptions(finalOptions, secondExtras.GetKey(), secondExtras.GetValue()); + strOption << " " << secondExtras.GetKey() << " " << secondExtras.GetValue(); + if (isDebug) { + LogInfo::MapleLogger() << Compiler::GetName() << " options: " << secondExtras.GetKey() << " " + << secondExtras.GetValue() << '\n'; + } } } @@ -103,7 +119,7 @@ std::map Compiler::MakeDefaultOptions(const MplOptions & if (rawDefaultOptions.mplOptions != nullptr) { for (uint32_t i = 0; i < rawDefaultOptions.length; ++i) { (void)defaultOptions.insert(std::make_pair(rawDefaultOptions.mplOptions[i].GetKey(), - rawDefaultOptions.mplOptions[i])); + rawDefaultOptions.mplOptions[i])); } } return defaultOptions; diff --git a/src/maple_driver/src/compiler_factory.cpp b/src/maple_driver/src/compiler_factory.cpp index e2a1bd1e5fc3e867147b235a752aea2c947c6537..05451f95865032c8c575f6d5e65252e50e999a08 100644 --- a/src/maple_driver/src/compiler_factory.cpp +++ b/src/maple_driver/src/compiler_factory.cpp @@ -53,10 +53,6 @@ CompilerFactory::~CompilerFactory() { delete compilerSelector; compilerSelector = nullptr; } - if (theModule != nullptr) { - delete theModule; - theModule = nullptr; - } } void CompilerFactory::Insert(const std::string &name, Compiler *value) { diff --git a/src/maple_driver/src/driver_runner.cpp b/src/maple_driver/src/driver_runner.cpp index c64b617a3e0591e56615ef4a8310f76cfcbc6f7b..5400b23a95a1f483f5ae9ef98c083ce799230586 100644 --- a/src/maple_driver/src/driver_runner.cpp +++ b/src/maple_driver/src/driver_runner.cpp @@ -19,6 +19,7 @@ #include "mpl_timer.h" #include "mir_function.h" #include "mir_parser.h" +#include "file_utils.h" #include "lower.h" #if TARGAARCH64 @@ -104,10 +105,6 @@ ErrorCode DriverRunner::Run() { return kErrorNoError; } -bool DriverRunner::FuncOrderLessThan(const MIRFunction *left, const MIRFunction *right) { - return left->GetLayoutType() < right->GetLayoutType(); -} - bool DriverRunner::IsFramework() const { return false; } @@ -134,10 +131,13 @@ ErrorCode DriverRunner::ParseInput(const std::string &outputFile, const std::str MIRParser parser(*theModule); ErrorCode ret = kErrorNoError; - bool parsed = parser.ParseMIR(0, 0, false, true); - if (!parsed) { - ret = kErrorExit; - parser.EmitError(outputFile); + bool parsed; + if (!fileParsed) { + parsed = parser.ParseMIR(0, 0, false, true); + if (!parsed) { + ret = kErrorExit; + parser.EmitError(outputFile); + } } timer.Stop(); LogInfo::MapleLogger() << "Parse consumed " << timer.Elapsed() << "s" << '\n'; diff --git a/src/maple_driver/src/maple_comb_compiler.cpp b/src/maple_driver/src/maple_comb_compiler.cpp index 52ae7fcac69d20f772daaad258b56e8814933ee9..3742816892f8e9486ab71e33c80022c2b4ab44b1 100644 --- a/src/maple_driver/src/maple_comb_compiler.cpp +++ b/src/maple_driver/src/maple_comb_compiler.cpp @@ -28,7 +28,7 @@ std::string MapleCombCompiler::GetInputFileName(const MplOptions &options) const return options.GetInputFiles(); } } - if (options.GetInputFileType() == InputFileType::kVtableImplMpl) { + if (options.GetInputFileType() == InputFileType::kFileTypeVtableImplMpl) { return options.GetOutputFolder() + options.GetOutputName() + ".VtableImpl.mpl"; } return options.GetOutputFolder() + options.GetOutputName() + ".mpl"; @@ -106,7 +106,7 @@ bool MapleCombCompiler::MakeMeOptions(const MplOptions &options) { } bool result = meOption.SolveOptions(it->second, options.HasSetDebugFlag()); if (result == false) { - LogInfo::MapleLogger() << "Meet error mpl2mpl options\n"; + LogInfo::MapleLogger() << "Meet error me options\n"; return false; } return true; @@ -127,10 +127,14 @@ bool MapleCombCompiler::MakeMpl2MplOptions(const MplOptions &options) { return true; } -ErrorCode MapleCombCompiler::Compile(const MplOptions &options, MIRModulePtr &theModule) { +ErrorCode MapleCombCompiler::Compile(const MplOptions &options, std::unique_ptr &theModule) { MemPool *optMp = memPoolCtrler.NewMemPool("maplecomb mempool"); std::string fileName = GetInputFileName(options); - theModule = new MIRModule(fileName); + bool fileParsed = true; + if (theModule == nullptr) { + theModule = std::make_unique(fileName); + fileParsed = false; + } MeOption &meOptions = MeOption::GetInstance(); Options &mpl2mplOptions = Options::GetInstance(); auto it = std::find(options.GetRunningExes().begin(), options.GetRunningExes().end(), kBinNameMe); @@ -150,8 +154,8 @@ ErrorCode MapleCombCompiler::Compile(const MplOptions &options, MIRModulePtr &th LogInfo::MapleLogger() << "Starting mpl2mpl&mplme\n"; PrintCommand(options); - DriverRunner runner(theModule, options.GetRunningExes(), &mpl2mplOptions, fileName, &meOptions, - fileName, fileName, optMp, + DriverRunner runner(theModule.get(), options.GetRunningExes(), &mpl2mplOptions, fileName, &meOptions, + fileName, fileName, optMp, fileParsed, options.HasSetTimePhases(), options.HasSetGenVtableImpl(), options.HasSetGenMeMpl()); ErrorCode nErr = runner.Run(); diff --git a/src/maple_driver/src/mpl_options.cpp b/src/maple_driver/src/mpl_options.cpp index 61b02ffae015a5ecf2c31b9df63f376428b9e319..6e3ab5adcb90f261b89f45364a9054af698d7da3 100644 --- a/src/maple_driver/src/mpl_options.cpp +++ b/src/maple_driver/src/mpl_options.cpp @@ -151,6 +151,7 @@ ErrorCode MplOptions::HandleGeneralOptions() { } break; case kInMplt: + mpltFile = opt.Args(); break; case kAllDebug: debugFlag = true; @@ -161,6 +162,7 @@ ErrorCode MplOptions::HandleGeneralOptions() { } ret = AddOption(opt); } + return ret; } @@ -218,20 +220,20 @@ ErrorCode MplOptions::DecideRunningPhases() { bool isNeedMapleComb = true; bool isNeedMplcg = true; switch (inputFileType) { - case InputFileType::kJar: + case InputFileType::kFileTypeJar: // fall-through - case InputFileType::kClass: + case InputFileType::kFileTypeClass: UpdateRunningExe(kBinNameJbc2mpl); break; - case InputFileType::kMpl: + case InputFileType::kFileTypeMpl: break; - case InputFileType::kVtableImplMpl: + case InputFileType::kFileTypeVtableImplMpl: isNeedMapleComb = false; break; - case InputFileType::kS: + case InputFileType::kFileTypeS: isNeedMplcg = false; break; - case InputFileType::kNone: + case InputFileType::kFileTypeNone: break; default: break; @@ -302,16 +304,6 @@ ErrorCode MplOptions::AddOption(const mapleOption::Option &option) { } // For compilers, such as me, mpl2mpl exeOptions[exeName].push_back(option); - // Fill extraOption - // For compiler bins called by system() - auto &extraOption = extras[exeName]; - if (option.Args() != "") { - MplOption mplOption("-" + option.OptionKey(), option.Args()); - extraOption.push_back(mplOption); - } else { - MplOption mplOption("-" + option.OptionKey(), ""); - extraOption.push_back(mplOption); - } } return kErrorNoError; } @@ -328,18 +320,18 @@ bool MplOptions::Init(const std::string &inputFile) { outputName = FileUtils::GetFileName(firstInputFile, false); std::string extensionName = FileUtils::GetFileExtension(firstInputFile); if (extensionName == "class") { - inputFileType = InputFileType::kClass; + inputFileType = InputFileType::kFileTypeClass; } else if (extensionName == "jar") { - inputFileType = InputFileType::kJar; + inputFileType = InputFileType::kFileTypeJar; } else if (extensionName == "mpl") { if (firstInputFile.find("VtableImpl") == std::string::npos) { - inputFileType = InputFileType::kMpl; + inputFileType = InputFileType::kFileTypeMpl; } else { - inputFileType = InputFileType::kVtableImplMpl; + inputFileType = InputFileType::kFileTypeVtableImplMpl; } } else if (extensionName == "s") { - inputFileType = InputFileType::kS; + inputFileType = InputFileType::kFileTypeS; } else { return false; } @@ -419,18 +411,6 @@ ErrorCode MplOptions::UpdatePhaseOption(const std::string &args, const std::stri if (ret != kErrorNoError) { return ret; } - // Fill extraOption - // For compiler bins called by system() - auto &extraOption = extras[exeName]; - for (size_t i = 0; i < exeOption.size(); ++i) { - if (exeOption[i].Args() != "") { - MplOption mplOption("-" + exeOption[i].OptionKey(), exeOption[i].Args()); - extraOption.push_back(mplOption); - } else { - MplOption mplOption("-" + exeOption[i].OptionKey(), ""); - extraOption.push_back(mplOption); - } - } return ret; } diff --git a/src/maple_driver/src/mplcg_compiler.cpp b/src/maple_driver/src/mplcg_compiler.cpp index 516fca1cb160b8d4d7535c7df9f3c48a4d757e8d..d56535abaae87a79370bf375d43c4eb618d4825c 100644 --- a/src/maple_driver/src/mplcg_compiler.cpp +++ b/src/maple_driver/src/mplcg_compiler.cpp @@ -97,7 +97,7 @@ bool MplcgCompiler::MakeCGOptions(const MplOptions &options) { return true; } -ErrorCode MplcgCompiler::Compile(const MplOptions &options, MIRModulePtr &theModule) { +ErrorCode MplcgCompiler::Compile(const MplOptions &options, std::unique_ptr &theModule) { MemPool *optMp = memPoolCtrler.NewMemPool("maplecg mempool"); CGOptions &cgOption = CGOptions::GetInstance(); bool result = MakeCGOptions(options); @@ -109,10 +109,12 @@ ErrorCode MplcgCompiler::Compile(const MplOptions &options, MIRModulePtr &theMod std::string output = baseName + ".s"; bool parsed = false; std::unique_ptr theParser; + bool fileparsed = true; if (theModule == nullptr) { MPLTimer timer; timer.Start(); - theModule = new MIRModule(fileName); + fileparsed = false; + theModule = std::make_unique(fileName); theModule->SetWithMe( std::find(options.GetRunningExes().begin(), options.GetRunningExes().end(), kBinNameMe) != options.GetRunningExes().end()); @@ -134,7 +136,8 @@ ErrorCode MplcgCompiler::Compile(const MplOptions &options, MIRModulePtr &theMod } LogInfo::MapleLogger() << "Starting mplcg\n"; - DriverRunner runner(theModule, options.GetRunningExes(), fileName, optMp, options.HasSetTimePhases()); + DriverRunner runner(theModule.get(), options.GetRunningExes(), fileName, optMp, + fileparsed, options.HasSetTimePhases()); PrintCommand(options); runner.SetCGInfo(&cgOption, fileName); runner.ProcessCGPhase(output, baseName); diff --git a/src/maple_ipa/src/clone.cpp b/src/maple_ipa/src/clone.cpp index 96a4eeea0f202b94fb992a49e242bf7e3e4aec34..0b1e8345c9316e0781bb3e906090a23a7f0806f3 100644 --- a/src/maple_ipa/src/clone.cpp +++ b/src/maple_ipa/src/clone.cpp @@ -127,6 +127,10 @@ MIRFunction *Clone::CloneFunction(MIRFunction &originalFunction, const std::stri CloneLabels(*newFunc, originalFunction); mirBuilder.SetCurrentFunction(*originalCurrFunction); } + // clone pregIndex + if (newFunc->GetPregTab() != nullptr && originalFunction.GetPregTab() != nullptr) { + newFunc->GetPregTab()->SetIndex(originalFunction.GetPregTab()->GetIndex()); + } return newFunc; } diff --git a/src/maple_ir/include/mir_function.h b/src/maple_ir/include/mir_function.h index 80e1aa7c8a1cea52b48348be4528cdf0aabac8dd..e0e17bc0cb9907daf7cc6f9257920a95ded26aed 100644 --- a/src/maple_ir/include/mir_function.h +++ b/src/maple_ir/include/mir_function.h @@ -442,6 +442,11 @@ class MIRFunction { inferredReturnTyIdx = tyIdx; } + void AllocTypeNameTab() { + if (typeNameTab == nullptr) { + typeNameTab = module->GetMemPool()->New(module->GetMPAllocator()); + } + } bool HaveTypeNameTab() { return typeNameTab != nullptr; } @@ -463,6 +468,11 @@ class MIRFunction { return labelTab->GetName(labelIdx); } + void AllocLabelTab() { + if (labelTab == nullptr) { + labelTab = module->GetMemPool()->New(module->GetMPAllocator()); + } + } MIRPregTable *GetPregTab() { return pregTab; } @@ -472,6 +482,11 @@ class MIRFunction { void SetPregTab(MIRPregTable *tab) { pregTab = tab; } + void AllocPregTab() { + if (pregTab == nullptr) { + pregTab = module->GetMemPool()->New(module, &module->GetMPAllocator()); + } + } MIRPreg *GetPregItem(PregIdx idx) { return const_cast(const_cast(this)->GetPregItem(idx)); } @@ -717,7 +732,11 @@ class MIRFunction { MIRSymbolTable *GetSymTab() { return symTab; } - + void AllocSymTab() { + if (symTab == nullptr) { + symTab = module->GetMemPool()->New(module->GetMPAllocator()); + } + } const MIRLabelTable *GetLabelTab() const { CHECK_FATAL(labelTab != nullptr, "must be"); return labelTab; diff --git a/src/maple_ir/include/mir_parser.h b/src/maple_ir/include/mir_parser.h index da6d05c23f0fa62c913673d7ff03928c8b8747ba..3764cbd7128c6af78ea0d25f8a6d5908a23cc325 100644 --- a/src/maple_ir/include/mir_parser.h +++ b/src/maple_ir/include/mir_parser.h @@ -190,6 +190,7 @@ class MIRParser { const std::string &GetWarning() const; bool ParseFuncInfo(void); void PrepareParsingMIR(); + void PrepareParsingMplt(); bool ParseMIR(uint32 fileIdx = 0, uint32 option = 0, bool isIpa = false, bool isComb = false); bool ParseMIR(std::ifstream&); // the main entry point bool ParseMPLT(std::ifstream&, const std::string&); diff --git a/src/maple_ir/include/mir_symbol.h b/src/maple_ir/include/mir_symbol.h index ab3901fd982626be498108899bc24587cb84994a..6420fc8f37f4a973186d1f23cf5442d09d3f7d80 100644 --- a/src/maple_ir/include/mir_symbol.h +++ b/src/maple_ir/include/mir_symbol.h @@ -113,6 +113,13 @@ class MIRSymbol { void SetIsTmpUnused(bool used) { isTmpUnused = used; } + void SetIsImportedDecl(bool imported) { + isImportedDecl = imported; + } + + bool GetIsImportedDecl() const { + return isImportedDecl; + } bool IsTmpUnused() const { return isTmpUnused; @@ -408,6 +415,7 @@ class MIRSymbol { bool isDeleted = false; // tell if it is deleted, NOT serialized bool instrumented = false; // a local ref pointer instrumented by RC opt, NOT serialized bool isImported = false; + bool isImportedDecl = false; bool isTmpUnused = false; // when parse the mplt_inline file, mark all the new symbol as tmpunused StIdx stIdx { 0, 0 }; TypeAttrs typeAttrs; diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index cdaa18c32e7646452fc066cefa831580d10220b5..0422ff9ca9e46eb9c241df867975caca0701ca17 100755 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -399,7 +399,7 @@ class MIRType { virtual void Dump(int indent, bool dontUseName = false) const; virtual void DumpAsCxx(int indent) const; virtual bool EqualTo(const MIRType &mirType) const; - virtual bool IsStructType() { + virtual bool IsStructType() const { return false; } @@ -722,7 +722,7 @@ class MIRStructType : public MIRType { ~MIRStructType() override = default; - bool IsStructType() override { + bool IsStructType() const override { return true; } diff --git a/src/maple_ir/include/option.h b/src/maple_ir/include/option.h index fe9137f2afc073b153668196f053c2f4f55c1cc6..b0d06d12cc89c15466e797eeb1a4991f541c1a43 100644 --- a/src/maple_ir/include/option.h +++ b/src/maple_ir/include/option.h @@ -99,6 +99,7 @@ class Options : public MapleDriverOptionBase { static bool genIRProfile; static bool profileTest; static bool checkArrayStore; + static bool noComment; private: void DecideMpl2MplRealLevel(const std::vector &inputOptions) const; std::vector phaseSeq; diff --git a/src/maple_ir/src/bin_mpl_import.cpp b/src/maple_ir/src/bin_mpl_import.cpp index 5f709e928a2dd53c88f6ca661913ee33742fc1bb..33c07d98158b93bfcf746617da08a21815f20f54 100755 --- a/src/maple_ir/src/bin_mpl_import.cpp +++ b/src/maple_ir/src/bin_mpl_import.cpp @@ -299,6 +299,7 @@ void BinaryMplImport::ImportMethodPair(MethodPair &memPool) { funcSt->SetSKind(kStFunc); funcSt->SetTyIdx(funcTyIdx); funcSt->SetIsImported(imported); + funcSt->SetIsImportedDecl(imported); methodSymbols.push_back(funcSt); fn = mod.GetMemPool()->New(&mod, funcSt->GetStIdx()); diff --git a/src/maple_ir/src/mir_module.cpp b/src/maple_ir/src/mir_module.cpp index e14241106337058272de8c8fe886ce060769cdba..0123e0f017d2197d4536612b7e8c102d14619735 100644 --- a/src/maple_ir/src/mir_module.cpp +++ b/src/maple_ir/src/mir_module.cpp @@ -266,7 +266,7 @@ void MIRModule::DumpGlobals(bool emitStructureType) const { if (s->IsJavaClassInterface()) { continue; } - if (!s->IsDeleted() && !s->GetIsImported()) { + if (!s->IsDeleted() && !s->GetIsImported() && !s->GetIsImportedDecl()) { s->Dump(false, 0); } } diff --git a/src/maple_ir/src/mir_parser.cpp b/src/maple_ir/src/mir_parser.cpp index 8d14fe8c2fbb5aecdcdc61a6de305d1bca5b59b4..be7b16a46215b8517f8943f1738e2a84b508ac97 100644 --- a/src/maple_ir/src/mir_parser.cpp +++ b/src/maple_ir/src/mir_parser.cpp @@ -1436,6 +1436,10 @@ bool MIRParser::ParseStmtBlock(BlockNodePtr &blk) { } void MIRParser::ParseStmtBlockForSeenComment(BlockNodePtr blk, uint32 mplNum) { + if (Options::noComment) { + lexer.seenComments.clear(); + return; + } // collect accumulated comments into comment statement nodes if (!lexer.seenComments.empty()) { for (size_t i = 0; i < lexer.seenComments.size(); ++i) { diff --git a/src/maple_ir/src/mir_type.cpp b/src/maple_ir/src/mir_type.cpp index c7a17a1f33ff49f95654dca86af265d80e323ae5..741f1c88add0bf1f1157e67f46646359392daf11 100755 --- a/src/maple_ir/src/mir_type.cpp +++ b/src/maple_ir/src/mir_type.cpp @@ -964,6 +964,9 @@ uint32 MIRClassType::GetInfo(const std::string &infoStr) const { } bool MIRClassType::IsFinal() const { + if (!IsStructType()) { + return false; + } uint32 attrStrIdx = GetInfo(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("INFO_attribute_string")); CHECK(attrStrIdx < GlobalTables::GetStrTable().StringTableSize(), "out of range of vector"); const std::string &kAttrString = GlobalTables::GetStrTable().GetStringFromStrIdx(GStrIdx(attrStrIdx)); diff --git a/src/maple_ir/src/option.cpp b/src/maple_ir/src/option.cpp index 79843c750e959f918f0925117db65459a4e4980d..4a2fed517c5d68b199e35c5926192966f40e9e39 100644 --- a/src/maple_ir/src/option.cpp +++ b/src/maple_ir/src/option.cpp @@ -66,6 +66,8 @@ std::string Options::proFileData = ""; std::string Options::proFileFuncData = ""; std::string Options::proFileClassData = ""; bool Options::checkArrayStore = false; +bool Options::noComment = false; + enum OptionIndex { kMpl2MplDumpPhase = kCommonOptionEnd + 1, kMpl2MplSkipPhase, @@ -103,6 +105,7 @@ enum OptionIndex { kMpl2MplNoDot, kGenIRProfile, kProfileTest, + kNoComment }; const Descriptor kUsage[] = { @@ -446,6 +449,15 @@ const Descriptor kUsage[] = { " --no-profile-test \tDisable profile test\n", "mpl2mpl", {} }, + { kNoComment, + 0, + "", + "no-comment", + kBuildTypeProduct, + kArgCheckPolicyBool, + " --no-comment \tbuild inlineCache 0:off, 1:open\n", + "mpl2mpl", + {} }, { kUnknown, 0, "", @@ -651,6 +663,9 @@ bool Options::SolveOptions(const std::vector