diff --git a/src/mapleall/maple_ipa/include/inline.h b/src/mapleall/maple_ipa/include/inline.h index 6640bf5badf43ac8b70999a76d5f7d64cae3364a..de4104c382a1a341e6fac321d3f842ddeb5b68db 100644 --- a/src/mapleall/maple_ipa/include/inline.h +++ b/src/mapleall/maple_ipa/include/inline.h @@ -68,14 +68,13 @@ enum ThresholdType { class MInline { public: - MInline(MIRModule &mod, MemPool *memPool, KlassHierarchy *kh = nullptr, CallGraph *cg = nullptr) + MInline(MIRModule &mod, MemPool *memPool, CallGraph *cg = nullptr) : alloc(memPool), module(mod), builder(*mod.GetMIRBuilder()), inlineTimesMap(std::less(), alloc.Adapter()), recursiveFuncToInlineLevel(alloc.Adapter()), funcToCostMap(alloc.Adapter()), - klassHierarchy(kh), cg(cg), excludedCaller(alloc.Adapter()), excludedCallee(alloc.Adapter()), @@ -100,7 +99,6 @@ class MInline { // store recursive function's inlining levels, and allow inline 4 levels at most. MapleMap recursiveFuncToInlineLevel; MapleMap funcToCostMap; // save the cost of calculated func to reduce the amount of calculation - KlassHierarchy *klassHierarchy; CallGraph *cg; private: diff --git a/src/mapleall/maple_ipa/src/inline.cpp b/src/mapleall/maple_ipa/src/inline.cpp index d570d0a7e52b7a592066d55e98e73c17fa569b69..1e05701f2de022b4488655c139291822aa853c7c 100644 --- a/src/mapleall/maple_ipa/src/inline.cpp +++ b/src/mapleall/maple_ipa/src/inline.cpp @@ -1403,12 +1403,10 @@ void MInline::MarkUsedSymbols(const BaseNode *baseNode) const { // Unified interface to run inline module phase. AnalysisResult *DoInline::Run(MIRModule *module, ModuleResultMgr *mgr) { MemPool *memPool = memPoolCtrler.NewMemPool("inline mempool", false /* isLocalPool */); - KlassHierarchy *klassHierarchy = static_cast(mgr->GetAnalysisResult(MoPhase_CHA, module)); - CHECK_FATAL(klassHierarchy != nullptr, "Expecting a valid KlassHierarchy, found nullptr"); CallGraph *cg = static_cast(mgr->GetAnalysisResult(MoPhase_CALLGRAPH_ANALYSIS, module)); CHECK_FATAL(cg != nullptr, "Expecting a valid CallGraph, found nullptr"); - MInline mInline(*module, memPool, klassHierarchy, cg); + MInline mInline(*module, memPool, cg); mInline.Inline(); mInline.CleanupInline(); mgr->InvalidAnalysisResult(MoPhase_CALLGRAPH_ANALYSIS, module); diff --git a/src/mapleall/maple_me/include/me_store_pre.h b/src/mapleall/maple_me/include/me_store_pre.h index 8e1c2d2727d63946e5c076ccef2ba53c3d21a050..783e4e6d9449ef7e408bf9376aa7bff20a133186 100644 --- a/src/mapleall/maple_me/include/me_store_pre.h +++ b/src/mapleall/maple_me/include/me_store_pre.h @@ -36,9 +36,9 @@ class MeStorePre : public MeSSUPre { void CodeMotion(); // step 0 methods void CreateRealOcc(const OStIdx &ostIdx, MeStmt &meStmt); - void CreateUseOcc(const OStIdx &ostIdx, BB &bb) const; - void CreateSpreUseOccsThruAliasing(const OriginalSt &muOst, BB &bb) const; - void FindAndCreateSpreUseOccs(const MeExpr &meExpr, BB &bb) const; + void CreateUseOcc(const OStIdx &ostIdx, BB &bb); + void CreateSpreUseOccsThruAliasing(const OriginalSt &muOst, BB &bb); + void FindAndCreateSpreUseOccs(const MeExpr &meExpr, BB &bb); void CreateSpreUseOccsForAll(BB &bb) const; void BuildWorkListBB(BB *bb); void PerCandInit() { diff --git a/src/mapleall/maple_me/src/me_store_pre.cpp b/src/mapleall/maple_me/src/me_store_pre.cpp index 3b3e5e42caa4bd272eb12c28239506c9b5c6266a..f69e9829e185b37e39c242ffea283b80ad382751 100644 --- a/src/mapleall/maple_me/src/me_store_pre.cpp +++ b/src/mapleall/maple_me/src/me_store_pre.cpp @@ -212,7 +212,7 @@ void MeStorePre::CreateRealOcc(const OStIdx &ostIdx, MeStmt &meStmt) { workCandMap[ostIdx] = wkCand; // if it is local symbol, insert artificial use occ at common_exit_bb if (ost->IsLocal()) { - SUseOcc *artOcc = spreMp->New(*func->GetCommonExitBB()); + SRealOcc *artOcc = spreMp->New(*func->GetCommonExitBB()); wkCand->GetRealOccs().push_back(artOcc); } } @@ -233,31 +233,42 @@ void MeStorePre::CreateRealOcc(const OStIdx &ostIdx, MeStmt &meStmt) { } // create a new use occurrence for symbol oidx in given bb -void MeStorePre::CreateUseOcc(const OStIdx &ostIdx, BB &bb) const { +void MeStorePre::CreateUseOcc(const OStIdx &ostIdx, BB &bb) { SpreWorkCand *wkCand = nullptr; auto mapIt = workCandMap.find(ostIdx); if (mapIt == workCandMap.end()) { - return; + 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 (ost->IsLocal()) { + SRealOcc *artOcc = spreMp->New(*func->GetCommonExitBB()); + wkCand->GetRealOccs().push_back(artOcc); + } + } else { + wkCand = mapIt->second; } - wkCand = mapIt->second; - CHECK_FATAL(!wkCand->GetRealOccs().empty(), "empty container check"); - SOcc *lastOcc = wkCand->GetRealOccs().back(); - if (lastOcc->GetOccTy() == kSOccUse && &lastOcc->GetBB() == &bb) { - return; // no need to push consecutive use occurrences at same BB + + if (!wkCand->GetRealOccs().empty()) { + SOcc *lastOcc = wkCand->GetRealOccs().back(); + if (lastOcc->GetOccTy() == kSOccUse && &lastOcc->GetBB() == &bb) { + return; // no need to push consecutive use occurrences at same BB + } } + SUseOcc *newOcc = spreMp->New(bb); wkCand->GetRealOccs().push_back(newOcc); } // create use occurs for all the symbols that alias with muost -void MeStorePre::CreateSpreUseOccsThruAliasing(const OriginalSt &muOst, BB &bb) const { +void MeStorePre::CreateSpreUseOccsThruAliasing(const OriginalSt &muOst, BB &bb) { if (muOst.GetIndex() >= aliasClass->GetAliasElemCount()) { return; } CreateUseOcc(muOst.GetIndex(), bb); } -void MeStorePre::FindAndCreateSpreUseOccs(const MeExpr &meExpr, BB &bb) const { +void MeStorePre::FindAndCreateSpreUseOccs(const MeExpr &meExpr, BB &bb) { if (meExpr.GetMeOp() == kMeOpVar) { auto *var = static_cast(&meExpr); const OriginalSt *ost = var->GetOst(); diff --git a/src/mapleall/mpl2mpl/include/constantfold.h b/src/mapleall/mpl2mpl/include/constantfold.h index 0bf8d497a0775c36977b71a6a67618e434f91cd8..5296c05d19d0b60591ec070b15fa99ee26a61d1c 100644 --- a/src/mapleall/mpl2mpl/include/constantfold.h +++ b/src/mapleall/mpl2mpl/include/constantfold.h @@ -47,7 +47,7 @@ class ConstantFold : public FuncOptimizeImpl { virtual ~ConstantFold() = default; template T CalIntValueFromFloatValue(T value, const MIRType &resultType) const; - MIRConst *FoldFloorMIRConst(const MIRConst&, PrimType, PrimType) const; + MIRConst *FoldFloorMIRConst(const MIRConst&, PrimType, PrimType, bool isFloor = true) const; MIRConst *FoldRoundMIRConst(const MIRConst&, PrimType, PrimType) const; MIRConst *FoldTypeCvtMIRConst(const MIRConst&, PrimType, PrimType) const; MIRConst *FoldSignExtendMIRConst(Opcode, PrimType, uint8, const MIRConst&) const; diff --git a/src/mapleall/mpl2mpl/src/constantfold.cpp b/src/mapleall/mpl2mpl/src/constantfold.cpp index 03ce7218861172ec3b23025e1b6b79e9ae5fdd99..650289d852e7d4ff363d1e0bfee8afb9f0b79e1b 100644 --- a/src/mapleall/mpl2mpl/src/constantfold.cpp +++ b/src/mapleall/mpl2mpl/src/constantfold.cpp @@ -1207,11 +1207,14 @@ T ConstantFold::CalIntValueFromFloatValue(T value, const MIRType &resultType) co return value; } -MIRConst *ConstantFold::FoldFloorMIRConst(const MIRConst &cst, PrimType fromType, PrimType toType) const { +MIRConst *ConstantFold::FoldFloorMIRConst(const MIRConst &cst, PrimType fromType, PrimType toType, bool isFloor) const { MIRType &resultType = *GlobalTables::GetTypeTable().GetPrimType(toType); if (fromType == PTY_f32) { const auto &constValue = static_cast(cst); - float floatValue = floor(constValue.GetValue()); + float floatValue = constValue.GetValue(); + if (isFloor) { + floatValue = floor(constValue.GetValue()); + } if (FloatToIntOverflow(floatValue, toType)) { return nullptr; } @@ -1219,7 +1222,10 @@ MIRConst *ConstantFold::FoldFloorMIRConst(const MIRConst &cst, PrimType fromType return GlobalTables::GetIntConstTable().GetOrCreateIntConst(static_cast(floatValue), resultType); } else { const auto &constValue = static_cast(cst); - double doubleValue = floor(constValue.GetValue()); + double doubleValue = constValue.GetValue(); + if (isFloor) { + doubleValue = floor(constValue.GetValue()); + } if (DoubleToIntOverflow(doubleValue, toType)) { return nullptr; } @@ -1362,7 +1368,7 @@ MIRConst *ConstantFold::FoldTypeCvtMIRConst(const MIRConst &cst, PrimType fromTy return toConst; } if (IsPrimitiveFloat(fromType) && IsPrimitiveInteger(toType)) { - return FoldFloorMIRConst(cst, fromType, toType); + return FoldFloorMIRConst(cst, fromType, toType, false); } if (IsPrimitiveInteger(fromType) && IsPrimitiveFloat(toType)) { return FoldRoundMIRConst(cst, fromType, toType); diff --git a/src/mplfe/ast_input/src/ast_parser.cpp b/src/mplfe/ast_input/src/ast_parser.cpp index b2e2b46e50f977404b3968afa9888f735497679a..b0225df766174988122847ba41074784fb9eeb82 100644 --- a/src/mplfe/ast_input/src/ast_parser.cpp +++ b/src/mplfe/ast_input/src/ast_parser.cpp @@ -1031,7 +1031,7 @@ ASTExpr *ASTParser::ProcessExprIntegerLiteral(MapleAllocator &allocator, const c ASTIntegerLiteral *astIntegerLiteral = ASTDeclsBuilder::ASTExprBuilder(allocator); ASSERT(astIntegerLiteral != nullptr, "astIntegerLiteral is nullptr"); uint64 val = 0; - MIRType *type; + MIRType *type = nullptr; llvm::APInt api = expr.getValue(); if (api.getBitWidth() > kInt32Width) { val = *api.getRawData();