57 #define DEBUG_TYPE "if-converter" 82 STATISTIC(NumSimple,
"Number of simple if-conversions performed");
83 STATISTIC(NumSimpleFalse,
"Number of simple (F) if-conversions performed");
84 STATISTIC(NumTriangle,
"Number of triangle if-conversions performed");
85 STATISTIC(NumTriangleRev,
"Number of triangle (R) if-conversions performed");
86 STATISTIC(NumTriangleFalse,
"Number of triangle (F) if-conversions performed");
87 STATISTIC(NumTriangleFRev,
"Number of triangle (F/R) if-conversions performed");
88 STATISTIC(NumDiamonds,
"Number of diamond if-conversions performed");
89 STATISTIC(NumForkedDiamonds,
"Number of forked-diamond if-conversions performed");
90 STATISTIC(NumIfConvBBs,
"Number of if-converted blocks");
91 STATISTIC(NumDupBBs,
"Number of duplicated blocks");
92 STATISTIC(NumUnpred,
"Number of true blocks of diamonds unpredicated");
135 bool IsBeingAnalyzed : 1;
138 bool IsBrAnalyzable : 1;
139 bool IsBrReversible : 1;
140 bool HasFallThrough : 1;
141 bool IsUnpredicable : 1;
142 bool CannotBeCopied : 1;
143 bool ClobbersPred : 1;
144 unsigned NonPredSize = 0;
145 unsigned ExtraCost = 0;
146 unsigned ExtraCost2 = 0;
153 BBInfo() : IsDone(
false), IsBeingAnalyzed(
false),
157 ClobbersPred(
false) {}
176 bool NeedSubsumption : 1;
177 bool TClobbersPred : 1;
178 bool FClobbersPred : 1;
180 IfcvtToken(BBInfo &b, IfcvtKind k,
bool s,
unsigned d,
unsigned d2 = 0,
181 bool tc =
false,
bool fc =
false)
182 : BBI(b), Kind(k), NumDups(d), NumDups2(d2), NeedSubsumption(s),
183 TClobbersPred(tc), FClobbersPred(fc) {}
188 std::vector<BBInfo> BBAnalysis;
202 std::function<bool(const MachineFunction &)> PredicateFtor;
226 bool reverseBranchCondition(BBInfo &BBI)
const;
227 bool ValidSimple(BBInfo &TrueBBI,
unsigned &Dups,
229 bool ValidTriangle(BBInfo &TrueBBI, BBInfo &FalseBBI,
230 bool FalseBranch,
unsigned &Dups,
232 bool CountDuplicatedInstructions(
235 unsigned &Dups1,
unsigned &Dups2,
237 bool SkipUnconditionalBranches)
const;
238 bool ValidDiamond(BBInfo &TrueBBI, BBInfo &FalseBBI,
239 unsigned &Dups1,
unsigned &Dups2,
240 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const;
241 bool ValidForkedDiamond(BBInfo &TrueBBI, BBInfo &FalseBBI,
242 unsigned &Dups1,
unsigned &Dups2,
243 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const;
244 void AnalyzeBranches(BBInfo &BBI);
245 void ScanInstructions(BBInfo &BBI,
248 bool BranchUnpredicable =
false)
const;
249 bool RescanInstructions(
252 BBInfo &TrueBBI, BBInfo &FalseBBI)
const;
254 std::vector<std::unique_ptr<IfcvtToken>> &Tokens);
256 bool isTriangle =
false,
bool RevBranch =
false,
257 bool hasCommonTail =
false);
259 std::vector<std::unique_ptr<IfcvtToken>> &Tokens);
261 bool IfConvertSimple(BBInfo &BBI, IfcvtKind
Kind);
262 bool IfConvertTriangle(BBInfo &BBI, IfcvtKind
Kind);
263 bool IfConvertDiamondCommon(BBInfo &BBI, BBInfo &TrueBBI, BBInfo &FalseBBI,
264 unsigned NumDups1,
unsigned NumDups2,
265 bool TClobbersPred,
bool FClobbersPred,
266 bool RemoveBranch,
bool MergeAddEdges);
267 bool IfConvertDiamond(BBInfo &BBI, IfcvtKind
Kind,
268 unsigned NumDups1,
unsigned NumDups2,
269 bool TClobbers,
bool FClobbers);
270 bool IfConvertForkedDiamond(BBInfo &BBI, IfcvtKind
Kind,
271 unsigned NumDups1,
unsigned NumDups2,
272 bool TClobbers,
bool FClobbers);
273 void PredicateBlock(BBInfo &BBI,
277 void CopyAndPredicateBlock(BBInfo &ToBBI, BBInfo &FromBBI,
279 bool IgnoreBr =
false);
280 void MergeBlocks(BBInfo &ToBBI, BBInfo &FromBBI,
bool AddEdges =
true);
283 unsigned Cycle,
unsigned Extra,
290 unsigned TCycle,
unsigned TExtra,
292 unsigned FCycle,
unsigned FExtra,
294 return TCycle > 0 && FCycle > 0 &&
300 bool blockAlwaysFallThrough(BBInfo &BBI)
const {
301 return BBI.IsBrAnalyzable && BBI.TrueBB ==
nullptr;
305 static bool IfcvtTokenCmp(
const std::unique_ptr<IfcvtToken> &C1,
306 const std::unique_ptr<IfcvtToken> &C2) {
307 int Incr1 = (C1->Kind == ICDiamond)
308 ? -(
int)(C1->NumDups + C1->NumDups2) : (
int)C1->NumDups;
309 int Incr2 = (C2->Kind == ICDiamond)
310 ? -(
int)(C2->NumDups + C2->NumDups2) : (
int)C2->NumDups;
313 else if (Incr1 == Incr2) {
315 if (!C1->NeedSubsumption && C2->NeedSubsumption)
317 else if (C1->NeedSubsumption == C2->NeedSubsumption) {
319 if ((
unsigned)C1->Kind < (
unsigned)C2->Kind)
321 else if (C1->Kind == C2->Kind)
322 return C1->BBI.BB->getNumber() < C2->BBI.BB->getNumber();
340 if (skipFunction(MF.getFunction()) || (PredicateFtor && !PredicateFtor(MF)))
348 MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
349 MRI = &MF.getRegInfo();
350 SchedModel.
init(&ST);
352 if (!TII)
return false;
354 PreRegAlloc = MRI->isSSA();
356 bool BFChange =
false;
361 getAnalysisIfAvailable<MachineModuleInfo>());
365 << MF.getName() <<
"\'");
374 BBAnalysis.resize(MF.getNumBlockIDs());
376 std::vector<std::unique_ptr<IfcvtToken>> Tokens;
378 unsigned NumIfCvts = NumSimple + NumSimpleFalse + NumTriangle +
379 NumTriangleRev + NumTriangleFalse + NumTriangleFRev + NumDiamonds;
384 AnalyzeBlocks(MF, Tokens);
385 while (!Tokens.empty()) {
386 std::unique_ptr<IfcvtToken> Token = std::move(Tokens.back());
388 BBInfo &BBI = Token->BBI;
389 IfcvtKind
Kind = Token->Kind;
390 unsigned NumDups = Token->NumDups;
391 unsigned NumDups2 = Token->NumDups2;
396 BBI.IsEnqueued =
false;
400 BBI.IsEnqueued =
false;
406 case ICSimpleFalse: {
407 bool isFalse = Kind == ICSimpleFalse;
410 << (Kind == ICSimpleFalse ?
" false" :
"")
412 << ((Kind == ICSimpleFalse) ? BBI.FalseBB->getNumber()
413 : BBI.TrueBB->getNumber())
415 RetVal = IfConvertSimple(BBI, Kind);
416 LLVM_DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
418 if (isFalse) ++NumSimpleFalse;
425 case ICTriangleFalse:
426 case ICTriangleFRev: {
427 bool isFalse = Kind == ICTriangleFalse;
428 bool isRev = (Kind == ICTriangleRev || Kind == ICTriangleFRev);
439 <<
" (T:" << BBI.TrueBB->getNumber()
440 <<
",F:" << BBI.FalseBB->getNumber() <<
") ");
441 RetVal = IfConvertTriangle(BBI, Kind);
442 LLVM_DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
445 if (isRev) ++NumTriangleFRev;
446 else ++NumTriangleFalse;
448 if (isRev) ++NumTriangleRev;
457 <<
" (T:" << BBI.TrueBB->getNumber()
458 <<
",F:" << BBI.FalseBB->getNumber() <<
") ");
459 RetVal = IfConvertDiamond(BBI, Kind, NumDups, NumDups2,
460 Token->TClobbersPred,
461 Token->FClobbersPred);
462 LLVM_DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
463 if (RetVal) ++NumDiamonds;
465 case ICForkedDiamond:
469 <<
" (T:" << BBI.TrueBB->getNumber()
470 <<
",F:" << BBI.FalseBB->getNumber() <<
") ");
471 RetVal = IfConvertForkedDiamond(BBI, Kind, NumDups, NumDups2,
472 Token->TClobbersPred,
473 Token->FClobbersPred);
474 LLVM_DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
475 if (RetVal) ++NumForkedDiamonds;
479 if (RetVal && MRI->tracksLiveness())
484 NumIfCvts = NumSimple + NumSimpleFalse + NumTriangle + NumTriangleRev +
485 NumTriangleFalse + NumTriangleFRev + NumDiamonds;
492 MadeChange |= Change;
501 getAnalysisIfAvailable<MachineModuleInfo>());
504 MadeChange |= BFChange;
512 if (SuccBB != TrueBB)
520 bool IfConverter::reverseBranchCondition(BBInfo &BBI)
const {
524 TII->
insertBranch(*BBI.BB, BBI.FalseBB, BBI.TrueBB, BBI.BrCond, dl);
544 bool IfConverter::ValidSimple(BBInfo &TrueBBI,
unsigned &Dups,
547 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone)
550 if (TrueBBI.IsBrAnalyzable)
553 if (TrueBBI.BB->pred_size() > 1) {
554 if (TrueBBI.CannotBeCopied ||
558 Dups = TrueBBI.NonPredSize;
569 bool IfConverter::ValidTriangle(BBInfo &TrueBBI, BBInfo &FalseBBI,
570 bool FalseBranch,
unsigned &Dups,
573 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone)
576 if (TrueBBI.BB->pred_size() > 1) {
577 if (TrueBBI.CannotBeCopied)
580 unsigned Size = TrueBBI.NonPredSize;
581 if (TrueBBI.IsBrAnalyzable) {
582 if (TrueBBI.TrueBB && TrueBBI.BrCond.empty())
587 ? TrueBBI.TrueBB : TrueBBI.FalseBB;
599 if (!TExit && blockAlwaysFallThrough(TrueBBI)) {
601 if (++I == TrueBBI.BB->getParent()->end())
605 return TExit && TExit == FalseBBI.BB;
628 bool IfConverter::CountDuplicatedInstructions(
633 unsigned &Dups1,
unsigned &Dups2,
635 bool SkipUnconditionalBranches)
const {
636 while (TIB != TIE && FIB != FIE) {
640 if (TIB == TIE || FIB == FIE)
642 if (!TIB->isIdenticalTo(*FIB))
646 std::vector<MachineOperand> PredDefs;
650 if (!TIB->isBranch())
657 if (TIB == TIE || FIB == FIE)
669 if (SkipUnconditionalBranches) {
670 while (RTIE != RTIB && RTIE->isUnconditionalBranch())
672 while (RFIE != RFIB && RFIE->isUnconditionalBranch())
678 while (RTIE != RTIB && RFIE != RFIB) {
683 if (RTIE == RTIB || RFIE == RFIB)
685 if (!RTIE->isIdenticalTo(*RFIE))
689 if (!RTIE->isBranch())
695 FIE = std::next(RFIE.getReverse());
708 bool IfConverter::RescanInstructions(
711 BBInfo &TrueBBI, BBInfo &FalseBBI)
const {
712 bool BranchUnpredicable =
true;
713 TrueBBI.IsUnpredicable = FalseBBI.IsUnpredicable =
false;
714 ScanInstructions(TrueBBI, TIB, TIE, BranchUnpredicable);
715 if (TrueBBI.IsUnpredicable)
717 ScanInstructions(FalseBBI, FIB, FIE, BranchUnpredicable);
718 if (FalseBBI.IsUnpredicable)
720 if (TrueBBI.ClobbersPred && FalseBBI.ClobbersPred)
733 while (E1 != B1 && E2 != B2) {
736 if (E1 == B1 && E2 == B2)
740 assert(!E2->isBranch() &&
"Branch mis-match, one block is empty.");
744 assert(!E1->isBranch() &&
"Branch mis-match, one block is empty.");
748 if (E1->isBranch() || E2->isBranch())
749 assert(E1->isIdenticalTo(*E2) &&
750 "Branch mis-match, branch instructions don't match.");
772 bool IfConverter::ValidForkedDiamond(
773 BBInfo &TrueBBI, BBInfo &FalseBBI,
774 unsigned &Dups1,
unsigned &Dups2,
775 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const {
777 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone ||
778 FalseBBI.IsBeingAnalyzed || FalseBBI.IsDone)
781 if (!TrueBBI.IsBrAnalyzable || !FalseBBI.IsBrAnalyzable)
784 if (TrueBBI.BB->pred_size() > 1 || FalseBBI.BB->pred_size() > 1)
789 if (TrueBBI.BrCond.size() == 0 ||
790 FalseBBI.BrCond.size() == 0)
811 if (!((TT == FT && TF == FF) || (TF == FT && TT == FF)))
814 bool FalseReversed =
false;
815 if (TF == FT && TT == FF) {
817 if (!FalseBBI.IsBrReversible)
819 FalseReversed =
true;
820 reverseBranchCondition(FalseBBI);
824 reverseBranchCondition(FalseBBI);
832 if(!CountDuplicatedInstructions(TIB, FIB, TIE, FIE, Dups1, Dups2,
833 *TrueBBI.BB, *FalseBBI.BB,
837 TrueBBICalc.BB = TrueBBI.BB;
838 FalseBBICalc.BB = FalseBBI.BB;
839 if (!RescanInstructions(TIB, FIB, TIE, FIE, TrueBBICalc, FalseBBICalc))
845 TrueBBICalc.NonPredSize = TrueBBI.NonPredSize;
846 FalseBBICalc.NonPredSize = FalseBBI.NonPredSize;
852 bool IfConverter::ValidDiamond(
853 BBInfo &TrueBBI, BBInfo &FalseBBI,
854 unsigned &Dups1,
unsigned &Dups2,
855 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const {
857 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone ||
858 FalseBBI.IsBeingAnalyzed || FalseBBI.IsDone)
864 if (!TT && blockAlwaysFallThrough(TrueBBI))
866 if (!FT && blockAlwaysFallThrough(FalseBBI))
870 if (!TT && (TrueBBI.IsBrAnalyzable || FalseBBI.IsBrAnalyzable))
872 if (TrueBBI.BB->pred_size() > 1 || FalseBBI.BB->pred_size() > 1)
876 if (TrueBBI.FalseBB || FalseBBI.FalseBB)
883 bool SkipUnconditionalBranches =
884 TrueBBI.IsBrAnalyzable && FalseBBI.IsBrAnalyzable;
889 if(!CountDuplicatedInstructions(TIB, FIB, TIE, FIE, Dups1, Dups2,
890 *TrueBBI.BB, *FalseBBI.BB,
891 SkipUnconditionalBranches))
894 TrueBBICalc.BB = TrueBBI.BB;
895 FalseBBICalc.BB = FalseBBI.BB;
896 if (!RescanInstructions(TIB, FIB, TIE, FIE, TrueBBICalc, FalseBBICalc))
901 TrueBBICalc.NonPredSize = TrueBBI.NonPredSize;
902 FalseBBICalc.NonPredSize = FalseBBI.NonPredSize;
908 void IfConverter::AnalyzeBranches(BBInfo &BBI) {
912 BBI.TrueBB = BBI.FalseBB =
nullptr;
915 !TII->
analyzeBranch(*BBI.BB, BBI.TrueBB, BBI.FalseBB, BBI.BrCond);
917 BBI.IsBrReversible = (RevCond.size() == 0) ||
919 BBI.HasFallThrough = BBI.IsBrAnalyzable && BBI.FalseBB ==
nullptr;
921 if (BBI.BrCond.size()) {
928 BBI.IsUnpredicable =
true;
938 void IfConverter::ScanInstructions(BBInfo &BBI,
941 bool BranchUnpredicable)
const {
942 if (BBI.IsDone || BBI.IsUnpredicable)
945 bool AlreadyPredicated = !BBI.Predicate.empty();
950 BBI.ClobbersPred =
false;
952 if (
MI.isDebugInstr())
985 if (
MI.isNotDuplicable() ||
MI.isConvergent())
986 BBI.CannotBeCopied =
true;
989 bool isCondBr = BBI.IsBrAnalyzable &&
MI.isConditionalBranch();
991 if (BranchUnpredicable &&
MI.isBranch()) {
992 BBI.IsUnpredicable =
true;
1003 unsigned NumCycles = SchedModel.computeInstrLatency(&
MI,
false);
1005 BBI.ExtraCost += NumCycles-1;
1006 BBI.ExtraCost2 += ExtraPredCost;
1007 }
else if (!AlreadyPredicated) {
1011 BBI.IsUnpredicable =
true;
1020 BBI.IsUnpredicable =
true;
1026 std::vector<MachineOperand> PredDefs;
1028 BBI.ClobbersPred =
true;
1031 BBI.IsUnpredicable =
true;
1046 bool IfConverter::FeasibilityAnalysis(BBInfo &BBI,
1048 bool isTriangle,
bool RevBranch,
1049 bool hasCommonTail) {
1054 if (BBI.IsDone || (BBI.IsUnpredicable && !hasCommonTail))
1060 if (BBI.Predicate.size() && !BBI.IsBrAnalyzable)
1068 if (!hasCommonTail && BBI.BrCond.size()) {
1089 void IfConverter::AnalyzeBlock(
1102 while (!BBStack.
empty()) {
1103 BBState &State = BBStack.
back();
1105 BBInfo &BBI = BBAnalysis[BB->
getNumber()];
1107 if (!State.SuccsAnalyzed) {
1108 if (BBI.IsAnalyzed || BBI.IsBeingAnalyzed) {
1114 BBI.IsBeingAnalyzed =
true;
1116 AnalyzeBranches(BBI);
1119 ScanInstructions(BBI, Begin, End);
1123 if (!BBI.IsBrAnalyzable || BBI.BrCond.empty() || BBI.IsDone) {
1124 BBI.IsBeingAnalyzed =
false;
1125 BBI.IsAnalyzed =
true;
1131 if (BBI.TrueBB == BB || BBI.FalseBB == BB) {
1132 BBI.IsBeingAnalyzed =
false;
1133 BBI.IsAnalyzed =
true;
1140 BBI.IsBeingAnalyzed =
false;
1141 BBI.IsAnalyzed =
true;
1147 State.SuccsAnalyzed =
true;
1153 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1154 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1156 if (TrueBBI.IsDone && FalseBBI.IsDone) {
1157 BBI.IsBeingAnalyzed =
false;
1158 BBI.IsAnalyzed =
true;
1164 RevCond(BBI.BrCond.begin(), BBI.BrCond.end());
1169 bool TNeedSub = !TrueBBI.Predicate.empty();
1170 bool FNeedSub = !FalseBBI.Predicate.empty();
1171 bool Enqueued =
false;
1176 BBInfo TrueBBICalc, FalseBBICalc;
1177 auto feasibleDiamond = [&]() {
1178 bool MeetsSize = MeetIfcvtSizeLimit(
1179 *TrueBBI.BB, (TrueBBICalc.NonPredSize - (Dups + Dups2) +
1180 TrueBBICalc.ExtraCost), TrueBBICalc.ExtraCost2,
1181 *FalseBBI.BB, (FalseBBICalc.NonPredSize - (Dups + Dups2) +
1182 FalseBBICalc.ExtraCost), FalseBBICalc.ExtraCost2,
1184 bool TrueFeasible = FeasibilityAnalysis(TrueBBI, BBI.BrCond,
1187 bool FalseFeasible = FeasibilityAnalysis(FalseBBI, RevCond,
1190 return MeetsSize && TrueFeasible && FalseFeasible;
1193 if (ValidDiamond(TrueBBI, FalseBBI, Dups, Dups2,
1194 TrueBBICalc, FalseBBICalc)) {
1195 if (feasibleDiamond()) {
1204 Tokens.push_back(llvm::make_unique<IfcvtToken>(
1205 BBI, ICDiamond, TNeedSub | FNeedSub, Dups, Dups2,
1206 (
bool) TrueBBICalc.ClobbersPred, (
bool) FalseBBICalc.ClobbersPred));
1209 }
else if (ValidForkedDiamond(TrueBBI, FalseBBI, Dups, Dups2,
1210 TrueBBICalc, FalseBBICalc)) {
1211 if (feasibleDiamond()) {
1222 Tokens.push_back(llvm::make_unique<IfcvtToken>(
1223 BBI, ICForkedDiamond, TNeedSub | FNeedSub, Dups, Dups2,
1224 (
bool) TrueBBICalc.ClobbersPred, (
bool) FalseBBICalc.ClobbersPred));
1230 if (ValidTriangle(TrueBBI, FalseBBI,
false, Dups, Prediction) &&
1231 MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize + TrueBBI.ExtraCost,
1232 TrueBBI.ExtraCost2, Prediction) &&
1233 FeasibilityAnalysis(TrueBBI, BBI.BrCond,
true)) {
1242 llvm::make_unique<IfcvtToken>(BBI, ICTriangle, TNeedSub, Dups));
1246 if (ValidTriangle(TrueBBI, FalseBBI,
true, Dups, Prediction) &&
1247 MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize + TrueBBI.ExtraCost,
1248 TrueBBI.ExtraCost2, Prediction) &&
1249 FeasibilityAnalysis(TrueBBI, BBI.BrCond,
true,
true)) {
1251 llvm::make_unique<IfcvtToken>(BBI, ICTriangleRev, TNeedSub, Dups));
1255 if (ValidSimple(TrueBBI, Dups, Prediction) &&
1256 MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize + TrueBBI.ExtraCost,
1257 TrueBBI.ExtraCost2, Prediction) &&
1258 FeasibilityAnalysis(TrueBBI, BBI.BrCond)) {
1267 llvm::make_unique<IfcvtToken>(BBI, ICSimple, TNeedSub, Dups));
1273 if (ValidTriangle(FalseBBI, TrueBBI,
false, Dups,
1275 MeetIfcvtSizeLimit(*FalseBBI.BB,
1276 FalseBBI.NonPredSize + FalseBBI.ExtraCost,
1277 FalseBBI.ExtraCost2, Prediction.
getCompl()) &&
1278 FeasibilityAnalysis(FalseBBI, RevCond,
true)) {
1279 Tokens.push_back(llvm::make_unique<IfcvtToken>(BBI, ICTriangleFalse,
1284 if (ValidTriangle(FalseBBI, TrueBBI,
true, Dups,
1286 MeetIfcvtSizeLimit(*FalseBBI.BB,
1287 FalseBBI.NonPredSize + FalseBBI.ExtraCost,
1288 FalseBBI.ExtraCost2, Prediction.
getCompl()) &&
1289 FeasibilityAnalysis(FalseBBI, RevCond,
true,
true)) {
1291 llvm::make_unique<IfcvtToken>(BBI, ICTriangleFRev, FNeedSub, Dups));
1295 if (ValidSimple(FalseBBI, Dups, Prediction.
getCompl()) &&
1296 MeetIfcvtSizeLimit(*FalseBBI.BB,
1297 FalseBBI.NonPredSize + FalseBBI.ExtraCost,
1298 FalseBBI.ExtraCost2, Prediction.
getCompl()) &&
1299 FeasibilityAnalysis(FalseBBI, RevCond)) {
1301 llvm::make_unique<IfcvtToken>(BBI, ICSimpleFalse, FNeedSub, Dups));
1306 BBI.IsEnqueued = Enqueued;
1307 BBI.IsBeingAnalyzed =
false;
1308 BBI.IsAnalyzed =
true;
1314 void IfConverter::AnalyzeBlocks(
1315 MachineFunction &MF, std::vector<std::unique_ptr<IfcvtToken>> &Tokens) {
1317 AnalyzeBlock(MBB, Tokens);
1320 std::stable_sort(Tokens.begin(), Tokens.end(), IfcvtTokenCmp);
1333 if (I == E || !I->empty() || !PI->isSuccessor(&*I))
1338 return PI->isSuccessor(&*I);
1345 BBInfo &PBBI = BBAnalysis[Predecessor->getNumber()];
1346 if (PBBI.IsDone || PBBI.BB == &MBB)
1348 PBBI.IsAnalyzed =
false;
1349 PBBI.IsEnqueued =
false;
1371 for (
unsigned Reg : Redefs)
1375 Redefs.stepForward(MI, Clobbers);
1378 for (
auto Clobber : Clobbers) {
1381 unsigned Reg = Clobber.first;
1388 if (LiveBeforeMI.
count(Reg))
1399 if (LiveBeforeMI.
count(Reg))
1402 bool HasLiveSubReg =
false;
1404 if (!LiveBeforeMI.
count(*S))
1406 HasLiveSubReg =
true;
1416 bool IfConverter::IfConvertSimple(BBInfo &BBI, IfcvtKind
Kind) {
1417 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1418 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1419 BBInfo *CvtBBI = &TrueBBI;
1420 BBInfo *NextBBI = &FalseBBI;
1423 if (Kind == ICSimpleFalse)
1428 if (CvtBBI->IsDone ||
1429 (CvtBBI->CannotBeCopied && CvtMBB.
pred_size() > 1)) {
1431 BBI.IsAnalyzed =
false;
1432 CvtBBI->IsAnalyzed =
false;
1440 if (Kind == ICSimpleFalse)
1460 CopyAndPredicateBlock(BBI, *CvtBBI, Cond);
1463 BBI.BB->removeSuccessor(&CvtMBB,
true);
1466 PredicateBlock(*CvtBBI, CvtMBB.
end(), Cond);
1470 MergeBlocks(BBI, *CvtBBI);
1473 bool IterIfcvt =
true;
1476 BBI.HasFallThrough =
false;
1493 InvalidatePreds(*BBI.BB);
1494 CvtBBI->IsDone =
true;
1501 bool IfConverter::IfConvertTriangle(BBInfo &BBI, IfcvtKind Kind) {
1502 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1503 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1504 BBInfo *CvtBBI = &TrueBBI;
1505 BBInfo *NextBBI = &FalseBBI;
1509 if (Kind == ICTriangleFalse || Kind == ICTriangleFRev)
1514 if (CvtBBI->IsDone ||
1515 (CvtBBI->CannotBeCopied && CvtMBB.
pred_size() > 1)) {
1517 BBI.IsAnalyzed =
false;
1518 CvtBBI->IsAnalyzed =
false;
1526 if (Kind == ICTriangleFalse || Kind == ICTriangleFRev)
1530 if (Kind == ICTriangleRev || Kind == ICTriangleFRev) {
1531 if (reverseBranchCondition(*CvtBBI)) {
1537 BBInfo &PBBI = BBAnalysis[PBB->getNumber()];
1538 if (PBBI.IsEnqueued) {
1539 PBBI.IsAnalyzed =
false;
1540 PBBI.IsEnqueued =
false;
1554 bool HasEarlyExit = CvtBBI->FalseBB !=
nullptr;
1572 CopyAndPredicateBlock(BBI, *CvtBBI, Cond,
true);
1576 PredicateBlock(*CvtBBI, CvtMBB.
end(), Cond);
1579 MergeBlocks(BBI, *CvtBBI,
false);
1583 BBI.BB->removeSuccessor(&CvtMBB,
true);
1588 CvtBBI->BrCond.end());
1599 auto NewNext = BBNext + BBCvt * CvtNext;
1600 auto NewTrueBBIter =
find(BBI.BB->successors(), NewTrueBB);
1601 if (NewTrueBBIter != BBI.BB->succ_end())
1602 BBI.BB->setSuccProbability(NewTrueBBIter, NewNext);
1604 auto NewFalse = BBCvt * CvtFalse;
1605 TII->
insertBranch(*BBI.BB, CvtBBI->FalseBB,
nullptr, RevCond, dl);
1606 BBI.BB->addSuccessor(CvtBBI->FalseBB, NewFalse);
1611 bool FalseBBDead =
false;
1612 bool IterIfcvt =
true;
1614 if (!isFallThrough) {
1618 if (!HasEarlyExit &&
1619 NextMBB.
pred_size() == 1 && !NextBBI->HasFallThrough &&
1621 MergeBlocks(BBI, *NextBBI);
1625 BBI.HasFallThrough =
false;
1635 InvalidatePreds(*BBI.BB);
1636 CvtBBI->IsDone =
true;
1638 NextBBI->IsDone =
true;
1655 bool IfConverter::IfConvertDiamondCommon(
1656 BBInfo &BBI, BBInfo &TrueBBI, BBInfo &FalseBBI,
1657 unsigned NumDups1,
unsigned NumDups2,
1658 bool TClobbersPred,
bool FClobbersPred,
1659 bool RemoveBranch,
bool MergeAddEdges) {
1661 if (TrueBBI.IsDone || FalseBBI.IsDone ||
1662 TrueBBI.BB->pred_size() > 1 || FalseBBI.BB->pred_size() > 1) {
1664 BBI.IsAnalyzed =
false;
1665 TrueBBI.IsAnalyzed =
false;
1666 FalseBBI.IsAnalyzed =
false;
1670 if (TrueBBI.BB->hasAddressTaken() || FalseBBI.BB->hasAddressTaken())
1677 BBInfo *BBI1 = &TrueBBI;
1678 BBInfo *BBI2 = &FalseBBI;
1686 bool DoSwap =
false;
1687 if (TClobbersPred && !FClobbersPred)
1689 else if (!TClobbersPred && !FClobbersPred) {
1690 if (TrueBBI.NonPredSize > FalseBBI.NonPredSize)
1692 }
else if (TClobbersPred && FClobbersPred)
1721 BBI1->NonPredSize -= NumDups1;
1722 BBI2->NonPredSize -= NumDups1;
1727 for (
unsigned i = 0; i < NumDups1; ++DI1) {
1728 if (DI1 == MBB1.
end())
1730 if (!DI1->isDebugInstr())
1733 while (NumDups1 != 0) {
1735 if (DI2 == MBB2.
end())
1737 if (!DI2->isDebugInstr())
1748 BBI.BB->splice(BBI.BB->end(), &MBB1, MBB1.
begin(), DI1);
1759 if (!BBI1->IsBrAnalyzable)
1765 for (
unsigned i = 0; i != NumDups2; ) {
1771 if (!DI1->isDebugInstr())
1776 DI2 = BBI2->BB->end();
1784 while (DI2 != MBB2.
begin()) {
1786 if (!Prev->isBranch() && !Prev->isDebugInstr())
1791 while (NumDups2 != 0) {
1797 if (!DI2->isDebugInstr())
1813 if (FI.isDebugInstr())
1819 unsigned Reg = MO.getReg();
1824 }
else if (!RedefsByFalse.
count(Reg)) {
1829 ExtUses.
insert(*SubRegs);
1837 RedefsByFalse.
insert(*SubRegs);
1844 PredicateBlock(*BBI1, MBB1.
end(), *Cond1, &RedefsByFalse);
1853 if (!MBB2.
empty() && (DI2 == MBB2.
end())) {
1856 bool BB1Predicated = BBI1T != MBB1.
end() && TII->
isPredicated(*BBI1T);
1857 bool BB2NonPredicated = BBI2T != MBB2.
end() && !TII->
isPredicated(*BBI2T);
1858 if (BB2NonPredicated && (BB1Predicated || !BBI2->IsBrAnalyzable))
1863 PredicateBlock(*BBI2, DI2, *Cond2);
1866 MergeBlocks(BBI, *BBI1, MergeAddEdges);
1867 MergeBlocks(BBI, *BBI2, MergeAddEdges);
1873 bool IfConverter::IfConvertForkedDiamond(
1874 BBInfo &BBI, IfcvtKind Kind,
1875 unsigned NumDups1,
unsigned NumDups2,
1876 bool TClobbersPred,
bool FClobbersPred) {
1877 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1878 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1883 if (TIE != TrueBBI.BB->end())
1884 dl = TIE->getDebugLoc();
1888 if (!IfConvertDiamondCommon(
1889 BBI, TrueBBI, FalseBBI,
1891 TClobbersPred, FClobbersPred,
1897 TII->
insertBranch(*BBI.BB, TrueBBI.TrueBB, TrueBBI.FalseBB,
1898 TrueBBI.BrCond, dl);
1901 BBI.IsDone = TrueBBI.IsDone = FalseBBI.IsDone =
true;
1902 InvalidatePreds(*BBI.BB);
1909 bool IfConverter::IfConvertDiamond(BBInfo &BBI, IfcvtKind Kind,
1910 unsigned NumDups1,
unsigned NumDups2,
1911 bool TClobbersPred,
bool FClobbersPred) {
1912 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1913 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1918 if (blockAlwaysFallThrough(TrueBBI))
1919 TailBB = FalseBBI.TrueBB;
1920 assert((TailBB || !TrueBBI.IsBrAnalyzable) &&
"Unexpected!");
1923 if (!IfConvertDiamondCommon(
1924 BBI, TrueBBI, FalseBBI,
1926 TClobbersPred, FClobbersPred,
1927 TrueBBI.IsBrAnalyzable,
1938 BBI.BB->removeSuccessor(TrueBBI.BB);
1939 BBI.BB->removeSuccessor(FalseBBI.BB,
true);
1941 BBInfo &TailBBI = BBAnalysis[TailBB->
getNumber()];
1942 bool CanMergeTail = !TailBBI.HasFallThrough &&
1943 !TailBBI.BB->hasAddressTaken();
1949 CanMergeTail =
false;
1952 unsigned NumPreds = TailBB->
pred_size();
1954 CanMergeTail =
false;
1955 else if (NumPreds == 1 && CanMergeTail) {
1957 if (*PI != TrueBBI.BB && *PI != FalseBBI.BB)
1958 CanMergeTail =
false;
1961 MergeBlocks(BBI, TailBBI);
1962 TailBBI.IsDone =
true;
1966 BBI.HasFallThrough =
false;
1971 BBI.IsDone = TrueBBI.IsDone = FalseBBI.IsDone =
true;
1972 InvalidatePreds(*BBI.BB);
1980 bool SawStore =
true;
1987 unsigned Reg = MO.getReg();
1990 if (MO.isDef() && !LaterRedefs.
count(Reg))
1999 void IfConverter::PredicateBlock(BBInfo &BBI,
2003 bool AnyUnpred =
false;
2004 bool MaySpec = LaterRedefs !=
nullptr;
2020 dbgs() <<
"Unable to predicate " <<
I <<
"!\n";
2030 BBI.Predicate.append(Cond.
begin(), Cond.
end());
2032 BBI.IsAnalyzed =
false;
2033 BBI.NonPredSize = 0;
2042 void IfConverter::CopyAndPredicateBlock(BBInfo &ToBBI, BBInfo &FromBBI,
2050 if (IgnoreBr &&
I.isBranch())
2054 ToBBI.BB->insert(ToBBI.BB->end(),
MI);
2055 ToBBI.NonPredSize++;
2057 unsigned NumCycles = SchedModel.computeInstrLatency(&
I,
false);
2059 ToBBI.ExtraCost += NumCycles-1;
2060 ToBBI.ExtraCost2 += ExtraPredCost;
2065 dbgs() <<
"Unable to predicate " <<
I <<
"!\n";
2077 std::vector<MachineBasicBlock *> Succs(FromMBB.succ_begin(),
2078 FromMBB.succ_end());
2084 if (Succ == FallThrough)
2086 ToBBI.BB->addSuccessor(Succ);
2090 ToBBI.Predicate.append(FromBBI.Predicate.begin(), FromBBI.Predicate.end());
2091 ToBBI.Predicate.append(Cond.
begin(), Cond.
end());
2093 ToBBI.ClobbersPred |= FromBBI.ClobbersPred;
2094 ToBBI.IsAnalyzed =
false;
2104 void IfConverter::MergeBlocks(BBInfo &ToBBI, BBInfo &FromBBI,
bool AddEdges) {
2107 "Removing a BB whose address is taken!");
2113 ToBBI.BB->splice(ToTI, &FromMBB, FromMBB.
begin(), FromTI);
2117 ToTI = ToBBI.BB->end();
2118 ToBBI.BB->splice(ToTI, &FromMBB, FromTI, FromMBB.
end());
2124 if (ToBBI.IsBrAnalyzable)
2125 ToBBI.BB->normalizeSuccProbs();
2134 if (AddEdges && ToBBI.BB->isSuccessor(&FromMBB)) {
2138 ToBBI.BB->removeSuccessor(&FromMBB);
2143 if (Succ == FallThrough)
2159 if (!To2FromProb.isZero())
2160 NewProb *= To2FromProb;
2188 if (ToBBI.BB->isSuccessor(Succ))
2189 ToBBI.BB->setSuccProbability(
2190 find(ToBBI.BB->successors(), Succ),
2193 ToBBI.BB->addSuccessor(Succ, NewProb);
2200 if (Last != &FromMBB)
2205 if (ToBBI.IsBrAnalyzable && FromBBI.IsBrAnalyzable)
2206 ToBBI.BB->normalizeSuccProbs();
2208 ToBBI.Predicate.append(FromBBI.Predicate.begin(), FromBBI.Predicate.end());
2209 FromBBI.Predicate.clear();
2211 ToBBI.NonPredSize += FromBBI.NonPredSize;
2212 ToBBI.ExtraCost += FromBBI.ExtraCost;
2213 ToBBI.ExtraCost2 += FromBBI.ExtraCost2;
2214 FromBBI.NonPredSize = 0;
2215 FromBBI.ExtraCost = 0;
2216 FromBBI.ExtraCost2 = 0;
2218 ToBBI.ClobbersPred |= FromBBI.ClobbersPred;
2219 ToBBI.HasFallThrough = FromBBI.HasFallThrough;
2220 ToBBI.IsAnalyzed =
false;
2221 FromBBI.IsAnalyzed =
false;
2226 return new IfConverter(std::move(Ftor));
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
BranchProbability getCompl() const
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
This class represents lattice values for constants.
static void UpdatePredRedefs(MachineInstr &MI, LivePhysRegs &Redefs)
Behaves like LiveRegUnits::StepForward() but also adds implicit uses to all values defined in MI whic...
virtual bool DefinesPredicate(MachineInstr &MI, std::vector< MachineOperand > &Pred) const
If the specified instruction defines any predicate or condition code register(s) used for predication...
std::pair< iterator, bool > insert(const ValueT &Val)
insert - Attempts to insert a new element.
static cl::opt< bool > DisableDiamond("disable-ifcvt-diamond", cl::init(false), cl::Hidden)
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
static bool MaySpeculate(const MachineInstr &MI, SmallSet< MCPhysReg, 4 > &LaterRedefs)
static cl::opt< bool > DisableForkedDiamond("disable-ifcvt-forked-diamond", cl::init(false), cl::Hidden)
static cl::opt< bool > DisableTriangleFR("disable-ifcvt-triangle-false-rev", cl::init(false), cl::Hidden)
void push_back(const T &Elt)
iterator getFirstNonDebugInstr()
Returns an iterator to the first non-debug instruction in the basic block, or end().
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
virtual const TargetLowering * getTargetLowering() const
virtual unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const
Insert branch code into the end of the specified MachineBasicBlock.
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
LLVM_NODISCARD detail::scope_exit< typename std::decay< Callable >::type > make_scope_exit(Callable &&F)
FunctionPass * createIfConverter(std::function< bool(const MachineFunction &)> Ftor)
STATISTIC(NumFunctions, "Total number of functions")
void moveAfter(MachineBasicBlock *NewBefore)
unsigned const TargetRegisterInfo * TRI
static cl::opt< bool > DisableSimple("disable-ifcvt-simple", cl::init(false), cl::Hidden)
static BranchProbability getOne()
iterator_range< mop_iterator > operands()
virtual unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const
Remove the branching code at the end of the specific MBB.
iterator_range< succ_iterator > successors()
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool OptimizeFunction(MachineFunction &MF, const TargetInstrInfo *tii, const TargetRegisterInfo *tri, MachineModuleInfo *mmi, MachineLoopInfo *mli=nullptr, bool AfterPlacement=false)
Perhaps branch folding, tail merging and other CFG optimizations on the given function.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Provide an instruction scheduling machine model to CodeGen passes.
const HexagonInstrInfo * TII
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
size_type count(const KeyT &Key) const
count - Returns 1 if this set contains an element identified by Key, 0 otherwise. ...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void initializeIfConverterPass(PassRegistry &)
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, unsigned ExtraPredCycles, BranchProbability Probability) const
Return true if it's profitable to predicate instructions with accumulated instruction latency of "Num...
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
virtual const TargetInstrInfo * getInstrInfo() const
static MachineBasicBlock * getNextBlock(MachineBasicBlock &MBB)
Returns the next block in the function blocks ordering.
reverse_iterator rbegin()
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
TargetInstrInfo - Interface to description of machine instruction set.
static cl::opt< bool > DisableTriangleR("disable-ifcvt-triangle-rev", cl::init(false), cl::Hidden)
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
initializer< Ty > init(const Ty &Val)
static MachineBasicBlock * findFalseBlock(MachineBasicBlock *BB, MachineBasicBlock *TrueBB)
BB has a fallthrough. Find its 'false' successor given its 'true' successor.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
unsigned const MachineRegisterInfo * MRI
virtual unsigned getPredicationCost(const MachineInstr &MI) const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
void addLiveIns(const MachineBasicBlock &MBB)
Adds all live-in registers of basic block MBB.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
static cl::opt< bool > DisableTriangleF("disable-ifcvt-triangle-false", cl::init(false), cl::Hidden)
void init(const TargetRegisterInfo &TRI)
(re-)initializes and clears the set.
Represent the analysis usage information of a pass.
static bool canFallThroughTo(MachineBasicBlock &MBB, MachineBasicBlock &ToMBB)
Returns true either if ToMBB is the next block after MBB or that all the intervening blocks are empty...
FunctionPass class - This class is used to implement most global optimizations.
self_iterator getIterator()
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void setUniverse(unsigned U)
setUniverse - Set the universe size which determines the largest key the set can hold.
iterator_range< pred_iterator > predecessors()
std::vector< MachineBasicBlock * >::iterator pred_iterator
void init(const TargetSubtargetInfo *TSInfo)
Initialize the machine model for instruction scheduling.
succ_iterator succ_begin()
virtual bool PredicateInstruction(MachineInstr &MI, ArrayRef< MachineOperand > Pred) const
Convert the instruction into a predicated instruction.
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
virtual bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify=false) const
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
pred_iterator pred_begin()
MCSubRegIterator enumerates all sub-registers of Reg.
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
virtual bool isPredicated(const MachineInstr &MI) const
Returns true if the instruction is already predicated.
bool isDebugInstr() const
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
MachineInstr * CloneMachineInstr(const MachineInstr *Orig)
Create a new MachineInstr which is a copy of Orig, identical in all ways except the instruction has n...
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static cl::opt< bool > DisableTriangle("disable-ifcvt-triangle", cl::init(false), cl::Hidden)
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, BranchProbability Probability) const
Return true if it's profitable for if-converter to duplicate instructions of specified accumulated in...
static cl::opt< int > IfCvtLimit("ifcvt-limit", cl::init(-1), cl::Hidden)
unsigned pred_size() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
virtual bool isPredicable(const MachineInstr &MI) const
Return true if the specified instruction can be predicated.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI)
IterT skipDebugInstructionsForward(IterT It, IterT End)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator...
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
TargetSubtargetInfo - Generic base class for all target subtargets.
BranchProbability getEdgeProbability(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
virtual bool SubsumesPredicate(ArrayRef< MachineOperand > Pred1, ArrayRef< MachineOperand > Pred2) const
Returns true if the first specified predicate subsumes the second, e.g.
static cl::opt< int > IfCvtFnStart("ifcvt-fn-start", cl::init(-1), cl::Hidden)
SparseSet - Fast set implmentation for objects that can be identified by small unsigned keys...
A set of physical registers with utility functions to track liveness when walking backward/forward th...
LLVM_NODISCARD bool empty() const
static cl::opt< bool > IfCvtBranchFold("ifcvt-branch-fold", cl::init(true), cl::Hidden)
char & IfConverterID
IfConverter - This pass performs machine code if conversion.
static cl::opt< bool > DisableSimpleF("disable-ifcvt-simple-false", cl::init(false), cl::Hidden)
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
virtual bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const
Reverses the branch condition of the specified condition list, returning false on success and true if...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static void InsertUncondBranch(MachineBasicBlock &MBB, MachineBasicBlock &ToMBB, const TargetInstrInfo *TII)
Inserts an unconditional branch from MBB to ToMBB.
This class keeps track of branch frequencies of newly created blocks and tail-merged blocks...
print Print MemDeps of function
static BranchProbability getZero()
void stepForward(const MachineInstr &MI, SmallVectorImpl< std::pair< MCPhysReg, const MachineOperand *>> &Clobbers)
Simulates liveness when stepping forward over an instruction(bundle).
void recomputeLivenessFlags(MachineBasicBlock &MBB)
Recomputes dead and kill flags in MBB.
reverse_iterator rbegin()
virtual bool isProfitableToUnpredicate(MachineBasicBlock &TMBB, MachineBasicBlock &FMBB) const
Return true if it's profitable to unpredicate one side of a 'diamond', i.e.
bool isSafeToMove(AliasAnalysis *AA, bool &SawStore) const
Return true if it is safe to move this instruction.
Properties which a MachineFunction may have at a given point in time.
This file describes how to lower LLVM code to machine code.
static void verifySameBranchInstructions(MachineBasicBlock *MBB1, MachineBasicBlock *MBB2)
static cl::opt< int > IfCvtFnStop("ifcvt-fn-stop", cl::init(-1), cl::Hidden)
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.