diff --git a/build/config.gni b/build/config.gni index 9c7d79fe171a517ce057a74be4d6a0acf5984f16..3a0877dcc8736779f2aec5d04f515590e83b27bd 100644 --- a/build/config.gni +++ b/build/config.gni @@ -13,9 +13,9 @@ # See the Mulan PSL v1 for more details. # # Toolchain setup -GN_C_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang" -GN_CXX_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++" -GN_AR_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-ar" +GN_C_COMPILER = "${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang" +GN_CXX_COMPILER = "${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++" +GN_AR_COMPILER = "${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-ar" target_toolchain = "//build/toolchain:clang" set_default_toolchain(target_toolchain) diff --git a/doc/cn/DeveloperGuide.md b/doc/cn/DeveloperGuide.md index 08e6cb025a65cded1ccf9a90da845e6d2bf8fce3..8d9ed169789c9b0776da2c84613e13fcc46ac111 100644 --- a/doc/cn/DeveloperGuide.md +++ b/doc/cn/DeveloperGuide.md @@ -78,10 +78,10 @@ make ``` cp output/compile_commands.json ./ -./tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/share/clang/run-clang-tidy.py -clang-tidy-binary='./tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang-tidy' -clang-apply-replacements-binary='./tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang-apply-replacements' src/maple_driver/ +./tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/share/clang/run-clang-tidy.py -clang-tidy-binary='./tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang-tidy' -clang-apply-replacements-binary='./tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang-apply-replacements' src/maple_driver/ ``` 命令说明: - `cp output/compile_commands.json ./` 将output目录之下的compile_commands.json复制到当前目录之下,它是clang-tidy运行所需要的编译命令; -- `./tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/share/clang/run-clang-tidy.py` 调用clang-tidy进行批量检查的脚本run-clang-tidy.py,其中 `./tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/`目录是之前配置的clang编译器的发行包主目录; `-clang-tidy-binary` 是指明clang-tidy的具体位置; `-clang-apply-replacements-binary` 是指明run-clang-tidy.py所依赖的clang-apply-replacements的位置; `src/maple_driver/` 是要进行源码检查的目录。 +- `./tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/share/clang/run-clang-tidy.py` 调用clang-tidy进行批量检查的脚本run-clang-tidy.py,其中 `./tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/`目录是之前配置的clang编译器的发行包主目录; `-clang-tidy-binary` 是指明clang-tidy的具体位置; `-clang-apply-replacements-binary` 是指明run-clang-tidy.py所依赖的clang-apply-replacements的位置; `src/maple_driver/` 是要进行源码检查的目录。 diff --git a/doc/cn/DevelopmentPreparation.md b/doc/cn/DevelopmentPreparation.md index 16f03472212ce8700bef34e07a325f3a03e1cbf1..a5bc10abf284a9da9b85b16de89c165d2bf24634 100644 --- a/doc/cn/DevelopmentPreparation.md +++ b/doc/cn/DevelopmentPreparation.md @@ -27,9 +27,9 @@ LLVM下载地址:http://releases.llvm.org/download.html#8.0.0 放置到`openarkcompiler/tools`目录,打开`openarkcompiler/build/config.gni`文件,将`GN_C_COMPILER`、`GN_CXX_COMPILER`和`GN_AR_COMPILER`三个变量配置为Clang编译器所在路径,例如: ``` -GN_C_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang" -GN_CXX_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++" -GN_AR_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-ar" +GN_C_COMPILER = "${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang" +GN_CXX_COMPILER = "${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++" +GN_AR_COMPILER = "${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-ar" ``` 其中${MAPLE_ROOT}为openarkcompiler源码根目录。 diff --git a/doc/en/DeveloperGuide.md b/doc/en/DeveloperGuide.md index 37297d9a8fa5ac5ac74e4f583abcf72371a27329..d5ecfa04d30547db1fbea61a12d32a8a1c0a8dd2 100644 --- a/doc/en/DeveloperGuide.md +++ b/doc/en/DeveloperGuide.md @@ -79,10 +79,10 @@ Before the static code analysis, we need compiled the OpenArkCompiler. After tha ``` cp output/compile_commands.json ./ -./tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/share/clang/run-clang-tidy.py -clang-tidy-binary='./tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang-tidy' -clang-apply-replacements-binary='./tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang-apply-replacements' src/maple_driver/ +./tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/share/clang/run-clang-tidy.py -clang-tidy-binary='./tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang-tidy' -clang-apply-replacements-binary='./tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang-apply-replacements' src/maple_driver/ ``` Command description: - `cp output/compile_commands.json ./`: Copy the compile_commands.json in the output directory to the openarkcompiler directory, it is required by the clang-tidy, it contains the compile commands of OpenArkCompiler. -- `./tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/share/clang/run-clang-tidy.py`: Call the run-clang-tidy.py which is the parallel clang-tidy runner. The `./tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/` directory is the directory of the release package of clang compiler. The `-clang-tidy-binary` set the path of clang-tidy binary. The `-clang-apply-replacements-binary` set the path of the clang-apply-replacements binary which is requried by the run-clang-tidy.py. The `src/maple_driver/` is the tested code directory. +- `./tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/share/clang/run-clang-tidy.py`: Call the run-clang-tidy.py which is the parallel clang-tidy runner. The `./tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/` directory is the directory of the release package of clang compiler. The `-clang-tidy-binary` set the path of clang-tidy binary. The `-clang-apply-replacements-binary` set the path of the clang-apply-replacements binary which is requried by the run-clang-tidy.py. The `src/maple_driver/` is the tested code directory. diff --git a/doc/en/DevelopmentPreparation.md b/doc/en/DevelopmentPreparation.md index bc1c900ba8721bc3c383fab5b4bb6a5242aefc91..f328c11a0148a76ac41d6ffa1b62ae897748a0d5 100644 --- a/doc/en/DevelopmentPreparation.md +++ b/doc/en/DevelopmentPreparation.md @@ -27,9 +27,9 @@ LLVM download address: http://releases.llvm.org/download.html#8.0.0 Place the downloaded files in the `openarkcompiler/tools` directory, open the `openarkcompiler/build/config.gni` file, and set the three variables `GN_C_COMPILER`, `GN_CXX_COMPILER`, and `GN_AR_COMPILER` to the path where Clang is located. For example: ``` -GN_C_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang" -GN_CXX_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++" -GN_AR_COMPILER = "${MAPLE_ROOT}/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-ar" +GN_C_COMPILER = "${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang" +GN_CXX_COMPILER = "${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang++" +GN_AR_COMPILER = "${MAPLE_ROOT}/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/llvm-ar" ``` ${MAPLE_ROOT} is the root directory of the OpenArkCompiler source code. diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index c900233e4c401056354ad8d34cc85e00203fef5c..67487ccb3ad3f68e5bca7c212bc9e44e21081265 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index dc5fcf0077375e1884b0f1fbd7725d1efebf3711..96b6d0b42c654e05304de5ff8633fa34f92781b7 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmempool.a b/src/deplibs/libmempool.a index 291c74cec65d7b4142b20b454275b13ab2b4b571..ac6365db3b02fcaa96220d5730df45726b1fd53f 100644 Binary files a/src/deplibs/libmempool.a and b/src/deplibs/libmempool.a differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index 33eeec2cb4a3a927359185c44d193cc4ac232883..1af676b0f7d2bb15f08d3d89ccbc79b4317d1998 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 9cb48dd32c6de9a9597ff5a9ef7cb7f734a66ca0..8689ac831edd35563952ded02797f38a6fa1fce5 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h b/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h index 78a874ac03e8c665fa0aacb58d1c87a205cca951..07c52802632e6efc6e90a1579be4b7672996f4ec 100644 --- a/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h +++ b/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h @@ -147,7 +147,7 @@ class AArch64CGFunc : public CGFunc { Operand *SelectCmpOp(CompareNode &node, Operand &o0, Operand &o1) override; void SelectAArch64Cmp(Operand &o, Operand &i, bool isIntType, uint32 dsize); - void SelectTargetFPCmpQuiet(Operand &o0, Operand &o1, uint32 dsize) override; + void SelectTargetFPCmpQuiet(Operand &o0, Operand &o1, uint32 dsize); void SelectAArch64CCmp(Operand &o, Operand &i, Operand &nzcv, CondOperand &cond, bool is64Bits); void SelectAArch64CSet(Operand &o, CondOperand &cond, bool is64Bits); void SelectAArch64CSINV(Operand &res, Operand &o0, Operand &o1, CondOperand &cond, bool is64Bits); diff --git a/src/maple_be/include/cg/cgfunc.h b/src/maple_be/include/cg/cgfunc.h index a9ddb5ce85f6c14c03a4b4a5424bab182bc65f3a..2ca42537c464a843448626063e3e654b4a07f696 100644 --- a/src/maple_be/include/cg/cgfunc.h +++ b/src/maple_be/include/cg/cgfunc.h @@ -211,7 +211,6 @@ class CGFunc { virtual Operand *SelectSelect(TernaryNode &node, Operand &opnd0, Operand &opnd1, Operand &opnd2) = 0; virtual Operand *SelectMalloc(UnaryNode &call, Operand &opnd0) = 0; virtual RegOperand &SelectCopy(Operand &src, PrimType srcType, PrimType dstType) = 0; - virtual void SelectTargetFPCmpQuiet(Operand &o0, Operand &o1, uint32 size) = 0; virtual Operand *SelectAlloca(UnaryNode &call, Operand &opnd0) = 0; virtual Operand *SelectGCMalloc(GCMallocNode &call) = 0; virtual Operand *SelectJarrayMalloc(JarrayMallocNode &call, Operand &opnd0) = 0; diff --git a/src/maple_be/src/cg/aarch64/aarch64_reg_alloc.cpp b/src/maple_be/src/cg/aarch64/aarch64_reg_alloc.cpp index 55fc0a9997c30d8c11548b67b1876d9b97447c71..95f13a391a9f856af0cce653c25c623dea91ef0c 100644 --- a/src/maple_be/src/cg/aarch64/aarch64_reg_alloc.cpp +++ b/src/maple_be/src/cg/aarch64/aarch64_reg_alloc.cpp @@ -597,7 +597,7 @@ bool DefaultO0RegAllocator::AllocateRegisters() { } /* hack. a better way to handle intrinsics? */ for (auto rememberReg : rememberRegs) { - ASSERT(rememberReg == kRinvalid, "not a valid register"); + ASSERT(rememberReg != kRinvalid, "not a valid register"); ReleaseReg(rememberReg); } rememberRegs.clear(); diff --git a/src/maple_be/src/cg/cg_option.cpp b/src/maple_be/src/cg/cg_option.cpp index d10b7935073089a3e21ef51e5340fce2e28af05e..a13af6ee754606942c726a631790b1177e95887c 100644 --- a/src/maple_be/src/cg/cg_option.cpp +++ b/src/maple_be/src/cg/cg_option.cpp @@ -37,7 +37,11 @@ std::unordered_map> CGOptions::cyclePatter std::string CGOptions::skipFrom = ""; std::string CGOptions::skipAfter = ""; std::string CGOptions::dumpFunc = "*"; +#ifdef TARGARM32 +std::string CGOptions::duplicateAsmFile = ""; +#else std::string CGOptions::duplicateAsmFile = "maple/mrt/codetricks/arch/arm64/duplicateFunc.s"; +#endif std::string CGOptions::globalVarProfile = ""; #if TARGAARCH64 bool CGOptions::useBarriersForVolatile = false; diff --git a/src/maple_be/src/cg/cg_phasemanager.cpp b/src/maple_be/src/cg/cg_phasemanager.cpp index 6e7dbd90ac04047a981461c3e7686b8a8d94d94b..232f04b989fec896d187d7789e51f68ad15846c6 100644 --- a/src/maple_be/src/cg/cg_phasemanager.cpp +++ b/src/maple_be/src/cg/cg_phasemanager.cpp @@ -42,7 +42,7 @@ void CgFuncPhaseManager::RunFuncPhase(CGFunc &func, FuncPhase &phase) { AnalysisResult *analysisRes = nullptr; if ((func.NumBBs() > 0) || (phase.GetPhaseID() == kCGFuncPhaseEMIT)) { analysisRes = phase.Run(&func, &arFuncManager); - phase.ReleaseMemPool(analysisRes == nullptr ? nullptr : analysisRes->GetMempool()); + phase.ClearMemPoolsExcept(analysisRes == nullptr ? nullptr : analysisRes->GetMempool()); } if (analysisRes != nullptr) { diff --git a/src/maple_ipa/include/interleaved_manager.h b/src/maple_ipa/include/interleaved_manager.h index 3e477f55462e7a696c164c0a4abc8265243c0b1d..65ea49b462b912268fcb42cf73d9bf54d9c87794 100644 --- a/src/maple_ipa/include/interleaved_manager.h +++ b/src/maple_ipa/include/interleaved_manager.h @@ -56,14 +56,15 @@ class InterleavedManager { const PhaseManager *GetSupportPhaseManager(const std::string &phase); private: + void InitSupportPhaseManagers(); + void OptimizeFuncs(MeFuncPhaseManager &fpm, MapleVector &compList); + MapleAllocator allocator; MIRModule &mirModule; MapleVector phaseManagers; MapleVector supportPhaseManagers; // Used to check whether a phase is supported and by which manager std::string meInput; bool timePasses = false; - - void InitSupportPhaseManagers(); }; } // namespace maple #endif // MAPLE_IPA_INCLUDE_INTERLEAVED_MANAGER_H diff --git a/src/maple_ipa/src/interleaved_manager.cpp b/src/maple_ipa/src/interleaved_manager.cpp index eaa94bd1f96b64023d9a059df1f54bfa1b56ac9a..bea6c8544b99d2bd53af3e2bde4668f754552728 100644 --- a/src/maple_ipa/src/interleaved_manager.cpp +++ b/src/maple_ipa/src/interleaved_manager.cpp @@ -21,6 +21,7 @@ #include "me_option.h" #include "mempool.h" #include "phase_manager.h" +#include "mpl_timer.h" namespace maple { void InterleavedManager::AddPhases(const std::vector &phases, bool isModulePhase, bool timePhases, @@ -55,6 +56,21 @@ void InterleavedManager::AddPhases(const std::vector &phases, bool } +void InterleavedManager::OptimizeFuncs(MeFuncPhaseManager &fpm, MapleVector &compList) { + for (size_t i = 0; i < compList.size(); ++i) { + MIRFunction *func = compList[i]; + ASSERT_NOT_NULL(func); + // skip empty func, and skip the func out of range if `useRange` is true + if (func->GetBody() == nullptr || (MeOption::useRange && (i < MeOption::range[0] || i > MeOption::range[1]))) { + continue; + } + mirModule.SetCurFunction(func); + // lower, create BB and build cfg + fpm.Run(func, i, meInput); + } +} + + void InterleavedManager::Run() { for (auto *pm : phaseManagers) { if (pm == nullptr) { @@ -65,6 +81,9 @@ void InterleavedManager::Run() { pm->Run(); continue; } + if (fpm->GetPhaseSequence()->empty()) { + continue; + } MapleVector *compList; if (!mirModule.GetCompilationList().empty()) { if ((mirModule.GetCompilationList().size() != mirModule.GetFunctionList().size()) && @@ -76,26 +95,13 @@ void InterleavedManager::Run() { } else { compList = &mirModule.GetFunctionList(); } - // If rangeNum < MeOption::range[0], Move to the next function with rangeNum++ - uint64 rangeNum = 0; - for (auto *func : *compList) { - ASSERT_NOT_NULL(func); - if (MeOption::useRange && (rangeNum < MeOption::range[0] || rangeNum > MeOption::range[1])) { - ++rangeNum; - continue; - } - if (func->GetBody() == nullptr) { - ++rangeNum; - continue; - } - if (fpm->GetPhaseSequence()->empty()) { - continue; - } - mirModule.SetCurFunction(func); - // lower, create BB and build cfg - fpm->Run(func, rangeNum, meInput); - ++rangeNum; - } + + MPLTimer optTimer; + optTimer.Start(); + std::string logPrefix = mirModule.IsInIPA() ? "[ipa]" : "[me]"; + OptimizeFuncs(*fpm, *compList); + optTimer.Stop(); + LogInfo::MapleLogger() << logPrefix << " Function phases cost " << optTimer.ElapsedMilliseconds() << "ms\n"; if (fpm->GetGenMeMpl()) { mirModule.Emit("comb.me.mpl"); } diff --git a/src/maple_ir/include/global_tables.h b/src/maple_ir/include/global_tables.h index f4b70e0b771563da6c5eff18b261e0410691d82a..afc8ac4bb3684e4e8452ef65318e02bf9a26ded4 100644 --- a/src/maple_ir/include/global_tables.h +++ b/src/maple_ir/include/global_tables.h @@ -87,13 +87,15 @@ class TypeTable { TypeTable(const TypeTable&) = delete; TypeTable &operator=(const TypeTable&) = delete; ~TypeTable(); - MIRType *CreateMirType(uint32 primTypeIdx) const; - void PutToHashTable(MIRType *mirType); std::vector &GetTypeTable() { return typeTable; } + const std::vector &GetTypeTable() const { + return typeTable; + } + MIRType *GetTypeFromTyIdx(TyIdx tyIdx) { return const_cast(const_cast(this)->GetTypeFromTyIdx(tyIdx)); } @@ -356,6 +358,9 @@ class TypeTable { MIRModule &module, bool forStruct = true); MIRType *GetOrCreateClassOrInterface(const std::string &name, MIRModule &module, bool forClass); + MIRType *CreateMirType(uint32 primTypeIdx) const; + void PutToHashTable(MIRType *mirType); + std::unordered_set typeHashTable; std::vector typeTable; }; @@ -455,6 +460,8 @@ class FPConstTable { private: FPConstTable() : floatConstTable(), doubleConstTable() {}; void PostInit(); + MIRFloatConst *DoGetOrCreateFloatConst(float); + MIRDoubleConst *DoGetOrCreateDoubleConst(double); std::unordered_map floatConstTable; // map float const value to the table; std::unordered_map doubleConstTable; // map double const value to the table; MIRFloatConst *nanFloatConst = nullptr; @@ -482,6 +489,7 @@ class IntConstTable { private: IntConstTable() = default; + MIRIntConst *DoGetOrCreateIntConst(int64 val, MIRType &type, uint32 fieldID); std::unordered_map intConstTable; }; diff --git a/src/maple_ir/include/mir_function.h b/src/maple_ir/include/mir_function.h index 78ee584e87f06950fe0832a0405125be5cac46e2..f150b1a673b3e9dbc1a26543ce507a45ab4df989 100644 --- a/src/maple_ir/include/mir_function.h +++ b/src/maple_ir/include/mir_function.h @@ -846,7 +846,7 @@ class MIRFunction { // the word at location (%%FP - N*4)) has // typetag; if yes, the typetag is the word // at (%%FP - N*4 + 4); the bitvector's size - // is given by BlockSize2BitvectorSize(framesize) + // is given by BlockSize2BitvectorSize(frameSize) uint8 *formalWordsRefCounted = nullptr; // bit vector where the Nth bit tells whether // the Nth word in the formal parameters area // addressed upward from %%FP (that means @@ -860,7 +860,7 @@ class MIRFunction { // the word at location (%%FP - N*4)) points to // a dynamic memory block that needs reference // count; the bitvector's size is given by - // BlockSize2BitvectorSize(framesize) + // BlockSize2BitvectorSize(frameSize) // uint16 numlabels; // removed. label table size // StmtNode **lbl2stmt; // lbl2stmt table, removed; // to hold unmangled class and function names diff --git a/src/maple_ir/include/mir_module.h b/src/maple_ir/include/mir_module.h index 31e080d4b82be0db9ff378e093a456edf463d218..06db828bbb7155986ac7ccb4380b99d265851745 100644 --- a/src/maple_ir/include/mir_module.h +++ b/src/maple_ir/include/mir_module.h @@ -546,7 +546,7 @@ class MIRModule { MIRFunction *entryFunc = nullptr; uint32 floatNum = 0; - MIRFunction *curFunction = nullptr; + MIRFunction *curFunction; MapleVector optimizedFuncs; // Add the field for decouple optimization std::unordered_set superCallSet; diff --git a/src/maple_ir/include/mir_nodes.h b/src/maple_ir/include/mir_nodes.h index a7ea7184fa61af6d8e02789e85a614cfbce7c863..9cd17985be95fc0646cbe4f328c0980e114272ba 100644 --- a/src/maple_ir/include/mir_nodes.h +++ b/src/maple_ir/include/mir_nodes.h @@ -16,6 +16,7 @@ #define MAPLE_IR_INCLUDE_MIR_NODES_H #include #include +#include #include "opcodes.h" #include "opcode_info.h" #include "mir_type.h" @@ -1389,8 +1390,8 @@ class SrcPosition { // membarstoreload, membarstorestore class StmtNode : public BaseNode, public PtrListNodeBase { public: - static uint32 stmtIDNext; // for assigning stmtID, initialized to 1; 0 is reserved - static uint32 lastPrintedLineNum; // used during printing ascii output + static std::atomic stmtIDNext; // for assigning stmtID, initialized to 1; 0 is reserved + static uint32 lastPrintedLineNum; // used during printing ascii output explicit StmtNode(Opcode o) : BaseNode(o), PtrListNodeBase(), stmtID(stmtIDNext) { ++stmtIDNext; diff --git a/src/maple_ir/src/global_tables.cpp b/src/maple_ir/src/global_tables.cpp index 4a0af15f2930a45d17ee56a3e44a1bc67dc432e5..d12855f1e829074402cd69ac3196a5f121711848 100644 --- a/src/maple_ir/src/global_tables.cpp +++ b/src/maple_ir/src/global_tables.cpp @@ -64,11 +64,12 @@ void TypeTable::PutToHashTable(MIRType *mirType) { } TyIdx TypeTable::GetOrCreateMIRType(MIRType *pType) { - const auto it = typeHashTable.find(pType); - if (it != typeHashTable.end()) { - return (*it)->GetTypeIndex(); + { + const auto it = typeHashTable.find(pType); + if (it != typeHashTable.end()) { + return (*it)->GetTypeIndex(); + } } - MIRType *newTy = CreateType(*pType); PutToHashTable(newTy); return newTy->GetTypeIndex(); @@ -205,6 +206,10 @@ void FPConstTable::PostInit() { } MIRIntConst *IntConstTable::GetOrCreateIntConst(int64 val, MIRType &type, uint32 fieldID) { + return DoGetOrCreateIntConst(val, type, fieldID); +} + +MIRIntConst *IntConstTable::DoGetOrCreateIntConst(int64 val, MIRType &type, uint32 fieldID) { uint64 idid = static_cast(type.GetTypeIndex()) + (static_cast(fieldID) << 32); // shift bit is 32 IntConstKey key(val, idid); if (intConstTable.find(key) != intConstTable.end()) { @@ -230,35 +235,43 @@ MIRFloatConst *FPConstTable::GetOrCreateFloatConst(float floatVal) { if (floatVal == 0.0 && std::signbit(floatVal)) { return minusZeroFloatConst; } + return DoGetOrCreateFloatConst(floatVal); +} + +MIRFloatConst *FPConstTable::DoGetOrCreateFloatConst(float floatVal) { const auto it = floatConstTable.find(floatVal); - if (it == floatConstTable.cend()) { - // create a new one - auto *floatConst = new MIRFloatConst(floatVal, *GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx{ PTY_f32 })); - floatConstTable[floatVal] = floatConst; - return floatConst; + if (it != floatConstTable.cend()) { + return it->second; } - return it->second; + // create a new one + auto *floatConst = new MIRFloatConst(floatVal, *GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx{ PTY_f32 })); + floatConstTable[floatVal] = floatConst; + return floatConst; } -MIRDoubleConst *FPConstTable::GetOrCreateDoubleConst(double floatVal) { - if (std::isnan(floatVal)) { +MIRDoubleConst *FPConstTable::GetOrCreateDoubleConst(double doubleVal) { + if (std::isnan(doubleVal)) { return nanDoubleConst; } - if (std::isinf(floatVal)) { - return (floatVal < 0) ? minusInfDoubleConst : infDoubleConst; + if (std::isinf(doubleVal)) { + return (doubleVal < 0) ? minusInfDoubleConst : infDoubleConst; } - if (floatVal == 0.0 && std::signbit(floatVal)) { + if (doubleVal == 0.0 && std::signbit(doubleVal)) { return minusZeroDoubleConst; } - const auto it = doubleConstTable.find(floatVal); - if (it == doubleConstTable.cend()) { - // create a new one - auto *doubleConst = new MIRDoubleConst(floatVal, - *GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_f64)); - doubleConstTable[floatVal] = doubleConst; - return doubleConst; + return DoGetOrCreateDoubleConst(doubleVal); +} + +MIRDoubleConst *FPConstTable::DoGetOrCreateDoubleConst(double doubleVal) { + const auto it = doubleConstTable.find(doubleVal); + if (it != doubleConstTable.cend()) { + return it->second; } - return it->second; + // create a new one + auto *doubleConst = new MIRDoubleConst(doubleVal, + *GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_f64)); + doubleConstTable[doubleVal] = doubleConst; + return doubleConst; } FPConstTable::~FPConstTable() { diff --git a/src/maple_ir/src/mir_builder.cpp b/src/maple_ir/src/mir_builder.cpp index abfe704983e992520f52cc71658ff79e3c64012f..d381f366f07aefaa517f68331964944f60caecb2 100644 --- a/src/maple_ir/src/mir_builder.cpp +++ b/src/maple_ir/src/mir_builder.cpp @@ -176,7 +176,7 @@ FieldID MIRBuilder::GetStructFieldIDFromNameAndTypeParentFirst(MIRType &type, co FieldID MIRBuilder::GetStructFieldIDFromNameAndTypeParentFirstFoundInChild(MIRType &type, const std::string &name, TyIdx idx) { - // do not match but traverse to update fieldid, traverse parent first, found in child + // do not match but traverse to update fieldID, traverse parent first, found in child return GetStructFieldIDFromNameAndType(type, name, idx, kFoundInChild | kParentFirst | kUpdateFieldID); } diff --git a/src/maple_ir/src/mir_function.cpp b/src/maple_ir/src/mir_function.cpp index d81f7dd7a09996f4be68a047c82ed947d07143d8..0e1d04dc1bc295a00fc3acafdd0ff5cfaa559b2d 100644 --- a/src/maple_ir/src/mir_function.cpp +++ b/src/maple_ir/src/mir_function.cpp @@ -26,7 +26,7 @@ enum FuncProp : uint32_t { kFuncPropHasCall = 1U, // the function has call kFuncPropRetStruct = 1U << 1, // the function returns struct kFuncPropUserFunc = 1U << 2, // the function is a user func - kFuncPropInfoPrinted = 1U << 3, // to avoid printing framesize/moduleid/funcSize info more + kFuncPropInfoPrinted = 1U << 3, // to avoid printing frameSize/moduleid/funcSize info more // than once per function since they // can only be printed at the beginning of a block kFuncPropNeverReturn = 1U << 4, // the function when called never returns @@ -237,7 +237,7 @@ void MIRFunction::Dump(bool withoutBody) { return; } - // save the module's curfunction and set it to the one currently Dump()ing + // save the module's curFunction and set it to the one currently Dump()ing MIRFunction *savedFunc = module->CurFunction(); module->SetCurFunction(this); @@ -262,7 +262,7 @@ void MIRFunction::Dump(bool withoutBody) { LogInfo::MapleLogger() << '\n'; } - // restore the curfunction + // restore the curFunction module->SetCurFunction(savedFunc); } diff --git a/src/maple_ir/src/mir_module.cpp b/src/maple_ir/src/mir_module.cpp index 5651a5ca4e1e90a3d4d25770580091a67f1f9311..7314d7072222d10e6b1ec3a158f0162d51ce6403 100644 --- a/src/maple_ir/src/mir_module.cpp +++ b/src/maple_ir/src/mir_module.cpp @@ -67,11 +67,13 @@ MemPool *MIRModule::CurFuncCodeMemPool() const { } MapleAllocator *MIRModule::CurFuncCodeMemPoolAllocator() const { + MIRFunction *curFunction = CurFunction(); CHECK_FATAL(curFunction != nullptr, "curFunction is null"); return &curFunction->GetCodeMempoolAllocator(); } MapleAllocator &MIRModule::GetCurFuncCodeMPAllocator() const { + MIRFunction *curFunction = CurFunction(); CHECK_FATAL(curFunction != nullptr, "curFunction is null"); return curFunction->GetCodeMPAllocator(); } diff --git a/src/maple_ir/src/mir_nodes.cpp b/src/maple_ir/src/mir_nodes.cpp index 9c161321b2c3bbc13062ed7b2978a3fd9be4db98..aed20069d2eeabcdf01919cf47e7b3aa3295df5d 100644 --- a/src/maple_ir/src/mir_nodes.cpp +++ b/src/maple_ir/src/mir_nodes.cpp @@ -24,7 +24,7 @@ namespace maple { MIRModule *theMIRModule = nullptr; -uint32 StmtNode::stmtIDNext = 1; // 0 is reserved +std::atomic StmtNode::stmtIDNext(1); // 0 is reserved uint32 StmtNode::lastPrintedLineNum = 0; const char *GetIntrinsicName(MIRIntrinsicID intrn) { diff --git a/src/maple_ir/src/mir_parser.cpp b/src/maple_ir/src/mir_parser.cpp index eae19b0ea0cd5636cc3dc25812c1d535d3fc1171..f9127cfd51f0e1757bd0d5c6d171d1f7aab091c3 100644 --- a/src/maple_ir/src/mir_parser.cpp +++ b/src/maple_ir/src/mir_parser.cpp @@ -2034,7 +2034,7 @@ bool MIRParser::ParseExprCompare(BaseNodePtr &expr) { } bool MIRParser::ParseExprDepositbits(BaseNodePtr &expr) { - // syntax: depositbits (, ) + // syntax: depositbits (, ) if (lexer.GetTokenKind() != TK_depositbits) { Error("expect depositbits but get "); return false; @@ -2048,7 +2048,7 @@ bool MIRParser::ParseExprDepositbits(BaseNodePtr &expr) { } dpsbNode->SetPrimType(ptyp); if (lexer.NextToken() != TK_intconst) { - Error("expect boffset but get "); + Error("expect bOffset but get "); return false; } dpsbNode->SetBitsOffset(lexer.GetTheIntVal()); @@ -2362,7 +2362,7 @@ bool MIRParser::ParseExprJarray(BaseNodePtr &expr) { // parse extractbits, sext, zext bool MIRParser::ParseExprExtractbits(BaseNodePtr &expr) { - // extractbits () + // extractbits () Opcode op = GetUnaryOp(lexer.GetTokenKind()); if (op == OP_undef) { Error("expect unary op but get "); @@ -2384,7 +2384,7 @@ bool MIRParser::ParseExprExtractbits(BaseNodePtr &expr) { extrctNode->SetPrimType(ptyp); if (op == OP_extractbits) { if (lexer.GetTokenKind() != TK_intconst) { - Error("expect boffset but get "); + Error("expect bOffset but get "); return false; } extrctNode->SetBitsOffset(lexer.GetTheIntVal()); diff --git a/src/maple_me/include/me_phase_manager.h b/src/maple_me/include/me_phase_manager.h index 6b214b4c715596aaa90566214b488f99bc26f463..6f86bccf6ebfbdd664d81b24bae3e408335ebe3f 100644 --- a/src/maple_me/include/me_phase_manager.h +++ b/src/maple_me/include/me_phase_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -54,10 +54,13 @@ class MeFuncPhaseManager : public PhaseManager { modResMgr = mrm; } - void Run(MIRFunction *mirFunc, uint64 rangeNum, const std::string &meInput); + void Run(MIRFunction *mirFunc, uint64 rangeNum, const std::string &meInput, + MemPoolCtrler &localMpCtrler = memPoolCtrler); void IPACleanUp(MeFunction *mirfunc); void Run() override {} + MeFuncPhaseManager &Clone(MemPool &mp, MemPoolCtrler &ctrler) const; + MeFuncResultMgr *GetAnalysisResultManager() { return &arFuncManager; } diff --git a/src/maple_me/include/me_profile_gen.h b/src/maple_me/include/me_profile_gen.h index 5acf00b3dda6fb2b2659e290a4c68ab303948726..4f16e9959e6e6690daa5ee69e955d9befc52b7c2 100644 --- a/src/maple_me/include/me_profile_gen.h +++ b/src/maple_me/include/me_profile_gen.h @@ -35,7 +35,6 @@ class MeProfGen : public PGOInstrument { private: void Init(); void InstrumentBB(BB &bb); - void SaveProfile(); MeFunction *func; MeIRMap *hMap; static uint64 counterIdx; diff --git a/src/maple_me/include/me_ssa_devirtual.h b/src/maple_me/include/me_ssa_devirtual.h index bab72181fa40e9a1f044231a43c3931ed36295a2..77a885d752c9db465b24d584bc3a96063dd2f04e 100644 --- a/src/maple_me/include/me_ssa_devirtual.h +++ b/src/maple_me/include/me_ssa_devirtual.h @@ -21,11 +21,12 @@ namespace maple { class MeSSADevirtual : public SSADevirtual { public: - MeSSADevirtual(MemPool &memPool, MIRModule &mod, MeFunction &func, IRMap &irMap, KlassHierarchy &kh, Dominance &dom) - : SSADevirtual(memPool, mod, irMap, kh, dom, func.GetAllBBs().size()), func(&func) {} MeSSADevirtual(MemPool &memPool, MIRModule &mod, MeFunction &func, IRMap &irMap, KlassHierarchy &kh, Dominance &dom, - Clone &clone) - : SSADevirtual(memPool, mod, irMap, kh, dom, func.GetAllBBs().size(), clone), func(&func) {} + bool skipReturnTypeOpt) + : SSADevirtual(memPool, mod, irMap, kh, dom, func.GetAllBBs().size(), skipReturnTypeOpt), func(&func) {} + MeSSADevirtual(MemPool &memPool, MIRModule &mod, MeFunction &func, IRMap &irMap, KlassHierarchy &kh, Dominance &dom, + Clone &clone, bool skipReturnTypeOpt) + : SSADevirtual(memPool, mod, irMap, kh, dom, func.GetAllBBs().size(), clone, skipReturnTypeOpt), func(&func) {} ~MeSSADevirtual() = default; diff --git a/src/maple_me/include/me_ssa_update.h b/src/maple_me/include/me_ssa_update.h index 7379d40373962d7d8e61d1ecde9899d4ae4170ea..1e5c7fc8d906ad071cd40a7b6ad4153addad6e17 100644 --- a/src/maple_me/include/me_ssa_update.h +++ b/src/maple_me/include/me_ssa_update.h @@ -31,9 +31,7 @@ class MeSSAUpdate { updateCands(cands), renameStacks(std::less(), ssaUpdateAlloc.Adapter()) {} - ~MeSSAUpdate() { - memPoolCtrler.DeleteMemPool(&ssaUpdateMp); - } + ~MeSSAUpdate() = default; void Run(); diff --git a/src/maple_me/include/prop.h b/src/maple_me/include/prop.h index 6ef6d126a06ec70b80084cc31b06f38aab05ecb0..50d07d79950b27bf3cc888139c00411d60d772ea 100644 --- a/src/maple_me/include/prop.h +++ b/src/maple_me/include/prop.h @@ -67,6 +67,8 @@ class Prop { MeExpr &PropMeExpr(MeExpr &meExpr, bool &isproped, bool atParm); MeExpr *SimplifyMeExpr(OpMeExpr &opMeExpr) const; MeExpr *SimplifyCvtMeExpr(const OpMeExpr &opMeExpr) const; + MeExpr *SimplifyCompareConstWithAddress(OpMeExpr &opMeExpr) const; + MeExpr *SimplifyCompareWithZero(OpMeExpr &opMeExpr) const; MeExpr *SimplifyCompareMeExpr(OpMeExpr &opMeExpr) const; MeExpr *SimplifyCompareSelectConstMeExpr(const OpMeExpr &opMeExpr, const MeExpr &opMeOpnd0, MeExpr &opnd1, MeExpr &opnd01, MeExpr &opnd02) const; diff --git a/src/maple_me/include/ssa_devirtual.h b/src/maple_me/include/ssa_devirtual.h index f453ef994ac4c43c921d82b431ffeec91bda92c8..3be585bed336139290f1c39853108af9b311454b 100644 --- a/src/maple_me/include/ssa_devirtual.h +++ b/src/maple_me/include/ssa_devirtual.h @@ -26,7 +26,7 @@ class SSADevirtual { public: static bool debug; SSADevirtual(MemPool &memPool, MIRModule &currMod, IRMap &irMap, KlassHierarchy &currKh, - Dominance &currDom, size_t bbVecSize) + Dominance &currDom, size_t bbVecSize, bool skipReturnTypeOpt) : devirtualAlloc(&memPool), mod(&currMod), irMap(&irMap), @@ -40,10 +40,11 @@ class SSADevirtual { optedVirtualCalls(0), totalInterfaceCalls(0), optedInterfaceCalls(0), - nullCheckCount(0) {} + nullCheckCount(0), + skipReturnTypeOpt(skipReturnTypeOpt) {} SSADevirtual(MemPool &memPool, MIRModule &currMod, IRMap &irMap, KlassHierarchy &currKh, - Dominance &currDom, size_t bbVecSize, Clone &currClone) - : SSADevirtual(memPool, currMod, irMap, currKh, currDom, bbVecSize) { + Dominance &currDom, size_t bbVecSize, Clone &currClone, bool skipReturnTypeOpt) + : SSADevirtual(memPool, currMod, irMap, currKh, currDom, bbVecSize, skipReturnTypeOpt) { clone = &currClone; } @@ -93,6 +94,7 @@ class SSADevirtual { unsigned int totalInterfaceCalls; unsigned int optedInterfaceCalls; unsigned int nullCheckCount; + const bool skipReturnTypeOpt = false; // whether skip return type optimization, true if running me phases in parallel }; } // namespace maple #endif // MAPLE_ME_INCLUDE_SSADEVIRTUAL_H diff --git a/src/maple_me/include/ssa_tab.h b/src/maple_me/include/ssa_tab.h index 0f43c223da30884aa6fea3a62b51d54f2e9b1c24..dc052e65ef4a94bc581e4cc25d301cfb276c4251 100644 --- a/src/maple_me/include/ssa_tab.h +++ b/src/maple_me/include/ssa_tab.h @@ -154,6 +154,11 @@ class SSATab : public AnalysisResult { return *(GetStmtsSSAPart().GetAssignedVarOf(stmt)->GetOrigSt()->GetMIRSymbol()); } + bool IsInitVersion(size_t vstIdx, const OStIdx &ostIdx) { + auto *ost = GetOriginalStFromID(ostIdx); + ASSERT(ost != nullptr, "null pointer check"); + return ost->GetZeroVersionIndex() == vstIdx; + } private: MIRModule &mirModule; VersionStTable versionStTable; // this uses special versMp because it will be freed earlier diff --git a/src/maple_me/src/bb.cpp b/src/maple_me/src/bb.cpp index 74088e86c1a38d5308b0fe37b15f793c84538c82..50911b386ae1c86d1f6c39746d3d51501bdb9daf 100644 --- a/src/maple_me/src/bb.cpp +++ b/src/maple_me/src/bb.cpp @@ -89,7 +89,7 @@ void BB::DumpHeader(const MIRModule *mod) const { } mod->GetOut() << '\n'; if (bbLabel != 0) { - static LabelNode lblNode; + LabelNode lblNode; lblNode.SetLabelIdx(bbLabel); lblNode.Dump(0); mod->GetOut() << '\n'; diff --git a/src/maple_me/src/me_abco.cpp b/src/maple_me/src/me_abco.cpp index 68829714dc9f5d3df30b4b1c135e6d6366c406b4..f8473e3e0d298884805704b5c12ec7eb38f93b2e 100644 --- a/src/maple_me/src/me_abco.cpp +++ b/src/maple_me/src/me_abco.cpp @@ -596,7 +596,6 @@ void MeABC::RemoveExtraNodes() { } } } - memPoolCtrler.DeleteMemPool(memPool); } bool MeABC::IsVirtualVar(const VarMeExpr &var, const SSATab &ssaTab) const { @@ -1366,7 +1365,7 @@ AnalysisResult *MeDoABCOpt::Run(MeFunction *func, MeFuncResultMgr *frm, ModuleRe CHECK_FATAL(dom != nullptr, "dominance phase has problem"); auto *irMap = static_cast(frm->GetAnalysisResult(MeFuncPhase_IRMAP, func)); CHECK_FATAL(irMap != nullptr, "irMap phase has problem"); - MemPool *abcoMemPool = memPoolCtrler.NewMemPool(PhaseName()); + MemPool *abcoMemPool = NewMemPool(); MeABC meABC(*func, *dom, *irMap, *abcoMemPool); meABC.ExecuteABCO(); if (DEBUGFUNC(func)) { diff --git a/src/maple_me/src/me_emit.cpp b/src/maple_me/src/me_emit.cpp index eb61da7f0c96f39b891ce1e223ba9e5ab2915c38..e04eea5a07a069c87e5905fc601c23380730d494 100644 --- a/src/maple_me/src/me_emit.cpp +++ b/src/maple_me/src/me_emit.cpp @@ -37,7 +37,7 @@ AnalysisResult *MeDoEmit::Run(MeFunction *func, MeFuncResultMgr *funcResMgr, Mod ASSERT(func->GetIRMap() != nullptr, "null ptr check"); MIRFunction *mirFunction = func->GetMirFunc(); if (mirFunction->GetCodeMempool() != nullptr) { - memPoolCtrler.DeleteMemPool(mirFunction->GetCodeMempool()); + mirFunction->GetCodeMempool()->Release(); } mirFunction->SetCodeMemPool(memPoolCtrler.NewMemPool("IR from IRMap::Emit()")); mirFunction->GetCodeMPAllocator().SetMemPool(mirFunction->GetCodeMempool()); diff --git a/src/maple_me/src/me_irmap.cpp b/src/maple_me/src/me_irmap.cpp index 6ffa3b927ddb6069b4c542495e98204ed710a15d..44f30eb3d493f8863ebe679f1312837bcb47098d 100644 --- a/src/maple_me/src/me_irmap.cpp +++ b/src/maple_me/src/me_irmap.cpp @@ -107,7 +107,7 @@ AnalysisResult *MeDoIRMap::Run(MeFunction *func, MeFuncResultMgr *funcResMgr, Mo irMap->GetTempAlloc().SetMemPool(nullptr); // delete input IR code for current function MIRFunction *mirFunc = func->GetMirFunc(); - memPoolCtrler.DeleteMemPool(mirFunc->GetCodeMempool()); + mirFunc->GetCodeMempool()->Release(); mirFunc->SetCodeMemPool(nullptr); // delete versionst_table #if MIR_FEATURE_FULL @@ -124,7 +124,7 @@ AnalysisResult *MeDoIRMap::Run(MeFunction *func, MeFuncResultMgr *funcResMgr, Mo bb->SetLast(nullptr); } #endif - memPoolCtrler.DeleteMemPool(func->GetMeSSATab()->GetVersionStTable().GetVSTAlloc().GetMemPool()); + func->GetMeSSATab()->GetVersionStTable().GetVSTAlloc().GetMemPool()->Release(); return irMap; } } // namespace maple diff --git a/src/maple_me/src/me_loop_canon.cpp b/src/maple_me/src/me_loop_canon.cpp index ffb01c747454b57f6fefcbdc0a6d5a68cad38328..916a6818b03d6300373c92e1ad2aa42c1068a8e6 100644 --- a/src/maple_me/src/me_loop_canon.cpp +++ b/src/maple_me/src/me_loop_canon.cpp @@ -101,7 +101,7 @@ void MeDoLoopCanon::Convert(MeFunction &func, BB &bb, BB &pred, MapleMapfallthru is in loopbody, latchBB need convert condgoto and make original target as its fallthru bool swapSuccOfLatch = (swapSuccs.find(std::make_pair(&bb, &pred)) != swapSuccs.end()); if (DEBUGFUNC(&func)) { - LogInfo::MapleLogger() << "***loop convert: backedge bb->id_ " << bb.GetBBId() << " pred->id_ " + LogInfo::MapleLogger() << "***loop convert: backedge bb->id " << bb.GetBBId() << " pred->id " << pred.GetBBId(); if (swapSuccOfLatch) { LogInfo::MapleLogger() << " need swap succs\n"; diff --git a/src/maple_me/src/me_phase_manager.cpp b/src/maple_me/src/me_phase_manager.cpp index 2b3131ef801feed58c0916e69a6204418498da54..1849bbf4ea363c8fe6d6bbf8e4c709b5d0cc668b 100644 --- a/src/maple_me/src/me_phase_manager.cpp +++ b/src/maple_me/src/me_phase_manager.cpp @@ -66,7 +66,7 @@ void MeFuncPhaseManager::RunFuncPhase(MeFunction *func, MeFuncPhase *phase) { MePhaseID phaseID = phase->GetPhaseId(); if ((func->NumBBs() > 0) || (phaseID == MeFuncPhase_EMIT)) { analysisRes = phase->Run(func, &arFuncManager, modResMgr); - phase->ReleaseMemPool(analysisRes == nullptr ? nullptr : analysisRes->GetMempool()); + phase->ClearMemPoolsExcept(analysisRes == nullptr ? nullptr : analysisRes->GetMempool()); phase->ClearString(); } if (analysisRes != nullptr) { @@ -130,13 +130,14 @@ void MeFuncPhaseManager::IPACleanUp(MeFunction *func) { memPoolCtrler.DeleteMemPool(func->GetMemPool()); } -void MeFuncPhaseManager::Run(MIRFunction *mirFunc, uint64 rangeNum, const std::string &meInput) { +void MeFuncPhaseManager::Run(MIRFunction *mirFunc, uint64 rangeNum, const std::string &meInput, + MemPoolCtrler &localMpCtrler) { if (!MeOption::quiet) { LogInfo::MapleLogger() << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>> Optimizing Function < " << mirFunc->GetName() << " id=" << mirFunc->GetPuidxOrigin() << " >---\n"; } - MemPool *funcMP = memPoolCtrler.NewMemPool("maple_me per-function mempool"); - MemPool *versMP = memPoolCtrler.NewMemPool("first verst mempool"); + MemPool *funcMP = localMpCtrler.NewMemPool("maple_me per-function mempool"); + MemPool *versMP = localMpCtrler.NewMemPool("first verst mempool"); MeFunction &func = *(funcMP->New(&mirModule, mirFunc, funcMP, versMP, meInput)); func.PartialInit(false); #if DEBUG @@ -186,7 +187,7 @@ void MeFuncPhaseManager::Run(MIRFunction *mirFunc, uint64 rangeNum, const std::s CHECK_FATAL(false, "phases in ipa will not chang cfg."); } // do all the phases start over - MemPool *versMemPool = memPoolCtrler.NewMemPool("second verst mempool"); + MemPool *versMemPool = localMpCtrler.NewMemPool("second verst mempool"); MeFunction function(&mirModule, mirFunc, funcMP, versMemPool, meInput); function.PartialInit(true); function.Prepare(rangeNum); @@ -211,7 +212,25 @@ void MeFuncPhaseManager::Run(MIRFunction *mirFunc, uint64 rangeNum, const std::s GetAnalysisResultManager()->InvalidAllResults(); } if (!ipa) { - memPoolCtrler.DeleteMemPool(funcMP); + localMpCtrler.DeleteMemPool(funcMP); } } + +MeFuncPhaseManager &MeFuncPhaseManager::Clone(MemPool &mp, MemPoolCtrler &ctrler) const { + auto *fpm = mp.New(&mp, mirModule, modResMgr); + fpm->RegisterFuncPhases(); + fpm->SetGenMeMpl(genMeMpl); + fpm->SetTimePhases(timePhases); + fpm->SetIPA(ipa); + fpm->SetMePhase(mePhaseType); + for (PhaseID id : phaseSequences) { + fpm->AddPhase(registeredPhases.find(id)->second->PhaseName()); + } + // set memPoolCtrler for phases + for (auto pair : fpm->GetRegisteredPhases()) { + Phase *phase = pair.second; + phase->SetMpCtrler(&ctrler); + } + return *fpm; +} } // namespace maple diff --git a/src/maple_me/src/me_profile_gen.cpp b/src/maple_me/src/me_profile_gen.cpp index 3beccbb6d72cb6763aef471cf621892f62f4cf27..34c5533a1be4b1051b86e577f706b8630517da28 100644 --- a/src/maple_me/src/me_profile_gen.cpp +++ b/src/maple_me/src/me_profile_gen.cpp @@ -80,19 +80,6 @@ void MeProfGen::InstrumentBB(BB &bb) { } } -void MeProfGen::SaveProfile() { - if (!Options::profileTest) { - return; - } - if (func->GetName().find("main") != std::string::npos) { - std::vector opnds; - IntrinsiccallMeStmt *saveProfCall = hMap->CreateIntrinsicCallMeStmt(INTRN_MCCSaveProf, opnds); - for (BB *exitBB : func->GetCommonExitBB()->GetPred()) { - exitBB->AddMeStmtFirst(saveProfCall); - } - } -} - void MeProfGen::InstrumentFunc() { FindInstrumentEdges(); std::vector instrumentBBs; @@ -113,7 +100,6 @@ void MeProfGen::InstrumentFunc() { instrumentBB += instrumentBBs.size(); totalBB += GetAllBBs(); instrumentFunc++; - SaveProfile(); if (dump) { LogInfo::MapleLogger() << "******************after profile gen dump function******************\n"; func->Dump(true); diff --git a/src/maple_me/src/me_ssa_devirtual.cpp b/src/maple_me/src/me_ssa_devirtual.cpp index 158247b830dec8c09a1373df642be2e083946553..7527beb00f0d59c011cd027062f2e6fac7d623ca 100644 --- a/src/maple_me/src/me_ssa_devirtual.cpp +++ b/src/maple_me/src/me_ssa_devirtual.cpp @@ -25,7 +25,8 @@ AnalysisResult *MeDoSSADevirtual::Run(MeFunction *func, MeFuncResultMgr *frm, Mo CHECK_FATAL(mrm != nullptr, "Needs module result manager for ipa"); auto *kh = static_cast(mrm->GetAnalysisResult(MoPhase_CHA, &func->GetMIRModule())); ASSERT(kh != nullptr, "KlassHierarchy has problem"); - MeSSADevirtual meSSADevirtual(*NewMemPool(), func->GetMIRModule(), *func, *irMap, *kh, *dom); + bool skipReturnTypeOpt = false; + MeSSADevirtual meSSADevirtual(*NewMemPool(), func->GetMIRModule(), *func, *irMap, *kh, *dom, skipReturnTypeOpt); if (Options::O2) { Clone *clone = static_cast(mrm->GetAnalysisResult(MoPhase_CLONE, &func->GetMIRModule())); if (clone != nullptr) { diff --git a/src/maple_me/src/me_ssa_epre.cpp b/src/maple_me/src/me_ssa_epre.cpp index 7c55a029a5e464afc73371222966784c33efb19b..7244e3eab5c243098207d86628c1421999a5e6c6 100644 --- a/src/maple_me/src/me_ssa_epre.cpp +++ b/src/maple_me/src/me_ssa_epre.cpp @@ -87,7 +87,7 @@ AnalysisResult *MeDoSSAEPre::Run(MeFunction *func, MeFuncResultMgr *m, ModuleRes } ssaPre.ApplySSAPRE(); if (!ssaPre.GetCandsForSSAUpdate().empty()) { - MemPool *tmp = memPoolCtrler.NewMemPool("MeSSAUpdate"); + MemPool *tmp = NewMemPool(); MeSSAUpdate ssaUpdate(*func, *func->GetMeSSATab(), *dom, ssaPre.GetCandsForSSAUpdate(), *tmp); ssaUpdate.Run(); } diff --git a/src/maple_me/src/me_stmt_pre.cpp b/src/maple_me/src/me_stmt_pre.cpp index c9cdb698ef9970c0720dc60d333456b8b4fd7d88..c63889492af1a712edb7de36691fcb277bdec457 100644 --- a/src/maple_me/src/me_stmt_pre.cpp +++ b/src/maple_me/src/me_stmt_pre.cpp @@ -1068,7 +1068,7 @@ AnalysisResult *MeDoStmtPre::Run(MeFunction *func, MeFuncResultMgr *m, ModuleRes } ssaPre.ApplySSAPRE(); if (!ssaPre.GetCandsForSSAUpdate().empty()) { - MemPool *memPool = memPoolCtrler.NewMemPool("MeSSAUpdate"); + MemPool *memPool = NewMemPool(); CHECK_FATAL(memPool != nullptr, "must be"); MeSSAUpdate ssaUpdate(*func, *func->GetMeSSATab(), *dom, ssaPre.GetCandsForSSAUpdate(), *memPool); ssaUpdate.Run(); diff --git a/src/maple_me/src/prop.cpp b/src/maple_me/src/prop.cpp index 7091c5ea7f5c6f56a87dd2352173e79e46f6e16c..628262fc274394b119dfc9810206c7f985d4b2a9 100644 --- a/src/maple_me/src/prop.cpp +++ b/src/maple_me/src/prop.cpp @@ -22,13 +22,26 @@ using namespace maple; const int kPropTreeLevel = 15; // tree height threshold to increase to -bool IsCvtSafe(PrimType typeA, PrimType typeB) { - if (GetPrimTypeSize(typeA) > GetPrimTypeSize(typeB)) { - return false; +// (typeA -> typeB -> typeC) => (typeA -> typeC) +bool IgnoreInnerTypeCvt(PrimType typeA, PrimType typeB, PrimType typeC) { + if (IsPrimitiveInteger(typeA)) { + if (IsPrimitiveInteger(typeB)) { + if (IsPrimitiveInteger(typeC)) { + return GetPrimTypeSize(typeB) >= GetPrimTypeSize(typeA) || GetPrimTypeSize(typeB) >= GetPrimTypeSize(typeC); + } else if (IsPrimitiveFloat(typeC)) { + return GetPrimTypeSize(typeB) >= GetPrimTypeSize(typeA); + } + } else if (IsPrimitiveFloat(typeB)) { + if (IsPrimitiveFloat(typeC)) { + return GetPrimTypeSize(typeB) >= GetPrimTypeSize(typeC); + } + } + } else if (IsPrimitiveFloat(typeA)) { + if (IsPrimitiveFloat(typeB) && IsPrimitiveFloat(typeC)) { + return GetPrimTypeSize(typeB) >= GetPrimTypeSize(typeA) || GetPrimTypeSize(typeB) >= GetPrimTypeSize(typeC); + } } - - return (IsPrimitiveInteger(typeA) && IsPrimitiveInteger(typeB)) || - (IsPrimitiveFloat(typeA) && IsPrimitiveFloat(typeB)); + return false; } } // namespace @@ -64,17 +77,14 @@ MeExpr *Prop::SimplifyCvtMeExpr(const OpMeExpr &opMeExpr) const { // convert a convert expr if (opnd0->GetOp() == OP_cvt) { auto *cvtOpnd0 = static_cast(opnd0); - // "cvt type1 type2 (cvt type2 type3 (expr ))" can be simplified to "cvt type1 type3 expr" when: - // 1. converting type3 to type2 is safe; - // 2. converting type1 to type2 is safe; - // Otherwise, deleting the cvt of cvtOpnd0 may result in information loss. - if (IsCvtSafe(cvtOpnd0->GetOpnd(0)->GetPrimType(), cvtOpnd0->GetPrimType()) && - IsCvtSafe(opMeExpr.GetPrimType(), cvtOpnd0->GetPrimType())) { - return irMap.CreateMeExprTypeCvt(opMeExpr.GetPrimType(), cvtOpnd0->GetOpndType(), - utils::ToRef(cvtOpnd0->GetOpnd(0))); + // simplify "cvt type1 type2 (cvt type2 type3 (expr ))" to "cvt type1 type3 expr" + auto typeA = cvtOpnd0->GetOpnd(0)->GetPrimType(); + auto typeB = cvtOpnd0->GetPrimType(); + auto typeC = opMeExpr.GetPrimType(); + if (IgnoreInnerTypeCvt(typeA, typeB, typeC)) { + return irMap.CreateMeExprTypeCvt(typeC, typeA, utils::ToRef(cvtOpnd0->GetOpnd(0))); } } - return nullptr; } @@ -119,32 +129,56 @@ MeExpr *Prop::SimplifyCompareSelectConstMeExpr(const OpMeExpr &opMeExpr, const M return irMap.HashMeExpr(newopMeExpr); } -MeExpr *Prop::SimplifyCompareMeExpr(OpMeExpr &opMeExpr) const { +MeExpr *Prop::SimplifyCompareConstWithAddress(OpMeExpr &opMeExpr) const { MeExpr *opnd0 = opMeExpr.GetOpnd(0); MeExpr *opnd1 = opMeExpr.GetOpnd(1); - - Opcode opcode = opMeExpr.GetOp(); bool isNeOrEq = (opcode == OP_ne || opcode == OP_eq); - - // compare constant with addrof - if (isNeOrEq && ((opnd0->GetMeOp() == kMeOpAddrof && opnd1->GetMeOp() == kMeOpConst) || - (opnd0->GetMeOp() == kMeOpConst && opnd1->GetMeOp() == kMeOpAddrof))) { + if (isNeOrEq) { MIRConst *constOpnd = nullptr; - if (opnd0->GetMeOp() == kMeOpAddrof) { - constOpnd = static_cast(opnd1)->GetConstVal(); - } else { - constOpnd = static_cast(opnd0)->GetConstVal(); + if (opnd0->GetMeOp() == kMeOpAddrof && opnd1->GetMeOp() == kMeOpConst) { + constOpnd = static_cast(opnd1)->GetConstVal(); + } else if (opnd0->GetMeOp() == kMeOpConst && opnd1->GetMeOp() == kMeOpAddrof) { + constOpnd = static_cast(opnd0)->GetConstVal(); } - if (constOpnd->IsZero()) { + + if (constOpnd != nullptr && constOpnd->IsZero()) { // addrof will not be zero, so this comparison can be replaced with a constant - auto *resConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(opcode == OP_ne), - utils::ToRef(GlobalTables::GetTypeTable().GetUInt1())); + auto *resConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( + static_cast(opcode == OP_ne), utils::ToRef(GlobalTables::GetTypeTable().GetUInt1())); return irMap.CreateConstMeExpr(opMeExpr.GetPrimType(), *resConst); } - return nullptr; } + return nullptr; +} +MeExpr *Prop::SimplifyCompareWithZero(OpMeExpr &opMeExpr) const { + Opcode opcode = opMeExpr.GetOp(); + MeExpr *opnd0 = opMeExpr.GetOpnd(0); + MeExpr *opnd1 = opMeExpr.GetOpnd(1); + if (opnd0->GetOp() == OP_cmp && opnd1->GetMeOp() == kMeOpConst) { + auto *constVal = static_cast(opnd1)->GetConstVal(); + if (constVal->GetKind() == kConstInt && constVal->IsZero()) { + auto *subOpnd0 = opnd0->GetOpnd(0); + auto *subOpnd1 = opnd0->GetOpnd(1); + return irMap.CreateMeExprCompare(opcode, PTY_u1, subOpnd0->GetPrimType(), *subOpnd0, *subOpnd1); + } + } + return nullptr; +} + +MeExpr *Prop::SimplifyCompareMeExpr(OpMeExpr &opMeExpr) const { + + // compare constant with addrof + auto *newOpExpr = SimplifyCompareConstWithAddress(opMeExpr); + if (newOpExpr != nullptr) { + return newOpExpr; + } + + MeExpr *opnd0 = opMeExpr.GetOpnd(0); + MeExpr *opnd1 = opMeExpr.GetOpnd(1); + Opcode opcode = opMeExpr.GetOp(); + bool isNeOrEq = (opcode == OP_ne || opcode == OP_eq); // compare select (a ? b : c) with constant 0 or 1 if (isNeOrEq && opnd0->GetOp() == OP_select && (opnd1->GetMeOp() == kMeOpConst && IsPrimitivePureScalar(opnd1->GetPrimType()))) { @@ -159,6 +193,11 @@ MeExpr *Prop::SimplifyCompareMeExpr(OpMeExpr &opMeExpr) const { return SimplifyCompareSelectConstMeExpr(opMeExpr, *opMeOpnd0, *opnd1, *opnd01, *opnd02); } + // compare compareRes with zero + newOpExpr = SimplifyCompareWithZero(opMeExpr); + if (newOpExpr != nullptr) { + return newOpExpr; + } return nullptr; } diff --git a/src/maple_me/src/ssa_devirtual.cpp b/src/maple_me/src/ssa_devirtual.cpp index 8809cf573ccfd7fe6f0ec7612a3b944f1fefd788..8a8a6b84cdf1c6d12420959215cbe982981f3f02 100644 --- a/src/maple_me/src/ssa_devirtual.cpp +++ b/src/maple_me/src/ssa_devirtual.cpp @@ -155,6 +155,9 @@ bool SSADevirtual::DevirtualizeCall(CallMeStmt &callStmt) { TyIdx receiverInferredTyIdx = GetInferredTyIdx(*thisParm); MIRFunction &mirFunc = callStmt.GetTargetFunction(); if (thisParm->GetPrimType() == PTY_ref && receiverInferredTyIdx != 0u) { + if (skipReturnTypeOpt) { + break; + } Klass *inferredKlass = kh->GetKlassFromTyIdx(receiverInferredTyIdx); if (inferredKlass == nullptr) { break; @@ -185,6 +188,9 @@ bool SSADevirtual::DevirtualizeCall(CallMeStmt &callStmt) { ReplaceCall(callStmt, *uniqFunc); return true; } else { + if (skipReturnTypeOpt) { + break; + } if (thisParm->GetMeOp() == kMeOpVar) { auto *varMeExpr = static_cast(thisParm); const MapleVector inferredTypeCandidates = varMeExpr->GetInferredTypeCandidates(); diff --git a/src/maple_me/src/ssa_epre.cpp b/src/maple_me/src/ssa_epre.cpp index db9f42d954da71972efde3018521c762c972a1d1..b0e242e3ca6d8c785703b06780d0c3a296c29056 100644 --- a/src/maple_me/src/ssa_epre.cpp +++ b/src/maple_me/src/ssa_epre.cpp @@ -320,7 +320,7 @@ void SSAEPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, b (naryMeExpr->GetOp() == OP_intrinsicop && IntrinDesc::intrinTable[naryMeExpr->GetIntrinsic()].IsPure())) && (epreIncludeRef || naryMeExpr->GetPrimType() != PTY_ref)) { if (meExpr.GetOp() == OP_array) { - MIRType *mirType = GlobalTables::GetTypeTable().GetTypeTable().at(naryMeExpr->GetTyIdx()); + MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(naryMeExpr->GetTyIdx()); CHECK_FATAL(mirType->GetKind() == kTypePointer, "array must have pointer type"); auto *ptrMIRType = static_cast(mirType); MIRJarrayType *arryType = safe_cast(ptrMIRType->GetPointedType()); diff --git a/src/maple_me/src/ssa_pre.cpp b/src/maple_me/src/ssa_pre.cpp index 9346fa647efefd54fa85d0d75a91312084afef5e..2b71b70df87ff53e83f921388f47cebd4abb1e3d 100644 --- a/src/maple_me/src/ssa_pre.cpp +++ b/src/maple_me/src/ssa_pre.cpp @@ -1195,7 +1195,8 @@ bool SSAPre::DefVarDominateOcc(const MeExpr *meExpr, const MeOccur &meOcc) const auto *varMeExpr = static_cast(meExpr); switch (varMeExpr->GetDefBy()) { case kDefByNo: - return true; // it's an original variable which dominates everything + // zero version vst dominate everything + return ssaTab->IsInitVersion(varMeExpr->GetVstIdx(), varMeExpr->GetOStIdx()); case kDefByStmt: { MeStmt *meStmt = varMeExpr->GetDefStmt(); CHECK_FATAL(meStmt != nullptr, "should have a def meStmt"); @@ -1359,7 +1360,7 @@ MeRealOcc *SSAPre::CreateRealOcc(MeStmt &meStmt, int seqStmt, MeExpr &meExpr, bo auto *ptrMIRType = static_cast(mirType); FieldID fieldId = ivarMeExpr->GetFieldID(); TyIdxFieldAttrPair fldPair = ptrMIRType->GetPointedTyIdxFldAttrPairWithFieldID(fieldId); - MIRType *ty = GlobalTables::GetTypeTable().GetTypeTable().at(fldPair.first); + MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fldPair.first); bool isFinal = fldPair.second.GetAttr(FLDATTR_final); wkCand->SetNeedLocalRefVar(ty->GetPrimType() == PTY_ref && !isFinal); } diff --git a/src/maple_phase/include/phase.h b/src/maple_phase/include/phase.h index b977ad382003bef6118ff4f2894a2599c24908bb..419a343d55595563b2bcb2b6d747f0557c41c5b5 100644 --- a/src/maple_phase/include/phase.h +++ b/src/maple_phase/include/phase.h @@ -40,7 +40,7 @@ class AnalysisResult { } void EraseMemPool() { - memPoolCtrler.DeleteMemPool(memPool); + memPool->Release(); } private: @@ -51,6 +51,8 @@ class Phase { public: Phase() = default; + explicit Phase(MemPoolCtrler &mpCtrler) : mpCtrler(&mpCtrler) {} + virtual ~Phase() = default; virtual std::string PhaseName() const { @@ -64,27 +66,37 @@ class Phase { ASSERT(!phaseName.empty(), "PhaseName should not be empty"); ++memPoolCount; std::string memPoolName = phaseName + " MemPool " + std::to_string(memPoolCount); - MemPool *memPool = memPoolCtrler.NewMemPool(memPoolName); - memPools.push_back(memPool); + MemPool *memPool = mpCtrler->NewMemPool(memPoolName); + memPools.insert(memPool); return memPool; } + // remove the specified memPool from memPools, then release the memPool + void ReleaseMemPool(MemPool *memPool) { + memPools.erase(memPool); + memPool->Release(); + } + // release all mempool use in this phase except exclusion - void ReleaseMemPool(const MemPool *exclusion) { + void ClearMemPoolsExcept(const MemPool *exclusion) { for (MemPool *memPool : memPools) { if (memPool == exclusion) { continue; } - memPoolCtrler.DeleteMemPool(memPool); + mpCtrler->DeleteMemPool(memPool); memPool = nullptr; } memPools.clear(); - memPools.shrink_to_fit(); + } + + void SetMpCtrler(MemPoolCtrler *ctrler) { + mpCtrler = ctrler; } private: unsigned int memPoolCount = 0; - std::vector memPools; + std::set memPools; + MemPoolCtrler *mpCtrler = &memPoolCtrler; }; template @@ -116,10 +128,10 @@ class AnalysisResultManager { AnalysisResult *result = anaPhase->Run(ir, this); // allow invoke phases whose return value is nullptr using GetAnalysisResult if (result == nullptr) { - anaPhase->ReleaseMemPool(nullptr); + anaPhase->ClearMemPoolsExcept(nullptr); return nullptr; } - anaPhase->ReleaseMemPool(result->GetMempool()); + anaPhase->ClearMemPoolsExcept(result->GetMempool()); analysisResults[key] = result; // add r to analysisResults return result; } diff --git a/src/maple_phase/include/phase_manager.h b/src/maple_phase/include/phase_manager.h index 2c06bf240078431e277c352a93a74e4060daa440..9d524163bbd6c33350b8418fce4534e84724cd52 100644 --- a/src/maple_phase/include/phase_manager.h +++ b/src/maple_phase/include/phase_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] 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. @@ -146,6 +146,11 @@ class PhaseManager { } return total; } + + const MapleMap &GetRegisteredPhases() const { + return registeredPhases; + } + protected: std::string managerName; MapleAllocator allocator; diff --git a/src/maple_util/include/muid.h b/src/maple_util/include/muid.h index c5f46227ebd484595642d188e6af50eb143ea772..65402dd78c939339cfdd56a2f2f334cb43fc1900 100644 --- a/src/maple_util/include/muid.h +++ b/src/maple_util/include/muid.h @@ -63,19 +63,15 @@ class MUID { public: union { #ifdef USE_64BIT_MUID - uint64_t raw; uint32_t words[kNumLowAndHigh]; uint8_t bytes[kMuidLength]; + uint64_t raw; #else uint64_t words[kNumLowAndHigh]; uint8_t bytes[kMuidLength]; #endif // USE_64BIT_MUID } data; - MUID() { - data.words[0] = 0; - data.words[1] = 0; - } inline bool IsSystemNameSpace() const { return (data.bytes[kMuidLength - 1] & ~kBitMask) == kSystemNamespace; } @@ -119,7 +115,7 @@ class MUID { } // Return 64-bit size hash for AArch64. - std::size_t hash() const { + uint64_t hash() const { #ifdef USE_64BIT_MUID return data.raw; #else diff --git a/src/mempool/include/mempool.h b/src/mempool/include/mempool.h index c6892415e7882012de242a2e7f62063e5b49378b..88bf1ad456a9442dd45a6ad30ef46b8e057f2d07 100644 --- a/src/mempool/include/mempool.h +++ b/src/mempool/include/mempool.h @@ -46,18 +46,7 @@ class MemPoolCtrler { MemPool *NewMemPool(const std::string&); void DeleteMemPool(MemPool *memPool); - void FreeMem() { - for (MemBlock *block : freeMemBlocks) { - free(block); - } - for (auto it = largeFreeMemBlocks.begin(); it != largeFreeMemBlocks.end(); ++it) { - for (auto itr = (*it).second.begin(); itr != (*it).second.end(); ++itr) { - free(*itr); - } - } - freeMemBlocks.clear(); - largeFreeMemBlocks.clear(); - } + void FreeMem(); bool IsEmpty() const { return memPools.empty(); } @@ -89,7 +78,7 @@ class MemPool { friend MemPoolCtrler; public: // Methods - MemPool(MemPoolCtrler &ctl, const std::string &name) : ctrler(&ctl), name(name) { + MemPool(MemPoolCtrler &ctl, const std::string &name) : ctrler(ctl), name(name) { } ~MemPool(); @@ -97,10 +86,19 @@ class MemPool { void *Calloc(size_t size); void *Realloc(const void *ptr, size_t oldSize, size_t newSize); void ReleaseContainingMem(); + + void Release() { + ctrler.DeleteMemPool(this); + } + const std::string &GetName() const { return name; } + const MemPoolCtrler &GetCtrler() const { + return ctrler; + } + template T *Clone(const T &t) { void *p = Malloc(sizeof(T)); @@ -136,7 +134,7 @@ class MemPool { static constexpr size_t kMemBlockOverhead = (BITS_ALIGN(sizeof(MemPoolCtrler::MemBlock))); MemPoolCtrler::MemBlock *GetLargeMemBlock(size_t size); // Raw allocate large memory block MemPoolCtrler::MemBlock *GetMemBlock(); - MemPoolCtrler *ctrler; // Hookup controller object + MemPoolCtrler &ctrler; // Hookup controller object std::string name; // Name of the memory pool // Save the memory block stack std::stack memBlockStack; diff --git a/src/mpl2mpl/include/constantfold.h b/src/mpl2mpl/include/constantfold.h index 914738c18b010d7c33c03621eb34e392f74ccf6c..476dd73d7afccfe164cbeba74f609452462be38e 100644 --- a/src/mpl2mpl/include/constantfold.h +++ b/src/mpl2mpl/include/constantfold.h @@ -45,6 +45,7 @@ class ConstantFold : public FuncOptimizeImpl { void ProcessFunc(MIRFunction *func); virtual ~ConstantFold() = default; + template T CalIntValueFromFloatValue(T value, MIRType &resultType) const; MIRConst *FoldFloorMIRConst(const MIRConst&, PrimType, PrimType) const; MIRConst *FoldRoundMIRConst(const MIRConst&, PrimType, PrimType) const; MIRConst *FoldTypeCvtMIRConst(const MIRConst&, PrimType, PrimType) const; diff --git a/src/mpl2mpl/include/muid_replacement.h b/src/mpl2mpl/include/muid_replacement.h index 13dd73916e9dba33dcc99affbc6fb9a314a95c81..fa47f938c5fd06db88fa5f90d9d150d41546d0f0 100644 --- a/src/mpl2mpl/include/muid_replacement.h +++ b/src/mpl2mpl/include/muid_replacement.h @@ -93,7 +93,7 @@ class MUIDReplacement : public FuncOptimizeImpl { uint32 FindIndexFromUndefTable(const MIRSymbol &mirSymbol, bool isFunc); void ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldID, bool isVtab); void ReplaceFuncTable(const std::string &name); - void ReplaceAddrofConst(MIRConst *&entry, bool isGlobalRootList = false); + void ReplaceAddrofConst(MIRConst *&entry); void ReplaceDataTable(const std::string &name); void ReplaceDirectInvokeOrAddroffunc(MIRFunction ¤tFunc, StmtNode &stmt); void ReplaceDassign(MIRFunction ¤tFunc, const DassignNode &dassignNode); @@ -113,6 +113,7 @@ class MUIDReplacement : public FuncOptimizeImpl { void CollectFuncAndDataFromGlobalTab(); void CollectFuncAndDataFromFuncList(); void GenerateCompilerVersionNum(); + int64 GetDefOrUndefOffsetWithMask(uint64, bool isDef) const; static MIRSymbol *GetSymbolFromName(const std::string &name); ConstvalNode* GetConstvalNode(int64 index); // The following sets are for internal uses. Sorting order does not matter here. diff --git a/src/mpl2mpl/src/class_hierarchy.cpp b/src/mpl2mpl/src/class_hierarchy.cpp index 90d5b4b15a56a65acad75f9d63b12a9d62d9e95f..03b532a2544267b3cbd17454d85804519ba14e8c 100644 --- a/src/mpl2mpl/src/class_hierarchy.cpp +++ b/src/mpl2mpl/src/class_hierarchy.cpp @@ -776,7 +776,7 @@ KlassHierarchy::KlassHierarchy(MIRModule *mirmodule, MemPool *memPool) topoWorkList(alloc.Adapter()) {} AnalysisResult *DoKlassHierarchy::Run(MIRModule *module, ModuleResultMgr *m) { - MemPool *memPool = memPoolCtrler.NewMemPool("classhierarchy mempool"); + MemPool *memPool = NewMemPool(); KlassHierarchy *kh = memPool->New(module, memPool); KlassHierarchy::traceFlag = TRACE_PHASE; kh->BuildHierarchy(); diff --git a/src/mpl2mpl/src/constantfold.cpp b/src/mpl2mpl/src/constantfold.cpp index e80a8959c3fa36609bf9fc1efbf314b422453803..3d8a4f2b9b05d287630798da2f553b5bca06ec58 100644 --- a/src/mpl2mpl/src/constantfold.cpp +++ b/src/mpl2mpl/src/constantfold.cpp @@ -24,6 +24,7 @@ namespace { constexpr maple::uint64 kJsTypeNumber = 4; constexpr maple::uint64 kJsTypeNumberInHigh32Bit = kJsTypeNumber << 32; // set high 32 bit as JSTYPE_NUMBER constexpr maple::uint32 kByteSizeOfBit64 = 8; // byte number for 64 bit +constexpr maple::uint32 kBitSizePerByte = 8; enum CompareRes : maple::int64 { kLess = -1, kEqual = 0, @@ -1034,15 +1035,37 @@ ConstvalNode *ConstantFold::FoldCeil(const ConstvalNode &cst, PrimType fromType, return resultConst; } +template +T ConstantFold::CalIntValueFromFloatValue(T value, MIRType &resultType) const { + ASSERT(kByteSizeOfBit64 >= resultType.GetSize(), "unsurpported type"); + size_t shiftNum = (kByteSizeOfBit64 - resultType.GetSize()) * kBitSizePerByte; + int64 max = 0; + int64 min = 0; + if (IsSignedInteger(resultType.GetPrimType())) { + max = static_cast(LONG_LONG_MAX >> shiftNum); + min = (LONG_LONG_MIN >> shiftNum); + } else { + max = static_cast(ULONG_LONG_MAX >> shiftNum); + } + if (value > max) { + return max; + } else if (value < min) { + return min; + } + return value; +} + MIRConst *ConstantFold::FoldFloorMIRConst(const MIRConst &cst, PrimType fromType, PrimType toType) const { MIRType &resultType = *GlobalTables::GetTypeTable().GetPrimType(toType); if (fromType == PTY_f32) { const auto &constValue = static_cast(cst); float floutValue = floor(constValue.GetValue()); + floutValue = CalIntValueFromFloatValue(floutValue, resultType); return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floutValue), resultType); } else { const auto &constValue = static_cast(cst); double doubleValue = floor(constValue.GetValue()); + doubleValue = CalIntValueFromFloatValue(doubleValue, resultType); return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(doubleValue), resultType); } } diff --git a/src/mpl2mpl/src/muid_replacement.cpp b/src/mpl2mpl/src/muid_replacement.cpp index bb4bd986a3d8c1f49e86c9e2b6bc35b71b53559a..9ead44929212ff8128e0fff27d0d2cca92ad428b 100644 --- a/src/mpl2mpl/src/muid_replacement.cpp +++ b/src/mpl2mpl/src/muid_replacement.cpp @@ -25,12 +25,18 @@ constexpr char kMuidFuncPtrStr[] = "__muid_funcptr"; constexpr char kMuidSymPtrStr[] = "__muid_symptr"; #ifdef USE_ARM32_MACRO -constexpr maple::uint32 kFromUndefIndexMask = 0x40000000; -constexpr maple::uint32 kFromDefIndexMask = 0x20000000; +enum LinkerRefFormat { + kLinkerRefAddress = 0, // must be 0 + kLinkerRefDef = 1, // def + kLinkerRefUnDef = 2, // undef + kLinkerRefOffset = 3 // offset +}; #else constexpr maple::uint64 kFromUndefIndexMask = 0x4000000000000000; constexpr maple::uint64 kFromDefIndexMask = 0x2000000000000000; #endif +constexpr maple::uint64 KReservedBits = 2u; + } // namespace @@ -853,7 +859,6 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldID, b MIRFunction *func = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(funcAddr->GetValue()); uint64 offset = 0; MIRIntConst *constNode = nullptr; - constexpr uint64 reservedBits = 2u; if (func->GetBody() != nullptr) { ASSERT(func->GetFuncSymbol() != nullptr, "null ptr check!"); offset = FindIndexFromDefTable(*(func->GetFuncSymbol()), true); @@ -863,7 +868,7 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldID, b // this is an index into the funcDefTab constexpr uint64 idxIntoFuncDefTabFlag = 2u; constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - static_cast(((offset + 1) << reservedBits) + idxIntoFuncDefTabFlag), voidType); + static_cast(((offset + 1) << KReservedBits) + idxIntoFuncDefTabFlag), voidType); } else if (isVtab && func->IsAbstract()) { MIRType &type = *GlobalTables::GetTypeTable().GetVoidPtr(); constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, type); @@ -872,7 +877,7 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldID, b offset = FindIndexFromUndefTable(*(func->GetFuncSymbol()), true); // The second least significant bit is set to 0, indicating // this is an index into the funcUndefTab - constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast((offset + 1) << reservedBits), + constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast((offset + 1) << KReservedBits), voidType); } if (fieldID != 0xffffffff) { @@ -891,14 +896,13 @@ void MUIDReplacement::ReplaceDataTable(const std::string &name) { if (oldConst == nullptr) { return; } - bool isGLobalRootList = (name == NameMangler::kGcRootList) ? true : false; for (MIRConst *&oldTabEntry : oldConst->GetConstVec()) { CHECK_NULL_FATAL(oldTabEntry); if (oldTabEntry->GetKind() == kConstAggConst) { auto *aggrC = static_cast(oldTabEntry); for (size_t i = 0; i < aggrC->GetConstVec().size(); ++i) { CHECK_NULL_FATAL(aggrC->GetConstVecItem(i)); - ReplaceAddrofConst(aggrC->GetConstVecItem(i), isGLobalRootList); + ReplaceAddrofConst(aggrC->GetConstVecItem(i)); MIRConstPtr mirConst = aggrC->GetConstVecItem(i); if (mirConst->GetKind() == kConstInt) { MIRIntConst *newIntConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( @@ -909,7 +913,7 @@ void MUIDReplacement::ReplaceDataTable(const std::string &name) { } } } else if (oldTabEntry->GetKind() == kConstAddrof) { - ReplaceAddrofConst(oldTabEntry, isGLobalRootList); + ReplaceAddrofConst(oldTabEntry); } } } @@ -944,7 +948,7 @@ void MUIDReplacement::ReplaceDecoupleKeyTable(MIRAggConst* oldConst) { } } -void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry, bool isGlobalRootList) { +void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry) { if (entry->GetKind() != kConstAddrof) { return; } @@ -959,26 +963,32 @@ void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry, bool isGlobalRootList MIRIntConst *constNode = nullptr; if (addrSym->GetStorageClass() != kScExtern) { offset = FindIndexFromDefTable(*addrSym, false); - if (isGlobalRootList == true) { -#ifdef USE_ARM32_MACRO - offset = (offset << 2) + 1; -#endif - } - constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(offset | kFromDefIndexMask), + constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(GetDefOrUndefOffsetWithMask(offset, true), voidType); } else { offset = FindIndexFromUndefTable(*addrSym, false); - if (isGlobalRootList == true) { -#ifdef USE_ARM32_MACRO - offset = (offset << 2) + 1; -#endif - } - constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(offset | kFromUndefIndexMask), + constNode = GlobalTables::GetIntConstTable().GetOrCreateIntConst(GetDefOrUndefOffsetWithMask(offset, false), voidType); } entry = constNode; } +int64 MUIDReplacement::GetDefOrUndefOffsetWithMask(uint64 offset, bool isDef) const { + if (isDef) { +#ifdef USE_ARM32_MACRO + return static_cast((offset << KReservedBits) + kLinkerRefDef); +#else + return static_cast(offset | kFromDefIndexMask); +#endif + } else { +#ifdef USE_ARM32_MACRO + return static_cast((offset << KReservedBits) + kLinkerRefUnDef); +#else + return static_cast(offset | kFromUndefIndexMask); +#endif + } +} + void MUIDReplacement::ReplaceDirectInvokeOrAddroffunc(MIRFunction ¤tFunc, StmtNode &stmt) { PUIdx puidx; CallNode *callNode = nullptr; diff --git a/src/mpl2mpl/src/vtable_impl.cpp b/src/mpl2mpl/src/vtable_impl.cpp index 64ae6d0a55ee8959c2be653c65dee0c37bb24c3a..f98ccf73b98f60282f98349a78eb2913f2818078 100644 --- a/src/mpl2mpl/src/vtable_impl.cpp +++ b/src/mpl2mpl/src/vtable_impl.cpp @@ -57,6 +57,13 @@ bool VtableImpl::Intrinsify(MIRFunction &func, CallNode &cnode) { if (!retvs.empty()) { StIdx stidx = retvs.begin()->first; StmtNode *intrnCallStmt = nullptr; + if (cnode.Opnd(0)->GetOpCode() == OP_iread) { + for (size_t i = 0; i < cnode.GetNopndSize() - 1; ++i) { + cnode.SetNOpndAt(i, cnode.GetNopnd().at(i + 1)); + } + cnode.SetNumOpnds(cnode.GetNumOpnds() - 1); + cnode.GetNopnd().resize(cnode.GetNumOpnds()); + } if (stidx.Idx() != 0) { MIRSymbol *retSt = currFunc->GetLocalOrGlobalSymbol(stidx); intrnCallStmt = builder->CreateStmtIntrinsicCallAssigned(intrnId, cnode.GetNopnd(), retSt); diff --git a/test/testsuite/maple.py b/test/testsuite/maple.py index 2f197642786fa7090fbf8f9cce24b7f7f4ff5335..f89366080931feef9c1eebb5b2881751c6df3a98 100644 --- a/test/testsuite/maple.py +++ b/test/testsuite/maple.py @@ -245,7 +245,7 @@ def do_prepare(components, info, maple_root): maple_out_path = maple_root + "/output" maple_out_lib_path = maple_out_path + "/ops" maple_out_bin_path = maple_out_path + "/bin/" - gnu_bin_path = maple_root + "/tools/clang_llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/" + gnu_bin_path = maple_root + "/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/" javac_options = "-g -d . " jar_options = "-cvf " as_options = "-g3 -O2 -x assembler-with-cpp -march=armv8-a -target aarch64-linux-gnu -c "