diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index f7000f932d2769f9713ae547c7058165593eceab..738f1e6dda59c390ef23eefcc092af2b82af794b 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index bc4e7069b186dd7c068242374936a03362d27a23..aa6fcd3a8a2540a79b634399a2c1922c74a648c2 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index 00bd1de0e75e57651111ec31f5eee4588a08137c..ea02b38f0bef7d55b145b979c8c012c80b400cd6 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/deplibs/libmempool.a b/src/deplibs/libmempool.a index 1a9db36584e163516526ff5a8e70223dce58fa7d..ccb8d9c59e31217546618853badc996f3d398e9c 100644 Binary files a/src/deplibs/libmempool.a and b/src/deplibs/libmempool.a differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index b114323b1261bf4e0164039e62f597dd2d92c3cd..52645dccffcfa2730210044bb977969ddedd81d7 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/maple_driver/include/mpl_options.h b/src/maple_driver/include/mpl_options.h index 0b994ee211d4d4e157c35f17d9ada52281a0d0c5..edc40df4df6fa391723e27214d2f3a9ac2bef691 100644 --- a/src/maple_driver/include/mpl_options.h +++ b/src/maple_driver/include/mpl_options.h @@ -37,8 +37,17 @@ enum InputFileType { kS, }; -enum OptimizationLevel { kO0, kO1, kO2 }; -enum RunMode { kAutoRun, kCustomRun, kUnkownRun }; +enum OptimizationLevel { + kO0, + kO1, + kO2 +}; + +enum RunMode { + kAutoRun, + kCustomRun, + kUnkownRun +}; class MplOption { public: diff --git a/src/maple_driver/include/safe_exe.h b/src/maple_driver/include/safe_exe.h index 5a2bf8086501bad8fbc399e3005197432462cad2..7286ee75b983c3de6b38f09734436d618aef114b 100644 --- a/src/maple_driver/include/safe_exe.h +++ b/src/maple_driver/include/safe_exe.h @@ -14,14 +14,12 @@ */ #ifndef MAPLE_DRIVER_INCLUDE_SAFE_EXE_H #define MAPLE_DRIVER_INCLUDE_SAFE_EXE_H -#if __linux__ or __linux -#include -#endif #if __linux__ or __linux #include #include #include +#include #include "error_code.h" #endif #include "mpl_logging.h" @@ -31,9 +29,7 @@ namespace maple { class SafeExe { public: - /** - * Current tool is for linux only - */ + // Current tool is for linux only #if __linux__ or __linux static ErrorCode HandleCommand(const std::string &cmd, const std::string &args) { std::vector vectorArgs = ParseArgsVector(cmd, args); diff --git a/src/maple_driver/include/usages.h b/src/maple_driver/include/usages.h index 5e1fe9b220ae752a8cc801257edb93dfdc1e68de..dc72a0e4fde6e3318e19b8dd9572e38d0315df4c 100644 --- a/src/maple_driver/include/usages.h +++ b/src/maple_driver/include/usages.h @@ -52,7 +52,6 @@ enum OptionIndex : uint64 { kMeDumpAfter, kMeRange, kLessThrowAlias, - kFinalFieldAlias, kRegReadAtReturn, //----------mpl2mpl begin--------- kMpl2MplHelp, diff --git a/src/maple_driver/src/driver_runner.cpp b/src/maple_driver/src/driver_runner.cpp index c720b73133403fbcde7736371e2f2d6f0e8a43d9..8962ed8ec6ba9a5d973c8bdd3ddfbb63e2793908 100644 --- a/src/maple_driver/src/driver_runner.cpp +++ b/src/maple_driver/src/driver_runner.cpp @@ -69,8 +69,8 @@ ErrorCode DriverRunner::Run() { printOutExe = exeNames[exeNames.size() - 1]; // Prepare output file - std::string::size_type lastdot = actualInput.find_last_of("."); - std::string baseName = lastdot == std::string::npos ? actualInput : actualInput.substr(0, lastdot); + std::string::size_type lastDot = actualInput.find_last_of("."); + std::string baseName = lastDot == std::string::npos ? actualInput : actualInput.substr(0, lastDot); std::string originBaseName = baseName; std::string outputFile = baseName.append(GetPostfix()); @@ -101,13 +101,10 @@ std::string DriverRunner::GetPostfix() const { return ".me.mpl"; } else if (printOutExe == mpl2Mpl) { return ".VtableImpl.mpl"; - } else { } - return ""; } - ErrorCode DriverRunner::ParseInput(const std::string &outputFile, const std::string &originBaseName) const { CHECK_MODULE(ErrorCode::kErrorExit); diff --git a/src/maple_driver/src/maple_comb_compiler.cpp b/src/maple_driver/src/maple_comb_compiler.cpp index e08ce349cfbec52eec312c732fb3a7c8c731fabb..283cf175795697cd00a5b8f51494b08c3bd5b8d5 100644 --- a/src/maple_driver/src/maple_comb_compiler.cpp +++ b/src/maple_driver/src/maple_comb_compiler.cpp @@ -150,9 +150,6 @@ MeOption *MapleCombCompiler::MakeMeOptions(const MplOptions &options, maple::Mem case kLessThrowAlias: meOption->lessThrowAlias = true; break; - case kFinalFieldAlias: - meOption->finalFieldAlias = true; - break; case kRegReadAtReturn: meOption->regreadAtReturn = true; break; diff --git a/src/maple_driver/src/mpl_options.cpp b/src/maple_driver/src/mpl_options.cpp index 104a32aeb11eb6609085d5001a8bc39391533351..8eb7ea60410f71c0c51b205c366038cd4d1f30fd 100644 --- a/src/maple_driver/src/mpl_options.cpp +++ b/src/maple_driver/src/mpl_options.cpp @@ -439,18 +439,6 @@ const mapleOption::Descriptor USAGES[] = { " --lessthrowalias \tHandle aliases at java throw statements more accurately\n", "me", { { nullptr } } }, - { kFinalFieldAlias, - 0, - nullptr, - "finalfieldalias", - nullptr, - false, - nullptr, - mapleOption::BuildType::kBuildTypeAll, - mapleOption::ArgCheckPolicy::kArgCheckPolicyNone, - " --finalfieldalias \tRegard final fields as having alias like other fields\n", - "me", - { { nullptr } } }, { kRegReadAtReturn, 0, nullptr, @@ -940,7 +928,7 @@ ErrorCode MplOptions::DecideRunType() { for (auto opt : optionParser->GetOptions()) { switch (opt.Index()) { case kOptimization0: - if (runMode == RunMode::kCustomRun) {// O0 and run should not appear at the same time + if (runMode == RunMode::kCustomRun) { // O0 and run should not appear at the same time runModeConflict = true; } else { runMode = RunMode::kAutoRun; @@ -948,7 +936,7 @@ ErrorCode MplOptions::DecideRunType() { } break; case kRun: - if (runMode == RunMode::kAutoRun) {// O0 and run should not appear at the same time + if (runMode == RunMode::kAutoRun) { // O0 and run should not appear at the same time runModeConflict = true; } else { runMode = RunMode::kCustomRun; diff --git a/src/maple_ipa/include/module_phase_manager.h b/src/maple_ipa/include/module_phase_manager.h index 6b1f0c1b48d7141a1b9acf7295cad289821a02ae..6a96573638c9d607e3f83bca2fba6faa52c954ec 100644 --- a/src/maple_ipa/include/module_phase_manager.h +++ b/src/maple_ipa/include/module_phase_manager.h @@ -66,7 +66,7 @@ class ModulePhaseManager : public PhaseManager { private: bool timePhases; MIRModule &mirModule; - ModuleResultMgr *arModuleMgr; /* module level analysis result */ + ModuleResultMgr *arModuleMgr; // module level analysis result }; } // namespace maple #endif // MAPLE_IPA_INCLUDE_MODULE_PHASE_MANAGER_H diff --git a/src/maple_ipa/src/module_phase_manager.cpp b/src/maple_ipa/src/module_phase_manager.cpp index 1500a956fec090fff96e35bde347719d253f3059..3bd49ed7ec0c9fe4d49d7fc3d4db1812551bb27c 100644 --- a/src/maple_ipa/src/module_phase_manager.cpp +++ b/src/maple_ipa/src/module_phase_manager.cpp @@ -39,9 +39,12 @@ AnalysisResult *DoKlassHierarchy::Run(MIRModule *module, ModuleResultMgr *m) { KlassHierarchy::traceFlag = TRACE_PHASE; kh->BuildHierarchy(); #if MIR_JAVA - if (!Options::skipVirtualMethod) -#endif + if (!Options::skipVirtualMethod) { kh->CountVirtualMethods(); + } +#else + kh->CountVirtualMethods(); +#endif if (KlassHierarchy::traceFlag) { kh->Dump(); } diff --git a/src/maple_ir/include/intrinsics.h b/src/maple_ir/include/intrinsics.h index d72c17e41c640d1cf6bd01cc57cc62ecadb53c0b..7480a46977e9a97e822f34876972863c43bd29d9 100644 --- a/src/maple_ir/include/intrinsics.h +++ b/src/maple_ir/include/intrinsics.h @@ -85,7 +85,7 @@ static constexpr uint32 INTRNISPURE = 1U << kIntrnIsPure; static constexpr uint32 INTRNNEVERRETURN = 1U << kIntrnNeverReturn; static constexpr uint32 INTRNATOMIC = 1U << kIntrnIsAtomic; static constexpr uint32 INTRNISRC = 1U << kIntrnIsRC; -class MIRType; // circular dependency exists, no other choice +class MIRType; // circular dependency exists, no other choice class MIRModule; // circular dependency exists, no other choice struct IntrinDesc { static constexpr int kMaxArgsNum = 7; diff --git a/src/maple_ir/include/mir_pragma.h b/src/maple_ir/include/mir_pragma.h index 43772710205c06830ac33a0e2005370d015f296b..35bbfae6c20130bb7f99b238428907c336adb9ba 100644 --- a/src/maple_ir/include/mir_pragma.h +++ b/src/maple_ir/include/mir_pragma.h @@ -21,11 +21,11 @@ #include "mempool_allocator.h" namespace maple { -class MIRModule; // circular dependency exists, no other choice -class MIRType; // circular dependency exists, no other choice -class MIRFunction; // circular dependency exists, no other choice -class MIRSymbol; // circular dependency exists, no other choice -class MIRSymbolTable; // circular dependency exists, no other choice +class MIRModule; // circular dependency exists, no other choice +class MIRType; // circular dependency exists, no other choice +class MIRFunction; // circular dependency exists, no other choice +class MIRSymbol; // circular dependency exists, no other choice +class MIRSymbolTable; // circular dependency exists, no other choice class MIRTypeNameTable; // circular dependency exists, no other choice enum PragmaKind { kPragmaUnknown, diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index 6ff392a17376d33db3afb3d1ea229fb9efb080ae..a5bf0108f6436254e54ffb53cdc47fa74d5a979f 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -15,6 +15,7 @@ #ifndef MAPLE_IR_INCLUDE_MIR_TYPE_H #define MAPLE_IR_INCLUDE_MIR_TYPE_H #include +#include #include "prim_types.h" #include "mir_pragma.h" #include "mpl_logging.h" @@ -32,10 +33,10 @@ using FieldPair = std::pair; using FieldVector = std::vector; using MIRTypePtr = MIRType*; -constexpr int kMaxArrayDim = 10; +constexpr size_t kMaxArrayDim = 10; const std::string kJstrTypeName = "constStr"; #if MIR_FEATURE_FULL -extern bool VerifyPrimType(PrimType primType1, PrimType primType2); // verify if primType1 and primType2 match +extern bool VerifyPrimType(PrimType primType1, PrimType primType2); // verify if primType1 and primType2 match extern uint32 GetPrimTypeSize(PrimType primType); // answer in bytes; 0 if unknown extern uint32 GetPrimTypeP2Size(PrimType primType); // answer in bytes in power-of-two. extern const char *GetPrimTypeName(PrimType primType); @@ -48,8 +49,8 @@ inline uint32 GetPrimTypeBitSize(PrimType primType) { #endif // MIR_FEATURE_FULL // return the same type with size increased to register size PrimType GetRegPrimType(PrimType primType); -PrimType GetDynType(PrimType pType); -PrimType GetNonDynType(PrimType pType); +PrimType GetDynType(PrimType primType); +PrimType GetNonDynType(PrimType primType); inline bool IsAddress(PrimitiveType primitiveType) { return primitiveType.IsAddress(); @@ -88,9 +89,9 @@ inline bool IsPrimitiveFloat(PrimitiveType primitiveType) { } inline bool IsPrimitiveScalar(PrimitiveType primitiveType) { - return (primitiveType.IsInteger() || primitiveType.IsFloat() || - (primitiveType.IsDynamic() && !primitiveType.IsDynamicNone()) || - primitiveType.IsSimple()); + return primitiveType.IsInteger() || primitiveType.IsFloat() || + (primitiveType.IsDynamic() && !primitiveType.IsDynamicNone()) || + primitiveType.IsSimple(); } inline bool IsPrimitiveValid(PrimitiveType primitiveType) { @@ -103,7 +104,9 @@ inline bool IsPrimitivePoint(PrimitiveType primitiveType) { bool IsNoCvtNeeded(PrimType toType, PrimType fromType); -bool IsRefOrPtrAssign(PrimType toType, PrimType fromType); +inline bool IsRefOrPtrAssign(PrimType toType, PrimType fromType) { + return (toType == PTY_ref && fromType == PTY_ptr) || (toType == PTY_ptr && fromType == PTY_ref); +} enum MIRTypeKind : std::uint8_t { kTypeInvalid, @@ -140,11 +143,9 @@ enum AttrKind : unsigned { class TypeAttrs { public: - TypeAttrs() : attrFlag(0), attrAlign(0) {} - - TypeAttrs &operator=(const TypeAttrs &t) = default; + TypeAttrs() = default; TypeAttrs(const TypeAttrs &ta) = default; - + TypeAttrs &operator=(const TypeAttrs &t) = default; ~TypeAttrs() = default; void SetAlignValue(uint8 flag) { @@ -180,18 +181,18 @@ class TypeAttrs { attrAlign = 0; while (x != 1) { x >>= 1; - attrAlign++; + ++attrAlign; } } - uint32 GetAlign(void) const { + uint32 GetAlign() const { if (attrAlign == 0) { return 1; } uint32 res = 1; uint32 exp = attrAlign; do { - exp--; + --exp; res *= 2; } while (exp != 0); return res; @@ -208,8 +209,8 @@ class TypeAttrs { void DumpAttributes() const; private: - uint64 attrFlag; - uint8 attrAlign; // alignment in bytes is 2 to the power of attrAlign + uint64 attrFlag = 0; + uint8 attrAlign = 0; // alignment in bytes is 2 to the power of attrAlign }; enum FieldAttrKind { @@ -222,15 +223,13 @@ enum FieldAttrKind { class FieldAttrs { public: - FieldAttrs() : attrFlag(0), attrAlign(0) {} - - ~FieldAttrs() {} - - FieldAttrs &operator=(const FieldAttrs &p) = default; + FieldAttrs() = default; FieldAttrs(const FieldAttrs &ta) = default; + FieldAttrs &operator=(const FieldAttrs &p) = default; + ~FieldAttrs() = default; - void SetAlignValue(uint8 flag) { - attrAlign = flag; + void SetAlignValue(uint8 align) { + attrAlign = align; } uint8 GetAlignValue() const { @@ -258,18 +257,18 @@ class FieldAttrs { attrAlign = 0; while (x != 1) { x >>= 1; - attrAlign++; + ++attrAlign; } } - uint32 GetAlign(void) const { + uint32 GetAlign() const { if (attrAlign == 0) { return 1; } uint32 res = 1; uint32 exp = attrAlign; do { - exp--; + --exp; res *= 2; } while (exp != 0); return res; @@ -287,8 +286,8 @@ class FieldAttrs { TypeAttrs ConvertToTypeAttrs(); private: - uint32 attrFlag; - uint8 attrAlign; // alignment in bytes is 2 to the power of attrAlign + uint32 attrFlag = 0; + uint8 attrAlign = 0; // alignment in bytes is 2 to the power of attrAlign }; enum FuncAttrKind : unsigned { @@ -301,14 +300,13 @@ enum FuncAttrKind : unsigned { class FuncAttrs { public: - FuncAttrs() : attrFlag(0) {} - + FuncAttrs() = default; FuncAttrs(const FuncAttrs &ta) = default; - FuncAttrs &operator=(const FuncAttrs &p) = default; ~FuncAttrs() = default; + void SetAttr(FuncAttrKind x, bool unSet = false) { - if (unSet == false) { + if (!unSet) { attrFlag |= (1ULL << x); } else { attrFlag &= ~(1ULL << x); @@ -338,7 +336,7 @@ class FuncAttrs { void DumpAttributes() const; private: - uint64 attrFlag; + uint64 attrFlag = 0; }; // only for internal use, not emitted @@ -356,11 +354,10 @@ enum GenericAttrKind { class GenericAttrs { public: + GenericAttrs() = default; + GenericAttrs(const GenericAttrs &ta) = default; GenericAttrs &operator=(const GenericAttrs &p) = default; - GenericAttrs() : attrFlag(0) {} - ~GenericAttrs() = default; - explicit GenericAttrs(const GenericAttrs &ta) = default; void SetAttr(GenericAttrKind x) { attrFlag |= (1ULL << x); @@ -383,7 +380,7 @@ class GenericAttrs { FuncAttrs ConvertToFuncAttrs(); private: - uint64 attrFlag; + uint64 attrFlag = 0; }; #if MIR_FEATURE_FULL @@ -391,7 +388,7 @@ constexpr int kShiftNumOfTypeKind = 8; constexpr int kShiftNumOfNameStrIdx = 6; class MIRType { public: - MIRType(MIRTypeKind kind, PrimType pType) : typeKind(kind), primType(pType), nameStrIdx(0) {} + MIRType(MIRTypeKind kind, PrimType pType) : typeKind(kind), primType(pType) {} MIRType(MIRTypeKind kind, PrimType pType, GStrIdx strIdx) : typeKind(kind), primType(pType), nameStrIdx(strIdx) {} @@ -459,45 +456,40 @@ class MIRType { } bool IsMIRPtrType() const { - return (typeKind == kTypePointer); + return typeKind == kTypePointer; } bool IsMIRStructType() const { - return ((typeKind == kTypeStruct) || (typeKind == kTypeStructIncomplete)); + return (typeKind == kTypeStruct) || (typeKind == kTypeStructIncomplete); } bool IsMIRClassType() const { - return ((typeKind == kTypeClass) || (typeKind == kTypeClassIncomplete)); + return (typeKind == kTypeClass) || (typeKind == kTypeClassIncomplete); } bool IsMIRInterfaceType() const { - return ((typeKind == kTypeInterface) || (typeKind == kTypeInterfaceIncomplete)); + return (typeKind == kTypeInterface) || (typeKind == kTypeInterfaceIncomplete); } bool IsInstanceOfMIRStructType() const { - return (IsMIRStructType() || IsMIRClassType() || IsMIRInterfaceType()); + return IsMIRStructType() || IsMIRClassType() || IsMIRInterfaceType(); } bool IsMIRJarrayType() const { - return (typeKind == kTypeJArray); + return typeKind == kTypeJArray; } bool IsMIRFuncType() const { - return (typeKind == kTypeFunction); + return typeKind == kTypeFunction; } bool IsScalarType() const { - return (typeKind == kTypeScalar); - } - - bool IsIncomplete() const { - return ((typeKind == kTypeStructIncomplete) || (typeKind == kTypeClassIncomplete) || - (typeKind == kTypeInterfaceIncomplete)); + return typeKind == kTypeScalar; } bool ValidateClassOrInterface(const std::string &className, bool noWarning) const; bool IsOfSameType(MIRType &type); - const std::string &GetName(void) const; + const std::string &GetName() const; virtual std::string GetMplTypeName() const; virtual std::string GetCompactMplTypeName() const; virtual bool PointsToConstString() const; @@ -510,19 +502,19 @@ class MIRType { MIRTypeKind typeKind; PrimType primType; bool nameIsLocal = false; // needed when printing the type name - TyIdx tyIdx{0}; - GStrIdx nameStrIdx; // name in global string table + TyIdx tyIdx{ 0 }; + GStrIdx nameStrIdx{ 0 }; // name in global string table }; class MIRPtrType : public MIRType { public: - explicit MIRPtrType(TyIdx pointedTyidx) : MIRType(kTypePointer, PTY_ptr), pointedTyIdx(pointedTyidx) {} + explicit MIRPtrType(TyIdx pTyIdx) : MIRType(kTypePointer, PTY_ptr), pointedTyIdx(pTyIdx) {} - MIRPtrType(TyIdx pointedTyidx, PrimType pty) : MIRType(kTypePointer, pty), pointedTyIdx(pointedTyidx) {} + MIRPtrType(TyIdx pTyIdx, PrimType pty) : MIRType(kTypePointer, pty), pointedTyIdx(pTyIdx) {} - MIRPtrType(PrimType pty, const GStrIdx &strIdx) : MIRType(kTypePointer, pty, strIdx), pointedTyIdx(TyIdx(0)) {} + MIRPtrType(PrimType primType, GStrIdx strIdx) : MIRType(kTypePointer, primType, strIdx), pointedTyIdx(0) {} - ~MIRPtrType() = default; + ~MIRPtrType() override = default; MIRType *CopyMIRTypeNode() const override { return new MIRPtrType(*this); @@ -533,7 +525,7 @@ class MIRPtrType : public MIRType { TyIdx GetPointedTyIdx() const { return pointedTyIdx; } - void SetPointedTyIdx(const TyIdx idx) { + void SetPointedTyIdx(TyIdx idx) { pointedTyIdx = idx; } @@ -560,35 +552,26 @@ class MIRPtrType : public MIRType { class MIRArrayType : public MIRType { public: - MIRArrayType() : MIRType(kTypeArray, PTY_agg), eTyIdx(0), dim(0), sizeArray{ 0 } {} - - explicit MIRArrayType(const MIRArrayType &pat) - : MIRType(kTypeArray, PTY_agg), - eTyIdx(pat.eTyIdx), - dim(pat.dim) { - for (int i = 0; i < dim; i++) { - sizeArray[i] = pat.sizeArray[i]; - } - } - - explicit MIRArrayType(const GStrIdx strIdx) : MIRType(kTypeArray, PTY_agg, strIdx), dim(0), sizeArray{ 0 } {} + MIRArrayType() : MIRType(kTypeArray, PTY_agg) {} + explicit MIRArrayType(GStrIdx strIdx) : MIRType(kTypeArray, PTY_agg, strIdx) {} MIRArrayType(TyIdx eTyIdx, const std::vector &sizeArray) : MIRType(kTypeArray, PTY_agg), - eTyIdx(eTyIdx), dim(sizeArray.size()) { - for (int i = 0; i < kMaxArrayDim; i++) { + eTyIdx(eTyIdx), + dim(sizeArray.size()) { + for (size_t i = 0; i < kMaxArrayDim; ++i) { this->sizeArray[i] = (i < dim) ? sizeArray[i] : 0; } } - ~MIRArrayType() = default; - + MIRArrayType(const MIRArrayType &pat) = default; MIRArrayType &operator=(const MIRArrayType &p) = default; + ~MIRArrayType() override = default; TyIdx GetElemTyIdx() const { return eTyIdx; } - void SetElemtTyIdx(const TyIdx idx) { + void SetElemTyIdx(TyIdx idx) { eTyIdx = idx; } @@ -628,7 +611,7 @@ class MIRArrayType : public MIRType { return 0; } size_t numElems = sizeArray[0]; - for (int i = 1; i < dim; i++) { + for (size_t i = 1; i < dim; ++i) { CHECK_FATAL(i < kMaxArrayDim, "array index out of range"); numElems *= sizeArray[i]; } @@ -638,9 +621,9 @@ class MIRArrayType : public MIRType { size_t GetHashIndex() const override { constexpr uint8 idxShift = 2; size_t hidx = (eTyIdx.GetIdx() << idxShift) + (typeKind << kShiftNumOfTypeKind); - for (size_t i = 0; i < dim; i++) { + for (size_t i = 0; i < dim; ++i) { CHECK_FATAL(i < kMaxArrayDim, "array index out of range"); - hidx += sizeArray[i] << i; + hidx += (sizeArray[i] << i); } return hidx % kTypeHashLength; } @@ -648,9 +631,9 @@ class MIRArrayType : public MIRType { std::string GetMplTypeName() const override; std::string GetCompactMplTypeName() const override; private: - TyIdx eTyIdx; - uint16 dim; - uint32 sizeArray[kMaxArrayDim]; + TyIdx eTyIdx{ 0 }; + uint16 dim = 0; + std::array sizeArray{ 0 }; }; // flexible array type, must be last field of a top-level struct @@ -662,9 +645,12 @@ class MIRFarrayType : public MIRType { explicit MIRFarrayType(GStrIdx strIdx) : MIRType(kTypeFArray, PTY_agg, strIdx), elemTyIdx(TyIdx(0)) {} - ~MIRFarrayType() = default; + ~MIRFarrayType() override = default; + + MIRType *CopyMIRTypeNode() const override { + return new MIRFarrayType(*this); + }; - MIRType *CopyMIRTypeNode() const override; MIRType *GetElemType() const; bool HasTypeParam() const override { @@ -674,7 +660,7 @@ class MIRFarrayType : public MIRType { TyIdx GetElemTyIdx() const { return elemTyIdx; } - void SetElemtTyIdx(const TyIdx idx) { + void SetElemtTyIdx(TyIdx idx) { elemTyIdx = idx; } @@ -688,6 +674,7 @@ class MIRFarrayType : public MIRType { std::string GetMplTypeName() const override; std::string GetCompactMplTypeName() const override; + private: TyIdx elemTyIdx; }; @@ -701,13 +688,11 @@ using MIREncodedArray = std::vector; // used by kTypeStruct, kTypeStructIncomplete, kTypeUnion class MIRStructType : public MIRType { public: - explicit MIRStructType(MIRTypeKind tKind) - : MIRType(tKind, PTY_agg) {} + explicit MIRStructType(MIRTypeKind typeKind) : MIRType(typeKind, PTY_agg) {} - MIRStructType(MIRTypeKind tKind, GStrIdx strIdx) - : MIRType(tKind, PTY_agg, strIdx) {} + MIRStructType(MIRTypeKind typeKind, GStrIdx strIdx) : MIRType(typeKind, PTY_agg, strIdx) {} - ~MIRStructType() {} + ~MIRStructType() override = default; bool IsStructType() override { return true; @@ -805,54 +790,53 @@ class MIRStructType : public MIRType { isUsed = flag; } - GStrIdx GetFieldGStrIdx(FieldID fieldid) { - FieldPair fieldPair = TraverseToField(fieldid); + GStrIdx GetFieldGStrIdx(FieldID id) { + const FieldPair &fieldPair = TraverseToField(id); return fieldPair.first; } - const TyIdxFieldAttrPair GetFieldTyIdxAttrPair(FieldID fieldid) const { - FieldPair fieldPair = TraverseToField(fieldid); - return TraverseToField(fieldid).second; + const TyIdxFieldAttrPair GetFieldTyIdxAttrPair(FieldID id) const { + return TraverseToField(id).second; } - TyIdx GetFieldTyIdx(FieldID fieldid) { - FieldPair fieldPair = TraverseToField(fieldid); + TyIdx GetFieldTyIdx(FieldID id) const { + const FieldPair &fieldPair = TraverseToField(id); return fieldPair.second.first; } - FieldAttrs GetFieldAttrs(FieldID fieldid) { - FieldPair fieldPair = TraverseToField(fieldid); + FieldAttrs GetFieldAttrs(FieldID id) const { + const FieldPair &fieldPair = TraverseToField(id); return fieldPair.second.second; } - FieldAttrs GetFieldAttrs(GStrIdx fieldStrIdx) { - FieldPair fieldPair = TraverseToField(fieldStrIdx); + FieldAttrs GetFieldAttrs(GStrIdx fieldStrIdx) const { + const FieldPair &fieldPair = TraverseToField(fieldStrIdx); return fieldPair.second.second; } - bool IsFieldVolatile(FieldID fieldid) { - FieldPair fieldPair = TraverseToField(fieldid); + bool IsFieldVolatile(FieldID id) const { + const FieldPair &fieldPair = TraverseToField(id); return fieldPair.second.second.GetAttr(FLDATTR_volatile); } - bool IsFieldFinal(FieldID fieldid) { - FieldPair fieldPair = TraverseToField(fieldid); + bool IsFieldFinal(FieldID id) const { + const FieldPair &fieldPair = TraverseToField(id); return fieldPair.second.second.GetAttr(FLDATTR_final); } - bool IsFieldRCUnownedRef(FieldID fieldid) { - FieldPair fieldPair = TraverseToField(fieldid); + bool IsFieldRCUnownedRef(FieldID id) const { + const FieldPair &fieldPair = TraverseToField(id); return fieldPair.second.second.GetAttr(FLDATTR_rcunowned); } - bool IsFieldRCWeak(FieldID fieldid) { - FieldPair fieldPair = TraverseToField(fieldid); + bool IsFieldRCWeak(FieldID id) const { + const FieldPair &fieldPair = TraverseToField(id); return fieldPair.second.second.GetAttr(FLDATTR_rcweak); } - bool IsOwnField(FieldID fieldid) { - FieldPair pair = TraverseToField(fieldid); - return std::find(fields.begin(), fields.end(), pair) != fields.end(); + bool IsOwnField(FieldID id) const { + const FieldPair &fieldPair = TraverseToField(id); + return std::find(fields.begin(), fields.end(), fieldPair) != fields.end(); } bool HasVolatileField() override; @@ -895,7 +879,7 @@ class MIRStructType : public MIRType { fields.at(n).second = TyIdxFieldAttrPair(tyIdx, FieldAttrs()); } - GStrIdx GetElemStrIdx(size_t n) { + GStrIdx GetElemStrIdx(size_t n) const { ASSERT(n < fields.size(), "array index out of range"); return fields.at(n).first; } @@ -989,6 +973,7 @@ class MIRStructType : public MIRType { virtual FieldPair TraverseToFieldRef(FieldID &fieldID) const; std::string GetMplTypeName() const override; std::string GetCompactMplTypeName() const override; + protected: FieldVector fields{}; std::vector fieldInferredTyIdx{}; @@ -1026,14 +1011,14 @@ class MIRJarrayType : public MIRFarrayType { typeKind = kTypeJArray; } - ~MIRJarrayType() = default; + ~MIRJarrayType() override = default; MIRType *CopyMIRTypeNode() const override { return new MIRJarrayType(*this); } MIRStructType *GetParentType(); - const std::string &GetJavaName(void); + const std::string &GetJavaName(); bool IsPrimitiveArray() { if (javaNameStrIdx == 0) { @@ -1055,8 +1040,8 @@ class MIRJarrayType : public MIRFarrayType { } private: - TyIdx parentTyIdx{0}; // since Jarray is also an object, this is java.lang.Object - GStrIdx javaNameStrIdx{0}; // for internal java name of Jarray. nameStrIdx is used for other purpose + TyIdx parentTyIdx{ 0 }; // since Jarray is also an object, this is java.lang.Object + GStrIdx javaNameStrIdx{ 0 }; // for internal java name of Jarray. nameStrIdx is used for other purpose bool fromPrimitive = false; // the lowest dimension is primitive type int dim = 0; // the dimension if decidable at compile time. otherwise 0 void DetermineName(); // determine the internal name of this type @@ -1065,13 +1050,9 @@ class MIRJarrayType : public MIRFarrayType { // used by kTypeClass, kTypeClassIncomplete class MIRClassType : public MIRStructType { public: - explicit MIRClassType(MIRTypeKind tKind) - : MIRStructType(tKind) {} - - MIRClassType(MIRTypeKind tKind, GStrIdx strIdx) - : MIRStructType(tKind, strIdx) {} - - ~MIRClassType() = default; + explicit MIRClassType(MIRTypeKind tKind) : MIRStructType(tKind) {} + MIRClassType(MIRTypeKind tKind, GStrIdx strIdx) : MIRStructType(tKind, strIdx) {} + ~MIRClassType() override = default; bool EqualTo(const MIRType &type) const override; @@ -1087,7 +1068,7 @@ class MIRClassType : public MIRStructType { } uint32 GetInfo(const std::string &infoStr) const; uint32 GetInfo(GStrIdx strIdx) const; - uint32 GetInfoSize() const { + size_t GetInfoSize() const { return info.size(); } @@ -1130,7 +1111,7 @@ class MIRClassType : public MIRStructType { TyIdx GetParentTyIdx() const { return parentTyIdx; } - void SetParentTyIdx(const TyIdx idx) { + void SetParentTyIdx(TyIdx idx) { parentTyIdx = idx; } @@ -1161,7 +1142,7 @@ class MIRClassType : public MIRStructType { bool IsInner() const; bool HasVolatileField() override; bool HasTypeParam() const override; - virtual FieldPair TraverseToFieldRef(FieldID &fieldID) const override; + FieldPair TraverseToFieldRef(FieldID &fieldID) const override; size_t GetSize() const override; FieldID GetLastFieldID() const; @@ -1175,11 +1156,10 @@ class MIRClassType : public MIRStructType { const MIRClassType *GetExceptionRootType() const; bool IsExceptionType() const; void AddImplementedInterface(TyIdx interfaceTyIdx) { - if (std::find(interfacesImplemented.begin(), interfacesImplemented.end(), interfaceTyIdx) != + if (std::find(interfacesImplemented.begin(), interfacesImplemented.end(), interfaceTyIdx) == interfacesImplemented.end()) { - return; + interfacesImplemented.push_back(interfaceTyIdx); } - interfacesImplemented.push_back(interfaceTyIdx); } void ClearContents() override { @@ -1197,7 +1177,7 @@ class MIRClassType : public MIRStructType { } private: - TyIdx parentTyIdx{0}; + TyIdx parentTyIdx{ 0 }; std::vector interfacesImplemented{}; // for the list of interfaces the class implements std::vector info{}; std::vector infoIsString{}; @@ -1208,13 +1188,9 @@ class MIRClassType : public MIRStructType { // used by kTypeInterface, kTypeInterfaceIncomplete class MIRInterfaceType : public MIRStructType { public: - explicit MIRInterfaceType(MIRTypeKind tKind) - : MIRStructType(tKind) {} - - MIRInterfaceType(MIRTypeKind tKind, GStrIdx strIdx) - : MIRStructType(tKind, strIdx) {} - - ~MIRInterfaceType() = default; + explicit MIRInterfaceType(MIRTypeKind tKind) : MIRStructType(tKind) {} + MIRInterfaceType(MIRTypeKind tKind, GStrIdx strIdx) : MIRStructType(tKind, strIdx) {} + ~MIRInterfaceType() override = default; bool EqualTo(const MIRType &type) const override; @@ -1230,7 +1206,7 @@ class MIRInterfaceType : public MIRStructType { } uint32 GetInfo(const std::string &infoStr) const; uint32 GetInfo(GStrIdx strIdx) const; - uint32 GetInfoSize() const { + size_t GetInfoSize() const { return info.size(); } @@ -1287,7 +1263,7 @@ class MIRInterfaceType : public MIRStructType { void Dump(int indent, bool dontUseName = false) const override; bool HasVolatileField() override; bool HasTypeParam() const override; - virtual FieldPair TraverseToFieldRef(FieldID &fieldID) const override; + FieldPair TraverseToFieldRef(FieldID &fieldID) const override; void SetComplete() override { typeKind = kTypeInterface; } @@ -1319,10 +1295,8 @@ class MIRInterfaceType : public MIRStructType { class MIRBitFieldType : public MIRType { public: MIRBitFieldType(uint8 field, PrimType pt) : MIRType(kTypeBitField, pt), fieldSize(field) {} - MIRBitFieldType(uint8 field, PrimType pt, GStrIdx strIdx) : MIRType(kTypeBitField, pt, strIdx), fieldSize(field) {} - - ~MIRBitFieldType() = default; + ~MIRBitFieldType() override = default; uint8 GetFieldSize() const { return fieldSize; @@ -1348,7 +1322,9 @@ class MIRBitFieldType : public MIRType { class MIRFuncType : public MIRType { public: - MIRFuncType() : MIRType(kTypeFunction, PTY_ptr), paramTypeList(), paramAttrsList() {} + MIRFuncType() : MIRType(kTypeFunction, PTY_ptr) {} + + explicit MIRFuncType(GStrIdx strIdx) : MIRType(kTypeFunction, PTY_ptr, strIdx) {} MIRFuncType(TyIdx retTyIdx, const std::vector &vecTy, const std::vector &vecAt) : MIRType(kTypeFunction, PTY_ptr), @@ -1356,13 +1332,7 @@ class MIRFuncType : public MIRType { paramTypeList(vecTy), paramAttrsList(vecAt) {} - explicit MIRFuncType(GStrIdx strIdx) - : MIRType(kTypeFunction, PTY_ptr, strIdx), - retTyIdx(TyIdx(0)), - paramTypeList(), - paramAttrsList() {} - - ~MIRFuncType() = default; + ~MIRFuncType() override = default; bool EqualTo(const MIRType &type) const override; MIRType *CopyMIRTypeNode() const override { @@ -1395,7 +1365,7 @@ class MIRFuncType : public MIRType { return paramTypeList[i]; } - void SetParamTypeList(std::vector &list) { + void SetParamTypeList(const std::vector &list) { paramTypeList = list; } @@ -1433,30 +1403,32 @@ class MIRFuncType : public MIRType { constexpr uint8 kIdxShift = 6; size_t hidx = (retTyIdx.GetIdx() << kIdxShift) + (typeKind << kShiftNumOfTypeKind); size_t size = paramTypeList.size(); - hidx += ((size) ? (paramTypeList[0].GetIdx() + size) : 0) << 4; + hidx += (size ? (paramTypeList[0].GetIdx() + size) : 0) << 4; return hidx % kTypeHashLength; } private: - TyIdx retTyIdx; - std::vector paramTypeList; - std::vector paramAttrsList; + TyIdx retTyIdx{ 0 }; + std::vector paramTypeList{}; + std::vector paramAttrsList{}; bool isVarArgs = false; }; class MIRTypeByName : public MIRType { // use nameStrIdx to store the name for both local and global public: - bool EqualTo(const MIRType &type) const override; - explicit MIRTypeByName(GStrIdx sidx) : MIRType(kTypeByName, PTY_void) { - nameStrIdx = sidx; + explicit MIRTypeByName(GStrIdx gStrIdx) : MIRType(kTypeByName, PTY_void) { + nameStrIdx = gStrIdx; } - ~MIRTypeByName() = default; + ~MIRTypeByName() override = default; + MIRType *CopyMIRTypeNode() const override { return new MIRTypeByName(*this); } + bool EqualTo(const MIRType &type) const override; + void Dump(int indent, bool dontUseName = false) const override; size_t GetSize() const override { return 0; @@ -1471,11 +1443,11 @@ class MIRTypeByName : public MIRType { class MIRTypeParam : public MIRType { // use nameStrIdx to store the name public: - explicit MIRTypeParam(GStrIdx sidx) : MIRType(kTypeParam, PTY_gen) { - nameStrIdx = sidx; + explicit MIRTypeParam(GStrIdx gStrIdx) : MIRType(kTypeParam, PTY_gen) { + nameStrIdx = gStrIdx; } - ~MIRTypeParam() = default; + ~MIRTypeParam() override = default; MIRType *CopyMIRTypeNode() const override { return new MIRTypeParam(*this); @@ -1507,7 +1479,8 @@ class MIRInstantVectorType : public MIRType { MIRInstantVectorType(MIRTypeKind kind, GStrIdx strIdx) : MIRType(kind, PTY_agg, strIdx) {} - ~MIRInstantVectorType() = default; + ~MIRInstantVectorType() override = default; + MIRType *CopyMIRTypeNode() const override { return new MIRInstantVectorType(*this); } @@ -1528,7 +1501,7 @@ class MIRInstantVectorType : public MIRType { size_t GetHashIndex() const override { uint32 hidx = typeKind << kShiftNumOfTypeKind; - for (TypePair typePair : instantVec) { + for (const TypePair &typePair : instantVec) { hidx += (typePair.first.GetIdx() + typePair.second.GetIdx()) << 3; } return hidx % kTypeHashLength; @@ -1544,9 +1517,9 @@ class MIRGenericInstantType : public MIRInstantVectorType { : MIRInstantVectorType(kTypeGenericInstant), genericTyIdx(genTyIdx) {} explicit MIRGenericInstantType(GStrIdx strIdx) - : MIRInstantVectorType(kTypeGenericInstant, strIdx), genericTyIdx(TyIdx(0)) {} + : MIRInstantVectorType(kTypeGenericInstant, strIdx), genericTyIdx(0) {} - ~MIRGenericInstantType() = default; + ~MIRGenericInstantType() override = default; MIRType *CopyMIRTypeNode() const override { return new MIRGenericInstantType(*this); @@ -1569,7 +1542,7 @@ class MIRGenericInstantType : public MIRInstantVectorType { size_t GetHashIndex() const override { constexpr uint8 kIdxShift = 2; uint32 hidx = (genericTyIdx.GetIdx() << kIdxShift) + (typeKind << kShiftNumOfTypeKind); - for (TypePair typePair : instantVec) { + for (const TypePair &typePair : instantVec) { hidx += (typePair.first.GetIdx() + typePair.second.GetIdx()) << 3; } return hidx % kTypeHashLength; @@ -1578,7 +1551,6 @@ class MIRGenericInstantType : public MIRInstantVectorType { private: TyIdx genericTyIdx; // the generic type to be instantiated }; - #endif // MIR_FEATURE_FULL } // namespace maple #endif // MAPLE_IR_INCLUDE_MIR_TYPE_H diff --git a/src/maple_ir/include/opcode_info.h b/src/maple_ir/include/opcode_info.h index 3629f9d4ad15d250e347aeccb927116c0e2bdb10..0fde39b5427e7ceb9fb20e090e965fb59fac7b2f 100644 --- a/src/maple_ir/include/opcode_info.h +++ b/src/maple_ir/include/opcode_info.h @@ -31,7 +31,7 @@ enum OpcodeProp { kOpcodePropIsCall, // The instruction is among the call instructions kOpcodePropIsCallAssigned, // The instruction is among the call instructions with implicit assignments of the // returned values - kOpcodePropNotPure, // The operation does not return same result with idential operands + kOpcodePropNotPure, // The operation does not return same result with idential operands kOpcodePropMayThrowException, }; diff --git a/src/maple_ir/include/option.h b/src/maple_ir/include/option.h index cdeb60a26b018157dc3125d3784e1a0e7f4f85dd..3a8496f477eec2fd2602088f0c20fb63e2c97ef5 100644 --- a/src/maple_ir/include/option.h +++ b/src/maple_ir/include/option.h @@ -25,9 +25,6 @@ namespace maple { constexpr uint32 kNoDecouple = 0; constexpr uint32 kConservativeDecouple = 1; constexpr uint32 kRadicalDecouple = 2; -constexpr uint32 kNoLazyBinding = 0; -constexpr uint32 kLazyBindingUseConditionCall = 1; -constexpr uint32 kLazyBindingUseSegv = 2; class Options { public: explicit Options(maple::MemPool &memPool) : optionAlloc(&memPool) {} diff --git a/src/maple_ir/src/bin_mpl_export.cpp b/src/maple_ir/src/bin_mpl_export.cpp index a7249b3983d34b640f773be507ab22b3ada293f2..96337769b6b0f75eb47e13eb4ca7b72d0ebc18ad 100644 --- a/src/maple_ir/src/bin_mpl_export.cpp +++ b/src/maple_ir/src/bin_mpl_export.cpp @@ -303,7 +303,7 @@ uint8 BinaryMplExport::Read() { return buf[bufI++]; } -/* Little endian */ +// Little endian int32 BinaryMplExport::ReadInt() { uint32 x0 = static_cast(Read()); uint32 x1 = static_cast(Read()); @@ -317,7 +317,7 @@ void BinaryMplExport::Write(uint8 b) { buf.push_back(b); } -/* Little endian */ +// Little endian void BinaryMplExport::WriteInt(int32 x) { Write(static_cast(static_cast(x) & 0xFF)); Write(static_cast((static_cast(x) >> 8) & 0xFF)); @@ -341,7 +341,7 @@ void BinaryMplExport::WriteInt64(int64 x) { WriteInt(static_cast((static_cast(x) >> 32) & 0xFFFFFFFF)); } -/* LEB128 */ +// LEB128 void BinaryMplExport::WriteNum(int64 x) { while (x < -0x40 || x >= 0x40) { Write(static_cast((static_cast(x) & 0x7F) + 0x80)); diff --git a/src/maple_ir/src/bin_mpl_import.cpp b/src/maple_ir/src/bin_mpl_import.cpp index f04845623c9ab10e1831af396accc84afe0c9fcb..33aaf10434221607fe90586178abcba616de22a4 100644 --- a/src/maple_ir/src/bin_mpl_import.cpp +++ b/src/maple_ir/src/bin_mpl_import.cpp @@ -30,7 +30,7 @@ uint8 BinaryMplImport::Read() { return buf[bufI++]; } -/* Little endian */ +// Little endian int32 BinaryMplImport::ReadInt() { uint32 x0 = static_cast(Read()); uint32 x1 = static_cast(Read()); @@ -46,7 +46,7 @@ int64 BinaryMplImport::ReadInt64() { return static_cast((x1 << 32) + x0); } -/* LEB128 */ +// LEB128 int64 BinaryMplImport::ReadNum() { uint64 n = 0; int64 y = 0; @@ -554,7 +554,7 @@ TyIdx BinaryMplImport::ImportType(bool forPointedType) { } size_t idx = typTab.size(); typTab.push_back(nullptr); - type.SetElemtTyIdx(ImportType(forPointedType)); + type.SetElemTyIdx(ImportType(forPointedType)); MIRType *origType = &InsertInTypeTables(type); typTab[idx] = origType; return origType->GetTypeIndex(); @@ -853,7 +853,7 @@ void BinaryMplImport::ReadContentField() { void BinaryMplImport::Jump2NextField() { uint32 totalSize = ReadInt(); bufI += (totalSize - sizeof(uint32)); - ReadNum(); /// skip end tag for this field + ReadNum(); // skip end tag for this field } bool BinaryMplImport::Import(const std::string &fname, bool readSymbols, bool readSe) { diff --git a/src/maple_ir/src/mir_type.cpp b/src/maple_ir/src/mir_type.cpp index fa3d6193cf5de12289014aa55de20b62bb5b2676..629d4afdd7b967ac8e68e45775a236565715092b 100644 --- a/src/maple_ir/src/mir_type.cpp +++ b/src/maple_ir/src/mir_type.cpp @@ -76,9 +76,9 @@ bool VerifyPrimType(PrimType primType1, PrimType primType2) { } } -PrimType GetDynType(PrimType pType) { +PrimType GetDynType(PrimType primType) { #ifdef DYNAMICLANG - switch (pType) { + switch (primType) { case PTY_u1: return PTY_dynbool; case PTY_i32: @@ -92,16 +92,16 @@ PrimType GetDynType(PrimType pType) { case PTY_f64: return PTY_dynf64; default: - return pType; + return primType; } #else - return pType; + return primType; #endif } -PrimType GetNonDynType(PrimType pType) { +PrimType GetNonDynType(PrimType primType) { #ifdef DYNAMICLANG - switch (pType) { + switch (primType) { case PTY_dynbool: return PTY_u1; case PTY_dyni32: @@ -115,10 +115,10 @@ PrimType GetNonDynType(PrimType pType) { case PTY_dynf64: return PTY_f64; default: - return pType; + return primType; } #else - return pType; + return primType; #endif } @@ -140,10 +140,6 @@ bool IsNoCvtNeeded(PrimType toType, PrimType fromType) { } } -bool IsRefOrPtrAssign(PrimType toType, PrimType fromType) { - return (toType == PTY_ref && fromType == PTY_ptr) || (toType == PTY_ptr && fromType == PTY_ref); -} - // answer in bytes; 0 if unknown uint32 GetPrimTypeSize(PrimType primType) { switch (primType) { @@ -241,8 +237,8 @@ const char *GetPrimTypeName(PrimType primType) { case kPtyInvalid: return "kPtyInvalid"; #define PRIMTYPE(P) \ - case PTY_##P: \ - return #P; + case PTY_##P: \ + return #P; #include "prim_types.def" #undef PRIMTYPE case kPtyDerived: @@ -320,15 +316,14 @@ bool MIRType::ValidateClassOrInterface(const std::string &className, bool noWarn return true; } if (!noWarning) { - int len = className.size(); + size_t len = className.size(); constexpr int minClassNameLen = 4; constexpr char suffix[] = "_3B"; - int suffixLen = std::strlen(suffix); + size_t suffixLen = std::strlen(suffix); if (len > minClassNameLen && strncmp(className.c_str() + len - suffixLen, suffix, suffixLen) == 0) { - LogInfo::MapleLogger(kLlErr) << "error: missing proper mplt file for " << className << std::endl; + LogInfo::MapleLogger(kLlErr) << "error: missing proper mplt file for " << className << '\n'; } else { - LogInfo::MapleLogger(kLlErr) << "internal error: type is not java class or interface " - << className << std::endl; + LogInfo::MapleLogger(kLlErr) << "internal error: type is not java class or interface " << className << '\n'; } } return false; @@ -413,7 +408,7 @@ void MIRType::DumpAsCxx(int indent) const { LogInfo::MapleLogger() << "double complex"; break; default: - ASSERT(false, "NYI"); + ASSERT(false, "not yet implemented"); } } @@ -423,8 +418,8 @@ bool MIRType::IsOfSameType(MIRType &type) { } if (typeKind == kTypePointer) { - MIRPtrType &ptrType = static_cast(*this); - MIRPtrType &ptrTypeIt = static_cast(type); + const auto &ptrType = static_cast(*this); + const auto &ptrTypeIt = static_cast(type); if (ptrType.GetPointedTyIdx() == ptrTypeIt.GetPointedTyIdx()) { return true; } else { @@ -432,8 +427,8 @@ bool MIRType::IsOfSameType(MIRType &type) { return GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptrType.GetPointedTyIdx())->IsOfSameType(mirTypeIt); } } else if (typeKind == kTypeJArray) { - MIRJarrayType &atype1 = static_cast(*this); - MIRJarrayType &atype2 = static_cast(type); + auto &atype1 = static_cast(*this); + auto &atype2 = static_cast(type); if (atype1.GetDim() != atype2.GetDim()) { return false; } @@ -463,7 +458,7 @@ void MIRFuncType::Dump(int indent, bool dontUseName) const { } LogInfo::MapleLogger() << "Dump(indent + 1); if (size - 1 != i) { LogInfo::MapleLogger() << ","; @@ -497,9 +492,6 @@ std::string MIRArrayType::GetCompactMplTypeName() const { ss << elemType->GetCompactMplTypeName(); return ss.str(); } -MIRType *MIRFarrayType::CopyMIRTypeNode() const { - return new MIRFarrayType(*this); -} void MIRFarrayType::Dump(int indent, bool dontUseName) const { if (!dontUseName && CheckAndDumpTypeName(nameStrIdx, nameIsLocal)) { @@ -559,7 +551,7 @@ void MIRJarrayType::DetermineName() { auto *tmpPtype = static_cast(ptype); elemType = tmpPtype->GetElemType(); ASSERT(elemType != nullptr, "elemType is null in MIRJarrayType::DetermineName"); - dim++; + ++dim; } else { ASSERT(false, "unexpected type!"); } @@ -611,7 +603,7 @@ size_t MIRClassType::GetSize() const { if (parentTyIdx == 0) { return MIRStructType::GetSize(); } - auto *parentType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); + const auto *parentType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); size_t parentSize = parentType->GetSize(); if (parentSize == 0) { return 0; @@ -624,18 +616,20 @@ size_t MIRClassType::GetSize() const { } FieldID MIRClassType::GetFirstLocalFieldID() const { - 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*); - CHECK_FATAL(parentClassType != nullptr, "null pointer check"); - return (!parentClassType->IsLocal()) ? parentClassType->GetLastFieldID() + lastFieldIDOffset - : parentClassType->GetFirstLocalFieldID() + firstLocalFieldIDOffset; } - return 1; + if (parentTyIdx == 0) { + return 1; + } + + constexpr uint8 lastFieldIDOffset = 2; + constexpr uint8 firstLocalFieldIDOffset = 1; + const auto *parentClassType = + MIR_DYN_CAST(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx), const MIRClassType*); + CHECK_FATAL(parentClassType != nullptr, "null pointer check"); + return !parentClassType->IsLocal() ? parentClassType->GetLastFieldID() + lastFieldIDOffset + : parentClassType->GetFirstLocalFieldID() + firstLocalFieldIDOffset; } const MIRClassType *MIRClassType::GetExceptionRootType() const { @@ -665,8 +659,8 @@ bool MIRClassType::IsExceptionType() const { FieldID MIRClassType::GetLastFieldID() const { FieldID fieldID = fields.size(); if (parentTyIdx != 0) { - MIRClassType *parentClassType = - MIR_DYN_CAST(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx), MIRClassType*); + const auto *parentClassType = + MIR_DYN_CAST(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx), const MIRClassType*); if (parentClassType != nullptr) { fieldID += parentClassType->GetLastFieldID() + 1; } @@ -709,8 +703,8 @@ uint32 MIRInterfaceType::GetInfo(GStrIdx strIdx) const { // return class id or superclass id accroding to input string uint32 MIRInterfaceType::GetInfo(const std::string &infoStr) const { - GStrIdx stridx = GlobalTables::GetStrTable().GetStrIdxFromName(infoStr); - return GetInfo(stridx); + GStrIdx strIdx = GlobalTables::GetStrTable().GetStrIdxFromName(infoStr); + return GetInfo(strIdx); } size_t MIRInterfaceType::GetSize() const { if (parentsTyIdx.empty()) { @@ -720,9 +714,9 @@ size_t MIRInterfaceType::GetSize() const { if (size == 0) { return 0; } - for (size_t i = 0; i < parentsTyIdx.size(); i++) { - auto *parentType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentsTyIdx[i])); + for (size_t i = 0; i < parentsTyIdx.size(); ++i) { + const auto *parentType = + static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentsTyIdx[i])); size_t parentSize = parentType->GetSize(); if (parentSize == 0) { return 0; @@ -902,7 +896,7 @@ static void DumpInterfaces(std::vector interfaces, int indent) { size_t MIRStructType::GetSize() const { if (typeKind == kTypeUnion) { size_t maxSize = GetElemType(0)->GetSize(); - for (size_t i = 1; i < fields.size(); i++) { + for (size_t i = 1; i < fields.size(); ++i) { size_t size = GetElemType(i)->GetSize(); if (size == 0) { return 0; @@ -914,7 +908,7 @@ size_t MIRStructType::GetSize() const { return maxSize; } size_t size = 0; - for (size_t i = 0; i < fields.size(); i++) { + for (size_t i = 0; i < fields.size(); ++i) { size_t fieldSize = GetElemType(i)->GetSize(); if (fieldSize == 0) { return 0; @@ -933,7 +927,7 @@ void MIRStructType::DumpFieldsAndMethods(int indent, bool hasMethod) const { } DumpFields(staticFields, indent, true); bool hasFieldOrStaticField = hasField || hasStaticField; - bool hasParentField = parentFields.size(); + bool hasParentField = !parentFields.empty(); if (hasFieldOrStaticField && hasParentField) { LogInfo::MapleLogger() << ","; } @@ -948,9 +942,9 @@ void MIRStructType::Dump(int indent, bool dontUseName) const { if (!dontUseName && CheckAndDumpTypeName(nameStrIdx, nameIsLocal)) { return; } - LogInfo::MapleLogger() << ((typeKind == kTypeStruct) - ? ""; } @@ -961,8 +955,8 @@ uint32 MIRClassType::GetInfo(GStrIdx strIdx) const { // return class id or superclass id accroding to input string uint32 MIRClassType::GetInfo(const std::string &infoStr) const { - GStrIdx stridx = GlobalTables::GetStrTable().GetStrIdxFromName(infoStr); - return GetInfo(stridx); + GStrIdx strIdx = GlobalTables::GetStrTable().GetStrIdxFromName(infoStr); + return GetInfo(strIdx); } bool MIRClassType::IsFinal() const { @@ -973,7 +967,7 @@ bool MIRClassType::IsFinal() const { } bool MIRClassType::IsInner() const { - const std::string name = GetName(); + const std::string &name = GetName(); return name.find("_24") != std::string::npos; } @@ -1026,9 +1020,9 @@ void MIRClassType::Dump(int indent, bool dontUseName) const { } void MIRClassType::DumpAsCxx(int indent) const { - LogInfo::MapleLogger() << "{" << std::endl; + LogInfo::MapleLogger() << "{\n"; DumpFieldsAsCxx(fields, indent); - LogInfo::MapleLogger() << "};" << std::endl; + LogInfo::MapleLogger() << "};\n"; DumpConstructorsAsCxx(methods, 0); } @@ -1061,15 +1055,15 @@ void MIRTypeParam::Dump(int indent, bool dontUseName) const { void MIRInstantVectorType::Dump(int indent, bool dontUseName) const { LogInfo::MapleLogger() << "{"; - for (size_t i = 0; i < instantVec.size(); i++) { - TypePair tpair = instantVec[i]; + for (size_t i = 0; i < instantVec.size(); ++i) { + TypePair typePair = instantVec[i]; if (i != 0) { LogInfo::MapleLogger() << ", "; } - MIRType *typeParmType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tpair.first); + MIRType *typeParmType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(typePair.first); const std::string &name = GlobalTables::GetStrTable().GetStringFromStrIdx(typeParmType->GetNameStrIdx()); LogInfo::MapleLogger() << "!" << name << "="; - MIRType *realty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tpair.second); + MIRType *realty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(typePair.second); realty->Dump(0); } LogInfo::MapleLogger() << "}"; @@ -1077,14 +1071,14 @@ void MIRInstantVectorType::Dump(int indent, bool dontUseName) const { void MIRGenericInstantType::Dump(int indent, bool dontUseName) const { LogInfo::MapleLogger() << "<"; - MIRType *genericty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(genericTyIdx); - DumpTypeName(genericty->GetNameStrIdx(), genericty->IsNameIsLocal()); + const MIRType *genericType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(genericTyIdx); + DumpTypeName(genericType->GetNameStrIdx(), genericType->IsNameIsLocal()); MIRInstantVectorType::Dump(indent, dontUseName); LogInfo::MapleLogger() << ">"; } bool MIRType::EqualTo(const MIRType &mirType) const { - return (typeKind == mirType.typeKind && primType == mirType.primType); + return typeKind == mirType.typeKind && primType == mirType.primType; } bool MIRPtrType::EqualTo(const MIRType &type) const { @@ -1103,7 +1097,7 @@ bool MIRArrayType::EqualTo(const MIRType &type) const { if (dim != pType.GetDim() || eTyIdx != pType.GetElemTyIdx()) { return false; } - for (int i = 0; i < dim; i++) { + for (size_t i = 0; i < dim; ++i) { if (GetSizeArrayItem(i) != pType.GetSizeArrayItem(i)) { return false; } @@ -1150,8 +1144,8 @@ bool MIRFuncType::EqualTo(const MIRType &type) const { return false; } const auto &pType = static_cast(type); - return (pType.retTyIdx == retTyIdx && pType.paramTypeList == paramTypeList && pType.isVarArgs == isVarArgs && - pType.paramAttrsList == paramAttrsList); + return (pType.retTyIdx == retTyIdx && pType.paramTypeList == paramTypeList && + pType.isVarArgs == isVarArgs && pType.paramAttrsList == paramAttrsList); } bool MIRBitFieldType::EqualTo(const MIRType &type) const { @@ -1175,7 +1169,7 @@ MIRType *MIRStructType::GetElemType(uint32 n) const { } MIRType *MIRStructType::GetFieldType(FieldID fieldID) { - FieldPair fieldPair = TraverseToField(fieldID); + const FieldPair &fieldPair = TraverseToField(fieldID); return GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldPair.second.first); } @@ -1266,7 +1260,7 @@ FieldPair MIRStructType::TraverseToField(FieldID fieldID) const { // in parentfields uint32 parentFieldIdx = -fieldID; if (parentFields.empty() || parentFieldIdx > parentFields.size()) { - return FieldPair(GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs())); + return { GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs()) }; } return parentFields[parentFieldIdx - 1]; } @@ -1282,13 +1276,13 @@ static bool TraverseToFieldInFields(const FieldVector &fields, const GStrIdx &fi } FieldPair MIRStructType::TraverseToField(GStrIdx fieldStrIdx) const { - FieldPair field; - if ((!fields.empty() && TraverseToFieldInFields(fields, fieldStrIdx, field)) || - (!staticFields.empty() && TraverseToFieldInFields(staticFields, fieldStrIdx, field)) || - TraverseToFieldInFields(parentFields, fieldStrIdx, field)) { - return field; + FieldPair fieldPair; + if ((!fields.empty() && TraverseToFieldInFields(fields, fieldStrIdx, fieldPair)) || + (!staticFields.empty() && TraverseToFieldInFields(staticFields, fieldStrIdx, fieldPair)) || + TraverseToFieldInFields(parentFields, fieldStrIdx, fieldPair)) { + return fieldPair; } - return FieldPair(GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs())); + return { GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs()) }; } bool MIRStructType::HasVolatileFieldInFields(const FieldVector &fieldsOfStruct) { @@ -1338,7 +1332,7 @@ bool MIRInterfaceType::HasVolatileField() { } bool MIRStructType::HasTypeParamInFields(const FieldVector &fieldsOfStruct) const { - for (FieldPair field : fieldsOfStruct) { + for (const FieldPair &field : fieldsOfStruct) { if (field.second.second.GetAttr(FLDATTR_generic)) { return true; } @@ -1371,11 +1365,10 @@ bool MIRInterfaceType::HasTypeParam() const { FieldPair MIRClassType::TraverseToFieldRef(FieldID &fieldID) const { if (parentTyIdx != 0) { - MIRClassType *parentClassType = - MIR_DYN_CAST(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx), MIRClassType*); + auto *parentClassType = MIR_DYN_CAST(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx), MIRClassType*); if (parentClassType != nullptr) { - fieldID--; - FieldPair curPair = parentClassType->TraverseToFieldRef(fieldID); + --fieldID; + const FieldPair &curPair = parentClassType->TraverseToFieldRef(fieldID); if (fieldID == 1 && curPair.second.first != 0) { return curPair; } @@ -1386,7 +1379,7 @@ FieldPair MIRClassType::TraverseToFieldRef(FieldID &fieldID) const { // fields in interface are all static and are global, won't be accessed through fields FieldPair MIRInterfaceType::TraverseToFieldRef(FieldID &fieldID) const { - return FieldPair(GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs())); + return { GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs()) }; } TyIdxFieldAttrPair MIRPtrType::GetPointedTyIdxFldAttrPairWithFieldID(FieldID fieldID) const { @@ -1423,12 +1416,12 @@ std::string MIRPtrType::GetCompactMplTypeName() const { TypeAttrs FieldAttrs::ConvertToTypeAttrs() { TypeAttrs attr; constexpr uint32 maxAttrNum = 64; - for (uint32 i = 0; i < maxAttrNum; i++) { + for (uint32 i = 0; i < maxAttrNum; ++i) { if ((attrFlag & (1ULL << i)) == 0) { continue; } - FieldAttrKind tA = static_cast(i); - switch (tA) { + auto attrKind = static_cast(i); + switch (attrKind) { #define FIELD_ATTR #define ATTR(STR) \ case FLDATTR_##STR: \ diff --git a/src/maple_ir/src/parser.cpp b/src/maple_ir/src/parser.cpp index 3d605f8b674e085ca7c594f5619de51ab93509c5..46e36e55260e4b94dddf6880996384edfb2e3b5b 100644 --- a/src/maple_ir/src/parser.cpp +++ b/src/maple_ir/src/parser.cpp @@ -592,7 +592,7 @@ bool MIRParser::ParseFields(MIRStructType &type) { TokenKind tk = lexer.NextToken(); MIRTypeKind tyKind = type.GetKind(); while (tk == TK_label || tk == kTkPrntfield || tk == TK_pragma) { - bool isPragma = tk == TK_pragma; + bool isPragma = (tk == TK_pragma); bool notaType = false; TyIdx fieldTyIdx(0); bool isParentField = false; @@ -658,9 +658,9 @@ bool MIRParser::ParseFields(MIRStructType &type) { } else if ((tk == kTkIntconst || tk == kTkString) && !isParentField && (tyKind == kTypeClass || tyKind == kTypeClassIncomplete || tyKind == kTypeInterface || tyKind == kTypeInterfaceIncomplete)) { - uint32 infoVal = (tk == kTkIntconst) - ? lexer.GetTheIntVal() - : GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()).GetIdx(); + uint32 infoVal = + (tk == kTkIntconst) ? lexer.GetTheIntVal() + : GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()).GetIdx(); type.PushbackMIRInfo(MIRInfoPair(strIdx, infoVal)); type.PushbackIsString(tk != kTkIntconst); notaType = true; @@ -738,7 +738,6 @@ bool MIRParser::ParseFields(MIRStructType &type) { 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"); fn->Init(); fn->SetPuidx(GlobalTables::GetFunctionTable().GetFuncTable().size()); GlobalTables::GetFunctionTable().GetFuncTable().push_back(fn); @@ -821,7 +820,8 @@ bool MIRParser::ParseStructType(TyIdx &styIdx) { case TK_union: tkind = kTypeUnion; break; - default:; + default: + break; } if (lexer.NextToken() != kTkLbrace) { Error("expect { parsing struct body"); @@ -1136,7 +1136,7 @@ bool MIRParser::ParseDefinedTypename(TyIdx &definedTyIdx, MIRTypeKind kind) { if (prevTypeIdx != 0 && prevTypeIdx != definedTyIdx) { // replace all uses of prevTypeIdx by tyIdx in type_table_ typeDefIdxMap[prevTypeIdx] = definedTyIdx; - // remove prevTypeIdx from classlist + // remove prevTypeIdx from classlist mod.RemoveClass(prevTypeIdx); } lexer.NextToken(); @@ -2192,7 +2192,7 @@ static void GenJStringType(MIRModule &module) { metaClassType.GetFields().push_back(FieldPair(stridx, TyIdxFieldAttrPair(TyIdx(PTY_ref), FieldAttrs()))); stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("__class_meta__"); TyIdx tyidx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&metaClassType); - // Global? + // Global module.GetTypeNameTab()->SetGStrIdxToTyIdx(stridx, tyidx); ASSERT(GlobalTables::GetTypeTable().GetTypeTable().empty() == false, "container check"); if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx)->GetNameStrIdx() == 0) { @@ -2266,9 +2266,9 @@ 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); + BinaryMplt binMplt(mod); std::string importFilename = *it; - if (!binmplt.Import(importFilename, false, true)) { // not a binary mplt + 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()); @@ -2345,7 +2345,6 @@ bool MIRParser::ParseMIRForVar() { if (prevSt->GetStorageClass() == kScExtern) { prevSt->SetStorageClass(st.GetStorageClass()); } - } else { } } else { // seeing the first time maple::MIRBuilder mirBuilder(&mod); @@ -2618,9 +2617,9 @@ bool MIRParser::ParseMIRForImport() { FATAL(kLncFatal, "MPLT file has wrong suffix: %s\n", importFileName.c_str()); } if (paramIsIPA && firstImport) { - BinaryMplt *binmplt = new BinaryMplt(mod); - mod.SetBinMplt(binmplt); - if (!(*binmplt).Import(importFileName, paramIsIPA && !firstImport, paramIsComb)) { // not a binary mplt + BinaryMplt *binMplt = new BinaryMplt(mod); + mod.SetBinMplt(binMplt); + if (!(*binMplt).Import(importFileName, paramIsIPA && !firstImport, paramIsComb)) { // not a binary mplt std::ifstream mpltFile(importFileName); if (!mpltFile.is_open()) { FATAL(kLncFatal, "cannot open MPLT file: %s\n", importFileName.c_str()); @@ -2632,8 +2631,8 @@ bool MIRParser::ParseMIRForImport() { } } } else { - BinaryMplt binmplt(mod); - if (!binmplt.Import(importFileName, paramIsIPA, false)) { // not a binary mplt + BinaryMplt binMplt(mod); + if (!binMplt.Import(importFileName, paramIsIPA, false)) { // not a binary mplt std::ifstream mpltFile(importFileName); if (!mpltFile.is_open()) { FATAL(kLncFatal, "cannot open MPLT file: %s\n", importFileName.c_str()); diff --git a/src/maple_me/include/alias_class.h b/src/maple_me/include/alias_class.h index 57ea74e9fd51c82a0b25d3d06ca76c12e48e102b..f5cf1074cc64ba316f5fc0ff1a93bf4460559402 100644 --- a/src/maple_me/include/alias_class.h +++ b/src/maple_me/include/alias_class.h @@ -90,8 +90,8 @@ class AliasElem { class AliasClass : public AnalysisResult { public: - AliasClass(MemPool &memPool, MIRModule &mod, SSATab &ssatb, bool lessThrowAliasParam, bool finalFieldHasAlias, - bool ignoreIpa, bool setCalleeHasSideEffect = false, KlassHierarchy *kh = nullptr) + AliasClass(MemPool &memPool, MIRModule &mod, SSATab &ssatb, bool lessThrowAliasParam, bool ignoreIPA, + bool setCalleeHasSideEffect = false, KlassHierarchy *kh = nullptr) : AnalysisResult(&memPool), mirModule(mod), acMemPool(memPool), @@ -104,8 +104,7 @@ class AliasClass : public AnalysisResult { globalsAffectedByCalls(std::less(), acAlloc.Adapter()), globalsMayAffectedByClinitCheck(acAlloc.Adapter()), lessThrowAlias(lessThrowAliasParam), - finalFieldAlias(finalFieldHasAlias), - ignoreIPA(ignoreIpa), + ignoreIPA(ignoreIPA), calleeHasSideEffect(setCalleeHasSideEffect), klassHierarchy(kh), aliasAnalysisTable(nullptr) {} @@ -174,7 +173,6 @@ class AliasClass : public AnalysisResult { // aliased at calls; needed only when wholeProgramScope is true MapleSet globalsMayAffectedByClinitCheck; bool lessThrowAlias; - bool finalFieldAlias; // whether to regard final fields as having alias; bool ignoreIPA; // whether to ignore information provided by IPA bool calleeHasSideEffect; KlassHierarchy *klassHierarchy; @@ -191,6 +189,8 @@ class AliasClass : public AnalysisResult { bool hasNoPrivateDefEffect); void ApplyUnionForDassignCopy(const AliasElem &lhsAe, const AliasElem *rhsAe, const BaseNode &rhs); AliasElem *FindOrCreateDummyNADSAe(); + bool IsPointedTo(OriginalSt &oSt); + AliasElem &FindOrCreateAliasElemOfAddrofOSt(OriginalSt &oSt); void CollectMayDefForMustDefs(const StmtNode &stmt, std::set &mayDefOsts); void CollectMayUseForCallOpnd(const StmtNode &stmt, std::set &mayUseOsts); void InsertMayDefNodeForCall(std::set &mayDefOsts, MapleMap &mayDefNodes, diff --git a/src/maple_me/include/bb.h b/src/maple_me/include/bb.h index 7e4809912c027599acb176b639390139f3f9a110..f1a6f20ba366445c913e2c7a8f84b381c70eeabb 100644 --- a/src/maple_me/include/bb.h +++ b/src/maple_me/include/bb.h @@ -25,7 +25,7 @@ namespace maple { class MeStmt; // circular dependency exists, no other choice class MeVarPhiNode; // circular dependency exists, no other choice class MeRegPhiNode; // circular dependency exists, no other choice -class PaiassignMeStmt; +class PaiassignMeStmt; // circular dependency exists, no other choice class IRMap; // circular dependency exists, no other choice enum BBKind { kBBUnknown, // uninitialized @@ -63,16 +63,12 @@ class BB { BB(MapleAllocator *alloc, MapleAllocator *versAlloc, BBId id) : id(id), - bbLabel(0), pred(kBBVectorInitialSize, nullptr, alloc->Adapter()), succ(kBBVectorInitialSize, nullptr, alloc->Adapter()), phiList(versAlloc->Adapter()), mevarPhiList(alloc->Adapter()), meregPhiList(alloc->Adapter()), - mevarPaiList(alloc->Adapter()), - frequency(0), - kind(kBBUnknown), - attributes(0) { + mevarPaiList(alloc->Adapter()) { pred.pop_back(); pred.pop_back(); succ.pop_back(); @@ -81,16 +77,12 @@ class BB { BB(MapleAllocator *alloc, MapleAllocator *versAlloc, BBId id, StmtNode *firstStmt, StmtNode *lastStmt) : id(id), - bbLabel(0), pred(kBBVectorInitialSize, nullptr, alloc->Adapter()), succ(kBBVectorInitialSize, nullptr, alloc->Adapter()), phiList(versAlloc->Adapter()), mevarPhiList(alloc->Adapter()), meregPhiList(alloc->Adapter()), mevarPaiList(alloc->Adapter()), - frequency(0), - kind(kBBUnknown), - attributes(0), stmtNodeList(firstStmt, lastStmt) { pred.pop_back(); pred.pop_back(); @@ -123,9 +115,9 @@ class BB { } void Dump(MIRModule *mod); - void DumpHeader(MIRModule *mod); + void DumpHeader(MIRModule *mod) const; void DumpPhi(MIRModule* mod); - void DumpBBAttribute(MIRModule *mod); + void DumpBBAttribute(MIRModule *mod) const; std::string StrAttribute() const; void AddPredBB(BB *predVal) { @@ -365,16 +357,16 @@ class BB { private: BBId id; - LabelIdx bbLabel; // the BB's label + LabelIdx bbLabel = 0; // the BB's label MapleVector pred; // predecessor list MapleVector succ; // successor list MapleMap phiList; MapleMap mevarPhiList; MapleMap meregPhiList; MapleMap> mevarPaiList; - uint32 frequency; - BBKind kind; - uint32 attributes; + uint32 frequency = 0; + BBKind kind = kBBUnknown; + uint32 attributes = 0; StmtNodes stmtNodeList; MeStmts meStmtList; }; @@ -413,7 +405,7 @@ class SCCOfBBs { return predSCC; } bool HasPred() const { - return (predSCC.size() != 0); + return !predSCC.empty(); } BB *GetEntry() { return entry; @@ -435,5 +427,4 @@ struct hash { } }; } // namespace std - #endif // MAPLE_ME_INCLUDE_BB_H diff --git a/src/maple_me/include/dominance.h b/src/maple_me/include/dominance.h index 2686f29c1c99d50a472d48b11bbde32eacf19b03..32a66d99eba47628836492041ff6bc7e5e97e3c3 100644 --- a/src/maple_me/include/dominance.h +++ b/src/maple_me/include/dominance.h @@ -42,7 +42,7 @@ class Dominance : public AnalysisResult { pdtPreOrder(bbVec.size(), BBId(0), domAllocator.Adapter()), pdtDfn(bbVec.size(), -1, domAllocator.Adapter()) {} - ~Dominance() = default; + ~Dominance() override = default; void GenPostOrderID(); void ComputeDominance(); @@ -129,7 +129,7 @@ class Dominance : public AnalysisResult { return pdomChildren[idx]; } - void ResizePdtPreOrder(int n) { + void ResizePdtPreOrder(size_t n) { pdtPreOrder.resize(n); } @@ -145,7 +145,7 @@ class Dominance : public AnalysisResult { return doms[idx]; } - uint32 GetDomsSize() const { + size_t GetDomsSize() const { return doms.size(); } @@ -190,14 +190,14 @@ class Dominance : public AnalysisResult { } protected: - MapleAllocator domAllocator; // stores the analysis results - void PostOrderWalk(const BB &bb, int32 &pid, std::vector &visitedMap); - BB *Intersect(BB &bb1, const BB &bb2); + BB *Intersect(BB &bb1, const BB &bb2) const; bool CommonEntryBBIsPred(const BB &bb) const; void PdomPostOrderWalk(BB &bb, int32 &pid, std::vector &visitedMap); BB *PdomIntersect(BB &bb1, const BB &bb2); + MapleAllocator domAllocator; // stores the analysis results + private: MapleAllocator tmpAllocator; // can be freed after dominator computation MapleVector &bbVec; diff --git a/src/maple_me/include/func_emit.h b/src/maple_me/include/func_emit.h index 458d2d6ff92e677b3ceee476da95f03c4d71840b..492d7605db4c365b9c8c74dfe49750ad6f6c6b56 100644 --- a/src/maple_me/include/func_emit.h +++ b/src/maple_me/include/func_emit.h @@ -16,7 +16,7 @@ #define MAPLE_ME_INCLUDE_FUNC_EMIT_H #include "bb.h" -/* Provide emit service for both MeFunction and WpoFunction. */ +// Provide emit service for both MeFunction and WpoFunction. namespace maple { class FuncEmit { public: diff --git a/src/maple_me/include/me_alias_class.h b/src/maple_me/include/me_alias_class.h index 1723f2d65d07155a7cd9f52d63a11eaa390588ea..b927a8d5e6336125b406e22566b0a1421d5f4277 100644 --- a/src/maple_me/include/me_alias_class.h +++ b/src/maple_me/include/me_alias_class.h @@ -22,8 +22,8 @@ namespace maple { class MeAliasClass : public AliasClass { public: MeAliasClass(MemPool &memPool, MIRModule &mod, SSATab &ssaTab, MeFunction &func, bool lessAliasAtThrow, - bool finalFieldHasAlias, bool ignoreIPA, bool debug, bool setCalleeHasSideEffect, KlassHierarchy *kh) - : AliasClass(memPool, mod, ssaTab, lessAliasAtThrow, finalFieldHasAlias, ignoreIPA, setCalleeHasSideEffect, kh), + bool ignoreIPA, bool debug, bool setCalleeHasSideEffect, KlassHierarchy *kh) + : AliasClass(memPool, mod, ssaTab, lessAliasAtThrow, ignoreIPA, setCalleeHasSideEffect, kh), func(func), enabledDebug(debug) {} virtual ~MeAliasClass() = default; diff --git a/src/maple_me/include/me_cfg.h b/src/maple_me/include/me_cfg.h index 080bf87abcde27a96f5258b20290c611a61b9768..e6f05f7c4fa17b926053ccfba5522355728c05e5 100644 --- a/src/maple_me/include/me_cfg.h +++ b/src/maple_me/include/me_cfg.h @@ -51,14 +51,14 @@ class MeCFG { } private: - MeFunction &func; - bool hasDoWhile = false; - std::string ConstructFileNameToDump(const std::string &prefix) const; void DumpToFileInStrs(std::ofstream &cfgFile) const; void ConvertPhiList2IdentityAssigns(BB &meBB) const; void ConvertMevarPhiList2IdentityAssigns(BB &meBB) const; void ConvertMeregphiList2IdentityAssigns(BB &meBB) const; + + MeFunction &func; + bool hasDoWhile = false; }; } // namespace maple #endif // MAPLE_ME_INCLUDE_ME_CFG_H diff --git a/src/maple_me/include/me_dominance.h b/src/maple_me/include/me_dominance.h index a9f8fbcafc6dfbc7263bef97ad60f3341a416ad9..9017e294c3a5e8c84fa802e5190954e641633980 100644 --- a/src/maple_me/include/me_dominance.h +++ b/src/maple_me/include/me_dominance.h @@ -23,7 +23,7 @@ class MeDoDominance : public MeFuncPhase { public: explicit MeDoDominance(MePhaseID id) : MeFuncPhase(id) {} - virtual ~MeDoDominance() = default; + ~MeDoDominance() override = default; AnalysisResult *Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) override; std::string PhaseName() const override { diff --git a/src/maple_me/include/me_emit.h b/src/maple_me/include/me_emit.h index d04c4080f9db343cc2946089eba2dd64262491c1..c3f7031bd7d17e856b9e0a690efc357f37e97a18 100644 --- a/src/maple_me/include/me_emit.h +++ b/src/maple_me/include/me_emit.h @@ -17,7 +17,7 @@ #include "me_function.h" #include "me_phase.h" -/* emit ir to specified file */ +// emit ir to specified file namespace maple { class MeDoEmit : public MeFuncPhase { public: diff --git a/src/maple_me/include/me_function.h b/src/maple_me/include/me_function.h index 41b458521c9c3770b3973d543f19c338fa6a1df5..84d275ccca265d8906823ca3505a7b6857011073 100644 --- a/src/maple_me/include/me_function.h +++ b/src/maple_me/include/me_function.h @@ -81,13 +81,13 @@ class FilterIterator { return func(iterator) ? *this : --(*this); } - FilterIterator operator++(int) { + const FilterIterator operator++(int) { FilterIterator it = *this; ++(*this); return it; } - FilterIterator operator--(int) { + const FilterIterator operator--(int) { FilterIterator it = *this; --(*this); return it; @@ -167,7 +167,7 @@ class MeFunction : public FuncEmit { backEdges(alloc.Adapter()), fileName(fileName) {} - virtual ~MeFunction() = default; + ~MeFunction() override = default; using value_type = BBPtrHolder::value_type; using size_type = BBPtrHolder::size_type; diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h index 70dd96063ca1844a9f2e29170d5e98e56c60b3d0..584cfd08771330d2e389d4acff6a944a162b56d0 100644 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -19,10 +19,10 @@ #include "bb.h" namespace maple { -class PhiNode; // circular dependency exists, no other choice -class MeStmt; // circular dependency exists, no other choice -class IRMap; // circular dependency exists, no other choice -class SSATab; // circular dependency exists, no other choice +class PhiNode; // circular dependency exists, no other choice +class MeStmt; // circular dependency exists, no other choice +class IRMap; // circular dependency exists, no other choice +class SSATab; // circular dependency exists, no other choice class VarMeExpr; // circular dependency exists, no other choice class RegMeExpr; // circular dependency exists, no other choice class Dominance; // circular dependency exists, no other choice @@ -187,7 +187,7 @@ enum MeDefBy { kDefByMustDef, // only applies to callassigned and its siblings }; -class ChiMeNode; // circular dependency exists, no other choice +class ChiMeNode; // circular dependency exists, no other choice class MustDefMeNode; // circular dependency exists, no other choice class IassignMeStmt; // circular dependency exists, no other choice @@ -323,7 +323,7 @@ class VarMeExpr final : public MeExpr { private: union { - MeStmt *defStmt; // definition stmt of this var + MeStmt *defStmt; // definition stmt of this var MeVarPhiNode *defPhi; ChiMeNode *defChi; // definition node by Chi MustDefMeNode *defMustDef; // definition by callassigned @@ -905,8 +905,8 @@ class OpMeExpr : public MeExpr { } private: - std::array opnds = { nullptr }; // kid - PrimType opndType = kPtyInvalid; // from type + std::array opnds = { nullptr }; // kid + PrimType opndType = kPtyInvalid; // from type uint8 bitsOffset = 0; uint8 bitsSize = 0; TyIdx tyIdx; diff --git a/src/maple_me/include/me_option.h b/src/maple_me/include/me_option.h index d222812627e1b8d08811bdf9b10f51e08b5b8350..6c118f6abc17812152f22da48a05be166447da51 100644 --- a/src/maple_me/include/me_option.h +++ b/src/maple_me/include/me_option.h @@ -51,7 +51,6 @@ class MeOption { static uint8 optLevel; static bool ignoreIPA; static bool lessThrowAlias; - static bool finalFieldAlias; static bool regreadAtReturn; void SplitPhases(const std::string &str, std::unordered_set &set) const; void SplitSkipPhases(const std::string &str) { diff --git a/src/maple_me/include/me_phase_manager.h b/src/maple_me/include/me_phase_manager.h index 349efa0820af9be0bf359d744af9d99168dbbfcf..d2aeea409ae7a11b62fe2be2760578db7e0a9a9a 100644 --- a/src/maple_me/include/me_phase_manager.h +++ b/src/maple_me/include/me_phase_manager.h @@ -25,7 +25,7 @@ namespace maple { enum MePhaseType { kMePhaseInvalid, kMePhaseMainopt, kMePhaseLno }; -/* driver of Me */ +// driver of Me class MeFuncPhaseManager : public PhaseManager { public: MeFuncPhaseManager(MemPool *memPool, MIRModule &mod, ModuleResultMgr *mrm = nullptr) @@ -84,7 +84,7 @@ class MeFuncPhaseManager : public PhaseManager { } private: - /* analysis phase result manager */ + // analysis phase result manager MeFuncResultMgr arFuncManager{GetMemAllocator()}; MIRModule &mirModule; ModuleResultMgr *modResMgr; diff --git a/src/maple_me/include/me_rc_lowering.h b/src/maple_me/include/me_rc_lowering.h index b3c4485a91642dc15006409ece3c3382e8fd5b8b..002bb7d57cfeedefc29cb33775726ea5191cef4e 100644 --- a/src/maple_me/include/me_rc_lowering.h +++ b/src/maple_me/include/me_rc_lowering.h @@ -48,10 +48,8 @@ class RCLowering { void HandleArguments(); // create new symbol from name and return its ost OriginalSt *RetrieveOSt(const std::string &name, bool isLocalrefvar) const; - /** - * create new symbol from temp name and return its VarMeExpr - * new symbols are stored in a set - */ + // create new symbol from temp name and return its VarMeExpr + // new symbols are stored in a set VarMeExpr *CreateNewTmpVarMeExpr(bool isLocalrefvar); VarMeExpr *CreateVarMeExprFromSym(MIRSymbol &sym) const; // return true if the rhs is simple so we can adjust RC count before assignments diff --git a/src/maple_me/include/ssa_mir_nodes.h b/src/maple_me/include/ssa_mir_nodes.h index b7ad07432389abe0a20f83d3b7e032e4e5163100..606e7896877c98c915af97c053fe7b4092860341 100644 --- a/src/maple_me/include/ssa_mir_nodes.h +++ b/src/maple_me/include/ssa_mir_nodes.h @@ -18,8 +18,7 @@ #include "bb.h" #include "ver_symbol.h" -/* This file define data structures to store SSA information in the IR - instructions */ +// This file define data structures to store SSA information in the IR instructions namespace maple { class MayDefNode { public: @@ -203,7 +202,7 @@ class MayDefPart : public AccessSSANodes { public: explicit MayDefPart(MapleAllocator *alloc) : mayDefNodes(std::less(), alloc->Adapter()) {} - virtual ~MayDefPart() = default; + ~MayDefPart() override = default; const MapleMap &GetMayDefNodes() const override { return mayDefNodes; @@ -221,7 +220,7 @@ class MayUsePart : public AccessSSANodes { public: explicit MayUsePart(MapleAllocator *alloc) : mayUseNodes(std::less(), alloc->Adapter()) {} - virtual ~MayUsePart() = default; + ~MayUsePart() override = default; const MapleMap &GetMayUseNodes() const override { return mayUseNodes; @@ -239,7 +238,7 @@ class MustDefPart : public AccessSSANodes { public: explicit MustDefPart(MapleAllocator *alloc) : mustDefNodes(alloc->Adapter()) {} - virtual ~MustDefPart() = default; + ~MustDefPart() override = default; const MapleVector &GetMustDefNodes() const override { return mustDefNodes; @@ -258,7 +257,7 @@ class MayDefPartWithVersionSt : public AccessSSANodes { explicit MayDefPartWithVersionSt(MapleAllocator *alloc) : mayDefNodes(std::less(), alloc->Adapter()) {} - ~MayDefPartWithVersionSt() = default; + ~MayDefPartWithVersionSt() override = default; const MapleMap &GetMayDefNodes() const override { return mayDefNodes; @@ -288,7 +287,7 @@ class MayDefPartWithVersionSt : public AccessSSANodes { class VersionStPart : public AccessSSANodes { public: VersionStPart() = default; - ~VersionStPart() = default; + ~VersionStPart() override = default; const VersionSt *GetSSAVar() const override { return ssaVar; @@ -311,7 +310,7 @@ class MayDefMayUsePart : public AccessSSANodes { explicit MayDefMayUsePart(MapleAllocator *alloc) : mayDefNodes(std::less(), alloc->Adapter()), mayUseNodes(std::less(), alloc->Adapter()) {} - ~MayDefMayUsePart() = default; + ~MayDefMayUsePart() override = default; const MapleMap &GetMayDefNodes() const override { return mayDefNodes; @@ -341,7 +340,7 @@ class MayDefMayUseMustDefPart : public AccessSSANodes { mayUseNodes(std::less(), alloc->Adapter()), mustDefNodes(alloc->Adapter()) {} - ~MayDefMayUseMustDefPart() = default; + ~MayDefMayUseMustDefPart() override = default; const MapleMap &GetMayDefNodes() const override { return mayDefNodes; @@ -419,7 +418,7 @@ class StmtsSSAPart { } void SetSSAPartOf(const StmtNode &s, VersionSt *vst) { - VersionStPart *vStSSAPart = GetSSAPartMp()->New(); + auto *vStSSAPart = GetSSAPartMp()->New(); vStSSAPart->SetSSAVar(*vst); ssaPart[s.GetStmtID()] = vStSSAPart; } @@ -448,9 +447,9 @@ class AddrofSSANode : public AddrofNode { ssaVar = nullptr; } - ~AddrofSSANode() = default; + ~AddrofSSANode() override = default; - void Dump(const MIRModule &mod, int32 indent) const { + void Dump(const MIRModule &mod, int32 indent) const override { AddrofNode::Dump(mod, indent); if (ssaVar != nullptr) { ssaVar->Dump(&mod, true); @@ -482,9 +481,9 @@ class IreadSSANode : public IreadNode { SetOpnd(inode->Opnd()); } - ~IreadSSANode() = default; + ~IreadSSANode() override = default; - void Dump(const MIRModule &mod, int32 indent) const { + void Dump(const MIRModule &mod, int32 indent) const override { if (ssaVar != nullptr) { ssaVar->Dump(&mod, true); } @@ -510,9 +509,9 @@ class RegreadSSANode : public RegreadNode { SetRegIdx(rreadnode->GetRegIdx()); } - ~RegreadSSANode() = default; + ~RegreadSSANode() override = default; - void Dump(const MIRModule &mod, int32 indent) const { + void Dump(const MIRModule &mod, int32 indent) const override { RegreadNode::Dump(mod, indent); if (ssaVar != nullptr) { ssaVar->Dump(&mod, true); diff --git a/src/maple_me/src/alias_class.cpp b/src/maple_me/src/alias_class.cpp index 74bd589072cc9980acf41add9509275ac3e03a6a..5060e248a0b382ac75e183872dc899552b9b4c9d 100644 --- a/src/maple_me/src/alias_class.cpp +++ b/src/maple_me/src/alias_class.cpp @@ -30,13 +30,6 @@ static inline bool IsReadOnlyOst(const OriginalSt &ost) { static inline bool IsPotentialAddress(PrimType ptyp) { return IsAddress(ptyp) || IsPrimitiveDynType(ptyp); } -static inline bool OriginalStIsZeroLevAndAuto(const OriginalSt &ost) { - if (ost.GetIndirectLev() == 0 && ost.IsSymbolOst()) { - const MIRSymbol *sym = ost.GetMIRSymbol(); - return sym->GetStorageClass() == kScAuto || sym->GetStorageClass() == kScFormal; - } - return false; -} bool AliasClass::CallHasNoSideEffectOrPrivateDefEffect(const CallNode &stmt, FuncAttrKind attrKind) const { ASSERT(attrKind == FUNCATTR_nosideeffect || attrKind == FUNCATTR_noprivate_defeffect, "Not supportted attrKind"); @@ -103,31 +96,38 @@ AliasElem *AliasClass::FindOrCreateExtraLevAliasElem(BaseNode &expr, TyIdx tyIdx return FindOrCreateAliasElem(*newOst); } +AliasElem &AliasClass::FindOrCreateAliasElemOfAddrofOSt(OriginalSt &oSt) { + OriginalSt *addrofOst = GetAliasAnalysisTable()->FindOrCreateAddrofSymbolOriginalSt(oSt); + if (addrofOst->GetIndex().idx == osym2Elem.size()) { + osym2Elem.push_back(nullptr); + } + return *FindOrCreateAliasElem(*addrofOst); +} + AliasElem *AliasClass::CreateAliasElemsExpr(BaseNode &expr) { switch (expr.GetOpCode()) { case OP_addrof: { - AddrofSSANode &addrof = static_cast(expr); - FindOrCreateAliasElem(*addrof.GetSSAVar()->GetOrigSt()); - OriginalSt *newOst = - GetAliasAnalysisTable()->FindOrCreateAddrofSymbolOriginalSt(*addrof.GetSSAVar()->GetOrigSt()); - if (newOst->GetIndex().idx == osym2Elem.size()) { - osym2Elem.push_back(nullptr); - } - return FindOrCreateAliasElem(*newOst); + OriginalSt &oSt = *static_cast(expr).GetSSAVar()->GetOrigSt(); + FindOrCreateAliasElem(oSt); + return &FindOrCreateAliasElemOfAddrofOSt(oSt); } case OP_dread: { - AddrofSSANode &dread = static_cast(expr); - return FindOrCreateAliasElem(*dread.GetSSAVar()->GetOrigSt()); + OriginalSt &oSt = *static_cast(expr).GetSSAVar()->GetOrigSt(); + return FindOrCreateAliasElem(oSt); } case OP_regread: { - RegreadSSANode &rread = static_cast(expr); - return (rread.GetRegIdx() < 0) ? nullptr : FindOrCreateAliasElem(*rread.GetSSAVar()->GetOrigSt()); + OriginalSt &oSt = *static_cast(expr).GetSSAVar()->GetOrigSt(); + return (oSt.IsSpecialPreg()) ? nullptr : FindOrCreateAliasElem(oSt); } - case OP_iread: - case OP_iaddrof: { + case OP_iread: { IreadNode &iread = static_cast(expr); return FindOrCreateExtraLevAliasElem(*iread.Opnd(0), iread.GetTyIdx(), iread.GetFieldID()); } + case OP_iaddrof: { + IreadNode &iread = static_cast(expr); + AliasElem *ae = FindOrCreateExtraLevAliasElem(*iread.Opnd(0), iread.GetTyIdx(), iread.GetFieldID()); + return &FindOrCreateAliasElemOfAddrofOSt(ae->GetOriginalSt()); + } case OP_malloc: case OP_gcmalloc: return nullptr; @@ -308,10 +308,14 @@ void AliasClass::DumpAssignSets() { } } +bool AliasClass::IsPointedTo(OriginalSt &oSt) { + return GetAliasAnalysisTable()->GetPrevLevelNode(oSt) != nullptr; +} + void AliasClass::UnionAllPointedTos() { std::vector pointedTos; for (AliasElem *aliasElem : id2Elem) { - if (aliasElem->GetOriginalSt().GetIndirectLev() > 0) { + if (IsPointedTo(aliasElem->GetOriginalSt())) { aliasElem->SetNotAllDefsSeen(true); pointedTos.push_back(aliasElem); } @@ -335,7 +339,7 @@ void AliasClass::UnionNodes(std::vector &nextLevelOsts) { for (size_t j = i + 1; j < nextLevelOsts.size(); j++) { OriginalSt *ost2 = nextLevelOsts[j]; if ((ost1->GetFieldID() == 0 || ost2->GetFieldID() == 0 || ost1->GetFieldID() == ost2->GetFieldID()) && - (finalFieldAlias || !(ost1->IsFinal() || ost2->IsFinal()))) { + !(ost1->IsFinal() || ost2->IsFinal())) { unionFind.Union(FindAliasElem(*ost1)->GetClassID(), FindAliasElem(*ost2)->GetClassID()); break; } @@ -359,7 +363,7 @@ void AliasClass::ApplyUnionForPointedTos() { void AliasClass::CollectRootIDOfNextLevelNodes(const OriginalSt &ost, std::set &rootIDOfNADSs) { for (OriginalSt *nextLevelNode : *(GetAliasAnalysisTable()->GetNextLevelNodes(ost))) { - if (finalFieldAlias || !nextLevelNode->IsFinal()) { + if (!nextLevelNode->IsFinal()) { uint32 id = FindAliasElem(*nextLevelNode)->GetClassID(); rootIDOfNADSs.insert(unionFind.Root(id)); } @@ -634,9 +638,7 @@ void AliasClass::CollectMayUseFromNADS(std::set &mayUseOsts) { } else { for (unsigned int elemID : *(notAllDefsSeenAE->GetClassSet())) { AliasElem *ae = id2Elem[elemID]; - if (!OriginalStIsZeroLevAndAuto(ae->GetOriginalSt())) { - mayUseOsts.insert(&ae->GetOriginalSt()); - } + mayUseOsts.insert(&ae->GetOriginalSt()); } } } @@ -668,7 +670,7 @@ void AliasClass::InsertMayUseReturn(const StmtNode &stmt) { void AliasClass::CollectPtsToOfReturnOpnd(const OriginalSt &ost, std::set &mayUseOsts) { for (OriginalSt *nextLevelOst : *(GetAliasAnalysisTable()->GetNextLevelNodes(ost))) { AliasElem *indAe = FindAliasElem(*nextLevelOst); - if (!indAe->IsNotAllDefsSeen() && (!indAe->GetOriginalSt().IsFinal() || finalFieldAlias)) { + if (!indAe->IsNotAllDefsSeen() && !indAe->GetOriginalSt().IsFinal()) { if (indAe->GetClassSet() == nullptr) { mayUseOsts.insert(&indAe->GetOriginalSt()); } else { @@ -783,9 +785,6 @@ void AliasClass::CollectMayDefForIassign(StmtNode &stmt, std::set & for (unsigned int elemID : *(lhsAe->GetClassSet())) { AliasElem *aliasElem = id2Elem[elemID]; OriginalSt &ostOfAliasAE = aliasElem->GetOriginalSt(); - if (aliasElem != lhsAe && OriginalStIsZeroLevAndAuto(ostOfAliasAE)) { - continue; - } mayDefOsts.insert(&ostOfAliasAE); } } @@ -842,11 +841,11 @@ void AliasClass::InsertMayDefUseSyncOps(StmtNode &stmt, BBId bbID) { } } // do the insertion according to aliasSet - MayDefMayUsePart *theSSAPart = static_cast(ssaTab.GetStmtsSSAPart().SSAPartOf(stmt)); + AccessSSANodes *theSSAPart = ssaTab.GetStmtsSSAPart().SSAPartOf(stmt); for (unsigned int elemid : aliasSet) { AliasElem *aliasElem = id2Elem[elemid]; OriginalSt &ostOfAliasAE = aliasElem->GetOriginalSt(); - if (!ostOfAliasAE.IsFinal() && !OriginalStIsZeroLevAndAuto(ostOfAliasAE)) { + if (!ostOfAliasAE.IsFinal()) { OStIdx ostIdx = ostOfAliasAE.GetIndex(); VersionSt *vst0 = ssaTab.GetVersionStTable().GetVersionStFromID(ostOfAliasAE.GetZeroVersionIndex()); theSSAPart->GetMayUseNodes().insert(std::make_pair(ostIdx, MayUseNode(vst0))); @@ -896,7 +895,7 @@ void AliasClass::CollectMayUseForCallOpnd(const StmtNode &stmt, std::setGetNextLevelNodes(ae->GetOriginalSt()))) { AliasElem *indAe = FindAliasElem(*nextLevelOst); - if (indAe->GetOriginalSt().IsFinal() && !finalFieldAlias) { + if (indAe->GetOriginalSt().IsFinal()) { continue; } diff --git a/src/maple_me/src/bb.cpp b/src/maple_me/src/bb.cpp index 1f38bb6aff1522667640c4109b83a90a82ad4a50..3a949948ace65268a6f0be5d714705ec75a5f0e4 100644 --- a/src/maple_me/src/bb.cpp +++ b/src/maple_me/src/bb.cpp @@ -43,7 +43,7 @@ std::string BB::StrAttribute() const { return "NYI"; } -void BB::DumpBBAttribute(MIRModule *mod) { +void BB::DumpBBAttribute(MIRModule *mod) const { if (GetAttributes(kBBAttrIsEntry)) { mod->GetOut() << " Entry "; } @@ -72,7 +72,7 @@ void BB::DumpBBAttribute(MIRModule *mod) { } } -void BB::DumpHeader(MIRModule *mod) { +void BB::DumpHeader(MIRModule *mod) const { mod->GetOut() << "============BB id:" << GetBBId() << " " << StrAttribute() << " ["; DumpBBAttribute(mod); mod->GetOut() << "]===============\n"; @@ -84,12 +84,12 @@ void BB::DumpHeader(MIRModule *mod) { for (const auto &succElement : succ) { mod->GetOut() << succElement->GetBBId() << " "; } - mod->GetOut() << "\n"; + mod->GetOut() << '\n'; if (bbLabel != 0) { static LabelNode lblNode; lblNode.SetLabelIdx(bbLabel); lblNode.Dump(*mod, 0); - mod->GetOut() << "\n"; + mod->GetOut() << '\n'; } } @@ -136,7 +136,7 @@ int BB::RemoveBBFromVector(MapleVector &bbVec) const { if (bbVec[i] == this) { break; } - i++; + ++i; } if (i == bbVec.size()) { // bb not in the vector @@ -149,17 +149,17 @@ int BB::RemoveBBFromVector(MapleVector &bbVec) const { 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.GetPhiOpnds().size() > index, "index out of range in BB::RemoveBBFromPred"); - (*phiIt).second.GetPhiOpnds().erase((*phiIt).second.GetPhiOpnds().cbegin() + index); + for (auto &phi : phiList) { + ASSERT(phi.second.GetPhiOpnds().size() > index, "index out of range in BB::RemoveBBFromPred"); + phi.second.GetPhiOpnds().erase(phi.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"); - (*phiIt).second->GetOpnds().erase((*phiIt).second->GetOpnds().cbegin() + index); + for (auto &phi : mevarPhiList) { + ASSERT(phi.second->GetOpnds().size() > index, "index out of range in BB::RemoveBBFromPred"); + phi.second->GetOpnds().erase(phi.second->GetOpnds().cbegin() + index); } - for (auto phiIt = meregPhiList.begin(); phiIt != meregPhiList.end(); phiIt++) { - ASSERT((*phiIt).second->GetOpnds().size() > index, "index out of range in BB::RemoveBBFromPred"); - (*phiIt).second->GetOpnds().erase((*phiIt).second->GetOpnds().cbegin() + index); + for (auto &phi : meregPhiList) { + ASSERT(phi.second->GetOpnds().size() > index, "index out of range in BB::RemoveBBFromPred"); + phi.second->GetOpnds().erase(phi.second->GetOpnds().cbegin() + index); } } @@ -167,13 +167,13 @@ void BB::RemoveBBFromSucc(BB *bb) { bb->RemoveBBFromVector(succ); } -/* add stmtnode to bb and update first_stmt_ and last_stmt_ */ +// add stmtnode to bb and update first_stmt_ and last_stmt_ void BB::AddStmtNode(StmtNode *stmt) { CHECK_FATAL(stmt != nullptr, "null ptr check"); stmtNodeList.push_back(stmt); } -/* add stmtnode at beginning of bb and update first_stmt_ and last_stmt_ */ +// add stmtnode at beginning of bb and update first_stmt_ and last_stmt_ void BB::PrependStmtNode(StmtNode *stmt) { stmtNodeList.push_front(stmt); } @@ -216,13 +216,12 @@ void BB::ReplaceStmt(StmtNode *stmt, StmtNode *newStmt) { RemoveStmtNode(stmt); } -/* delete last_stmt_ and update */ +// delete last_stmt_ and update void BB::RemoveLastStmt() { stmtNodeList.pop_back(); } -/* replace pred with newbb to keep position and - * add this as succ of newpred */ +// replace pred with newbb to keep position and add this as succ of newpred void BB::ReplacePred(const BB *old, BB *newPred) { for (auto &predElement : pred) { if (predElement == old) { @@ -233,8 +232,7 @@ void BB::ReplacePred(const BB *old, BB *newPred) { } } -/* replace succ in current position with newsucc - * and add this as pred of newsucc */ +// replace succ in current position with newsucc and add this as pred of newsucc void BB::ReplaceSucc(const BB *old, BB *newSucc) { for (auto &succElement : succ) { if (succElement == old) { @@ -245,7 +243,7 @@ void BB::ReplaceSucc(const BB *old, BB *newSucc) { } } -/* this is common_entry_bb, so newsucc's pred is left as is */ +// this is common_entry_bb, so newsucc's pred is left as is void BB::ReplaceSuccOfCommonEntryBB(const BB *old, BB *newSucc) { for (auto &succElement : succ) { if (succElement == old) { @@ -261,8 +259,8 @@ void BB::FindReachableBBs(std::vector &visitedBBs) const { return; } visitedBBs[GetBBId()] = true; - for (auto it = succ.begin(); it != succ.end(); ++it) { - (*it)->FindReachableBBs(visitedBBs); + for (const BB *bb : succ) { + bb->FindReachableBBs(visitedBBs); } } @@ -272,8 +270,8 @@ void BB::FindWillExitBBs(std::vector &visitedBBs) const { return; } visitedBBs[GetBBId()] = true; - for (auto it = pred.begin(); it != pred.end(); ++it) { - (*it)->FindWillExitBBs(visitedBBs); + for (const BB *bb : pred) { + bb->FindWillExitBBs(visitedBBs); } } @@ -322,15 +320,15 @@ void BB::InsertMeStmtAfter(MeStmt *meStmt, MeStmt *inStmt) { void BB::InsertMeStmtLastBr(MeStmt *inStmt) { if (IsMeStmtEmpty()) { AddMeStmtLast(inStmt); + return; + } + MeStmt *brStmt = meStmtList.rbegin().base().d(); + Opcode op = brStmt->GetOp(); + if (brStmt->IsCondBr() || op == OP_goto || op == OP_switch || op == OP_throw || op == OP_return || op == OP_gosub || + op == OP_retsub) { + InsertMeStmtBefore(brStmt, inStmt); } else { - MeStmt *brStmt = meStmtList.rbegin().base().d(); - Opcode op = brStmt->GetOp(); - if (brStmt->IsCondBr() || op == OP_goto || op == OP_switch || op == OP_throw || op == OP_return || op == OP_gosub || - op == OP_retsub) { - InsertMeStmtBefore(brStmt, inStmt); - } else { - AddMeStmtLast(inStmt); - } + AddMeStmtLast(inStmt); } } @@ -346,24 +344,24 @@ void BB::DumpMeBB(IRMap &irMap) { } void BB::DumpMeVarPaiList(IRMap *irMap) { - if (mevarPaiList.size() == 0) { + if (mevarPaiList.empty()) { return; } - std::cout << "<<<<<<<<<<<<<< PAI Node Start >>>>>>>>>>>>>>>>>>" << '\n'; - for (auto pair : mevarPaiList) { + std::cout << "<<<<<<<<<<<<<< PAI Node Start >>>>>>>>>>>>>>>>>>\n"; + for (const auto &pair : mevarPaiList) { BB *bb = pair.first; std::cout << "Frome BB : " << bb->GetBBId() << '\n'; - for (uint32 j = 0; j < pair.second.size(); ++j) { - pair.second.at(j)->Dump(irMap); + for (const auto *stmt : pair.second) { + stmt->Dump(irMap); } } - std::cout << "<<<<<<<<<<<<<< PAI Node End >>>>>>>>>>>>>>>>>>>>" << '\n'; + std::cout << "<<<<<<<<<<<<<< PAI Node End >>>>>>>>>>>>>>>>>>>>\n"; } void BB::DumpMeVarPhiList(IRMap *irMap) { int count = 0; - for (auto phiIt = mevarPhiList.begin(); phiIt != mevarPhiList.end(); phiIt++) { - (*phiIt).second->Dump(irMap); + for (const auto &phi : mevarPhiList) { + phi.second->Dump(irMap); int dumpVsyNum = DumpOptions::GetDumpVsyNum(); if (dumpVsyNum > 0 && ++count >= dumpVsyNum) { break; @@ -373,13 +371,13 @@ void BB::DumpMeVarPhiList(IRMap *irMap) { } void BB::DumpMeRegPhiList(IRMap *irMap) { - for (auto phiIt = meregPhiList.begin(); phiIt != meregPhiList.end(); phiIt++) { - (*phiIt).second->Dump(irMap); + for (const auto &phi : meregPhiList) { + phi.second->Dump(irMap); } } void SCCOfBBs::Dump() { - std::cout << "SCC " << id << " contains" << '\n'; + std::cout << "SCC " << id << " contains\n"; for (BB *bb : bbs) { std::cout << "bb(" << bb->UintID() << ") "; } @@ -387,12 +385,12 @@ void SCCOfBBs::Dump() { } bool SCCOfBBs::HasCycle() const { - CHECK_FATAL(bbs.size() > 0, "should have bbs in the scc"); + CHECK_FATAL(!bbs.empty(), "should have bbs in the scc"); if (bbs.size() > 1) { return true; } BB *bb = bbs[0]; - for (BB *succ : bb->GetSucc()) { + for (const BB *succ : bb->GetSucc()) { if (succ == bb) { return true; } @@ -401,8 +399,8 @@ bool SCCOfBBs::HasCycle() const { } void SCCOfBBs::Verify(MapleVector &sccOfBB) { - CHECK_FATAL(bbs.size() > 0, "should have bbs in the scc"); - for (BB *bb : bbs) { + CHECK_FATAL(!bbs.empty(), "should have bbs in the scc"); + for (const BB *bb : bbs) { SCCOfBBs *scc = sccOfBB.at(bb->UintID()); CHECK_FATAL(scc == this, ""); } diff --git a/src/maple_me/src/dominance.cpp b/src/maple_me/src/dominance.cpp index 977c0edb23424e93a693e07d9e8f78dcf0a3b572..fa7c8e27773d725145819babeb3a4d3356410b00 100644 --- a/src/maple_me/src/dominance.cpp +++ b/src/maple_me/src/dominance.cpp @@ -23,12 +23,11 @@ void Dominance::PostOrderWalk(const BB &bb, int32 &pid, std::vector &visit return; } visitedMap[bb.GetBBId()] = true; - for (BB *suc : bb.GetSucc()) { + for (const BB *suc : bb.GetSucc()) { PostOrderWalk(*suc, pid, visitedMap); } ASSERT(bb.GetBBId() < postOrderIDVec.size(), "index out of range in Dominance::PostOrderWalk"); postOrderIDVec[bb.GetBBId()] = pid++; - return; } void Dominance::GenPostOrderID() { @@ -39,7 +38,7 @@ void Dominance::GenPostOrderID() { // initialize reversePostOrder int32 maxPostOrderID = postOrderID - 1; reversePostOrder.resize(maxPostOrderID + 1); - for (size_t i = 0; i < postOrderIDVec.size(); i++) { + for (size_t i = 0; i < postOrderIDVec.size(); ++i) { int32 postOrderNo = postOrderIDVec[i]; if (postOrderNo == -1) { continue; @@ -48,7 +47,7 @@ void Dominance::GenPostOrderID() { } } -BB *Dominance::Intersect(BB &bb1, const BB &bb2) { +BB *Dominance::Intersect(BB &bb1, const BB &bb2) const { auto *ptrBB1 = &bb1; auto *ptrBB2 = &bb2; while (ptrBB1 != ptrBB2) { @@ -63,7 +62,7 @@ BB *Dominance::Intersect(BB &bb1, const BB &bb2) { } bool Dominance::CommonEntryBBIsPred(const BB &bb) const { - for (BB *suc : GetCommonEntryBB().GetSucc()) { + for (const BB *suc : GetCommonEntryBB().GetSucc()) { if (suc == &bb) { return true; } @@ -77,7 +76,7 @@ void Dominance::ComputeDominance() { bool changed = false; do { changed = false; - for (size_t i = 1; i < reversePostOrder.size(); i++) { + for (size_t i = 1; i < reversePostOrder.size(); ++i) { BB *bb = reversePostOrder[i]; BB *pre = nullptr; if (CommonEntryBBIsPred(*bb) || bb->GetPred().empty()) { @@ -88,10 +87,10 @@ void Dominance::ComputeDominance() { size_t j = 1; while ((doms[pre->GetBBId()] == nullptr || pre == bb) && j < bb->GetPred().size()) { pre = bb->GetPred(j); - j++; + ++j; } BB *newIDom = pre; - for (; j < bb->GetPred().size(); j++) { + for (; j < bb->GetPred().size(); ++j) { pre = bb->GetPred(j); if (doms[pre->GetBBId()] != nullptr && pre != bb) { newIDom = Intersect(*pre, *newIDom); @@ -149,7 +148,7 @@ void Dominance::ComputeDtPreorder(const BB &bb, size_t &num) { } void Dominance::ComputeDtDfn() { - for (uint32 i = 0; i < dtPreOrder.size(); i++) { + for (uint32 i = 0; i < dtPreOrder.size(); ++i) { dtDfn[dtPreOrder[i]] = i; } } @@ -191,7 +190,6 @@ void Dominance::PdomPostOrderWalk(BB &bb, int32 &pid, std::vector &visited } CHECK_FATAL(bb.GetBBId() < pdomPostOrderIDVec.size(), "index out of range in Dominance::PdomPostOrderWalk"); pdomPostOrderIDVec[bb.GetBBId()] = pid++; - return; } void Dominance::PdomGenPostOrderID() { @@ -231,7 +229,7 @@ void Dominance::ComputePostDominance() { bool changed = false; do { changed = false; - for (size_t i = 1; i < pdomReversePostOrder.size(); i++) { + for (size_t i = 1; i < pdomReversePostOrder.size(); ++i) { BB *bb = pdomReversePostOrder[i]; BB *suc = nullptr; if (bb->GetAttributes(kBBAttrIsExit) || bb->GetSucc().empty()) { @@ -242,13 +240,13 @@ void Dominance::ComputePostDominance() { size_t j = 1; while ((pdoms[suc->GetBBId()] == nullptr || suc == bb) && j < bb->GetSucc().size()) { suc = bb->GetSucc(j); - j++; + ++j; } if (pdoms[suc->GetBBId()] == nullptr) { suc = &commonExitBB; } BB *newIDom = suc; - for (; j < bb->GetSucc().size(); j++) { + for (; j < bb->GetSucc().size(); ++j) { suc = bb->GetSucc(j); if (pdoms[suc->GetBBId()] != nullptr && suc != bb) { newIDom = PdomIntersect(*suc, *newIDom); @@ -305,7 +303,7 @@ void Dominance::ComputePdtPreorder(const BB &bb, size_t &num) { } void Dominance::ComputePdtDfn() { - for (uint32 i = 0; i < pdtPreOrder.size(); i++) { + for (uint32 i = 0; i < pdtPreOrder.size(); ++i) { pdtDfn[pdtPreOrder[i]] = i; } } @@ -333,8 +331,7 @@ bool Dominance::PostDominate(const BB &bb1, BB &bb2) { } void Dominance::DumpDoms() { - for (size_t i = 0; i < reversePostOrder.size(); i++) { - BB *bb = reversePostOrder[i]; + for (BB *bb : reversePostOrder) { LogInfo::MapleLogger() << "postorder no " << postOrderIDVec[bb->GetBBId()]; LogInfo::MapleLogger() << " is bb:" << bb->GetBBId(); LogInfo::MapleLogger() << " im_dom is bb:" << doms[bb->GetBBId()]->GetBBId(); @@ -356,8 +353,7 @@ void Dominance::DumpDoms() { } void Dominance::DumpPdoms() { - for (size_t i = 0; i < pdomReversePostOrder.size(); i++) { - BB *bb = pdomReversePostOrder[i]; + for (BB *bb : pdomReversePostOrder) { LogInfo::MapleLogger() << "pdom_postorder no " << pdomPostOrderIDVec[bb->GetBBId()]; LogInfo::MapleLogger() << " is bb:" << bb->GetBBId(); LogInfo::MapleLogger() << " im_pdom is bb:" << pdoms[bb->GetBBId()]->GetBBId(); diff --git a/src/maple_me/src/func_emit.cpp b/src/maple_me/src/func_emit.cpp index 9f729b6d6f0d943656d342ba9568a52c89f43e40..1738903d32bdbb1ba0bc0f33e5de70fdc015727f 100644 --- a/src/maple_me/src/func_emit.cpp +++ b/src/maple_me/src/func_emit.cpp @@ -25,14 +25,14 @@ void FuncEmit::EmitLabelForBB(MIRFunction &func, BB &bb) const { bb.SetFirst(label); bb.SetLast(label); } else { - // Insert label before the first non-comment statement of bb + // Insert label before the first non-comment statement of bb. StmtNode *first = bb.GetStmtNodes().begin().d(); StmtNode *firstPrev = nullptr; while (first != nullptr && first->GetOpCode() == OP_comment) { firstPrev = first; first = first->GetNext(); } - // "first" points to the first non-comment statement, or nullptr + // "first" points to the first non-comment statement, or nullptr. if (first != nullptr) { label->InsertAfterThis(*first); if (first == bb.GetStmtNodes().begin().d()) { @@ -58,8 +58,8 @@ static void ConvertMaydassign(BB &bb) { // Inserting BBs in bblist into func's body. void FuncEmit::EmitBeforeHSSA(MIRFunction &func, const MapleVector &bbList) const { - StmtNode *lastStmt = nullptr; /* last stmt of previous bb */ - func.GetBody()->SetFirst(nullptr); /* reset body first stmt */ + StmtNode *lastStmt = nullptr; // last stmt of previous bb + func.GetBody()->SetFirst(nullptr); // reset body first stmt func.GetBody()->SetLast(nullptr); for (BB *bb : bbList) { if (bb == nullptr) { @@ -79,7 +79,7 @@ void FuncEmit::EmitBeforeHSSA(MIRFunction &func, const MapleVector &bbList) lastStmt = bb->GetStmtNodes().rbegin().base().d(); } if (bb->AddBackEndTry()) { - /* generate op_endtry andd added to next, it could be in an empty bb. */ + // generate op_endtry andd added to next, it could be in an empty bb. StmtNode *endtry = func.GetCodeMempool()->New(OP_endtry); CHECK_FATAL(lastStmt != nullptr, "EmitBeforeHSSA: shouldn't insert before a null stmt"); endtry->InsertBeforeThis(*lastStmt); diff --git a/src/maple_me/src/irmap.cpp b/src/maple_me/src/irmap.cpp index 5a2f853c4524d3f9b92701c91ae5b318c76219c8..27f4746b7f4e6ffeb51c47f5a024cbeda9b49f68 100644 --- a/src/maple_me/src/irmap.cpp +++ b/src/maple_me/src/irmap.cpp @@ -628,6 +628,7 @@ MeExpr *IRMap::HashMeExpr(MeExpr &meExpr) { if (resultExpr == nullptr) { resultExpr = &meBuilder.CreateMeExpr(exprID++, meExpr); + PutToBucket(hidx, *resultExpr); } return resultExpr; } diff --git a/src/maple_me/src/me_alias_class.cpp b/src/maple_me/src/me_alias_class.cpp index 5fd40e68d419b37a9d1cd51ce4ff56bd369f03a9..da409010a242557dfbf001e3a27e03bb1acacb52 100644 --- a/src/maple_me/src/me_alias_class.cpp +++ b/src/maple_me/src/me_alias_class.cpp @@ -91,7 +91,7 @@ AnalysisResult *MeDoAliasClass::Run(MeFunction *func, MeFuncResultMgr *funcResMg 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); + MeOption::ignoreIPA, DEBUGFUNC(func), MeOption::setCalleeHasSideEffect, kh); // pass 1 through the program statements if (DEBUGFUNC(func)) { LogInfo::MapleLogger() << "\n============ Alias Classification Pass 1 ============" << '\n'; diff --git a/src/maple_me/src/me_cfg.cpp b/src/maple_me/src/me_cfg.cpp index e5803b21ae3ea78aba142e82d770734f1661a580..752f2fab6da062aefea4ca61d9cceff552062cff 100644 --- a/src/maple_me/src/me_cfg.cpp +++ b/src/maple_me/src/me_cfg.cpp @@ -50,8 +50,8 @@ void MeCFG::BuildMirCFG() { break; } ASSERT(lastStmt.GetOpCode() == OP_goto, "runtime check error"); - GotoNode &gotoStmt = static_cast(lastStmt); - LabelIdx lblIdx = (LabelIdx)gotoStmt.GetOffset(); + auto &gotoStmt = static_cast(lastStmt); + LabelIdx lblIdx = gotoStmt.GetOffset(); BB *meBB = func.GetLabelBBAt(lblIdx); bb->GetSucc().push_back(meBB); meBB->GetPred().push_back(bb); @@ -67,8 +67,8 @@ void MeCFG::BuildMirCFG() { (*rightNextBB)->GetPred().push_back(bb); bb->GetSucc().push_back(*rightNextBB); /* link goto */ - CondGotoNode &gotoStmt = static_cast(lastStmt); - LabelIdx lblIdx = (LabelIdx)gotoStmt.GetOffset(); + auto &gotoStmt = static_cast(lastStmt); + LabelIdx lblIdx = gotoStmt.GetOffset(); BB *meBB = func.GetLabelBBAt(lblIdx); bb->GetSucc().push_back(meBB); meBB->GetPred().push_back(bb); @@ -77,7 +77,7 @@ void MeCFG::BuildMirCFG() { case kBBSwitch: { StmtNode &lastStmt = bb->GetStmtNodes().back(); ASSERT(lastStmt.GetOpCode() == OP_switch, "runtime check error"); - SwitchNode &switchStmt = static_cast(lastStmt); + auto &switchStmt = static_cast(lastStmt); LabelIdx lblIdx = switchStmt.GetDefaultLabel(); BB *mirBB = func.GetLabelBBAt(lblIdx); bb->GetSucc().push_back(mirBB); @@ -112,10 +112,10 @@ void MeCFG::BuildMirCFG() { auto it = func.GetBBTryNodeMap().find(bb); CHECK_FATAL(it != func.GetBBTryNodeMap().end(), "try bb without try"); StmtNode *currTry = it->second; - const TryNode *tryNode = static_cast(currTry); + const auto *tryNode = static_cast(currTry); bool hasFinallyHandler = false; /* add exception handler bb */ - for (size_t j = 0; j < tryNode->GetOffsetsCount(); j++) { + for (size_t j = 0; j < tryNode->GetOffsetsCount(); ++j) { LabelIdx labelIdx = tryNode->GetOffset(j); ASSERT(func.GetLabelBBIdMap().find(labelIdx) != func.GetLabelBBIdMap().end(), "runtime check error"); BB *meBB = func.GetLabelBBAt(labelIdx); @@ -126,7 +126,7 @@ void MeCFG::BuildMirCFG() { hasFinallyHandler = true; } /* avoid redundant succ */ - for (; si < bb->GetSucc().size(); si++) { + for (; si < bb->GetSucc().size(); ++si) { if (meBB == bb->GetSucc(si)) { break; } @@ -137,7 +137,7 @@ void MeCFG::BuildMirCFG() { } } /* if try block don't have finally catch handler, add common_exit_bb as its succ */ - if (hasFinallyHandler == false) { + if (!hasFinallyHandler) { if (!bb->GetAttributes(kBBAttrIsExit)) { bb->SetAttributes(kBBAttrIsExit); // may exit exitBlocks.push_back(bb); @@ -154,23 +154,25 @@ void MeCFG::BuildMirCFG() { } } // merge all blocks in entryBlocks - for (auto it = entryBlocks.begin(); it != entryBlocks.end(); ++it) { - func.GetCommonEntryBB()->GetSucc().push_back(*it); + for (BB *bb : entryBlocks) { + func.GetCommonEntryBB()->GetSucc().push_back(bb); + } // merge all blocks in exitBlocks - for (auto it = exitBlocks.begin(); it != exitBlocks.end(); ++it) { - func.GetCommonExitBB()->GetPred().push_back(*it); + for (BB *bb : exitBlocks) { + func.GetCommonExitBB()->GetPred().push_back(bb); + } } bool MeCFG::FindExprUse(const BaseNode &expr, StIdx stIdx) const { if (expr.GetOpCode() == OP_addrof || expr.GetOpCode() == OP_dread) { - const AddrofNode &addofNode = static_cast(expr); + const auto &addofNode = static_cast(expr); return addofNode.GetStIdx() == stIdx; } else if (expr.GetOpCode() == OP_iread) { return FindExprUse(*expr.Opnd(0), stIdx); } else { - for (size_t i = 0; i < expr.NumOpnds(); i++) { + for (size_t i = 0; i < expr.NumOpnds(); ++i) { if (FindExprUse(*expr.Opnd(i), stIdx)) { return true; } @@ -217,18 +219,18 @@ bool MeCFG::FindUse(const StmtNode &stmt, StIdx stIdx) const { break; } case OP_dassign: { - const DassignNode &dNode = static_cast(stmt); + const auto &dNode = static_cast(stmt); return FindExprUse(*dNode.GetRHS(), stIdx); } case OP_regassign: { - const RegassignNode &rNode = static_cast(stmt); + const auto &rNode = static_cast(stmt); if (rNode.GetRegIdx() < 0) { return false; } return FindExprUse(*rNode.Opnd(0), stIdx); } case OP_iassign: { - const IassignNode &iNode = static_cast(stmt); + const auto &iNode = static_cast(stmt); if (FindExprUse(*iNode.Opnd(0), stIdx)) { return true; } else { @@ -253,18 +255,17 @@ bool MeCFG::FindDef(const StmtNode &stmt, StIdx stIdx) const { return false; } if (stmt.GetOpCode() == OP_dassign) { - const DassignNode &dassStmt = static_cast(stmt); + const auto &dassStmt = static_cast(stmt); return dassStmt.GetStIdx() == stIdx; - } else { - const CallNode &cnode = static_cast(stmt); - const CallReturnVector &nrets = cnode.GetReturnVec(); - if (nrets.size() != 0) { - ASSERT(nrets.size() == 1, "Single Ret value for now."); - StIdx stidx = nrets[0].first; - RegFieldPair regfieldpair = nrets[0].second; - if (!regfieldpair.IsReg()) { - return stidx == stIdx; - } + } + const auto &cnode = static_cast(stmt); + const CallReturnVector &nrets = cnode.GetReturnVec(); + if (!nrets.empty()) { + ASSERT(nrets.size() == 1, "Single Ret value for now."); + StIdx idx = nrets[0].first; + RegFieldPair regFieldPair = nrets[0].second; + if (!regFieldPair.IsReg()) { + return idx == stIdx; } } return false; @@ -295,10 +296,10 @@ void MeCFG::FixMirCFG() { for (StmtNode *stmt = to_ptr(bb->GetStmtNodes().begin()); stmt != nullptr; stmt = stmt->GetNext()) { const MIRSymbol *sym = nullptr; if (kOpcodeInfo.IsCallAssigned(stmt->GetOpCode())) { - CallNode *cNode = static_cast(stmt); + auto *cNode = static_cast(stmt); sym = cNode->GetCallReturnSymbol(func.GetMIRModule()); } else if (stmt->GetOpCode() == OP_dassign) { - DassignNode *dassStmt = static_cast(stmt); + auto *dassStmt = static_cast(stmt); // exclude the case a = b; if (dassStmt->GetRHS()->GetOpCode() == OP_dread) { continue; @@ -320,7 +321,7 @@ void MeCFG::FixMirCFG() { bb->ReplaceStmt(stmt, dassign); stmt = dassign; } else { - CallNode *cnode = static_cast(stmt); + auto *cnode = static_cast(stmt); CallReturnPair retPair = cnode->GetReturnPair(0); retPair.first = targetSt->GetStIdx(); cnode->SetReturnPair(retPair, 0); @@ -353,7 +354,7 @@ void MeCFG::FixMirCFG() { const MIRSymbol *sym = nullptr; StmtNode *nextStmt = splitPoint.GetNext(); if (kOpcodeInfo.IsCallAssigned(splitPoint.GetOpCode())) { - CallNode *cNode = static_cast(&splitPoint); + auto *cNode = static_cast(&splitPoint); sym = cNode->GetCallReturnSymbol(func.GetMIRModule()); } else { if (nextStmt == nullptr || @@ -361,11 +362,11 @@ void MeCFG::FixMirCFG() { continue; } if (nextStmt->GetOpCode() == OP_dassign) { - DassignNode *dassignStmt = static_cast(nextStmt); + auto *dassignStmt = static_cast(nextStmt); const StIdx stIdx = dassignStmt->GetStIdx(); sym = func.GetMirFunc()->GetLocalOrGlobalSymbol(stIdx); } else { - CallNode *cNode = static_cast(nextStmt); + auto *cNode = static_cast(nextStmt); sym = cNode->GetCallReturnSymbol(func.GetMIRModule()); } } @@ -382,7 +383,7 @@ void MeCFG::FixMirCFG() { bIt = build_filter_iterator( newBBIt, std::bind(FilterNullPtr::const_iterator>, std::placeholders::_1, func.end())); eIt = func.valid_end(); - for (size_t si = 0; si < newBB.GetSucc().size(); si++) { + for (size_t si = 0; si < newBB.GetSucc().size(); ++si) { BB *sucBB = newBB.GetSucc(si); if (sucBB->GetAttributes(kBBAttrIsCatch)) { bb->AddSuccBB(sucBB); @@ -405,12 +406,12 @@ void MeCFG::FixMirCFG() { if (stmt != nullptr) { size_t si = 0; // simplify the cfg removing all succs of this bb - for (; si < bb->GetSucc().size(); si++) { + for (; si < bb->GetSucc().size(); ++si) { BB *sucBB = bb->GetSucc(si); if (sucBB->GetAttributes(kBBAttrIsCatch)) { sucBB->RemoveBBFromPred(bb); bb->RemoveBBFromSucc(sucBB); - si--; + --si; } } continue; @@ -434,7 +435,7 @@ void MeCFG::FixMirCFG() { if (sucBB->GetAttributes(kBBAttrIsCatch)) { sucBB->ReplacePred(&newBB, bb); newBB.RemoveBBFromSucc(sucBB); - si--; + --si; } } if (bIt == eIt) { @@ -448,7 +449,7 @@ void MeCFG::ConvertPhiList2IdentityAssigns(BB &meBB) const { auto phiIt = meBB.GetPhiList().begin(); while (phiIt != meBB.GetPhiList().end()) { if (!(*phiIt).second.GetResult()->IsLive()) { - phiIt++; + ++phiIt; continue; } // replace phi with identify assignment as it only has 1 opnd @@ -468,7 +469,7 @@ void MeCFG::ConvertPhiList2IdentityAssigns(BB &meBB) const { theSSAPart->SetSSAVar(*((*phiIt).second.GetResult())); meBB.PrependStmtNode(dassign); } - phiIt++; + ++phiIt; } meBB.ClearPhiList(); // delete all the phis } @@ -477,7 +478,7 @@ void MeCFG::ConvertMevarPhiList2IdentityAssigns(BB &meBB) const { auto varPhiIt = meBB.GetMevarPhiList().begin(); while (varPhiIt != meBB.GetMevarPhiList().end()) { if (!(*varPhiIt).second->GetIsLive()) { - varPhiIt++; + ++varPhiIt; continue; } // replace phi with identify assignment as it only has 1 opnd @@ -491,7 +492,7 @@ void MeCFG::ConvertMevarPhiList2IdentityAssigns(BB &meBB) const { dassign->SetIsLive(varPhi->GetIsLive()); meBB.PrependMeStmt(dassign); } - varPhiIt++; + ++varPhiIt; } meBB.GetMevarPhiList().clear(); // delete all the phis } @@ -500,7 +501,7 @@ void MeCFG::ConvertMeregphiList2IdentityAssigns(BB &meBB) const { auto regPhiIt = meBB.GetMeregphiList().begin(); while (regPhiIt != meBB.GetMeregphiList().end()) { if (!(*regPhiIt).second->GetIsLive()) { - regPhiIt++; + ++regPhiIt; continue; } // replace phi with identify assignment as it only has 1 opnd @@ -514,7 +515,7 @@ void MeCFG::ConvertMeregphiList2IdentityAssigns(BB &meBB) const { regass->SetIsLive(regPhi->GetIsLive()); meBB.PrependMeStmt(regass); } - regPhiIt++; + ++regPhiIt; } meBB.GetMeregphiList().clear(); // delete all the phis } @@ -543,7 +544,7 @@ void MeCFG::UnreachCodeAnalysis(bool updatePhi) { bb->SetAttributes(kBBAttrWontExit); /* avoid redundant pred before adding to common_exit_bb's pred list */ size_t pi = 0; - for (; pi < func.GetCommonExitBB()->GetPred().size(); pi++) { + for (; pi < func.GetCommonExitBB()->GetPred().size(); ++pi) { if (bb == func.GetCommonExitBB()->GetPred(pi)) { break; } @@ -571,7 +572,7 @@ void MeCFG::UnreachCodeAnalysis(bool updatePhi) { } func.DeleteBasicBlock(*bb); // remove the bb from its succ's pred_ list - for (auto it = bb->GetSucc().begin(); it != bb->GetSucc().end(); it++) { + for (auto it = bb->GetSucc().begin(); it != bb->GetSucc().end(); ++it) { BB *sucBB = *it; if (!updatePhi) { bb->RemoveBBFromVector(sucBB->GetPred()); @@ -586,7 +587,7 @@ void MeCFG::UnreachCodeAnalysis(bool updatePhi) { } // remove the bb from common_exit_bb's pred list if it is there for (auto it = func.GetCommonExitBB()->GetPred().begin(); - it != func.GetCommonExitBB()->GetPred().end(); it++) { + it != func.GetCommonExitBB()->GetPred().end(); ++it) { if (*it == bb) { func.GetCommonExitBB()->RemoveBBFromPred(bb); break; @@ -697,7 +698,7 @@ void MeCFG::VerifyLabels() const { static_cast(stmtNodes.back()).GetOffset(), "undefined label in conditional branch"); } else if (mirBB->GetKind() == kBBSwitch) { - SwitchNode &switchStmt = static_cast(stmtNodes.back()); + auto &switchStmt = static_cast(stmtNodes.back()); LabelIdx targetLabIdx = switchStmt.GetDefaultLabel(); BB *bb = func.GetLabelBBAt(targetLabIdx); ASSERT(bb->GetBBLabel() == targetLabIdx, "undefined label in switch"); @@ -725,7 +726,7 @@ void MeCFG::Dump() const { continue; } BBId id = bb->GetBBId(); - if (visitedMap[static_cast(id)] == true) { + if (visitedMap[static_cast(id)]) { continue; } LogInfo::MapleLogger() << id << " "; @@ -736,19 +737,19 @@ void MeCFG::Dump() const { if (!visitedMap[static_cast(kidBB->GetBBId())]) { qu.push(kidBB); } - it++; + ++it; } } - LogInfo::MapleLogger() << "\n"; + LogInfo::MapleLogger() << '\n'; free(visitedMap); } } /* replace special char in FunctionName for output file */ static void ReplaceFilename(std::string &fileName) { - for (size_t i = 0; i < fileName.length(); i++) { - if (fileName[i] == ';' || fileName[i] == '/' || fileName[i] == '|') { - fileName[i] = '_'; + for (char &c : fileName) { + if (c == ';' || c == '/' || c == '|') { + c = '_'; } } } @@ -757,7 +758,7 @@ static bool ContainsConststr(const BaseNode &x) { if (x.GetOpCode() == OP_conststr || x.GetOpCode() == OP_conststr16) { return true; } - for (size_t i = 0; i < x.NumOpnds(); i++) + for (size_t i = 0; i < x.NumOpnds(); ++i) if (ContainsConststr(*x.Opnd(i))) { return true; } @@ -796,8 +797,8 @@ void MeCFG::DumpToFileInStrs(std::ofstream &cfgFile) const { if (bb->GetBBLabel() != 0) { cfgFile << "@" << func.GetMirFunc()->GetLabelName(bb->GetBBLabel()) << ":\n"; } - for (auto phiIt = bb->GetPhiList().begin(); phiIt != bb->GetPhiList().end(); phiIt++) { - (*phiIt).second.Dump(&(func.GetMIRModule())); + for (auto &phiPair : bb->GetPhiList()) { + phiPair.second.Dump(&(func.GetMIRModule())); } for (auto &stmt : bb->GetStmtNodes()) { // avoid printing content that may contain " as this needs to be quoted @@ -832,13 +833,13 @@ void MeCFG::DumpToFile(const std::string &prefix, bool dumpInStrs) const { auto *bb = *bIt; if (bIt == func.common_exit()) { /* specical case for common_exit_bb */ - for (auto it = bb->GetPred().begin(); it != bb->GetPred().end(); it++) { + for (auto it = bb->GetPred().begin(); it != bb->GetPred().end(); ++it) { cfgFile << "BB" << (*it)->GetBBId() << " -> " << "BB" << bb->GetBBId() << "[style=dotted];\n"; } continue; } - for (auto it = bb->GetSucc().begin(); it != bb->GetSucc().end(); it++) { + for (auto it = bb->GetSucc().begin(); it != bb->GetSucc().end(); ++it) { cfgFile << "BB" << bb->GetBBId() << " -> " << "BB" << (*it)->GetBBId(); if (bb == func.GetCommonEntryBB()) { diff --git a/src/maple_me/src/me_dominance.cpp b/src/maple_me/src/me_dominance.cpp index ca05ea4ac2067cd6644a888d50d92cea08fa6edc..248d240f35a2352a0586ea8d85583a00a0982ee3 100644 --- a/src/maple_me/src/me_dominance.cpp +++ b/src/maple_me/src/me_dominance.cpp @@ -24,8 +24,8 @@ namespace maple { AnalysisResult *MeDoDominance::Run(MeFunction *func, MeFuncResultMgr *funcResMgr, ModuleResultMgr *moduleResMgr) { MemPool *memPool = NewMemPool(); - Dominance *dom = memPool->New(*memPool, *NewMemPool(), func->GetAllBBs(), - *func->GetCommonEntryBB(), *func->GetCommonExitBB()); + auto *dom = memPool->New(*memPool, *NewMemPool(), func->GetAllBBs(), + *func->GetCommonEntryBB(), *func->GetCommonExitBB()); dom->GenPostOrderID(); dom->ComputeDominance(); dom->ComputeDomFrontiers(); diff --git a/src/maple_me/src/me_emit.cpp b/src/maple_me/src/me_emit.cpp index 83274c3801060d5c34e376d3252284f0f1d8978c..05e5e10795adcbf4140948bdd4baed11c4fb97e6 100644 --- a/src/maple_me/src/me_emit.cpp +++ b/src/maple_me/src/me_emit.cpp @@ -18,11 +18,11 @@ #include "me_cfg.h" namespace maple { -/* emit IR to specified file */ +// emit IR to specified file 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) */ + // generate bblist after layout (bb physical position) if (!MeOption::quiet) { CHECK_FATAL(funcResMgr->GetAnalysisPhase(MeFuncPhase_BBLAYOUT) != nullptr, "null ptr check"); LogInfo::MapleLogger() << "===== Check/run Depended Phase [ " diff --git a/src/maple_me/src/me_function.cpp b/src/maple_me/src/me_function.cpp index ad404e5ffd5095dccd5907079c155c7ec4cf382c..179d0c76f465b9d88cac1d1985a23efaded140cf 100644 --- a/src/maple_me/src/me_function.cpp +++ b/src/maple_me/src/me_function.cpp @@ -39,11 +39,11 @@ void MeFunction::PartialInit(bool isSecondPass) { secondPass = isSecondPass; if ((mirModule.GetSrcLang() == kSrcLangJava) && (!mirModule.CurFunction()->GetInfoVector().empty())) { std::string string("INFO_registers"); - GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(string); - regNum = mirModule.CurFunction()->GetInfo(stridx); - std::string trynum("INFO_tries_size"); - stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(trynum); - uint32 num = mirModule.CurFunction()->GetInfo(stridx); + GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(string); + regNum = mirModule.CurFunction()->GetInfo(strIdx); + std::string tryNum("INFO_tries_size"); + strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(tryNum); + uint32 num = mirModule.CurFunction()->GetInfo(strIdx); hasEH = (num != 0); } } @@ -154,7 +154,7 @@ void MeFunction::CreateBasicBlocks() { case OP_doloop: case OP_dowhile: case OP_while: { - ASSERT(false, "NYI"); + ASSERT(false, "not yet implemented"); break; } case OP_throw: @@ -283,17 +283,18 @@ void MeFunction::CreateBasicBlocks() { } curBB->SetFirst(stmt); curBB->SetAttributes(kBBAttrIsCatch); - CatchNode *catchNode = static_cast(stmt); - const MapleVector &exceptiontyidxvec = catchNode->GetExceptionTyIdxVec(); - for (size_t i = 0; i < exceptiontyidxvec.size(); i++) { - MIRType *eType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(exceptiontyidxvec[i]); + auto *catchNode = static_cast(stmt); + const MapleVector &exceptionTyIdxVec = catchNode->GetExceptionTyIdxVec(); + + for (TyIdx excepIdx : exceptionTyIdxVec) { + MIRType *eType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(excepIdx); ASSERT(eType != nullptr && (eType->GetPrimType() == PTY_ptr || eType->GetPrimType() == PTY_ref), "wrong exception type"); - MIRPtrType *epType = static_cast(eType); + auto *epType = static_cast(eType); MIRType *pointType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(epType->GetPointedTyIdx()); const std::string &ename = GlobalTables::GetStrTable().GetStringFromStrIdx(pointType->GetNameStrIdx()); - if ((pointType->GetPrimType() == PTY_void) || (ename.compare("Ljava/lang/Throwable;") == 0) || - (ename.compare("Ljava/lang/Exception;") == 0)) { + if ((pointType->GetPrimType() == PTY_void) || (ename == "Ljava/lang/Throwable;") || + (ename == "Ljava/lang/Exception;")) { // "Ljava/lang/Exception;" is risk to set isJavaFinally because it // only deal with "throw exception". if throw error, it's wrong curBB->SetAttributes(kBBAttrIsJavaFinally); // this is a start of finally handler @@ -302,7 +303,7 @@ void MeFunction::CreateBasicBlocks() { break; } case OP_label: { - LabelNode *lblNode = static_cast(stmt); + auto *lblNode = static_cast(stmt); LabelIdx labidx = lblNode->GetLabelIdx(); if (!curBB->IsEmpty() || curBB->GetBBLabel() != 0) { // prepare a new bb @@ -391,7 +392,6 @@ void MeFunction::CreateBasicBlocks() { } else if (lastBB->GetKind() == kBBUnknown) { lastBB->SetKind(kBBReturn); } - return; } void MeFunction::Prepare(unsigned long rangeNum) { @@ -447,7 +447,7 @@ BB *MeFunction::InsertNewBasicBlock(const BB &position) { if ((*it) != nullptr) { (*it)->SetBBId(BBId(idx)); } - idx++; + ++idx; } return newBB; } @@ -488,7 +488,7 @@ void MeFunction::CloneBasicBlock(BB &newBB, const BB &orig) { return; } for (const auto &stmt : orig.GetStmtNodes()) { - StmtNode *newStmt = static_cast(stmt.CloneTree(mirModule.GetCurFuncCodeMPAllocator())); + StmtNode *newStmt = stmt.CloneTree(mirModule.GetCurFuncCodeMPAllocator()); newStmt->SetNext(nullptr); newStmt->SetPrev(nullptr); newBB.AddStmtNode(newStmt); @@ -539,13 +539,13 @@ BB &MeFunction::SplitBB(BB &bb, StmtNode &splitPoint, BB *newBB) { } // Special Case: commonExitBB is orig bb's succ auto *commonExitBB = *common_exit(); - for (size_t i = 0; i < commonExitBB->GetPred().size(); i++) { + for (size_t i = 0; i < commonExitBB->GetPred().size(); ++i) { if (commonExitBB->GetPred(i) == &bb) { commonExitBB->SetPred(i, newBB); break; } } - for (size_t i = 0; i < bb.GetSucc().size(); i++) { + for (size_t i = 0; i < bb.GetSucc().size(); ++i) { BB *succ = bb.GetSucc(i); succ->ReplacePred(&bb, newBB); } @@ -586,9 +586,9 @@ void MeFunction::RemoveEhEdgesInSyncRegion() { if (endTryBB2TryBB.size() != 1) { return; } - for (auto iter : endTryBB2TryBB) { - BB *tryBB = iter.second; - BB *endtryBB = iter.first; + for (auto &pair : endTryBB2TryBB) { + BB *tryBB = pair.second; + BB *endtryBB = pair.first; CHECK_FATAL(tryBB != nullptr, "null ptr check "); CHECK_FATAL(endtryBB != nullptr, "null ptr check "); // Filter out complex cases @@ -598,8 +598,8 @@ void MeFunction::RemoveEhEdgesInSyncRegion() { tryBB->GetStmtNodes().back().GetOpCode() != OP_try) { return; } - for (auto it : bbTryNodeMap) { - BB *bb = it.first; + for (auto &bbTryPair : bbTryNodeMap) { + BB *bb = bbTryPair.first; if (bb != tryBB && bb != endtryBB) { for (auto &stmt : bb->GetStmtNodes()) { if (stmt.GetOpCode() == OP_try || stmt.GetOpCode() == OP_catch || stmt.GetOpCode() == OP_throw) { @@ -609,8 +609,8 @@ void MeFunction::RemoveEhEdgesInSyncRegion() { } } // Unmark unnecessary isTry flags - for (auto it : bbTryNodeMap) { - BB *bb = it.first; + for (auto &bbTryPair : bbTryNodeMap) { + BB *bb = bbTryPair.first; if (bb != tryBB && bb != endtryBB) { bb->ClearAttributes(kBBAttrIsTry); } @@ -624,7 +624,7 @@ void MeFunction::BuildSCCDFS(BB &bb, uint32 &visitIndex, std::vector uint32 id = bb.UintID(); visitedOrder[id] = visitIndex; lowestOrder[id] = visitIndex; - visitIndex++; + ++visitIndex; visitStack.push(id); inStack[id] = true; @@ -647,7 +647,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); + auto *sccNode = alloc.GetMemPool()->New(numOfSCCs++, &bb, &alloc); uint32 stackTopId; do { stackTopId = visitStack.top(); @@ -702,7 +702,7 @@ void MeFunction::SCCTopologicalSort(std::vector &sccNodes) { } // Top-down iterates all nodes - for (size_t i = 0; i < sccTopologicalVec.size(); i++) { + for (size_t i = 0; i < sccTopologicalVec.size(); ++i) { SCCOfBBs *scc = sccTopologicalVec[i]; for (SCCOfBBs *succ : scc->GetSucc()) { if (InQueue.find(succ) == InQueue.end()) { @@ -734,7 +734,7 @@ void MeFunction::BBTopologicalSort(SCCOfBBs &scc) { scc.AddBBNode(scc.GetEntry()); InQueue.insert(scc.GetEntry()); - for (size_t i = 0; i < scc.GetBBs().size(); i++) { + for (size_t i = 0; i < scc.GetBBs().size(); ++i) { BB *bb = scc.GetBBs()[i]; for (BB *succ : bb->GetSucc()) { if (succ == nullptr) { diff --git a/src/maple_me/src/me_ir.cpp b/src/maple_me/src/me_ir.cpp index 0fb9e5fc932f64986ab55a83a3191308b088fad2..569e48fd1f9991949b21aafea6e81d49dc8dd19e 100644 --- a/src/maple_me/src/me_ir.cpp +++ b/src/maple_me/src/me_ir.cpp @@ -331,10 +331,10 @@ bool IvarMeExpr::IsFinal() { return static_cast(pointedTy)->IsFieldFinal(fieldID); } -/* - * check paragma - * pragma 0 var %keySet <$Ljava_2Flang_2Fannotation_2FRCWeakRef_3B> - */ + +// check paragma +// pragma 0 var %keySet <$Ljava_2Flang_2Fannotation_2FRCWeakRef_3B> + bool IvarMeExpr::IsRCWeak() const { MIRPtrType *ty = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)); MIRType *pointedType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ty->GetPointedTyIdx()); diff --git a/src/maple_me/src/me_irmap.cpp b/src/maple_me/src/me_irmap.cpp index fab5ac9d3ed14ce3cd1e9aa508d6fa84f5cc5fb0..72470a5921e09c60b40f86a18832ba658a9b6610 100644 --- a/src/maple_me/src/me_irmap.cpp +++ b/src/maple_me/src/me_irmap.cpp @@ -84,7 +84,7 @@ void MeIRMap::EmitBB(const BB &bb, BlockNode &curblk) { } EmitBBStmts(bb, curblk); if (bb.GetAttributes(kBBAttrIsTryEnd)) { - /* generate op_endtry */ + // generate op_endtry StmtNode *endtry = GetSSATab().GetModule().CurFunction()->GetCodeMempool()->New(OP_endtry); curblk.AddStatement(endtry); } diff --git a/src/maple_me/src/me_option.cpp b/src/maple_me/src/me_option.cpp index ea5cb6ff232924d8caaf0752b0fa4d0ac3ff9e1f..4795bf9c4fd1e3343e30eb3a7863c51b74c1ec28 100644 --- a/src/maple_me/src/me_option.cpp +++ b/src/maple_me/src/me_option.cpp @@ -37,7 +37,6 @@ bool MeOption::stmtNum = false; uint8 MeOption::optLevel = 0; bool MeOption::ignoreIPA = true; bool MeOption::lessThrowAlias = true; -bool MeOption::finalFieldAlias = false; bool MeOption::regreadAtReturn = true; void MeOption::SplitPhases(const std::string &str, std::unordered_set &set) const { diff --git a/src/maple_me/src/me_phase_manager.cpp b/src/maple_me/src/me_phase_manager.cpp index 5ccb1b20f4396da38d4bc66bfaaea0c36e4f2279..7558852267a38e2fc054ae85f8101be53558f935 100644 --- a/src/maple_me/src/me_phase_manager.cpp +++ b/src/maple_me/src/me_phase_manager.cpp @@ -47,13 +47,13 @@ void MeFuncPhaseManager::RunFuncPhase(MeFunction *func, MeFuncPhase *phase) { phase->ReleaseMemPool(r == nullptr ? nullptr : r->GetMempool()); } if (r != nullptr) { - /* if phase is an analysis Phase, add result to arm */ + // if phase is an analysis Phase, add result to arm arFuncManager.AddResult(phase->GetPhaseId(), *func, *r); } } void MeFuncPhaseManager::RegisterFuncPhases() { - /* register all Funcphases defined in me_phases.def */ + // register all Funcphases defined in me_phases.def #define FUNCTPHASE(id, mephase) \ do { \ void *buf = GetMemAllocator()->GetMemPool()->Malloc(sizeof(mephase(id))); \ @@ -87,7 +87,7 @@ void MeFuncPhaseManager::AddPhases(const std::unordered_set &skipPh } }; if (mePhaseType == kMePhaseMainopt) { - /* default phase sequence */ + // default phase sequence addPhase("ssaTab"); addPhase("aliasclass"); addPhase("ssa"); @@ -110,9 +110,10 @@ void MeFuncPhaseManager::IPACleanUp(MeFunction *func) { } void MeFuncPhaseManager::Run(MIRFunction *mirFunc, uint64 rangeNum, const std::string &meInput) { - if (!MeOption::quiet) + if (!MeOption::quiet) { LogInfo::MapleLogger() << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>> Optimizing Function < " << mirFunc->GetName() << " id=" << mirFunc->GetPuidxOrigin() << " >---\n"; + } MemPool *funcMP = memPoolCtrler.NewMemPool("maple_me per-function mempool"); MemPool *versMP = memPoolCtrler.NewMemPool("first verst mempool"); MeFunction func(&mirModule, mirFunc, funcMP, versMP, meInput); @@ -127,13 +128,13 @@ void MeFuncPhaseManager::Run(MIRFunction *mirFunc, uint64 rangeNum, const std::s } std::string phaseName = ""; MeFuncPhase *changeCFGPhase = nullptr; - /* each function level phase */ + // each function level phase bool dumpFunc = FuncFilter(MeOption::dumpFunc, func.GetName()); size_t phaseIndex = 0; for (auto it = PhaseSequenceBegin(); it != PhaseSequenceEnd(); ++it, ++phaseIndex) { PhaseID id = GetPhaseId(it); MeFuncPhase *p = static_cast(GetPhase(id)); - p->SetPreviousPhaseName(phaseName); /* prev phase name is for filename used in emission after phase */ + p->SetPreviousPhaseName(phaseName); // prev phase name is for filename used in emission after phase phaseName = p->PhaseName(); // new phase name bool dumpPhase = MeOption::DumpPhase(phaseName); MPLTimer timer; @@ -174,7 +175,7 @@ void MeFuncPhaseManager::Run(MIRFunction *mirFunc, uint64 rangeNum, const std::s if (p == changeCFGPhase) { continue; } - p->SetPreviousPhaseName(phaseName); /* prev phase name is for filename used in emission after phase */ + p->SetPreviousPhaseName(phaseName); // prev phase name is for filename used in emission after phase phaseName = p->PhaseName(); // new phase name bool dumpPhase = MeOption::DumpPhase(phaseName); RunFuncPhase(&function, p); diff --git a/src/maple_me/src/me_rc_lowering.cpp b/src/maple_me/src/me_rc_lowering.cpp index b125fbe4cbe0721870681f032874cc4221ce093d..ec9f834ea1d6564432ed1b27f11a675557547840 100644 --- a/src/maple_me/src/me_rc_lowering.cpp +++ b/src/maple_me/src/me_rc_lowering.cpp @@ -15,11 +15,9 @@ #include "me_rc_lowering.h" #include -/* - * RCLowering phase generate RC intrinsic for reference assignment - * based on previous analyze results. RC intrinsic will later be lowered - * in Code Generation - */ +// RCLowering phase generate RC intrinsic for reference assignment +// based on previous analyze results. RC intrinsic will later be lowered +// in Code Generation namespace { } @@ -256,11 +254,9 @@ void RCLowering::HandleRetOfCallAssignedMeStmt(MeStmt &stmt, MeExpr &pendingDec) bb->InsertMeStmtBefore(&stmt, backup); bb->InsertMeStmtAfter(&stmt, decRefCall); } else { - /* - * simple optimization for callassign - * instead of change callassign {dassign} to backup; callassign {dassign}; decref - * callassign {regassign}; backup; dassign (regread); decref - */ + // simple optimization for callassign + // instead of change callassign {dassign} to backup; callassign {dassign}; decref + // callassign {regassign}; backup; dassign (regread); decref RegMeExpr *curTmp = irMap.CreateRegMeExpr(PTY_ref); MeStmt *regToVar = irMap.CreateDassignMeStmt(*stmt.GetAssignedLHS(), *curTmp, *bb); stmt.GetMustDefList()->front().UpdateLHS(*curTmp); @@ -305,11 +301,9 @@ void RCLowering::PreprocessAssignMeStmt(MeStmt &stmt) { } gcMallocObjects.insert(lhs); if (lsym->GetAttr(ATTR_rcunowned)) { - /* - * if new obj is assigned to unowned refvar, we need a localrefvar - * to decref at exit - * introduce new localrefvar = lhs after current stmt - */ + // if new obj is assigned to unowned refvar, we need a localrefvar + // to decref at exit + // introduce new localrefvar = lhs after current stmt MeStmt *backup = irMap.CreateDassignMeStmt(*CreateNewTmpVarMeExpr(true), *lhs, *bb); // backup will not have any incref/decref bb->InsertMeStmtAfter(&stmt, backup); @@ -452,11 +446,10 @@ void RCLowering::HandleAssignMeStmt(MeStmt &stmt, MeExpr *pendingDec) { } } -/* - * align with order in rcinsertion, otherwise missing weak volatile - * note that we are generating INTRN_MCCWriteNoRC so write_barrier is supported, - * otherwise iassign would be enough. - */ + +// align with order in rcinsertion, otherwise missing weak volatile +// note that we are generating INTRN_MCCWriteNoRC so write_barrier is supported, +// otherwise iassign would be enough. MIRIntrinsicID RCLowering::SelectWriteBarrier(const MeStmt &stmt) { bool incWithLHS = stmt.NeedIncref(); bool decWithLHS = stmt.NeedDecref(); @@ -498,11 +491,10 @@ void RCLowering::RCLower() { } } -/* - * if a var me expr is initialized by constructor, record it's initialized map - * if a field id is not in initialized map, means the field has not been assigned a value - * dec ref is not necessary in it's first assignment. - */ + +// if a var me expr is initialized by constructor, record it's initialized map +// if a field id is not in initialized map, means the field has not been assigned a value +// dec ref is not necessary in it's first assignment. void RCLowering::InitializedObjectFields(MeStmt &stmt) { if (stmt.GetOp() != OP_callassigned) { return; @@ -586,10 +578,8 @@ void RCLowering::HandleReturnVar(RetMeStmt &ret) { if (sym != nullptr && sym->IsGlobal() && !sym->IsFinal()) { HandleReturnGlobal(ret); } else if (assignedPtrSym.count(sym) > 0 && sym->GetStorageClass() == kScAuto && sym->GetAttr(ATTR_localrefvar)) { - /* - * must be regreadAtReturn - * checking localrefvar because some objects are meta - */ + // must be regreadAtReturn + // checking localrefvar because some objects are meta HandleReturnRegread(ret); } else { // if returning formal, incref unless placementRC is used and formal is NOT reassigned @@ -665,10 +655,8 @@ void RCLowering::HandleReturnIvar(RetMeStmt &ret) { } void RCLowering::HandleReturnReg(RetMeStmt &ret) { - /* - * if the register with ref value is defined by callassigned or gcmalloc - * return incref should have been delegated and not needed. - */ + // if the register with ref value is defined by callassigned or gcmalloc + // return incref should have been delegated and not needed. auto *regRet = static_cast(ret.GetOpnd(0)); if (regRet->GetDefBy() == kDefByMustDef) { return; @@ -723,10 +711,8 @@ void RCLowering::HandleReturnWithCleanup() { } void RCLowering::HandleReturnNeedBackup() { - /* - * any return value expression containing ivar has to be saved in a - * temp with the temp being returned - */ + // any return value expression containing ivar has to be saved in a + // temp with the temp being returned for (auto *stmt : rets) { auto *ret = static_cast(stmt); if (ret->NumMeStmtOpnds() == 0) { @@ -754,10 +740,8 @@ void RCLowering::HandleReturnStmt() { } void RCLowering::HandleArguments() { - /* - * handle arguments, if the formal gets modified - * insert incref at entry and decref before all returns - */ + // handle arguments, if the formal gets modified + // insert incref at entry and decref before all returns MIRFunction *mirFunc = func.GetMirFunc(); BB *firstBB = func.GetFirstBB(); MeStmt *firstMeStmt = to_ptr(firstBB->GetMeStmts().begin()); diff --git a/src/maple_me/src/me_ssa.cpp b/src/maple_me/src/me_ssa.cpp index b92ff249baf400cb149357f6d40a27e398c2ccd4..19d0871bddb7000b7bb2d67da1c2af14cc46cfe2 100644 --- a/src/maple_me/src/me_ssa.cpp +++ b/src/maple_me/src/me_ssa.cpp @@ -21,31 +21,29 @@ #include "dominance.h" #include "me_function.h" -/* - This phase builds the SSA form of a function. Before this we have got the dominator tree - and each bb's dominance frontiers. Then the algorithm follows this outline: - - Step 1: Inserting phi-node. - With dominance frontiers, we can determine more - precisely where phi-node might be needed. The basic idea is simple. - A definition of x in block b forces a phi-node at every node in b's - dominance frontiers. Since that phi-node is a new definition of x, - it may, in turn, force the insertion of additional phi-node. - - Step 2: Renaming. - Renames both definitions and uses of each symbol in - a preorder walk over the dominator tree. In each block, we first - rename the values defined by phi-node at the head of the block, then - visit each stmt in the block: we rewrite each uses of a symbol with current - SSA names(top of the stack which holds the current SSA version of the corresponding symbol), - then it creates a new SSA name for the result of the stmt. - This latter act makes the new name current. After all the stmts in the - block have been rewritten, we rewrite the appropriate phi-node's - parameters in each cfg successor of the block, using the current SSA names. - Finally, it recurs on any children of the block in the dominator tree. When it - returns from those recursive calls, we restores the stack of current SSA names to - the state that existed before the current block was visited. - */ +// This phase builds the SSA form of a function. Before this we have got the dominator tree +// and each bb's dominance frontiers. Then the algorithm follows this outline: +// +// Step 1: Inserting phi-node. +// With dominance frontiers, we can determine more +// precisely where phi-node might be needed. The basic idea is simple. +// A definition of x in block b forces a phi-node at every node in b's +// dominance frontiers. Since that phi-node is a new definition of x, +// it may, in turn, force the insertion of additional phi-node. +// +// Step 2: Renaming. +// Renames both definitions and uses of each symbol in +// a preorder walk over the dominator tree. In each block, we first +// rename the values defined by phi-node at the head of the block, then +// visit each stmt in the block: we rewrite each uses of a symbol with current +// SSA names(top of the stack which holds the current SSA version of the corresponding symbol), +// then it creates a new SSA name for the result of the stmt. +// This latter act makes the new name current. After all the stmts in the +// block have been rewritten, we rewrite the appropriate phi-node's +// parameters in each cfg successor of the block, using the current SSA names. +// Finally, it recurs on any children of the block in the dominator tree. When it +// returns from those recursive calls, we restores the stack of current SSA names to +// the state that existed before the current block was visited. namespace maple { void MeSSA::BuildSSA() { InsertPhiNode(); diff --git a/src/maple_me/src/ssa_mir_nodes.cpp b/src/maple_me/src/ssa_mir_nodes.cpp index 132c0573086d2533b32c4e6d7a0b358cf821706a..c8294fe75dc681000a1fb902175fa5caa3e620c9 100644 --- a/src/maple_me/src/ssa_mir_nodes.cpp +++ b/src/maple_me/src/ssa_mir_nodes.cpp @@ -71,7 +71,7 @@ static MapleMap *SSAGenericGetMayDefsFromVersionSt(VersionSt visited.insert(&vst); if (vst.GetDefType() == VersionSt::kPhi) { PhiNode *phi = vst.GetPhi(); - for (size_t i = 0; i < phi->GetPhiOpnds().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) { @@ -91,14 +91,14 @@ MapleMap *SSAGenericGetMayDefsFromVersionSt(VersionSt &sym, } bool HasMayUseOpnd(const BaseNode &baseNode, SSATab &func) { - const StmtNode &stmtNode = static_cast(baseNode); + const auto &stmtNode = static_cast(baseNode); if (kOpcodeInfo.HasSSAUse(stmtNode.GetOpCode())) { MapleMap &mayUses = func.GetStmtsSSAPart().GetMayUseNodesOf(stmtNode); if (!mayUses.empty()) { return true; } } - for (size_t i = 0; i < baseNode.NumOpnds(); i++) { + for (size_t i = 0; i < baseNode.NumOpnds(); ++i) { if (HasMayUseOpnd(*baseNode.Opnd(i), func)) { return true; } diff --git a/src/maple_phase/include/phase.h b/src/maple_phase/include/phase.h index 45fc92b1f5118002b06ecbfc458d368bae1d478e..c7d4b6b4f75930a64af27bfddf3dbdb1f1d313fd 100644 --- a/src/maple_phase/include/phase.h +++ b/src/maple_phase/include/phase.h @@ -25,7 +25,7 @@ using PhaseID = int; namespace maple { -/* base class of analysisPhase's result */ +// base class of analysisPhase's result class AnalysisResult { public: explicit AnalysisResult(MemPool *memPoolParam) { @@ -97,11 +97,11 @@ class AnalysisResultManager { } virtual ~AnalysisResultManager() { + // global variable mirModule which use same mempool control is not delete yet InvalidAllResults(); - /* global variable mirModule which use same mempool control is not delete yet */ } - /* analysis result use global mempool and allocator */ + // analysis result use global mempool and allocator AnalysisResult *GetAnalysisResult(PhaseIDT id, UnitIR *ir) { ASSERT(ir != nullptr, "ir is null in AnalysisResultManager::GetAnalysisResult"); std::pair key = std::make_pair(id, ir); @@ -118,7 +118,7 @@ class AnalysisResultManager { return nullptr; } anaPhase->ReleaseMemPool(result->GetMempool()); - analysisResults[key] = result; /* add r to analysisResults */ + analysisResults[key] = result; // add r to analysisResults return result; } else { return nullptr; @@ -178,7 +178,7 @@ class AnalysisResultManager { } private: - MapleAllocator *allocator; /* allocator used in local field */ + MapleAllocator *allocator; // allocator used in local field using analysisResultKey = std::pair; MapleMap analysisResults; MapleMap analysisPhases; diff --git a/src/maple_phase/include/phase_impl.h b/src/maple_phase/include/phase_impl.h index ec380741aaec0dc2267f06784a31ed15f4c85f76..72174a1fecff2ed7c96f477c9d1af77624bb8da8 100644 --- a/src/maple_phase/include/phase_impl.h +++ b/src/maple_phase/include/phase_impl.h @@ -49,7 +49,7 @@ class FuncOptimizeImpl : public MplTaskParam { KlassHierarchy *klassHierarchy = nullptr; MIRFunction *currFunc = nullptr; - MIRBuilder *builder; + MIRBuilder *builder = nullptr; bool trace = false; private: @@ -58,7 +58,7 @@ class FuncOptimizeImpl : public MplTaskParam { class FuncOptimizeIterator { public: - explicit FuncOptimizeIterator(const std::string &phaseName, FuncOptimizeImpl *phaseImpl); + FuncOptimizeIterator(const std::string &phaseName, FuncOptimizeImpl *phaseImpl); virtual ~FuncOptimizeIterator(); virtual void Run(); diff --git a/src/maple_phase/include/phase_manager.h b/src/maple_phase/include/phase_manager.h index 257e5b13bbe8fade685427cbeb5e2a079c5e2268..f516523dd373d1cb231714aa8d0149b54b9f913b 100644 --- a/src/maple_phase/include/phase_manager.h +++ b/src/maple_phase/include/phase_manager.h @@ -84,7 +84,7 @@ class PhaseManager { return &phaseSequences; } - /* iterator for register_phases */ + // iterator for register_phases using iterator = MapleMap::iterator; iterator RegPhaseBegin() { return registeredPhases.begin(); @@ -106,7 +106,7 @@ class PhaseManager { return (*it).first; } - /* iterator for phaseSeq */ + // iterator for phaseSeq using phaseSeq_iterator = MapleVector::iterator; phaseSeq_iterator PhaseSequenceBegin() { return phaseSequences.begin(); diff --git a/src/maple_util/include/mpl_logging.h b/src/maple_util/include/mpl_logging.h index 12992b8dd65c56a0e0eee97c313699ae6e5f8a60..643f3741f5431d3be4a647af09a803bdf5311186 100644 --- a/src/maple_util/include/mpl_logging.h +++ b/src/maple_util/include/mpl_logging.h @@ -16,131 +16,142 @@ #define MAPLE_UTIL_INCLUDE_MPL_LOGGING_H #include - -/*************************************************************************** - - This file defines the APIs that govern all messaging-styled output from - a running program under MAPLE, which can be a compiler or a runtime component. - - There are two overall classes of messages: - - (1) Those of interest only to developers, and thus should be suppressed in the - production release version of the software. The message content will include - the source file and line number of the trigger point of the message. - - (2) Those intended to be visible to users of the software in general, in - addition to the developers. - - Messages are divided into 6 types, or levels, from 0 to 5. Conceptually, - the lower the level, the higher the frequency of occurrences, the larger the - output volume, the smaller the audience of interest and the more often they need - to be filtered out. In addition, the higher the level, the greater the severity. - - Level 0 (DBG) - These are messages for debugging purposes, used by the - developer during development to debug his code. - - Level 1 (LOG) - These are log messages, also for helping the developer in - debugging, but at a higher level of algorithmic operation. - - Level 2 (INFO) - These provide information that are of general usefulness in - the normal operation of the SW. - - Level 3 (WARN) - These provide warning messages. - - Level 4 (ERR) - These provide error messages. - - Level 5 (FATAL) - These indicate errors of such severity that the program r - execution cannot continue. - - DBG and LOG are only for developers' use. INFO, WARN, ERR and FATAL are - intended for general visibility. There is an additional type of ERR that - designate developer errors that arise out of checking code inserted by the - developers, which has the following 4 usage patterns: - - CHECK - If the specified program condition is not satisfied, output the error - message. The program will continue execution. - - DCHECK - Same as CHECK, but the check is suppressed in the release version of - the SW. - - CHECK_FATAL - If the specified program condition is not satisfied, output the error - message. The program will stop execution at that point. - - ASSERT - Same as CHECK_FATAL, but the check is suppressed in the release version of - the SW. - - The macro setting DEBUG=1 picks developer and DEBUG=0 picks release builds. - - the macro PRINT_LEVEL_DEV is a filter for DBG messages in developer builds. - When PRINT_LEVEL_DEV is set to kLlLog, DBG messages are not printed. - - Instantiated object c_logInfo, of class LogInfo, provides finer control of - the logging behavior during execution. Use emitLogDevice() to change the - message destination. Use setLogMode() to change the verbosity of the messages. - - In the case of DBG and LOG, the message needs to print the name of the SW - component as the volume of messages can be huge. Use enum LOG_TAGS to define - the component ID and its name string. - - Since INFO, WARN, ERR and FATAL are for general consumption, each message - should provide an number code under enum LogNumberCode. - - Following are usage examples for the 10 types of logging actions supported: - - GDB(LT_MPLME, "symbol %s SSA version %d made required during DSE", - vers->origsym->name, vers->id); - - LOG(LT_MPLME, "deleting BB %d because it is unreachable", bb->id_.GetIdx()); - - INFO(kLncInfo, "function %s inlined into %s", callee->name, caller->name); - - WARN(kLncWarn, "variable %s defined but never used", sym->name); - - ERR(kLncErr, "syntax error at file %s line %d", filename, lineno); - - FATAL(kLncFatal, "segmentation error"); - - CHECK(tyidx < type_table.size(), "%d is not a valid type index", tyidx); - - DCHECK(tyidx < type_table.size(), "%d is not a valid type index", tyidx); - - CHECK_FATAL(tyidx < type_table.size(), "%d is not a valid type index", tyidx); - - ASSERT(tyidx < type_table.size(), "%d is not a valid type index", tyidx); - - Each of the above are mapped to one of the following 3 methods in class LogInfo: - - EmitLogForDev() - for DBG and LOG - - EmitLogForUser() - for INFO, WARN, ERR and FATAL - - EmitErrorMessage() - for CHECK, DCHECK, CHECK_FATAL and ASSERT - - DBG and LOG send their messages to stdout, and provide additional date and time - information. For the rest, the messages are sent to stderr. - - In debugging the program, the developer can set breakpoint in one of the above - 3 methods depending on the type of message. For ASSERT, abort() is called - instead of exit(1) so that the program will not completely exit, to allow the - developer to print stack trace and peruse the program environment at the point - of the assertion. - -***************************************************************************/ - #include #include #include #include +// This file defines the APIs that govern all messaging-styled output from +// a running program under MAPLE, which can be a compiler or a runtime component. +// +// There are two overall classes of messages: +// +// (1) Those of interest only to developers, and thus should be suppressed in the +// production release version of the software. The message content will include +// the source file and line number of the trigger point of the message. +// +// (2) Those intended to be visible to users of the software in general, in +// addition to the developers. +// +// Messages are divided into 6 types, or levels, from 0 to 5. Conceptually, +// the lower the level, the higher the frequency of occurrences, the larger the +// output volume, the smaller the audience of interest and the more often they need +// to be filtered out. In addition, the higher the level, the greater the severity. +// +// Level 0 (DBG) - These are messages for debugging purposes, used by the +// developer during development to debug his code. +// +// Level 1 (LOG) - These are log messages, also for helping the developer in +// debugging, but at a higher level of algorithmic operation. +// +// Level 2 (INFO) - These provide information that are of general usefulness in +// the normal operation of the SW. +// +// Level 3 (WARN) - These provide warning messages. +// +// Level 4 (ERR) - These provide error messages. +// +// Level 5 (FATAL) - These indicate errors of such severity that the program r +// execution cannot continue. +// +// DBG and LOG are only for developers' use. INFO, WARN, ERR and FATAL are +// intended for general visibility. There is an additional type of ERR that +// designate developer errors that arise out of checking code inserted by the +// developers, which has the following 4 usage patterns: +// +// CHECK - If the specified program condition is not satisfied, output the error +// message. The program will continue execution. +// +// DCHECK - Same as CHECK, but the check is suppressed in the release version of +// the SW. +// +// CHECK_FATAL - If the specified program condition is not satisfied, output the error +// message. The program will stop execution at that point. +// +// ASSERT - Same as CHECK_FATAL, but the check is suppressed in the release version of +// the SW. +// +// The macro setting DEBUG=1 picks developer and DEBUG=0 picks release builds. +// +// the macro PRINT_LEVEL_DEV is a filter for DBG messages in developer builds. +// When PRINT_LEVEL_DEV is set to kLlLog, DBG messages are not printed. +// +// Instantiated object c_logInfo, of class LogInfo, provides finer control of +// the logging behavior during execution. Use emitLogDevice() to change the +// message destination. Use setLogMode() to change the verbosity of the messages. +// +// In the case of DBG and LOG, the message needs to print the name of the SW +// component as the volume of messages can be huge. Use enum LOG_TAGS to define +// the component ID and its name string. +// +// Since INFO, WARN, ERR and FATAL are for general consumption, each message +// should provide an number code under enum LogNumberCode. +// +// Following are usage examples for the 10 types of logging actions supported: +// +// GDB(LT_MPLME, "symbol %s SSA version %d made required during DSE", +// vers->origsym->name, vers->id); +// +// LOG(LT_MPLME, "deleting BB %d because it is unreachable", bb->id_.GetIdx()); +// +// INFO(kLncInfo, "function %s inlined into %s", callee->name, caller->name); +// +// WARN(kLncWarn, "variable %s defined but never used", sym->name); +// +// ERR(kLncErr, "syntax error at file %s line %d", filename, lineno); +// +// FATAL(kLncFatal, "segmentation error"); +// +// CHECK(tyidx < type_table.size(), "%d is not a valid type index", tyidx); +// +// DCHECK(tyidx < type_table.size(), "%d is not a valid type index", tyidx); +// +// CHECK_FATAL(tyidx < type_table.size(), "%d is not a valid type index", tyidx); +// +// ASSERT(tyidx < type_table.size(), "%d is not a valid type index", tyidx); +// +// Each of the above are mapped to one of the following 3 methods in class LogInfo: +// +// EmitLogForDev() - for DBG and LOG +// +// EmitLogForUser() - for INFO, WARN, ERR and FATAL +// +// EmitErrorMessage() - for CHECK, DCHECK, CHECK_FATAL and ASSERT +// +// DBG and LOG send their messages to stdout, and provide additional date and time +// information. For the rest, the messages are sent to stderr. +// +// In debugging the program, the developer can set breakpoint in one of the above +// 3 methods depending on the type of message. For ASSERT, abort() is called +// instead of exit(1) so that the program will not completely exit, to allow the +// developer to print stack trace and peruse the program environment at the point +// of the assertion. + namespace maple { extern class LogInfo logInfo; extern class LogInfo &log; -enum LogLevel { kLlDbg, kLlLog, kLlInfo, kLlWarn, kLlErr, kLlFatal, kLlMax }; +enum LogLevel { + kLlDbg, + kLlLog, + kLlInfo, + kLlWarn, + kLlErr, + kLlFatal, + kLlMax +}; -enum LogTags { kLtThread, kLtLooper, kLtAll }; +enum LogTags { + kLtThread, + kLtLooper, + kLtAll +}; -enum LogMode { kLmSimple, kLmComplex, kLmMax }; +enum LogMode { + kLmSimple, + kLmComplex, + kLmMax +}; enum LogNumberCode { kLncInfo = 0, @@ -197,19 +208,25 @@ class LogInfo { #define DBG(tag, fmt, ...) \ do { \ - if (PRINT_LEVEL_DEV <= kLlLog) \ + if (PRINT_LEVEL_DEV <= kLlLog) { \ maple::logInfo.EmitLogForDev(tag, kLlLog, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ } while (0) + #define LOG(tag, fmt, ...) \ do { \ - if (PRINT_LEVEL_DEV <= kLlLog) \ + if (PRINT_LEVEL_DEV <= kLlLog) { \ maple::logInfo.EmitLogForDev(tag, kLlLog, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ } while (0) + #define CHECK(cond, fmt, ...) \ do { \ - if (!(cond)) \ + if (!(cond)) { \ maple::logInfo.EmitErrorMessage(#cond, __FILE__, __LINE__, fmt "\n", ##__VA_ARGS__); \ + } \ } while (0) + #define DCHECK(cond, fmt, ...) \ do { \ DEBUG_STMT(CHECK(cond, fmt, ##__VA_ARGS__)); \ @@ -219,10 +236,11 @@ class LogInfo { do { \ if (!(cond)) { \ maple::logInfo.EmitErrorMessage(#cond, __FILE__, __LINE__, fmt "\n", ##__VA_ARGS__); \ - if (DEBUG_TEST) \ + if (DEBUG_TEST) { \ abort(); \ - else \ + } else { \ exit(1); \ + } \ } \ } while (0) @@ -248,33 +266,42 @@ class LogInfo { #define INFO(num, fmt, ...) \ do { \ - if (PRINT_LEVEL_USER <= kLlInfo) \ + if (PRINT_LEVEL_USER <= kLlInfo) { \ maple::logInfo.EmitLogForUser(num, kLlInfo, fmt, ##__VA_ARGS__); \ + } \ } while (0) + #define INFO_V(verbose, num, fmt, ...) \ if (verbose) { \ - if (PRINT_LEVEL_USER <= kLlInfo) \ + if (PRINT_LEVEL_USER <= kLlInfo) { \ maple::logInfo.EmitLogForUser(num, kLlInfo, fmt, ##__VA_ARGS__); \ + } \ } + #define WARN(num, fmt, ...) \ do { \ - if (PRINT_LEVEL_USER <= kLlWarn) \ + if (PRINT_LEVEL_USER <= kLlWarn) { \ maple::logInfo.EmitLogForUser(num, kLlWarn, fmt, ##__VA_ARGS__); \ + } \ } while (0) + #define ERR(num, fmt, ...) \ do { \ - if (PRINT_LEVEL_USER <= kLlErr) \ + if (PRINT_LEVEL_USER <= kLlErr) { \ maple::logInfo.EmitLogForUser(num, kLlErr, fmt, ##__VA_ARGS__); \ + } \ } while (0) #define FATAL(num, fmt, ...) \ do { \ - if (PRINT_LEVEL_USER <= kLlFatal) \ + if (PRINT_LEVEL_USER <= kLlFatal) { \ maple::logInfo.EmitLogForUser(num, kLlFatal, fmt, ##__VA_ARGS__); \ - if (DEBUG_TEST) \ + } \ + if (DEBUG_TEST) { \ abort(); \ - else \ + } else { \ exit(1); \ + } \ } while (0) } // namespace maple #endif // MAPLE_UTIL_INCLUDE_MPL_LOGGING_H diff --git a/src/maple_util/include/option_parser.h b/src/maple_util/include/option_parser.h index dc38c99ce78262afeef57022f8724bff22fd8b03..c54572f35dfb9a0f2c7aa3c79b1b24597b3e39a1 100644 --- a/src/maple_util/include/option_parser.h +++ b/src/maple_util/include/option_parser.h @@ -35,91 +35,61 @@ enum ArgCheckPolicy { }; struct ExtraOption { - /** - * Tool bin name - */ + // Tool bin name const char * const exeName; - /** - * Key mapping with -/-- if needed. - */ + // Key mapping with -/-- if needed. const char * const optionKey; - /** - * Can override the connector defined in Descriptor. - */ + // Can override the connector defined in Descriptor. const char * const connector; - /** - * Can override the delimiter defined in Descriptor - */ + // Can override the delimiter defined in Descriptor const char * const delimiter; }; constexpr static unsigned int kMaxExtraOptions = 10; struct Descriptor { - /** - * Unique option index - */ + // Unique option index const unsigned int index; - /** - * Unique option type - */ + // Unique option type const int type; - /** - * Short form option key - */ + // Short form option key const char * const shortOption; - /** - * Long form option key - */ + // Long form option key const char * const longOption; #ifdef OPTION_PARSER_EXTRAOPT - /** - * Connector followed after key when passing args to target tool. - */ + // Connector followed after key when passing args to target tool. const char * const connector; - /** - * There's default args for the option. - * When user set it again, if true, append to the default args, - * else replace it. - */ + // There's default args for the option. + // When user set it again, if true, append to the default args, + // else replace it. const bool isCanAppend; - /** - * Delimiter when append. - * if isCanAppend is false, it's meaningless. - */ + // Delimiter when append. + // if isCanAppend is false, it's meaningless. const char * const delimiter; #endif - /** - * The option can be seen in which build type. - */ + // The option can be seen in which build type. const BuildType enableBuildType; - /** - * Should we have a parameter? - */ + // Should we have a parameter? const ArgCheckPolicy checkPolicy; - /** - * Help info - */ + // Help info const char * const help; #ifdef OPTION_PARSER_EXTRAOPT const char * const exeName; - /** - * option key mapping to target tool - */ + // option key mapping to target tool const ExtraOption extras[kMaxExtraOptions]; #endif diff --git a/src/mempool/include/maple_string.h b/src/mempool/include/maple_string.h index 2dabb74356fbf51869dc974228985bc7fe193851..d261330493aa406a4b4098a9d715a1aab66cf9a3 100644 --- a/src/mempool/include/maple_string.h +++ b/src/mempool/include/maple_string.h @@ -72,9 +72,7 @@ class MapleString { } MapleString &operator=(const char *str) { - if (str == nullptr) - // If str is nullptr, do nothing - { + if (str == nullptr) { return *this; } size_t size = strlen(str); @@ -151,9 +149,7 @@ class MapleString { } MapleString &operator+=(const char *str) { - if (str == nullptr) - // If str is nullptr, do nothing - { + if (str == nullptr) { return *this; } size_t size = strlen(str); diff --git a/src/mempool/include/mempool_allocator.h b/src/mempool/include/mempool_allocator.h index e34c9c0521d7c7df5ae70a112182bda94efdb10a..a2d5a47afd39889059ad8e3e74e8023afee85ec6 100644 --- a/src/mempool/include/mempool_allocator.h +++ b/src/mempool/include/mempool_allocator.h @@ -67,7 +67,6 @@ class MapleStack { using size_type = typename MapleVector::size_type; using iterator = typename MapleVector::iterator; - public: MapleStack(MapleAllocatorAdapter adapter) : vect(adapter) {} ~MapleStack() = default; diff --git a/src/mpl2mpl/include/class_hierarchy.h b/src/mpl2mpl/include/class_hierarchy.h index 8c347f0b041a08cc3f7160b0ddbcde6c5b42e943..bd280b4d57ba96c3827f599a2b63873301acf28b 100644 --- a/src/mpl2mpl/include/class_hierarchy.h +++ b/src/mpl2mpl/include/class_hierarchy.h @@ -316,7 +316,7 @@ class WKTypes { static MIRType *javalangrefConstructor; }; -/* data structure to represent class information defined in the module */ +// data structure to represent class information defined in the module class KlassHierarchy : public AnalysisResult { public: static bool traceFlag; @@ -339,7 +339,7 @@ class KlassHierarchy : public AnalysisResult { GStrIdx GetLCA(GStrIdx str1, GStrIdx str2) const; const std::string &GetLCA(const std::string &name1, const std::string &name2) const; bool IsSuperKlass(const Klass *super, const Klass *base) const; - bool IsSuperKlassForInterface(const Klass *super, Klass *base) const; + bool IsSuperKlassForInterface(const Klass *super, const Klass *base) const; 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 diff --git a/src/mpl2mpl/include/muid_replacement.h b/src/mpl2mpl/include/muid_replacement.h index bb13143b86eb0b65e15880c0f27198e074794f9b..58ee09c7a711355e8885fb44201efa61af7dd183 100644 --- a/src/mpl2mpl/include/muid_replacement.h +++ b/src/mpl2mpl/include/muid_replacement.h @@ -98,11 +98,6 @@ 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(); @@ -130,25 +125,25 @@ class MUIDReplacement : public FuncOptimizeImpl { void CollectFuncAndDataFromGlobalTab(); void CollectFuncAndDataFromFuncList(); void GenericCompilerVersionNum(); - inline static MIRSymbol *GetSymbolFromName(const std::string &name); + static MIRSymbol *GetSymbolFromName(const std::string &name); // The following sets are for internal uses. Sorting order does not matter here. std::unordered_set funcDefSet; std::unordered_set funcUndefSet; std::unordered_set dataDefSet; std::unordered_set dataUndefSet; - inline void AddDefFunc(MIRFunction *func) { + void AddDefFunc(MIRFunction *func) { funcDefSet.insert(func); } - inline void AddUndefFunc(MIRFunction *func) { + void AddUndefFunc(MIRFunction *func) { funcUndefSet.insert(func); } - inline void AddDefData(MIRSymbol *sym) { + void AddDefData(MIRSymbol *sym) { dataDefSet.insert(sym); } - inline void AddUndefData(MIRSymbol *sym) { + void AddUndefData(MIRSymbol *sym) { dataUndefSet.insert(sym); } diff --git a/src/mpl2mpl/include/native_stub_func.h b/src/mpl2mpl/include/native_stub_func.h index fb421c5b0baf94bace3014d9e181da406e7bd941..6d2a3912b47319cfe91d773cf41a0274ea6711fd 100644 --- a/src/mpl2mpl/include/native_stub_func.h +++ b/src/mpl2mpl/include/native_stub_func.h @@ -86,7 +86,7 @@ class GenericNativeStubFunc : public FuncOptimizeImpl { return (retType == jstrPointerTypeIdx); } void InitStaticBindingMethodList(); - bool IsStaticBindingMethod(const std::string &methodName); + bool IsStaticBindingMethod(const std::string &methodName) const; MIRFunction &GetOrCreateDefaultNativeFunc(MIRFunction &stubFunc); void GenericRegisteredNativeFuncCall(MIRFunction &func, const MIRFunction &nativeFunc, MapleVector &args, const MIRSymbol *ret, bool needNativeCall, CallNode &prevNativeFuncCall, diff --git a/src/mpl2mpl/include/reflection_analysis.h b/src/mpl2mpl/include/reflection_analysis.h index d0ab57a27b63572ed8572c42440a302a97133092..831f78bc77b97dedc47f263ae44d5a8047648352 100644 --- a/src/mpl2mpl/include/reflection_analysis.h +++ b/src/mpl2mpl/include/reflection_analysis.h @@ -316,8 +316,8 @@ class ReflectionAnalysis : public AnalysisResult { void SetAnnoFieldConst(const MIRStructType &metadataRoType, MIRAggConst &newConst, uint32 fieldID, std::map &idxNumMap, const std::string &annoArr); bool IsAnonymousClass(const std::string &annotationString); - bool IsPrivateClass(MIRClassType &classType); - bool IsStaticClass(MIRClassType &classType); + bool IsPrivateClass(MIRClassType &classType) const; + bool IsStaticClass(MIRClassType &classType) const; int8 JudgePara(MIRClassType &ctype); void CheckPrivateInnerAndNoSubClass(Klass &clazz, const std::string &annoArr); void ConvertMapleClassName(const std::string &mplClassName, std::string &javaDsp); diff --git a/src/mpl2mpl/include/vtable_analysis.h b/src/mpl2mpl/include/vtable_analysis.h index dd015136ef5dde2a5c1a059f85982540cbb87de7..08712b2bc25d14ad1292beeb68373ca4ca8218ea 100644 --- a/src/mpl2mpl/include/vtable_analysis.h +++ b/src/mpl2mpl/include/vtable_analysis.h @@ -20,7 +20,7 @@ namespace maple { #ifdef USE_32BIT_REF static constexpr unsigned int kTabEntrySize = 4; -#else //! USE_32BIT_REF +#else // !USE_32BIT_REF static constexpr unsigned int kTabEntrySize = 8; #endif // USE_32BIT_REF diff --git a/src/mpl2mpl/src/class_hierarchy.cpp b/src/mpl2mpl/src/class_hierarchy.cpp index 93dd1f697d1c80d090cbb7e6878cf79b8bddcf68..fc39a7e0a3ee79e62afe85876e91a58ec84e4b41 100644 --- a/src/mpl2mpl/src/class_hierarchy.cpp +++ b/src/mpl2mpl/src/class_hierarchy.cpp @@ -347,20 +347,20 @@ bool KlassHierarchy::IsSuperKlass(const Klass *super, const Klass *base) const { } // Interface -bool KlassHierarchy::IsSuperKlassForInterface(const Klass *super, Klass *base) const { +bool KlassHierarchy::IsSuperKlassForInterface(const Klass *super, const Klass *base) const { if (super == nullptr || base == nullptr) { return false; } if (!super->IsInterface() || !base->IsInterface()) { return false; } - std::vector tmpVector; + std::vector tmpVector; tmpVector.push_back(base); for (size_t idx = 0; idx < tmpVector.size(); idx++) { if (tmpVector[idx] == super) { return true; } - for (Klass *superKlass : tmpVector[idx]->GetSuperKlasses()) { + for (const Klass *superKlass : tmpVector[idx]->GetSuperKlasses()) { tmpVector.push_back(superKlass); } } diff --git a/src/mpl2mpl/src/java_eh_lower.cpp b/src/mpl2mpl/src/java_eh_lower.cpp index b5ae2e1aec2528662c8626f5f05419033669a45e..31e84695f78a6541109f1eae0fbd545f0287b32e 100644 --- a/src/mpl2mpl/src/java_eh_lower.cpp +++ b/src/mpl2mpl/src/java_eh_lower.cpp @@ -210,7 +210,7 @@ BlockNode *JavaEHLowerer::DoLowerBlock(BlockNode &block) { DoLowerBoundaryCheck(*intrinCall, *newBlock); break; } - // fallthrough; + // fallthrough; } default: { for (size_t i = 0; i < stmt->NumOpnds(); i++) { diff --git a/src/mpl2mpl/src/native_stub_func.cpp b/src/mpl2mpl/src/native_stub_func.cpp index 49ef55c4a99f130c823e71bacf0be7eec08b9153..35567ffdcdcbf89458a4ed1969b163c565b157c3 100644 --- a/src/mpl2mpl/src/native_stub_func.cpp +++ b/src/mpl2mpl/src/native_stub_func.cpp @@ -140,11 +140,11 @@ void GenericNativeStubFunc::ProcessFunc(MIRFunction *func) { const size_t funcFormalsSize = func->GetFormalCount(); CHECK_FATAL(funcFormalsSize > 0, "container check"); MIRSymbol *formal0St = func->GetFormal(0); - if (formal0St->GetSKind() == kStPreg) + if (formal0St->GetSKind() == kStPreg) { monitor = builder->CreateExprRegread(formal0St->GetType()->GetPrimType(), func->GetPregTab()->GetPregIdxFromPregno(formal0St->GetPreg()->GetPregNo())); - else { + } else { monitor = builder->CreateExprDread(*formal0St); } } @@ -169,11 +169,11 @@ void GenericNativeStubFunc::ProcessFunc(MIRFunction *func) { } else { // Grab _this pointer MIRSymbol *formal0St = func->GetFormal(0); - if (formal0St->GetSKind() == kStPreg) + if (formal0St->GetSKind() == kStPreg) { callerObj = builder->CreateExprRegread(formal0St->GetType()->GetPrimType(), func->GetPregTab()->GetPregIdxFromPregno(formal0St->GetPreg()->GetPregNo())); - else { + } else { callerObj = builder->CreateExprDread(*formal0St); } } @@ -207,10 +207,10 @@ void GenericNativeStubFunc::ProcessFunc(MIRFunction *func) { for (uint32 i = 0; i < func->GetFormalCount(); i++) { auto argSt = func->GetFormal(i); BaseNode *argExpr = nullptr; - if (argSt->GetSKind() == kStPreg) + if (argSt->GetSKind() == kStPreg) { argExpr = builder->CreateExprRegread(argSt->GetType()->GetPrimType(), func->GetPregTab()->GetPregIdxFromPregno(argSt->GetPreg()->GetPregNo())); - else { + } else { argExpr = builder->CreateExprDread(*argSt); } allocCallArgs.push_back(argExpr); @@ -254,11 +254,11 @@ void GenericNativeStubFunc::ProcessFunc(MIRFunction *func) { } else { // Grab _this pointer MIRSymbol *formal0St = func->GetFormal(0); - if (formal0St->GetSKind() == kStPreg) + if (formal0St->GetSKind() == kStPreg) { monitor = builder->CreateExprRegread(formal0St->GetType()->GetPrimType(), func->GetPregTab()->GetPregIdxFromPregno(formal0St->GetPreg()->GetPregNo())); - else { + } else { monitor = builder->CreateExprDread(*formal0St); } } @@ -661,7 +661,7 @@ void GenericNativeStubFunc::InitStaticBindingMethodList() { } } -bool GenericNativeStubFunc::IsStaticBindingMethod(const std::string &methodName) { +bool GenericNativeStubFunc::IsStaticBindingMethod(const std::string &methodName) const { return (staticBindingMethodsSet.find(NameMangler::NativeJavaName(methodName.c_str())) != staticBindingMethodsSet.end()); } diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index f98746e749a5ec512005828cb4cd872eef365bb5..ad3c881b2bd186ba925e256c14d265d445b472fd 100644 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -207,11 +207,11 @@ uint32 GetClassAccessFlags(MIRClassType &classType) { return 0; } -bool ReflectionAnalysis::IsStaticClass(MIRClassType &classType) { +bool ReflectionAnalysis::IsStaticClass(MIRClassType &classType) const { return GetClassAccessFlags(classType) & 0x00000008; // # Modifier_Static 0x00000008; } -bool ReflectionAnalysis::IsPrivateClass(MIRClassType &classType) { +bool ReflectionAnalysis::IsPrivateClass(MIRClassType &classType) const { return GetClassAccessFlags(classType) & 0x00000002; // # Modifier_Private 0x00000002; }