diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 285173f5496087782ae9ddb3513f39639124660b..26893d03c4e2bf675d69bd0385ca61a64b85c255 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index cb9e09590c4f92b75665d57efb2a934e236a38cc..a7b69e8730219fdca4a276195c15d37fac0569bf 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index f29743b12145e1e23d3b50349488fd7d81c67cfb..a7da3f16d43c0d9ff299b9ce04fe92059e64cc06 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/maple_ipa/include/interleaved_manager.h b/src/maple_ipa/include/interleaved_manager.h index b8797c388f1ea6a0da944a9eca7891959b2ad7e7..9098785f65bd1483cb7480555459fc158e24cfd6 100644 --- a/src/maple_ipa/include/interleaved_manager.h +++ b/src/maple_ipa/include/interleaved_manager.h @@ -52,7 +52,10 @@ class InterleavedManager { } void AddPhases(std::vector &phases, bool isModulePhase, bool timePhases = false, bool genMpl = false); + void AddIPAPhases(std::vector &phases, bool timePhases = false, bool genMpl = false); void Run(); + void IPARun(MeFuncPhaseManager*); + PhaseManager *AccessPhaseManager(int i) const { return phaseManagers.at(i); } diff --git a/src/maple_ipa/include/module_phase_manager.h b/src/maple_ipa/include/module_phase_manager.h index 4c1e5c34e66a9fb51d2b95ee76792f58e12648b5..dc02fcdb3aa0901b9dec978d82fa94d63b153669 100644 --- a/src/maple_ipa/include/module_phase_manager.h +++ b/src/maple_ipa/include/module_phase_manager.h @@ -52,7 +52,7 @@ class ModulePhaseManager : public PhaseManager { // Add module phases which are going to be run void AddModulePhases(std::vector &phases); void RunModulePhases() const; - ModuleResultMgr *GetModResultMgr() { + ModuleResultMgr *GetModResultMgr() override { return arModuleMgr; } diff --git a/src/maple_ipa/src/interleaved_manager.cpp b/src/maple_ipa/src/interleaved_manager.cpp index 5b6a6f33866dc09c63743d2d96dfe289fcc1910b..8bdacf944855b730084dc8cd49ea9efe4b857642 100644 --- a/src/maple_ipa/src/interleaved_manager.cpp +++ b/src/maple_ipa/src/interleaved_manager.cpp @@ -27,17 +27,13 @@ using namespace maple; + void InterleavedManager::AddPhases(std::vector &phases, bool isModulePhase, bool timePhases, bool genMpl) { ModuleResultMgr *mrm = nullptr; if (!phaseManagers.empty()) { // ModuleResult such class hierarchy need to be carried on - ModulePhaseManager *mpm = dynamic_cast(phaseManagers[phaseManagers.size() - 1]); - MeFuncPhaseManager *mepm = dynamic_cast(phaseManagers[phaseManagers.size() - 1]); - if (mpm != nullptr) { - mrm = mpm->GetModResultMgr(); - } else if (mepm != nullptr) { - mrm = mepm->GetModResultMgr(); - } + PhaseManager *pm = phaseManagers.back(); + mrm = pm->GetModResultMgr(); } if (isModulePhase) { @@ -62,6 +58,7 @@ void InterleavedManager::AddPhases(std::vector &phases, bool isModu } } + void InterleavedManager::Run() { for (PhaseManager * const &pm : phaseManagers) { if (pm == nullptr) { diff --git a/src/maple_ir/include/bin_mpl_export.h b/src/maple_ir/include/bin_mpl_export.h index f74a74acbd4a768b1fd4084b9480c542c4615022..6a602d1c387c03c0078bb3f2af8e074c95a4b867 100644 --- a/src/maple_ir/include/bin_mpl_export.h +++ b/src/maple_ir/include/bin_mpl_export.h @@ -28,6 +28,11 @@ enum : uint8 { kBinInitConst = 2, kBinSymbol = 3, kBinFunction = 4, + kBinEaCgNode, + kBinEaCgActNode, + kBinEaCgFieldNode, + kBinEaCgRefNode, + kBinEaCgObjNode, kBinCallinfo = 5, kBinKindTypeScalar = 6, kBinKindTypeByName = 7, @@ -57,6 +62,8 @@ enum : uint8 { kBinTypeStart = 31, kBinCgStart = 32, kBinSeStart = 33, + kBinEaCgStart, + kBinEaStart, kBinFinish = 34, kStartMethod = 35, }; diff --git a/src/maple_ir/include/bin_mpl_import.h b/src/maple_ir/include/bin_mpl_import.h index 7ca0ef7686754d55f4cab7f6487fb8746e9c9c52..d9311fa959c459ab15e784690d4ac69019cc4d27 100644 --- a/src/maple_ir/include/bin_mpl_import.h +++ b/src/maple_ir/include/bin_mpl_import.h @@ -19,7 +19,6 @@ #include "mir_preg.h" #include "parser_opt.h" #include "mir_builder.h" - namespace maple { class BinaryMplImport { using CallSite = std::pair; diff --git a/src/maple_ir/include/global_tables.h b/src/maple_ir/include/global_tables.h index 01fb39fef4e2c574c5d4c071c98cb300f6df9ea4..9e902f9e8e1446411f4c7856b8eafbf01ffd1671 100644 --- a/src/maple_ir/include/global_tables.h +++ b/src/maple_ir/include/global_tables.h @@ -60,26 +60,9 @@ class UStrIdxHash { }; class TypeTable { - private: - using MIRTypePtr = MIRType*; - struct Hash { - uint32 operator()(const MIRTypePtr &ty) const { - return ty->GetHashIndex(); - } - }; - - struct Equal { - uint32 operator()(const MIRTypePtr &tx, const MIRTypePtr &ty) const { - return tx->EqualTo(*ty); - } - }; - - std::unordered_set typeHashTable; - public: static MIRType *voidPtrType; - public: TypeTable(); TypeTable(const TypeTable&) = delete; TypeTable &operator=(const TypeTable&) = delete; @@ -305,9 +288,22 @@ class TypeTable { void AddFieldToStructType(MIRStructType *structType, const char *fieldName, MIRType *fieldType); private: + using MIRTypePtr = MIRType*; + struct Hash { + uint32 operator()(const MIRTypePtr &ty) const { + return ty->GetHashIndex(); + } + }; + + struct Equal { + uint32 operator()(const MIRTypePtr &tx, const MIRTypePtr &ty) const { + return tx->EqualTo(*ty); + } + }; + + std::unordered_set typeHashTable; std::vector typeTable; - private: MIRType *CreateType(MIRType *oldType); MIRType *GetOrCreateStructOrUnion(const char *name, const FieldVector &fields, const FieldVector &prntFields, MIRModule *module, bool forStruct = true); diff --git a/src/maple_ir/include/intrinsics.def b/src/maple_ir/include/intrinsics.def index c8fe2c60fdc5d5ae711a641377db1b057473ba85..bf6c0ec63b4c023eeaf688911cae96ed092069b1 100644 --- a/src/maple_ir/include/intrinsics.def +++ b/src/maple_ir/include/intrinsics.def @@ -45,6 +45,8 @@ DEF_MIR_INTRINSIC(MCCLoadRefSVol,\ "MCC_LoadVolatileStaticField", INTRNISRC | INTRNNOSIDEEFFECT, kArgTyVoid, kArgTyRef) DEF_MIR_INTRINSIC(MCCLoadRefS,\ "MCC_LoadRefStatic", INTRNISRC | INTRNNOSIDEEFFECT, kArgTyVoid, kArgTyRef) +DEF_MIR_INTRINSIC(MCCSetObjectPermanent,\ + "MCC_SetObjectPermanent", INTRNISRC | INTRNNOSIDEEFFECT, kArgTyVoid, kArgTyRef) // start of RC Intrinsics with two parameters DEF_MIR_INTRINSIC(MCCIncDecRef,\ @@ -110,6 +112,9 @@ DEF_MIR_INTRINSIC(MPL_MEMSET_LOCALVAR,\ "", kIntrnUndef, kArgTyPtr, kArgTyU32, kArgTyU8, kArgTyU32, kArgTyUndef, kArgTyUndef, kArgTyUndef) DEF_MIR_INTRINSIC(MPL_SET_CLASS,\ "", kIntrnUndef, kArgTyPtr, kArgTyPtr, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) +DEF_MIR_INTRINSIC(MPL_CLEANUP_NORETESCOBJS,\ + "__mpl_cleanup_noretescobjs", INTRNISJAVA | INTRNNOSIDEEFFECT, kArgTyUndef, kArgTyRef, kArgTyRef,\ + kArgTyRef, kArgTyRef, kArgTyRef, kArgTyRef) #include "intrinsic_java.def" DEF_MIR_INTRINSIC(LAST,\ nullptr, kIntrnUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef, kArgTyUndef) diff --git a/src/maple_ir/include/mir_function.h b/src/maple_ir/include/mir_function.h index fdc261ddae8c27f149bbdee2b26dbdac088e7ccf..6bdb07a2f801310f8f9b37be49a96407c2fb716c 100644 --- a/src/maple_ir/include/mir_function.h +++ b/src/maple_ir/include/mir_function.h @@ -58,6 +58,9 @@ constexpr uint8 kNoUseEffect = 0x8; constexpr uint8 kNoDefEffect = 0x4; constexpr uint8 kNoRetNewlyAllocObj = 0x2; constexpr uint8 kNoThrowException = 0x1; + +class MeFunction; +class EAConnectionGraph; class MIRFunction { public: MIRFunction(MIRModule *mod, const StIdx sidx) @@ -94,6 +97,8 @@ class MIRFunction { signatureStrIdx = GStrIdx(0); hashCode = 0; layoutType = kLayoutUnused; + mefunc = nullptr; + eacg = nullptr; } ~MIRFunction() {} @@ -824,6 +829,22 @@ class MIRFunction { localWordsRefCounted = lwr; } + MeFunction *GetMeFunc() { + return mefunc; + } + + void SetMeFunc(MeFunction *func) { + mefunc = func; + } + + EAConnectionGraph *GetEACG() { + return eacg; + } + + void SetEACG(EAConnectionGraph *eacgVal) { + eacg = eacgVal; + } + TyIdx GetClassTyIdx() { return classTyIdx; } @@ -983,6 +1004,8 @@ class MIRFunction { // uint16 numlabels; // removed. label table size // StmtNode **lbl2stmt; // lbl2stmt table, removed; // to hold unmangled class and function names + MeFunction *mefunc; + EAConnectionGraph *eacg; GStrIdx baseClassStrIdx; // the string table index of base class name GStrIdx baseFuncStrIdx; // the string table index of base function name // the string table index of base function name mangled with type info diff --git a/src/maple_ir/include/mir_module.h b/src/maple_ir/include/mir_module.h index 7707a3e925f1778f6d3f53132bb7437ccb9d745c..bb6053c6d152506be256844b8038a388b80b8ce1 100644 --- a/src/maple_ir/include/mir_module.h +++ b/src/maple_ir/include/mir_module.h @@ -67,6 +67,7 @@ class MIRDoubleConst; class MIRBuilder; class DebugInfo; class BinaryMplt; +class EAConnectionGraph; using MIRInfoPair = std::pair; using MIRInfoVector = MapleVector; using MIRDataPair = std::pair>; @@ -77,10 +78,6 @@ struct EncodedValue { }; class MIRTypeNameTable { - private: - MapleAllocator *mAllocator; - MapleMap gStrIdxToTyIdxMap; - public: explicit MIRTypeNameTable(MapleAllocator *allocator) : mAllocator(allocator), gStrIdxToTyIdxMap(std::less(), mAllocator->Adapter()) {} @@ -106,6 +103,10 @@ class MIRTypeNameTable { size_t Size() const { return gStrIdxToTyIdxMap.size(); } + private: + MapleAllocator *mAllocator; + MapleMap gStrIdxToTyIdxMap; + }; class MIRModule { @@ -328,6 +329,14 @@ class MIRModule { binMplt = binaryMplt; } + bool IsInIPA() { + return inIPA; + } + + void SetInIPA(bool isInIPA) { + inIPA = isInIPA; + } + MIRInfoVector &GetFileInfo() { return fileInfo; } @@ -448,6 +457,10 @@ class MIRModule { method2TargetHash[idx] = value; } + std::map &GetEASummary() { + return EASummary; + } + private: MemPool *memPool; MapleAllocator memPoolAllocator; @@ -471,6 +484,7 @@ class MIRModule { bool withProfileInfo; // for cg in mplt BinaryMplt *binMplt; + bool inIPA; MIRInfoVector fileInfo; // store info provided under fileInfo keyword MapleVector fileInfoIsString; // tells if an entry has string value MIRDataVector fileData; @@ -497,6 +511,7 @@ class MIRModule { std::map> method2TargetMap; std::map> method2TargetHash; + std::map EASummary; MIRFunction *entryFunc; uint32 floatNum; diff --git a/src/maple_ir/include/mir_nodes.h b/src/maple_ir/include/mir_nodes.h index aad5a7b032b1474e231331bfc33968a893e702ed..bad084f80b5af311762c0db93a8153c32aae9d20 100644 --- a/src/maple_ir/include/mir_nodes.h +++ b/src/maple_ir/include/mir_nodes.h @@ -92,13 +92,13 @@ class BaseNode { return allocator.GetMemPool()->New(*this); } - virtual void DumpBase(const MIRModule *mod, int32 indent) const; + virtual void DumpBase(const MIRModule &mod, int32 indent) const; - virtual void Dump(const MIRModule *mod, int32 indent) const { + virtual void Dump(const MIRModule &mod, int32 indent) const { DumpBase(mod, indent); } - void Dump(const MIRModule *mod) const { + void Dump(const MIRModule &mod) const { Dump(mod, 0); LogInfo::MapleLogger() << std::endl; } @@ -192,8 +192,8 @@ class UnaryNode : public BaseNode { virtual ~UnaryNode() = default; - void DumpOpnd(const MIRModule *mod, int32 indent) const; - void Dump(const MIRModule *mod, int32 indent) const; + void DumpOpnd(const MIRModule &mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; UnaryNode *CloneTree(MapleAllocator &allocator) const { @@ -238,7 +238,7 @@ class TypeCvtNode : public UnaryNode { ~TypeCvtNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; TypeCvtNode *CloneTree(MapleAllocator &allocator) const { @@ -270,7 +270,7 @@ class RetypeNode : public TypeCvtNode { : TypeCvtNode(OP_retype, typ, fromtyp, expr), tyIdx(idx) {} ~RetypeNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; RetypeNode *CloneTree(MapleAllocator &allocator) const { RetypeNode *nd = allocator.GetMemPool()->New(*this); @@ -305,7 +305,7 @@ class ExtractbitsNode : public UnaryNode { ~ExtractbitsNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; ExtractbitsNode *CloneTree(MapleAllocator &allocator) const { @@ -343,7 +343,7 @@ class GCMallocNode : public BaseNode { ~GCMallocNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; GCMallocNode *CloneTree(MapleAllocator &allocator) const { GCMallocNode *nd = allocator.GetMemPool()->New(*this); @@ -379,7 +379,7 @@ class JarrayMallocNode : public UnaryNode { ~JarrayMallocNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; JarrayMallocNode *CloneTree(MapleAllocator &allocator) const { JarrayMallocNode *nd = allocator.GetMemPool()->New(*this); @@ -412,7 +412,7 @@ class IreadNode : public UnaryNode { : UnaryNode(o, typ, expr), tyIdx(typeIdx), fieldID(fid) {} ~IreadNode() = default; - virtual void Dump(const MIRModule *mod, int32 indent) const; + virtual void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; IreadNode *CloneTree(MapleAllocator &allocator) const { @@ -464,7 +464,7 @@ class IreadoffNode : public UnaryNode { ~IreadoffNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; IreadoffNode *CloneTree(MapleAllocator &allocator) const { @@ -493,7 +493,7 @@ class IreadFPoffNode : public BaseNode { ~IreadFPoffNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; IreadFPoffNode *CloneTree(MapleAllocator &allocator) const { @@ -517,7 +517,7 @@ class BinaryOpnds { public: virtual ~BinaryOpnds() = default; - virtual void Dump(const MIRModule *mod, int32 indent) const; + virtual void Dump(const MIRModule &mod, int32 indent) const; BaseNode *GetBOpnd(int32 i) const { CHECK_FATAL(i >= 0 && i < 2, "Invalid operand idx in BinaryOpnds"); @@ -546,8 +546,8 @@ class BinaryNode : public BaseNode, public BinaryOpnds { ~BinaryNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; - void Dump(const MIRModule *mod) const; + void Dump(const MIRModule &mod, int32 indent) const; + void Dump(const MIRModule &mod) const; bool Verify() const; BinaryNode *CloneTree(MapleAllocator &allocator) const { @@ -606,8 +606,8 @@ class CompareNode : public BinaryNode { ~CompareNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; - void Dump(const MIRModule *mod) const; + void Dump(const MIRModule &mod, int32 indent) const; + void Dump(const MIRModule &mod) const; bool Verify() const; CompareNode *CloneTree(MapleAllocator &allocator) const { @@ -640,7 +640,7 @@ class DepositbitsNode : public BinaryNode { ~DepositbitsNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; DepositbitsNode *CloneTree(MapleAllocator &allocator) const { @@ -687,7 +687,7 @@ class ResolveFuncNode : public BinaryNode { ~ResolveFuncNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; ResolveFuncNode *CloneTree(MapleAllocator &allocator) const { ResolveFuncNode *nd = allocator.GetMemPool()->New(*this); @@ -738,7 +738,7 @@ class TernaryNode : public BaseNode { ~TernaryNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; TernaryNode *CloneTree(MapleAllocator &allocator) const { @@ -777,7 +777,7 @@ class NaryOpnds { virtual ~NaryOpnds() = default; - virtual void Dump(const MIRModule *mod, int32 indent) const; + virtual void Dump(const MIRModule &mod, int32 indent) const; bool VerifyOpnds() const; const MapleVector &GetNopnd() const { @@ -829,7 +829,7 @@ class NaryNode : public BaseNode, public NaryOpnds { NaryNode &operator=(const NaryNode &node) = delete; ~NaryNode() = default; - virtual void Dump(const MIRModule *mod, int32 indent) const; + virtual void Dump(const MIRModule &mod, int32 indent) const; NaryNode *CloneTree(MapleAllocator &allocator) const { NaryNode *nd = allocator.GetMemPool()->New(&allocator, this); @@ -886,7 +886,7 @@ class IntrinsicopNode : public NaryNode { IntrinsicopNode &operator=(const IntrinsicopNode &node) = delete; ~IntrinsicopNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; IntrinsicopNode *CloneTree(MapleAllocator &allocator) const { @@ -930,7 +930,7 @@ class ConstvalNode : public BaseNode { ConstvalNode(PrimType typ, MIRConst *constv) : BaseNode(OP_constval, typ, 0), constVal(constv) {} ~ConstvalNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; ConstvalNode *CloneTree(MapleAllocator &allocator) const { return allocator.GetMemPool()->New(*this); @@ -962,7 +962,7 @@ class ConststrNode : public BaseNode { ~ConststrNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; ConststrNode *CloneTree(MapleAllocator &allocator) const { return allocator.GetMemPool()->New(*this); @@ -990,7 +990,7 @@ class Conststr16Node : public BaseNode { ~Conststr16Node() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; Conststr16Node *CloneTree(MapleAllocator &allocator) const { return allocator.GetMemPool()->New(*this); @@ -1018,7 +1018,7 @@ class SizeoftypeNode : public BaseNode { ~SizeoftypeNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; SizeoftypeNode *CloneTree(MapleAllocator &allocator) const { @@ -1048,7 +1048,7 @@ class FieldsDistNode : public BaseNode { ~FieldsDistNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; FieldsDistNode *CloneTree(MapleAllocator &allocator) const { return allocator.GetMemPool()->New(*this); @@ -1113,7 +1113,7 @@ class ArrayNode : public NaryNode { ArrayNode &operator=(const ArrayNode &node) = delete; ~ArrayNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; bool IsSameBase(ArrayNode*); @@ -1174,7 +1174,7 @@ class AddrofNode : public BaseNode { ~AddrofNode() = default; - virtual void Dump(const MIRModule *mod, int32 indent) const; + virtual void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; bool CheckNode(const MIRModule *mod) const; @@ -1222,7 +1222,7 @@ class RegreadNode : public BaseNode { ~RegreadNode() = default; - virtual void Dump(const MIRModule *mod, int32 indent) const; + virtual void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; RegreadNode *CloneTree(MapleAllocator &allocator) const { @@ -1253,7 +1253,7 @@ class AddroffuncNode : public BaseNode { ~AddroffuncNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; AddroffuncNode *CloneTree(MapleAllocator &allocator) const { @@ -1280,7 +1280,7 @@ class AddroflabelNode : public BaseNode { ~AddroflabelNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; AddroflabelNode *CloneTree(MapleAllocator &allocator) const { @@ -1395,9 +1395,9 @@ class StmtNode : public BaseNode, public PtrListNodeBase { virtual ~StmtNode() = default; - void DumpBase(const MIRModule *mod, int32 indent) const; - void Dump(const MIRModule *mod, int32 indent) const; - void Dump(const MIRModule *mod) const; + void DumpBase(const MIRModule &mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; + void Dump(const MIRModule &mod) const; void InsertAfterThis(StmtNode *pos); void InsertBeforeThis(StmtNode *pos); @@ -1486,7 +1486,7 @@ class IassignNode : public StmtNode { } } - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; IassignNode *CloneTree(MapleAllocator &allocator) const { @@ -1534,7 +1534,7 @@ class GotoNode : public StmtNode { ~GotoNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; GotoNode *CloneTree(MapleAllocator &allocator) const { GotoNode *g = allocator.GetMemPool()->New(*this); @@ -1564,7 +1564,7 @@ class JsTryNode : public StmtNode { ~JsTryNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; JsTryNode *CloneTree(MapleAllocator &allocator) const { JsTryNode *t = allocator.GetMemPool()->New(*this); @@ -1606,8 +1606,8 @@ class TryNode : public StmtNode { TryNode &operator=(const TryNode &node) = delete; ~TryNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; - void Dump(const MIRModule *mod) const; + void Dump(const MIRModule &mod, int32 indent) const; + void Dump(const MIRModule &mod) const; LabelIdx GetOffset(size_t i) const { ASSERT(i < offsets.size(), "array index out of range"); @@ -1675,8 +1675,8 @@ class CatchNode : public StmtNode { CatchNode &operator=(const CatchNode &node) = delete; ~CatchNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; - void Dump(const MIRModule *mod) const; + void Dump(const MIRModule &mod, int32 indent) const; + void Dump(const MIRModule &mod) const; TyIdx GetExceptionTyIdxVecElement(size_t i) const { CHECK_FATAL(i < exceptionTyIdxVec.size(), "array index out of range"); @@ -1746,7 +1746,7 @@ class SwitchNode : public StmtNode { SwitchNode &operator=(const SwitchNode &node) = delete; ~SwitchNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; SwitchNode *CloneTree(MapleAllocator &allocator) const { @@ -1833,7 +1833,7 @@ class MultiwayNode : public StmtNode { MultiwayNode &operator=(const MultiwayNode &node) = delete; ~MultiwayNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; MultiwayNode *CloneTree(MapleAllocator &allocator) const { MultiwayNode *nd = allocator.GetMemPool()->New(&allocator, this); @@ -1887,9 +1887,9 @@ class UnaryStmtNode : public StmtNode { virtual ~UnaryStmtNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; - void Dump(const MIRModule *mod) const; - void DumpOpnd(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; + void Dump(const MIRModule &mod) const; + void DumpOpnd(const MIRModule &mod, int32 indent) const; bool Verify() const { return uopnd->Verify(); @@ -1944,7 +1944,7 @@ class DassignNode : public UnaryStmtNode { ~DassignNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; DassignNode *CloneTree(MapleAllocator &allocator) const { @@ -2008,7 +2008,7 @@ class RegassignNode : public UnaryStmtNode { ~RegassignNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; RegassignNode *CloneTree(MapleAllocator &allocator) const { @@ -2053,7 +2053,7 @@ class CondGotoNode : public UnaryStmtNode { ~CondGotoNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; uint32 GetOffset() const { @@ -2096,7 +2096,7 @@ class RangegotoNode : public UnaryStmtNode { RangegotoNode &operator=(const RangegotoNode &node) = delete; ~RangegotoNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; RangegotoNode *CloneTree(MapleAllocator &allocator) const { RangegotoNode *nd = allocator.GetMemPool()->New(&allocator, this); @@ -2154,11 +2154,11 @@ class BlockNode : public StmtNode { void InsertAfter(StmtNode *stmtNode1, StmtNode *stmtNode2); // Insert ss2 after ss1 in current block. void InsertBlockAfter(BlockNode *inblock, StmtNode *stmt1); // insert all the stmts in inblock to the current block after stmt1 - void Dump(const MIRModule *mod, int32 indent, const MIRSymbolTable *theSymTab, MIRPregTable *thePregTab, + void Dump(const MIRModule &mod, int32 indent, const MIRSymbolTable *theSymTab, MIRPregTable *thePregTab, bool withInfo, bool isFuncbody) const; bool Verify() const; - void Dump(const MIRModule *mod, int32 indent) const { + void Dump(const MIRModule &mod, int32 indent) const { Dump(mod, indent, nullptr, nullptr, false, false); } @@ -2242,7 +2242,7 @@ class IfStmtNode : public UnaryStmtNode { ~IfStmtNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; IfStmtNode *CloneTree(MapleAllocator &allocator) const { @@ -2304,7 +2304,7 @@ class WhileStmtNode : public UnaryStmtNode { ~WhileStmtNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; WhileStmtNode *CloneTree(MapleAllocator &allocator) const { @@ -2342,8 +2342,8 @@ class DoloopNode : public StmtNode { ~DoloopNode() = default; - void DumpDoVar(const MIRModule *mod) const; - void Dump(const MIRModule *mod, int32 indent) const; + void DumpDoVar(const MIRModule &mod) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; DoloopNode *CloneTree(MapleAllocator &allocator) const { @@ -2488,7 +2488,7 @@ class ForeachelemNode : public StmtNode { return numopnds; } - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; ForeachelemNode *CloneTree(MapleAllocator &allocator) const { ForeachelemNode *nd = allocator.GetMemPool()->New(*this); @@ -2510,7 +2510,7 @@ class BinaryStmtNode : public StmtNode, public BinaryOpnds { ~BinaryStmtNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; virtual bool Verify() const; BinaryStmtNode *CloneTree(MapleAllocator &allocator) const { BinaryStmtNode *nd = allocator.GetMemPool()->New(*this); @@ -2555,7 +2555,7 @@ class IassignoffNode : public BinaryStmtNode { ~IassignoffNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; IassignoffNode *CloneTree(MapleAllocator &allocator) const { @@ -2580,7 +2580,7 @@ class IassignFPoffNode : public UnaryStmtNode { ~IassignFPoffNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; bool Verify() const; IassignFPoffNode *CloneTree(MapleAllocator &allocator) const { @@ -2619,7 +2619,7 @@ class NaryStmtNode : public StmtNode, public NaryOpnds { NaryStmtNode &operator=(const NaryStmtNode &node) = delete; ~NaryStmtNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; virtual bool Verify() const; NaryStmtNode *CloneTree(MapleAllocator &allocator) const { @@ -2699,7 +2699,7 @@ class CallNode : public NaryStmtNode { CallNode(CallNode &node) = delete; CallNode &operator=(const CallNode &node) = delete; ~CallNode() = default; - virtual void Dump(const MIRModule *mod, int32 indent, bool newline) const; + virtual void Dump(const MIRModule &mod, int32 indent, bool newline) const; bool Verify() const; MIRType *GetCallReturnType(); @@ -2763,7 +2763,7 @@ class CallNode : public NaryStmtNode { return GetNopndSize(); } - virtual void Dump(const MIRModule *mod, int32 indent) const { + virtual void Dump(const MIRModule &mod, int32 indent) const { Dump(mod, indent, true); } @@ -2802,7 +2802,7 @@ class IcallNode : public NaryStmtNode { IcallNode &operator=(const IcallNode &node) = delete; ~IcallNode() = default; - virtual void Dump(const MIRModule *mod, int32 indent, bool newline) const; + virtual void Dump(const MIRModule &mod, int32 indent, bool newline) const; bool Verify() const; MIRType *GetCallReturnType(); IcallNode *CloneTree(MapleAllocator &allocator) const { @@ -2842,7 +2842,7 @@ class IcallNode : public NaryStmtNode { return GetNopndSize(); } - virtual void Dump(const MIRModule *mod, int32 indent) const { + virtual void Dump(const MIRModule &mod, int32 indent) const { Dump(mod, indent, true); } @@ -2883,7 +2883,7 @@ class IntrinsiccallNode : public NaryStmtNode { IntrinsiccallNode &operator=(const IntrinsiccallNode &node) = delete; ~IntrinsiccallNode() = default; - virtual void Dump(const MIRModule *mod, int32 indent, bool newline) const; + virtual void Dump(const MIRModule &mod, int32 indent, bool newline) const; bool Verify() const; MIRType *GetCallReturnType(); @@ -2932,7 +2932,7 @@ class IntrinsiccallNode : public NaryStmtNode { return GetNopndSize(); } - virtual void Dump(const MIRModule *mod, int32 indent) const { + virtual void Dump(const MIRModule &mod, int32 indent) const { Dump(mod, indent, true); } @@ -2972,8 +2972,8 @@ class CallinstantNode : public CallNode { CallinstantNode &operator=(const CallinstantNode &node) = delete; ~CallinstantNode() = default; - virtual void Dump(const MIRModule *mod, int32 indent, bool newline) const; - virtual void Dump(const MIRModule *mod, int32 indent) const { + virtual void Dump(const MIRModule &mod, int32 indent, bool newline) const; + virtual void Dump(const MIRModule &mod, int32 indent) const { Dump(mod, indent, true); } @@ -3006,7 +3006,7 @@ class AssertStmtNode : public BinaryStmtNode { ~AssertStmtNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; private: bool isLt; @@ -3020,7 +3020,7 @@ class LabelNode : public StmtNode { ~LabelNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; LabelNode *CloneTree(MapleAllocator &allocator) const { LabelNode *l = allocator.GetMemPool()->New(*this); @@ -3061,7 +3061,7 @@ class CommentNode : public StmtNode { CommentNode &operator=(const CommentNode &node) = delete; ~CommentNode() = default; - void Dump(const MIRModule *mod, int32 indent) const; + void Dump(const MIRModule &mod, int32 indent) const; CommentNode *CloneTree(MapleAllocator &allocator) const { CommentNode *c = allocator.GetMemPool()->New(&allocator, this); @@ -3092,6 +3092,6 @@ class CommentNode : public StmtNode { MapleString comment; }; -void DumpCallReturns(const MIRModule *mod, CallReturnVector nrets, int32 indent); +void DumpCallReturns(const MIRModule &mod, CallReturnVector nrets, int32 indent); } // namespace maple #endif // MAPLE_IR_INCLUDE_MIR_NODES_H diff --git a/src/maple_ir/include/mir_symbol.h b/src/maple_ir/include/mir_symbol.h index c8cd04df6ba7a8868f10f4807e880da9410ce561..128d1baad580626804bc911c2b23f71d4417ae0f 100644 --- a/src/maple_ir/include/mir_symbol.h +++ b/src/maple_ir/include/mir_symbol.h @@ -57,26 +57,6 @@ class MIRSymbol { MIRPreg *preg; // the MIRSymKind must be kStPreg }; - // Please keep order of the fields, avoid paddings. - private: - TyIdx tyIdx; - TyIdx inferredTyIdx; - MIRStorageClass storageClass; - MIRSymKind sKind; - bool isTmp; - bool needForwDecl; // addrof of this symbol used in initialization, NOT serialized - bool isDeleted; // tell if it is deleted, NOT serialized - bool instrumented; // a local ref pointer instrumented by RC opt, NOT serialized - bool isImported; - StIdx stIdx; - TypeAttrs typeAttrs; - GStrIdx nameStrIdx; - SymbolType value; - static GStrIdx reflectClassNameIdx; - static GStrIdx reflectMethodNameIdx; - static GStrIdx reflectFieldNameIdx; - - public: MIRSymbol() : tyIdx(0), inferredTyIdx(kInitTyIdx), @@ -357,7 +337,7 @@ class MIRSymbol { bool IsReflectionFieldsInfo() const; bool IsReflectionFieldsInfoCompact() const; bool IsReflectionSuperclassInfo(); - bool IsReflectionClassInfo(); + bool IsReflectionClassInfo() const; bool IsReflectionArrayClassInfo() const; bool IsReflectionClassInfoPtr() const; bool IsReflectionClassInfoRO(); @@ -400,6 +380,25 @@ class MIRSymbol { bool operator<(const MIRSymbol &msym) const { return nameStrIdx < msym.nameStrIdx; } + // Please keep order of the fields, avoid paddings. + private: + TyIdx tyIdx; + TyIdx inferredTyIdx; + MIRStorageClass storageClass; + MIRSymKind sKind; + bool isTmp; + bool needForwDecl; // addrof of this symbol used in initialization, NOT serialized + bool isDeleted; // tell if it is deleted, NOT serialized + bool instrumented; // a local ref pointer instrumented by RC opt, NOT serialized + bool isImported; + StIdx stIdx; + TypeAttrs typeAttrs; + GStrIdx nameStrIdx; + SymbolType value; + static GStrIdx reflectClassNameIdx; + static GStrIdx reflectMethodNameIdx; + static GStrIdx reflectFieldNameIdx; + }; class MIRSymbolTable { diff --git a/src/maple_ir/src/mir_function.cpp b/src/maple_ir/src/mir_function.cpp index 1dc6e4282c40ccdbc320b82ebc3c7c2250674c7a..c6f7eb5757aac6c7d84c300d139fed3c59e6c669 100644 --- a/src/maple_ir/src/mir_function.cpp +++ b/src/maple_ir/src/mir_function.cpp @@ -88,7 +88,7 @@ void MIRFunction::Dump(bool withoutBody) { LogInfo::MapleLogger() << "# [WARNING] skipped dumping because codeMemPool is nullptr " << std::endl; } else if (GetBody() && !withoutBody && fnSt->GetStorageClass() != kScExtern) { ResetInfoPrinted(); // this ensures funcinfo will be printed - GetBody()->Dump(module, 0, module->GetFlavor() < kMmpl ? GetSymTab() : nullptr, + GetBody()->Dump(*module, 0, module->GetFlavor() < kMmpl ? GetSymTab() : nullptr, module->GetFlavor() < kMmpl ? GetPregTab() : nullptr, false, true); // Dump body } else { LogInfo::MapleLogger() << std::endl; diff --git a/src/maple_ir/src/mir_module.cpp b/src/maple_ir/src/mir_module.cpp index b8bc8a1e66aad8b5606eea176aaee1bebb60a7a9..7ccfcb8728ff0a43fe8eb453825aebfca6eff86a 100644 --- a/src/maple_ir/src/mir_module.cpp +++ b/src/maple_ir/src/mir_module.cpp @@ -69,6 +69,7 @@ MIRModule::MIRModule(const char *fn) IntrinDesc::InitMIRModule(this); binMplt = nullptr; curFunction = nullptr; + inIPA = false; } MIRModule::~MIRModule() { diff --git a/src/maple_ir/src/mir_nodes.cpp b/src/maple_ir/src/mir_nodes.cpp index ee9d3999e5f55db8818b88dc03710818e3d5f63a..935256c823a9ed0044f562f0f95a6fa4ea1cf851 100644 --- a/src/maple_ir/src/mir_nodes.cpp +++ b/src/maple_ir/src/mir_nodes.cpp @@ -200,12 +200,12 @@ void BlockNode::InsertBlockAfter(BlockNode *inblock, StmtNode *stmt1) { stmtNodeList.splice(stmt1, inblock->GetStmtNodes()); } -void BaseNode::DumpBase(const MIRModule *mod, int32 indent) const { +void BaseNode::DumpBase(const MIRModule &mod, int32 indent) const { PrintIndentation(indent); LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " " << GetPrimTypeName(GetPrimType()); } -void CatchNode::Dump(const MIRModule *mod, int32 indent) const { +void CatchNode::Dump(const MIRModule &mod, int32 indent) const { PrintIndentation(indent); LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " {"; size_t size = exceptionTyIdxVec.size(); @@ -216,28 +216,28 @@ void CatchNode::Dump(const MIRModule *mod, int32 indent) const { LogInfo::MapleLogger() << " }" << std::endl; } -void CatchNode::Dump(const MIRModule *mod) const { +void CatchNode::Dump(const MIRModule &mod) const { this->BaseNode::Dump(mod); } -void UnaryNode::DumpOpnd(const MIRModule *mod, int indent) const { +void UnaryNode::DumpOpnd(const MIRModule &mod, int indent) const { LogInfo::MapleLogger() << " ("; uOpnd->Dump(mod, indent); LogInfo::MapleLogger() << ")"; } -void UnaryNode::Dump(const MIRModule *mod, int32 indent) const { +void UnaryNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); DumpOpnd(mod, indent); } -void TypeCvtNode::Dump(const MIRModule *mod, int32 indent) const { +void TypeCvtNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " "; LogInfo::MapleLogger() << GetPrimTypeName(GetPrimType()) << " " << GetPrimTypeName(FromType()); DumpOpnd(mod, indent); } -void RetypeNode::Dump(const MIRModule *mod, int32 indent) const { +void RetypeNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " "; LogInfo::MapleLogger() << GetPrimTypeName(GetPrimType()) << " "; MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); @@ -251,7 +251,7 @@ void RetypeNode::Dump(const MIRModule *mod, int32 indent) const { DumpOpnd(mod, indent); } -void ExtractbitsNode::Dump(const MIRModule *mod, int32 indent) const { +void ExtractbitsNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " " << GetPrimTypeName(GetPrimType()); if (GetOpCode() == OP_extractbits) { LogInfo::MapleLogger() << " " << static_cast(bitsOffset) << " " << static_cast(bitsSize); @@ -261,7 +261,7 @@ void ExtractbitsNode::Dump(const MIRModule *mod, int32 indent) const { DumpOpnd(mod, indent); } -void IreadNode::Dump(const MIRModule *mod, int32 indent) const { +void IreadNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); LogInfo::MapleLogger() << " "; GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->Dump(0); @@ -269,27 +269,27 @@ void IreadNode::Dump(const MIRModule *mod, int32 indent) const { DumpOpnd(mod, indent); } -void IreadoffNode::Dump(const MIRModule *mod, int32 indent) const { +void IreadoffNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " " << GetPrimTypeName(GetPrimType()); LogInfo::MapleLogger() << " " << offset; DumpOpnd(mod, indent); } -void IreadFPoffNode::Dump(const MIRModule *mod, int32 indent) const { +void IreadFPoffNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " " << GetPrimTypeName(GetPrimType()); LogInfo::MapleLogger() << " " << offset; } -void BinaryNode::Dump(const MIRModule *mod, int32 indent) const { +void BinaryNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); BinaryOpnds::Dump(mod, indent); } -void BinaryNode::Dump(const MIRModule *mod) const { +void BinaryNode::Dump(const MIRModule &mod) const { this->BaseNode::Dump(mod); } -void BinaryOpnds::Dump(const MIRModule *mod, int32 indent) const { +void BinaryOpnds::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << " ("; if (bOpnd[0]->IsLeaf() && bOpnd[1]->IsLeaf()) { bOpnd[0]->Dump(mod, 0); @@ -306,24 +306,24 @@ void BinaryOpnds::Dump(const MIRModule *mod, int32 indent) const { LogInfo::MapleLogger() << ")"; } -void ResolveFuncNode::Dump(const MIRModule *mod, int32 indent) const { +void ResolveFuncNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); MIRFunction *func = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(puIdx); LogInfo::MapleLogger() << " &" << func->GetName(); BinaryOpnds::Dump(mod, indent); } -void CompareNode::Dump(const MIRModule *mod, int32 indent) const { +void CompareNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " " << GetPrimTypeName(GetPrimType()); LogInfo::MapleLogger() << " " << GetPrimTypeName(opndType); BinaryOpnds::Dump(mod, indent); } -void CompareNode::Dump(const MIRModule *mod) const { +void CompareNode::Dump(const MIRModule &mod) const { this->BaseNode::Dump(mod); } -void DepositbitsNode::Dump(const MIRModule *mod, int32 indent) const { +void DepositbitsNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); LogInfo::MapleLogger() << " " << static_cast(bitsOffset) << " " << static_cast(bitsSize) << " ("; if (GetBOpnd(0)->IsLeaf() && GetBOpnd(1)->IsLeaf()) { @@ -341,7 +341,7 @@ void DepositbitsNode::Dump(const MIRModule *mod, int32 indent) const { LogInfo::MapleLogger() << ")"; } -void TernaryNode::Dump(const MIRModule *mod, int32 indent) const { +void TernaryNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); LogInfo::MapleLogger() << " ("; if (topnd[0]->IsLeaf() && topnd[1]->IsLeaf() && topnd[2]->IsLeaf()) { @@ -364,7 +364,7 @@ void TernaryNode::Dump(const MIRModule *mod, int32 indent) const { LogInfo::MapleLogger() << ")"; } -void NaryOpnds::Dump(const MIRModule *mod, int32 indent) const { +void NaryOpnds::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << " ("; if (GetNopndSize() == 0) { LogInfo::MapleLogger() << ")"; @@ -410,7 +410,7 @@ bool NaryOpnds::VerifyOpnds() const { return nOpndsVerify; } -void NaryNode::Dump(const MIRModule *mod, int32 indent) const { +void NaryNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); NaryOpnds::Dump(mod, indent); } @@ -427,7 +427,7 @@ BaseNode *ArrayNode::GetDim(const MIRModule *mod, TypeTable *tt, int i) { return mod->CurFuncCodeMemPool()->New(mirConst); } -void ArrayNode::Dump(const MIRModule *mod, int32 indent) const { +void ArrayNode::Dump(const MIRModule &mod, int32 indent) const { PrintIndentation(0); LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " "; if (boundsCheck) { @@ -453,7 +453,7 @@ bool ArrayNode::IsSameBase(ArrayNode *arry) { return static_cast(curBase)->GetStIdx() == static_cast(otherBase)->GetStIdx(); } -void IntrinsicopNode::Dump(const MIRModule *mod, int32 indent) const { +void IntrinsicopNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " " << GetPrimTypeName(GetPrimType()); if (GetOpCode() == OP_intrinsicopwithtype) { LogInfo::MapleLogger() << " "; @@ -463,7 +463,7 @@ void IntrinsicopNode::Dump(const MIRModule *mod, int32 indent) const { NaryOpnds::Dump(mod, indent); } -void ConstvalNode::Dump(const MIRModule *mod, int32 indent) const { +void ConstvalNode::Dump(const MIRModule &mod, int32 indent) const { if (GetConstVal()->GetType()->GetKind() != kTypePointer) { BaseNode::DumpBase(mod, 0); LogInfo::MapleLogger() << " "; @@ -471,13 +471,13 @@ void ConstvalNode::Dump(const MIRModule *mod, int32 indent) const { GetConstVal()->Dump(); } -void ConststrNode::Dump(const MIRModule *mod, int32 indent) const { +void ConststrNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); const std::string kStr = GlobalTables::GetUStrTable().GetStringFromStrIdx(UStrIdx(strIdx.GetIdx())); PrintString(kStr); } -void Conststr16Node::Dump(const MIRModule *mod, int32 indent) const { +void Conststr16Node::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); const std::u16string kStr16 = GlobalTables::GetU16StrTable().GetStringFromStrIdx(U16StrIdx(strIdx.GetIdx())); // UTF-16 string are dumped as UTF-8 string in mpl to keep the printable chars in ascii form @@ -486,22 +486,22 @@ void Conststr16Node::Dump(const MIRModule *mod, int32 indent) const { PrintString(str); } -void SizeoftypeNode::Dump(const MIRModule *mod, int32 indent) const { +void SizeoftypeNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); LogInfo::MapleLogger() << " "; GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->Dump(0); } -void FieldsDistNode::Dump(const MIRModule *mod, int32 indent) const { +void FieldsDistNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); LogInfo::MapleLogger() << " "; GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->Dump(0); LogInfo::MapleLogger() << " " << fieldID1 << " " << fieldID2; } -void AddrofNode::Dump(const MIRModule *mod, int32 indent) const { +void AddrofNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " " << GetPrimTypeName(GetPrimType()); - MIRSymbol *st = mod->CurFunction()->GetLocalOrGlobalSymbol(GetStIdx()); + MIRSymbol *st = mod.CurFunction()->GetLocalOrGlobalSymbol(GetStIdx()); LogInfo::MapleLogger() << (GetStIdx().Islocal() ? " %" : " $"); LogInfo::MapleLogger() << st->GetName(); if (fieldID != 0) { @@ -509,11 +509,11 @@ void AddrofNode::Dump(const MIRModule *mod, int32 indent) const { } } -void RegreadNode::Dump(const MIRModule *mod, int32 indent) const { +void RegreadNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " " << GetPrimTypeName(GetPrimType()); if (regIdx >= 0) { LogInfo::MapleLogger() - << " %" << mod->CurFunction()->GetPregTab()->PregFromPregIdx(static_cast(regIdx))->GetPregNo(); + << " %" << mod.CurFunction()->GetPregTab()->PregFromPregIdx(static_cast(regIdx))->GetPregNo(); } else { LogInfo::MapleLogger() << " %%"; if (regIdx == -kSregSp) { @@ -533,20 +533,20 @@ void RegreadNode::Dump(const MIRModule *mod, int32 indent) const { } } -void AddroffuncNode::Dump(const MIRModule *mod, int32 indent) const { +void AddroffuncNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " " << GetPrimTypeName(GetPrimType()); MIRFunction *func = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(puIdx); LogInfo::MapleLogger() << " &" << GlobalTables::GetGsymTable().GetSymbolFromStidx(func->GetStIdx().Idx())->GetName(); } -void AddroflabelNode::Dump(const MIRModule *mod, int32 indent) const { +void AddroflabelNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name << " " << GetPrimTypeName(GetPrimType()); - LogInfo::MapleLogger() << " @" << mod->CurFunction()->GetLabelName((LabelIdx)offset); + LogInfo::MapleLogger() << " @" << mod.CurFunction()->GetLabelName((LabelIdx)offset); } -void StmtNode::DumpBase(const MIRModule *mod, int32 indent) const { +void StmtNode::DumpBase(const MIRModule &mod, int32 indent) const { if (srcPosition.FileNum() != 0 && srcPosition.LineNum() != 0 && srcPosition.LineNum() != lastPrintedLineNum && - mod->CurFunction()->WithLocInfo()) { + mod.CurFunction()->WithLocInfo()) { LogInfo::MapleLogger() << "LOC " << srcPosition.FileNum() << " " << srcPosition.LineNum() << std::endl; lastPrintedLineNum = srcPosition.LineNum(); } @@ -554,12 +554,12 @@ void StmtNode::DumpBase(const MIRModule *mod, int32 indent) const { LogInfo::MapleLogger() << kOpcodeInfo.GetTableItemAt(GetOpCode()).name; } -void StmtNode::Dump(const MIRModule *mod, int32 indent) const { +void StmtNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); LogInfo::MapleLogger() << std::endl; } -void StmtNode::Dump(const MIRModule *mod) const { +void StmtNode::Dump(const MIRModule &mod) const { this->BaseNode::Dump(mod); } @@ -597,9 +597,9 @@ void StmtNode::InsertBeforeThis(StmtNode *pos) { pos->SetNext(this); } -void DassignNode::Dump(const MIRModule *mod, int32 indent) const { +void DassignNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); - MIRSymbol *st = mod->CurFunction()->GetLocalOrGlobalSymbol(stIdx); + MIRSymbol *st = mod.CurFunction()->GetLocalOrGlobalSymbol(stIdx); LogInfo::MapleLogger() << (st->IsLocal() ? " %" : " $"); LogInfo::MapleLogger() << st->GetName() << " " << fieldID; LogInfo::MapleLogger() << " ("; @@ -611,12 +611,12 @@ void DassignNode::Dump(const MIRModule *mod, int32 indent) const { LogInfo::MapleLogger() << ")" << std::endl; } -void RegassignNode::Dump(const MIRModule *mod, int32 indent) const { +void RegassignNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); LogInfo::MapleLogger() << " " << GetPrimTypeName(GetPrimType()); if (regIdx >= 0) { LogInfo::MapleLogger() - << " %" << mod->CurFunction()->GetPregTab()->PregFromPregIdx(static_cast(regIdx))->GetPregNo(); + << " %" << mod.CurFunction()->GetPregTab()->PregFromPregIdx(static_cast(regIdx))->GetPregNo(); } else { LogInfo::MapleLogger() << " %%"; if (regIdx == -kSregSp) { @@ -638,7 +638,7 @@ void RegassignNode::Dump(const MIRModule *mod, int32 indent) const { LogInfo::MapleLogger() << ")" << std::endl; } -void IassignNode::Dump(const MIRModule *mod, int32 indent) const { +void IassignNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); LogInfo::MapleLogger() << " "; GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->Dump(0); @@ -659,84 +659,84 @@ void IassignNode::Dump(const MIRModule *mod, int32 indent) const { LogInfo::MapleLogger() << ")" << std::endl; } -void IassignoffNode::Dump(const MIRModule *mod, int32 indent) const { +void IassignoffNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); LogInfo::MapleLogger() << " " << GetPrimTypeName(GetPrimType()) << " " << offset; BinaryOpnds::Dump(mod, indent); LogInfo::MapleLogger() << std::endl; } -void IassignFPoffNode::Dump(const MIRModule *mod, int32 indent) const { +void IassignFPoffNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); LogInfo::MapleLogger() << " " << GetPrimTypeName(GetPrimType()) << " " << offset; DumpOpnd(mod, indent); LogInfo::MapleLogger() << std::endl; } -void GotoNode::Dump(const MIRModule *mod, int32 indent) const { +void GotoNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); if (offset == 0) { LogInfo::MapleLogger() << std::endl; } else { - LogInfo::MapleLogger() << " @" << mod->CurFunction()->GetLabelName((LabelIdx)offset) << std::endl; + LogInfo::MapleLogger() << " @" << mod.CurFunction()->GetLabelName((LabelIdx)offset) << std::endl; } } -void JsTryNode::Dump(const MIRModule *mod, int32 indent) const { +void JsTryNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); if (catchOffset == 0) { LogInfo::MapleLogger() << " 0"; } else { - LogInfo::MapleLogger() << " @" << mod->CurFunction()->GetLabelName((LabelIdx)catchOffset); + LogInfo::MapleLogger() << " @" << mod.CurFunction()->GetLabelName((LabelIdx)catchOffset); } if (finallyOffset == 0) { LogInfo::MapleLogger() << " 0" << std::endl; } else { - LogInfo::MapleLogger() << " @" << mod->CurFunction()->GetLabelName((LabelIdx)finallyOffset) << std::endl; + LogInfo::MapleLogger() << " @" << mod.CurFunction()->GetLabelName((LabelIdx)finallyOffset) << std::endl; } } -void TryNode::Dump(const MIRModule *mod, int32 indent) const { +void TryNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); LogInfo::MapleLogger() << " {"; for (size_t i = 0; i < offsets.size(); i++) { int64 offset = offsets[i]; - LogInfo::MapleLogger() << " @" << mod->CurFunction()->GetLabelName((LabelIdx)offset); + LogInfo::MapleLogger() << " @" << mod.CurFunction()->GetLabelName((LabelIdx)offset); } LogInfo::MapleLogger() << " }" << std::endl; } -void TryNode::Dump(const MIRModule *mod) const { +void TryNode::Dump(const MIRModule &mod) const { this->BaseNode::Dump(mod); } -void CondGotoNode::Dump(const MIRModule *mod, int32 indent) const { +void CondGotoNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); - LogInfo::MapleLogger() << " @" << mod->CurFunction()->GetLabelName((LabelIdx)offset); + LogInfo::MapleLogger() << " @" << mod.CurFunction()->GetLabelName((LabelIdx)offset); LogInfo::MapleLogger() << " ("; Opnd()->Dump(mod, indent); LogInfo::MapleLogger() << ")" << std::endl; } -void SwitchNode::Dump(const MIRModule *mod, int32 indent) const { +void SwitchNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); LogInfo::MapleLogger() << " ("; switchOpnd->Dump(mod, indent); if (defaultLabel == 0) { LogInfo::MapleLogger() << ") 0 {"; } else { - LogInfo::MapleLogger() << ") @" << mod->CurFunction()->GetLabelName(defaultLabel) << " {"; + LogInfo::MapleLogger() << ") @" << mod.CurFunction()->GetLabelName(defaultLabel) << " {"; } for (auto it = switchTable.begin(); it != switchTable.end(); it++) { LogInfo::MapleLogger() << std::endl; PrintIndentation(indent + 1); LogInfo::MapleLogger() << std::hex << "0x" << (it)->first << std::dec; - LogInfo::MapleLogger() << ": goto @" << mod->CurFunction()->GetLabelName((it)->second); + LogInfo::MapleLogger() << ": goto @" << mod.CurFunction()->GetLabelName((it)->second); } LogInfo::MapleLogger() << " }" << std::endl; } -void RangegotoNode::Dump(const MIRModule *mod, int32 indent) const { +void RangegotoNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); LogInfo::MapleLogger() << " ("; Opnd()->Dump(mod, indent); @@ -745,37 +745,37 @@ void RangegotoNode::Dump(const MIRModule *mod, int32 indent) const { LogInfo::MapleLogger() << std::endl; PrintIndentation(indent + 1); LogInfo::MapleLogger() << std::hex << "0x" << (it)->first << std::dec; - LogInfo::MapleLogger() << ": goto @" << mod->CurFunction()->GetLabelName((it)->second); + LogInfo::MapleLogger() << ": goto @" << mod.CurFunction()->GetLabelName((it)->second); } LogInfo::MapleLogger() << " }" << std::endl; } -void MultiwayNode::Dump(const MIRModule *mod, int32 indent) const { +void MultiwayNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); LogInfo::MapleLogger() << " ("; multiWayOpnd->Dump(mod, indent); if (defaultLabel == 0) { LogInfo::MapleLogger() << ") 0 {"; } else { - LogInfo::MapleLogger() << ") @" << mod->CurFunction()->GetLabelName(defaultLabel) << " {"; + LogInfo::MapleLogger() << ") @" << mod.CurFunction()->GetLabelName(defaultLabel) << " {"; } for (auto it = multiWayTable.begin(); it != multiWayTable.end(); it++) { LogInfo::MapleLogger() << std::endl; PrintIndentation(indent); LogInfo::MapleLogger() << " ("; it->first->Dump(mod, indent + 1); - LogInfo::MapleLogger() << "): goto @" << mod->CurFunction()->GetLabelName((it)->second); + LogInfo::MapleLogger() << "): goto @" << mod.CurFunction()->GetLabelName((it)->second); } LogInfo::MapleLogger() << " }" << std::endl; } -void UnaryStmtNode::DumpOpnd(const MIRModule *mod, int indent) const { +void UnaryStmtNode::DumpOpnd(const MIRModule &mod, int indent) const { LogInfo::MapleLogger() << " ("; uopnd->Dump(mod, indent); LogInfo::MapleLogger() << ")"; } -void UnaryStmtNode::Dump(const MIRModule *mod, int32 indent) const { +void UnaryStmtNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); LogInfo::MapleLogger() << " ("; if (uopnd) { @@ -784,24 +784,24 @@ void UnaryStmtNode::Dump(const MIRModule *mod, int32 indent) const { LogInfo::MapleLogger() << ")" << std::endl; } -void UnaryStmtNode::Dump(const MIRModule *mod) const { +void UnaryStmtNode::Dump(const MIRModule &mod) const { this->BaseNode::Dump(mod); } -void GCMallocNode::Dump(const MIRModule *mod, int32 indent) const { +void GCMallocNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); LogInfo::MapleLogger() << " "; GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->Dump(0); } -void JarrayMallocNode::Dump(const MIRModule *mod, int32 indent) const { +void JarrayMallocNode::Dump(const MIRModule &mod, int32 indent) const { BaseNode::DumpBase(mod, 0); LogInfo::MapleLogger() << " "; GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->Dump(0, false); DumpOpnd(mod, indent); } -void IfStmtNode::Dump(const MIRModule *mod, int32 indent) const { +void IfStmtNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); LogInfo::MapleLogger() << " ("; Opnd()->Dump(mod, indent); @@ -818,7 +818,7 @@ void IfStmtNode::Dump(const MIRModule *mod, int32 indent) const { } } -void WhileStmtNode::Dump(const MIRModule *mod, int32 indent) const { +void WhileStmtNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); if (GetOpCode() == OP_while) { LogInfo::MapleLogger() << " ("; @@ -837,18 +837,18 @@ void WhileStmtNode::Dump(const MIRModule *mod, int32 indent) const { } } -void DoloopNode::DumpDoVar(const MIRModule *mod) const { +void DoloopNode::DumpDoVar(const MIRModule &mod) const { if (isPreg) { LogInfo::MapleLogger() << " %" - << mod->CurFunction()->GetPregTab()->PregFromPregIdx(doVarStIdx.FullIdx())->GetPregNo() + << mod.CurFunction()->GetPregTab()->PregFromPregIdx(doVarStIdx.FullIdx())->GetPregNo() << " (" << std::endl; } else { - MIRSymbol *st = mod->CurFunction()->GetLocalOrGlobalSymbol(doVarStIdx); + MIRSymbol *st = mod.CurFunction()->GetLocalOrGlobalSymbol(doVarStIdx); LogInfo::MapleLogger() << " %" << st->GetName().c_str() << " (" << std::endl; } } -void DoloopNode::Dump(const MIRModule *mod, int32 indent) const { +void DoloopNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); DumpDoVar(mod); PrintIndentation(indent + 1); @@ -863,37 +863,36 @@ void DoloopNode::Dump(const MIRModule *mod, int32 indent) const { doBody->Dump(mod, indent + 1); } -void ForeachelemNode::Dump(const MIRModule *mod, int32 indent) const { +void ForeachelemNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); - MIRSymbol *st = mod->CurFunction()->GetLocalOrGlobalSymbol(elemStIdx); + MIRSymbol *st = mod.CurFunction()->GetLocalOrGlobalSymbol(elemStIdx); ASSERT(st != nullptr, "null ptr check"); LogInfo::MapleLogger() << " %" << st->GetName().c_str(); - st = mod->CurFunction()->GetLocalOrGlobalSymbol(arrayStIdx); + st = mod.CurFunction()->GetLocalOrGlobalSymbol(arrayStIdx); ASSERT(st != nullptr, "null ptr check"); LogInfo::MapleLogger() << (arrayStIdx.Islocal() ? " %" : " $"); LogInfo::MapleLogger() << st->GetName().c_str(); loopBody->Dump(mod, indent + 1); } -void BinaryStmtNode::Dump(const MIRModule *mod, int32 indent) const { +void BinaryStmtNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); BinaryOpnds::Dump(mod, indent); LogInfo::MapleLogger() << std::endl; } -void AssertStmtNode::Dump(const MIRModule *mod, int32 indent) const { +void AssertStmtNode::Dump(const MIRModule &mod, int32 indent) const { BinaryStmtNode::Dump(mod, indent); } -void NaryStmtNode::Dump(const MIRModule *mod, int32 indent) const { +void NaryStmtNode::Dump(const MIRModule &mod, int32 indent) const { StmtNode::DumpBase(mod, indent); NaryOpnds::Dump(mod, indent); LogInfo::MapleLogger() << std::endl; } -void DumpCallReturns(const MIRModule *mod, CallReturnVector nrets, int32 indent) { - ASSERT(mod != nullptr, "mod is null"); - const MIRFunction *mirFunc = mod->CurFunction(); +void DumpCallReturns(const MIRModule &mod, CallReturnVector nrets, int32 indent) { + const MIRFunction *mirFunc = mod.CurFunction(); if (nrets.empty()) { LogInfo::MapleLogger() << " {}" << std::endl; return; @@ -901,7 +900,7 @@ void DumpCallReturns(const MIRModule *mod, CallReturnVector nrets, int32 indent) StIdx stIdx = nrets.begin()->first; RegFieldPair regFieldPair = nrets.begin()->second; if (!regFieldPair.IsReg()) { - MIRSymbol *st = mod->CurFunction()->GetLocalOrGlobalSymbol(stIdx); + MIRSymbol *st = mirFunc->GetLocalOrGlobalSymbol(stIdx); ASSERT(st != nullptr, "st is null"); uint16 fieldID = regFieldPair.GetFieldID(); LogInfo::MapleLogger() << " { dassign "; @@ -952,7 +951,7 @@ MIRType *CallNode::GetCallReturnType() { return mirFunc->GetReturnType(); } -void CallNode::Dump(const MIRModule *mod, int32 indent, bool newline) const { +void CallNode::Dump(const MIRModule &mod, int32 indent, bool newline) const { StmtNode::DumpBase(mod, indent); if (tyIdx != 0) { LogInfo::MapleLogger() << " "; @@ -973,7 +972,7 @@ MIRType *IcallNode::GetCallReturnType() { return GlobalTables::GetTypeTable().GetTypeFromTyIdx(retTyIdx); } -void IcallNode::Dump(const MIRModule *mod, int32 indent, bool newline) const { +void IcallNode::Dump(const MIRModule &mod, int32 indent, bool newline) const { StmtNode::DumpBase(mod, indent); NaryOpnds::Dump(mod, indent); if (kOpcodeInfo.IsCallAssigned(GetOpCode())) { @@ -989,7 +988,7 @@ MIRType *IntrinsiccallNode::GetCallReturnType() { return intrinDesc->GetReturnType(); } -void IntrinsiccallNode::Dump(const MIRModule *mod, int32 indent, bool newline) const { +void IntrinsiccallNode::Dump(const MIRModule &mod, int32 indent, bool newline) const { StmtNode::DumpBase(mod, indent); if (tyIdx != 0) { LogInfo::MapleLogger() << " "; @@ -1009,7 +1008,7 @@ void IntrinsiccallNode::Dump(const MIRModule *mod, int32 indent, bool newline) c } } -void CallinstantNode::Dump(const MIRModule *mod, int32 indent, bool newline) const { +void CallinstantNode::Dump(const MIRModule &mod, int32 indent, bool newline) const { StmtNode::DumpBase(mod, indent); MIRFunction *func = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(GetPUIdx()); LogInfo::MapleLogger() << " &" << func->GetName(); @@ -1026,18 +1025,17 @@ void CallinstantNode::Dump(const MIRModule *mod, int32 indent, bool newline) con } } -void BlockNode::Dump(const MIRModule *mod, int32 indent, const MIRSymbolTable *theSymTab, MIRPregTable *thePregTab, +void BlockNode::Dump(const MIRModule &mod, int32 indent, const MIRSymbolTable *theSymTab, MIRPregTable *thePregTab, bool withInfo, bool isFuncbody) const { - ASSERT(mod != nullptr, "mod is null"); if (!withInfo) { LogInfo::MapleLogger() << " {" << std::endl; } // output puid for debugging purpose if (isFuncbody) { - mod->CurFunction()->DumpFuncBody(indent); + mod.CurFunction()->DumpFuncBody(indent); if (theSymTab != nullptr) { // print the locally declared type names - for (auto it : mod->CurFunction()->GetTypeNameTab()->GetGStrIdxToTyIdxMap()) { + for (auto it : mod.CurFunction()->GetTypeNameTab()->GetGStrIdxToTyIdxMap()) { const std::string &name = GlobalTables::GetStrTable().GetStringFromStrIdx(it.first); MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(it.second); PrintIndentation(indent + 1); @@ -1054,7 +1052,7 @@ void BlockNode::Dump(const MIRModule *mod, int32 indent, const MIRSymbolTable *t thePregTab->DumpRef(indent + 1); } LogInfo::MapleLogger() << std::endl; - for (std::pair it : mod->CurFunction()->GetAliasVarMap()) { + for (std::pair it : mod.CurFunction()->GetAliasVarMap()) { LogInfo::MapleLogger() << "ALIAS %" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.first) << " %" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.second.memPoolStrIdx) << " "; GlobalTables::GetTypeTable().GetTypeFromTyIdx(it.second.tyIdx)->Dump(0); @@ -1065,7 +1063,7 @@ void BlockNode::Dump(const MIRModule *mod, int32 indent, const MIRSymbolTable *t } } if (srcPosition.FileNum() != 0 && srcPosition.LineNum() != 0 && srcPosition.LineNum() != lastPrintedLineNum && - mod->CurFunction()->WithLocInfo()) { + mod.CurFunction()->WithLocInfo()) { LogInfo::MapleLogger() << "LOC " << srcPosition.FileNum() << " " << srcPosition.LineNum() << std::endl; lastPrintedLineNum = srcPosition.LineNum(); } @@ -1076,20 +1074,18 @@ void BlockNode::Dump(const MIRModule *mod, int32 indent, const MIRSymbolTable *t LogInfo::MapleLogger() << "}" << std::endl; } -void LabelNode::Dump(const MIRModule *mod, int32 indent) const { - ASSERT(mod != nullptr, "mod is null"); +void LabelNode::Dump(const MIRModule &mod, int32 indent) const { if (srcPosition.FileNum() != 0 && srcPosition.LineNum() != 0 && srcPosition.LineNum() != lastPrintedLineNum && - mod->CurFunction()->WithLocInfo()) { + mod.CurFunction()->WithLocInfo()) { LogInfo::MapleLogger() << "LOC " << srcPosition.FileNum() << " " << srcPosition.LineNum() << std::endl; lastPrintedLineNum = srcPosition.LineNum(); } - LogInfo::MapleLogger() << "@" << mod->CurFunction()->GetLabelName(labelIdx) << " "; + LogInfo::MapleLogger() << "@" << mod.CurFunction()->GetLabelName(labelIdx) << " "; } -void CommentNode::Dump(const MIRModule *mod, int32 indent) const { - ASSERT(mod != nullptr, "mod is null"); +void CommentNode::Dump(const MIRModule &mod, int32 indent) const { if (srcPosition.FileNum() != 0 && srcPosition.LineNum() != 0 && srcPosition.LineNum() != lastPrintedLineNum && - mod->CurFunction()->WithLocInfo()) { + mod.CurFunction()->WithLocInfo()) { LogInfo::MapleLogger() << "LOC " << srcPosition.FileNum() << " " << srcPosition.LineNum() << std::endl; lastPrintedLineNum = srcPosition.LineNum(); } @@ -1117,7 +1113,7 @@ bool ArithTypeVerify(const BaseNode *opnd) { bool verifyResult = ExcludeSmallIntTypeVerify(opnd); if (!verifyResult) { LogInfo::MapleLogger() << "\n#Error:u1,i8,u8,i16,u16 should not be used as types of arithmetic operations\n"; - opnd->Dump(theModule); + opnd->Dump(*theModule); } return verifyResult; } @@ -1127,7 +1123,7 @@ inline bool ReadTypeVerify(const BaseNode *opnd) { if (!verifyResult) { LogInfo::MapleLogger() << "\n#Error:u1,i8,u8,i16,u16 should not be used as result types for dread/iread/regread/ireadoff/ireadfpoff\n"; - opnd->Dump(theModule); + opnd->Dump(*theModule); } return verifyResult; } @@ -1258,8 +1254,8 @@ bool CompatibleTypeVerify(const BaseNode *opnd1, const BaseNode *opnd2) { } if (!verifyResult) { LogInfo::MapleLogger() << "\n#Error:incompatible operand types :\n"; - opnd1->Dump(theModule); - opnd2->Dump(theModule); + opnd1->Dump(*theModule); + opnd2->Dump(*theModule); } return verifyResult; } @@ -1533,12 +1529,12 @@ bool BinaryNode::Verify() const { resTypeVerf = true; // don't print the same kind of error message twice if (GetOpCode() != OP_add && GetOpCode() != OP_sub) { LogInfo::MapleLogger() << "\n#Error: Only add and sub are allowed for pointer arithemetic\n"; - this->Dump(theModule); + this->Dump(*theModule); } else if (!IsAddress(GetPrimType())) { LogInfo::MapleLogger() << "\n#Error: Adding an offset to a pointer or subtracting one from a pointer should result in a pointer " "value\n"; - this->Dump(theModule); + this->Dump(*theModule); } } } @@ -1546,7 +1542,7 @@ bool BinaryNode::Verify() const { LogInfo::MapleLogger() << "\n#Error:result type of [add,div,sub,mul,max,min] and [ashr,band,bior,bxor,land,lior,lshr,shl,rem] must " "be in [i32,u32,i64,u64,f32,f64,dynamic-type]\n"; - this->Dump(theModule); + this->Dump(*theModule); } bool comp0Verf = CompatibleTypeVerify(GetBOpnd(0), this); bool comp1Verf = CompatibleTypeVerify(GetBOpnd(1), this); @@ -1570,7 +1566,7 @@ bool CompareNode::Verify() const { bool compVerf = CompatibleTypeVerify(GetBOpnd(0), GetBOpnd(1)); bool resTypeVerf = CompareTypeVerify(GetPrimType()); if (!resTypeVerf) { - this->Dump(theModule); + this->Dump(*theModule); } bool signVerf = true; bool typeVerf = compVerf && resTypeVerf; diff --git a/src/maple_ir/src/mir_symbol.cpp b/src/maple_ir/src/mir_symbol.cpp index ab9302d9ca69fdf7396e0f3c9d61908c429d9ba6..b85659c4298ab6527b5b4406304d26dee061b2d5 100644 --- a/src/maple_ir/src/mir_symbol.cpp +++ b/src/maple_ir/src/mir_symbol.cpp @@ -172,7 +172,7 @@ bool MIRSymbol::IsReflectionSuperclassInfo() { return (GetName().find(SUPERCLASSINFO_PREFIX_STR) == 0); } -bool MIRSymbol::IsReflectionClassInfo() { +bool MIRSymbol::IsReflectionClassInfo() const { return (GetName().find(CLASSINFO_PREFIX_STR) == 0); } diff --git a/src/maple_me/include/alias_class.h b/src/maple_me/include/alias_class.h index 3903745f7a5d625a8dfac549359aba28cc4d2908..c68b72591a0686d49a56b129cf13e978391e7cf6 100644 --- a/src/maple_me/include/alias_class.h +++ b/src/maple_me/include/alias_class.h @@ -24,7 +24,7 @@ namespace maple { class AliasElem { - friend class AliasClass; + friend class AliasClass; public: AliasElem(uint32 i, OriginalSt &origst) : id(i), diff --git a/src/maple_me/include/bb.h b/src/maple_me/include/bb.h index 1cf4f1e61072e131b345b6e9927421b900ba0f0f..658672210cd8059dfa073b72ed8c9210e9ad04d0 100644 --- a/src/maple_me/include/bb.h +++ b/src/maple_me/include/bb.h @@ -47,7 +47,8 @@ enum BBAttr { kBBIsCatch, // bb is start of catch handler kBBIsJavaFinally, // bb is start of finally handler kBBArtificial, // bb is inserted by maple_me - kBBIsInLoop // Is bb in a loop body + kBBIsInLoop, // Is bb in a loop body + kBBIsInLoopForEA // For EA use }; struct BBId { @@ -103,6 +104,7 @@ constexpr uint32 kBBAttrIsCatch = (1U << kBBIsCatch); constexpr uint32 kBBAttrIsJavaFinally = (1U << kBBIsJavaFinally); constexpr uint32 kBBAttrArtificial = (1U << kBBArtificial); constexpr uint32 kBBAttrIsInLoop = (1U << kBBIsInLoop); +constexpr uint32 kBBAttrIsInLoopForEA = (1 << kBBIsInLoopForEA); constexpr uint32 kBBVectorInitialSize = 2; using StmtNodes = PtrListRef; using MeStmts = PtrListRef; diff --git a/src/maple_me/include/dominance.h b/src/maple_me/include/dominance.h index 2ff5425f8e9a306f799274950a6d921c222dab00..155c9d8db0d3dec72c140ebc1dbc41d8dab6fbd2 100644 --- a/src/maple_me/include/dominance.h +++ b/src/maple_me/include/dominance.h @@ -194,6 +194,12 @@ class Dominance : public AnalysisResult { protected: MapleAllocator domAllocator; // stores the analysis results + + void PostOrderWalk(BB &bb, int32 &pid, std::vector &visitedMap); + BB *Intersect(BB &bb1, const BB &bb2); + bool CommonEntryBBIsPred(const BB &bb); + void PdomPostOrderWalk(BB &bb, int32 &pid, std::vector &visitedMap); + BB *PdomIntersect(BB &bb1, const BB &bb2); private: MapleAllocator tmpAllocator; // can be freed after dominator computation MapleVector &bbVec; @@ -214,13 +220,6 @@ class Dominance : public AnalysisResult { MapleVector> pdomChildren; // index is bb id; for pdom tree MapleVector pdtPreOrder; // ordering of the BBs in a preorder traversal of the post-dominator tree MapleVector pdtDfn; // gives position of each BB in pdt_preorder - - protected: - void PostOrderWalk(BB &bb, int32 &pid, std::vector &visitedMap); - BB *Intersect(BB &bb1, const BB &bb2); - bool CommonEntryBBIsPred(const BB &bb); - void PdomPostOrderWalk(BB &bb, int32 &pid, std::vector &visitedMap); - BB *PdomIntersect(BB &bb1, const BB &bb2); }; } // namespace maple #endif // MAPLE_ME_INCLUDE_DOMINANCE_H diff --git a/src/maple_me/include/me_bb_layout.h b/src/maple_me/include/me_bb_layout.h index 8a0d0c9fc985587cf305c71ffe19749726d00321..83650ec9707439379194134a22bad5fdcc748e74 100644 --- a/src/maple_me/include/me_bb_layout.h +++ b/src/maple_me/include/me_bb_layout.h @@ -19,15 +19,6 @@ namespace maple { class BBLayout : public AnalysisResult { - private: - MeFunction &func; - MapleAllocator layoutAlloc; - MapleVector layoutBBs; // gives the determined layout order - BBId curBBId; // to index into func.bb_vec_ to return the next BB - bool bbCreated; // new create bb will change mefunction::bb_vec_ and - // related analysis result - MapleVector laidOut; // indexed by bbid to tell if has been laid out - bool tryOutstanding; // true if a try laid out but not its endtry public: BBLayout(MemPool &memPool, MeFunction &f) : AnalysisResult(&memPool), @@ -97,6 +88,15 @@ class BBLayout : public AnalysisResult { std::string PhaseName() const { return "bblayout"; } + private: + MeFunction &func; + MapleAllocator layoutAlloc; + MapleVector layoutBBs; // gives the determined layout order + BBId curBBId; // to index into func.bb_vec_ to return the next BB + bool bbCreated; // new create bb will change mefunction::bb_vec_ and + // related analysis result + MapleVector laidOut; // indexed by bbid to tell if has been laid out + bool tryOutstanding; // true if a try laid out but not its endtry }; class MeDoBBLayout : public MeFuncPhase { diff --git a/src/maple_me/include/me_function.h b/src/maple_me/include/me_function.h index 45b0d7e08cd91256ca95760d687f13af49ea1d7e..b081b24713419ba9074d4fe8018998ae588ca69a 100644 --- a/src/maple_me/include/me_function.h +++ b/src/maple_me/include/me_function.h @@ -438,6 +438,10 @@ class MeFunction : public FuncEmit { hints = num; } + MemPool *GetMemPool() { + return memPool; + } + void PartialInit(bool isSecondPass); private: diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h index 71fa684bf2d6d9237ece074a6c5faaeb39d6d82f..550f52df67973412581065750577d20756eb8196 100644 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -1967,6 +1967,10 @@ class CallMeStmt : public NaryMeStmt, public MuChiMePart, public AssignedPart { return &mustDefList; } + MustDefMeNode &GetMustDefListItem(int i) { + return mustDefList[i]; + } + size_t MustDefListSize() const { return mustDefList.size(); } @@ -2115,6 +2119,7 @@ class IntrinsiccallMeStmt : public NaryMeStmt, public MuChiMePart, public Assign MuChiMePart(alloc), AssignedPart(alloc), intrinsic(static_cast(stt)->GetIntrinsic()), + oriExprInRcLowering(alloc->Adapter()), tyIdx(static_cast(stt)->GetTyIdx()), retPType(stt->GetPrimType()) {} @@ -2123,6 +2128,7 @@ class IntrinsiccallMeStmt : public NaryMeStmt, public MuChiMePart, public Assign MuChiMePart(alloc), AssignedPart(alloc), intrinsic(id), + oriExprInRcLowering(alloc->Adapter()), tyIdx(tyid), retPType(kPtyInvalid) {} @@ -2131,6 +2137,7 @@ class IntrinsiccallMeStmt : public NaryMeStmt, public MuChiMePart, public Assign MuChiMePart(alloc), AssignedPart(intrn->mustDefList), intrinsic(intrn->GetIntrinsic()), + oriExprInRcLowering(alloc->Adapter()), tyIdx(intrn->tyIdx), retPType(intrn->retPType) {} @@ -2210,8 +2217,13 @@ class IntrinsiccallMeStmt : public NaryMeStmt, public MuChiMePart, public Assign return tyIdx; } + MapleVector &GetOriExprInRcLowering() { + return oriExprInRcLowering; + } + private: MIRIntrinsicID intrinsic; + MapleVector oriExprInRcLowering; TyIdx tyIdx; // Used to store return value type PrimType retPType; diff --git a/src/maple_me/include/me_phase_manager.h b/src/maple_me/include/me_phase_manager.h index 665c94397c6067257d1539ecbfbbc7530b398015..15b3f876d34d976e137a87fdf8b0fc09495d859f 100644 --- a/src/maple_me/include/me_phase_manager.h +++ b/src/maple_me/include/me_phase_manager.h @@ -35,7 +35,8 @@ class MeFuncPhaseManager : public PhaseManager { modResMgr(mrm), mePhaseType(kMePhaseInvalid), genMempool(false), - timePhases(false) {} + timePhases(false), + ipa(false) {} ~MeFuncPhaseManager() { arFuncManager.InvalidAllResults(); @@ -54,13 +55,14 @@ class MeFuncPhaseManager : public PhaseManager { } void Run(MIRFunction *mirfunc, uint64 rangenum, const std::string &meinput); + void IPACleanUp(MeFunction *mirfunc); void Run() override {} MeFuncResultMgr *GetAnalysisResultManager(void) { return &arFuncManager; } - ModuleResultMgr *GetModResultMgr() { + ModuleResultMgr *GetModResultMgr() override { return modResMgr; } @@ -78,6 +80,14 @@ class MeFuncPhaseManager : public PhaseManager { timePhases = phs; } + bool isIPA() { + return ipa; + } + + void SetIPA(bool ipaVal) { + ipa = ipaVal; + } + private: /* analysis phase result manager */ MeFuncResultMgr arFuncManager; @@ -86,6 +96,7 @@ class MeFuncPhaseManager : public PhaseManager { MePhaseType mePhaseType; bool genMempool; bool timePhases; + bool ipa; }; } // namespace maple #endif // MAPLE_ME_INCLUDE_ME_PHASE_MANAGER_H \ No newline at end of file diff --git a/src/maple_me/include/orig_symbol.h b/src/maple_me/include/orig_symbol.h index 6a3e6a0a9025316ea13c8df4129c82390758e9a9..fe0b468cb5d01886c432e72a3a61a239d582fa3f 100644 --- a/src/maple_me/include/orig_symbol.h +++ b/src/maple_me/include/orig_symbol.h @@ -159,6 +159,10 @@ class OriginalSt { return versionsIndex; } + const MapleVector &GetVersionsIndex() const { + return versionsIndex; + } + size_t GetZeroVersionIndex() const { return zeroVersionIndex; } diff --git a/src/maple_me/include/ssa_mir_nodes.h b/src/maple_me/include/ssa_mir_nodes.h index 5090ba670d441308ee9eeab40f99dba7561be2b3..d9811ada30bd6a8ca0a4d09b96c79f1d09e7a039 100644 --- a/src/maple_me/include/ssa_mir_nodes.h +++ b/src/maple_me/include/ssa_mir_nodes.h @@ -439,10 +439,10 @@ class AddrofSSANode : public AddrofNode { ~AddrofSSANode() {} - void Dump(const MIRModule *mod, int32 indent) const { + void Dump(const MIRModule &mod, int32 indent) const { AddrofNode::Dump(mod, indent); if (ssaVar != nullptr) { - ssaVar->Dump(mod, true); + ssaVar->Dump(&mod, true); } } @@ -469,9 +469,9 @@ class IreadSSANode : public IreadNode { ~IreadSSANode() {} - void Dump(const MIRModule *mod, int32 indent) const { + void Dump(const MIRModule &mod, int32 indent) const { if (mayUse.GetOpnd() != nullptr) { - mayUse.Dump(mod); + mayUse.Dump(&mod); } IreadNode::Dump(mod, indent); } @@ -494,10 +494,10 @@ class RegreadSSANode : public RegreadNode { ~RegreadSSANode() {} - void Dump(const MIRModule *mod, int32 indent) const { + void Dump(const MIRModule &mod, int32 indent) const { RegreadNode::Dump(mod, indent); if (ssaVar != nullptr) { - ssaVar->Dump(mod, true); + ssaVar->Dump(&mod, true); } } diff --git a/src/maple_me/src/alias_class.cpp b/src/maple_me/src/alias_class.cpp index 64c03307c1359d6043a2ff1456071515de89ccdd..817e5dbf5c6d4c8c99082a5ed35d5aa895cd665e 100644 --- a/src/maple_me/src/alias_class.cpp +++ b/src/maple_me/src/alias_class.cpp @@ -21,12 +21,9 @@ #include "mir_builder.h" namespace { - - } namespace maple { - static inline bool IsReadOnlyOst(const OriginalSt &ost) { return ost.GetMIRSymbol()->HasAddrOfValues(); } diff --git a/src/maple_me/src/bb.cpp b/src/maple_me/src/bb.cpp index 417ce724d3381ec544f4a9f06504b6ad19e1ffad..84129e337fc73bc8fa31a694d36da07b7c4d730e 100644 --- a/src/maple_me/src/bb.cpp +++ b/src/maple_me/src/bb.cpp @@ -88,7 +88,7 @@ void BB::DumpHeader(MIRModule *mod) { if (bbLabel != 0) { static LabelNode lblNode; lblNode.SetLabelIdx(bbLabel); - lblNode.Dump(mod, 0); + lblNode.Dump(*mod, 0); mod->GetOut() << "\n"; } } @@ -97,7 +97,7 @@ void BB::Dump(MIRModule *mod) { DumpHeader(mod); DumpPhi(mod); for (auto &stmt : stmtNodeList) { - stmt.Dump(mod, 1); + stmt.Dump(*mod, 1); } } diff --git a/src/maple_me/src/dominance.cpp b/src/maple_me/src/dominance.cpp index e37ea0007f2e83a1399f1a06fa4297d9f5ba219b..80854f3b6020bef0c55041573d600be5e279352f 100644 --- a/src/maple_me/src/dominance.cpp +++ b/src/maple_me/src/dominance.cpp @@ -111,7 +111,7 @@ void Dominance::ComputeDomFrontiers() { if (bb == nullptr || bb == &commonExitBB) { continue; } - if (bb->GetPred().size() < 2) { + if (bb->GetPred().size() < kBBVectorInitialSize) { continue; } for (BB *pre : bb->GetPred()) { @@ -269,7 +269,7 @@ void Dominance::ComputePdomFrontiers() { if (bb == nullptr || bb == &commonEntryBB) { continue; } - if (bb->GetSucc().size() < 2) { + if (bb->GetSucc().size() < kBBVectorInitialSize) { continue; } for (BB *suc : bb->GetSucc()) { diff --git a/src/maple_me/src/irmap.cpp b/src/maple_me/src/irmap.cpp index 88e39dafc732db35ef66575e701d06d5083aa363..d8e91f1dba710f54e91352bf262cc363aabd3015 100644 --- a/src/maple_me/src/irmap.cpp +++ b/src/maple_me/src/irmap.cpp @@ -1272,7 +1272,7 @@ BB *IRMap::GetFalseBrBB(CondGotoMeStmt &condgoto) { LabelIdx lblidx = (LabelIdx)condgoto.GetOffset(); BB *gotobb = GetBBForLabIdx(lblidx); BB *bb = condgoto.GetBB(); - ASSERT(bb->GetSucc().size() == 2, "array size error"); + ASSERT(bb->GetSucc().size() == kBBVectorInitialSize, "array size error"); if (condgoto.GetOp() == OP_brfalse) { return gotobb; } else { diff --git a/src/maple_me/src/me_cfg.cpp b/src/maple_me/src/me_cfg.cpp index cb3464bbf10773fa6506e0f1338d8d2d8f459bfe..b00671d45c92778c7c9cfece2fab64cf7b9e104c 100644 --- a/src/maple_me/src/me_cfg.cpp +++ b/src/maple_me/src/me_cfg.cpp @@ -314,7 +314,7 @@ void MeCFG::FixMirCFG() { sym = func.GetMirFunc()->GetLocalOrGlobalSymbol(dassStmt->GetStIdx()); } if (sym == nullptr || sym->GetType()->GetPrimType() != PTY_ref || !sym->IsLocal()) { - continue; + continue; } if (FindUse(*stmt, sym->GetStIdx())) { func.GetMirFunc()->IncTempCount(); @@ -653,7 +653,7 @@ void MeCFG::Verify() { if (bb->GetKind() == kBBCondGoto) { if (!bb->GetAttributes(kBBAttrIsTry) && !bb->GetAttributes(kBBAttrWontExit)) { ASSERT(bb->GetStmtNodes().rbegin().base().d() != nullptr, "runtime check error"); - ASSERT(bb->GetSucc().size() == 2, "runtime check error"); + ASSERT(bb->GetSucc().size() == kBBVectorInitialSize, "runtime check error"); } ASSERT(bb->GetSucc(1)->GetBBLabel() == static_cast(bb->GetStmtNodes().back()).GetOffset(), "runtime check error"); @@ -690,7 +690,7 @@ void MeCFG::VerifyLabels(void) { ASSERT( func.GetLabelBBIdMap()[(LabelIdx) static_cast(stmtNodes.back()).GetOffset()]->GetBBLabel() == (LabelIdx) static_cast(stmtNodes.back()).GetOffset(), - "undefined label in conditional branch"); + "undefined label in conditional branch"); } else if (mirBB->GetKind() == kBBSwitch) { SwitchNode &switchStmt = static_cast(stmtNodes.back()); LabelIdx targetLabIdx = switchStmt.GetDefaultLabel(); @@ -840,7 +840,7 @@ void MeCFG::DumpToFile(const std::string &prefix, bool dumpInStrs) { if (ContainsConststr(&stmt)) { continue; } - stmt.Dump(&(func.GetMIRModule()), 1); + stmt.Dump(func.GetMIRModule(), 1); } cfgFile << "}\"];\n"; } diff --git a/src/maple_me/src/me_irmap.cpp b/src/maple_me/src/me_irmap.cpp index fcd68f63576e0f438be9e7f051c98bc6b47a0591..80a6a3b14236f7f2cd7bf34cf91d5109fb6a8713 100644 --- a/src/maple_me/src/me_irmap.cpp +++ b/src/maple_me/src/me_irmap.cpp @@ -46,7 +46,7 @@ void MeIRMap::Dump() { if (GetDumpStmtNum()) { LogInfo::MapleLogger() << "(" << i++ << ") "; } - mestmt.EmitStmt(*GetSSATab()).Dump(GetMIRModule(), 0); + mestmt.EmitStmt(*GetSSATab()).Dump(*GetMIRModule(), 0); mestmt.Dump(this); } } diff --git a/src/maple_me/src/me_phase_manager.cpp b/src/maple_me/src/me_phase_manager.cpp index 428be32823e7d5af4a530b932452e3f107b17691..98e85a03af5a08c53c09ad03ee973d7624cc729d 100644 --- a/src/maple_me/src/me_phase_manager.cpp +++ b/src/maple_me/src/me_phase_manager.cpp @@ -106,6 +106,11 @@ bool MeFuncPhaseManager::FuncFilter(const std::string &filter, const std::string return false; } +void MeFuncPhaseManager::IPACleanUp(MeFunction *func) { + GetAnalysisResultManager()->InvalidAllResults(); + mempoolctrler.DeleteMemPool(func->GetMemPool()); +} + void MeFuncPhaseManager::Run(MIRFunction *mirfunc, uint64 rangenum, const std::string &meinput) { if (!MeOption::quiet) LogInfo::MapleLogger() << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>> Optimizing Function < " << mirfunc->GetName() @@ -119,6 +124,9 @@ void MeFuncPhaseManager::Run(MIRFunction *mirfunc, uint64 rangenum, const std::s g_func = &func; #endif func.Prepare(rangenum); + if (ipa) { + mirfunc->SetMeFunc(&func); + } std::string phaseName = ""; MeFuncPhase *changeCFGPhase = nullptr; /* each function level phase */ @@ -150,8 +158,13 @@ void MeFuncPhaseManager::Run(MIRFunction *mirfunc, uint64 rangenum, const std::s break; } } - GetAnalysisResultManager()->InvalidAllResults(); + if (!ipa) { + GetAnalysisResultManager()->InvalidAllResults(); + } if (changeCFGPhase != nullptr) { + if (ipa) { + CHECK_FATAL(false, "phases in ipa will not chang cfg."); + } // do all the phases start over MemPool *versMemPool = mempoolctrler.NewMemPool("second verst mempool"); MeFunction function(&mirModule, mirfunc, funcMP, versMemPool, meinput); @@ -177,6 +190,8 @@ void MeFuncPhaseManager::Run(MIRFunction *mirfunc, uint64 rangenum, const std::s } GetAnalysisResultManager()->InvalidAllResults(); } - mempoolctrler.DeleteMemPool(funcMP); + if (!ipa) { + mempoolctrler.DeleteMemPool(funcMP); + } } } // namespace maple diff --git a/src/maple_me/src/me_rc_lowering.cpp b/src/maple_me/src/me_rc_lowering.cpp index a064b67d94c3b45a7f38e13ad76654027be4294d..81df30d771308319f937dafb72c5daf13a936e36 100644 --- a/src/maple_me/src/me_rc_lowering.cpp +++ b/src/maple_me/src/me_rc_lowering.cpp @@ -186,6 +186,7 @@ void RCLowering::HandleAssignMeStmtRHS(MeStmt &stmt) { if (loadCall == nullptr) { return; } + loadCall->GetOriExprInRcLowering().push_back(rhs); if (stmt.GetOp() == OP_regassign) { stmt.GetBB()->ReplaceMeStmt(&stmt, loadCall); if (rhs->IsVolatile(ssaTab)) { @@ -208,7 +209,8 @@ void RCLowering::HandleCallAssignedMeStmt(MeStmt &stmt, MeExpr *pendingDec) { // introduce a ret and decref on it as callee has +1 return ref RegMeExpr *curTmp = irMap.CreateRegMeExpr(PTY_ref); stmt.GetMustDefList()->push_back(MustDefMeNode(curTmp, &stmt)); - MeStmt *decrefCall = CreateRCIntrinsic(INTRN_MCCDecRef, stmt, std::vector({ curTmp })); + IntrinsiccallMeStmt *decrefCall = CreateRCIntrinsic(INTRN_MCCDecRef, stmt, std::vector({ curTmp })); + decrefCall->GetOriExprInRcLowering().push_back(curTmp); bb->InsertMeStmtAfter(&stmt, decrefCall); return; } @@ -232,8 +234,9 @@ void RCLowering::HandleCallAssignedMeStmt(MeStmt &stmt, MeExpr *pendingDec) { } MeStmt *backup = irMap.CreateRegassignMeStmt(*irMap.CreateRegMeExpr(PTY_ref), *pendingDec, *bb); - MeStmt *decrefCall = CreateRCIntrinsic( + IntrinsiccallMeStmt *decrefCall = CreateRCIntrinsic( INTRN_MCCDecRef, stmt, std::vector({ static_cast(backup)->GetRegLHS() })); + decrefCall->GetOriExprInRcLowering().push_back(backup->GetRegLHS()); if (!dynamic_cast(&stmt)) { bb->InsertMeStmtBefore(&stmt, backup); bb->InsertMeStmtAfter(&stmt, decrefCall); @@ -304,7 +307,8 @@ void RCLowering::HandleAssignMeStmtRegLHS(MeStmt &stmt) { if (!stmt.NeedIncref()) { return; } - MeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, stmt, std::vector({ stmt.GetLHS() })); + IntrinsiccallMeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, stmt, std::vector({ stmt.GetLHS() })); + incCall->GetOriExprInRcLowering().push_back(stmt.GetLHS()); stmt.GetBB()->InsertMeStmtAfter(&stmt, incCall); } @@ -320,8 +324,9 @@ void RCLowering::HandleAssignMeStmtVarLHS(MeStmt &stmt, MeExpr *pendingDec) { BB *bb = stmt.GetBB(); if (lsym->IsGlobal()) { // decref could be optimized away after if null check - MeStmt *writeRefCall = CreateRCIntrinsic(SelectWriteBarrier(stmt), stmt, + IntrinsiccallMeStmt *writeRefCall = CreateRCIntrinsic(SelectWriteBarrier(stmt), stmt, std::vector({irMap.CreateAddrofMeExpr(*lhs), rhs})); + writeRefCall->GetOriExprInRcLowering().push_back(lhs); bb->ReplaceMeStmt(&stmt, writeRefCall); } else { // local assign, backup old value and insert Inc and Dec after @@ -333,18 +338,21 @@ void RCLowering::HandleAssignMeStmtVarLHS(MeStmt &stmt, MeExpr *pendingDec) { bb->InsertMeStmtBefore(&stmt, incCall); incWithLHS = false; } - MeStmt *decCall = CreateRCIntrinsic(INTRN_MCCDecRef, stmt, std::vector({ pendingDec })); + IntrinsiccallMeStmt *decCall = CreateRCIntrinsic(INTRN_MCCDecRef, stmt, std::vector({ pendingDec })); + decCall->GetOriExprInRcLowering().push_back(pendingDec); bb->InsertMeStmtBefore(&stmt, decCall); } else { MeStmt *backup = irMap.CreateRegassignMeStmt(*irMap.CreateRegMeExpr(PTY_ref), *pendingDec, *bb); bb->InsertMeStmtBefore(&stmt, backup); - MeStmt *decCall = CreateRCIntrinsic(INTRN_MCCDecRef, stmt, + IntrinsiccallMeStmt *decCall = CreateRCIntrinsic(INTRN_MCCDecRef, stmt, std::vector({ static_cast(backup)->GetLHS() })); + decCall->GetOriExprInRcLowering().push_back(backup->GetLHS()); bb->InsertMeStmtAfter(&stmt, decCall); } } if (incWithLHS) { - MeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, stmt, std::vector({ lhs })); + IntrinsiccallMeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, stmt, std::vector({ lhs })); + incCall->GetOriExprInRcLowering().push_back(lhs); bb->InsertMeStmtAfter(&stmt, incCall); } } @@ -394,9 +402,10 @@ void RCLowering::HandleAssignMeStmtIvarLHS(MeStmt &stmt) { } MeExpr *rhsInner = stmt.GetRHS(); MIRIntrinsicID intrinsicID = SelectWriteBarrier(stmt); - MeStmt *writeRefCall = CreateRCIntrinsic( + IntrinsiccallMeStmt *writeRefCall = CreateRCIntrinsic( intrinsicID, stmt, std::vector({ &lhsInner->GetBase()->GetAddrExprBase(), irMap.CreateAddrofMeExpr(*lhsInner), rhsInner })); + writeRefCall->GetOriExprInRcLowering().push_back(lhsInner); stmt.GetBB()->ReplaceMeStmt(&stmt, writeRefCall); } @@ -522,7 +531,9 @@ void RCLowering::BBLower(BB *bb) { RegMeExpr *regreadExpr = irMap.CreateRegMeExprVersion(*ost); regreadExpr->SetPtyp(PTY_ref); MeStmt *firstMeStmt = to_ptr(bb->GetMeStmts().begin()); - MeStmt *decRefcall = CreateRCIntrinsic(INTRN_MCCDecRef, *firstMeStmt, std::vector({ regreadExpr })); + IntrinsiccallMeStmt *decRefcall = CreateRCIntrinsic(INTRN_MCCDecRef, *firstMeStmt, + std::vector({ regreadExpr })); + decRefcall->GetOriExprInRcLowering().push_back(regreadExpr); bb->InsertMeStmtAfter(firstMeStmt, decRefcall); } } @@ -550,6 +561,7 @@ void RCLowering::HandleReturnVar(RetMeStmt &ret) { if (sym != nullptr && sym->IsGlobal() && !sym->IsFinal()) { IntrinsiccallMeStmt *loadCall = CreateRCIntrinsic(INTRN_MCCLoadRefS, ret, std::vector({ irMap.CreateAddrofMeExpr(*retVar) }), true); + loadCall->GetOriExprInRcLowering().push_back(retVar); ret.GetBB()->InsertMeStmtBefore(&ret, loadCall); ret.SetOpnd(0, loadCall->GetMustDefList()->front().GetLHS()); } else if (assignedPtrSym.count(sym) > 0 && sym->GetStorageClass() == kScAuto && sym->GetAttr(ATTR_localrefvar)) { @@ -559,7 +571,9 @@ void RCLowering::HandleReturnVar(RetMeStmt &ret) { */ IntrinsiccallMeStmt *cleanup = FindCleanupIntrinsic(ret); if (cleanup == nullptr) { - ret.GetBB()->InsertMeStmtBefore(&ret, CreateRCIntrinsic(INTRN_MCCIncRef, ret, std::vector({ retVar }))); + IntrinsiccallMeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, ret, std::vector({ retVar })); + incCall->GetOriExprInRcLowering().push_back(retVar); + ret.GetBB()->InsertMeStmtBefore(&ret, incCall); } else { // remove argument from intrinsiccall MPL_CLEANUP_LOCALREFVARS (dread ref %Reg1_R5678, ... MapleVector *opnds = &cleanup->GetOpnds(); @@ -576,6 +590,8 @@ void RCLowering::HandleReturnVar(RetMeStmt &ret) { // if returning formal, incref unless placementRC is used and formal is NOT reassigned IntrinsiccallMeStmt *increfStmt = CreateRCIntrinsic(INTRN_MCCIncRef, ret, std::vector({ retVar }), true); ret.SetOpnd(0, increfStmt->GetMustDefList()->front().GetLHS()); + increfStmt->GetOriExprInRcLowering().push_back(retVar); + ret.SetOpnd(0, increfStmt->GetMustDefList()->front().GetLHS()); IntrinsiccallMeStmt *cleanup = FindCleanupIntrinsic(ret); if (cleanup == nullptr) { ret.GetBB()->InsertMeStmtBefore(&ret, increfStmt); @@ -594,6 +610,7 @@ void RCLowering::HandleReturnIvar(RetMeStmt &ret) { std::vector({ &retIvar->GetBase()->GetAddrExprBase(), irMap.CreateAddrofMeExpr(*retIvar) }), true); ret.GetBB()->InsertMeStmtBefore(&ret, loadCall); ret.SetOpnd(0, loadCall->GetMustDefList()->front().GetLHS()); + loadCall->GetOriExprInRcLowering().push_back(retIvar); } else { MeStmt *loadCall = CreateRCIntrinsic( INTRN_MCCLoadRef, ret, @@ -619,7 +636,8 @@ void RCLowering::HandleReturnReg(RetMeStmt &ret) { return; } } - MeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, ret, std::vector({ retreg }), true); + IntrinsiccallMeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, ret, std::vector({ retreg }), true); + incCall->GetOriExprInRcLowering().push_back(retreg); ret.SetOpnd(0, incCall->GetMustDefList()->front().GetLHS()); ret.GetBB()->InsertMeStmtBefore(&ret, incCall); } @@ -652,8 +670,9 @@ void RCLowering::HandleReturnWithCleanup() { RegMeExpr *tmpReg = irMap.CreateRegMeExpr(PTY_ref); MeStmt *temp = irMap.CreateRegassignMeStmt(*tmpReg, *retVal, *stmt->GetBB()); stmt->GetBB()->InsertMeStmtBefore(stmt, temp); - stmt->GetBB()->InsertMeStmtBefore(stmt, - CreateRCIntrinsic(INTRN_MCCIncRef, *stmt, std::vector({ tmpReg }))); + IntrinsiccallMeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, *stmt, std::vector({ tmpReg })); + incCall->GetOriExprInRcLowering().push_back(tmpReg); + stmt->GetBB()->InsertMeStmtBefore(stmt, incCall); ret->SetOpnd(0, tmpReg); } } @@ -705,9 +724,11 @@ void RCLowering::HandleArguments() { } VarMeExpr *argVar = CreateVarMeExprFromSym(*sym); CHECK_FATAL(argVar != nullptr, "null ptr check"); + IntrinsiccallMeStmt *incCall = nullptr; if (firstMestmt != nullptr) { - firstBB->InsertMeStmtBefore(firstMestmt, - CreateRCIntrinsic(INTRN_MCCIncRef, *firstMestmt, std::vector({ argVar }))); + incCall = CreateRCIntrinsic(INTRN_MCCIncRef, *firstMestmt, std::vector({ argVar })); + incCall->GetOriExprInRcLowering().push_back(argVar); + firstBB->InsertMeStmtBefore(firstMestmt, incCall); } TypeAttrs typeAttr = mirFunc->GetNthParamAttr(i); typeAttr.SetAttr(ATTR_localrefvar); @@ -715,7 +736,8 @@ void RCLowering::HandleArguments() { sym->SetLocalRefVar(); for (auto *stmt : rets) { - MeStmt *decrefCall = CreateRCIntrinsic(INTRN_MCCDecRef, *stmt, std::vector({ argVar })); + IntrinsiccallMeStmt *decrefCall = CreateRCIntrinsic(INTRN_MCCDecRef, *stmt, std::vector({ argVar })); + decrefCall->GetOriExprInRcLowering().push_back(argVar); stmt->GetBB()->InsertMeStmtBefore(stmt, decrefCall); } } diff --git a/src/maple_me/src/ssa_mir_nodes.cpp b/src/maple_me/src/ssa_mir_nodes.cpp index 63d56d85afa47c4698e333d7cf0e0665dc173b14..663bc9d11c0cd0c5ae953e807e1f5ecf1e984a95 100644 --- a/src/maple_me/src/ssa_mir_nodes.cpp +++ b/src/maple_me/src/ssa_mir_nodes.cpp @@ -36,7 +36,7 @@ bool HasMayUsePart(const StmtNode *stmtNode) { } void GenericSSAPrint(MIRModule *mod, const StmtNode *stmtNode, int32 indent, StmtsSSAPart *stmtsSsaprt) { - stmtNode->Dump(mod, indent); + stmtNode->Dump(*mod, indent); // print SSAPart Opcode op = stmtNode->GetOpCode(); AccessSSANodes *ssaPart = stmtsSsaprt->SSAPartOf(stmtNode); diff --git a/src/maple_me/src/ver_symbol.cpp b/src/maple_me/src/ver_symbol.cpp index 042b7692f875fa4e3e60b5c50b39eecb20a3db64..cc421560dfce61a0f269bd236214985f25d76253 100644 --- a/src/maple_me/src/ver_symbol.cpp +++ b/src/maple_me/src/ver_symbol.cpp @@ -24,7 +24,7 @@ void VersionSt::DumpDefStmt(const MIRModule *mod) { } switch (defType) { case kDassign: - defStmt.dassign->Dump(mod, 0); + defStmt.dassign->Dump(*mod, 0); return; case kPhi: defStmt.phi->Dump(mod); diff --git a/src/maple_phase/include/phase_manager.h b/src/maple_phase/include/phase_manager.h index a5b4a10ea30da637843ffd18126dfa06dc32c23d..b9e9fe71aaa1adf4f66e0e1d0f02041466fd29e5 100644 --- a/src/maple_phase/include/phase_manager.h +++ b/src/maple_phase/include/phase_manager.h @@ -16,6 +16,7 @@ #define MAPLE_PHASE_INCLUDE_PHASE_MANAGER_H #include #include "phase.h" +#include "module_phase.h" namespace maple { class PhaseManager { @@ -44,6 +45,16 @@ class PhaseManager { registeredPhases[id] = p; } + Phase *GetPhaseFromName(const char *pname) { + for (auto it = RegPhaseBegin(); it != RegPhaseEnd(); it++) { + if (GetPhaseName(it) == pname) { + return GetPhase(GetPhaseId(it)); + } + } + MIR_WARNING("not a valid phase"); + return nullptr; + } + Phase *GetPhase(PhaseID id) { if (registeredPhases.find(id) != registeredPhases.end()) { return registeredPhases[id]; @@ -56,6 +67,11 @@ class PhaseManager { MIR_ASSERT(false && "should not run here"); } + virtual ModuleResultMgr *GetModResultMgr() { + MIR_ASSERT(false && "should not run here"); + return nullptr; + } + MapleAllocator *GetMemAllocator() { return &allocator; } diff --git a/src/mpl2mpl/include/class_hierarchy.h b/src/mpl2mpl/include/class_hierarchy.h index 3c6cf85426bc253dc92dc516617579872028362e..a4b20cd2053abccbe4ebfe0dd11f686997048a53 100644 --- a/src/mpl2mpl/include/class_hierarchy.h +++ b/src/mpl2mpl/include/class_hierarchy.h @@ -384,6 +384,5 @@ class KlassHierarchy : public AnalysisResult { Klass *AddClassFlag(const char *name, uint32 flag); int GetFieldIDOffsetBetweenClasses(const Klass &super, const Klass &base) const; }; - } // namespace maple #endif // MPL2MPL_INCLUDE_CLASS_HIERARCHY_H diff --git a/src/mpl2mpl/include/class_init.h b/src/mpl2mpl/include/class_init.h index 41c277e780e1f436055cf028821ac00be66dcd85..0ca98d62f36ce79037770f17faaaa96e15d301cc 100644 --- a/src/mpl2mpl/include/class_init.h +++ b/src/mpl2mpl/include/class_init.h @@ -55,6 +55,5 @@ class DoClassInit : public ModulePhase { return nullptr; } }; - } // namespace maple #endif // MPL2MPL_INCLUDE_CLASS_INIT_H diff --git a/src/mpl2mpl/include/gen_check_cast.h b/src/mpl2mpl/include/gen_check_cast.h index 088a182e9a1e305ff617eb170da0e728766c0267..a9a31f021578a825c267cbf4ae2c6ec9c1e8727f 100644 --- a/src/mpl2mpl/include/gen_check_cast.h +++ b/src/mpl2mpl/include/gen_check_cast.h @@ -65,6 +65,5 @@ class DoCheckCastGeneration : public ModulePhase { } }; - } // namespace maple #endif // MPL2MPL_INCLUDE_GEN_CHECK_CAST_H diff --git a/src/mpl2mpl/include/java_intrn_lowering.h b/src/mpl2mpl/include/java_intrn_lowering.h index 27a60bfd4eef5931a4026242dbeffef8c9e2fbc0..abb684374ba99d255520dc60c01938f4e71f9bd9 100644 --- a/src/mpl2mpl/include/java_intrn_lowering.h +++ b/src/mpl2mpl/include/java_intrn_lowering.h @@ -51,6 +51,5 @@ class DoJavaIntrnLowering : public ModulePhase { return nullptr; } }; - } // namespace maple #endif // MPL2MPL_INCLUDE_JAVA_INTRN_LOWERING_H diff --git a/src/mpl2mpl/include/muid_replacement.h b/src/mpl2mpl/include/muid_replacement.h index 7f97327212bfdb877f0ebe39c32ba016427d499d..2ebc32df5c1921884cafe1a767df5ec9108a0ed1 100644 --- a/src/mpl2mpl/include/muid_replacement.h +++ b/src/mpl2mpl/include/muid_replacement.h @@ -173,6 +173,5 @@ class DoMUIDReplacement : public ModulePhase { return nullptr; } }; - } // namespace maple #endif // MPL2MPL_INCLUDE_MUID_REPLACEMENT_H diff --git a/src/mpl2mpl/include/native_stub_func.h b/src/mpl2mpl/include/native_stub_func.h index 538d4d5b7db7f64150a4a45cd57d8008b1e067b0..5961445262c618e2b049d39ecfc40bebecd7b16d 100644 --- a/src/mpl2mpl/include/native_stub_func.h +++ b/src/mpl2mpl/include/native_stub_func.h @@ -18,7 +18,6 @@ #include "phase_impl.h" namespace maple { - static constexpr int kSlownativeFuncnum = 9; static constexpr int kJniTypeNormal = 0; static constexpr int kJniTypeMapleCriticalNative = 1; @@ -122,6 +121,5 @@ class DoGenericNativeStubFunc : public ModulePhase { return nullptr; } }; - } // namespace maple #endif // MPL2MPL_INCLUDE_NATIVE_STUB_FUNC_H diff --git a/src/mpl2mpl/include/reflection_analysis.h b/src/mpl2mpl/include/reflection_analysis.h index 09bae3239978f86e641c42d461f52f47fda24302..3477adc6f3dc7c822830ebff4860dece059ae625 100644 --- a/src/mpl2mpl/include/reflection_analysis.h +++ b/src/mpl2mpl/include/reflection_analysis.h @@ -17,7 +17,6 @@ #include "class_hierarchy.h" namespace maple { - // +1 is needed here because our field id starts with 0 pointing to the struct itself #define OBJ_KLASS_FIELDID (static_cast(ClassProperty::kShadow) + 1) #define METADATA_KLASS_FIELDID (static_cast(ClassProperty::kShadow) + 1) @@ -349,6 +348,7 @@ class ReflectionAnalysis : public AnalysisResult { static std::string strTabRunHot; static bool strTabInited; static TyIdx invalidIdx; + static constexpr uint16 kNoHashBits = 6u; }; class DoReflectionAnalysis : public ModulePhase { @@ -362,6 +362,5 @@ class DoReflectionAnalysis : public ModulePhase { return "reflectionanalysis"; } }; - } // namespace maple #endif // MPL2MPL_INCLUDE_REFLECTION_ANALYSIS_H diff --git a/src/mpl2mpl/include/vtable_analysis.h b/src/mpl2mpl/include/vtable_analysis.h index f499be0cd4b7a3a85ea152ff000ac350e9e9607f..7ec004a0dd0c6670a2899e3ca2005abe9bfc2149 100644 --- a/src/mpl2mpl/include/vtable_analysis.h +++ b/src/mpl2mpl/include/vtable_analysis.h @@ -76,6 +76,5 @@ class DoVtableAnalysis : public ModulePhase { return nullptr; } }; - } // namespace maple #endif // MPL2MPL_INCLUDE_VTABLE_ANALYSIS_H diff --git a/src/mpl2mpl/include/vtable_impl.h b/src/mpl2mpl/include/vtable_impl.h index e96e6c2c2de8843c34f02db0925f98c0f243a3d3..7c7a65ef33c8b50a9c3c987194251cc04a5546ad 100644 --- a/src/mpl2mpl/include/vtable_impl.h +++ b/src/mpl2mpl/include/vtable_impl.h @@ -59,6 +59,5 @@ class DoVtableImpl : public ModulePhase { return nullptr; } }; - } // namespace maple #endif // MPL2MPL_INCLUDE_VTABLE_IMPL_H diff --git a/src/mpl2mpl/src/class_hierarchy.cpp b/src/mpl2mpl/src/class_hierarchy.cpp index 6e66da4fa8cb8a3fe1dda8438a22b2777200c7f7..17e1900a910132b923174c513647cdf3db83339d 100644 --- a/src/mpl2mpl/src/class_hierarchy.cpp +++ b/src/mpl2mpl/src/class_hierarchy.cpp @@ -959,5 +959,4 @@ bool WKTypes::Util::NotCyclicType(MIRType *type, std::set &workList) { } return false; } - } // namespace maple diff --git a/src/mpl2mpl/src/class_init.cpp b/src/mpl2mpl/src/class_init.cpp index d824e183763074143694d1dfde218771cdb0af84..4c976b9573a35fe4d06b017133d819798a6b9659 100644 --- a/src/mpl2mpl/src/class_init.cpp +++ b/src/mpl2mpl/src/class_init.cpp @@ -72,8 +72,12 @@ void ClassInit::ProcessFunc(MIRFunction *func) { } else { const std::string &funcName = func->GetName(); size_t pos = funcName.find(NameMangler::kNameSplitterStr); - while (pos != std::string::npos && (pos >= 2 && funcName[pos - 1] == '_' && funcName[pos - 2] != '_')) { - pos = funcName.find(NameMangler::kNameSplitterStr, pos + 3); + constexpr size_t kPrePos = 2; + constexpr size_t kLigalPos = 2; + while (pos != std::string::npos && + (pos >= kLigalPos && funcName[pos - 1] == '_' && funcName[pos - kPrePos] != '_')) { + constexpr size_t kNextPos = 3; + pos = funcName.find(NameMangler::kNameSplitterStr, pos + kNextPos); } selfClassName = funcName.substr(0, pos); } @@ -160,5 +164,4 @@ MIRSymbol *ClassInit::GetClassInfo(const std::string &classname) { } return classInfo; } - } // namespace maple diff --git a/src/mpl2mpl/src/gen_check_cast.cpp b/src/mpl2mpl/src/gen_check_cast.cpp index f58f91570384219643d21d94662bb59e8716c9a0..3278642b52f6fce3631e93855907576d73708d82 100644 --- a/src/mpl2mpl/src/gen_check_cast.cpp +++ b/src/mpl2mpl/src/gen_check_cast.cpp @@ -137,7 +137,7 @@ void CheckCastGenerator::GenCheckCast(BaseNode *stmt) { BaseNode *ireadExpr = GetObjectShadow(opnd); BaseNode *innerCond = builder->CreateExprCompare(OP_ne, GlobalTables::GetTypeTable().GetUInt1(), - GlobalTables::GetTypeTable().GetPtr(), valueExpr, ireadExpr); + GlobalTables::GetTypeTable().GetPtr(), valueExpr, ireadExpr); IfStmtNode *innerIfStmt = static_cast(builder->CreateStmtIf(innerCond)); MapleVector args(builder->GetCurrentFuncCodeMpAllocator()->Adapter()); args.push_back(valueExpr); @@ -291,5 +291,4 @@ void CheckCastGenerator::ProcessFunc(MIRFunction *func) { MIRLower mirlowerer(*(GetModule()), 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 32e72f446b195bb3d65d1b9a033644664d372143..237fafb084c59d544f47c8a0d6cafbfbf0420968 100644 --- a/src/mpl2mpl/src/java_eh_lower.cpp +++ b/src/mpl2mpl/src/java_eh_lower.cpp @@ -231,5 +231,4 @@ void JavaEHLowerer::ProcessFunc(MIRFunction *func) { BlockNode *newBody = DoLowerBlock(func->GetBody()); func->SetBody(newBody); } - } // namespace maple diff --git a/src/mpl2mpl/src/java_intrn_lowering.cpp b/src/mpl2mpl/src/java_intrn_lowering.cpp index ec9ec1304f5e818f4d3e62aca730140258692eaf..cc7e31ccb854e590580d9fb1563c9ba315fd04c2 100644 --- a/src/mpl2mpl/src/java_intrn_lowering.cpp +++ b/src/mpl2mpl/src/java_intrn_lowering.cpp @@ -178,6 +178,7 @@ void JavaIntrnLowering::ProcessJavaIntrnFillNewArray(IntrinsiccallNode *intrinCa currFunc->GetBody()->ReplaceStmt1WithStmt2(intrinCall, assignStmt); addrExpr = builder->CreateExprRegread(mirpreg->GetPrimType(), pregidx); } + assignStmt->SetSrcPos(intrinCall->GetSrcPos()); StmtNode *stmt = assignStmt; for (int i = 0; i < intrinCall->NumOpnds(); i++) { ArrayNode *arrayexpr = builder->CreateExprArray(arrayType, addrExpr, builder->CreateIntConst(i, PTY_i32)); @@ -187,5 +188,4 @@ void JavaIntrnLowering::ProcessJavaIntrnFillNewArray(IntrinsiccallNode *intrinCa stmt = storeStmt; } } - } // namespace maple diff --git a/src/mpl2mpl/src/muid_replacement.cpp b/src/mpl2mpl/src/muid_replacement.cpp index cdadbb18981fedfcd1ca4479b1ab20e88cfdb9a7..28cdcd3141f83ec62852c579e7ff478e168e86c5 100644 --- a/src/mpl2mpl/src/muid_replacement.cpp +++ b/src/mpl2mpl/src/muid_replacement.cpp @@ -25,7 +25,6 @@ // // B) It will replace the relevant reference about the methods and static variable with def or undef // table.And then we can close these symbols to reduce the code size. -// namespace maple { MUID MUIDReplacement::kMplMuid; @@ -312,8 +311,9 @@ void MUIDReplacement::GenericFuncDefTable() { // Use the left 1 bit of muidIdx to mark wether the function is weak or not. 1 is for weak MIRIntConst *indexConst = nullptr; if (kReflectionList.find(mirFunc->GetName()) != kReflectionList.end()) { + constexpr uint32 kWeakFuncFlag = 0x80000000; // 0b10000000 00000000 00000000 00000000 indexConst = - GetModule()->GetMemPool()->New((1u << 31) | idx, GlobalTables::GetTypeTable().GetUInt32()); + GetModule()->GetMemPool()->New(kWeakFuncFlag | idx, GlobalTables::GetTypeTable().GetUInt32()); } else { indexConst = GetModule()->GetMemPool()->New(idx, GlobalTables::GetTypeTable().GetUInt32()); } @@ -325,7 +325,7 @@ void MUIDReplacement::GenericFuncDefTable() { if (trace) { LogInfo::MapleLogger() << "funcDefMap, MUID: " << muid.ToStr() << ", Function Name: " << iter->second.first->GetName() - << ", Offset in addr order: " << idx - 1 + << ", Offset in addr order: " << (idx - 1) << ", Offset in muid order: " << iter->second.second << std::endl; } } @@ -714,13 +714,16 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldId, b ASSERT(func, "Invalid MIRFunction"); uint64 offset = 0; MIRIntConst *constNode = nullptr; + constexpr uint64 kReservedBits = 2u; if (func->GetBody()) { offset = FindIndexFromDefTable(func->GetFuncSymbol(), true); // Left shifting is needed because in itable 0 and 1 are reserved. // 0 marks no entry and 1 marks a conflict. // The second least significant bit is set to 1, indicating // this is an index into the funcDefTab - constNode = GetModule()->GetMemPool()->New(((offset + 1) << 2) + 2, voidType); + constexpr uint64 kIdxIntoFuncDefTabFlag = 2u; + constNode = GetModule()->GetMemPool()->New(((offset + 1) << kReservedBits) + kIdxIntoFuncDefTabFlag, + voidType); } else if (isVtab && func->IsAbstract()) { MIRType *type = GlobalTables::GetTypeTable().GetVoidPtr(); constNode = GetModule()->GetMemPool()->New(0, type); @@ -728,7 +731,7 @@ void MUIDReplacement::ReplaceAddroffuncConst(MIRConst *&entry, uint32 fieldId, b offset = FindIndexFromUndefTable(func->GetFuncSymbol(), true); // The second least significant bit is set to 0, indicating // this is an index into the funcUndefTab - constNode = GetModule()->GetMemPool()->New((offset + 1) << 2, voidType); + constNode = GetModule()->GetMemPool()->New((offset + 1) << kReservedBits, voidType); } if (fieldId != 0xffffffff) { constNode->SetFieldID(fieldId); @@ -1151,5 +1154,4 @@ void MUIDReplacement::GenericTables() { ReplaceDataTable(NameMangler::kGcRootList); GenericCompilerVersionNum(); } - } // namespace maple diff --git a/src/mpl2mpl/src/native_stub_func.cpp b/src/mpl2mpl/src/native_stub_func.cpp index d1e1d392bd52eaab96c72e11fa3e5db46c333077..b2d71f179025027802e2b297cdd66de4573c9319 100644 --- a/src/mpl2mpl/src/native_stub_func.cpp +++ b/src/mpl2mpl/src/native_stub_func.cpp @@ -25,7 +25,6 @@ // for the preparations before the actual native function is called, // including the parameter mapping, GC preparation, and so on. namespace maple { - GenericNativeStubFunc::GenericNativeStubFunc(MIRModule *mod, KlassHierarchy *kh, bool dump) : FuncOptimizeImpl(mod, kh, dump) { MIRType *jstrType = GlobalTables::GetTypeTable().GetOrCreateClassType( @@ -298,8 +297,9 @@ void GenericNativeStubFunc::GenericRegFuncTabEntry() { constexpr int locIdxShift = 4; constexpr uint64 locIdxMask = 0xFF00000000000000; uint64 locIdx = regFuncTabConst->GetConstVec().size(); - MIRConst *newConst = GetModule()->GetMemPool()->New((uint64)((locIdx << locIdxShift) | locIdxMask), - GlobalTables::GetTypeTable().GetVoidPtr()); + MIRConst *newConst = + GetModule()->GetMemPool()->New(static_cast((locIdx << locIdxShift) | locIdxMask), + GlobalTables::GetTypeTable().GetVoidPtr()); regFuncTabConst->GetConstVec().push_back(newConst); } @@ -379,9 +379,9 @@ void GenericNativeStubFunc::GenericRegisteredNativeFuncCall(MIRFunction *func, c // Use native wrapper if required. if (Options::nativeWrapper) { // Now native binding have three mode: default mode, dynamic-only mode, static binding list mode - // default mode, it will generate a week function, which can link in compile time - // dynamic only mode, it won't generate any week function, it can't link in compile time - // static binding list mode, it will generate a week function only in list + // default mode, it will generate a weak function, which can link in compile time + // dynamic only mode, it won't generate any weak function, it can't link in compile time + // static binding list mode, it will generate a weak function only in list if (IsStaticBindingListMode() && IsStaticBindingMethod(func->GetName())) { // Get current func_ptr (strong/weak symbol address) auto *nativeFuncAddr = builder->CreateExprAddroffunc(nativeFunc->GetPuidx()); @@ -443,7 +443,8 @@ void GenericNativeStubFunc::GenericRegisteredNativeFuncCall(MIRFunction *func, c ifStmt->GetThenPart()->AddStatement(callGetExceptFunc); BlockNode *elseBlock = func->GetCodeMempool()->New(); ifStmt->SetElsePart(elseBlock); - ifStmt->SetNumOpnds(3); + constexpr uint32 kNumOfOpnds = 3u; + ifStmt->SetNumOpnds(kNumOfOpnds); wrapperCall = CreateNativeWrapperCallNode(func, readFuncPtr, args, ret); elseBlock->AddStatement(wrapperCall); func->GetBody()->AddStatement(ifStmt); @@ -513,7 +514,8 @@ StmtNode *GenericNativeStubFunc::CreateNativeWrapperCallNode(MIRFunction *func, auto isFast = (func->GetAttr(FUNCATTR_fast_native) || func->GetAttr(FUNCATTR_critical_native)); // Do not need native wrapper for critical natives // if num_of_args < 8 - if (func->GetAttr(FUNCATTR_critical_native) && args.size() <= 7) { + constexpr size_t kNumOfArgs = 8; + if (func->GetAttr(FUNCATTR_critical_native) && args.size() < kNumOfArgs) { IcallNode *icall = func->GetCodeMempool()->New(GetModule(), OP_icallassigned); CallReturnVector nrets(func->GetCodeMempoolAllocator()->Adapter()); if (ret) { @@ -534,7 +536,7 @@ StmtNode *GenericNativeStubFunc::CreateNativeWrapperCallNode(MIRFunction *func, } // If num of args > 8 - if (args.size() > 8) { + if (args.size() > kNumOfArgs) { wrapperFunc = isFast ? MRTCallFastNativeExtFunc : MRTCallSlowNativeExtFunc; } else if (isFast) { wrapperFunc = MRTCallFastNativeFunc; @@ -670,5 +672,4 @@ void GenericNativeStubFunc::Finish() { ReflectionAnalysis::GenStrTab(GetModule()); } } - } // namespace maple diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index 2d527acc5eae349baa3af32b5c7ebebd4be1c2ec..cd3e7ddfc3cc74c7df9c06a0df46bbce5ecea415 100644 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -123,26 +123,29 @@ TyIdx ReflectionAnalysis::fieldsInfoTyIdx = TyIdx(0); TyIdx ReflectionAnalysis::fieldsInfoCompactTyIdx = TyIdx(0); TyIdx ReflectionAnalysis::superclassMetadataTyIdx = TyIdx(0); TyIdx ReflectionAnalysis::invalidIdx = TyIdx(-1); -static constexpr int kModPublic = 1; // 0x00000001 -static constexpr int kModPrivate = 2; // 0x00000002 -static constexpr int kModProtected = 3; // 0x00000004 -static constexpr int kModStatic = 4; // 0x00000008 -static constexpr int kModFinal = 5; // 0x00000010 -static constexpr int kModSynchronized = 6; // 0x00000020 -static constexpr int kModVolatile = 7; // 0x00000040 -static constexpr int kModTransient = 8; // 0x00000080 -static constexpr int kModNative = 9; // 0x00000100 -static constexpr int kModAbstract = 11; // 0x00000400 -static constexpr int kModStrict = 12; // 0x00000800 -static constexpr int kModSynthetic = 13; // 0x00001000 -static constexpr int kModConstructor = 17; // 0x00010000 -static constexpr int kModDefault = 22; // 0x00400000 -static constexpr int kModBridge = 7; // 0x00000040 -static constexpr int kModVarargs = 8; // 0x00000080 -static constexpr int kModEnum = 15; // 0x00004000 -static constexpr int kModDeclaredSynchronized = 18; // 0x00020000 -static constexpr int kModifierRCUnowned = 24; // 0x00800000 -static constexpr int kModifierRCWeak = 25; // 0x01000000 +namespace { +constexpr int kModPublic = 1; // 0x00000001 +constexpr int kModPrivate = 2; // 0x00000002 +constexpr int kModProtected = 3; // 0x00000004 +constexpr int kModStatic = 4; // 0x00000008 +constexpr int kModFinal = 5; // 0x00000010 +constexpr int kModSynchronized = 6; // 0x00000020 +constexpr int kModVolatile = 7; // 0x00000040 +constexpr int kModTransient = 8; // 0x00000080 +constexpr int kModNative = 9; // 0x00000100 +constexpr int kModAbstract = 11; // 0x00000400 +constexpr int kModStrict = 12; // 0x00000800 +constexpr int kModSynthetic = 13; // 0x00001000 +constexpr int kModConstructor = 17; // 0x00010000 +constexpr int kModDefault = 22; // 0x00400000 +constexpr int kModBridge = 7; // 0x00000040 +constexpr int kModVarargs = 8; // 0x00000080 +constexpr int kModEnum = 15; // 0x00004000 +constexpr int kModDeclaredSynchronized = 18; // 0x00020000 +constexpr int kModifierRCUnowned = 24; // 0x00800000 +constexpr int kModifierRCWeak = 25; // 0x01000000 +} + uint32 GetMethodModifier(FuncAttrs fa) { return (static_cast(fa.GetAttr(FUNCATTR_public)) << (kModPublic - 1)) | @@ -406,20 +409,21 @@ uint16 GetFieldHash(std::vector> &fieldV, FieldPair } static void DelimeterConvert(std::string &str) { + constexpr size_t kNextPos = 2; size_t loc = str.find("`"); while (loc != std::string::npos) { str.replace(loc, 1, "``"); - loc = str.find("`", loc + 2); + loc = str.find("`", loc + kNextPos); } loc = str.find("!"); while (loc != std::string::npos) { str.replace(loc, 1, "`!"); - loc = str.find("!", loc + 2); + loc = str.find("!", loc + kNextPos); } loc = str.find("|"); while (loc != std::string::npos) { str.replace(loc, 1, "`|"); - loc = str.find("|", loc + 2); + loc = str.find("|", loc + kNextPos); } } @@ -685,7 +689,7 @@ MIRSymbol *ReflectionAnalysis::GenMethodsMetaData(const Klass *klass) { flag |= kMethodAbstract; } uint16 hash = func->GetHashCode(); - flag |= (hash << 6); // hash 10 bit + flag |= (hash << kNoHashBits); // hash 10 bit // @method_in_vtable_index uint32 methodInVtabIndex = static_cast(static_cast(GetMethodInVtabIndex(klass, func))); methodInVtabIndex &= 0xFFFF; @@ -714,8 +718,7 @@ MIRSymbol *ReflectionAnalysis::GenMethodsMetaData(const Klass *klass) { ConvertMethodSig(signature); std::vector typeNames; GetSignatureTypeNames(signature.c_str(), typeNames); - uint32 signatureIdx = 0; - signatureIdx = FindOrInsertReflectString(signature); + uint32 signatureIdx = FindOrInsertReflectString(signature); mirBuilder.AddIntFieldConst(*methodsInfoType, *newconst, fieldID++, signatureIdx); // @annotation int annotationIdx = SolveAnnotation(classType, func); @@ -865,7 +868,7 @@ MIRSymbol *ReflectionAnalysis::GenFieldsMetaData(const Klass *klass) { uint32 typeNameIdx = GetTypeNameIdxFromType(ty, klass, fieldname); // @flag uint16 hash = GetFieldHash(fieldHashvec, fieldP); - uint16 flag = (hash << 6); // Hash 10 bit. + uint16 flag = (hash << kNoHashBits); // Hash 10 bit. mirBuilder.AddIntFieldConst(*fieldsInfoType, *newconst, fieldID++, flag); // @index mirBuilder.AddIntFieldConst(*fieldsInfoType, *newconst, fieldID++, idx); @@ -1685,5 +1688,4 @@ AnalysisResult *DoReflectionAnalysis::Run(MIRModule *module, ModuleResultMgr *mr mempoolctrler.DeleteMemPool(memPool); return nullptr; } - } // namespace maple diff --git a/src/mpl2mpl/src/vtable_analysis.cpp b/src/mpl2mpl/src/vtable_analysis.cpp index b1358771c60a5ed9f5e511862029a3cb8e9d184e..d2467621bc1a6a87cf67e863dd005a226d760b8a 100644 --- a/src/mpl2mpl/src/vtable_analysis.cpp +++ b/src/mpl2mpl/src/vtable_analysis.cpp @@ -472,5 +472,4 @@ void VtableAnalysis::ReplaceInterfaceInvoke(CallNode *stmt) { stmt->GetNopnd().insert(stmt->GetNopnd().begin(), resolveNode); stmt->SetNumOpnds(stmt->GetNumOpnds() + 1); } - } // namespace maple diff --git a/src/mpl2mpl/src/vtable_impl.cpp b/src/mpl2mpl/src/vtable_impl.cpp index 0695e03689f2f16f7f962d92c76882c834e46b3b..e4048ef242987592921a6dabf0e09fd5c57d4a6b 100644 --- a/src/mpl2mpl/src/vtable_impl.cpp +++ b/src/mpl2mpl/src/vtable_impl.cpp @@ -148,5 +148,4 @@ void VtableImpl::ReplaceResolveInterface(StmtNode *stmt, const ResolveFuncNode * icall->SetNOpndAt(0, builder->CreateExprRegread(compactPtrPrim, pregFuncPtr)); } } - } // namespace maple