diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 00e6b4d9b3a27aeeca2eeed0a7c5740efd747f7e..84ea5241d5765e70afd9181db3473d5b74afedd8 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 12d5dab3696190e60b6315cfe012df2aec362c9e..43bd7e27a7ea7779beadbe98790f55001e6bec5f 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index db718428c8942b5bb253e1e87071031943e366da..6f58063b8f211db814ea07c31fac5c648743ce58 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 cf44edeeeff0e798e9d621f0eec64c6bcbb8a44e..1a92467cd373d11837d86aaefe8845d3655692a5 100644 Binary files a/src/deplibs/libmaple_driverutil.a and b/src/deplibs/libmaple_driverutil.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index be5dd045e06df5ee2d6cd59ce9d2b1c40584c7e6..2bde69a30febfa1781cdffed942fc7fa84bcb4a8 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_ir/include/cfg_primitive_types.h b/src/maple_ir/include/cfg_primitive_types.h index 8ce704de83b136751664290612c11c2e687eb466..48829447c20acff4341f7386b59b37c9efbff4b4 100644 --- a/src/maple_ir/include/cfg_primitive_types.h +++ b/src/maple_ir/include/cfg_primitive_types.h @@ -45,5 +45,4 @@ struct PrimitiveTypeProperty { const PrimitiveTypeProperty &GetPrimitiveTypeProperty(PrimType pType); } // namespace maple - #endif // MAPLE_IR_INCLUDE_CFG_PRIMITIVE_TYPES_H diff --git a/src/maple_ir/include/metadata_layout.h b/src/maple_ir/include/metadata_layout.h index cb85221840cb2111a95928e7ed659b58718e488f..d02dd41a41e3c4e07f3e190c1536ec63c2d610b2 100644 --- a/src/maple_ir/include/metadata_layout.h +++ b/src/maple_ir/include/metadata_layout.h @@ -17,15 +17,12 @@ #include // metadata layout is shared between maple compiler and runtime, thus not in namespace maplert -#ifdef __cplusplus -extern "C" { -#endif // data types for address offset #ifdef USE_32BIT_REF using AddrOffset = int32_t; #else -using AddrOffset = int64_t; +using AddrOffset = intptr_t; #endif // some of the reference field of metadata is stored as relative offset @@ -33,14 +30,10 @@ using AddrOffset = int64_t; // which can be negative #ifdef USE_32BIT_REF using MetaRef = uint32_t; // consistent with reffield_t in address.h -using MetaRefOffset = int32_t; #else -using MetaRef = uintptr_t; // consistent with reffield_t in address.h -using MetaRefOffset = int64_t; +using MetaRef = uintptr_t; // consistent iwth reffield_t in address.h #endif // USE_32BIT_REF -using MetadataRelOffset = MetaRefOffset; - static inline void *DecodeValueAsRelOffset32(const int32_t *addr) { intptr_t realAddr = reinterpret_cast(addr) + *addr; return reinterpret_cast(realAddr); @@ -51,11 +44,6 @@ static inline void *DecodeValueAsRelOffset64(const int64_t *addr) { return reinterpret_cast(realAddr); } -static inline void *DecodeValueAsMetadataRelOffset(const MetadataRelOffset *addr) { - intptr_t realAddr = reinterpret_cast(addr) + *addr; - return reinterpret_cast(realAddr); -} - static inline void EncodeValueAsRelOffset32(const void *value, int32_t *addr) { int32_t offset = reinterpret_cast(value) - reinterpret_cast(addr); *addr = offset; @@ -72,21 +60,133 @@ static inline void EncodeValueAsRelOffset64(const void *value, int64_t *addr) { } } -static inline void EncodeValueAsMetadataRelOffset(const void *value, MetadataRelOffset *addr) { - MetadataRelOffset offset = reinterpret_cast(value) - reinterpret_cast(addr); - *addr = offset; - if (DecodeValueAsMetadataRelOffset(addr) != value) { - std::abort(); +template +struct BaseDataRefOffset { + INT refOffset; + + void* DecodeDataRef() const { + intptr_t ref = static_cast(refOffset); + ref += reinterpret_cast(this); + return reinterpret_cast(ref); } -} +}; -inline void MRTSetMetaRefOffset(MetaRefOffset *pOffset, char *addr) { - (*pOffset) = (MetaRefOffset)(addr - reinterpret_cast(pOffset)); -} +// specialized for int32_t, check for out-of-boundary +struct DataRefOffset32 : public BaseDataRefOffset { + void EncodeDataRef(void* ref) { + intptr_t offset = reinterpret_cast(ref) - reinterpret_cast(this); + if (INT32_MIN <= offset && offset <= INT32_MAX) { + refOffset = static_cast(offset); + } else { + std::abort(); + } + } +}; -inline void *MRTGetAddressFromMetaRefOffset(MetaRefOffset *pOffset) { - return reinterpret_cast(reinterpret_cast(pOffset) + (*pOffset)); -} +// DataRefOffset is meant to have pointer size. +struct DataRefOffset : public BaseDataRefOffset { + void EncodeDataRef(void* ref) { + refOffset = reinterpret_cast(ref) - reinterpret_cast(this); + } +}; + +/* DataRef aims for reference to data generated by maple compiler. + DataRef field allows 4 formats of value: + 0. "label_name" for direct reference + 1. "label_name - . + 2" for historical compact metadata reference + 2. "label_name - . + 1" for reference in offset format + 3. "indirect.label_name - . + 3" for indirect reference + this format aims to support lld which does not support expression "global_symbol - ." + DataRef is self-decoded by also encoding the format and is declared for binary compatibility. + If no compatibility problem is involved, is preferred. + */ + +enum DataRefFormat { + kDataRefIsDirect = 0, + kDataRefIsCompact = 1, // read-only + kDataRefIsOffset = 2, + kDataRefIsIndirect = 3, // read-only + kDataRefBitMask = 3, +}; + +template +struct BaseDataRef { + INT refVal; + + void* DecodeDataRef() const { + intptr_t ref = static_cast(refVal); + intptr_t format = refVal & kDataRefBitMask; + switch (format) { + case kDataRefIsDirect: return reinterpret_cast(ref); + case kDataRefIsOffset: { + ref += reinterpret_cast(this); + return reinterpret_cast(ref); + } + case kDataRefIsCompact: return reinterpret_cast(ref); // TODO + case kDataRefIsIndirect: { + ref += reinterpret_cast(this); + void **pRef = reinterpret_cast(ref); + return *pRef; + } + } + } +}; + +// specialized for int32_t, check for out-of-boundary +struct DataRef32 : public BaseDataRef { + void EncodeDataRef(void* ref, DataRefFormat format) { + intptr_t val = reinterpret_cast(ref); + switch (format) { + case kDataRefIsDirect: { + if (INT32_MIN <= val && val <= INT32_MAX) { + refVal = static_cast(val); + return; + } else { + std::abort(); + } + } + case kDataRefIsOffset: { + intptr_t offset = val - reinterpret_cast(this); + if ((offset & kDataRefBitMask) == 0 && INT32_MIN <= refVal && refVal <= INT32_MAX) { + refVal = static_cast(offset) | kDataRefIsOffset; + return; + } else { + std::abort(); + } + } + case kDataRefIsCompact: + case kDataRefIsIndirect: { + std::abort(); + } + } + } +}; + +// DataRef is meant to have pointer size. +struct DataRef : public BaseDataRef { + void EncodeDataRef(void* ref, DataRefFormat format) { + intptr_t val = reinterpret_cast(ref); + switch (format) { + case kDataRefIsDirect: { + refVal = val; + return; + } + case kDataRefIsOffset: { + intptr_t offset = val - reinterpret_cast(this); + if ((offset & kDataRefBitMask) == 0) { + refVal = offset | kDataRefIsOffset; + return; + } else { + std::abort(); + } + } + case kDataRefIsCompact: + case kDataRefIsIndirect: { + std::abort(); + } + } + } +}; // MethodMeta defined in MethodMeta.h // FieldMeta defined in FieldMeta.h @@ -211,10 +311,6 @@ static inline intptr_t ClassMetadataOffsetOfInitFlag() { return reinterpret_cast(&(base->initState)); } -#ifdef __cplusplus -} -#endif - // function to set Class/Field/Method metadata's shadow field to avoid type conversion // Note 1: here we don't do NULL-check and type-compatibility check // NOte 2: C should be of jclass/ClassMetata* type @@ -223,13 +319,4 @@ static inline void MRTSetMetadataShadow(M *meta, C cls) { meta->shadow = (MetaRef)(uintptr_t)cls; } -// help function to set Field/Method's declaringclass field to avoid type conversion -// Note: here we don't do NULL-check and type-compatibility check -// Note: Declaring class is encoded as relative offset which can be negative -// Note: here declaring class is stored as an offset rather than a raw pointer -template -static inline void MRTSetMetadataDeclaringClass(M *meta, C cls) { - meta->declaringclass = (MetaRefOffset)(intptr_t)cls; -} - #endif // METADATA_LAYOUT_H diff --git a/src/maple_ir/include/mir_module.h b/src/maple_ir/include/mir_module.h index 0b08be608e1e750572246a2c88cddc0e6c85fd77..2f577b1758ffd5ceb44c8da123770458a3cd50a7 100644 --- a/src/maple_ir/include/mir_module.h +++ b/src/maple_ir/include/mir_module.h @@ -47,7 +47,6 @@ enum MIRFlavor { enum MIRSrcLang { kSrcLangUnknown, kSrcLangC, kSrcLangJs, kSrcLangJava, kSrcLangCPlusPlus }; - // blksize gives the size of the memory block in bytes; there are (blksize+3)/4 // words; 1 bit for each word, so the bit vector's length in bytes is // ((blksize+3)/4+7)/8 @@ -513,7 +512,6 @@ class MIRModule { // and writes to all field id otherwise, it writes the field ids in MapleSet MapleMap*> puIdxFieldInitializedMap; }; - #endif // MIR_FEATURE_FULL } // namespace maple #endif // MAPLE_IR_INCLUDE_MIR_MODULE_H diff --git a/src/maple_ir/include/mir_nodes.h b/src/maple_ir/include/mir_nodes.h index 91b56a0268136d7161a1a13c63d4f1a813763715..f2c1b2c526a05a57143411569f2750fcd77007e9 100644 --- a/src/maple_ir/include/mir_nodes.h +++ b/src/maple_ir/include/mir_nodes.h @@ -1428,7 +1428,7 @@ class StmtNode : public BaseNode, public PtrListNodeBase { stmtID = id; } - StmtNode *GetRealNext(); + StmtNode *GetRealNext() const; protected: SrcPosition srcPosition; @@ -2153,7 +2153,7 @@ class BlockNode : public StmtNode { void AppendStatementsFromBlock(BlockNode &blk); void InsertFirst(StmtNode *stmt); // Insert stmt as the first void InsertLast(StmtNode *stmt); // Insert stmt as the last - void ReplaceStmtWithBlock(StmtNode *stmtNode, BlockNode &blk); + void ReplaceStmtWithBlock(StmtNode &stmtNode, BlockNode &blk); void ReplaceStmt1WithStmt2(StmtNode *stmtNode1, StmtNode *stmtNode2); void RemoveStmt(StmtNode *stmtNode2); void InsertBefore(StmtNode *stmtNode1, StmtNode *stmtNode2); // Insert ss2 before ss1 in current block. diff --git a/src/maple_ir/include/mir_parser.h b/src/maple_ir/include/mir_parser.h index 8b0232a9128f7c8a444c2c9957fa265e89f771eb..ac416d6ebd8a016bdfcb39db53447001bbcd1024 100644 --- a/src/maple_ir/include/mir_parser.h +++ b/src/maple_ir/include/mir_parser.h @@ -39,6 +39,7 @@ class MIRParser { firstLineNum(0), maxPregNo(0), paramParseLocalType(false), + paramFileIdx(0), paramIsIPA(false), paramIsComb(false), paramTokenKind(kTkInvalid), @@ -68,7 +69,7 @@ class MIRParser { bool IsStatement(TokenKind tk) const; PrimType GetPrimitiveType(TokenKind tk) const; MIRIntrinsicID GetIntrinsicId(TokenKind tk) const; - bool ParseScalarValue(MIRConstPtr&, MIRType*); + bool ParseScalarValue(MIRConstPtr&, MIRType&); bool ParseConstAddrLeafExpr(MIRConstPtr&, MIRType&); bool ParseInitValue(MIRConstPtr&, TyIdx); bool ParseDeclaredSt(StIdx&); @@ -89,7 +90,7 @@ class MIRParser { bool ParsePragmaElementForAnnotation(MIRPragmaElement &elem); bool ParsePragma(MIRStructType &type); bool ParseFields(MIRStructType &type); - bool ParseStructType(TyIdx &tyIdx); + bool ParseStructType(TyIdx &styIdx); bool ParseClassType(TyIdx &tyIdx); bool ParseInterfaceType(TyIdx &tyIdx); bool ParseDefinedTypename(TyIdx &tyIdx, MIRTypeKind kind = kTypeUnknown); diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index 33c9bc281514f02559a7c8608f09b848791290e0..9f07b5226ef9a6f1c5f49eacfbf646214bb47853 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -41,6 +41,7 @@ extern uint32 GetPrimTypeP2Size(PrimType primType); // ans extern const char *GetPrimTypeName(PrimType primType); extern const char *GetPrimTypeJavaName(PrimType primType); inline uint32 GetPrimTypeBitSize(PrimType primType) { + // 1 byte = 8 bits = 2^3 bits return GetPrimTypeSize(primType) << 3; } @@ -501,8 +502,8 @@ class MIRType { virtual std::string GetCompactMplTypeName() const; virtual bool PointsToConstString() const; virtual size_t GetHashIndex() const { - constexpr uint8 kIdxShift = 2; - return ((static_cast(primType) << kIdxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; + constexpr uint8 idxShift = 2; + return ((static_cast(primType) << idxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; } protected: @@ -544,8 +545,8 @@ class MIRPtrType : public MIRType { TyIdxFieldAttrPair GetPointedTyIdxFldAttrPairWithFieldID(FieldID fieldID) const; TyIdx GetPointedTyIdxWithFieldID(FieldID fieldID) const; size_t GetHashIndex() const override { - constexpr uint8 kIdxShift = 4; - return ((pointedTyIdx.GetIdx() << kIdxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; + constexpr uint8 idxShift = 4; + return ((pointedTyIdx.GetIdx() << idxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; } bool PointsToConstString() const override; @@ -635,8 +636,8 @@ class MIRArrayType : public MIRType { } size_t GetHashIndex() const override { - constexpr uint8 kIdxShift = 2; - size_t hidx = (eTyIdx.GetIdx() << kIdxShift) + (typeKind << kShiftNumOfTypeKind); + constexpr uint8 idxShift = 2; + size_t hidx = (eTyIdx.GetIdx() << idxShift) + (typeKind << kShiftNumOfTypeKind); for (size_t i = 0; i < dim; i++) { CHECK_FATAL(i < kMaxArrayDim, "array index out of range"); hidx += sizeArray[i] << i; @@ -681,8 +682,8 @@ class MIRFarrayType : public MIRType { void Dump(int indent, bool dontUseName = false) const override; size_t GetHashIndex() const override { - constexpr uint8 kIdxShift = 5; - return ((elemTyIdx.GetIdx() << kIdxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; + constexpr uint8 idxShift = 5; + return ((elemTyIdx.GetIdx() << idxShift) + (typeKind << kShiftNumOfTypeKind)) % kTypeHashLength; } std::string GetMplTypeName() const override; @@ -1014,13 +1015,11 @@ class MIRJarrayType : public MIRFarrayType { typeKind = kTypeJArray; }; - explicit MIRJarrayType(TyIdx elemTyIdx) - : MIRFarrayType(elemTyIdx) { + explicit MIRJarrayType(TyIdx elemTyIdx) : MIRFarrayType(elemTyIdx) { typeKind = kTypeJArray; } - explicit MIRJarrayType(GStrIdx strIdx) - : MIRFarrayType(strIdx) { + explicit MIRJarrayType(GStrIdx strIdx) : MIRFarrayType(strIdx) { typeKind = kTypeJArray; } @@ -1032,6 +1031,7 @@ class MIRJarrayType : public MIRFarrayType { MIRStructType *GetParentType(); const std::string &GetJavaName(void); + bool IsPrimitiveArray() { if (javaNameStrIdx == 0) { DetermineName(); @@ -1169,7 +1169,7 @@ class MIRClassType : public MIRStructType { FieldID GetFirstLocalFieldID() const; // return class id or superclass id accroding to input string MIRClassType *GetExceptionRootType(); - bool IsExceptionType(); + bool IsExceptionType() const; void AddImplementedInterface(TyIdx interfaceTyIdx) { if (std::find(interfacesImplemented.begin(), interfacesImplemented.end(), interfaceTyIdx) != interfacesImplemented.end()) { diff --git a/src/maple_ir/include/opcode_info.h b/src/maple_ir/include/opcode_info.h index 357e2fe2f246a00957577a73eccd12aec13a7f3c..21013d496f7ba251106f5fc236a985dd24db4069 100644 --- a/src/maple_ir/include/opcode_info.h +++ b/src/maple_ir/include/opcode_info.h @@ -46,6 +46,7 @@ constexpr unsigned long OPCODEISCALL(1ULL << kOpcodePropIsCall); constexpr unsigned long OPCODEISCALLASSIGNED(1ULL << kOpcodePropIsCallAssigned); constexpr unsigned long OPCODENOTPURE(1ULL << kOpcodePropNotPure); constexpr unsigned long OPCODEMAYTHROWEXCEPTION(1ULL << kOpcodePropMayThrowException); + struct OpcodeDesc { uint8 instrucSize; // size of instruction in bytes uint16 flag; // stores the opcode property flags diff --git a/src/maple_ir/include/parser_opt.h b/src/maple_ir/include/parser_opt.h index 33cc2cf8793a7ecb577134dc3e8c1e70de6eae12..05f49d49c69bd306279e678ec310e000204cb934 100644 --- a/src/maple_ir/include/parser_opt.h +++ b/src/maple_ir/include/parser_opt.h @@ -18,7 +18,7 @@ namespace maple { // option bits passed into ParseMIR -enum ParserOptions: uint8 { +enum ParserOptions : uint8 { kInvalidOption = 0x0, kWithDbgInfo = 0x1, // collect dbginfo kKeepFirst = 0x2, // ignore second type def, not emit error diff --git a/src/maple_ir/include/prim_types.h b/src/maple_ir/include/prim_types.h index 4f1c49202abb6c5cc508730a2ad8fd3dc01b62ab..a4e7d92d7c909c2ce070b6c72140d00baf4b7630 100644 --- a/src/maple_ir/include/prim_types.h +++ b/src/maple_ir/include/prim_types.h @@ -20,6 +20,7 @@ namespace maple { class PrimitiveType { public: + // we need implicit conversion from PrimType to PrimitiveType, so there is no explicit keyword here. PrimitiveType(PrimType type) { property = &GetPrimitiveTypeProperty(type); } diff --git a/src/maple_ir/src/mir_const.cpp b/src/maple_ir/src/mir_const.cpp index 4ea8d374e154c37d56653f3441576490bbaa8f94..bedd6f3e465334bc75820b3d8cad7befc56a28ff 100644 --- a/src/maple_ir/src/mir_const.cpp +++ b/src/maple_ir/src/mir_const.cpp @@ -42,8 +42,11 @@ bool MIRIntConst::operator==(MIRConst &rhs) const { if (&rhs == this) { return true; } - MIRIntConst *intConst = dynamic_cast(&rhs); - return (intConst && (&intConst->GetType() == &GetType()) && (intConst->value == value)); + if (GetKind() != rhs.GetKind()) { + return false; + } + auto &intConst = static_cast(rhs); + return ((&intConst.GetType() == &GetType()) && (intConst.value == value)); } void MIRAddrofConst::Dump() const { @@ -61,14 +64,14 @@ bool MIRAddrofConst::operator==(MIRConst &rhs) const { if (&rhs == this) { return true; } - MIRAddrofConst *rhsA = dynamic_cast(&rhs); - if (rhsA == nullptr) { + if (GetKind() != rhs.GetKind()) { return false; } + auto &rhsA = static_cast(rhs); if (&GetType() != &rhs.GetType()) { return false; } - return (stIdx == rhsA->stIdx && fldID == rhsA->fldID); + return (stIdx == rhsA.stIdx && fldID == rhsA.fldID); } void MIRAddroffuncConst::Dump() const { @@ -82,64 +85,67 @@ bool MIRAddroffuncConst::operator==(MIRConst &rhs) const { if (&rhs == this) { return true; } - MIRAddroffuncConst *rhsAf = dynamic_cast(&rhs); - if (rhsAf == nullptr) { + if (GetKind() != rhs.GetKind()) { return false; } - return (&GetType() == &rhs.GetType() && puIdx == rhsAf->puIdx); + auto &rhsAf = static_cast(rhs); + return (&GetType() == &rhs.GetType() && puIdx == rhsAf.puIdx); } bool MIRLblConst::operator==(MIRConst &rhs) const { if (&rhs == this) { return true; } - MIRLblConst *lblConst = dynamic_cast(&rhs); - return (lblConst && (lblConst->value == value)); + if (GetKind() != rhs.GetKind()) { + return false; + } + auto &lblConst = static_cast(rhs); + return (lblConst.value == value); } bool MIRFloatConst::operator==(MIRConst &rhs) const { if (&rhs == this) { return true; } - MIRFloatConst *floatConst = dynamic_cast(&rhs); - if (floatConst == nullptr) { + if (GetKind() != rhs.GetKind()) { return false; } - if (std::isnan(floatConst->value.floatValue)) { + auto &floatConst = static_cast(rhs); + if (std::isnan(floatConst.value.floatValue)) { return std::isnan(value.floatValue); } if (std::isnan(value.floatValue)) { - return std::isnan(floatConst->value.floatValue); + return std::isnan(floatConst.value.floatValue); } - return (fabs(floatConst->value.floatValue - value.floatValue) <= 1e-6); + return (fabs(floatConst.value.floatValue - value.floatValue) <= 1e-6); } bool MIRDoubleConst::operator==(MIRConst &rhs) const { if (&rhs == this) { return true; } - MIRDoubleConst *floatConst = dynamic_cast(&rhs); - if (floatConst == nullptr) { + if (GetKind() != rhs.GetKind()) { return false; } - if (std::isnan(floatConst->value.dValue)) { + auto &floatConst = static_cast(rhs); + if (std::isnan(floatConst.value.dValue)) { return std::isnan(value.dValue); } if (std::isnan(value.dValue)) { - return std::isnan(floatConst->value.dValue); + return std::isnan(floatConst.value.dValue); } - return (fabs(floatConst->value.dValue - value.dValue) <= 1e-15); + return (fabs(floatConst.value.dValue - value.dValue) <= 1e-15); } bool MIRFloat128Const::operator==(MIRConst &rhs) const { if (&rhs == this) { return true; } - MIRFloat128Const *floatConst = dynamic_cast(&rhs); - if (floatConst == nullptr) { + if (GetKind() != rhs.GetKind()) { return false; } - if ((value[0] == floatConst->value[0]) && (value[1] == floatConst->value[1])) { + auto &floatConst = static_cast(rhs); + if ((value[0] == floatConst.value[0]) && (value[1] == floatConst.value[1])) { return true; } return false; @@ -149,15 +155,15 @@ bool MIRAggConst::operator==(MIRConst &rhs) const { if (&rhs == this) { return true; } - MIRAggConst *aggregateConst = dynamic_cast(&rhs); - if (aggregateConst == nullptr) { + if (GetKind() != rhs.GetKind()) { return false; } - if (aggregateConst->constVec.size() != constVec.size()) { + auto &aggregateConst = static_cast(rhs); + if (aggregateConst.constVec.size() != constVec.size()) { return false; } for (size_t i = 0; i < constVec.size(); ++i) { - if (!(*aggregateConst->constVec[i] == *constVec[i])) { + if (!(*aggregateConst.constVec[i] == *constVec[i])) { return false; } } @@ -213,11 +219,11 @@ bool MIRStrConst::operator==(MIRConst &rhs) const { if (&rhs == this) { return true; } - MIRStrConst *rhsCs = dynamic_cast(&rhs); - if (rhsCs == nullptr) { + if (GetKind() != rhs.GetKind()) { return false; } - return (&rhs.GetType() == &GetType() && value == rhsCs->value); + auto &rhsCs = static_cast(rhs); + return (&rhs.GetType() == &GetType() && value == rhsCs.value); } MIRStr16Const::MIRStr16Const(const std::u16string &str, MIRType &type) @@ -239,11 +245,11 @@ bool MIRStr16Const::operator==(MIRConst &rhs) const { if (&rhs == this) { return true; } - MIRStr16Const *rhsCs = dynamic_cast(&rhs); - if (rhsCs == nullptr) { + if (GetKind() != rhs.GetKind()) { return false; } - return (&GetType() == &rhs.GetType() && value == rhsCs->value); + auto &rhsCs = static_cast(rhs); + return (&GetType() == &rhs.GetType() && value == rhsCs.value); } } // namespace maple #endif // MIR_FEATURE_FULL diff --git a/src/maple_ir/src/mir_nodes.cpp b/src/maple_ir/src/mir_nodes.cpp index a4dbe2c806abceb698837a3eae4fd03f4eac2f0f..0b700924225fe1dda37fb82f57c7dbdad6858194 100644 --- a/src/maple_ir/src/mir_nodes.cpp +++ b/src/maple_ir/src/mir_nodes.cpp @@ -56,10 +56,11 @@ bool BaseNode::MayThrowException() { return true; } } - for (size_t i = 0; i < NumOpnds(); i++) + for (size_t i = 0; i < NumOpnds(); i++) { if (Opnd(i)->MayThrowException()) { return true; } + } return false; } @@ -156,10 +157,10 @@ void BlockNode::InsertLast(StmtNode *stmt) { stmtNodeList.push_back(stmt); } -void BlockNode::ReplaceStmtWithBlock(StmtNode *stmtNode, BlockNode &blk) { - stmtNodeList.splice(stmtNode, blk.GetStmtNodes()); - stmtNodeList.erase(stmtNode); - stmtNode->SetNext(blk.GetLast()->GetNext()); +void BlockNode::ReplaceStmtWithBlock(StmtNode &stmtNode, BlockNode &blk) { + stmtNodeList.splice(&stmtNode, blk.GetStmtNodes()); + stmtNodeList.erase(&stmtNode); + stmtNode.SetNext(blk.GetLast()->GetNext()); } void BlockNode::ReplaceStmt1WithStmt2(StmtNode *stmtNode1, StmtNode *stmtNode2) { @@ -562,7 +563,7 @@ void StmtNode::Dump(const MIRModule &mod) const { } // Get the next stmt skip the comment stmt. -StmtNode *StmtNode::GetRealNext() { +StmtNode *StmtNode::GetRealNext() const { StmtNode *stmt = this->GetNext(); while (stmt != nullptr) { if (stmt->GetOpCode() != OP_comment) { @@ -599,7 +600,7 @@ void DassignNode::Dump(const MIRModule &mod, int32 indent) const { LogInfo::MapleLogger() << (st->IsLocal() ? " %" : " $"); LogInfo::MapleLogger() << st->GetName() << " " << fieldID; LogInfo::MapleLogger() << " ("; - if (GetRHS()) { + if (GetRHS() != nullptr) { GetRHS()->Dump(mod, indent + 1); } else { LogInfo::MapleLogger() << "/*empty-rhs*/"; @@ -1503,8 +1504,8 @@ bool ExtractbitsNode::Verify() const { bool opndTypeVerf = ArithTypeVerify(*Opnd()); bool compVerf = CompatibleTypeVerify(*Opnd(), *this); bool resTypeVerf = UnaryTypeVerify0(GetPrimType()); - constexpr int kNumBitsInByte = 8; - bool opnd0SizeVerf = (kNumBitsInByte * GetPrimTypeSize(Opnd()->GetPrimType()) >= bitsSize); + constexpr int numBitsInByte = 8; + bool opnd0SizeVerf = (numBitsInByte * GetPrimTypeSize(Opnd()->GetPrimType()) >= bitsSize); if (!opnd0SizeVerf) { LogInfo::MapleLogger() << "\n#Error: The operand of extractbits must be large enough to contain the specified bitfield\n"; @@ -1574,8 +1575,8 @@ bool CompareNode::Verify() const { bool DepositbitsNode::Verify() const { bool opndsVerf = BinaryGenericVerify(*GetBOpnd(0), *GetBOpnd(1)); bool resTypeVerf = IntTypeVerify(GetPrimType()); - constexpr int kNumBitsInByte = 8; - bool opnd0SizeVerf = (kNumBitsInByte * GetPrimTypeSize(GetBOpnd(0)->GetPrimType()) >= bitsSize); + constexpr int numBitsInByte = 8; + bool opnd0SizeVerf = (numBitsInByte * GetPrimTypeSize(GetBOpnd(0)->GetPrimType()) >= bitsSize); if (!opnd0SizeVerf) { LogInfo::MapleLogger() << "\n#Error:opnd0 of depositbits must be large enough to contain the specified bitfield\n"; } @@ -1769,10 +1770,10 @@ bool IfStmtNode::Verify() const { bool condVerf = Opnd()->Verify(); bool thenVerf = true; bool elseVerf = true; - if (thenPart) { + if (thenPart != nullptr) { thenVerf = thenPart->Verify(); } - if (elsePart) { + if (elsePart != nullptr) { elseVerf = elsePart->Verify(); } return condVerf && thenVerf && elseVerf; @@ -1781,7 +1782,7 @@ bool IfStmtNode::Verify() const { bool WhileStmtNode::Verify() const { bool condVerf = Opnd()->Verify(); bool bodyVerf = true; - if (body) { + if (body != nullptr) { bodyVerf = body->Verify(); } return condVerf && bodyVerf; diff --git a/src/maple_ir/src/mir_parser.cpp b/src/maple_ir/src/mir_parser.cpp index ab1c688ffa647a9d7aae426b56ccc5cb57befd06..c52195e2efcc1cb83cf8ef771ca958fdb08b39a5 100644 --- a/src/maple_ir/src/mir_parser.cpp +++ b/src/maple_ir/src/mir_parser.cpp @@ -669,8 +669,8 @@ bool MIRParser::ParseStmtMultiway(StmtNodePtr &stmt) { multiwaynode->AppendElemToMultiWayTable(MCasePair(static_cast(x), lblIdx)); tk = lexer.GetTokenKind(); } - const MapleVector &multiwaytable = multiwaynode->GetMultiWayTable(); - multiwaynode->SetNumOpnds(multiwaytable.size()); + const MapleVector &multiWayTable = multiwaynode->GetMultiWayTable(); + multiwaynode->SetNumOpnds(multiWayTable.size()); lexer.NextToken(); return true; } @@ -739,7 +739,8 @@ bool MIRParser::ParseStmtCall(StmtNodePtr &stmt) { case TK_interfacecallinstantassigned: hasinstant = true; break; - default:; + default: + break; } TyIdx polymophictyidx(0); if (o == OP_polymorphiccallassigned || o == OP_polymorphiccall) { @@ -776,7 +777,7 @@ bool MIRParser::ParseStmtCall(StmtNodePtr &stmt) { } lexer.NextToken(); CallNode *callstmt = nullptr; - CallinstantNode *callinstantstmt = nullptr; + CallinstantNode *callInstantStmt = nullptr; if (withtype) { callstmt = mod.CurFuncCodeMemPool()->New(mod, o); callstmt->SetTyIdx(polymophictyidx); @@ -802,8 +803,8 @@ bool MIRParser::ParseStmtCall(StmtNodePtr &stmt) { return false; } TyIdx tyidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&instvecty); - callinstantstmt = mod.CurFuncCodeMemPool()->New(mod, o, tyidx); - callstmt = callinstantstmt; + callInstantStmt = mod.CurFuncCodeMemPool()->New(mod, o, tyidx); + callstmt = callInstantStmt; lexer.NextToken(); // skip the > } else { callstmt = mod.CurFuncCodeMemPool()->New(mod, o); @@ -824,8 +825,8 @@ bool MIRParser::ParseStmtCall(StmtNodePtr &stmt) { ASSERT(callstmt != nullptr, "callstmt is null in MIRParser::ParseStmtCall"); callstmt->SetReturnVec(retsvec); } else { - ASSERT(callinstantstmt != nullptr, "callinstantstmt is null in MIRParser::ParseStmtCall"); - callinstantstmt->SetReturnVec(retsvec); + ASSERT(callInstantStmt != nullptr, "callinstantstmt is null in MIRParser::ParseStmtCall"); + callInstantStmt->SetReturnVec(retsvec); } } lexer.NextToken(); @@ -1853,7 +1854,7 @@ bool MIRParser::ParseExprConstval(BaseNodePtr &expr) { exprconst->SetPrimType(GetPrimitiveType(typeTk)); lexer.NextToken(); MIRConst *constval = nullptr; - if (!ParseScalarValue(constval, GlobalTables::GetTypeTable().GetPrimType(exprconst->GetPrimType()))) { + if (!ParseScalarValue(constval, *GlobalTables::GetTypeTable().GetPrimType(exprconst->GetPrimType()))) { Error("expect scalar type but get "); return false; } @@ -2580,14 +2581,14 @@ bool MIRParser::ParseExprIntrinsicop(BaseNodePtr &expr) { return true; } -bool MIRParser::ParseScalarValue(MIRConstPtr &stype, MIRType *type) { - PrimType ptp = type->GetPrimType(); +bool MIRParser::ParseScalarValue(MIRConstPtr &stype, MIRType &type) { + PrimType ptp = type.GetPrimType(); if (IsPrimitiveInteger(ptp) || IsPrimitiveDynType(ptp) || ptp == PTY_gen) { if (lexer.GetTokenKind() != kTkIntconst) { Error("constant value incompatible with integer type at "); return false; } - stype = mod.GetMemPool()->New(lexer.GetTheIntVal(), *type); + stype = mod.GetMemPool()->New(lexer.GetTheIntVal(), type); } else if (ptp == PTY_f32) { if (lexer.GetTokenKind() != kTkFloatconst) { Error("constant value incompatible with single-precision float type at "); diff --git a/src/maple_ir/src/mir_type.cpp b/src/maple_ir/src/mir_type.cpp index b6ffd4c02c186451055f8f661d7e18aa82fab025..dc0a6f3d22e4dc6562646793925214e4ce50835f 100644 --- a/src/maple_ir/src/mir_type.cpp +++ b/src/maple_ir/src/mir_type.cpp @@ -91,10 +91,12 @@ PrimType GetDynType(PrimType pType) { return PTY_dynf32; case PTY_f64: return PTY_dynf64; - default:; + default: + return pType; } -#endif +#else return pType; +#endif } PrimType GetNonDynType(PrimType pType) { @@ -112,10 +114,12 @@ PrimType GetNonDynType(PrimType pType) { return PTY_f32; case PTY_dynf64: return PTY_f64; - default:; + default: + return pType; } -#endif +#else return pType; +#endif } bool IsNoCvtNeeded(PrimType toType, PrimType fromType) { @@ -221,7 +225,6 @@ uint32 GetPrimTypeP2Size(PrimType primType) { case PTY_dynundef: case PTY_dynnull: case PTY_dynbool: - return 3; case PTY_dynany: case PTY_dynf64: return 3; @@ -235,7 +238,6 @@ uint32 GetPrimTypeP2Size(PrimType primType) { const char *GetPrimTypeName(PrimType primType) { #define LOAD_ALGO_PRIMARY_TYPE switch (primType) { - default: case kPtyInvalid: return "kPtyInvalid"; #define PRIMTYPE(P) \ @@ -245,6 +247,8 @@ const char *GetPrimTypeName(PrimType primType) { #undef PRIMTYPE case kPtyDerived: return "derived"; // just for test: no primitive type for derived + default: + return "kPtyInvalid"; } // SIMD types to be defined } @@ -306,7 +310,7 @@ void FieldAttrs::DumpAttributes() const { } } -const std::string &MIRType::GetName(void) const { +const std::string &MIRType::GetName() const { return GlobalTables::GetStrTable().GetStringFromStrIdx(nameStrIdx); } @@ -514,7 +518,7 @@ std::string MIRFarrayType::GetCompactMplTypeName() const { return ss.str(); } -const std::string &MIRJarrayType::GetJavaName(void) { +const std::string &MIRJarrayType::GetJavaName() { if (javaNameStrIdx == 0) { DetermineName(); } @@ -544,18 +548,17 @@ void MIRJarrayType::DetermineName() { fromPrimitive = true; break; } else if (elemType->GetKind() == kTypePointer) { - MIRType *ptype = static_cast(elemType)->GetPointedType(); - ASSERT(ptype, "ptype is null in MIRJarrayType::DetermineName"); + auto *ptype = static_cast(elemType)->GetPointedType(); + ASSERT(ptype != nullptr, "ptype is null in MIRJarrayType::DetermineName"); if (ptype->GetKind() == kTypeByName || ptype->GetKind() == kTypeClass || ptype->GetKind() == kTypeInterface || ptype->GetKind() == kTypeClassIncomplete || ptype->GetKind() == kTypeInterfaceIncomplete) { baseName = static_cast(ptype)->GetName(); fromPrimitive = false; break; - } else if (ptype->GetKind() == kTypeArray || ptype->GetKind() == kTypeJArray) { - MIRJarrayType *tmpPtype = dynamic_cast(ptype); - ASSERT(tmpPtype != nullptr, "null ptr check"); + } else if (ptype->GetKind() == kTypeJArray) { + auto *tmpPtype = static_cast(ptype); elemType = tmpPtype->GetElemType(); - ASSERT(elemType, "elemType is null in MIRJarrayType::DetermineName"); + ASSERT(elemType != nullptr, "elemType is null in MIRJarrayType::DetermineName"); dim++; } else { ASSERT(false, "unexpected type!"); @@ -608,7 +611,7 @@ size_t MIRClassType::GetSize() const { if (parentTyIdx == 0) { return MIRStructType::GetSize(); } - MIRClassType *parentType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); + auto *parentType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); size_t parentSize = parentType->GetSize(); if (parentSize == 0) { return 0; @@ -621,16 +624,16 @@ size_t MIRClassType::GetSize() const { } FieldID MIRClassType::GetFirstLocalFieldID() const { - constexpr uint8 kLastFieldIDOffset = 2; - constexpr uint8 kFirstLocalFieldIDOffset = 1; + constexpr uint8 lastFieldIDOffset = 2; + constexpr uint8 firstLocalFieldIDOffset = 1; if (!IsLocal()) { return 0; } else if (parentTyIdx != 0) { MIRClassType *parentClassType = MIR_DYN_CAST(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx), MIRClassType*); ASSERT(parentClassType != nullptr, "null pointer check"); - return (!parentClassType->IsLocal()) ? parentClassType->GetLastFieldID() + kLastFieldIDOffset - : parentClassType->GetFirstLocalFieldID() + kFirstLocalFieldIDOffset; + return (!parentClassType->IsLocal()) ? parentClassType->GetLastFieldID() + lastFieldIDOffset + : parentClassType->GetFirstLocalFieldID() + firstLocalFieldIDOffset; } return 1; } @@ -645,9 +648,9 @@ MIRClassType *MIRClassType::GetExceptionRootType() { return subClassType; } -bool MIRClassType::IsExceptionType() { +bool MIRClassType::IsExceptionType() const { GStrIdx ehTypeNameIdx = GlobalTables::GetStrTable().GetStrIdxFromName("Ljava_2Flang_2FThrowable_3B"); - MIRClassType *parentClassType = this; + const MIRClassType *parentClassType = this; while (parentClassType != nullptr && parentClassType->nameStrIdx != ehTypeNameIdx) { parentClassType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentClassType->parentTyIdx)); @@ -714,7 +717,7 @@ size_t MIRInterfaceType::GetSize() const { return 0; } for (size_t i = 0; i < parentsTyIdx.size(); i++) { - MIRInterfaceType *parentType = + auto *parentType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentsTyIdx[i])); size_t parentSize = parentType->GetSize(); if (parentSize == 0) { @@ -739,9 +742,9 @@ static void DumpStaticValue(const MIREncodedArray &staticValue, int indent) { uint8 valueArg = static_cast(value.encodedValue[0]) >> typeLen; uint8 valueType = static_cast(value.encodedValue[0]) & typeMask; // kValueNull kValueBoolean - constexpr uint32 kSimpleOffset = 1; - constexpr uint32 kAggOffSet = 2; - valueArg = (valueType == kValueNull || valueType == kValueBoolean) ? kSimpleOffset : valueArg + kAggOffSet; + constexpr uint32 simpleOffset = 1; + constexpr uint32 aggOffSet = 2; + valueArg = (valueType == kValueNull || valueType == kValueBoolean) ? simpleOffset : valueArg + aggOffSet; for (uint32 k = 0; k < valueArg; k++) { LogInfo::MapleLogger() << static_cast(value.encodedValue[k]); if (k != static_cast(valueArg - 1)) { @@ -767,7 +770,8 @@ static void DumpFields(FieldVector fields, int indent, bool otherFields = false) const char *fieldName = GlobalTables::GetStrTable().GetStringFromStrIdx(fields[i].first).c_str(); MIRSymbol *fieldVar = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(GlobalTables::GetStrTable().GetStrIdxFromName(fieldName)); - if (fieldVar != nullptr && dynamic_cast(fieldVar->GetKonst())) { + if (fieldVar != nullptr && fieldVar->GetKonst() != nullptr && + fieldVar->GetKonst()->GetKind() == kConstStr16Const) { LogInfo::MapleLogger() << " = "; fieldVar->GetKonst()->Dump(); } @@ -803,7 +807,7 @@ static void DumpMethods(MethodVector methods, int indent) { LogInfo::MapleLogger() << "&" << GlobalTables::GetGsymTable().GetSymbolFromStidx(methods[i].first.Idx())->GetName(); methods[i].second.second.DumpAttributes(); LogInfo::MapleLogger() << " ("; - MIRFuncType *funcType = + auto *funcType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(methods[i].second.first)); size_t parmListSize = funcType->GetParamTypeList().size(); for (size_t j = 0; j < parmListSize; j++) { @@ -830,7 +834,7 @@ static void DumpConstructorsAsCxx(MethodVector methods, int indent) { if (!fa.GetAttr(FUNCATTR_constructor) || !fa.GetAttr(FUNCATTR_public)) { continue; } - MIRFuncType *funcType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(m.second.first)); + auto *funcType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(m.second.first)); PrintIndentation(indent); LogInfo::MapleLogger() << "/* &" << GlobalTables::GetGsymTable().GetSymbolFromStidx(m.first.Idx())->GetName(); fa.DumpAttributes(); @@ -965,8 +969,8 @@ bool MIRClassType::IsFinal() const { } bool MIRClassType::IsInner() const { - const std::string kName = GetName(); - return kName.find("_24") != std::string::npos; + const std::string name = GetName(); + return name.find("_24") != std::string::npos; } static void DumpInfoPragmaStaticValue(const std::vector &info, const std::vector &pragmaVec, @@ -1083,22 +1087,20 @@ bool MIRPtrType::EqualTo(const MIRType &type) const { if (typeKind != type.GetKind() || GetPrimType() != type.GetPrimType()) { return false; } - const MIRPtrType *pType = dynamic_cast(&type); - ASSERT(pType != nullptr, "null ptr check"); - return pointedTyIdx == pType->GetPointedTyIdx(); + const auto &pType = static_cast(type); + return pointedTyIdx == pType.GetPointedTyIdx(); } bool MIRArrayType::EqualTo(const MIRType &type) const { if (type.GetKind() != typeKind) { return false; } - const MIRArrayType *pType = dynamic_cast(&type); - ASSERT(pType != nullptr, "null ptr check"); - if (dim != pType->GetDim() || eTyIdx != pType->GetElemTyIdx()) { + const auto &pType = static_cast(type); + if (dim != pType.GetDim() || eTyIdx != pType.GetElemTyIdx()) { return false; } for (int i = 0; i < dim; i++) { - if (GetSizeArrayItem(i) != pType->GetSizeArrayItem(i)) { + if (GetSizeArrayItem(i) != pType.GetSizeArrayItem(i)) { return false; } } @@ -1126,9 +1128,8 @@ bool MIRFarrayType::EqualTo(const MIRType &type) const { if (type.GetKind() != typeKind) { return false; } - const MIRFarrayType *pType = dynamic_cast(&type); - ASSERT(pType, "make sure the elemTyIdx is not nullptr"); - return elemTyIdx == pType->GetElemTyIdx(); + const auto &pType = static_cast(type); + return elemTyIdx == pType.GetElemTyIdx(); } std::string MIRFarrayType::GetMplTypeName() const { @@ -1144,19 +1145,17 @@ bool MIRFuncType::EqualTo(const MIRType &type) const { if (type.GetKind() != typeKind) { return false; } - const MIRFuncType *pType = dynamic_cast(&type); - ASSERT(pType, "null ptr check"); - return (pType->retTyIdx == retTyIdx && pType->paramTypeList == paramTypeList && pType->isVarArgs == isVarArgs && - pType->paramAttrsList == paramAttrsList); + const auto &pType = static_cast(type); + return (pType.retTyIdx == retTyIdx && pType.paramTypeList == paramTypeList && pType.isVarArgs == isVarArgs && + pType.paramAttrsList == paramAttrsList); } bool MIRBitFieldType::EqualTo(const MIRType &type) const { if (type.GetKind() != typeKind || type.GetPrimType() != primType) { return false; } - const MIRBitFieldType *pType = dynamic_cast(&type); - ASSERT(pType != nullptr, "null ptr check"); - return pType->fieldSize == fieldSize; + const auto &pType = static_cast(type); + return pType.fieldSize == fieldSize; } bool MIRStructType::EqualTo(const MIRType &type) const { @@ -1208,18 +1207,16 @@ bool MIRInstantVectorType::EqualTo(const MIRType &type) const { if (type.GetKind() != typeKind) { return false; } - const MIRInstantVectorType *pty = dynamic_cast(&type); - ASSERT(pty, "null ptr check"); - return (instantVec == pty->GetInstantVec()); + const auto &pty = static_cast(type); + return (instantVec == pty.GetInstantVec()); } bool MIRGenericInstantType::EqualTo(const MIRType &type) const { if (!MIRInstantVectorType::EqualTo(type)) { return false; } - const MIRGenericInstantType *pType = dynamic_cast(&type); - ASSERT(pType, "null ptr check"); - return genericTyIdx == pType->GetGenericTyIdx(); + const auto &pType = static_cast(type); + return genericTyIdx == pType.GetGenericTyIdx(); } // in the search, curfieldid is being decremented until it reaches 1 @@ -1240,8 +1237,7 @@ FieldPair MIRStructType::TraverseToFieldRef(FieldID &fieldID) const { case kTypeClassIncomplete: case kTypeInterface: case kTypeInterfaceIncomplete: - curFieldStructType = dynamic_cast(curFieldType); - ASSERT(curFieldStructType != nullptr, "call cast failed"); + curFieldStructType = static_cast(curFieldType); curPair = curFieldStructType->TraverseToFieldRef(fieldID); if (fieldID == 1 && curPair.second.first != 0) { return curPair; @@ -1314,7 +1310,7 @@ bool MIRStructType::HasVolatileField() { // set hasVolatileField to true if parent type has volatile field, otherwise flase. static bool ParentTypeHasVolatileField(const TyIdx parentTyIdx, bool &hasVolatileField) { - hasVolatileField = (GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)->HasVolatileField()) ? true : false; + hasVolatileField = (GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)->HasVolatileField()); return hasVolatileField; } @@ -1396,7 +1392,7 @@ TyIdxFieldAttrPair MIRPtrType::GetPointedTyIdxFldAttrPairWithFieldID(FieldID fie } MIRStructType *structType = dynamic_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointedTyIdx)); - ASSERT(structType, + ASSERT(structType != nullptr, "MIRPtrType::GetPointedTyIdxWithFieldID(): cannot have non-zero fieldID for something other than a struct"); return structType->GetFieldTyIdxAttrPair(fieldID); } @@ -1409,7 +1405,7 @@ std::string MIRPtrType::GetMplTypeName() const { std::stringstream ss; ss << "<* "; MIRType *pointedType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointedTyIdx); - CHECK_FATAL(pointedType, "invalid ptr type"); + CHECK_FATAL(pointedType != nullptr, "invalid ptr type"); ss << pointedType->GetMplTypeName(); ss << ">"; return ss.str(); @@ -1417,7 +1413,7 @@ std::string MIRPtrType::GetMplTypeName() const { std::string MIRPtrType::GetCompactMplTypeName() const { MIRType *pointedType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointedTyIdx); - CHECK_FATAL(pointedType, "invalid ptr type"); + CHECK_FATAL(pointedType != nullptr, "invalid ptr type"); return pointedType->GetCompactMplTypeName(); } @@ -1431,10 +1427,10 @@ TypeAttrs FieldAttrs::ConvertToTypeAttrs() { FieldAttrKind tA = static_cast(i); switch (tA) { #define FIELD_ATTR -#define ATTR(STR) \ - case FLDATTR_##STR: \ - attr.SetAttr(ATTR_##STR); \ - break; +#define ATTR(STR) \ + case FLDATTR_##STR: \ + attr.SetAttr(ATTR_##STR); \ + break; #include "all_attributes.def" #undef ATTR #undef FIELD_ATTR @@ -1456,10 +1452,10 @@ TypeAttrs GenericAttrs::ConvertToTypeAttrs() { GenericAttrKind tA = static_cast(i); switch (tA) { #define TYPE_ATTR -#define ATTR(STR) \ - case GENATTR_##STR: \ - attr.SetAttr(ATTR_##STR); \ - break; +#define ATTR(STR) \ + case GENATTR_##STR: \ + attr.SetAttr(ATTR_##STR); \ + break; #include "all_attributes.def" #undef ATTR #undef TYPE_ATTR @@ -1481,10 +1477,10 @@ FuncAttrs GenericAttrs::ConvertToFuncAttrs() { GenericAttrKind tA = static_cast(i); switch (tA) { #define FUNC_ATTR -#define ATTR(STR) \ - case GENATTR_##STR: \ - attr.SetAttr(FUNCATTR_##STR); \ - break; +#define ATTR(STR) \ + case GENATTR_##STR: \ + attr.SetAttr(FUNCATTR_##STR); \ + break; #include "all_attributes.def" #undef ATTR #undef FUNC_ATTR @@ -1506,10 +1502,10 @@ FieldAttrs GenericAttrs::ConvertToFieldAttrs() { GenericAttrKind tA = static_cast(i); switch (tA) { #define FIELD_ATTR -#define ATTR(STR) \ - case GENATTR_##STR: \ - attr.SetAttr(FLDATTR_##STR); \ - break; +#define ATTR(STR) \ + case GENATTR_##STR: \ + attr.SetAttr(FLDATTR_##STR); \ + break; #include "all_attributes.def" #undef ATTR #undef FIELD_ATTR diff --git a/src/maple_ir/src/parser.cpp b/src/maple_ir/src/parser.cpp index 89b566b754b7385a99026f048e254c6ef75dbd6a..13db3f2cd0af9c17ad53abd58a424cd54a8931a5 100644 --- a/src/maple_ir/src/parser.cpp +++ b/src/maple_ir/src/parser.cpp @@ -98,11 +98,11 @@ bool MIRParser::IsDelimitationTK(TokenKind tk) const { } } -inline bool IsPowerOf2(uint64 i) { - if (i == 0) { +inline bool IsPowerOf2(uint64 num) { + if (num == 0) { return false; } - return (~(i - 1) & i) == i; + return (~(num - 1) & num) == num; } Opcode MIRParser::GetOpFromToken(TokenKind tk) const { @@ -146,8 +146,8 @@ MIRIntrinsicID MIRParser::GetIntrinsicId(TokenKind tk) const { switch (tk) { default: #define DEF_MIR_INTRINSIC(P, NAME, INTRN_CLASS, RETURN_TYPE, ...) \ - case TK_##P: \ - return INTRN_##P; + case TK_##P: \ + return INTRN_##P; #include "intrinsics.def" #undef DEF_MIR_INTRINSIC } @@ -549,12 +549,12 @@ bool MIRParser::ParsePragma(MIRStructType &type) { } p->SetStrIdx(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName())); tk = lexer.NextToken(); - TyIdx tyidx; - if (!ParseType(tyidx)) { + TyIdx tyIdx; + if (!ParseType(tyIdx)) { Error("parsing pragma error: wrong type "); return false; } - p->SetTyIdx(tyidx); + p->SetTyIdx(tyIdx); tk = lexer.GetTokenKind(); if (tk != kTkLbrace) { Error("parsing pragma error: expecting { but get "); @@ -590,6 +590,7 @@ bool MIRParser::ParseFields(MIRStructType &type) { Warning("incomplete class/interface type"); } TokenKind tk = lexer.NextToken(); + MIRTypeKind tyKind = type.GetKind(); while (tk == TK_label || tk == kTkPrntfield || tk == TK_pragma) { bool isPragma = tk == TK_pragma; bool notaType = false; @@ -601,8 +602,8 @@ bool MIRParser::ParseFields(MIRStructType &type) { GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); tk = lexer.NextToken(); if (isPragma) { - if (type.GetKind() == kTypeClass || type.GetKind() == kTypeClassIncomplete || type.GetKind() == kTypeInterface || - type.GetKind() == kTypeInterfaceIncomplete) { + if (tyKind == kTypeClass || tyKind == kTypeClassIncomplete || tyKind == kTypeInterface || + tyKind == kTypeInterfaceIncomplete) { if (!ParsePragma(type)) { Error("parsing pragma error "); return false; @@ -630,8 +631,8 @@ bool MIRParser::ParseFields(MIRStructType &type) { tk = lexer.NextToken(); } tk = lexer.NextToken(); - if (type.GetKind() == kTypeClass || type.GetKind() == kTypeClassIncomplete || - type.GetKind() == kTypeInterface || type.GetKind() == kTypeInterfaceIncomplete) { + if (tyKind == kTypeClass || tyKind == kTypeClassIncomplete || + tyKind == kTypeInterface || tyKind == kTypeInterfaceIncomplete) { type.PushbackStaticValue(elem); } else { Error("parsing staticvalue error "); @@ -655,8 +656,8 @@ bool MIRParser::ParseFields(MIRStructType &type) { return false; } } else if ((tk == kTkIntconst || tk == kTkString) && !isParentField && - (type.GetKind() == kTypeClass || type.GetKind() == kTypeClassIncomplete || - type.GetKind() == kTypeInterface || type.GetKind() == kTypeInterfaceIncomplete)) { + (tyKind == kTypeClass || tyKind == kTypeClassIncomplete || + tyKind == kTypeInterface || tyKind == kTypeInterfaceIncomplete)) { uint32 infoVal = (tk == kTkIntconst) ? lexer.GetTheIntVal() : GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()).GetIdx(); @@ -724,8 +725,8 @@ bool MIRParser::ParseFields(MIRStructType &type) { } while (tk == kTkFname) { const std::string &funcName = lexer.GetName(); - GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(funcName); - MIRSymbol *prevFuncSymbol = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(stridx); + GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(funcName); + MIRSymbol *prevFuncSymbol = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(strIdx); if (prevFuncSymbol && (prevFuncSymbol->GetStorageClass() != kScText || prevFuncSymbol->GetSKind() != kStFunc)) { // Based on the current maple format, a previous declaration at this // point can only come from another module. Check consistency. @@ -734,7 +735,7 @@ bool MIRParser::ParseFields(MIRStructType &type) { } // Always create a new symbol because we can not reuse symbol from other module maple::MIRBuilder mirBuilder(&mod); - MIRSymbol *funcSymbol = mirBuilder.CreateSymbol(TyIdx(0), stridx, kStFunc, kScText, nullptr, kScopeGlobal); + MIRSymbol *funcSymbol = mirBuilder.CreateSymbol(TyIdx(0), strIdx, kStFunc, kScText, nullptr, kScopeGlobal); ASSERT(funcSymbol != nullptr, "Failed to create MIRSymbol"); MIRFunction *fn = mod.GetMemPool()->New(&mod, funcSymbol->GetStIdx()); ASSERT(fn != nullptr, "Failed to create MIRFunction"); @@ -781,7 +782,7 @@ bool MIRParser::ParseFields(MIRStructType &type) { while (tk == kTkGname) { tk = lexer.NextToken(); if ((tk == kTkComa || tk == kTkRbrace) && - (type.GetKind() == kTypeClass || type.GetKind() == kTypeClassIncomplete)) { + (tyKind == kTypeClass || tyKind == kTypeClassIncomplete)) { MIRClassType *classType = static_cast(&type); std::string nameStr = lexer.GetName(); GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(nameStr); @@ -808,7 +809,7 @@ bool MIRParser::ParseFields(MIRStructType &type) { return false; } -bool MIRParser::ParseStructType(TyIdx &styidx) { +bool MIRParser::ParseStructType(TyIdx &styIdx) { MIRTypeKind tkind = kTypeInvalid; switch (lexer.GetTokenKind()) { case TK_struct: @@ -830,17 +831,17 @@ bool MIRParser::ParseStructType(TyIdx &styidx) { if (!ParseFields(structType)) { return false; } - if (styidx != 0) { - MIRType *prevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(styidx); + if (styIdx != 0) { + MIRType *prevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(styIdx); ASSERT(prevType->GetKind() == kTypeStruct || prevType->GetKind() == kTypeStructIncomplete, "type kind should be consistent."); if (static_cast(prevType)->IsIncomplete() && !(structType.IsIncomplete())) { structType.SetNameStrIdx(prevType->GetNameStrIdx()); - structType.SetTypeIndex(styidx); - GlobalTables::GetTypeTable().SetTypeWithTyIdx(styidx, structType.CopyMIRTypeNode()); + structType.SetTypeIndex(styIdx); + GlobalTables::GetTypeTable().SetTypeWithTyIdx(styIdx, structType.CopyMIRTypeNode()); } } else { - styidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&structType); + styIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&structType); } lexer.NextToken(); return true; @@ -874,8 +875,8 @@ bool MIRParser::ParseClassType(TyIdx &styidx) { styidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&classType); // set up classTyIdx for methods for (size_t i = 0; i < classType.GetMethods().size(); i++) { - StIdx stidx = classType.GetMethodsElement(i).first; - MIRSymbol *st = GlobalTables::GetGsymTable().GetSymbolFromStidx(stidx.Idx()); + StIdx stIdx = classType.GetMethodsElement(i).first; + MIRSymbol *st = GlobalTables::GetGsymTable().GetSymbolFromStidx(stIdx.Idx()); ASSERT(st->GetSKind() == kStFunc, "unexpected st->sKind"); st->GetFunction()->SetClassTyIdx(styidx); } @@ -988,19 +989,19 @@ bool MIRParser::ParseVarTypeAttrs(MIRSymbol &st) { } // for non-variable type attribute specification. -bool MIRParser::ParseTypeAttrs(TypeAttrs &t_a) { +bool MIRParser::ParseTypeAttrs(TypeAttrs &attrs) { do { switch (lexer.GetTokenKind()) { #define TYPE_ATTR #define ATTR(X) \ case TK_##X: \ - t_a.SetAttr(ATTR_##X); \ + attrs.SetAttr(ATTR_##X); \ break; #include "all_attributes.def" #undef ATTR #undef TYPE_ATTR case TK_align: { - if (!ParseAlignAttrs(t_a)) { + if (!ParseAlignAttrs(attrs)) { return false; } break; @@ -1012,13 +1013,13 @@ bool MIRParser::ParseTypeAttrs(TypeAttrs &t_a) { } while (true); } -bool MIRParser::ParseFieldAttrs(FieldAttrs &t_a) { +bool MIRParser::ParseFieldAttrs(FieldAttrs &attrs) { do { switch (lexer.GetTokenKind()) { #define FIELD_ATTR #define ATTR(X) \ case TK_##X: \ - t_a.SetAttr(FLDATTR_##X); \ + attrs.SetAttr(FLDATTR_##X); \ break; #include "all_attributes.def" #undef ATTR @@ -1027,7 +1028,7 @@ bool MIRParser::ParseFieldAttrs(FieldAttrs &t_a) { if (!CheckAlignTk()) { return false; } - t_a.SetAlign(lexer.GetTheIntVal()); + attrs.SetAlign(lexer.GetTheIntVal()); break; } default: @@ -1037,13 +1038,13 @@ bool MIRParser::ParseFieldAttrs(FieldAttrs &t_a) { } while (true); } -bool MIRParser::ParseFuncAttrs(FuncAttrs &t_a) { +bool MIRParser::ParseFuncAttrs(FuncAttrs &attrs) { do { switch (lexer.GetTokenKind()) { #define FUNC_ATTR #define ATTR(X) \ case TK_##X: \ - t_a.SetAttr(FUNCATTR_##X); \ + attrs.SetAttr(FUNCATTR_##X); \ break; #include "all_attributes.def" #undef ATTR @@ -1211,8 +1212,8 @@ bool MIRParser::ParseFuncType(TyIdx &tyIdx) { } std::vector vecTyIdx; std::vector vecAttrs; - TokenKind tokenkind = lexer.NextToken(); - while (tokenkind != kTkRparen) { + TokenKind tokenKind = lexer.NextToken(); + while (tokenKind != kTkRparen) { TyIdx tyIdxTmp(0); if (!ParseType(tyIdxTmp)) { Error("expect type parsing function parameters "); @@ -1223,10 +1224,10 @@ bool MIRParser::ParseFuncType(TyIdx &tyIdx) { Error("bad attribute in function parameter type at "); return false; } - tokenkind = lexer.GetTokenKind(); - if (tokenkind == kTkComa) { - tokenkind = lexer.NextToken(); - if (tokenkind == kTkRparen) { + tokenKind = lexer.GetTokenKind(); + if (tokenKind == kTkComa) { + tokenKind = lexer.NextToken(); + if (tokenKind == kTkRparen) { Error("syntax error, meeting ,) expect another type after , or ) without , "); return false; } @@ -1947,7 +1948,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { if (tokenKind != kTkLbrack) { // scalar MIRConst *mirConst = nullptr; if (IsConstValue(tokenKind)) { - if (!ParseScalarValue(mirConst, &type)) { + if (!ParseScalarValue(mirConst, type)) { Error("ParseInitValue expect scalar value"); return false; } @@ -1978,7 +1979,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { // parse single const or another dimension array MIRConst *subConst = nullptr; if (IsConstValue(tokenKind)) { - if (!ParseScalarValue(subConst, elemType)) { + if (!ParseScalarValue(subConst, *elemType)) { Error("ParseInitValue expect scalar value"); return false; } @@ -2052,7 +2053,7 @@ bool MIRParser::ParseInitValue(MIRConstPtr &theConst, TyIdx tyIdx) { tokenKind = lexer.NextToken(); MIRConst *subConst = nullptr; if (IsConstValue(tokenKind)) { - if (!ParseScalarValue(subConst, GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx))) { + if (!ParseScalarValue(subConst, *GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx))) { Error("ParseInitValue expect scalar value"); return false; } @@ -2201,10 +2202,10 @@ static void GenJStringType(MIRModule &module) { } } -bool MIRParser::ParseMIR(std::ifstream &mplfile) { +bool MIRParser::ParseMIR(std::ifstream &mplFile) { std::ifstream *origFile = lexer.GetFile(); // parse mplfile - lexer.SetFile(mplfile); + lexer.SetFile(mplFile); // try to read the first line if (lexer.ReadALine() < 0) { lexer.lineNum = 0; @@ -2268,13 +2269,13 @@ bool MIRParser::ParseMIR(uint32 fileIdx, uint32 option, bool isIPA, bool isComb) if (!isIPA && isComb) { for (auto it = paramImportFileList.begin(); it != paramImportFileList.end(); it++) { BinaryMplt binmplt(mod); - std::string importfilename = *it; - if (!binmplt.Import(importfilename, false, true)) { // not a binary mplt - std::ifstream mpltFile(importfilename); + std::string importFilename = *it; + if (!binmplt.Import(importFilename, false, true)) { // not a binary mplt + std::ifstream mpltFile(importFilename); if (!mpltFile.is_open()) { - FATAL(kLncFatal, "cannot open MPLT file: %s\n", importfilename.c_str()); + FATAL(kLncFatal, "cannot open MPLT file: %s\n", importFilename.c_str()); } - bool failedParse = !ParseMPLT(mpltFile, importfilename); + bool failedParse = !ParseMPLT(mpltFile, importFilename); mpltFile.close(); if (failedParse) { return false; @@ -2395,7 +2396,7 @@ bool MIRParser::ParseMIRForFlavor() { Error("expect integer after flavor but get "); return false; } - mod.SetFlavor((MIRFlavor)lexer.GetTheIntVal()); + mod.SetFlavor(static_cast(lexer.GetTheIntVal())); lexer.NextToken(); return true; } @@ -2406,7 +2407,7 @@ bool MIRParser::ParseMIRForSrcLang() { Error("expect integer after srclang but get "); return false; } - mod.SetSrcLang((MIRSrcLang)lexer.GetTheIntVal()); + mod.SetSrcLang(static_cast(lexer.GetTheIntVal())); lexer.NextToken(); return true; } @@ -2510,12 +2511,12 @@ bool MIRParser::ParseMIRForFileInfo() { GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); tk = lexer.NextToken(); if (tk == kTkIntconst) { - uint32 fieldval = lexer.GetTheIntVal(); - mod.PushFileInfoPair(MIRInfoPair(stridx, fieldval)); + uint32 fieldVal = lexer.GetTheIntVal(); + mod.PushFileInfoPair(MIRInfoPair(stridx, fieldVal)); mod.PushFileInfoIsString(false); } else if (tk == kTkString) { - GStrIdx litstridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); - mod.PushFileInfoPair(MIRInfoPair(stridx, litstridx.GetIdx())); + GStrIdx litStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); + mod.PushFileInfoPair(MIRInfoPair(stridx, litStrIdx.GetIdx())); mod.PushFileInfoIsString(true); } else { Error("illegal value after fileInfo field name at "); diff --git a/src/maple_me/include/alias_class.h b/src/maple_me/include/alias_class.h index 7d25132dce89b4a4f29baff60073801c06956651..57ea74e9fd51c82a0b25d3d06ca76c12e48e102b 100644 --- a/src/maple_me/include/alias_class.h +++ b/src/maple_me/include/alias_class.h @@ -187,7 +187,8 @@ class AliasClass : public AnalysisResult { AliasElem *CreateAliasElemsExpr(BaseNode &expr); void SetNotAllDefsSeenForMustDefs(const StmtNode &callas); void SetPtrOpndNextLevNADS(const BaseNode &opnd, AliasElem *ae, bool hasNoPrivateDefEffect); - void SetPtrOpndsNextLevNADS(unsigned int start, unsigned int end, MapleVector &opnds, bool hasNoPrivateDefEffect); + void SetPtrOpndsNextLevNADS(unsigned int start, unsigned int end, MapleVector &opnds, + bool hasNoPrivateDefEffect); void ApplyUnionForDassignCopy(const AliasElem &lhsAe, const AliasElem *rhsAe, const BaseNode &rhs); AliasElem *FindOrCreateDummyNADSAe(); void CollectMayDefForMustDefs(const StmtNode &stmt, std::set &mayDefOsts); diff --git a/src/maple_me/include/bb.h b/src/maple_me/include/bb.h index 3ae79679b10a75e72c45ab923cd3eaf9abf3419e..13b08a45a985dd1d8e66d1cd58001a6b620a28c6 100644 --- a/src/maple_me/include/bb.h +++ b/src/maple_me/include/bb.h @@ -412,11 +412,11 @@ class BB { class SCCOfBBs { public: SCCOfBBs(uint32 index, BB *bb, MapleAllocator *alloc) - : id(index), - entry(bb), - bbs(alloc->Adapter()), - predSCC(std::less(), alloc->Adapter()), - succSCC(std::less(), alloc->Adapter()) {} + : id(index), + entry(bb), + bbs(alloc->Adapter()), + predSCC(std::less(), alloc->Adapter()), + succSCC(std::less(), alloc->Adapter()) {} void Dump(); void Verify(MapleVector &sccOfBB); void SetUp(MapleVector &sccOfBB); diff --git a/src/maple_me/include/me_alias_class.h b/src/maple_me/include/me_alias_class.h index 0882ece2b8fefe877596da08539fa8ed7202f110..13bae9171ab4f94d8e484c63acc53c55a2ba5b63 100644 --- a/src/maple_me/include/me_alias_class.h +++ b/src/maple_me/include/me_alias_class.h @@ -53,7 +53,7 @@ class MeDoAliasClass : public MeFuncPhase { explicit MeDoAliasClass(MePhaseID id) : MeFuncPhase(id) {} virtual ~MeDoAliasClass() = default; - AnalysisResult *Run(MeFunction *ir, MeFuncResultMgr *m, ModuleResultMgr *mrm) override; + AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) override; std::string PhaseName() const override { return "aliasclass"; } diff --git a/src/maple_me/include/me_bb_layout.h b/src/maple_me/include/me_bb_layout.h index 21087458f89a398c8f13348f79c20daa46d7b92f..dd66a2a395830df0379118f3e9e75f16a86efe6b 100644 --- a/src/maple_me/include/me_bb_layout.h +++ b/src/maple_me/include/me_bb_layout.h @@ -104,7 +104,7 @@ class MeDoBBLayout : public MeFuncPhase { explicit MeDoBBLayout(MePhaseID id) : MeFuncPhase(id) {} virtual ~MeDoBBLayout() = default; - AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) override; + AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) override; std::string PhaseName() const override { return "bblayout"; } diff --git a/src/maple_me/include/me_emit.h b/src/maple_me/include/me_emit.h index d7ff6c7034cf2e128d81e9f2ed42a8c061e9dee8..d04c4080f9db343cc2946089eba2dd64262491c1 100644 --- a/src/maple_me/include/me_emit.h +++ b/src/maple_me/include/me_emit.h @@ -24,7 +24,7 @@ class MeDoEmit : public MeFuncPhase { explicit MeDoEmit(MePhaseID id) : MeFuncPhase(id) {} virtual ~MeDoEmit() = default; - AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) override; + AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) override; std::string PhaseName() const override { return "emit"; } diff --git a/src/maple_me/include/me_function.h b/src/maple_me/include/me_function.h index f375ac76f1726f80320ad2e55802028a316a9051..38e808c031f6ad2e299660a51991460f38d2ffd0 100644 --- a/src/maple_me/include/me_function.h +++ b/src/maple_me/include/me_function.h @@ -450,12 +450,12 @@ class MeFunction : public FuncEmit { const MapleVector &GetSccTopologicalVec() const { return sccTopologicalVec; } - void BBTopologicalSort(SCCOfBBs *scc); + void BBTopologicalSort(SCCOfBBs &scc); void BuildSCC(); private: void VerifySCC(); void SCCTopologicalSort(std::vector &sccNodes); - void BuildSCCDFS(BB *bb, uint32 &visitIndex, std::vector &sccNodes, std::vector &visitedOrder, + void BuildSCCDFS(BB &bb, uint32 &visitIndex, std::vector &sccNodes, std::vector &visitedOrder, std::vector &lowestOrder, std::vector &inStack, std::stack &visitStack); void CreateBasicBlocks(); void SetTryBlockInfo(const StmtNode *nextStmt, StmtNode *tryStmt, BB *lastTryBB, BB *curBB, BB *newBB); diff --git a/src/maple_me/include/me_irmap.h b/src/maple_me/include/me_irmap.h index 454e2582f19be28c92849c07bce90e734396a9fe..19e3f294c5802b90f41e34b070c37c01c958f346 100644 --- a/src/maple_me/include/me_irmap.h +++ b/src/maple_me/include/me_irmap.h @@ -60,7 +60,7 @@ class MeDoIRMap : public MeFuncPhase { ~MeDoIRMap() = default; - AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) override; + AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) override; std::string PhaseName() const override { return "irmap"; } diff --git a/src/maple_me/include/me_phase.h b/src/maple_me/include/me_phase.h index 5c0fa651a143d45eebd90acda683ddfa1c9ef80c..2c035d0720caff228c5d9f06fed922a8e137c7c5 100644 --- a/src/maple_me/include/me_phase.h +++ b/src/maple_me/include/me_phase.h @@ -45,7 +45,8 @@ class MeFuncPhase : public Phase { // By default mrm will not be used because most ME phases do not need IPA // result. For those will use IPA result, this function will be overrode. - virtual AnalysisResult *Run(MeFunction *ir, MeFuncResultMgr *frm, ModuleResultMgr *mrm = nullptr) = 0; + virtual AnalysisResult *Run(MeFunction *func, + MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr = nullptr) = 0; const std::string &GetPreviousPhaseName() const { return prevPhaseName; @@ -79,4 +80,4 @@ class MeFuncPhase : public Phase { bool isCFGChanged; // is this phase changed CFG }; } // namespace maple -#endif // MAPLE_ME_INCLUDE_ME_PHASE_H \ No newline at end of file +#endif // MAPLE_ME_INCLUDE_ME_PHASE_H diff --git a/src/maple_me/include/me_rc_lowering.h b/src/maple_me/include/me_rc_lowering.h index 2c1b0e78d55f5b93e23f86378ebdbb89dcc9e82f..8cc45dcbc323bf9952cb1bccda423d7860d96983 100644 --- a/src/maple_me/include/me_rc_lowering.h +++ b/src/maple_me/include/me_rc_lowering.h @@ -23,7 +23,6 @@ namespace maple { class RCLowering { public: - RCLowering(MeFunction &f, KlassHierarchy &kh) : func(f), mirModule(f.GetMIRModule()), @@ -40,16 +39,30 @@ class RCLowering { void Finish(); void FastBBLower(BB &bb); + private: + MeFunction &func; + MIRModule &mirModule; + IRMap &irMap; + SSATab &ssaTab; + KlassHierarchy &klassHierarchy; + std::vector rets{}; // std::vector of return statement + unsigned int tmpCount = 0; + bool needSpecialHandleException = false; + std::set assignedPtrSym; + std::set tmpLocalRefVars; + std::set gcMallocObjects{}; + std::map cleanUpVars{}; + std::map varOStMap{}; + // used to store initialized map, help to optimize dec ref in first assignment + std::unordered_map*> initializedFields{}; std::string PhaseName() const { return "rclowering"; } - void MarkLocalRefVar(); void MarkAllRefOpnds(); void BBLower(BB &bb); void CreateCleanupIntrinsics(); void HandleArguments(); - void InitRCFunc(); // create new symbol from name and return its ost OriginalSt *RetrieveOSt(const std::string &name, bool isLocalrefvar) const; /** @@ -88,23 +101,6 @@ class RCLowering { void HandleReturnStmt(); void HandleAssignMeStmt(MeStmt &stmt, MeExpr *pendingDec); MIRIntrinsicID SelectWriteBarrier(const MeStmt &stmt); - - private: - MeFunction &func; - MIRModule &mirModule; - IRMap &irMap; - SSATab &ssaTab; - KlassHierarchy &klassHierarchy; - std::vector rets{}; // std::vector of return statement - unsigned int tmpCount = 0; - std::set assignedPtrSym; - std::set tmpLocalRefVars; - std::map cleanUpVars{}; - std::map varOStMap{}; - bool needSpecialHandleException = false; - std::set gcMallocObjects{}; - // used to store initialized map, help to optimize dec ref in first assignment - std::unordered_map*> initializedFields{}; }; class MeDoRCLowering : public MeFuncPhase { diff --git a/src/maple_me/include/me_ssa.h b/src/maple_me/include/me_ssa.h index be1b266baa48bd166d33f98a4dae89142b1104dd..ae9ddc4baa452ddbe527ca41c975ee46e7e990da 100644 --- a/src/maple_me/include/me_ssa.h +++ b/src/maple_me/include/me_ssa.h @@ -28,19 +28,19 @@ class MeSSA : public SSA, public AnalysisResult { MeSSA(MeFunction *func, Dominance *dom, MemPool *memPool); ~MeSSA() = default; - void CollectDefBBs(std::map> &ostDefBBs); void BuildSSA(); - void InsertPhiNode(); - void RenameBB(BB&); bool VerifySSA() const; - std::string PhaseName() const { - return "ssa"; - } private: - bool VerifySSAOpnd(const BaseNode &node) const; MeFunction *func; Dominance *dom; + bool VerifySSAOpnd(const BaseNode &node) const; + void CollectDefBBs(std::map> &ostDefBBs); + void InsertPhiNode(); + void RenameBB(BB&); + std::string PhaseName() const { + return "ssa"; + } }; class MeDoSSA : public MeFuncPhase { @@ -49,7 +49,8 @@ class MeDoSSA : public MeFuncPhase { ~MeDoSSA() = default; - AnalysisResult *Run(MeFunction *ir, MeFuncResultMgr *m, ModuleResultMgr *mrm) override; + private: + AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) override; std::string PhaseName() const override { return "ssa"; } diff --git a/src/maple_me/include/me_ssa_tab.h b/src/maple_me/include/me_ssa_tab.h index fc0c5ceda2fa12d74e12ad51b87c510ccae90eb0..f3132d96d5d35f10945b7786f643d4d1e784fa2f 100644 --- a/src/maple_me/include/me_ssa_tab.h +++ b/src/maple_me/include/me_ssa_tab.h @@ -23,7 +23,9 @@ class MeDoSSATab : public MeFuncPhase { explicit MeDoSSATab(MePhaseID id) : MeFuncPhase(id) {} virtual ~MeDoSSATab() = default; - AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) override; + + private: + AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) override; std::string PhaseName() const override { return "ssaTab"; } diff --git a/src/maple_me/src/alias_analysis_table.cpp b/src/maple_me/src/alias_analysis_table.cpp index 6eceb432fe5c69334e5a8bcb1715731f27c8a2e4..32d15aff1848fd9dadaeac7d8ee2f5dd4f66c2b8 100644 --- a/src/maple_me/src/alias_analysis_table.cpp +++ b/src/maple_me/src/alias_analysis_table.cpp @@ -13,7 +13,8 @@ * See the Mulan PSL v1 for more details. */ #include "alias_analysis_table.h" -using namespace maple; + +namespace maple { OriginalSt *AliasAnalysisTable::GetPrevLevelNode(const OriginalSt &ost) { auto it = prevLevelNode.find(ost.GetIndex()); if (it != prevLevelNode.end()) { @@ -164,3 +165,4 @@ OriginalSt *AliasAnalysisTable::FindDiffFieldOriginalSt(const OriginalSt &ost, F MapleVector *nextLevelOsts = GetNextLevelNodes(*parentOst); return FindExtraLevOriginalSt(*nextLevelOsts, fld); } +} // namespace maple diff --git a/src/maple_me/src/me_alias_class.cpp b/src/maple_me/src/me_alias_class.cpp index 4c0e2cfa4495faa3874e04809a47a6b54c935ee0..92faf25d9c3978ead009d5c89ea786ea3de65bcc 100644 --- a/src/maple_me/src/me_alias_class.cpp +++ b/src/maple_me/src/me_alias_class.cpp @@ -82,12 +82,13 @@ void MeAliasClass::DoAliasAnalysis() { } } -AnalysisResult *MeDoAliasClass::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) { +AnalysisResult *MeDoAliasClass::Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) { MPLTimer timer; timer.Start(); - (void)m->GetAnalysisResult(MeFuncPhase_SSATAB, func); + (void)funcResMgr->GetAnalysisResult(MeFuncPhase_SSATAB, func); MemPool *aliasClassMp = NewMemPool(); - KlassHierarchy *kh = static_cast(mrm->GetAnalysisResult(MoPhase_CHA, &func->GetMIRModule())); + KlassHierarchy *kh = static_cast(moduleResMgr->GetAnalysisResult( + MoPhase_CHA, &func->GetMIRModule())); MeAliasClass *aliasClass = aliasClassMp->New( *aliasClassMp, func->GetMIRModule(), *func->GetMeSSATab(), *func, MeOption::lessThrowAlias, MeOption::finalFieldAlias, MeOption::ignoreIPA, DEBUGFUNC(func), MeOption::setCalleeHasSideEffect, kh); diff --git a/src/maple_me/src/me_bb_layout.cpp b/src/maple_me/src/me_bb_layout.cpp index 84227d9d310e4cbd467e067a135f088b85f376c0..913764135c9c9216c5b9a9198178550815cee693 100644 --- a/src/maple_me/src/me_bb_layout.cpp +++ b/src/maple_me/src/me_bb_layout.cpp @@ -415,7 +415,7 @@ void BBLayout::ResolveUnconditionalFallThru(BB &bb, BB &nextBB) { } } -AnalysisResult *MeDoBBLayout::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) { +AnalysisResult *MeDoBBLayout::Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) { // mempool used in analysisresult MemPool *layoutMp = NewMemPool(); BBLayout *bbLayout = layoutMp->New(*layoutMp, *func); @@ -538,7 +538,7 @@ AnalysisResult *MeDoBBLayout::Run(MeFunction *func, MeFuncResultMgr *m, ModuleRe bb = nextBB; } if (bbLayout->IsNewBBInLayout()) { - m->InvalidAnalysisResult(MeFuncPhase_DOMINANCE, func); + funcResMgr->InvalidAnalysisResult(MeFuncPhase_DOMINANCE, func); } if (DEBUGFUNC(func)) { func->GetTheCfg()->DumpToFile("afterBBLayout", false); diff --git a/src/maple_me/src/me_cfg.cpp b/src/maple_me/src/me_cfg.cpp index 7c88a915345b9940d02bb94f94cdf43af456f0fd..1e5a2c451ee20500d3a20c9738c9457e90b13aa8 100644 --- a/src/maple_me/src/me_cfg.cpp +++ b/src/maple_me/src/me_cfg.cpp @@ -337,7 +337,7 @@ void MeCFG::FixMirCFG() { if (stmt->GetNext() != nullptr) { bb->InsertStmtBefore(stmt->GetNext(), dassign); } else { - ASSERT( stmt == &(bb->GetStmtNodes().back()), "just check"); + ASSERT(stmt == &(bb->GetStmtNodes().back()), "just check"); stmt->SetNext(dassign); dassign->SetPrev(stmt); bb->GetStmtNodes().update_back(dassign); @@ -720,9 +720,7 @@ void MeCFG::VerifyLabels() const { } void MeCFG::Dump() const { - // BSF Dump the cfg - // map visited_map; - // set visited_set; + // BSF Dump the cfg LogInfo::MapleLogger() << "####### CFG Dump: "; ASSERT(func.NumBBs() != 0, "size to be allocated is 0"); bool *visitedMap = static_cast(calloc(func.NumBBs(), sizeof(bool))); diff --git a/src/maple_me/src/me_emit.cpp b/src/maple_me/src/me_emit.cpp index c5d55455432b3745eaf1aa0328bda16ba977d895..de95266b245ff4dcc4cb3bba28b5423a67b82eda 100644 --- a/src/maple_me/src/me_emit.cpp +++ b/src/maple_me/src/me_emit.cpp @@ -19,16 +19,16 @@ namespace maple { /* emit IR to specified file */ -AnalysisResult *MeDoEmit::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) { +AnalysisResult *MeDoEmit::Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) { bool emitHssaOrAfter = (func->GetIRMap() != nullptr); if (func->NumBBs() > 0) { /* generate bblist after layout (bb physical position) */ if (!MeOption::quiet) { - CHECK_FATAL(m->GetAnalysisPhase(MeFuncPhase_BBLAYOUT) != nullptr, "null ptr check"); + CHECK_FATAL(funcResMgr->GetAnalysisPhase(MeFuncPhase_BBLAYOUT) != nullptr, "null ptr check"); LogInfo::MapleLogger() << "===== Check/run Depended Phase [ " - << m->GetAnalysisPhase(MeFuncPhase_BBLAYOUT)->PhaseName() << " ]=====\n"; + << funcResMgr->GetAnalysisPhase(MeFuncPhase_BBLAYOUT)->PhaseName() << " ]=====\n"; } - BBLayout *layoutBBs = static_cast(m->GetAnalysisResult(MeFuncPhase_BBLAYOUT, func)); + BBLayout *layoutBBs = static_cast(funcResMgr->GetAnalysisResult(MeFuncPhase_BBLAYOUT, func)); if (!MeOption::quiet) { LogInfo::MapleLogger() << "===== Depended Phase ended =====\n"; } diff --git a/src/maple_me/src/me_function.cpp b/src/maple_me/src/me_function.cpp index f645469950bb3d6c43c2f7a4e30dc24b3e3dc895..b5cff5ecc5e3a168f6746a8f2453ac64882b5393 100644 --- a/src/maple_me/src/me_function.cpp +++ b/src/maple_me/src/me_function.cpp @@ -609,23 +609,23 @@ void MeFunction::RemoveEhEdgesInSyncRegion() { } } -void MeFunction::BuildSCCDFS(BB *bb, uint32 &visitIndex, std::vector &sccNodes, +void MeFunction::BuildSCCDFS(BB &bb, uint32 &visitIndex, std::vector &sccNodes, std::vector &visitedOrder, std::vector &lowestOrder, std::vector &inStack, std::stack &visitStack) { - uint32 id = bb->UintID(); + uint32 id = bb.UintID(); visitedOrder[id] = visitIndex; lowestOrder[id] = visitIndex; visitIndex++; visitStack.push(id); inStack[id] = true; - for (BB *succ : bb->GetSucc()){ + for (BB *succ : bb.GetSucc()){ if (succ == nullptr) { continue; } uint32 succId = succ->UintID(); if (!visitedOrder[succId]) { - BuildSCCDFS(succ, visitIndex, sccNodes, visitedOrder, lowestOrder, inStack, visitStack); + BuildSCCDFS(*succ, visitIndex, sccNodes, visitedOrder, lowestOrder, inStack, visitStack); if (lowestOrder[succId] < lowestOrder[id]) { lowestOrder[id] = lowestOrder[succId]; } @@ -638,7 +638,7 @@ void MeFunction::BuildSCCDFS(BB *bb, uint32 &visitIndex, std::vector } if (visitedOrder.at(id) == lowestOrder.at(id)) { - SCCOfBBs *sccNode = alloc.GetMemPool()->New(numOfSCCs++, bb, &alloc); + SCCOfBBs *sccNode = alloc.GetMemPool()->New(numOfSCCs++, &bb, &alloc); uint32 stackTopId; do { stackTopId = visitStack.top(); @@ -672,7 +672,7 @@ void MeFunction::BuildSCC() { std::stack visitStack; // Starting from common entry bb for DFS - BuildSCCDFS(GetCommonEntryBB(), visitIndex, sccNodes, visitedOrder, lowestOrder, inStack, visitStack); + BuildSCCDFS(*GetCommonEntryBB(), visitIndex, sccNodes, visitedOrder, lowestOrder, inStack, visitStack); for (SCCOfBBs *scc : sccNodes) { scc->Verify(sccOfBB); @@ -715,18 +715,18 @@ void MeFunction::SCCTopologicalSort(std::vector &sccNodes) { } } -void MeFunction::BBTopologicalSort(SCCOfBBs *scc) { +void MeFunction::BBTopologicalSort(SCCOfBBs &scc) { std::set InQueue; std::vector bbs; - for (BB *bb : scc->GetBBs()) { + for (BB *bb : scc.GetBBs()) { bbs.push_back(bb); } - scc->Clear(); - scc->AddBBNode(scc->GetEntry()); - InQueue.insert(scc->GetEntry()); + scc.Clear(); + scc.AddBBNode(scc.GetEntry()); + InQueue.insert(scc.GetEntry()); - for (size_t i = 0; i < scc->GetBBs().size(); i++) { - BB *bb = scc->GetBBs()[i]; + for (size_t i = 0; i < scc.GetBBs().size(); i++) { + BB *bb = scc.GetBBs()[i]; for (BB *succ : bb->GetSucc()) { if (succ == nullptr) { continue; @@ -752,7 +752,7 @@ void MeFunction::BBTopologicalSort(SCCOfBBs *scc) { } } if (predAllVisited) { - scc->AddBBNode(succ); + scc.AddBBNode(succ); InQueue.insert(succ); } } diff --git a/src/maple_me/src/me_irmap.cpp b/src/maple_me/src/me_irmap.cpp index a179d5be1501ea01300f3c1f5734938f8d3ab5ec..b45415f1dd523765bf74b4879bc283af490e410e 100644 --- a/src/maple_me/src/me_irmap.cpp +++ b/src/maple_me/src/me_irmap.cpp @@ -87,8 +87,8 @@ void MeIRMap::EmitBB(const BB &bb, BlockNode &curblk) { } } -AnalysisResult *MeDoIRMap::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) { - Dominance *dom = static_cast(m->GetAnalysisResult(MeFuncPhase_DOMINANCE, func)); +AnalysisResult *MeDoIRMap::Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) { + Dominance *dom = static_cast(funcResMgr->GetAnalysisResult(MeFuncPhase_DOMINANCE, func)); ASSERT(dom != nullptr, "dominance phase has problem"); MemPool *irMapMemPool = NewMemPool(); MeIRMap *irMap = irMapMemPool->New(*func, *dom, *irMapMemPool, *NewMemPool()); diff --git a/src/maple_me/src/me_rc_lowering.cpp b/src/maple_me/src/me_rc_lowering.cpp index 4702425e190e03ce4d15a4b3ca95f89c197af53e..0053f4fa86bcdffed842bb41969733ad9d516a72 100644 --- a/src/maple_me/src/me_rc_lowering.cpp +++ b/src/maple_me/src/me_rc_lowering.cpp @@ -833,11 +833,11 @@ VarMeExpr *RCLowering::CreateNewTmpVarMeExpr(bool isLocalRefVar) { return varMeExpr; } -AnalysisResult *MeDoRCLowering::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) { - auto *kh = static_cast(mrm->GetAnalysisResult(MoPhase_CHA, &func->GetMIRModule())); +AnalysisResult *MeDoRCLowering::Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) { + auto *kh = static_cast(moduleResMgr->GetAnalysisResult(MoPhase_CHA, &func->GetMIRModule())); ASSERT(kh != nullptr, "KlassHierarchy has problem"); if (func->GetIRMap() == nullptr) { - auto *hmap = static_cast(m->GetAnalysisResult(MeFuncPhase_IRMAP, func)); + auto *hmap = static_cast(funcResMgr->GetAnalysisResult(MeFuncPhase_IRMAP, func)); CHECK_FATAL(hmap != nullptr, "hssamap has problem"); func->SetIRMap(hmap); } diff --git a/src/maple_me/src/me_ssa.cpp b/src/maple_me/src/me_ssa.cpp index c80f2bf939aeec4fa79470165fd54805905822d6..c8f932a56e126735e5c763df586fbb211a768a95 100644 --- a/src/maple_me/src/me_ssa.cpp +++ b/src/maple_me/src/me_ssa.cpp @@ -68,11 +68,11 @@ void MeSSA::CollectDefBBs(std::map> &ostDefBBs) { MapleMap::iterator iter; for (iter = mayDefs.begin(); iter != mayDefs.end(); ++iter) { const OriginalSt *ost = func->GetMeSSATab()->GetOriginalStFromID(iter->first); - if (ost && (!ost->IsFinal() || func->GetMirFunc()->IsConstructor())) { + if (ost != nullptr && (!ost->IsFinal() || func->GetMirFunc()->IsConstructor())) { ostDefBBs[iter->first].insert(bb->GetBBId()); } else if (stmt.GetOpCode() == OP_intrinsiccallwithtype) { - IntrinsiccallNode &innode = static_cast(stmt); - if (innode.GetIntrinsic() == INTRN_JAVA_CLINIT_CHECK) { + auto &inNode = static_cast(stmt); + if (inNode.GetIntrinsic() == INTRN_JAVA_CLINIT_CHECK) { ostDefBBs[iter->first].insert(bb->GetBBId()); } } @@ -80,7 +80,7 @@ void MeSSA::CollectDefBBs(std::map> &ostDefBBs) { if (stmt.GetOpCode() == OP_dassign || stmt.GetOpCode() == OP_maydassign) { VersionSt *vst = GetSSATab()->GetStmtsSSAPart().SSAPartOf(stmt)->GetSSAVar(); OriginalSt *ost = vst->GetOrigSt(); - if (ost && (!ost->IsFinal() || func->GetMirFunc()->IsConstructor())) { + if (ost != nullptr && (!ost->IsFinal() || func->GetMirFunc()->IsConstructor())) { ostDefBBs[vst->GetOrigIdx()].insert(bb->GetBBId()); } } @@ -116,9 +116,9 @@ void MeSSA::InsertPhiNode() { } std::deque *workList = new std::deque(); for (auto it = ost2DefBBs[ost->GetIndex()].begin(); it != ost2DefBBs[ost->GetIndex()].end(); it++) { - BB *defBb = func->GetAllBBs()[(*it).idx]; - if (defBb != nullptr) { - workList->push_back(defBb); + BB *defBB = func->GetAllBBs()[(*it).idx]; + if (defBB != nullptr) { + workList->push_back(defBB); } } while (!workList->empty()) { @@ -128,7 +128,7 @@ void MeSSA::InsertPhiNode() { for (auto &bbID : dfs) { BB *dfBB = func->GetBBFromID(bbID); CHECK_FATAL(dfBB != nullptr, "null ptr check"); - if (!dfBB->PhiofVerStInserted(*vst)) { + if (dfBB->PhiofVerStInserted(*vst) == nullptr) { workList->push_back(dfBB); dfBB->InsertPhi(&func->GetAlloc(), vst); if (DEBUGFUNC(func)) { @@ -183,12 +183,12 @@ bool MeSSA::VerifySSAOpnd(const BaseNode &node) const { Opcode op = node.GetOpCode(); size_t vtableSize = func->GetMeSSATab()->GetVersionStTable().GetVersionStVectorSize(); if (op == OP_dread || op == OP_addrof) { - const AddrofSSANode &addrofSSANode = static_cast(node); - const VersionSt *verSt = addrofSSANode.GetSSAVar(); + const auto &addrOfSSANode = static_cast(node); + const VersionSt *verSt = addrOfSSANode.GetSSAVar(); CHECK_FATAL(verSt->GetIndex() < vtableSize, "runtime check error"); return true; } else if (op == OP_regread) { - const RegreadSSANode ®Node = static_cast(node); + const auto ®Node = static_cast(node); const VersionSt *verSt = regNode.GetSSAVar(); CHECK_FATAL(verSt->GetIndex() < vtableSize, "runtime check error"); return true; @@ -219,17 +219,17 @@ bool MeSSA::VerifySSA() const { return true; } -AnalysisResult *MeDoSSA::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) { - Dominance *dom = static_cast(m->GetAnalysisResult(MeFuncPhase_DOMINANCE, func)); +AnalysisResult *MeDoSSA::Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) { + auto *dom = static_cast(funcResMgr->GetAnalysisResult(MeFuncPhase_DOMINANCE, func)); CHECK_FATAL(dom != nullptr, "dominance phase has problem"); - SSATab *ssatab = static_cast(m->GetAnalysisResult(MeFuncPhase_SSATAB, func)); - CHECK_FATAL(ssatab != nullptr, "ssaTab phase has problem"); - MemPool *ssamp = NewMemPool(); - MeSSA *ssa = ssamp->New(func, dom, ssamp); + auto *ssaTab = static_cast(funcResMgr->GetAnalysisResult(MeFuncPhase_SSATAB, func)); + CHECK_FATAL(ssaTab != nullptr, "ssaTab phase has problem"); + MemPool *ssaMp = NewMemPool(); + MeSSA *ssa = ssaMp->New(func, dom, ssaMp); ssa->BuildSSA(); ssa->VerifySSA(); if (DEBUGFUNC(func)) { - ssatab->GetVersionStTable().Dump(&ssatab->GetModule()); + ssaTab->GetVersionStTable().Dump(&ssaTab->GetModule()); } return ssa; } diff --git a/src/maple_me/src/me_ssa_tab.cpp b/src/maple_me/src/me_ssa_tab.cpp index 8cff3050d70c04ba12688272631b9df9e829b0e2..6c0b9b196a12591d5ff9de687ffe8a56e980afff 100644 --- a/src/maple_me/src/me_ssa_tab.cpp +++ b/src/maple_me/src/me_ssa_tab.cpp @@ -18,7 +18,7 @@ // allocate the data structure to store SSA information namespace maple { -AnalysisResult *MeDoSSATab::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) { +AnalysisResult *MeDoSSATab::Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) { MPLTimer timer; timer.Start(); if (DEBUGFUNC(func)) { diff --git a/src/maple_me/src/me_ssa_update.cpp b/src/maple_me/src/me_ssa_update.cpp index f81299216c103fd8e712ea7c6e0df2b24162a60d..ebf5bc928ec2fa312e4e83bb83837126d720b0b4 100644 --- a/src/maple_me/src/me_ssa_update.cpp +++ b/src/maple_me/src/me_ssa_update.cpp @@ -75,15 +75,15 @@ void MeSSAUpdate::RenamePhi(BB &bb) { if (phi->GetLHS() == nullptr) { // create a new VarMeExpr defined by this phi irMap.SetExprID(irMap.GetExprID() + 1); - VarMeExpr *newvar = irMap.New(&irMap.GetIRMapAlloc(), irMap.GetExprID(), it2->first, + VarMeExpr *newVar = irMap.New(&irMap.GetIRMapAlloc(), irMap.GetExprID(), it2->first, irMap.GetVerst2MeExprTableSize()); - newvar->InitBase(OP_dread, PTY_ref, 0); - newvar->SetFieldID(0); - irMap.PushBackVerst2MeExprTable(newvar); - CHECK_FATAL(newvar->GetVstIdx() == irMap.GetVerst2MeExprTableSize() - 1, + newVar->InitBase(OP_dread, PTY_ref, 0); + newVar->SetFieldID(0); + irMap.PushBackVerst2MeExprTable(newVar); + CHECK_FATAL(newVar->GetVstIdx() == irMap.GetVerst2MeExprTableSize() - 1, "RenamePhi: vstIdx wrongly initialized"); - phi->UpdateLHS(*newvar); - it1->second->push(newvar); // push the stack + phi->UpdateLHS(*newVar); + it1->second->push(newVar); // push the stack } else { it1->second->push(phi->GetLHS()); // push the stack } @@ -96,21 +96,21 @@ MeExpr *MeSSAUpdate::RenameExpr(MeExpr &meExpr, bool &changed) { bool needRehash = false; switch (meExpr.GetMeOp()) { case kMeOpVar: { - VarMeExpr &varExpr = static_cast(meExpr); + auto &varExpr = static_cast(meExpr); MapleMap*>::iterator it1 = renameStacks.find(varExpr.GetOStIdx()); if (it1 == renameStacks.end()) { return &meExpr; } MapleStack *renameStack = it1->second; - VarMeExpr *curvar = renameStack->top(); - if (&varExpr == curvar) { + VarMeExpr *curVar = renameStack->top(); + if (&varExpr == curVar) { return &meExpr; } changed = true; - return curvar; + return curVar; } case kMeOpIvar: { - IvarMeExpr &ivarMeExpr = static_cast(meExpr); + auto &ivarMeExpr = static_cast(meExpr); IvarMeExpr newMeExpr(kInvalidExprID); newMeExpr.SetBase(RenameExpr(*ivarMeExpr.GetBase(), needRehash)); if (needRehash) { @@ -124,12 +124,12 @@ MeExpr *MeSSAUpdate::RenameExpr(MeExpr &meExpr, bool &changed) { return &meExpr; } case kMeOpOp: { - OpMeExpr &meOpExpr = static_cast(meExpr); + auto &meOpExpr = static_cast(meExpr); OpMeExpr newMeExpr(kInvalidExprID); newMeExpr.SetOpnd(0, RenameExpr(*meOpExpr.GetOpnd(0), needRehash)); - if (meOpExpr.GetOpnd(1)) { + if (meOpExpr.GetOpnd(1) != nullptr) { newMeExpr.SetOpnd(1, RenameExpr(*meOpExpr.GetOpnd(1), needRehash)); - if (meOpExpr.GetOpnd(2)) { + if (meOpExpr.GetOpnd(2) != nullptr) { newMeExpr.SetOpnd(2, RenameExpr(*meOpExpr.GetOpnd(2), needRehash)); } } @@ -146,7 +146,7 @@ MeExpr *MeSSAUpdate::RenameExpr(MeExpr &meExpr, bool &changed) { return &meExpr; } case kMeOpNary: { - NaryMeExpr &naryMeExpr = static_cast(meExpr); + auto &naryMeExpr = static_cast(meExpr); NaryMeExpr newMeExpr(&irMap.GetIRMapAlloc(), kInvalidExprID, naryMeExpr.GetTyIdx(), naryMeExpr.GetIntrinsic(), naryMeExpr.GetBoundCheck()); for (size_t i = 0; i < naryMeExpr.GetOpnds().size(); i++) { @@ -176,31 +176,31 @@ void MeSSAUpdate::RenameStmts(BB &bb) { if (chiList != nullptr) { for (auto chi : *chiList) { MapleMap*>::iterator it = renameStacks.find(chi.first); - if (it != renameStacks.end() && chi.second) { + if (it != renameStacks.end() && chi.second != nullptr) { it->second->push(chi.second->GetLHS()); } } } // process the LHS - VarMeExpr *lhsvar = nullptr; + VarMeExpr *lhsVar = nullptr; if (stmt.GetOp() == OP_dassign || stmt.GetOp() == OP_maydassign) { - lhsvar = stmt.GetVarLHS(); + lhsVar = stmt.GetVarLHS(); } else if (kOpcodeInfo.IsCallAssigned(stmt.GetOp())) { MapleVector *mustDefList = stmt.GetMustDefList(); if (mustDefList->empty() || mustDefList->front().GetLHS()->GetMeOp() != kMeOpVar) { continue; } - lhsvar = static_cast(mustDefList->front().GetLHS()); + lhsVar = static_cast(mustDefList->front().GetLHS()); } else { continue; } - CHECK_FATAL(lhsvar != nullptr, "stmt doesn't have lhs?"); - MapleMap*>::iterator it = renameStacks.find(lhsvar->GetOStIdx()); + CHECK_FATAL(lhsVar != nullptr, "stmt doesn't have lhs?"); + MapleMap*>::iterator it = renameStacks.find(lhsVar->GetOStIdx()); if (it == renameStacks.end()) { continue; } MapleStack *renameStack = it->second; - renameStack->push(lhsvar); + renameStack->push(lhsVar); } } @@ -223,9 +223,9 @@ void MeSSAUpdate::RenamePhiOpndsInSucc(BB &bb) { } MeVarPhiNode *phi = it2->second; MapleStack *renameStack = it1->second; - VarMeExpr *curvar = renameStack->top(); - if (phi->GetOpnd(index) != curvar) { - phi->SetOpnd(index, curvar); + VarMeExpr *curVar = renameStack->top(); + if (phi->GetOpnd(index) != curVar) { + phi->SetOpnd(index, curVar); } } } diff --git a/src/maple_util/include/mpl_logging.h b/src/maple_util/include/mpl_logging.h index 35580807991f983adbdb5ec0bf126767086ede45..084a7f7f42f54b5d853a3fd6fff29f9757a473cc 100644 --- a/src/maple_util/include/mpl_logging.h +++ b/src/maple_util/include/mpl_logging.h @@ -139,22 +139,13 @@ enum LogLevel { kLlDbg, kLlLog, kLlInfo, kLlWarn, kLlErr, kLlFatal, kLlMax }; enum LogTags { kLtThread, kLtLooper, kLtAll }; -enum LogMode { - kLmSimple, - kLmComplex, - - kLmMax -}; +enum LogMode { kLmSimple, kLmComplex, kLmMax }; enum LogNumberCode { kLncInfo = 0, - kLncWarn = 20, - kLncErr = 40, - kLncFatal = 60, - kLncMax = 99 }; @@ -169,16 +160,6 @@ class LogInfo { fclose(outStream); } - void SetLogDevice(FILE &stream) { - outStream = &stream; - } - - void SetLogMode(LogMode lm) { - outMode = lm; - } - - 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 std::string &cond, const std::string &file, unsigned int line, @@ -187,6 +168,14 @@ class LogInfo { private: FILE *outStream; LogMode outMode; + void SetLogDevice(FILE &stream) { + outStream = &stream; + } + void SetLogMode(LogMode lm) { + outMode = lm; + } + void EmitLogForDevelop(enum LogTags tag, enum LogLevel ll, const std::string &file, const std::string &func, + int line, const char *fmt, ...); }; #ifdef DEBUG