Skip to content

Commit 145a692

Browse files
authored
[CodeGen] Format PHIElimination.cpp NFC (#98289)
clang-format will format entire class when `class PHIElimination : public MachineFunctionPass {` is changed. Format it firstly to reduce unnecessary changes when porting it to new pass manager.
1 parent b7a457e commit 145a692

File tree

1 file changed

+84
-84
lines changed

1 file changed

+84
-84
lines changed

llvm/lib/CodeGen/PHIElimination.cpp

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -47,76 +47,78 @@ using namespace llvm;
4747
#define DEBUG_TYPE "phi-node-elimination"
4848

4949
static cl::opt<bool>
50-
DisableEdgeSplitting("disable-phi-elim-edge-splitting", cl::init(false),
51-
cl::Hidden, cl::desc("Disable critical edge splitting "
52-
"during PHI elimination"));
50+
DisableEdgeSplitting("disable-phi-elim-edge-splitting", cl::init(false),
51+
cl::Hidden,
52+
cl::desc("Disable critical edge splitting "
53+
"during PHI elimination"));
5354

5455
static cl::opt<bool>
55-
SplitAllCriticalEdges("phi-elim-split-all-critical-edges", cl::init(false),
56-
cl::Hidden, cl::desc("Split all critical edges during "
57-
"PHI elimination"));
56+
SplitAllCriticalEdges("phi-elim-split-all-critical-edges", cl::init(false),
57+
cl::Hidden,
58+
cl::desc("Split all critical edges during "
59+
"PHI elimination"));
5860

5961
static cl::opt<bool> NoPhiElimLiveOutEarlyExit(
6062
"no-phi-elim-live-out-early-exit", cl::init(false), cl::Hidden,
6163
cl::desc("Do not use an early exit if isLiveOutPastPHIs returns true."));
6264

6365
namespace {
6466

65-
class PHIElimination : public MachineFunctionPass {
66-
MachineRegisterInfo *MRI = nullptr; // Machine register information
67-
LiveVariables *LV = nullptr;
68-
LiveIntervals *LIS = nullptr;
67+
class PHIElimination : public MachineFunctionPass {
68+
MachineRegisterInfo *MRI = nullptr; // Machine register information
69+
LiveVariables *LV = nullptr;
70+
LiveIntervals *LIS = nullptr;
6971

70-
public:
71-
static char ID; // Pass identification, replacement for typeid
72+
public:
73+
static char ID; // Pass identification, replacement for typeid
7274

73-
PHIElimination() : MachineFunctionPass(ID) {
74-
initializePHIEliminationPass(*PassRegistry::getPassRegistry());
75-
}
75+
PHIElimination() : MachineFunctionPass(ID) {
76+
initializePHIEliminationPass(*PassRegistry::getPassRegistry());
77+
}
7678

77-
bool runOnMachineFunction(MachineFunction &MF) override;
78-
void getAnalysisUsage(AnalysisUsage &AU) const override;
79+
bool runOnMachineFunction(MachineFunction &MF) override;
80+
void getAnalysisUsage(AnalysisUsage &AU) const override;
7981

80-
private:
81-
/// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions
82-
/// in predecessor basic blocks.
83-
bool EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB);
82+
private:
83+
/// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions
84+
/// in predecessor basic blocks.
85+
bool EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB);
8486

85-
void LowerPHINode(MachineBasicBlock &MBB,
86-
MachineBasicBlock::iterator LastPHIIt,
87-
bool AllEdgesCritical);
87+
void LowerPHINode(MachineBasicBlock &MBB,
88+
MachineBasicBlock::iterator LastPHIIt,
89+
bool AllEdgesCritical);
8890

89-
/// analyzePHINodes - Gather information about the PHI nodes in
90-
/// here. In particular, we want to map the number of uses of a virtual
91-
/// register which is used in a PHI node. We map that to the BB the
92-
/// vreg is coming from. This is used later to determine when the vreg
93-
/// is killed in the BB.
94-
void analyzePHINodes(const MachineFunction& MF);
91+
/// analyzePHINodes - Gather information about the PHI nodes in
92+
/// here. In particular, we want to map the number of uses of a virtual
93+
/// register which is used in a PHI node. We map that to the BB the
94+
/// vreg is coming from. This is used later to determine when the vreg
95+
/// is killed in the BB.
96+
void analyzePHINodes(const MachineFunction &MF);
9597

96-
/// Split critical edges where necessary for good coalescer performance.
97-
bool SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
98-
MachineLoopInfo *MLI,
99-
std::vector<SparseBitVector<>> *LiveInSets);
98+
/// Split critical edges where necessary for good coalescer performance.
99+
bool SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
100+
MachineLoopInfo *MLI,
101+
std::vector<SparseBitVector<>> *LiveInSets);
100102

