@@ -212,7 +212,6 @@ class SSAIfConv {
212
212
// / Update LoopInfo after if-conversion.
213
213
void updateLoops (ArrayRef<MachineBasicBlock *> Removed);
214
214
};
215
- } // end anonymous namespace
216
215
217
216
// / Check that there is no dependencies preventing if conversion.
218
217
// /
@@ -370,8 +369,6 @@ bool SSAIfConv::findInsertionPoint() {
370
369
return false ;
371
370
}
372
371
373
-
374
-
375
372
// / canConvertIf - analyze the sub-cfg rooted in MBB, and return true if it is
376
373
// / a potential candidate for if-conversion. Fill out the internal state.
377
374
// /
@@ -490,9 +487,8 @@ bool SSAIfConv::canConvertIf(MachineBasicBlock *MBB) {
490
487
}
491
488
492
489
// / \return true iff the two registers are known to have the same value.
493
- static bool hasSameValue (const MachineRegisterInfo &MRI,
494
- const TargetInstrInfo *TII, Register TReg,
495
- Register FReg) {
490
+ bool hasSameValue (const MachineRegisterInfo &MRI, const TargetInstrInfo *TII,
491
+ Register TReg, Register FReg) {
496
492
if (TReg == FReg)
497
493
return true ;
498
494
@@ -682,42 +678,6 @@ void SSAIfConv::convertIf(SmallVectorImpl<MachineBasicBlock *> &RemoveBlocks) {
682
678
LLVM_DEBUG (dbgs () << *Head);
683
679
}
684
680
685
- // ===----------------------------------------------------------------------===//
686
- // EarlyIfConverter Pass
687
- // ===----------------------------------------------------------------------===//
688
-
689
- namespace {
690
- struct EarlyIfConverter : MachineFunctionPass {
691
- static char ID;
692
- EarlyIfConverter () : MachineFunctionPass(ID) {}
693
- void getAnalysisUsage (AnalysisUsage &AU) const override ;
694
- bool runOnMachineFunction (MachineFunction &MF) override ;
695
- StringRef getPassName () const override { return " Early If-Conversion" ; }
696
- };
697
- } // end anonymous namespace
698
-
699
- char EarlyIfConverter::ID = 0 ;
700
- char &llvm::EarlyIfConverterID = EarlyIfConverter::ID;
701
-
702
- INITIALIZE_PASS_BEGIN (EarlyIfConverter, DEBUG_TYPE,
703
- " Early If Converter" , false , false )
704
- INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
705
- INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
706
- INITIALIZE_PASS_DEPENDENCY(MachineTraceMetrics)
707
- INITIALIZE_PASS_END(EarlyIfConverter, DEBUG_TYPE,
708
- " Early If Converter" , false , false )
709
-
710
- void EarlyIfConverter::getAnalysisUsage(AnalysisUsage &AU) const {
711
- AU.addRequired <MachineBranchProbabilityInfoWrapperPass>();
712
- AU.addRequired <MachineDominatorTreeWrapperPass>();
713
- AU.addPreserved <MachineDominatorTreeWrapperPass>();
714
- AU.addRequired <MachineLoopInfoWrapperPass>();
715
- AU.addPreserved <MachineLoopInfoWrapperPass>();
716
- AU.addRequired <MachineTraceMetrics>();
717
- AU.addPreserved <MachineTraceMetrics>();
718
- MachineFunctionPass::getAnalysisUsage (AU);
719
- }
720
-
721
681
void SSAIfConv::updateDomTree (ArrayRef<MachineBasicBlock *> Removed) {
722
682
// convertIf can remove TBB, FBB, and Tail can be merged into Head.
723
683
// TBB and FBB should not dominate any blocks.
@@ -752,14 +712,68 @@ void SSAIfConv::invalidateTraces() {
752
712
Traces->verifyAnalysis ();
753
713
}
754
714
715
+ // Visit blocks in dominator tree post-order. The post-order enables nested
716
+ // if-conversion in a single pass. The tryConvertIf() function may erase
717
+ // blocks, but only blocks dominated by the head block. This makes it safe to
718
+ // update the dominator tree while the post-order iterator is still active.
719
+ bool SSAIfConv::run () {
720
+ bool Changed = false ;
721
+ for (auto *DomNode : post_order (DomTree))
722
+ if (tryConvertIf (DomNode->getBlock ()))
723
+ Changed = true ;
724
+ return Changed;
725
+ }
726
+
727
+ bool SSAIfConv::tryConvertIf (MachineBasicBlock *MBB) {
728
+ bool Changed = false ;
729
+ while (canConvertIf (MBB) && Predicate.shouldConvertIf (*this )) {
730
+ // If-convert MBB and update analyses.
731
+ invalidateTraces ();
732
+ SmallVector<MachineBasicBlock *, 4 > RemoveBlocks;
733
+ convertIf (RemoveBlocks);
734
+ Changed = true ;
735
+ updateDomTree (RemoveBlocks);
736
+ for (MachineBasicBlock *MBB : RemoveBlocks)
737
+ MBB->eraseFromParent ();
738
+ updateLoops (RemoveBlocks);
739
+ }
740
+ return Changed;
741
+ }
742
+ } // end anonymous namespace
743
+
744
+ // ===----------------------------------------------------------------------===//
745
+ // EarlyIfConverter Pass
746
+ // ===----------------------------------------------------------------------===//
747
+
748
+ namespace {
749
+ struct EarlyIfConverter : MachineFunctionPass {
750
+ static char ID;
751
+ EarlyIfConverter () : MachineFunctionPass(ID) {}
752
+ void getAnalysisUsage (AnalysisUsage &AU) const override ;
753
+ bool runOnMachineFunction (MachineFunction &MF) override ;
754
+ StringRef getPassName () const override { return " Early If-Conversion" ; }
755
+ };
756
+
757
+ char EarlyIfConverter::ID = 0 ;
758
+
759
+ void EarlyIfConverter::getAnalysisUsage (AnalysisUsage &AU) const {
760
+ AU.addRequired <MachineBranchProbabilityInfoWrapperPass>();
761
+ AU.addRequired <MachineDominatorTreeWrapperPass>();
762
+ AU.addPreserved <MachineDominatorTreeWrapperPass>();
763
+ AU.addRequired <MachineLoopInfoWrapperPass>();
764
+ AU.addPreserved <MachineLoopInfoWrapperPass>();
765
+ AU.addRequired <MachineTraceMetrics>();
766
+ AU.addPreserved <MachineTraceMetrics>();
767
+ MachineFunctionPass::getAnalysisUsage (AU);
768
+ }
769
+
755
770
// Adjust cycles with downward saturation.
756
- static unsigned adjCycles (unsigned Cyc, int Delta) {
771
+ unsigned adjCycles (unsigned Cyc, int Delta) {
757
772
if (Delta < 0 && Cyc + Delta > Cyc)
758
773
return 0 ;
759
774
return Cyc + Delta;
760
775
}
761
776
762
- namespace {
763
777
// / Helper class to simplify emission of cycle counts into optimization remarks.
764
778
struct Cycles {
765
779
const char *Key;
@@ -768,7 +782,6 @@ struct Cycles {
768
782
template <typename Remark> Remark &operator <<(Remark &R, Cycles C) {
769
783
return R << ore::NV (C.Key , C.Value ) << (C.Value == 1 ? " cycle" : " cycles" );
770
784
}
771
- } // anonymous namespace
772
785
773
786
struct SpeculateStrategy : SSAIfConv::PredicationStrategyBase {
774
787
MachineLoopInfo *Loops = nullptr ;
@@ -1011,34 +1024,6 @@ bool SpeculateStrategy::shouldConvertIf(SSAIfConv &IfConv) {
1011
1024
return ShouldConvert;
1012
1025
}
1013
1026
1014
- // Visit blocks in dominator tree post-order. The post-order enables nested
1015
- // if-conversion in a single pass. The tryConvertIf() function may erase
1016
- // blocks, but only blocks dominated by the head block. This makes it safe to
1017
- // update the dominator tree while the post-order iterator is still active.
1018
- bool SSAIfConv::run () {
1019
- bool Changed = false ;
1020
- for (auto *DomNode : post_order (DomTree))
1021
- if (tryConvertIf (DomNode->getBlock ()))
1022
- Changed = true ;
1023
- return Changed;
1024
- }
1025
-
1026
- bool SSAIfConv::tryConvertIf (MachineBasicBlock *MBB) {
1027
- bool Changed = false ;
1028
- while (canConvertIf (MBB) && Predicate.shouldConvertIf (*this )) {
1029
- // If-convert MBB and update analyses.
1030
- invalidateTraces ();
1031
- SmallVector<MachineBasicBlock *, 4 > RemoveBlocks;
1032
- convertIf (RemoveBlocks);
1033
- Changed = true ;
1034
- updateDomTree (RemoveBlocks);
1035
- for (MachineBasicBlock *MBB : RemoveBlocks)
1036
- MBB->eraseFromParent ();
1037
- updateLoops (RemoveBlocks);
1038
- }
1039
- return Changed;
1040
- }
1041
-
1042
1027
bool EarlyIfConverter::runOnMachineFunction (MachineFunction &MF) {
1043
1028
LLVM_DEBUG (dbgs () << " ********** EARLY IF-CONVERSION **********\n "
1044
1029
<< " ********** Function: " << MF.getName () << ' \n ' );
@@ -1059,6 +1044,17 @@ bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
1059
1044
SSAIfConv IfConv (Speculate, MF, DomTree, Loops, Traces);
1060
1045
return IfConv.run ();
1061
1046
}
1047
+ } // end anonymous namespace
1048
+
1049
+ char &llvm::EarlyIfConverterID = EarlyIfConverter::ID;
1050
+
1051
+ INITIALIZE_PASS_BEGIN (EarlyIfConverter, DEBUG_TYPE, " Early If Converter" , false ,
1052
+ false )
1053
+ INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
1054
+ INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
1055
+ INITIALIZE_PASS_DEPENDENCY(MachineTraceMetrics)
1056
+ INITIALIZE_PASS_END(EarlyIfConverter, DEBUG_TYPE, " Early If Converter" , false ,
1057
+ false )
1062
1058
1063
1059
// ===----------------------------------------------------------------------===//
1064
1060
// EarlyIfPredicator Pass
@@ -1072,20 +1068,11 @@ struct EarlyIfPredicator : MachineFunctionPass {
1072
1068
bool runOnMachineFunction (MachineFunction &MF) override ;
1073
1069
StringRef getPassName () const override { return " Early If-predicator" ; }
1074
1070
};
1075
- } // end anonymous namespace
1076
1071
1077
1072
#undef DEBUG_TYPE
1078
1073
#define DEBUG_TYPE " early-if-predicator"
1079
1074
1080
1075
char EarlyIfPredicator::ID = 0 ;
1081
- char &llvm::EarlyIfPredicatorID = EarlyIfPredicator::ID;
1082
-
1083
- INITIALIZE_PASS_BEGIN (EarlyIfPredicator, DEBUG_TYPE, " Early If Predicator" ,
1084
- false , false )
1085
- INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
1086
- INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
1087
- INITIALIZE_PASS_END(EarlyIfPredicator, DEBUG_TYPE, " Early If Predicator" , false ,
1088
- false )
1089
1076
1090
1077
void EarlyIfPredicator::getAnalysisUsage (AnalysisUsage &AU) const {
1091
1078
AU.addRequired <MachineBranchProbabilityInfoWrapperPass>();
@@ -1199,3 +1186,13 @@ bool EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
1199
1186
SSAIfConv IfConv (Predicate, MF, DomTree, Loops);
1200
1187
return IfConv.run ();
1201
1188
}
1189
+
1190
+ } // end anonymous namespace
1191
+ char &llvm::EarlyIfPredicatorID = EarlyIfPredicator::ID;
1192
+
1193
+ INITIALIZE_PASS_BEGIN (EarlyIfPredicator, DEBUG_TYPE, " Early If Predicator" ,
1194
+ false , false )
1195
+ INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
1196
+ INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
1197
+ INITIALIZE_PASS_END(EarlyIfPredicator, DEBUG_TYPE, " Early If Predicator" , false ,
1198
+ false )
0 commit comments