diff --git a/src/mapleall/maple_ipa/include/stmt_identify.h b/src/mapleall/maple_ipa/include/stmt_identify.h index 7239add8f39d480ca4b9267ff431f28ce14e2692..b8561c66433bf89461ac7d1ba63942782ff2c9ca 100644 --- a/src/mapleall/maple_ipa/include/stmt_identify.h +++ b/src/mapleall/maple_ipa/include/stmt_identify.h @@ -177,11 +177,11 @@ class StmtInfo { return puIdx; } - const uint32 GetFrequency() const { + const uint64 GetFrequency() const { return frequency; } - void SetFrequency(uint32 freq) { + void SetFrequency(uint64 freq) { frequency = freq; } @@ -214,7 +214,7 @@ class StmtInfo { BlockNode *currBlock = nullptr; MeStmt *meStmt = nullptr; PUIdx puIdx = kInvalidPuIdx; - uint32 frequency = 0; + uint64 frequency = 0; bool valid = true; std::vector hashCandidate; std::unordered_map symbolDefUse; diff --git a/src/mapleall/maple_ir/include/mir_function.h b/src/mapleall/maple_ir/include/mir_function.h index f54bf54a604d2c0a2fd8c65ce0e06464ed4c0096..03ef31096791c8e9b292636e16555e3a08ec13b9 100644 --- a/src/mapleall/maple_ir/include/mir_function.h +++ b/src/mapleall/maple_ir/include/mir_function.h @@ -776,44 +776,44 @@ class MIRFunction { return freqFirstMap != nullptr; } - const MapleMap &GetFirstFreqMap() const { + const MapleMap &GetFirstFreqMap() const { return *freqFirstMap; } - void SetFirstFreqMap(uint32 stmtID, uint32 freq) { + void SetFirstFreqMap(uint32 stmtID, uint64 freq) { if (freqFirstMap == nullptr) { - freqFirstMap = module->GetMemPool()->New>(module->GetMPAllocator().Adapter()); + freqFirstMap = module->GetMemPool()->New>(module->GetMPAllocator().Adapter()); } (*freqFirstMap)[stmtID] = freq; } - const MapleMap &GetLastFreqMap() const { + const MapleMap &GetLastFreqMap() const { return *freqLastMap; } - int32 GetFreqFromLastStmt(uint32 stmtId) const { + int64 GetFreqFromLastStmt(uint32 stmtId) const { if (freqLastMap == nullptr) { return -1; } if ((*freqLastMap).find(stmtId) == (*freqLastMap).end()) { return -1; } - return static_cast((*freqLastMap)[stmtId]); + return (*freqLastMap)[stmtId]; } - int32 GetFreqFromFirstStmt(uint32 stmtId) const { + int64 GetFreqFromFirstStmt(uint32 stmtId) const { if (freqFirstMap == nullptr) { return -1; } if ((*freqFirstMap).find(stmtId) == (*freqFirstMap).end()) { return -1; } - return static_cast((*freqFirstMap)[stmtId]); + return (*freqFirstMap)[stmtId]; } - void SetLastFreqMap(uint32 stmtID, uint32 freq) { + void SetLastFreqMap(uint32 stmtID, uint64 freq) { if (freqLastMap == nullptr) { - freqLastMap = module->GetMemPool()->New>(module->GetMPAllocator().Adapter()); + freqLastMap = module->GetMemPool()->New>(module->GetMPAllocator().Adapter()); } (*freqLastMap)[stmtID] = freq; } @@ -1340,8 +1340,8 @@ class MIRFunction { MIRInfoVector info{module->GetMPAllocator().Adapter()}; MapleVector infoIsString{module->GetMPAllocator().Adapter()}; // tells if an entry has string value MIRScope *scope = nullptr; - MapleMap *freqFirstMap = nullptr; // save bb frequency in its first_stmt, key is stmtId - MapleMap *freqLastMap = nullptr; // save bb frequency in its last_stmt, key is stmtId + MapleMap *freqFirstMap = nullptr; // save bb frequency in its first_stmt, key is stmtId + MapleMap *freqLastMap = nullptr; // save bb frequency in its last_stmt, key is stmtId MapleSet referedPregs{module->GetMPAllocator().Adapter()}; bool referedRegsValid = false; bool hasVlaOrAlloca = false; diff --git a/src/mapleall/maple_ir/src/mir_parser.cpp b/src/mapleall/maple_ir/src/mir_parser.cpp index d425dad1816cb68e5045feecacd52cfc0cbeec6e..a422fccbb02aa06772de86e0feb200dadde1c13e 100644 --- a/src/mapleall/maple_ir/src/mir_parser.cpp +++ b/src/mapleall/maple_ir/src/mir_parser.cpp @@ -610,6 +610,8 @@ bool MIRParser::ParseStmtSwitch(StmtNodePtr &stmt) { } if (lexer.NextToken() == TK_label) { switchNode->SetDefaultLabel(mod.CurFunction()->GetOrCreateLableIdxFromName(lexer.GetName())); + } else if (lexer.GetTokenKind() == TK_intconst && lexer.GetTheIntVal() == 0) { + switchNode->SetDefaultLabel(0); } else { Error("expect label in switch but get "); return false; diff --git a/src/mapleall/maple_me/include/bb.h b/src/mapleall/maple_me/include/bb.h index 93f6e4f6b70177b6279f3729e40471313f1de5b7..582a403ca2f61b83dbfb4bd8effcd8c894a1ebdc 100644 --- a/src/mapleall/maple_me/include/bb.h +++ b/src/mapleall/maple_me/include/bb.h @@ -337,11 +337,11 @@ class BB { bbLabel = idx; } - uint32 GetFrequency() const { + uint64 GetFrequency() const { return frequency; } - void SetFrequency(uint32 f) { + void SetFrequency(uint64 f) { frequency = f; } @@ -548,7 +548,7 @@ class BB { MapleMap phiList; MapleMap mePhiList; MapleMap> meVarPiList; - uint32 frequency = 0; + uint64 frequency = 0; BBKind kind = kBBUnknown; uint32 attributes = 0; diff --git a/src/mapleall/maple_me/include/me_function.h b/src/mapleall/maple_me/include/me_function.h index ab1f8d853352ec48b250aa8ce3c4973ec6fab323..33169261da8028613b68a25000c34a94cc35955e 100644 --- a/src/mapleall/maple_me/include/me_function.h +++ b/src/mapleall/maple_me/include/me_function.h @@ -302,11 +302,11 @@ class MeFunction : public FuncEmit { profValid = val; } - uint32 GetFrequency() const { + uint64 GetFrequency() const { return frequency; } - void SetFrequency(uint32 f) { + void SetFrequency(uint64 f) { frequency = f; } @@ -399,7 +399,7 @@ class MeFunction : public FuncEmit { bool hasWriteInputAsmNode = false; /* set when ssa tab build */ bool profValid = false; IRProfileDesc *profileDesc = nullptr; - uint32 frequency = 0; + uint64 frequency = 0; // lfo bool isLfo = false; // during pme processing diff --git a/src/mapleall/maple_me/include/me_loop_unrolling.h b/src/mapleall/maple_me/include/me_loop_unrolling.h index fe36d56e73a4b8d9215617f813e94c31a12b7512..d28667d9a8c74bb6788fed97b7dc449f1422da2c 100644 --- a/src/mapleall/maple_me/include/me_loop_unrolling.h +++ b/src/mapleall/maple_me/include/me_loop_unrolling.h @@ -80,7 +80,7 @@ class LoopUnrolling { MeExpr *CreateExprWithCRNode(CRNode &crNode); void InsertCondGotoBB(); void ResetFrequency(BB &bb); - void ResetFrequency(BB &newCondGotoBB, BB &exitingBB, const BB &exitedBB, uint32 headFreq); + void ResetFrequency(BB &newCondGotoBB, BB &exitingBB, const BB &exitedBB, uint64 headFreq); void ResetFrequency(); void ResetFrequency(const BB &curBB, const BB &succ, const BB &exitBB, BB &curCopyBB, bool copyAllLoop); BB *CopyBB(BB &bb, bool isInLoop); diff --git a/src/mapleall/maple_me/include/me_predict.h b/src/mapleall/maple_me/include/me_predict.h index 57f2f932c6c286fab0dcdd8aff48123f82475936..8e99c43a9d495dd66a486a2d3209de0ebc7328bf 100644 --- a/src/mapleall/maple_me/include/me_predict.h +++ b/src/mapleall/maple_me/include/me_predict.h @@ -23,7 +23,7 @@ namespace maple { // The base value for branch probability notes and edge probabilities. constexpr int kProbBase = 10000; // The base value for BB frequency. -constexpr int kFreqBase = 100000; +constexpr uint64 kFreqBase = 100000; // Information about each branch predictor. struct PredictorInfo { diff --git a/src/mapleall/maple_me/include/pme_emit.h b/src/mapleall/maple_me/include/pme_emit.h index 40642c1757f8938409c25c41994fd32eb07309e8..895f1f1256298e405be738387d44719e9cb4a4aa 100644 --- a/src/mapleall/maple_me/include/pme_emit.h +++ b/src/mapleall/maple_me/include/pme_emit.h @@ -82,7 +82,7 @@ class PreMeEmitter : public AnalysisResult { MapleMap *GetPreMeExprExtensionMap() { return &preMeExprExtensionMap; } FuncProfInfo *GetFuncProfData() { return mirFunc->GetFuncProfData(); } void SetIpaInfo(CollectIpaInfo *info) { ipaInfo = info; } - void UpdateStmtInfo(const MeStmt &meStmt, StmtNode &stmt, BlockNode &currBlock, uint32 frequency); + void UpdateStmtInfo(const MeStmt &meStmt, StmtNode &stmt, BlockNode &currBlock, uint64 frequency); void UpdateStmtInfoForLabelNode(LabelNode &label, BB &bb); private: ArrayNode *ConvertToArray(BaseNode *x, TyIdx ptrTyIdx); diff --git a/src/mapleall/maple_me/src/bb.cpp b/src/mapleall/maple_me/src/bb.cpp index fd287332f53b713035280c89edef25c16a5ef9ae..a2c038fc11ad530ab7dbc226a719e8759e1f29ad 100644 --- a/src/mapleall/maple_me/src/bb.cpp +++ b/src/mapleall/maple_me/src/bb.cpp @@ -482,27 +482,28 @@ void BB::DumpMePhiList(const IRMap *irMap) { void BB::UpdateEdgeFreqs(bool updateBBFreqOfSucc) { int len = GetSucc().size(); ASSERT(len == GetSuccFreq().size(), "sanity check"); - int64_t succFreqs = 0; + uint64 succFreqs = 0; for (int i = 0; i < len; i++) { succFreqs += GetSuccFreq()[i]; } - int diff = static_cast(abs(succFreqs - GetFrequency())); + int64 diff = succFreqs - GetFrequency(); + diff = abs(diff); if (len == 0 || (len == 1 && diff == 0) || (len > 1 && diff <= 1)) { return; } - for (uint32 i = 0; i < len; ++i) { - int64_t sfreq = GetSuccFreq()[static_cast(i)]; - int64_t scalefreq = (succFreqs == 0 ? (frequency / len) : (sfreq * frequency / succFreqs)); - SetSuccFreq(static_cast(i), scalefreq); + for (int i = 0; i < len; ++i) { + uint64 sfreq = GetSuccFreq()[i]; + uint64 scalefreq = (succFreqs == 0 ? (frequency / len) : (sfreq * frequency / succFreqs)); + SetSuccFreq(i, scalefreq); // update succ frequency with new difference if needed if (updateBBFreqOfSucc) { - auto *succBBLoc = GetSucc(static_cast(i)); + auto *succBBLoc = GetSucc(i); int64_t diffFreq = scalefreq - sfreq; int64_t succBBnewFreq = succBBLoc->GetFrequency() + diffFreq; if (succBBnewFreq >= 0) { - succBBLoc->SetFrequency(static_cast(succBBnewFreq)); + succBBLoc->SetFrequency(static_cast(succBBnewFreq)); } } } diff --git a/src/mapleall/maple_me/src/hdse.cpp b/src/mapleall/maple_me/src/hdse.cpp index c20ee03498acda5fd1ac8a933c272495ab33ea5d..312c6e2cedee26bbebfe197c165c1737787a8f19 100644 --- a/src/mapleall/maple_me/src/hdse.cpp +++ b/src/mapleall/maple_me/src/hdse.cpp @@ -250,12 +250,11 @@ void HDSE::RemoveNotRequiredStmtsInBB(BB &bb) { } bb.SetKind(kBBFallthru); if (UpdateFreq()) { - int64_t succ0Freq = static_cast(bb.GetSuccFreq()[0]); + uint64 succ0Freq = static_cast(bb.GetSuccFreq()[0]); bb.GetSuccFreq().resize(1); bb.SetSuccFreq(0, bb.GetFrequency()); ASSERT(bb.GetFrequency() >= succ0Freq, "sanity check"); - bb.GetSucc(0)->SetFrequency(static_cast(bb.GetSucc(0)->GetFrequency() + - (bb.GetFrequency() - succ0Freq))); + bb.GetSucc(0)->SetFrequency(bb.GetSucc(0)->GetFrequency() + (bb.GetFrequency() - succ0Freq)); } } // A ivar contained in stmt @@ -281,7 +280,7 @@ void HDSE::RemoveNotRequiredStmtsInBB(BB &bb) { bool isPme = mirModule.CurFunction()->GetMeFunc()->GetPreMeFunc() != nullptr; if (mestmt->IsCondBr() && !isPme) { // see if foldable to unconditional branch CondGotoMeStmt *condbr = static_cast(mestmt); - int64_t removedFreq = 0; + uint64 removedFreq = 0; if (!mirModule.IsJavaModule() && condbr->GetOpnd()->GetMeOp() == kMeOpConst) { CHECK_FATAL(IsPrimitiveInteger(condbr->GetOpnd()->GetPrimType()), "MeHDSE::DseProcess: branch condition must be integer type"); @@ -317,7 +316,7 @@ void HDSE::RemoveNotRequiredStmtsInBB(BB &bb) { if (UpdateFreq()) { bb.GetSuccFreq().resize(1); bb.SetSuccFreq(0, bb.GetFrequency()); - bb.GetSucc(0)->SetFrequency(static_cast(bb.GetSucc(0)->GetFrequency() + removedFreq)); + bb.GetSucc(0)->SetFrequency(bb.GetSucc(0)->GetFrequency() + removedFreq); } } else { DetermineUseCounts(condbr->GetOpnd()); diff --git a/src/mapleall/maple_me/src/me_bb_analyze.cpp b/src/mapleall/maple_me/src/me_bb_analyze.cpp index bd34586662c929b636f63d3be75f46b28f377193..2909ee682b770b3ac81a53476ade440f931f309e 100644 --- a/src/mapleall/maple_me/src/me_bb_analyze.cpp +++ b/src/mapleall/maple_me/src/me_bb_analyze.cpp @@ -16,7 +16,7 @@ namespace maple { void BBAnalyze::SetHotAndColdBBCountThreshold() { - std::vector times; + std::vector times; auto eIt = cfg->valid_end(); for (auto bIt = cfg->valid_begin(); bIt != eIt; ++bIt) { auto *bb = *bIt; diff --git a/src/mapleall/maple_me/src/me_bb_layout.cpp b/src/mapleall/maple_me/src/me_bb_layout.cpp index ceafc3e6b0db1879f2f39fa32a73603dbc1ba8bb..49a42897bd7bc98dde03ad4d6e54a76b77f404f4 100644 --- a/src/mapleall/maple_me/src/me_bb_layout.cpp +++ b/src/mapleall/maple_me/src/me_bb_layout.cpp @@ -206,15 +206,15 @@ bool BBLayout::HasBetterLayoutPred(const BB &bb, BB &succ) { if (predList.size() <= 1) { return false; } - uint32 sumEdgeFreq = succ.GetFrequency(); + uint64 sumEdgeFreq = succ.GetFrequency(); const double hotEdgeFreqPercent = 0.8; // should further fine tuning - uint32 hotEdgeFreq = static_cast(sumEdgeFreq * hotEdgeFreqPercent); + uint64 hotEdgeFreq = static_cast(sumEdgeFreq * hotEdgeFreqPercent); // if edge freq(bb->succ) contribute more than 80% to succ block freq, no better layout pred than bb for (uint32 i = 0; i < predList.size(); ++i) { if (predList[i] == &bb) { continue; } - uint32 edgeFreq = static_cast(predList[i]->GetEdgeFreq(&succ)); + uint64 edgeFreq = predList[i]->GetEdgeFreq(&succ); if (edgeFreq > (sumEdgeFreq - hotEdgeFreq)) { return true; } @@ -258,7 +258,7 @@ BB *BBLayout::GetBestSucc(BB &bb, const BBChain &chain, const MapleVector } // (2) search in readyToLayoutChains - uint32 bestFreq = 0; + uint64 bestFreq = 0; for (auto it = readyToLayoutChains.begin(); it != readyToLayoutChains.end(); ++it) { BBChain *readyChain = *it; BB *header = readyChain->GetHeader(); diff --git a/src/mapleall/maple_me/src/me_loop_canon.cpp b/src/mapleall/maple_me/src/me_loop_canon.cpp index 3aae6c2514ef82b13d8e78708a5935eb33735510..4edad676544f7cff1a4a3f1502602438497001e4 100644 --- a/src/mapleall/maple_me/src/me_loop_canon.cpp +++ b/src/mapleall/maple_me/src/me_loop_canon.cpp @@ -95,19 +95,19 @@ void MeLoopCanon::SplitPreds(const std::vector &splitList, BB *splittedBB, if (splitList.size() == 1) { // quick split auto *pred = splitList[0]; - auto index = pred->GetSuccIndex(*splittedBB); + int index = pred->GetSuccIndex(*splittedBB); // add frequency to mergedBB if (updateFreqs) { int idx = pred->GetSuccIndex(*splittedBB); ASSERT(idx >= 0 && idx < pred->GetSucc().size(), "sanity check"); uint64_t freq = pred->GetEdgeFreq(static_cast(idx)); - mergedBB->SetFrequency(static_cast(freq)); + mergedBB->SetFrequency(freq); mergedBB->PushBackSuccFreq(freq); } splittedBB->ReplacePred(pred, mergedBB); - pred->AddSucc(*mergedBB, static_cast(static_cast(index))); + pred->AddSucc(*mergedBB, static_cast(index)); if (updateFreqs) { - pred->AddSuccFreq(mergedBB->GetFrequency(), static_cast(static_cast(index))); + pred->AddSuccFreq(mergedBB->GetFrequency(), static_cast(index)); } if (!pred->GetMeStmts().empty()) { UpdateTheOffsetOfStmtWhenTargetBBIsChange(*pred, *splittedBB, *mergedBB); @@ -134,8 +134,8 @@ void MeLoopCanon::SplitPreds(const std::vector &splitList, BB *splittedBB, if (updateFreqs) { int idx = pred->GetSuccIndex(*splittedBB); ASSERT(idx >= 0 && idx < pred->GetSucc().size(), "sanity check"); - freq = pred->GetEdgeFreq(static_cast(idx)); - mergedBB->SetFrequency(static_cast(mergedBB->GetFrequency() + freq)); + freq = pred->GetEdgeFreq(static_cast(idx)); + mergedBB->SetFrequency(mergedBB->GetFrequency() + freq); } pred->ReplaceSucc(splittedBB, mergedBB); if (updateFreqs) { @@ -277,7 +277,7 @@ void MeLoopCanon::InsertExitBB(LoopDesc &loop) { curBB->ReplaceSucc(succ, newExitBB); succ->AddPred(*newExitBB, pos); if (updateFreqs) { - newExitBB->SetFrequency(static_cast(freq)); + newExitBB->SetFrequency(freq); newExitBB->PushBackSuccFreq(freq); } if (!curBB->GetMeStmts().empty()) { diff --git a/src/mapleall/maple_me/src/me_loop_unrolling.cpp b/src/mapleall/maple_me/src/me_loop_unrolling.cpp index 11ef561b38fbc22b265c9debd816862f0d72550d..5e39fd56c19680327314fbd1ec4b534162655aa3 100644 --- a/src/mapleall/maple_me/src/me_loop_unrolling.cpp +++ b/src/mapleall/maple_me/src/me_loop_unrolling.cpp @@ -309,11 +309,11 @@ void LoopUnrolling::CopyLoopBody(BB &newHeadBB, std::unordered_map &ol // Update frequency of old BB. void LoopUnrolling::ResetFrequency(BB &bb) { - auto freq = bb.GetFrequency() / replicatedLoopNum; + uint64 freq = bb.GetFrequency() / replicatedLoopNum; if ((!instrumentProf) && freq == 0 && partialCount == 0 && bb.GetFrequency() != 0) { freq = 1; } - bb.SetFrequency(static_cast(freq + partialCount)); + bb.SetFrequency(freq + partialCount); for (size_t i = 0; i < bb.GetSucc().size(); ++i) { auto currFreq = bb.GetEdgeFreq(i) / replicatedLoopNum; if ((!instrumentProf) && currFreq == 0 && partialCount == 0 && bb.GetFrequency() != 0) { @@ -328,17 +328,17 @@ void LoopUnrolling::ResetFrequency() { auto exitBB = cfg->GetBBFromID(loop->inloopBB2exitBBs.begin()->first); auto latchBB = loop->latch; if (isUnrollWithVar) { - auto latchFreq = loop->head->GetFrequency() % replicatedLoopNum - loop->preheader->GetFrequency(); - exitBB->SetFrequency(static_cast(loop->head->GetFrequency() % replicatedLoopNum - latchFreq)); + uint64 latchFreq = loop->head->GetFrequency() % replicatedLoopNum - loop->preheader->GetFrequency(); + exitBB->SetFrequency(loop->head->GetFrequency() % replicatedLoopNum - latchFreq); exitBB->SetEdgeFreq(latchBB, latchFreq); - latchBB->SetFrequency(static_cast(latchFreq)); + latchBB->SetFrequency(latchFreq); latchBB->SetEdgeFreq(loop->head, latchFreq); } else { - auto exitFreq = exitBB->GetFrequency() / replicatedLoopNum; + uint64 exitFreq = exitBB->GetFrequency() / replicatedLoopNum; if (exitFreq == 0 && exitBB->GetFrequency() != 0) { exitFreq = 1; } - exitBB->SetFrequency(static_cast(exitFreq)); + exitBB->SetFrequency(exitFreq); auto exitEdgeFreq = exitBB->GetEdgeFreq(latchBB) / replicatedLoopNum; if (exitEdgeFreq == 0 && exitBB->GetEdgeFreq(latchBB) != 0) { exitEdgeFreq = 1; @@ -348,7 +348,7 @@ void LoopUnrolling::ResetFrequency() { if (latchFreq == 0 && latchBB->GetFrequency() != 0) { latchFreq = 1; } - latchBB->SetFrequency(static_cast(latchFreq)); + latchBB->SetFrequency(latchFreq); latchBB->SetEdgeFreq(loop->head, latchFreq); } } @@ -532,7 +532,7 @@ LoopUnrolling::ReturnKindOfFullyUnroll LoopUnrolling::LoopFullyUnroll(int64 trip return kCanFullyUnroll; } -void LoopUnrolling::ResetFrequency(BB &newCondGotoBB, BB &exitingBB, const BB &exitedBB, uint32 headFreq) { +void LoopUnrolling::ResetFrequency(BB &newCondGotoBB, BB &exitingBB, const BB &exitedBB, uint64 headFreq) { if (profValid) { newCondGotoBB.SetFrequency(headFreq); exitingBB.SetEdgeFreq(&exitedBB, 0); @@ -544,7 +544,7 @@ void LoopUnrolling::InsertCondGotoBB() { BB *exitingBB = cfg->GetBBFromID(loop->inloopBB2exitBBs.begin()->first); BB *exitedBB = *(loop->inloopBB2exitBBs.cbegin()->second->cbegin()); BB *newCondGotoBB = CopyBB(*exitingBB, true); - auto headFreq = loop->head->GetFrequency(); + uint64 headFreq = loop->head->GetFrequency(); ResetFrequency(*newCondGotoBB, *exitingBB, *exitedBB, headFreq); MeStmt *lastMeStmt = newCondGotoBB->GetLastMe(); CHECK_FATAL(lastMeStmt != nullptr, "last meStmt must not be nullptr"); @@ -642,7 +642,7 @@ void LoopUnrolling::AddPreHeader(BB *oldPreHeader, BB *head) { head->AddPred(*preheader, index); if (profValid) { preheader->PushBackSuccFreq(preheaderFreq); - preheader->SetFrequency(static_cast(preheaderFreq)); + preheader->SetFrequency(preheaderFreq); } CondGotoMeStmt *condGotoStmt = static_cast(oldPreHeader->GetLastMe()); LabelIdx oldlabIdx = condGotoStmt->GetOffset(); @@ -818,8 +818,7 @@ void LoopUnrolling::CopyLoopForPartial(BB &partialCondGoto, BB &exitedBB, BB &ex partialCondGoto.AddSucc(*partialHead); if (profValid) { partialCondGoto.PushBackSuccFreq(loop->head->GetFrequency() % replicatedLoopNum); - partialCondGoto.SetFrequency( - static_cast(partialCondGoto.GetEdgeFreq(static_cast(0)) + partialCondGoto.GetEdgeFreq(1))); + partialCondGoto.SetFrequency(partialCondGoto.GetEdgeFreq(static_cast(0)) + partialCondGoto.GetEdgeFreq(1)); } CHECK_FATAL(partialCondGoto.GetKind() == kBBCondGoto, "must be partialCondGoto"); CHECK_FATAL(!partialCondGoto.GetMeStmts().empty(), "must not be empty"); diff --git a/src/mapleall/maple_me/src/me_predict.cpp b/src/mapleall/maple_me/src/me_predict.cpp index 80f6db36e0dc77b54750d0a5356b407ef3f3e0de..acbe0c74adaa9ffcf442d28bdb50bc4ab7b5ed60 100644 --- a/src/mapleall/maple_me/src/me_predict.cpp +++ b/src/mapleall/maple_me/src/me_predict.cpp @@ -735,7 +735,7 @@ bool MePrediction::DoPropFreq(const BB *head, std::vector *headers, BB &bb) return false; } } - uint32 freq = 0; + uint64 freq = 0; double cyclicProb = 0; for (BB *pred : bb.GetPred()) { Edge *edge = FindEdge(*pred, bb); @@ -750,7 +750,7 @@ bool MePrediction::DoPropFreq(const BB *head, std::vector *headers, BB &bb) cyclicProb = 1 - std::numeric_limits::epsilon(); } // Floating-point numbers have precision problems, consider using integers to represent backEdgeProb? - bb.SetFrequency(static_cast(freq / (1 - cyclicProb))); + bb.SetFrequency(static_cast(static_cast(freq / (1 - cyclicProb)))); } // 2. calculate frequencies of bb's out edges if (predictDebug) { @@ -758,7 +758,7 @@ bool MePrediction::DoPropFreq(const BB *head, std::vector *headers, BB &bb) } bbVisited[bb.GetBBId()] = true; uint32 tmp = 0; - uint32 total = 0; + uint64 total = 0; Edge *bestEdge = nullptr; for (size_t i = 0; i < bb.GetSucc().size(); ++i) { Edge *edge = FindEdge(bb, *bb.GetSucc(i)); diff --git a/src/mapleall/maple_me/src/me_profile_use.cpp b/src/mapleall/maple_me/src/me_profile_use.cpp index 195eb16512ba7f3b4f8b641ab524494061087e4a..d43fa03e7361af5cefbc653b38d1ea46a130af2c 100644 --- a/src/mapleall/maple_me/src/me_profile_use.cpp +++ b/src/mapleall/maple_me/src/me_profile_use.cpp @@ -244,7 +244,7 @@ void MeProfUse::SetFuncEdgeInfo() { for (auto bIt = cfg->valid_begin(); bIt != eIt; ++bIt) { auto *bb = *bIt; auto *bbInfo = GetBBUseInfo(*bb); - bb->SetFrequency(static_cast(bbInfo->GetCount())); + bb->SetFrequency(bbInfo->GetCount()); if (bIt == cfg->common_entry() || bIt == cfg->common_exit()) { continue; } diff --git a/src/mapleall/maple_me/src/me_value_range_prop.cpp b/src/mapleall/maple_me/src/me_value_range_prop.cpp index 67448df356a860794a45ea1bafd18295287b9ace..2f5dffcaafa20ce52f167fa5f850041f0ecdd19e 100644 --- a/src/mapleall/maple_me/src/me_value_range_prop.cpp +++ b/src/mapleall/maple_me/src/me_value_range_prop.cpp @@ -3230,17 +3230,17 @@ void ValueRangePropagation::AnalysisUnreachableBBOrEdge(BB &bb, BB &unreachableB } Insert2UnreachableBBs(unreachableBB); // update frequency before cfg changed - int64_t removedFreq = 0; + uint64 removedFreq = 0; if (func.GetCfg()->UpdateCFGFreq()) { int idx = bb.GetSuccIndex(unreachableBB); - removedFreq = static_cast(bb.GetSuccFreq()[static_cast(idx)]); + removedFreq = bb.GetSuccFreq()[static_cast(idx)]; } bb.RemoveSucc(unreachableBB); bb.RemoveMeStmt(bb.GetLastMe()); bb.SetKind(kBBFallthru); if (func.GetCfg()->UpdateCFGFreq()) { bb.SetSuccFreq(0, bb.GetFrequency()); - succBB.SetFrequency(static_cast(succBB.GetFrequency() + removedFreq)); + succBB.SetFrequency(succBB.GetFrequency() + removedFreq); unreachableBB.SetFrequency(0); } auto *loop = loops->GetBBLoopParent(bb.GetBBId()); @@ -3623,9 +3623,9 @@ void ValueRangePropagation::RemoveUnreachableBB( condGotoBB.SetKind(kBBFallthru); // update frequency before cfg changed if (func.GetCfg()->UpdateCFGFreq()) { - int64_t removedFreq = static_cast(condGotoBB.GetSuccFreq()[1]); + uint64 removedFreq = condGotoBB.GetSuccFreq()[1]; condGotoBB.SetSuccFreq(0, condGotoBB.GetFrequency()); - succ0->SetFrequency(static_cast(succ0->GetFrequency() + removedFreq)); + succ0->SetFrequency(succ0->GetFrequency() + removedFreq); } condGotoBB.RemoveSucc(*succ1); DeleteThePhiNodeWhichOnlyHasOneOpnd(*succ1, updateSSAExceptTheScalarExpr, ssaupdateCandsForCondExpr); @@ -3639,15 +3639,15 @@ void ValueRangePropagation::RemoveUnreachableBB( UpdateProfile(*condGotoBB.GetPred(0), condGotoBB, trueBranch); } condGotoBB.SetKind(kBBFallthru); - int64_t removedFreq = 0; + uint64 removedFreq = 0; // update frequency before cfg changed if (func.GetCfg()->UpdateCFGFreq()) { - removedFreq = static_cast(condGotoBB.GetSuccFreq()[0]); + removedFreq = condGotoBB.GetSuccFreq()[0]; } condGotoBB.RemoveSucc(*succ0); if (func.GetCfg()->UpdateCFGFreq()) { condGotoBB.SetSuccFreq(0, condGotoBB.GetFrequency()); - succ1->SetFrequency(static_cast(succ1->GetFrequency() + removedFreq)); + succ1->SetFrequency(succ1->GetFrequency() + removedFreq); } DeleteThePhiNodeWhichOnlyHasOneOpnd(*succ0, updateSSAExceptTheScalarExpr, ssaupdateCandsForCondExpr); condGotoBB.RemoveMeStmt(condGotoBB.GetLastMe()); @@ -3806,20 +3806,20 @@ bool ValueRangePropagation::ChangeTheSuccOfPred2TrueBranch( if (exitCopyFallthru != nullptr) { PrepareForSSAUpdateWhenPredBBIsRemoved(pred, bb, updateSSAExceptTheScalarExpr, ssaupdateCandsForCondExpr); size_t index = FindBBInSuccs(pred, bb); - int64_t edgeFreq = 0; + uint64 edgeFreq = 0; if (func.GetCfg()->UpdateCFGFreq()) { - edgeFreq = static_cast(pred.GetSuccFreq()[index]); + edgeFreq = pred.GetSuccFreq()[index]; } pred.RemoveSucc(bb); DeleteThePhiNodeWhichOnlyHasOneOpnd(bb, updateSSAExceptTheScalarExpr, ssaupdateCandsForCondExpr); pred.AddSucc(*exitCopyFallthru, index); CreateLabelForTargetBB(pred, *exitCopyFallthru); if (func.GetCfg()->UpdateCFGFreq()) { - exitCopyFallthru->SetFrequency(static_cast(exitCopyFallthru->GetFrequency() + edgeFreq)); - pred.AddSuccFreq(static_cast(edgeFreq), index); + exitCopyFallthru->SetFrequency(exitCopyFallthru->GetFrequency() + edgeFreq); + pred.AddSuccFreq(edgeFreq, index); // update bb frequency ASSERT(bb.GetFrequency() >= edgeFreq, "sanity check"); - bb.SetFrequency(static_cast(bb.GetFrequency() - edgeFreq)); + bb.SetFrequency(bb.GetFrequency() - edgeFreq); bb.UpdateEdgeFreqs(); } return true; @@ -3855,19 +3855,19 @@ bool ValueRangePropagation::ChangeTheSuccOfPred2TrueBranch( mergeAllFallthruBBs->AddMeStmtLast(gotoMeStmt); PrepareForSSAUpdateWhenPredBBIsRemoved(pred, bb, updateSSAExceptTheScalarExpr, ssaupdateCandsForCondExpr); size_t index = FindBBInSuccs(pred, bb); - int64_t edgeFreq = 0; + uint64 edgeFreq = 0; if (func.GetCfg()->UpdateCFGFreq()) { - edgeFreq = static_cast(pred.GetSuccFreq()[index]); + edgeFreq = pred.GetSuccFreq()[index]; } pred.RemoveSucc(bb); pred.AddSucc(*mergeAllFallthruBBs, index); if (func.GetCfg()->UpdateCFGFreq()) { - mergeAllFallthruBBs->SetFrequency(static_cast(edgeFreq)); - mergeAllFallthruBBs->PushBackSuccFreq(static_cast(edgeFreq)); - pred.AddSuccFreq(static_cast(edgeFreq), index); + mergeAllFallthruBBs->SetFrequency(edgeFreq); + mergeAllFallthruBBs->PushBackSuccFreq(edgeFreq); + pred.AddSuccFreq(edgeFreq, index); // update bb frequency ASSERT(bb.GetFrequency() >= edgeFreq, "sanity check"); - bb.SetFrequency(static_cast(bb.GetFrequency() - edgeFreq)); + bb.SetFrequency(bb.GetFrequency() - edgeFreq); bb.UpdateEdgeFreqs(); } mergeAllFallthruBBs->AddSucc(trueBranch); @@ -3938,9 +3938,9 @@ bool ValueRangePropagation::RemoveTheEdgeOfPredBB( if (OnlyHaveCondGotoStmt(bb)) { PrepareForSSAUpdateWhenPredBBIsRemoved(pred, bb, updateSSAExceptTheScalarExpr, ssaupdateCandsForCondExpr); size_t index = FindBBInSuccs(pred, bb); - int64_t edgeFreq = 0; + uint64 edgeFreq = 0; if (func.GetCfg()->UpdateCFGFreq()) { - edgeFreq = static_cast(pred.GetSuccFreq()[index]); + edgeFreq = pred.GetSuccFreq()[index]; ASSERT(bb.GetFrequency() >= edgeFreq, "sanity check"); } pred.RemoveSucc(bb); @@ -3948,22 +3948,22 @@ bool ValueRangePropagation::RemoveTheEdgeOfPredBB( pred.AddSucc(trueBranch, index); CreateLabelForTargetBB(pred, trueBranch); if (func.GetCfg()->UpdateCFGFreq()) { - bb.SetFrequency(static_cast(bb.GetFrequency() - edgeFreq)); + bb.SetFrequency(bb.GetFrequency() - edgeFreq); size_t trueBranchIdx = static_cast(bb.GetSuccIndex(trueBranch)); - int64_t updatedtrueFreq = static_cast(bb.GetSuccFreq()[trueBranchIdx] - static_cast(edgeFreq)); + int64_t updatedtrueFreq = static_cast(bb.GetSuccFreq()[trueBranchIdx] - edgeFreq); // transform may not be consistent with frequency value updatedtrueFreq = updatedtrueFreq > 0 ? updatedtrueFreq : 0; bb.SetSuccFreq(static_cast(trueBranchIdx), static_cast(updatedtrueFreq)); - pred.AddSuccFreq(static_cast(edgeFreq), index); + pred.AddSuccFreq(edgeFreq, index); } } else { auto *exitCopyFallthru = GetNewCopyFallthruBB(trueBranch, bb); if (exitCopyFallthru != nullptr) { PrepareForSSAUpdateWhenPredBBIsRemoved(pred, bb, updateSSAExceptTheScalarExpr, ssaupdateCandsForCondExpr); size_t index = FindBBInSuccs(pred, bb); - int64_t edgeFreq = 0; + uint64 edgeFreq = 0; if (func.GetCfg()->UpdateCFGFreq()) { - edgeFreq = static_cast(pred.GetSuccFreq()[index]); + edgeFreq = pred.GetSuccFreq()[index]; ASSERT(bb.GetFrequency() >= edgeFreq, "sanity check"); } pred.RemoveSucc(bb); @@ -3971,15 +3971,14 @@ bool ValueRangePropagation::RemoveTheEdgeOfPredBB( pred.AddSucc(*exitCopyFallthru, index); CreateLabelForTargetBB(pred, *exitCopyFallthru); if (func.GetCfg()->UpdateCFGFreq()) { - bb.SetFrequency(static_cast(bb.GetFrequency() - edgeFreq)); - exitCopyFallthru->SetFrequency(static_cast(edgeFreq)); - exitCopyFallthru->PushBackSuccFreq(static_cast(edgeFreq)); + bb.SetFrequency(bb.GetFrequency() - edgeFreq); + exitCopyFallthru->SetFrequency(edgeFreq); + exitCopyFallthru->PushBackSuccFreq(edgeFreq); size_t trueBranchIdx = static_cast(bb.GetSuccIndex(trueBranch)); - int64_t updatedtrueFreq = static_cast( - bb.GetSuccFreq()[trueBranchIdx] - static_cast(edgeFreq)); + int64_t updatedtrueFreq = static_cast(bb.GetSuccFreq()[trueBranchIdx] - edgeFreq); ASSERT(updatedtrueFreq >= 0, "sanity check"); bb.SetSuccFreq(static_cast(trueBranchIdx), static_cast(updatedtrueFreq)); - pred.AddSuccFreq(static_cast(edgeFreq), index); + pred.AddSuccFreq(edgeFreq, index); } return true; } @@ -3994,20 +3993,20 @@ bool ValueRangePropagation::RemoveTheEdgeOfPredBB( newBB->AddMeStmtLast(gotoMeStmt); PrepareForSSAUpdateWhenPredBBIsRemoved(pred, bb, updateSSAExceptTheScalarExpr, ssaupdateCandsForCondExpr); size_t index = FindBBInSuccs(pred, bb); - int64_t edgeFreq = 0; + uint64 edgeFreq = 0; if (func.GetCfg()->UpdateCFGFreq()) { - edgeFreq = static_cast(pred.GetSuccFreq()[index]); + edgeFreq = pred.GetSuccFreq()[index]; ASSERT(bb.GetFrequency() >= edgeFreq, "sanity check"); } pred.RemoveSucc(bb); pred.AddSucc(*newBB, index); newBB->AddSucc(trueBranch); if (func.GetCfg()->UpdateCFGFreq()) { - bb.SetFrequency(static_cast(bb.GetFrequency() - edgeFreq)); + bb.SetFrequency(bb.GetFrequency() - edgeFreq); bb.UpdateEdgeFreqs(); - newBB->SetFrequency(static_cast(edgeFreq)); - newBB->PushBackSuccFreq(static_cast(edgeFreq)); - pred.AddSuccFreq(static_cast(edgeFreq), index); + newBB->SetFrequency(edgeFreq); + newBB->PushBackSuccFreq(edgeFreq); + pred.AddSuccFreq(edgeFreq, index); } DeleteThePhiNodeWhichOnlyHasOneOpnd(bb, updateSSAExceptTheScalarExpr, ssaupdateCandsForCondExpr); (void)func.GetOrCreateBBLabel(trueBranch); diff --git a/src/mapleall/maple_me/src/optimizeCFG.cpp b/src/mapleall/maple_me/src/optimizeCFG.cpp index 051b59542ad405d04dd4981ff626785d52e2910c..79b0ba7d01e3a2c167267b3c1343f8b770a3ef34 100644 --- a/src/mapleall/maple_me/src/optimizeCFG.cpp +++ b/src/mapleall/maple_me/src/optimizeCFG.cpp @@ -1822,16 +1822,16 @@ bool OptimizeBB::SkipRedundantCond(BB &pred, BB &succ) { DEBUG_LOG() << "SkipRedundantCond : Remove condBr in BB" << LOG_BBID(&succ) << ", turn it to fallthruBB\n"; } BB *rmBB = (FindFirstRealSucc(succ.GetSucc(0)) == newTarget) ? succ.GetSucc(1) : succ.GetSucc(0); - int64_t deletedSuccFreq = 0; + uint64 deletedSuccFreq = 0; if (cfg->UpdateCFGFreq()) { int idx = succ.GetSuccIndex(*rmBB); - deletedSuccFreq = static_cast(succ.GetSuccFreq()[static_cast(idx)]); + deletedSuccFreq = succ.GetSuccFreq()[static_cast(idx)]; } succ.RemoveSucc(*rmBB, true); if (cfg->UpdateCFGFreq()) { succ.SetSuccFreq(0, succ.GetFrequency()); auto *succofSucc = succ.GetSucc(0); - succofSucc->SetFrequency(static_cast(succofSucc->GetFrequency() + deletedSuccFreq)); + succofSucc->SetFrequency(succofSucc->GetFrequency() + deletedSuccFreq); } DEBUG_LOG() << "Remove succ BB" << LOG_BBID(rmBB) << " of pred BB" << LOG_BBID(&succ) << "\n"; return true; @@ -1886,12 +1886,12 @@ bool OptimizeBB::SkipRedundantCond(BB &pred, BB &succ) { if (cfg->UpdateCFGFreq()) { int idx = pred.GetSuccIndex(*newBB); ASSERT(idx >= 0 && idx < pred.GetSucc().size(), "sanity check"); - uint64_t freq = pred.GetEdgeFreq(idx); + uint64 freq = pred.GetEdgeFreq(idx); newBB->SetFrequency(freq); newBB->PushBackSuccFreq(freq); // update frequency of succ because one of its pred is removed // frequency of - uint32_t freqOfSucc = succ.GetFrequency(); + uint64 freqOfSucc = succ.GetFrequency(); ASSERT(freqOfSucc >= freq, "sanity check"); succ.SetFrequency(freqOfSucc - freq); // update edge frequency @@ -2084,25 +2084,25 @@ bool OptimizeBB::MergeGotoBBToPred(BB *succ, BB *pred) { } int predIdx = succ->GetPredIndex(*pred); bool needUpdatePhi = false; - int64_t removedFreq = 0; + uint64 removedFreq = 0; if (cfg->UpdateCFGFreq()) { int idx = pred->GetSuccIndex(*succ); - removedFreq = static_cast(pred->GetSuccFreq()[static_cast(idx)]); + removedFreq = pred->GetSuccFreq()[static_cast(idx)]; } if (pred->IsPredBB(*newTarget)) { pred->RemoveSucc(*succ, true); // one of pred's succ has been newTarget, avoid duplicate succ here if (cfg->UpdateCFGFreq()) { int idx = pred->GetSuccIndex(*newTarget); - pred->SetSuccFreq(idx, pred->GetSuccFreq()[static_cast(idx)] + static_cast(removedFreq)); + pred->SetSuccFreq(idx, pred->GetSuccFreq()[static_cast(idx)] + removedFreq); } } else { pred->ReplaceSucc(succ, newTarget); // phi opnd is not removed from currBB's philist, we will remove it later needUpdatePhi = true; } if (cfg->UpdateCFGFreq()) { - int64_t succFreq = succ->GetFrequency(); + uint64 succFreq = succ->GetFrequency(); ASSERT(succFreq >= removedFreq, "sanity check"); - succ->SetFrequency(static_cast(succFreq - removedFreq)); + succ->SetFrequency(succFreq - removedFreq); succ->SetSuccFreq(0, succ->GetFrequency()); } DEBUG_LOG() << "Merge Uncond BB" << LOG_BBID(succ) << " to its pred BB" << LOG_BBID(pred) << ": BB" << LOG_BBID(pred) diff --git a/src/mapleall/maple_me/src/pme_emit.cpp b/src/mapleall/maple_me/src/pme_emit.cpp index 4f3f8c4b7455591fd00b8958ddf436a05d1c143d..56dbc5b764c9a610843fa0fb938541842e9fc24b 100644 --- a/src/mapleall/maple_me/src/pme_emit.cpp +++ b/src/mapleall/maple_me/src/pme_emit.cpp @@ -767,7 +767,7 @@ void PreMeEmitter::UpdateStmtInfoForLabelNode(LabelNode &label, BB &bb) { label.SetStmtInfoId(ipaInfo->GetRealFirstStmtInfoId(bb)); } -void PreMeEmitter::UpdateStmtInfo(const MeStmt &meStmt, StmtNode &stmt, BlockNode &currBlock, uint32 frequency) { +void PreMeEmitter::UpdateStmtInfo(const MeStmt &meStmt, StmtNode &stmt, BlockNode &currBlock, uint64 frequency) { if (ipaInfo == nullptr || meStmt.GetStmtInfoId() == kInvalidIndex) { return; } @@ -1066,10 +1066,10 @@ uint32 PreMeEmitter::Raise2PreMeIf(uint32 curJ, BlockNode *curBlk) { CHECK_FATAL(j < bbvec.size(), ""); if (GetFuncProfData()) { // set then part/else part frequency - int64_t ifFreq = GetFuncProfData()->GetStmtFreq(ifStmtNode->GetStmtID()); - int64_t branchFreq = bbvec[curJ + 1]->GetFrequency(); - GetFuncProfData()->SetStmtFreq(branchBlock->GetStmtID(), static_cast(branchFreq)); - GetFuncProfData()->SetStmtFreq(emptyBlock->GetStmtID(), static_cast(ifFreq - branchFreq)); + uint64 ifFreq = GetFuncProfData()->GetStmtFreq(ifStmtNode->GetStmtID()); + uint64 branchFreq = bbvec[curJ + 1]->GetFrequency(); + GetFuncProfData()->SetStmtFreq(branchBlock->GetStmtID(), branchFreq); + GetFuncProfData()->SetStmtFreq(emptyBlock->GetStmtID(), ifFreq - branchFreq); } return j; }