101-
// These functions are temporary abstractions around LiveVariables and
102-
// LiveIntervals, so they can go away when LiveVariables does.
103-
bool isLiveIn(Register Reg, const MachineBasicBlock *MBB);
104-
bool isLiveOutPastPHIs(Register Reg, const MachineBasicBlock *MBB);
103+
// These functions are temporary abstractions around LiveVariables and
104+
// LiveIntervals, so they can go away when LiveVariables does.
105+
bool isLiveIn(Register Reg, const MachineBasicBlock *MBB);
106+
bool isLiveOutPastPHIs(Register Reg, const MachineBasicBlock *MBB);
105107

106-
using BBVRegPair = std::pair<unsigned, Register>;
107-
using VRegPHIUse = DenseMap<BBVRegPair, unsigned>;
108+
using BBVRegPair = std::pair<unsigned, Register>;
109+
using VRegPHIUse = DenseMap<BBVRegPair, unsigned>;
108110

109-
// Count the number of non-undef PHI uses of each register in each BB.
110-
VRegPHIUse VRegPHIUseCount;
111+
// Count the number of non-undef PHI uses of each register in each BB.
112+
VRegPHIUse VRegPHIUseCount;
111113

112-
// Defs of PHI sources which are implicit_def.
113-
SmallPtrSet<MachineInstr*, 4> ImpDefs;
114+
// Defs of PHI sources which are implicit_def.
115+
SmallPtrSet<MachineInstr *, 4> ImpDefs;
114116

115-
// Map reusable lowered PHI node -> incoming join register.
116-
using LoweredPHIMap =
117-
DenseMap<MachineInstr*, unsigned, MachineInstrExpressionTrait>;
118-
LoweredPHIMap LoweredPHIs;
119-
};
117+
// Map reusable lowered PHI node -> incoming join register.
118+
using LoweredPHIMap =
119+
DenseMap<MachineInstr *, unsigned, MachineInstrExpressionTrait>;
120+
LoweredPHIMap LoweredPHIs;
121+
};
120122

121123
} // end anonymous namespace
122124

@@ -126,11 +128,11 @@ STATISTIC(NumReused, "Number of reused lowered phis");
126128

127129
char PHIElimination::ID = 0;
128130

129-
char& llvm::PHIEliminationID = PHIElimination::ID;
131+
char &llvm::PHIEliminationID = PHIElimination::ID;
130132

131133
INITIALIZE_PASS_BEGIN(PHIElimination, DEBUG_TYPE,
132-
"Eliminate PHI nodes for register allocation",
133-
false, false)
134+
"Eliminate PHI nodes for register allocation", false,
135+
false)
134136
INITIALIZE_PASS_DEPENDENCY(LiveVariablesWrapperPass)
135137
INITIALIZE_PASS_END(PHIElimination, DEBUG_TYPE,
136138
"Eliminate PHI nodes for register allocation", false, false)
@@ -238,11 +240,11 @@ bool PHIElimination::runOnMachineFunction(MachineFunction &MF) {
238240
bool PHIElimination::EliminatePHINodes(MachineFunction &MF,
239241
MachineBasicBlock &MBB) {
240242
if (MBB.empty() || !MBB.front().isPHI())
241-
return false; // Quick exit for basic blocks without PHIs.
243+
return false; // Quick exit for basic blocks without PHIs.
242244

243245
// Get an iterator to the last PHI node.
244246
MachineBasicBlock::iterator LastPHIIt =
245-
std::prev(MBB.SkipPHIsAndLabels(MBB.begin()));
247+
std::prev(MBB.SkipPHIsAndLabels(MBB.begin()));
246248

247249
// If all incoming edges are critical, we try to deduplicate identical PHIs so
248250
// that we generate fewer copies. If at any edge is non-critical, we either
@@ -301,8 +303,8 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
301303
// Create a new register for the incoming PHI arguments.
302304
MachineFunction &MF = *MBB.getParent();
303305
unsigned IncomingReg = 0;
304-
bool EliminateNow = true; // delay elimination of nodes in LoweredPHIs
305-
bool reusedIncoming = false; // Is IncomingReg reused from an earlier PHI?
306+
bool EliminateNow = true; // delay elimination of nodes in LoweredPHIs
307+
bool reusedIncoming = false; // Is IncomingReg reused from an earlier PHI?
306308

307309
// Insert a register to register copy at the top of the current block (but
308310
// after any remaining phi nodes) which copies the new incoming register
@@ -313,7 +315,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
313315
// If all sources of a PHI node are implicit_def or undef uses, just emit an
314316
// implicit_def instead of a copy.
315317
PHICopy = BuildMI(MBB, AfterPHIsIt, MPhi->getDebugLoc(),
316-
TII->get(TargetOpcode::IMPLICIT_DEF), DestReg);
318+
TII->get(TargetOpcode::IMPLICIT_DEF), DestReg);
317319
else {
318320
// Can we reuse an earlier PHI node? This only happens for critical edges,
319321
// typically those created by tail duplication. Typically, an identical PHI
@@ -339,8 +341,8 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
339341
}
340342

341343
// Give the target possiblity to handle special cases fallthrough otherwise
342-
PHICopy = TII->createPHIDestinationCopy(MBB, AfterPHIsIt, MPhi->getDebugLoc(),
343-
IncomingReg, DestReg);
344+
PHICopy = TII->createPHIDestinationCopy(
345+
MBB, AfterPHIsIt, MPhi->getDebugLoc(), IncomingReg, DestReg);
344346
}
345347

