Skip to content

Commit 067f9a4

Browse files
committed
[NFC][EarlyIfConverter] rearrange annonymous namespaces
1 parent aec9fef commit 067f9a4

File tree

1 file changed

+79
-82
lines changed

1 file changed

+79
-82
lines changed

llvm/lib/CodeGen/EarlyIfConversion.cpp

Lines changed: 79 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ class SSAIfConv {
212212
/// Update LoopInfo after if-conversion.
213213
void updateLoops(ArrayRef<MachineBasicBlock *> Removed);
214214
};
215-
} // end anonymous namespace
216215

217216
/// Check that there is no dependencies preventing if conversion.
218217
///
@@ -370,8 +369,6 @@ bool SSAIfConv::findInsertionPoint() {
370369
return false;
371370
}
372371

373-
374-
375372
/// canConvertIf - analyze the sub-cfg rooted in MBB, and return true if it is
376373
/// a potential candidate for if-conversion. Fill out the internal state.
377374
///
@@ -490,9 +487,8 @@ bool SSAIfConv::canConvertIf(MachineBasicBlock *MBB) {
490487
}
491488

492489
/// \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) {
496492
if (TReg == FReg)
497493
return true;
498494

@@ -682,42 +678,6 @@ void SSAIfConv::convertIf(SmallVectorImpl<MachineBasicBlock *> &RemoveBlocks) {
682678
LLVM_DEBUG(dbgs() << *Head);
683679
}
684680

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-
721681
void SSAIfConv::updateDomTree(ArrayRef<MachineBasicBlock *> Removed) {
722682
// convertIf can remove TBB, FBB, and Tail can be merged into Head.
723683
// TBB and FBB should not dominate any blocks.
@@ -752,14 +712,68 @@ void SSAIfConv::invalidateTraces() {
752712
Traces->verifyAnalysis();
753713
}
754714

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+
755770
// Adjust cycles with downward saturation.
756-
static unsigned adjCycles(unsigned Cyc, int Delta) {
771+
unsigned adjCycles(unsigned Cyc, int Delta) {
757772
if (Delta < 0 && Cyc + Delta > Cyc)
758773
return 0;
759774
return Cyc + Delta;
760775
}
761776

762-
namespace {
763777
/// Helper class to simplify emission of cycle counts into optimization remarks.
764778
struct Cycles {
765779
const char *Key;
@@ -768,7 +782,6 @@ struct Cycles {
768782
template <typename Remark> Remark &operator<<(Remark &R, Cycles C) {
769783
return R << ore::NV(C.Key, C.Value) << (C.Value == 1 ? " cycle" : " cycles");
770784
}
771-
} // anonymous namespace
772785

773786
struct SpeculateStrategy : SSAIfConv::PredicationStrategyBase {
774787
MachineLoopInfo *Loops = nullptr;
@@ -1011,34 +1024,6 @@ bool SpeculateStrategy::shouldConvertIf(SSAIfConv &IfConv) {
10111024
return ShouldConvert;
10121025
}
10131026

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-
10421027
bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
10431028
LLVM_DEBUG(dbgs() << "********** EARLY IF-CONVERSION **********\n"
10441029
<< "********** Function: " << MF.getName() << '\n');
@@ -1059,6 +1044,17 @@ bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
10591044
SSAIfConv IfConv(Speculate, MF, DomTree, Loops, Traces);
10601045
return IfConv.run();
10611046
}
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)
10621058

10631059
//===----------------------------------------------------------------------===//
10641060
// EarlyIfPredicator Pass
@@ -1072,20 +1068,11 @@ struct EarlyIfPredicator : MachineFunctionPass {
10721068
bool runOnMachineFunction(MachineFunction &MF) override;
10731069
StringRef getPassName() const override { return "Early If-predicator"; }
10741070
};
1075-
} // end anonymous namespace
10761071

10771072
#undef DEBUG_TYPE
10781073
#define DEBUG_TYPE "early-if-predicator"
10791074

10801075
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)
10891076

10901077
void EarlyIfPredicator::getAnalysisUsage(AnalysisUsage &AU) const {
10911078
AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
@@ -1199,3 +1186,13 @@ bool EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
11991186
SSAIfConv IfConv(Predicate, MF, DomTree, Loops);
12001187
return IfConv.run();
12011188
}
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

Comments
 (0)