diff --git a/doc/Development_Preparation.md b/doc/Development_Preparation.md index 11ee3ac4e9140e4bcf6220f7bdbbe2ea060f304e..567caeb0373bdfc2acc58767f46797b82fb8675e 100644 --- a/doc/Development_Preparation.md +++ b/doc/Development_Preparation.md @@ -43,8 +43,8 @@ GN下载地址:https://archive.softwareheritage.org/browse/content/sha1_git:2d 将GN和Ninja可执行程序放置到openarkcompiler/tools目录,然后修改这两个文件为可执行: ``` cd openarkcompiler/tools -chmod 777 gn -chmod 777 ninja +chmod 775 gn +chmod 775 ninja ``` 打开openarkcompiler/Makefile文件,将GN和NINJA两个变量配置为GN和Ninja可执行程序所在路径。例如: diff --git a/license/Third_Party_Open_Source_Software_Notice.md b/license/Third_Party_Open_Source_Software_Notice.md deleted file mode 100644 index 634cb20ffd026ac201f62b000d0eb845d0fe4aa0..0000000000000000000000000000000000000000 --- a/license/Third_Party_Open_Source_Software_Notice.md +++ /dev/null @@ -1,98 +0,0 @@ -**OPEN SOURCE SOFTWARE NOTICE** - -Please note we provide an open source software notice for the third party open source software along with this software and/or this software component contributed by Huawei (in the following just “this SOFTWARE”). The open source software licenses are granted by the respective right holders. - -**Warranty Disclaimer ** - -**The open source software in this product is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the applicable licenses for more details.** - -**Copyright Notice and License Texts ** - -Software: zlib 1.2.11 - -**Copyright notice: ** - -Copyright (C) 1995-2016 Mark Adler - -Copyright (C) 2004, 2008, 2012 Mark Adler, all rights reserved - -Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - -Copyright (C) 2007-2008 Even Rouault - -Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - -Copyright (C) 2004, 2008, 2012, 2016 Mark Adler, all rights reserved - -Copyright (C) 1995-2003 Mark Adler - -Copyright (C) 2003 Chris Anderson <christop@charm.net> - -© Copyright Henrik Ravn 2004 - -Copyright (C) 1995-2006, 2011, 2016 Jean-loup Gailly - -Copyright (C) 2002-2013 Mark Adler - -Copyright (C) 2002-2013 Mark Adler, all rights reserved - -Copyright (C) 2004, 2005, 2012 Mark Adler, all rights reserved - -Copyright (C) 1995-2017 Jean-loup Gailly - -Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler - -Copyright (C) 2011, 2016 Mark Adler - -Copyright (C) 2003, 2012 Mark Adler, all rights reserved - -- Add version and copyright to help - -Copyright (C) 1995-2017 Mark Adler - -Copyright (C) 1995-2008 Mark Adler - -Copyright (C) 2005, 2012 Mark Adler - -Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler - -Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler - -Copyright (C) 1995-2016 Jean-loup Gailly - -Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler - -**License:** zlib/libpng License - -Copyright (c) <year> <copyright holders> - -This software is provided 'as-is', without any express or implied - -warranty. In no event will the authors be held liable for any damages - -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, - -including commercial applications, and to alter it and redistribute it - -freely, subject to the following restrictions: - -1\. The origin of this software must not be misrepresented; you must not - -claim that you wrote the original software. If you use this software - -in a product, an acknowledgment in the product documentation would be - -appreciated but is not required. - -2\. Altered source versions must be plainly marked as such, and must not be - -misrepresented as being the original software. - -3\. This notice may not be removed or altered from any source - -distribution. - - - diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index e775aeac35377c226fc005bcedc0c6f64849cbbd..d083083b7d3334fd9d896ba8b916234a38df6ecc 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index b59930ce1f9cb257463377b0867103acec2d03d1..cb22709bac5c2e58aa095ff90b726450be0944b3 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index 9068235ee7cb3d79b127fc20c51a074de9fa317b..65c234a17bc270545a2f0c5516772afb3761cf43 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/deplibs/libmaple_driverutil.a b/src/deplibs/libmaple_driverutil.a index 22befbc20bd39bee9c5d26cc85c1a213784b7a30..c1262b62e5722495e3d5fbddf11140183b8f2b5c 100644 Binary files a/src/deplibs/libmaple_driverutil.a and b/src/deplibs/libmaple_driverutil.a differ diff --git a/src/deplibs/libmempool.a b/src/deplibs/libmempool.a index c9946baf59fe0819105e47043f4a5979d4f343e2..77f7f9b4b4549f791375f4f42bd8ab5f3c69bcfd 100644 Binary files a/src/deplibs/libmempool.a and b/src/deplibs/libmempool.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index 2fd24ac5f66a5e3cb7c56a0831190aae75c1e9d7..4e28d0f891c40b01917084268b0ff2131e414064 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_ipa/include/interleaved_manager.h b/src/maple_ipa/include/interleaved_manager.h index 9098785f65bd1483cb7480555459fc158e24cfd6..84d5b4ab2d47295135dcc3d9b52fa178888486bc 100644 --- a/src/maple_ipa/include/interleaved_manager.h +++ b/src/maple_ipa/include/interleaved_manager.h @@ -18,7 +18,6 @@ #include "module_phase_manager.h" namespace maple { - class InterleavedManager { public: InterleavedManager(MemPool *memPool, MIRModule *mirm, std::string input, bool timer) @@ -72,6 +71,5 @@ class InterleavedManager { void InitSupportPhaseManagers(); }; - } // namespace maple #endif // MAPLE_IPA_INCLUDE_INTERLEAVED_MANAGER_H diff --git a/src/maple_ipa/include/module_phase.h b/src/maple_ipa/include/module_phase.h index 15194b36b18afd18f695794499016e9877d44201..c51a36eae40148dceb2dfda586116f98e497a394 100644 --- a/src/maple_ipa/include/module_phase.h +++ b/src/maple_ipa/include/module_phase.h @@ -47,6 +47,5 @@ class ModulePhase : public Phase { private: ModulePhaseID phaseID; }; - } // namespace maple #endif // MAPLE_IPA_INCLUDE_MODULE_PHASE_H diff --git a/src/maple_ipa/include/module_phase_manager.h b/src/maple_ipa/include/module_phase_manager.h index dc02fcdb3aa0901b9dec978d82fa94d63b153669..ccd3e87e9fad47ea96672807e4aa2548aa7e7b84 100644 --- a/src/maple_ipa/include/module_phase_manager.h +++ b/src/maple_ipa/include/module_phase_manager.h @@ -68,6 +68,5 @@ class ModulePhaseManager : public PhaseManager { MIRModule &mirModule; ModuleResultMgr *arModuleMgr; /* module level analysis result */ }; - } // namespace maple #endif // MAPLE_IPA_INCLUDE_MODULE_PHASE_MANAGER_H diff --git a/src/maple_ipa/src/interleaved_manager.cpp b/src/maple_ipa/src/interleaved_manager.cpp index 8bdacf944855b730084dc8cd49ea9efe4b857642..963de3278dd117489e2c5d72d3af84b13cec200b 100644 --- a/src/maple_ipa/src/interleaved_manager.cpp +++ b/src/maple_ipa/src/interleaved_manager.cpp @@ -120,7 +120,7 @@ void InterleavedManager::DumpTimers() { for (const auto &lapse : timeVec) { LogInfo::MapleLogger() << std::left << std::setw(25) << lapse.first << std::setw(10) << std::right << std::fixed << std::setprecision(2) << (100.0 * lapse.second / total) << "%" << std::setw(10) - << (lapse.second / 1000) << "ms" << std::endl; + << (lapse.second / 1000) << "ms" << "\n"; } LogInfo::MapleLogger() << "================================================\n"; LogInfo::MapleLogger().flags(f); diff --git a/src/maple_ipa/src/module_phase_manager.cpp b/src/maple_ipa/src/module_phase_manager.cpp index 8cef4beaa2ea4515da5347cfd6b87d8e34783fab..36e5f3b7cba60b3d71314de24363a337da5fbcb6 100644 --- a/src/maple_ipa/src/module_phase_manager.cpp +++ b/src/maple_ipa/src/module_phase_manager.cpp @@ -120,5 +120,4 @@ void ModulePhaseManager::Emit(const char *passName) { outFileName = outFileName.append(kDotMplStr); mirModule.DumpToFile(outFileName); } - } // namespace maple diff --git a/src/maple_ir/include/bin_mpl_export.h b/src/maple_ir/include/bin_mpl_export.h index 7566bceb8a4702907da5344271f6f5bca957f3e0..96dc481e9f5d4b6fb2b3006af41c64cbd7626a29 100644 --- a/src/maple_ir/include/bin_mpl_export.h +++ b/src/maple_ir/include/bin_mpl_export.h @@ -76,19 +76,19 @@ class BinaryMplExport { virtual ~BinaryMplExport() {} void Export(const std::string &fname); - void WriteContentField(int fieldNum, uint64 *fieldStartP); + void WriteContentField(int fieldNum, uint64 &fieldStartP); void WriteStrField(uint64 contentIdx); void WriteTypeField(uint64 contentIdx); void Init(); void OutputConst(MIRConst *c); - void OutputConstBase(const MIRConst *c); + void OutputConstBase(const MIRConst &c); void OutputStr(const GStrIdx &gstr); void OutputUsrStr(UStrIdx ustr); - void OutputTypePairs(MIRInstantVectorType *typ); - void OutputTypeBase(const MIRType *type); + void OutputTypePairs(MIRInstantVectorType &typ); + void OutputTypeBase(const MIRType &type); void OutputType(const TyIdx &tyIdx); void OutputTypeAttrs(const TypeAttrs &ta); - void OutputPragmaElement(const MIRPragmaElement *e); + void OutputPragmaElement(const MIRPragmaElement &e); void OutputPragma(const MIRPragma *p); void OutputFieldPair(const FieldPair &fp); void OutputMethodPair(const MethodPair &memPool); @@ -101,7 +101,7 @@ class BinaryMplExport { void OutputPragmaVec(const std::vector &pragmaVec); void OutputClassTypeData(MIRClassType *type); void OutputInterfaceTypeData(MIRInterfaceType *type); - void OutputSymbol(MIRSymbol *sym); + void OutputSymbol(const MIRSymbol *sym); void OutputFunction(PUIdx puIdx); void OutWords(uint8 *typeTagged, int64 targetTag, uint16 size); void Write(uint8 b); @@ -126,7 +126,7 @@ class BinaryMplExport { std::unordered_map funcMark; std::string importFileName; std::unordered_map uStrMark; - std::unordered_map symMark; + std::unordered_map symMark; std::unordered_map typMark; static int typeMarkOffset; // offset of mark (tag in binmplimport) resulting from duplicated function void ExpandFourBuffSize(); diff --git a/src/maple_ir/include/bin_mpl_import.h b/src/maple_ir/include/bin_mpl_import.h index a3dbfdb48bf701aee3b963630c1069cb2382c15a..270be3ec9215cf9d9d7a777185f55c9dc4a35178 100644 --- a/src/maple_ir/include/bin_mpl_import.h +++ b/src/maple_ir/include/bin_mpl_import.h @@ -75,8 +75,8 @@ class BinaryMplImport { void Reset(); MIRSymbol *GetOrCreateSymbol(const TyIdx &tyIdx, const GStrIdx &strIdx, MIRSymKind mclass, MIRStorageClass sclass, MIRFunction *func, uint8 scpID); - MIRType *InsertInTypeTables(MIRType *ptype); - void InsertInHashTable(MIRType *ptype); + MIRType &InsertInTypeTables(MIRType &ptype); + void InsertInHashTable(MIRType &ptype); void SetupEHRootType(); void UpdateMethodSymbols(); void ImportConstBase(MIRConstKind &kind, MIRTypePtr &type, uint32 &fieldID); @@ -97,14 +97,14 @@ class BinaryMplImport { void ImportFieldPair(FieldPair &fp); void ImportMethodPair(MethodPair &memPool); void ImportMethodsOfStructType(MethodVector &methods); - void ImportStructTypeData(MIRStructType *type); + void ImportStructTypeData(MIRStructType &type); void ImportInterfacesOfClassType(std::vector &interfaces); void ImportInfoIsStringOfClassType(std::vector &infoIsString); void ImportInfoOfClassType(std::vector &infoIsString, std::vector &infos); void ImportPragmaOfClassType(std::vector &pragmas); - void SetClassTyidxOfMethods(MIRStructType *type); - void ImportClassTypeData(MIRClassType *type); - void ImportInterfaceTypeData(MIRInterfaceType *type); + void SetClassTyidxOfMethods(MIRStructType &type); + void ImportClassTypeData(MIRClassType &type); + void ImportInterfaceTypeData(MIRInterfaceType &type); PUIdx ImportFunction(); MIRSymbol *InSymbol(MIRFunction *func); void InWord(int64 targetTag, uint8 **typeTagged, uint16 frameSize); diff --git a/src/maple_ir/include/bin_mplt.h b/src/maple_ir/include/bin_mplt.h index a4ad9271de37273c573ca2e2d4d7a14426ffa20a..50416d686801b10eb1551074706b2885d80cf54f 100644 --- a/src/maple_ir/include/bin_mplt.h +++ b/src/maple_ir/include/bin_mplt.h @@ -50,7 +50,7 @@ class BinaryMplt { return binExport; } - std::string &GetImportFileName() { + const std::string &GetImportFileName() const { return importFileName; } diff --git a/src/maple_ir/include/global_tables.h b/src/maple_ir/include/global_tables.h index efbc15f4d6bb2534a97e744de031dbd3a07a2115..2303c0d2f5da136c2a238a6696cdf5c4c4346c31 100644 --- a/src/maple_ir/include/global_tables.h +++ b/src/maple_ir/include/global_tables.h @@ -424,7 +424,7 @@ class STypeNameTable { return gStrIdxToTyIdxMap; } - TyIdx GetTyidxFromGstrIdx(GStrIdx idx) const { + TyIdx GetTyIdxFromGStrIdx(GStrIdx idx) const { auto it = gStrIdxToTyIdxMap.find(idx); if (it == gStrIdxToTyIdxMap.end()) { return TyIdx(0); diff --git a/src/maple_ir/include/lexer.h b/src/maple_ir/include/lexer.h index 99e929368832846a358d6f69b894aae6c7b940bd..fcd7ad3c28c72c98123d694a5c69cc4001fc025a 100644 --- a/src/maple_ir/include/lexer.h +++ b/src/maple_ir/include/lexer.h @@ -68,18 +68,7 @@ class MIRLexer { return theDoubleVal; } - MapleVector &GetSeenComments() { - return seenComments; - } - std::string GetTokenString() const; // for error reporting purpose - void SetFile(std::ifstream *file) { - airFile = file; - } - - std::ifstream *GetFile() const { - return airFile; - } private: MIRModule *module; @@ -145,6 +134,14 @@ class MIRLexer { curIdx++; return curIdx < currentLineSize ? line[curIdx] : 0; } + + void SetFile(std::ifstream *file) { + airFile = file; + } + + std::ifstream *GetFile() const { + return airFile; + } }; inline bool IsPrimitiveType(TokenKind tk) { diff --git a/src/maple_ir/include/mir_const.h b/src/maple_ir/include/mir_const.h index acd8a3730e0eb7aec51451f62858ef8dc88fae1d..bc99c91924619f76627e63e7b7c0140960925093 100644 --- a/src/maple_ir/include/mir_const.h +++ b/src/maple_ir/include/mir_const.h @@ -485,12 +485,10 @@ class MIRAggConst : public MIRConst { CHECK_FATAL(index < constVec.size(), "index out of range"); return constVec[index]; } - void SetConstVecItem(uint32 index, MIRConst *mirConst) { CHECK_FATAL(index < constVec.size(), "index out of range"); constVec[index] = mirConst; } - void PushBack(MIRConst *elem) { constVec.push_back(elem); } @@ -511,18 +509,24 @@ class MIRStConst : public MIRConst { SetKind(kConstStConst); } - MapleVector &GetStVec() { + const MapleVector &GetStVec() const { return stVec; } + void PushbackSt(MIRSymbol *sym) { + stVec.push_back(sym); + } - MIRSymbol *GetStVecItem(size_t index) { + const MIRSymbol *GetStVecItem(size_t index) const { CHECK_FATAL(index < stVec.size(), "array index out of range"); return stVec[index]; } - MapleVector &GetStOffsetVec() { + const MapleVector &GetStOffsetVec() const { return stOffsetVec; } + void PushbackStOffset(uint32 offset) { + stOffsetVec.push_back(offset); + } uint32 GetStOffsetVecItem(size_t index) const { CHECK_FATAL(index < stOffsetVec.size(), "array index out of range"); diff --git a/src/maple_ir/include/mir_function.h b/src/maple_ir/include/mir_function.h index 91e393c526f1d15de1d73316caf0df511cbf4f06..c3227c8c5fd5edd747b034f086d6b56a1a954d8b 100644 --- a/src/maple_ir/include/mir_function.h +++ b/src/maple_ir/include/mir_function.h @@ -197,9 +197,15 @@ class MIRFunction { return GlobalTables::GetTypeTable().GetTypeFromTyIdx(classTyIdx); } - TyIdx &GetClassTyidx() { + TyIdx GetClassTyIdx() const { return classTyIdx; } + void SetClassTyIdx(TyIdx tyIdx) { + classTyIdx = tyIdx; + } + void SetClassTyIdx(uint32 idx) { + classTyIdx.SetIdx(idx); + } void SetReturnTyIdx(TyIdx tyidx) { funcType->SetRetTyIdx(tyidx); @@ -297,11 +303,9 @@ class MIRFunction { funcAttrs.SetAttr(FUNCATTR_nothrow_exception); } } - bool GetAttr(FuncAttrKind x) const { return funcAttrs.GetAttr(x); } - void SetAttr(FuncAttrKind x) { funcAttrs.SetAttr(x); } @@ -572,9 +576,12 @@ class MIRFunction { puIdxOrigin = n; } - StIdx &GetStIdx() { + StIdx GetStIdx() const { return symbolTableIdx; } + void SetStIdx(StIdx stIdx) { + symbolTableIdx = stIdx; + } MIRFuncType *GetMIRFuncType() { @@ -586,13 +593,12 @@ class MIRFunction { } - void SetClassTyIdx(uint32 n) { - classTyIdx.SetIdx(n); - } - - MapleVector &GetArgumentsTyIdx() { + const MapleVector &GetArgumentsTyIdx() const { return argumentsTyIdx; } + void ClearArgumentsTyIdx() { + argumentsTyIdx.clear(); + } TyIdx GetArgumentsTyIdxItem(size_t n) const { ASSERT(n < argumentsTyIdx.size(), "array index out of range"); @@ -603,24 +609,21 @@ class MIRFunction { return argumentsTyIdx.size(); } - MapleVector &GetArgumentsAttrs() { + const MapleVector &GetArgumentsAttrs() const { return argumentsAttrs; } - - uint32 GetSymbolTabSize() const { - return symTab->GetSymbolTableSize(); + void ClearArgumentsAttrs() { + argumentsAttrs.clear(); } - MIRSymbol *GetSymbolTabItem(uint32 idx, bool checkfirst = false) const { - return symTab->GetSymbolFromStIdx(idx, checkfirst); + const MapleMap &GetGStrIdxToTyIdxMap() const { + return typeNameTab->GetGStrIdxToTyIdxMap(); } - - MIRTypeNameTable *GetTypeNameTable() { - return typeNameTab; + TyIdx GetTyIdxFromGStrIdx(GStrIdx idx) const { + return typeNameTab->GetTyIdxFromGStrIdx(idx); } - - void SetTypeNameTable(MIRTypeNameTable *tab) { - typeNameTab = tab; + void SetGStrIdxToTyIdx(GStrIdx gStrIdx, TyIdx tyIdx) { + typeNameTab->SetGStrIdxToTyIdx(gStrIdx, tyIdx); } const std::string &GetLabelTabItem(LabelIdx labidx) const { @@ -654,18 +657,19 @@ class MIRFunction { SrcPosition &GetSrcPosition() { return srcPosition; } - - void SetSrcPosition(SrcPosition &sp) { + void SetSrcPosition(const SrcPosition &sp) { srcPosition = sp; } - FuncAttrs &GetFuncAttrs() { + const FuncAttrs &GetFuncAttrs() const { return funcAttrs; } - - void SetFuncAttrs(FuncAttrs &fa) { + void SetFuncAttrs(const FuncAttrs &fa) { funcAttrs = fa; } + void SetFuncAttrs(uint64 attrFlag) { + funcAttrs.SetAttrFlag(attrFlag); + } uint32 GetFlag() { return flag; @@ -687,26 +691,26 @@ class MIRFunction { fileIndex = fi; } - MIRInfoVector &GetInfoVector() { - return info; - } - const MIRInfoVector &GetInfoVector() const { return info; } - - MapleVector &InfoIsString() { - return infoIsString; + void PushbackMIRInfo(const MIRInfoPair &pair) { + info.push_back(pair); + } + void SetMIRInfoNum(size_t idx, uint32 num) { + info[idx].second = num; } const MapleVector &InfoIsString() const { return infoIsString; } + void PushbackIsString(bool isString) { + infoIsString.push_back(isString); + } - MapleMap &GetAliasVarMap() { + const MapleMap &GetAliasVarMap() const { return aliasVarMap; } - void SetAliasVarMap(GStrIdx g, MIRAliasVars &a) { aliasVarMap[g] = a; } @@ -773,7 +777,7 @@ class MIRFunction { tempCount++; } - uint8 *GetFormalWordsTypeTagged() { + const uint8 *GetFormalWordsTypeTagged() const { return formalWordsTypeTagged; } @@ -785,10 +789,6 @@ class MIRFunction { formalWordsTypeTagged = fwt; } - uint8 *GetLocalWordsTypeTagged() { - return localWordsTypeTagged; - } - uint8 **GetLwtAddress() { return &localWordsTypeTagged; } @@ -801,10 +801,6 @@ class MIRFunction { localWordsTypeTagged = lwt; } - uint8 *GetFormalWordsRefCounted() { - return formalWordsRefCounted; - } - uint8 **GetFwrAddress() { return &formalWordsRefCounted; } @@ -817,14 +813,9 @@ class MIRFunction { formalWordsRefCounted = fwr; } - uint8 *GetLocalWordsRefCounted() { - return localWordsRefCounted; - } - const uint8 *GetLocalWordsRefCounted() const { return localWordsRefCounted; } - void SetLocalWordsRefCounted(uint8 *lwr) { localWordsRefCounted = lwr; } @@ -832,7 +823,6 @@ class MIRFunction { MeFunction *GetMeFunc() { return mefunc; } - void SetMeFunc(MeFunction *func) { mefunc = func; } @@ -840,19 +830,10 @@ class MIRFunction { EAConnectionGraph *GetEACG() { return eacg; } - void SetEACG(EAConnectionGraph *eacgVal) { eacg = eacgVal; } - TyIdx GetClassTyIdx() { - return classTyIdx; - } - - void SetClassTyIdx(TyIdx currTyIdx) { - classTyIdx = currTyIdx; - } - void SetFormals(MapleVector currFormals) { formals = currFormals; } @@ -879,18 +860,19 @@ class MIRFunction { formals.clear(); } + uint32 GetSymbolTabSize() const { + return symTab->GetSymbolTableSize(); + } + MIRSymbol *GetSymbolTabItem(uint32 idx, bool checkfirst = false) const { + return symTab->GetSymbolFromStIdx(idx, checkfirst); + } const MIRSymbolTable *GetSymTab() const { return symTab; } - MIRSymbolTable *GetSymTab() { return symTab; } - void SetSymTab(MIRSymbolTable *currSymTab) { - symTab = currSymTab; - } - const MIRLabelTable *GetLabelTab() const { return labelTab; } @@ -903,13 +885,12 @@ class MIRFunction { labelTab = currLabelTab; } - MIRPregTable *GetPregTab() const { - return pregTab; - } - - MapleSet &GetRetRefSym() { + const MapleSet &GetRetRefSym() const { return retRefSym; } + void InsertMIRSymbol(MIRSymbol *sym) { + retRefSym.insert(sym); + } MemPool *GetDataMemPool() { return dataMemPool; @@ -923,14 +904,6 @@ class MIRFunction { codeMemPool = currCodemp; } - MIRTypeNameTable *GetTypeNameTab() { - return typeNameTab; - } - - void SetTypeNameTab(MIRTypeNameTable *currTypeNameTab) { - typeNameTab = currTypeNameTab; - } - MapleAllocator &GetCodeMPAllocator() { return codeMemPoolAllocator; } diff --git a/src/maple_ir/include/mir_lower.h b/src/maple_ir/include/mir_lower.h index c055ce9371ae1f7df239e57f126e943fd849bd9d..45badc3bc79c8cf45a55bca39549f5fa68953c03 100644 --- a/src/maple_ir/include/mir_lower.h +++ b/src/maple_ir/include/mir_lower.h @@ -31,8 +31,8 @@ inline bool OpCodeNoFallThrough(const Opcode opCode) { opCode == OP_retsub; } -inline bool IfStmtNoFallThrough(const IfStmtNode *ifStmt) { - return OpCodeNoFallThrough(ifStmt->GetThenPart()->GetLast()->GetOpCode()); +inline bool IfStmtNoFallThrough(const IfStmtNode &ifStmt) { + return OpCodeNoFallThrough(ifStmt.GetThenPart()->GetLast()->GetOpCode()); } class MIRLower { @@ -40,7 +40,7 @@ class MIRLower { static const std::set kSetArrayHotFunc; public: - explicit MIRLower(MIRModule &mod, MIRFunction *f) : mirModule(mod), mirFunc(f), mirBuilder(nullptr), lowerPhase(0) {} + MIRLower(MIRModule &mod, MIRFunction *f) : mirModule(mod), mirFunc(f), mirBuilder(nullptr), lowerPhase(0) {} virtual ~MIRLower() {} @@ -52,21 +52,21 @@ class MIRLower { mirBuilder = mirModule.GetMemPool()->New(&mirModule); } - virtual BlockNode *LowerIfStmt(IfStmtNode *ifStmt, bool recursive); - virtual BlockNode *LowerWhileStmt(WhileStmtNode*); - BlockNode *LowerDowhileStmt(WhileStmtNode*); - BlockNode *LowerDoloopStmt(DoloopNode*); - BlockNode *LowerBlock(BlockNode*); - void LowerBrCondition(BlockNode *block); - void LowerFunc(MIRFunction *func); - void ExpandArrayMrt(MIRFunction *func); - static bool ShouldOptArrayMrt(const MIRFunction *func); - IfStmtNode *ExpandArrayMrtIfBlock(IfStmtNode *node); - WhileStmtNode *ExpandArrayMrtWhileBlock(WhileStmtNode *node); - DoloopNode *ExpandArrayMrtDoloopBlock(DoloopNode *node); - ForeachelemNode *ExpandArrayMrtForeachelemBlock(ForeachelemNode *node); - BlockNode *ExpandArrayMrtBlock(BlockNode *block); - void AddArrayMrtMpl(BaseNode *exp, BlockNode *newblk); + virtual BlockNode *LowerIfStmt(IfStmtNode &ifStmt, bool recursive); + virtual BlockNode *LowerWhileStmt(WhileStmtNode&); + BlockNode *LowerDowhileStmt(WhileStmtNode&); + BlockNode *LowerDoloopStmt(DoloopNode&); + BlockNode *LowerBlock(BlockNode&); + void LowerBrCondition(BlockNode &block); + void LowerFunc(MIRFunction &func); + void ExpandArrayMrt(MIRFunction &func); + static bool ShouldOptArrayMrt(const MIRFunction &func); + IfStmtNode *ExpandArrayMrtIfBlock(IfStmtNode &node); + WhileStmtNode *ExpandArrayMrtWhileBlock(WhileStmtNode &node); + DoloopNode *ExpandArrayMrtDoloopBlock(DoloopNode &node); + ForeachelemNode *ExpandArrayMrtForeachelemBlock(ForeachelemNode &node); + BlockNode *ExpandArrayMrtBlock(BlockNode &block); + void AddArrayMrtMpl(BaseNode &exp, BlockNode &newblk); void SetLowerME() { lowerPhase |= LOWERME; } diff --git a/src/maple_ir/include/mir_module.h b/src/maple_ir/include/mir_module.h index bb6053c6d152506be256844b8038a388b80b8ce1..ac010c0864b1154a98b12ceac4fd310968cfe591 100644 --- a/src/maple_ir/include/mir_module.h +++ b/src/maple_ir/include/mir_module.h @@ -84,11 +84,11 @@ class MIRTypeNameTable { ~MIRTypeNameTable() = default; - MapleMap &GetGStrIdxToTyIdxMap() { + const MapleMap &GetGStrIdxToTyIdxMap() const { return gStrIdxToTyIdxMap; } - TyIdx GetTyIdxFromGStrIdx(GStrIdx idx) { + TyIdx GetTyIdxFromGStrIdx(GStrIdx idx) const { auto it = gStrIdxToTyIdxMap.find(idx); if (it == gStrIdxToTyIdxMap.end()) { return TyIdx(0); diff --git a/src/maple_ir/src/bin_mpl_export.cpp b/src/maple_ir/src/bin_mpl_export.cpp index 39ff2bec09954752950fe9763582cb2237289d57..6782775b48304e975e9754297423f2845346628f 100644 --- a/src/maple_ir/src/bin_mpl_export.cpp +++ b/src/maple_ir/src/bin_mpl_export.cpp @@ -31,13 +31,13 @@ using OutputTypeFactory = FunctionFactoryWriteNum(kBinKindConstInt); - mplExport->OutputConstBase(constVal); + mplExport->OutputConstBase(*constVal); mplExport->WriteNum(static_cast(constVal)->GetValue()); } void OutputConstAddrof(MIRConst *constVal, BinaryMplExport *mplExport) { mplExport->WriteNum(kBinKindConstAddrof); - mplExport->OutputConstBase(constVal); + mplExport->OutputConstBase(*constVal); MIRAddrofConst *addrof = static_cast(constVal); mplExport->OutputSymbol(mplExport->GetMIRModule().CurFunction()->GetLocalOrGlobalSymbol(addrof->GetSymbolIndex())); mplExport->WriteNum(addrof->GetFieldID()); @@ -45,7 +45,7 @@ void OutputConstAddrof(MIRConst *constVal, BinaryMplExport *mplExport) { void OutputConstAddrofFunc(MIRConst *constVal, BinaryMplExport *mplExport) { mplExport->WriteNum(kBinKindConstAddrofFunc); - mplExport->OutputConstBase(constVal); + mplExport->OutputConstBase(*constVal); MIRAddroffuncConst *addrfunc = static_cast(constVal); mplExport->OutputFunction(addrfunc->GetValue()); } @@ -56,14 +56,14 @@ void OutputConstLbl(MIRConst *constVal, BinaryMplExport *mplExport) { void OutputConstStr(MIRConst *constVal, BinaryMplExport *mplExport) { mplExport->WriteNum(kBinKindConstStr); - mplExport->OutputConstBase(constVal); + mplExport->OutputConstBase(*constVal); MIRStrConst *strc = static_cast(constVal); mplExport->OutputUsrStr(strc->GetValue()); } void OutputConstStr16(MIRConst *constVal, BinaryMplExport *mplExport) { mplExport->WriteNum(kBinKindConstStr16); - mplExport->OutputConstBase(constVal); + mplExport->OutputConstBase(*constVal); MIRStr16Const *mirStr16 = static_cast(constVal); std::u16string str16 = GlobalTables::GetU16StrTable().GetStringFromStrIdx(mirStr16->GetValue()); std::string str; @@ -88,7 +88,7 @@ void OutputConstDouble(MIRConst *constVal, BinaryMplExport *mplExport) { void OutputConstAgg(MIRConst *constVal, BinaryMplExport *mplExport) { mplExport->WriteNum(kBinKindConstAgg); - mplExport->OutputConstBase(constVal); + mplExport->OutputConstBase(*constVal); MIRAggConst *aggConst = static_cast(constVal); size_t size = aggConst->GetConstVec().size(); mplExport->WriteNum(size); @@ -99,7 +99,7 @@ void OutputConstAgg(MIRConst *constVal, BinaryMplExport *mplExport) { void OutputConstSt(MIRConst *constVal, BinaryMplExport *mplExport) { mplExport->WriteNum(kBinKindConstSt); - mplExport->OutputConstBase(constVal); + mplExport->OutputConstBase(*constVal); MIRStConst *stConst = static_cast(constVal); size_t size = stConst->GetStVec().size(); mplExport->WriteNum(size); @@ -128,40 +128,40 @@ void InitOutputConstFactory() { void OutputTypeScalar(MIRType *ty, BinaryMplExport *mplExport) { mplExport->WriteNum(kBinKindTypeScalar); - mplExport->OutputTypeBase(ty); + mplExport->OutputTypeBase(*ty); } void OutputTypePointer(MIRType *ty, BinaryMplExport *mplExport) { MIRPtrType *type = static_cast(ty); mplExport->WriteNum(kBinKindTypePointer); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); mplExport->OutputType(type->GetPointedTyIdx()); } void OutputTypeByName(MIRType *ty, BinaryMplExport *mplExport) { MIRTypeByName *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeByName); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); } void OutputTypeFArray(MIRType *ty, BinaryMplExport *mplExport) { MIRFarrayType *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeFArray); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); mplExport->OutputType(type->GetElemTyIdx()); } void OutputTypeJArray(MIRType *ty, BinaryMplExport *mplExport) { MIRJarrayType *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeJarray); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); mplExport->OutputType(type->GetElemTyIdx()); } void OutputTypeArray(MIRType *ty, BinaryMplExport *mplExport) { MIRArrayType *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeArray); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); mplExport->WriteNum(type->GetDim()); for (int i = 0; i < type->GetDim(); i++) { mplExport->WriteNum(type->GetSizeArrayItem(i)); @@ -172,7 +172,7 @@ void OutputTypeArray(MIRType *ty, BinaryMplExport *mplExport) { void OutputTypeFunction(MIRType *ty, BinaryMplExport *mplExport) { MIRFuncType *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeFunction); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); mplExport->OutputType(type->GetRetTyIdx()); mplExport->WriteNum(type->IsVarargs()); size_t size = type->GetParamTypeList().size(); @@ -190,29 +190,29 @@ void OutputTypeFunction(MIRType *ty, BinaryMplExport *mplExport) { void OutputTypeParam(MIRType *ty, BinaryMplExport *mplExport) { MIRTypeParam *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeParam); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); } void OutputTypeInstantVector(MIRType *ty, BinaryMplExport *mplExport) { MIRInstantVectorType *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeInstantVector); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); mplExport->WriteNum(ty->GetKind()); - mplExport->OutputTypePairs(type); + mplExport->OutputTypePairs(*type); } void OutputTypeGenericInstant(MIRType *ty, BinaryMplExport *mplExport) { MIRGenericInstantType *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeGenericInstant); - mplExport->OutputTypeBase(type); - mplExport->OutputTypePairs(type); + mplExport->OutputTypeBase(*type); + mplExport->OutputTypePairs(*type); mplExport->OutputType(type->GetGenericTyIdx()); } void OutputTypeBitField(MIRType *ty, BinaryMplExport *mplExport) { MIRBitFieldType *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeBitField); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); mplExport->WriteNum(type->GetFieldSize()); } @@ -220,7 +220,7 @@ void OutputTypeBitField(MIRType *ty, BinaryMplExport *mplExport) { void OutputTypeStruct(MIRType *ty, BinaryMplExport *mplExport) { MIRStructType *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeStruct); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); MIRTypeKind kind = ty->GetKind(); if (type->IsImported()) { CHECK_FATAL(ty->GetKind() != kTypeUnion, "must be"); @@ -235,7 +235,7 @@ void OutputTypeStruct(MIRType *ty, BinaryMplExport *mplExport) { void OutputTypeClass(MIRType *ty, BinaryMplExport *mplExport) { MIRClassType *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeClass); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); MIRTypeKind kind = ty->GetKind(); if (type->IsImported()) { kind = kTypeClassIncomplete; @@ -250,7 +250,7 @@ void OutputTypeClass(MIRType *ty, BinaryMplExport *mplExport) { void OutputTypeInterface(MIRType *ty, BinaryMplExport *mplExport) { MIRInterfaceType *type = static_cast(ty); mplExport->WriteNum(kBinKindTypeInterface); - mplExport->OutputTypeBase(type); + mplExport->OutputTypeBase(*type); MIRTypeKind kind = ty->GetKind(); if (type->IsImported()) { kind = kTypeInterfaceIncomplete; @@ -372,10 +372,10 @@ void BinaryMplExport::DumpBuf(const std::string &name) { } } -void BinaryMplExport::OutputConstBase(const MIRConst *constVal) { - WriteNum(constVal->GetKind()); - OutputType(constVal->GetType()->GetTypeIndex()); - WriteNum(constVal->GetFieldId()); +void BinaryMplExport::OutputConstBase(const MIRConst &constVal) { + WriteNum(constVal.GetKind()); + OutputType(constVal.GetType()->GetTypeIndex()); + WriteNum(constVal.GetFieldId()); } void BinaryMplExport::OutputConst(MIRConst *constVal) { @@ -426,22 +426,21 @@ void BinaryMplExport::OutputUsrStr(UStrIdx ustr) { WriteAsciiStr(GlobalTables::GetUStrTable().GetStringFromStrIdx(ustr)); } -void BinaryMplExport::OutputPragmaElement(const MIRPragmaElement *e) { - ASSERT(e != nullptr, "MIRPragmaElement is null."); - OutputStr(e->GetNameStrIdx()); - OutputStr(e->GetTypeStrIdx()); - WriteNum(e->GetType()); +void BinaryMplExport::OutputPragmaElement(const MIRPragmaElement &e) { + OutputStr(e.GetNameStrIdx()); + OutputStr(e.GetTypeStrIdx()); + WriteNum(e.GetType()); - if (e->GetType() == kValueString || e->GetType() == kValueType || e->GetType() == kValueField || - e->GetType() == kValueMethod || e->GetType() == kValueEnum) { - OutputStr(GStrIdx(e->GetI32Val())); + if (e.GetType() == kValueString || e.GetType() == kValueType || e.GetType() == kValueField || + e.GetType() == kValueMethod || e.GetType() == kValueEnum) { + OutputStr(GStrIdx(e.GetI32Val())); } else { - WriteInt64(e->GetU64Val()); + WriteInt64(e.GetU64Val()); } - size_t size = e->GetSubElemVec().size(); + size_t size = e.GetSubElemVec().size(); WriteNum(size); for (size_t i = 0; i < size; i++) { - OutputPragmaElement(e->GetSubElement(i)); + OutputPragmaElement(*(e.GetSubElement(i))); } } @@ -456,15 +455,14 @@ void BinaryMplExport::OutputPragma(const MIRPragma *p) { size_t size = p->GetElementVector().size(); WriteNum(size); for (size_t i = 0; i < size; i++) { - OutputPragmaElement(p->GetNthElement(i)); + OutputPragmaElement(*(p->GetNthElement(i))); } } -void BinaryMplExport::OutputTypeBase(const MIRType *type) { - ASSERT(type != nullptr, "MIRType is null."); - WriteNum(type->GetPrimType()); - OutputStr(type->GetNameStrIdx()); - WriteNum(type->IsNameIsLocal()); +void BinaryMplExport::OutputTypeBase(const MIRType &type) { + WriteNum(type.GetPrimType()); + OutputStr(type.GetNameStrIdx()); + WriteNum(type.IsNameIsLocal()); } void BinaryMplExport::OutputFieldPair(const FieldPair &fp) { @@ -578,7 +576,7 @@ void BinaryMplExport::Init() { } } -void BinaryMplExport::OutputSymbol(MIRSymbol *sym) { +void BinaryMplExport::OutputSymbol(const MIRSymbol *sym) { if (sym == nullptr) { WriteNum(0); return; @@ -678,8 +676,7 @@ void BinaryMplExport::WriteTypeField(uint64 contentIdx) { } -void BinaryMplExport::WriteContentField(int fieldNum, uint64 *fieldStartP) { - ASSERT(fieldStartP != nullptr, "fieldStartP is null."); +void BinaryMplExport::WriteContentField(int fieldNum, uint64 &fieldStartP) { WriteNum(kBinContentStart); size_t totalSizeIdx = buf.size(); ExpandFourBuffSize(); // total size of this field to ~BIN_SYM_START @@ -687,15 +684,15 @@ void BinaryMplExport::WriteContentField(int fieldNum, uint64 *fieldStartP) { WriteInt(fieldNum); // size of Content item WriteNum(kBinStrStart); - fieldStartP[0] = buf.size(); + (&fieldStartP)[0] = buf.size(); ExpandFourBuffSize(); WriteNum(kBinTypeStart); - fieldStartP[1] = buf.size(); + (&fieldStartP)[1] = buf.size(); ExpandFourBuffSize(); WriteNum(kBinCgStart); - fieldStartP[2] = buf.size(); + (&fieldStartP)[2] = buf.size(); ExpandFourBuffSize(); Fixup(totalSizeIdx, buf.size() - totalSizeIdx); @@ -706,7 +703,7 @@ void BinaryMplExport::Export(const std::string &fname) { constexpr int kFieldNum = 3; uint64 fieldStartPoint[kFieldNum]; WriteInt(kMpltMagicNumber); - WriteContentField(kFieldNum, fieldStartPoint); + WriteContentField(kFieldNum, *fieldStartPoint); WriteStrField(fieldStartPoint[0]); WriteTypeField(fieldStartPoint[1]); WriteNum(kBinFinish); @@ -730,10 +727,10 @@ void BinaryMplExport::AppendAt(const std::string &name, int32 offset) { } } -void BinaryMplExport::OutputTypePairs(MIRInstantVectorType *type) { - size_t size = type->GetInstantVec().size(); +void BinaryMplExport::OutputTypePairs(MIRInstantVectorType &type) { + size_t size = type.GetInstantVec().size(); WriteNum(size); - for (TypePair &tpair : type->GetInstantVec()) { + for (TypePair &tpair : type.GetInstantVec()) { OutputType(tpair.first); OutputType(tpair.second); } diff --git a/src/maple_ir/src/bin_mpl_import.cpp b/src/maple_ir/src/bin_mpl_import.cpp index ec5392209208bf771bf697b3ef1302c912e0ee81..1bc76bea45c0a0937a641438f093f66e97aa3226 100644 --- a/src/maple_ir/src/bin_mpl_import.cpp +++ b/src/maple_ir/src/bin_mpl_import.cpp @@ -169,11 +169,11 @@ MIRConst *BinaryMplImport::ImportConst(MIRFunction *func) { MIRStConst *stConst = mod.GetMemPool()->New(&mod, type); int64 size = ReadNum(); for (int64 i = 0; i < size; i++) { - stConst->GetStVec().push_back(InSymbol(func)); + stConst->PushbackSt(InSymbol(func)); } size = ReadNum(); for (int64 i = 0; i < size; i++) { - stConst->GetStOffsetVec().push_back(ReadNum()); + stConst->PushbackStOffset(ReadNum()); } return stConst; } else { @@ -295,11 +295,11 @@ void BinaryMplImport::ImportMethodPair(MethodPair &memPool) { fn->SetPuidx(GlobalTables::GetFunctionTable().GetFuncTable().size()); GlobalTables::GetFunctionTable().GetFuncTable().push_back(fn); funcSt->SetFunction(fn); - MIRFuncType *funcType = dynamic_cast(funcSt->GetType()); + MIRFuncType *funcType = static_cast(funcSt->GetType()); fn->SetMIRFuncType(funcType); fn->SetFileIndex(0); fn->SetBaseClassFuncNames(funcSt->GetNameStrIdx()); - fn->GetFuncAttrs().SetAttrFlag(attrFlag); + fn->SetFuncAttrs(attrFlag); } memPool.first.SetFullIdx(funcSt->GetStIdx().FullIdx()); memPool.second.first.SetIdx(funcTyidx.GetIdx()); @@ -340,13 +340,13 @@ void BinaryMplImport::ImportMethodsOfStructType(MethodVector &methods) { } } -void BinaryMplImport::ImportStructTypeData(MIRStructType *type) { - uint32 methodSize = type->GetMethods().size(); - ImportFieldsOfStructType(type->GetFields(), methodSize); - ImportFieldsOfStructType(type->GetStaticFields(), methodSize); - ImportFieldsOfStructType(type->GetParentFields(), methodSize); - ImportMethodsOfStructType(type->GetMethods()); - type->SetIsImported(imported); +void BinaryMplImport::ImportStructTypeData(MIRStructType &type) { + uint32 methodSize = type.GetMethods().size(); + ImportFieldsOfStructType(type.GetFields(), methodSize); + ImportFieldsOfStructType(type.GetStaticFields(), methodSize); + ImportFieldsOfStructType(type.GetParentFields(), methodSize); + ImportMethodsOfStructType(type.GetMethods()); + type.SetIsImported(imported); } void BinaryMplImport::ImportInterfacesOfClassType(std::vector &interfaces) { @@ -398,37 +398,37 @@ void BinaryMplImport::ImportPragmaOfClassType(std::vector &pragmas) } } -void BinaryMplImport::SetClassTyidxOfMethods(MIRStructType *type) { - if (type->GetTypeIndex() != 0) { +void BinaryMplImport::SetClassTyidxOfMethods(MIRStructType &type) { + if (type.GetTypeIndex() != 0) { // set up classTyIdx for methods - for (size_t i = 0; i < type->GetMethods().size(); i++) { - StIdx stidx = type->GetMethodsElement(i).first; + for (size_t i = 0; i < type.GetMethods().size(); i++) { + StIdx stidx = type.GetMethodsElement(i).first; MIRSymbol *st = GlobalTables::GetGsymTable().GetSymbolFromStidx(stidx.Idx()); CHECK_FATAL(st != nullptr, "st is null"); CHECK_FATAL(st->GetSKind() == kStFunc, "unexpected st->sKind"); - st->GetFunction()->SetClassTyIdx(type->GetTypeIndex()); + st->GetFunction()->SetClassTyIdx(type.GetTypeIndex()); } } } -void BinaryMplImport::ImportClassTypeData(MIRClassType *type) { +void BinaryMplImport::ImportClassTypeData(MIRClassType &type) { TyIdx tempType = ImportType(); // Keep the parent_tyidx we first met. - if (type->GetParentTyIdx().GetIdx() == 0) { - type->GetParentTyIdx() = tempType; + if (type.GetParentTyIdx().GetIdx() == 0) { + type.GetParentTyIdx() = tempType; } - ImportInterfacesOfClassType(type->GetInerfaceImplemented()); - ImportInfoIsStringOfClassType(type->GetInfoIsString()); - ImportInfoOfClassType(type->GetInfoIsString(), type->GetInfo()); - ImportPragmaOfClassType(type->GetPragmVec()); + ImportInterfacesOfClassType(type.GetInerfaceImplemented()); + ImportInfoIsStringOfClassType(type.GetInfoIsString()); + ImportInfoOfClassType(type.GetInfoIsString(), type.GetInfo()); + ImportPragmaOfClassType(type.GetPragmVec()); SetClassTyidxOfMethods(type); } -void BinaryMplImport::ImportInterfaceTypeData(MIRInterfaceType *type) { - ImportInterfacesOfClassType(type->GetParentsTyIdx()); - ImportInfoIsStringOfClassType(type->GetInfoIsString()); - ImportInfoOfClassType(type->GetInfoIsString(), type->GetInfo()); - ImportPragmaOfClassType(type->GetPragmVec()); +void BinaryMplImport::ImportInterfaceTypeData(MIRInterfaceType &type) { + ImportInterfacesOfClassType(type.GetParentsTyIdx()); + ImportInfoIsStringOfClassType(type.GetInfoIsString()); + ImportInfoOfClassType(type.GetInfoIsString(), type.GetInfo()); + ImportPragmaOfClassType(type.GetPragmVec()); SetClassTyidxOfMethods(type); } @@ -474,15 +474,15 @@ void BinaryMplImport::completeAggInfo(TyIdx tyIdx) { CHECK_FATAL(type != nullptr, "MIRType is null"); if (type->GetKind() == kTypeInterface) { MIRInterfaceType *interfaceType = static_cast(type); - ImportStructTypeData(interfaceType); - ImportInterfaceTypeData(interfaceType); + ImportStructTypeData(*interfaceType); + ImportInterfaceTypeData(*interfaceType); } else if (type->GetKind() == kTypeClass) { MIRClassType *classType = static_cast(type); - ImportStructTypeData(classType); - ImportClassTypeData(classType); + ImportStructTypeData(*classType); + ImportClassTypeData(*classType); } else if (type->GetKind() == kTypeStruct) { MIRStructType *structType = static_cast(type); - ImportStructTypeData(structType); + ImportStructTypeData(*structType); } else { ERR(kLncErr, "in BinaryMplImport::completeAggInfo, MIRType error"); } @@ -512,7 +512,7 @@ TyIdx BinaryMplImport::ImportType(bool forPointedType) { ++ptrLev; type.SetPointedTyIdx(ImportType(true)); --ptrLev; - MIRType *origType = InsertInTypeTables(&type); + MIRType *origType = &InsertInTypeTables(type); typTab[idx] = origType; if (typeNeedsComplete != nullptr && ptrLev == 0) { TyIdx tyIdxNeedsComplete = typeNeedsComplete->GetTypeIndex(); @@ -523,7 +523,7 @@ TyIdx BinaryMplImport::ImportType(bool forPointedType) { } else if (tag == kBinKindTypeByName) { MIRTypeByName type(strIdx); type.SetNameIsLocal(nameIsLocal); - MIRType *origType = InsertInTypeTables(&type); + MIRType *origType = &InsertInTypeTables(type); typTab.push_back(origType); return origType->GetTypeIndex(); } else if (tag == kBinKindTypeFArray) { @@ -532,7 +532,7 @@ TyIdx BinaryMplImport::ImportType(bool forPointedType) { size_t idx = typTab.size(); typTab.push_back(nullptr); type.SetElemtTyIdx(ImportType(forPointedType)); - MIRType *origType = InsertInTypeTables(&type); + MIRType *origType = &InsertInTypeTables(type); typTab[idx] = origType; return origType->GetTypeIndex(); } else if (tag == kBinKindTypeJarray) { @@ -541,7 +541,7 @@ TyIdx BinaryMplImport::ImportType(bool forPointedType) { size_t idx = typTab.size(); typTab.push_back(nullptr); type.SetElemtTyIdx(ImportType(forPointedType)); - MIRType *origType = InsertInTypeTables(&type); + MIRType *origType = &InsertInTypeTables(type); typTab[idx] = origType; return origType->GetTypeIndex(); } else if (tag == kBinKindTypeArray) { @@ -555,7 +555,7 @@ TyIdx BinaryMplImport::ImportType(bool forPointedType) { size_t idx = typTab.size(); typTab.push_back(nullptr); type.SetElemtTyIdx(ImportType(forPointedType)); - MIRType *origType = InsertInTypeTables(&type); + MIRType *origType = &InsertInTypeTables(type); typTab[idx] = origType; return origType->GetTypeIndex(); } else if (tag == kBinKindTypeFunction) { @@ -573,27 +573,27 @@ TyIdx BinaryMplImport::ImportType(bool forPointedType) { for (int64 i = 0; i < size; i++) { type.GetParamAttrsList().push_back(ImportTypeAttrs()); } - MIRType *origType = InsertInTypeTables(&type); + MIRType *origType = &InsertInTypeTables(type); typTab[idx] = origType; return origType->GetTypeIndex(); } else if (tag == kBinKindTypeParam) { MIRTypeParam type(strIdx); type.SetNameIsLocal(nameIsLocal); - MIRType *origType = InsertInTypeTables(&type); + MIRType *origType = &InsertInTypeTables(type); typTab.push_back(origType); return origType->GetTypeIndex(); } else if (tag == kBinKindTypeInstantVector) { MIRTypeKind kind = (MIRTypeKind)ReadNum(); MIRInstantVectorType type(kind, strIdx); type.SetNameIsLocal(nameIsLocal); - MIRInstantVectorType *origType = static_cast(InsertInTypeTables(&type)); + MIRInstantVectorType *origType = static_cast(&InsertInTypeTables(type)); typTab.push_back(origType); ImportTypePairs(origType->GetInstantVec()); return origType->GetTypeIndex(); } else if (tag == kBinKindTypeGenericInstant) { MIRGenericInstantType type(strIdx); type.SetNameIsLocal(nameIsLocal); - MIRGenericInstantType *origType = static_cast(InsertInTypeTables(&type)); + MIRGenericInstantType *origType = static_cast(&InsertInTypeTables(type)); typTab.push_back(origType); ImportTypePairs(origType->GetInstantVec()); origType->SetGenericTyIdx(ImportType()); @@ -602,53 +602,53 @@ TyIdx BinaryMplImport::ImportType(bool forPointedType) { uint8 fieldSize = ReadNum(); MIRBitFieldType type(fieldSize, primType, strIdx); type.SetNameIsLocal(nameIsLocal); - MIRType *origType = InsertInTypeTables(&type); + MIRType *origType = &InsertInTypeTables(type); typTab.push_back(origType); return origType->GetTypeIndex(); } else if (tag == kBinKindTypeStruct) { MIRTypeKind kind = (MIRTypeKind)ReadNum(); MIRStructType type(kind, strIdx); type.SetNameIsLocal(nameIsLocal); - MIRStructType *origType = static_cast(InsertInTypeTables(&type)); - typTab.push_back(origType); + MIRStructType &origType = static_cast(InsertInTypeTables(type)); + typTab.push_back(&origType); if (kind != kTypeStructIncomplete) { if (forPointedType) { - typeNeedsComplete = origType; + typeNeedsComplete = &origType; } else { ImportStructTypeData(origType); } } - return origType->GetTypeIndex(); + return origType.GetTypeIndex(); } else if (tag == kBinKindTypeClass) { MIRTypeKind kind = (MIRTypeKind)ReadNum(); MIRClassType type(kind, strIdx); type.SetNameIsLocal(nameIsLocal); - MIRClassType *origType = static_cast(InsertInTypeTables(&type)); - typTab.push_back(origType); + MIRClassType &origType = static_cast(InsertInTypeTables(type)); + typTab.push_back(&origType); if (kind != kTypeClassIncomplete) { if (forPointedType) { - typeNeedsComplete = origType; + typeNeedsComplete = &origType; } else { ImportStructTypeData(origType); ImportClassTypeData(origType); } } - return origType->GetTypeIndex(); + return origType.GetTypeIndex(); } else if (tag == kBinKindTypeInterface) { MIRTypeKind kind = (MIRTypeKind)ReadNum(); MIRInterfaceType type(kind, strIdx); type.SetNameIsLocal(nameIsLocal); - MIRInterfaceType *origType = static_cast(InsertInTypeTables(&type)); - typTab.push_back(origType); + MIRInterfaceType &origType = static_cast(InsertInTypeTables(type)); + typTab.push_back(&origType); if (kind != kTypeInterfaceIncomplete) { if (forPointedType) { - typeNeedsComplete = origType; + typeNeedsComplete = &origType; } else { ImportStructTypeData(origType); ImportInterfaceTypeData(origType); } } - return origType->GetTypeIndex(); + return origType.GetTypeIndex(); } else { ASSERT(false, "Unexpected binary kind"); } @@ -661,64 +661,60 @@ void BinaryMplImport::ImportTypeBase(PrimType &primType, GStrIdx &strIdx, bool & nameIsLocal = ReadNum(); } -inline static bool IsIncomplete(const MIRType *type) { - ASSERT(type != nullptr, "MIRType is null"); - return (type->GetKind() == kTypeInterfaceIncomplete || type->GetKind() == kTypeClassIncomplete || - type->GetKind() == kTypeStructIncomplete); +inline static bool IsIncomplete(const MIRType &type) { + return (type.GetKind() == kTypeInterfaceIncomplete || type.GetKind() == kTypeClassIncomplete || + type.GetKind() == kTypeStructIncomplete); } -inline static bool IsObject(const MIRType *type) { - ASSERT(type != nullptr, "MIRType is null"); - return (type->GetKind() == kTypeClass || type->GetKind() == kTypeClassIncomplete || - type->GetKind() == kTypeInterface || type->GetKind() == kTypeInterfaceIncomplete); +inline static bool IsObject(const MIRType &type) { + return (type.GetKind() == kTypeClass || type.GetKind() == kTypeClassIncomplete || + type.GetKind() == kTypeInterface || type.GetKind() == kTypeInterfaceIncomplete); } -MIRType *BinaryMplImport::InsertInTypeTables(MIRType *type) { - ASSERT(type != nullptr, "null ptr check"); - TyIdx prevTyIdx = mod.GetTypeNameTab()->GetTyIdxFromGStrIdx(type->GetNameStrIdx()); - if (prevTyIdx != 0 && !type->IsNameIsLocal()) { +MIRType &BinaryMplImport::InsertInTypeTables(MIRType &type) { + MIRType *resultTypePtr = &type; + TyIdx prevTyIdx = mod.GetTypeNameTab()->GetTyIdxFromGStrIdx(type.GetNameStrIdx()); + if (prevTyIdx != 0 && !type.IsNameIsLocal()) { MIRType *prevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(prevTyIdx); - if ((IsIncomplete(prevType) && IsIncomplete(type)) || (!IsIncomplete(prevType) && !IsIncomplete(type)) || - (!IsIncomplete(prevType) && IsIncomplete(type))) { - ASSERT(IsObject(prevType) && IsObject(type), "impossible"); - type = prevType->CopyMIRTypeNode(); - if (type->GetKind() == kTypeStruct || type->GetKind() == kTypeStructIncomplete) { - tmpStruct.push_back(static_cast(type)); - } else if (type->GetKind() == kTypeClass || type->GetKind() == kTypeClassIncomplete) { - tmpClass.push_back(static_cast(type)); - } else if (type->GetKind() == kTypeInterface || type->GetKind() == kTypeInterfaceIncomplete) { - tmpInterface.push_back(static_cast(type)); + if ((IsIncomplete(*prevType) && IsIncomplete(type)) || (!IsIncomplete(*prevType) && !IsIncomplete(type)) || + (!IsIncomplete(*prevType) && IsIncomplete(type))) { + resultTypePtr = prevType->CopyMIRTypeNode(); + if (resultTypePtr->GetKind() == kTypeStruct || resultTypePtr->GetKind() == kTypeStructIncomplete) { + tmpStruct.push_back(static_cast(resultTypePtr)); + } else if (resultTypePtr->GetKind() == kTypeClass || resultTypePtr->GetKind() == kTypeClassIncomplete) { + tmpClass.push_back(static_cast(resultTypePtr)); + } else if (resultTypePtr->GetKind() == kTypeInterface || resultTypePtr->GetKind() == kTypeInterfaceIncomplete) { + tmpInterface.push_back(static_cast(resultTypePtr)); } } else { - ASSERT(IsObject(prevType) && IsObject(type), "impossible"); // New definition wins - type->GetTypeIndex() = prevTyIdx; + type.SetTypeIndex(prevTyIdx); ASSERT(GlobalTables::GetTypeTable().GetTypeTable().empty() == false, "container check"); - GlobalTables::GetTypeTable().SetTypeWithTyIdx(prevTyIdx, type->CopyMIRTypeNode()); - type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(prevTyIdx); - if (!IsIncomplete(type)) { - GlobalTables::GetTypeNameTable().SetGStrIdxToTyIdx(type->GetNameStrIdx(), type->GetTypeIndex()); + GlobalTables::GetTypeTable().SetTypeWithTyIdx(prevTyIdx, type.CopyMIRTypeNode()); + resultTypePtr = GlobalTables::GetTypeTable().GetTypeFromTyIdx(prevTyIdx); + if (!IsIncomplete(*resultTypePtr)) { + GlobalTables::GetTypeNameTable().SetGStrIdxToTyIdx(resultTypePtr->GetNameStrIdx(), resultTypePtr->GetTypeIndex()); } } } else { // New type, no previous definition or anonymous type - TyIdx tyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(type); - type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); - if (tyIdx.GetIdx() + 1 == GlobalTables::GetTypeTable().GetTypeTable().size() && !type->IsNameIsLocal()) { - GStrIdx stridx = type->GetNameStrIdx(); - if (IsObject(type)) { + TyIdx tyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&type); + resultTypePtr = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); + if (tyIdx.GetIdx() + 1 == GlobalTables::GetTypeTable().GetTypeTable().size() && !resultTypePtr->IsNameIsLocal()) { + GStrIdx stridx = resultTypePtr->GetNameStrIdx(); + if (IsObject(*resultTypePtr)) { mod.GetTypeNameTab()->SetGStrIdxToTyIdx(stridx, tyIdx); mod.AddClass(tyIdx); mod.GetTypeDefOrder().push_back(stridx); - if (!IsIncomplete(type)) { + if (!IsIncomplete(*resultTypePtr)) { GlobalTables::GetTypeNameTable().SetGStrIdxToTyIdx(stridx, tyIdx); } - } else if (type->GetKind() == kTypeByName) { + } else if (resultTypePtr->GetKind() == kTypeByName) { mod.GetTypeNameTab()->SetGStrIdxToTyIdx(stridx, tyIdx); } } } - return type; + return *resultTypePtr; } void BinaryMplImport::SetupEHRootType() { @@ -728,7 +724,7 @@ void BinaryMplImport::SetupEHRootType() { return; } - TyIdx tyIdx = GlobalTables::GetTypeNameTable().GetTyidxFromGstrIdx(gStrIdx); + TyIdx tyIdx = GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(gStrIdx); if (tyIdx != 0) { mod.SetThrowableTyIdx(tyIdx); } @@ -804,8 +800,8 @@ PUIdx BinaryMplImport::ImportFunction() { TyIdx retType = ImportType(); func->SetReturnTyIdx(retType); - func->GetStIdx() = funcSt->GetStIdx(); - func->GetFuncAttrs().SetAttrFlag(ReadNum()); + func->SetStIdx(funcSt->GetStIdx()); + func->SetFuncAttrs(ReadNum()); func->SetFlag(ReadNum()); func->SetClassTyIdx(ImportType()); return func->GetPuidx(); diff --git a/src/maple_ir/src/driver.cpp b/src/maple_ir/src/driver.cpp index c4c23b62b2daa7eee1c25742d879898b4c5a3aa9..dc419978344303aa5b9fc998c54d540583a94df7 100644 --- a/src/maple_ir/src/driver.cpp +++ b/src/maple_ir/src/driver.cpp @@ -23,16 +23,17 @@ using namespace maple; #if MIR_FEATURE_FULL -void ConstantFoldModule(maple::MIRModule *module) { - MapleVector &funcList = module->GetFunctionList(); +void ConstantFoldModule(maple::MIRModule &module) { + MapleVector &funcList = module.GetFunctionList(); for (auto it = funcList.begin(); it != funcList.end(); it++) { maple::MIRFunction *curfun = *it; - module->SetCurFunction(curfun); + module.SetCurFunction(curfun); } } int main(int argc, char **argv) { - if (argc < 2) { + constexpr int judgeNumber = 2; + if (argc < judgeNumber) { MIR_PRINTF( "usage: ./irbuild [i|e] \n\n" "The optional 'i' flag will convert the binary mplt input file to ascii\n\n" @@ -43,17 +44,17 @@ int main(int argc, char **argv) { maple::int32 i = 1; if (argv[1][0] == 'i' && argv[1][1] == '\0') { flag = 'i'; - i = 2; + i = judgeNumber; } else if (argv[1][0] == 'e' && argv[1][1] == '\0') { flag = 'e'; - i = 2; + i = judgeNumber; } while (i < argc) { maple::MIRModule module{ argv[i] }; if (flag == '\0') { maple::MIRParser theparser(module); if (theparser.ParseMIR()) { - ConstantFoldModule(&module); + ConstantFoldModule(module); module.OutputAsciiMpl(".irb"); } else { theparser.EmitError(module.GetFileName().c_str()); @@ -62,7 +63,7 @@ int main(int argc, char **argv) { } else if (flag == 'e') { maple::MIRParser theparser(module); if (theparser.ParseMIR()) { - ConstantFoldModule(&module); + ConstantFoldModule(module); BinaryMplt binmplt(module); std::string modid = module.GetFileName(); binmplt.Export("bin." + modid); diff --git a/src/maple_ir/src/mir_function.cpp b/src/maple_ir/src/mir_function.cpp index 1a339b55dde9f4b8eed22e0ab2ff0215bc6fcf12..e642b58b2e15223e883dba272fbbd63663258318 100644 --- a/src/maple_ir/src/mir_function.cpp +++ b/src/maple_ir/src/mir_function.cpp @@ -101,25 +101,25 @@ void MIRFunction::Dump(bool withoutBody) { void MIRFunction::DumpUpFormal(int32 indent) const { PrintIndentation(indent + 1); LogInfo::MapleLogger() << "upformalsize " << static_cast(GetUpFormalSize()) << std::endl; - if (GetLocalWordsTypeTagged() != nullptr) { + if (localWordsTypeTagged != nullptr) { PrintIndentation(indent + 1); LogInfo::MapleLogger() << "formalwordstypetagged = [ "; - uint32 *p = const_cast(reinterpret_cast(GetLocalWordsTypeTagged())); + uint32 *p = const_cast(reinterpret_cast(localWordsTypeTagged)); LogInfo::MapleLogger() << std::hex; while (p < const_cast(reinterpret_cast( - GetLocalWordsTypeTagged() + BlockSize2BitVectorSize(GetUpFormalSize())))) { + localWordsTypeTagged + BlockSize2BitVectorSize(GetUpFormalSize())))) { LogInfo::MapleLogger() << std::hex << "0x" << *p << " "; p++; } LogInfo::MapleLogger() << std::dec << "]\n"; } - if (GetFormalWordsRefCounted() != nullptr) { + if (formalWordsRefCounted != nullptr) { PrintIndentation(indent + 1); LogInfo::MapleLogger() << "formalwordsrefcounted = [ "; - uint32 *p = const_cast(reinterpret_cast(GetFormalWordsRefCounted())); + uint32 *p = const_cast(reinterpret_cast(formalWordsRefCounted)); LogInfo::MapleLogger() << std::hex; while (p < const_cast(reinterpret_cast( - GetFormalWordsRefCounted() + BlockSize2BitVectorSize(GetUpFormalSize())))) { + formalWordsRefCounted + BlockSize2BitVectorSize(GetUpFormalSize())))) { LogInfo::MapleLogger() << std::hex << "0x" << *p << " "; p++; } @@ -130,25 +130,25 @@ void MIRFunction::DumpUpFormal(int32 indent) const { void MIRFunction::DumpFrame(int32 indent) const { PrintIndentation(indent + 1); LogInfo::MapleLogger() << "framesize " << GetFrameSize() << std::endl; - if (GetLocalWordsTypeTagged() != nullptr) { + if (localWordsTypeTagged != nullptr) { PrintIndentation(indent + 1); LogInfo::MapleLogger() << "localwordstypetagged = [ "; - uint32 *p = const_cast(reinterpret_cast(GetLocalWordsTypeTagged())); + uint32 *p = const_cast(reinterpret_cast(localWordsTypeTagged)); LogInfo::MapleLogger() << std::hex; while (p < const_cast(reinterpret_cast( - GetLocalWordsTypeTagged() + BlockSize2BitVectorSize(GetFrameSize())))) { + localWordsTypeTagged + BlockSize2BitVectorSize(GetFrameSize())))) { LogInfo::MapleLogger() << std::hex << "0x" << *p << " "; p++; } LogInfo::MapleLogger() << std::dec << "]\n"; } - if (GetLocalWordsRefCounted() != nullptr) { + if (localWordsRefCounted != nullptr) { PrintIndentation(indent + 1); LogInfo::MapleLogger() << "localwordsrefcounted = [ "; - uint32 *p = const_cast(reinterpret_cast(GetLocalWordsRefCounted())); + uint32 *p = const_cast(reinterpret_cast(localWordsRefCounted)); LogInfo::MapleLogger() << std::hex; while (p < const_cast(reinterpret_cast( - GetLocalWordsRefCounted() + BlockSize2BitVectorSize(GetFrameSize())))) { + localWordsRefCounted + BlockSize2BitVectorSize(GetFrameSize())))) { LogInfo::MapleLogger() << std::hex << "0x" << *p << " "; p++; } @@ -175,7 +175,7 @@ void MIRFunction::DumpFuncBody(int32 indent) { LogInfo::MapleLogger() << "funcsize " << GetFuncSize() << std::endl; } if (!GetInfoVector().empty()) { - MIRInfoVector funcInfo = GetInfoVector(); + const MIRInfoVector &funcInfo = GetInfoVector(); MapleVector funcInfoIsString = InfoIsString(); PrintIndentation(indent + 1); LogInfo::MapleLogger() << "funcinfo {\n"; @@ -309,7 +309,7 @@ void MIRFunction::NewBody() { MIRPregTable *oldPregTable = GetPregTab(); MIRTypeNameTable *oldTypenameTable = typeNameTab; MIRLabelTable *oldLabelTable = GetLabelTab(); - SetSymTab(dataMemPool->New(&dataMPAllocator)); + symTab = dataMemPool->New(&dataMPAllocator); SetPregTab(dataMemPool->New(module, &dataMPAllocator)); typeNameTab = dataMemPool->New(&dataMPAllocator); SetLabelTab(dataMemPool->New(&dataMPAllocator)); diff --git a/src/maple_ir/src/mir_lower.cpp b/src/maple_ir/src/mir_lower.cpp index baa30652a4f402b1bb64ff8b7aec8e5772fd7159..17b961d3edddc2802ee45b915908a4698c231fc6 100644 --- a/src/maple_ir/src/mir_lower.cpp +++ b/src/maple_ir/src/mir_lower.cpp @@ -18,37 +18,36 @@ #define DO_LT_0_CHECK 1 namespace maple { -BlockNode *MIRLower::LowerIfStmt(IfStmtNode *ifStmt, bool recursive) { - ASSERT(ifStmt != nullptr, "ifStmt is null"); - bool thenEmpty = ifStmt->GetThenPart() == nullptr || ifStmt->GetThenPart()->GetFirst() == nullptr; - bool elseEmpty = ifStmt->GetElsePart() == nullptr || ifStmt->GetElsePart()->GetFirst() == nullptr; +BlockNode *MIRLower::LowerIfStmt(IfStmtNode &ifStmt, bool recursive) { + bool thenEmpty = ifStmt.GetThenPart() == nullptr || ifStmt.GetThenPart()->GetFirst() == nullptr; + bool elseEmpty = ifStmt.GetElsePart() == nullptr || ifStmt.GetElsePart()->GetFirst() == nullptr; if (recursive) { if (!thenEmpty) { - ifStmt->SetThenPart(LowerBlock(ifStmt->GetThenPart())); + ifStmt.SetThenPart(LowerBlock(*ifStmt.GetThenPart())); } if (!elseEmpty) { - ifStmt->SetElsePart(LowerBlock(ifStmt->GetElsePart())); + ifStmt.SetElsePart(LowerBlock(*ifStmt.GetElsePart())); } } BlockNode *blk = mirModule.CurFuncCodeMemPool()->New(); if (thenEmpty && elseEmpty) { // generate EVAL statement UnaryStmtNode *evalStmt = mirModule.CurFuncCodeMemPool()->New(OP_eval); - evalStmt->SetOpnd(ifStmt->Opnd()); - evalStmt->SetSrcPos(ifStmt->GetSrcPos()); + evalStmt->SetOpnd(ifStmt.Opnd()); + evalStmt->SetSrcPos(ifStmt.GetSrcPos()); blk->AddStatement(evalStmt); } else if (elseEmpty) { // brfalse // // label CondGotoNode *brFalseStmt = mirModule.CurFuncCodeMemPool()->New(OP_brfalse); - brFalseStmt->SetOpnd(ifStmt->Opnd()); - brFalseStmt->SetSrcPos(ifStmt->GetSrcPos()); + brFalseStmt->SetOpnd(ifStmt.Opnd()); + brFalseStmt->SetSrcPos(ifStmt.GetSrcPos()); LabelIdx lableIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); (void)mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(lableIdx); brFalseStmt->SetOffset(lableIdx); blk->AddStatement(brFalseStmt); - blk->AppendStatementsFromBlock(ifStmt->GetThenPart()); + blk->AppendStatementsFromBlock(ifStmt.GetThenPart()); LabelNode *lableStmt = mirModule.CurFuncCodeMemPool()->New(); lableStmt->SetLabelIdx(lableIdx); blk->AddStatement(lableStmt); @@ -57,13 +56,13 @@ BlockNode *MIRLower::LowerIfStmt(IfStmtNode *ifStmt, bool recursive) { // // label CondGotoNode *brTrueStmt = mirModule.CurFuncCodeMemPool()->New(OP_brtrue); - brTrueStmt->SetOpnd(ifStmt->Opnd()); - brTrueStmt->SetSrcPos(ifStmt->GetSrcPos()); + brTrueStmt->SetOpnd(ifStmt.Opnd()); + brTrueStmt->SetSrcPos(ifStmt.GetSrcPos()); LabelIdx lableIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(lableIdx); brTrueStmt->SetOffset(lableIdx); blk->AddStatement(brTrueStmt); - blk->AppendStatementsFromBlock(ifStmt->GetElsePart()); + blk->AppendStatementsFromBlock(ifStmt.GetElsePart()); LabelNode *lableStmt = mirModule.CurFuncCodeMemPool()->New(); lableStmt->SetLabelIdx(lableIdx); blk->AddStatement(lableStmt); @@ -75,15 +74,15 @@ BlockNode *MIRLower::LowerIfStmt(IfStmtNode *ifStmt, bool recursive) { // // label CondGotoNode *brFalseStmt = mirModule.CurFuncCodeMemPool()->New(OP_brfalse); - brFalseStmt->SetOpnd(ifStmt->Opnd()); - brFalseStmt->SetSrcPos(ifStmt->GetSrcPos()); + brFalseStmt->SetOpnd(ifStmt.Opnd()); + brFalseStmt->SetSrcPos(ifStmt.GetSrcPos()); LabelIdx lIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); (void)mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(lIdx); brFalseStmt->SetOffset(lIdx); blk->AddStatement(brFalseStmt); - blk->AppendStatementsFromBlock(ifStmt->GetThenPart()); - ASSERT(ifStmt->GetThenPart()->GetLast()->GetOpCode() != OP_brtrue, "then or else block should not end with brtrue"); - ASSERT(ifStmt->GetThenPart()->GetLast()->GetOpCode() != OP_brfalse, + blk->AppendStatementsFromBlock(ifStmt.GetThenPart()); + ASSERT(ifStmt.GetThenPart()->GetLast()->GetOpCode() != OP_brtrue, "then or else block should not end with brtrue"); + ASSERT(ifStmt.GetThenPart()->GetLast()->GetOpCode() != OP_brfalse, "then or else block should not end with brfalse"); bool fallThroughFromThen = !IfStmtNoFallThrough(ifStmt); LabelIdx gotoLableIdx = 0; @@ -97,7 +96,7 @@ BlockNode *MIRLower::LowerIfStmt(IfStmtNode *ifStmt, bool recursive) { LabelNode *lableStmt = mirModule.CurFuncCodeMemPool()->New(); lableStmt->SetLabelIdx(lIdx); blk->AddStatement(lableStmt); - blk->AppendStatementsFromBlock(ifStmt->GetElsePart()); + blk->AppendStatementsFromBlock(ifStmt.GetElsePart()); if (fallThroughFromThen) { lableStmt = mirModule.CurFuncCodeMemPool()->New(); lableStmt->SetLabelIdx(gotoLableIdx); @@ -114,13 +113,13 @@ BlockNode *MIRLower::LowerIfStmt(IfStmtNode *ifStmt, bool recursive) { // // brtrue // label -BlockNode *MIRLower::LowerWhileStmt(WhileStmtNode *whileStmt) { - ASSERT(whileStmt != nullptr, "whileStmt is null"); - whileStmt->SetBody(LowerBlock(whileStmt->GetBody())); +BlockNode *MIRLower::LowerWhileStmt(WhileStmtNode &whileStmt) { + ASSERT(whileStmt.GetBody() != nullptr, "nullptr check"); + whileStmt.SetBody(LowerBlock(*whileStmt.GetBody())); BlockNode *blk = mirModule.CurFuncCodeMemPool()->New(); CondGotoNode *brFalseStmt = mirModule.CurFuncCodeMemPool()->New(OP_brfalse); - brFalseStmt->SetOpnd(whileStmt->Opnd()); - brFalseStmt->SetSrcPos(whileStmt->GetSrcPos()); + brFalseStmt->SetOpnd(whileStmt.Opnd()); + brFalseStmt->SetSrcPos(whileStmt.GetSrcPos()); LabelIdx lalbeIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); (void)mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(lalbeIdx); brFalseStmt->SetOffset(lalbeIdx); @@ -130,10 +129,10 @@ BlockNode *MIRLower::LowerWhileStmt(WhileStmtNode *whileStmt) { LabelNode *lableStmt = mirModule.CurFuncCodeMemPool()->New(); lableStmt->SetLabelIdx(bodyLableIdx); blk->AddStatement(lableStmt); - ASSERT(whileStmt->GetBody(), "null ptr check"); - blk->AppendStatementsFromBlock(whileStmt->GetBody()); + ASSERT(whileStmt.GetBody(), "null ptr check"); + blk->AppendStatementsFromBlock(whileStmt.GetBody()); CondGotoNode *brTrueStmt = mirModule.CurFuncCodeMemPool()->New(OP_brtrue); - brTrueStmt->SetOpnd(whileStmt->Opnd()->CloneTree(mirModule.GetCurFuncCodeMPAllocator())); + brTrueStmt->SetOpnd(whileStmt.Opnd()->CloneTree(mirModule.GetCurFuncCodeMPAllocator())); brTrueStmt->SetOffset(bodyLableIdx); blk->AddStatement(brTrueStmt); lableStmt = mirModule.CurFuncCodeMemPool()->New(); @@ -151,30 +150,30 @@ BlockNode *MIRLower::LowerWhileStmt(WhileStmtNode *whileStmt) { // dassign () // brtrue // label -BlockNode *MIRLower::LowerDoloopStmt(DoloopNode *doloop) { - ASSERT(doloop != nullptr, "doloop is null"); - doloop->SetDoBody(LowerBlock(doloop->GetDoBody())); +BlockNode *MIRLower::LowerDoloopStmt(DoloopNode &doloop) { + ASSERT(doloop.GetDoBody() != nullptr, "nullptr check"); + doloop.SetDoBody(LowerBlock(*doloop.GetDoBody())); BlockNode *blk = mirModule.CurFuncCodeMemPool()->New(); - if (doloop->IsPreg()) { - PregIdx regIdx = (PregIdx)doloop->GetDoVarStIdx().FullIdx(); + if (doloop.IsPreg()) { + PregIdx regIdx = (PregIdx)doloop.GetDoVarStIdx().FullIdx(); MIRPreg *mirPReg = mirModule.CurFunction()->GetPregTab()->PregFromPregIdx(regIdx); PrimType primType = mirPReg->GetPrimType(); ASSERT(primType != kPtyInvalid, "runtime check error"); RegassignNode *startRegassign = mirModule.CurFuncCodeMemPool()->New(); startRegassign->SetRegIdx(regIdx); startRegassign->SetPrimType(primType); - startRegassign->SetOpnd(doloop->GetStartExpr()); - startRegassign->SetSrcPos(doloop->GetSrcPos()); + startRegassign->SetOpnd(doloop.GetStartExpr()); + startRegassign->SetSrcPos(doloop.GetSrcPos()); blk->AddStatement(startRegassign); } else { DassignNode *startDassign = mirModule.CurFuncCodeMemPool()->New(); - startDassign->SetStIdx(doloop->GetDoVarStIdx()); - startDassign->SetRHS(doloop->GetStartExpr()); - startDassign->SetSrcPos(doloop->GetSrcPos()); + startDassign->SetStIdx(doloop.GetDoVarStIdx()); + startDassign->SetRHS(doloop.GetStartExpr()); + startDassign->SetSrcPos(doloop.GetSrcPos()); blk->AddStatement(startDassign); } CondGotoNode *brFalseStmt = mirModule.CurFuncCodeMemPool()->New(OP_brfalse); - brFalseStmt->SetOpnd(doloop->GetCondExpr()); + brFalseStmt->SetOpnd(doloop.GetCondExpr()); LabelIdx lIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); (void)mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(lIdx); brFalseStmt->SetOffset(lIdx); @@ -184,10 +183,10 @@ BlockNode *MIRLower::LowerDoloopStmt(DoloopNode *doloop) { LabelNode *labelStmt = mirModule.CurFuncCodeMemPool()->New(); labelStmt->SetLabelIdx(bodyLabelIdx); blk->AddStatement(labelStmt); - ASSERT(doloop->GetDoBody(), "null ptr check "); - blk->AppendStatementsFromBlock(doloop->GetDoBody()); - if (doloop->IsPreg()) { - PregIdx regIdx = (PregIdx)doloop->GetDoVarStIdx().FullIdx(); + ASSERT(doloop.GetDoBody(), "null ptr check "); + blk->AppendStatementsFromBlock(doloop.GetDoBody()); + if (doloop.IsPreg()) { + PregIdx regIdx = (PregIdx)doloop.GetDoVarStIdx().FullIdx(); MIRPreg *mirPreg = mirModule.CurFunction()->GetPregTab()->PregFromPregIdx(regIdx); PrimType doVarPType = mirPreg->GetPrimType(); ASSERT(doVarPType != kPtyInvalid, "runtime check error"); @@ -195,26 +194,26 @@ BlockNode *MIRLower::LowerDoloopStmt(DoloopNode *doloop) { readDoVar->SetRegIdx(regIdx); readDoVar->SetPrimType(doVarPType); BinaryNode *add = - mirModule.CurFuncCodeMemPool()->New(OP_add, doVarPType, doloop->GetIncrExpr(), readDoVar); + mirModule.CurFuncCodeMemPool()->New(OP_add, doVarPType, doloop.GetIncrExpr(), readDoVar); RegassignNode *endRegassign = mirModule.CurFuncCodeMemPool()->New(); endRegassign->SetRegIdx(regIdx); endRegassign->SetPrimType(doVarPType); endRegassign->SetOpnd(add); blk->AddStatement(endRegassign); } else { - MIRSymbol *doVarSym = mirModule.CurFunction()->GetLocalOrGlobalSymbol(doloop->GetDoVarStIdx()); + MIRSymbol *doVarSym = mirModule.CurFunction()->GetLocalOrGlobalSymbol(doloop.GetDoVarStIdx()); PrimType doVarPType = doVarSym->GetType()->GetPrimType(); DreadNode *readDovar = - mirModule.CurFuncCodeMemPool()->New(OP_dread, doVarPType, doloop->GetDoVarStIdx(), 0); + mirModule.CurFuncCodeMemPool()->New(OP_dread, doVarPType, doloop.GetDoVarStIdx(), 0); BinaryNode *add = - mirModule.CurFuncCodeMemPool()->New(OP_add, doVarPType, doloop->GetIncrExpr(), readDovar); + mirModule.CurFuncCodeMemPool()->New(OP_add, doVarPType, doloop.GetIncrExpr(), readDovar); DassignNode *endDassign = mirModule.CurFuncCodeMemPool()->New(); - endDassign->SetStIdx(doloop->GetDoVarStIdx()); + endDassign->SetStIdx(doloop.GetDoVarStIdx()); endDassign->SetRHS(add); blk->AddStatement(endDassign); } CondGotoNode *brTrueStmt = mirModule.CurFuncCodeMemPool()->New(OP_brtrue); - brTrueStmt->SetOpnd(doloop->GetCondExpr()->CloneTree(mirModule.GetCurFuncCodeMPAllocator())); + brTrueStmt->SetOpnd(doloop.GetCondExpr()->CloneTree(mirModule.GetCurFuncCodeMPAllocator())); brTrueStmt->SetOffset(bodyLabelIdx); blk->AddStatement(brTrueStmt); labelStmt = mirModule.CurFuncCodeMemPool()->New(); @@ -228,52 +227,52 @@ BlockNode *MIRLower::LowerDoloopStmt(DoloopNode *doloop) { // label // // brtrue -BlockNode *MIRLower::LowerDowhileStmt(WhileStmtNode *doWhileStmt) { - ASSERT(doWhileStmt != nullptr, "doWhildStmt is null"); - doWhileStmt->SetBody(LowerBlock(doWhileStmt->GetBody())); +BlockNode *MIRLower::LowerDowhileStmt(WhileStmtNode &doWhileStmt) { + ASSERT(doWhileStmt.GetBody() != nullptr, "nullptr check"); + doWhileStmt.SetBody(LowerBlock(*doWhileStmt.GetBody())); BlockNode *blk = mirModule.CurFuncCodeMemPool()->New(); LabelIdx lIdx = mirModule.CurFunction()->GetLabelTab()->CreateLabel(); (void)mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(lIdx); LabelNode *labelStmt = mirModule.CurFuncCodeMemPool()->New(); labelStmt->SetLabelIdx(lIdx); blk->AddStatement(labelStmt); - ASSERT(doWhileStmt->GetBody(), "null ptr check "); - blk->AppendStatementsFromBlock(doWhileStmt->GetBody()); + ASSERT(doWhileStmt.GetBody(), "null ptr check "); + blk->AppendStatementsFromBlock(doWhileStmt.GetBody()); CondGotoNode *brTrueStmt = mirModule.CurFuncCodeMemPool()->New(OP_brtrue); - brTrueStmt->SetOpnd(doWhileStmt->Opnd()); + brTrueStmt->SetOpnd(doWhileStmt.Opnd()); brTrueStmt->SetOffset(lIdx); blk->AddStatement(brTrueStmt); return blk; } -BlockNode *MIRLower::LowerBlock(BlockNode *block) { - ASSERT(block != nullptr, "block is null"); +BlockNode *MIRLower::LowerBlock(BlockNode &block) { BlockNode *newBlock = mirModule.CurFuncCodeMemPool()->New(); BlockNode *tmp = nullptr; - if (!block->GetFirst()) { + if (!block.GetFirst()) { return newBlock; } - StmtNode *nextStmt = block->GetFirst(); + StmtNode *nextStmt = block.GetFirst(); + ASSERT(nextStmt != nullptr, "nullptr check"); do { StmtNode *stmt = nextStmt; nextStmt = stmt->GetNext(); switch (stmt->GetOpCode()) { case OP_if: - tmp = LowerIfStmt(static_cast(stmt), true); + tmp = LowerIfStmt(static_cast(*stmt), true); ASSERT(tmp, "null ptr check"); newBlock->AppendStatementsFromBlock(tmp); break; case OP_while: - newBlock->AppendStatementsFromBlock(LowerWhileStmt(static_cast(stmt))); + newBlock->AppendStatementsFromBlock(LowerWhileStmt(static_cast(*stmt))); break; case OP_dowhile: - newBlock->AppendStatementsFromBlock(LowerDowhileStmt(static_cast(stmt))); + newBlock->AppendStatementsFromBlock(LowerDowhileStmt(static_cast(*stmt))); break; case OP_doloop: - newBlock->AppendStatementsFromBlock(LowerDoloopStmt(static_cast(stmt))); + newBlock->AppendStatementsFromBlock(LowerDoloopStmt(static_cast(*stmt))); break; case OP_block: - tmp = LowerBlock(static_cast(stmt)); + tmp = LowerBlock(static_cast(*stmt)); ASSERT(tmp, "null ptr check "); newBlock->AppendStatementsFromBlock(tmp); break; @@ -287,12 +286,11 @@ BlockNode *MIRLower::LowerBlock(BlockNode *block) { // for lowering OP_cand and OP_cior that are top level operators in the // condition operand of OP_brfalse and OP_brtrue -void MIRLower::LowerBrCondition(BlockNode *block) { - ASSERT(block != nullptr, "block is null"); - if (!block->GetFirst()) { +void MIRLower::LowerBrCondition(BlockNode &block) { + if (!block.GetFirst()) { return; } - StmtNode *nextStmt = block->GetFirst(); + StmtNode *nextStmt = block.GetFirst(); do { StmtNode *stmt = nextStmt; nextStmt = stmt->GetNext(); @@ -307,7 +305,7 @@ void MIRLower::LowerBrCondition(BlockNode *block) { CondGotoNode *newCondGoto = mirModule.CurFuncCodeMemPool()->New(Opcode(stmt->GetOpCode())); newCondGoto->SetOpnd(cond->GetBOpnd(1)); newCondGoto->SetOffset(condGoto->GetOffset()); - block->InsertAfter(newCondGoto, condGoto); + block.InsertAfter(newCondGoto, condGoto); nextStmt = stmt; // so it will be re-processed if another cand/cior } else { // short-circuit target is next statement LabelIdx lIdx; @@ -320,13 +318,13 @@ void MIRLower::LowerBrCondition(BlockNode *block) { (void)mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(lIdx); labelStmt = mirModule.CurFuncCodeMemPool()->New(); labelStmt->SetLabelIdx(lIdx); - block->InsertAfter(condGoto, labelStmt); + block.InsertAfter(condGoto, labelStmt); } CondGotoNode *newCondGoto = mirModule.CurFuncCodeMemPool()->New( stmt->GetOpCode() == OP_brfalse ? OP_brtrue : OP_brfalse); newCondGoto->SetOpnd(cond->GetBOpnd(0)); newCondGoto->SetOffset(lIdx); - block->InsertBefore(condGoto, newCondGoto); + block.InsertBefore(condGoto, newCondGoto); condGoto->SetOpnd(cond->GetBOpnd(1)); nextStmt = newCondGoto; // so it will be re-processed if another cand/cior } @@ -335,70 +333,66 @@ void MIRLower::LowerBrCondition(BlockNode *block) { } while (nextStmt != nullptr); } -void MIRLower::LowerFunc(MIRFunction *func) { - ASSERT(func != nullptr, "func is null"); - mirModule.SetCurFunction(func); +void MIRLower::LowerFunc(MIRFunction &func) { + mirModule.SetCurFunction(&func); if (IsLowerExpandArray()) { ExpandArrayMrt(func); } - BlockNode *origBody = func->GetBody(); - BlockNode *newBody = LowerBlock(origBody); - LowerBrCondition(newBody); - func->SetBody(newBody); + BlockNode *origBody = func.GetBody(); + ASSERT(origBody != nullptr, "nullptr check"); + BlockNode *newBody = LowerBlock(*origBody); + ASSERT(newBody != nullptr, "nullptr check"); + LowerBrCondition(*newBody); + func.SetBody(newBody); } -IfStmtNode *MIRLower::ExpandArrayMrtIfBlock(IfStmtNode *node) { - ASSERT(node != nullptr, "node is null"); - if (node->GetThenPart()) { - node->SetThenPart(ExpandArrayMrtBlock(node->GetThenPart())); +IfStmtNode *MIRLower::ExpandArrayMrtIfBlock(IfStmtNode &node) { + if (node.GetThenPart()) { + node.SetThenPart(ExpandArrayMrtBlock(*node.GetThenPart())); } - if (node->GetElsePart()) { - node->SetElsePart(ExpandArrayMrtBlock(node->GetElsePart())); + if (node.GetElsePart()) { + node.SetElsePart(ExpandArrayMrtBlock(*node.GetElsePart())); } - return node; + return &node; } -WhileStmtNode *MIRLower::ExpandArrayMrtWhileBlock(WhileStmtNode *node) { - ASSERT(node != nullptr, "node is null"); - if (node->GetBody()) { - node->SetBody(ExpandArrayMrtBlock(node->GetBody())); +WhileStmtNode *MIRLower::ExpandArrayMrtWhileBlock(WhileStmtNode &node) { + if (node.GetBody()) { + node.SetBody(ExpandArrayMrtBlock(*node.GetBody())); } - return node; + return &node; } -DoloopNode *MIRLower::ExpandArrayMrtDoloopBlock(DoloopNode *node) { - ASSERT(node != nullptr, "node is null"); - if (node->GetDoBody()) { - node->SetDoBody(ExpandArrayMrtBlock(node->GetDoBody())); +DoloopNode *MIRLower::ExpandArrayMrtDoloopBlock(DoloopNode &node) { + if (node.GetDoBody()) { + node.SetDoBody(ExpandArrayMrtBlock(*node.GetDoBody())); } - return node; + return &node; } -ForeachelemNode *MIRLower::ExpandArrayMrtForeachelemBlock(ForeachelemNode *node) { - ASSERT(node != nullptr, "node is null"); - if (node->GetLoopBody()) { - node->SetLoopBody(ExpandArrayMrtBlock(node->GetLoopBody())); +ForeachelemNode *MIRLower::ExpandArrayMrtForeachelemBlock(ForeachelemNode &node) { + if (node.GetLoopBody()) { + node.SetLoopBody(ExpandArrayMrtBlock(*node.GetLoopBody())); } - return node; + return &node; } -void MIRLower::AddArrayMrtMpl(BaseNode *exp, BlockNode *newBlock) { - ASSERT(exp != nullptr, "exp is null"); - ASSERT(newBlock != nullptr, "newBlock is null"); +void MIRLower::AddArrayMrtMpl(BaseNode &exp, BlockNode &newBlock) { MIRModule &mod = mirModule; MIRBuilder *builder = mod.GetMIRBuilder(); - for (size_t i = 0; i < exp->NumOpnds(); i++) { - AddArrayMrtMpl(exp->Opnd(i), newBlock); + for (size_t i = 0; i < exp.NumOpnds(); i++) { + ASSERT(exp.Opnd(i) != nullptr, "nullptr check"); + AddArrayMrtMpl(*exp.Opnd(i), newBlock); } - if (exp->GetOpCode() == OP_array) { - ArrayNode *arrayNode = static_cast(exp); + if (exp.GetOpCode() == OP_array) { + ArrayNode *arrayNode = static_cast(&exp); if (arrayNode->GetBoundsCheck()) { BaseNode *arrAddr = arrayNode->Opnd(0); BaseNode *index = arrayNode->Opnd(1); ASSERT(index != nullptr, "null ptr check"); MIRType *indexType = GlobalTables::GetTypeTable().GetPrimType(index->GetPrimType()); UnaryStmtNode *nullCheck = builder->CreateStmtUnary(OP_assertnonnull, arrAddr); - newBlock->AddStatement(nullCheck); + newBlock.AddStatement(nullCheck); #if DO_LT_0_CHECK ConstvalNode *indexZero = builder->GetConstUInt32(0); CompareNode *lessZero = builder->CreateExprCompare(OP_lt, GlobalTables::GetTypeTable().GetUInt1(), @@ -428,42 +422,42 @@ void MIRLower::AddArrayMrtMpl(BaseNode *exp, BlockNode *newBlock) { args.push_back(largeLen); IntrinsiccallNode *boundaryTrinsicCall = builder->CreateStmtIntrinsicCall(INTRN_MPL_BOUNDARY_CHECK, args); #endif - newBlock->AddStatement(boundaryTrinsicCall); + newBlock.AddStatement(boundaryTrinsicCall); } } } -BlockNode *MIRLower::ExpandArrayMrtBlock(BlockNode *block) { - ASSERT(block != nullptr, "block is null"); +BlockNode *MIRLower::ExpandArrayMrtBlock(BlockNode &block) { BlockNode *newBlock = mirModule.CurFuncCodeMemPool()->New(); - if (!block->GetFirst()) { + if (!block.GetFirst()) { return newBlock; } - StmtNode *nextStmt = block->GetFirst(); + StmtNode *nextStmt = block.GetFirst(); do { StmtNode *stmt = nextStmt; + ASSERT(stmt != nullptr, "nullptr check"); nextStmt = stmt->GetNext(); switch (stmt->GetOpCode()) { case OP_if: - newBlock->AddStatement(ExpandArrayMrtIfBlock(static_cast(stmt))); + newBlock->AddStatement(ExpandArrayMrtIfBlock(static_cast(*stmt))); break; case OP_while: - newBlock->AddStatement(ExpandArrayMrtWhileBlock(static_cast(stmt))); + newBlock->AddStatement(ExpandArrayMrtWhileBlock(static_cast(*stmt))); break; case OP_dowhile: - newBlock->AddStatement(ExpandArrayMrtWhileBlock(static_cast(stmt))); + newBlock->AddStatement(ExpandArrayMrtWhileBlock(static_cast(*stmt))); break; case OP_doloop: - newBlock->AddStatement(ExpandArrayMrtDoloopBlock(static_cast(stmt))); + newBlock->AddStatement(ExpandArrayMrtDoloopBlock(static_cast(*stmt))); break; case OP_foreachelem: - newBlock->AddStatement(ExpandArrayMrtForeachelemBlock(static_cast(stmt))); + newBlock->AddStatement(ExpandArrayMrtForeachelemBlock(static_cast(*stmt))); break; case OP_block: - newBlock->AddStatement(ExpandArrayMrtBlock(static_cast(stmt))); + newBlock->AddStatement(ExpandArrayMrtBlock(static_cast(*stmt))); break; default: - AddArrayMrtMpl(stmt, newBlock); + AddArrayMrtMpl(*stmt, *newBlock); newBlock->AddStatement(stmt); break; } @@ -471,18 +465,18 @@ BlockNode *MIRLower::ExpandArrayMrtBlock(BlockNode *block) { return newBlock; } -void MIRLower::ExpandArrayMrt(MIRFunction *func) { - ASSERT(func != nullptr, "func is null"); +void MIRLower::ExpandArrayMrt(MIRFunction &func) { if (ShouldOptArrayMrt(func)) { - BlockNode *origBody = func->GetBody(); - BlockNode *newBody = ExpandArrayMrtBlock(origBody); - func->SetBody(newBody); + BlockNode *origBody = func.GetBody(); + ASSERT(origBody != nullptr, "nullptr check"); + BlockNode *newBody = ExpandArrayMrtBlock(*origBody); + func.SetBody(newBody); } } const std::set MIRLower::kSetArrayHotFunc = {}; -bool MIRLower::ShouldOptArrayMrt(const MIRFunction *func) { - ASSERT(func != nullptr, "func is null"); - return (MIRLower::kSetArrayHotFunc.find(func->GetName()) != MIRLower::kSetArrayHotFunc.end()); + +bool MIRLower::ShouldOptArrayMrt(const MIRFunction &func) { + return (MIRLower::kSetArrayHotFunc.find(func.GetName()) != MIRLower::kSetArrayHotFunc.end()); } } // namespace maple diff --git a/src/maple_ir/src/mir_nodes.cpp b/src/maple_ir/src/mir_nodes.cpp index 994ccfea62b0dcb05bbb7e01041fc8c0cc4f0ffd..1cb5d966683a529a635879ddeafabd3b33bc2247 100644 --- a/src/maple_ir/src/mir_nodes.cpp +++ b/src/maple_ir/src/mir_nodes.cpp @@ -1035,7 +1035,7 @@ void BlockNode::Dump(const MIRModule &mod, int32 indent, const MIRSymbolTable *t 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()->GetGStrIdxToTyIdxMap()) { const std::string &name = GlobalTables::GetStrTable().GetStringFromStrIdx(it.first); MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(it.second); PrintIndentation(indent + 1); diff --git a/src/maple_ir/src/mir_parser.cpp b/src/maple_ir/src/mir_parser.cpp index c3ea914f26263405ac4b3643bf08aba544f4557e..64d6c15e7a61ca6775c7dbcdaefa115e4b7aa1c1 100644 --- a/src/maple_ir/src/mir_parser.cpp +++ b/src/maple_ir/src/mir_parser.cpp @@ -1438,7 +1438,7 @@ void MIRParser::ParseStmtBlockForSeenComment(BlockNodePtr blk, uint32 mplNum) { SetSrcPos(cmnt, mplNum); blk->AddStatement(cmnt); } - lexer.GetSeenComments().clear(); + lexer.seenComments.clear(); } } diff --git a/src/maple_ir/src/mir_type.cpp b/src/maple_ir/src/mir_type.cpp index f916da92b4ea1ddf7feb39ec55c0a6df1c9bb816..4170e7de63129e9aa6bc064ff4ad17917dc99af1 100644 --- a/src/maple_ir/src/mir_type.cpp +++ b/src/maple_ir/src/mir_type.cpp @@ -502,7 +502,7 @@ MIRStructType *MIRJarrayType::GetParentType() { if (parentTyIdx == 0) { GStrIdx jloStrIdx = GlobalTables::GetStrTable().GetStrIdxFromName( NameMangler::GetInternalNameLiteral(NameMangler::kJavaLangObjectStr)); - parentTyIdx = GlobalTables::GetTypeNameTable().GetTyidxFromGstrIdx(jloStrIdx); + parentTyIdx = GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(jloStrIdx); ASSERT((parentTyIdx != 0), "cannot find type for java.lang.Object"); } return static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); diff --git a/src/maple_ir/src/parser.cpp b/src/maple_ir/src/parser.cpp index c5b032215866e7cbe028c3e287f7be396192d582..7b69f18ef406414797e9d7e17226d333820e82f5 100644 --- a/src/maple_ir/src/parser.cpp +++ b/src/maple_ir/src/parser.cpp @@ -46,7 +46,7 @@ MIRFunction *MIRParser::CreateDummyFunction() { func->SetPuidxOrigin(func->GetPuidx()); MIRType *returnType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(PTY_void)); func->SetReturnTyIdx(returnType->GetTypeIndex()); - func->SetClassTyIdx(0); + func->SetClassTyIdx(0U); func->SetBaseClassFuncNames(strIdx); funcSt->SetFunction(func); return func; @@ -883,7 +883,7 @@ bool MIRParser::ParseClassType(TyIdx &styidx) { StIdx stidx = classType.GetMethodsElement(i).first; MIRSymbol *st = GlobalTables::GetGsymTable().GetSymbolFromStidx(stidx.Idx()); ASSERT(st->GetSKind() == kStFunc, "unexpected st->sKind"); - st->GetFunction()->GetClassTyidx() = styidx; + st->GetFunction()->SetClassTyIdx(styidx); } mod.AddClass(styidx); } @@ -927,7 +927,7 @@ bool MIRParser::ParseInterfaceType(TyIdx &styidx) { MIRSymbol *st = GlobalTables::GetGsymTable().GetSymbolFromStidx(stidx.Idx()); ASSERT(st != nullptr, "st is null"); ASSERT(st->GetSKind() == kStFunc, "unexpected st->sKind"); - st->GetFunction()->GetClassTyidx() = styidx; + st->GetFunction()->SetClassTyIdx(styidx); } mod.AddClass(styidx); } @@ -1130,7 +1130,7 @@ bool MIRParser::ParseDefinedTypename(TyIdx &definedTyIdx, MIRTypeKind kind) { } } } else { - definedTyIdx = mod.CurFunction()->GetTypeNameTable()->GetTyIdxFromGStrIdx(strIdx); + definedTyIdx = mod.CurFunction()->GetTyIdxFromGStrIdx(strIdx); if (definedTyIdx == 0) { MIRTypeByName nameType(strIdx); definedTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&nameType); @@ -1481,7 +1481,7 @@ bool MIRParser::ParseTypedef() { Error("A global type must use global type name "); return false; } - prevTyIdx = mod.CurFunction()->GetTypeNameTable()->GetTyIdxFromGStrIdx(strIdx); + prevTyIdx = mod.CurFunction()->GetTyIdxFromGStrIdx(strIdx); if (prevTyIdx != 0) { MIRType *prevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(prevTyIdx); prevStructType = dynamic_cast(prevType); @@ -1510,8 +1510,8 @@ bool MIRParser::ParseTypedef() { // for class/interface types, prev_tyidx could also be set during processing // so we check again right before SetGStrIdxToTyIdx if (isLocal) { - prevTyIdx = mod.CurFunction()->GetTypeNameTable()->GetTyIdxFromGStrIdx(strIdx); - mod.CurFunction()->GetTypeNameTable()->SetGStrIdxToTyIdx(strIdx, tyIdx); + prevTyIdx = mod.CurFunction()->GetTyIdxFromGStrIdx(strIdx); + mod.CurFunction()->SetGStrIdxToTyIdx(strIdx, tyIdx); ASSERT(GlobalTables::GetTypeTable().GetTypeTable().empty() == false, "container check"); if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->GetNameStrIdx() == 0) { GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->SetNameStrIdx(strIdx); @@ -1531,7 +1531,7 @@ bool MIRParser::ParseTypedef() { MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); if (!isLocal && (type->GetKind() == kTypeClass || type->GetKind() == kTypeClassIncomplete || type->GetKind() == kTypeInterface || type->GetKind() == kTypeInterfaceIncomplete)) { - prevTyIdx = GlobalTables::GetTypeNameTable().GetTyidxFromGstrIdx(strIdx); + prevTyIdx = GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(strIdx); if (prevTyIdx == 0) { GlobalTables::GetTypeNameTable().SetGStrIdxToTyIdx(strIdx, tyIdx); } @@ -1640,7 +1640,7 @@ bool MIRParser::ParseDeclareReg(MIRSymbol *symbol, MIRFunction *func) { } if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->HasTypeParam()) { symbol->SetAttr(ATTR_generic); - mod.CurFunction()->GetFuncAttrs().SetAttr(FUNCATTR_generic); + mod.CurFunction()->SetAttr(FUNCATTR_generic); } return true; } @@ -1709,7 +1709,7 @@ bool MIRParser::ParseDeclareVar(MIRSymbol *symbol) { if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->HasTypeParam()) { symbol->SetAttr(ATTR_generic); if (isLocal) { - mod.CurFunction()->GetFuncAttrs().SetAttr(FUNCATTR_generic); + mod.CurFunction()->SetAttr(FUNCATTR_generic); } } tk = lexer.GetTokenKind(); @@ -1859,12 +1859,9 @@ bool MIRParser::ParseFunction(uint32 fileIdx) { // Skip attribute checking func = funcSymbol->GetFunction(); func->ClearFormals(); - func->GetArgumentsTyIdx().clear(); - func->GetArgumentsAttrs().clear(); - func->SetSymTab(mod.GetMemPool()->New(&mod.GetMPAllocator())); - func->SetPregTab(mod.GetMemPool()->New(&mod, &mod.GetMPAllocator())); - func->SetTypeNameTab(mod.GetMemPool()->New(&mod.GetMPAllocator())); - func->SetLabelTab(mod.GetMemPool()->New(&mod.GetMPAllocator())); + func->ClearArgumentsTyIdx(); + func->ClearArgumentsAttrs(); + func->Init(); // update with current attr if (funcAttrs.GetAttrFlag()) { if (func->IsIpaSeen()) { @@ -1901,7 +1898,7 @@ bool MIRParser::ParseFunction(uint32 fileIdx) { func->SetPuidx(GlobalTables::GetFunctionTable().GetFuncTable().size()); GlobalTables::GetFunctionTable().GetFuncTable().push_back(func); funcSymbol->SetFunction(func); - func->GetFuncAttrs() = funcAttrs; + func->SetFuncAttrs(funcAttrs); } func->SetFileIndex(fileIdx); curFunc = func; @@ -1937,7 +1934,7 @@ bool MIRParser::ParseFunction(uint32 fileIdx) { func->GetSrcPosition().SetLineNum(firstLineNum); func->GetSrcPosition().SetFileNum(lastFileNum); // check if any local type name is undefined - for (auto it : func->GetTypeNameTab()->GetGStrIdxToTyIdxMap()) { + for (auto it : func->GetGStrIdxToTyIdxMap()) { MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(it.second); if (type->GetKind() == kTypeByName) { std::string strStream; @@ -2120,12 +2117,12 @@ bool MIRParser::ParseFuncInfo(void) { tokenKind = lexer.NextToken(); if (tokenKind == kTkIntconst) { uint32 fieldVal = lexer.GetTheIntVal(); - func->GetInfoVector().push_back(MIRInfoPair(strIdx, fieldVal)); - func->InfoIsString().push_back(false); + func->PushbackMIRInfo(MIRInfoPair(strIdx, fieldVal)); + func->PushbackIsString(false); } else if (tokenKind == kTkString) { GStrIdx literalStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); - func->GetInfoVector().push_back(MIRInfoPair(strIdx, literalStrIdx.GetIdx())); - func->InfoIsString().push_back(true); + func->PushbackMIRInfo(MIRInfoPair(strIdx, literalStrIdx.GetIdx())); + func->PushbackIsString(true); } else { Error("illegal value after funcinfo field name at "); return false; @@ -2331,7 +2328,7 @@ bool MIRParser::ParseMIRForFunc() { return false; } if ((this->options & kParseOptFunc) && curFunc) { - curFunc->GetFuncAttrs().SetAttr(FUNCATTR_optimized); + curFunc->SetAttr(FUNCATTR_optimized); mod.AddOptFuncs(curFunc); } return true; diff --git a/src/maple_me/include/ssa.h b/src/maple_me/include/ssa.h index ae66f42e5b071fc632010f38c52aac3af63d47df..92832b96a1299c56d297e52c5f32b5fbc344fb90 100644 --- a/src/maple_me/include/ssa.h +++ b/src/maple_me/include/ssa.h @@ -43,7 +43,7 @@ class PhiNode { result = resultPara; } - MapleVector &GetPhiOpns() { + MapleVector &GetPhiOpnds() { return phiOpnds; } @@ -57,7 +57,7 @@ class PhiNode { phiOpnds[index] = opnd; } - void SetPhiOpns(MapleVector phiOpndsPara) { + void SetPhiOpnds(MapleVector phiOpndsPara) { phiOpnds = phiOpndsPara; } diff --git a/src/maple_me/include/ssa_mir_nodes.h b/src/maple_me/include/ssa_mir_nodes.h index 875250199ec5c5b686bbe489c1e690ade07955a2..5fef3af46a705d2411f739eec1c29e4af3ef6cc0 100644 --- a/src/maple_me/include/ssa_mir_nodes.h +++ b/src/maple_me/include/ssa_mir_nodes.h @@ -168,6 +168,10 @@ class AccessSSANodes { CHECK_FATAL(false, "No ssaVar"); } + virtual void SetSSAVar(VersionSt &vst) { + CHECK_FATAL(false, "No ssaVar"); + } + virtual void DumpMayDefNodes(const MIRModule &mod) const { for (const auto &mayDefNode : GetMayDefNodes()) { mayDefNode.second.Dump(&mod); @@ -272,8 +276,8 @@ class MayDefPartWithVersionSt : public AccessSSANodes { return ssaVar; } - void SetSSAVar(VersionSt *ssaVarPara) { - ssaVar = ssaVarPara; + void SetSSAVar(VersionSt &ssaVarPara) override { + ssaVar = &ssaVarPara; } private: @@ -294,8 +298,8 @@ class VersionStPart : public AccessSSANodes { return ssaVar; } - void SetSSAVar(VersionSt *ssaVarPara) { - ssaVar = ssaVarPara; + void SetSSAVar(VersionSt &ssaVarPara) override { + ssaVar = &ssaVarPara; } private: @@ -396,7 +400,7 @@ class StmtsSSAPart { void SetSSAPartOf(const StmtNode &s, VersionSt *vst) { VersionStPart *vStSSAPart = GetSSAPartMp()->New(); - vStSSAPart->SetSSAVar(vst); + vStSSAPart->SetSSAVar(*vst); ssaPart[s.GetStmtID()] = vStSSAPart; } @@ -451,7 +455,7 @@ class AddrofSSANode : public AddrofNode { class IreadSSANode : public IreadNode { public: - IreadSSANode(MapleAllocator *alloc, IreadNode *inode) : IreadNode(inode->GetOpCode()), mayUse(nullptr) { + IreadSSANode(MapleAllocator *alloc, IreadNode *inode) : IreadNode(inode->GetOpCode()), ssaVar(nullptr) { SetPrimType(inode->GetPrimType()); tyIdx = inode->GetTyIdx(); fieldID = inode->GetFieldID(); @@ -461,18 +465,22 @@ class IreadSSANode : public IreadNode { ~IreadSSANode() = default; void Dump(const MIRModule &mod, int32 indent) const { - if (mayUse.GetOpnd() != nullptr) { - mayUse.Dump(&mod); + if (ssaVar != nullptr) { + ssaVar->Dump(&mod, true); } IreadNode::Dump(mod, indent); } - MayUseNode &GetMayUse() { - return mayUse; + VersionSt *GetSSAVar() { + return ssaVar; + } + + void SetSSAVar(VersionSt *ssaVarPara) { + ssaVar = ssaVarPara; } private: - MayUseNode mayUse; + VersionSt *ssaVar; }; class RegreadSSANode : public RegreadNode { diff --git a/src/maple_me/src/alias_class.cpp b/src/maple_me/src/alias_class.cpp index a84364f4ffa38f428542648c8cc81704efba4b3a..93b80a7866f40354409b7b4ee0d3035e82c8e9d7 100644 --- a/src/maple_me/src/alias_class.cpp +++ b/src/maple_me/src/alias_class.cpp @@ -609,9 +609,8 @@ void AliasClass::InsertMayUseExpr(BaseNode &expr) { rhsAe = FindOrCreateDummyNADSAe(); } IreadSSANode &ireadNode = static_cast(expr); - ireadNode.GetMayUse().SetOpnd( - ssaTab.GetVersionStTable().GetVersionStFromID(rhsAe->GetOriginalSt().GetZeroVersionIndex())); - ASSERT(ireadNode.GetMayUse().GetOpnd() != nullptr, "AliasClass::InsertMayUseExpr(): iread cannot have empty mayuse"); + ireadNode.SetSSAVar(ssaTab.GetVersionStTable().GetVersionStFromID(rhsAe->GetOriginalSt().GetZeroVersionIndex())); + ASSERT(ireadNode.GetSSAVar() != nullptr, "AliasClass::InsertMayUseExpr(): iread cannot have empty mayuse"); } // collect the mayUses caused by globalsAffectedByCalls. diff --git a/src/maple_me/src/bb.cpp b/src/maple_me/src/bb.cpp index 5ef5b49abbc4dae5b9d222f66c103333f56f5fe5..f19f444209348680e54df732c24b5fea055cb535 100644 --- a/src/maple_me/src/bb.cpp +++ b/src/maple_me/src/bb.cpp @@ -115,7 +115,7 @@ const PhiNode *BB::PhiofVerStInserted(const VersionSt &versionSt) const { void BB::InsertPhi(MapleAllocator *alloc, VersionSt *versionSt) { PhiNode phiNode(alloc, versionSt); for (auto prevIt = pred.begin(); prevIt != pred.end(); prevIt++) { - phiNode.GetPhiOpns().push_back(versionSt); + phiNode.GetPhiOpnds().push_back(versionSt); } phiList.insert(std::make_pair(versionSt->GetOrigSt(), phiNode)); } @@ -150,8 +150,8 @@ void BB::RemoveBBFromPred(BB *bb) { int index = bb->RemoveBBFromVector(pred); ASSERT(index != -1, "-1 is a very large number in BB::RemoveBBFromPred"); for (auto phiIt = phiList.begin(); phiIt != phiList.end(); phiIt++) { - ASSERT((*phiIt).second.GetPhiOpns().size() > index, "index out of range in BB::RemoveBBFromPred"); - (*phiIt).second.GetPhiOpns().erase((*phiIt).second.GetPhiOpns().cbegin() + index); + ASSERT((*phiIt).second.GetPhiOpnds().size() > index, "index out of range in BB::RemoveBBFromPred"); + (*phiIt).second.GetPhiOpnds().erase((*phiIt).second.GetPhiOpnds().cbegin() + index); } for (auto phiIt = mevarPhiList.begin(); phiIt != mevarPhiList.end(); phiIt++) { ASSERT((*phiIt).second->GetOpnds().size() > index, "index out of range in BB::RemoveBBFromPred"); diff --git a/src/maple_me/src/irmap.cpp b/src/maple_me/src/irmap.cpp index a713bb0c6afec09c1f6ce8c748796bedbba80d83..cecf8cfcfc446065aa16c8fa05f40651744ba7de 100644 --- a/src/maple_me/src/irmap.cpp +++ b/src/maple_me/src/irmap.cpp @@ -56,7 +56,7 @@ void IRMap::BuildPhiMeNode(BB &bb) { phiMeNode->UpdateLHS(*medef); phiMeNode->SetDefBB(&bb); // build phi operands - for (VersionSt *opnd : phi.second.GetPhiOpns()) { + for (VersionSt *opnd : phi.second.GetPhiOpnds()) { phiMeNode->GetOpnds().push_back(GetOrCreateRegFromVerSt(*opnd)); } bb.GetMeregphiList().insert(std::make_pair(medef->GetOstIdx(), phiMeNode)); @@ -66,7 +66,7 @@ void IRMap::BuildPhiMeNode(BB &bb) { phimenode->UpdateLHS(*medef); phimenode->SetDefBB(&bb); // build phi operands - for (VersionSt *opnd : phi.second.GetPhiOpns()) { + for (VersionSt *opnd : phi.second.GetPhiOpnds()) { phimenode->GetOpnds().push_back(GetOrCreateVarFromVerSt(*opnd)); } bb.GetMevarPhiList().insert(std::make_pair(medef->GetOStIdx(), phimenode)); @@ -609,7 +609,7 @@ MeExpr *IRMap::BuildExpr(BaseNode &mirNode) { ivarmeexpr.SetTyIdx(ireadnode.GetTyIdx()); ivarmeexpr.SetBase(BuildExpr(*ireadnode.Opnd(0))); ivarmeexpr.InitBase(mirNode.GetOpCode(), mirNode.GetPrimType(), mirNode.GetNumOpnds()); - VersionSt *verSt = ireadnode.GetMayUse().GetOpnd(); + VersionSt *verSt = ireadnode.GetSSAVar(); if (verSt != nullptr) { VarMeExpr *varmeexpr = GetOrCreateVarFromVerSt(*verSt); ivarmeexpr.SetMuVal(varmeexpr); diff --git a/src/maple_me/src/me_cfg.cpp b/src/maple_me/src/me_cfg.cpp index eb6c654bc2c9911d6131d86250c117442b5cbf5a..737603264238c5e9e0d3010a18d46a2cd41f6d7e 100644 --- a/src/maple_me/src/me_cfg.cpp +++ b/src/maple_me/src/me_cfg.cpp @@ -475,7 +475,7 @@ void MeCFG::ConvertPhis2IdentityAssigns(BB &meBB) const { &func.GetMeSSATab()->GetStmtsSSAPart().GetSSAPartAlloc())); MayDefPartWithVersionSt *theSSAPart = static_cast(func.GetMeSSATab()->GetStmtsSSAPart().SSAPartOf(*dassign)); - theSSAPart->SetSSAVar((*phiIt).second.GetResult()); + theSSAPart->SetSSAVar(*((*phiIt).second.GetResult())); meBB.PrependStmtNode(dassign); } phiIt++; diff --git a/src/maple_me/src/me_function.cpp b/src/maple_me/src/me_function.cpp index 76eedf3795fdabe5547d0657d9627b37d0c1be18..b391087d679d8497e547396bedb2f6b000c0e380 100644 --- a/src/maple_me/src/me_function.cpp +++ b/src/maple_me/src/me_function.cpp @@ -404,7 +404,8 @@ void MeFunction::Prepare(unsigned long rangeNum) { mirLowerer.Init(); mirLowerer.SetLowerME(); mirLowerer.SetLowerExpandArray(); - mirLowerer.LowerFunc(CurFunction()); + ASSERT(CurFunction() != nullptr, "nullptr check"); + mirLowerer.LowerFunc(*CurFunction()); CreateBasicBlocks(); if (NumBBs() == 0) { /* there's no basicblock generated */ diff --git a/src/maple_me/src/ssa.cpp b/src/maple_me/src/ssa.cpp index 970083ec46406da3d0b29e7bf0ec79d2a3b1dc49..0bd50e87c6631369d1bfcec2991309e54330b4a0 100644 --- a/src/maple_me/src/ssa.cpp +++ b/src/maple_me/src/ssa.cpp @@ -62,112 +62,59 @@ void SSA::RenamePhi(BB &bb) { void SSA::RenameDefs(StmtNode &stmt, BB &defBB) { Opcode opcode = stmt.GetOpCode(); - switch (opcode) { - case OP_regassign: { - RegassignNode ®Node = static_cast(stmt); - if (regNode.GetRegIdx() < 0) { - return; - } - VersionSt *theSSAPart = ssaTab->GetStmtsSSAPart().SSAPartOf(stmt)->GetSSAVar(); - VersionSt *newVersionSym = CreateNewVersion(*theSSAPart, defBB); - newVersionSym->SetDefType(VersionSt::kRegassign); - newVersionSym->SetRegassignNode(®Node); - ssaTab->GetStmtsSSAPart().SetSSAPartOf(stmt, newVersionSym); + if (opcode == OP_regassign) { + RegassignNode ®Node = static_cast(stmt); + if (regNode.GetRegIdx() < 0) { return; } - case OP_dassign: { - DassignNode &dnode = static_cast(stmt); - MayDefPartWithVersionSt *theSSAPart = - static_cast(ssaTab->GetStmtsSSAPart().SSAPartOf(stmt)); - VersionSt *newVersionSym = CreateNewVersion(*theSSAPart->GetSSAVar(), defBB); - theSSAPart->SetSSAVar(newVersionSym); - newVersionSym->SetDefType(VersionSt::kDassign); - newVersionSym->SetDassignNode(&dnode); - } - // intentional fall though - case OP_call: - case OP_virtualcall: - case OP_virtualicall: - case OP_superclasscall: - case OP_interfacecall: - case OP_interfaceicall: - case OP_customcall: - case OP_polymorphiccall: - case OP_icall: - case OP_intrinsiccall: - case OP_xintrinsiccall: - case OP_intrinsiccallwithtype: - case OP_callassigned: - case OP_virtualcallassigned: - case OP_virtualicallassigned: - case OP_superclasscallassigned: - case OP_interfacecallassigned: - case OP_interfaceicallassigned: - case OP_customcallassigned: - case OP_polymorphiccallassigned: - case OP_icallassigned: - case OP_intrinsiccallassigned: - case OP_xintrinsiccallassigned: - case OP_intrinsiccallwithtypeassigned: - case OP_syncenter: - case OP_syncexit: - case OP_maydassign: - case OP_iassign: { - MapleMap &mayDefList = SSAGenericGetMayDefNodes(stmt, ssaTab->GetStmtsSSAPart()); - for (auto it = mayDefList.begin(); it != mayDefList.end(); it++) { - MayDefNode &mayDef = it->second; - VersionSt *vsym = mayDef.GetResult(); - ASSERT(vsym->GetOrigIdx().idx < vstStacks.size(), "index out of range in SSA::RenameMayDefs"); - mayDef.SetOpnd(vstStacks[vsym->GetOrigIdx().idx]->top()); - VersionSt *newVersionSym = CreateNewVersion(*vsym, defBB); - mayDef.SetResult(newVersionSym); - newVersionSym->SetDefType(VersionSt::kMayDef); - newVersionSym->SetMayDef(&mayDef); - } - return; + AccessSSANodes *theSSAPart = ssaTab->GetStmtsSSAPart().SSAPartOf(stmt); + VersionSt *newVersionSym = CreateNewVersion(*(theSSAPart->GetSSAVar()), defBB); + newVersionSym->SetDefType(VersionSt::kRegassign); + newVersionSym->SetRegassignNode(®Node); + theSSAPart->SetSSAVar(*newVersionSym); + return; + } else if (opcode == OP_dassign) { + AccessSSANodes *theSSAPart = ssaTab->GetStmtsSSAPart().SSAPartOf(stmt); + VersionSt *newVersionSym = CreateNewVersion(*theSSAPart->GetSSAVar(), defBB); + newVersionSym->SetDefType(VersionSt::kDassign); + newVersionSym->SetDassignNode(static_cast(&stmt)); + theSSAPart->SetSSAVar(*newVersionSym); + } + if (HasMayDefPart(stmt)) { + MapleMap &mayDefList = SSAGenericGetMayDefNodes(stmt, ssaTab->GetStmtsSSAPart()); + for (auto it = mayDefList.begin(); it != mayDefList.end(); it++) { + MayDefNode &mayDef = it->second; + VersionSt *vsym = mayDef.GetResult(); + ASSERT(vsym->GetOrigIdx().idx < vstStacks.size(), "index out of range in SSA::RenameMayDefs"); + mayDef.SetOpnd(vstStacks[vsym->GetOrigIdx().idx]->top()); + VersionSt *newVersionSym = CreateNewVersion(*vsym, defBB); + mayDef.SetResult(newVersionSym); + newVersionSym->SetDefType(VersionSt::kMayDef); + newVersionSym->SetMayDef(&mayDef); } - default: - return; } } void SSA::RenameMustDefs(const StmtNode &stmt, BB &defBB) { Opcode opcode = stmt.GetOpCode(); - switch (opcode) { - case OP_callassigned: - case OP_virtualcallassigned: - case OP_virtualicallassigned: - case OP_superclasscallassigned: - case OP_interfacecallassigned: - case OP_interfaceicallassigned: - case OP_customcallassigned: - case OP_polymorphiccallassigned: - case OP_icallassigned: - case OP_intrinsiccallassigned: - case OP_xintrinsiccallassigned: - case OP_intrinsiccallwithtypeassigned: { - MapleVector &mustDefs = SSAGenericGetMustDefNode(stmt, ssaTab->GetStmtsSSAPart()); - MapleVector::iterator it = mustDefs.begin(); - for (; it != mustDefs.end(); it++) { - VersionSt *newVersionSym = CreateNewVersion(*(*it).GetResult(), defBB); - (*it).SetResult(newVersionSym); - newVersionSym->SetDefType(VersionSt::kMustDef); - newVersionSym->SetMustDef(&(*it)); - } - return; + if (kOpcodeInfo.IsCallAssigned(opcode)) { + MapleVector &mustDefs = SSAGenericGetMustDefNode(stmt, ssaTab->GetStmtsSSAPart()); + for (MustDefNode &mustDefNode : mustDefs) { + VersionSt *newVersionSym = CreateNewVersion(*mustDefNode.GetResult(), defBB); + mustDefNode.SetResult(newVersionSym); + newVersionSym->SetDefType(VersionSt::kMustDef); + newVersionSym->SetMustDef(&(mustDefNode)); } - default: - return; } } void SSA::RenameMayUses(BaseNode &node) { if (node.GetOpCode() == OP_iread) { IreadSSANode &iread = static_cast(node); - VersionSt *vsym = iread.GetMayUse().GetOpnd(); + VersionSt *vsym = iread.GetSSAVar(); CHECK_FATAL(vsym != nullptr, "SSA::RenameMayUses: iread has no mayUse opnd"); ASSERT(vsym->GetOrigIdx().idx < vstStacks.size(), "index out of range in SSA::RenameMayUses"); - iread.GetMayUse().SetOpnd(vstStacks[vsym->GetOrigIdx().idx]->top()); + iread.SetSSAVar(vstStacks[vsym->GetOrigIdx().idx]->top()); return; } MapleMap &mayUseList = @@ -208,108 +155,11 @@ void SSA::RenameExpr(BaseNode &expr) { } void SSA::RenameUses(StmtNode &stmt) { - Opcode opcode = stmt.GetOpCode(); - switch (opcode) { - case OP_brfalse: - case OP_brtrue: { - RenameExpr(*stmt.Opnd(0)); - break; - } - case OP_return: { - NaryStmtNode &retNode = static_cast(stmt); - BaseNode *retValue = retNode.NumOpnds() == 0 ? nullptr : retNode.Opnd(0); - RenameMayUses(stmt); - if (retValue != nullptr) { - RenameExpr(*retValue); - } - break; - } - case OP_call: - case OP_virtualcall: - case OP_virtualicall: - case OP_superclasscall: - case OP_interfacecall: - case OP_interfaceicall: - case OP_customcall: - case OP_polymorphiccall: - case OP_icall: - case OP_intrinsiccall: - case OP_xintrinsiccall: - case OP_intrinsiccallwithtype: - case OP_callassigned: - case OP_virtualcallassigned: - case OP_virtualicallassigned: - case OP_superclasscallassigned: - case OP_interfacecallassigned: - case OP_interfaceicallassigned: - case OP_customcallassigned: - case OP_polymorphiccallassigned: - case OP_icallassigned: - case OP_intrinsiccallassigned: - case OP_xintrinsiccallassigned: - case OP_intrinsiccallwithtypeassigned: - case OP_syncenter: - case OP_syncexit: { - RenameMayUses(stmt); - for (size_t i = 0; i < stmt.NumOpnds(); i++) { - BaseNode *argExpr = stmt.Opnd(i); - RenameExpr(*argExpr); - } - break; - } - case OP_maydassign: - case OP_dassign: { - DassignNode &dnode = static_cast(stmt); - RenameExpr(*dnode.GetRHS()); - break; - } - case OP_regassign: { - RegassignNode &rnode = static_cast(stmt); - if (rnode.GetRegIdx() < 0) { - return; - } - RenameExpr(*rnode.Opnd(0)); - break; - } - case OP_iassign: { - IassignNode &inode = static_cast(stmt); - RenameExpr(*inode.Opnd(0)); - RenameExpr(*inode.GetRHS()); - break; - } - case OP_throw: - RenameMayUses(stmt); - // fallthrough; - case OP_assertnonnull: - case OP_eval: - case OP_free: - case OP_switch: { - BaseNode *argExpr = stmt.Opnd(0); - RenameExpr(*argExpr); - break; - } - case OP_gosub: - case OP_retsub: - RenameMayUses(stmt); - break; - case OP_comment: - case OP_label: - case OP_goto: - case OP_jstry: - case OP_jscatch: - case OP_finally: - case OP_endtry: - case OP_cleanuptry: - case OP_try: - case OP_catch: - case OP_membaracquire: - case OP_membarrelease: - case OP_membarstoreload: - case OP_membarstorestore: - break; - default: - CHECK_FATAL(false, "NYI"); - break; + if (HasMayUsePart(stmt)) { + RenameMayUses(stmt); + } + for (int i = 0; i < stmt.NumOpnds(); i++) { + RenameExpr(*stmt.Opnd(i)); } } @@ -336,9 +186,9 @@ void SSA::RenamePhiUseInSucc(BB &bb) { void PhiNode::Dump(const MIRModule *mod) { GetResult()->Dump(mod); LogInfo::MapleLogger() << " = PHI("; - for (size_t i = 0; i < GetPhiOpns().size(); i++) { + for (size_t i = 0; i < GetPhiOpnds().size(); i++) { GetPhiOpnd(i)->Dump(mod); - if (i < GetPhiOpns().size() - 1) { + if (i < GetPhiOpnds().size() - 1) { LogInfo::MapleLogger() << ','; } } diff --git a/src/maple_me/src/ssa_mir_nodes.cpp b/src/maple_me/src/ssa_mir_nodes.cpp index 34dc5fcf6dc8d4176469c4fadb97ef0f1f687c0f..d9942b00f1707193d1e83bff0e3d3c8a1350eb95 100644 --- a/src/maple_me/src/ssa_mir_nodes.cpp +++ b/src/maple_me/src/ssa_mir_nodes.cpp @@ -105,7 +105,7 @@ static MapleMap *SSAGenericGetMayDefsFromVersionSt(VersionSt visited.insert(&vst); if (vst.GetDefType() == VersionSt::kPhi) { PhiNode *phi = vst.GetPhi(); - for (size_t i = 0; i < phi->GetPhiOpns().size(); i++) { + for (size_t i = 0; i < phi->GetPhiOpnds().size(); i++) { VersionSt *vsym = phi->GetPhiOpnd(i); MapleMap *mayDefs = SSAGenericGetMayDefsFromVersionSt(*vsym, stmtsSSAPart, visited); if (mayDefs != nullptr) { diff --git a/src/maple_me/src/ssa_tab.cpp b/src/maple_me/src/ssa_tab.cpp index 6f3ca44b2585da0f36ac78027ca12394ac49e6fd..cefe07511a90c992ff595d7ab408c3d2e4eb82c3 100644 --- a/src/maple_me/src/ssa_tab.cpp +++ b/src/maple_me/src/ssa_tab.cpp @@ -81,7 +81,7 @@ void SSATab::CreateSSAStmt(StmtNode &stmt, const BB &curbb, bool ignoreCallassig OriginalSt *ost = FindOrCreateSymbolOriginalSt(*st, mirModule.CurFunction()->GetPuidx(), dnode.GetFieldID()); VersionSt *vst = versionStTable.FindOrCreateVersionSt(ost, kInitVersion); - theSSAPart->SetSSAVar(vst); + theSSAPart->SetSSAVar(*vst); // if the rhs may throw exception, we insert MayDef of the lhs var if (stmt.GetOpCode() == OP_maydassign) { theSSAPart->InsertMayDefNode(theSSAPart->GetSSAVar(), &dnode); diff --git a/src/maple_phase/include/phase.h b/src/maple_phase/include/phase.h index 8ef8a7fe47458f55d9aa9f28132ee96e88ea2f86..06ae295606f5fb7aea853db1f9b2b2a4eac5f826 100644 --- a/src/maple_phase/include/phase.h +++ b/src/maple_phase/include/phase.h @@ -184,6 +184,5 @@ class AnalysisResultManager { MapleMap analysisResults; MapleMap analysisPhases; }; - } // namespace maple #endif // MAPLE_PHASE_INCLUDE_PHASE_H diff --git a/src/maple_phase/include/phase_manager.h b/src/maple_phase/include/phase_manager.h index 6825b4210a041d97d95970ab014e425e56a02c3d..6e85faa4993a64f10d60b52fcca53a4717e07979 100644 --- a/src/maple_phase/include/phase_manager.h +++ b/src/maple_phase/include/phase_manager.h @@ -147,7 +147,6 @@ class PhaseManager { } return total; } - protected: std::string managerName; MapleAllocator allocator; diff --git a/src/maple_util/include/mpl_logging.h b/src/maple_util/include/mpl_logging.h index 945730d437d8cf2d14983043636faa1f5318f490..35580807991f983adbdb5ec0bf126767086ede45 100644 --- a/src/maple_util/include/mpl_logging.h +++ b/src/maple_util/include/mpl_logging.h @@ -169,19 +169,20 @@ class LogInfo { fclose(outStream); } - void SetLogDevice(FILE *stream) { - outStream = stream; + void SetLogDevice(FILE &stream) { + outStream = &stream; } void SetLogMode(LogMode lm) { outMode = lm; } - void EmitLogForDevelop(enum LogTags tag, enum LogLevel ll, const char *file, const char *func, int line, - const char *fmt, ...); + void EmitLogForDevelop(enum LogTags tag, enum LogLevel ll, const std::string &file, const std::string &func, + int line, const char *fmt, ...); void EmitLogForUser(enum LogNumberCode num, enum LogLevel ll, const char *fmt, ...) const; void EmitLogForUser(enum LogNumberCode num, enum LogLevel ll, const std::string &message) const; - void EmitErrorMessage(const char *cond, const char *file, unsigned int line, const char *fmt, ...) const; + void EmitErrorMessage(const std::string &cond, const std::string &file, unsigned int line, + const char *fmt, ...) const; private: FILE *outStream; diff --git a/src/maple_util/include/name_mangler.h b/src/maple_util/include/name_mangler.h index c6555189433407cbdff433306757fb37e830390b..e3b319a54c00e9369c615bee9a1b1e5c17858b0a 100644 --- a/src/maple_util/include/name_mangler.h +++ b/src/maple_util/include/name_mangler.h @@ -135,7 +135,7 @@ static constexpr const char kBindingProtectedRegionStr[] = "__BindingProtectRegi extern bool doCompression; // Return the input string if the compression is not on; otherwise, return its compressed version -std::string GetInternalNameLiteral(const char *name); +std::string GetInternalNameLiteral(const std::string &name); std::string GetOriginalNameLiteral(const char *name); std::string EncodeName(const std::string &name); diff --git a/src/mpl2mpl/include/class_hierarchy.h b/src/mpl2mpl/include/class_hierarchy.h index 2c63c9a8d953853a3b99574e6b857470bd051bc8..ff1126deb969593a293e6ca7bbc0a4112974300c 100644 --- a/src/mpl2mpl/include/class_hierarchy.h +++ b/src/mpl2mpl/include/class_hierarchy.h @@ -98,7 +98,7 @@ class Klass { // Return true if found in the member methods bool IsKlassMethod(const MIRFunction *func) const; // Return MIRFunction if has method - const MIRFunction *HasMethod(const char *funcname); + const MIRFunction *HasMethod(const std::string &funcname); const MapleList &GetMethods() const { return methods; } @@ -271,9 +271,9 @@ class Klass { strIdx2Method.insert({ func->GetBaseFuncNameWithTypeStrIdx(), func }); } - void DelMethod(const MIRFunction *func); + void DelMethod(const MIRFunction &func); // Collect the virtual methods from parent class and interfaces - void CountVirtMethTopDown(const KlassHierarchy *kh); + void CountVirtMethTopDown(const KlassHierarchy &kh); // Count the virtual methods for subclasses and merge with itself void CountVirtMethBottomUp(); void Dump() const; @@ -288,15 +288,15 @@ class WKTypes { static void Init(); class Util { public: - static bool MayRefString(const BaseNode *n, MIRType *type); - static bool MayRefMeta(const BaseNode *n, MIRType *type); - static bool MayNotRefCyclicly(const BaseNode *n, MIRType *type); + static bool MayRefString(const BaseNode &n, MIRType &type); + static bool MayRefMeta(const BaseNode &n, MIRType &type); + static bool MayNotRefCyclicly(const BaseNode &n, MIRType &type); static MIRType *GetJavaLangObjectType() { return javalangObject; } private: - static bool NotCyclicType(MIRType *type, std::set &workList); + static bool NotCyclicType(MIRType &type, std::set &workList); }; private: @@ -329,7 +329,7 @@ class KlassHierarchy : public AnalysisResult { Klass *GetKlassFromTyIdx(TyIdx tyidx) const; Klass *GetKlassFromFunc(const MIRFunction *func) const; Klass *GetKlassFromName(const std::string &name) const; - Klass *GetKlassFromLiteral(const char *name) const; + Klass *GetKlassFromLiteral(const std::string &name) const; const MapleMap &GetKlasses() const { return strIdx2KlassMap; } @@ -344,7 +344,7 @@ class KlassHierarchy : public AnalysisResult { bool IsInterfaceImplemented(Klass *interface, const Klass *base) const; bool UpdateFieldID(TyIdx baseTypeIdx, TyIdx targetTypeIdx, FieldID &fldID) const; // return true if class, its super or interfaces have at least one clinit function - bool NeedClinitCheckRecursively(Klass *kl); + bool NeedClinitCheckRecursively(Klass &kl); void TopologicalSortKlasses(); void MarkClassFlags(); void CountVirtualMethods(); @@ -377,11 +377,11 @@ class KlassHierarchy : public AnalysisResult { // Connect all class<->interface edges based on Depth-First Search void UpdateImplementedInterfaces(); // Get a vector of parent class and implementing interface - void GetParentKlasses(const Klass *klass, std::vector &parentKlasses) const; + void GetParentKlasses(const Klass &klass, std::vector &parentKlasses) const; // Get a vector of child class and implemented class - void GetChildKlasses(const Klass *klass, std::vector &childKlasses) const; - void ExceptionFlagProp(Klass *klass); - Klass *AddClassFlag(const char *name, uint32 flag); + void GetChildKlasses(const Klass &klass, std::vector &childKlasses) const; + void ExceptionFlagProp(Klass &klass); + Klass *AddClassFlag(const std::string &name, uint32 flag); int GetFieldIDOffsetBetweenClasses(const Klass &super, const Klass &base) const; }; } // namespace maple diff --git a/src/mpl2mpl/include/class_init.h b/src/mpl2mpl/include/class_init.h index 0ca98d62f36ce79037770f17faaaa96e15d301cc..29719d91108c2803aa88206ab7ce9d63b88f27a1 100644 --- a/src/mpl2mpl/include/class_init.h +++ b/src/mpl2mpl/include/class_init.h @@ -33,9 +33,9 @@ class ClassInit : public FuncOptimizeImpl { void ProcessFunc(MIRFunction *func) override; private: - void GenClassInitCheckProfile(MIRFunction *func, MIRSymbol *classinfo, StmtNode *clinit) const; - void GenPreClassInitCheck(MIRFunction *func, const MIRSymbol *classinfo, StmtNode *clinit); - void GenPostClassInitCheck(MIRFunction *func, const MIRSymbol *classinfo, StmtNode *clinit); + void GenClassInitCheckProfile(MIRFunction &func, MIRSymbol &classinfo, StmtNode *clinit) const; + void GenPreClassInitCheck(MIRFunction &func, const MIRSymbol &classinfo, StmtNode *clinit); + void GenPostClassInitCheck(MIRFunction &func, const MIRSymbol &classinfo, StmtNode *clinit); MIRSymbol *GetClassInfo(const std::string &classname); bool CanRemoveClinitCheck(const std::string &clinitClassname); }; diff --git a/src/mpl2mpl/include/gen_check_cast.h b/src/mpl2mpl/include/gen_check_cast.h index a970242b82217b44e401f5eeefb35e34ff73da95..977d2c7ec566e0ff53f29cdf05e676ed41568456 100644 --- a/src/mpl2mpl/include/gen_check_cast.h +++ b/src/mpl2mpl/include/gen_check_cast.h @@ -46,7 +46,7 @@ class CheckCastGenerator : public FuncOptimizeImpl { void InitTypes(); void InitFuncs(); void GenAllCheckCast(); - void GenCheckCast(BaseNode *stmt); + void GenCheckCast(BaseNode &stmt); BaseNode *GetObjectShadow(BaseNode *opnd); MIRSymbol *GetOrCreateClassInfoSymbol(const std::string &className); }; diff --git a/src/mpl2mpl/include/muid_replacement.h b/src/mpl2mpl/include/muid_replacement.h index 2ebc32df5c1921884cafe1a767df5ec9108a0ed1..6d01d1256e95631f580194ac174930654b60d268 100644 --- a/src/mpl2mpl/include/muid_replacement.h +++ b/src/mpl2mpl/include/muid_replacement.h @@ -98,6 +98,12 @@ class MUIDReplacement : public FuncOptimizeImpl { std::map funcUndefMap; std::map dataUndefMap; std::map defMuidIdxMap; + enum LazyBindingOption : uint32 { + kNoLazyBinding = 0, + kConservativeLazyBinding = 1, + kRadicalLazyBinding = 2 + }; + void GenericTables(); void GenericFuncDefTable(); void GenericDataDefTable(); diff --git a/src/mpl2mpl/src/class_hierarchy.cpp b/src/mpl2mpl/src/class_hierarchy.cpp index 7ba18defc5719d8520e49adeec921eeb47db4fbc..c0f13d3965d27a157f6352cf5d59a80dbddf0776 100644 --- a/src/mpl2mpl/src/class_hierarchy.cpp +++ b/src/mpl2mpl/src/class_hierarchy.cpp @@ -137,12 +137,12 @@ MIRFunction *Klass::GetClosestMethod(GStrIdx funcnamewithtype) const { } } -void Klass::DelMethod(const MIRFunction *func) { - if (GetMethod(func->GetBaseFuncNameWithTypeStrIdx()) == func) { - strIdx2Method.erase(func->GetBaseFuncNameWithTypeStrIdx()); +void Klass::DelMethod(const MIRFunction &func) { + if (GetMethod(func.GetBaseFuncNameWithTypeStrIdx()) == &func) { + strIdx2Method.erase(func.GetBaseFuncNameWithTypeStrIdx()); } for (auto it = methods.begin(); it != methods.end(); it++) { - if (*it == func) { + if (*it == &func) { methods.erase(it--); return; } @@ -210,14 +210,14 @@ bool Klass::IsVirtualMethod(const MIRFunction &func) const { return (func.GetAttr(FUNCATTR_virtual) && !func.GetAttr(FUNCATTR_private) && !func.GetAttr(FUNCATTR_abstract)); } -void Klass::CountVirtMethTopDown(const KlassHierarchy *kh) { +void Klass::CountVirtMethTopDown(const KlassHierarchy &kh) { MapleVector *vec, *pvec; GStrIdx stridx; MapleVector *superAndImplClasses = alloc->GetMemPool()->New>(alloc->Adapter()); // Add default methods of interface. Add them first because they have lowest // priorities compared with methods defined in classes for (TyIdx const &tyidx : GetMIRClassType()->GetInerfaceImplemented()) { - Klass *interface = kh->GetKlassFromTyIdx(tyidx); + Klass *interface = kh.GetKlassFromTyIdx(tyidx); if (interface != nullptr) { superAndImplClasses->push_back(interface); } @@ -240,17 +240,17 @@ void Klass::CountVirtMethTopDown(const KlassHierarchy *kh) { } else { // Override the method coming from previous klass (must be an interface) ASSERT(strIdx2CandidateMap[stridx]->size() == 1, "Expect exactly one method definition"); - ASSERT(kh->GetKlassFromStrIdx(strIdx2CandidateMap[stridx]->at(0)->GetBaseClassNameStrIdx())->IsInterface(), + ASSERT(kh.GetKlassFromStrIdx(strIdx2CandidateMap[stridx]->at(0)->GetBaseClassNameStrIdx())->IsInterface(), "Override interface default methods"); // Interfaces implemented methods override, need to determine the inherit relation. // class method can override interface method, interface method can override its parent's methods vec = strIdx2CandidateMap[stridx]; ASSERT(vec != nullptr, "nullptr check!"); ASSERT(vec->size() == 1, "Expect exactly one method definition from parent class"); - Klass *parentKlass = kh->GetKlassFromFunc((*vec)[0]); - Klass *childKlass = kh->GetKlassFromFunc((*pvec)[0]); + Klass *parentKlass = kh.GetKlassFromFunc((*vec)[0]); + Klass *childKlass = kh.GetKlassFromFunc((*pvec)[0]); CHECK_FATAL(childKlass != nullptr, "childKlass is null in Klass::CountVirtMethTopDown"); - if (childKlass->IsInterface() && !kh->IsSuperKlassForInterface(parentKlass, childKlass)) { + if (childKlass->IsInterface() && !kh.IsSuperKlassForInterface(parentKlass, childKlass)) { continue; } (*vec)[0] = (*pvec)[0]; @@ -303,7 +303,7 @@ void Klass::CountVirtMethBottomUp() { } } -const MIRFunction *Klass::HasMethod(const char *funcname) { +const MIRFunction *Klass::HasMethod(const std::string &funcname) { for (auto *method : methods) { if (method->GetBaseFuncNameWithType().find(funcname) != std::string::npos) { return method; @@ -323,14 +323,14 @@ Klass *KlassHierarchy::GetKlassFromTyIdx(TyIdx tyidx) const { } Klass *KlassHierarchy::GetKlassFromFunc(const MIRFunction *func) const { - return (func ? GetKlassFromStrIdx(func->GetBaseClassNameStrIdx()) : nullptr); + return (func != nullptr ? GetKlassFromStrIdx(func->GetBaseClassNameStrIdx()) : nullptr); } Klass *KlassHierarchy::GetKlassFromName(const std::string &name) const { return GetKlassFromStrIdx(GlobalTables::GetStrTable().GetStrIdxFromName(name)); } -Klass *KlassHierarchy::GetKlassFromLiteral(const char *name) const { +Klass *KlassHierarchy::GetKlassFromLiteral(const std::string &name) const { return GetKlassFromStrIdx(GlobalTables::GetStrTable().GetStrIdxFromName(NameMangler::GetInternalNameLiteral(name))); } @@ -417,8 +417,8 @@ bool KlassHierarchy::UpdateFieldID(TyIdx baseTypeIdx, TyIdx targetTypeIdx, Field return false; } -bool KlassHierarchy::NeedClinitCheckRecursively(Klass *kl) { - Klass *klass = kl; +bool KlassHierarchy::NeedClinitCheckRecursively(Klass &kl) { + Klass *klass = &kl; if (klass->IsClass()) { while (klass != nullptr) { if (klass->GetClinit()) { @@ -426,7 +426,7 @@ bool KlassHierarchy::NeedClinitCheckRecursively(Klass *kl) { } klass = klass->GetSuperKlass(); } - for (Klass *implInterface : kl->GetImplInterfaces()) { + for (Klass *implInterface : kl.GetImplInterfaces()) { if (implInterface->GetClinit()) { for (auto &func : implInterface->GetMethods()) { if (!func->GetAttr(FUNCATTR_abstract) && !func->GetAttr(FUNCATTR_static)) { @@ -446,11 +446,11 @@ bool KlassHierarchy::NeedClinitCheckRecursively(Klass *kl) { // Get lowest common ancestor for two classes Klass *KlassHierarchy::GetLCA(Klass *k1, Klass *k2) const { std::vector v1, v2; - while (k1) { + while (k1 != nullptr) { v1.push_back(k1); k1 = k1->GetSuperKlass(); } - while (k2) { + while (k2 != nullptr) { v2.push_back(k2); k2 = k2->GetSuperKlass(); } @@ -501,14 +501,12 @@ void KlassHierarchy::AddKlasses() { } } -void KlassHierarchy::ExceptionFlagProp(Klass *klass) { - if (klass == nullptr) { - return; - } - klass->SetExceptionKlass(); - for (Klass *subClass : klass->GetSubKlasses()) { +void KlassHierarchy::ExceptionFlagProp(Klass &klass) { + klass.SetExceptionKlass(); + for (Klass *subClass : klass.GetSubKlasses()) { + ASSERT(subClass != nullptr, "null ptr check!"); subClass->SetExceptionKlass(); - ExceptionFlagProp(subClass); + ExceptionFlagProp(*subClass); } } @@ -563,11 +561,11 @@ void KlassHierarchy::AddKlassRelationAndMethods() { } } // Propagate isExceptionKlass flag - ExceptionFlagProp(GetKlassFromLiteral(NameMangler::kThrowClassStr)); - if (GetKlassFromLiteral(NameMangler::kThrowClassStr)) { + if (GetKlassFromLiteral(NameMangler::kThrowClassStr) != nullptr) { + ExceptionFlagProp(*GetKlassFromLiteral(NameMangler::kThrowClassStr)); CHECK_FATAL(GetKlassFromLiteral(NameMangler::kThrowClassStr)->IsExceptionKlass(), "must be exception class"); } - if (GetKlassFromLiteral(kJavaLangNoMethodStr)) { + if (GetKlassFromLiteral(kJavaLangNoMethodStr) != nullptr) { CHECK_FATAL(GetKlassFromLiteral(kJavaLangNoMethodStr)->IsExceptionKlass(), "must be exception class"); } } @@ -619,23 +617,23 @@ void KlassHierarchy::UpdateImplementedInterfaces() { } } -void KlassHierarchy::GetParentKlasses(const Klass *klass, std::vector &parentKlasses) const { - for (Klass *superKlass : klass->GetSuperKlasses()) { +void KlassHierarchy::GetParentKlasses(const Klass &klass, std::vector &parentKlasses) const { + for (Klass *superKlass : klass.GetSuperKlasses()) { parentKlasses.push_back(superKlass); } - if (!klass->IsInterface()) { - for (Klass *iklass : klass->GetImplInterfaces()) { + if (!klass.IsInterface()) { + for (Klass *iklass : klass.GetImplInterfaces()) { parentKlasses.push_back(iklass); } } } -void KlassHierarchy::GetChildKlasses(const Klass *klass, std::vector &childKlasses) const { - for (Klass *subKlass : klass->GetSubKlasses()) { +void KlassHierarchy::GetChildKlasses(const Klass &klass, std::vector &childKlasses) const { + for (Klass *subKlass : klass.GetSubKlasses()) { childKlasses.push_back(subKlass); } - if (klass->IsInterface()) { - for (Klass *implKlass : klass->GetImplKlasses()) { + if (klass.IsInterface()) { + for (Klass *implKlass : klass.GetImplKlasses()) { childKlasses.push_back(implKlass); } } @@ -655,13 +653,15 @@ void KlassHierarchy::TopologicalSortKlasses() { for (size_t i = 0; i < topoWorkList.size(); i++) { Klass *klass = topoWorkList[i]; std::vector childklasses; - GetChildKlasses(klass, childklasses); + ASSERT(klass != nullptr, "null ptr check!"); + GetChildKlasses(*klass, childklasses); for (Klass *childklass : childklasses) { if (inQueue.find(childklass) == inQueue.end()) { // callee has not been visited bool parentKlassAllVisited = true; std::vector parentKlasses; - GetParentKlasses(childklass, parentKlasses); + ASSERT(childklass != nullptr, "null ptr check!"); + GetParentKlasses(*childklass, parentKlasses); // Check whether all callers of the current callee have been visited for (Klass *parentKlass : parentKlasses) { if (inQueue.find(parentKlass) == inQueue.end()) { @@ -681,7 +681,7 @@ void KlassHierarchy::TopologicalSortKlasses() { void KlassHierarchy::CountVirtualMethods() { // Top-down iterates all klass nodes for (size_t i = 0; i < topoWorkList.size(); i++) { - topoWorkList[i]->CountVirtMethTopDown(this); + topoWorkList[i]->CountVirtMethTopDown(*this); } // Bottom-up iterates all klass nodes for (size_t i = topoWorkList.size(); i != 0; i--) { @@ -689,7 +689,7 @@ void KlassHierarchy::CountVirtualMethods() { } } -Klass *KlassHierarchy::AddClassFlag(const char *name, uint32 flag) { +Klass *KlassHierarchy::AddClassFlag(const std::string &name, uint32 flag) { Klass *refKlass = GetKlassFromLiteral(name); if (refKlass != nullptr) { refKlass->SetFlag(flag); @@ -793,7 +793,7 @@ MIRType *WKTypes::javalangrefField; MIRType *WKTypes::javalangrefConstructor; inline static MIRType *GetMIRTypeFromName(const char *name) { GStrIdx gStrIdx = GlobalTables::GetStrTable().GetStrIdxFromName(NameMangler::GetInternalNameLiteral(name)); - return GlobalTables::GetTypeTable().GetTypeFromTyIdx(GlobalTables::GetTypeNameTable().GetTyidxFromGstrIdx(gStrIdx)); + return GlobalTables::GetTypeTable().GetTypeFromTyIdx(GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(gStrIdx)); } void WKTypes::Init() { @@ -819,9 +819,9 @@ void WKTypes::Init() { // public final class String implements java.io.Serializable, Comparable, CharSequence // So n can point to String only if n's type is a ref to String or Object, or is an interface // type of java.io.Serializable, Comparable or CharSequence -bool WKTypes::Util::MayRefString(const BaseNode *n, MIRType *type) { - if ((n->GetPrimType() == PTY_ref || n->GetPrimType() == PTY_ptr) && type->GetKind() == kTypePointer) { - MIRPtrType *pointType = static_cast(type); +bool WKTypes::Util::MayRefString(const BaseNode &n, MIRType &type) { + if ((n.GetPrimType() == PTY_ref || n.GetPrimType() == PTY_ptr) && type.GetKind() == kTypePointer) { + MIRPtrType *pointType = static_cast(&type); MIRType *pointedType = pointType->GetPointedType(); if (pointedType == jlString || pointedType == javalangobjectSerializable || pointedType == javalangComparable || pointedType == javalangCharSequence || pointedType == javalangObject) { @@ -834,9 +834,9 @@ bool WKTypes::Util::MayRefString(const BaseNode *n, MIRType *type) { // Return true if node n may point to Meta object, i.e, n is a reference // of java.lang.Class, java.lang.reflect.Method, java.lang.reflect.Field, // java.lang.reflect.Constructor -bool WKTypes::Util::MayRefMeta(const BaseNode *n, MIRType *type) { - if ((n->GetPrimType() == PTY_ref || n->GetPrimType() == PTY_ptr) && type->GetKind() == kTypePointer) { - MIRPtrType *pointType = static_cast(type); +bool WKTypes::Util::MayRefMeta(const BaseNode &n, MIRType &type) { + if ((n.GetPrimType() == PTY_ref || n.GetPrimType() == PTY_ptr) && type.GetKind() == kTypePointer) { + MIRPtrType *pointType = static_cast(&type); MIRType *pointedType = pointType->GetPointedType(); /* Definition of java.lang.Class: @@ -893,31 +893,33 @@ bool WKTypes::Util::MayRefMeta(const BaseNode *n, MIRType *type) { // Return true if node 'n', whose type is 'type', can not form a reference cycle. // E.g, all fields are primitive types, String, array of primitive, etc. -bool WKTypes::Util::MayNotRefCyclicly(const BaseNode *n, MIRType *type) { - CHECK_FATAL((n->GetPrimType() == PTY_ref || n->GetPrimType() == PTY_ptr) && type->GetKind() == kTypePointer, +bool WKTypes::Util::MayNotRefCyclicly(const BaseNode &n, MIRType &type) { + CHECK_FATAL((n.GetPrimType() == PTY_ref || n.GetPrimType() == PTY_ptr) && type.GetKind() == kTypePointer, "n must be a reference"); std::set workList; - workList.insert(type); + workList.insert(&type); return NotCyclicType(type, workList); } // Helper function of WKTypes::Util::MayNotRefCyclicly. -bool WKTypes::Util::NotCyclicType(MIRType *type, std::set &workList) { +bool WKTypes::Util::NotCyclicType(MIRType &type, std::set &workList) { // Fast path for special cases: String, Class - if (type == jlString || type == javalangClass) { + if (&type == jlString || &type == javalangClass) { return true; } - if (type->GetKind() == kTypeScalar) { // primitive type + if (type.GetKind() == kTypeScalar) { // primitive type return true; - } else if (type->GetKind() == kTypePointer) { - MIRType *pointedType = static_cast(type)->GetPointedType(); - return NotCyclicType(pointedType, workList); - } else if (type->GetKind() == kTypeJArray) { + } else if (type.GetKind() == kTypePointer) { + MIRType *pointedType = static_cast(&type)->GetPointedType(); + ASSERT(pointedType != nullptr, "null ptr check!"); + return NotCyclicType(*pointedType, workList); + } else if (type.GetKind() == kTypeJArray) { MIRType *elemType = - GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast(type)->GetElemTyIdx()); - return NotCyclicType(elemType, workList); - } else if (type->GetKind() == kTypeClass) { - MIRClassType *classType = static_cast(type); + GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast(&type)->GetElemTyIdx()); + ASSERT(elemType != nullptr, "null ptr check!"); + return NotCyclicType(*elemType, workList); + } else if (type.GetKind() == kTypeClass) { + MIRClassType *classType = static_cast(&type); if (!classType->IsFinal()) { // Not sure what actual class it refers to return false; } @@ -935,6 +937,7 @@ bool WKTypes::Util::NotCyclicType(MIRType *type, std::set &workList) { // Ignore interface fields, as they are all static final (constant) variables for (FieldPair &fieldPair : allFields) { MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldPair.second.first); + ASSERT(fieldType != nullptr, "null ptr check!"); if (fieldType->GetKind() == kTypePointer) { // Strictly, we should check whether fieldType is 'assignable' from any type // recorded in worklist, which means a cycle may be formed. However, this @@ -951,12 +954,12 @@ bool WKTypes::Util::NotCyclicType(MIRType *type, std::set &workList) { } workList.insert(fieldType); } - if (!NotCyclicType(fieldType, workList)) { + if (!NotCyclicType(*fieldType, workList)) { return false; } } return true; - } else if (type->GetKind() == kTypeInterface) { + } else if (type.GetKind() == kTypeInterface) { // Perhaps something more can do. return false; } diff --git a/src/mpl2mpl/src/class_init.cpp b/src/mpl2mpl/src/class_init.cpp index 07da4b549b76a8da58c2dfc312acc06de46309f9..5123e3f0d477b997f373980492a94137a30de9b2 100644 --- a/src/mpl2mpl/src/class_init.cpp +++ b/src/mpl2mpl/src/class_init.cpp @@ -32,33 +32,34 @@ bool ClassInit::CanRemoveClinitCheck(const std::string &clinitClassname) { } #undef CLINIT_CHECK -void ClassInit::GenClassInitCheckProfile(MIRFunction *func, MIRSymbol *classinfo, StmtNode *clinit) const { +void ClassInit::GenClassInitCheckProfile(MIRFunction &func, MIRSymbol &classinfo, StmtNode *clinit) const { #ifdef CLINIT_CHECK GenPreClassInitCheck(func, classinfo, clinit); GenPostClassInitCheck(func, classinfo, clinit); #endif // CLINIT_CHECK } -void ClassInit::GenPreClassInitCheck(MIRFunction *func, const MIRSymbol *classinfo, StmtNode *clinit) { +void ClassInit::GenPreClassInitCheck(MIRFunction &func, const MIRSymbol &classinfo, StmtNode *clinit) { MIRFunction *preClinit = builder->GetOrCreateFunction(kMCCPreClinitCheck, (TyIdx)(PTY_void)); - BaseNode *classInfoNode = builder->CreateExprAddrof(0, classinfo); + BaseNode *classInfoNode = builder->CreateExprAddrof(0, &classinfo); MapleVector args(builder->GetCurrentFuncCodeMpAllocator()->Adapter()); args.push_back(classInfoNode); CallNode *callPreclinit = builder->CreateStmtCall(preClinit->GetPuidx(), args); - func->GetBody()->InsertBefore(clinit, callPreclinit); + func.GetBody()->InsertBefore(clinit, callPreclinit); } -void ClassInit::GenPostClassInitCheck(MIRFunction *func, const MIRSymbol *classinfo, StmtNode *clinit) { +void ClassInit::GenPostClassInitCheck(MIRFunction &func, const MIRSymbol &classinfo, StmtNode *clinit) { MIRFunction *postClinit = builder->GetOrCreateFunction(kMCCPostClinitCheck, (TyIdx)(PTY_void)); - BaseNode *classInfoNode = builder->CreateExprAddrof(0, classinfo); + BaseNode *classInfoNode = builder->CreateExprAddrof(0, &classinfo); MapleVector args(builder->GetCurrentFuncCodeMpAllocator()->Adapter()); args.push_back(classInfoNode); CallNode *callPostclinit = builder->CreateStmtCall(postClinit->GetPuidx(), args); - func->GetBody()->InsertAfter(clinit, callPostclinit); + func.GetBody()->InsertAfter(clinit, callPostclinit); } void ClassInit::ProcessFunc(MIRFunction *func) { // No field will be involved in critical native funcs. + ASSERT(func != nullptr, "null ptr check!"); if (func->IsEmpty() || func->GetAttr(FUNCATTR_critical_native)) { return; } @@ -105,7 +106,8 @@ void ClassInit::ProcessFunc(MIRFunction *func) { args.push_back(classInfoNode); StmtNode *intrinsicCall = builder->CreateStmtIntrinsicCall(INTRN_MPL_CLINIT_CHECK, args); func->GetBody()->InsertFirst(intrinsicCall); - GenClassInitCheckProfile(func, classInfo, intrinsicCall); + ASSERT(classInfo != nullptr, "null ptr check!"); + GenClassInitCheckProfile(*func, *classInfo, intrinsicCall); } } } @@ -131,7 +133,7 @@ void ClassInit::ProcessFunc(MIRFunction *func) { WARN(kLncWarn, "ClassInit::ProcessFunc: Skip INCOMPLETE type %s", className.c_str()); doClinitCheck = true; } else { - doClinitCheck = !CanRemoveClinitCheck(className) && klassHierarchy->NeedClinitCheckRecursively(klass); + doClinitCheck = !CanRemoveClinitCheck(className) && klassHierarchy->NeedClinitCheckRecursively(*klass); } if (doClinitCheck) { MIRSymbol *classInfo = GetClassInfo(className); @@ -144,7 +146,8 @@ void ClassInit::ProcessFunc(MIRFunction *func) { LogInfo::MapleLogger() << "\t- low-cost clinit - lower JAVA_CLINIT_CHECK " << className << " in " << func->GetName() << "()" << std::endl; } - GenClassInitCheckProfile(func, classInfo, mplIntrinsicCall); + ASSERT(classInfo != nullptr, "null ptr check!"); + GenClassInitCheckProfile(*func, *classInfo, mplIntrinsicCall); } else { func->GetBody()->RemoveStmt(stmt); } diff --git a/src/mpl2mpl/src/gen_check_cast.cpp b/src/mpl2mpl/src/gen_check_cast.cpp index e62682af12f35feab5d9f06104581bc64100a43a..8e313ff0083f3987f57d5b4596c6469f199f2852 100644 --- a/src/mpl2mpl/src/gen_check_cast.cpp +++ b/src/mpl2mpl/src/gen_check_cast.cpp @@ -58,7 +58,7 @@ MIRSymbol *CheckCastGenerator::GetOrCreateClassInfoSymbol(const std::string &cla if (classInfoSymbol == nullptr) { GStrIdx gStrIdx = GlobalTables::GetStrTable().GetStrIdxFromName(className); MIRType *classType = - GlobalTables::GetTypeTable().GetTypeFromTyIdx(GlobalTables::GetTypeNameTable().GetTyidxFromGstrIdx(gStrIdx)); + GlobalTables::GetTypeTable().GetTypeFromTyIdx(GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(gStrIdx)); MIRStorageClass sclass = (classType && static_cast(classType)->IsLocal()) ? kScGlobal : kScExtern; // Creating global symbol needs synchronization. classInfoSymbol = builder->CreateGlobalDecl(classInfoName.c_str(), GlobalTables::GetTypeTable().GetPtr(), sclass); @@ -66,10 +66,10 @@ MIRSymbol *CheckCastGenerator::GetOrCreateClassInfoSymbol(const std::string &cla return classInfoSymbol; } -void CheckCastGenerator::GenCheckCast(BaseNode *stmt) { +void CheckCastGenerator::GenCheckCast(BaseNode &stmt) { // Handle the special case like (Type)null, we don't need a checkcast. - if (stmt->GetOpCode() == OP_intrinsiccallwithtypeassigned) { - IntrinsiccallNode *callNode = static_cast(stmt); + if (stmt.GetOpCode() == OP_intrinsiccallwithtypeassigned) { + IntrinsiccallNode *callNode = static_cast(&stmt); ASSERT(callNode->GetNopndSize() == 1, "array size error"); BaseNode *opnd = callNode->Opnd(0); if (opnd->GetOpCode() == OP_constval) { @@ -85,12 +85,12 @@ void CheckCastGenerator::GenCheckCast(BaseNode *stmt) { MIRPreg *mirPreg = currFunc->GetPregTab()->PregFromPregIdx(pregIdx); assignReturnTypeNode = builder->CreateStmtRegassign(mirPreg->GetPrimType(), pregIdx, opnd); } - currFunc->GetBody()->ReplaceStmt1WithStmt2(static_cast(stmt), assignReturnTypeNode); + currFunc->GetBody()->ReplaceStmt1WithStmt2(static_cast(&stmt), assignReturnTypeNode); return; } } // Do type check first. - IntrinsiccallNode *callNode = static_cast(stmt); + IntrinsiccallNode *callNode = static_cast(&stmt); ASSERT(callNode->GetNopndSize() == 1, "array size error"); TyIdx checkTyidx = callNode->GetTyIdx(); MIRType *checkType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(checkTyidx); @@ -110,7 +110,7 @@ void CheckCastGenerator::GenCheckCast(BaseNode *stmt) { args.push_back(callNode->GetNopndAt(0)); args.push_back(builder->CreateIntConst(0, PTY_ptr)); StmtNode *dassignStmt = builder->CreateStmtCall(throwCastException->GetPuidx(), args); - currFunc->GetBody()->InsertBefore(static_cast(stmt), dassignStmt); + currFunc->GetBody()->InsertBefore(static_cast(&stmt), dassignStmt); } } else { MIRSymbol *classSt = GetOrCreateClassInfoSymbol(checkKlass->GetKlassName()); @@ -136,7 +136,7 @@ void CheckCastGenerator::GenCheckCast(BaseNode *stmt) { StmtNode *dassignStmt = builder->CreateStmtCall(checkCastingNoArray->GetPuidx(), args); innerIfStmt->GetThenPart()->AddStatement(dassignStmt); ifStmt->GetThenPart()->AddStatement(innerIfStmt); - currFunc->GetBody()->InsertBefore(static_cast(stmt), ifStmt); + currFunc->GetBody()->InsertBefore(static_cast(&stmt), ifStmt); } } else { MIRType *pointedType = @@ -176,7 +176,7 @@ void CheckCastGenerator::GenCheckCast(BaseNode *stmt) { opnds.push_back(builder->CreateIntConst(dim, PTY_ptr)); opnds.push_back(signatureNode); StmtNode *dassignStmt = builder->CreateStmtCall(checkCastingArray->GetPuidx(), opnds); - currFunc->GetBody()->InsertBefore(static_cast(stmt), dassignStmt); + currFunc->GetBody()->InsertBefore(static_cast(&stmt), dassignStmt); } else { MIRTypeKind kd = pointedType->GetKind(); if (kd == kTypeStructIncomplete || kd == kTypeClassIncomplete || kd == kTypeInterfaceIncomplete) { @@ -248,7 +248,7 @@ void CheckCastGenerator::GenCheckCast(BaseNode *stmt) { MIRPreg *mirPreg = currFunc->GetPregTab()->PregFromPregIdx(pregIdx); assignReturnTypeNode = builder->CreateStmtRegassign(mirPreg->GetPrimType(), pregIdx, opnd); } - currFunc->GetBody()->ReplaceStmt1WithStmt2(static_cast(stmt), assignReturnTypeNode); + currFunc->GetBody()->ReplaceStmt1WithStmt2(static_cast(&stmt), assignReturnTypeNode); } void CheckCastGenerator::GenAllCheckCast() { @@ -257,7 +257,7 @@ void CheckCastGenerator::GenAllCheckCast() { if (stmt.GetOpCode() == OP_intrinsiccallwithtypeassigned || stmt.GetOpCode() == OP_intrinsiccallwithtype) { IntrinsiccallNode &callNode = static_cast(stmt); if (callNode.GetIntrinsic() == INTRN_JAVA_CHECK_CAST) { - GenCheckCast(&stmt); + GenCheckCast(stmt); if (stmt.GetOpCode() == OP_intrinsiccallwithtype) { currFunc->GetBody()->RemoveStmt(&stmt); } @@ -281,6 +281,6 @@ void CheckCastGenerator::ProcessFunc(MIRFunction *func) { SetCurrentFunction(func); GenAllCheckCast(); MIRLower mirlowerer(*(GetModule()), func); - mirlowerer.LowerFunc(func); + mirlowerer.LowerFunc(*func); } } // namespace maple diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index 437653fd00c684bcd718bce7c528fa4a67e6a868..3f40f4cf162201db4ff8318ea15a8481066c2fda 100644 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -1122,6 +1122,7 @@ MIRSymbol *ReflectionAnalysis::GetClinitFuncSymbol(const Klass *klass) { } void ReflectionAnalysis::GenClassMetaData(Klass *klass) { + ASSERT(klass != nullptr, "null ptr check!"); MIRClassType *classType = klass->GetMIRClassType(); if (!classType->IsLocal()) { // External class. @@ -1299,7 +1300,7 @@ void ReflectionAnalysis::GenClassMetaData(Klass *klass) { mirBuilder.AddAddrofFieldConst(*classMetadataType, *newconst, fieldID++, *classMetadataROSymbolType); // Set default value to class initialization state. // If this class and its parents do not have clinit, we do not clinit-check for this class. - if (klassh->NeedClinitCheckRecursively(klass)) { + if (klassh->NeedClinitCheckRecursively(*klass)) { MIRType *ptrType = GlobalTables::GetTypeTable().GetPtr(); MIRSymbol *classInitProtectRegion = mirBuilder.GetOrCreateSymbol( ptrType->GetTypeIndex(), kClassInitProtectRegionStr, kStVar, kScExtern, nullptr, kScopeGlobal, true);