42 #define DEBUG_TYPE "if-converter"
67 STATISTIC(NumSimple,
"Number of simple if-conversions performed");
68 STATISTIC(NumSimpleFalse,
"Number of simple (F) if-conversions performed");
69 STATISTIC(NumTriangle,
"Number of triangle if-conversions performed");
70 STATISTIC(NumTriangleRev,
"Number of triangle (R) if-conversions performed");
71 STATISTIC(NumTriangleFalse,
"Number of triangle (F) if-conversions performed");
72 STATISTIC(NumTriangleFRev,
"Number of triangle (F/R) if-conversions performed");
73 STATISTIC(NumDiamonds,
"Number of diamond if-conversions performed");
74 STATISTIC(NumForkedDiamonds,
"Number of forked-diamond if-conversions performed");
75 STATISTIC(NumIfConvBBs,
"Number of if-converted blocks");
76 STATISTIC(NumDupBBs,
"Number of duplicated blocks");
77 STATISTIC(NumUnpred,
"Number of true blocks of diamonds unpredicated");
119 bool IsBeingAnalyzed : 1;
122 bool IsBrAnalyzable : 1;
123 bool IsBrReversible : 1;
124 bool HasFallThrough : 1;
125 bool IsUnpredicable : 1;
126 bool CannotBeCopied : 1;
127 bool ClobbersPred : 1;
128 unsigned NonPredSize;
136 BBInfo() : IsDone(
false), IsBeingAnalyzed(
false),
140 ClobbersPred(
false), NonPredSize(0), ExtraCost(0),
141 ExtraCost2(0), BB(nullptr), TrueBB(nullptr),
161 bool NeedSubsumption : 1;
162 bool TClobbersPred : 1;
163 bool FClobbersPred : 1;
164 IfcvtToken(BBInfo &b, IfcvtKind k,
bool s,
unsigned d,
unsigned d2 = 0,
165 bool tc =
false,
bool fc =
false)
166 : BBI(b),
Kind(k), NumDups(d), NumDups2(d2), NeedSubsumption(s),
167 TClobbersPred(tc), FClobbersPred(fc) {}
172 std::vector<BBInfo> BBAnalysis;
187 std::function<bool(const MachineFunction &)> PredicateFtor;
210 bool reverseBranchCondition(BBInfo &BBI)
const;
211 bool ValidSimple(BBInfo &TrueBBI,
unsigned &Dups,
213 bool ValidTriangle(BBInfo &TrueBBI, BBInfo &FalseBBI,
214 bool FalseBranch,
unsigned &Dups,
216 bool CountDuplicatedInstructions(
219 unsigned &Dups1,
unsigned &Dups2,
221 bool SkipUnconditionalBranches)
const;
222 bool ValidDiamond(BBInfo &TrueBBI, BBInfo &FalseBBI,
223 unsigned &Dups1,
unsigned &Dups2,
224 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const;
225 bool ValidForkedDiamond(BBInfo &TrueBBI, BBInfo &FalseBBI,
226 unsigned &Dups1,
unsigned &Dups2,
227 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const;
228 void AnalyzeBranches(BBInfo &BBI);
229 void ScanInstructions(BBInfo &BBI,
232 bool BranchUnpredicable =
false)
const;
233 bool RescanInstructions(
236 BBInfo &TrueBBI, BBInfo &FalseBBI)
const;
238 std::vector<std::unique_ptr<IfcvtToken>> &Tokens);
240 bool isTriangle =
false,
bool RevBranch =
false,
241 bool hasCommonTail =
false);
243 std::vector<std::unique_ptr<IfcvtToken>> &Tokens);
245 void RemoveExtraEdges(BBInfo &BBI);
246 bool IfConvertSimple(BBInfo &BBI, IfcvtKind
Kind);
247 bool IfConvertTriangle(BBInfo &BBI, IfcvtKind
Kind);
248 bool IfConvertDiamondCommon(BBInfo &BBI, BBInfo &TrueBBI, BBInfo &FalseBBI,
249 unsigned NumDups1,
unsigned NumDups2,
250 bool TClobbersPred,
bool FClobbersPred,
251 bool RemoveBranch,
bool MergeAddEdges);
252 bool IfConvertDiamond(BBInfo &BBI, IfcvtKind
Kind,
253 unsigned NumDups1,
unsigned NumDups2,
254 bool TClobbers,
bool FClobbers);
255 bool IfConvertForkedDiamond(BBInfo &BBI, IfcvtKind
Kind,
256 unsigned NumDups1,
unsigned NumDups2,
257 bool TClobbers,
bool FClobbers);
258 void PredicateBlock(BBInfo &BBI,
262 void CopyAndPredicateBlock(BBInfo &ToBBI, BBInfo &FromBBI,
264 bool IgnoreBr =
false);
265 void MergeBlocks(BBInfo &ToBBI, BBInfo &FromBBI,
bool AddEdges =
true);
268 unsigned Cycle,
unsigned Extra,
275 unsigned TCycle,
unsigned TExtra,
277 unsigned FCycle,
unsigned FExtra,
279 return TCycle > 0 && FCycle > 0 &&
285 bool blockAlwaysFallThrough(BBInfo &BBI)
const {
286 return BBI.IsBrAnalyzable && BBI.TrueBB ==
nullptr;
290 static bool IfcvtTokenCmp(
const std::unique_ptr<IfcvtToken> &C1,
291 const std::unique_ptr<IfcvtToken> &C2) {
292 int Incr1 = (C1->Kind == ICDiamond)
293 ? -(
int)(C1->NumDups + C1->NumDups2) : (
int)C1->NumDups;
294 int Incr2 = (C2->Kind == ICDiamond)
295 ? -(
int)(C2->NumDups + C2->NumDups2) : (
int)C2->NumDups;
298 else if (Incr1 == Incr2) {
300 if (!C1->NeedSubsumption && C2->NeedSubsumption)
302 else if (C1->NeedSubsumption == C2->NeedSubsumption) {
304 if ((
unsigned)C1->Kind < (
unsigned)C2->Kind)
306 else if (C1->Kind == C2->Kind)
307 return C1->BBI.BB->getNumber() < C2->BBI.BB->getNumber();
324 if (skipFunction(*MF.getFunction()) || (PredicateFtor && !PredicateFtor(MF)))
332 MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
333 MRI = &MF.getRegInfo();
336 if (!
TII)
return false;
338 PreRegAlloc = MRI->isSSA();
340 bool BFChange =
false;
345 getAnalysisIfAvailable<MachineModuleInfo>());
348 DEBUG(
dbgs() <<
"\nIfcvt: function (" << ++FnNum <<
") \'"
349 << MF.getName() <<
"\'");
358 BBAnalysis.resize(MF.getNumBlockIDs());
360 std::vector<std::unique_ptr<IfcvtToken>> Tokens;
362 unsigned NumIfCvts = NumSimple + NumSimpleFalse + NumTriangle +
363 NumTriangleRev + NumTriangleFalse + NumTriangleFRev + NumDiamonds;
368 AnalyzeBlocks(MF, Tokens);
369 while (!Tokens.empty()) {
370 std::unique_ptr<IfcvtToken> Token = std::move(Tokens.back());
372 BBInfo &BBI = Token->BBI;
373 IfcvtKind
Kind = Token->Kind;
374 unsigned NumDups = Token->NumDups;
375 unsigned NumDups2 = Token->NumDups2;
380 BBI.IsEnqueued =
false;
384 BBI.IsEnqueued =
false;
390 case ICSimpleFalse: {
391 bool isFalse = Kind == ICSimpleFalse;
393 DEBUG(
dbgs() <<
"Ifcvt (Simple" << (Kind == ICSimpleFalse ?
395 <<
"): BB#" << BBI.BB->getNumber() <<
" ("
396 << ((Kind == ICSimpleFalse)
397 ? BBI.FalseBB->getNumber()
398 : BBI.TrueBB->getNumber()) <<
") ");
399 RetVal = IfConvertSimple(BBI, Kind);
400 DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
402 if (isFalse) ++NumSimpleFalse;
409 case ICTriangleFalse:
410 case ICTriangleFRev: {
411 bool isFalse = Kind == ICTriangleFalse;
412 bool isRev = (Kind == ICTriangleRev || Kind == ICTriangleFRev);
422 DEBUG(
dbgs() <<
"): BB#" << BBI.BB->getNumber() <<
" (T:"
423 << BBI.TrueBB->getNumber() <<
",F:"
424 << BBI.FalseBB->getNumber() <<
") ");
425 RetVal = IfConvertTriangle(BBI, Kind);
426 DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
429 if (isRev) ++NumTriangleFRev;
430 else ++NumTriangleFalse;
432 if (isRev) ++NumTriangleRev;
440 DEBUG(
dbgs() <<
"Ifcvt (Diamond): BB#" << BBI.BB->getNumber() <<
" (T:"
441 << BBI.TrueBB->getNumber() <<
",F:"
442 << BBI.FalseBB->getNumber() <<
") ");
443 RetVal = IfConvertDiamond(BBI, Kind, NumDups, NumDups2,
444 Token->TClobbersPred,
445 Token->FClobbersPred);
446 DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
447 if (RetVal) ++NumDiamonds;
450 case ICForkedDiamond: {
452 DEBUG(
dbgs() <<
"Ifcvt (Forked Diamond): BB#"
453 << BBI.BB->getNumber() <<
" (T:"
454 << BBI.TrueBB->getNumber() <<
",F:"
455 << BBI.FalseBB->getNumber() <<
") ");
456 RetVal = IfConvertForkedDiamond(BBI, Kind, NumDups, NumDups2,
457 Token->TClobbersPred,
458 Token->FClobbersPred);
459 DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
460 if (RetVal) ++NumForkedDiamonds;
467 NumIfCvts = NumSimple + NumSimpleFalse + NumTriangle + NumTriangleRev +
468 NumTriangleFalse + NumTriangleFRev + NumDiamonds;
475 MadeChange |= Change;
484 getAnalysisIfAvailable<MachineModuleInfo>());
487 MadeChange |= BFChange;
495 if (SuccBB != TrueBB)
503 bool IfConverter::reverseBranchCondition(BBInfo &BBI)
const {
527 bool IfConverter::ValidSimple(BBInfo &TrueBBI,
unsigned &Dups,
530 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone)
533 if (TrueBBI.IsBrAnalyzable)
536 if (TrueBBI.BB->pred_size() > 1) {
537 if (TrueBBI.CannotBeCopied ||
541 Dups = TrueBBI.NonPredSize;
552 bool IfConverter::ValidTriangle(BBInfo &TrueBBI, BBInfo &FalseBBI,
553 bool FalseBranch,
unsigned &Dups,
556 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone)
559 if (TrueBBI.BB->pred_size() > 1) {
560 if (TrueBBI.CannotBeCopied)
563 unsigned Size = TrueBBI.NonPredSize;
564 if (TrueBBI.IsBrAnalyzable) {
565 if (TrueBBI.TrueBB && TrueBBI.BrCond.empty())
570 ? TrueBBI.TrueBB : TrueBBI.FalseBB;
582 if (!TExit && blockAlwaysFallThrough(TrueBBI)) {
584 if (++I == TrueBBI.BB->getParent()->end())
588 return TExit && TExit == FalseBBI.BB;
611 bool IfConverter::CountDuplicatedInstructions(
616 unsigned &Dups1,
unsigned &Dups2,
618 bool SkipUnconditionalBranches)
const {
620 while (TIB != TIE && FIB != FIE) {
624 if (TIB == TIE || FIB == FIE)
626 if (!TIB->isIdenticalTo(*FIB))
630 std::vector<MachineOperand> PredDefs;
634 if (!TIB->isBranch())
641 if (TIB == TIE || FIB == FIE)
653 if (SkipUnconditionalBranches) {
654 while (RTIE != RTIB && RTIE->isUnconditionalBranch())
656 while (RFIE != RFIB && RFIE->isUnconditionalBranch())
662 while (RTIE != RTIB && RFIE != RFIB) {
667 if (RTIE == RTIB || RFIE == RFIB)
669 if (!RTIE->isIdenticalTo(*RFIE))
673 if (!RTIE->isBranch())
679 FIE = std::next(RFIE.getReverse());
692 bool IfConverter::RescanInstructions(
695 BBInfo &TrueBBI, BBInfo &FalseBBI)
const {
696 bool BranchUnpredicable =
true;
697 TrueBBI.IsUnpredicable = FalseBBI.IsUnpredicable =
false;
698 ScanInstructions(TrueBBI, TIB, TIE, BranchUnpredicable);
699 if (TrueBBI.IsUnpredicable)
701 ScanInstructions(FalseBBI, FIB, FIE, BranchUnpredicable);
702 if (FalseBBI.IsUnpredicable)
704 if (TrueBBI.ClobbersPred && FalseBBI.ClobbersPred)
717 while (E1 != B1 && E2 != B2) {
720 if (E1 == B1 && E2 == B2)
724 assert(!E2->isBranch() &&
"Branch mis-match, one block is empty.");
728 assert(!E1->isBranch() &&
"Branch mis-match, one block is empty.");
732 if (E1->isBranch() || E2->isBranch())
733 assert(E1->isIdenticalTo(*E2) &&
734 "Branch mis-match, branch instructions don't match.");
756 bool IfConverter::ValidForkedDiamond(
757 BBInfo &TrueBBI, BBInfo &FalseBBI,
758 unsigned &Dups1,
unsigned &Dups2,
759 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const {
761 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone ||
762 FalseBBI.IsBeingAnalyzed || FalseBBI.IsDone)
765 if (!TrueBBI.IsBrAnalyzable || !FalseBBI.IsBrAnalyzable)
768 if (TrueBBI.BB->pred_size() > 1 || FalseBBI.BB->pred_size() > 1)
773 if (TrueBBI.BrCond.size() == 0 ||
774 FalseBBI.BrCond.size() == 0)
795 if (!((TT == FT && TF == FF) || (TF == FT && TT == FF)))
798 bool FalseReversed =
false;
799 if (TF == FT && TT == FF) {
801 if (!FalseBBI.IsBrReversible)
803 FalseReversed =
true;
804 reverseBranchCondition(FalseBBI);
808 reverseBranchCondition(FalseBBI);
816 if(!CountDuplicatedInstructions(TIB, FIB, TIE, FIE, Dups1, Dups2,
817 *TrueBBI.BB, *FalseBBI.BB,
821 TrueBBICalc.BB = TrueBBI.BB;
822 FalseBBICalc.BB = FalseBBI.BB;
823 if (!RescanInstructions(TIB, FIB, TIE, FIE, TrueBBICalc, FalseBBICalc))
829 TrueBBICalc.NonPredSize = TrueBBI.NonPredSize;
830 FalseBBICalc.NonPredSize = FalseBBI.NonPredSize;
836 bool IfConverter::ValidDiamond(
837 BBInfo &TrueBBI, BBInfo &FalseBBI,
838 unsigned &Dups1,
unsigned &Dups2,
839 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const {
841 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone ||
842 FalseBBI.IsBeingAnalyzed || FalseBBI.IsDone)
848 if (!TT && blockAlwaysFallThrough(TrueBBI))
850 if (!FT && blockAlwaysFallThrough(FalseBBI))
854 if (!TT && (TrueBBI.IsBrAnalyzable || FalseBBI.IsBrAnalyzable))
856 if (TrueBBI.BB->pred_size() > 1 || FalseBBI.BB->pred_size() > 1)
860 if (TrueBBI.FalseBB || FalseBBI.FalseBB)
867 bool SkipUnconditionalBranches =
868 TrueBBI.IsBrAnalyzable && FalseBBI.IsBrAnalyzable;
873 if(!CountDuplicatedInstructions(TIB, FIB, TIE, FIE, Dups1, Dups2,
874 *TrueBBI.BB, *FalseBBI.BB,
875 SkipUnconditionalBranches))
878 TrueBBICalc.BB = TrueBBI.BB;
879 FalseBBICalc.BB = FalseBBI.BB;
880 if (!RescanInstructions(TIB, FIB, TIE, FIE, TrueBBICalc, FalseBBICalc))
885 TrueBBICalc.NonPredSize = TrueBBI.NonPredSize;
886 FalseBBICalc.NonPredSize = FalseBBI.NonPredSize;
892 void IfConverter::AnalyzeBranches(BBInfo &BBI) {
896 BBI.TrueBB = BBI.FalseBB =
nullptr;
901 BBI.IsBrReversible = (RevCond.size() == 0) ||
903 BBI.HasFallThrough = BBI.IsBrAnalyzable && BBI.FalseBB ==
nullptr;
905 if (BBI.BrCond.size()) {
912 BBI.IsUnpredicable =
true;
922 void IfConverter::ScanInstructions(BBInfo &BBI,
925 bool BranchUnpredicable)
const {
926 if (BBI.IsDone || BBI.IsUnpredicable)
929 bool AlreadyPredicated = !BBI.Predicate.empty();
934 BBI.ClobbersPred =
false;
936 if (
MI.isDebugValue())
969 if (
MI.isNotDuplicable() ||
MI.isConvergent())
970 BBI.CannotBeCopied =
true;
973 bool isCondBr = BBI.IsBrAnalyzable &&
MI.isConditionalBranch();
975 if (BranchUnpredicable &&
MI.isBranch()) {
976 BBI.IsUnpredicable =
true;
986 unsigned ExtraPredCost =
TII->getPredicationCost(
MI);
987 unsigned NumCycles = SchedModel.computeInstrLatency(&
MI,
false);
989 BBI.ExtraCost += NumCycles-1;
990 BBI.ExtraCost2 += ExtraPredCost;
991 }
else if (!AlreadyPredicated) {
995 BBI.IsUnpredicable =
true;
1004 BBI.IsUnpredicable =
true;
1010 std::vector<MachineOperand> PredDefs;
1012 BBI.ClobbersPred =
true;
1015 BBI.IsUnpredicable =
true;
1030 bool IfConverter::FeasibilityAnalysis(BBInfo &BBI,
1032 bool isTriangle,
bool RevBranch,
1033 bool hasCommonTail) {
1038 if (BBI.IsDone || (BBI.IsUnpredicable && !hasCommonTail))
1044 if (BBI.Predicate.size() && !BBI.IsBrAnalyzable)
1052 if (!hasCommonTail && BBI.BrCond.size()) {
1073 void IfConverter::AnalyzeBlock(
1086 while (!BBStack.empty()) {
1087 BBState &State = BBStack.back();
1089 BBInfo &BBI = BBAnalysis[BB->
getNumber()];
1091 if (!State.SuccsAnalyzed) {
1092 if (BBI.IsAnalyzed || BBI.IsBeingAnalyzed) {
1098 BBI.IsBeingAnalyzed =
true;
1100 AnalyzeBranches(BBI);
1103 ScanInstructions(BBI, Begin, End);
1107 if (!BBI.IsBrAnalyzable || BBI.BrCond.empty() || BBI.IsDone) {
1108 BBI.IsBeingAnalyzed =
false;
1109 BBI.IsAnalyzed =
true;
1115 if (BBI.TrueBB == BB || BBI.FalseBB == BB) {
1116 BBI.IsBeingAnalyzed =
false;
1117 BBI.IsAnalyzed =
true;
1124 BBI.IsBeingAnalyzed =
false;
1125 BBI.IsAnalyzed =
true;
1131 State.SuccsAnalyzed =
true;
1132 BBStack.push_back(*BBI.FalseBB);
1133 BBStack.push_back(*BBI.TrueBB);
1137 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1138 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1140 if (TrueBBI.IsDone && FalseBBI.IsDone) {
1141 BBI.IsBeingAnalyzed =
false;
1142 BBI.IsAnalyzed =
true;
1148 RevCond(BBI.BrCond.begin(), BBI.BrCond.end());
1153 bool TNeedSub = !TrueBBI.Predicate.empty();
1154 bool FNeedSub = !FalseBBI.Predicate.empty();
1155 bool Enqueued =
false;
1160 BBInfo TrueBBICalc, FalseBBICalc;
1161 auto feasibleDiamond = [&]() {
1162 bool MeetsSize = MeetIfcvtSizeLimit(
1163 *TrueBBI.BB, (TrueBBICalc.NonPredSize - (Dups + Dups2) +
1164 TrueBBICalc.ExtraCost), TrueBBICalc.ExtraCost2,
1165 *FalseBBI.BB, (FalseBBICalc.NonPredSize - (Dups + Dups2) +
1166 FalseBBICalc.ExtraCost), FalseBBICalc.ExtraCost2,
1168 bool TrueFeasible = FeasibilityAnalysis(TrueBBI, BBI.BrCond,
1171 bool FalseFeasible = FeasibilityAnalysis(FalseBBI, RevCond,
1174 return MeetsSize && TrueFeasible && FalseFeasible;
1177 if (ValidDiamond(TrueBBI, FalseBBI, Dups, Dups2,
1178 TrueBBICalc, FalseBBICalc)) {
1179 if (feasibleDiamond()) {
1188 Tokens.push_back(llvm::make_unique<IfcvtToken>(
1189 BBI, ICDiamond, TNeedSub | FNeedSub, Dups, Dups2,
1190 (
bool) TrueBBICalc.ClobbersPred, (
bool) FalseBBICalc.ClobbersPred));
1193 }
else if (ValidForkedDiamond(TrueBBI, FalseBBI, Dups, Dups2,
1194 TrueBBICalc, FalseBBICalc)) {
1195 if (feasibleDiamond()) {
1206 Tokens.push_back(llvm::make_unique<IfcvtToken>(
1207 BBI, ICForkedDiamond, TNeedSub | FNeedSub, Dups, Dups2,
1208 (
bool) TrueBBICalc.ClobbersPred, (
bool) FalseBBICalc.ClobbersPred));
1214 if (ValidTriangle(TrueBBI, FalseBBI,
false, Dups, Prediction) &&
1215 MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize + TrueBBI.ExtraCost,
1216 TrueBBI.ExtraCost2, Prediction) &&
1217 FeasibilityAnalysis(TrueBBI, BBI.BrCond,
true)) {
1226 llvm::make_unique<IfcvtToken>(BBI, ICTriangle, TNeedSub, Dups));
1230 if (ValidTriangle(TrueBBI, FalseBBI,
true, Dups, Prediction) &&
1231 MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize + TrueBBI.ExtraCost,
1232 TrueBBI.ExtraCost2, Prediction) &&
1233 FeasibilityAnalysis(TrueBBI, BBI.BrCond,
true,
true)) {
1235 llvm::make_unique<IfcvtToken>(BBI, ICTriangleRev, TNeedSub, Dups));
1239 if (ValidSimple(TrueBBI, Dups, Prediction) &&
1240 MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize + TrueBBI.ExtraCost,
1241 TrueBBI.ExtraCost2, Prediction) &&
1242 FeasibilityAnalysis(TrueBBI, BBI.BrCond)) {
1251 llvm::make_unique<IfcvtToken>(BBI, ICSimple, TNeedSub, Dups));
1257 if (ValidTriangle(FalseBBI, TrueBBI,
false, Dups,
1259 MeetIfcvtSizeLimit(*FalseBBI.BB,
1260 FalseBBI.NonPredSize + FalseBBI.ExtraCost,
1261 FalseBBI.ExtraCost2, Prediction.
getCompl()) &&
1262 FeasibilityAnalysis(FalseBBI, RevCond,
true)) {
1263 Tokens.push_back(llvm::make_unique<IfcvtToken>(BBI, ICTriangleFalse,
1268 if (ValidTriangle(FalseBBI, TrueBBI,
true, Dups,
1270 MeetIfcvtSizeLimit(*FalseBBI.BB,
1271 FalseBBI.NonPredSize + FalseBBI.ExtraCost,
1272 FalseBBI.ExtraCost2, Prediction.
getCompl()) &&
1273 FeasibilityAnalysis(FalseBBI, RevCond,
true,
true)) {
1275 llvm::make_unique<IfcvtToken>(BBI, ICTriangleFRev, FNeedSub, Dups));
1279 if (ValidSimple(FalseBBI, Dups, Prediction.
getCompl()) &&
1280 MeetIfcvtSizeLimit(*FalseBBI.BB,
1281 FalseBBI.NonPredSize + FalseBBI.ExtraCost,
1282 FalseBBI.ExtraCost2, Prediction.
getCompl()) &&
1283 FeasibilityAnalysis(FalseBBI, RevCond)) {
1285 llvm::make_unique<IfcvtToken>(BBI, ICSimpleFalse, FNeedSub, Dups));
1290 BBI.IsEnqueued = Enqueued;
1291 BBI.IsBeingAnalyzed =
false;
1292 BBI.IsAnalyzed =
true;
1298 void IfConverter::AnalyzeBlocks(
1299 MachineFunction &MF, std::vector<std::unique_ptr<IfcvtToken>> &Tokens) {
1301 AnalyzeBlock(MBB, Tokens);
1304 std::stable_sort(Tokens.begin(), Tokens.end(), IfcvtTokenCmp);
1317 if (I == E || !I->empty() || !PI->isSuccessor(&*I))
1322 return PI->isSuccessor(&*I);
1329 BBInfo &PBBI = BBAnalysis[Predecessor->getNumber()];
1330 if (PBBI.IsDone || PBBI.BB == &MBB)
1332 PBBI.IsAnalyzed =
false;
1333 PBBI.IsEnqueued =
false;
1346 void IfConverter::RemoveExtraEdges(BBInfo &BBI) {
1350 BBI.BB->CorrectExtraCFGEdges(TBB, FBB, !Cond.
empty());
1364 for (
unsigned Reg : Redefs)
1368 Redefs.stepForward(MI, Clobbers);
1371 for (
auto Clobber : Clobbers) {
1374 unsigned Reg = Clobber.first;
1381 if (LiveBeforeMI.
count(Reg))
1392 assert(Op.
isReg() &&
"Register operand required");
1396 if (Redefs.contains(Op.
getReg()))
1399 if (LiveBeforeMI.
count(Reg))
1402 bool HasLiveSubReg =
false;
1404 if (!LiveBeforeMI.
count(*S))
1406 HasLiveSubReg =
true;
1418 if (!O->isReg() || !O->isKill())
1420 if (DontKill.
contains(O->getReg()))
1421 O->setIsKill(
false);
1436 bool IfConverter::IfConvertSimple(BBInfo &BBI, IfcvtKind
Kind) {
1437 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1438 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1439 BBInfo *CvtBBI = &TrueBBI;
1440 BBInfo *NextBBI = &FalseBBI;
1443 if (Kind == ICSimpleFalse)
1448 if (CvtBBI->IsDone ||
1449 (CvtBBI->CannotBeCopied && CvtMBB.
pred_size() > 1)) {
1451 BBI.IsAnalyzed =
false;
1452 CvtBBI->IsAnalyzed =
false;
1460 if (Kind == ICSimpleFalse)
1465 DontKill.init(*TRI);
1467 if (
MRI->tracksLiveness()) {
1470 Redefs.addLiveIns(CvtMBB);
1471 Redefs.addLiveIns(NextMBB);
1474 DontKill.addLiveIns(NextMBB);
1484 CopyAndPredicateBlock(BBI, *CvtBBI, Cond);
1488 BBI.BB->removeSuccessor(&CvtMBB,
true);
1492 PredicateBlock(*CvtBBI, CvtMBB.
end(), Cond);
1495 MergeBlocks(BBI, *CvtBBI);
1498 bool IterIfcvt =
true;
1501 BBI.HasFallThrough =
false;
1515 RemoveExtraEdges(BBI);
1520 InvalidatePreds(*BBI.BB);
1521 CvtBBI->IsDone =
true;
1528 bool IfConverter::IfConvertTriangle(BBInfo &BBI, IfcvtKind Kind) {
1529 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1530 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1531 BBInfo *CvtBBI = &TrueBBI;
1532 BBInfo *NextBBI = &FalseBBI;
1536 if (Kind == ICTriangleFalse || Kind == ICTriangleFRev)
1541 if (CvtBBI->IsDone ||
1542 (CvtBBI->CannotBeCopied && CvtMBB.
pred_size() > 1)) {
1544 BBI.IsAnalyzed =
false;
1545 CvtBBI->IsAnalyzed =
false;
1553 if (Kind == ICTriangleFalse || Kind == ICTriangleFRev)
1557 if (Kind == ICTriangleRev || Kind == ICTriangleFRev) {
1558 if (reverseBranchCondition(*CvtBBI)) {
1564 BBInfo &PBBI = BBAnalysis[PBB->getNumber()];
1565 if (PBBI.IsEnqueued) {
1566 PBBI.IsAnalyzed =
false;
1567 PBBI.IsEnqueued =
false;
1576 if (
MRI->tracksLiveness()) {
1577 Redefs.addLiveIns(CvtMBB);
1578 Redefs.addLiveIns(NextMBB);
1583 bool HasEarlyExit = CvtBBI->FalseBB !=
nullptr;
1588 CvtNext = MBPI->getEdgeProbability(&CvtMBB, &NextMBB);
1589 CvtFalse = MBPI->getEdgeProbability(&CvtMBB, CvtBBI->FalseBB);
1590 BBNext = MBPI->getEdgeProbability(BBI.BB, &NextMBB);
1591 BBCvt = MBPI->getEdgeProbability(BBI.BB, &CvtMBB);
1601 CopyAndPredicateBlock(BBI, *CvtBBI, Cond,
true);
1605 BBI.BB->removeSuccessor(&CvtMBB,
true);
1609 PredicateBlock(*CvtBBI, CvtMBB.
end(), Cond);
1612 MergeBlocks(BBI, *CvtBBI,
false);
1618 CvtBBI->BrCond.end());
1629 auto NewNext = BBNext + BBCvt * CvtNext;
1630 auto NewTrueBBIter =
find(BBI.BB->successors(), NewTrueBB);
1631 if (NewTrueBBIter != BBI.BB->succ_end())
1632 BBI.BB->setSuccProbability(NewTrueBBIter, NewNext);
1634 auto NewFalse = BBCvt * CvtFalse;
1636 BBI.BB->addSuccessor(CvtBBI->FalseBB, NewFalse);
1641 bool FalseBBDead =
false;
1642 bool IterIfcvt =
true;
1644 if (!isFallThrough) {
1648 if (!HasEarlyExit &&
1649 NextMBB.
pred_size() == 1 && !NextBBI->HasFallThrough &&
1651 MergeBlocks(BBI, *NextBBI);
1655 BBI.HasFallThrough =
false;
1662 RemoveExtraEdges(BBI);
1667 InvalidatePreds(*BBI.BB);
1668 CvtBBI->IsDone =
true;
1670 NextBBI->IsDone =
true;
1687 bool IfConverter::IfConvertDiamondCommon(
1688 BBInfo &BBI, BBInfo &TrueBBI, BBInfo &FalseBBI,
1689 unsigned NumDups1,
unsigned NumDups2,
1690 bool TClobbersPred,
bool FClobbersPred,
1691 bool RemoveBranch,
bool MergeAddEdges) {
1693 if (TrueBBI.IsDone || FalseBBI.IsDone ||
1694 TrueBBI.BB->pred_size() > 1 || FalseBBI.BB->pred_size() > 1) {
1696 BBI.IsAnalyzed =
false;
1697 TrueBBI.IsAnalyzed =
false;
1698 FalseBBI.IsAnalyzed =
false;
1702 if (TrueBBI.BB->hasAddressTaken() || FalseBBI.BB->hasAddressTaken())
1709 BBInfo *BBI1 = &TrueBBI;
1710 BBInfo *BBI2 = &FalseBBI;
1718 bool DoSwap =
false;
1719 if (TClobbersPred && !FClobbersPred)
1721 else if (!TClobbersPred && !FClobbersPred) {
1722 if (TrueBBI.NonPredSize > FalseBBI.NonPredSize)
1724 }
else if (TClobbersPred && FClobbersPred)
1744 if (
MRI->tracksLiveness()) {
1745 Redefs.addLiveIns(MBB1);
1746 Redefs.addLiveIns(MBB2);
1753 BBI1->NonPredSize -= NumDups1;
1754 BBI2->NonPredSize -= NumDups1;
1758 for (
unsigned i = 0; i < NumDups1; ++DI1) {
1759 if (!DI1->isDebugValue())
1762 while (NumDups1 != 0) {
1764 if (!DI2->isDebugValue())
1771 DontKill.init(*TRI);
1772 if (
MRI->tracksLiveness()) {
1774 DontKill.stepBackward(
MI);
1778 Redefs.stepForward(
MI, Dummy);
1781 BBI.BB->splice(BBI.BB->end(), &MBB1, MBB1.
begin(), DI1);
1788 if (!BBI1->IsBrAnalyzable)
1794 for (
unsigned i = 0; i != NumDups2; ) {
1800 if (!DI1->isDebugValue())
1809 DI2 = BBI2->BB->end();
1818 }
while (DI2->isBranch() || DI2->isDebugValue());
1821 while (NumDups2 != 0) {
1827 if (!DI2->isDebugValue())
1841 if (
TII->isProfitableToUnpredicate(MBB1, MBB2)) {
1843 if (FI.isDebugValue())
1849 unsigned Reg = MO.getReg();
1854 }
else if (!RedefsByFalse.
count(Reg)) {
1859 ExtUses.
insert(*SubRegs);
1863 for (
unsigned Reg : Defs) {
1864 if (!ExtUses.
count(Reg)) {
1867 RedefsByFalse.
insert(*SubRegs);
1874 PredicateBlock(*BBI1, MBB1.
end(), *Cond1, &RedefsByFalse);
1880 if (!MBB2.
empty() && (DI2 == MBB2.
end())) {
1889 PredicateBlock(*BBI2, DI2, *Cond2);
1892 MergeBlocks(BBI, *BBI1, MergeAddEdges);
1893 MergeBlocks(BBI, *BBI2, MergeAddEdges);
1899 bool IfConverter::IfConvertForkedDiamond(
1900 BBInfo &BBI, IfcvtKind Kind,
1901 unsigned NumDups1,
unsigned NumDups2,
1902 bool TClobbersPred,
bool FClobbersPred) {
1903 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1904 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1909 if (TIE != TrueBBI.BB->end())
1910 dl = TIE->getDebugLoc();
1914 if (!IfConvertDiamondCommon(
1915 BBI, TrueBBI, FalseBBI,
1917 TClobbersPred, FClobbersPred,
1924 TrueBBI.BrCond, dl);
1926 RemoveExtraEdges(BBI);
1929 BBI.IsDone = TrueBBI.IsDone = FalseBBI.IsDone =
true;
1930 InvalidatePreds(*BBI.BB);
1937 bool IfConverter::IfConvertDiamond(BBInfo &BBI, IfcvtKind Kind,
1938 unsigned NumDups1,
unsigned NumDups2,
1939 bool TClobbersPred,
bool FClobbersPred) {
1940 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1941 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1946 if (blockAlwaysFallThrough(TrueBBI))
1947 TailBB = FalseBBI.TrueBB;
1948 assert((TailBB || !TrueBBI.IsBrAnalyzable) &&
"Unexpected!");
1951 if (!IfConvertDiamondCommon(
1952 BBI, TrueBBI, FalseBBI,
1954 TClobbersPred, FClobbersPred,
1955 TrueBBI.IsBrAnalyzable,
1964 BBInfo &TailBBI = BBAnalysis[TailBB->
getNumber()];
1965 bool CanMergeTail = !TailBBI.HasFallThrough &&
1966 !TailBBI.BB->hasAddressTaken();
1972 CanMergeTail =
false;
1975 unsigned NumPreds = TailBB->
pred_size();
1977 CanMergeTail =
false;
1978 else if (NumPreds == 1 && CanMergeTail) {
1980 if (*PI != TrueBBI.BB && *PI != FalseBBI.BB)
1981 CanMergeTail =
false;
1984 MergeBlocks(BBI, TailBBI);
1985 TailBBI.IsDone =
true;
1989 BBI.HasFallThrough =
false;
1996 BBI.BB->removeSuccessor(TrueBBI.BB);
1997 BBI.BB->removeSuccessor(FalseBBI.BB,
true);
1998 RemoveExtraEdges(BBI);
2001 BBI.IsDone = TrueBBI.IsDone = FalseBBI.IsDone =
true;
2002 InvalidatePreds(*BBI.BB);
2017 unsigned Reg = MO.getReg();
2020 if (MO.isDef() && !LaterRedefs.
count(Reg))
2029 void IfConverter::PredicateBlock(BBInfo &BBI,
2033 bool AnyUnpred =
false;
2034 bool MaySpec = LaterRedefs !=
nullptr;
2050 dbgs() <<
"Unable to predicate " << I <<
"!\n";
2060 BBI.Predicate.append(Cond.
begin(), Cond.
end());
2062 BBI.IsAnalyzed =
false;
2063 BBI.NonPredSize = 0;
2072 void IfConverter::CopyAndPredicateBlock(BBInfo &ToBBI, BBInfo &FromBBI,
2080 if (IgnoreBr && I.isBranch())
2084 ToBBI.BB->insert(ToBBI.BB->end(),
MI);
2085 ToBBI.NonPredSize++;
2086 unsigned ExtraPredCost =
TII->getPredicationCost(I);
2087 unsigned NumCycles = SchedModel.computeInstrLatency(&I,
false);
2089 ToBBI.ExtraCost += NumCycles-1;
2090 ToBBI.ExtraCost2 += ExtraPredCost;
2095 dbgs() <<
"Unable to predicate " << I <<
"!\n";
2106 if (!DontKill.empty())
2111 std::vector<MachineBasicBlock *> Succs(FromMBB.succ_begin(),
2112 FromMBB.succ_end());
2118 if (Succ == FallThrough)
2120 ToBBI.BB->addSuccessor(Succ);
2124 ToBBI.Predicate.append(FromBBI.Predicate.begin(), FromBBI.Predicate.end());
2125 ToBBI.Predicate.append(Cond.
begin(), Cond.
end());
2127 ToBBI.ClobbersPred |= FromBBI.ClobbersPred;
2128 ToBBI.IsAnalyzed =
false;
2137 void IfConverter::MergeBlocks(BBInfo &ToBBI, BBInfo &FromBBI,
bool AddEdges) {
2140 "Removing a BB whose address is taken!");
2146 ToBBI.BB->splice(ToTI, &FromMBB, FromMBB.
begin(), FromTI);
2150 ToTI = ToBBI.BB->end();
2151 ToBBI.BB->splice(ToTI, &FromMBB, FromTI, FromMBB.
end());
2157 if (ToBBI.IsBrAnalyzable)
2158 ToBBI.BB->normalizeSuccProbs();
2167 if (AddEdges && ToBBI.BB->isSuccessor(&FromMBB)) {
2168 To2FromProb = MBPI->getEdgeProbability(ToBBI.BB, &FromMBB);
2172 ToBBI.BB->setSuccProbability(
find(ToBBI.BB->successors(), &FromMBB),
2178 if (Succ == FallThrough)
2187 NewProb = MBPI->getEdgeProbability(&FromMBB, Succ);
2194 if (!To2FromProb.isZero())
2195 NewProb *= To2FromProb;
2223 if (ToBBI.BB->isSuccessor(Succ))
2224 ToBBI.BB->setSuccProbability(
2225 find(ToBBI.BB->successors(), Succ),
2226 MBPI->getEdgeProbability(ToBBI.BB, Succ) + NewProb);
2228 ToBBI.BB->addSuccessor(Succ, NewProb);
2238 if (ToBBI.IsBrAnalyzable && FromBBI.IsBrAnalyzable)
2239 ToBBI.BB->normalizeSuccProbs();
2241 ToBBI.Predicate.append(FromBBI.Predicate.begin(), FromBBI.Predicate.end());
2242 FromBBI.Predicate.clear();
2244 ToBBI.NonPredSize += FromBBI.NonPredSize;
2245 ToBBI.ExtraCost += FromBBI.ExtraCost;
2246 ToBBI.ExtraCost2 += FromBBI.ExtraCost2;
2247 FromBBI.NonPredSize = 0;
2248 FromBBI.ExtraCost = 0;
2249 FromBBI.ExtraCost2 = 0;
2251 ToBBI.ClobbersPred |= FromBBI.ClobbersPred;
2252 ToBBI.HasFallThrough = FromBBI.HasFallThrough;
2253 ToBBI.IsAnalyzed =
false;
2254 FromBBI.IsAnalyzed =
false;
2259 return new IfConverter(std::move(Ftor));
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool DefinesPredicate(MachineInstr &MI, std::vector< MachineOperand > &Pred) const override
If the specified instruction defines any predicate or condition code register(s) used for predication...
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...
STATISTIC(NumFunctions,"Total number of functions")
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
static void UpdatePredRedefs(MachineInstr &MI, LivePhysRegs &Redefs)
Behaves like LiveRegUnits::StepForward() but also adds implicit uses to all values defined in MI whic...
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
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)
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)
Maximum length of the test input If
size_type count(const KeyT &Key) const
count - Returns 1 if this set contains an element identified by Key, 0 otherwise. ...
iterator getFirstNonDebugInstr()
Returns an iterator to the first non-debug instruction in the basic block, or end().
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool SubsumesPredicate(ArrayRef< MachineOperand > Pred1, ArrayRef< MachineOperand > Pred2) const override
Returns true if the first specified predicate subsumes the second, e.g.
MIBundleOperands - Iterate over all operands in a bundle of machine instructions. ...
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
Reverses the branch condition of the specified condition list, returning false on success and true if...
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)
void setIsDead(bool Val=true)
static cl::opt< bool > DisableSimple("disable-ifcvt-simple", cl::init(false), cl::Hidden)
static BranchProbability getOne()
iterator_range< mop_iterator > operands()
iterator_range< succ_iterator > successors()
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e...
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.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Reg
All possible values of the reg field in the ModR/M byte.
void initializeIfConverterPass(PassRegistry &)
const MCSchedModel & getSchedModel() const
Get the machine model for this subtarget's CPU.
LLVM_NODISCARD bool empty() const
bool PredicateInstruction(MachineInstr &MI, ArrayRef< MachineOperand > Cond) const override
Convert the instruction into a predicated instruction.
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.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
const HexagonRegisterInfo & getRegisterInfo() const
HexagonInstrInfo specifics.
static MachineBasicBlock * getNextBlock(MachineBasicBlock &MBB)
Returns the next block in the function blocks ordering.
reverse_iterator rbegin()
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
bool isDebugValue() const
bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, BranchProbability Probability) const override
Return true if it's profitable for if-converter to duplicate instructions of specified accumulated in...
static cl::opt< bool > DisableTriangleR("disable-ifcvt-triangle-rev", cl::init(false), cl::Hidden)
Function Alias Analysis false
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
bool isPredicable(const MachineInstr &MI) const override
Return true if the specified instruction can be predicated.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static cl::opt< bool > DisableTriangleF("disable-ifcvt-triangle-false", cl::init(false), cl::Hidden)
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...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
bool contains(unsigned Reg) const
Returns true if register Reg is contained in the set.
static const unsigned End
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
succ_iterator succ_begin()
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.
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
bool isPredicated(const MachineInstr &MI) const override
Returns true if the instruction is already predicated.
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
bool isSafeToMove(AliasAnalysis *AA, bool &SawStore) const
Return true if it is safe to move this instruction.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
MachineInstr * CloneMachineInstr(const MachineInstr *Orig)
CloneMachineInstr - Create a new MachineInstr which is a copy of the 'Orig' instruction, identical in all ways except the instruction has no parent, prev, or next.
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)
virtual const TargetLowering * getTargetLowering() const
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
static bool MaySpeculate(const MachineInstr &MI, SmallSet< unsigned, 4 > &LaterRedefs)
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
Insert branch code into the end of the specified MachineBasicBlock.
bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, unsigned ExtraPredCycles, BranchProbability Probability) const override
Return true if it's profitable to predicate instructions with accumulated instruction latency of "Num...
static void RemoveKills(MachineInstr &MI, const LivePhysRegs &DontKill)
Remove kill flags from operands with a registers in the DontKill set.
static cl::opt< int > IfCvtLimit("ifcvt-limit", cl::init(-1), cl::Hidden)
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.
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
Remove the branching code at the end of the specific MBB.
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...
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
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.
Representation of each machine instruction.
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
static cl::opt< int > IfCvtFnStart("ifcvt-fn-start", cl::init(-1), cl::Hidden)
A set of physical registers with utility functions to track liveness when walking backward/forward th...
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)
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
unsigned getReg() const
getReg - Returns the register number.
bool isValid() const
isValid - Returns true until all the operands have been visited.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual const TargetInstrInfo * getInstrInfo() const
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
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
static BranchProbability getZero()
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
unsigned pred_size() const
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)
BranchProbability getCompl() const