diff --git a/src/mapleall/bin/dex2mpl_android b/src/mapleall/bin/dex2mpl_android index c82f201abf066f8fe2c36ed1b30877337cff6d8a..8dab0112a8b02d67120142358e28254bf9f548f1 100755 Binary files a/src/mapleall/bin/dex2mpl_android and b/src/mapleall/bin/dex2mpl_android differ diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h index d6b86cfca29364a290c8e3f9cc1b3132fb83240f..db53899070230fdf1ab240248b656398617804b0 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h @@ -91,7 +91,7 @@ class AArch64CGFunc : public CGFunc { void SelectDassign(DassignNode &stmt, Operand &opnd0) override; void SelectRegassign(RegassignNode &stmt, Operand &opnd0) override; void SelectAssertNull(UnaryStmtNode &stmt) override; - Operand &GenLargeAggFormalMemOpnd(const MIRSymbol &sym, uint32 alignUsed, int32 offset); + AArch64MemOperand &GenLargeAggFormalMemOpnd(const MIRSymbol &sym, uint32 alignUsed, int32 offset); void SelectAggDassign(DassignNode &stmt) override; void SelectIassign(IassignNode &stmt) override; void SelectAggIassign(IassignNode &stmt, Operand &lhsAddrOpnd) override; diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 2fca02d1698c2e129686fce1a5a30252600a29dc..c736c15c54a1f86542404fba89e4ae600524250d 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -995,8 +995,8 @@ void AArch64CGFunc::SelectRegassign(RegassignNode &stmt, Operand &opnd0) { } } -Operand &AArch64CGFunc::GenLargeAggFormalMemOpnd(const MIRSymbol &sym, uint32 align, int32 offset) { - Operand *memOpnd; +AArch64MemOperand &AArch64CGFunc::GenLargeAggFormalMemOpnd(const MIRSymbol &sym, uint32 align, int32 offset) { + MemOperand *memOpnd; if (sym.GetStorageClass() == kScFormal && GetBecommon().GetTypeSize(sym.GetTyIdx()) > k16ByteSize) { /* formal of size of greater than 16 is copied by the caller and the pointer to it is passed. */ /* otherwise it is passed in register and is accessed directly. */ @@ -1009,7 +1009,7 @@ Operand &AArch64CGFunc::GenLargeAggFormalMemOpnd(const MIRSymbol &sym, uint32 al } else { memOpnd = &GetOrCreateMemOpnd(sym, offset, align * kBitsPerByte); } - return *memOpnd; + return *(static_cast(memOpnd)); } void AArch64CGFunc::SelectAggDassign(DassignNode &stmt) { @@ -1055,9 +1055,13 @@ void AArch64CGFunc::SelectAggDassign(DassignNode &stmt) { GetCurBB()->AppendInsn(GetCG()->BuildInstruction(PickLdInsn(alignUsed * k8BitSize, PTY_u32), result, *rhsMemOpnd)); /* generate the store */ - Operand &lhsMemOpnd = GenLargeAggFormalMemOpnd(*lhsSymbol, alignUsed, (lhsOffset + i * alignUsed)); + AArch64MemOperand *lhsMemOpnd = &GenLargeAggFormalMemOpnd(*lhsSymbol, alignUsed, (lhsOffset + i * alignUsed)); + if ((lhsMemOpnd->GetMemVaryType() == kNotVary) && + IsImmediateOffsetOutOfRange(*lhsMemOpnd, alignUsed * kBitsPerByte)) { + lhsMemOpnd = &SplitOffsetWithAddInstruction(*lhsMemOpnd, alignUsed * k8BitSize); + } GetCurBB()->AppendInsn(GetCG()->BuildInstruction(PickStInsn(alignUsed * k8BitSize, PTY_u32), - result, lhsMemOpnd)); + result, *lhsMemOpnd)); } /* take care of extra content at the end less than the unit of alignUsed */ uint64 lhsSizeCovered = (lhsSize / alignUsed) * alignUsed; @@ -2364,6 +2368,7 @@ void AArch64CGFunc::SelectCondGoto(CondGotoNode &stmt, Operand &opnd0, Operand & void AArch64CGFunc::SelectGoto(GotoNode &stmt) { Operand &targetOpnd = GetOrCreateLabelOperand(stmt.GetOffset()); GetCurBB()->AppendInsn(GetCG()->BuildInstruction(MOP_xuncond, targetOpnd)); + GetCurBB()->SetKind(BB::kBBGoto); } Operand *AArch64CGFunc::SelectAdd(BinaryNode &node, Operand &opnd0, Operand &opnd1) { diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_dependence.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_dependence.cpp index ba3790b5cd9f0137e407b407c7a9af12cf4022a8..b4e38bf6834bd6b40a407d682af8747298411d71 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_dependence.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_dependence.cpp @@ -407,18 +407,19 @@ void AArch64DepAnalysis::BuildDepsUseMem(Insn &insn, MemOperand &memOpnd) { RegOperand *baseRegister = memOpnd.GetBaseRegister(); AArch64MemOperand &aarchMemOpnd = static_cast(memOpnd); AArch64MemOperand *nextMemOpnd = GetNextMemOperand(insn, aarchMemOpnd); - if (((baseRegister != nullptr) && IsFrameReg(*baseRegister)) || aarchMemOpnd.IsStackMem()) { - /* Stack memory address */ - for (auto defInsn : stackDefs) { - if (defInsn->IsCall() || NeedBuildDepsMem(aarchMemOpnd, nextMemOpnd, *defInsn)) { - AddDependence(*defInsn->GetDepNode(), *insn.GetDepNode(), kDependenceTypeTrue); - continue; - } + + /* Stack memory address */ + for (auto defInsn : stackDefs) { + if (defInsn->IsCall() || NeedBuildDepsMem(aarchMemOpnd, nextMemOpnd, *defInsn)) { + AddDependence(*defInsn->GetDepNode(), *insn.GetDepNode(), kDependenceTypeTrue); + continue; } + } + /* Heap memory */ + AddDependence4InsnInVectorByType(heapDefs, insn, kDependenceTypeTrue); + if (((baseRegister != nullptr) && IsFrameReg(*baseRegister)) || aarchMemOpnd.IsStackMem()) { stackUses.emplace_back(&insn); } else { - /* Heap memory */ - AddDependence4InsnInVectorByType(heapDefs, insn, kDependenceTypeTrue); heapUses.emplace_back(&insn); } if (memBarInsn != nullptr) { @@ -479,26 +480,28 @@ void AArch64DepAnalysis::BuildDepsDefMem(Insn &insn, MemOperand &memOpnd) { AArch64MemOperand &aarchMemOpnd = static_cast(memOpnd); AArch64MemOperand *nextMemOpnd = GetNextMemOperand(insn, aarchMemOpnd); - if (((baseRegister != nullptr) && IsFrameReg(*baseRegister)) || aarchMemOpnd.IsStackMem()) { - /* Build anti dependences. */ - BuildAntiDepsDefStackMem(insn, aarchMemOpnd, nextMemOpnd); - /* Build output depnedence. */ - BuildOutputDepsDefStackMem(insn, aarchMemOpnd, nextMemOpnd); - if (lastCallInsn != nullptr) { - /* Build a dependence between stack passed arguments and call. */ - ASSERT(baseRegister != nullptr, "baseRegister shouldn't be null here"); - if (baseRegister->GetRegisterNumber() == RSP) { - AddDependence(*lastCallInsn->GetDepNode(), *insn.GetDepNode(), kDependenceTypeControl); - } + /* Build anti dependences. */ + BuildAntiDepsDefStackMem(insn, aarchMemOpnd, nextMemOpnd); + /* Build output depnedence. */ + BuildOutputDepsDefStackMem(insn, aarchMemOpnd, nextMemOpnd); + if (lastCallInsn != nullptr) { + /* Build a dependence between stack passed arguments and call. */ + ASSERT(baseRegister != nullptr, "baseRegister shouldn't be null here"); + if (baseRegister->GetRegisterNumber() == RSP) { + AddDependence(*lastCallInsn->GetDepNode(), *insn.GetDepNode(), kDependenceTypeControl); } + } + + /* Heap memory + * Build anti dependences. + */ + AddDependence4InsnInVectorByType(heapUses, insn, kDependenceTypeAnti); + /* Build output depnedence. */ + AddDependence4InsnInVectorByType(heapDefs, insn, kDependenceTypeOutput); + + if (((baseRegister != nullptr) && IsFrameReg(*baseRegister)) || aarchMemOpnd.IsStackMem()) { stackDefs.emplace_back(&insn); } else { - /* Heap memory - * Build anti dependences. - */ - AddDependence4InsnInVectorByType(heapUses, insn, kDependenceTypeAnti); - /* Build output depnedence. */ - AddDependence4InsnInVectorByType(heapDefs, insn, kDependenceTypeOutput); heapDefs.emplace_back(&insn); } if (memBarInsn != nullptr) { diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_peep.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_peep.cpp index 57936b3600d19938a33b24c72a3012061f7b8609..0584b99103c57be991a72947a201612089a7530c 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_peep.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_peep.cpp @@ -1908,7 +1908,6 @@ void RemoveIncRefAArch64::Run(BB &bb, Insn &insn) { bb.RemoveInsn(insn); bb.RemoveInsn(*insnMov2); bb.RemoveInsn(*insnMov1); - bb.SetKind(BB::kBBFallthru); } bool LongIntCompareWithZAArch64::FindLondIntCmpWithZ(std::vector &optInsn, Insn &insn) { diff --git a/src/mapleall/maple_driver/defs/phases.def b/src/mapleall/maple_driver/defs/phases.def index 9a81103ebfd261baaf2b9072d07409d1364cedd7..1d7c88cca7635e7ed1538ea4d008ab193d324c51 100644 --- a/src/mapleall/maple_driver/defs/phases.def +++ b/src/mapleall/maple_driver/defs/phases.def @@ -42,7 +42,7 @@ ADD_PHASE("stmtpre", JAVALANG && MeOption::optLevel == 2) ADD_PHASE("analyzerc", JAVALANG && MeOption::optLevel == 2) ADD_PHASE("rclowering", JAVALANG) ADD_PHASE("rename2preg", MeOption::optLevel == 2) -//ADD_PHASE("lpre", MeOption::optLevel == 2) +ADD_PHASE("lpre", MeOption::optLevel == 2) ADD_PHASE("pregrename", MeOption::optLevel == 2) ADD_PHASE("bblayout", MeOption::optLevel == 2 || JAVALANG) ADD_PHASE("emit", MeOption::optLevel == 2 || JAVALANG) diff --git a/src/mapleall/maple_ipa/include/inline.h b/src/mapleall/maple_ipa/include/inline.h index 922e599323eb682fce9c77ebc708cf39d81386c0..6640bf5badf43ac8b70999a76d5f7d64cae3364a 100644 --- a/src/mapleall/maple_ipa/include/inline.h +++ b/src/mapleall/maple_ipa/include/inline.h @@ -31,7 +31,7 @@ constexpr char kCommentsignStr[] = "#"; constexpr char kHyphenStr[] = "-"; constexpr char kAppointStr[] = "->"; constexpr char kUnderlineStr[] = "_"; -constexpr char kVerticalLineStr[] = "|"; +constexpr char kVerticalLineStr[] = "__"; constexpr char kNumberZeroStr[] = "0"; constexpr char kReturnlocStr[] = "return_loc_"; constexpr char kThisStr[] = "_this"; diff --git a/src/mapleall/maple_ipa/src/inline.cpp b/src/mapleall/maple_ipa/src/inline.cpp index 730fc8d31c6bc874a897b576b47e644ded7a1ee2..d570d0a7e52b7a592066d55e98e73c17fa569b69 100644 --- a/src/mapleall/maple_ipa/src/inline.cpp +++ b/src/mapleall/maple_ipa/src/inline.cpp @@ -650,14 +650,17 @@ bool MInline::PerformInline(MIRFunction &caller, BlockNode &enclosingBlk, CallNo ReplacePregs(newBody, pregOld2New); // Step 4: Null check 'this' and assign actuals to formals. if (static_cast(callStmt.NumOpnds()) != callee.GetFormalCount()) { - CHECK_FATAL(false, "# formal arguments != # actual arguments"); + LogInfo::MapleLogger() << "warning: # formal arguments != # actual arguments in the function " << + callee.GetName() << "\n"; } if (callee.GetFormalCount() > 0 && callee.GetFormal(0)->GetName() == kThisStr) { UnaryStmtNode *nullCheck = module.CurFuncCodeMemPool()->New(OP_assertnonnull); nullCheck->SetOpnd(callStmt.Opnd(0), 0); newBody->InsertBefore(newBody->GetFirst(), nullCheck); } - for (size_t i = 0; i < callStmt.NumOpnds(); ++i) { + // The number of formals and realArg are not always equal + size_t realArgNum = std::min(callStmt.NumOpnds(), callee.GetFormalCount()); + for (size_t i = 0; i < realArgNum; ++i) { BaseNode *currBaseNode = callStmt.Opnd(i); MIRSymbol *formal = callee.GetFormal(i); if (formal->IsPreg()) { @@ -667,6 +670,12 @@ bool MInline::PerformInline(MIRFunction &caller, BlockNode &enclosingBlk, CallNo newBody->InsertBefore(newBody->GetFirst(), regAssign); } else { MIRSymbol *newFormal = caller.GetSymTab()->GetSymbolFromStIdx(formal->GetStIndex() + stIdxOff); + PrimType formalPrimType = newFormal->GetType()->GetPrimType(); + PrimType realArgPrimType = currBaseNode->GetPrimType(); + // If realArg's type is different from formal's type, use cvt + if (formalPrimType != realArgPrimType) { + currBaseNode = builder.CreateExprTypeCvt(OP_cvt, formalPrimType, realArgPrimType, *currBaseNode); + } DassignNode *stmt = builder.CreateStmtDassign(*newFormal, 0, currBaseNode); newBody->InsertBefore(newBody->GetFirst(), stmt); } @@ -916,6 +925,8 @@ FuncCostResultType MInline::GetFuncCost(const MIRFunction &func, const BaseNode cost += kPentupleInsn; } else if (id == INTRN_MPL_READ_OVTABLE_ENTRY) { cost += kDoubleInsn; + } else if (id == INTRN_C_ctz32 || id == INTRN_C_clz32 || id == INTRN_C_constant_p) { + cost += kOneInsn; } else { CHECK_FATAL(false, "[IMPOSSIBLE] %s", func.GetName().c_str()); cost += kQuadrupleInsn; diff --git a/src/mapleall/maple_me/include/alias_class.h b/src/mapleall/maple_me/include/alias_class.h index 7d78d8ad2b1c0dd2f7938072cae43e3dd876b26f..18c6beb982c1ad2982743f4bc915d6076c9656ce 100644 --- a/src/mapleall/maple_me/include/alias_class.h +++ b/src/mapleall/maple_me/include/alias_class.h @@ -192,7 +192,8 @@ class AliasClass : public AnalysisResult { bool IsPointedTo(OriginalSt &oSt); AliasElem &FindOrCreateAliasElemOfAddrofOSt(OriginalSt &oSt); void CollectMayDefForMustDefs(const StmtNode &stmt, std::set &mayDefOsts); - void CollectMayUseForNextLevel(OriginalSt *ost, std::set &mayUseOsts, const StmtNode &stmt, bool isFirstOpnd); + void CollectMayUseForNextLevel(const OriginalSt *ost, std::set &mayUseOsts, + const StmtNode &stmt, bool isFirstOpnd); void CollectMayUseForCallOpnd(const StmtNode &stmt, std::set &mayUseOsts); void InsertMayDefNodeForCall(std::set &mayDefOsts, TypeOfMayDefList &mayDefNodes, StmtNode &stmt, BBId bbid, bool hasNoPrivateDefEffect); diff --git a/src/mapleall/maple_me/src/alias_class.cpp b/src/mapleall/maple_me/src/alias_class.cpp index 6e8593622ac99eb40bc0d7710140d439c15a9016..259a6a8e0bd6aa35b7c44339390ace80a5cbfa34 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -159,7 +159,8 @@ AliasElem *AliasClass::FindOrCreateExtraLevAliasElem(BaseNode &expr, TyIdx tyIdx return nullptr; } } else if (ainfo.ae == nullptr || - (fieldId && ainfo.ae->GetOriginalSt().GetIndirectLev() != -1 && ainfo.ae->GetOriginalSt().GetTyIdx() != tyIdx)) { + (fieldId && ainfo.ae->GetOriginalSt().GetIndirectLev() != -1 && + ainfo.ae->GetOriginalSt().GetTyIdx() != tyIdx)) { return FindOrCreateDummyNADSAe(); } OriginalSt *newOst = nullptr; @@ -471,7 +472,8 @@ void AliasClass::ApplyUnionForPointedTos() { // first, process nextLevNotAllDefsSeen for alias elems for (AliasElem *aliaselem : id2Elem) { if (aliaselem->IsNextLevNotAllDefsSeen()) { - MapleVector *nextLevelNodes = GetAliasAnalysisTable()->GetNextLevelNodes(aliaselem->GetOriginalSt()); + MapleVector *nextLevelNodes = + GetAliasAnalysisTable()->GetNextLevelNodes(aliaselem->GetOriginalSt()); MapleVector::iterator ostit = nextLevelNodes->begin(); for (; ostit != nextLevelNodes->end(); ++ostit) { AliasElem *indae = FindAliasElem(**ostit); @@ -485,7 +487,8 @@ void AliasClass::ApplyUnionForPointedTos() { // do one more time to ensure proper propagation for (AliasElem *aliaselem : id2Elem) { if (aliaselem->IsNextLevNotAllDefsSeen()) { - MapleVector *nextLevelNodes = GetAliasAnalysisTable()->GetNextLevelNodes(aliaselem->GetOriginalSt()); + MapleVector *nextLevelNodes = + GetAliasAnalysisTable()->GetNextLevelNodes(aliaselem->GetOriginalSt()); MapleVector::iterator ostit = nextLevelNodes->begin(); for (; ostit != nextLevelNodes->end(); ++ostit) { AliasElem *indae = FindAliasElem(**ostit); @@ -1366,7 +1369,8 @@ void AliasClass::CollectMayDefForMustDefs(const StmtNode &stmt, std::set &mayUseOsts, const StmtNode &stmt, bool isFirstOpnd) { +void AliasClass::CollectMayUseForNextLevel(const OriginalSt *ost, std::set &mayUseOsts, + const StmtNode &stmt, bool isFirstOpnd) { for (OriginalSt *nextLevelOst : *(GetAliasAnalysisTable()->GetNextLevelNodes(*ost))) { AliasElem *indAe = FindAliasElem(*nextLevelOst); @@ -1416,7 +1420,7 @@ void AliasClass::CollectMayUseForCallOpnd(const StmtNode &stmt, std::setIsNextLevNotAllDefsSeen() && aInfo.ae->GetOriginalSt().GetIndirectLev() > 0)) { continue; } diff --git a/src/mapleall/maple_me/src/irmap.cpp b/src/mapleall/maple_me/src/irmap.cpp index 1e710bb9fa4de927233cb773c867b705d17c6d5c..dfe805bfed05bf72f548dfff7c0763356dff2970 100644 --- a/src/mapleall/maple_me/src/irmap.cpp +++ b/src/mapleall/maple_me/src/irmap.cpp @@ -589,7 +589,11 @@ MeExpr *IRMap::SimplifyOpMeExpr(OpMeExpr *opmeexpr) { maple::IsPrimitiveInteger(cvtopnd0->GetOpnd(0)->GetPrimType())) || (maple::IsPrimitiveFloat(cvtopnd0->GetPrimType()) && maple::IsPrimitiveFloat(cvtopnd0->GetOpnd(0)->GetPrimType()))) { - return CreateMeExprTypeCvt(cvtmeexpr->GetPrimType(), cvtopnd0->GetOpndType(), *cvtopnd0->GetOpnd(0)); + if (cvtmeexpr->GetPrimType() == cvtopnd0->GetOpndType()) { + return cvtopnd0->GetOpnd(0); + } else { + return CreateMeExprTypeCvt(cvtmeexpr->GetPrimType(), cvtopnd0->GetOpndType(), *cvtopnd0->GetOpnd(0)); + } } } if (maple::GetPrimTypeSize(cvtopnd0->GetPrimType()) >= maple::GetPrimTypeSize(cvtmeexpr->GetPrimType())) { diff --git a/src/mapleall/maple_me/src/me_store_pre.cpp b/src/mapleall/maple_me/src/me_store_pre.cpp index 57fea929c055b49e214775b5e5b8d5ecaaee0caf..3b3e5e42caa4bd272eb12c28239506c9b5c6266a 100644 --- a/src/mapleall/maple_me/src/me_store_pre.cpp +++ b/src/mapleall/maple_me/src/me_store_pre.cpp @@ -193,6 +193,15 @@ void MeStorePre::CodeMotion() { // ================ Step 0: collect occurrences ================ // create a new real occurrence for the store of meStmt of symbol oidx void MeStorePre::CreateRealOcc(const OStIdx &ostIdx, MeStmt &meStmt) { + // skip vars with alias until we can deal with chi + if (ostIdx >= aliasClass->GetAliasElemCount()) { + return; + } + AliasElem *ae = aliasClass->FindAliasElem(*ssaTab->GetSymbolOriginalStFromID(ostIdx)); + if (ae->GetClassSet() != nullptr) { + return; + } + SpreWorkCand *wkCand = nullptr; auto mapIt = workCandMap.find(ostIdx); if (mapIt != workCandMap.end()) { @@ -201,9 +210,9 @@ void MeStorePre::CreateRealOcc(const OStIdx &ostIdx, MeStmt &meStmt) { OriginalSt *ost = ssaTab->GetSymbolOriginalStFromID(ostIdx); wkCand = spreMp->New(spreAllocator, *ost); workCandMap[ostIdx] = wkCand; - // if it is local symbol, insert artificial real occ at common_exit_bb + // if it is local symbol, insert artificial use occ at common_exit_bb if (ost->IsLocal()) { - SRealOcc *artOcc = spreMp->New(*func->GetCommonExitBB()); + SUseOcc *artOcc = spreMp->New(*func->GetCommonExitBB()); wkCand->GetRealOccs().push_back(artOcc); } } @@ -245,17 +254,7 @@ void MeStorePre::CreateSpreUseOccsThruAliasing(const OriginalSt &muOst, BB &bb) if (muOst.GetIndex() >= aliasClass->GetAliasElemCount()) { return; } - AliasElem *ae = aliasClass->FindAliasElem(muOst); - if (ae->GetClassSet() == nullptr) { - return; - } - for (auto setIt = ae->GetClassSet()->begin(); setIt != ae->GetClassSet()->end(); ++setIt) { - unsigned int elemId = *setIt; - AliasElem *ae0 = aliasClass->FindID2Elem(elemId); - if (ae0->GetOriginalSt().GetIndirectLev() == 0) { - CreateUseOcc(ae0->GetOriginalSt().GetIndex(), bb); - } - } + CreateUseOcc(muOst.GetIndex(), bb); } void MeStorePre::FindAndCreateSpreUseOccs(const MeExpr &meExpr, BB &bb) const { diff --git a/src/mapleall/mpl2mpl/src/constantfold.cpp b/src/mapleall/mpl2mpl/src/constantfold.cpp index cddbad61c5eb42fd1e4de2f62563a690cb70d523..03ce7218861172ec3b23025e1b6b79e9ae5fdd99 100644 --- a/src/mapleall/mpl2mpl/src/constantfold.cpp +++ b/src/mapleall/mpl2mpl/src/constantfold.cpp @@ -1329,7 +1329,7 @@ MIRConst *ConstantFold::FoldTypeCvtMIRConst(const MIRConst &cst, PrimType fromTy uint32 toSize = GetPrimTypeBitSize(toType); if (toSize > fromSize) { Opcode op = OP_zext; - if (IsSignedInteger(toType) && IsSignedInteger(fromType)) { + if (IsSignedInteger(fromType)) { op = OP_sext; } toConst = FoldSignExtendMIRConst(op, toType, fromSize, cst); diff --git a/src/mplfe/ast_input/src/ast_expr.cpp b/src/mplfe/ast_input/src/ast_expr.cpp index bb222912ad17973a306f22436c5bc392fd820500..b9f86fab0a293ed12dadc7d5e1be79ef3f244516 100644 --- a/src/mplfe/ast_input/src/ast_expr.cpp +++ b/src/mplfe/ast_input/src/ast_expr.cpp @@ -511,6 +511,7 @@ UniqueFEIRExpr ASTMemberExpr::Emit2FEExprImpl(std::list &stmts) } auto dread = std::make_unique(std::move(tmpVar)); dread->SetFieldName(memberName); + dread->SetFieldType(memberType); return dread; } } diff --git a/src/mplfe/common/include/feir_stmt.h b/src/mplfe/common/include/feir_stmt.h index 1ff7d0231ad8240927d9a9b03e0a102b7e129d89..84dcfc510316d47ea70d6a4b2d0868bf9679e19a 100644 --- a/src/mplfe/common/include/feir_stmt.h +++ b/src/mplfe/common/include/feir_stmt.h @@ -410,15 +410,23 @@ class FEIRExprDRead : public FEIRExpr { return varSrc; } - void SetFieldName(const std::string &argFieldName){ + void SetFieldName(const std::string &argFieldName) { fieldName = argFieldName; } - std::string GetFieldName(){ + std::string GetFieldName() const { return fieldName; } - void SetFieldID(FieldID argFieldID){ + void SetFieldType(MIRType *type) { + fieldType = type; + } + + MIRType *GetFieldType() const { + return fieldType; + } + + void SetFieldID(FieldID argFieldID) { fieldID = argFieldID; } @@ -433,6 +441,7 @@ class FEIRExprDRead : public FEIRExpr { std::unique_ptr varSrc; FieldID fieldID = 0; std::string fieldName; + MIRType *fieldType; }; // ---------- FEIRExprRegRead ---------- diff --git a/src/mplfe/common/src/feir_stmt.cpp b/src/mplfe/common/src/feir_stmt.cpp index 3712714a349f17895e478c88e294f8e64bcee3fc..85543e475d2cb0bd51c4e8afae3418067a17eb06 100644 --- a/src/mplfe/common/src/feir_stmt.cpp +++ b/src/mplfe/common/src/feir_stmt.cpp @@ -1991,7 +1991,7 @@ BaseNode *FEIRExprDRead::GenMIRNodeImpl(MIRBuilder &mirBuilder) const { if (fieldIdVar == 0) { fieldIdVar = mirBuilder.GetStructFieldIDFromFieldName(*type, fieldName); } - node = mirBuilder.CreateExprDread(*type, fieldIdVar, *symbol); + node = mirBuilder.CreateExprDread(*fieldType, fieldIdVar, *symbol); } return node; }