aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-03-20 11:40:34 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-05-14 11:43:05 +0000
commit349cc55c9796c4596a5b9904cd3281af295f878f (patch)
tree410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp
parentcb2ae6163174b90e999326ecec3699ee093a5d43 (diff)
parentc0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp95
1 files changed, 32 insertions, 63 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp b/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp
index 697513b5db7a..5d4b007f11e6 100644
--- a/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp
@@ -194,7 +194,7 @@ bool PHILinearize::findSourcesFromMBB(MachineBasicBlock *SourceMBB,
}
void PHILinearize::addDest(unsigned DestReg, const DebugLoc &DL) {
- assert(findPHIInfoElement(DestReg) == nullptr && "Dest already exsists");
+ assert(findPHIInfoElement(DestReg) == nullptr && "Dest already exists");
PHISourcesT EmptySet;
PHIInfoElementT *NewElement = new PHIInfoElementT();
NewElement->DestReg = DestReg;
@@ -606,7 +606,7 @@ MRT::initializeMRT(MachineFunction &MF, const MachineRegionInfo *RegionInfo,
DenseMap<MachineRegion *, RegionMRT *> &RegionMap) {
for (auto &MFI : MF) {
MachineBasicBlock *ExitMBB = &MFI;
- if (ExitMBB->succ_size() == 0) {
+ if (ExitMBB->succ_empty()) {
return ExitMBB;
}
}
@@ -748,10 +748,8 @@ void LinearizedRegion::storeLiveOuts(MachineBasicBlock *MBB,
// If we have a successor with a PHI, source coming from this MBB we have to
// add the register as live out
- for (MachineBasicBlock::succ_iterator SI = MBB->succ_begin(),
- E = MBB->succ_end();
- SI != E; ++SI) {
- for (auto &II : *(*SI)) {
+ for (MachineBasicBlock *Succ : MBB->successors()) {
+ for (auto &II : *Succ) {
if (II.isPHI()) {
MachineInstr &PHI = II;
int numPreds = getPHINumInputs(PHI);
@@ -760,7 +758,7 @@ void LinearizedRegion::storeLiveOuts(MachineBasicBlock *MBB,
unsigned PHIReg = getPHISourceReg(PHI, i);
LLVM_DEBUG(dbgs()
<< "Add LiveOut (PhiSource " << printMBBReference(*MBB)
- << " -> " << printMBBReference(*(*SI))
+ << " -> " << printMBBReference(*Succ)
<< "): " << printReg(PHIReg, TRI) << "\n");
addLiveOut(PHIReg);
}
@@ -813,7 +811,7 @@ void LinearizedRegion::storeLiveOuts(RegionMRT *Region,
} else {
LinearizedRegion *SubRegion = CI->getRegionMRT()->getLinearizedRegion();
// We should be limited to only store registers that are live out from the
- // lineaized region
+ // linearized region
for (auto MBBI : SubRegion->MBBs) {
storeMBBLiveOuts(MBBI, MRI, TRI, PHIInfo, TopRegion);
}
@@ -896,7 +894,7 @@ void LinearizedRegion::replaceRegister(unsigned Register,
assert(Register != NewRegister && "Cannot replace a reg with itself");
LLVM_DEBUG(
- dbgs() << "Pepareing to replace register (region): "
+ dbgs() << "Preparing to replace register (region): "
<< printReg(Register, MRI->getTargetRegisterInfo()) << " with "
<< printReg(NewRegister, MRI->getTargetRegisterInfo()) << "\n");
@@ -1073,7 +1071,6 @@ private:
const SIInstrInfo *TII;
const TargetRegisterInfo *TRI;
MachineRegisterInfo *MRI;
- unsigned BBSelectRegister;
PHILinearize PHIInfo;
DenseMap<MachineBasicBlock *, MachineBasicBlock *> FallthroughMap;
RegionMRT *RMRT;
@@ -1125,8 +1122,6 @@ private:
void transformSimpleIfRegion(RegionMRT *Region);
- void eliminateDeadBranchOperands(MachineBasicBlock::instr_iterator &II);
-
void insertUnconditionalBranch(MachineBasicBlock *MBB,
MachineBasicBlock *Dest,
const DebugLoc &DL = DebugLoc());
@@ -1238,11 +1233,7 @@ bool AMDGPUMachineCFGStructurizer::regionIsSimpleIf(RegionMRT *Region) {
return false;
}
- for (MachineBasicBlock::const_succ_iterator SI = Entry->succ_begin(),
- E = Entry->succ_end();
- SI != E; ++SI) {
- MachineBasicBlock *Current = *SI;
-
+ for (MachineBasicBlock *Current : Entry->successors()) {
if (Current == Succ) {
FoundBypass = true;
} else if ((Current->succ_size() == 1) &&
@@ -1280,10 +1271,7 @@ static void fixRegionTerminator(RegionMRT *Region) {
auto Exit = LRegion->getExit();
SmallPtrSet<MachineBasicBlock *, 2> Successors;
- for (MachineBasicBlock::const_succ_iterator SI = Exit->succ_begin(),
- SE = Exit->succ_end();
- SI != SE; ++SI) {
- MachineBasicBlock *Succ = *SI;
+ for (MachineBasicBlock *Succ : Exit->successors()) {
if (LRegion->contains(Succ)) {
// Do not allow re-assign
assert(InternalSucc == nullptr);
@@ -1404,7 +1392,7 @@ void AMDGPUMachineCFGStructurizer::extractKilledPHIs(MachineBasicBlock *MBB) {
MachineInstr &Instr = *I;
if (Instr.isPHI()) {
unsigned PHIDestReg = getPHIDestReg(Instr);
- LLVM_DEBUG(dbgs() << "Extractking killed phi:\n");
+ LLVM_DEBUG(dbgs() << "Extracting killed phi:\n");
LLVM_DEBUG(Instr.dump());
PHIs.insert(&Instr);
PHIInfo.addDest(PHIDestReg, Instr.getDebugLoc());
@@ -1589,11 +1577,9 @@ void AMDGPUMachineCFGStructurizer::replaceLiveOutRegs(
// Check if register is live out of the basic block
MachineBasicBlock *DefMBB = getDefInstr(Reg)->getParent();
- for (auto UI = MRI->use_begin(Reg), E = MRI->use_end(); UI != E; ++UI) {
- if ((*UI).getParent()->getParent() != DefMBB) {
+ for (const MachineOperand &MO : MRI->use_operands(Reg))
+ if (MO.getParent()->getParent() != DefMBB)
IsDead = false;
- }
- }
LLVM_DEBUG(dbgs() << "Register " << printReg(Reg, TRI) << " is "
<< (IsDead ? "dead" : "alive")
@@ -1686,7 +1672,7 @@ void AMDGPUMachineCFGStructurizer::insertUnconditionalBranch(MachineBasicBlock *
static MachineBasicBlock *getSingleExitNode(MachineFunction &MF) {
MachineBasicBlock *result = nullptr;
for (auto &MFI : MF) {
- if (MFI.succ_size() == 0) {
+ if (MFI.succ_empty()) {
if (result == nullptr) {
result = &MFI;
} else {
@@ -1770,34 +1756,27 @@ static void removeExternalCFGSuccessors(MachineBasicBlock *MBB) {
static void removeExternalCFGEdges(MachineBasicBlock *StartMBB,
MachineBasicBlock *EndMBB) {
- // We have to check against the StartMBB successor becasuse a
+ // We have to check against the StartMBB successor because a
// structurized region with a loop will have the entry block split,
// and the backedge will go to the entry successor.
DenseSet<std::pair<MachineBasicBlock *, MachineBasicBlock *>> Succs;
unsigned SuccSize = StartMBB->succ_size();
if (SuccSize > 0) {
MachineBasicBlock *StartMBBSucc = *(StartMBB->succ_begin());
- for (MachineBasicBlock::succ_iterator PI = EndMBB->succ_begin(),
- E = EndMBB->succ_end();
- PI != E; ++PI) {
+ for (MachineBasicBlock *Succ : EndMBB->successors()) {
// Either we have a back-edge to the entry block, or a back-edge to the
// successor of the entry block since the block may be split.
- if ((*PI) != StartMBB &&
- !((*PI) == StartMBBSucc && StartMBB != EndMBB && SuccSize == 1)) {
+ if (Succ != StartMBB &&
+ !(Succ == StartMBBSucc && StartMBB != EndMBB && SuccSize == 1)) {
Succs.insert(
- std::pair<MachineBasicBlock *, MachineBasicBlock *>(EndMBB, *PI));
+ std::pair<MachineBasicBlock *, MachineBasicBlock *>(EndMBB, Succ));
}
}
}
- for (MachineBasicBlock::pred_iterator PI = StartMBB->pred_begin(),
- E = StartMBB->pred_end();
- PI != E; ++PI) {
- if ((*PI) != EndMBB) {
- Succs.insert(
- std::pair<MachineBasicBlock *, MachineBasicBlock *>(*PI, StartMBB));
- }
- }
+ for (MachineBasicBlock *Pred : StartMBB->predecessors())
+ if (Pred != EndMBB)
+ Succs.insert(std::make_pair(Pred, StartMBB));
for (auto SI : Succs) {
std::pair<MachineBasicBlock *, MachineBasicBlock *> Edge = SI;
@@ -1815,14 +1794,9 @@ MachineBasicBlock *AMDGPUMachineCFGStructurizer::createIfBlock(
MachineBasicBlock *IfBB = MF->CreateMachineBasicBlock();
if (InheritPreds) {
- for (MachineBasicBlock::pred_iterator PI = CodeBBStart->pred_begin(),
- E = CodeBBStart->pred_end();
- PI != E; ++PI) {
- if ((*PI) != CodeBBEnd) {
- MachineBasicBlock *Pred = (*PI);
+ for (MachineBasicBlock *Pred : CodeBBStart->predecessors())
+ if (Pred != CodeBBEnd)
Pred->addSuccessor(IfBB);
- }
- }
}
removeExternalCFGEdges(CodeBBStart, CodeBBEnd);
@@ -1872,9 +1846,8 @@ void AMDGPUMachineCFGStructurizer::ensureCondIsNotKilled(
return;
Register CondReg = Cond[0].getReg();
- for (auto UI = MRI->use_begin(CondReg), E = MRI->use_end(); UI != E; ++UI) {
- (*UI).setIsKill(false);
- }
+ for (MachineOperand &MO : MRI->use_operands(CondReg))
+ MO.setIsKill(false);
}
void AMDGPUMachineCFGStructurizer::rewriteCodeBBTerminator(MachineBasicBlock *CodeBB,
@@ -2018,7 +1991,7 @@ void AMDGPUMachineCFGStructurizer::rewriteLiveOutRegs(MachineBasicBlock *IfBB,
LLVM_DEBUG(dbgs() << "LiveOut: " << printReg(LI, TRI));
if (!containsDef(CodeBB, InnerRegion, LI) ||
(!IsSingleBB && (getDefInstr(LI)->getParent() == LRegion->getExit()))) {
- // If the register simly lives through the CodeBB, we don't have
+ // If the register simply lives through the CodeBB, we don't have
// to rewrite anything since the register is not defined in this
// part of the code.
LLVM_DEBUG(dbgs() << "- through");
@@ -2028,14 +2001,14 @@ void AMDGPUMachineCFGStructurizer::rewriteLiveOutRegs(MachineBasicBlock *IfBB,
unsigned Reg = LI;
if (/*!PHIInfo.isSource(Reg) &&*/ Reg != InnerRegion->getBBSelectRegOut()) {
// If the register is live out, we do want to create a phi,
- // unless it is from the Exit block, becasuse in that case there
+ // unless it is from the Exit block, because in that case there
// is already a PHI, and no need to create a new one.
// If the register is just a live out def and not part of a phi
// chain, we need to create a PHI node to handle the if region,
// and replace all uses outside of the region with the new dest
// register, unless it is the outgoing BB select register. We have
- // already creaed phi nodes for these.
+ // already created phi nodes for these.
const TargetRegisterClass *RegClass = MRI->getRegClass(Reg);
Register PHIDestReg = MRI->createVirtualRegister(RegClass);
Register IfSourceReg = MRI->createVirtualRegister(RegClass);
@@ -2569,11 +2542,9 @@ static void removeOldExitPreds(RegionMRT *Region) {
static bool mbbHasBackEdge(MachineBasicBlock *MBB,
SmallPtrSet<MachineBasicBlock *, 8> &MBBs) {
- for (auto SI = MBB->succ_begin(), SE = MBB->succ_end(); SI != SE; ++SI) {
- if (MBBs.contains(*SI)) {
+ for (MachineBasicBlock *Succ : MBB->successors())
+ if (MBBs.contains(Succ))
return true;
- }
- }
return false;
}
@@ -2591,11 +2562,9 @@ static bool containsNewBackedge(MRT *Tree,
}
} else {
RegionMRT *Region = Tree->getRegionMRT();
- SetVector<MRT *> *Children = Region->getChildren();
- for (auto CI = Children->rbegin(), CE = Children->rend(); CI != CE; ++CI) {
- if (containsNewBackedge(*CI, MBBs))
+ for (MRT *C : llvm::reverse(*Region->getChildren()))
+ if (containsNewBackedge(C, MBBs))
return true;
- }
}
return false;
}