59 #define DEBUG_TYPE "if-converter" 84 STATISTIC(NumSimple,
"Number of simple if-conversions performed");
85 STATISTIC(NumSimpleFalse,
"Number of simple (F) if-conversions performed");
86 STATISTIC(NumTriangle,
"Number of triangle if-conversions performed");
87 STATISTIC(NumTriangleRev,
"Number of triangle (R) if-conversions performed");
88 STATISTIC(NumTriangleFalse,
"Number of triangle (F) if-conversions performed");
89 STATISTIC(NumTriangleFRev,
"Number of triangle (F/R) if-conversions performed");
90 STATISTIC(NumDiamonds,
"Number of diamond if-conversions performed");
91 STATISTIC(NumForkedDiamonds,
"Number of forked-diamond if-conversions performed");
92 STATISTIC(NumIfConvBBs,
"Number of if-converted blocks");
93 STATISTIC(NumDupBBs,
"Number of duplicated blocks");
94 STATISTIC(NumUnpred,
"Number of true blocks of diamonds unpredicated");
137 bool IsBeingAnalyzed : 1;
140 bool IsBrAnalyzable : 1;
141 bool IsBrReversible : 1;
142 bool HasFallThrough : 1;
143 bool IsUnpredicable : 1;
144 bool CannotBeCopied : 1;
145 bool ClobbersPred : 1;
146 unsigned NonPredSize = 0;
147 unsigned ExtraCost = 0;
148 unsigned ExtraCost2 = 0;
155 BBInfo() : IsDone(
false), IsBeingAnalyzed(
false),
159 ClobbersPred(
false) {}
178 bool NeedSubsumption : 1;
179 bool TClobbersPred : 1;
180 bool FClobbersPred : 1;
182 IfcvtToken(BBInfo &b, IfcvtKind k,
bool s,
unsigned d,
unsigned d2 = 0,
183 bool tc =
false,
bool fc =
false)
184 : BBI(b), Kind(k), NumDups(d), NumDups2(d2), NeedSubsumption(s),
185 TClobbersPred(tc), FClobbersPred(fc) {}
190 std::vector<BBInfo> BBAnalysis;
204 std::function<bool(const MachineFunction &)> PredicateFtor;
229 bool reverseBranchCondition(BBInfo &BBI)
const;
230 bool ValidSimple(BBInfo &TrueBBI,
unsigned &Dups,
232 bool ValidTriangle(BBInfo &TrueBBI, BBInfo &FalseBBI,
233 bool FalseBranch,
unsigned &Dups,
235 bool CountDuplicatedInstructions(
238 unsigned &Dups1,
unsigned &Dups2,
240 bool SkipUnconditionalBranches)
const;
241 bool ValidDiamond(BBInfo &TrueBBI, BBInfo &FalseBBI,
242 unsigned &Dups1,
unsigned &Dups2,
243 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const;
244 bool ValidForkedDiamond(BBInfo &TrueBBI, BBInfo &FalseBBI,
245 unsigned &Dups1,
unsigned &Dups2,
246 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const;
247 void AnalyzeBranches(BBInfo &BBI);
248 void ScanInstructions(BBInfo &BBI,
251 bool BranchUnpredicable =
false)
const;
252 bool RescanInstructions(
255 BBInfo &TrueBBI, BBInfo &FalseBBI)
const;
257 std::vector<std::unique_ptr<IfcvtToken>> &Tokens);
259 bool isTriangle =
false,
bool RevBranch =
false,
260 bool hasCommonTail =
false);
262 std::vector<std::unique_ptr<IfcvtToken>> &Tokens);
264 bool IfConvertSimple(BBInfo &BBI, IfcvtKind
Kind);
265 bool IfConvertTriangle(BBInfo &BBI, IfcvtKind
Kind);
266 bool IfConvertDiamondCommon(BBInfo &BBI, BBInfo &TrueBBI, BBInfo &FalseBBI,
267 unsigned NumDups1,
unsigned NumDups2,
268 bool TClobbersPred,
bool FClobbersPred,
269 bool RemoveBranch,
bool MergeAddEdges);
270 bool IfConvertDiamond(BBInfo &BBI, IfcvtKind
Kind,
271 unsigned NumDups1,
unsigned NumDups2,
272 bool TClobbers,
bool FClobbers);
273 bool IfConvertForkedDiamond(BBInfo &BBI, IfcvtKind
Kind,
274 unsigned NumDups1,
unsigned NumDups2,
275 bool TClobbers,
bool FClobbers);
276 void PredicateBlock(BBInfo &BBI,
280 void CopyAndPredicateBlock(BBInfo &ToBBI, BBInfo &FromBBI,
282 bool IgnoreBr =
false);
283 void MergeBlocks(BBInfo &ToBBI, BBInfo &FromBBI,
bool AddEdges =
true);
286 unsigned Cycle,
unsigned Extra,
292 bool MeetIfcvtSizeLimit(BBInfo &TBBInfo, BBInfo &FBBInfo,
302 unsigned Dups1, Dups2;
303 if (!CountDuplicatedInstructions(TIB, FIB, TIE, FIE, Dups1, Dups2,
304 *TBBInfo.BB, *FBBInfo.BB,
308 unsigned BranchBytes = 0;
309 unsigned CommonBytes = 0;
312 for (
auto &
I :
make_range(TBBInfo.BB->begin(), TIB)) {
316 for (
auto &
I :
make_range(FBBInfo.BB->begin(), FIB)) {
325 for (
auto &
I :
make_range(TIE, TBBInfo.BB->end())) {
326 if (
I.isBranch() && TBBInfo.IsBrAnalyzable && !Forked) {
334 for (
auto &
I :
make_range(FIE, FBBInfo.BB->end())) {
335 if (
I.isBranch() && FBBInfo.IsBrAnalyzable && !Forked) {
355 unsigned NumPredicatedInstructions = 0;
357 if (!
I.isDebugInstr()) {
359 NumPredicatedInstructions++;
363 if (!
I.isDebugInstr()) {
365 NumPredicatedInstructions++;
371 if (NumPredicatedInstructions > 15)
377 MF, NumPredicatedInstructions);
379 LLVM_DEBUG(
dbgs() <<
"MeetIfcvtSizeLimit(BranchBytes=" << BranchBytes
380 <<
", CommonBytes=" << CommonBytes
381 <<
", NumPredicatedInstructions=" 382 << NumPredicatedInstructions
383 <<
", ExtraPredicateBytes=" << ExtraPredicateBytes
385 return (BranchBytes + CommonBytes) > ExtraPredicateBytes;
387 unsigned TCycle = TBBInfo.NonPredSize + TBBInfo.ExtraCost - Dups;
388 unsigned FCycle = FBBInfo.NonPredSize + FBBInfo.ExtraCost - Dups;
389 bool Res = TCycle > 0 && FCycle > 0 &&
391 *TBBInfo.BB, TCycle, TBBInfo.ExtraCost2, *FBBInfo.BB,
392 FCycle, FBBInfo.ExtraCost2, Prediction);
394 <<
", FCycle=" << FCycle
395 <<
", TExtra=" << TBBInfo.ExtraCost2 <<
", FExtra=" 396 << FBBInfo.ExtraCost2 <<
") = " << Res <<
"\n");
402 bool blockAlwaysFallThrough(BBInfo &BBI)
const {
403 return BBI.IsBrAnalyzable && BBI.TrueBB ==
nullptr;
407 static bool IfcvtTokenCmp(
const std::unique_ptr<IfcvtToken> &C1,
408 const std::unique_ptr<IfcvtToken> &C2) {
409 int Incr1 = (C1->Kind == ICDiamond)
410 ? -(
int)(C1->NumDups + C1->NumDups2) : (
int)C1->NumDups;
411 int Incr2 = (C2->Kind == ICDiamond)
412 ? -(
int)(C2->NumDups + C2->NumDups2) : (
int)C2->NumDups;
415 else if (Incr1 == Incr2) {
417 if (!C1->NeedSubsumption && C2->NeedSubsumption)
419 else if (C1->NeedSubsumption == C2->NeedSubsumption) {
421 if ((
unsigned)C1->Kind < (
unsigned)C2->Kind)
423 else if (C1->Kind == C2->Kind)
424 return C1->BBI.BB->getNumber() < C2->BBI.BB->getNumber();
443 if (skipFunction(MF.getFunction()) || (PredicateFtor && !PredicateFtor(MF)))
451 MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
453 &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
454 MRI = &MF.getRegInfo();
455 SchedModel.
init(&ST);
457 if (!TII)
return false;
459 PreRegAlloc = MRI->
isSSA();
461 bool BFChange =
false;
465 auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
468 MMIWP ? &MMIWP->getMMI() :
nullptr);
472 << MF.getName() <<
"\'");
481 BBAnalysis.resize(MF.getNumBlockIDs());
483 std::vector<std::unique_ptr<IfcvtToken>> Tokens;
485 unsigned NumIfCvts = NumSimple + NumSimpleFalse + NumTriangle +
486 NumTriangleRev + NumTriangleFalse + NumTriangleFRev + NumDiamonds;
491 AnalyzeBlocks(MF, Tokens);
492 while (!Tokens.empty()) {
493 std::unique_ptr<IfcvtToken> Token = std::move(Tokens.back());
495 BBInfo &BBI = Token->BBI;
496 IfcvtKind
Kind = Token->Kind;
497 unsigned NumDups = Token->NumDups;
498 unsigned NumDups2 = Token->NumDups2;
503 BBI.IsEnqueued =
false;
507 BBI.IsEnqueued =
false;
513 case ICSimpleFalse: {
514 bool isFalse = Kind == ICSimpleFalse;
517 << (Kind == ICSimpleFalse ?
" false" :
"")
519 << ((Kind == ICSimpleFalse) ? BBI.FalseBB->getNumber()
520 : BBI.TrueBB->getNumber())
522 RetVal = IfConvertSimple(BBI, Kind);
523 LLVM_DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
525 if (isFalse) ++NumSimpleFalse;
532 case ICTriangleFalse:
533 case ICTriangleFRev: {
534 bool isFalse = Kind == ICTriangleFalse;
535 bool isRev = (Kind == ICTriangleRev || Kind == ICTriangleFRev);
546 <<
" (T:" << BBI.TrueBB->getNumber()
547 <<
",F:" << BBI.FalseBB->getNumber() <<
") ");
548 RetVal = IfConvertTriangle(BBI, Kind);
549 LLVM_DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
552 if (isRev) ++NumTriangleFRev;
553 else ++NumTriangleFalse;
555 if (isRev) ++NumTriangleRev;
564 <<
" (T:" << BBI.TrueBB->getNumber()
565 <<
",F:" << BBI.FalseBB->getNumber() <<
") ");
566 RetVal = IfConvertDiamond(BBI, Kind, NumDups, NumDups2,
567 Token->TClobbersPred,
568 Token->FClobbersPred);
569 LLVM_DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
570 if (RetVal) ++NumDiamonds;
572 case ICForkedDiamond:
576 <<
" (T:" << BBI.TrueBB->getNumber()
577 <<
",F:" << BBI.FalseBB->getNumber() <<
") ");
578 RetVal = IfConvertForkedDiamond(BBI, Kind, NumDups, NumDups2,
579 Token->TClobbersPred,
580 Token->FClobbersPred);
581 LLVM_DEBUG(
dbgs() << (RetVal ?
"succeeded!" :
"failed!") <<
"\n");
582 if (RetVal) ++NumForkedDiamonds;
591 NumIfCvts = NumSimple + NumSimpleFalse + NumTriangle + NumTriangleRev +
592 NumTriangleFalse + NumTriangleFRev + NumDiamonds;
599 MadeChange |= Change;
607 auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
609 MF, TII, MF.getSubtarget().getRegisterInfo(),
610 MMIWP ? &MMIWP->getMMI() :
nullptr);
613 MadeChange |= BFChange;
621 if (SuccBB != TrueBB)
629 bool IfConverter::reverseBranchCondition(BBInfo &BBI)
const {
633 TII->
insertBranch(*BBI.BB, BBI.FalseBB, BBI.TrueBB, BBI.BrCond, dl);
653 bool IfConverter::ValidSimple(BBInfo &TrueBBI,
unsigned &Dups,
656 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone)
659 if (TrueBBI.IsBrAnalyzable)
662 if (TrueBBI.BB->pred_size() > 1) {
663 if (TrueBBI.CannotBeCopied ||
667 Dups = TrueBBI.NonPredSize;
678 bool IfConverter::ValidTriangle(BBInfo &TrueBBI, BBInfo &FalseBBI,
679 bool FalseBranch,
unsigned &Dups,
682 if (TrueBBI.BB == FalseBBI.BB)
685 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone)
688 if (TrueBBI.BB->pred_size() > 1) {
689 if (TrueBBI.CannotBeCopied)
692 unsigned Size = TrueBBI.NonPredSize;
693 if (TrueBBI.IsBrAnalyzable) {
694 if (TrueBBI.TrueBB && TrueBBI.BrCond.empty())
699 ? TrueBBI.TrueBB : TrueBBI.FalseBB;
711 if (!TExit && blockAlwaysFallThrough(TrueBBI)) {
713 if (++I == TrueBBI.BB->getParent()->end())
717 return TExit && TExit == FalseBBI.BB;
740 bool IfConverter::CountDuplicatedInstructions(
745 unsigned &Dups1,
unsigned &Dups2,
747 bool SkipUnconditionalBranches)
const {
748 while (TIB != TIE && FIB != FIE) {
752 if (TIB == TIE || FIB == FIE)
754 if (!TIB->isIdenticalTo(*FIB))
758 std::vector<MachineOperand> PredDefs;
762 if (!TIB->isBranch())
769 if (TIB == TIE || FIB == FIE)
781 if (SkipUnconditionalBranches) {
782 while (RTIE != RTIB && RTIE->isUnconditionalBranch())
784 while (RFIE != RFIB && RFIE->isUnconditionalBranch())
790 while (RTIE != RTIB && RFIE != RFIB) {
795 if (RTIE == RTIB || RFIE == RFIB)
797 if (!RTIE->isIdenticalTo(*RFIE))
801 if (!RTIE->isBranch())
807 FIE = std::next(RFIE.getReverse());
820 bool IfConverter::RescanInstructions(
823 BBInfo &TrueBBI, BBInfo &FalseBBI)
const {
824 bool BranchUnpredicable =
true;
825 TrueBBI.IsUnpredicable = FalseBBI.IsUnpredicable =
false;
826 ScanInstructions(TrueBBI, TIB, TIE, BranchUnpredicable);
827 if (TrueBBI.IsUnpredicable)
829 ScanInstructions(FalseBBI, FIB, FIE, BranchUnpredicable);
830 if (FalseBBI.IsUnpredicable)
832 if (TrueBBI.ClobbersPred && FalseBBI.ClobbersPred)
845 while (E1 != B1 && E2 != B2) {
848 if (E1 == B1 && E2 == B2)
852 assert(!E2->isBranch() &&
"Branch mis-match, one block is empty.");
856 assert(!E1->isBranch() &&
"Branch mis-match, one block is empty.");
860 if (E1->isBranch() || E2->isBranch())
861 assert(E1->isIdenticalTo(*E2) &&
862 "Branch mis-match, branch instructions don't match.");
884 bool IfConverter::ValidForkedDiamond(
885 BBInfo &TrueBBI, BBInfo &FalseBBI,
886 unsigned &Dups1,
unsigned &Dups2,
887 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const {
889 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone ||
890 FalseBBI.IsBeingAnalyzed || FalseBBI.IsDone)
893 if (!TrueBBI.IsBrAnalyzable || !FalseBBI.IsBrAnalyzable)
896 if (TrueBBI.BB->pred_size() > 1 || FalseBBI.BB->pred_size() > 1)
901 if (TrueBBI.BrCond.size() == 0 ||
902 FalseBBI.BrCond.size() == 0)
923 if (!((TT == FT && TF == FF) || (TF == FT && TT == FF)))
926 bool FalseReversed =
false;
927 if (TF == FT && TT == FF) {
929 if (!FalseBBI.IsBrReversible)
931 FalseReversed =
true;
932 reverseBranchCondition(FalseBBI);
936 reverseBranchCondition(FalseBBI);
944 if(!CountDuplicatedInstructions(TIB, FIB, TIE, FIE, Dups1, Dups2,
945 *TrueBBI.BB, *FalseBBI.BB,
949 TrueBBICalc.BB = TrueBBI.BB;
950 FalseBBICalc.BB = FalseBBI.BB;
951 TrueBBICalc.IsBrAnalyzable = TrueBBI.IsBrAnalyzable;
952 FalseBBICalc.IsBrAnalyzable = FalseBBI.IsBrAnalyzable;
953 if (!RescanInstructions(TIB, FIB, TIE, FIE, TrueBBICalc, FalseBBICalc))
959 TrueBBICalc.NonPredSize = TrueBBI.NonPredSize;
960 FalseBBICalc.NonPredSize = FalseBBI.NonPredSize;
966 bool IfConverter::ValidDiamond(
967 BBInfo &TrueBBI, BBInfo &FalseBBI,
968 unsigned &Dups1,
unsigned &Dups2,
969 BBInfo &TrueBBICalc, BBInfo &FalseBBICalc)
const {
971 if (TrueBBI.IsBeingAnalyzed || TrueBBI.IsDone ||
972 FalseBBI.IsBeingAnalyzed || FalseBBI.IsDone)
978 if (!TT && blockAlwaysFallThrough(TrueBBI))
980 if (!FT && blockAlwaysFallThrough(FalseBBI))
984 if (!TT && (TrueBBI.IsBrAnalyzable || FalseBBI.IsBrAnalyzable))
986 if (TrueBBI.BB->pred_size() > 1 || FalseBBI.BB->pred_size() > 1)
990 if (TrueBBI.FalseBB || FalseBBI.FalseBB)
997 bool SkipUnconditionalBranches =
998 TrueBBI.IsBrAnalyzable && FalseBBI.IsBrAnalyzable;
1003 if(!CountDuplicatedInstructions(TIB, FIB, TIE, FIE, Dups1, Dups2,
1004 *TrueBBI.BB, *FalseBBI.BB,
1005 SkipUnconditionalBranches))
1008 TrueBBICalc.BB = TrueBBI.BB;
1009 FalseBBICalc.BB = FalseBBI.BB;
1010 TrueBBICalc.IsBrAnalyzable = TrueBBI.IsBrAnalyzable;
1011 FalseBBICalc.IsBrAnalyzable = FalseBBI.IsBrAnalyzable;
1012 if (!RescanInstructions(TIB, FIB, TIE, FIE, TrueBBICalc, FalseBBICalc))
1017 TrueBBICalc.NonPredSize = TrueBBI.NonPredSize;
1018 FalseBBICalc.NonPredSize = FalseBBI.NonPredSize;
1024 void IfConverter::AnalyzeBranches(BBInfo &BBI) {
1028 BBI.TrueBB = BBI.FalseBB =
nullptr;
1030 BBI.IsBrAnalyzable =
1031 !TII->
analyzeBranch(*BBI.BB, BBI.TrueBB, BBI.FalseBB, BBI.BrCond);
1032 if (!BBI.IsBrAnalyzable) {
1033 BBI.TrueBB =
nullptr;
1034 BBI.FalseBB =
nullptr;
1039 BBI.IsBrReversible = (RevCond.size() == 0) ||
1041 BBI.HasFallThrough = BBI.IsBrAnalyzable && BBI.FalseBB ==
nullptr;
1043 if (BBI.BrCond.size()) {
1050 BBI.IsUnpredicable =
true;
1060 void IfConverter::ScanInstructions(BBInfo &BBI,
1063 bool BranchUnpredicable)
const {
1064 if (BBI.IsDone || BBI.IsUnpredicable)
1067 bool AlreadyPredicated = !BBI.Predicate.empty();
1069 BBI.NonPredSize = 0;
1072 BBI.ClobbersPred =
false;
1074 if (
MI.isDebugInstr())
1107 if (
MI.isNotDuplicable() ||
MI.isConvergent())
1108 BBI.CannotBeCopied =
true;
1111 bool isCondBr = BBI.IsBrAnalyzable &&
MI.isConditionalBranch();
1113 if (BranchUnpredicable &&
MI.isBranch()) {
1114 BBI.IsUnpredicable =
true;
1125 unsigned NumCycles = SchedModel.computeInstrLatency(&
MI,
false);
1127 BBI.ExtraCost += NumCycles-1;
1128 BBI.ExtraCost2 += ExtraPredCost;
1129 }
else if (!AlreadyPredicated) {
1133 BBI.IsUnpredicable =
true;
1142 BBI.IsUnpredicable =
true;
1148 std::vector<MachineOperand> PredDefs;
1150 BBI.ClobbersPred =
true;
1153 BBI.IsUnpredicable =
true;
1168 bool IfConverter::FeasibilityAnalysis(BBInfo &BBI,
1170 bool isTriangle,
bool RevBranch,
1171 bool hasCommonTail) {
1176 if (BBI.IsDone || (BBI.IsUnpredicable && !hasCommonTail))
1182 if (BBI.Predicate.size() && !BBI.IsBrAnalyzable)
1190 if (!hasCommonTail && BBI.BrCond.size()) {
1211 void IfConverter::AnalyzeBlock(
1224 while (!BBStack.
empty()) {
1225 BBState &State = BBStack.
back();
1227 BBInfo &BBI = BBAnalysis[BB->
getNumber()];
1229 if (!State.SuccsAnalyzed) {
1230 if (BBI.IsAnalyzed || BBI.IsBeingAnalyzed) {
1236 BBI.IsBeingAnalyzed =
true;
1238 AnalyzeBranches(BBI);
1241 ScanInstructions(BBI, Begin, End);
1245 if (!BBI.IsBrAnalyzable || BBI.BrCond.empty() || BBI.IsDone) {
1246 BBI.IsBeingAnalyzed =
false;
1247 BBI.IsAnalyzed =
true;
1253 if (BBI.TrueBB == BB || BBI.FalseBB == BB) {
1254 BBI.IsBeingAnalyzed =
false;
1255 BBI.IsAnalyzed =
true;
1262 BBI.IsBeingAnalyzed =
false;
1263 BBI.IsAnalyzed =
true;
1269 State.SuccsAnalyzed =
true;
1275 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1276 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1278 if (TrueBBI.IsDone && FalseBBI.IsDone) {
1279 BBI.IsBeingAnalyzed =
false;
1280 BBI.IsAnalyzed =
true;
1286 RevCond(BBI.BrCond.begin(), BBI.BrCond.end());
1291 bool TNeedSub = !TrueBBI.Predicate.empty();
1292 bool FNeedSub = !FalseBBI.Predicate.empty();
1293 bool Enqueued =
false;
1298 BBInfo TrueBBICalc, FalseBBICalc;
1299 auto feasibleDiamond = [&](
bool Forked) {
1300 bool MeetsSize = MeetIfcvtSizeLimit(TrueBBICalc, FalseBBICalc, *BB,
1301 Dups + Dups2, Prediction, Forked);
1302 bool TrueFeasible = FeasibilityAnalysis(TrueBBI, BBI.BrCond,
1305 bool FalseFeasible = FeasibilityAnalysis(FalseBBI, RevCond,
1308 return MeetsSize && TrueFeasible && FalseFeasible;
1311 if (ValidDiamond(TrueBBI, FalseBBI, Dups, Dups2,
1312 TrueBBICalc, FalseBBICalc)) {
1313 if (feasibleDiamond(
false)) {
1322 Tokens.push_back(std::make_unique<IfcvtToken>(
1323 BBI, ICDiamond, TNeedSub | FNeedSub, Dups, Dups2,
1324 (
bool) TrueBBICalc.ClobbersPred, (
bool) FalseBBICalc.ClobbersPred));
1327 }
else if (ValidForkedDiamond(TrueBBI, FalseBBI, Dups, Dups2,
1328 TrueBBICalc, FalseBBICalc)) {
1329 if (feasibleDiamond(
true)) {
1340 Tokens.push_back(std::make_unique<IfcvtToken>(
1341 BBI, ICForkedDiamond, TNeedSub | FNeedSub, Dups, Dups2,
1342 (
bool) TrueBBICalc.ClobbersPred, (
bool) FalseBBICalc.ClobbersPred));
1348 if (ValidTriangle(TrueBBI, FalseBBI,
false, Dups, Prediction) &&
1349 MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize + TrueBBI.ExtraCost,
1350 TrueBBI.ExtraCost2, Prediction) &&
1351 FeasibilityAnalysis(TrueBBI, BBI.BrCond,
true)) {
1360 std::make_unique<IfcvtToken>(BBI, ICTriangle, TNeedSub, Dups));
1364 if (ValidTriangle(TrueBBI, FalseBBI,
true, Dups, Prediction) &&
1365 MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize + TrueBBI.ExtraCost,
1366 TrueBBI.ExtraCost2, Prediction) &&
1367 FeasibilityAnalysis(TrueBBI, BBI.BrCond,
true,
true)) {
1369 std::make_unique<IfcvtToken>(BBI, ICTriangleRev, TNeedSub, Dups));
1373 if (ValidSimple(TrueBBI, Dups, Prediction) &&
1374 MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize + TrueBBI.ExtraCost,
1375 TrueBBI.ExtraCost2, Prediction) &&
1376 FeasibilityAnalysis(TrueBBI, BBI.BrCond)) {
1385 std::make_unique<IfcvtToken>(BBI, ICSimple, TNeedSub, Dups));
1391 if (ValidTriangle(FalseBBI, TrueBBI,
false, Dups,
1393 MeetIfcvtSizeLimit(*FalseBBI.BB,
1394 FalseBBI.NonPredSize + FalseBBI.ExtraCost,
1395 FalseBBI.ExtraCost2, Prediction.
getCompl()) &&
1396 FeasibilityAnalysis(FalseBBI, RevCond,
true)) {
1397 Tokens.push_back(std::make_unique<IfcvtToken>(BBI, ICTriangleFalse,
1402 if (ValidTriangle(FalseBBI, TrueBBI,
true, Dups,
1404 MeetIfcvtSizeLimit(*FalseBBI.BB,
1405 FalseBBI.NonPredSize + FalseBBI.ExtraCost,
1406 FalseBBI.ExtraCost2, Prediction.
getCompl()) &&
1407 FeasibilityAnalysis(FalseBBI, RevCond,
true,
true)) {
1409 std::make_unique<IfcvtToken>(BBI, ICTriangleFRev, FNeedSub, Dups));
1413 if (ValidSimple(FalseBBI, Dups, Prediction.
getCompl()) &&
1414 MeetIfcvtSizeLimit(*FalseBBI.BB,
1415 FalseBBI.NonPredSize + FalseBBI.ExtraCost,
1416 FalseBBI.ExtraCost2, Prediction.
getCompl()) &&
1417 FeasibilityAnalysis(FalseBBI, RevCond)) {
1419 std::make_unique<IfcvtToken>(BBI, ICSimpleFalse, FNeedSub, Dups));
1424 BBI.IsEnqueued = Enqueued;
1425 BBI.IsBeingAnalyzed =
false;
1426 BBI.IsAnalyzed =
true;
1432 void IfConverter::AnalyzeBlocks(
1433 MachineFunction &MF, std::vector<std::unique_ptr<IfcvtToken>> &Tokens) {
1435 AnalyzeBlock(MBB, Tokens);
1451 if (I == E || !I->empty() || !PI->isSuccessor(&*I))
1456 return PI->isSuccessor(&*I);
1463 BBInfo &PBBI = BBAnalysis[Predecessor->getNumber()];
1464 if (PBBI.IsDone || PBBI.BB == &MBB)
1466 PBBI.IsAnalyzed =
false;
1467 PBBI.IsEnqueued =
false;
1489 for (
unsigned Reg : Redefs)
1493 Redefs.stepForward(MI, Clobbers);
1496 for (
auto Clobber : Clobbers) {
1499 unsigned Reg = Clobber.first;
1506 if (LiveBeforeMI.
count(Reg))
1517 if (LiveBeforeMI.
count(Reg))
1520 bool HasLiveSubReg =
false;
1522 if (!LiveBeforeMI.
count(*S))
1524 HasLiveSubReg =
true;
1534 bool IfConverter::IfConvertSimple(BBInfo &BBI, IfcvtKind
Kind) {
1535 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1536 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1537 BBInfo *CvtBBI = &TrueBBI;
1538 BBInfo *NextBBI = &FalseBBI;
1541 if (Kind == ICSimpleFalse)
1546 if (CvtBBI->IsDone ||
1547 (CvtBBI->CannotBeCopied && CvtMBB.
pred_size() > 1)) {
1549 BBI.IsAnalyzed =
false;
1550 CvtBBI->IsAnalyzed =
false;
1558 if (Kind == ICSimpleFalse)
1578 CopyAndPredicateBlock(BBI, *CvtBBI, Cond);
1581 BBI.BB->removeSuccessor(&CvtMBB,
true);
1584 PredicateBlock(*CvtBBI, CvtMBB.
end(), Cond);
1588 MergeBlocks(BBI, *CvtBBI);
1591 bool IterIfcvt =
true;
1594 BBI.HasFallThrough =
false;
1611 InvalidatePreds(*BBI.BB);
1612 CvtBBI->IsDone =
true;
1619 bool IfConverter::IfConvertTriangle(BBInfo &BBI, IfcvtKind Kind) {
1620 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
1621 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
1622 BBInfo *CvtBBI = &TrueBBI;
1623 BBInfo *NextBBI = &FalseBBI;
1627 if (Kind == ICTriangleFalse || Kind == ICTriangleFRev)
1632 if (CvtBBI->IsDone ||
1633 (CvtBBI->CannotBeCopied && CvtMBB.
pred_size() > 1)) {
1635 BBI.IsAnalyzed =
false;
1636 CvtBBI->IsAnalyzed =
false;
1644 if (Kind == ICTriangleFalse || Kind == ICTriangleFRev)
1648 if (Kind == ICTriangleRev || Kind == ICTriangleFRev) {
1649 if (reverseBranchCondition(*CvtBBI)) {
1655 BBInfo &PBBI = BBAnalysis[PBB->getNumber()];
1656 if (PBBI.IsEnqueued) {
1657 PBBI.IsAnalyzed =
false;
1658 PBBI.IsEnqueued =
false;
1672 bool HasEarlyExit = CvtBBI->FalseBB !=
nullptr;
1690 CopyAndPredicateBlock(BBI, *CvtBBI, Cond,
true);
1694 PredicateBlock(*CvtBBI, CvtMBB.
end(), Cond);
1697 MergeBlocks(BBI, *CvtBBI,
false);
1701 BBI.BB->removeSuccessor(&CvtMBB,
true);
1706 CvtBBI->BrCond.end());
1717 auto NewNext = BBNext + BBCvt * CvtNext;
1718 auto NewTrueBBIter =
find(BBI.BB->successors(), NewTrueBB);
1719 if (NewTrueBBIter != BBI.BB->succ_end())
1720 BBI.BB->setSuccProbability(NewTrueBBIter, NewNext);
1722 auto NewFalse = BBCvt * CvtFalse;
1723 TII->
insertBranch(*BBI.BB, CvtBBI->FalseBB,
nullptr, RevCond, dl);
1724 BBI.BB->addSuccessor(CvtBBI->FalseBB, NewFalse);
1729 bool FalseBBDead =
false;
1730 bool IterIfcvt =
true;
1732 if (!isFallThrough) {
1736 if (!HasEarlyExit &&
1737 NextMBB.
pred_size() == 1 && !NextBBI->HasFallThrough &&
1739 MergeBlocks(BBI, *NextBBI);
1743 BBI.HasFallThrough =
false;
1753 InvalidatePreds(*BBI.BB);
1754 CvtBBI->IsDone =
true;
1756 NextBBI->IsDone =
true;
1773 bool IfConverter::IfConvertDiamondCommon(
1774 BBInfo &BBI, BBInfo &TrueBBI, BBInfo &FalseBBI,
1775 unsigned NumDups1,
unsigned NumDups2,
1776 bool TClobbersPred,
bool FClobbersPred,
1777 bool RemoveBranch,
bool MergeAddEdges) {
1779 if (TrueBBI.IsDone || FalseBBI.IsDone ||
1780 TrueBBI.BB->pred_size() > 1 || FalseBBI.BB->pred_size() > 1) {
1782 BBI.IsAnalyzed =
false;
1783 TrueBBI.IsAnalyzed =
false;
1784 FalseBBI.IsAnalyzed =
false;
1788 if (TrueBBI.BB->hasAddressTaken() || FalseBBI.BB->hasAddressTaken())
1795 BBInfo *BBI1 = &TrueBBI;
1796 BBInfo *BBI2 = &FalseBBI;
1804 bool DoSwap =
false;
1805 if (TClobbersPred && !FClobbersPred)
1807 else if (!TClobbersPred && !FClobbersPred) {
1808 if (TrueBBI.NonPredSize > FalseBBI.NonPredSize)
1810 }
else if (TClobbersPred && FClobbersPred)
1839 BBI1->NonPredSize -= NumDups1;
1840 BBI2->NonPredSize -= NumDups1;
1845 for (
unsigned i = 0; i < NumDups1; ++DI1) {
1846 if (DI1 == MBB1.
end())
1848 if (!DI1->isDebugInstr())
1851 while (NumDups1 != 0) {
1858 if (DI2 == MBB2.
end())
1860 if (!DI2->isDebugInstr())
1871 BBI.BB->splice(BBI.BB->end(), &MBB1, MBB1.
begin(), DI1);
1882 if (!BBI1->IsBrAnalyzable)
1888 while (DI1 != MBB1.
begin()) {
1890 if (!Prev->isBranch() && !Prev->isDebugInstr())
1894 for (
unsigned i = 0; i != NumDups2; ) {
1907 if (!DI1->isDebugInstr())
1912 DI2 = BBI2->BB->end();
1920 while (DI2 != MBB2.
begin()) {
1922 if (!Prev->isBranch() && !Prev->isDebugInstr())
1927 while (NumDups2 != 0) {
1933 if (!DI2->isDebugInstr())
1949 if (FI.isDebugInstr())
1960 }
else if (!RedefsByFalse.
count(Reg)) {
1965 ExtUses.
insert(*SubRegs);
1973 RedefsByFalse.
insert(*SubRegs);
1980 PredicateBlock(*BBI1, MBB1.
end(), *Cond1, &RedefsByFalse);
1989 if (!MBB2.
empty() && (DI2 == MBB2.
end())) {
1992 bool BB1Predicated = BBI1T != MBB1.
end() && TII->
isPredicated(*BBI1T);
1993 bool BB2NonPredicated = BBI2T != MBB2.
end() && !TII->
isPredicated(*BBI2T);
1994 if (BB2NonPredicated && (BB1Predicated || !BBI2->IsBrAnalyzable))
1999 PredicateBlock(*BBI2, DI2, *Cond2);
2002 MergeBlocks(BBI, *BBI1, MergeAddEdges);
2003 MergeBlocks(BBI, *BBI2, MergeAddEdges);
2009 bool IfConverter::IfConvertForkedDiamond(
2010 BBInfo &BBI, IfcvtKind Kind,
2011 unsigned NumDups1,
unsigned NumDups2,
2012 bool TClobbersPred,
bool FClobbersPred) {
2013 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
2014 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
2019 if (TIE != TrueBBI.BB->end())
2020 dl = TIE->getDebugLoc();
2024 if (!IfConvertDiamondCommon(
2025 BBI, TrueBBI, FalseBBI,
2027 TClobbersPred, FClobbersPred,
2033 TII->
insertBranch(*BBI.BB, TrueBBI.TrueBB, TrueBBI.FalseBB,
2034 TrueBBI.BrCond, dl);
2037 BBI.IsDone = TrueBBI.IsDone = FalseBBI.IsDone =
true;
2038 InvalidatePreds(*BBI.BB);
2045 bool IfConverter::IfConvertDiamond(BBInfo &BBI, IfcvtKind Kind,
2046 unsigned NumDups1,
unsigned NumDups2,
2047 bool TClobbersPred,
bool FClobbersPred) {
2048 BBInfo &TrueBBI = BBAnalysis[BBI.TrueBB->getNumber()];
2049 BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
2054 if (blockAlwaysFallThrough(TrueBBI))
2055 TailBB = FalseBBI.TrueBB;
2056 assert((TailBB || !TrueBBI.IsBrAnalyzable) &&
"Unexpected!");
2059 if (!IfConvertDiamondCommon(
2060 BBI, TrueBBI, FalseBBI,
2062 TClobbersPred, FClobbersPred,
2063 TrueBBI.IsBrAnalyzable,
2074 BBI.BB->removeSuccessor(TrueBBI.BB);
2075 BBI.BB->removeSuccessor(FalseBBI.BB,
true);
2077 BBInfo &TailBBI = BBAnalysis[TailBB->
getNumber()];
2078 bool CanMergeTail = !TailBBI.HasFallThrough &&
2079 !TailBBI.BB->hasAddressTaken();
2085 CanMergeTail =
false;
2088 unsigned NumPreds = TailBB->
pred_size();
2090 CanMergeTail =
false;
2091 else if (NumPreds == 1 && CanMergeTail) {
2093 if (*PI != TrueBBI.BB && *PI != FalseBBI.BB)
2094 CanMergeTail =
false;
2097 MergeBlocks(BBI, TailBBI);
2098 TailBBI.IsDone =
true;
2102 BBI.HasFallThrough =
false;
2107 BBI.IsDone = TrueBBI.IsDone = FalseBBI.IsDone =
true;
2108 InvalidatePreds(*BBI.BB);
2116 bool SawStore =
true;
2126 if (MO.isDef() && !LaterRedefs.
count(Reg))
2135 void IfConverter::PredicateBlock(BBInfo &BBI,
2139 bool AnyUnpred =
false;
2140 bool MaySpec = LaterRedefs !=
nullptr;
2156 dbgs() <<
"Unable to predicate " <<
I <<
"!\n";
2166 BBI.Predicate.append(Cond.
begin(), Cond.
end());
2168 BBI.IsAnalyzed =
false;
2169 BBI.NonPredSize = 0;
2178 void IfConverter::CopyAndPredicateBlock(BBInfo &ToBBI, BBInfo &FromBBI,
2186 if (IgnoreBr &&
I.isBranch())
2194 ToBBI.BB->insert(ToBBI.BB->end(),
MI);
2195 ToBBI.NonPredSize++;
2197 unsigned NumCycles = SchedModel.computeInstrLatency(&
I,
false);
2199 ToBBI.ExtraCost += NumCycles-1;
2200 ToBBI.ExtraCost2 += ExtraPredCost;
2205 dbgs() <<
"Unable to predicate " <<
I <<
"!\n";
2217 std::vector<MachineBasicBlock *> Succs(FromMBB.succ_begin(),
2218 FromMBB.succ_end());
2224 if (Succ == FallThrough)
2226 ToBBI.BB->addSuccessor(Succ);
2230 ToBBI.Predicate.append(FromBBI.Predicate.begin(), FromBBI.Predicate.end());
2231 ToBBI.Predicate.append(Cond.
begin(), Cond.
end());
2233 ToBBI.ClobbersPred |= FromBBI.ClobbersPred;
2234 ToBBI.IsAnalyzed =
false;
2244 void IfConverter::MergeBlocks(BBInfo &ToBBI, BBInfo &FromBBI,
bool AddEdges) {
2247 "Removing a BB whose address is taken!");
2253 ToBBI.BB->splice(ToTI, &FromMBB, FromMBB.
begin(), FromTI);
2257 ToTI = ToBBI.BB->end();
2258 ToBBI.BB->splice(ToTI, &FromMBB, FromTI, FromMBB.
end());
2264 if (ToBBI.IsBrAnalyzable)
2265 ToBBI.BB->normalizeSuccProbs();
2274 if (AddEdges && ToBBI.BB->isSuccessor(&FromMBB)) {
2278 ToBBI.BB->removeSuccessor(&FromMBB);
2283 if (Succ == FallThrough)
2299 if (!To2FromProb.isZero())
2300 NewProb *= To2FromProb;
2328 if (ToBBI.BB->isSuccessor(Succ))
2329 ToBBI.BB->setSuccProbability(
2330 find(ToBBI.BB->successors(), Succ),
2333 ToBBI.BB->addSuccessor(Succ, NewProb);
2340 if (Last != &FromMBB)
2345 if (ToBBI.IsBrAnalyzable && FromBBI.IsBrAnalyzable)
2346 ToBBI.BB->normalizeSuccProbs();
2348 ToBBI.Predicate.append(FromBBI.Predicate.begin(), FromBBI.Predicate.end());
2349 FromBBI.Predicate.clear();
2351 ToBBI.NonPredSize += FromBBI.NonPredSize;
2352 ToBBI.ExtraCost += FromBBI.ExtraCost;
2353 ToBBI.ExtraCost2 += FromBBI.ExtraCost2;
2354 FromBBI.NonPredSize = 0;
2355 FromBBI.ExtraCost = 0;
2356 FromBBI.ExtraCost2 = 0;
2358 ToBBI.ClobbersPred |= FromBBI.ClobbersPred;
2359 ToBBI.HasFallThrough = FromBBI.HasFallThrough;
2360 ToBBI.IsAnalyzed =
false;
2361 FromBBI.IsAnalyzed =
false;
2366 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
bool isCall(QueryType Type=AnyInBundle) 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.
Analysis providing profile information.
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()
virtual unsigned getInstSizeInBytes(const MachineInstr &MI) const
Returns the size in bytes of the specified MachineInstr, or ~0U when this function is not implemented...
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
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
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...
This file contains the simple types necessary to represent the attributes associated with functions a...
iterator_range< iterator > terminators()
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...
void eraseCallSiteInfo(const MachineInstr *MI)
Erase the call site info for MI.
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.
virtual unsigned extraSizeToPredicateInstructions(const MachineFunction &MF, unsigned NumInsts) const
Return the increase in code size needed to predicate a contiguous run of NumInsts instructions...
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")
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.
void copyCallSiteInfo(const MachineInstr *Old, const MachineInstr *New)
Copy the call site info from Old to \ New.
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.
virtual unsigned predictBranchSizeForIfCvt(MachineInstr &MI) const
Return an estimate for the code size reduction (in bytes) which will be caused by removing the given ...
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
const Function & getFunction() const
Return the LLVM function that this machine code represents.
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.
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 hasMinSize() const
Optimize this function for minimum size (-Oz).
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
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())
bool isSafeToMove(AAResults *AA, bool &SawStore) const
Return true if it is safe to move this instruction.
void stable_sort(R &&Range)
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.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Properties which a MachineFunction may have at a given point in time.
Wrapper class representing virtual and physical registers.
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.