diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 987e803daa6887157a3cb72c75a45b40439d0d4f..4648a2ecdc3a48d41a2dcc95231eadae5be84561 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 368895a8fdb51d5a134967b87917e07a11b3c753..90ab14cab8007777b5eb5280d35c635d8b76cd11 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmempool.a b/src/deplibs/libmempool.a index 29f0ae940ee9106b52e72e9c7db0436de9b29540..f21d024ae004a397bb7b63b60f46934352a697b1 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 d98a9bb6defcfa1ed8d7cda606caec939ec40bf7..854853dc1f8e27d8c168654fc31a1cfcfa7a09c7 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 9fd0079a236a7ae934f7cf345654c9251d325bcd..974d497c5d03105a7b39502370144ffb77d0f786 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h b/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h index 319bfa89892a5cecbf51af21dd542734b4451689..84aaf981c8bba37e81908354d64e10b43b36a337 100644 --- a/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h +++ b/src/maple_be/include/cg/aarch64/aarch64_cgfunc.h @@ -231,6 +231,9 @@ class AArch64CGFunc : public CGFunc { return GetOrCreateFpZeroOperand(GetPrimTypeBitSize(ptyp)); } + const Operand *GetFloatRflag() const override { + return nullptr; + } /* create an integer immediate operand */ AArch64ImmOperand &CreateImmOperand(int64 val, uint32 size, bool isSigned, VaryType varyType = kNotVary, bool isFmov = false) { diff --git a/src/maple_be/include/cg/aarch64/aarch64_ebo.h b/src/maple_be/include/cg/aarch64/aarch64_ebo.h index f785cac5f21f4f145e0ca2f72a3566106c4e21c6..79fa21e7ed264b4819ae2af45d0bb5d2a141fa21 100644 --- a/src/maple_be/include/cg/aarch64/aarch64_ebo.h +++ b/src/maple_be/include/cg/aarch64/aarch64_ebo.h @@ -41,8 +41,9 @@ class AArch64Ebo : public Ebo { bool IsGlobalNeeded(Insn &insn) const override; bool OperandEqSpecial(const Operand &op1, const Operand &op2) const override; bool DoConstProp(Insn &insn, uint32 i, Operand &opnd) override; - bool DoConstantFold(Insn &insn, const MapleVector &opnds) override; - bool ConstantOperand(Insn &insn, const MapleVector &opnds, const MapleVector &opndInfo) override; + bool Csel2Cset(Insn &insn, const MapleVector &opnds) override; + bool SimplifyConstOperand(Insn &insn, const MapleVector &opnds, + const MapleVector &opndInfo) override; void BuildCallerSaveRegisters() override; void DefineCallerSaveRegisters(InsnInfo &insnInfo) override; void DefineReturnUseRegister(Insn &insn) override; diff --git a/src/maple_be/include/cg/cgfunc.h b/src/maple_be/include/cg/cgfunc.h index 337b9c86707162e4121b9a53fe2d49a0dbf013ff..31f90329af438b67821c2d059634887caa2083af 100644 --- a/src/maple_be/include/cg/cgfunc.h +++ b/src/maple_be/include/cg/cgfunc.h @@ -234,6 +234,7 @@ class CGFunc { virtual Operand &GetOrCreateRflag() = 0; virtual const Operand *GetRflag() const = 0; + virtual const Operand *GetFloatRflag() const = 0; virtual const LabelOperand *GetLabelOperand(LabelIdx labIdx) const = 0; virtual LabelOperand &GetOrCreateLabelOperand(LabelIdx labIdx) = 0; virtual LabelOperand &GetOrCreateLabelOperand(BB &bb) = 0; diff --git a/src/maple_be/include/cg/ebo.h b/src/maple_be/include/cg/ebo.h index 19d81d910d53d3674628ace71443e7ddc6c9dc64..c3151581b05f7fc16969218e1421ab1b7518af25 100644 --- a/src/maple_be/include/cg/ebo.h +++ b/src/maple_be/include/cg/ebo.h @@ -188,9 +188,9 @@ class Ebo { virtual bool IsFmov(const Insn &insn) const = 0; virtual bool SpecialSequence(Insn &insn, const MapleVector &origInfos) = 0; virtual bool DoConstProp(Insn &insn, uint32 i, Operand &opnd) = 0; - virtual bool DoConstantFold(Insn &insn, const MapleVector &opnds) = 0; - virtual bool ConstantOperand(Insn &insn, const MapleVector &opnds, - const MapleVector &opndInfo) = 0; + virtual bool Csel2Cset(Insn &insn, const MapleVector &opnds) = 0; + virtual bool SimplifyConstOperand(Insn &insn, const MapleVector &opnds, + const MapleVector &opndInfo) = 0; virtual int32 GetOffsetVal(const MemOperand &mem) const = 0; virtual bool OperandEqSpecial(const Operand &op1, const Operand &op2) const = 0; virtual void BuildCallerSaveRegisters() = 0; diff --git a/src/maple_be/src/be/lower.cpp b/src/maple_be/src/be/lower.cpp index e68d1c9f1c0869222f398b5c1adc55008af39e96..6de2d313c635e705d488bba74256f784c3780e66 100644 --- a/src/maple_be/src/be/lower.cpp +++ b/src/maple_be/src/be/lower.cpp @@ -2441,8 +2441,8 @@ StmtNode *CGLowerer::LowerIntrinsiccall(IntrinsiccallNode &intrincall, BlockNode } /* default lowers intrinsic call to real function call. */ MIRSymbol *st = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); - const std::string name = intrinDesc->name; CHECK_FATAL(intrinDesc->name != nullptr, "intrinsic's name should not be nullptr"); + const std::string name = intrinDesc->name; st->SetNameStrIdx(name); st->SetStorageClass(kScText); st->SetSKind(kStFunc); diff --git a/src/maple_be/src/cg/aarch64/aarch64_ebo.cpp b/src/maple_be/src/cg/aarch64/aarch64_ebo.cpp index 1c8efbd37ff53c39ca0a314e5dfe7ea191c5b023..9fd8f0fef8ee834893e4d4104f6ea6e11b369599 100644 --- a/src/maple_be/src/cg/aarch64/aarch64_ebo.cpp +++ b/src/maple_be/src/cg/aarch64/aarch64_ebo.cpp @@ -140,12 +140,12 @@ void AArch64Ebo::BuildCallerSaveRegisters() { } for (uint32 i = V1; i <= V7; i++) { RegOperand &phyOpnd = - a64CGFunc->GetOrCreatePhysicalRegisterOperand(static_cast(i), k64BitSize, kRegTyInt); + a64CGFunc->GetOrCreatePhysicalRegisterOperand(static_cast(i), k64BitSize, kRegTyFloat); callerSaveRegTable.push_back(&phyOpnd); } for (uint32 i = V16; i <= V31; i++) { RegOperand &phyOpnd = - a64CGFunc->GetOrCreatePhysicalRegisterOperand(static_cast(i), k64BitSize, kRegTyInt); + a64CGFunc->GetOrCreatePhysicalRegisterOperand(static_cast(i), k64BitSize, kRegTyFloat); callerSaveRegTable.push_back(&phyOpnd); } CHECK_FATAL(callerSaveRegTable.size() < kMaxCallerSaveReg, @@ -253,10 +253,11 @@ int32 AArch64Ebo::GetOffsetVal(const MemOperand &mem) const { } /* - * move vreg, 0 - * store vreg, mem + * move vreg1, #1 + * move vreg2, vreg1 * ===> - * store wzr, mem + * move vreg1, #1 + * move vreg2, #1 * return true if do simplify successfully. */ bool AArch64Ebo::DoConstProp(Insn &insn, uint32 idx, Operand &opnd) { @@ -337,8 +338,8 @@ bool AArch64Ebo::DoConstProp(Insn &insn, uint32 idx, Operand &opnd) { return false; } -/* Constant folding */ -bool AArch64Ebo::DoConstantFold(Insn &insn, const MapleVector &opnds) { +/* optimize csel to cset */ +bool AArch64Ebo::Csel2Cset(Insn &insn, const MapleVector &opnds) { MOperator opCode = insn.GetMachineOpcode(); if (insn.GetOpndNum() == 0) { @@ -405,9 +406,9 @@ bool AArch64Ebo::DoConstantFold(Insn &insn, const MapleVector &opnds) return false; } -/* Look at an exression that has a constant second operand and attempt to simplify the computations. */ -bool AArch64Ebo::ConstantOperand(Insn &insn, const MapleVector &opnds, - const MapleVector &opndInfo) { +/* Look at an expression that has a constant operand and attempt to simplify the computations. */ +bool AArch64Ebo::SimplifyConstOperand(Insn &insn, const MapleVector &opnds, + const MapleVector &opndInfo) { BB *bb = insn.GetBB(); bool result = false; if (insn.GetOpndNum() < 1) { @@ -420,29 +421,78 @@ bool AArch64Ebo::ConstantOperand(Insn &insn, const MapleVector &opnds, CHECK_FATAL(res != nullptr, "null ptr check"); const AArch64MD *md = &AArch64CG::kMd[static_cast(&insn)->GetMachineOpcode()]; uint32 opndSize = md->GetOperandSize(); - bool first = op0->IsConstant() && !op1->IsConstant(); - ASSERT((op1->IsConstant() && !op0->IsConstant()) || (op0->IsConstant() && !op1->IsConstant()), - "op0 or op1 must be constant op"); + bool op0IsConstant = op0->IsConstant() && !op1->IsConstant(); + bool op1IsConstant = !op0->IsConstant() && op1->IsConstant(); + bool bothConstant = op0->IsConstant() && op1->IsConstant(); AArch64ImmOperand *immOpnd = nullptr; Operand *op = nullptr; int32 idx0 = kInsnSecondOpnd; - if (first) { + if (op0IsConstant) { immOpnd = static_cast(op0); op = op1; if (op->IsMemoryAccessOperand()) { op = &(insn.GetOperand(kInsnThirdOpnd)); } idx0 = kInsnThirdOpnd; - } else { + } else if (op1IsConstant) { immOpnd = static_cast(op1); op = op0; if (op->IsMemoryAccessOperand()) { op = &(insn.GetOperand(kInsnSecondOpnd)); } + } else if (bothConstant) { + /* special orr insn : + * orr resOp, imm1, 0 + * =======> + * mov resOp, #0 */ + if ((insn.GetMachineOpcode() == MOP_wiorrri12) || (insn.GetMachineOpcode() == MOP_xiorrri13) || + (insn.GetMachineOpcode() == MOP_xiorri13r) || (insn.GetMachineOpcode() == MOP_wiorri12r)) { + immOpnd = static_cast(op1); + op = op0; + if (op->IsMemoryAccessOperand()) { + op = &(insn.GetOperand(kInsnSecondOpnd)); + } + } else { + return false; + } + } else if (bothConstant) { + /* i) special orr insn, one of imm is 0: + * orr resOp, imm1, #0 | orr resOp, #0, imm1 + * =======> + * mov resOp, imm1 + * + * ii) special orr insn, both of imm is 0: + * orr resOp, #0, #0 + * =======> + * mov resOp, #0 */ + if ((insn.GetMachineOpcode() == MOP_wiorrri12) || (insn.GetMachineOpcode() == MOP_xiorrri13) || + (insn.GetMachineOpcode() == MOP_xiorri13r) || (insn.GetMachineOpcode() == MOP_wiorri12r)) { + AArch64ImmOperand *immOpnd0 = static_cast(op0); + AArch64ImmOperand *immOpnd1 = static_cast(op1); + if (immOpnd0->IsZero() && immOpnd1->IsZero()) { + immOpnd = immOpnd0; + op = op0; + } else if (immOpnd0->IsZero()) { + immOpnd = immOpnd0; + op = op1; + } else if (immOpnd1->IsZero()) { + immOpnd = immOpnd1; + op = op0; + } else { + return false; + } + if (op->IsMemoryAccessOperand()) { + op = &(insn.GetOperand(kInsnSecondOpnd)); + } + } else { + return false; + } } + CHECK_FATAL(immOpnd != nullptr, "constant operand required!"); + CHECK_FATAL(op != nullptr, "constant operand required!"); /* For orr insn and one of the opnd is zero */ if (((insn.GetMachineOpcode() == MOP_wiorrri12) || (insn.GetMachineOpcode() == MOP_xiorrri13) || - (insn.GetMachineOpcode() == MOP_xiorri13r) || (insn.GetMachineOpcode() == MOP_wiorri12r)) && + (insn.GetMachineOpcode() == MOP_xiorri13r) || (insn.GetMachineOpcode() == MOP_wiorri12r)) && immOpnd->IsZero()) { MOperator mOp = opndSize == k64BitSize ? MOP_xmovrr : MOP_wmovrr; Insn &newInsn = cgFunc->GetCG()->BuildInstruction(mOp, *res, *op); @@ -451,7 +501,7 @@ bool AArch64Ebo::ConstantOperand(Insn &insn, const MapleVector &opnds, } /* For the imm is 0. Then replace the insn by a move insn. */ if (((MOP_xaddrrr <= insn.GetMachineOpcode()) && (insn.GetMachineOpcode() <= MOP_sadd) && immOpnd->IsZero()) || - (!first && (MOP_xsubrrr <= insn.GetMachineOpcode()) && (insn.GetMachineOpcode() <= MOP_ssub) && + (op1IsConstant && (MOP_xsubrrr <= insn.GetMachineOpcode()) && (insn.GetMachineOpcode() <= MOP_ssub) && immOpnd->IsZero())) { Insn &newInsn = cgFunc->GetCG()->BuildInstruction(opndSize == k64BitSize ? MOP_xmovrr : MOP_wmovrr, *res, *op); diff --git a/src/maple_be/src/cg/aarch64/aarch64_md.def b/src/maple_be/src/cg/aarch64/aarch64_md.def index fe89f03404e628524d7edac977309436fc850c1d..0e2b3c71f24ef506282423d5c3278b5f1a316970 100644 --- a/src/maple_be/src/cg/aarch64/aarch64_md.def +++ b/src/maple_be/src/cg/aarch64/aarch64_md.def @@ -706,7 +706,7 @@ * stlxr w2, w3, [xt] * cbnz w2, label */ -{MOP_get_and_setI, {mopdReg32ID,mopdReg64ID,mopdReg32ID,mopdReg64IS,mopdReg64IDS,mopdReg32IS,mopdLabel},HASLOOP|CANTHROW,kLtBranch,"intrinsic_get_set_int","0,1,2,3,4",4}, +{MOP_get_and_setI, {mopdReg32ID,mopdReg64ID,mopdReg32ID,mopdReg64IS,mopdReg64IS,mopdReg32IS,mopdLabel},HASLOOP|CANTHROW,kLtBranch,"intrinsic_get_set_int","0,1,2,3,4",4}, /* * intrinsic Unsafe.getAndSetLong * intrinsic_get_set_long x0, x1, x2, x3, label @@ -716,7 +716,7 @@ * stlxr w2, x3, [xt] * cbnz w2, label */ -{MOP_get_and_setL, {mopdReg64ID,mopdReg64ID,mopdReg32ID,mopdReg64IS,mopdReg64IDS,mopdReg64IS,mopdLabel},HASLOOP|CANTHROW,kLtBranch,"intrinsic_get_set_long","0,1,2,3,4",4}, +{MOP_get_and_setL, {mopdReg64ID,mopdReg64ID,mopdReg32ID,mopdReg64IS,mopdReg64IS,mopdReg64IS,mopdLabel},HASLOOP|CANTHROW,kLtBranch,"intrinsic_get_set_long","0,1,2,3,4",4}, /* * intrinsic Unsafe.compareAndSwapInt diff --git a/src/maple_be/src/cg/ebo.cpp b/src/maple_be/src/cg/ebo.cpp index f62115bf75577dc34240226d0acc105bbbaaaf69..5e675ebcd3f15d7560d4f967e42ba294a25bfcb9 100644 --- a/src/maple_be/src/cg/ebo.cpp +++ b/src/maple_be/src/cg/ebo.cpp @@ -482,7 +482,6 @@ OpndInfo *Ebo::BuildOperandInfo(BB &bb, Insn &insn, Operand &opnd, uint32 opndIn bool Ebo::ForwardPropagateOpnd(Insn &insn, Operand *&opnd, uint32 opndIndex, OpndInfo *&opndInfo, MapleVector &origInfos) { CHECK_FATAL(opnd != nullptr, "nullptr check"); - bool replaceInsnExist = false; Operand *opndReplace = opndInfo->replacementOpnd; /* Don't propagate physical registers before register allocation. */ if (beforeRegAlloc && (opndReplace != nullptr) && (IsPhysicalReg(*opndReplace) || IsPhysicalReg(*opnd))) { @@ -509,6 +508,24 @@ bool Ebo::ForwardPropagateOpnd(Insn &insn, Operand *&opnd, uint32 opndIndex, origInfos.at(opndIndex) = opndInfo; } } + /* move reg, wzr, store vreg, mem ==> store wzr, mem */ +#if TARGAARCH64 + if (opnd->IsZeroRegister() && opndIndex == 0 && + (insn.GetMachineOpcode() == MOP_wstr || insn.GetMachineOpcode() == MOP_xstr)) { + if (EBO_DUMP) { + LogInfo::MapleLogger() << "===replace operand " << opndIndex << " of insn: \n"; + insn.Dump(); + LogInfo::MapleLogger() << "the new insn is:\n"; + } + insn.SetOperand(opndIndex, *opnd); + DecRef(*origInfos.at(opndIndex)); + /* Update the actual expression info. */ + origInfos.at(opndIndex) = opndInfo; + if (EBO_DUMP) { + insn.Dump(); + } + } +#endif /* forward prop for registers. */ if (!opnd->IsConstant() && (!beforeRegAlloc || (HasAssignedReg(*oldOpnd) == HasAssignedReg(*opndReplace)) || opnd->IsConstReg() || @@ -527,8 +544,7 @@ bool Ebo::ForwardPropagateOpnd(Insn &insn, Operand *&opnd, uint32 opndIndex, insn.Dump(); LogInfo::MapleLogger() << "===Remove the new insn because Copies to and from the same register. \n"; } - replaceInsnExist = true; - return replaceInsnExist; + return true; } if (EBO_DUMP) { @@ -552,7 +568,7 @@ bool Ebo::ForwardPropagateOpnd(Insn &insn, Operand *&opnd, uint32 opndIndex, } } - return replaceInsnExist; + return false; } /* @@ -581,16 +597,19 @@ void Ebo::SimplifyInsn(Insn &insn, bool &insnReplaced, bool opndsConstant, uint32 opndNum = insn.GetOpndNum(); if (opndsConstant && (opndNum > 1)) { if (insn.GetResultNum() >= 1) { - insnReplaced = DoConstantFold(insn, opnds); + insnReplaced = Csel2Cset(insn, opnds); } - } else if (opndNum >= 1) { + } + if (insnReplaced) { + return; + } + if (opndNum >= 1) { /* special case */ if (insn.GetResultNum() > 0 && ResIsNotDefAndUse(insn)) { - /* Here mainly to do is optimizatinn of "add" with two source operands when only one operand is constant */ if ((opndNum == 2) && (insn.GetResultNum() == 1) && (((opnds[kInsnSecondOpnd] != nullptr) && opnds[kInsnSecondOpnd]->IsConstant()) || ((opnds[kInsnThirdOpnd] != nullptr) && opnds[kInsnThirdOpnd]->IsConstant()))) { - insnReplaced = ConstantOperand(insn, opnds, opndInfos); + insnReplaced = SimplifyConstOperand(insn, opnds, opndInfos); } } if (!insnReplaced) { diff --git a/src/maple_be/src/cg/emit.cpp b/src/maple_be/src/cg/emit.cpp index 51aec39d7f12728bfbe854535e3fea504f1eaf63..262b9397e73ad8caeb3b50a96e155f17c8f832ab 100644 --- a/src/maple_be/src/cg/emit.cpp +++ b/src/maple_be/src/cg/emit.cpp @@ -26,6 +26,7 @@ using namespace NameMangler; namespace { using namespace maple; constexpr uint32 kSizeOfHugesoRoutine = 3; +constexpr uint32 kFromDefIndexMask32Mod = 0x40000000; int32 GetPrimitiveTypeSize(const std::string &name) { if (name.length() != 1) { @@ -696,11 +697,17 @@ void Emitter::EmitAddrofSymbolConst(const MIRSymbol &mirSymbol, MIRConst &elemCo } if ((idx == static_cast(FieldProperty::kDeclarclass)) && mirSymbol.IsReflectionFieldsInfo()) { +#if USE_32BIT_REF + Emit("\t.long\t"); +#else + #if TARGAARCH64 Emit("\t.quad\t"); #else Emit("\t.word\t"); #endif + +#endif /* USE_32BIT_REF */ Emit(symAddrName + " - .\n"); return; } @@ -1066,7 +1073,7 @@ void Emitter::EmitIntConst(const MIRSymbol &mirSymbol, MIRAggConst &aggConst, ui } else if (idx == static_cast(ClassRO::kClassName)) { /* output in hex format to show it is a flag of bits. */ std::stringstream ss; - ss << std::hex << "0x" << MByteRef::PositiveOffsetBias; + ss << std::hex << "0x" << MByteRef::kPositiveOffsetBias; Emit(" - . + " + ss.str()); } } @@ -1076,7 +1083,7 @@ void Emitter::EmitIntConst(const MIRSymbol &mirSymbol, MIRAggConst &aggConst, ui if (StringUtils::StartsWith(stName, ITAB_CONFLICT_PREFIX_STR)) { /* output in hex format to show it is a flag of bits. */ std::stringstream ss; - ss << std::hex << "0x" << MByteRef32::PositiveOffsetBias; + ss << std::hex << "0x" << MByteRef32::kPositiveOffsetBias; Emit(" - . + " + ss.str()); } if ((idx == 1 || idx == methodTypeIdx) && StringUtils::StartsWith(stName, kVtabOffsetTabStr)) { @@ -1105,11 +1112,33 @@ void Emitter::EmitIntConst(const MIRSymbol &mirSymbol, MIRAggConst &aggConst, ui } else { Emit("0\n"); } + } else if (idx == static_cast(FieldProperty::kPClassType) && mirSymbol.IsReflectionFieldsInfo()) { +#ifdef USE_32BIT_REF + Emit("\t.long\t"); + const int width = 4; +#else + Emit("\t.quad\t"); + const int width = 8; +#endif /* USE_32BIT_REF */ + uint32 muidDataTabAddr = static_cast((safe_cast(elemConst))->GetValue()); + if (muidDataTabAddr != 0) { + bool isDefTabIndex = (muidDataTabAddr & kFromDefIndexMask32Mod) == kFromDefIndexMask32Mod; + std::string muidDataTabPrefix = isDefTabIndex ? kMuidDataDefTabPrefixStr : kMuidDataUndefTabPrefixStr; + std::string muidDataTabName = muidDataTabPrefix + cg->GetMIRModule()->GetFileNameAsPostfix(); + Emit(muidDataTabName + "+"); + uint32 muidDataTabIndex = muidDataTabAddr & 0x3FFFFFFF; // high 2 bit is the mask of muid tab + Emit(std::to_string(muidDataTabIndex * width)); + Emit("-.\n"); + } else { + Emit(muidDataTabAddr); + Emit("\n"); + } + return; } else if (mirSymbol.IsRegJNIFuncTab()) { std::string strTabName = kRegJNITabPrefixStr + cg->GetMIRModule()->GetFileNameAsPostfix(); EmitScalarConstant(*elemConst, false); #ifdef TARGARM32 - Emit("+" + strTabName).Emit("+").Emit(MByteRef::PositiveOffsetBias).Emit("-.\n"); + Emit("+" + strTabName).Emit("+").Emit(MByteRef::kPositiveOffsetBias).Emit("-.\n"); #else Emit("+" + strTabName + "\n"); #endif @@ -1270,7 +1299,7 @@ void Emitter::EmitConstantTable(const MIRSymbol &mirSymbol, MIRConst &mirConst, } else if (elemConst->GetKind() == kConstAddrof) { /* addrof symbol const */ EmitAddrofSymbolConst(mirSymbol, *elemConst, i); } else { /* intconst */ - EmitIntConst(mirSymbol, aggConst, itabConflictIndex, strIdx2Type, i); + EmitIntConst(mirSymbol, aggConst, itabConflictIndex, strIdx2Type, i); } } else if (elemConst->GetType().GetKind() == kTypeArray || elemConst->GetType().GetKind() == kTypeStruct) { if (StringUtils::StartsWith(mirSymbol.GetName(), NameMangler::kOffsetTabStr) && (i == 0 || i == 1)) { @@ -1678,6 +1707,7 @@ void Emitter::EmitGlobalVariable() { std::vector methodAddrDatas; std::vector staticDecoupleKeyVec; std::vector staticDecoupleValueVec; + std::vector superClassStVec; for (size_t i = 0; i < size; ++i) { MIRSymbol *mirSymbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(i); @@ -1746,6 +1776,9 @@ void Emitter::EmitGlobalVariable() { } else if (mirSymbol->IsReflectionMethodAddrData()) { methodAddrDatas.push_back(mirSymbol); continue; + } else if (mirSymbol->IsReflectionSuperclassInfo()) { + superClassStVec.push_back(mirSymbol); + continue; } if (mirSymbol->IsReflectionInfo()) { @@ -1895,7 +1928,6 @@ void Emitter::EmitGlobalVariable() { EmitMuidTable(constStrVec, strIdx2Type, kMuidConststrPrefixStr); /* emit classinfo, field, method */ - std::vector superClassStVec; std::vector fieldInfoStVec; std::vector fieldInfoStCompactVec; std::vector methodInfoStVec; @@ -1926,9 +1958,6 @@ void Emitter::EmitGlobalVariable() { GlobalTables::GetStrTable().GetStrIdxFromName(kMethodsInfoPrefixStr + className)); MIRSymbol *methodStCompact = GlobalTables::GetGsymTable().GetSymbolFromStrIdx( GlobalTables::GetStrTable().GetStrIdxFromName(kMethodsInfoCompactPrefixStr + className)); - /* Get superclass */ - MIRSymbol *superClassSt = GlobalTables::GetGsymTable().GetSymbolFromStrIdx( - GlobalTables::GetStrTable().GetStrIdxFromName(SUPERCLASSINFO_PREFIX_STR + className)); if (fieldSt != nullptr) { fieldInfoStVec.push_back(fieldSt); @@ -1942,9 +1971,6 @@ void Emitter::EmitGlobalVariable() { if (methodStCompact != nullptr) { methodInfoStCompactVec.push_back(methodStCompact); } - if (superClassSt != nullptr) { - superClassStVec.push_back(superClassSt); - } } } Emit(sectionName + "_end:\n"); @@ -1959,16 +1985,12 @@ void Emitter::EmitGlobalVariable() { std::vector coldMethodsInfoCStVec; std::vector hotFieldsInfoCStVec; std::vector coldFieldsInfoCStVec; - std::vector hotSuperClassStVec; - std::vector coldSuperClassStVec; GetHotAndColdMetaSymbolInfo(vtabVec, hotVtabStVec, coldVtabStVec, VTAB_PREFIX_STR, ((CGOptions::IsLazyBinding() || CGOptions::IsHotFix()) && !cg->IsLibcore())); GetHotAndColdMetaSymbolInfo(itabVec, hotItabStVec, coldItabStVec, ITAB_PREFIX_STR, ((CGOptions::IsLazyBinding() || CGOptions::IsHotFix()) && !cg->IsLibcore())); GetHotAndColdMetaSymbolInfo(itabConflictVec, hotItabCStVec, coldItabCStVec, ITAB_CONFLICT_PREFIX_STR, ((CGOptions::IsLazyBinding() || CGOptions::IsHotFix()) && !cg->IsLibcore())); - GetHotAndColdMetaSymbolInfo(superClassStVec, hotSuperClassStVec, coldSuperClassStVec, SUPERCLASSINFO_PREFIX_STR, - ((CGOptions::IsLazyBinding() || CGOptions::IsHotFix()) && !cg->IsLibcore())); GetHotAndColdMetaSymbolInfo(fieldInfoStVec, hotFieldsInfoCStVec, coldFieldsInfoCStVec, kFieldsInfoPrefixStr); GetHotAndColdMetaSymbolInfo(methodInfoStVec, hotMethodsInfoCStVec, coldMethodsInfoCStVec, kMethodsInfoPrefixStr); @@ -2019,9 +2041,7 @@ void Emitter::EmitGlobalVariable() { EmitMuidTable(staticDecoupleValueVec, strIdx2Type, kDecoupleStaticValueStr); /* super class */ - EmitMuidTable(hotSuperClassStVec, strIdx2Type, kMuidSuperclassPrefixStr); - EmitMetaDataSymbolWithMarkFlag(coldSuperClassStVec, strIdx2Type, SUPERCLASSINFO_PREFIX_STR, sectionNameIsEmpty, - false); + EmitMuidTable(superClassStVec, strIdx2Type, kMuidSuperclassPrefixStr); /* field offset rw */ EmitMetaDataSymbolWithMarkFlag(fieldOffsetDatas, strIdx2Type, kFieldOffsetDataPrefixStr, sectionNameIsEmpty, false); diff --git a/src/maple_driver/include/mpl_options.h b/src/maple_driver/include/mpl_options.h index 4ba6e2786a761338d45d56a77efb971ec323e128..19a848a83b90deed56320e327cfa4a7379a39be1 100644 --- a/src/maple_driver/include/mpl_options.h +++ b/src/maple_driver/include/mpl_options.h @@ -170,10 +170,6 @@ class MplOptions { return genVtableImpl; } - bool HasSetVerify() const { - return verify; - } - private: bool Init(const std::string &inputFile); ErrorCode HandleGeneralOptions(); @@ -210,7 +206,6 @@ class MplOptions { bool timePhases = false; bool genMeMpl = false; bool genVtableImpl = false; - bool verify = false; unsigned int helpLevel = mapleOption::kBuildTypeDefault; }; } // namespace maple diff --git a/src/maple_driver/src/maple_comb_compiler.cpp b/src/maple_driver/src/maple_comb_compiler.cpp index 002bca9e0ed065ac84e065c08e34df115d673f9b..b64ba13b08cfaadb0592f32eecce737faa8447cb 100644 --- a/src/maple_driver/src/maple_comb_compiler.cpp +++ b/src/maple_driver/src/maple_comb_compiler.cpp @@ -119,8 +119,7 @@ bool MapleCombCompiler::MakeMpl2MplOptions(const MplOptions &options) { LogInfo::MapleLogger() << "no mpl2mpl input options\n"; return false; } - bool result = mpl2mplOption.SolveOptions(it->second, - options.HasSetDebugFlag()); + bool result = mpl2mplOption.SolveOptions(it->second, options.HasSetDebugFlag()); if (result == false) { LogInfo::MapleLogger() << "Meet error mpl2mpl options\n"; return false; diff --git a/src/maple_ipa/include/callgraph.h b/src/maple_ipa/include/callgraph.h index 7db64edcfe2ba30005798eabb88f4cf436077a86..f48142cf750d3e77505a5b72a0a29a8da55ff217 100644 --- a/src/maple_ipa/include/callgraph.h +++ b/src/maple_ipa/include/callgraph.h @@ -95,9 +95,6 @@ class CallInfo { uint32 id; }; -class CGNode; -using Callsite = std::pair>*>; -using CalleeIt = MapleMap>*, Comparator>::iterator; // Node in callgraph class CGNode { public: @@ -152,11 +149,11 @@ class CGNode { } int32 GetPuIdx() const { - return mirFunc ? mirFunc->GetPuidx() : -1; + return (mirFunc != nullptr) ? mirFunc->GetPuidx() : -1; } const std::string &GetMIRFuncName() const { - return mirFunc ? mirFunc->GetName() : GlobalTables::GetStrTable().GetStringFromStrIdx(GStrIdx(0)); + return (mirFunc != nullptr) ? mirFunc->GetName() : GlobalTables::GetStrTable().GetStringFromStrIdx(GStrIdx(0)); } void AddCandsForCallNode(const KlassHierarchy &kh); @@ -305,6 +302,9 @@ class CGNode { MapleVector vcallCands; }; +using Callsite = std::pair>*>; +using CalleeIt = MapleMap>*, Comparator>::iterator; + class SCCNode { public: uint32 id; @@ -345,6 +345,7 @@ class SCCNode { return id; } }; + class CallGraph : public AnalysisResult { public: CallGraph(MIRModule &m, MemPool &memPool, KlassHierarchy &kh, const std::string &fn); diff --git a/src/maple_ipa/src/callgraph.cpp b/src/maple_ipa/src/callgraph.cpp index 9bfbe5d8c1ec67fa5c5b1d68c5d059bde7c1025c..57e344af0392abbfde3a2bddbc8568ff66413289 100644 --- a/src/maple_ipa/src/callgraph.cpp +++ b/src/maple_ipa/src/callgraph.cpp @@ -310,7 +310,7 @@ CGNode *CallGraph::GetCGNode(PUIdx puIdx) const { SCCNode *CallGraph::GetSCCNode(MIRFunction *func) const { CGNode *cgNode = GetCGNode(func); - return cgNode != nullptr ? cgNode->GetSCCNode() : nullptr; + return (cgNode != nullptr) ? cgNode->GetSCCNode() : nullptr; } bool CallGraph::IsRootNode(MIRFunction *func) const { @@ -688,6 +688,14 @@ void IPODevirtulize::SearchDefInClinit(const Klass &klass) { GCMallocNode *gcmallocNode = static_cast(dassignNode->GetRHS()); TyIdx inferredTypeIdx = gcmallocNode->GetTyIdx(); SetInferredType(gcmallocSymbols, *leftSymbol, inferredTypeIdx); + } else if (dassignNode->GetRHS()->GetOpCode() == OP_retype) { + if (dassignNode->GetRHS()->Opnd(0)->GetOpCode() == OP_dread) { + DreadNode *dreadNode = static_cast(dassignNode->GetRHS()->Opnd(0)); + MIRSymbol *rightSymbol = func->GetLocalOrGlobalSymbol(dreadNode->GetStIdx()); + if (rightSymbol->GetInferredTyIdx() != kInitTyIdx && rightSymbol->GetInferredTyIdx() != kNoneTyIdx) { + SetInferredType(gcmallocSymbols, *leftSymbol, rightSymbol->GetInferredTyIdx()); + } + } } else { ResetInferredType(gcmallocSymbols, leftSymbol); } @@ -697,7 +705,8 @@ void IPODevirtulize::SearchDefInClinit(const Klass &klass) { case OP_callassigned: { CallNode *callNode = static_cast(stmt); MIRFunction *calleeFunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(callNode->GetPUIdx()); - if (calleeFunc->GetName().find(NameMangler::kClinitSubStr, 0) != std::string::npos) { + if (calleeFunc->GetName().find(NameMangler::kClinitSubStr, 0) != std::string::npos || + calleeFunc->GetName().find("MCC_", 0) == 0) { // ignore all side effect of initizlizor continue; } @@ -880,6 +889,8 @@ void DoDevirtual(const Klass &klass, const KlassHierarchy &klassh) { case OP_assertnonnull: case OP_brtrue: case OP_brfalse: + case OP_try: + case OP_endtry: break; case OP_dassign: { DassignNode *dassignNode = static_cast(stmt); @@ -1667,7 +1678,7 @@ MIRFunction *CGNode::HasOneCandidate() const { } } } - return count == 1 ? cand : nullptr; + return (count == 1) ? cand : nullptr; } AnalysisResult *DoCallGraph::Run(MIRModule *module, ModuleResultMgr *m) { diff --git a/src/maple_ipa/src/clone.cpp b/src/maple_ipa/src/clone.cpp index 361be9893750d0575bd583c3f94e4b0271db386e..56d1de62b8cd34f490cc9f5610c2f8fcd5e997ba 100644 --- a/src/maple_ipa/src/clone.cpp +++ b/src/maple_ipa/src/clone.cpp @@ -101,10 +101,8 @@ MIRFunction *Clone::CloneFunction(MIRFunction &originalFunction, const std::stri } std::string fullName = originalFunction.GetBaseClassName(); const std::string &signature = originalFunction.GetSignature(); - fullName = fullName.append(NameMangler::kNameSplitterStr) - .append(newBaseFuncName) - .append(NameMangler::kNameSplitterStr) - .append(signature); + fullName = fullName.append( + NameMangler::kNameSplitterStr).append(newBaseFuncName).append(NameMangler::kNameSplitterStr).append(signature); MIRFunction *newFunc = dexBuilder.CreateFunction(fullName, *retType, argument, false, originalFunction.GetBody() != nullptr); CHECK_FATAL(newFunc != nullptr, "create cloned function failed"); diff --git a/src/maple_ir/include/global_tables.h b/src/maple_ir/include/global_tables.h index 5e8bce42e95cc339968460f27df720b4e0e94fd7..f8864c348d46c11e9bc64a359a8c57a0a5b06897 100644 --- a/src/maple_ir/include/global_tables.h +++ b/src/maple_ir/include/global_tables.h @@ -116,9 +116,9 @@ class TypeTable { void SetTypeWithTyIdx(const TyIdx &tyIdx, MIRType &type); - MIRType *CreateAndUpdateMirTypeNode(MIRType *pType); - MIRType *GetOrCreateMIRTypeNode(MIRType *ptype); - TyIdx GetOrCreateMIRType(MIRType *pType) { return GetOrCreateMIRTypeNode(pType)->GetTypeIndex(); } + TyIdx GetOrCreateMIRType(MIRType *pType) { + return GetOrCreateMIRTypeNode(*pType)->GetTypeIndex(); + } size_t GetTypeTableSize() const { return typeTable.size(); @@ -356,6 +356,8 @@ class TypeTable { return newType; } + MIRType *CreateAndUpdateMirTypeNode(MIRType &pType); + MIRType *GetOrCreateMIRTypeNode(MIRType &ptype); MIRType *GetOrCreateStructOrUnion(const std::string &name, const FieldVector &fields, const FieldVector &printFields, MIRModule &module, bool forStruct = true); MIRType *GetOrCreateClassOrInterface(const std::string &name, MIRModule &module, bool forClass); diff --git a/src/maple_ir/include/metadata_layout.h b/src/maple_ir/include/metadata_layout.h index b4b89ce3509ddde588b9640be3f51ea8eafc2abe..a704c581279befc9f37cbb73c718a77b55b97cf2 100644 --- a/src/maple_ir/include/metadata_layout.h +++ b/src/maple_ir/include/metadata_layout.h @@ -159,26 +159,26 @@ struct MByteRef { #if defined(__arm__) || defined(USE_ARM32_MACRO) // assume address range 0 ~ 256MB is unused in arm runtime - // EncodedOffsetMin ~ EncodedOffsetMax is the value range of encoded offset - static constexpr intptr_t OffsetBound = 128 * 1024 * 1024; - static constexpr intptr_t OffsetMin = -OffsetBound; - static constexpr intptr_t OffsetMax = OffsetBound; - - static constexpr intptr_t PositiveOffsetBias = 128 * 1024 * 1024; - static constexpr intptr_t EncodedOffsetMin = PositiveOffsetBias + OffsetMin; - static constexpr intptr_t EncodedOffsetMax = PositiveOffsetBias + OffsetMax; + // kEncodedOffsetMin ~ kEncodedOffsetMax is the value range of encoded offset + static constexpr intptr_t kOffsetBound = 128 * 1024 * 1024; + static constexpr intptr_t kOffsetMin = -kOffsetBound; + static constexpr intptr_t kOffsetMax = kOffsetBound; + + static constexpr intptr_t kPositiveOffsetBias = 128 * 1024 * 1024; + static constexpr intptr_t kEncodedOffsetMin = kPositiveOffsetBias + kOffsetMin; + static constexpr intptr_t kEncodedOffsetMax = kPositiveOffsetBias + kOffsetMax; #else enum { kBiasBitPosition = sizeof(refVal) * 8 - 4, // the most significant 4 bits }; - static constexpr uintptr_t OffsetBound = 256 * 1024 * 1024; // according to kDsoLoadedAddessEnd = 0xF0000000 - static constexpr uintptr_t PositiveOffsetMin = 0; - static constexpr uintptr_t PositiveOffsetMax = OffsetBound; + static constexpr uintptr_t kOffsetBound = 256 * 1024 * 1024; // according to kDsoLoadedAddessEnd = 0xF0000000 + static constexpr uintptr_t kPositiveOffsetMin = 0; + static constexpr uintptr_t kPositiveOffsetMax = kOffsetBound; - static constexpr uintptr_t PositiveOffsetBias = static_cast(6) << kBiasBitPosition; - static constexpr uintptr_t EncodedPosOffsetMin = PositiveOffsetMin + PositiveOffsetBias; - static constexpr uintptr_t EncodedPosOffsetMax = PositiveOffsetMax + PositiveOffsetBias; + static constexpr uintptr_t kPositiveOffsetBias = static_cast(6) << kBiasBitPosition; + static constexpr uintptr_t kEncodedPosOffsetMin = kPositiveOffsetMin + kPositiveOffsetBias; + static constexpr uintptr_t kEncodedPosOffsetMax = kPositiveOffsetMax + kPositiveOffsetBias; #endif template @@ -190,19 +190,19 @@ struct MByteRef { struct MByteRef32 { uint32_t refVal; - static constexpr uint32_t OffsetBound = 256 * 1024 * 1024; // according to kDsoLoadedAddessEnd = 0xF0000000 - static constexpr uint32_t PositiveOffsetMin = 0; - static constexpr uint32_t PositiveOffsetMax = OffsetBound; + static constexpr uint32_t kOffsetBound = 256 * 1024 * 1024; // according to kDsoLoadedAddessEnd = 0xF0000000 + static constexpr uint32_t kPositiveOffsetMin = 0; + static constexpr uint32_t kPositiveOffsetMax = kOffsetBound; - static constexpr uint32_t PositiveOffsetBias = 0x60000000; // the most significant 4 bits 0110 - static constexpr uint32_t EncodedPosOffsetMin = PositiveOffsetMin + PositiveOffsetBias; - static constexpr uint32_t EncodedPosOffsetMax = PositiveOffsetMax + PositiveOffsetBias; + static constexpr uint32_t kPositiveOffsetBias = 0x60000000; // the most significant 4 bits 0110 + static constexpr uint32_t kEncodedPosOffsetMin = kPositiveOffsetMin + kPositiveOffsetBias; + static constexpr uint32_t kEncodedPosOffsetMax = kPositiveOffsetMax + kPositiveOffsetBias; - static constexpr uint32_t DirectRefMin = 0xC0000000; // according to kDsoLoadedAddessStart = 0xC0000000 - static constexpr uint32_t DirectRefMax = 0xF0000000; // according to kDsoLoadedAddessEnd = 0xF0000000 + static constexpr uint32_t kDirectRefMin = 0xC0000000; // according to kDsoLoadedAddessStart = 0xC0000000 + static constexpr uint32_t kDirectRefMax = 0xF0000000; // according to kDsoLoadedAddessEnd = 0xF0000000 - static constexpr int32_t NegativeOffsetMin = -OffsetBound; - static constexpr int32_t NegativeOffsetMax = 0; + static constexpr int32_t kNegativeOffsetMin = -(256 * 1024 * 1024); // -kOffsetBound + static constexpr int32_t kNegativeOffsetMax = 0; template inline T GetRef() const; @@ -213,7 +213,7 @@ struct MByteRef32 { inline bool IsNegativeOffset() const; }; -// MethodMeta defined in MethodMeta.h +// MethodMeta defined in methodmeta.h // FieldMeta defined in FieldMeta.h // MethodDesc contains MethodMetadata and stack map struct MethodDesc { @@ -252,7 +252,7 @@ struct ClassMetadataRO { DataRefOffset32 clinitAddr; }; -static constexpr size_t PageSize = 4096; +static constexpr size_t kPageSize = 4096; static constexpr size_t kCacheLine = 64; // according to kSpaceAnchor and kFireBreak defined in bpallocator.cpp @@ -280,7 +280,7 @@ enum ClassInitState { }; enum SEGVAddr { - kSEGVAddrRangeStart = PageSize + 0, + kSEGVAddrRangeStart = kPageSize + 0, // Note any readable address is treated as Initialized. kSEGVAddrForClassInitStateMin = kSEGVAddrRangeStart + kClassInitStateMin, diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index 688856536dee71e77a5b74d15beef8cd4b3b2019..faa9b0aa44b2c87ad3c5cd319633bb55739a8256 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -962,6 +962,10 @@ class MIRStructType : public MIRType { CHECK_FATAL(false, "can not use GetInfoIsString"); } + virtual bool GetInfoIsStringElemt(size_t) const { + CHECK_FATAL(false, "can not use GetInfoIsStringElemt"); + } + virtual const std::vector &GetPragmaVec() const { CHECK_FATAL(false, "can not use GetPragmaVec"); } @@ -1100,13 +1104,16 @@ class MIRClassType : public MIRStructType { const std::vector &GetInfoIsString() const override { return infoIsString; } + void PushbackIsString(bool isString) override { infoIsString.push_back(isString); } + size_t GetInfoIsStringSize() const { return infoIsString.size(); } - bool GetInfoIsStringElemt(size_t n) const { + + bool GetInfoIsStringElemt(size_t n) const override { ASSERT(n < infoIsString.size(), "array index out of range"); return infoIsString.at(n); } @@ -1248,7 +1255,7 @@ class MIRInterfaceType : public MIRStructType { size_t GetInfoIsStringSize() const { return infoIsString.size(); } - bool GetInfoIsStringElemt(size_t n) const { + bool GetInfoIsStringElemt(size_t n) const override { ASSERT(n < infoIsString.size(), "array index out of range"); return infoIsString.at(n); } diff --git a/src/maple_ir/include/option.h b/src/maple_ir/include/option.h index 12998d24c484e809367ff3f35fca263551803488..fe9137f2afc073b153668196f053c2f4f55c1cc6 100644 --- a/src/maple_ir/include/option.h +++ b/src/maple_ir/include/option.h @@ -32,8 +32,7 @@ class Options : public MapleDriverOptionBase { bool ParseOptions(int argc, char **argv, std::string &fileName) const; - bool SolveOptions(const std::vector &opts, - bool isDebug) const; + bool SolveOptions(const std::vector &opts, bool isDebug) const; ~Options() = default; void DumpOptions() const; diff --git a/src/maple_ir/src/bin_mpl_import.cpp b/src/maple_ir/src/bin_mpl_import.cpp index 214816c6791b00d9fadae35aa320fb65da08010a..059acecdeeb2d3954e8445e4c95b61bfbacabdfe 100644 --- a/src/maple_ir/src/bin_mpl_import.cpp +++ b/src/maple_ir/src/bin_mpl_import.cpp @@ -389,7 +389,7 @@ void BinaryMplImport::ImportInfoOfStructType(MIRStructType &type) { bool isEmpty = type.GetInfo().empty(); for (int64 i = 0; i < size; ++i) { GStrIdx idx = ImportStr(); - int64 x = (type.GetInfoIsString()[i]) ? static_cast(ImportStr()) : ReadNum(); + int64 x = (type.GetInfoIsStringElemt(i)) ? static_cast(ImportStr()) : ReadNum(); CHECK_FATAL(x >= 0, "ReadNum nagative, x: %d", x); CHECK_FATAL(x <= std::numeric_limits::max(), "ReadNum too large, x: %d", x); if (isEmpty) { diff --git a/src/maple_ir/src/global_tables.cpp b/src/maple_ir/src/global_tables.cpp index e29f6ff170b6c519ed7b3d1307f0e446b172f8dc..e51ecd2a67cd14d262e02027f367d34933f16bed 100644 --- a/src/maple_ir/src/global_tables.cpp +++ b/src/maple_ir/src/global_tables.cpp @@ -27,7 +27,7 @@ MIRType *TypeTable::CreateMirType(uint32 primTypeIdx) const { return mirType; } -TypeTable::TypeTable() : ptrTypeMap(), refTypeMap() { +TypeTable::TypeTable() { // enter the primitve types in type_table_ typeTable.push_back(static_cast(nullptr)); ASSERT(typeTable.size() == static_cast(PTY_void), "use PTY_void as the first index to type table"); @@ -63,43 +63,48 @@ void TypeTable::PutToHashTable(MIRType *mirType) { typeHashTable.insert(mirType); } -MIRType *TypeTable::CreateAndUpdateMirTypeNode(MIRType *ptype) { - MIRType *ntype = ptype->CopyMIRTypeNode(); - ntype->SetTypeIndex(TyIdx(typeTable.size())); - typeTable.push_back(ntype); +MIRType *TypeTable::CreateAndUpdateMirTypeNode(MIRType &pType) { + MIRType *nType = pType.CopyMIRTypeNode(); + nType->SetTypeIndex(TyIdx(typeTable.size())); + typeTable.push_back(nType); - if (ptype->GetKind() == kTypePointer) { - MIRPtrType *pty = static_cast(ptype); - if (pty->GetPrimType() == PTY_ptr) { - ptrTypeMap[pty->GetPointedTyIdx()] = ntype->GetTypeIndex(); + if (pType.IsMIRPtrType()) { + MIRPtrType &pty = static_cast(pType); + if (pty.GetPrimType() == PTY_ptr) { + ptrTypeMap[pty.GetPointedTyIdx()] = nType->GetTypeIndex(); } else { - refTypeMap[pty->GetPointedTyIdx()] = ntype->GetTypeIndex(); + refTypeMap[pty.GetPointedTyIdx()] = nType->GetTypeIndex(); } } else { - typeHashTable.insert(ntype); + typeHashTable.insert(nType); } - return ntype; -} - -MIRType* TypeTable::GetOrCreateMIRTypeNode(MIRType *ptype) { - if (ptype->GetKind() == kTypePointer) { - MIRPtrType *type = static_cast(ptype); - auto *pMap = (type->GetPrimType() == PTY_ptr ? &ptrTypeMap : &refTypeMap); - auto *otherPMap = (type->GetPrimType() == PTY_ref ? &ptrTypeMap : &refTypeMap); - auto it = pMap->find(type->GetPointedTyIdx()); - if (it != pMap->end()) { - return GetTypeFromTyIdx(it->second); + return nType; +} + +MIRType* TypeTable::GetOrCreateMIRTypeNode(MIRType &pType) { + if (pType.IsMIRPtrType()) { + auto &type = static_cast(pType); + auto *pMap = (type.GetPrimType() == PTY_ptr ? &ptrTypeMap : &refTypeMap); + auto *otherPMap = (type.GetPrimType() == PTY_ref ? &ptrTypeMap : &refTypeMap); + { + const auto it = pMap->find(type.GetPointedTyIdx()); + if (it != pMap->end()) { + return GetTypeFromTyIdx(it->second); + } } - CHECK_FATAL(!((PrimType)(type->GetPointedTyIdx().GetIdx()) >= kPtyDerived && type->GetPrimType() == PTY_ref && - otherPMap->find(type->GetPointedTyIdx()) != otherPMap->end()), "GetOrCreateMIRType: ref pointed-to type %d has previous ptr occurrence", type->GetPointedTyIdx().GetIdx()); - return CreateAndUpdateMirTypeNode(ptype); + CHECK_FATAL(!(type.GetPointedTyIdx().GetIdx() >= kPtyDerived && type.GetPrimType() == PTY_ref && + otherPMap->find(type.GetPointedTyIdx()) != otherPMap->end()), + "GetOrCreateMIRType: ref pointed-to type %d has previous ptr occurrence", + type.GetPointedTyIdx().GetIdx()); + return CreateAndUpdateMirTypeNode(pType); } - - auto it = typeHashTable.find(ptype); - if (it != typeHashTable.end()) { - return *it; + { + const auto it = typeHashTable.find(&pType); + if (it != typeHashTable.end()) { + return *it; + } } - return CreateAndUpdateMirTypeNode(ptype); + return CreateAndUpdateMirTypeNode(pType); } MIRType *TypeTable::voidPtrType = nullptr; diff --git a/src/maple_ir/src/mir_symbol_builder.cpp b/src/maple_ir/src/mir_symbol_builder.cpp index 48dc386b42151e970b4987460779c20777a07cdd..f396114ed50bc132b0849e686fe0340badd60e45 100644 --- a/src/maple_ir/src/mir_symbol_builder.cpp +++ b/src/maple_ir/src/mir_symbol_builder.cpp @@ -88,7 +88,7 @@ MIRSymbol *MIRSymbolBuilder::GetSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind m MIRSymbol *MIRSymbolBuilder::CreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass, MIRFunction *func, uint8 scpID) const { MIRSymbol *st = - func != nullptr ? func->GetSymTab()->CreateSymbol(scpID) : GlobalTables::GetGsymTable().CreateSymbol(scpID); + (func != nullptr) ? func->GetSymTab()->CreateSymbol(scpID) : GlobalTables::GetGsymTable().CreateSymbol(scpID); CHECK_FATAL(st != nullptr, "Failed to create MIRSymbol"); st->SetStorageClass(sClass); st->SetSKind(mClass); diff --git a/src/maple_ir/src/option.cpp b/src/maple_ir/src/option.cpp index 197faf9b558a1dbdfc08d4c849ba9d38618716a0..79843c750e959f918f0925117db65459a4e4980d 100644 --- a/src/maple_ir/src/option.cpp +++ b/src/maple_ir/src/option.cpp @@ -486,8 +486,7 @@ void Options::DecideMpl2MplRealLevel(const std::vector &inp } } -bool Options::SolveOptions(const std::vector