346348
if (MPhi->peekDebugInstrNum()) {
@@ -367,8 +369,8 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
367369
// by default, so it's before the OldKill. But some Target hooks for
368370
// createPHIDestinationCopy() may modify the default insert position of
369371
// PHICopy.
370-
for (auto I = MBB.SkipPHIsAndLabels(MBB.begin()), E = MBB.end();
371-
I != E; ++I) {
372+
for (auto I = MBB.SkipPHIsAndLabels(MBB.begin()), E = MBB.end(); I != E;
373+
++I) {
372374
if (I == PHICopy)
373375
break;
374376

@@ -420,11 +422,10 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
420422
LiveInterval &IncomingLI = LIS->getOrCreateEmptyInterval(IncomingReg);
421423
VNInfo *IncomingVNI = IncomingLI.getVNInfoAt(MBBStartIndex);
422424
if (!IncomingVNI)
423-
IncomingVNI = IncomingLI.getNextValue(MBBStartIndex,
424-
LIS->getVNInfoAllocator());
425-
IncomingLI.addSegment(LiveInterval::Segment(MBBStartIndex,
426-
DestCopyIndex.getRegSlot(),
427-
IncomingVNI));
425+
IncomingVNI =
426+
IncomingLI.getNextValue(MBBStartIndex, LIS->getVNInfoAllocator());
427+
IncomingLI.addSegment(LiveInterval::Segment(
428+
MBBStartIndex, DestCopyIndex.getRegSlot(), IncomingVNI));
428429
}
429430

430431
LiveInterval &DestLI = LIS->getInterval(DestReg);
@@ -485,24 +486,24 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
485486

486487
// Now loop over all of the incoming arguments, changing them to copy into the
487488
// IncomingReg register in the corresponding predecessor basic block.
488-
SmallPtrSet<MachineBasicBlock*, 8> MBBsInsertedInto;
489+
SmallPtrSet<MachineBasicBlock *, 8> MBBsInsertedInto;
489490
for (int i = NumSrcs - 1; i >= 0; --i) {
490491
Register SrcReg = MPhi->getOperand(i * 2 + 1).getReg();
491-
unsigned SrcSubReg = MPhi->getOperand(i*2+1).getSubReg();
492-
bool SrcUndef = MPhi->getOperand(i*2+1).isUndef() ||
493-
isImplicitlyDefined(SrcReg, *MRI);
492+
unsigned SrcSubReg = MPhi->getOperand(i * 2 + 1).getSubReg();
493+
bool SrcUndef = MPhi->getOperand(i * 2 + 1).isUndef() ||
494+
isImplicitlyDefined(SrcReg, *MRI);
494495
assert(SrcReg.isVirtual() &&
495496
"Machine PHI Operands must all be virtual registers!");
496497

497498
// Get the MachineBasicBlock equivalent of the BasicBlock that is the source
498499
// path the PHI.
499-
MachineBasicBlock &opBlock = *MPhi->getOperand(i*2+2).getMBB();
500+
MachineBasicBlock &opBlock = *MPhi->getOperand(i * 2 + 2).getMBB();
500501

501502
// Check to make sure we haven't already emitted the copy for this block.
502503
// This can happen because PHI nodes may have multiple entries for the same
503504
// basic block.
504505
if (!MBBsInsertedInto.insert(&opBlock).second)
505-
continue; // If the copy has already been emitted, we're done.
506+
continue; // If the copy has already been emitted, we're done.
506507

507508
MachineInstr *SrcRegDef = MRI->getVRegDef(SrcReg);
508509
if (SrcRegDef && TII->isUnspillableTerminator(SrcRegDef)) {
@@ -529,7 +530,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
529530
// Find a safe location to insert the copy, this may be the first terminator
530531
// in the block (or end()).
531532
MachineBasicBlock::iterator InsertPos =
532-
findPHICopyInsertPoint(&opBlock, &MBB, SrcReg);
533+
findPHICopyInsertPoint(&opBlock, &MBB, SrcReg);
533534

534535
// Insert the copy.
535536
MachineInstr *NewSrcInstr = nullptr;
@@ -538,9 +539,9 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
538539
// The source register is undefined, so there is no need for a real
539540
// COPY, but we still need to ensure joint dominance by defs.
540541
// Insert an IMPLICIT_DEF instruction.
541-
NewSrcInstr = BuildMI(opBlock, InsertPos, MPhi->getDebugLoc(),
542-
TII->get(TargetOpcode::IMPLICIT_DEF),
543-
IncomingReg);
542+
NewSrcInstr =
543+
BuildMI(opBlock, InsertPos, MPhi->getDebugLoc(),
544+
TII->get(TargetOpcode::IMPLICIT_DEF), IncomingReg);
544545

545546
// Clean up the old implicit-def, if there even was one.
546547
if (MachineInstr *DefMI = MRI->getVRegDef(SrcReg))
@@ -687,7 +688,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
687688
/// particular, we want to map the number of uses of a virtual register which is
688689
/// used in a PHI node. We map that to the BB the vreg is coming from. This is
689690
/// used later to determine when the vreg is killed in the BB.
690-
void PHIElimination::analyzePHINodes(const MachineFunction& MF) {
691+
void PHIElimination::analyzePHINodes(const MachineFunction &MF) {
691692
for (const auto &MBB : MF) {
692693
for (const auto &BBI : MBB) {
693694
if (!BBI.isPHI())
@@ -703,12 +704,11 @@ void PHIElimination::analyzePHINodes(const MachineFunction& MF) {
703704
}
704705
}
705706

706-
bool PHIElimination::SplitPHIEdges(MachineFunction &MF,
707-
MachineBasicBlock &MBB,
707+
bool PHIElimination::SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
708708
MachineLoopInfo *MLI,
709709
std::vector<SparseBitVector<>> *LiveInSets) {
710710
if (MBB.empty() || !MBB.front().isPHI() || MBB.isEHPad())
711-
return false; // Quick exit for basic blocks without PHIs.
711+
return false; // Quick exit for basic blocks without PHIs.
712712

713713
const MachineLoop *CurLoop = MLI ? MLI->getLoopFor(&MBB) : nullptr;
714714
bool IsLoopHeader = CurLoop && &MBB == CurLoop->getHeader();
@@ -718,7 +718,7 @@ bool PHIElimination::SplitPHIEdges(MachineFunction &MF,
718718
BBI != BBE && BBI->isPHI(); ++BBI) {
719719
for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2) {
720720
Register Reg = BBI->getOperand(i).getReg();
721-
MachineBasicBlock *PreMBB = BBI->getOperand(i+1).getMBB();
721+
MachineBasicBlock *PreMBB = BBI->getOperand(i + 1).getMBB();
722722
// Is there a critical edge from PreMBB to MBB?
723723
if (PreMBB->succ_size() == 1)
724724
continue;
@@ -799,9 +799,9 @@ bool PHIElimination::isLiveOutPastPHIs(Register Reg,
799799
"isLiveOutPastPHIs() requires either LiveVariables or LiveIntervals");
800800
// LiveVariables considers uses in PHIs to be in the predecessor basic block,
801801
// so that a register used only in a PHI is not live out of the block. In
802-
// contrast, LiveIntervals considers uses in PHIs to be on the edge rather than
803-
// in the predecessor basic block, so that a register used only in a PHI is live
804-
// out of the block.
802+
// contrast, LiveIntervals considers uses in PHIs to be on the edge rather
803+
// than in the predecessor basic block, so that a register used only in a PHI
804+
// is live out of the block.
805805
if (LIS) {
806806
const LiveInterval &LI = LIS->getInterval(Reg);
807807
for (const MachineBasicBlock *SI : MBB->successors())

0 commit comments

Comments
 (0)