diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 4648a2ecdc3a48d41a2dcc95231eadae5be84561..3afa3e8786d3b0bb111c0fd480ed71f5a3080481 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 90ab14cab8007777b5eb5280d35c635d8b76cd11..db6799ada744926d1036c08e922d738dbe0ef573 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index 854853dc1f8e27d8c168654fc31a1cfcfa7a09c7..dbe5c974020e89e8671a46d3e2335b17d4ee7c02 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index 974d497c5d03105a7b39502370144ffb77d0f786..627f3c8f7e9c9b2f583ecb0126cd4298d790e259 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_be/include/be/becommon.h b/src/maple_be/include/be/becommon.h index 6fa3d6cb35386153e02a5a0250546006485b5443..0181d849ec419ca115c667dc11ac2c6f1dd068f3 100644 --- a/src/maple_be/include/be/becommon.h +++ b/src/maple_be/include/be/becommon.h @@ -195,7 +195,7 @@ class BECommon { private: bool TyIsInSizeAlignTable(const MIRType&) const; void AddAndComputeSizeAlign(MIRType&); - void ComputeStructTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx, uint8 align = 0); + void ComputeStructTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx); void ComputeClassTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx, uint8 align = 0); void ComputeArrayTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx); void ComputeFArrayOrJArrayTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx); diff --git a/src/maple_be/include/cg/aarch64/aarch64_peep.h b/src/maple_be/include/cg/aarch64/aarch64_peep.h index 3a95dabff1ae1c24ef9d9e6844f10f2ebb6e6ef0..889d1433223b9256aeaa759ab963998bf495ae18 100644 --- a/src/maple_be/include/cg/aarch64/aarch64_peep.h +++ b/src/maple_be/include/cg/aarch64/aarch64_peep.h @@ -178,9 +178,9 @@ class InlineReadBarriersAArch64 : public PeepPattern { * mov w16, #0x588f * movk w16, #0x4f8b, LSL #16 * smull x16, w0, w16 - * lsr x16, x16, #32 + * asr x16, x16, #32 * add x16, x16, w0, SXTW - * lsr x16, x16, #17 + * asr x16, x16, #17 * add x2, x16, x0, LSR #31 */ class ReplaceDivToMultiAArch64 : public PeepPattern { @@ -466,6 +466,7 @@ class ComplexMemOperandLSLAArch64 : public PeepPattern { public: explicit ComplexMemOperandLSLAArch64(CGFunc &cgFunc) : PeepPattern(cgFunc) {} ~ComplexMemOperandLSLAArch64() override = default; + bool CheckShiftValid(AArch64MemOperand &memOpnd, BitShiftOperand &lsl); void Run(BB &bb, Insn &insn) override; }; diff --git a/src/maple_be/src/be/becommon.cpp b/src/maple_be/src/be/becommon.cpp index b7f1973f6c2a35c8b6f442a1d98a64395d544198..5e6932ed845e1130287587e323a2dff7bb344dec 100644 --- a/src/maple_be/src/be/becommon.cpp +++ b/src/maple_be/src/be/becommon.cpp @@ -106,12 +106,17 @@ static void AddPaddingSlot(std::list paddingSlots[], uint32 offset, uint } } -void BECommon::ComputeStructTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx, uint8 align) { +void BECommon::ComputeStructTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx) { auto &structType = static_cast(ty); const FieldVector &fields = structType.GetFields(); uint64 allocedSize = 0; uint64 allocedSizeInBits = 0; SetStructFieldCount(structType.GetTypeIndex(), fields.size()); + if (fields.size() == 0 && mirModule.IsCModule()) { + SetTypeAlign(tyIdx.GetIdx(), 1); + SetTypeSize(tyIdx.GetIdx(), 1); + return; + } for (size_t j = 0; j < fields.size(); ++j) { TyIdx fieldTyIdx = fields[j].second.first; MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); @@ -149,7 +154,7 @@ void BECommon::ComputeStructTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx, uin } SetTypeAlign(tyIdx, std::max(GetTypeAlign(tyIdx), fieldAlign)); } - SetTypeSize(tyIdx, RoundUp(allocedSize, align)); + SetTypeSize(tyIdx, RoundUp(allocedSize, GetTypeAlign(tyIdx.GetIdx()))); } void BECommon::ComputeClassTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx, uint8 align) { @@ -197,6 +202,11 @@ void BECommon::ComputeClassTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx, uint std::list paddingSlots[3]; /* process fields */ AppendStructFieldCount(tyIdx, fields.size()); + if (fields.size() == 0 && mirModule.IsCModule()) { + SetTypeAlign(tyIdx.GetIdx(), 1); + SetTypeSize(tyIdx.GetIdx(), 1); + return; + } for (uint32 j = 0; j < fields.size(); ++j) { TyIdx fieldTyIdx = fields[j].second.first; MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); @@ -305,7 +315,7 @@ void BECommon::ComputeTypeSizesAligns(MIRType &ty, uint8 align) { } case kTypeUnion: case kTypeStruct: { - ComputeStructTypeSizesAligns(ty, tyIdx, align); + ComputeStructTypeSizesAligns(ty, tyIdx); break; } case kTypeInterface: { /* interface shouldn't have instance fields */ diff --git a/src/maple_be/src/be/lower.cpp b/src/maple_be/src/be/lower.cpp index 6de2d313c635e705d488bba74256f784c3780e66..510fff18ebd01b8834b16266553d478b522aadf1 100644 --- a/src/maple_be/src/be/lower.cpp +++ b/src/maple_be/src/be/lower.cpp @@ -263,20 +263,36 @@ BaseNode *CGLowerer::LowerArrayDim(ArrayNode &array, int32 dim) { /* process left dimension index, resNode express the last dim, so dim need sub 2 */ CHECK_FATAL(dim > (std::numeric_limits::min)() + 1, "out of range"); int leftDim = dim - 2; + MIRType *aType = array.GetArrayType(GlobalTables::GetTypeTable()); + MIRArrayType *arrayType = static_cast(aType); for (int i = leftDim; i >= 0; --i) { - BaseNode *mpyNode = nullptr; + BaseNode *mpyNode = mirModule.CurFuncCodeMemPool()->New(OP_mul); BaseNode *item = NodeConvert(array.GetPrimType(), *array.GetDim(mirModule, GlobalTables::GetTypeTable(), dim - 1)); - for (int j = leftDim; j > i; --j) { - BaseNode *mpyNodes = mirModule.CurFuncCodeMemPool()->New(OP_mul); - mpyNodes->SetPrimType(array.GetPrimType()); - mpyNodes->SetOpnd(item, 0); - mpyNodes->SetOpnd(NodeConvert(array.GetPrimType(), *array.GetDim(mirModule, GlobalTables::GetTypeTable(), j)), 1); - item = mpyNodes; + if (mirModule.IsCModule()) { + item = NodeConvert(array.GetPrimType(), *array.GetIndex(i)); + int64 offsetSize = 1; + for (int j = i + 1; j < dim; j++) { + offsetSize *= arrayType->GetSizeArrayItem(j); + } + MIRIntConst *offsetCst = mirModule.CurFuncCodeMemPool()->New( + offsetSize, *GlobalTables::GetTypeTable().GetTypeFromTyIdx(array.GetPrimType())); + BaseNode *eleOffset = mirModule.CurFuncCodeMemPool()->New(offsetCst); + eleOffset->SetPrimType(array.GetPrimType()); + mpyNode->SetPrimType(array.GetPrimType()); + mpyNode->SetOpnd(eleOffset, 0); + mpyNode->SetOpnd(item, 1); + } else { + for (int j = leftDim; j > i; --j) { + BaseNode *mpyNodes = mirModule.CurFuncCodeMemPool()->New(OP_mul); + mpyNodes->SetPrimType(array.GetPrimType()); + mpyNodes->SetOpnd(item, 0); + mpyNodes->SetOpnd(NodeConvert(array.GetPrimType(), *array.GetDim(mirModule, GlobalTables::GetTypeTable(), j)), 1); + item = mpyNodes; + } + mpyNode->SetPrimType(array.GetPrimType()); + mpyNode->SetOpnd(NodeConvert(array.GetPrimType(), *array.GetIndex(i)), 0); + mpyNode->SetOpnd(item, 1); } - mpyNode = mirModule.CurFuncCodeMemPool()->New(OP_mul); - mpyNode->SetPrimType(array.GetPrimType()); - mpyNode->SetOpnd(NodeConvert(array.GetPrimType(), *array.GetIndex(i)), 0); - mpyNode->SetOpnd(item, 1); BaseNode *newResNode = mirModule.CurFuncCodeMemPool()->New(OP_add); newResNode->SetPrimType(array.GetPrimType()); @@ -317,7 +333,7 @@ BaseNode *CGLowerer::LowerArray(ArrayNode &array, const BaseNode &parent) { int32 dim = arrayType->GetDim(); BaseNode *resNode = LowerArrayDim(array, dim); BaseNode *rMul = nullptr; - size_t eSize = GlobalTables::GetTypeTable().GetTypeFromTyIdx(arrayType->GetElemTyIdx())->GetSize(); + size_t eSize = beCommon.GetTypeSize(arrayType->GetElemTyIdx().GetIdx()); Opcode opAdd = OP_add; MIRType &arrayTypes = *GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(array.GetPrimType())); if (resNode->GetOpCode() == OP_constval) { @@ -1205,7 +1221,7 @@ void CGLowerer::LowerEntry(MIRFunction &func) { auto formal = func.GetFormal(i); formals.push_back(formal); } - func.ClearFormals(); + func.ClearArguments(); for (MapleVector::iterator it = formals.begin(); it != formals.end(); ++it) { func.AddArgument(*it); } diff --git a/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 496b78e81e594025806876d38b0bd81223e050bd..6bd0b759985759a80333e7fc44f0953bb3079a1b 100644 --- a/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -1140,21 +1140,21 @@ void AArch64CGFunc::SelectAggIassign(IassignNode &stmt, Operand &AddrOpnd) { lhsType = structType->GetFieldType(stmt.GetFieldID()); lhsOffset = GetBecommon().GetFieldOffset(*structType, stmt.GetFieldID()).first; } else if (lhsType->GetKind() == kTypeArray) { +#if DEBUG MIRArrayType *arrayLhsType = static_cast(lhsType); /* access an array element */ - lhsType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(arrayLhsType->GetElemTyIdx()); -#if DEBUG + MIRType *lhsType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(arrayLhsType->GetElemTyIdx()); MIRTypeKind typeKind = lhsType->GetKind(); ASSERT(((typeKind == kTypeScalar) || (typeKind == kTypeStruct) || (typeKind == kTypeClass) || (typeKind == kTypePointer)), "unexpected array element type in iassign"); #endif } else if (lhsType->GetKind() == kTypeFArray) { +#if DEBUG MIRFarrayType *farrayLhsType = static_cast(lhsType); /* access an array element */ - lhsType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(farrayLhsType->GetElemTyIdx()); -#if DEBUG - MIRTypeKind typeKind = lhsType->GetKind(); + MIRType *lhsElemType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(farrayLhsType->GetElemTyIdx()); + MIRTypeKind typeKind = lhsElemType->GetKind(); ASSERT(((typeKind == kTypeScalar) || (typeKind == kTypeStruct) || (typeKind == kTypeClass) || (typeKind == kTypePointer)), "unexpected array element type in iassign"); diff --git a/src/maple_be/src/cg/aarch64/aarch64_emitter.cpp b/src/maple_be/src/cg/aarch64/aarch64_emitter.cpp index d194bf884db2fb54afe639bf97c132a15bc4a437..17e14810da9c3d09cfb3dffdafff73b17c938c31 100644 --- a/src/maple_be/src/cg/aarch64/aarch64_emitter.cpp +++ b/src/maple_be/src/cg/aarch64/aarch64_emitter.cpp @@ -278,6 +278,11 @@ void AArch64Emitter::Run() { CG *currCG = cgFunc->GetCG(); /* emit header of this function */ Emitter &emitter = *currCG->GetEmitter(); + // insert for __cxx_global_var_init + if (cgFunc->GetName() == "__cxx_global_var_init") { + emitter.Emit("\t.section\t.init_array,\"aw\"\n"); + emitter.Emit("\t.quad\t").Emit(cgFunc->GetName()).Emit("\n"); + } emitter.Emit("\n"); EmitMethodDesc(emitter); /* emit java code to the java section. */ diff --git a/src/maple_be/src/cg/aarch64/aarch64_peep.cpp b/src/maple_be/src/cg/aarch64/aarch64_peep.cpp index b7496cf2b3472a4c16db64748b9de5f2afb80909..458f6cff2a4c4804c759d22d9c7ed5b7714a901c 100644 --- a/src/maple_be/src/cg/aarch64/aarch64_peep.cpp +++ b/src/maple_be/src/cg/aarch64/aarch64_peep.cpp @@ -996,10 +996,10 @@ void ReplaceDivToMultiAArch64::Run(BB &bb, Insn &insn) { cg->BuildInstruction(MOP_xsmullrrr, tempOpnd, sdivOpnd1, tempOpnd); bb.InsertInsnBefore(*prePrevInsn, newSmullInsn); - /* lsr x16, x16, #32 */ + /* asr x16, x16, #32 */ ImmOperand &dstLsrImmHigh = aarch64CGFunc->CreateImmOperand(k32BitSize, k32BitSize, false); Insn &dstLsrInsnHigh = - cg->BuildInstruction(MOP_xlsrrri6, tempOpnd, tempOpnd, dstLsrImmHigh); + cg->BuildInstruction(MOP_xasrrri6, tempOpnd, tempOpnd, dstLsrImmHigh); bb.InsertInsnBefore(*prePrevInsn, dstLsrInsnHigh); /* add x16, x16, w0, SXTW */ @@ -1008,10 +1008,10 @@ void ReplaceDivToMultiAArch64::Run(BB &bb, Insn &insn) { cg->BuildInstruction(MOP_xxwaddrrre, tempOpnd, tempOpnd, sdivOpnd1, sxtw); bb.InsertInsnBefore(*prePrevInsn, addInsn); - /* lsr x16, x16, #17 */ + /* asr x16, x16, #17 */ ImmOperand &dstLsrImmChange = aarch64CGFunc->CreateImmOperand(17, k32BitSize, false); Insn &dstLsrInsnChange = - cg->BuildInstruction(MOP_xlsrrri6, tempOpnd, tempOpnd, dstLsrImmChange); + cg->BuildInstruction(MOP_xasrrri6, tempOpnd, tempOpnd, dstLsrImmChange); bb.InsertInsnBefore(*prePrevInsn, dstLsrInsnChange); /* add x2, x16, x0, LSR #31 */ @@ -2075,6 +2075,21 @@ void ComplexMemOperandPreAddAArch64::Run(BB &bb, Insn &insn) { } } +bool ComplexMemOperandLSLAArch64::CheckShiftValid(AArch64MemOperand &memOpnd, BitShiftOperand &lsl) { + /* check if shift amount is valid */ + uint32 lslAmount = lsl.GetShiftAmount(); + if ((memOpnd.GetSize() == k32BitSize && (lsl.GetShiftAmount() != 0 && lslAmount != 2)) || + (memOpnd.GetSize() == k64BitSize && (lsl.GetShiftAmount() != 0 && lslAmount != 3))) { + return false; + } + + if (memOpnd.GetSize() != (k8BitSize << lslAmount)) { + return false; + } + + return true; +} + void ComplexMemOperandLSLAArch64::Run(BB &bb, Insn &insn) { AArch64CGFunc *aarch64CGFunc = static_cast(&cgFunc); Insn *nextInsn = insn.GetNextMachineInsn(); @@ -2125,12 +2140,9 @@ void ComplexMemOperandLSLAArch64::Run(BB &bb, Insn &insn) { return; } auto &lsl = static_cast(insn.GetOperand(kInsnFourthOpnd)); - /* check if shift amount is valid */ - if ((memOpnd->GetSize() == k32BitSize && (lsl.GetShiftAmount() != 0 && lsl.GetShiftAmount() != 2)) || - (memOpnd->GetSize() == k64BitSize && (lsl.GetShiftAmount() != 0 && lsl.GetShiftAmount() != 3))) { + if (!CheckShiftValid(*memOpnd, lsl)) { return; } - auto &newBaseOpnd = static_cast(insn.GetOperand(kInsnSecondOpnd)); auto &newIndexOpnd = static_cast(insn.GetOperand(kInsnThirdOpnd)); AArch64MemOperand &newMemOpnd = diff --git a/src/maple_be/src/cg/cg_phasemanager.cpp b/src/maple_be/src/cg/cg_phasemanager.cpp index 69e624f7c473590443ff65e7b22241c47fa0a199..0ba991c0594538fa73cbb6be7a543e79d91da82d 100644 --- a/src/maple_be/src/cg/cg_phasemanager.cpp +++ b/src/maple_be/src/cg/cg_phasemanager.cpp @@ -88,9 +88,7 @@ void CgFuncPhaseManager::AddPhases(std::vector &phases) { /* default phase sequence */ ADDPHASE("layoutstackframe"); ADDPHASE("createstartendlabel"); - if (!CLANG) { - ADDPHASE("buildehfunc"); - } + ADDPHASE("buildehfunc"); ADDPHASE("handlefunction"); ADDPHASE("moveargs"); @@ -103,7 +101,7 @@ void CgFuncPhaseManager::AddPhases(std::vector &phases) { if (CGOptions::DoICO()) { ADDPHASE("ico"); } - if (CGOptions::DoCFGO()) { + if (!CLANG && CGOptions::DoCFGO()) { ADDPHASE("cfgo"); } @@ -145,9 +143,7 @@ void CgFuncPhaseManager::AddPhases(std::vector &phases) { ADDPHASE("peephole"); } - if (!CLANG) { - ADDPHASE("gencfi"); - } + ADDPHASE("gencfi"); if (JAVALANG && CGOptions::IsInsertYieldPoint()) { ADDPHASE("yieldpoint"); } diff --git a/src/maple_be/src/cg/cgfunc.cpp b/src/maple_be/src/cg/cgfunc.cpp index ae19c1a2f36b434ef38abcc55a921f8c1be977ef..c58641a92b3c768709168683705107cb4c727311 100644 --- a/src/maple_be/src/cg/cgfunc.cpp +++ b/src/maple_be/src/cg/cgfunc.cpp @@ -852,7 +852,7 @@ void CGFunc::GenerateCfiPrologEpilog() { * always generate ".cfi_personality 155, DW.ref.__mpl_personality_v0" for Java methods. * we depend on this to tell whether it is a java method. */ - if (func.IsJava()) { + if (mirModule.IsJavaModule() && func.IsJava()) { Insn &personality = GetCG()->BuildInstruction(cfi::OP_CFI_personality_symbol, CreateCfiImmOperand(EHFunc::kTypeEncoding, k8BitSize), CreateCfiStrOperand("DW.ref.__mpl_personality_v0")); @@ -943,15 +943,17 @@ void CGFunc::MarkCleanupEntryBB() { #if DEBUG /* Please don't remove me. */ /* Check if all of the cleanup bb is at bottom of the function. */ bool isCleanupArea = true; - FOR_ALL_BB_REV(bb, this) { - if (isCleanupArea) { - ASSERT(bb->IsCleanup(), "CG internal error, cleanup BBs should be at the bottom of the function."); - } else { - ASSERT(!bb->IsCleanup(), "CG internal error, cleanup BBs should be at the bottom of the function."); - } + if (!mirModule.IsCModule()) { + FOR_ALL_BB_REV(bb, this) { + if (isCleanupArea) { + ASSERT(bb->IsCleanup(), "CG internal error, cleanup BBs should be at the bottom of the function."); + } else { + ASSERT(!bb->IsCleanup(), "CG internal error, cleanup BBs should be at the bottom of the function."); + } - if (bb == cleanupEntry) { - isCleanupArea = false; + if (bb == cleanupEntry) { + isCleanupArea = false; + } } } #endif /* DEBUG */ @@ -1051,8 +1053,8 @@ void CGFunc::ProcessExitBBVec() { } Insn *insn = bb->GetFirstInsn(); while (insn != nullptr) { - retBBPart->AppendInsn(*insn); bb->RemoveInsn(*insn); + retBBPart->AppendInsn(*insn); insn = bb->GetFirstInsn(); } bb->PrependBB(*retBBPart); @@ -1066,13 +1068,15 @@ void CGFunc::HandleFunction() { /* select instruction */ GenerateInstruction(); /* merge multi return */ - MergeReturn(); + if (!func.GetModule()->IsCModule()) { + MergeReturn(); + } ASSERT(exitBBVec.size() <= 1, "there are more than one BB_return in func"); ProcessExitBBVec(); if (func.IsJava()) { GenerateCleanupCodeForExtEpilog(*cleanupBB); - } else { + } else if (!func.GetModule()->IsCModule()) { GenerateCleanupCode(*cleanupBB); } GenSaveMethodInfoCode(*firstBB); diff --git a/src/maple_be/src/cg/emit.cpp b/src/maple_be/src/cg/emit.cpp index 262b9397e73ad8caeb3b50a96e155f17c8f832ab..be48740f9bd7488ee8f85d9421c4fc2d59ed0346 100644 --- a/src/maple_be/src/cg/emit.cpp +++ b/src/maple_be/src/cg/emit.cpp @@ -495,6 +495,13 @@ void Emitter::EmitScalarConstant(MIRConst &mirConst, bool newLine, bool flag32) EmitAddressString(symAddrSym->GetName()); break; } + case kConstAddrofFunc: { + MIRAddroffuncConst &funcAddr = static_cast(mirConst); + MIRFunction *func = GlobalTables::GetFunctionTable().GetFuncTable().at(funcAddr.GetValue()); + MIRSymbol *symAddrSym = GlobalTables::GetGsymTable().GetSymbolFromStidx(func->GetStIdx().Idx()); + Emit("\t.quad\t" + symAddrSym->GetName()); + break; + } default: ASSERT(false, "NYI"); break; @@ -1561,6 +1568,9 @@ void Emitter::EmitMetaDataSymbolWithMarkFlag(const std::vector &mirS const std::map &strIdx2Type, const std::string &prefixStr, const std::string §ionName, bool isHotFlag) { + if (cg->GetMIRModule()->IsCModule()) { + return; + } if (mirSymbolVec.empty()) { return; } @@ -2050,7 +2060,9 @@ void Emitter::EmitGlobalVariable() { #if !defined(TARGARM32) /* finally emit __gxx_personality_v0 DW.ref */ - EmitDWRef("__mpl_personality_v0"); + if (!cg->GetMIRModule()->IsCModule()) { + EmitDWRef("__mpl_personality_v0"); + } #endif } void Emitter::EmitAddressString(const std::string &address) { diff --git a/src/maple_driver/include/option_parser.h b/src/maple_driver/include/option_parser.h index bacd68f6f0810c40b28d77eda80b0579e5945bf1..4d77f95437c4cd4cc0d99f31c6b73cd696b57884 100644 --- a/src/maple_driver/include/option_parser.h +++ b/src/maple_driver/include/option_parser.h @@ -25,7 +25,6 @@ namespace mapleOption { class OptionParser { public: OptionParser() = default; - ~OptionParser() = default; void RegisteUsages(const maple::MapleDriverOptionBase &base); diff --git a/src/maple_ipa/include/callgraph.h b/src/maple_ipa/include/callgraph.h index f48142cf750d3e77505a5b72a0a29a8da55ff217..2824957c0b383297d8558d431b6c8da4a24e3316 100644 --- a/src/maple_ipa/include/callgraph.h +++ b/src/maple_ipa/include/callgraph.h @@ -51,8 +51,8 @@ struct Comparator { // Information description of each callsite class CallInfo { public: - CallInfo(CallType type, MIRFunction *call, StmtNode *s, uint32 ld, uint32 stmtId, bool local = false) - : areAllArgsLocal(local), ctype(type), mirFunc(call), callStmt(s), loopDepth(ld), id(stmtId) {} + CallInfo(CallType type, MIRFunction &call, StmtNode *s, uint32 ld, uint32 stmtId, bool local = false) + : areAllArgsLocal(local), ctype(type), mirFunc(&call), callStmt(s), loopDepth(ld), id(stmtId) {} virtual ~CallInfo() {} @@ -106,8 +106,8 @@ class CGNode { --numReferences; } - CGNode(MIRFunction *func, MapleAllocator *allocater, uint32 index) - : alloc(allocater), + CGNode(MIRFunction *func, MapleAllocator &allocater, uint32 index) + : alloc(&allocater), id(index), sccNode(nullptr), mirFunc(func), @@ -307,15 +307,11 @@ using CalleeIt = MapleMap>*, Com class SCCNode { public: - uint32 id; - MapleVector cgNodes; - MapleSet> callerScc; - MapleSet> calleeScc; - SCCNode(uint32 index, MapleAllocator *alloc) + SCCNode(uint32 index, MapleAllocator &alloc) : id(index), - cgNodes(alloc->Adapter()), - callerScc(alloc->Adapter()), - calleeScc(alloc->Adapter()) {} + cgNodes(alloc.Adapter()), + callerScc(alloc.Adapter()), + calleeScc(alloc.Adapter()) {} virtual ~SCCNode() {} @@ -331,10 +327,18 @@ class SCCNode { return cgNodes; } - const MapleSet> &GetCalles() const { + MapleVector &GetCGNodes() { + return cgNodes; + } + + const MapleSet> &GetCalleeScc() const { return calleeScc; } + const MapleSet> &GetCallerScc() const { + return callerScc; + } + bool HasRecursion() const; bool HasSelfRecursion() const; bool HasCaller() const { @@ -344,6 +348,12 @@ class SCCNode { uint32 GetID() const { return id; } + + private: + uint32 id; + MapleVector cgNodes; + MapleSet> callerScc; + MapleSet> calleeScc; }; class CallGraph : public AnalysisResult { @@ -351,6 +361,10 @@ class CallGraph : public AnalysisResult { CallGraph(MIRModule &m, MemPool &memPool, KlassHierarchy &kh, const std::string &fn); ~CallGraph() {} + void InitCallExternal() { + callExternal = cgAlloc.GetMemPool()->New(static_cast(nullptr), cgAlloc, numOfNodes++); + } + CGNode *CallExternal() const { return callExternal; } @@ -413,8 +427,6 @@ class CallGraph : public AnalysisResult { } void DelNode(CGNode &node); - bool debug_flag; - bool debug_scc; void BuildSCC(); void VerifySCC() const; void BuildSCCDFS(CGNode &caller, unsigned int &visitIndex, std::vector &sccNodes, @@ -422,7 +434,13 @@ class CallGraph : public AnalysisResult { std::vector &lowestOrder, std::vector &inStack, std::vector &visitStack); + void SetDebugFlag(bool flag) { + debugFlag = flag; + } + private: + bool debugFlag = false; + bool debugScc = false; MIRModule *mirModule; MapleAllocator cgAlloc; MIRBuilder *mirBuilder; @@ -432,7 +450,7 @@ class CallGraph : public AnalysisResult { KlassHierarchy *klassh; MapleMap nodesMap; MapleVector sccTopologicalVec; - CGNode *callExternal; /* Auxiliary node used in icall/intrinsic call */ + CGNode *callExternal = nullptr; /* Auxiliary node used in icall/intrinsic call */ uint32 numOfNodes; uint32 numOfSccs; std::unordered_set callsiteHash; @@ -440,7 +458,7 @@ class CallGraph : public AnalysisResult { CGNode *GetOrGenCGNode(PUIdx puIdx, bool isVcall = false, bool isIcall = false); CallType GetCallType(Opcode op) const; CallInfo *GenCallInfo(CallType type, MIRFunction *call, StmtNode *s, uint32 loopDepth, uint32 callsiteID) { - return cgAlloc.GetMemPool()->New(type, call, s, loopDepth, callsiteID); + return cgAlloc.GetMemPool()->New(type, *call, s, loopDepth, callsiteID); } void FindRootNodes(); diff --git a/src/maple_ipa/include/retype.h b/src/maple_ipa/include/retype.h index 7533839589c5e448066ef6e8d9edf97519446ba2..456524adcfdc781cc77678c255bf0638f74e6919 100644 --- a/src/maple_ipa/include/retype.h +++ b/src/maple_ipa/include/retype.h @@ -21,20 +21,17 @@ namespace maple { class Retype { public: - MIRModule *mirModule; - MapleAllocator allocator; - MIRBuilder &dexBuilder; - KlassHierarchy *klassh; - - public: - Retype(MIRModule *mod, MemPool *memPool, MIRBuilder &builder, KlassHierarchy *k) - : mirModule(mod), allocator(memPool), dexBuilder(builder), klassh(k) {} + Retype(MIRModule *mod, MemPool *memPool) : mirModule(mod), allocator(memPool) {} virtual ~Retype() {} void ReplaceRetypeExpr(const BaseNode &opnd) const; void RetypeStmt(MIRFunction &func) const; void DoRetype() const; + + private: + MIRModule *mirModule; + MapleAllocator allocator; }; } // namespace maple #endif // MAPLE_IPA_INCLUDE_RETYPE_H diff --git a/src/maple_ipa/src/callgraph.cpp b/src/maple_ipa/src/callgraph.cpp index 57e344af0392abbfde3a2bddbc8568ff66413289..44b9865e705c9413dda19e1aa4567db10b17eea5 100644 --- a/src/maple_ipa/src/callgraph.cpp +++ b/src/maple_ipa/src/callgraph.cpp @@ -73,8 +73,8 @@ const char *CallInfo::GetCallTypeName() const { const char *CallInfo::GetCalleeName() const { if ((ctype >= kCallTypeCall) && (ctype <= kCallTypeInterfaceCall)) { - MIRFunction *mirf = mirFunc; - return mirf->GetName().c_str(); + MIRFunction &mirf = *mirFunc; + return mirf.GetName().c_str(); } else if (ctype == kCallTypeIcall) { return "IcallUnknown"; } else if ((ctype >= kCallTypeIntrinsicCall) && (ctype <= kCallTypeIntrinsicCallWithType)) { @@ -139,7 +139,7 @@ void CGNode::Dump(std::ofstream &fout) const { fout << "\"" << mirFunc->GetName() << "\" -> "; if (func != nullptr) { if (node->GetSCCNode() != nullptr && node->GetSCCNode()->GetCGNodes().size() > 1) { - fout << "\"" << func->GetName() << "\"[label=" << node->GetSCCNode()->id << " color=red];\n"; + fout << "\"" << func->GetName() << "\"[label=" << node->GetSCCNode()->GetID() << " color=red];\n"; } else { fout << "\"" << func->GetName() << "\"[label=" << 0 << " color=blue];\n"; } @@ -242,11 +242,7 @@ CallGraph::CallGraph(MIRModule &m, MemPool &memPool, KlassHierarchy &kh, const s nodesMap(cgAlloc.Adapter()), sccTopologicalVec(cgAlloc.Adapter()), numOfNodes(0), - numOfSccs(0) { - callExternal = cgAlloc.GetMemPool()->New(static_cast(nullptr), &cgAlloc, numOfNodes++); - debug_flag = false; - debug_scc = false; -} + numOfSccs(0) {} CallType CallGraph::GetCallType(Opcode op) const { CallType t = kCallTypeInvalid; @@ -325,7 +321,7 @@ CGNode *CallGraph::GetOrGenCGNode(PUIdx puIdx, bool isVcall, bool isIcall) { CGNode *node = GetCGNode(puIdx); if (node == nullptr) { MIRFunction *mirFunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(puIdx); - node = cgAlloc.GetMemPool()->New(mirFunc, &cgAlloc, numOfNodes++); + node = cgAlloc.GetMemPool()->New(mirFunc, cgAlloc, numOfNodes++); nodesMap.insert(std::make_pair(mirFunc, node)); } if (isVcall && !node->IsVcallCandidatesValid()) { @@ -1339,7 +1335,7 @@ void CallGraph::DumpToFile(bool dumpAll) { void CallGraph::BuildCallGraph() { GenCallGraph(); // Dump callgraph to dot file - if (debug_flag) { + if (debugFlag) { DumpToFile(true); } if (mirModule->firstInline) { @@ -1374,8 +1370,8 @@ void CallGraph::SetCompilationFunclist() const { const MapleVector &sccTopVec = GetSCCTopVec(); for (int i = sccTopVec.size() - 1; i >= 0; i--) { SCCNode *sccNode = sccTopVec[i]; - std::sort(sccNode->cgNodes.begin(), sccNode->cgNodes.end(), CGNodeCompare); - for (auto const kIt : sccNode->cgNodes) { + std::sort(sccNode->GetCGNodes().begin(), sccNode->GetCGNodes().end(), CGNodeCompare); + for (auto const kIt : sccNode->GetCGNodes()) { CGNode *node = kIt; MIRFunction *func = node->GetMIRFunction(); if ((func != nullptr && func->GetBody() && !IsInIPA()) || (func != nullptr && !func->IsNative())) { @@ -1558,7 +1554,7 @@ void CallGraph::BuildSCCDFS(CGNode &caller, uint32 &visitIndex, std::vectorNew(numOfSccs++, &cgAlloc); + SCCNode *sccNode = cgAlloc.GetMemPool()->New(numOfSccs++, cgAlloc); uint32 stackTopId; do { stackTopId = visitStack.back(); @@ -1606,7 +1602,7 @@ void CallGraph::BuildSCC() { for (SCCNode *const &scc : sccNodes) { scc->Verify(); scc->Setup(); // fix caller and callee info. - if (debug_scc && scc->HasRecursion()) { + if (debugScc && scc->HasRecursion()) { scc->Dump(); } } @@ -1624,12 +1620,12 @@ void CallGraph::SCCTopologicalSort(const std::vector &sccNodes) { // Top-down iterates all nodes for (unsigned i = 0; i < sccTopologicalVec.size(); i++) { SCCNode *sccNode = sccTopologicalVec[i]; - for (SCCNode *callee : sccNode->calleeScc) { + for (SCCNode *callee : sccNode->GetCalleeScc()) { if (inQueue.find(callee) == inQueue.end()) { // callee has not been visited bool callerAllVisited = true; // Check whether all callers of the current callee have been visited - for (SCCNode *caller : callee->callerScc) { + for (SCCNode *caller : callee->GetCallerScc()) { if (inQueue.find(caller) == inQueue.end()) { callerAllVisited = false; break; @@ -1686,14 +1682,15 @@ AnalysisResult *DoCallGraph::Run(MIRModule *module, ModuleResultMgr *m) { KlassHierarchy *klassh = static_cast(m->GetAnalysisResult(MoPhase_CHA, module)); CHECK_FATAL(klassh != nullptr, "CHA can't be null"); CallGraph *cg = memPool->New(*module, *memPool, *klassh, module->GetFileName()); - cg->debug_flag = TRACE_PHASE; + cg->InitCallExternal(); + cg->SetDebugFlag(TRACE_PHASE); cg->BuildCallGraph(); m->AddResult(GetPhaseID(), *module, *cg); if (!module->IsInIPA() && module->firstInline) { // do retype MemPool *localMp = memPoolCtrler.NewMemPool(PhaseName()); maple::MIRBuilder dexMirbuilder(module); - Retype retype(module, localMp, dexMirbuilder, klassh); + Retype retype(module, localMp); retype.DoRetype(); memPoolCtrler.DeleteMemPool(localMp); } diff --git a/src/maple_ipa/src/clone.cpp b/src/maple_ipa/src/clone.cpp index 56d1de62b8cd34f490cc9f5610c2f8fcd5e997ba..316b9510242c6e6dcdc5a04fc1f807067e2b8a18 100644 --- a/src/maple_ipa/src/clone.cpp +++ b/src/maple_ipa/src/clone.cpp @@ -45,12 +45,10 @@ std::string ReplaceRetIgnored::GenerateNewBaseName(const MIRFunction &originalFu std::string ReplaceRetIgnored::GenerateNewFullName(const MIRFunction &originalFunc) const { const std::string &oldSignature = originalFunc.GetSignature(); auto retPos = oldSignature.find("_29"); - return std::string(originalFunc.GetBaseClassName()) - .append(NameMangler::kNameSplitterStr) - .append(GenerateNewBaseName(originalFunc)) - .append(NameMangler::kNameSplitterStr) - .append(oldSignature.substr(0, retPos + 3)) - .append("V"); + constexpr auto retPosIndex = 3; + return std::string(originalFunc.GetBaseClassName()).append(NameMangler::kNameSplitterStr). + append(GenerateNewBaseName(originalFunc)).append(NameMangler::kNameSplitterStr). + append(oldSignature.substr(0, retPos + retPosIndex)).append("V"); } MIRSymbol *Clone::CloneLocalSymbol(const MIRSymbol &oldSym, const MIRFunction &newFunc) { diff --git a/src/maple_ir/include/metadata_layout.h b/src/maple_ir/include/metadata_layout.h index a704c581279befc9f37cbb73c718a77b55b97cf2..7c750babfafc66f7a6618f056d9df17400945409 100644 --- a/src/maple_ir/include/metadata_layout.h +++ b/src/maple_ir/include/metadata_layout.h @@ -271,23 +271,23 @@ extern "C" uint8_t classInitProtectRegion[]; // Note there is no state to indicate a class is already initialized. // Any state beyond listed below is treated as initialized. enum ClassInitState { - kClassInitStateMin = 0, - kClassUninitialized = 1, - kClassInitializing = 2, - kClassInitFailed = 3, - kClassInitialized = 4, - kClassInitStateMax = 4, + kClassInitStateMin = 0, + kClassUninitialized = 1, + kClassInitializing = 2, + kClassInitFailed = 3, + kClassInitialized = 4, + kClassInitStateMax = 4, }; enum SEGVAddr { - kSEGVAddrRangeStart = kPageSize + 0, + kSEGVAddrRangeStart = kPageSize + 0, // Note any readable address is treated as Initialized. - kSEGVAddrForClassInitStateMin = kSEGVAddrRangeStart + kClassInitStateMin, + kSEGVAddrForClassInitStateMin = kSEGVAddrRangeStart + kClassInitStateMin, kSEGVAddrForClassUninitialized = kSEGVAddrForClassInitStateMin + kClassUninitialized, - kSEGVAddrForClassInitializing = kSEGVAddrForClassInitStateMin + kClassInitializing, - kSEGVAddrForClassInitFailed = kSEGVAddrForClassInitStateMin + kClassInitFailed, - kSEGVAddrFoClassInitStateMax = kSEGVAddrForClassInitStateMin + kClassInitStateMax, + kSEGVAddrForClassInitializing = kSEGVAddrForClassInitStateMin + kClassInitializing, + kSEGVAddrForClassInitFailed = kSEGVAddrForClassInitStateMin + kClassInitFailed, + kSEGVAddrFoClassInitStateMax = kSEGVAddrForClassInitStateMin + kClassInitStateMax, kSEGVAddrRangeEnd, }; diff --git a/src/maple_ir/include/mir_builder.h b/src/maple_ir/include/mir_builder.h index ec1d39c01f94762d269cc77905ba412fb548a6b9..53e5ccec923ace2aea11d42ec3b99efebb74e4d1 100644 --- a/src/maple_ir/include/mir_builder.h +++ b/src/maple_ir/include/mir_builder.h @@ -297,7 +297,7 @@ class MIRBuilder { MIRModule *mirModule; MapleSet incompleteTypeRefedSet; - // + // std::vector> extraFieldsTuples; unsigned int lineNum = 0; }; diff --git a/src/maple_ir/include/mir_function.h b/src/maple_ir/include/mir_function.h index f150b1a673b3e9dbc1a26543ce507a45ab4df989..b3be8edded0493811d54d46130707e825507f4ed 100644 --- a/src/maple_ir/include/mir_function.h +++ b/src/maple_ir/include/mir_function.h @@ -724,6 +724,12 @@ class MIRFunction { formals.clear(); } + void ClearArguments() { + formals.clear(); + funcType->GetParamTypeList().clear(); + funcType->GetParamAttrsList().clear(); + } + size_t GetSymbolTabSize() const { ASSERT(symTab != nullptr, "symTab is nullptr"); return symTab->GetSymbolTableSize(); diff --git a/src/maple_ir/include/mir_nodes.h b/src/maple_ir/include/mir_nodes.h index 0a58dda4075c496c559b6a7fd141be79c10e9beb..51ffa35e17d319471de39160c16f715b26b9cfc8 100644 --- a/src/maple_ir/include/mir_nodes.h +++ b/src/maple_ir/include/mir_nodes.h @@ -1952,7 +1952,8 @@ class UnaryStmtNode : public StmtNode { this->SetOpnd(rhs, 0); } - BaseNode *Opnd(size_t) const override { + BaseNode *Opnd(size_t i = 0) const override { + (void)i; return uOpnd; } @@ -2349,6 +2350,16 @@ class WhileStmtNode : public UnaryStmtNode { return body; } + BaseNode *Opnd(size_t i = 0) const override { + if (i == 0) { + return UnaryStmtNode::Opnd(); + } else if (i == 1) { + return body; + } + ASSERT(false, "WhileStmtNode has wrong numOpnds field: %u", NumOpnds()); + return nullptr; + } + private: BlockNode *body = nullptr; }; diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index faa9b0aa44b2c87ad3c5cd319633bb55739a8256..2870fb36a925e0ed68c94491faf0fe6940a46110 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -643,7 +643,7 @@ class MIRArrayType : public MIRType { private: TyIdx eTyIdx{ 0 }; uint16 dim = 0; - std::array sizeArray{ 0 }; + std::array sizeArray{ {0} }; }; // flexible array type, must be last field of a top-level struct diff --git a/src/maple_ir/src/mir_const.cpp b/src/maple_ir/src/mir_const.cpp index bba5c5bc9b35ef8e91b1704db6cc719e7d42a0bc..f032343ac3edafa804f22f34056f5877566b08e6 100644 --- a/src/maple_ir/src/mir_const.cpp +++ b/src/maple_ir/src/mir_const.cpp @@ -94,7 +94,7 @@ void MIRAddrofConst::Dump() const { MIRSymbol *sym = GlobalTables::GetGsymTable().GetSymbolFromStidx(stIdx.Idx()); LogInfo::MapleLogger() << " $" << sym->GetName(); if (fldID > 0) { - LogInfo::MapleLogger() << fldID; + LogInfo::MapleLogger() << " " << fldID; } } diff --git a/src/maple_ir/src/parser.cpp b/src/maple_ir/src/parser.cpp index aa382fea18e915f9be3ed1a969024ce37ad50bb0..6388a2bb522844d247e7785b678687280306adfb 100644 --- a/src/maple_ir/src/parser.cpp +++ b/src/maple_ir/src/parser.cpp @@ -847,12 +847,16 @@ bool MIRParser::ParseStructType(TyIdx &styIdx) { } if (styIdx != 0u) { MIRType *prevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(styIdx); - ASSERT(prevType->GetKind() == kTypeStruct || prevType->GetKind() == kTypeStructIncomplete, - "type kind should be consistent."); - if (static_cast(prevType)->IsIncomplete() && !(structType.IsIncomplete())) { - structType.SetNameStrIdx(prevType->GetNameStrIdx()); - structType.SetTypeIndex(styIdx); - GlobalTables::GetTypeTable().SetTypeWithTyIdx(styIdx, *structType.CopyMIRTypeNode()); + if (prevType->GetKind() != kTypeByName) { + ASSERT(prevType->GetKind() == kTypeStruct || prevType->GetKind() == kTypeStructIncomplete, + "type kind should be consistent."); + if (static_cast(prevType)->IsIncomplete() && !(structType.IsIncomplete())) { + structType.SetNameStrIdx(prevType->GetNameStrIdx()); + structType.SetTypeIndex(styIdx); + GlobalTables::GetTypeTable().SetTypeWithTyIdx(styIdx, *structType.CopyMIRTypeNode()); + } + } else { + styIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&structType); } } else { styIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&structType); @@ -876,8 +880,11 @@ bool MIRParser::ParseClassType(TyIdx &styidx) { if (!ParseFields(classType)) { return false; } + MIRType *prevType = nullptr; if (styidx != 0u) { - MIRType *prevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(styidx); + prevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(styidx); + } + if (prevType != nullptr && prevType->GetKind() != kTypeByName) { ASSERT(prevType->GetKind() == kTypeClass || prevType->GetKind() == kTypeClassIncomplete, "type kind should be consistent."); if (static_cast(prevType)->IsIncomplete() && !(classType.IsIncomplete())) { @@ -1512,7 +1519,12 @@ bool MIRParser::ParseTypedef() { return false; } if (prevTyIdx != 0u) { - return true; + MIRType *prevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(prevTyIdx); + MIRType *newType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); + MIRStructType *newStructType = dynamic_cast(newType); + if (prevType->GetKind() != kTypeByName || newStructType == nullptr){ + return true; + } } // for class/interface types, prev_tyidx could also be set during processing // so we check again right before SetGStrIdxToTyIdx diff --git a/src/maple_me/include/bb.h b/src/maple_me/include/bb.h index 00737e7ad65c89176f1530da31daf3880c5ad46f..b68beef87fb836939fab85607a60d91542ab935c 100755 --- a/src/maple_me/include/bb.h +++ b/src/maple_me/include/bb.h @@ -24,6 +24,7 @@ namespace maple { class MeStmt; // circular dependency exists, no other choice class MePhiNode; // circular dependency exists, no other choice +class MeRegPhiNode; // circular dependency exists, no other choice class PiassignMeStmt; // circular dependency exists, no other choice class IRMap; // circular dependency exists, no other choice enum BBKind { diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h index a02804aa84adc0403336dedc34f49ab6ff08c3f4..be0064672b64921381e2f9718c3b3da1d89c23c6 100755 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -198,26 +198,27 @@ class IassignMeStmt; // circular dependency exists, no other choice class ScalarMeExpr : public MeExpr { public: ScalarMeExpr(int32 exprid, OStIdx oidx, uint32 vidx, MeExprOp meop) - : MeExpr(exprid, meop), - ostIdx(oidx), - vstIdx(vidx), - defBy(kDefByNo) { + : MeExpr(exprid, meop), + ostIdx(oidx), + vstIdx(vidx), + defBy(kDefByNo) { def.defStmt = nullptr; } ~ScalarMeExpr() = default; - bool IsIdentical(MeExpr &meexpr) { + bool IsIdentical(MeExpr&) { CHECK_FATAL(false, "ScalarMeExpr::IsIdentical() should not be called"); return true; } + bool IsUseSameSymbol(const MeExpr&) const override; - - void SetDefByStmt(MeStmt &defStmt) override { + + void SetDefByStmt(MeStmt &defStmt) override { defBy = kDefByStmt; def.defStmt = &defStmt; } - + MePhiNode *GetMePhiDef() const { return IsDefByPhi() ? def.defPhi : nullptr; } @@ -225,11 +226,11 @@ class ScalarMeExpr : public MeExpr { bool IsDefByNo() const { return defBy == kDefByNo; } - + bool IsDefByPhi() const { return defBy == kDefByPhi; } - + BB *DefByBB() const; const OStIdx &GetOStIdx() const { @@ -310,12 +311,9 @@ class ScalarMeExpr : public MeExpr { MePhiNode *defPhi; ChiMeNode *defChi; // definition node by Chi MustDefMeNode *defMustDef; // definition by callassigned - } def; + } def; }; - - - // represant dread class VarMeExpr final : public ScalarMeExpr { public: @@ -381,6 +379,7 @@ class VarMeExpr final : public ScalarMeExpr { noDelegateRC = noDelegateRCVal; } + private: bool noDelegateRC = false; // true if this cannot be optimized by delegaterc FieldID fieldID = 0; @@ -413,11 +412,10 @@ class MePhiNode { expr.SetDefPhi(*this); } - bool IsPureLocal(const SSATab &ssaTab, const MIRFunction &mirFunc); void Dump(const IRMap *irMap) const; ScalarMeExpr *GetOpnd(size_t idx) const { - ASSERT(idx < opnds.size(), "out of range in MePhiNode::GetOpnd"); + ASSERT(idx < opnds.size(), "out of range in MeVarPhiNode::GetOpnd"); return opnds.at(idx); } @@ -477,7 +475,7 @@ class MePhiNode { class RegMeExpr : public ScalarMeExpr { public: RegMeExpr(MapleAllocator *alloc, int32 exprid, PregIdx preg, PUIdx pidx, OStIdx oidx, uint32 vidx) - : ScalarMeExpr(exprid, oidx, vidx, kMeOpReg), + : ScalarMeExpr(exprid, oidx, vidx, kMeOpReg), regIdx(preg), puIdx(pidx), phiUseSet(std::less(), alloc->Adapter()) {} @@ -516,71 +514,6 @@ class RegMeExpr : public ScalarMeExpr { MapleSet phiUseSet; // the use set of this reg node, used by preg renamer }; -#if 0 -class MeRegPhiNode { - public: - explicit MeRegPhiNode(MapleAllocator *alloc) - : opnds(kOperandNumBinary, nullptr, alloc->Adapter()) { - opnds.pop_back(); - opnds.pop_back(); - } - - ~MeRegPhiNode() = default; - - void UpdateLHS(RegMeExpr ®) { - lhs = ® - reg.SetDefBy(kDefByPhi); - reg.SetDefPhi(*this); - } - - void Dump(const IRMap *irMap) const; - - RegMeExpr *GetLHS() { - return lhs; - } - - void SetLHS(RegMeExpr *lhsVal) { - lhs = lhsVal; - } - - MapleVector &GetOpnds() { - return opnds; - } - - RegMeExpr *GetOpnd(size_t idx) const { - CHECK_FATAL(idx < opnds.size(), "out of range in MeRegPhiNode::GetOpnd"); - return opnds[idx]; - } - - void SetOpnd(size_t idx, RegMeExpr *opnd) { - CHECK_FATAL(idx < opnds.size(), "out of range in MeRegPhiNode::SetOpnd"); - opnds[idx] = opnd; - } - - void SetIsLive(bool isLiveVal) { - isLive = isLiveVal; - } - - bool GetIsLive() const { - return isLive; - } - - void SetDefBB(BB *defBBVal) { - defBB = defBBVal; - } - - BB *GetDefBB() const { - return defBB; - } - - private: - RegMeExpr *lhs = nullptr; - MapleVector opnds; - bool isLive = true; - BB *defBB = nullptr; // the bb that defines this phi -}; -#endif - class ConstMeExpr : public MeExpr { public: ConstMeExpr(int32 exprID, MIRConst *constValParam) : MeExpr(exprID, kMeOpConst), constVal(constValParam) {} diff --git a/src/maple_me/include/ssa_tab.h b/src/maple_me/include/ssa_tab.h index dc052e65ef4a94bc581e4cc25d301cfb276c4251..e4b71b0412fb099fd938c7bd5e2af5fd32e3d4a5 100644 --- a/src/maple_me/include/ssa_tab.h +++ b/src/maple_me/include/ssa_tab.h @@ -154,7 +154,7 @@ class SSATab : public AnalysisResult { return *(GetStmtsSSAPart().GetAssignedVarOf(stmt)->GetOrigSt()->GetMIRSymbol()); } - bool IsInitVersion(size_t vstIdx, const OStIdx &ostIdx) { + bool IsInitVersion(size_t vstIdx, const OStIdx &ostIdx) const { auto *ost = GetOriginalStFromID(ostIdx); ASSERT(ost != nullptr, "null pointer check"); return ost->GetZeroVersionIndex() == vstIdx; diff --git a/src/maple_me/src/alias_class.cpp b/src/maple_me/src/alias_class.cpp index c8bdbc877bc34976f1fdcec54150c400263807d0..7cd06895d94e1ba5efb7e55cb8f79ff6dd8c1753 100644 --- a/src/maple_me/src/alias_class.cpp +++ b/src/maple_me/src/alias_class.cpp @@ -219,8 +219,9 @@ void AliasClass::ApplyUnionForCopies(StmtNode &stmt) { AliasElem *rhsAliasElem = CreateAliasElemsExpr(*iassignNode.Opnd(1)); AliasElem *lhsAliasElem = FindOrCreateExtraLevAliasElem(*iassignNode.Opnd(0), iassignNode.GetTyIdx(), iassignNode.GetFieldID()); - ASSERT(lhsAliasElem != nullptr, "aliaselem of lhs should not be null"); - ApplyUnionForDassignCopy(*lhsAliasElem, rhsAliasElem, *iassignNode.Opnd(1)); + if (lhsAliasElem != nullptr) { + ApplyUnionForDassignCopy(*lhsAliasElem, rhsAliasElem, *iassignNode.Opnd(1)); + } return; } case OP_throw: { diff --git a/src/maple_me/src/hdse.cpp b/src/maple_me/src/hdse.cpp index bebac82d41f6cf3dc6807fb89d6848e3fc75b5e3..50ec401609de5754b74987e4fa3867f7f66c3e39 100755 --- a/src/maple_me/src/hdse.cpp +++ b/src/maple_me/src/hdse.cpp @@ -520,7 +520,7 @@ void HDSE::DseInit() { continue; } // mark phi nodes dead - for (std::pair phiPair : bb->GetMePhiList()) { + for (const auto &phiPair : bb->GetMePhiList()) { phiPair.second->SetIsLive(false); } diff --git a/src/maple_me/src/irmap.cpp b/src/maple_me/src/irmap.cpp index 92f3b250b206caf83c16659116b2147d1838c37c..daa0c774d3ef728101944edcdea71142e76c7b2d 100755 --- a/src/maple_me/src/irmap.cpp +++ b/src/maple_me/src/irmap.cpp @@ -53,9 +53,10 @@ void IRMap::BuildPhiMeNode(BB &bb) { for (auto &phi : bb.GetPhiList()) { const OriginalSt *oSt = ssaTab.GetOriginalStFromID(phi.first); VersionSt *vSt = phi.second.GetResult(); + auto *phiMeNode = NewInPool(); phiMeNode->SetDefBB(&bb); - + bb.GetMePhiList().insert(std::make_pair(oSt->GetIndex(), phiMeNode)); if (oSt->IsPregOst()) { RegMeExpr *meDef = GetOrCreateRegFromVerSt(*vSt); phiMeNode->UpdateLHS(*meDef); @@ -63,7 +64,6 @@ void IRMap::BuildPhiMeNode(BB &bb) { for (VersionSt *opnd : phi.second.GetPhiOpnds()) { phiMeNode->GetOpnds().push_back(GetOrCreateRegFromVerSt(*opnd)); } - bb.GetMePhiList().insert(std::make_pair(meDef->GetOStIdx(), phiMeNode)); } else { VarMeExpr *meDef = GetOrCreateVarFromVerSt(*vSt); phiMeNode->UpdateLHS(*meDef); @@ -71,7 +71,6 @@ void IRMap::BuildPhiMeNode(BB &bb) { for (VersionSt *opnd : phi.second.GetPhiOpnds()) { phiMeNode->GetOpnds().push_back(GetOrCreateVarFromVerSt(*opnd)); } - bb.GetMePhiList().insert(std::make_pair(meDef->GetOStIdx(), phiMeNode)); } } } @@ -802,9 +801,9 @@ bool IRMap::ReplaceMeExprStmt(MeStmt &meStmt, const MeExpr &meExpr, MeExpr &repe return isReplaced; } -MePhiNode *IRMap::CreateMePhi(ScalarMeExpr &meScalar) { +MePhiNode *IRMap::CreateMePhi(ScalarMeExpr &meExpr) { auto *phiMeVar = NewInPool(); - phiMeVar->UpdateLHS(meScalar); + phiMeVar->UpdateLHS(meExpr); return phiMeVar; } diff --git a/src/maple_me/src/me_abco.cpp b/src/maple_me/src/me_abco.cpp index 8920b772f0d8ae3c10108ceed3caabd731637886..27b87c33317f8b422fc986e9bbec2e3261b8b700 100755 --- a/src/maple_me/src/me_abco.cpp +++ b/src/maple_me/src/me_abco.cpp @@ -635,7 +635,7 @@ void MeABC::BuildPhiInGraph(MePhiNode &phi) { if (lhsExpr != nullptr && IsVirtualVar(*lhsExpr, irMap->GetSSATab())) { return; } - for (ScalarMeExpr *phiRHS : phi.GetOpnds()) { + for (auto *phiRHS : phi.GetOpnds()) { AddUseDef(*phiRHS); } } @@ -824,7 +824,7 @@ MeExpr *MeABC::TryToResolveVar(MeExpr &expr, std::set &visitedPhi, M } visitedPhi.insert(phi); std::set res; - for (ScalarMeExpr *phiOpnd : phi->GetOpnds()) { + for (auto *phiOpnd : phi->GetOpnds()) { MeExpr *tmp = TryToResolveVar(*phiOpnd, visitedPhi, dummyExpr, isConst); if (tmp == nullptr) { return nullptr; @@ -835,7 +835,7 @@ MeExpr *MeABC::TryToResolveVar(MeExpr &expr, std::set &visitedPhi, M } if (res.size() == 1) { return *(res.begin()); - } else if (res.size() == 0) { + } else if (res.empty()) { return &dummyExpr; } } diff --git a/src/maple_me/src/me_cfg.cpp b/src/maple_me/src/me_cfg.cpp index 436815dce10cbe0c40c34e63f716af33155c812f..ffd014f95be7d4f6dac8c3a819d75c66266a5ab9 100755 --- a/src/maple_me/src/me_cfg.cpp +++ b/src/maple_me/src/me_cfg.cpp @@ -561,23 +561,22 @@ void MeCFG::ConvertMePhiList2IdentityAssigns(BB &meBB) const { while (phiIt != meBB.GetMePhiList().end()) { // replace phi with identify assignment as it only has 1 opnd const OriginalSt *ost = func.GetMeSSATab()->GetOriginalStFromID(phiIt->first); - if (ost->GetIndirectLev() == 0) { - MePhiNode *Phi = phiIt->second; - if (ost->IsSymbolOst()) { - auto *dassign = func.GetIRMap()->NewInPool(); - dassign->SetLHS(static_cast(Phi->GetLHS())); - dassign->SetRHS(Phi->GetOpnd(0)); - dassign->SetBB(Phi->GetDefBB()); - dassign->SetIsLive(Phi->GetIsLive()); - meBB.PrependMeStmt(dassign); - } else { - auto *regAss = func.GetIRMap()->New(); - regAss->SetLHS(static_cast(Phi->GetLHS())); - regAss->SetRHS(Phi->GetOpnd(0)); - regAss->SetBB(Phi->GetDefBB()); - regAss->SetIsLive(Phi->GetIsLive()); - meBB.PrependMeStmt(regAss); - } + if (ost->IsSymbolOst() && ost->GetIndirectLev() == 0) { + auto *dassign = func.GetIRMap()->NewInPool(); + MePhiNode *varPhi = phiIt->second; + dassign->SetLHS(static_cast(varPhi->GetLHS())); + dassign->SetRHS(varPhi->GetOpnd(0)); + dassign->SetBB(varPhi->GetDefBB()); + dassign->SetIsLive(varPhi->GetIsLive()); + meBB.PrependMeStmt(dassign); + } else if (ost->IsPregOst()) { + auto *regAss = func.GetIRMap()->New(); + MePhiNode *regPhi = phiIt->second; + regAss->SetLHS(static_cast(regPhi->GetLHS())); + regAss->SetRHS(regPhi->GetOpnd(0)); + regAss->SetBB(regPhi->GetDefBB()); + regAss->SetIsLive(regPhi->GetIsLive()); + meBB.PrependMeStmt(regAss); } ++phiIt; } diff --git a/src/maple_me/src/me_cond_based_opt.cpp b/src/maple_me/src/me_cond_based_opt.cpp index 0ebee48decb6def7c148c4cb4b6bf243304eee57..4f6d46ab6dc53213fdea72f1b5c175c43eecac69 100755 --- a/src/maple_me/src/me_cond_based_opt.cpp +++ b/src/maple_me/src/me_cond_based_opt.cpp @@ -150,7 +150,6 @@ bool MeCondBased::PointerWasDereferencedBefore(const VarMeExpr &var, const Unary // If it sees an iread or iassign whose base is var, then the assertnonnull can be deleted. MeStmt *defMeStmt = nullptr; BB *bbx = var.GetDefByBBMeStmt(*dominance, defMeStmt); - if (bbx == nullptr) { return false; } diff --git a/src/maple_me/src/me_delegate_rc.cpp b/src/maple_me/src/me_delegate_rc.cpp index 417f5d4879f85e4e82554ce1292b7c4aefc38475..d2aea5721adf9c83869c10100b4e19d3784bd85a 100755 --- a/src/maple_me/src/me_delegate_rc.cpp +++ b/src/maple_me/src/me_delegate_rc.cpp @@ -90,7 +90,7 @@ void DelegateRC::SetCantDelegate(const MapleMap &meVarPhiLis if (!mePhi->GetIsLive()) { continue; } - for (ScalarMeExpr *phiOpnd : mePhi->GetOpnds()) { + for (auto *phiOpnd : mePhi->GetOpnds()) { verStCantDelegate[phiOpnd->GetVstIdx()] = true; } } @@ -148,7 +148,7 @@ void DelegateRC::CollectDerefedOrCopied(const MeExpr &expr) { } } else if (baseVar->GetDefBy() == kDefByPhi) { MePhiNode &defPhi = baseVar->GetDefPhi(); - for (ScalarMeExpr *phiOpnd : defPhi.GetOpnds()) { + for (auto *phiOpnd : defPhi.GetOpnds()) { if (phiOpnd->GetDefBy() == kDefByStmt) { MeStmt *defStmt = phiOpnd->GetDefStmt(); if (defStmt->GetOp() == OP_dassign && defStmt->GetRHS() != nullptr && diff --git a/src/maple_me/src/me_inequality_graph.cpp b/src/maple_me/src/me_inequality_graph.cpp index a3e7ccd04669d75c852e2ceebaa229ab86690aa9..6acc998c21fefb0b3ddf34199ea1de151f7bab52 100755 --- a/src/maple_me/src/me_inequality_graph.cpp +++ b/src/maple_me/src/me_inequality_graph.cpp @@ -55,8 +55,7 @@ ESSAPhiNode *InequalityGraph::GetOrCreatePhiNode(MePhiNode &phiNode) { newPhiNode->SetPhiOpnds(phiNode.GetOpnds()); ESSAPhiNode *newPhi = newPhiNode.get(); varNodes[expr->GetExprID()] = std::move(newPhiNode); - for (ScalarMeExpr *phit : phiNode.GetOpnds()) { - VarMeExpr *phiRHS = static_cast(phit); + for (auto *phiRHS : phiNode.GetOpnds()) { ESSABaseNode *rhs = nullptr; if (phiRHS->GetDefBy() != kDefByPhi) { rhs = GetOrCreateVarNode(*phiRHS); diff --git a/src/maple_me/src/me_ir.cpp b/src/maple_me/src/me_ir.cpp index 4951c7553d93adfdaa3c5759c56769e494368416..07c0eb16ac57971f9788c42b94864cbb55548b50 100755 --- a/src/maple_me/src/me_ir.cpp +++ b/src/maple_me/src/me_ir.cpp @@ -135,7 +135,6 @@ bool RegMeExpr::IsSameVariableValue(const VarMeExpr &expr) const { VarMeExpr &VarMeExpr::ResolveVarMeValue(SSATab &ssaTab) { VarMeExpr *cmpop0 = this; while (true) { - if (cmpop0->GetDefBy() != kDefByStmt || cmpop0->IsVolatile(ssaTab)) { break; } @@ -201,8 +200,8 @@ RegMeExpr *RegMeExpr::FindDefByStmt(std::set &visited) { } if (GetDefBy() == kDefByPhi) { MePhiNode &phiReg = GetDefPhi(); - for (ScalarMeExpr *phiOpnd : phiReg.GetOpnds()) { - RegMeExpr *res = static_cast(phiOpnd)->FindDefByStmt(visited); + for (auto *phiOpnd : phiReg.GetOpnds()) { + auto *res = static_cast(phiOpnd)->FindDefByStmt(visited); if (res != nullptr) { return res; } @@ -456,12 +455,11 @@ MeExpr *IvarMeExpr::GetIdenticalExpr(MeExpr &expr, bool inConstructor) const { } bool ScalarMeExpr::IsUseSameSymbol(const MeExpr &expr) const { - if (expr.GetMeOp() == kMeOpVar || expr.GetMeOp() == kMeOpReg ) { - auto &scalarMeExpr = static_cast(expr); - return ostIdx == scalarMeExpr.ostIdx; - } else { + if (expr.GetMeOp() != GetMeOp()) { return false; } + auto &scalarMeExpr = static_cast(expr); + return ostIdx == scalarMeExpr.ostIdx; } BB *ScalarMeExpr::DefByBB() const{ @@ -485,7 +483,7 @@ BB *ScalarMeExpr::DefByBB() const{ return def.defMustDef->GetBase()->GetBB(); } default: - ASSERT(false, "scalar define unknown"); + ASSERT(false, "ScalarMeExpr define unknown"); return nullptr; } } @@ -493,41 +491,40 @@ BB *ScalarMeExpr::DefByBB() const{ BB *ScalarMeExpr::GetDefByBBMeStmt(const Dominance &dominance, MeStmtPtr &defMeStmt) const { switch (defBy) { case kDefByNo: - return nullptr; + return &dominance.GetCommonEntryBB(); case kDefByStmt: - ASSERT(def.defStmt, "VarMeExpr::DefByBB: defStmt cannot be nullptr"); - defMeStmt = def.defStmt; + ASSERT(def.defStmt, "ScalarMeExpr::DefByBB: defStmt cannot be nullptr"); + defMeStmt = def.defStmt; return def.defStmt->GetBB(); case kDefByPhi: - ASSERT(def.defPhi, "VarMeExpr::DefByBB: defPhi cannot be nullptr"); + ASSERT(def.defPhi, "ScalarMeExpr::DefByBB: defPhi cannot be nullptr"); return def.defPhi->GetDefBB(); case kDefByChi: { - ASSERT(def.defChi, "VarMeExpr::DefByBB: defChi cannot be nullptr"); - ASSERT(def.defChi->GetBase(), "VarMeExpr::DefByBB: defChi->base cannot be nullptr"); - defMeStmt = def.defChi->GetBase(); + ASSERT(def.defChi, "ScalarMeExpr::DefByBB: defChi cannot be nullptr"); + ASSERT(def.defChi->GetBase(), "ScalarMeExpr::DefByBB: defChi->base cannot be nullptr"); + defMeStmt = GetDefChi().GetBase(); return def.defChi->GetBase()->GetBB(); } case kDefByMustDef: { - ASSERT(def.defMustDef, "VarMeExpr::DefByBB: defMustDef cannot be nullptr"); - ASSERT(def.defMustDef->GetBase(), "VarMeExpr::DefByBB: defMustDef->base cannot be nullptr"); - defMeStmt = def.defMustDef->GetBase(); + ASSERT(def.defMustDef, "ScalarMeExpr::DefByBB: defMustDef cannot be nullptr"); + ASSERT(def.defMustDef->GetBase(), "ScalarMeExpr::DefByBB: defMustDef->base cannot be nullptr"); + defMeStmt = def.defMustDef->GetBase(); return def.defMustDef->GetBase()->GetBB(); } default: - ASSERT(false, "var define unknown"); + ASSERT(false, "ScalarMeExpr define unknown"); return nullptr; } } -bool VarMeExpr::IsPureLocal(const SSATab &tab, const MIRFunction &irFunc) const { - const MIRSymbol *st = tab.GetMIRSymbolFromID(GetOStIdx()); +bool VarMeExpr::IsPureLocal(const SSATab &ssaTab, const MIRFunction &irFunc) const { + const MIRSymbol *st = ssaTab.GetMIRSymbolFromID(GetOStIdx()); return st->IsLocal() && !irFunc.IsAFormal(st); } -bool VarMeExpr::IsZeroVersion(const SSATab &ssatab) const { +bool VarMeExpr::IsZeroVersion(const SSATab &ssaTab) const { ASSERT(GetVstIdx() != 0, "VarMeExpr::IsZeroVersion: cannot determine because vstIdx is 0"); - const OriginalSt *ost = ssatab.GetOriginalStFromID(GetOStIdx()); - return ost->GetZeroVersionIndex() == GetVstIdx(); + return ssaTab.IsInitVersion(GetVstIdx(), GetOstIdx()); } bool AddrofMeExpr::IsUseSameSymbol(const MeExpr &expr) const { @@ -730,15 +727,15 @@ MeExpr *AddroffuncMeExpr::GetIdenticalExpr(MeExpr &expr, bool isConstructor) con void MePhiNode::Dump(const IRMap *irMap) const { const OriginalSt *ost = irMap->GetSSATab().GetOriginalStFromID(lhs->GetOStIdx()); bool isSym = ost->IsSymbolOst(); - CHECK_FATAL(lhs != nullptr, "lsh is null"); - if (isSym) { + CHECK_FATAL(lhs != nullptr, "lsh is null"); + if (isSym) { if (isPiAdded) { LogInfo::MapleLogger() << "PI_ADD VAR:"; } LogInfo::MapleLogger() << "VAR:"; irMap->GetSSATab().GetOriginalStFromID(lhs->GetOStIdx())->Dump(); } else { - PregIdx16 regId = static_cast(lhs)->GetRegIdx(); + PregIdx16 regId = static_cast(lhs)->GetRegIdx(); LogInfo::MapleLogger() << "REGVAR: " << regId; LogInfo::MapleLogger() << "(%" << irMap->GetMIRModule().CurFunction() @@ -765,7 +762,7 @@ void MePhiNode::Dump(const IRMap *irMap) const { void VarMeExpr::Dump(const IRMap *irMap, int32) const { CHECK_NULL_FATAL(irMap); LogInfo::MapleLogger() << "VAR "; - irMap->GetSSATab().GetOriginalStFromID(GetOStIdx())->Dump(); + irMap->GetSSATab().GetOriginalStFromID(GetOstIdx())->Dump(); LogInfo::MapleLogger() << " (field)" << fieldID; LogInfo::MapleLogger() << " mx" << GetExprID(); if (IsZeroVersion(irMap->GetSSATab())) { @@ -1348,7 +1345,7 @@ void AssertMeStmt::Dump(const IRMap *irMap) const { } bool VarMeExpr::IsVolatile(const SSATab &ssatab) const { - const OriginalSt *ost = ssatab.GetOriginalStFromID(GetOStIdx()); + const OriginalSt *ost = ssatab.GetOriginalStFromID(GetOstIdx()); if (!ost->IsSymbolOst()) { return false; } @@ -1446,7 +1443,7 @@ MapleMap *GenericGetChiListFromVarMeExprInner(VarMeExpr &exp MePhiNode &phiMe = expr.GetDefPhi(); MapleVector &phiOpnds = phiMe.GetOpnds(); for (auto it = phiOpnds.begin(); it != phiOpnds.end(); ++it) { - VarMeExpr *meExpr = static_cast(*it); + auto *meExpr = static_cast(*it); MapleMap *chiList = GenericGetChiListFromVarMeExprInner(*meExpr, visited); if (chiList != nullptr) { return chiList; diff --git a/src/maple_me/src/me_rename2preg.cpp b/src/maple_me/src/me_rename2preg.cpp index 2e00c77152ca444bc26ec9f84a34835d743b9a0b..5867539c8c4860d2aaeaeb30cd162fe185f95ba7 100755 --- a/src/maple_me/src/me_rename2preg.cpp +++ b/src/maple_me/src/me_rename2preg.cpp @@ -330,7 +330,7 @@ class SSARename2Preg { if (lhs == nullptr) { return; } - + VarMeExpr &varExpr =(utils::ToRef(lhs)); RegMeExpr *pRegExpr = RenameVar(aliasClass, varExpr); if (pRegExpr == nullptr) { @@ -347,7 +347,7 @@ class SSARename2Preg { MePhiNode ®PhiNode) const { PregCache &pregCache = cacheProxy.Preg(); for (ScalarMeExpr *phiOpnd : phiNodeOpnds) { - const VarMeExpr&varExpr = utils::ToRef(static_cast(phiOpnd)); + const VarMeExpr &varExpr = utils::ToRef(static_cast(phiOpnd)); RegMeExpr ®Expr = pregCache.CloneRegExprIfNotExist(varExpr, [&curRegExpr](MeIRMap &irMap) { return irMap.CreateRegMeExprVersion(curRegExpr); }); diff --git a/src/maple_me/src/preg_renamer.cpp b/src/maple_me/src/preg_renamer.cpp index 412f975c00c873850832053619518ccc7375ce99..33bf57f33d5aa9b0145ac470fcebecee552ece78 100755 --- a/src/maple_me/src/preg_renamer.cpp +++ b/src/maple_me/src/preg_renamer.cpp @@ -24,7 +24,7 @@ void PregRenamer::EnqueDefUses(std::list &qu, RegMeExpr *node, std:: if (node->GetDefBy() == kDefByPhi) { MePhiNode &defPhi = node->GetDefPhi(); for (auto it : defPhi.GetOpnds()) { - RegMeExpr *neibNode = static_cast(it); // node's connected register node + RegMeExpr *neibNode = static_cast(it); // node's connected register node if (neibNode != node && curVisited.find(neibNode) == curVisited.end()) { qu.push_back(neibNode); (void)curVisited.insert(neibNode); @@ -35,13 +35,13 @@ void PregRenamer::EnqueDefUses(std::list &qu, RegMeExpr *node, std:: MapleSet &phiUseSet = node->GetPhiUseSet(); for (auto setIt : phiUseSet) { MePhiNode *meRegPhi = setIt; - RegMeExpr *lhsReg = static_cast(meRegPhi->GetLHS()); + RegMeExpr *lhsReg = static_cast(meRegPhi->GetLHS()); if (lhsReg != node && curVisited.find(lhsReg) == curVisited.end()) { qu.push_back(lhsReg); (void)curVisited.insert(lhsReg); } for (auto opdIt : meRegPhi->GetOpnds()) { - RegMeExpr *opndReg = static_cast(opdIt); + RegMeExpr *opndReg = static_cast(opdIt); if (opndReg != node && curVisited.find(opndReg) == curVisited.end()) { qu.push_back(opndReg); (void)curVisited.insert(opndReg); diff --git a/src/maple_me/src/ssa_devirtual.cpp b/src/maple_me/src/ssa_devirtual.cpp index 8ead4b7d6f77451871862b379d8ae3898049570b..f6e02438062227a88f8da262a4c17f08a03f7a8f 100755 --- a/src/maple_me/src/ssa_devirtual.cpp +++ b/src/maple_me/src/ssa_devirtual.cpp @@ -332,15 +332,16 @@ void SSADevirtual::PropIvarInferredType(IvarMeExpr &ivar) const { void SSADevirtual::VisitVarPhiNode(MePhiNode &varPhi) const { MapleVector opnds = varPhi.GetOpnds(); - auto *phiLhs = varPhi.GetLHS(); + auto *lhs = varPhi.GetLHS(); // RegPhiNode cases NYI - if (phiLhs == nullptr || phiLhs->GetMeOp() != kMeOpVar) - return; + if (lhs == nullptr || lhs->GetMeOp() != kMeOpVar) { + return; + } + VarMeExpr *lhsVar = static_cast(varPhi.GetLHS()); - auto *lhs = static_cast(phiLhs); - const MapleVector &inferredTypeCandidates = lhs->GetInferredTypeCandidates(); + const MapleVector &inferredTypeCandidates = lhsVar->GetInferredTypeCandidates(); for (size_t i = 0; i < opnds.size(); ++i) { - VarMeExpr *opnd = static_cast(opnds[i]); + VarMeExpr *opnd = static_cast(opnds[i]); PropVarInferredType(*opnd); if (opnd->GetInferredTyIdx() != 0u) { size_t j = 0; @@ -350,10 +351,10 @@ void SSADevirtual::VisitVarPhiNode(MePhiNode &varPhi) const { } } if (j == inferredTypeCandidates.size()) { - lhs->AddInferredTypeCandidate(opnd->GetInferredTyIdx()); + lhsVar->AddInferredTypeCandidate(opnd->GetInferredTyIdx()); } } else { - lhs->ClearInferredTypeCandidates(); + lhsVar->ClearInferredTypeCandidates(); break; } } @@ -608,6 +609,9 @@ void SSADevirtual::TraversalBB(BB *bb) { MapleMap &mePhiList = bb->GetMePhiList(); for (auto it = mePhiList.begin(); it != mePhiList.end(); ++it) { MePhiNode *phiMeNode = it->second; + if (phiMeNode == nullptr || phiMeNode->GetLHS()->GetMeOp() != kMeOpVar) { + continue; + } VisitVarPhiNode(*phiMeNode); } // traversal reg phi nodes (NYI) diff --git a/src/maple_me/src/ssa_pre.cpp b/src/maple_me/src/ssa_pre.cpp index d12d18c4eccf56ef2f5b43df8fe7897176eba809..efef5fc6378eaabedac92a539a21e10ca914c511 100755 --- a/src/maple_me/src/ssa_pre.cpp +++ b/src/maple_me/src/ssa_pre.cpp @@ -148,7 +148,7 @@ void SSAPre::GenerateSavePhiOcc(MePhiOcc &phiOcc) { CHECK_NULL_FATAL(regOrVar); MePhiNode *phiNode = irMap->CreateMePhi(static_cast(*regOrVar)); phiNode->SetDefBB(phiOcc.GetBB()); - + if (instance_of(regOrVar)) { // create a reg phi phiOcc.SetRegPhi(*phiNode); @@ -968,7 +968,7 @@ void SSAPre::SetVarPhis(const MeExpr &meExpr) { MePhiNode *phiMeNode = static_cast(&meExpr)->GetMePhiDef(); if (phiMeNode != nullptr) { BBId defBBId = phiMeNode->GetDefBB()->GetBBId(); - CHECK(defBBId < dom->GetDtDfnSize(), "defBBId.idx out of range in SSAPre::SetVarPhis"); + CHECK(defBBId < dom->GetDtDfnSize(), "defBBId.idx out of range in SSAPre::SetVarPhis"); if (varPhiDfns.find(dom->GetDtDfnItem(defBBId)) == varPhiDfns.end() && ScreenPhiBB(defBBId)) { (void)varPhiDfns.insert(dom->GetDtDfnItem(defBBId)); for (auto opndIt = phiMeNode->GetOpnds().begin(); opndIt != phiMeNode->GetOpnds().end(); ++opndIt) { diff --git a/src/maple_phase/include/phase_impl.h b/src/maple_phase/include/phase_impl.h index 131f81815409ad8b4a9fca1e9e689a59cdedefca..2c324b095ede6372aa35e5552d9df159000e2ca9 100644 --- a/src/maple_phase/include/phase_impl.h +++ b/src/maple_phase/include/phase_impl.h @@ -70,7 +70,7 @@ class FuncOptimizeIterator { #define OPT_TEMPLATE(OPT_NAME) \ auto *kh = static_cast(mrm->GetAnalysisResult(MoPhase_CHA, mod)); \ ASSERT_NOT_NULL(kh); \ - FuncOptimizeIterator opt(PhaseName(), new OPT_NAME(*mod, kh, TRACE_PHASE)); \ + FuncOptimizeIterator opt(PhaseName(), new OPT_NAME(*mod, kh, TRACE_PHASE)); \ opt.Run(); } // namespace maple #endif // MAPLE_PHASE_INCLUDE_PHASE_IMPL_H diff --git a/src/maple_phase/include/phase_manager.h b/src/maple_phase/include/phase_manager.h index ae511f6526ce4007756428e9493f095824094d26..e7302c2b57fb04370a7f221c393b94b12eb7099d 100644 --- a/src/maple_phase/include/phase_manager.h +++ b/src/maple_phase/include/phase_manager.h @@ -30,15 +30,15 @@ class PhaseManager { virtual ~PhaseManager() = default; - void AddPhase(const std::string &pname) { + void AddPhase(const std::string &paseName) { for (auto it = RegPhaseBegin(); it != RegPhaseEnd(); ++it) { - if (GetPhaseName(it) == pname) { + if (GetPhaseName(it) == paseName) { phaseSequences.push_back(GetPhaseId(it)); phaseTimers.push_back(0); return; } } - CHECK_FATAL(false, "%s is not a valid phase name", pname.c_str()); + CHECK_FATAL(false, "%s is not a valid phase name", paseName.c_str()); } void RegisterPhase(PhaseID id, Phase &p) { @@ -116,7 +116,7 @@ class PhaseManager { return phaseSequences.end(); } - PhaseID GetPhaseId(PhaseSeqIterator it) const { + PhaseID GetPhaseId(const PhaseSeqIterator &it) const { return (*it); } @@ -138,9 +138,10 @@ class PhaseManager { ASSERT(total != 0, "calculation check"); ASSERT(registeredPhases[phaseSequences[i]] != nullptr, "Phase null ptr check"); std::ios::fmtflags f(LogInfo::MapleLogger().flags()); - LogInfo::MapleLogger() << std::left << std::setw(25) << registeredPhases[phaseSequences[i]]->PhaseName() << - std::setw(10) << std::right << std::fixed << std::setprecision(2) << (100.0 * phaseTimers[i] / total) << - "%" << std::setw(10) << std::setprecision(0) << (phaseTimers[i] / 1000.0) << "ms" << '\n'; + LogInfo::MapleLogger() << std::left << std::setw(25) << + registeredPhases[phaseSequences[i]]->PhaseName() << std::setw(10) << std::right << std::fixed << + std::setprecision(2) << (100.0 * phaseTimers[i] / total) << "%" << std::setw(10) << + std::setprecision(0) << (phaseTimers[i] / 1000.0) << "ms" << '\n'; LogInfo::MapleLogger().flags(f); } return total; diff --git a/src/maple_util/include/mpl_number.h b/src/maple_util/include/mpl_number.h index 377f1011396991e983aeeba510ed975a2d85f14e..67f0deed3ac79ef8a335bc8933c18fb32c3861f1 100644 --- a/src/maple_util/include/mpl_number.h +++ b/src/maple_util/include/mpl_number.h @@ -45,14 +45,14 @@ class Number { Number &operator=(ElementType data) = delete; Number &operator=(const Number &num) noexcept { - if (this != &num) { + if (&num != this) { val = num.val; } return *this; } Number &operator=(Number &&num) noexcept { - if (this != &num) { + if (&num != this) { val = std::move(num.val); } return *this; diff --git a/src/maple_util/include/mpl_scheduler.h b/src/maple_util/include/mpl_scheduler.h index 55d66a0462ed1035ddd75ad49cfafbaa0c24932e..a38af23f6dba0f8b9a3c9732755503b738811152 100644 --- a/src/maple_util/include/mpl_scheduler.h +++ b/src/maple_util/include/mpl_scheduler.h @@ -83,6 +83,7 @@ class MplScheduler { explicit MplScheduler(const std::string &name); virtual ~MplScheduler() {} + void Init(); virtual void AddTask(MplTask *task); virtual int RunTask(uint32 threadsNum, bool seq = false); virtual MplSchedulerParam *EncodeThreadMainEnvironment(uint32) { diff --git a/src/maple_util/include/profile.h b/src/maple_util/include/profile.h index 385250771a0d7b10ccc66ce8aa7288d74dce9660..dd2515748da286dd0586f20c12617764d0fa787b 100644 --- a/src/maple_util/include/profile.h +++ b/src/maple_util/include/profile.h @@ -46,7 +46,7 @@ class Profile { BBInfo() = default; BBInfo(uint64 hash, uint32 num, std::vector &&counter) : funcHash(hash), totalCounter(num), counter(counter) {} - BBInfo(uint64 hash, uint32 num, std::initializer_list iList) + BBInfo(uint64 hash, uint32 num, const std::initializer_list &iList) : funcHash(hash), totalCounter(num), counter(iList) {} }; diff --git a/src/maple_util/include/ptr.h b/src/maple_util/include/ptr.h index 0094fc74d4349f1c3900de9809242a6c3f3a4117..295b17e6e51389e5ba9ae76ec74ac8195200f9ce 100644 --- a/src/maple_util/include/ptr.h +++ b/src/maple_util/include/ptr.h @@ -135,7 +135,7 @@ class Ptr { } Ptr &operator=(Ptr &&ptr) noexcept { - if (this != &ptr) { + if (&ptr != this) { pointer = std::move(ptr.pointer); } return *this; diff --git a/src/maple_util/include/safe_cast.h b/src/maple_util/include/safe_cast.h index abf94f12052267f58f8c0bde0e2538316982fbdc..bcebd323efa0231673b4c3652e082644c7810358 100644 --- a/src/maple_util/include/safe_cast.h +++ b/src/maple_util/include/safe_cast.h @@ -46,8 +46,7 @@ struct InstanceOfImpl -struct EnabledSafeCast - : utils::meta_or, SafeCastCondition>::type {}; +struct EnabledSafeCast : utils::meta_or, SafeCastCondition>::type {}; } template ConstantFold::FoldIread(IreadNode *node) { if (msyType->GetKind() == kTypeStruct || msyType->GetKind() == kTypeClass) { FieldID newFieldId = fieldID + addrofNode->GetFieldID(); MIRStructType *stty = static_cast(msyType); - MIRType *fieldTy = stty->GetFieldType(newFieldId); + // 0 for type itself + MIRType *fieldTy = newFieldId == 0 ? stty : stty->GetFieldType(newFieldId); result = mirModule->CurFuncCodeMemPool()->New(OP_dread, fieldTy->GetPrimType(), addrofNode->GetStIdx(), newFieldId); diff --git a/src/mpl2mpl/src/reflection_analysis.cpp b/src/mpl2mpl/src/reflection_analysis.cpp index 40a743a0e4d3e2edcc09aff2eb40db90a7ba2474..cd12ade232d1cd01f6e91074a557090678b2c079 100755 --- a/src/mpl2mpl/src/reflection_analysis.cpp +++ b/src/mpl2mpl/src/reflection_analysis.cpp @@ -58,6 +58,7 @@ constexpr int kModifierRCUnowned = 24; // 0x00800000 constexpr int kModifierRCWeak = 25; // 0x01000000 constexpr int kModifierHiddenApiGrey = 26; // 0x02000000 constexpr int kModifierHiddenApiBlack = 27; // 0x04000000 +constexpr int kModifierAFOriginPublic = 28; // 0x08000000 // +1 is needed here because our field id starts with 0 pointing to the struct itself constexpr uint32 kObjKlassFieldID = static_cast(ClassProperty::kShadow) + 1; @@ -322,6 +323,14 @@ uint32 GetFieldModifier(const FieldAttrs &fa) { } uint32 GetClassAccessFlags(const MIRStructType &classType) { + uint32 originAF = 0; + size_t size = classType.GetInfo().size(); + for (size_t i = 0; i < size; ++i) { + if (GlobalTables::GetStrTable().GetStringFromStrIdx(classType.GetInfoElemt(i).first) == kINFOAccessFlags) { + originAF = classType.GetInfoElemt(i).second; + } + } + int32 accessFlag = 0; for (const MIRPragma *prag : classType.GetPragmaVec()) { if (prag->GetKind() == kPragmaClass) { @@ -330,18 +339,13 @@ uint32 GetClassAccessFlags(const MIRStructType &classType) { const std::string &name = GlobalTables::GetStrTable().GetStringFromStrIdx(elem->GetNameStrIdx()); if (name == kAccessFlags) { accessFlag = elem->GetI32Val(); + accessFlag |= (originAF & kModPublic) << (kModifierAFOriginPublic - 1); return static_cast(accessFlag); } } } } - size_t size = classType.GetInfo().size(); - for (size_t i = 0; i < size; ++i) { - if (GlobalTables::GetStrTable().GetStringFromStrIdx(classType.GetInfoElemt(i).first) == kINFOAccessFlags) { - return classType.GetInfoElemt(i).second; - } - } - return 0; + return originAF; } bool ReflectionAnalysis::IsStaticClass(const MIRStructType &classType) const {