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