diff --git a/doc/RC_API.md b/doc/RC_API.md index 6ec46a75068a8a29b58996517c914c2fd22ed0d6..7a3777a7c277ecef8771dea1b3f9048ee35ea8fa 100644 --- a/doc/RC_API.md +++ b/doc/RC_API.md @@ -111,7 +111,7 @@ obj的堆对象地址。 **功能说明:** -从非易失性(Volatile)静态变量中取值,并且将取到的堆对象的RC原子性的加一。 +从易失性(Volatile)静态变量中取值,并且将取到的堆对象的RC原子性的加一。 **入参说明:** diff --git a/doc/Vtable_Itable_Description.md b/doc/Vtable_Itable_Description.md index 91fa68b5980ee926519f6674f534688ed82d6cc5..afa52db41a1351eb016eea04b7832cee40a37be5 100644 --- a/doc/Vtable_Itable_Description.md +++ b/doc/Vtable_Itable_Description.md @@ -146,14 +146,39 @@ Interface call类似于多重继承,比java单继承要复杂。多继承无 一级函数表结构如下: -|表序| 接口函数表项| 说明 | -|----|------------|---------------------------------------------| -|0 | &Func 或 0 | 对应Hash值的函数地址,没有则为0; 如果出现冲突,| -|1 | &Func 或 0 | 那么冲突的位置也为0,并且在第23个表项填上二级表 | -|2 | &Func 或 0 | 的地址; 如果没有冲突,那么将最后一个有对应函数的| -|... | &Func 或 0 | hash值( n )之后的表项删除 | -|n | &Func | -|23 | &itbC | 二级表的地址。如果一级表没有出现冲突,则该项不存在| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
表序接口函数表项说明
0&Func 或 0对应Hash值的函数地址,没有则为0; 如果出现冲突,那么冲突的位置也为0,并且在第23个表项填上二级表的地址; 如果没有冲突,那么将最后一个有对应函数的hash值( n )之后的表项删除
1&Func 或 0
2&Func 或 0
...&Func 或 0
n&Func
23&itbC二级表的地址。如果一级表没有出现冲突,则该项不存在
二级函数表的结构如下: diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index e75d02a25af445e0e0f09cd6817b80a24a946e06..e583957b4a404cdcf9debc5131affa5b29ec1770 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index da07cd0c7ea1d1a23c25b58d90423b1713d4b0af..a67406e837c1e8cde92f11d1ad058df20d47beca 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index 682212700691f38f1ac57ae123b056a04bc4828b..a2e23a4f5ab25ab3da7a0ff19365238eebfd9c60 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/maple_driver/include/usages.h b/src/maple_driver/include/usages.h index 8aec6f877312c1480fe1b5d3fb2a7e5e72006209..fd32d8b8c63426a1fd959bfcc1e7441d422cf19a 100644 --- a/src/maple_driver/include/usages.h +++ b/src/maple_driver/include/usages.h @@ -16,7 +16,7 @@ #define MAPLE_DRIVER_INCLUDE_USAGES_H namespace maple { -enum OptionIndex { +enum OptionIndex : uint64 { kUnknown, kHelp, kVersion, diff --git a/src/maple_ipa/src/module_phase_manager.cpp b/src/maple_ipa/src/module_phase_manager.cpp index e7477cd1777be844bed7a5748aa49ec74a2d9914..96f37fc26ad0dfcb53e8d89b656e7dfaf49e89df 100644 --- a/src/maple_ipa/src/module_phase_manager.cpp +++ b/src/maple_ipa/src/module_phase_manager.cpp @@ -45,7 +45,7 @@ AnalysisResult *DoKlassHierarchy::Run(MIRModule *module, ModuleResultMgr *m) { if (KlassHierarchy::traceFlag) { kh->Dump(); } - m->AddResult(GetPhaseID(), module, kh); + m->AddResult(GetPhaseID(), *module, *kh); return kh; } @@ -55,7 +55,7 @@ void ModulePhaseManager::RegisterModulePhases() { MemPool *memPool = GetMemPool(); \ ModulePhase *phase = new (memPool->Malloc(sizeof(modphase(id)))) modphase(id); \ CHECK_FATAL(phase != nullptr, "null ptr check "); \ - RegisterPhase(id, phase); \ + RegisterPhase(id, *phase); \ arModuleMgr->AddAnalysisPhase(id, phase); \ } while (0); #define MODTPHASE(id, modphase) \ @@ -63,7 +63,7 @@ void ModulePhaseManager::RegisterModulePhases() { MemPool *memPool = GetMemPool(); \ ModulePhase *phase = new (memPool->Malloc(sizeof(modphase(id)))) modphase(id); \ CHECK_FATAL(phase != nullptr, "null ptr check "); \ - RegisterPhase(id, phase); \ + RegisterPhase(id, *phase); \ } while (0); #include "module_phases.def" #undef MODAPHASE diff --git a/src/maple_ir/include/mir_builder.h b/src/maple_ir/include/mir_builder.h index ba85075c475181e207ff8930d60f247c3ca0f55a..d1756b9a23478e0cfdededa03cc56c36db2361a2 100644 --- a/src/maple_ir/include/mir_builder.h +++ b/src/maple_ir/include/mir_builder.h @@ -65,8 +65,8 @@ class MIRBuilder { return func; } - MIRModule *GetMirModule() const { - return mirModule; + MIRModule &GetMirModule() const { + return *mirModule; } const MapleSet &GetIncompleteTypeRefedSet() const { @@ -143,7 +143,7 @@ class MIRBuilder { MIRSymbol *GetOrCreateGlobalDecl(const std::string &str, const MIRType &type); MIRSymbol *GetGlobalDecl(const std::string &str); MIRSymbol *GetDecl(const std::string &str); - MIRSymbol *CreateGlobalDecl(const std::string &str, const MIRType *type, MIRStorageClass sc = kScGlobal); + MIRSymbol *CreateGlobalDecl(const std::string &str, const MIRType &type, MIRStorageClass sc = kScGlobal); MIRSymbol *GetOrCreateDeclInFunc(const std::string &str, const MIRType &type, MIRFunction &func); // for creating Expression ConstvalNode *CreateIntConst(int64, PrimType); diff --git a/src/maple_ir/include/mir_const.h b/src/maple_ir/include/mir_const.h index bc99c91924619f76627e63e7b7c0140960925093..2452ddae848dc64750db64524eddc4072eea11be 100644 --- a/src/maple_ir/include/mir_const.h +++ b/src/maple_ir/include/mir_const.h @@ -39,7 +39,7 @@ enum MIRConstKind { class MIRConst { public: - explicit MIRConst(MIRType *type, uint32 fieldID = 0) : kind(kConstInvalid), type(type), fieldID(fieldID) {} + explicit MIRConst(MIRType &type, uint32 fieldID = 0) : kind(kConstInvalid), type(type), fieldID(fieldID) {} virtual ~MIRConst() {} @@ -84,26 +84,26 @@ class MIRConst { kind = ind; } - MIRType *GetType() { + MIRType &GetType() { return type; } - const MIRType *GetType() const { + const MIRType &GetType() const { return type; } private: MIRConstKind kind; - MIRType *type; + MIRType &type; uint32 fieldID; }; class MIRIntConst : public MIRConst { public: using value_type = int64; - MIRIntConst(int64 val, MIRType *type, uint32 fieldID = 0) : MIRConst(type, fieldID), value(val) { - if (!IsPrimitiveDynType(GetType()->GetPrimType())) { - Trunc(GetPrimTypeBitSize(GetType()->GetPrimType())); + MIRIntConst(int64 val, MIRType &type, uint32 fieldID = 0) : MIRConst(type, fieldID), value(val) { + if (!IsPrimitiveDynType(type.GetPrimType())) { + Trunc(GetPrimTypeBitSize(type.GetPrimType())); } SetKind(kConstInt); } @@ -129,7 +129,7 @@ class MIRIntConst : public MIRConst { CHECK_FATAL(false, "shiftBitNum should not be less than zero"); } uint32 unsignShiftBitNum = static_cast(shiftBitNum); - if (IsSignedInteger(GetType()->GetPrimType())) { + if (IsSignedInteger(GetType().GetPrimType())) { value = (value << unsignShiftBitNum) >> unsignShiftBitNum; } else { value = ((static_cast(value)) << unsignShiftBitNum) >> unsignShiftBitNum; @@ -137,12 +137,12 @@ class MIRIntConst : public MIRConst { } int64 GetValueUnderType() const { - uint32 bitSize = GetPrimTypeBitSize(GetNonDynType(GetType()->GetPrimType())); + uint32 bitSize = GetPrimTypeBitSize(GetNonDynType(GetType().GetPrimType())); int32 shiftBitNum = 64u - bitSize; if (shiftBitNum < 0) { CHECK_FATAL(false, "shiftBitNum should not be less than zero"); } - if (IsSignedInteger(GetType()->GetPrimType())) { + if (IsSignedInteger(GetType().GetPrimType())) { return static_cast(((value) << shiftBitNum) >> shiftBitNum); } else { uint64 unsignedVal = static_cast(value); @@ -152,18 +152,18 @@ class MIRIntConst : public MIRConst { void Dump() const; bool IsZero() { - return value == 0 && IsPrimitiveInteger(GetType()->GetPrimType()); + return value == 0 && IsPrimitiveInteger(GetType().GetPrimType()); } bool IsOne() { - return value == 1 && IsPrimitiveInteger(GetType()->GetPrimType()); + return value == 1 && IsPrimitiveInteger(GetType().GetPrimType()); }; bool IsMagicNum() { constexpr int64 kMagicNum = 51; - return value == kMagicNum && IsPrimitiveInteger(GetType()->GetPrimType()); + return value == kMagicNum && IsPrimitiveInteger(GetType().GetPrimType()); }; bool IsAllBitsOne() { - return value == -1 && IsPrimitiveInteger(GetType()->GetPrimType()); + return value == -1 && IsPrimitiveInteger(GetType().GetPrimType()); }; void Neg() { value = -value; @@ -185,7 +185,7 @@ class MIRIntConst : public MIRConst { class MIRAddrofConst : public MIRConst { public: - MIRAddrofConst(StIdx sy, FieldID fi, MIRType *ty) : MIRConst(ty), stIdx(sy), fldID(fi) { + MIRAddrofConst(StIdx sy, FieldID fi, MIRType &ty) : MIRConst(ty), stIdx(sy), fldID(fi) { SetKind(kConstAddrof); } @@ -211,7 +211,7 @@ class MIRAddrofConst : public MIRConst { class MIRAddroffuncConst : public MIRConst { public: - MIRAddroffuncConst(PUIdx idx, MIRType *ty, uint32 fieldID = 0) : MIRConst(ty, fieldID), puIdx(idx) { + MIRAddroffuncConst(PUIdx idx, MIRType &ty, uint32 fieldID = 0) : MIRConst(ty, fieldID), puIdx(idx) { SetKind(kConstAddrofFunc); } @@ -232,7 +232,7 @@ class MIRAddroffuncConst : public MIRConst { class MIRLblConst : public MIRConst { public: - MIRLblConst(LabelIdx val, MIRType *type) : MIRConst(type), value(val) { + MIRLblConst(LabelIdx val, MIRType &type) : MIRConst(type), value(val) { SetKind(kConstLblConst); } @@ -250,11 +250,11 @@ class MIRLblConst : public MIRConst { class MIRStrConst : public MIRConst { public: - MIRStrConst(UStrIdx val, MIRType *type, uint32 fieldID = 0) : MIRConst(type, fieldID), value(val) { + MIRStrConst(UStrIdx val, MIRType &type, uint32 fieldID = 0) : MIRConst(type, fieldID), value(val) { SetKind(kConstStrConst); } - MIRStrConst(const std::string &str, MIRType *type); + MIRStrConst(const std::string &str, MIRType &type); ~MIRStrConst() {} @@ -275,12 +275,11 @@ class MIRStrConst : public MIRConst { class MIRStr16Const : public MIRConst { public: - using value_type = const char*; - MIRStr16Const(U16StrIdx val, MIRType *type) : MIRConst(type), value(val) { + MIRStr16Const(U16StrIdx val, MIRType &type) : MIRConst(type), value(val) { SetKind(kConstStr16Const); } - MIRStr16Const(const std::u16string &str, MIRType *type); + MIRStr16Const(const std::u16string &str, MIRType &type); ~MIRStr16Const() {} @@ -302,7 +301,7 @@ class MIRStr16Const : public MIRConst { class MIRFloatConst : public MIRConst { public: using value_type = float; - MIRFloatConst(float val, MIRType *type) : MIRConst(type) { + MIRFloatConst(float val, MIRType &type) : MIRConst(type) { value.floatValue = val; SetKind(kConstFloatConst); } @@ -357,7 +356,7 @@ class MIRFloatConst : public MIRConst { class MIRDoubleConst : public MIRConst { public: using value_type = double; - MIRDoubleConst(double val, MIRType *type) : MIRConst(type) { + MIRDoubleConst(double val, MIRType &type) : MIRConst(type) { value.dValue = val; SetKind(kConstDoubleConst); } @@ -413,9 +412,8 @@ class MIRDoubleConst : public MIRConst { class MIRFloat128Const : public MIRConst { public: - MIRFloat128Const(const uint64 *val, MIRType *type) : MIRConst(type) { - MIR_ASSERT(val && "val must not nullptr!"); - value = val; + MIRFloat128Const(const uint64 &val, MIRType &type) : MIRConst(type) { + value = &val; SetKind(kConstFloat128Const); } @@ -453,13 +451,8 @@ class MIRFloat128Const : public MIRConst { class MIRAggConst : public MIRConst { public: - MIRAggConst(MIRModule *mod, MIRType *type) - : MIRConst(type), allocator(nullptr), constVec(mod->GetMPAllocator().Adapter()) { - SetKind(kConstAggConst); - } - - MIRAggConst(MIRModule *mod, MIRType *type, MemPool *memPool) - : MIRConst(type), allocator(memPool), constVec(allocator.Adapter()) { + MIRAggConst(MIRModule &mod, MIRType &type) + : MIRConst(type), allocator(nullptr), constVec(mod.GetMPAllocator().Adapter()) { SetKind(kConstAggConst); } @@ -485,12 +478,12 @@ class MIRAggConst : public MIRConst { CHECK_FATAL(index < constVec.size(), "index out of range"); return constVec[index]; } - void SetConstVecItem(uint32 index, MIRConst *mirConst) { + void SetConstVecItem(uint32 index, MIRConst &mirConst) { CHECK_FATAL(index < constVec.size(), "index out of range"); - constVec[index] = mirConst; + constVec[index] = &mirConst; } - void PushBack(MIRConst *elem) { - constVec.push_back(elem); + void PushBack(MIRConst &elem) { + constVec.push_back(&elem); } void Dump() const; @@ -504,8 +497,8 @@ class MIRAggConst : public MIRConst { // the const has one or more symbols class MIRStConst : public MIRConst { public: - MIRStConst(MIRModule *mod, MIRType *type) - : MIRConst(type), stVec(mod->GetMPAllocator().Adapter()), stOffsetVec(mod->GetMPAllocator().Adapter()) { + MIRStConst(MIRModule &mod, MIRType &type) + : MIRConst(type), stVec(mod.GetMPAllocator().Adapter()), stOffsetVec(mod.GetMPAllocator().Adapter()) { SetKind(kConstStConst); } diff --git a/src/maple_ir/include/mir_lower.h b/src/maple_ir/include/mir_lower.h index f02dd3dca82a05c50644e67528c79aa3d4fa5c8b..45eab32df2d84b4b708597a5965a72df27de5d8b 100644 --- a/src/maple_ir/include/mir_lower.h +++ b/src/maple_ir/include/mir_lower.h @@ -19,7 +19,7 @@ #include "opcodes.h" namespace maple { -enum MirLowerPhase { kLowerUnder, kLowerMe, kLowerExpandArray, kLowerBe, kLowerCG }; +enum MirLowerPhase : uint8 { kLowerUnder, kLowerMe, kLowerExpandArray, kLowerBe, kLowerCG }; #define LOWERME (1U << kLowerMe) #define LOWEREXPANDARRAY (1U << kLowerExpandArray) @@ -103,6 +103,10 @@ class MIRLower { MIRFunction *mirFunc; MIRBuilder *mirBuilder; uint32 lowerPhase; + LabelIdx CreateCondGotoStmt(Opcode op, BlockNode &blk, const IfStmtNode &ifStmt); + void CreateBrFalseStmt(BlockNode &blk, const IfStmtNode &ifStmt); + void CreateBrTrueStmt(BlockNode &blk, const IfStmtNode &ifStmt); + void CreateBrFalseAndGotoStmt(BlockNode &blk, const IfStmtNode &ifStmt); }; } // namespace maple #endif // MAPLE_IR_INCLUDE_MIR_LOWER_H diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index 4c12c4e483e81933645d710ad3427ccf695368b3..c1039b4a7a56e9b4d247d35fa6081ee4ddc6a1ce 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -1168,16 +1168,16 @@ class MIRClassType : public MIRStructType { parentTyIdx = idx; } - std::vector &GetInerfaceImplemented() { + std::vector &GetInterfaceImplemented() { return interfacesImplemented; } - const TyIdx &GetNthInerfaceImplemented(size_t i) const { + const TyIdx &GetNthInterfaceImplemented(size_t i) const { ASSERT(i < interfacesImplemented.size(), "array index out of range"); return interfacesImplemented.at(i); } - void SetNthInerfaceImplemented(uint32 i, TyIdx tyIdx) { + void SetNthInterfaceImplemented(uint32 i, TyIdx tyIdx) { ASSERT(i < interfacesImplemented.size(), "array index out of range"); interfacesImplemented.at(i) = tyIdx; } diff --git a/src/maple_ir/src/bin_mpl_export.cpp b/src/maple_ir/src/bin_mpl_export.cpp index 32aab6487cee23f05a7c43541fed2553ddf75757..8b28023504d0f0cd0e0804a5cdf309953e25be09 100644 --- a/src/maple_ir/src/bin_mpl_export.cpp +++ b/src/maple_ir/src/bin_mpl_export.cpp @@ -374,7 +374,7 @@ void BinaryMplExport::DumpBuf(const std::string &name) { void BinaryMplExport::OutputConstBase(const MIRConst &constVal) { WriteNum(constVal.GetKind()); - OutputType(constVal.GetType()->GetTypeIndex()); + OutputType(constVal.GetType().GetTypeIndex()); WriteNum(constVal.GetFieldId()); } @@ -549,7 +549,7 @@ void BinaryMplExport::OutputPragmaVec(const std::vector &pragmaVec) void BinaryMplExport::OutputClassTypeData(MIRClassType &type) { OutputType(type.GetParentTyIdx()); - OutputImplementedInterfaces(type.GetInerfaceImplemented()); + OutputImplementedInterfaces(type.GetInterfaceImplemented()); OutputInfoIsString(type.GetInfoIsString()); OutputInfo(type.GetInfo(), type.GetInfoIsString()); OutputPragmaVec(type.GetPragmVec()); diff --git a/src/maple_ir/src/bin_mpl_import.cpp b/src/maple_ir/src/bin_mpl_import.cpp index 5c5329444f33c6c5d4b622f57276083816d89b1c..3ac28206cfd4f7eff656fea96cdeee1123104a75 100644 --- a/src/maple_ir/src/bin_mpl_import.cpp +++ b/src/maple_ir/src/bin_mpl_import.cpp @@ -111,21 +111,21 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { if (tag == kBinKindConstInt) { ImportConstBase(kind, type, fieldID); - return mod.GetMemPool()->New(ReadNum(), type, fieldID); + return mod.GetMemPool()->New(ReadNum(), *type, fieldID); } else if (tag == kBinKindConstAddrof) { ImportConstBase(kind, type, fieldID); MIRSymbol *sym = InSymbol(func); ASSERT(sym, "null ptr check"); FieldID fi = ReadNum(); - return memPool->New(sym->GetStIdx(), fi, type); + return memPool->New(sym->GetStIdx(), fi, *type); } else if (tag == kBinKindConstAddrofFunc) { ImportConstBase(kind, type, fieldID); PUIdx puidx = ImportFunction(); - return memPool->New(puidx, type, fieldID); + return memPool->New(puidx, *type, fieldID); } else if (tag == kBinKindConstStr) { ImportConstBase(kind, type, fieldID); UStrIdx ustr = ImportUsrStr(); - return memPool->New(ustr, type, fieldID); + return memPool->New(ustr, *type, fieldID); } else if (tag == kBinKindConstStr16) { ImportConstBase(kind, type, fieldID); Conststr16Node *cs; @@ -139,7 +139,7 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { std::u16string str16; NameMangler::UTF8ToUTF16(str16, ostr.str()); cs->SetStrIdx(GlobalTables::GetU16StrTable().GetOrCreateStrIdxFromName(str16)); - return memPool->New(cs->GetStrIdx(), type); + return memPool->New(cs->GetStrIdx(), *type); } else if (tag == kBinKindConstFloat) { union { float fvalue; @@ -158,7 +158,7 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { return GlobalTables::GetFpConstTable().GetOrCreateDoubleConst(value.dvalue); } else if (tag == kBinKindConstAgg) { ImportConstBase(kind, type, fieldID); - MIRAggConst *aggConst = mod.GetMemPool()->New(&mod, type); + MIRAggConst *aggConst = mod.GetMemPool()->New(mod, *type); int64 size = ReadNum(); for (int64 i = 0; i < size; i++) { aggConst->GetConstVec().push_back(ImportConst(func)); @@ -166,7 +166,7 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { return aggConst; } else if (tag == kBinKindConstSt) { ImportConstBase(kind, type, fieldID); - MIRStConst *stConst = mod.GetMemPool()->New(&mod, type); + MIRStConst *stConst = mod.GetMemPool()->New(mod, *type); int64 size = ReadNum(); for (int64 i = 0; i < size; i++) { stConst->PushbackSt(InSymbol(func)); @@ -417,7 +417,7 @@ void BinaryMplImport::ImportClassTypeData(MIRClassType &type) { if (type.GetParentTyIdx().GetIdx() == 0) { type.GetParentTyIdx() = tempType; } - ImportInterfacesOfClassType(type.GetInerfaceImplemented()); + ImportInterfacesOfClassType(type.GetInterfaceImplemented()); ImportInfoIsStringOfClassType(type.GetInfoIsString()); ImportInfoOfClassType(type.GetInfoIsString(), type.GetInfo()); ImportPragmaOfClassType(type.GetPragmVec()); diff --git a/src/maple_ir/src/global_tables.cpp b/src/maple_ir/src/global_tables.cpp index f46460725e698415b1720638a84f553810160060..722f4e0823c1ddbb553df7936fe2a33ee0fb1aa2 100644 --- a/src/maple_ir/src/global_tables.cpp +++ b/src/maple_ir/src/global_tables.cpp @@ -187,12 +187,12 @@ void TypeTable::AddFieldToStructType(MIRStructType &structType, const std::strin } void FPConstTable::PostInit() { - MIRType *typeFloat = GlobalTables::GetTypeTable().GetPrimType(PTY_f32); + MIRType &typeFloat = *GlobalTables::GetTypeTable().GetPrimType(PTY_f32); nanFloatConst = new MIRFloatConst(NAN, typeFloat); infFloatConst = new MIRFloatConst(INFINITY, typeFloat); minusInfFloatConst = new MIRFloatConst(-INFINITY, typeFloat); minusZeroFloatConst = new MIRFloatConst(-0.0, typeFloat); - MIRType *typeDouble = GlobalTables::GetTypeTable().GetPrimType(PTY_f64); + MIRType &typeDouble = *GlobalTables::GetTypeTable().GetPrimType(PTY_f64); nanDoubleConst = new MIRDoubleConst(NAN, typeDouble); infDoubleConst = new MIRDoubleConst(INFINITY, typeDouble); minusInfDoubleConst = new MIRDoubleConst(-INFINITY, typeDouble); @@ -212,7 +212,7 @@ MIRFloatConst *FPConstTable::GetOrCreateFloatConst(float fval) { auto it = floatConstTable.find(fval); if (it == floatConstTable.end()) { // create a new one - MIRFloatConst *fconst = new MIRFloatConst(fval, GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_f32)); + MIRFloatConst *fconst = new MIRFloatConst(fval, *GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_f32)); floatConstTable[fval] = fconst; return fconst; } else { @@ -233,7 +233,7 @@ MIRDoubleConst *FPConstTable::GetOrCreateDoubleConst(double fval) { auto it = doubleConstTable.find(fval); if (it == doubleConstTable.end()) { // create a new one - MIRDoubleConst *dconst = new MIRDoubleConst(fval, GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_f64)); + MIRDoubleConst *dconst = new MIRDoubleConst(fval, *GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_f64)); doubleConstTable[fval] = dconst; return dconst; } else { diff --git a/src/maple_ir/src/mir_builder.cpp b/src/maple_ir/src/mir_builder.cpp index cde82168232646965239e71df1f9347483f2c3e6..facf2a651ef3c8e873d4e03317c43f9601528ea9 100644 --- a/src/maple_ir/src/mir_builder.cpp +++ b/src/maple_ir/src/mir_builder.cpp @@ -19,7 +19,7 @@ namespace maple { // This is for compiler-generated metadata 1-level struct void MIRBuilder::AddIntFieldConst(const MIRStructType &sType, MIRAggConst &newConst, uint32 fieldID, int64 constValue) { - MIRConst *fieldConst = mirModule->GetMemPool()->New(constValue, sType.GetElemType(fieldID - 1), fieldID); + MIRConst *fieldConst = mirModule->GetMemPool()->New(constValue, *sType.GetElemType(fieldID - 1), fieldID); newConst.GetConstVec().push_back(fieldConst); } @@ -28,7 +28,7 @@ void MIRBuilder::AddAddrofFieldConst(const MIRStructType &structType, MIRAggCons const MIRSymbol &fieldSymbol) { AddrofNode *fieldExpr = CreateExprAddrof(0, fieldSymbol, mirModule->GetMemPool()); MIRConst *fieldConst = mirModule->GetMemPool()->New(fieldExpr->GetStIdx(), fieldExpr->GetFieldID(), - structType.GetElemType(fieldID - 1)); + *structType.GetElemType(fieldID - 1)); fieldConst->SetFieldID(fieldID); newConst.GetConstVec().push_back(fieldConst); } @@ -39,12 +39,12 @@ void MIRBuilder::AddAddroffuncFieldConst(const MIRStructType &structType, MIRAgg MIRConst *fieldConst = nullptr; MIRFunction *vMethod = funcSymbol.GetFunction(); if (vMethod->IsAbstract()) { - fieldConst = mirModule->GetMemPool()->New(0, structType.GetElemType(fieldID - 1), fieldID); + fieldConst = mirModule->GetMemPool()->New(0, *structType.GetElemType(fieldID - 1), fieldID); } else { AddroffuncNode *addrofFuncExpr = CreateExprAddroffunc(funcSymbol.GetFunction()->GetPuidx(), mirModule->GetMemPool()); fieldConst = mirModule->GetMemPool()->New(addrofFuncExpr->GetPUIdx(), - structType.GetElemType(fieldID - 1), fieldID); + *structType.GetElemType(fieldID - 1), fieldID); } newConst.GetConstVec().push_back(fieldConst); } @@ -399,12 +399,11 @@ MIRSymbol *MIRBuilder::GetDecl(const std::string &str) { return sym; } -MIRSymbol *MIRBuilder::CreateGlobalDecl(const std::string &str, const MIRType *type, MIRStorageClass sc) { - ASSERT(type != nullptr, "type is null"); +MIRSymbol *MIRBuilder::CreateGlobalDecl(const std::string &str, const MIRType &type, MIRStorageClass sc) { GStrIdx strIdx = GetOrCreateStringIndex(str); MIRSymbol *st = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); st->SetNameStrIdx(strIdx); - st->SetTyIdx(type->GetTypeIndex()); + st->SetTyIdx(type.GetTypeIndex()); (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(*st); st->SetStorageClass(sc); st->SetSKind(kStVar); @@ -432,33 +431,33 @@ MIRSymbol *MIRBuilder::GetOrCreateGlobalDecl(const std::string &str, const MIRTy ConstvalNode *MIRBuilder::CreateIntConst(int64 val, PrimType pty) { MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); MIRIntConst *mirConst = - currentFunctionInner->GetDataMemPool()->New(val, GlobalTables::GetTypeTable().GetPrimType(pty)); + currentFunctionInner->GetDataMemPool()->New(val, *GlobalTables::GetTypeTable().GetPrimType(pty)); return GetCurrentFuncCodeMp()->New(pty, mirConst); } ConstvalNode *MIRBuilder::CreateFloatConst(float val) { MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); MIRFloatConst *mirConst = currentFunctionInner->GetDataMemPool()->New( - val, GlobalTables::GetTypeTable().GetPrimType(PTY_f32)); + val, *GlobalTables::GetTypeTable().GetPrimType(PTY_f32)); return GetCurrentFuncCodeMp()->New(PTY_f32, mirConst); } ConstvalNode *MIRBuilder::CreateDoubleConst(double val) { MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); MIRDoubleConst *mirConst = currentFunctionInner->GetDataMemPool()->New( - val, GlobalTables::GetTypeTable().GetPrimType(PTY_f64)); + val, *GlobalTables::GetTypeTable().GetPrimType(PTY_f64)); return GetCurrentFuncCodeMp()->New(PTY_f64, mirConst); } ConstvalNode *MIRBuilder::CreateFloat128Const(const uint64 *val) { MIRFunction *currentFunctionInner = GetCurrentFunctionNotNull(); MIRFloat128Const *mirConst = currentFunctionInner->GetDataMemPool()->New( - val, GlobalTables::GetTypeTable().GetPrimType(PTY_f128)); + *val, *GlobalTables::GetTypeTable().GetPrimType(PTY_f128)); return GetCurrentFuncCodeMp()->New(PTY_f128, mirConst); } ConstvalNode *MIRBuilder::GetConstInt(MemPool &memPool, int i) { - MIRIntConst *mirConst = memPool.New(i, GlobalTables::GetTypeTable().GetInt64()); + MIRIntConst *mirConst = memPool.New(i, *GlobalTables::GetTypeTable().GetInt64()); return memPool.New(PTY_i32, mirConst); } @@ -472,7 +471,7 @@ ConstvalNode *MIRBuilder::CreateAddrofConst(BaseNode &e) { TyIdx ptyIdx = var->GetTyIdx(); MIRPtrType ptrType(ptyIdx); ptyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&ptrType); - MIRType *exprty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptyIdx); + MIRType &exprty = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptyIdx); MIRAddrofConst *temp = mirModule->GetMemPool()->New(aNode.GetStIdx(), aNode.GetFieldID(), exprty); return GetCurrentFuncCodeMp()->New(PTY_ptr, temp); } @@ -486,7 +485,7 @@ ConstvalNode *MIRBuilder::CreateAddroffuncConst(const BaseNode &e) { MIRPtrType ptrType(ptyIdx); ptyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&ptrType); MIRType *exprty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptyIdx); - MIRAddroffuncConst *mirConst = mirModule->GetMemPool()->New(aNode.GetPUIdx(), exprty); + MIRAddroffuncConst *mirConst = mirModule->GetMemPool()->New(aNode.GetPUIdx(), *exprty); return GetCurrentFuncCodeMp()->New(PTY_ptr, mirConst); } @@ -499,7 +498,7 @@ ConstvalNode *MIRBuilder::CreateStrConst(const BaseNode &e) { MIRPtrType ptrType(ptyidx); ptyidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&ptrType); MIRType *exprType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptyidx); - MIRStrConst *mirConst = mirModule->GetMemPool()->New(strIdx, exprType); + MIRStrConst *mirConst = mirModule->GetMemPool()->New(strIdx, *exprType); return GetCurrentFuncCodeMp()->New(PTY_ptr, mirConst); } @@ -512,7 +511,7 @@ ConstvalNode *MIRBuilder::CreateStr16Const(const BaseNode &e) { MIRPtrType ptrType(ptyIdx); ptyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&ptrType); MIRType *exprty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptyIdx); - MIRStr16Const *mirConst = mirModule->GetMemPool()->New(strIdx, exprty); + MIRStr16Const *mirConst = mirModule->GetMemPool()->New(strIdx, *exprty); return GetCurrentFuncCodeMp()->New(PTY_ptr, mirConst); } diff --git a/src/maple_ir/src/mir_const.cpp b/src/maple_ir/src/mir_const.cpp index fb298a0a99755e34b80cac5b413d874123259781..4ea8d374e154c37d56653f3441576490bbaa8f94 100644 --- a/src/maple_ir/src/mir_const.cpp +++ b/src/maple_ir/src/mir_const.cpp @@ -43,7 +43,7 @@ bool MIRIntConst::operator==(MIRConst &rhs) const { return true; } MIRIntConst *intConst = dynamic_cast(&rhs); - return (intConst && (intConst->GetType() == GetType()) && (intConst->value == value)); + return (intConst && (&intConst->GetType() == &GetType()) && (intConst->value == value)); } void MIRAddrofConst::Dump() const { @@ -65,7 +65,7 @@ bool MIRAddrofConst::operator==(MIRConst &rhs) const { if (rhsA == nullptr) { return false; } - if (GetType() != rhs.GetType()) { + if (&GetType() != &rhs.GetType()) { return false; } return (stIdx == rhsA->stIdx && fldID == rhsA->fldID); @@ -86,7 +86,7 @@ bool MIRAddroffuncConst::operator==(MIRConst &rhs) const { if (rhsAf == nullptr) { return false; } - return (GetType() == rhs.GetType() && puIdx == rhsAf->puIdx); + return (&GetType() == &rhs.GetType() && puIdx == rhsAf->puIdx); } bool MIRLblConst::operator==(MIRConst &rhs) const { @@ -179,8 +179,8 @@ void MIRFloat128Const::Dump() const { MIRConst::Dump(); std::ios::fmtflags f(LogInfo::MapleLogger().flags()); LogInfo::MapleLogger().setf(std::ios::uppercase); - LogInfo::MapleLogger() << "0xL" << std::hex << std::setfill('0') << std::setw(kFieldWidth) << value[0] << std::setfill('0') - << std::setw(kFieldWidth) << value[1]; + LogInfo::MapleLogger() << "0xL" << std::hex << std::setfill('0') << std::setw(kFieldWidth) << value[0] + << std::setfill('0') << std::setw(kFieldWidth) << value[1]; LogInfo::MapleLogger().flags(f); } @@ -197,14 +197,14 @@ void MIRAggConst::Dump() const { LogInfo::MapleLogger() << "]"; } -MIRStrConst::MIRStrConst(const std::string &str, MIRType *type) +MIRStrConst::MIRStrConst(const std::string &str, MIRType &type) : MIRConst(type), value(GlobalTables::GetUStrTable().GetOrCreateStrIdxFromName(str)) { SetKind(kConstStrConst); } void MIRStrConst::Dump() const { MIRConst::Dump(); - LogInfo::MapleLogger() << "conststr " << GetPrimTypeName(GetType()->GetPrimType()); + LogInfo::MapleLogger() << "conststr " << GetPrimTypeName(GetType().GetPrimType()); const std::string kStr = GlobalTables::GetUStrTable().GetStringFromStrIdx(value); PrintString(kStr); } @@ -217,17 +217,17 @@ bool MIRStrConst::operator==(MIRConst &rhs) const { if (rhsCs == nullptr) { return false; } - return (GetType() == rhs.GetType() && value == rhsCs->value); + return (&rhs.GetType() == &GetType() && value == rhsCs->value); } -MIRStr16Const::MIRStr16Const(const std::u16string &str, MIRType *type) +MIRStr16Const::MIRStr16Const(const std::u16string &str, MIRType &type) : MIRConst(type), value(GlobalTables::GetU16StrTable().GetOrCreateStrIdxFromName(str)) { SetKind(kConstStr16Const); } void MIRStr16Const::Dump() const { MIRConst::Dump(); - LogInfo::MapleLogger() << "conststr16 " << GetPrimTypeName(GetType()->GetPrimType()); + LogInfo::MapleLogger() << "conststr16 " << GetPrimTypeName(GetType().GetPrimType()); std::u16string str16 = GlobalTables::GetU16StrTable().GetStringFromStrIdx(value); // UTF-16 string are dumped as UTF-8 string in mpl to keep the printable chars in ascii form std::string str; @@ -243,7 +243,7 @@ bool MIRStr16Const::operator==(MIRConst &rhs) const { if (rhsCs == nullptr) { return false; } - return (GetType() == rhs.GetType() && value == rhsCs->value); + return (&GetType() == &rhs.GetType() && value == rhsCs->value); } } // namespace maple #endif // MIR_FEATURE_FULL diff --git a/src/maple_ir/src/mir_lower.cpp b/src/maple_ir/src/mir_lower.cpp index 34fd6d6a5d571d2a1efbe71b0440f2a094a9585d..50f5468f841a75cd412f43f39a2a91af1604afb5 100644 --- a/src/maple_ir/src/mir_lower.cpp +++ b/src/maple_ir/src/mir_lower.cpp @@ -18,6 +18,63 @@ #define DO_LT_0_CHECK 1 namespace maple { +LabelIdx MIRLower::CreateCondGotoStmt(Opcode op, BlockNode &blk, const IfStmtNode &ifStmt) { + CondGotoNode *brStmt = mirModule.CurFuncCodeMemPool()->New(op); + brStmt->SetOpnd(ifStmt.Opnd()); + brStmt->SetSrcPos(ifStmt.GetSrcPos()); + LabelIdx lableIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); + (void)mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(lableIdx); + brStmt->SetOffset(lableIdx); + blk.AddStatement(brStmt); + bool thenEmpty = ifStmt.GetThenPart() == nullptr || ifStmt.GetThenPart()->GetFirst() == nullptr; + if (thenEmpty) { + blk.AppendStatementsFromBlock(*ifStmt.GetElsePart()); + } else { + blk.AppendStatementsFromBlock(*ifStmt.GetThenPart()); + } + return lableIdx; +} + +void MIRLower::CreateBrFalseStmt(BlockNode &blk, const IfStmtNode &ifStmt) { + LabelIdx labelIdx =CreateCondGotoStmt(OP_brfalse, blk, ifStmt); + LabelNode *lableStmt = mirModule.CurFuncCodeMemPool()->New(); + lableStmt->SetLabelIdx(labelIdx); + blk.AddStatement(lableStmt); +} + +void MIRLower::CreateBrTrueStmt(BlockNode &blk, const IfStmtNode &ifStmt) { + LabelIdx labelIdx =CreateCondGotoStmt(OP_brtrue, blk, ifStmt); + LabelNode *lableStmt = mirModule.CurFuncCodeMemPool()->New(); + lableStmt->SetLabelIdx(labelIdx); + blk.AddStatement(lableStmt); +} + + +void MIRLower::CreateBrFalseAndGotoStmt(BlockNode &blk, const IfStmtNode &ifStmt) { + LabelIdx labelIdx =CreateCondGotoStmt(OP_brfalse, blk, ifStmt); + ASSERT(ifStmt.GetThenPart()->GetLast()->GetOpCode() != OP_brtrue, "then or else block should not end with brtrue"); + ASSERT(ifStmt.GetThenPart()->GetLast()->GetOpCode() != OP_brfalse, + "then or else block should not end with brfalse"); + bool fallThroughFromThen = !IfStmtNoFallThrough(ifStmt); + LabelIdx gotoLableIdx = 0; + if (fallThroughFromThen) { + GotoNode *gotoStmt = mirModule.CurFuncCodeMemPool()->New(OP_goto); + gotoLableIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); + (void)mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(gotoLableIdx); + gotoStmt->SetOffset(gotoLableIdx); + blk.AddStatement(gotoStmt); + } + LabelNode *lableStmt = mirModule.CurFuncCodeMemPool()->New(); + lableStmt->SetLabelIdx(labelIdx); + blk.AddStatement(lableStmt); + blk.AppendStatementsFromBlock(*ifStmt.GetElsePart()); + if (fallThroughFromThen) { + lableStmt = mirModule.CurFuncCodeMemPool()->New(); + lableStmt->SetLabelIdx(gotoLableIdx); + blk.AddStatement(lableStmt); + } +} + BlockNode *MIRLower::LowerIfStmt(IfStmtNode &ifStmt, bool recursive) { bool thenEmpty = ifStmt.GetThenPart() == nullptr || ifStmt.GetThenPart()->GetFirst() == nullptr; bool elseEmpty = ifStmt.GetElsePart() == nullptr || ifStmt.GetElsePart()->GetFirst() == nullptr; @@ -40,32 +97,12 @@ BlockNode *MIRLower::LowerIfStmt(IfStmtNode &ifStmt, bool recursive) { // brfalse // // label - CondGotoNode *brFalseStmt = mirModule.CurFuncCodeMemPool()->New(OP_brfalse); - brFalseStmt->SetOpnd(ifStmt.Opnd()); - brFalseStmt->SetSrcPos(ifStmt.GetSrcPos()); - LabelIdx lableIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); - (void)mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(lableIdx); - brFalseStmt->SetOffset(lableIdx); - blk->AddStatement(brFalseStmt); - blk->AppendStatementsFromBlock(*ifStmt.GetThenPart()); - LabelNode *lableStmt = mirModule.CurFuncCodeMemPool()->New(); - lableStmt->SetLabelIdx(lableIdx); - blk->AddStatement(lableStmt); + CreateBrFalseStmt(*blk, ifStmt); } else if (thenEmpty) { // brtrue // // label - CondGotoNode *brTrueStmt = mirModule.CurFuncCodeMemPool()->New(OP_brtrue); - brTrueStmt->SetOpnd(ifStmt.Opnd()); - brTrueStmt->SetSrcPos(ifStmt.GetSrcPos()); - LabelIdx lableIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); - mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(lableIdx); - brTrueStmt->SetOffset(lableIdx); - blk->AddStatement(brTrueStmt); - blk->AppendStatementsFromBlock(*ifStmt.GetElsePart()); - LabelNode *lableStmt = mirModule.CurFuncCodeMemPool()->New(); - lableStmt->SetLabelIdx(lableIdx); - blk->AddStatement(lableStmt); + CreateBrTrueStmt(*blk, ifStmt); } else { // brfalse // @@ -73,35 +110,7 @@ BlockNode *MIRLower::LowerIfStmt(IfStmtNode &ifStmt, bool recursive) { // label // // label - CondGotoNode *brFalseStmt = mirModule.CurFuncCodeMemPool()->New(OP_brfalse); - brFalseStmt->SetOpnd(ifStmt.Opnd()); - brFalseStmt->SetSrcPos(ifStmt.GetSrcPos()); - LabelIdx lIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); - (void)mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(lIdx); - brFalseStmt->SetOffset(lIdx); - blk->AddStatement(brFalseStmt); - blk->AppendStatementsFromBlock(*ifStmt.GetThenPart()); - ASSERT(ifStmt.GetThenPart()->GetLast()->GetOpCode() != OP_brtrue, "then or else block should not end with brtrue"); - ASSERT(ifStmt.GetThenPart()->GetLast()->GetOpCode() != OP_brfalse, - "then or else block should not end with brfalse"); - bool fallThroughFromThen = !IfStmtNoFallThrough(ifStmt); - LabelIdx gotoLableIdx = 0; - if (fallThroughFromThen) { - GotoNode *gotoStmt = mirModule.CurFuncCodeMemPool()->New(OP_goto); - gotoLableIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); - (void)mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(gotoLableIdx); - gotoStmt->SetOffset(gotoLableIdx); - blk->AddStatement(gotoStmt); - } - LabelNode *lableStmt = mirModule.CurFuncCodeMemPool()->New(); - lableStmt->SetLabelIdx(lIdx); - blk->AddStatement(lableStmt); - blk->AppendStatementsFromBlock(*ifStmt.GetElsePart()); - if (fallThroughFromThen) { - lableStmt = mirModule.CurFuncCodeMemPool()->New(); - lableStmt->SetLabelIdx(gotoLableIdx); - blk->AddStatement(lableStmt); - } + CreateBrFalseAndGotoStmt(*blk, ifStmt); } return blk; } @@ -245,7 +254,7 @@ BlockNode *MIRLower::LowerDowhileStmt(WhileStmtNode &doWhileStmt) { BlockNode *MIRLower::LowerBlock(BlockNode &block) { BlockNode *newBlock = mirModule.CurFuncCodeMemPool()->New(); BlockNode *tmp = nullptr; - if (!block.GetFirst()) { + if (block.GetFirst() == nullptr) { return newBlock; } StmtNode *nextStmt = block.GetFirst(); @@ -284,7 +293,7 @@ BlockNode *MIRLower::LowerBlock(BlockNode &block) { // for lowering OP_cand and OP_cior that are top level operators in the // condition operand of OP_brfalse and OP_brtrue void MIRLower::LowerBrCondition(BlockNode &block) { - if (!block.GetFirst()) { + if (block.GetFirst() == nullptr) { return; } StmtNode *nextStmt = block.GetFirst(); @@ -344,31 +353,31 @@ void MIRLower::LowerFunc(MIRFunction &func) { } IfStmtNode *MIRLower::ExpandArrayMrtIfBlock(IfStmtNode &node) { - if (node.GetThenPart()) { + if (node.GetThenPart() != nullptr) { node.SetThenPart(ExpandArrayMrtBlock(*node.GetThenPart())); } - if (node.GetElsePart()) { + if (node.GetElsePart() != nullptr) { node.SetElsePart(ExpandArrayMrtBlock(*node.GetElsePart())); } return &node; } WhileStmtNode *MIRLower::ExpandArrayMrtWhileBlock(WhileStmtNode &node) { - if (node.GetBody()) { + if (node.GetBody() != nullptr) { node.SetBody(ExpandArrayMrtBlock(*node.GetBody())); } return &node; } DoloopNode *MIRLower::ExpandArrayMrtDoloopBlock(DoloopNode &node) { - if (node.GetDoBody()) { + if (node.GetDoBody() != nullptr) { node.SetDoBody(ExpandArrayMrtBlock(*node.GetDoBody())); } return &node; } ForeachelemNode *MIRLower::ExpandArrayMrtForeachelemBlock(ForeachelemNode &node) { - if (node.GetLoopBody()) { + if (node.GetLoopBody() != nullptr) { node.SetLoopBody(ExpandArrayMrtBlock(*node.GetLoopBody())); } return &node; @@ -426,7 +435,7 @@ void MIRLower::AddArrayMrtMpl(BaseNode &exp, BlockNode &newBlock) { BlockNode *MIRLower::ExpandArrayMrtBlock(BlockNode &block) { BlockNode *newBlock = mirModule.CurFuncCodeMemPool()->New(); - if (!block.GetFirst()) { + if (block.GetFirst() == nullptr) { return newBlock; } StmtNode *nextStmt = block.GetFirst(); diff --git a/src/maple_ir/src/mir_nodes.cpp b/src/maple_ir/src/mir_nodes.cpp index 2778fd5cb23c837fbbc34cd85ac30c71de96f656..a4dbe2c806abceb698837a3eae4fd03f4eac2f0f 100644 --- a/src/maple_ir/src/mir_nodes.cpp +++ b/src/maple_ir/src/mir_nodes.cpp @@ -421,7 +421,7 @@ MIRType *ArrayNode::GetArrayType(TypeTable &tt) const { BaseNode *ArrayNode::GetDim(const MIRModule &mod, TypeTable &tt, int i) { MIRArrayType *arrayType = static_cast(GetArrayType(tt)); - MIRConst *mirConst = mod.CurFuncCodeMemPool()->New(tt.GetTypeFromTyIdx(arrayType->GetElemTyIdx())); + MIRConst *mirConst = mod.CurFuncCodeMemPool()->New(*tt.GetTypeFromTyIdx(arrayType->GetElemTyIdx())); return mod.CurFuncCodeMemPool()->New(mirConst); } @@ -462,7 +462,7 @@ void IntrinsicopNode::Dump(const MIRModule &mod, int32 indent) const { } void ConstvalNode::Dump(const MIRModule &mod, int32 indent) const { - if (GetConstVal()->GetType()->GetKind() != kTypePointer) { + if (GetConstVal()->GetType().GetKind() != kTypePointer) { BaseNode::DumpBase(mod, 0); LogInfo::MapleLogger() << " "; } diff --git a/src/maple_ir/src/mir_parser.cpp b/src/maple_ir/src/mir_parser.cpp index dce2eed889666f6cc29044d8816fa9528eb89e54..afee5adb5342aa7f1dbee602bdf87b611c697206 100644 --- a/src/maple_ir/src/mir_parser.cpp +++ b/src/maple_ir/src/mir_parser.cpp @@ -1306,7 +1306,7 @@ bool MIRParser::ParseNaryStmt(StmtNodePtr &stmt, Opcode op) { } else { MIRType *inttype = GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_i32); // default 2 for __sync_enter_fast() - MIRIntConst *intconst = mod.GetMemPool()->New(2, inttype); + MIRIntConst *intconst = mod.GetMemPool()->New(2, *inttype); ConstvalNode *exprconst = mod.GetMemPool()->New(); exprconst->SetPrimType(PTY_i32); exprconst->SetConstVal(intconst); @@ -2588,7 +2588,7 @@ bool MIRParser::ParseScalarValue(MIRConstPtr &stype, MIRType *type) { Error("constant value incompatible with integer type at "); return false; } - stype = mod.GetMemPool()->New(lexer.GetTheIntVal(), type); + stype = mod.GetMemPool()->New(lexer.GetTheIntVal(), *type); } else if (ptp == PTY_f32) { if (lexer.GetTokenKind() != kTkFloatconst) { Error("constant value incompatible with single-precision float type at "); @@ -2630,7 +2630,7 @@ bool MIRParser::ParseConstAddrLeafExpr(MIRConstPtr &cexpr, MIRType &type) { MIRPtrType ptrtype(ptyidx, (mod.IsJavaModule() ? PTY_ref : PTY_ptr)); ptyidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&ptrtype); MIRType *exprty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptyidx); - cexpr = mod.CurFuncCodeMemPool()->New(anode->GetStIdx(), anode->GetFieldID(), exprty); + cexpr = mod.CurFuncCodeMemPool()->New(anode->GetStIdx(), anode->GetFieldID(), *exprty); } else if (expr->GetOpCode() == OP_addroffunc) { AddroffuncNode *aof = static_cast(expr); MIRFunction *f = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(aof->GetPUIdx()); @@ -2639,7 +2639,7 @@ bool MIRParser::ParseConstAddrLeafExpr(MIRConstPtr &cexpr, MIRType &type) { MIRPtrType ptrtype(ptyidx); ptyidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&ptrtype); MIRType *exprty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptyidx); - cexpr = mod.CurFuncCodeMemPool()->New(aof->GetPUIdx(), exprty); + cexpr = mod.CurFuncCodeMemPool()->New(aof->GetPUIdx(), *exprty); } else if (expr->GetOpCode() == OP_conststr) { ConststrNode *cs = static_cast(expr); UStrIdx stridx = cs->GetStrIdx(); @@ -2647,7 +2647,7 @@ bool MIRParser::ParseConstAddrLeafExpr(MIRConstPtr &cexpr, MIRType &type) { MIRPtrType ptrtype(ptyidx); ptyidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&ptrtype); MIRType *exprty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptyidx); - cexpr = mod.CurFuncCodeMemPool()->New(stridx, exprty); + cexpr = mod.CurFuncCodeMemPool()->New(stridx, *exprty); } else { Conststr16Node *cs = static_cast(expr); U16StrIdx stridx = cs->GetStrIdx(); @@ -2655,7 +2655,7 @@ bool MIRParser::ParseConstAddrLeafExpr(MIRConstPtr &cexpr, MIRType &type) { MIRPtrType ptrtype(ptyidx); ptyidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&ptrtype); MIRType *exprty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptyidx); - cexpr = mod.CurFuncCodeMemPool()->New(stridx, exprty); + cexpr = mod.CurFuncCodeMemPool()->New(stridx, *exprty); } return true; } diff --git a/src/maple_ir/src/parser.cpp b/src/maple_ir/src/parser.cpp index aa58ef73090c4923aefd586f7ea7c9ff09bc2aaf..8d61e39c8ceb19652adfdca177fa8e8b69d5c089 100644 --- a/src/maple_ir/src/parser.cpp +++ b/src/maple_ir/src/parser.cpp @@ -794,7 +794,7 @@ bool MIRParser::ParseFields(MIRStructType &type) { mod.AddExternStructType(tyidx); mod.GetTypeNameTab()->SetGStrIdxToTyIdx(strIdx, tyidx); } - classType->GetInerfaceImplemented().push_back(tyidx); + classType->GetInterfaceImplemented().push_back(tyidx); } if (tk == kTkComa) { tk = lexer.NextToken(); @@ -1386,10 +1386,10 @@ void MIRParser::FixupForwardReferencedTypeByMap() { if (it != typeDefIdxMap.end()) { classType->GetParentTyIdx() = it->second; } - for (size_t j = 0; j < classType->GetInerfaceImplemented().size(); j++) { - std::map::iterator it2 = typeDefIdxMap.find(classType->GetNthInerfaceImplemented(j)); + for (size_t j = 0; j < classType->GetInterfaceImplemented().size(); j++) { + std::map::iterator it2 = typeDefIdxMap.find(classType->GetNthInterfaceImplemented(j)); if (it2 != typeDefIdxMap.end()) { - classType->SetNthInerfaceImplemented(j, it2->second); + classType->SetNthInterfaceImplemented(j, it2->second); } } } else if (type->GetKind() == kTypeInterface || type->GetKind() == kTypeInterfaceIncomplete) { @@ -1943,18 +1943,17 @@ bool MIRParser::ParseFunction(uint32 fileIdx) { bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { TokenKind tokenKind = lexer.GetTokenKind(); - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); - ASSERT(type != nullptr, "type is null"); + MIRType &type = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); if (tokenKind != kTkLbrack) { // scalar MIRConst *mirConst = nullptr; if (IsConstValue(tokenKind)) { - if (!ParseScalarValue(mirConst, type)) { + if (!ParseScalarValue(mirConst, &type)) { Error("ParseInitValue expect scalar value"); return false; } lexer.NextToken(); } else if (IsConstAddrExpr(tokenKind)) { - if (!ParseConstAddrLeafExpr(mirConst, *type)) { + if (!ParseConstAddrLeafExpr(mirConst, type)) { Error("ParseInitValue expect const addr expr"); return false; } @@ -1964,10 +1963,10 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { } theConst = mirConst; } else { // aggregates - if (type->GetKind() == kTypeArray) { - MIRArrayType *arrayType = static_cast(type); - MIRType *elemType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(arrayType->GetElemTyIdx()); - MIRAggConst *newConst = mod.GetMemPool()->New(&mod, type); + if (type.GetKind() == kTypeArray) { + MIRArrayType &arrayType = static_cast(type); + MIRType *elemType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(arrayType.GetElemTyIdx()); + MIRAggConst *newConst = mod.GetMemPool()->New(mod, type); theConst = newConst; MapleVector &constVec = newConst->GetConstVec(); tokenKind = lexer.NextToken(); @@ -1985,21 +1984,21 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { } lexer.NextToken(); } else if (IsConstAddrExpr(tokenKind)) { - if (!ParseConstAddrLeafExpr(subConst, *type)) { + if (!ParseConstAddrLeafExpr(subConst, type)) { Error("ParseInitValue expect const addr expr"); return false; } } else if (tokenKind == kTkLbrack) { - if (elemType->GetKind() == kTypeStruct && arrayType->GetDim() == 1) { - if (!ParseInitValue(subConst, arrayType->GetElemTyIdx())) { + if (elemType->GetKind() == kTypeStruct && arrayType.GetDim() == 1) { + if (!ParseInitValue(subConst, arrayType.GetElemTyIdx())) { Error("initializaton value wrong when parsing structure array "); return false; } } else { std::vector sizeSubArray; - ASSERT(arrayType->GetDim() > 1, "array dim must large then 1"); - for (uint16 i = 1; i < arrayType->GetDim(); i++) { - sizeSubArray.push_back(arrayType->GetSizeArrayItem(i)); + ASSERT(arrayType.GetDim() > 1, "array dim must large then 1"); + for (uint16 i = 1; i < arrayType.GetDim(); i++) { + sizeSubArray.push_back(arrayType.GetSizeArrayItem(i)); } MIRArrayType subArraytype(elemType->GetTypeIndex(), sizeSubArray); TyIdx arrayTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&subArraytype); @@ -2024,8 +2023,8 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { } } while (tokenKind != kTkRbrack); lexer.NextToken(); - } else if (type->GetKind() == kTypeStruct) { - MIRAggConst *newConst = mod.GetMemPool()->New(&mod, type); + } else if (type.GetKind() == kTypeStruct) { + MIRAggConst *newConst = mod.GetMemPool()->New(mod, type); uint32 theFieldID; TyIdx fieldTyIdx; theConst = newConst; @@ -2045,7 +2044,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { Error("expect = after field ID in struct initialization but get "); return false; } - fieldTyIdx = static_cast(type)->GetFieldTyIdx(theFieldID); + fieldTyIdx = static_cast(type).GetFieldTyIdx(theFieldID); if (fieldTyIdx == 0) { Error("field ID out of range at struct initialization at "); return false; @@ -2059,7 +2058,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { } lexer.NextToken(); } else if (IsConstAddrExpr(tokenKind)) { - if (!ParseConstAddrLeafExpr(subConst, *type)) { + if (!ParseConstAddrLeafExpr(subConst, type)) { Error("ParseInitValue expect const addr expr"); return false; } diff --git a/src/maple_me/include/bb.h b/src/maple_me/include/bb.h index cbc7f657bd7a4ffc690cec711c8b54986c3c188c..3ae79679b10a75e72c45ab923cd3eaf9abf3419e 100644 --- a/src/maple_me/include/bb.h +++ b/src/maple_me/include/bb.h @@ -409,6 +409,49 @@ class BB { StmtNodes stmtNodeList; MeStmts meStmtList; }; +class SCCOfBBs { + public: + SCCOfBBs(uint32 index, BB *bb, MapleAllocator *alloc) + : id(index), + entry(bb), + bbs(alloc->Adapter()), + predSCC(std::less(), alloc->Adapter()), + succSCC(std::less(), alloc->Adapter()) {} + void Dump(); + void Verify(MapleVector &sccOfBB); + void SetUp(MapleVector &sccOfBB); + bool HasCycle() const; + void AddBBNode(BB *bb) { + bbs.push_back(bb); + } + void Clear() { + bbs.clear(); + } + uint32 GetID() const { + return id; + } + const MapleVector &GetBBs() const { + return bbs; + } + const MapleSet &GetSucc() const { + return succSCC; + } + const MapleSet &GetPred() const { + return predSCC; + } + bool HasPred() const { + return (predSCC.size() != 0); + } + BB *GetEntry() { + return entry; + } + private: + uint32 id; + BB *entry; + MapleVector bbs; + MapleSet predSCC; + MapleSet succSCC; +}; } // namespace maple namespace std { diff --git a/src/maple_me/include/me_function.h b/src/maple_me/include/me_function.h index d2475e0069b0bbb28c3ef6d1211af0ebf766807c..f375ac76f1726f80320ad2e55802028a316a9051 100644 --- a/src/maple_me/include/me_function.h +++ b/src/maple_me/include/me_function.h @@ -162,6 +162,9 @@ class MeFunction : public FuncEmit { bbVec(alloc.Adapter()), bbTryNodeMap(alloc.Adapter()), endTryBB2TryBB(alloc.Adapter()), + sccTopologicalVec(alloc.Adapter()), + sccOfBB(GetAllBBs().size(), nullptr, alloc.Adapter()), + backEdges(alloc.Adapter()), fileName(fileName) {} virtual ~MeFunction() = default; @@ -444,7 +447,16 @@ class MeFunction : public FuncEmit { void PartialInit(bool isSecondPass); + const MapleVector &GetSccTopologicalVec() const { + return sccTopologicalVec; + } + void BBTopologicalSort(SCCOfBBs *scc); + void BuildSCC(); private: + void VerifySCC(); + void SCCTopologicalSort(std::vector &sccNodes); + void BuildSCCDFS(BB *bb, uint32 &visitIndex, std::vector &sccNodes, std::vector &visitedOrder, + std::vector &lowestOrder, std::vector &inStack, std::stack &visitStack); void CreateBasicBlocks(); void SetTryBlockInfo(const StmtNode *nextStmt, StmtNode *tryStmt, BB *lastTryBB, BB *curBB, BB *newBB); void RemoveEhEdgesInSyncRegion(); @@ -467,6 +479,11 @@ class MeFunction : public FuncEmit { MeIRMap *irmap = nullptr; MapleUnorderedMap bbTryNodeMap; // maps isTry bb to its try stmt MapleUnorderedMap endTryBB2TryBB; // maps endtry bb to its try bb + // BB SCC + MapleVector sccTopologicalVec; + uint32 numOfSCCs = 0; + MapleVector sccOfBB; + MapleSet> backEdges; /* input */ std::string fileName; uint32 regNum = 0; // count virtual registers diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h index ae21b716d95ff67092b47398ecc335443dbe116e..bae657562c160cf878ff542d11bba049225bf3f8 100644 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -1093,7 +1093,7 @@ class MeStmt { } virtual void Dump(IRMap*) const; - MeStmt *GetNextMeStmt(); + MeStmt *GetNextMeStmt() const; virtual size_t NumMeStmtOpnds() const { return 0; } @@ -1168,11 +1168,11 @@ class MeStmt { virtual void DisableNeedIncref() {} - virtual MeExpr *GetLHS() { + virtual MeExpr *GetLHS() const { return nullptr; } - virtual MeExpr *GetRHS() { + virtual MeExpr *GetRHS() const { return nullptr; } @@ -1243,11 +1243,11 @@ class MeStmt { next = n; } - MeStmt *GetPrev() { + MeStmt *GetPrev() const { return prev; } - MeStmt *GetNext() { + MeStmt *GetNext() const { return next; } @@ -1510,7 +1510,7 @@ class DassignMeStmt : public MeStmt { } void Dump(IRMap*) const; - MeExpr *GetLHS() { + MeExpr *GetLHS() const { return lhs; } @@ -1518,7 +1518,7 @@ class DassignMeStmt : public MeStmt { lhs = value; } - MeExpr *GetRHS() { + MeExpr *GetRHS() const { return rhs; } @@ -1587,11 +1587,11 @@ class RegassignMeStmt : public MeStmt { needIncref = false; } - MeExpr *GetLHS() { + MeExpr *GetLHS() const { return lhs; } - MeExpr *GetRHS() { + MeExpr *GetRHS() const { return rhs; } @@ -1689,11 +1689,11 @@ class MaydassignMeStmt : public MeStmt { } void Dump(IRMap*) const; - MeExpr *GetLHS() { + MeExpr *GetLHS() const { return chiList.begin()->second->GetLHS(); } - MeExpr *GetRHS() { + MeExpr *GetRHS() const { return rhs; } @@ -1802,11 +1802,11 @@ class IassignMeStmt : public MeStmt { } void Dump(IRMap*) const; - MeExpr *GetLHS() { + MeExpr *GetLHS() const { return lhsVar; } - MeExpr *GetRHS() { + MeExpr *GetRHS() const { return rhs; } diff --git a/src/maple_me/include/me_rc_lowering.h b/src/maple_me/include/me_rc_lowering.h index f13ff520e859d6f03f2afe8a696295b250dc2196..2c1b0e78d55f5b93e23f86378ebdbb89dcc9e82f 100644 --- a/src/maple_me/include/me_rc_lowering.h +++ b/src/maple_me/include/me_rc_lowering.h @@ -60,10 +60,10 @@ class RCLowering { VarMeExpr *CreateVarMeExprFromSym(MIRSymbol &sym) const; // return true if the rhs is simple so we can adjust RC count before assignments bool RCFirst(MeExpr &rhs); - IntrinsiccallMeStmt *GetVarRHSHandleStmt(MeStmt &stmt); - IntrinsiccallMeStmt *GetIvarRHSHandleStmt(MeStmt &stmt); - MIRIntrinsicID PrepareVolatileCall(MeStmt &stmt, MIRIntrinsicID index = INTRN_UNDEFINED); - IntrinsiccallMeStmt *CreateRCIntrinsic(MIRIntrinsicID intrnID, MeStmt &stmt, std::vector &opnds, + IntrinsiccallMeStmt *GetVarRHSHandleStmt(const MeStmt &stmt); + IntrinsiccallMeStmt *GetIvarRHSHandleStmt(const MeStmt &stmt); + MIRIntrinsicID PrepareVolatileCall(const MeStmt &stmt, const MIRIntrinsicID index = INTRN_UNDEFINED); + IntrinsiccallMeStmt *CreateRCIntrinsic(const MIRIntrinsicID intrnID, const MeStmt &stmt, std::vector &opnds, bool assigned = false); void InitializedObjectFields(MeStmt &stmt); bool IsInitialized(IvarMeExpr &ivar); @@ -87,7 +87,7 @@ class RCLowering { void HandleReturnNeedBackup(); void HandleReturnStmt(); void HandleAssignMeStmt(MeStmt &stmt, MeExpr *pendingDec); - MIRIntrinsicID SelectWriteBarrier(MeStmt &stmt); + MIRIntrinsicID SelectWriteBarrier(const MeStmt &stmt); private: MeFunction &func; diff --git a/src/maple_me/src/bb.cpp b/src/maple_me/src/bb.cpp index 22bc1721766f907413018d67ad0b432637182c6c..aecb151c49d8b9c683c391831c95c9615c086e0f 100644 --- a/src/maple_me/src/bb.cpp +++ b/src/maple_me/src/bb.cpp @@ -352,4 +352,52 @@ void BB::DumpMeRegPhiList(IRMap *irMap) { (*phiIt).second->Dump(irMap); } } + +void SCCOfBBs::Dump() { + std::cout << "SCC " << id << " contains" << std::endl; + for (BB *bb : bbs) { + std::cout << "bb(" << bb->UintID() << ") "; + } + std::cout << std::endl; +} + +bool SCCOfBBs::HasCycle() const { + CHECK_FATAL(bbs.size() > 0, "should have bbs in the scc"); + if (bbs.size() > 1) { + return true; + } + BB *bb = bbs[0]; + for (BB *succ : bb->GetSucc()) { + if (succ == bb) { + return true; + } + } + return false; +} + +void SCCOfBBs::Verify(MapleVector &sccOfBB) { + CHECK_FATAL(bbs.size() > 0, "should have bbs in the scc"); + for (BB *bb : bbs) { + SCCOfBBs *scc = sccOfBB.at(bb->UintID()); + CHECK_FATAL(scc == this, ""); + } +} + +void SCCOfBBs::SetUp(MapleVector &sccOfBB) { + for (BB *bb : bbs) { + for (BB *succ : bb->GetSucc()) { + if (succ == nullptr || sccOfBB.at(succ->UintID()) == this) { + continue; + } + succSCC.insert(sccOfBB[succ->UintID()]); + } + + for (BB *pred : bb->GetPred()) { + if (pred == nullptr || sccOfBB.at(pred->UintID()) == this) { + continue; + } + predSCC.insert(sccOfBB[pred->UintID()]); + } + } +} } // namespace maple diff --git a/src/maple_me/src/irmap.cpp b/src/maple_me/src/irmap.cpp index 6cd3758c7325994b9fda03029a5e3a0cd20a2b87..7dc542780304bf489e93009e09900e87aec52d3a 100644 --- a/src/maple_me/src/irmap.cpp +++ b/src/maple_me/src/irmap.cpp @@ -1284,7 +1284,7 @@ MeExpr *IRMap::CreateConstMeExpr(PrimType ptyp, MIRConst &mirConst) { MeExpr *IRMap::CreateIntConstMeExpr(int64 value, PrimType ptyp) { MIRIntConst *intConst = - mirModule.GetMemPool()->New(value, GlobalTables::GetTypeTable().GetPrimType(ptyp)); + mirModule.GetMemPool()->New(value, *GlobalTables::GetTypeTable().GetPrimType(ptyp)); return CreateConstMeExpr(ptyp, *intConst); } diff --git a/src/maple_me/src/me_function.cpp b/src/maple_me/src/me_function.cpp index b391087d679d8497e547396bedb2f6b000c0e380..f645469950bb3d6c43c2f7a4e30dc24b3e3dc895 100644 --- a/src/maple_me/src/me_function.cpp +++ b/src/maple_me/src/me_function.cpp @@ -608,4 +608,154 @@ void MeFunction::RemoveEhEdgesInSyncRegion() { } } } + +void MeFunction::BuildSCCDFS(BB *bb, uint32 &visitIndex, std::vector &sccNodes, + std::vector &visitedOrder, std::vector &lowestOrder, + std::vector &inStack, std::stack &visitStack) { + uint32 id = bb->UintID(); + visitedOrder[id] = visitIndex; + lowestOrder[id] = visitIndex; + visitIndex++; + visitStack.push(id); + inStack[id] = true; + + for (BB *succ : bb->GetSucc()){ + if (succ == nullptr) { + continue; + } + uint32 succId = succ->UintID(); + if (!visitedOrder[succId]) { + BuildSCCDFS(succ, visitIndex, sccNodes, visitedOrder, lowestOrder, inStack, visitStack); + if (lowestOrder[succId] < lowestOrder[id]) { + lowestOrder[id] = lowestOrder[succId]; + } + } else if (inStack[succId]) { + backEdges.insert(std::pair(id, succId)); + if (visitedOrder[succId] < lowestOrder[id]) { + lowestOrder[id] = visitedOrder[succId]; + } + } + } + + if (visitedOrder.at(id) == lowestOrder.at(id)) { + SCCOfBBs *sccNode = alloc.GetMemPool()->New(numOfSCCs++, bb, &alloc); + uint32 stackTopId; + do { + stackTopId = visitStack.top(); + visitStack.pop(); + inStack[stackTopId] = false; + BB *topBB = static_cast(GetAllBBs()[stackTopId]); + sccNode->AddBBNode(topBB); + sccOfBB[stackTopId] = sccNode; + } while (stackTopId != id); + + sccNodes.push_back(sccNode); + } +} + +void MeFunction::VerifySCC() { + for (BB *bb : GetAllBBs()) { + if (bb == nullptr || bb == GetCommonExitBB()) { + continue; + } + SCCOfBBs *scc = sccOfBB.at(bb->UintID()); + CHECK_FATAL(scc != nullptr, "bb should belong to a scc"); + } +} + +void MeFunction::BuildSCC() { + std::vector visitedOrder(GetAllBBs().size(), 0); + std::vector lowestOrder(GetAllBBs().size(), 0); + std::vector inStack(GetAllBBs().size(), false); + std::vector sccNodes; + uint32 visitIndex = 1; + std::stack visitStack; + + // Starting from common entry bb for DFS + BuildSCCDFS(GetCommonEntryBB(), visitIndex, sccNodes, visitedOrder, lowestOrder, inStack, visitStack); + + for (SCCOfBBs *scc : sccNodes) { + scc->Verify(sccOfBB); + scc->SetUp(sccOfBB); + } + + VerifySCC(); + SCCTopologicalSort(sccNodes); +} + +void MeFunction::SCCTopologicalSort(std::vector &sccNodes) { + std::set InQueue; + for (SCCOfBBs *node : sccNodes) { + if (!node->HasPred()) { + sccTopologicalVec.push_back(node); + InQueue.insert(node); + } + } + + // Top-down iterates all nodes + for (size_t i = 0; i < sccTopologicalVec.size(); i++) { + SCCOfBBs *scc = sccTopologicalVec[i]; + for (SCCOfBBs *succ : scc->GetSucc()) { + if (InQueue.find(succ) == InQueue.end()) { + // successor has not been visited + bool predAllVisited = true; + // check whether all predecessors of the current successor have been visited + for (SCCOfBBs *pred : succ->GetPred()) { + if (InQueue.find(pred) == InQueue.end()) { + predAllVisited = false; + break; + } + } + if (predAllVisited) { + sccTopologicalVec.push_back(succ); + InQueue.insert(succ); + } + } + } + } +} + +void MeFunction::BBTopologicalSort(SCCOfBBs *scc) { + std::set InQueue; + std::vector bbs; + for (BB *bb : scc->GetBBs()) { + bbs.push_back(bb); + } + scc->Clear(); + scc->AddBBNode(scc->GetEntry()); + InQueue.insert(scc->GetEntry()); + + for (size_t i = 0; i < scc->GetBBs().size(); i++) { + BB *bb = scc->GetBBs()[i]; + for (BB *succ : bb->GetSucc()) { + if (succ == nullptr) { + continue; + } + if (InQueue.find(succ) != InQueue.end() || + std::find(bbs.begin(), bbs.end(), succ) == bbs.end()) { + continue; + } + bool predAllVisited = true; + for (BB *pred : succ->GetPred()) { + if (pred == nullptr) { + continue; + } + if (std::find(bbs.begin(), bbs.end(), pred) == bbs.end()) { + continue; + } + if (backEdges.find(std::pair(pred->UintID(), succ->UintID())) != backEdges.end()) { + continue; + } + if (InQueue.find(pred) == InQueue.end()) { + predAllVisited = false; + break; + } + } + if (predAllVisited) { + scc->AddBBNode(succ); + InQueue.insert(succ); + } + } + } +} } // namespace maple diff --git a/src/maple_me/src/me_ir.cpp b/src/maple_me/src/me_ir.cpp index 56974f117faa8b71eb471f687b352429db0d8e55..e37cb78f5bc753b8d54ee018288378cdc5b93e09 100644 --- a/src/maple_me/src/me_ir.cpp +++ b/src/maple_me/src/me_ir.cpp @@ -751,7 +751,7 @@ void MeStmt::Dump(IRMap *irMap) const { } // get the real next mestmt that is not a comment -MeStmt *MeStmt::GetNextMeStmt() { +MeStmt *MeStmt::GetNextMeStmt() const { MeStmt *nextMeStmt = next; while (nextMeStmt != nullptr && nextMeStmt->op == OP_comment) { nextMeStmt = nextMeStmt->next; diff --git a/src/maple_me/src/me_phase_manager.cpp b/src/maple_me/src/me_phase_manager.cpp index 6bde8185f619b7f064acd5c00de425207bc03def..636f1b7125602183eab3ad291a15adfd0a5a4a1b 100644 --- a/src/maple_me/src/me_phase_manager.cpp +++ b/src/maple_me/src/me_phase_manager.cpp @@ -48,7 +48,7 @@ void MeFuncPhaseManager::RunFuncPhase(MeFunction *func, MeFuncPhase *phase) { } if (r != nullptr) { /* if phase is an analysis Phase, add result to arm */ - arFuncManager.AddResult(phase->GetPhaseId(), func, r); + arFuncManager.AddResult(phase->GetPhaseId(), *func, *r); } } @@ -58,13 +58,13 @@ void MeFuncPhaseManager::RegisterFuncPhases() { do { \ void *buf = GetMemAllocator()->GetMemPool()->Malloc(sizeof(mephase(id))); \ CHECK_FATAL(buf != nullptr, "null ptr check"); \ - RegisterPhase(id, (new (buf) mephase(id))); \ + RegisterPhase(id, *(new (buf) mephase(id))); \ } while (0); #define FUNCAPHASE(id, mephase) \ do { \ void *buf = GetMemAllocator()->GetMemPool()->Malloc(sizeof(mephase(id))); \ CHECK_FATAL(buf != nullptr, "null ptr check"); \ - RegisterPhase(id, (new (buf) mephase(id))); \ + RegisterPhase(id, *(new (buf) mephase(id))); \ arFuncManager.AddAnalysisPhase(id, (static_cast(GetPhase(id)))); \ } while (0); #include "me_phases.def" diff --git a/src/maple_me/src/me_rc_lowering.cpp b/src/maple_me/src/me_rc_lowering.cpp index 4c37e11977f4ac47976eedcf4e5aa9921bb12e13..4702425e190e03ce4d15a4b3ca95f89c197af53e 100644 --- a/src/maple_me/src/me_rc_lowering.cpp +++ b/src/maple_me/src/me_rc_lowering.cpp @@ -51,10 +51,10 @@ void RCLowering::PreRCLower() { } void RCLowering::MarkLocalRefVar() { - MIRFunction *mirfunction = func.GetMirFunc(); - size_t bsize = mirfunction->GetSymTab()->GetSymbolTableSize(); + MIRFunction *mirFunction = func.GetMirFunc(); + size_t bsize = mirFunction->GetSymTab()->GetSymbolTableSize(); for (size_t i = 0; i < bsize; ++i) { - MIRSymbol *sym = mirfunction->GetSymTab()->GetSymbolFromStIdx(i); + MIRSymbol *sym = mirFunction->GetSymTab()->GetSymbolFromStIdx(i); if (sym != nullptr && sym->GetStorageClass() == kScAuto && !sym->IgnoreRC()) { sym->SetLocalRefVar(); } @@ -113,8 +113,8 @@ VarMeExpr *RCLowering::CreateVarMeExprFromSym(MIRSymbol &sym) const { } // note that RCInstrinsic creation will check the ref assignment and reuse lhs if possible -IntrinsiccallMeStmt *RCLowering::CreateRCIntrinsic(MIRIntrinsicID intrnID, MeStmt &stmt, std::vector &opnds, - bool assigned) { +IntrinsiccallMeStmt *RCLowering::CreateRCIntrinsic(const MIRIntrinsicID intrnID, const MeStmt &stmt, + std::vector &opnds, bool assigned) { IntrinsiccallMeStmt *intrn = nullptr; if (assigned) { MeExpr *ret = stmt.GetOp() == OP_regassign ? stmt.GetLHS() : irMap.CreateRegMeExpr(PTY_ref); @@ -126,7 +126,7 @@ IntrinsiccallMeStmt *RCLowering::CreateRCIntrinsic(MIRIntrinsicID intrnID, MeStm return intrn; } -MIRIntrinsicID RCLowering::PrepareVolatileCall(MeStmt &stmt, MIRIntrinsicID intrnId) { +MIRIntrinsicID RCLowering::PrepareVolatileCall(const MeStmt &stmt, const MIRIntrinsicID intrnId) { bool isLoad = (intrnId == INTRN_MCCLoadRefSVol || intrnId == INTRN_MCCLoadWeakVol || intrnId == INTRN_MCCLoadRefVol); if (isLoad) { CheckRemove(stmt.GetNext(), OP_membaracquire); @@ -137,7 +137,7 @@ MIRIntrinsicID RCLowering::PrepareVolatileCall(MeStmt &stmt, MIRIntrinsicID intr return intrnId; } -IntrinsiccallMeStmt *RCLowering::GetVarRHSHandleStmt(MeStmt &stmt) { +IntrinsiccallMeStmt *RCLowering::GetVarRHSHandleStmt(const MeStmt &stmt) { auto *var = static_cast(stmt.GetRHS()); const MIRSymbol *sym = ssaTab.GetMIRSymbolFromID(var->GetOStIdx()); if (!sym->IsGlobal() || sym->IsFinal()) { @@ -156,7 +156,7 @@ IntrinsiccallMeStmt *RCLowering::GetVarRHSHandleStmt(MeStmt &stmt) { return CreateRCIntrinsic(rcCallID, stmt, opnds, true); } -IntrinsiccallMeStmt *RCLowering::GetIvarRHSHandleStmt(MeStmt &stmt) { +IntrinsiccallMeStmt *RCLowering::GetIvarRHSHandleStmt(const MeStmt &stmt) { auto *ivar = static_cast(stmt.GetRHS()); if (ivar->IsFinal()) { return nullptr; @@ -402,7 +402,7 @@ bool RCLowering::IsInitialized(IvarMeExpr &ivar) { MIRType *baseType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ivar.GetTyIdx()); ASSERT(dynamic_cast(baseType) != nullptr, "unexpected type"); auto *ptype = static_cast(baseType)->GetPointedType(); - MIRClassType *classType = dynamic_cast(ptype); + auto *classType = dynamic_cast(ptype); return classType == nullptr || !classType->IsOwnField(fieldID); } @@ -457,7 +457,7 @@ void RCLowering::HandleAssignMeStmt(MeStmt &stmt, MeExpr *pendingDec) { * note that we are generating INTRN_MCCWriteNoRC so write_barrier is supported, * otherwise iassign would be enough. */ -MIRIntrinsicID RCLowering::SelectWriteBarrier(MeStmt &stmt) { +MIRIntrinsicID RCLowering::SelectWriteBarrier(const MeStmt &stmt) { bool incWithLHS = stmt.NeedIncref(); bool decWithLHS = stmt.NeedDecref(); MeExpr *lhs = stmt.GetLHS(); @@ -554,16 +554,16 @@ void RCLowering::BBLower(BB &bb) { OriginalSt *ost = ssaTab.GetOriginalStTable().FindOrCreatePregOriginalSt(-kSregThrownval, func.GetMirFunc()->GetPuidx()); ost->SetTyIdx(GlobalTables::GetTypeTable().GetPrimType(PTY_ref)->GetTypeIndex()); - RegMeExpr *regreadExpr = irMap.CreateRegMeExprVersion(*ost); - regreadExpr->SetPtyp(PTY_ref); + RegMeExpr *regReadExpr = irMap.CreateRegMeExprVersion(*ost); + regReadExpr->SetPtyp(PTY_ref); MeStmt *firstMeStmt = to_ptr(bb.GetMeStmts().begin()); - std::vector opnds = { regreadExpr }; + std::vector opnds = { regReadExpr }; IntrinsiccallMeStmt *decRefcall = CreateRCIntrinsic(INTRN_MCCDecRef, *firstMeStmt, opnds); bb.InsertMeStmtAfter(firstMeStmt, decRefcall); } } -IntrinsiccallMeStmt *FindCleanupIntrinsic(MeStmt &ret) { +IntrinsiccallMeStmt *FindCleanupIntrinsic(const MeStmt &ret) { auto &meStmts = ret.GetBB()->GetMeStmts(); for (auto iter = meStmts.rbegin(); iter != meStmts.rend(); ++iter) { if (CheckOp(to_ptr(iter), OP_intrinsiccall)) { @@ -737,8 +737,8 @@ void RCLowering::HandleReturnNeedBackup() { continue; } RegMeExpr *curTmp = irMap.CreateRegMeExpr(retVal->GetPrimType()); - MeStmt *regass = irMap.CreateRegassignMeStmt(*curTmp, *retVal, *ret->GetBB()); - ret->GetBB()->InsertMeStmtBefore(ret, regass); + MeStmt *regAssign = irMap.CreateRegassignMeStmt(*curTmp, *retVal, *ret->GetBB()); + ret->GetBB()->InsertMeStmtBefore(ret, regAssign); ret->SetOpnd(0, curTmp); } } @@ -760,7 +760,7 @@ void RCLowering::HandleArguments() { */ MIRFunction *mirFunc = func.GetMirFunc(); BB *firstBB = func.GetFirstBB(); - MeStmt *firstMestmt = to_ptr(firstBB->GetMeStmts().begin()); + MeStmt *firstMeStmt = to_ptr(firstBB->GetMeStmts().begin()); for (size_t i = (mirFunc->IsStatic() ? 0 : 1); i < mirFunc->GetFormalCount(); ++i) { MIRSymbol *sym = mirFunc->GetFormal(i); if (sym == nullptr || sym->IgnoreRC() || (!sym->IsGlobal() && assignedPtrSym.count(sym) == 0)) { @@ -769,10 +769,10 @@ void RCLowering::HandleArguments() { VarMeExpr *argVar = CreateVarMeExprFromSym(*sym); CHECK_FATAL(argVar != nullptr, "null ptr check"); IntrinsiccallMeStmt *incCall = nullptr; - if (firstMestmt != nullptr) { + if (firstMeStmt != nullptr) { std::vector opnds = { argVar }; - incCall = CreateRCIntrinsic(INTRN_MCCIncRef, *firstMestmt, opnds); - firstBB->InsertMeStmtBefore(firstMestmt, incCall); + incCall = CreateRCIntrinsic(INTRN_MCCIncRef, *firstMeStmt, opnds); + firstBB->InsertMeStmtBefore(firstMeStmt, incCall); } TypeAttrs typeAttr = mirFunc->GetNthParamAttr(i); typeAttr.SetAttr(ATTR_localrefvar); @@ -800,11 +800,11 @@ void RCLowering::Finish() { } } -OriginalSt *RCLowering::RetrieveOSt(const std::string &name, bool isLocalrefvar) const { +OriginalSt *RCLowering::RetrieveOSt(const std::string &name, bool isLocalRefVar) const { MIRSymbol *backupSym = mirModule.GetMIRBuilder()->GetOrCreateLocalDecl( name, *GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(PTY_ptr))); // use PTY_ptr for temp backupSym->SetIsTmp(true); - if (isLocalrefvar) { + if (isLocalRefVar) { backupSym->SetLocalRefVar(); } OriginalSt *ost = ssaTab.FindOrCreateSymbolOriginalSt(*backupSym, func.GetMirFunc()->GetPuidx(), 0); @@ -812,9 +812,9 @@ OriginalSt *RCLowering::RetrieveOSt(const std::string &name, bool isLocalrefvar) } // function for creating short-lived temp -VarMeExpr *RCLowering::CreateNewTmpVarMeExpr(bool isLocalrefvar) { +VarMeExpr *RCLowering::CreateNewTmpVarMeExpr(bool isLocalRefVar) { std::string name = std::string("__RCTemp__").append(std::to_string(++tmpCount)); - OriginalSt *ost = RetrieveOSt(name, isLocalrefvar); + OriginalSt *ost = RetrieveOSt(name, isLocalRefVar); if (ost->GetZeroVersionIndex() == 0) { ost->SetZeroVersionIndex(irMap.GetVerst2MeExprTableSize()); irMap.PushBackVerst2MeExprTable(nullptr); @@ -827,7 +827,7 @@ VarMeExpr *RCLowering::CreateNewTmpVarMeExpr(bool isLocalrefvar) { varMeExpr->SetFieldID(0); irMap.PushBackVerst2MeExprTable(varMeExpr); ost->PushbackVersionIndex(varMeExpr->GetVstIdx()); - if (isLocalrefvar) { + if (isLocalRefVar) { tmpLocalRefVars.insert(varMeExpr); } return varMeExpr; diff --git a/src/maple_phase/include/phase.h b/src/maple_phase/include/phase.h index 06ae295606f5fb7aea853db1f9b2b2a4eac5f826..c1fded6b4be94c0fc0d4860269ee19378a62b9ad 100644 --- a/src/maple_phase/include/phase.h +++ b/src/maple_phase/include/phase.h @@ -125,13 +125,12 @@ class AnalysisResultManager { } } - void AddResult(PhaseIDT id, UnitIR *ir, AnalysisResult *ar) { - ASSERT(ar != nullptr, "ar is null in AnalysisResultManager::AddResult"); - std::pair key = std::make_pair(id, ir); + void AddResult(PhaseIDT id, UnitIR &ir, AnalysisResult &ar) { + std::pair key = std::make_pair(id, &ir); if (analysisResults.find(key) != analysisResults.end()) { - InvalidAnalysisResult(id, ir); + InvalidAnalysisResult(id, &ir); } - analysisResults.insert(std::make_pair(key, ar)); + analysisResults.insert(std::make_pair(key, &ar)); } void InvalidAnalysisResult(PhaseIDT id, UnitIR *ir) { @@ -144,11 +143,11 @@ class AnalysisResultManager { } } - void InvalidIRbaseAnalysisResult(UnitIR *ir) { + void InvalidIRbaseAnalysisResult(UnitIR &ir) { PhaseIDT id; for (auto it = analysisPhases.begin(); it != analysisPhases.end(); it++) { id = it->first; - InvalidAnalysisResult(id, ir); + InvalidAnalysisResult(id, &ir); } } diff --git a/src/maple_phase/include/phase_impl.h b/src/maple_phase/include/phase_impl.h index 4c09a9f2ff04e32b026adfdd8f96ff51e58456f9..e31e47e14b9b8453991b599635b2deb6fe6fc15e 100644 --- a/src/maple_phase/include/phase_impl.h +++ b/src/maple_phase/include/phase_impl.h @@ -24,22 +24,22 @@ class FuncOptimizeImpl { virtual ~FuncOptimizeImpl(); // Each phase needs to implement its own Clone virtual FuncOptimizeImpl *Clone() = 0; - MIRModule *GetModule() { - return module; + MIRModule &GetMIRModule() { + return *module; } - const MIRModule *GetModule() const { - return module; + const MIRModule &GetMIRModule() const { + return *module; } virtual void ProcessFunc(MIRFunction *func); virtual void Finish() {} protected: - void SetCurrentFunction(MIRFunction *func) { - currFunc = func; + void SetCurrentFunction(MIRFunction &func) { + currFunc = &func; ASSERT(builder, "builder is null in FuncOptimizeImpl::SetCurrentFunction"); - module->SetCurFunction(func); + module->SetCurFunction(&func); } virtual void ProcessBlock(StmtNode &stmt); diff --git a/src/maple_phase/include/phase_manager.h b/src/maple_phase/include/phase_manager.h index f2eba40bb8ada3aed1925849e6cc60cc5cacc957..575be72887858b47cccc36ca4161332b9c71714b 100644 --- a/src/maple_phase/include/phase_manager.h +++ b/src/maple_phase/include/phase_manager.h @@ -41,11 +41,11 @@ class PhaseManager { CHECK_FATAL(false, "%s is not a valid phase name", pname.c_str()); } - void RegisterPhase(PhaseID id, Phase *p) { - registeredPhases[id] = p; + void RegisterPhase(PhaseID id, Phase &p) { + registeredPhases[id] = &p; } - Phase *GetPhaseFromName(const char *pname) { + Phase *GetPhaseFromName(const std::string &pname) { for (auto it = RegPhaseBegin(); it != RegPhaseEnd(); it++) { if (GetPhaseName(it) == pname) { return GetPhase(GetPhaseId(it)); diff --git a/src/mpl2mpl/src/class_hierarchy.cpp b/src/mpl2mpl/src/class_hierarchy.cpp index 924b1097f32481940591ae4eda187c6377876e09..cb7eaabe5ad61ee9aa15b7085510799c08b5de7d 100644 --- a/src/mpl2mpl/src/class_hierarchy.cpp +++ b/src/mpl2mpl/src/class_hierarchy.cpp @@ -18,14 +18,14 @@ #include "option.h" /* - * Class Hierarchy Anlysis + * Class Hierarchy Analysis * This phase is a foundation phase of compilation. This phase build * the class hierarchy for both this module and all modules it depends * on. So many phases rely on this phase's analysis result, such as * call graph, ssa and so on. * The main procedure shows as following. - * A. Based on the information read from mplts, it collect all class that - * declared in modules. And create a Klass for each class. + * A. Based on the information read from mplts, it collects all class that + * declared in modules. And creates a Klass for each class. * B. Fill class method info. Connect superclass<->subclass and * interface->implementation edges. * C. Tag All Throwable class and its child class. @@ -35,7 +35,7 @@ * E. Topological Sort * F. Based on Topological Sort Order, for each virtual method in a class, * we collect all its potential implementation. If the number of - * potential implementations is 1, it means all virtual call to this + * potential implementations is 1, it means all virtual calls to this * method can be easily devirtualized. */ @@ -181,7 +181,7 @@ bool Klass::ImplementsKlass() const { } MIRClassType *ctype = GetMIRClassType(); ASSERT(ctype != nullptr, "null ptr check"); - return (!ctype->GetInerfaceImplemented().empty()); + return (!ctype->GetInterfaceImplemented().empty()); } MapleVector *Klass::GetCandidates(GStrIdx mnameNoklassStridx) const { @@ -216,7 +216,7 @@ void Klass::CountVirtMethTopDown(const KlassHierarchy &kh) { MapleVector *superAndImplClasses = alloc->GetMemPool()->New>(alloc->Adapter()); // Add default methods of interface. Add them first because they have lowest // priorities compared with methods defined in classes - for (TyIdx const &tyidx : GetMIRClassType()->GetInerfaceImplemented()) { + for (TyIdx const &tyidx : GetMIRClassType()->GetInterfaceImplemented()) { Klass *interface = kh.GetKlassFromTyIdx(tyidx); if (interface != nullptr) { superAndImplClasses->push_back(interface); @@ -531,7 +531,7 @@ void KlassHierarchy::AddKlassRelationAndMethods() { MIRClassType *ctype = klass->GetMIRClassType(); ASSERT(ctype != nullptr, "null ptr check"); // Add interface relationship - for (TyIdx const &intfTyIdx : ctype->GetInerfaceImplemented()) { + for (TyIdx const &intfTyIdx : ctype->GetInterfaceImplemented()) { Klass *intfKlass = GetKlassFromTyIdx(intfTyIdx); if (intfKlass != nullptr) { intfKlass->AddImplKlass(klass); diff --git a/src/mpl2mpl/src/class_init.cpp b/src/mpl2mpl/src/class_init.cpp index bf91120ff6c29ea1482a49591ff78c7f6b9be331..cd002979bd2adff5ed1d1da55a3be57689602f6d 100644 --- a/src/mpl2mpl/src/class_init.cpp +++ b/src/mpl2mpl/src/class_init.cpp @@ -160,7 +160,7 @@ void ClassInit::ProcessFunc(MIRFunction *func) { MIRSymbol *ClassInit::GetClassInfo(const std::string &classname) { const std::string &classInfoName = CLASSINFO_PREFIX_STR + classname; MIRType *classInfoType = - GlobalTables::GetTypeTable().GetOrCreateClassType(NameMangler::kClassMetadataTypeName, *GetModule()); + GlobalTables::GetTypeTable().GetOrCreateClassType(NameMangler::kClassMetadataTypeName, GetMIRModule()); MIRSymbol *classInfo = builder->GetOrCreateGlobalDecl(classInfoName.c_str(), *classInfoType); Klass *klass = klassHierarchy->GetKlassFromName(classname); if (klass == nullptr || !klass->GetMIRStructType()->IsLocal()) { diff --git a/src/mpl2mpl/src/gen_check_cast.cpp b/src/mpl2mpl/src/gen_check_cast.cpp index 87e6dbdb0bcd689ffa47715547e21f7cbf1d2a54..1f7f550cd4e0281fa3a9591d564eb443fa255daf 100644 --- a/src/mpl2mpl/src/gen_check_cast.cpp +++ b/src/mpl2mpl/src/gen_check_cast.cpp @@ -38,7 +38,7 @@ CheckCastGenerator::CheckCastGenerator(MIRModule *mod, KlassHierarchy *kh, bool void CheckCastGenerator::InitTypes() { pointerObjType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*WKTypes::Util::GetJavaLangObjectType()); - classinfoType = GlobalTables::GetTypeTable().GetOrCreateClassType(NameMangler::kClassMetadataTypeName, *GetModule()); + classinfoType = GlobalTables::GetTypeTable().GetOrCreateClassType(NameMangler::kClassMetadataTypeName, GetMIRModule()); pointerClassMetaType = GlobalTables::GetTypeTable().GetOrCreatePointerType(*classinfoType); } @@ -61,7 +61,7 @@ MIRSymbol *CheckCastGenerator::GetOrCreateClassInfoSymbol(const std::string &cla GlobalTables::GetTypeTable().GetTypeFromTyIdx(GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(gStrIdx)); MIRStorageClass sclass = (classType && static_cast(classType)->IsLocal()) ? kScGlobal : kScExtern; // Creating global symbol needs synchronization. - classInfoSymbol = builder->CreateGlobalDecl(classInfoName.c_str(), GlobalTables::GetTypeTable().GetPtr(), sclass); + classInfoSymbol = builder->CreateGlobalDecl(classInfoName.c_str(), *GlobalTables::GetTypeTable().GetPtr(), sclass); } return classInfoSymbol; } @@ -159,7 +159,7 @@ void CheckCastGenerator::GenCheckCast(BaseNode &stmt) { std::string primClassinfoName = PRIMITIVECLASSINFO_PREFIX_STR + elementName; elemClassSt = builder->GetGlobalDecl(primClassinfoName.c_str()); if (elemClassSt == nullptr) { - elemClassSt = builder->CreateGlobalDecl(primClassinfoName.c_str(), GlobalTables::GetTypeTable().GetPtr()); + elemClassSt = builder->CreateGlobalDecl(primClassinfoName.c_str(), *GlobalTables::GetTypeTable().GetPtr()); } } else { elemClassSt = GetOrCreateClassInfoSymbol(elementName); @@ -279,9 +279,9 @@ void CheckCastGenerator::ProcessFunc(MIRFunction *func) { if (func->IsEmpty()) { return; } - SetCurrentFunction(func); + SetCurrentFunction(*func); GenAllCheckCast(); - MIRLower mirlowerer(*(GetModule()), func); + MIRLower mirlowerer(GetMIRModule(), func); mirlowerer.LowerFunc(*func); } } // namespace maple diff --git a/src/mpl2mpl/src/java_eh_lower.cpp b/src/mpl2mpl/src/java_eh_lower.cpp index 2c0abaa2b17a093dc75dfb2249a849d7fbdd2fa1..9971de35b27235b35eb220569c115d4323b3d5b3 100644 --- a/src/mpl2mpl/src/java_eh_lower.cpp +++ b/src/mpl2mpl/src/java_eh_lower.cpp @@ -37,8 +37,8 @@ JavaEHLowerer::JavaEHLowerer(MIRModule *mod, KlassHierarchy *kh, bool dump) : Fu BaseNode *JavaEHLowerer::DoLowerDiv(BinaryNode &expr, BlockNode &blknode) { PrimType ptype = expr.GetPrimType(); - MIRBuilder *mirBuilder = GetModule()->GetMIRBuilder(); - MIRFunction *func = GetModule()->CurFunction(); + MIRBuilder *mirBuilder = GetMIRModule().GetMIRBuilder(); + MIRFunction *func = GetMIRModule().CurFunction(); if (IsPrimitiveInteger(ptype)) { // Store divopnd to a tmp st if not a leaf node. BaseNode *divOpnd = expr.Opnd(1); @@ -52,7 +52,7 @@ BaseNode *JavaEHLowerer::DoLowerDiv(BinaryNode &expr, BlockNode &blknode) { divOpnd = mirBuilder->CreateExprRegread(ptype, pregIdx); } else { MIRSymbol *divOpndSymbol = mirBuilder->CreateSymbol(TyIdx(ptype), opnd1name.c_str(), kStVar, kScAuto, - GetModule()->CurFunction(), kScopeLocal); + GetMIRModule().CurFunction(), kScopeLocal); DassignNode *dssDivNode = mirBuilder->CreateStmtDassign(*divOpndSymbol, 0, divOpnd); blknode.AddStatement(dssDivNode); divOpnd = mirBuilder->CreateExprDread(*divOpndSymbol); @@ -64,15 +64,15 @@ BaseNode *JavaEHLowerer::DoLowerDiv(BinaryNode &expr, BlockNode &blknode) { if (useRegTmp) { PregIdx resPregIdx = func->GetPregTab()->CreatePreg(ptype); divStmt = mirBuilder->CreateStmtRegassign(ptype, resPregIdx, &expr); - retExprNode = GetModule()->GetMIRBuilder()->CreateExprRegread(ptype, resPregIdx); + retExprNode = GetMIRModule().GetMIRBuilder()->CreateExprRegread(ptype, resPregIdx); } else { std::string resName(strDivRes); resName.append(std::to_string(divSTIndex++)); MIRSymbol *divResSymbol = mirBuilder->CreateSymbol(TyIdx(ptype), resName.c_str(), kStVar, kScAuto, - GetModule()->CurFunction(), kScopeLocal); + GetMIRModule().CurFunction(), kScopeLocal); // Put expr result to dssnode. divStmt = mirBuilder->CreateStmtDassign(*divResSymbol, 0, &expr); - retExprNode = GetModule()->GetMIRBuilder()->CreateExprDread(*divResSymbol, 0); + retExprNode = GetMIRModule().GetMIRBuilder()->CreateExprDread(*divResSymbol, 0); } // Check if the second operand of the div expression is 0. // Inser if statement for high level ir. @@ -82,7 +82,7 @@ BaseNode *JavaEHLowerer::DoLowerDiv(BinaryNode &expr, BlockNode &blknode) { IfStmtNode *ifStmtNode = mirBuilder->CreateStmtIf(cmpNode); blknode.AddStatement(ifStmtNode); // Call the MCC_ThrowArithmeticException() that will never return. - MapleVector args(GetModule()->GetMIRBuilder()->GetCurrentFuncCodeMpAllocator()->Adapter()); + MapleVector args(GetMIRModule().GetMIRBuilder()->GetCurrentFuncCodeMpAllocator()->Adapter()); IntrinsiccallNode *intrinCallNode = mirBuilder->CreateStmtIntrinsicCall(INTRN_JAVA_THROW_ARITHMETIC, args); ifStmtNode->GetThenPart()->AddStatement(intrinCallNode); blknode.AddStatement(divStmt); @@ -112,25 +112,25 @@ BaseNode *JavaEHLowerer::DoLowerExpr(BaseNode &expr, BlockNode &curblk) { void JavaEHLowerer::DoLowerBoundaryCheck(IntrinsiccallNode &intrincall, BlockNode &newblk) { const size_t intrincallNopndSize = intrincall.GetNopndSize(); CHECK_FATAL(intrincallNopndSize > 0, "null ptr check"); - CondGotoNode *brFalseStmt = GetModule()->CurFuncCodeMemPool()->New(OP_brfalse); + CondGotoNode *brFalseStmt = GetMIRModule().CurFuncCodeMemPool()->New(OP_brfalse); brFalseStmt->SetOpnd(DoLowerExpr(*(intrincall.GetNopndAt(0)), newblk)); brFalseStmt->SetSrcPos(intrincall.GetSrcPos()); - LabelIdx lbidx = GetModule()->CurFunction()->GetLabelTab()->CreateLabel(); - GetModule()->CurFunction()->GetLabelTab()->AddToStringLabelMap(lbidx); + LabelIdx lbidx = GetMIRModule().CurFunction()->GetLabelTab()->CreateLabel(); + GetMIRModule().CurFunction()->GetLabelTab()->AddToStringLabelMap(lbidx); brFalseStmt->SetOffset(lbidx); newblk.AddStatement(brFalseStmt); - LabelNode *labStmt = GetModule()->CurFuncCodeMemPool()->New(); + LabelNode *labStmt = GetMIRModule().CurFuncCodeMemPool()->New(); labStmt->SetLabelIdx(lbidx); MIRFunction *func = - GetModule()->GetMIRBuilder()->GetOrCreateFunction(strMCCThrowArrayIndexOutOfBoundsException, TyIdx(PTY_void)); - MapleVector args(GetModule()->GetMIRBuilder()->GetCurrentFuncCodeMpAllocator()->Adapter()); - CallNode *callStmt = GetModule()->GetMIRBuilder()->CreateStmtCall(func->GetPuidx(), args); + GetMIRModule().GetMIRBuilder()->GetOrCreateFunction(strMCCThrowArrayIndexOutOfBoundsException, TyIdx(PTY_void)); + MapleVector args(GetMIRModule().GetMIRBuilder()->GetCurrentFuncCodeMpAllocator()->Adapter()); + CallNode *callStmt = GetMIRModule().GetMIRBuilder()->CreateStmtCall(func->GetPuidx(), args); newblk.AddStatement(callStmt); newblk.AddStatement(labStmt); } BlockNode *JavaEHLowerer::DoLowerBlock(BlockNode &block) { - BlockNode *newBlock = GetModule()->CurFuncCodeMemPool()->New(); + BlockNode *newBlock = GetMIRModule().CurFuncCodeMemPool()->New(); StmtNode *nextStmt = block.GetFirst(); if (nextStmt == nullptr) { return newBlock; @@ -192,10 +192,10 @@ BlockNode *JavaEHLowerer::DoLowerBlock(BlockNode &block) { MIRIntConst *intConst = static_cast(static_cast(opnd0)->GetConstVal()); CHECK_FATAL(intConst->IsZero(), "can only be zero"); MIRFunction *func = - GetModule()->GetMIRBuilder()->GetOrCreateFunction(strMCCThrowNullPointerException, TyIdx(PTY_void)); + GetMIRModule().GetMIRBuilder()->GetOrCreateFunction(strMCCThrowNullPointerException, TyIdx(PTY_void)); func->SetNoReturn(); - MapleVector args(GetModule()->GetMIRBuilder()->GetCurrentFuncCodeMpAllocator()->Adapter()); - CallNode *callStmt = GetModule()->GetMIRBuilder()->CreateStmtCall(func->GetPuidx(), args); + MapleVector args(GetMIRModule().GetMIRBuilder()->GetCurrentFuncCodeMpAllocator()->Adapter()); + CallNode *callStmt = GetMIRModule().GetMIRBuilder()->CreateStmtCall(func->GetPuidx(), args); newBlock->AddStatement(callStmt); } else { tstmt->SetOpnd(opnd0, 0); @@ -224,7 +224,7 @@ BlockNode *JavaEHLowerer::DoLowerBlock(BlockNode &block) { } void JavaEHLowerer::ProcessFunc(MIRFunction *func) { - GetModule()->SetCurFunction(func); + GetMIRModule().SetCurFunction(func); if (func->GetBody() == nullptr) { return; } diff --git a/src/mpl2mpl/src/muid_replacement.cpp b/src/mpl2mpl/src/muid_replacement.cpp index 5b35603785328cecc3ec7dfea9e0c6198453c0a3..ce89d73eadb9edb9cad33e7a1ab79fb8a7ba01ab 100644 --- a/src/mpl2mpl/src/muid_replacement.cpp +++ b/src/mpl2mpl/src/muid_replacement.cpp @@ -47,7 +47,7 @@ MIRSymbol *MUIDReplacement::GetSymbolFromName(const std::string &name) { void MUIDReplacement::DumpMUIDFile(bool isFunc) { std::ofstream outFile; - const std::string &mplName = GetModule()->GetFileName(); + const std::string &mplName = GetMIRModule().GetFileName(); CHECK_FATAL(mplName.rfind(".mpl") != std::string::npos, "can not find .mpl"); std::string prefix = mplName.substr(0, mplName.rfind(".mpl")); std::string outFileName; @@ -142,7 +142,7 @@ void MUIDReplacement::CollectFuncAndDataFromGlobalTab() { void MUIDReplacement::CollectFuncAndDataFromFuncList() { // Iterate function bodies - for (MIRFunction *mirFunc : GetModule()->GetFunctionList()) { + for (MIRFunction *mirFunc : GetMIRModule().GetFunctionList()) { if (!mirFunc->GetBody()) { continue; } @@ -237,7 +237,7 @@ void MUIDReplacement::CollectImplicitUndefClassInfo(StmtNode &stmt) { std::string classInfoName = CLASSINFO_PREFIX_STR + classType->GetName(); MIRSymbol *classSym = GetSymbolFromName(classInfoName); if (classSym == nullptr) { - classSym = builder->CreateGlobalDecl(classInfoName.c_str(), GlobalTables::GetTypeTable().GetPtr()); + classSym = builder->CreateGlobalDecl(classInfoName.c_str(), *GlobalTables::GetTypeTable().GetPtr()); classSym->SetStorageClass(kScExtern); AddUndefData(classSym); } @@ -255,15 +255,15 @@ void MUIDReplacement::GenericFuncDefTable() { } uint32 idx = 0; size_t arraySize = funcDefMap.size(); - MIRArrayType *muidIdxArrayType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetUInt32(), arraySize); - MIRAggConst *muidIdxTabConst = GetModule()->GetMemPool()->New(GetModule(), muidIdxArrayType); + MIRArrayType &muidIdxArrayType = + *GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetUInt32(), arraySize); + MIRAggConst *muidIdxTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), muidIdxArrayType); for (auto &keyVal : funcDefMap) { // Fill in the real index keyVal.second.second = idx++; // Use the muid index for now. It will be back-filled once we have the whole vector. MIRIntConst *indexConst = - GetModule()->GetMemPool()->New(keyVal.second.second, GlobalTables::GetTypeTable().GetUInt32()); + GetMIRModule().GetMemPool()->New(keyVal.second.second, *GlobalTables::GetTypeTable().GetUInt32()); muidIdxTabConst->GetConstVec().push_back(indexConst); } FieldVector parentFields; @@ -271,14 +271,14 @@ void MUIDReplacement::GenericFuncDefTable() { GlobalTables::GetTypeTable().PushIntoFieldVector(fields, "funcUnifiedAddr", *GlobalTables::GetTypeTable().GetCompactPtr()); MIRStructType *funcDefTabEntryType = static_cast( - GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDFuncDefTabEntry", fields, parentFields, *GetModule())); + GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDFuncDefTabEntry", fields, parentFields, GetMIRModule())); FieldVector funcinffields; GlobalTables::GetTypeTable().PushIntoFieldVector(funcinffields, "funcSize", *GlobalTables::GetTypeTable().GetUInt32()); GlobalTables::GetTypeTable().PushIntoFieldVector(funcinffields, "funcName", *GlobalTables::GetTypeTable().GetUInt32()); MIRStructType *funcInfTabEntryType = static_cast(GlobalTables::GetTypeTable().GetOrCreateStructType( - "MUIDFuncInfTabEntry", funcinffields, parentFields, *GetModule())); + "MUIDFuncInfTabEntry", funcinffields, parentFields, GetMIRModule())); FieldVector muidFields; #ifdef USE_64BIT_MUID GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidLow", *GlobalTables::GetTypeTable().GetUInt32()); @@ -289,17 +289,17 @@ void MUIDReplacement::GenericFuncDefTable() { #endif // USE_64BIT_MUID MIRStructType *funcDefMuidTabEntryType = static_cast(GlobalTables::GetTypeTable().GetOrCreateStructType( - "MUIDFuncDefMuidTabEntry", muidFields, parentFields, *GetModule())); - MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*funcDefTabEntryType, arraySize); - MIRAggConst *funcDefTabConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); - MIRArrayType *funcInfArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*funcInfTabEntryType, arraySize); - MIRAggConst *funcInfTabConst = GetModule()->GetMemPool()->New(GetModule(), funcInfArrayType); - MIRArrayType *muidArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*funcDefMuidTabEntryType, arraySize); - MIRAggConst *funcDefMuidTabConst = GetModule()->GetMemPool()->New(GetModule(), muidArrayType); + "MUIDFuncDefMuidTabEntry", muidFields, parentFields, GetMIRModule())); + MIRArrayType &arrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*funcDefTabEntryType, arraySize); + MIRAggConst *funcDefTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), arrayType); + MIRArrayType &funcInfArrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*funcInfTabEntryType, arraySize); + MIRAggConst *funcInfTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), funcInfArrayType); + MIRArrayType &muidArrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*funcDefMuidTabEntryType, arraySize); + MIRAggConst *funcDefMuidTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), muidArrayType); // Create funcDefSet to store functions sorted by address std::vector> funcDefArray; idx = 0; - for (MIRFunction *mirFunc : GetModule()->GetFunctionList()) { + for (MIRFunction *mirFunc : GetMIRModule().GetFunctionList()) { ASSERT(mirFunc != nullptr, "null ptr check!"); MUID muid = GetMUID(mirFunc->GetName()); MapleMap::iterator iter = funcDefMap.find(muid); @@ -314,12 +314,12 @@ void MUIDReplacement::GenericFuncDefTable() { if (kReflectionList.find(mirFunc->GetName()) != kReflectionList.end()) { constexpr uint32 kWeakFuncFlag = 0x80000000; // 0b10000000 00000000 00000000 00000000 indexConst = - GetModule()->GetMemPool()->New(kWeakFuncFlag | idx, GlobalTables::GetTypeTable().GetUInt32()); + GetMIRModule().GetMemPool()->New(kWeakFuncFlag | idx, *GlobalTables::GetTypeTable().GetUInt32()); } else { - indexConst = GetModule()->GetMemPool()->New(idx, GlobalTables::GetTypeTable().GetUInt32()); + indexConst = GetMIRModule().GetMemPool()->New(idx, *GlobalTables::GetTypeTable().GetUInt32()); } uint32 muidIdx = iter->second.second; - muidIdxTabConst->SetConstVecItem(muidIdx, indexConst); + muidIdxTabConst->SetConstVecItem(muidIdx, *indexConst); // Store the real idx of funcdefTab, for ReplaceAddroffuncConst->FindIndexFromDefTable defMuidIdxMap[muid] = idx; idx++; @@ -334,11 +334,11 @@ void MUIDReplacement::GenericFuncDefTable() { for (auto keyVal : funcDefArray) { MIRSymbol *funcSymbol = keyVal.first; MUID muid = keyVal.second; - MIRAggConst *entryConst = GetModule()->GetMemPool()->New(GetModule(), funcDefTabEntryType); + MIRAggConst *entryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), *funcDefTabEntryType); uint32 fieldID = 1; - MIRAggConst *funcInfEntryConst = GetModule()->GetMemPool()->New(GetModule(), funcInfTabEntryType); + MIRAggConst *funcInfEntryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), *funcInfTabEntryType); uint32 funcInfFieldID = 1; - MIRAggConst *muidEntryConst = GetModule()->GetMemPool()->New(GetModule(), funcDefMuidTabEntryType); + MIRAggConst *muidEntryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), *funcDefMuidTabEntryType); uint32 muidFieldID = 1; // To be processed by runtime builder->AddAddroffuncFieldConst(*funcDefTabEntryType, *entryConst, fieldID++, *funcSymbol); @@ -354,25 +354,25 @@ void MUIDReplacement::GenericFuncDefTable() { mplMuidStr += muid.ToStr(); } if (!funcDefTabConst->GetConstVec().empty()) { - std::string funcDefTabName = NameMangler::kMuidFuncDefTabPrefixStr + GetModule()->GetFileNameAsPostfix(); + std::string funcDefTabName = NameMangler::kMuidFuncDefTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); funcDefTabSym = builder->CreateGlobalDecl(funcDefTabName.c_str(), arrayType); funcDefTabSym->SetKonst(funcDefTabConst); funcDefTabSym->SetStorageClass(kScFstatic); } if (!funcInfTabConst->GetConstVec().empty()) { - std::string funcInfTabName = NameMangler::kMuidFuncInfTabPrefixStr + GetModule()->GetFileNameAsPostfix(); + std::string funcInfTabName = NameMangler::kMuidFuncInfTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); funcInfTabSym = builder->CreateGlobalDecl(funcInfTabName.c_str(), funcInfArrayType); funcInfTabSym->SetKonst(funcInfTabConst); funcInfTabSym->SetStorageClass(kScFstatic); } if (!funcDefMuidTabConst->GetConstVec().empty()) { - std::string funcDefMuidTabName = NameMangler::kMuidFuncDefMuidTabPrefixStr + GetModule()->GetFileNameAsPostfix(); + std::string funcDefMuidTabName = NameMangler::kMuidFuncDefMuidTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); funcDefMuidTabSym = builder->CreateGlobalDecl(funcDefMuidTabName.c_str(), muidArrayType); funcDefMuidTabSym->SetKonst(funcDefMuidTabConst); funcDefMuidTabSym->SetStorageClass(kScFstatic); } if (!muidIdxTabConst->GetConstVec().empty()) { - std::string muidIdxTabName = NameMangler::kMuidFuncMuidIdxTabPrefixStr + GetModule()->GetFileNameAsPostfix(); + std::string muidIdxTabName = NameMangler::kMuidFuncMuidIdxTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); funcMuidIdxTabSym = builder->CreateGlobalDecl(muidIdxTabName.c_str(), muidIdxArrayType); funcMuidIdxTabSym->SetKonst(muidIdxTabConst); funcMuidIdxTabSym->SetStorageClass(kScFstatic); @@ -400,7 +400,7 @@ void MUIDReplacement::GenericDataDefTable() { GlobalTables::GetTypeTable().PushIntoFieldVector(fields, "dataUnifiedAddr", *GlobalTables::GetTypeTable().GetCompactPtr()); MIRStructType *dataDefTabEntryType = static_cast( - GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDDataDefTabEntry", fields, parentFields, *GetModule())); + GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDDataDefTabEntry", fields, parentFields, GetMIRModule())); FieldVector muidFields; #ifdef USE_64BIT_MUID // USE_64BIT_MUID GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidLow", *GlobalTables::GetTypeTable().GetUInt32()); @@ -411,18 +411,18 @@ void MUIDReplacement::GenericDataDefTable() { #endif MIRStructType *dataDefMuidTabEntryType = static_cast(GlobalTables::GetTypeTable().GetOrCreateStructType( - std::string("MUIDDataDefMuidTabEntry"), muidFields, parentFields, *GetModule())); + std::string("MUIDDataDefMuidTabEntry"), muidFields, parentFields, GetMIRModule())); size_t arraySize = dataDefMap.size(); - MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*dataDefTabEntryType, arraySize); - MIRAggConst *dataDefTabConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); - MIRArrayType *muidArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*dataDefMuidTabEntryType, arraySize); - MIRAggConst *dataDefMuidTabConst = GetModule()->GetMemPool()->New(GetModule(), muidArrayType); + MIRArrayType &arrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*dataDefTabEntryType, arraySize); + MIRAggConst *dataDefTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), arrayType); + MIRArrayType &muidArrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*dataDefMuidTabEntryType, arraySize); + MIRAggConst *dataDefMuidTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), muidArrayType); for (auto keyVal : dataDefMap) { MIRSymbol *mirSymbol = keyVal.second.first; - MIRAggConst *entryConst = GetModule()->GetMemPool()->New(GetModule(), dataDefTabEntryType); + MIRAggConst *entryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), *dataDefTabEntryType); uint32 fieldID = 1; MUID muid = keyVal.first; - MIRAggConst *muidEntryConst = GetModule()->GetMemPool()->New(GetModule(), dataDefMuidTabEntryType); + MIRAggConst *muidEntryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), *dataDefMuidTabEntryType); uint32 muidFieldID = 1; // Will be emitted as 0 and processed by runtime builder->AddAddrofFieldConst(*dataDefTabEntryType, *entryConst, fieldID++, *mirSymbol); @@ -440,13 +440,13 @@ void MUIDReplacement::GenericDataDefTable() { DumpMUIDFile(false); } if (!dataDefTabConst->GetConstVec().empty()) { - std::string dataDefTabName = NameMangler::kMuidDataDefTabPrefixStr + GetModule()->GetFileNameAsPostfix(); + std::string dataDefTabName = NameMangler::kMuidDataDefTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); dataDefTabSym = builder->CreateGlobalDecl(dataDefTabName.c_str(), arrayType); dataDefTabSym->SetKonst(dataDefTabConst); dataDefTabSym->SetStorageClass(kScFstatic); } if (!dataDefMuidTabConst->GetConstVec().empty()) { - std::string dataDefMuidTabName = NameMangler::kMuidDataDefMuidTabPrefixStr + GetModule()->GetFileNameAsPostfix(); + std::string dataDefMuidTabName = NameMangler::kMuidDataDefMuidTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); dataDefMuidTabSym = builder->CreateGlobalDecl(dataDefMuidTabName.c_str(), muidArrayType); dataDefMuidTabSym->SetKonst(dataDefMuidTabConst); dataDefMuidTabSym->SetStorageClass(kScFstatic); @@ -481,7 +481,7 @@ void MUIDReplacement::GenericUnifiedUndefTable() { *GlobalTables::GetTypeTable().GetCompactPtr()); MIRStructType *unifiedUndefTabEntryType = static_cast(GlobalTables::GetTypeTable().GetOrCreateStructType( - std::string("MUIDUnifiedUndefTabEntry"), fields, parentFields, *GetModule())); + std::string("MUIDUnifiedUndefTabEntry"), fields, parentFields, GetMIRModule())); FieldVector muidFields; #ifdef USE_64BIT_MUID GlobalTables::GetTypeTable().PushIntoFieldVector(muidFields, "muidLow", *GlobalTables::GetTypeTable().GetUInt32()); @@ -492,13 +492,13 @@ void MUIDReplacement::GenericUnifiedUndefTable() { #endif MIRStructType *unifiedUndefMuidTabEntryType = static_cast(GlobalTables::GetTypeTable().GetOrCreateStructType( - "MUIDUnifiedUndefMuidTabEntry", muidFields, parentFields, *GetModule())); + "MUIDUnifiedUndefMuidTabEntry", muidFields, parentFields, GetMIRModule())); size_t arraySize = funcUndefMap.size(); - MIRArrayType *funcArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefTabEntryType, arraySize); - MIRAggConst *funcUndefTabConst = GetModule()->GetMemPool()->New(GetModule(), funcArrayType); - MIRArrayType *funcMuidArrayType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefMuidTabEntryType, arraySize); - MIRAggConst *funcUndefMuidTabConst = GetModule()->GetMemPool()->New(GetModule(), funcMuidArrayType); + MIRArrayType &funcArrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefTabEntryType, arraySize); + MIRAggConst *funcUndefTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), funcArrayType); + MIRArrayType &funcMuidArrayType = + *GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefMuidTabEntryType, arraySize); + MIRAggConst *funcUndefMuidTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), funcMuidArrayType); for (auto keyVal : funcUndefMap) { MUID muid = keyVal.first; mplMuidStr += muid.ToStr(); @@ -507,10 +507,10 @@ void MUIDReplacement::GenericUnifiedUndefTable() { << ", Function Name: " << keyVal.second.first->GetName() << ", Offset: " << keyVal.second.second << std::endl; } - MIRAggConst *entryConst = GetModule()->GetMemPool()->New(GetModule(), unifiedUndefTabEntryType); + MIRAggConst *entryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), *unifiedUndefTabEntryType); uint32 fieldID = 1; MIRAggConst *muidEntryConst = - GetModule()->GetMemPool()->New(GetModule(), unifiedUndefMuidTabEntryType); + GetMIRModule().GetMemPool()->New(GetMIRModule(), *unifiedUndefMuidTabEntryType); uint32 muidFieldID = 1; // to be filled by runtime builder->AddIntFieldConst(*unifiedUndefTabEntryType, *entryConst, fieldID++, 0); @@ -520,32 +520,32 @@ void MUIDReplacement::GenericUnifiedUndefTable() { funcUndefMuidTabConst->GetConstVec().push_back(muidEntryConst); } if (!funcUndefTabConst->GetConstVec().empty()) { - std::string funcUndefTabName = NameMangler::kMuidFuncUndefTabPrefixStr + GetModule()->GetFileNameAsPostfix(); + std::string funcUndefTabName = NameMangler::kMuidFuncUndefTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); funcUndefTabSym = builder->CreateGlobalDecl(funcUndefTabName.c_str(), funcArrayType); funcUndefTabSym->SetKonst(funcUndefTabConst); funcUndefTabSym->SetStorageClass(kScFstatic); } if (!funcUndefMuidTabConst->GetConstVec().empty()) { std::string funcUndefMuidTabName = - NameMangler::kMuidFuncUndefMuidTabPrefixStr + GetModule()->GetFileNameAsPostfix(); + NameMangler::kMuidFuncUndefMuidTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); funcUndefMuidTabSym = builder->CreateGlobalDecl(funcUndefMuidTabName.c_str(), funcMuidArrayType); funcUndefMuidTabSym->SetKonst(funcUndefMuidTabConst); funcUndefMuidTabSym->SetStorageClass(kScFstatic); } // Continue to generate dataUndefTab arraySize = dataUndefMap.size(); - MIRArrayType *dataArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefTabEntryType, arraySize); - MIRAggConst *dataUndefTabConst = GetModule()->GetMemPool()->New(GetModule(), dataArrayType); - MIRArrayType *dataMuidArrayType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefMuidTabEntryType, arraySize); - MIRAggConst *dataUndefMuidTabConst = GetModule()->GetMemPool()->New(GetModule(), dataMuidArrayType); + MIRArrayType &dataArrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefTabEntryType, arraySize); + MIRAggConst *dataUndefTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), dataArrayType); + MIRArrayType &dataMuidArrayType = + *GlobalTables::GetTypeTable().GetOrCreateArrayType(*unifiedUndefMuidTabEntryType, arraySize); + MIRAggConst *dataUndefMuidTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), dataMuidArrayType); for (auto keyVal : dataUndefMap) { - MIRAggConst *entryConst = GetModule()->GetMemPool()->New(GetModule(), unifiedUndefTabEntryType); + MIRAggConst *entryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), *unifiedUndefTabEntryType); uint32 fieldID = 1; MIRSymbol *mirSymbol = keyVal.second.first; MUID muid = keyVal.first; MIRAggConst *muidEntryConst = - GetModule()->GetMemPool()->New(GetModule(), unifiedUndefMuidTabEntryType); + GetMIRModule().GetMemPool()->New(GetMIRModule(), *unifiedUndefMuidTabEntryType); uint32 muidFieldID = 1; // Will be emitted as 0 and filled by runtime builder->AddAddrofFieldConst(*unifiedUndefTabEntryType, *entryConst, fieldID++, *mirSymbol); @@ -560,14 +560,14 @@ void MUIDReplacement::GenericUnifiedUndefTable() { } } if (!dataUndefTabConst->GetConstVec().empty()) { - std::string dataUndefTabName = NameMangler::kMuidDataUndefTabPrefixStr + GetModule()->GetFileNameAsPostfix(); + std::string dataUndefTabName = NameMangler::kMuidDataUndefTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); dataUndefTabSym = builder->CreateGlobalDecl(dataUndefTabName.c_str(), dataArrayType); dataUndefTabSym->SetKonst(dataUndefTabConst); dataUndefTabSym->SetStorageClass(kScFstatic); } if (!dataUndefMuidTabConst->GetConstVec().empty()) { std::string dataUndefMuidTabName = - NameMangler::kMuidDataUndefMuidTabPrefixStr + GetModule()->GetFileNameAsPostfix(); + NameMangler::kMuidDataUndefMuidTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); dataUndefMuidTabSym = builder->CreateGlobalDecl(dataUndefMuidTabName.c_str(), dataMuidArrayType); dataUndefMuidTabSym->SetKonst(dataUndefMuidTabConst); dataUndefMuidTabSym->SetStorageClass(kScFstatic); @@ -580,37 +580,37 @@ void MUIDReplacement::GenericRangeTable() { FieldVector fields; GlobalTables::GetTypeTable().PushIntoFieldVector(fields, "tabBegin", *GlobalTables::GetTypeTable().GetVoidPtr()); GlobalTables::GetTypeTable().PushIntoFieldVector(fields, "tabEnd", *GlobalTables::GetTypeTable().GetVoidPtr()); - MIRStructType *rangeTabEntryType = static_cast( - GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDRangeTabEntry", fields, parentFields, *GetModule())); - MIRArrayType *rangeArrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*rangeTabEntryType, 0); - MIRAggConst *rangeTabConst = GetModule()->GetMemPool()->New(GetModule(), rangeArrayType); + MIRStructType &rangeTabEntryType = static_cast( + *GlobalTables::GetTypeTable().GetOrCreateStructType("MUIDRangeTabEntry", fields, parentFields, GetMIRModule())); + MIRArrayType &rangeArrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(rangeTabEntryType, 0); + MIRAggConst *rangeTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), rangeArrayType); // First entry is reserved for a compile-time-stamp // Second entry is reserved for a decouple-stamp mplMuidStr += kMplLinkerVersionNumber; const std::string muidStr[2] = { mplMuidStr, mplMuidStr + GetMplMd5().ToStr() }; for (auto &item : muidStr) { uint32 fieldID = 1; - MIRAggConst *entryConst = GetModule()->GetMemPool()->New(GetModule(), rangeTabEntryType); + MIRAggConst *entryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), rangeTabEntryType); MUID mplMd5 = GetMUID(item); - builder->AddIntFieldConst(*rangeTabEntryType, *entryConst, fieldID++, mplMd5.data.words[0]); - builder->AddIntFieldConst(*rangeTabEntryType, *entryConst, fieldID++, mplMd5.data.words[1]); + builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, mplMd5.data.words[0]); + builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, mplMd5.data.words[1]); rangeTabConst->GetConstVec().push_back(entryConst); } for (uint32 i = RangeIdx::kVtab; i < RangeIdx::kMaxNum; i++) { // Use an integer to mark which entry is for which table - MIRAggConst *entryConst = GetModule()->GetMemPool()->New(GetModule(), rangeTabEntryType); + MIRAggConst *entryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), rangeTabEntryType); uint32 fieldID = 1; if (i == RangeIdx::kGlobalRootlist) { MIRSymbol *st = GetSymbolFromName(NameMangler::kGcRootList); if (st == nullptr) { - builder->AddIntFieldConst(*rangeTabEntryType, *entryConst, fieldID++, 0); - builder->AddIntFieldConst(*rangeTabEntryType, *entryConst, fieldID++, 0); + builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); + builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); rangeTabConst->GetConstVec().push_back(entryConst); continue; } } - builder->AddIntFieldConst(*rangeTabEntryType, *entryConst, fieldID++, i); - builder->AddIntFieldConst(*rangeTabEntryType, *entryConst, fieldID++, i); + builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, i); + builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, i); rangeTabConst->GetConstVec().push_back(entryConst); } // Please refer to mrt/compiler-rt/include/mpl_linker.h for the layout @@ -619,20 +619,20 @@ void MUIDReplacement::GenericRangeTable() { funcUndefMuidTabSym, dataDefMuidTabSym, dataUndefMuidTabSym, funcMuidIdxTabSym, funcProfileTabSym }; for (MIRSymbol *mirSymbol : workList) { - MIRAggConst *entryConst = GetModule()->GetMemPool()->New(GetModule(), rangeTabEntryType); + MIRAggConst *entryConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), rangeTabEntryType); uint32 fieldID = 1; if (mirSymbol != nullptr) { - builder->AddAddrofFieldConst(*rangeTabEntryType, *entryConst, fieldID++, *mirSymbol); - builder->AddAddrofFieldConst(*rangeTabEntryType, *entryConst, fieldID++, *mirSymbol); + builder->AddAddrofFieldConst(rangeTabEntryType, *entryConst, fieldID++, *mirSymbol); + builder->AddAddrofFieldConst(rangeTabEntryType, *entryConst, fieldID++, *mirSymbol); } else { - builder->AddIntFieldConst(*rangeTabEntryType, *entryConst, fieldID++, 0); - builder->AddIntFieldConst(*rangeTabEntryType, *entryConst, fieldID++, 0); + builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); + builder->AddIntFieldConst(rangeTabEntryType, *entryConst, fieldID++, 0); } rangeTabConst->GetConstVec().push_back(entryConst); } if (!rangeTabConst->GetConstVec().empty()) { - rangeArrayType->SetSizeArrayItem(0, rangeTabConst->GetConstVec().size()); - std::string rangeTabName = NameMangler::kMuidRangeTabPrefixStr + GetModule()->GetFileNameAsPostfix(); + rangeArrayType.SetSizeArrayItem(0, rangeTabConst->GetConstVec().size()); + std::string rangeTabName = NameMangler::kMuidRangeTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); rangeTabSym = builder->CreateGlobalDecl(rangeTabName.c_str(), rangeArrayType); rangeTabSym->SetKonst(rangeTabConst); rangeTabSym->SetStorageClass(kScFstatic); @@ -707,7 +707,7 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldId, b if (entry->GetKind() != kConstAddrofFunc) { return; } - MIRType *voidType = GlobalTables::GetTypeTable().GetVoidPtr(); + MIRType &voidType = *GlobalTables::GetTypeTable().GetVoidPtr(); MIRAddroffuncConst *funcAddr = static_cast(entry); MIRFunction *func = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(funcAddr->GetValue()); ASSERT(func != nullptr, "Invalid MIRFunction"); @@ -722,17 +722,17 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldId, b // The second least significant bit is set to 1, indicating // this is an index into the funcDefTab constexpr uint64 kIdxIntoFuncDefTabFlag = 2u; - constNode = GetModule()->GetMemPool()->New(((offset + 1) << kReservedBits) + kIdxIntoFuncDefTabFlag, - voidType); + constNode = GetMIRModule().GetMemPool()->New(((offset + 1) << kReservedBits) + kIdxIntoFuncDefTabFlag, + voidType); } else if (isVtab && func->IsAbstract()) { - MIRType *type = GlobalTables::GetTypeTable().GetVoidPtr(); - constNode = GetModule()->GetMemPool()->New(0, type); + MIRType &type = *GlobalTables::GetTypeTable().GetVoidPtr(); + constNode = GetMIRModule().GetMemPool()->New(0, type); } else { ASSERT(func->GetFuncSymbol() != nullptr, "null ptr check!"); offset = FindIndexFromUndefTable(*(func->GetFuncSymbol()), true); // The second least significant bit is set to 0, indicating // this is an index into the funcUndefTab - constNode = GetModule()->GetMemPool()->New((offset + 1) << kReservedBits, voidType); + constNode = GetMIRModule().GetMemPool()->New((offset + 1) << kReservedBits, voidType); } if (fieldId != 0xffffffff) { constNode->SetFieldID(fieldId); @@ -768,7 +768,7 @@ void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry) { if (entry->GetKind() != kConstAddrof) { return; } - MIRType *voidType = GlobalTables::GetTypeTable().GetVoidPtr(); + MIRType &voidType = *GlobalTables::GetTypeTable().GetVoidPtr(); MIRAddrofConst *addr = static_cast(entry); MIRSymbol *addrSym = GlobalTables::GetGsymTable().GetSymbolFromStidx(addr->GetSymbolIndex().Idx()); ASSERT(addrSym != nullptr, "Invalid MIRSymbol"); @@ -779,10 +779,10 @@ void MUIDReplacement::ReplaceAddrofConst(MIRConst *&entry) { MIRIntConst *constNode = nullptr; if (addrSym->GetStorageClass() != kScExtern) { offset = FindIndexFromDefTable(*addrSym, false); - constNode = GetModule()->GetMemPool()->New(offset | kFromDefIndexMask, voidType); + constNode = GetMIRModule().GetMemPool()->New(offset | kFromDefIndexMask, voidType); } else { offset = FindIndexFromUndefTable(*addrSym, false); - constNode = GetModule()->GetMemPool()->New(offset | kFromUndefIndexMask, voidType); + constNode = GetMIRModule().GetMemPool()->New(offset | kFromUndefIndexMask, voidType); } entry = constNode; } @@ -824,9 +824,9 @@ void MUIDReplacement::ReplaceDirectInvokeOrAddroffunc(MIRFunction ¤tFunc, std::string commentLabel = NameMangler::kMarkMuidFuncDefStr + calleeFunc->GetName(); currentFunc.GetBody()->InsertBefore(&stmt, builder->CreateStmtComment(commentLabel.c_str())); - std::string moduleName = GetModule()->GetFileNameAsPostfix(); + std::string moduleName = GetMIRModule().GetFileNameAsPostfix(); std::string baseName = calleeFunc->GetBaseClassName(); - baseExpr = builder->CreateExprAddrof(0, *funcDefTabSym, GetModule()->GetMemPool()); + baseExpr = builder->CreateExprAddrof(0, *funcDefTabSym, GetMIRModule().GetMemPool()); ASSERT(calleeFunc->GetFuncSymbol() != nullptr, "null ptr check!"); index = FindIndexFromDefTable(*(calleeFunc->GetFuncSymbol()), true); arrayType = static_cast(funcDefTabSym->GetType()); @@ -836,7 +836,7 @@ void MUIDReplacement::ReplaceDirectInvokeOrAddroffunc(MIRFunction ¤tFunc, std::string commentLabel = NameMangler::kMarkMuidFuncUndefStr + calleeFunc->GetName(); currentFunc.GetBody()->InsertBefore(&stmt, builder->CreateStmtComment(commentLabel.c_str())); - baseExpr = builder->CreateExprAddrof(0, *funcUndefTabSym, GetModule()->GetMemPool()); + baseExpr = builder->CreateExprAddrof(0, *funcUndefTabSym, GetMIRModule().GetMemPool()); ASSERT(calleeFunc->GetFuncSymbol() != nullptr, "null ptr check!"); index = FindIndexFromUndefTable(*(calleeFunc->GetFuncSymbol()), true); arrayType = static_cast(funcUndefTabSym->GetType()); @@ -864,13 +864,13 @@ void MUIDReplacement::ReplaceDirectInvokeOrAddroffunc(MIRFunction ¤tFunc, } if (callNode != nullptr) { // Create icallNode to replace callNode - IcallNode *icallNode = GetModule()->CurFuncCodeMemPool()->New( - *GetModule(), callNode->GetOpCode() == OP_call ? OP_icall : OP_icallassigned); + IcallNode *icallNode = GetMIRModule().CurFuncCodeMemPool()->New( + GetMIRModule(), callNode->GetOpCode() == OP_call ? OP_icall : OP_icallassigned); icallNode->SetNumOpnds(callNode->GetNumOpnds() + 1); icallNode->GetNopnd().resize(icallNode->GetNumOpnds()); icallNode->SetNOpndAt(0, readFuncPtr); for (size_t i = 1; i < icallNode->GetNopndSize(); i++) { - icallNode->SetNOpndAt(i, callNode->GetNopnd()[i - 1]->CloneTree(GetModule()->GetCurFuncCodeMPAllocator())); + icallNode->SetNOpndAt(i, callNode->GetNopnd()[i - 1]->CloneTree(GetMIRModule().GetCurFuncCodeMPAllocator())); } icallNode->SetRetTyIdx(calleeFunc->GetReturnTyIdx()); if (callNode->GetOpCode() == OP_callassigned) { @@ -1061,7 +1061,7 @@ void MUIDReplacement::ProcessFunc(MIRFunction *func) { if (isLibcore || func->IsEmpty()) { return; } - SetCurrentFunction(func); + SetCurrentFunction(*func); StmtNode *stmt = func->GetBody()->GetFirst(); StmtNode *next = nullptr; while (stmt != nullptr) { @@ -1085,8 +1085,8 @@ void MUIDReplacement::ProcessFunc(MIRFunction *func) { void MUIDReplacement::GenericGlobalRootList() { MIRType *voidType = GlobalTables::GetTypeTable().GetVoidPtr(); MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*voidType, 0); - MIRAggConst *newConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); - for (StIdx stidx : GetModule()->GetSymbolSet()) { + MIRAggConst *newConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), *arrayType); + for (StIdx stidx : GetMIRModule().GetSymbolSet()) { MIRSymbol *symbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(stidx.Idx()); MIRSymKind st = symbol->GetSKind(); MIRStorageClass sc = symbol->GetStorageClass(); @@ -1112,13 +1112,13 @@ void MUIDReplacement::GenericGlobalRootList() { } // Now it is a pointer/ref to a class. Record it for GC scanning. ASSERT(PTY_ptr < GlobalTables::GetTypeTable().GetTypeTable().size(), "index out of bound"); - MIRType *ptrType = GlobalTables::GetTypeTable().GetTypeTable()[PTY_ptr]; - MIRConst *constNode = GetModule()->GetMemPool()->New(symbol->GetStIdx(), 0, ptrType); + MIRType &ptrType = *GlobalTables::GetTypeTable().GetTypeTable()[PTY_ptr]; + MIRConst *constNode = GetMIRModule().GetMemPool()->New(symbol->GetStIdx(), 0, ptrType); newConst->GetConstVec().push_back(constNode); } std::string gcRootsName = NameMangler::kGcRootList; if (!newConst->GetConstVec().empty()) { - MIRSymbol *gcRootsSt = builder->CreateSymbol(newConst->GetType()->GetTypeIndex(), gcRootsName.c_str(), kStVar, + MIRSymbol *gcRootsSt = builder->CreateSymbol(newConst->GetType().GetTypeIndex(), gcRootsName.c_str(), kStVar, kScAuto, nullptr, kScopeGlobal); arrayType->SetSizeArrayItem(0, newConst->GetConstVec().size()); gcRootsSt->SetKonst(newConst); @@ -1127,14 +1127,14 @@ void MUIDReplacement::GenericGlobalRootList() { void MUIDReplacement::GenericCompilerVersionNum() { MIRType *ptrType = GlobalTables::GetTypeTable().GetVoidPtr(); - MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*ptrType, 0); - MIRAggConst *newConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); - MIRType *type = GlobalTables::GetTypeTable().GetInt32(); - MIRConst *firstConst = GetModule()->GetMemPool()->New(Version::kMajorMplVersion, type); - MIRConst *secondConst = GetModule()->GetMemPool()->New(Version::kMinorCompilerVersion, type); + MIRArrayType &arrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*ptrType, 0); + MIRAggConst *newConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), arrayType); + MIRType &type = *GlobalTables::GetTypeTable().GetInt32(); + MIRConst *firstConst = GetMIRModule().GetMemPool()->New(Version::kMajorMplVersion, type); + MIRConst *secondConst = GetMIRModule().GetMemPool()->New(Version::kMinorCompilerVersion, type); newConst->GetConstVec().push_back(firstConst); newConst->GetConstVec().push_back(secondConst); - std::string symName = NameMangler::kCompilerVersionNum + GetModule()->GetFileNameAsPostfix(); + std::string symName = NameMangler::kCompilerVersionNum + GetMIRModule().GetFileNameAsPostfix(); MIRSymbol *versionNum = builder->CreateGlobalDecl(symName.c_str(), arrayType); versionNum->SetKonst(newConst); } @@ -1151,9 +1151,7 @@ void MUIDReplacement::GenericTables() { // When MapleLinker is enabled, MUIDReplacement becomes the last // phase that updates the reflection string table, thus the table // is emitted here. - MIRModule *mirModule = GetModule(); - ASSERT(mirModule != nullptr, "null ptr check!"); - ReflectionAnalysis::GenStrTab(*mirModule); + ReflectionAnalysis::GenStrTab(GetMIRModule()); // Replace undef entries in vtab/itab/reflectionMetaData for (Klass *klass : klassHierarchy->GetTopoSortedKlasses()) { ReplaceDataTable(SUPERCLASSINFO_PREFIX_STR + klass->GetKlassName()); diff --git a/src/mpl2mpl/src/native_stub_func.cpp b/src/mpl2mpl/src/native_stub_func.cpp index 56d92dc2363372dea526acda38746b87c60cd7b3..4546dd62d252ffca909461baff0ed66c09240244 100644 --- a/src/mpl2mpl/src/native_stub_func.cpp +++ b/src/mpl2mpl/src/native_stub_func.cpp @@ -84,7 +84,7 @@ MIRFunction &GenericNativeStubFunc::GetOrCreateDefaultNativeFunc(MIRFunction &st CallNode *callGetFindNativeFunc = builder->CreateStmtCallAssigned(findNativeFunc->GetPuidx(), args, nullptr, OP_callassigned); nativeFunc->GetBody()->AddStatement(callGetFindNativeFunc); - GetModule()->AddFunction(nativeFunc); + GetMIRModule().AddFunction(nativeFunc); builder->SetCurrentFunction(&stubFunc); } return *nativeFunc; @@ -110,7 +110,7 @@ void GenericNativeStubFunc::ProcessFunc(MIRFunction *func) { func->GetAttr(FUNCATTR_bridge)) { return; } - SetCurrentFunction(func); + SetCurrentFunction(*func); if (trace) { LogInfo::MapleLogger(kLlErr) << "Create stub func: " << func->GetName() << std::endl; } @@ -287,11 +287,11 @@ void GenericNativeStubFunc::ProcessFunc(MIRFunction *func) { } void GenericNativeStubFunc::GenericRegFuncTabEntryType() { - MIRArrayType *arrayType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetVoidPtr(), 0); - regFuncTabConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); - std::string regFuncTab = NameMangler::kRegJNIFuncTabPrefixStr + GetModule()->GetFileNameAsPostfix(); - regFuncSymbol = builder->CreateSymbol(regFuncTabConst->GetType()->GetTypeIndex(), regFuncTab.c_str(), kStVar, + MIRArrayType &arrayType = + *GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetVoidPtr(), 0); + regFuncTabConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), arrayType); + std::string regFuncTab = NameMangler::kRegJNIFuncTabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); + regFuncSymbol = builder->CreateSymbol(regFuncTabConst->GetType().GetTypeIndex(), regFuncTab.c_str(), kStVar, kScGlobal, nullptr, kScopeGlobal); } @@ -300,15 +300,14 @@ void GenericNativeStubFunc::GenericRegFuncTabEntry() { constexpr uint64 locIdxMask = 0xFF00000000000000; uint64 locIdx = regFuncTabConst->GetConstVec().size(); MIRConst *newConst = - GetModule()->GetMemPool()->New(static_cast((locIdx << locIdxShift) | locIdxMask), - GlobalTables::GetTypeTable().GetVoidPtr()); + GetMIRModule().GetMemPool()->New(static_cast((locIdx << locIdxShift) | locIdxMask), + *GlobalTables::GetTypeTable().GetVoidPtr()); regFuncTabConst->GetConstVec().push_back(newConst); } void GenericNativeStubFunc::GenericRegFuncTab() { - MIRArrayType *arrayType = static_cast(regFuncTabConst->GetType()); - ASSERT(arrayType, "Can not get arrayType from ref_func_tab"); - arrayType->SetSizeArrayItem(0, regFuncTabConst->GetConstVec().size()); + MIRArrayType &arrayType = static_cast(regFuncTabConst->GetType()); + arrayType.SetSizeArrayItem(0, regFuncTabConst->GetConstVec().size()); regFuncSymbol->SetKonst(regFuncTabConst); } @@ -324,9 +323,9 @@ void GenericNativeStubFunc::GenericRegTabEntry(const MIRFunction &func) { uint32 classIdx = ReflectionAnalysis::FindOrInsertRepeatString(base, true); // always used // Using MIRIntConst instead of MIRStruct for RegTable. MIRConst *baseConst = - GetModule()->GetMemPool()->New(classIdx, GlobalTables::GetTypeTable().GetVoidPtr()); + GetMIRModule().GetMemPool()->New(classIdx, *GlobalTables::GetTypeTable().GetVoidPtr()); regTableConst->GetConstVec().push_back(baseConst); - MIRConst *newConst = GetModule()->GetMemPool()->New(nameIdx, GlobalTables::GetTypeTable().GetVoidPtr()); + MIRConst *newConst = GetMIRModule().GetMemPool()->New(nameIdx, *GlobalTables::GetTypeTable().GetVoidPtr()); regTableConst->GetConstVec().push_back(newConst); } @@ -345,12 +344,11 @@ void GenericNativeStubFunc::GenericRegisteredNativeFuncCall(MIRFunction &func, c nrets.push_back(CallReturnPair(ret->GetStIdx(), RegFieldPair(0, 0))); } size_t loc = regFuncTabConst->GetConstVec().size(); - MIRArrayType *regArrayType = static_cast(regFuncTabConst->GetType()); + MIRArrayType ®ArrayType = static_cast(regFuncTabConst->GetType()); AddrofNode *regFuncExpr = builder->CreateExprAddrof(0, *regFuncSymbol); - ArrayNode *arrayExpr = - builder->CreateExprArray(*regArrayType, regFuncExpr, builder->CreateIntConst(loc - 1, PTY_i32)); + ArrayNode *arrayExpr = builder->CreateExprArray(regArrayType, regFuncExpr, builder->CreateIntConst(loc - 1, PTY_i32)); arrayExpr->SetBoundsCheck(false); - MIRType *elemType = static_cast(regArrayType)->GetElemType(); + MIRType *elemType = static_cast(regArrayType).GetElemType(); BaseNode *ireadExpr = builder->CreateExprIread(*elemType, *GlobalTables::GetTypeTable().GetOrCreatePointerType(*elemType), 0, arrayExpr); // assign registered func ptr to a preg. @@ -482,12 +480,12 @@ void GenericNativeStubFunc::GenericRegisteredNativeFuncCall(MIRFunction &func, c return; } // Without native wrapper - IcallNode *icall = func.GetCodeMempool()->New(*GetModule(), OP_icallassigned); + IcallNode *icall = func.GetCodeMempool()->New(GetMIRModule(), OP_icallassigned); icall->SetNumOpnds(args.size() + 1); icall->GetNopnd().resize(icall->GetNumOpnds()); icall->SetReturnVec(nrets); for (size_t i = 1; i < icall->GetNopndSize(); i++) { - icall->SetNOpndAt(i, args[i - 1]->CloneTree(GetModule()->GetCurFuncCodeMPAllocator())); + icall->SetNOpndAt(i, args[i - 1]->CloneTree(GetMIRModule().GetCurFuncCodeMPAllocator())); } icall->SetNOpndAt(0, readFuncPtr); icall->SetRetTyIdx(nativeFunc.GetReturnTyIdx()); @@ -520,7 +518,7 @@ StmtNode *GenericNativeStubFunc::CreateNativeWrapperCallNode(MIRFunction &func, // if num_of_args < 8 constexpr size_t kNumOfArgs = 8; if (func.GetAttr(FUNCATTR_critical_native) && args.size() < kNumOfArgs) { - IcallNode *icall = func.GetCodeMempool()->New(*GetModule(), OP_icallassigned); + IcallNode *icall = func.GetCodeMempool()->New(GetMIRModule(), OP_icallassigned); CallReturnVector nrets(func.GetCodeMempoolAllocator()->Adapter()); if (ret != nullptr) { CHECK_FATAL((ret->GetStorageClass() == kScAuto || ret->GetStorageClass() == kScFormal || @@ -532,7 +530,7 @@ StmtNode *GenericNativeStubFunc::CreateNativeWrapperCallNode(MIRFunction &func, icall->GetNopnd().resize(icall->GetNumOpnds()); icall->SetReturnVec(nrets); for (size_t i = 1; i < icall->GetNopndSize(); i++) { - icall->SetNOpndAt(i, args[i - 1]->CloneTree(GetModule()->GetCurFuncCodeMPAllocator())); + icall->SetNOpndAt(i, args[i - 1]->CloneTree(GetMIRModule().GetCurFuncCodeMPAllocator())); } icall->SetNOpndAt(0, funcPtr); icall->SetRetTyIdx(func.GetReturnTyIdx()); @@ -567,9 +565,9 @@ void GenericNativeStubFunc::GenericNativeWrapperFuncCall(MIRFunction &func, cons void GenericNativeStubFunc::GenericRegTableEntryType() { // Use MIRIntType instead of MIRStructType in RegTableEntry - MIRArrayType *arrayType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetVoidPtr(), 0); - regTableConst = GetModule()->GetMemPool()->New(GetModule(), arrayType); + MIRArrayType &arrayType = + *GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetVoidPtr(), 0); + regTableConst = GetMIRModule().GetMemPool()->New(GetMIRModule(), arrayType); } void GenericNativeStubFunc::GenericHelperFuncDecl() { @@ -584,26 +582,26 @@ void GenericNativeStubFunc::GenericHelperFuncDecl() { MRTCheckThrowPendingExceptionFunc->SetAttr(FUNCATTR_nosideeffect); MRTCheckThrowPendingExceptionFunc->SetBody(nullptr); // MRT_PreNativeCall - ArgVector preArgs(GetModule()->GetMPAllocator().Adapter()); + ArgVector preArgs(GetMIRModule().GetMPAllocator().Adapter()); preArgs.push_back(ArgPair("caller", refType)); MRTPreNativeFunc = builder->CreateFunction(kPreNativeFunc, *voidPointerType, preArgs); CHECK_FATAL(MRTPreNativeFunc, "MRTPreNativeFunc is null in GenericNativeStubFunc::GenericHelperFuncDecl"); MRTPreNativeFunc->SetBody(nullptr); // MRT_PostNativeCall - ArgVector postArgs(GetModule()->GetMPAllocator().Adapter()); + ArgVector postArgs(GetMIRModule().GetMPAllocator().Adapter()); postArgs.push_back(ArgPair("env", voidPointerType)); MRTPostNativeFunc = builder->CreateFunction(kPostNativeFunc, *voidType, postArgs); CHECK_FATAL(MRTPostNativeFunc, "MRTPostNativeFunc is null in GenericNativeStubFunc::GenericHelperFuncDecl"); MRTPostNativeFunc->SetBody(nullptr); // MRT_DecodeReference - ArgVector decodeArgs(GetModule()->GetMPAllocator().Adapter()); + ArgVector decodeArgs(GetMIRModule().GetMPAllocator().Adapter()); decodeArgs.push_back(ArgPair("obj", refType)); MRTDecodeRefFunc = builder->CreateFunction(kDecodeRefFunc, *refType, decodeArgs); CHECK_FATAL(MRTDecodeRefFunc, "MRTDecodeRefFunc is null in GenericNativeStubFunc::GenericHelperFuncDecl"); MRTDecodeRefFunc->SetAttr(FUNCATTR_nosideeffect); MRTDecodeRefFunc->SetBody(nullptr); // MCC_CallFastNative - ArgVector callArgs(GetModule()->GetMPAllocator().Adapter()); + ArgVector callArgs(GetMIRModule().GetMPAllocator().Adapter()); callArgs.push_back(ArgPair("func", voidPointerType)); MRTCallFastNativeFunc = builder->CreateFunction(kCallFastNativeFunc, *voidPointerType, callArgs); CHECK_FATAL(MRTCallFastNativeFunc, "MRTCallFastNativeFunc is null in GenericNativeStubFunc::GenericHelperFuncDecl"); @@ -616,7 +614,7 @@ void GenericNativeStubFunc::GenericHelperFuncDecl() { MRTCallSlowNativeFunc[i]->SetBody(nullptr); } // MCC_CallFastNativeExt - ArgVector callExtArgs(GetModule()->GetMPAllocator().Adapter()); + ArgVector callExtArgs(GetMIRModule().GetMPAllocator().Adapter()); callExtArgs.push_back(ArgPair("func", voidPointerType)); MRTCallFastNativeExtFunc = builder->CreateFunction(kCallFastNativeExtFunc, *voidPointerType, callExtArgs); CHECK_FATAL(MRTCallFastNativeExtFunc != nullptr, @@ -637,10 +635,10 @@ void GenericNativeStubFunc::GenericHelperFuncDecl() { } void GenericNativeStubFunc::GenericRegTable() { - MIRArrayType *arrayType = static_cast(regTableConst->GetType()); - arrayType->SetSizeArrayItem(0, regTableConst->GetConstVec().size()); - std::string regJniTabName = NameMangler::kRegJNITabPrefixStr + GetModule()->GetFileNameAsPostfix(); - MIRSymbol *regJNISt = builder->CreateSymbol(regTableConst->GetType()->GetTypeIndex(), regJniTabName.c_str(), kStVar, + MIRArrayType &arrayType = static_cast(regTableConst->GetType()); + arrayType.SetSizeArrayItem(0, regTableConst->GetConstVec().size()); + std::string regJniTabName = NameMangler::kRegJNITabPrefixStr + GetMIRModule().GetFileNameAsPostfix(); + MIRSymbol *regJNISt = builder->CreateSymbol(regTableConst->GetType().GetTypeIndex(), regJniTabName.c_str(), kStVar, kScGlobal, nullptr, kScopeGlobal); regJNISt->SetKonst(regTableConst); } @@ -673,9 +671,7 @@ void GenericNativeStubFunc::Finish() { } if (!Options::mapleLinker) { // If use maplelinker, we postpone this generation to MUIDReplacement - MIRModule *mirModule = GetModule(); - ASSERT(mirModule != nullptr, "null ptr check!"); - ReflectionAnalysis::GenStrTab(*mirModule); + ReflectionAnalysis::GenStrTab(GetMIRModule()); } } } // namespace maple diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index d2adeae4403cf35ee896dec5c5f9100b2d0615f8..10d79d4d8898bd09c7662775f12d9396559636b9 100644 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -95,9 +95,7 @@ uint32 ReflectionAnalysis::FindOrInsertRepeatString(const std::string &str, bool } BaseNode *ReflectionAnalysis::GenClassInfoAddr(BaseNode *obj, MIRBuilder &builder) { - MIRModule *mirModule = builder.GetMirModule(); - ASSERT(mirModule != nullptr, "null ptr check!"); - GenMetadataType(*mirModule); + GenMetadataType(builder.GetMirModule()); MIRClassType *objectType = static_cast(WKTypes::Util::GetJavaLangObjectType()); BaseNode *classinfoAddress = nullptr; if (objectType != nullptr && objectType->GetKind() != kTypeClassIncomplete) { @@ -653,15 +651,16 @@ struct HashCodeComparator { }; MIRSymbol *ReflectionAnalysis::GenMethodsMetaData(const Klass &klass) { + MIRModule &module = *mirModule; MIRClassType *classType = klass.GetMIRClassType(); if (!classType || classType->GetMethods().empty()) { return nullptr; } size_t arraySize = classType->GetMethods().size(); - MIRStructType *methodsInfoType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(methodsInfoTyIdx)); - MIRArrayType *arraytype = GlobalTables::GetTypeTable().GetOrCreateArrayType(*methodsInfoType, arraySize); - MIRAggConst *aggconst = mirModule->GetMemPool()->New(mirModule, arraytype); + MIRStructType &methodsInfoType = + static_cast(*GlobalTables::GetTypeTable().GetTypeFromTyIdx(methodsInfoTyIdx)); + MIRArrayType &arraytype = *GlobalTables::GetTypeTable().GetOrCreateArrayType(methodsInfoType, arraySize); + MIRAggConst *aggconst = module.GetMemPool()->New(module, arraytype); std::vector> methodinfoVec; for (MethodPair &methodPair : classType->GetMethods()) { methodinfoVec.push_back(std::make_pair(&methodPair, -1)); @@ -678,7 +677,7 @@ MIRSymbol *ReflectionAnalysis::GenMethodsMetaData(const Klass &klass) { MIRSymbol *funcSym = GlobalTables::GetGsymTable().GetSymbolFromStidx(methodinfo.first->first.Idx()); reflectionMuidStr += funcSym->GetName(); MIRFunction *func = funcSym->GetFunction(); - MIRAggConst *newconst = mirModule->GetMemPool()->New(mirModule, methodsInfoType); + MIRAggConst *newconst = module.GetMemPool()->New(module, methodsInfoType); uint32 fieldID = 1; uint32 flag = 0; if (!VtableFunc(*func)) { @@ -696,13 +695,13 @@ MIRSymbol *ReflectionAnalysis::GenMethodsMetaData(const Klass &klass) { uint32 methodInVtabIndex = 0u; methodInVtabIndex = static_cast(static_cast(GetMethodInVtabIndex(klass, *func))); methodInVtabIndex &= 0xFFFF; - mirBuilder.AddIntFieldConst(*methodsInfoType, *newconst, fieldID++, methodInVtabIndex); + mirBuilder.AddIntFieldConst(methodsInfoType, *newconst, fieldID++, methodInVtabIndex); // @declaringclass MIRSymbol *dklassSt = GetOrCreateSymbol(CLASSINFO_PREFIX_STR + func->GetBaseClassName(), classMetadataTyIdx); - mirBuilder.AddAddrofFieldConst(*methodsInfoType, *newconst, fieldID++, *dklassSt); + mirBuilder.AddAddrofFieldConst(methodsInfoType, *newconst, fieldID++, *dklassSt); // @addr : Function address - mirBuilder.AddAddroffuncFieldConst(*methodsInfoType, *newconst, fieldID++, *funcSym); + mirBuilder.AddAddroffuncFieldConst(methodsInfoType, *newconst, fieldID++, *funcSym); // @modifier uint32 mod = GetMethodModifier(func->GetFuncAttrs()); @@ -710,11 +709,11 @@ MIRSymbol *ReflectionAnalysis::GenMethodsMetaData(const Klass &klass) { if (klass.IsInterface() && !func->GetAttr(FUNCATTR_abstract) && !func->GetAttr(FUNCATTR_static)) { mod |= (1 << (kModDefault)); } - mirBuilder.AddIntFieldConst(*methodsInfoType, *newconst, fieldID++, mod); + mirBuilder.AddIntFieldConst(methodsInfoType, *newconst, fieldID++, mod); // @methodname std::string baseName = basenameMp[func->GetBaseFuncNameStrIdx().GetIdx()]; uint32 methodnameIdx = FindOrInsertReflectString(baseName); - mirBuilder.AddIntFieldConst(*methodsInfoType, *newconst, fieldID++, methodnameIdx); + mirBuilder.AddIntFieldConst(methodsInfoType, *newconst, fieldID++, methodnameIdx); // @methodsignature std::string fullname = fullnameMp[func->GetBaseFuncNameWithTypeStrIdx().GetIdx()]; std::string signature = GetSignatureFromFullName(fullname); @@ -722,42 +721,43 @@ MIRSymbol *ReflectionAnalysis::GenMethodsMetaData(const Klass &klass) { std::vector typeNames; GetSignatureTypeNames(signature.c_str(), typeNames); uint32 signatureIdx = FindOrInsertReflectString(signature); - mirBuilder.AddIntFieldConst(*methodsInfoType, *newconst, fieldID++, signatureIdx); + mirBuilder.AddIntFieldConst(methodsInfoType, *newconst, fieldID++, signatureIdx); // @annotation int annotationIdx = 0; annotationIdx = SolveAnnotation(*classType, *func); - mirBuilder.AddIntFieldConst(*methodsInfoType, *newconst, fieldID++, annotationIdx); - mirBuilder.AddIntFieldConst(*methodsInfoType, *newconst, fieldID++, flag); + mirBuilder.AddIntFieldConst(methodsInfoType, *newconst, fieldID++, annotationIdx); + mirBuilder.AddIntFieldConst(methodsInfoType, *newconst, fieldID++, flag); // @argsize: Number of arguments. size_t argsSize = func->GetParamSize(); - mirBuilder.AddIntFieldConst(*methodsInfoType, *newconst, fieldID++, argsSize); + mirBuilder.AddIntFieldConst(methodsInfoType, *newconst, fieldID++, argsSize); #ifndef USE_32BIT_REF // @padding - mirBuilder.AddIntFieldConst(*methodsInfoType, *newconst, fieldID++, 0); + mirBuilder.AddIntFieldConst(methodsInfoType, *newconst, fieldID++, 0); #endif aggconst->GetConstVec().push_back(newconst); } MIRSymbol *methodsArraySt = - GetOrCreateSymbol(NameMangler::kMethodsInfoPrefixStr + klass.GetKlassName(), arraytype->GetTypeIndex(), true); + GetOrCreateSymbol(NameMangler::kMethodsInfoPrefixStr + klass.GetKlassName(), arraytype.GetTypeIndex(), true); methodsArraySt->SetStorageClass(kScFstatic); methodsArraySt->SetKonst(aggconst); return methodsArraySt; } MIRSymbol *ReflectionAnalysis::GenSuperClassMetaData(const Klass &klass, std::list superClassList) { + MIRModule &module = *mirModule; size_t size = superClassList.size(); - MIRStructType *superclassMetadataType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(superclassMetadataTyIdx)); - MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*superclassMetadataType, size); - MIRAggConst *aggconst = mirModule->GetMemPool()->New(mirModule, arrayType); + MIRStructType &superclassMetadataType = + static_cast(*GlobalTables::GetTypeTable().GetTypeFromTyIdx(superclassMetadataTyIdx)); + MIRArrayType &arrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(superclassMetadataType, size); + MIRAggConst *aggconst = module.GetMemPool()->New(module, arrayType); for (auto it = superClassList.begin(); it != superClassList.end(); ++it) { MIRSymbol *dklassSt = GetOrCreateSymbol(CLASSINFO_PREFIX_STR + (*it)->GetKlassName(), classMetadataTyIdx); - MIRAggConst *newconst = mirModule->GetMemPool()->New(mirModule, superclassMetadataType); - mirBuilder.AddAddrofFieldConst(*superclassMetadataType, *newconst, 1, *dklassSt); + MIRAggConst *newconst = module.GetMemPool()->New(module, superclassMetadataType); + mirBuilder.AddAddrofFieldConst(superclassMetadataType, *newconst, 1, *dklassSt); aggconst->GetConstVec().push_back(newconst); } MIRSymbol *superclassArraySt = - GetOrCreateSymbol(SUPERCLASSINFO_PREFIX_STR + klass.GetKlassName(), arrayType->GetTypeIndex(), true); + GetOrCreateSymbol(SUPERCLASSINFO_PREFIX_STR + klass.GetKlassName(), arrayType.GetTypeIndex(), true); // Direct access to superclassinfo is only possible within a .so. superclassArraySt->SetStorageClass(kScFstatic); superclassArraySt->SetKonst(aggconst); @@ -781,6 +781,7 @@ static void ConvertFieldName(std::string &fieldname, bool staticfield) { } MIRSymbol *ReflectionAnalysis::GenFieldsMetaData(const Klass &klass) { + MIRModule &module = *mirModule; MIRClassType *classType = klass.GetMIRClassType(); FieldVector fields = classType->GetFields(); FieldVector staticFields = classType->GetStaticFields(); @@ -789,10 +790,10 @@ MIRSymbol *ReflectionAnalysis::GenFieldsMetaData(const Klass &klass) { if (size == 0) { return nullptr; } - MIRStructType *fieldsInfoType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldsInfoTyIdx)); - MIRArrayType *arraytype = GlobalTables::GetTypeTable().GetOrCreateArrayType(*fieldsInfoType, size); - MIRAggConst *aggconst = mirModule->GetMemPool()->New(mirModule, arraytype); + MIRStructType &fieldsInfoType = + static_cast(*GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldsInfoTyIdx)); + MIRArrayType &arraytype = *GlobalTables::GetTypeTable().GetOrCreateArrayType(fieldsInfoType, size); + MIRAggConst *aggconst = module.GetMemPool()->New(module, arraytype); std::vector> fieldHashvec(size); size_t i = 0; for (; i < fields.size(); i++) { @@ -832,7 +833,7 @@ MIRSymbol *ReflectionAnalysis::GenFieldsMetaData(const Klass &klass) { for (auto &fieldinfo : fieldinfoVec) { std::vector fieldsCompactLeb128Vec; FieldPair fieldP = fieldinfo.first; - MIRAggConst *newconst = mirModule->GetMemPool()->New(mirModule, fieldsInfoType); + MIRAggConst *newconst = module.GetMemPool()->New(module, fieldsInfoType); uint32 fieldID = 1; // We'll amend for the fieldname in generated metadata, so we need an original version of fieldname. std::string originFieldname = GlobalTables::GetStrTable().GetStringFromStrIdx(fieldP.first); @@ -857,18 +858,18 @@ MIRSymbol *ReflectionAnalysis::GenFieldsMetaData(const Klass &klass) { gvarSt->SetAttr(ATTR_weak); gvarSt->SetAttr(ATTR_static); } - mirBuilder.AddAddrofFieldConst(*fieldsInfoType, *newconst, fieldID++, *gvarSt); + mirBuilder.AddAddrofFieldConst(fieldsInfoType, *newconst, fieldID++, *gvarSt); } else { // Offset of the instance field, we fill the index of fields here and let CG to fill in. MIRClassType *mirClassType = klass.GetMIRClassType(); ASSERT(mirClassType != nullptr, "GetMIRClassType() returns null"); FieldID fldID = mirBuilder.GetStructFieldIDFromNameAndTypeParentFirstFoundInChild( *mirClassType, originFieldname.c_str(), fieldP.second.first); - mirBuilder.AddIntFieldConst(*fieldsInfoType, *newconst, fieldID++, fldID); + mirBuilder.AddIntFieldConst(fieldsInfoType, *newconst, fieldID++, fldID); } // @modifier FieldAttrs fa = fieldP.second.second; - mirBuilder.AddIntFieldConst(*fieldsInfoType, *newconst, fieldID++, GetFieldModifier(fa)); + mirBuilder.AddIntFieldConst(fieldsInfoType, *newconst, fieldID++, GetFieldModifier(fa)); ConvertFieldName(fieldname, staticfield); uint32 fieldname32Idx = FindOrInsertReflectString(fieldname); uint32 typeNameIdx = 0u; @@ -876,29 +877,29 @@ MIRSymbol *ReflectionAnalysis::GenFieldsMetaData(const Klass &klass) { // @flag uint16 hash = GetFieldHash(fieldHashvec, fieldP); uint16 flag = (hash << kNoHashBits); // Hash 10 bit. - mirBuilder.AddIntFieldConst(*fieldsInfoType, *newconst, fieldID++, flag); + mirBuilder.AddIntFieldConst(fieldsInfoType, *newconst, fieldID++, flag); // @index - mirBuilder.AddIntFieldConst(*fieldsInfoType, *newconst, fieldID++, idx); + mirBuilder.AddIntFieldConst(fieldsInfoType, *newconst, fieldID++, idx); // @type : Klass for type. // It's stored as type name, it's stored as a MIRIntConst. - mirBuilder.AddIntFieldConst(*fieldsInfoType, *newconst, fieldID++, typeNameIdx); + mirBuilder.AddIntFieldConst(fieldsInfoType, *newconst, fieldID++, typeNameIdx); // @fieldname : Offset of the name in *local* strTab. // In CG, we need to fill the offset as (__reflection_strtab___$file + offset of name). - mirBuilder.AddIntFieldConst(*fieldsInfoType, *newconst, fieldID++, fieldname32Idx); + mirBuilder.AddIntFieldConst(fieldsInfoType, *newconst, fieldID++, fieldname32Idx); // @annotation std::string annoArr; std::map idxNumMap; GeneAnnotation(idxNumMap, annoArr, *classType, kPragmaVar, fieldname, ty->GetTypeIndex()); uint32 annotationIdx = GetAnnoCstrIndex(idxNumMap, annoArr); - mirBuilder.AddIntFieldConst(*fieldsInfoType, *newconst, fieldID++, annotationIdx); + mirBuilder.AddIntFieldConst(fieldsInfoType, *newconst, fieldID++, annotationIdx); // @declaring class MIRSymbol *dklassSt = GetOrCreateSymbol(CLASSINFO_PREFIX_STR + klass.GetKlassName(), classMetadataTyIdx); - mirBuilder.AddAddrofFieldConst(*fieldsInfoType, *newconst, fieldID++, *dklassSt); + mirBuilder.AddAddrofFieldConst(fieldsInfoType, *newconst, fieldID++, *dklassSt); aggconst->GetConstVec().push_back(newconst); idx++; } MIRSymbol *fieldsArraySt = - GetOrCreateSymbol(NameMangler::kFieldsInfoPrefixStr + klass.GetKlassName(), arraytype->GetTypeIndex(), true); + GetOrCreateSymbol(NameMangler::kFieldsInfoPrefixStr + klass.GetKlassName(), arraytype.GetTypeIndex(), true); fieldsArraySt->SetStorageClass(kScFstatic); fieldsArraySt->SetKonst(aggconst); return fieldsArraySt; @@ -1129,6 +1130,7 @@ MIRSymbol *ReflectionAnalysis::GetClinitFuncSymbol(const Klass &klass) { } void ReflectionAnalysis::GenClassMetaData(Klass &klass) { + MIRModule &module = *mirModule; MIRClassType *classType = klass.GetMIRClassType(); ASSERT(classType != nullptr, "null ptr check!"); if (!classType->IsLocal()) { @@ -1146,14 +1148,13 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { LogInfo::MapleLogger(kLlErr) << "========= Gen Class: " << klassJavaDescriptor << " (" << hashIndex << ") ========" << std::endl; } - MIRStructType *classMetadataROType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(classMetadataRoTyIdx)); - MIRAggConst *newconst = mirModule->GetMemPool()->New(mirModule, classMetadataROType); + MIRStructType &classMetadataROType = + static_cast(*GlobalTables::GetTypeTable().GetTypeFromTyIdx(classMetadataRoTyIdx)); + MIRAggConst *newconst = module.GetMemPool()->New(module, classMetadataROType); uint32 fieldID = 1; // @classname uint32 nameIdx = FindOrInsertReflectString(klassJavaDescriptor); - ASSERT(classMetadataROType != nullptr, "null ptr check!"); - mirBuilder.AddIntFieldConst(*classMetadataROType, *newconst, fieldID++, nameIdx); + mirBuilder.AddIntFieldConst(classMetadataROType, *newconst, fieldID++, nameIdx); // @iFields: All instance fields. int numOfFields = 0; bool hasAdded = false; @@ -1162,7 +1163,7 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { kFieldsInfoPrefixStr + NameMangler::GetInternalNameLiteral(kJavaLangObjectStr)); MIRSymbol *fieldsSt = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(stridx); if (fieldsSt != nullptr) { - mirBuilder.AddAddrofFieldConst(*classMetadataROType, *newconst, fieldID++, *fieldsSt); + mirBuilder.AddAddrofFieldConst(classMetadataROType, *newconst, fieldID++, *fieldsSt); hasAdded = true; } } @@ -1171,9 +1172,9 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { if (fieldsSt != nullptr) { numOfFields = static_cast(fieldsSt->GetKonst())->GetConstVec().size(); // All meta data will be weak if dummy constructors. - mirBuilder.AddAddrofFieldConst(*classMetadataROType, *newconst, fieldID++, *fieldsSt); + mirBuilder.AddAddrofFieldConst(classMetadataROType, *newconst, fieldID++, *fieldsSt); } else { - mirBuilder.AddIntFieldConst(*classMetadataROType, *newconst, fieldID++, 0); + mirBuilder.AddIntFieldConst(classMetadataROType, *newconst, fieldID++, 0); } } // @methods: All methods. @@ -1182,9 +1183,9 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { methodsSt = GenMethodsMetaData(klass); if (methodsSt != nullptr) { numOfMethods = static_cast(methodsSt->GetKonst())->GetConstVec().size(); - mirBuilder.AddAddrofFieldConst(*classMetadataROType, *newconst, fieldID++, *methodsSt); + mirBuilder.AddAddrofFieldConst(classMetadataROType, *newconst, fieldID++, *methodsSt); } else { - mirBuilder.AddIntFieldConst(*classMetadataROType, *newconst, fieldID++, 0); + mirBuilder.AddIntFieldConst(classMetadataROType, *newconst, fieldID++, 0); } // @superclass: Super class and a list of implemented interfaces. std::list superClassList; @@ -1192,7 +1193,7 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { for (Klass *superClass : klass.GetSuperKlasses()) { superClassList.push_back(superClass); } - for (TyIdx const kTyIdx : classType->GetInerfaceImplemented()) { + for (TyIdx const kTyIdx : classType->GetInterfaceImplemented()) { Klass *interface = klassh->GetKlassFromTyIdx(kTyIdx); if (interface == nullptr) { missingSuper = true; @@ -1212,16 +1213,16 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { size_t superClassSize = superClassList.size(); if (superClassSize >= 1) { MIRSymbol *superClassSymbolType = GenSuperClassMetaData(klass, superClassList); - mirBuilder.AddAddrofFieldConst(*classMetadataROType, *newconst, fieldID++, *superClassSymbolType); + mirBuilder.AddAddrofFieldConst(classMetadataROType, *newconst, fieldID++, *superClassSymbolType); } else { - mirBuilder.AddIntFieldConst(*classMetadataROType, *newconst, fieldID++, 0); + mirBuilder.AddIntFieldConst(classMetadataROType, *newconst, fieldID++, 0); } // @numoffields: Num of fields (own). CHECK_FATAL(numOfFields <= 0xffff, "Error:the num of fields is too large"); - mirBuilder.AddIntFieldConst(*classMetadataROType, *newconst, fieldID++, numOfFields); + mirBuilder.AddIntFieldConst(classMetadataROType, *newconst, fieldID++, numOfFields); // @numofmethods: Num of methods in vtable. CHECK_FATAL(numOfMethods <= 0xffff, "Error:the num of methods is too large"); - mirBuilder.AddIntFieldConst(*classMetadataROType, *newconst, fieldID++, numOfMethods); + mirBuilder.AddIntFieldConst(classMetadataROType, *newconst, fieldID++, numOfMethods); // Do annotation. std::string annoArray; std::map idxNumMap; @@ -1234,67 +1235,67 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { // Array class and primitive class is not generated by compiler. uint32 flag = klass.GetFlag(kClassHasFinalizer | CLASS_REFERENCE | kClassFinalizerreferenceSentinel); flag = isAnonymous ? (flag | kClassIsanonymousclass) : flag; - mirBuilder.AddIntFieldConst(*classMetadataROType, *newconst, fieldID++, flag); + mirBuilder.AddIntFieldConst(classMetadataROType, *newconst, fieldID++, flag); // @numofsuperclasses CHECK_FATAL(superClassSize <= 0xffff, "Error:the size of superClass is too big"); - mirBuilder.AddIntFieldConst(*classMetadataROType, *newconst, fieldID++, superClassSize); + mirBuilder.AddIntFieldConst(classMetadataROType, *newconst, fieldID++, superClassSize); // @padding - mirBuilder.AddIntFieldConst(*classMetadataROType, *newconst, fieldID++, 0); + mirBuilder.AddIntFieldConst(classMetadataROType, *newconst, fieldID++, 0); #endif // USE_32BIT_REF // @modifier: For class fill ClassAccessFlags. uint32 modifier = GetClassAccessFlags(*classType); - mirBuilder.AddIntFieldConst(*classMetadataROType, *newconst, fieldID++, modifier); + mirBuilder.AddIntFieldConst(classMetadataROType, *newconst, fieldID++, modifier); // @annotation: Set annotation field. - SetAnnoFieldConst(*classMetadataROType, *newconst, fieldID++, idxNumMap, annoArray); + SetAnnoFieldConst(classMetadataROType, *newconst, fieldID++, idxNumMap, annoArray); // @ClinitFuncAddr MIRSymbol *clinitFuncSym = GetClinitFuncSymbol(klass); if (clinitFuncSym != nullptr) { - mirBuilder.AddAddroffuncFieldConst(*classMetadataROType, *newconst, fieldID++, *clinitFuncSym); + mirBuilder.AddAddroffuncFieldConst(classMetadataROType, *newconst, fieldID++, *clinitFuncSym); } else { - mirBuilder.AddIntFieldConst(*classMetadataROType, *newconst, fieldID++, 0); + mirBuilder.AddIntFieldConst(classMetadataROType, *newconst, fieldID++, 0); } MIRSymbol *classMetadataROSymbolType = GetOrCreateSymbol(CLASSINFO_RO_PREFIX_STR + klass.GetKlassName(), classMetadataRoTyIdx, true); classMetadataROSymbolType->SetStorageClass(kScFstatic); classMetadataROSymbolType->SetKonst(newconst); // Class Metadata definition start here. - MIRStructType *classMetadataType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(classMetadataTyIdx)); - newconst = mirModule->GetMemPool()->New(mirModule, classMetadataType); + MIRStructType &classMetadataType = + static_cast(*GlobalTables::GetTypeTable().GetTypeFromTyIdx(classMetadataTyIdx)); + newconst = module.GetMemPool()->New(module, classMetadataType); fieldID = 1; // @shadow: multiplex used for def index. - mirBuilder.AddIntFieldConst(*classMetadataType, *newconst, fieldID++, 0); + mirBuilder.AddIntFieldConst(classMetadataType, *newconst, fieldID++, 0); // @monitor: multiplex used for class hash. - mirBuilder.AddIntFieldConst(*classMetadataType, *newconst, fieldID++, hashIndex); + mirBuilder.AddIntFieldConst(classMetadataType, *newconst, fieldID++, hashIndex); // @class loader: Use maximum value unsigned(-1) as non-initialized flag. - mirBuilder.AddIntFieldConst(*classMetadataType, *newconst, fieldID++, static_cast(-1)); + mirBuilder.AddIntFieldConst(classMetadataType, *newconst, fieldID++, static_cast(-1)); // @objsize: Fill this in the CG. - mirBuilder.AddIntFieldConst(*classMetadataType, *newconst, fieldID++, 0); + mirBuilder.AddIntFieldConst(classMetadataType, *newconst, fieldID++, 0); #ifdef USE_32BIT_REF // @flag // Array class and primitive class is not generated by compiler. uint32 flag = klass.GetFlag(kClassHasFinalizer | CLASS_REFERENCE | kClassFinalizerreferenceSentinel); flag = isAnonymous ? (flag | kClassIsanonymousclass) : flag; - mirBuilder.AddIntFieldConst(*classMetadataType, *newconst, fieldID++, flag); + mirBuilder.AddIntFieldConst(classMetadataType, *newconst, fieldID++, flag); // @numofsuperclasses CHECK_FATAL(superClassSize <= 0xffff, "Error:the size of superClass is too big"); - mirBuilder.AddIntFieldConst(*classMetadataType, *newconst, fieldID++, superClassSize); + mirBuilder.AddIntFieldConst(classMetadataType, *newconst, fieldID++, superClassSize); #endif // USE_32BIT_REF // @itab GStrIdx strIdx = GlobalTables::GetStrTable().GetStrIdxFromName(ITAB_PREFIX_STR + klass.GetKlassName()); if (strIdx != 0) { MIRSymbol *itableSymbolType = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(strIdx); - mirBuilder.AddAddrofFieldConst(*classMetadataType, *newconst, fieldID++, *itableSymbolType); + mirBuilder.AddAddrofFieldConst(classMetadataType, *newconst, fieldID++, *itableSymbolType); } else { - mirBuilder.AddIntFieldConst(*classMetadataType, *newconst, fieldID++, 0); + mirBuilder.AddIntFieldConst(classMetadataType, *newconst, fieldID++, 0); } // @vtab strIdx = GlobalTables::GetStrTable().GetStrIdxFromName(VTAB_PREFIX_STR + klass.GetKlassName()); if (strIdx != 0) { MIRSymbol *vtableSymbolType = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(strIdx); - mirBuilder.AddAddrofFieldConst(*classMetadataType, *newconst, fieldID++, *vtableSymbolType); + mirBuilder.AddAddrofFieldConst(classMetadataType, *newconst, fieldID++, *vtableSymbolType); } else { - mirBuilder.AddIntFieldConst(*classMetadataType, *newconst, fieldID++, 0); + mirBuilder.AddIntFieldConst(classMetadataType, *newconst, fieldID++, 0); } // @gctib MIRSymbol *gctibSt = GetOrCreateSymbol(GCTIB_PREFIX_STR + klass.GetKlassName(), @@ -1303,9 +1304,9 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { // Direct access to gctib is only possible within a .so, for most classes. gctibSt->SetStorageClass(kScFstatic); } - mirBuilder.AddAddrofFieldConst(*classMetadataType, *newconst, fieldID++, *gctibSt); + mirBuilder.AddAddrofFieldConst(classMetadataType, *newconst, fieldID++, *gctibSt); // @classinfo ro. - mirBuilder.AddAddrofFieldConst(*classMetadataType, *newconst, fieldID++, *classMetadataROSymbolType); + mirBuilder.AddAddrofFieldConst(classMetadataType, *newconst, fieldID++, *classMetadataROSymbolType); // Set default value to class initialization state. // If this class and its parents do not have clinit, we do not clinit-check for this class. if (klassh->NeedClinitCheckRecursively(klass)) { @@ -1313,12 +1314,12 @@ void ReflectionAnalysis::GenClassMetaData(Klass &klass) { MIRSymbol *classInitProtectRegion = mirBuilder.GetOrCreateSymbol( ptrType->GetTypeIndex(), kClassInitProtectRegionStr, kStVar, kScExtern, nullptr, kScopeGlobal, true); classInitProtectRegion->SetAttr(ATTR_extern); - mirBuilder.AddAddrofFieldConst(*classMetadataType, *newconst, fieldID++, *classInitProtectRegion); + mirBuilder.AddAddrofFieldConst(classMetadataType, *newconst, fieldID++, *classInitProtectRegion); } else { MIRType *clinitState = GlobalTables::GetTypeTable().GetUInt64(); // The class initialization state is modified to classStateInitialized. MIRSymbol *classInfo = mirBuilder.GetOrCreateGlobalDecl(kClassStateInitializedStr, *clinitState); - mirBuilder.AddAddrofFieldConst(*classMetadataType, *newconst, fieldID++, *classInfo); + mirBuilder.AddAddrofFieldConst(classMetadataType, *newconst, fieldID++, *classInfo); } // Finally generate class metadata here. MIRSymbol *classSt = GetOrCreateSymbol(CLASSINFO_PREFIX_STR + klass.GetKlassName(), classMetadataTyIdx, true); @@ -1483,8 +1484,10 @@ void ReflectionAnalysis::GenMetadataType(MIRModule &mirModule) { MIRType *typeU16 = GlobalTables::GetTypeTable().GetUInt16(); MIRType *typeI32 = GlobalTables::GetTypeTable().GetInt32(); MIRType *typeU32 = GlobalTables::GetTypeTable().GetUInt32(); +#ifndef USE_32BIT_REF MIRType *typeI64 = GlobalTables::GetTypeTable().GetInt64(); MIRType *typeU64 = GlobalTables::GetTypeTable().GetUInt64(); +#endif MIRType *typeVoidPtr = GlobalTables::GetTypeTable().GetVoidPtr(); MIRStructType classMetadataType(kTypeStruct); GlobalTables::GetTypeTable().AddFieldToStructType(classMetadataType, kShadowStr, *GetRefFieldType(mirBuilder)); @@ -1578,6 +1581,7 @@ void ReflectionAnalysis::GenMetadataType(MIRModule &mirModule) { void ReflectionAnalysis::GenClassHashMetaData() { MIRType *type = GlobalTables::GetTypeTable().GetVoidPtr(); + MIRModule &module = *mirModule; CHECK_FATAL(type != nullptr, "type is null in ReflectionAnalysis::GenClassHashMetaData"); if (raDebug) { LogInfo::MapleLogger(kLlErr) << "========= HASH TABLE ========" << std::endl; @@ -1585,41 +1589,41 @@ void ReflectionAnalysis::GenClassHashMetaData() { if (classTab.empty()) { return; } - std::string bucketName = NameMangler::kMuidClassMetadataBucketPrefixStr + mirModule->GetFileNameAsPostfix(); + std::string bucketName = NameMangler::kMuidClassMetadataBucketPrefixStr + module.GetFileNameAsPostfix(); size_t bucketArraySize = classTab.size(); - MIRArrayType *bucketArraytype = GlobalTables::GetTypeTable().GetOrCreateArrayType(*type, bucketArraySize); - MIRSymbol *bucketSt = GetOrCreateSymbol(bucketName, bucketArraytype->GetTypeIndex(), true); - MIRAggConst *bucketAggconst = mirModule->GetMemPool()->New(mirModule, bucketArraytype); + MIRArrayType &bucketArraytype = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*type, bucketArraySize); + MIRSymbol *bucketSt = GetOrCreateSymbol(bucketName, bucketArraytype.GetTypeIndex(), true); + MIRAggConst *bucketAggconst = module.GetMemPool()->New(module, bucketArraytype); if (bucketAggconst == nullptr) { return; } for (MIRSymbol *classSt : classTab) { AddrofNode *classExpr = mirBuilder.CreateExprAddrof(0, *classSt); - MIRType *ptrType = GlobalTables::GetTypeTable().GetTypeTable()[PTY_ptr]; + MIRType &ptrType = *GlobalTables::GetTypeTable().GetTypeTable()[PTY_ptr]; MIRConst *classConst = - mirModule->GetMemPool()->New(classExpr->GetStIdx(), classExpr->GetFieldID(), ptrType); + module.GetMemPool()->New(classExpr->GetStIdx(), classExpr->GetFieldID(), ptrType); bucketAggconst->GetConstVec().push_back(classConst); } bucketSt->SetKonst(bucketAggconst); } -static void ReflectionAnalysisGenStrTab(MIRModule *mirModule, const std::string &strTab, +static void ReflectionAnalysisGenStrTab(MIRModule &mirModule, const std::string &strTab, const std::string &strtabName) { - MIRBuilder &mirBuilder = *(mirModule->GetMIRBuilder()); + MIRBuilder &mirBuilder = *(mirModule.GetMIRBuilder()); size_t strtabSize = strTab.length(); if (strtabSize == 1) { return; } - MIRArrayType *strtabType = - GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetUInt8(), strtabSize); + MIRArrayType &strtabType = + *GlobalTables::GetTypeTable().GetOrCreateArrayType(*GlobalTables::GetTypeTable().GetUInt8(), strtabSize); MIRSymbol *strtabSt = mirBuilder.CreateGlobalDecl(strtabName.c_str(), strtabType); - MIRAggConst *strtabAggconst = mirModule->GetMemPool()->New(mirModule, strtabType); + MIRAggConst *strtabAggconst = mirModule.GetMemPool()->New(mirModule, strtabType); if (strtabAggconst == nullptr) { return; } strtabSt->SetStorageClass(kScFstatic); for (const char &c : strTab) { - MIRConst *newconst = mirModule->GetMemPool()->New(c, GlobalTables::GetTypeTable().GetUInt8()); + MIRConst *newconst = mirModule.GetMemPool()->New(c, *GlobalTables::GetTypeTable().GetUInt8()); strtabAggconst->GetConstVec().push_back(newconst); } strtabSt->SetKonst(strtabAggconst); @@ -1628,14 +1632,14 @@ static void ReflectionAnalysisGenStrTab(MIRModule *mirModule, const std::string void ReflectionAnalysis::GenStrTab(MIRModule &mirModule) { // Hot string tab. std::string hotStrtabName = NameMangler::kReflectionStartHotStrtabPrefixStr + mirModule.GetFileNameAsPostfix(); - ReflectionAnalysisGenStrTab(&mirModule, strTabStartHot, hotStrtabName); + ReflectionAnalysisGenStrTab(mirModule, strTabStartHot, hotStrtabName); hotStrtabName = NameMangler::kReflectionBothHotStrTabPrefixStr + mirModule.GetFileNameAsPostfix(); - ReflectionAnalysisGenStrTab(&mirModule, strTabBothHot, hotStrtabName); + ReflectionAnalysisGenStrTab(mirModule, strTabBothHot, hotStrtabName); hotStrtabName = NameMangler::kReflectionRunHotStrtabPrefixStr + mirModule.GetFileNameAsPostfix(); - ReflectionAnalysisGenStrTab(&mirModule, strTabRunHot, hotStrtabName); + ReflectionAnalysisGenStrTab(mirModule, strTabRunHot, hotStrtabName); // Cold string tab. std::string strtabName = NameMangler::kReflectionStrtabPrefixStr + mirModule.GetFileNameAsPostfix(); - ReflectionAnalysisGenStrTab(&mirModule, strTab, strtabName); + ReflectionAnalysisGenStrTab(mirModule, strTab, strtabName); } void ReflectionAnalysis::MarkWeakMethods() { diff --git a/src/mpl2mpl/src/vtable_analysis.cpp b/src/mpl2mpl/src/vtable_analysis.cpp index 715fe32d23c1000a0780807edfdaa6e58fbe0eef..17821d468991b76f551416aecd713a44bb9994c5 100644 --- a/src/mpl2mpl/src/vtable_analysis.cpp +++ b/src/mpl2mpl/src/vtable_analysis.cpp @@ -29,8 +29,8 @@ VtableAnalysis::VtableAnalysis(MIRModule *mod, KlassHierarchy *kh, bool dump) : voidPtrType = GlobalTables::GetTypeTable().GetVoidPtr(); // zeroConst and oneConst are shared amony itab entries. It is safe to share them because // they are never removed by anybody. - zeroConst = GetModule()->GetMemPool()->New(0, voidPtrType); - oneConst = GetModule()->GetMemPool()->New(1, voidPtrType); + zeroConst = GetMIRModule().GetMemPool()->New(0, *voidPtrType); + oneConst = GetMIRModule().GetMemPool()->New(1, *voidPtrType); for (Klass *klass : klassHierarchy->GetTopoSortedKlasses()) { ASSERT(klass != nullptr, "null ptr check!"); GenVtableList(*klass); @@ -112,7 +112,7 @@ void VtableAnalysis::GenVtableList(const Klass &klass) { } // vtable from implemented interfaces, need to merge in. both default or none-default // Note, all interface methods are also virtual methods, need to be in vtable too. - for (TyIdx const &tyIdx : curType->GetInerfaceImplemented()) { + for (TyIdx const &tyIdx : curType->GetInterfaceImplemented()) { MIRInterfaceType *iType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)); for (MethodPair *methodPair : iType->GetVTableMethods()) { MIRFunction *method = builder->GetFunctionFromStidx(methodPair->first); @@ -160,12 +160,12 @@ void VtableAnalysis::GenVtableList(const Klass &klass) { void VtableAnalysis::GenVtableDefinition(const Klass &klass) { MIRStructType *curType = klass.GetMIRStructType(); - MIRAggConst *newconst = GetModule()->GetMemPool()->New(GetModule(), voidPtrType); + MIRAggConst *newconst = GetMIRModule().GetMemPool()->New(GetMIRModule(), *voidPtrType); ASSERT(newconst != nullptr, "null ptr check!"); for (MethodPair *methodPair : curType->GetVTableMethods()) { MIRFunction *vtabMethod = builder->GetFunctionFromStidx(methodPair->first); - AddroffuncNode *addrofFuncNode = builder->CreateExprAddroffunc(vtabMethod->GetPuidx(), GetModule()->GetMemPool()); - MIRConst *constNode = GetModule()->GetMemPool()->New(addrofFuncNode->GetPUIdx(), voidPtrType); + AddroffuncNode *addrofFuncNode = builder->CreateExprAddroffunc(vtabMethod->GetPuidx(), GetMIRModule().GetMemPool()); + MIRConst *constNode = GetMIRModule().GetMemPool()->New(addrofFuncNode->GetPUIdx(), *voidPtrType); newconst->GetConstVec().push_back(constNode); } // We also need to generate vtable and itable even if the class does not @@ -273,30 +273,30 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { } } // Create the first-level itable, which is directly accessed as an array - MIRAggConst *firstItabEmitArray = GetModule()->GetMemPool()->New(GetModule(), voidPtrType); + MIRAggConst *firstItabEmitArray = GetMIRModule().GetMemPool()->New(GetMIRModule(), *voidPtrType); ASSERT(firstItabEmitArray != nullptr, "null ptr check!"); for (MIRFunction *func : firstItabVec) { if (func != nullptr) { firstItabEmitArray->GetConstVec().push_back( - GetModule()->GetMemPool()->New(func->GetPuidx(), voidPtrType)); + GetMIRModule().GetMemPool()->New(func->GetPuidx(), *voidPtrType)); } else { firstItabEmitArray->GetConstVec().push_back(zeroConst); } } // initialize conflict solution array if (count != 0) { - MIRAggConst *secondItabEmitArray = GetModule()->GetMemPool()->New(GetModule(), voidPtrType); + MIRAggConst *secondItabEmitArray = GetMIRModule().GetMemPool()->New(GetMIRModule(), *voidPtrType); // remember count in secondItabVec - secondItabEmitArray->GetConstVec().push_back(GetModule()->GetMemPool()->New(count, voidPtrType)); + secondItabEmitArray->GetConstVec().push_back(GetMIRModule().GetMemPool()->New(count, *voidPtrType)); secondItabEmitArray->GetConstVec().push_back(oneConst); // padding for (uint32 i = 0; i < kItabSecondHashSize; i++) { if (!secondItab[i] && !secondConflictFlag[i]) { continue; } else { - secondItabEmitArray->GetConstVec().push_back(GetModule()->GetMemPool()->New(i, voidPtrType)); + secondItabEmitArray->GetConstVec().push_back(GetMIRModule().GetMemPool()->New(i, *voidPtrType)); if (secondItab[i]) { secondItabEmitArray->GetConstVec().push_back( - GetModule()->GetMemPool()->New(secondItab[i]->GetPuidx(), voidPtrType)); + GetMIRModule().GetMemPool()->New(secondItab[i]->GetPuidx(), *voidPtrType)); } else { // it measn it was conflict again in the second hash secondItabEmitArray->GetConstVec().push_back(oneConst); @@ -307,23 +307,23 @@ void VtableAnalysis::GenItableDefinition(const Klass &klass) { ASSERT(func != nullptr, "null ptr check!"); const std::string &signatureName = DecodeBaseNameWithType(*func); uint32 nameIdx = ReflectionAnalysis::FindOrInsertRepeatString(signatureName); - secondItabEmitArray->GetConstVec().push_back(GetModule()->GetMemPool()->New(nameIdx, voidPtrType)); + secondItabEmitArray->GetConstVec().push_back(GetMIRModule().GetMemPool()->New(nameIdx, *voidPtrType)); secondItabEmitArray->GetConstVec().push_back( - GetModule()->GetMemPool()->New(func->GetPuidx(), voidPtrType)); + GetMIRModule().GetMemPool()->New(func->GetPuidx(), *voidPtrType)); } // Create the second-level itable, in which hashcode is looked up by binary searching GenTableSymbol(ITAB_CONFLICT_PREFIX_STR, klass.GetKlassName(), *secondItabEmitArray); // push the conflict symbol to the first-level itable StIdx symIdx = GlobalTables::GetGsymTable().GetStIdxFromStrIdx( GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(ITAB_CONFLICT_PREFIX_STR + klass.GetKlassName())); - firstItabEmitArray->GetConstVec().push_back(GetModule()->GetMemPool()->New(symIdx, 0, voidPtrType)); + firstItabEmitArray->GetConstVec().push_back(GetMIRModule().GetMemPool()->New(symIdx, 0, *voidPtrType)); } GenTableSymbol(ITAB_PREFIX_STR, klass.GetKlassName(), *firstItabEmitArray); } void VtableAnalysis::GenTableSymbol(const std::string &prefix, const std::string klassName, MIRAggConst &newconst) { size_t arraySize = newconst.GetConstVec().size(); - MIRArrayType *arrayType = GlobalTables::GetTypeTable().GetOrCreateArrayType(*voidPtrType, arraySize); + MIRArrayType &arrayType = *GlobalTables::GetTypeTable().GetOrCreateArrayType(*voidPtrType, arraySize); MIRSymbol *vtabSt = builder->CreateGlobalDecl((prefix + klassName).c_str(), arrayType); if (klassName == NameMangler::GetInternalNameLiteral(NameMangler::kJavaLangObjectStr)) { vtabSt->SetStorageClass(kScGlobal); @@ -345,7 +345,7 @@ void VtableAnalysis::ProcessFunc(MIRFunction *func) { if (func->IsEmpty()) { return; } - SetCurrentFunction(func); + SetCurrentFunction(*func); StmtNode *stmt = func->GetBody()->GetFirst(); StmtNode *next = nullptr; while (stmt != nullptr) { @@ -405,12 +405,12 @@ void VtableAnalysis::ReplaceSuperclassInvoke(CallNode &stmt) { CHECK_FATAL(actualMIRFunc, "Can not find the implementation of %s", callee->GetName().c_str()); stmt.SetOpCode(OP_callassigned); stmt.SetPUIdx(actualMIRFunc->GetPuidx()); - GetModule()->addSuperCall(actualMIRFunc->GetName()); + GetMIRModule().addSuperCall(actualMIRFunc->GetName()); } void VtableAnalysis::ReplacePolymorphicInvoke(CallNode &stmt) { IntrinsiccallNode *intrinCall = - GetModule()->CurFuncCodeMemPool()->New(*GetModule(), OP_xintrinsiccallassigned); + GetMIRModule().CurFuncCodeMemPool()->New(GetMIRModule(), OP_xintrinsiccallassigned); intrinCall->SetIntrinsic(INTRN_JAVA_POLYMORPHIC_CALL); intrinCall->SetNumOpnds(stmt.GetNumOpnds()); intrinCall->SetReturnVec(stmt.GetReturnVec()); diff --git a/src/mpl2mpl/src/vtable_impl.cpp b/src/mpl2mpl/src/vtable_impl.cpp index c40d0c0b5e2511241bfa22b0ca472267398130f4..95cf3c3c4848d6bc8867abc8abf2ba75068a738f 100644 --- a/src/mpl2mpl/src/vtable_impl.cpp +++ b/src/mpl2mpl/src/vtable_impl.cpp @@ -31,7 +31,7 @@ void VtableImpl::ProcessFunc(MIRFunction *func) { if (func->IsEmpty()) { return; } - SetCurrentFunction(func); + SetCurrentFunction(*func); StmtNode *stmt = func->GetBody()->GetFirst(); StmtNode *next = nullptr; while (stmt != nullptr) {