diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index e026dfd2272b47c669148544111f3ae8147a553f..6c34ff45ba4a6a7b3527b6f089788cd134a0c6e5 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index d462859ba38f1c72467751a0e48911047004a595..91a8cfa45d9ed7e912a6e2784334e0762c43707a 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index d67a9f95f01cc494a9a82f827b50b638e3257e9c..b614723a41d7984bcd877ef886e701293921ff8c 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/deplibs/libmaple_driverutil.a b/src/deplibs/libmaple_driverutil.a index cf80ffef7184fcf172e558e3e73a5cdd3905263b..dfc8618702d06c1489e30773926b29f0974622d2 100644 Binary files a/src/deplibs/libmaple_driverutil.a and b/src/deplibs/libmaple_driverutil.a differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index 3c5f6bf730f7c3ac8235bcd8d385a558bbb177d1..aee4d531c7f47987b819538200196e673f200284 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 4e0e223778ecc49b518701b0268d16df32ffa9db..690e1097824a4af8cb69282bd8fd9efb19ea6bf7 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_driver/include/mpl_options.h b/src/maple_driver/include/mpl_options.h index b4579804bb02ce109e273cff31d4052fd96278a3..7ae85e471d14de3ebb47ee3af77a0285bdf261d0 100644 --- a/src/maple_driver/include/mpl_options.h +++ b/src/maple_driver/include/mpl_options.h @@ -205,7 +205,7 @@ class MplOptions { ErrorCode DecideRunningPhases(); ErrorCode CheckInputFileValidity(); ErrorCode CheckFileExits(); - void AddOption(const mapleOption::Option &option); + ErrorCode AddOption(const mapleOption::Option &option); ErrorCode UpdatePhaseOption(const std::string &args, const std::string &exeName); ErrorCode UpdateExtraOptionOpt(const std::string &args); ErrorCode AppendDefaultCombOptions(); diff --git a/src/maple_driver/include/usages.h b/src/maple_driver/include/usages.h index c60a280349cb1baae3a2df5cffd4b43d5a412ea4..a4342640030406c70e910f5ca887e68d824797a5 100644 --- a/src/maple_driver/include/usages.h +++ b/src/maple_driver/include/usages.h @@ -71,6 +71,21 @@ enum OptionIndex : uint64 { kMpl2MplMapleLinker, kMplnkDumpMuid, kEmitVtableImpl, + kInlineWithProfile, + kInlineWithoutProfile, + kMpl2MplUseInline, + kMpl2MplNoInline, + kMpl2MplUseCrossModuleInline, + kMpl2MplNoCrossModuleInline, + kInlineSmallFunctionThreshold, + kInlineSyntheticFunctionThreshold, + kInlineHotFunctionThreshold, + kInlineModuleGrowth, + kInlineColdFunctionThreshold, + kProfileHotCount, + kProfileColdCount, + kProfileHotRate, + kProfileColdRate, // ----------mplcg begin--------- kCGQuiet, kPie, diff --git a/src/maple_driver/src/maple_comb_compiler.cpp b/src/maple_driver/src/maple_comb_compiler.cpp index bb82b3f0fde37a755827a63ea79fe7985c4b8873..61349468b34d64839218e5f7c9f0687eae78df9a 100644 --- a/src/maple_driver/src/maple_comb_compiler.cpp +++ b/src/maple_driver/src/maple_comb_compiler.cpp @@ -73,6 +73,7 @@ void MapleCombCompiler::PrintCommand(const MplOptions &options) const { << GetInputFileName(options) << options.GetPrintCommandStr() << '\n'; } + MeOption *MapleCombCompiler::MakeMeOptions(const MplOptions &options, MemPool &optMp) { MeOption *meOption = new MeOption(optMp); auto it = options.GetExeOptions().find(kBinNameMe); @@ -163,6 +164,7 @@ MeOption *MapleCombCompiler::MakeMeOptions(const MplOptions &options, MemPool &o return meOption; } + Options *MapleCombCompiler::MakeMpl2MplOptions(const MplOptions &options, MemPool &optMp) { auto *mpl2mplOption = new Options(optMp); auto it = options.GetExeOptions().find(kBinNameMpl2mpl); @@ -212,6 +214,96 @@ Options *MapleCombCompiler::MakeMpl2MplOptions(const MplOptions &options, MemPoo case kNativeWrapper: mpl2mplOption->nativeWrapper = opt.Type(); break; + case kInlineWithProfile: + mpl2mplOption->inlineWithProfile = true; + break; + case kInlineWithoutProfile: + mpl2mplOption->inlineWithProfile = false; + break; + case kMpl2MplUseInline: + mpl2mplOption->useInline = true; + break; + case kMpl2MplNoInline: + mpl2mplOption->useInline = false; + break; + case kMpl2MplUseCrossModuleInline: + mpl2mplOption->useCrossModuleInline = true; + break; + case kMpl2MplNoCrossModuleInline: + mpl2mplOption->useCrossModuleInline = false; + break; + case kInlineSmallFunctionThreshold: + if (opt.Args().empty()) { + LogInfo::MapleLogger(kLlErr) << "expecting not empty for --inline-small-function-threshold\n"; + exit(1); + } else { + mpl2mplOption->inlineSmallFunctionThreshold = std::stoul(opt.Args()); + } + break; + case kInlineSyntheticFunctionThreshold: + if (opt.Args().empty()) { + LogInfo::MapleLogger(kLlErr) << "expecting not empty for --inline-synthetic-function-threshold\n"; + exit(1); + } else { + mpl2mplOption->inlineSyntheticFunctionThreshold = std::stoul(opt.Args()); + } + break; + case kInlineHotFunctionThreshold: + if (opt.Args().empty()) { + LogInfo::MapleLogger(kLlErr) << "expecting not empty for --inline-hot-function-threshold\n"; + exit(1); + } else { + mpl2mplOption->inlineHotFunctionThreshold = std::stoul(opt.Args()); + } + break; + case kInlineModuleGrowth: + if (opt.Args().empty()) { + LogInfo::MapleLogger(kLlErr) << "expecting not empty for --inline-module-growth\n"; + exit(1); + } else { + mpl2mplOption->inlineModuleGrowth = std::stoul(opt.Args()); + } + break; + case kInlineColdFunctionThreshold: + if (opt.Args().empty()) { + LogInfo::MapleLogger(kLlErr) << "expecting not empty for --inline-cold-function-threshold\n"; + exit(1); + } else { + mpl2mplOption->inlineColdFunctionThreshold = std::stoul(opt.Args()); + } + break; + case kProfileHotCount: + if (opt.Args().empty()) { + LogInfo::MapleLogger(kLlErr) << "expecting not empty for --profile-hot-count\n"; + exit(1); + } else { + mpl2mplOption->profileHotCount = std::stoul(opt.Args()); + } + break; + case kProfileColdCount: + if (opt.Args().empty()) { + LogInfo::MapleLogger(kLlErr) << "expecting not empty for --profile-cold-count\n"; + exit(1); + } else { + mpl2mplOption->profileColdCount = std::stoul(opt.Args()); + } + break; + case kProfileHotRate: + if (opt.Args().empty()) { + LogInfo::MapleLogger(kLlErr) << "expecting not empty for --profile-hot-rate\n"; + exit(1); + } else { + mpl2mplOption->profileHotRate = std::stoul(opt.Args()); + } + break; + case kProfileColdRate: + if (opt.Args().empty()) { + LogInfo::MapleLogger(kLlErr) << "expecting not empty for --profile-cold-rate\n"; + exit(1); + } else { + mpl2mplOption->profileColdRate = std::stoul(opt.Args()); + } + break; case kMpl2MplMapleLinker: mpl2mplOption->mapleLinker = true; mpl2mplOption->dumpMuidFile = true; diff --git a/src/maple_driver/src/mpl_options.cpp b/src/maple_driver/src/mpl_options.cpp index 122131782d5176bc833fabe717a5c3ca18271383..f1b0442b7614d5d013e7710e24fc2a21bb2cab9b 100644 --- a/src/maple_driver/src/mpl_options.cpp +++ b/src/maple_driver/src/mpl_options.cpp @@ -567,6 +567,186 @@ const mapleOption::Descriptor USAGES[] = { " --regnativefunc \tGenerate native stub function to support JNI registration and calling\n", "mpl2mpl", { { nullptr } } }, + { kInlineWithProfile, + 0, + nullptr, + "inline-with-profile", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyNone, + " --inline-with-profile \tEnable profile-based inlining\n", + "mpl2mpl", + { { nullptr } } }, + { kInlineWithoutProfile, + 0, + nullptr, + "inline-without-profile", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyNone, + " --inline-without-profile \tDisable profile-based inlining\n", + "mpl2mpl", + { { nullptr } } }, + { kMpl2MplUseInline, + 0, + nullptr, + "inline", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyNone, + " --inline \tEnable function inlining\n", + "mpl2mpl", + { { nullptr } } }, + { kMpl2MplNoInline, + 0, + nullptr, + "no-inline", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyNone, + " --no-inline \tDisable function inlining\n", + "mpl2mpl", + { { nullptr } } }, + { kMpl2MplUseCrossModuleInline, + 0, + nullptr, + "cross-module-inline", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyNone, + " --cross-module-inline \tEnable cross-module inlining\n", + "mpl2mpl", + { { nullptr } } }, + { kMpl2MplNoCrossModuleInline, + 0, + nullptr, + "no-cross-module-inline", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyNone, + " --no-cross-module-inline \tDisable cross-module inlining\n", + "mpl2mpl", + { { nullptr } } }, + { kInlineSmallFunctionThreshold, + 0, + nullptr, + "inline-small-function-threshold", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyRequired, + " --inline-small-function-threshold=15 \tThreshold for inlining small function\n", + "mpl2mpl", + { { nullptr } } }, + { kInlineSyntheticFunctionThreshold, + 0, + nullptr, + "inline-synthetic-function-threshold", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyRequired, + " --inline-synthetic-function-threshold=15 \tThreshold for inlining synthetic function\n", + "mpl2mpl", + { { nullptr } } }, + { kInlineHotFunctionThreshold, + 0, + nullptr, + "inline-hot-function-threshold", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyRequired, + " --inline-hot-function-threshold=30 \tThreshold for inlining hot function\n", + "mpl2mpl", + { { nullptr } } }, + { kInlineModuleGrowth, + 0, + nullptr, + "inline-module-growth", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyRequired, + " --inline-module-growth=100000 \tThreshold for maxmium code size growth rate (10%)\n", + "mpl2mpl", + { { nullptr } } }, + { kInlineColdFunctionThreshold, + 0, + nullptr, + "inline-cold-function-threshold", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyRequired, + " --inline-cold-function-threshold=3 \tThreshold for inlining hot function\n", + "mpl2mpl", + { { nullptr } } }, + { kProfileHotCount, + 0, + nullptr, + "profile-hot-count", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyRequired, + " --profile-hot-count=1000 \tA count is regarded as hot if it exceeds this number\n", + "mpl2mpl", + { { nullptr } } }, + { kProfileColdCount, + 0, + nullptr, + "profile-cold-count", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyRequired, + " --profile-cold-count=10 \tA count is regarded as cold if it is below this number\n", + "mpl2mpl", + { { nullptr } } }, + { kProfileHotRate, + 0, + nullptr, + "profile-hot-rate", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyRequired, + " --profile-hot-rate=500000 \tA count is regarded as hot if it is in the largest 50%\n", + "mpl2mpl", + { { nullptr } } }, + { kProfileColdRate, + 0, + nullptr, + "profile-cold-rate", + nullptr, + false, + nullptr, + mapleOption::BuildType::kBuildTypeAll, + mapleOption::ArgCheckPolicy::kArgCheckPolicyRequired, + " --profile-cold-rate=900000 \tA count is regarded as cold if it is in the smallest 10%\n", + "mpl2mpl", + { { nullptr } } }, { kNativeWrapper, kEnable, nullptr, @@ -813,7 +993,7 @@ int MplOptions::Parse(int argc, char **argv) { exeFolder = FileUtils::GetFileFolder(*argv); int ret = optionParser->Parse(argc, argv); if (ret != kErrorNoError) { - return kErrorInvalidParameter; + return ret; } // We should recognize O0, O2 and run options firstly to decide the real options ret = DecideRunType(); @@ -917,7 +1097,7 @@ ErrorCode MplOptions::HandleGeneralOptions() { // I do not care break; } - AddOption(opt); + ret = AddOption(opt); } return ret; } @@ -1036,17 +1216,25 @@ ErrorCode MplOptions::CheckFileExits() { return ret; } -void MplOptions::AddOption(const mapleOption::Option &option) { +ErrorCode MplOptions::AddOption(const mapleOption::Option &option) { if (!option.HasExtra()) { - return; + return kErrorNoError; } for (const auto &extra : option.GetExtras()) { auto iter = std::find(runningExes.begin(), runningExes.end(), extra.exeName); if (iter == runningExes.end()) { continue; } + // For outside compilers, such as jbc2mpl options[extra.exeName].push_back(option); + // For internel compilers, such as me, mpl2mpl + auto &exeOption = exeOptions[extra.exeName]; + bool ret = optionParser->SetOption(option.OptionKey(), option.Args(), extra.exeName, exeOption); + if (!ret) { + return kErrorInvalidParameter; + } } + return kErrorNoError; } bool MplOptions::Init(const std::string &inputFile) { diff --git a/src/maple_ir/include/global_tables.h b/src/maple_ir/include/global_tables.h index 097cbdacf281a2951af24f0eab9edcc4782ada8a..ab84ee8c92a7291455be542c177223cd0b8d2fe3 100644 --- a/src/maple_ir/include/global_tables.h +++ b/src/maple_ir/include/global_tables.h @@ -35,7 +35,7 @@ using FieldVector = std::vector; class TyIdxHash { public: std::size_t operator()(const TyIdx &tyIdx) const { - return std::hash{}(tyIdx.GetIdx()); + return std::hash{}(tyIdx); } }; @@ -43,7 +43,7 @@ class TyIdxHash { class GStrIdxHash { public: std::size_t operator()(const GStrIdx &gStrIdx) const { - return std::hash{}(gStrIdx.GetIdx()); + return std::hash{}(gStrIdx); } }; @@ -51,7 +51,7 @@ class GStrIdxHash { class UStrIdxHash { public: std::size_t operator()(const UStrIdx &uStrIdx) const { - return std::hash{}(uStrIdx.GetIdx()); + return std::hash{}(uStrIdx); } }; @@ -74,8 +74,8 @@ class TypeTable { return const_cast(const_cast(this)->GetTypeFromTyIdx(tyIdx)); } const MIRType *GetTypeFromTyIdx(TyIdx tyIdx) const { - CHECK_FATAL(tyIdx.GetIdx() < typeTable.size(), "array index out of range"); - return typeTable.at(tyIdx.GetIdx()); + CHECK_FATAL(tyIdx < typeTable.size(), "array index out of range"); + return typeTable.at(tyIdx); } MIRType *GetTypeFromTyIdx(uint32 index) const { @@ -84,13 +84,13 @@ class TypeTable { } PrimType GetPrimTypeFromTyIdx(TyIdx tyIdx) const { - CHECK_FATAL(tyIdx.GetIdx() < typeTable.size(), "array index out of range"); - return typeTable.at(tyIdx.GetIdx())->GetPrimType(); + CHECK_FATAL(tyIdx < typeTable.size(), "array index out of range"); + return typeTable.at(tyIdx)->GetPrimType(); } void SetTypeWithTyIdx(TyIdx tyIdx, MIRType *type) { - CHECK_FATAL(tyIdx.GetIdx() < typeTable.size(), "array index out of range"); - typeTable.at(tyIdx.GetIdx()) = type; + CHECK_FATAL(tyIdx < typeTable.size(), "array index out of range"); + typeTable.at(tyIdx) = type; } TyIdx GetOrCreateMIRType(MIRType *pType); @@ -372,7 +372,7 @@ class StringTable { U GetOrCreateStrIdxFromName(const T &str) { U strIdx = GetStrIdxFromName(str); if (strIdx == 0) { - strIdx.SetIdx(stringTable.size()); + strIdx.reset(stringTable.size()); T *newStr = new T(str); stringTable.push_back(newStr); stringTableMap[newStr] = strIdx; @@ -385,8 +385,8 @@ class StringTable { } const T &GetStringFromStrIdx(U strIdx) const { - ASSERT(strIdx.GetIdx() < stringTable.size(), "array index out of range"); - return *stringTable[strIdx.GetIdx()]; + ASSERT(strIdx < stringTable.size(), "array index out of range"); + return *stringTable[strIdx]; } private: diff --git a/src/maple_ir/include/mir_function.h b/src/maple_ir/include/mir_function.h index e4bdaa5f12cdae1f03b53b57ebf71031a58126da..cb03661ab5ed3b62126bdd95bb00bde0edb5b172 100644 --- a/src/maple_ir/include/mir_function.h +++ b/src/maple_ir/include/mir_function.h @@ -119,7 +119,7 @@ class MIRFunction { classTyIdx = tyIdx; } void SetClassTyIdx(uint32 idx) { - classTyIdx = idx; + classTyIdx.reset(idx); } size_t GetParamSize() const { @@ -360,7 +360,7 @@ class MIRFunction { // tell whether this function is a Java method bool IsJava() const { - return classTyIdx.GetIdx(); + return classTyIdx != 0; } const MIRType *GetNodeType(const BaseNode &node) const; diff --git a/src/maple_ir/include/mir_module.h b/src/maple_ir/include/mir_module.h index 4bfe914947c6e3a98e96adcbb4154c5b576b23b5..266a3b4c78f3daad5e350580d6d7c1c668929814 100644 --- a/src/maple_ir/include/mir_module.h +++ b/src/maple_ir/include/mir_module.h @@ -172,8 +172,8 @@ class MIRModule { typeDefOrder.push_back(gstrIdx); } - void AddClass(TyIdx t); - void RemoveClass(TyIdx t); + void AddClass(TyIdx tyIdx); + void RemoveClass(TyIdx tyIdx); void SetCurFunction(MIRFunction *f) { curFunction = f; diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index 0c550d80029e77a3993fd1125a346573a422d42c..a9d25a783ffa51a42d9c937fdfcdd6c567ef8862 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -440,7 +440,7 @@ class MIRType { nameStrIdx = strIdx; } void SetNameStrIdxItem(uint32 idx) { - nameStrIdx.SetIdx(idx); + nameStrIdx.reset(idx); } virtual size_t GetSize() const { @@ -546,7 +546,7 @@ class MIRPtrType : public MIRType { TyIdx GetPointedTyIdxWithFieldID(FieldID fieldID) const; size_t GetHashIndex() const override { constexpr uint8 idxShift = 4; - return ((pointedTyIdx.GetIdx() << idxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; + return ((static_cast(pointedTyIdx) << idxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; } bool PointsToConstString() const override; @@ -628,7 +628,7 @@ class MIRArrayType : public MIRType { size_t GetHashIndex() const override { constexpr uint8 idxShift = 2; - size_t hIdx = (eTyIdx.GetIdx() << idxShift) + (typeKind << kShiftNumOfTypeKind); + size_t hIdx = (static_cast(eTyIdx) << idxShift) + (typeKind << kShiftNumOfTypeKind); for (size_t i = 0; i < dim; ++i) { CHECK_FATAL(i < kMaxArrayDim, "array index out of range"); hIdx += (sizeArray[i] << i); @@ -677,7 +677,7 @@ class MIRFarrayType : public MIRType { size_t GetHashIndex() const override { constexpr uint8 idxShift = 5; - return ((elemTyIdx.GetIdx() << idxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; + return ((static_cast(elemTyIdx) << idxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; } std::string GetMplTypeName() const override; @@ -931,7 +931,8 @@ class MIRStructType : public MIRType { size_t GetSize() const override; size_t GetHashIndex() const override { - return ((nameStrIdx.GetIdx() << kShiftNumOfNameStrIdx) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; + return ((static_cast(nameStrIdx) << kShiftNumOfNameStrIdx) + (typeKind << kShiftNumOfTypeKind)) % + kTypeHashLength; } virtual void ClearContents() { @@ -1045,7 +1046,7 @@ class MIRJarrayType : public MIRFarrayType { size_t GetHashIndex() const override { constexpr uint8 idxShift = 5; - return ((GetElemTyIdx().GetIdx() << idxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; + return ((static_cast(GetElemTyIdx()) << idxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; } private: @@ -1184,7 +1185,8 @@ class MIRClassType : public MIRStructType { } size_t GetHashIndex() const override { - return ((nameStrIdx.GetIdx() << kShiftNumOfNameStrIdx) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; + return ((static_cast(nameStrIdx) << kShiftNumOfNameStrIdx) + (typeKind << kShiftNumOfTypeKind)) % + kTypeHashLength; } private: @@ -1297,7 +1299,8 @@ class MIRInterfaceType : public MIRStructType { } size_t GetHashIndex() const override { - return ((nameStrIdx.GetIdx() << kShiftNumOfNameStrIdx) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; + return ((static_cast(nameStrIdx) << kShiftNumOfNameStrIdx) + (typeKind << kShiftNumOfTypeKind)) % + kTypeHashLength; } private: @@ -1423,9 +1426,9 @@ class MIRFuncType : public MIRType { size_t GetHashIndex() const override { constexpr uint8 idxShift = 6; - size_t hIdx = (retTyIdx.GetIdx() << idxShift) + (typeKind << kShiftNumOfTypeKind); + size_t hIdx = (static_cast(retTyIdx) << idxShift) + (typeKind << kShiftNumOfTypeKind); size_t size = paramTypeList.size(); - hIdx += (size ? (paramTypeList[0].GetIdx() + size) : 0) << 4; + hIdx += (size ? (static_cast(paramTypeList[0]) + size) : 0) << 4; return hIdx % kTypeHashLength; } @@ -1458,7 +1461,8 @@ class MIRTypeByName : public MIRType { size_t GetHashIndex() const override { constexpr uint8 idxShift = 2; - return ((nameStrIdx.GetIdx() << idxShift) + nameIsLocal + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; + return ((static_cast(nameStrIdx) << idxShift) + nameIsLocal + (typeKind << kShiftNumOfTypeKind)) % + kTypeHashLength; } }; @@ -1487,7 +1491,7 @@ class MIRTypeParam : public MIRType { size_t GetHashIndex() const override { constexpr uint8 idxShift = 3; - return ((nameStrIdx.GetIdx() << idxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; + return ((static_cast(nameStrIdx) << idxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; } }; @@ -1524,7 +1528,7 @@ class MIRInstantVectorType : public MIRType { size_t GetHashIndex() const override { uint32 hIdx = typeKind << kShiftNumOfTypeKind; for (const TypePair &typePair : instantVec) { - hIdx += (typePair.first.GetIdx() + typePair.second.GetIdx()) << 3; + hIdx += static_cast(typePair.first + typePair.second) << 3; } return hIdx % kTypeHashLength; } @@ -1563,9 +1567,9 @@ class MIRGenericInstantType : public MIRInstantVectorType { size_t GetHashIndex() const override { constexpr uint8 idxShift = 2; - uint32 hIdx = (genericTyIdx.GetIdx() << idxShift) + (typeKind << kShiftNumOfTypeKind); + uint32 hIdx = (static_cast(genericTyIdx) << idxShift) + (typeKind << kShiftNumOfTypeKind); for (const TypePair &typePair : instantVec) { - hIdx += (typePair.first.GetIdx() + typePair.second.GetIdx()) << 3; + hIdx += static_cast(typePair.first + typePair.second) << 3; } return hIdx % kTypeHashLength; } diff --git a/src/maple_ir/include/option.h b/src/maple_ir/include/option.h index f5a6e4482e52d54ad893d31b43f79c3bfcb887ea..4ddf02c691bf3313daeafcc1dd313522d0978c7b 100644 --- a/src/maple_ir/include/option.h +++ b/src/maple_ir/include/option.h @@ -27,6 +27,11 @@ constexpr uint32 kConservativeDecouple = 1; constexpr uint32 kRadicalDecouple = 2; class Options { public: + enum Level { + kMpl2MplLevelZero = 0, + kMpl2MplLevelOne = 1, + kMpl2MplLevelTwo = 2 + }; explicit Options(MemPool &memPool) : optionAlloc(&memPool) {} bool ParseOptions(int argc, char **argv, std::string &fileName) const; @@ -52,6 +57,20 @@ class Options { static bool regNativeFunc; static bool regNativeDynamicOnly; static bool nativeWrapper; + static bool inlineWithProfile; + static bool useInline; + static bool useCrossModuleInline; + static uint32 inlineSmallFunctionThreshold; + static uint32 inlineSyntheticFunctionThreshold; + static uint32 inlineHotFunctionThreshold; + static uint32 inlineModuleGrowth; + static uint32 inlineColdFunctionThreshold; + static uint32 profileHotCount; + static uint32 profileColdCount; + static bool profileHotCountSeted; + static bool profileColdCountSeted; + static uint32 profileHotRate; + static uint32 profileColdRate; static std::string staticBindingList; static bool usePreg; static bool mapleLinker; diff --git a/src/maple_ir/include/prim_types.def b/src/maple_ir/include/prim_types.def index 27b90b04d590a5b0503292e0159e1a3a86a106c1..886b32f2378d2758f02e4221d9feb2d5bbd407bb 100644 --- a/src/maple_ir/include/prim_types.def +++ b/src/maple_ir/include/prim_types.def @@ -14,8 +14,7 @@ */ #ifdef LOAD_ALGO_PRIMARY_TYPE #undef LOAD_ALGO_PRIMARY_TYPE -/* NOTE: this ordering needs to be in sync with ptypesizetable[] in - maplevm/src/vmfunc.cpp */ +// NOTE: this ordering needs to be in sync with ptypesizetable[] in maplevm/src/vmfunc.cpp PRIMTYPE(void) PRIMTYPE(i8) PRIMTYPE(i16) diff --git a/src/maple_ir/include/types_def.h b/src/maple_ir/include/types_def.h index 9c3f4ff939a8dd453c3d414352896cb268fc7cdb..0d3a3089f0bf32a5a5c49b4445589289ba880438 100644 --- a/src/maple_ir/include/types_def.h +++ b/src/maple_ir/include/types_def.h @@ -20,6 +20,7 @@ // reinventing our own primitive types. #include #include +#include "mpl_number.h" namespace maple { // Let's keep the following definitions so that existing code will continue to work. @@ -105,61 +106,17 @@ using PregIdx16 = int16; using ExprIdx = int32; using FieldID = int32; -// T is integer, category is Idx kind. -// this template is for instantiating some kinds of Idx Class such as TyIdx, GStrIdx, UStrIdx, U16StrIdx -template -class IdxTemplate { - public: - IdxTemplate() = default; - explicit IdxTemplate(T i) : idx(i) {} - IdxTemplate(const IdxTemplate&) = default; - IdxTemplate &operator=(const IdxTemplate&) = default; - ~IdxTemplate() = default; - - void operator=(T id) { - idx = id; - } - bool operator==(const IdxTemplate &x) const { - return idx == x.idx; - } - - bool operator!=(const IdxTemplate &x) const { - return !(*this == x); - } - - bool operator==(T id) const { - return idx == id; - } - - bool operator!=(T id) const { - return !(*this == id); - } - - bool operator<(const IdxTemplate &x) const { - return idx < x.idx; - } - - T GetIdx() const { - return idx; - } +class TypeTag; +using TyIdx = utils::Index; // global type table index - void SetIdx(T i) { - idx = i; - } - - private: - T idx = 0; -}; +class GStrTag; +using GStrIdx = utils::Index; // global string table index -struct TyIdxCategory {}; -struct GStrIdxCategory {}; -struct UStrIdxCategory {}; -struct U16StrIdxCategory {}; +class UStrTag; +using UStrIdx = utils::Index; // user string table index (from the conststr opcode) -using TyIdx = IdxTemplate; // global type table index -using GStrIdx = IdxTemplate; // global string table index -using UStrIdx = IdxTemplate; // user string table index (from the conststr opcode) -using U16StrIdx = IdxTemplate; // user string table index (from the conststr opcode) +class U16StrTag; +using U16StrIdx = utils::Index; // user string table index (from the conststr opcode) const TyIdx kInitTyIdx = TyIdx(0); const TyIdx kNoneTyIdx = TyIdx(UINT32_MAX); diff --git a/src/maple_ir/src/bin_mpl_import.cpp b/src/maple_ir/src/bin_mpl_import.cpp index 2ea110c472f2e254989508f008dab7e41736b56c..ff1ea3dbb5516177a1a953b05144d19a2fc2a7ac 100644 --- a/src/maple_ir/src/bin_mpl_import.cpp +++ b/src/maple_ir/src/bin_mpl_import.cpp @@ -231,7 +231,7 @@ MIRPragmaElement *BinaryMplImport::ImportPragmaElement() { element->SetType((PragmaValueType)ReadNum()); if (element->GetType() == kValueString || element->GetType() == kValueType || element->GetType() == kValueField || element->GetType() == kValueMethod || element->GetType() == kValueEnum) { - element->SetI32Val(static_cast(ImportStr().GetIdx())); + element->SetI32Val(static_cast(ImportStr())); } else { element->SetU64Val(static_cast(ReadInt64())); } @@ -310,7 +310,7 @@ void BinaryMplImport::ImportMethodPair(MethodPair &memPool) { fn->SetFuncAttrs(attrFlag); } memPool.first.SetFullIdx(funcSt->GetStIdx().FullIdx()); - memPool.second.first.SetIdx(funcTyIdx.GetIdx()); + memPool.second.first.reset(funcTyIdx); memPool.second.second.SetAttrFlag(attrFlag); } @@ -386,7 +386,7 @@ void BinaryMplImport::ImportInfoOfStructType(MIRStructType &type) { bool isEmpty = type.GetInfo().empty(); for (int64 i = 0; i < size; ++i) { GStrIdx idx = ImportStr(); - int64 x = (type.GetInfoIsString()[i]) ? ImportStr().GetIdx() : ReadNum(); + int64 x = (type.GetInfoIsString()[i]) ? static_cast(ImportStr()) : ReadNum(); CHECK_FATAL(x >= 0, "ReadNum nagative, x: %d", x); CHECK_FATAL(x <= std::numeric_limits::max(), "ReadNum too large, x: %d", x); if (isEmpty) { @@ -422,7 +422,7 @@ void BinaryMplImport::SetClassTyidxOfMethods(MIRStructType &type) { void BinaryMplImport::ImportClassTypeData(MIRClassType &type) { TyIdx tempType = ImportType(); // Keep the parent_tyidx we first met. - if (type.GetParentTyIdx().GetIdx() == 0) { + if (type.GetParentTyIdx() == 0) { type.SetParentTyIdx(tempType); } ImportInterfacesOfClassType(type.GetInterfaceImplemented()); @@ -724,7 +724,7 @@ MIRType &BinaryMplImport::InsertInTypeTables(MIRType &type) { // New type, no previous definition or anonymous type TyIdx tyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&type); resultTypePtr = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); - if (tyIdx.GetIdx() + 1 == GlobalTables::GetTypeTable().GetTypeTable().size() && !resultTypePtr->IsNameIsLocal()) { + if (tyIdx + 1 == GlobalTables::GetTypeTable().GetTypeTable().size() && !resultTypePtr->IsNameIsLocal()) { GStrIdx stridx = resultTypePtr->GetNameStrIdx(); if (IsObject(*resultTypePtr)) { mod.GetTypeNameTab()->SetGStrIdxToTyIdx(stridx, tyIdx); diff --git a/src/maple_ir/src/global_tables.cpp b/src/maple_ir/src/global_tables.cpp index 9e5ba8b75544849369f2a799c3e451cae976cca8..645dca944947451d091e5ca54d849bdc052d4404 100644 --- a/src/maple_ir/src/global_tables.cpp +++ b/src/maple_ir/src/global_tables.cpp @@ -69,8 +69,8 @@ MIRType *TypeTable::voidPtrType = nullptr; MIRType *TypeTable::GetOrCreatePointerType(TyIdx pointedTyIdx, PrimType primType) { MIRPtrType type(pointedTyIdx, primType); TyIdx tyIdx = GetOrCreateMIRType(&type); - ASSERT(tyIdx.GetIdx() < typeTable.size(), "index out of range in TypeTable::GetOrCreatePointerType"); - return typeTable.at(tyIdx.GetIdx()); + ASSERT(tyIdx < typeTable.size(), "index out of range in TypeTable::GetOrCreatePointerType"); + return typeTable.at(tyIdx); } MIRType *TypeTable::GetOrCreatePointerType(const MIRType &pointTo, PrimType primType) { @@ -98,7 +98,7 @@ MIRArrayType *TypeTable::GetOrCreateArrayType(const MIRType &elem, uint8 dim, co } MIRArrayType arrayType(elem.GetTypeIndex(), sizeVector); TyIdx tyIdx = GetOrCreateMIRType(&arrayType); - return static_cast(typeTable[tyIdx.GetIdx()]); + return static_cast(typeTable[tyIdx]); } // For one dimension array @@ -110,16 +110,16 @@ MIRType *TypeTable::GetOrCreateFarrayType(const MIRType &elem) { MIRFarrayType type; type.SetElemtTyIdx(elem.GetTypeIndex()); TyIdx tyIdx = GetOrCreateMIRType(&type); - ASSERT(tyIdx.GetIdx() < typeTable.size(), "index out of range in TypeTable::GetOrCreateFarrayType"); - return typeTable.at(tyIdx.GetIdx()); + ASSERT(tyIdx < typeTable.size(), "index out of range in TypeTable::GetOrCreateFarrayType"); + return typeTable.at(tyIdx); } MIRType *TypeTable::GetOrCreateJarrayType(const MIRType &elem) { MIRJarrayType type; type.SetElemtTyIdx(elem.GetTypeIndex()); TyIdx tyIdx = GetOrCreateMIRType(&type); - ASSERT(tyIdx.GetIdx() < typeTable.size(), "index out of range in TypeTable::GetOrCreateJarrayType"); - return typeTable.at(tyIdx.GetIdx()); + ASSERT(tyIdx < typeTable.size(), "index out of range in TypeTable::GetOrCreateJarrayType"); + return typeTable.at(tyIdx); } MIRType *TypeTable::GetOrCreateFunctionType(MIRModule &module, TyIdx retTyIdx, const std::vector &vecType, @@ -130,8 +130,8 @@ MIRType *TypeTable::GetOrCreateFunctionType(MIRModule &module, TyIdx retTyIdx, c return funcType; } TyIdx tyIdx = GetOrCreateMIRType(funcType); - ASSERT(tyIdx.GetIdx() < typeTable.size(), "index out of range in TypeTable::GetOrCreateFunctionType"); - return typeTable.at(tyIdx.GetIdx()); + ASSERT(tyIdx < typeTable.size(), "index out of range in TypeTable::GetOrCreateFunctionType"); + return typeTable.at(tyIdx); } MIRType *TypeTable::GetOrCreateStructOrUnion(const std::string &name, const FieldVector &fields, @@ -144,8 +144,8 @@ MIRType *TypeTable::GetOrCreateStructOrUnion(const std::string &name, const Fiel // Global? module.GetTypeNameTab()->SetGStrIdxToTyIdx(strIdx, tyIdx); module.PushbackTypeDefOrder(strIdx); - ASSERT(tyIdx.GetIdx() < typeTable.size(), "index out of range in TypeTable::GetOrCreateStructOrUnion"); - return typeTable.at(tyIdx.GetIdx()); + ASSERT(tyIdx < typeTable.size(), "index out of range in TypeTable::GetOrCreateStructOrUnion"); + return typeTable.at(tyIdx); } void TypeTable::PushIntoFieldVector(FieldVector &fields, const std::string &name, MIRType &type) { @@ -156,7 +156,7 @@ void TypeTable::PushIntoFieldVector(FieldVector &fields, const std::string &name MIRType *TypeTable::GetOrCreateClassOrInterface(const std::string &name, MIRModule &module, bool forClass) { GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); TyIdx tyIdx = module.GetTypeNameTab()->GetTyIdxFromGStrIdx(strIdx); - if (!tyIdx.GetIdx()) { + if (!tyIdx) { if (forClass) { MIRClassType type(kTypeClassIncomplete, strIdx); // for class type tyIdx = GetOrCreateMIRType(&type); @@ -166,12 +166,12 @@ MIRType *TypeTable::GetOrCreateClassOrInterface(const std::string &name, MIRModu } module.PushbackTypeDefOrder(strIdx); module.GetTypeNameTab()->SetGStrIdxToTyIdx(strIdx, tyIdx); - if (typeTable[tyIdx.GetIdx()]->GetNameStrIdx() == 0) { - typeTable[tyIdx.GetIdx()]->SetNameStrIdx(strIdx); + if (typeTable[tyIdx]->GetNameStrIdx() == 0) { + typeTable[tyIdx]->SetNameStrIdx(strIdx); } } - ASSERT(tyIdx.GetIdx() < typeTable.size(), "index out of range in TypeTable::GetOrCreateClassOrInterface"); - return typeTable.at(tyIdx.GetIdx()); + ASSERT(tyIdx < typeTable.size(), "index out of range in TypeTable::GetOrCreateClassOrInterface"); + return typeTable.at(tyIdx); } void TypeTable::AddFieldToStructType(MIRStructType &structType, const std::string &fieldName, MIRType &fieldType) { diff --git a/src/maple_ir/src/mir_builder.cpp b/src/maple_ir/src/mir_builder.cpp index e47cc3155daeaf06745cf90dbdd31b017f4851e5..8836e3e1f7ed66ac83e84d26cfee4f7db65e7c49 100644 --- a/src/maple_ir/src/mir_builder.cpp +++ b/src/maple_ir/src/mir_builder.cpp @@ -122,11 +122,11 @@ bool MIRBuilder::TraverseToNamedFieldWithTypeAndMatchStyle(MIRStructType &struct ++fieldID; if (matchStyle == (kFoundInChild | kParentFirst | kUpdateFieldID)) { matchStyle = kParentFirst; - uint32 idxBackup = nameIdx.GetIdx(); - nameIdx.SetIdx(0); + uint32 idxBackup = nameIdx; + nameIdx.reset(); // do not match but traverse to update fieldID, traverse parent first TraverseToNamedFieldWithTypeAndMatchStyle(*parentType, nameIdx, typeIdx, fieldID, matchStyle); - nameIdx.SetIdx(idxBackup); + nameIdx.reset(idxBackup); } else if (TraverseToNamedFieldWithTypeAndMatchStyle(*parentType, nameIdx, typeIdx, fieldID, matchStyle)) { return true; } @@ -580,7 +580,7 @@ AddroffuncNode *MIRBuilder::CreateExprAddroffunc(PUIdx puIdx, MemPool *memPool) AddrofNode *MIRBuilder::CreateExprDread(const MIRType &type, FieldID fieldID, const MIRSymbol &symbol) { auto *node = GetCurrentFuncCodeMp()->New(OP_dread, kPtyInvalid, symbol.GetStIdx(), fieldID); - CHECK(type.GetTypeIndex().GetIdx() < GlobalTables::GetTypeTable().GetTypeTable().size(), + CHECK(type.GetTypeIndex() < GlobalTables::GetTypeTable().GetTypeTable().size(), "index out of range in MIRBuilder::CreateExprDread"); node->SetPrimType(GlobalTables::GetTypeTable().GetPrimTypeFromTyIdx(type.GetTypeIndex())); return node; @@ -615,7 +615,7 @@ AddrofNode *MIRBuilder::CreateExprDread(PregIdx pregID, PrimType pty) { IreadNode *MIRBuilder::CreateExprIread(const MIRType &returnType, const MIRType &ptrType, FieldID fieldID, BaseNode *addr) { TyIdx returnTypeIdx = returnType.GetTypeIndex(); - ASSERT(returnTypeIdx.GetIdx() < GlobalTables::GetTypeTable().GetTypeTable().size(), + ASSERT(returnTypeIdx < GlobalTables::GetTypeTable().GetTypeTable().size(), "index out of range in MIRBuilder::CreateExprIread"); ASSERT(fieldID != 0 || ptrType.GetPrimType() != PTY_agg, "Error: Fieldid should not be 0 when trying to iread a field from type "); diff --git a/src/maple_ir/src/mir_function.cpp b/src/maple_ir/src/mir_function.cpp index 878b4446b8d74ec70c777c13e0a5b1e6f0a81d80..dc95aac7f4534176ae302b7ae64eb39fc8f1194b 100644 --- a/src/maple_ir/src/mir_function.cpp +++ b/src/maple_ir/src/mir_function.cpp @@ -420,8 +420,8 @@ uint32 MIRFunction::GetInfo(const std::string &string) const { } void MIRFunction::OverrideBaseClassFuncNames(GStrIdx strIdx) { - baseClassStrIdx.SetIdx(0); - baseFuncStrIdx.SetIdx(0); + baseClassStrIdx.reset(); + baseFuncStrIdx.reset(); SetBaseClassFuncNames(strIdx); } diff --git a/src/maple_ir/src/mir_module.cpp b/src/maple_ir/src/mir_module.cpp index a7755163e6589094c273170a9ad7f93e624159af..f2325ed0ae08c9b460788a8ae598ff48d161f6c9 100644 --- a/src/maple_ir/src/mir_module.cpp +++ b/src/maple_ir/src/mir_module.cpp @@ -462,12 +462,12 @@ std::string MIRModule::GetFileNameAsPostfix() const { return fileNameStr; } -void MIRModule::AddClass(TyIdx t) { - classList.insert(t.GetIdx()); +void MIRModule::AddClass(TyIdx tyIdx) { + classList.insert(tyIdx); } -void MIRModule::RemoveClass(TyIdx t) { - classList.erase(t.GetIdx()); +void MIRModule::RemoveClass(TyIdx tyIdx) { + classList.erase(tyIdx); } #endif // MIR_FEATURE_FULL diff --git a/src/maple_ir/src/mir_nodes.cpp b/src/maple_ir/src/mir_nodes.cpp index fd058a2eba591bd3be079888e77624d14539ffb4..96c2515876bcd1b12e1f0be692e2e61f7d1d7c91 100644 --- a/src/maple_ir/src/mir_nodes.cpp +++ b/src/maple_ir/src/mir_nodes.cpp @@ -475,13 +475,13 @@ void ConstvalNode::Dump(const MIRModule &mod, int32 indent) const { void ConststrNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); - const std::string kStr = GlobalTables::GetUStrTable().GetStringFromStrIdx(UStrIdx(strIdx.GetIdx())); + const std::string kStr = GlobalTables::GetUStrTable().GetStringFromStrIdx(UStrIdx(strIdx)); PrintString(kStr); } void Conststr16Node::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); - const std::u16string kStr16 = GlobalTables::GetU16StrTable().GetStringFromStrIdx(U16StrIdx(strIdx.GetIdx())); + const std::u16string kStr16 = GlobalTables::GetU16StrTable().GetStringFromStrIdx(U16StrIdx(strIdx)); // UTF-16 string are dumped as UTF-8 string in mpl to keep the printable chars in ascii form std::string str; NameMangler::UTF16ToUTF8(str, kStr16); @@ -1090,7 +1090,7 @@ void BlockNode::Dump(const MIRModule &mod, int32 indent, const MIRSymbolTable *t LogInfo::MapleLogger() << "ALIAS %" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.first) << " %" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.second.memPoolStrIdx) << " "; GlobalTables::GetTypeTable().GetTypeFromTyIdx(it.second.tyIdx)->Dump(0); - if (it.second.sigStrIdx.GetIdx()) { + if (it.second.sigStrIdx) { LogInfo::MapleLogger() << " \"" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.second.sigStrIdx) << "\""; } LogInfo::MapleLogger() << '\n'; @@ -1319,7 +1319,7 @@ inline MIRTypeKind GetTypeKind(TyIdx tyIdx) { inline MIRType *GetPointedMIRType(TyIdx tyIdx) { MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); - CHECK_FATAL(type->GetKind() == kTypePointer, "TyIdx: %d is not pointer type", tyIdx.GetIdx()); + CHECK_FATAL(type->GetKind() == kTypePointer, "TyIdx: %d is not pointer type", static_cast(tyIdx)); auto *ptrType = static_cast(type); return ptrType->GetPointedType(); } @@ -1340,7 +1340,7 @@ bool GetFieldType(MIRSrcLang srcLang, const MIRStructType *structType, FieldID t const auto *classType = static_cast(structType); std::stack inheritChain; TyIdx parentTyIdx = classType->GetParentTyIdx(); - while (parentTyIdx.GetIdx() > 0) { + while (parentTyIdx > 0) { auto *parentType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); inheritChain.push(parentType); parentTyIdx = static_cast(parentType)->GetParentTyIdx(); diff --git a/src/maple_ir/src/mir_parser.cpp b/src/maple_ir/src/mir_parser.cpp index 622a8eb9e90c34db5f484adb77c07f842e58e365..b3b8c4aaf95b59f04d76a72c063a204960d3e7ea 100644 --- a/src/maple_ir/src/mir_parser.cpp +++ b/src/maple_ir/src/mir_parser.cpp @@ -1490,7 +1490,7 @@ bool MIRParser::ParseStmtBlockForReg() { Error("ParseDeclareVar failed when parsing the type"); return false; } - ASSERT(tyidx.GetIdx() > 0, "parse declare var failed "); + ASSERT(tyidx > 0, "parse declare var failed "); MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx); preg->SetMIRType(mirType); if (lexer.GetTokenKind() == kTkIntconst) { diff --git a/src/maple_ir/src/mir_pragma.cpp b/src/maple_ir/src/mir_pragma.cpp index ef321678b026f8bbbe1046e93215acdba2da1387..d96f475ee9f9d3a0e765c603dbba01d52f61a0b3 100644 --- a/src/maple_ir/src/mir_pragma.cpp +++ b/src/maple_ir/src/mir_pragma.cpp @@ -173,7 +173,7 @@ MIRPragmaElement *MIRPragma::GetPragmaElemFromSignature(const std::string &signa MIRPragmaElement *etmp = mod->GetMemPool()->New(*mod); etmp->SetType(kValueType); std::string typeStr = signature.substr(start, end - start); - etmp->SetU64Val(static_cast(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(typeStr).GetIdx())); + etmp->SetU64Val(static_cast(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(typeStr))); elemStack.top()->SubElemVecPushBack(etmp); break; } @@ -181,7 +181,7 @@ MIRPragmaElement *MIRPragma::GetPragmaElemFromSignature(const std::string &signa MIRPragmaElement *etmp = mod->GetMemPool()->New(*mod); etmp->SetType(kValueType); std::string typeStr = signature.substr(start, end - start) + ";"; - etmp->SetU64Val(static_cast(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(typeStr).GetIdx())); + etmp->SetU64Val(static_cast(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(typeStr))); elemStack.top()->SubElemVecPushBack(etmp); break; } @@ -239,25 +239,25 @@ void MIRPragmaElement::Dump(int indent) const { LogInfo::MapleLogger() << str << " " << std::hex << "0x" << val.u << std::dec; break; case kValueString: - gStrIdx.SetIdx(val.u); + gStrIdx.reset(val.u); LogInfo::MapleLogger() << str << " \"" << GlobalTables::GetStrTable().GetStringFromStrIdx(gStrIdx) << "\""; break; case kValueType: - gStrIdx.SetIdx(val.u); + gStrIdx.reset(val.u); LogInfo::MapleLogger() << str << " <$" << GlobalTables::GetStrTable().GetStringFromStrIdx(gStrIdx) << ">"; break; case kValueField: - gStrIdx.SetIdx(val.u); + gStrIdx.reset(val.u); LogInfo::MapleLogger() << str << " @" << GlobalTables::GetStrTable().GetStringFromStrIdx(gStrIdx); break; case kValueMethod: - gStrIdx.SetIdx(val.u); + gStrIdx.reset(val.u); LogInfo::MapleLogger() << str << " &" << GlobalTables::GetStrTable().GetStringFromStrIdx(gStrIdx); break; case kValueEnum: - gStrIdx.SetIdx(val.u); + gStrIdx.reset(val.u); LogInfo::MapleLogger() << str << " " << GlobalTables::GetStrTable().GetStringFromStrIdx(gStrIdx); break; case kValueArray: { @@ -353,7 +353,7 @@ void MIRPragma::Dump(int indent) const { } LogInfo::MapleLogger() << GlobalTables::GetStrTable().GetStringFromStrIdx(strIdx) << " "; GStrIdx gStrIdx = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->GetNameStrIdx(); - if (tyIdxEx.GetIdx() != 0) { + if (tyIdxEx != 0) { MIRType *typeEx = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdxEx); LogInfo::MapleLogger() << "\"" << typeEx->GetMplTypeName() << "\" "; } diff --git a/src/maple_ir/src/mir_symbol.cpp b/src/maple_ir/src/mir_symbol.cpp index f4b7aeb2c72d76b536c45485999742ec50062795..6e2e05286ca0a98bbb1863008a4feafdf855e5bf 100644 --- a/src/maple_ir/src/mir_symbol.cpp +++ b/src/maple_ir/src/mir_symbol.cpp @@ -288,7 +288,7 @@ void MIRSymbol::Dump(bool isLocal, int32 indent, bool suppressInit) const { (GetStorageClass() == kScExtern && sKind == kStFunc)) { return; } - if (GetTyIdx().GetIdx() >= GlobalTables::GetTypeTable().GetTypeTable().size()) { + if (GetTyIdx() >= GlobalTables::GetTypeTable().GetTypeTable().size()) { FATAL(kLncFatal, "valid maple_ir with illegal type"); } if (GetStorageClass() == kScText && GetFunction() != nullptr) { diff --git a/src/maple_ir/src/mir_type.cpp b/src/maple_ir/src/mir_type.cpp index 89f393888201d7df9087d69ab51b16c52587f0ee..c05e070f03fa1d4a5ff8dd3b27c5f39e7af58810 100644 --- a/src/maple_ir/src/mir_type.cpp +++ b/src/maple_ir/src/mir_type.cpp @@ -310,7 +310,7 @@ const std::string &MIRType::GetName() const { bool MIRType::ValidateClassOrInterface(const std::string &className, bool noWarning) const { if (primType == maple::PTY_agg && (typeKind == maple::kTypeClass || typeKind == maple::kTypeInterface) && - nameStrIdx.GetIdx()) { + nameStrIdx != 0) { return true; } if (!noWarning) { diff --git a/src/maple_ir/src/option.cpp b/src/maple_ir/src/option.cpp index 3b7c8d23bf88746d47fadbbb558b303e24d99d2e..1d1db7188c2ff7fae665a27ca53c31213b0c5d8d 100644 --- a/src/maple_ir/src/option.cpp +++ b/src/maple_ir/src/option.cpp @@ -31,7 +31,21 @@ std::string Options::skipFrom; std::string Options::skipAfter; bool Options::quiet = false; bool Options::regNativeFunc = false; -bool Options::nativeWrapper = true; // enabled by default +bool Options::nativeWrapper = true; // Enabled by default +bool Options::inlineWithProfile = false; +bool Options::useInline = true; // Enabled by default +bool Options::useCrossModuleInline = true; // Enabled by default +uint32 Options::inlineSmallFunctionThreshold = 15; +uint32 Options::inlineSyntheticFunctionThreshold = 15; +uint32 Options::inlineHotFunctionThreshold = 30; +uint32 Options::inlineModuleGrowth = 10; +uint32 Options::inlineColdFunctionThreshold = 3; +uint32 Options::profileHotCount = 1000; +uint32 Options::profileColdCount = 10; +bool Options::profileHotCountSeted = false; +bool Options::profileColdCountSeted = false; +uint32 Options::profileHotRate = 500000; +uint32 Options::profileColdRate = 900000; bool Options::regNativeDynamicOnly = false; std::string Options::staticBindingList; bool Options::usePreg = false; @@ -51,6 +65,21 @@ enum OptionIndex { kDumpFunc, kQuiet, kStubJniFunc, + kInlineWithProfile, + kInlineWithoutProfile, + kUseInline, + kNoInline, + kUseCrossModuleInline, + kNoCrossModuleInline, + kInlineSmallFunctionThreshold, + kInlineSyntheticFunctionThreshold, + kInlineHotFunctionThreshold, + kInlineModuleGrowth, + kInlineColdFunctionThreshold, + kProfileHotCount, + kProfileColdCount, + kProfileHotRate, + kProfileColdRate, kRegNativeDynamicOnly, kRegNativeStaticBindingList, kNativeWrapper, @@ -83,6 +112,37 @@ const Descriptor kUsage[] = { " --quiet Disable brief trace messages with phase/function names" }, { kStubJniFunc, 0, "", "regnativefunc", kBuildTypeAll, kArgCheckPolicyNone, " --regnativefunc Generate native stub function to support JNI registration and calling" }, + { kInlineWithProfile, 0, "", "inline-with-profile", kBuildTypeAll, kArgCheckPolicyNone, + " --inline-with-profile Enable profile-based inlining" }, + { kInlineWithoutProfile, 0, "", "inline-without-profile", kBuildTypeAll, kArgCheckPolicyNone, + " --inline-without-profile Disable profile-based inlining" }, + { kUseInline, 0, "", "inline", kBuildTypeAll, kArgCheckPolicyNone, + " --inline Enable function inlining" }, + { kNoInline, 0, "", "no-inline", kBuildTypeAll, kArgCheckPolicyNone, + " --no-inline Disable function inlining" }, + { kUseCrossModuleInline, 0, "", "cross-module-inline", kBuildTypeAll, kArgCheckPolicyNone, + " --cross-module-inline Enable cross-module inlining" }, + { kNoCrossModuleInline, 0, "", "no-cross-module-inline", kBuildTypeAll, kArgCheckPolicyNone, + " --no-cross-module-inline Disable cross-module inlining" }, + { kInlineSmallFunctionThreshold, 0, "", "inline-small-function-threshold", kBuildTypeAll, kArgCheckPolicyRequired, + " --inline-small-function-threshold=15 Threshold for inlining small function" }, + { kInlineSyntheticFunctionThreshold, 0, "", "inline-synthetic-function-threshold", + kBuildTypeAll, kArgCheckPolicyRequired, + " --inline-synthetic-function-threshold=15 Threshold for inlining synthetic function" }, + { kInlineHotFunctionThreshold, 0, "", "inline-hot-function-threshold", kBuildTypeAll, kArgCheckPolicyRequired, + " --inline-hot-function-threshold=30 Threshold for inlining hot function" }, + { kInlineModuleGrowth, 0, "", "inline-module-growth", kBuildTypeAll, kArgCheckPolicyRequired, + " --inline-module-growth=100000 Threshold for maxmium code size growth rate. (10%)" }, + { kInlineColdFunctionThreshold, 0, "", "inline-cold-function-threshold", kBuildTypeAll, kArgCheckPolicyRequired, + " --inline-cold-function-threshold=3 Threshold for inlining cold function" }, + { kProfileHotCount, 0, "", "profile-hot-count", kBuildTypeAll, kArgCheckPolicyRequired, + " --profile-hot-count=1000 A count is regarded as hot if it exceeds this number" }, + { kProfileColdCount, 0, "", "profile-cold-count", kBuildTypeAll, kArgCheckPolicyRequired, + " --profile-cold-count=10 A count is regarded as cold if it is below this number" }, + { kProfileHotRate, 0, "", "profile-hot-rate", kBuildTypeAll, kArgCheckPolicyRequired, + " --profile-hot-rate=500000 A count is regarded as hot if it is in the largest 50%" }, + { kProfileColdRate, 0, "", "profile-cold-rate", kBuildTypeAll, kArgCheckPolicyRequired, + " --profile-cold-rate=900000 A count is regarded as cold if it is in the smallest 10%" }, { kNativeWrapper, 1, "", "nativewrapper", kBuildTypeAll, kArgCheckPolicyNone, " --nativewrapper Generate native wrappers [default]" }, { kNativeWrapper, 0, "", "no-nativewrapper", kBuildTypeAll, kArgCheckPolicyNone, @@ -154,6 +214,53 @@ bool Options::ParseOptions(int argc, char **argv, std::string &fileName) const { case kStubJniFunc: Options::regNativeFunc = true; break; + case kInlineWithProfile: + Options::inlineWithProfile = true; + break; + case kInlineWithoutProfile: + Options::inlineWithProfile = false; + break; + case kUseInline: + Options::useInline = true; + break; + case kNoInline: + Options::useInline = false; + break; + case kUseCrossModuleInline: + Options::useCrossModuleInline = true; + break; + case kNoCrossModuleInline: + Options::useCrossModuleInline = false; + break; + case kInlineSmallFunctionThreshold: + Options::inlineSmallFunctionThreshold = std::stoul(opt.Args()); + break; + case kInlineSyntheticFunctionThreshold: + Options::inlineSyntheticFunctionThreshold = std::stoul(opt.Args()); + break; + case kInlineHotFunctionThreshold: + Options::inlineHotFunctionThreshold = std::stoul(opt.Args()); + break; + case kInlineModuleGrowth: + Options::inlineModuleGrowth = std::stoul(opt.Args()); + break; + case kInlineColdFunctionThreshold: + Options::inlineColdFunctionThreshold = std::stoul(opt.Args()); + break; + case kProfileHotCount: + Options::profileHotCount = std::stoul(opt.Args()); + Options::profileHotCountSeted = true; + break; + case kProfileColdCount: + Options::profileColdCount = std::stoul(opt.Args()); + Options::profileColdCountSeted = true; + break; + case kProfileHotRate: + Options::profileHotRate = std::stoul(opt.Args()); + break; + case kProfileColdRate: + Options::profileColdRate = std::stoul(opt.Args()); + break; case kNativeWrapper: Options::nativeWrapper = opt.Type(); break; diff --git a/src/maple_ir/src/parser.cpp b/src/maple_ir/src/parser.cpp index 1ec6b4f50bfec911cc4533dac6413d368e72d495..bf1e67d599af0e10ee39eca5737abeb1ef77d0d2 100644 --- a/src/maple_ir/src/parser.cpp +++ b/src/maple_ir/src/parser.cpp @@ -429,11 +429,11 @@ bool MIRParser::ParsePragmaElement(MIRPragmaElement &elem) { case TK_var: case TK_func: case TK_enum: - elem.SetI32Val(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()).GetIdx()); + elem.SetI32Val(static_cast(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()))); break; case TK_type: lexer.NextToken(); - elem.SetI32Val(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()).GetIdx()); + elem.SetI32Val(static_cast(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()))); lexer.NextToken(); break; case TK_array: @@ -672,9 +672,8 @@ bool MIRParser::ParseFields(MIRStructType &type) { } else if ((tk == kTkIntconst || tk == kTkString) && !isParentField && (tyKind == kTypeClass || tyKind == kTypeClassIncomplete || tyKind == kTypeInterface || tyKind == kTypeInterfaceIncomplete)) { - uint32 infoVal = - (tk == kTkIntconst) ? lexer.GetTheIntVal() - : GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()).GetIdx(); + uint32 infoVal = (tk == kTkIntconst) ? static_cast(lexer.GetTheIntVal()) : + static_cast(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName())); type.PushbackMIRInfo(MIRInfoPair(strIdx, infoVal)); type.PushbackIsString(tk != kTkIntconst); notaType = true; @@ -1101,7 +1100,7 @@ bool MIRParser::ParseDefinedTypename(TyIdx &definedTyIdx, MIRTypeKind kind) { // check if type already exist definedTyIdx = mod.GetTypeNameTab()->GetTyIdxFromGStrIdx(strIdx); TyIdx prevTypeIdx(0); - if (definedTyIdx.GetIdx()) { + if (definedTyIdx) { MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(definedTyIdx); if (type->IsStructType()) { auto *stype = static_cast(type); @@ -1625,7 +1624,7 @@ bool MIRParser::ParseDeclareReg(MIRSymbol &symbol, MIRFunction &func) { Error("ParseDeclarePreg failed while parsing the type"); return false; } - ASSERT(tyIdx.GetIdx() > 0, "parse declare preg failed"); + ASSERT(tyIdx > 0, "parse declare preg failed"); if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->GetKind() == kTypeByName) { Error("type in var declaration cannot be forward-referenced at "); return false; @@ -1687,7 +1686,7 @@ bool MIRParser::ParseDeclareVar(MIRSymbol &symbol) { Error("ParseDeclareVar failed when parsing the type"); return false; } - ASSERT(tyIdx.GetIdx() > 0, "parse declare var failed "); + ASSERT(tyIdx > 0, "parse declare var failed "); if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->GetKind() == kTypeByName) { Error("type in var declaration cannot be forward-referenced at "); return false; @@ -2131,7 +2130,7 @@ bool MIRParser::ParseFuncInfo() { func->PushbackIsString(false); } else if (tokenKind == kTkString) { GStrIdx literalStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); - func->PushbackMIRInfo(MIRInfoPair(strIdx, literalStrIdx.GetIdx())); + func->PushbackMIRInfo(MIRInfoPair(strIdx, literalStrIdx)); func->PushbackIsString(true); } else { Error("illegal value after funcinfo field name at "); @@ -2536,7 +2535,7 @@ bool MIRParser::ParseMIRForFileInfo() { mod.PushFileInfoIsString(false); } else if (tk == kTkString) { GStrIdx litStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); - mod.PushFileInfoPair(MIRInfoPair(strIdx, litStrIdx.GetIdx())); + mod.PushFileInfoPair(MIRInfoPair(strIdx, litStrIdx)); mod.PushFileInfoIsString(true); } else { Error("illegal value after fileInfo field name at "); diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h index 8af23142fbd11f093d71bf8b53bf68d30009020a..573cb2142f75e1647e2b76e7a9b7791825be3ba4 100644 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -638,7 +638,7 @@ class ConststrMeExpr : public MeExpr { uint32 GetHashIndex() const override { constexpr uint32 kConststrHashShift = 6; - return strIdx.GetIdx() << kConststrHashShift; + return static_cast(strIdx) << kConststrHashShift; } private: @@ -660,7 +660,7 @@ class Conststr16MeExpr : public MeExpr { uint32 GetHashIndex() const override { constexpr uint32 kConststr16HashShift = 6; - return strIdx.GetIdx() << kConststr16HashShift; + return static_cast(strIdx) << kConststr16HashShift; } private: @@ -682,7 +682,7 @@ class SizeoftypeMeExpr : public MeExpr { uint32 GetHashIndex() const override { constexpr uint32 sizeoftypeHashShift = 5; - return tyIdx.GetIdx() << sizeoftypeHashShift; + return static_cast(tyIdx) << sizeoftypeHashShift; } private: @@ -714,7 +714,8 @@ class FieldsDistMeExpr : public MeExpr { uint32 GetHashIndex() const override { constexpr uint32 kFieldsDistHashShift = 5; constexpr uint32 kTyIdxShiftFactor = 10; - return (tyIdx.GetIdx() << kTyIdxShiftFactor) + (static_cast(fieldID1) << kFieldsDistHashShift) + fieldID2; + return (static_cast(tyIdx) << kTyIdxShiftFactor) + (static_cast(fieldID1) << kFieldsDistHashShift) + + fieldID2; } private: @@ -794,7 +795,7 @@ class GcmallocMeExpr : public MeExpr { uint32 GetHashIndex() const { constexpr uint32 kGcmallocHashShift = 4; - return tyIdx.GetIdx() << kGcmallocHashShift; + return static_cast(tyIdx) << kGcmallocHashShift; } private: diff --git a/src/maple_me/src/me_ir.cpp b/src/maple_me/src/me_ir.cpp index ea045affebe3ccda077a187210a3afead3b75d93..a6fc90530650981594e18191d27156a785b48bd4 100644 --- a/src/maple_me/src/me_ir.cpp +++ b/src/maple_me/src/me_ir.cpp @@ -725,20 +725,20 @@ void ConstMeExpr::Dump(IRMap *irMap, int32 indent) const { void ConststrMeExpr::Dump(IRMap *irMap, int32 indent) const { LogInfo::MapleLogger() << "CONSTSTR"; LogInfo::MapleLogger() << " "; - LogInfo::MapleLogger() << strIdx.GetIdx(); + LogInfo::MapleLogger() << strIdx; LogInfo::MapleLogger() << " mx" << GetExprID(); } void Conststr16MeExpr::Dump(IRMap *irMap, int32 indent) const { LogInfo::MapleLogger() << "CONSTSTR16"; LogInfo::MapleLogger() << " "; - LogInfo::MapleLogger() << strIdx.GetIdx(); + LogInfo::MapleLogger() << strIdx; LogInfo::MapleLogger() << " mx" << GetExprID(); } void SizeoftypeMeExpr::Dump(IRMap *irMap, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOp()).name << " " << GetPrimTypeName(GetPrimType()); - LogInfo::MapleLogger() << " TYIDX:" << tyIdx.GetIdx(); + LogInfo::MapleLogger() << " TYIDX:" << tyIdx; MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); mirType->Dump(0); LogInfo::MapleLogger() << " mx" << GetExprID(); @@ -746,7 +746,7 @@ void SizeoftypeMeExpr::Dump(IRMap *irMap, int32 indent) const { void FieldsDistMeExpr::Dump(IRMap *irMap, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOp()).name << " " << GetPrimTypeName(GetPrimType()); - LogInfo::MapleLogger() << " TYIDX:" << tyIdx.GetIdx(); + LogInfo::MapleLogger() << " TYIDX:" << tyIdx; MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); mirType->Dump(0); LogInfo::MapleLogger() << " (field)" << fieldID1; @@ -790,7 +790,7 @@ void OpMeExpr::Dump(IRMap *irMap, int32 indent) const { void IvarMeExpr::Dump(IRMap *irMap, int32 indent) const { LogInfo::MapleLogger() << "IVAR mx" << GetExprID(); LogInfo::MapleLogger() << " " << GetPrimTypeName(GetPrimType()); - LogInfo::MapleLogger() << " TYIDX:" << tyIdx.GetIdx(); + LogInfo::MapleLogger() << " TYIDX:" << tyIdx; MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); mirType->Dump(0); LogInfo::MapleLogger() << " (field)" << fieldID << '\n'; @@ -1100,7 +1100,7 @@ void AssignedPart::DumpAssignedPart(IRMap *irMap) const { void CallMeStmt::Dump(IRMap *irMap) const { LogInfo::MapleLogger() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << " "; if (tyIdx != 0) { - LogInfo::MapleLogger() << " TYIDX:" << tyIdx.GetIdx(); + LogInfo::MapleLogger() << " TYIDX:" << tyIdx; MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); mirType->Dump(0); } @@ -1115,7 +1115,7 @@ void CallMeStmt::Dump(IRMap *irMap) const { void IcallMeStmt::Dump(IRMap *irMap) const { LogInfo::MapleLogger() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << " "; - LogInfo::MapleLogger() << " TYIDX:" << retTyIdx.GetIdx(); + LogInfo::MapleLogger() << " TYIDX:" << retTyIdx; DumpOpnds(irMap); DumpMuList(irMap, muList, 0); DumpChiList(irMap, chiList); @@ -1124,7 +1124,7 @@ void IcallMeStmt::Dump(IRMap *irMap) const { void IntrinsiccallMeStmt::Dump(IRMap *irMap) const { LogInfo::MapleLogger() << "||MEIR|| " << kOpcodeInfo.GetTableItemAt(GetOp()).name << " "; - LogInfo::MapleLogger() << "TYIDX:" << tyIdx.GetIdx(); + LogInfo::MapleLogger() << "TYIDX:" << tyIdx; MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); if (mirType != nullptr) { mirType->Dump(0); diff --git a/src/maple_util/include/meta.h b/src/maple_util/include/meta.h new file mode 100644 index 0000000000000000000000000000000000000000..0b13debc524a603c17418b43b793b4b774645852 --- /dev/null +++ b/src/maple_util/include/meta.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + */ +#ifndef MAPLE_UTIL_INCLUDE_META_H +#define MAPLE_UTIL_INCLUDE_META_H +#include + +namespace maple { namespace utils { +template +struct meta_and + : public std::conditional_t {}; + +template +struct meta_or + : public std::conditional_t {}; + +template +struct meta_not + : public std::integral_constant {}; + +template +struct is_signed; + +template <> +struct is_signed<> + : public std::true_type {}; + +template +struct is_signed + : public std::is_signed {}; + +template +struct is_signed + : public meta_and, std::is_signed> {}; + +template +constexpr bool is_signed_v = is_signed::value; + +template +struct is_unsigned; + +template <> +struct is_unsigned<> + : public std::true_type {}; + +template +struct is_unsigned + : public std::is_unsigned {}; + +template +struct is_unsigned + : public meta_and, std::is_unsigned> {}; + +template +constexpr bool is_unsigned_v = is_unsigned::value; + +template +struct is_same_sign + : public meta_or, is_unsigned> {}; + +template +struct is_diff_sign + : public meta_not> {}; +}} +#endif //MAPLE_UTIL_INCLUDE_META_H diff --git a/src/maple_util/include/mpl_number.h b/src/maple_util/include/mpl_number.h index d1838e79997aa649468606959a287c14f292fd48..3ff2d5423fdd52e793c460d4182c4edafb0d8b31 100644 --- a/src/maple_util/include/mpl_number.h +++ b/src/maple_util/include/mpl_number.h @@ -15,12 +15,16 @@ #ifndef MAPLE_UTIL_INCLUDE_MPL_NUMBER_H #define MAPLE_UTIL_INCLUDE_MPL_NUMBER_H #include +#include +#include "meta.h" namespace maple { namespace utils { template class Number { public: + static_assert(std::is_integral::value, "Type for Number should be an integral."); + using element_type = T; Number() = default; @@ -54,7 +58,7 @@ class Number { return *this; } - void reset(element_type data) noexcept { + void reset(element_type data = 0) noexcept { val = data; } @@ -66,13 +70,19 @@ class Number { return val; } - operator bool() const = delete; - - operator element_type() const noexcept { + template + operator std::enable_if_t::value, U>() const noexcept { return val; } - template ::value>> + template + operator + std::enable_if_t>, std::is_same>::value, U>() const noexcept { + return static_cast(val); + } + + template >, + meta_not>>::value>> explicit operator U() const noexcept { return static_cast(val); } @@ -115,6 +125,14 @@ class Number { return Number(tmp); } + T GetIdx() const { + return val; + } + + void SetIdx(T i) { + val = i; + } + private: element_type val = 0; }; @@ -154,67 +172,80 @@ inline Number operator+(const Number &lhs, const Number return Number(lhs.get() + rhs.get()); } + template inline Number operator-(const Number &lhs, const Number &rhs) { return Number(lhs.get() + rhs.get()); } -template ::value>> +template , std::is_enum>::value>> inline bool operator==(const Number &lhs, const U &rhs) { return lhs.get() == rhs; } -template ::value>> +template , std::is_enum>::value>> inline bool operator==(const U &lhs, const Number &rhs) { return lhs == rhs.get(); } -template ::value>> +template , std::is_enum>::value>> inline bool operator!=(const Number &lhs, const U &rhs) { return !(lhs == rhs); } -template ::value>> +template , std::is_enum>::value>> inline bool operator!=(const U &lhs, const Number &rhs) { return !(lhs == rhs); } -template ::value>> +template , std::is_enum>::value>> inline bool operator<(const Number &lhs, const U &rhs) { return lhs.get() < rhs; } -template ::value>> +template , std::is_enum>::value>> inline bool operator<(const U &lhs, const Number &rhs) { return lhs < rhs.get(); } -template ::value>> +template , std::is_enum>::value>> inline bool operator<=(const Number &lhs, const U &rhs) { return lhs.get() <= rhs; } -template ::value>> +template , std::is_enum>::value>> inline bool operator<=(const U &lhs, const Number &rhs) { return lhs <= rhs.get(); } -template ::value>> +template , std::is_enum>::value>> inline bool operator>(const Number &lhs, const U &rhs) { return !(lhs <= rhs); } -template ::value>> +template , std::is_enum>::value>> inline bool operator>(const U &lhs, const Number &rhs) { return !(lhs <= rhs); } -template ::value>> +template , std::is_enum>::value>> inline bool operator>=(const Number &lhs, const U &rhs) { return !(lhs < rhs); } -template ::value>> +template , std::is_enum>::value>> inline bool operator>=(const U &lhs, const Number &rhs) { return !(lhs < rhs); } @@ -249,4 +280,11 @@ template using Index = Number; }} -#endif //MAPLE_UTIL_INCLUDE_NUMBER_H + +namespace std { + template + inline string to_string(maple::utils::Number val) { + return std::to_string (val.get()); + } +} +#endif //MAPLE_UTIL_INCLUDE_MPL_NUMBER_H diff --git a/src/maple_util/include/name_mangler.h b/src/maple_util/include/name_mangler.h index 1f719cbc5d5088df4aca14a7289b6bff1b487bda..f334dcc254068790d2c13f445702fbea0be4369f 100644 --- a/src/maple_util/include/name_mangler.h +++ b/src/maple_util/include/name_mangler.h @@ -114,6 +114,8 @@ static constexpr const char kDecoupleStaticKeyStr[] = "__staticDecoupleKeyOffset static constexpr const char kDecoupleStaticValueStr[] = "__staticDecoupleValueOffset"; static constexpr const char kMarkDecoupleStaticStr[] = "decouple_static:"; static constexpr const char kClassInfoPrefix[] = "__cinf"; +static constexpr const char kBssSectionStr[] = "__bss_section"; +static constexpr const char kLinkerHashSoStr[] = "__linkerHashSo"; static constexpr const char kStaticFieldNamePrefixStr[] = "__static_field_name"; static constexpr const char kPackageNameSplitterStr[] = "_2F"; diff --git a/src/mpl2mpl/include/class_hierarchy.h b/src/mpl2mpl/include/class_hierarchy.h index 06214e8fe6606110474734f2bab25cbaf3f52f1e..13335b85180a37c84eaa7220ea66b99dd1057df0 100644 --- a/src/mpl2mpl/include/class_hierarchy.h +++ b/src/mpl2mpl/include/class_hierarchy.h @@ -34,6 +34,7 @@ constexpr uint32 kClassIsanonymousclass = 0x0400; constexpr uint32 kClassIscoldclass = 0x0800; constexpr uint32 kClassNeedDecouple = 0x1000; constexpr uint32 kClassLazyBindingClass = 0x2000; +constexpr uint32 kClassLazyBoundClass = 0x4000; // Only used in runtime, occupancy. constexpr char kJavaLangNoMethodStr[] = "Ljava_2Flang_2FNoSuchMethodException_3B"; constexpr uint32 kClassReference = (kClassSoftreference | kClassWeakreference | kClassCleaner | kClassFinalizereference | kClassPhantomreference); diff --git a/src/mpl2mpl/src/class_hierarchy.cpp b/src/mpl2mpl/src/class_hierarchy.cpp index 76d516c6d71cfc8018505ea27b27338869ffbec9..bd0c139de6b873a18183280d9152ce722b7f26b7 100644 --- a/src/mpl2mpl/src/class_hierarchy.cpp +++ b/src/mpl2mpl/src/class_hierarchy.cpp @@ -76,7 +76,7 @@ void Klass::DumpKlassImplKlasses() const { } LogInfo::MapleLogger() << " implemented by:\n"; for (Klass *implKlass : implKlasses) { - LogInfo::MapleLogger() << " \t@implbyclass_idx " << implKlass->structType->GetTypeIndex().GetIdx() << "\n"; + LogInfo::MapleLogger() << " \t@implbyclass_idx " << implKlass->structType->GetTypeIndex() << "\n"; } } @@ -86,7 +86,7 @@ void Klass::DumpKlassImplInterfaces() const { } LogInfo::MapleLogger() << " implements:\n"; for (Klass *interface : implInterfaces) { - LogInfo::MapleLogger() << " \t@implinterface_idx " << interface->structType->GetTypeIndex().GetIdx() << "\n"; + LogInfo::MapleLogger() << " \t@implinterface_idx " << interface->structType->GetTypeIndex() << "\n"; } } @@ -96,7 +96,7 @@ void Klass::DumpKlassSuperKlasses() const { } LogInfo::MapleLogger() << " superclasses:\n"; for (Klass *superKlass : superKlasses) { - LogInfo::MapleLogger() << " \t@superclass_idx " << superKlass->structType->GetTypeIndex().GetIdx() << "\n"; + LogInfo::MapleLogger() << " \t@superclass_idx " << superKlass->structType->GetTypeIndex() << "\n"; } } @@ -106,13 +106,13 @@ void Klass::DumpKlassSubKlasses() const { } LogInfo::MapleLogger() << " subclasses:\n"; for (Klass *subKlass : subKlasses) { - LogInfo::MapleLogger() << " \t@subclass_idx " << subKlass->structType->GetTypeIndex().GetIdx() << "\n"; + LogInfo::MapleLogger() << " \t@subclass_idx " << subKlass->structType->GetTypeIndex() << "\n"; } } void Klass::Dump() const { // Dump detailed class info - LogInfo::MapleLogger() << "class \" " << GetKlassName() << " \" @class_id " << structType->GetTypeIndex().GetIdx() + LogInfo::MapleLogger() << "class \" " << GetKlassName() << " \" @class_id " << structType->GetTypeIndex() << "\n"; DumpKlassSuperKlasses(); DumpKlassSubKlasses(); diff --git a/src/mpl2mpl/src/class_init.cpp b/src/mpl2mpl/src/class_init.cpp index d0ec3bc1a2a6cab84b665f67dee14526d119d89a..a16b039a24a40bbe63b8c453ecc1ed86127bd395 100644 --- a/src/mpl2mpl/src/class_init.cpp +++ b/src/mpl2mpl/src/class_init.cpp @@ -125,12 +125,12 @@ void ClassInit::ProcessFunc(MIRFunction *func) { // intrinsiccallwithtype <$LTest_3B> JAVA_CLINIT_CHECK () --> // intrinsiccall MPL_CLINIT_CHECK (addrof ptr $__cinf_LTest_3B) CHECK_FATAL(intrinsicCall->GetNopndSize() == 0, "wrong arg vectors"); - CHECK_FATAL(intrinsicCall->GetTyIdx().GetIdx() < GlobalTables::GetTypeTable().GetTypeTable().size(), + CHECK_FATAL(intrinsicCall->GetTyIdx() < GlobalTables::GetTypeTable().GetTypeTable().size(), "index out of range"); - MIRType *classType = GlobalTables::GetTypeTable().GetTypeTable()[intrinsicCall->GetTyIdx().GetIdx()]; + MIRType *classType = GlobalTables::GetTypeTable().GetTypeTable()[intrinsicCall->GetTyIdx()]; ASSERT(classType != nullptr, "null ptr check!"); CHECK_FATAL(classType->GetNameStrIdx() != 0, "symbol name is null for type index %d", - intrinsicCall->GetTyIdx().GetIdx()); + static_cast(intrinsicCall->GetTyIdx())); const std::string &className = GlobalTables::GetStrTable().GetStringFromStrIdx(classType->GetNameStrIdx()); Klass *klass = klassHierarchy->GetKlassFromName(className); bool doClinitCheck = false; diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index aa2c5e70fee5427162e00f8c654ba7c75a0ac63a..8702a978af37df3060b44a294f6c7853039de71d 100644 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -463,10 +463,10 @@ void ReflectionAnalysis::GenAllMethodHash(std::vectorGetFunction(); std::string baseName = func->GetBaseFuncName(); baseName = NameMangler::DecodeName(baseName); - baseNameMap[func->GetBaseFuncNameStrIdx().GetIdx()] = baseName; + baseNameMap[func->GetBaseFuncNameStrIdx()] = baseName; std::string fullName = func->GetBaseFuncNameWithType(); fullName = NameMangler::DecodeName(fullName); - fullNameMap[func->GetBaseFuncNameWithTypeStrIdx().GetIdx()] = fullName; + fullNameMap[func->GetBaseFuncNameWithTypeStrIdx()] = fullName; CHECK_FATAL(fullName.find("|") != std::string::npos, "can not find |"); std::string signature = fullName.substr(fullName.find("|") + 1); ConvertMethodSig(signature); @@ -579,7 +579,7 @@ bool RtRetentionPolicyCheck(const MIRSymbol &clInfo) { if (GlobalTables::GetStrTable().GetStringFromStrIdx( GlobalTables::GetTypeTable().GetTypeFromTyIdx(p->GetTyIdx())->GetNameStrIdx()) == (kJavaLangAnnotationRetentionStr)) { - strIdx.SetIdx(p->GetElementVector()[0]->GetU64Val()); + strIdx.reset(p->GetNthElement(0)->GetU64Val()); std::string retentionType = GlobalTables::GetStrTable().GetStringFromStrIdx(strIdx); if (retentionType != "RUNTIME") { return false; @@ -677,20 +677,20 @@ struct HashCodeComparator { bool operator()(std::pair a, std::pair b) { const MIRSymbol *funcSymA = GlobalTables::GetGsymTable().GetSymbolFromStidx(a.first->first.Idx()); const MIRFunction *funcA = funcSymA->GetFunction(); - auto itB = basenameMp.find(funcA->GetBaseFuncNameStrIdx().GetIdx()); + auto itB = basenameMp.find(funcA->GetBaseFuncNameStrIdx()); ASSERT(itB != basenameMp.end(), "check funcAname!"); const std::string &funcAName = itB->second; - auto itF = fullnameMp.find(funcA->GetBaseFuncNameWithTypeStrIdx().GetIdx()); + auto itF = fullnameMp.find(funcA->GetBaseFuncNameWithTypeStrIdx()); ASSERT(itF != fullnameMp.end(), "check funcAname!"); const std::string &fullNameA = itF->second; CHECK_FATAL(fullNameA.find("|") != fullNameA.npos, "not found |"); const std::string &signatureA = fullNameA.substr(fullNameA.find("|") + 1); const MIRSymbol *funcSymB = GlobalTables::GetGsymTable().GetSymbolFromStidx(b.first->first.Idx()); const MIRFunction *funcB = funcSymB->GetFunction(); - itB = basenameMp.find(funcB->GetBaseFuncNameStrIdx().GetIdx()); + itB = basenameMp.find(funcB->GetBaseFuncNameStrIdx()); ASSERT(itB != basenameMp.end(), "check funcBname!"); const std::string &funcBName = itB->second; - itF = fullnameMp.find(funcB->GetBaseFuncNameWithTypeStrIdx().GetIdx()); + itF = fullnameMp.find(funcB->GetBaseFuncNameWithTypeStrIdx()); ASSERT(itF != fullnameMp.end(), "check funcBname!"); const std::string &fullNameB = itF->second; CHECK_FATAL(fullNameB.find("|") != std::string::npos, "not found |"); @@ -762,11 +762,11 @@ void ReflectionAnalysis::GenMethodMeta(const Klass &klass, MIRStructType &method uint32 mod = GetMethodModifier(klass, func); mirBuilder.AddIntFieldConst(methodsInfoType, newConst, fieldID++, mod); // @methodname - std::string baseName = baseNameMp[func.GetBaseFuncNameStrIdx().GetIdx()]; + std::string baseName = baseNameMp[func.GetBaseFuncNameStrIdx()]; uint32 methodnameIdx = FindOrInsertReflectString(baseName); mirBuilder.AddIntFieldConst(methodsInfoType, newConst, fieldID++, methodnameIdx); // @methodsignature - std::string fullname = fullNameMp[func.GetBaseFuncNameWithTypeStrIdx().GetIdx()]; + std::string fullname = fullNameMp[func.GetBaseFuncNameWithTypeStrIdx()]; std::string signature = GetSignatureFromFullName(fullname); ConvertMethodSig(signature); std::vector typeNames; @@ -1115,7 +1115,7 @@ void ReflectionAnalysis::AppendValueByType(std::string &annoArr, const MIRPragma break; default: { // kValueString kValueEnum kValueType GStrIdx strIdx; - strIdx.SetIdx(elem.GetU64Val()); + strIdx.reset(elem.GetU64Val()); std::string s = GlobalTables::GetStrTable().GetStringFromStrIdx(strIdx); uint32 idx = ReflectionAnalysis::FindOrInsertReflectString(s); annoArr += annoDelimiterPrefix; @@ -1191,7 +1191,7 @@ std::string ReflectionAnalysis::GetArrayValue(const MapleVectorGetU64Val()) + annoDelimiter); annoArray += GlobalTables::GetStrTable().GetStringFromStrIdx(arrayElem->GetNameStrIdx()); - strIdx.SetIdx(arrayElem->GetU64Val()); + strIdx.reset(arrayElem->GetU64Val()); annoArray += (GlobalTables::GetStrTable().GetStringFromStrIdx(strIdx) + annoDelimiter); } } @@ -1214,7 +1214,7 @@ std::string ReflectionAnalysis::GetAnnoValueNoArray(const MIRPragmaElement &anno break; default: { GStrIdx strIdx; - strIdx.SetIdx(annoElem.GetU64Val()); + strIdx.reset(annoElem.GetU64Val()); std::string javaDescriptor; ConvertMapleClassName(GlobalTables::GetStrTable().GetStringFromStrIdx(strIdx), javaDescriptor); uint32_t idx = ReflectionAnalysis::FindOrInsertReflectString(javaDescriptor); @@ -1575,13 +1575,13 @@ bool ReflectionAnalysis::IsAnonymousClass(const std::string &annotationString) { return false; } -TyIdx ReflectionAnalysis::GenMetaStructType(MIRModule &mirModule, MIRStructType &metatype, const std::string &str) { +TyIdx ReflectionAnalysis::GenMetaStructType(MIRModule &mirModule, MIRStructType &metaType, const std::string &str) { const GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(str); - TyIdx tyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&metatype); + TyIdx tyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&metaType); // Global? mirModule.GetTypeNameTab()->SetGStrIdxToTyIdx(strIdx, tyIdx); mirModule.PushbackTypeDefOrder(strIdx); - if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx.GetIdx())->GetNameStrIdx() == 0) { + if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->GetNameStrIdx() == 0) { GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->SetNameStrIdx(strIdx); } return tyIdx;