Skip to content

Commit 9ff7013

Browse files
committed
Revert for: [AMDGPU]: PHI Elimination hooks added for custom COPY insertion.
llvm-svn: 371873
1 parent 713da8d commit 9ff7013

File tree

7 files changed

+20
-142
lines changed

7 files changed

+20
-142
lines changed

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "llvm/CodeGen/MachineCombinerPattern.h"
2323
#include "llvm/CodeGen/MachineFunction.h"
2424
#include "llvm/CodeGen/MachineInstr.h"
25-
#include "llvm/CodeGen/MachineInstrBuilder.h"
2625
#include "llvm/CodeGen/MachineLoopInfo.h"
2726
#include "llvm/CodeGen/MachineOperand.h"
2827
#include "llvm/CodeGen/MachineOutliner.h"
@@ -1639,28 +1638,6 @@ class TargetInstrInfo : public MCInstrInfo {
16391638
return false;
16401639
}
16411640

1642-
/// During PHI eleimination lets target to make necessary checks and
1643-
/// insert the copy to the PHI destination register in a target specific
1644-
/// manner.
1645-
virtual MachineInstr *createPHIDestinationCopy(
1646-
MachineBasicBlock &MBB, MachineBasicBlock::iterator InsPt,
1647-
const DebugLoc &DL, Register Src, Register Dst) const {
1648-
return BuildMI(MBB, InsPt, DL, get(TargetOpcode::COPY), Dst)
1649-
.addReg(Src);
1650-
}
1651-
1652-
/// During PHI eleimination lets target to make necessary checks and
1653-
/// insert the copy to the PHI destination register in a target specific
1654-
/// manner.
1655-
virtual MachineInstr *createPHISourceCopy(MachineBasicBlock &MBB,
1656-
MachineBasicBlock::iterator InsPt,
1657-
const DebugLoc &DL, Register Src,
1658-
Register SrcSubReg,
1659-
Register Dst) const {
1660-
return BuildMI(MBB, InsPt, DL, get(TargetOpcode::COPY), Dst)
1661-
.addReg(Src, 0, SrcSubReg);
1662-
}
1663-
16641641
/// Returns a \p outliner::OutlinedFunction struct containing target-specific
16651642
/// information for a set of outlining candidates.
16661643
virtual outliner::OutlinedFunction getOutliningCandidateInfo(

llvm/lib/CodeGen/PHIElimination.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
#include "llvm/CodeGen/MachineRegisterInfo.h"
3232
#include "llvm/CodeGen/SlotIndexes.h"
3333
#include "llvm/CodeGen/TargetInstrInfo.h"
34-
#include "llvm/CodeGen/TargetLowering.h"
3534
#include "llvm/CodeGen/TargetOpcodes.h"
36-
#include "llvm/CodeGen/TargetPassConfig.h"
3735
#include "llvm/CodeGen/TargetRegisterInfo.h"
3836
#include "llvm/CodeGen/TargetSubtargetInfo.h"
3937
#include "llvm/Pass.h"
@@ -254,12 +252,11 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
254252
// Insert a register to register copy at the top of the current block (but
255253
// after any remaining phi nodes) which copies the new incoming register
256254
// into the phi node destination.
257-
MachineInstr *PHICopy = nullptr;
258255
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
259256
if (allPhiOperandsUndefined(*MPhi, *MRI))
260257
// If all sources of a PHI node are implicit_def or undef uses, just emit an
261258
// implicit_def instead of a copy.
262-
PHICopy = BuildMI(MBB, AfterPHIsIt, MPhi->getDebugLoc(),
259+
BuildMI(MBB, AfterPHIsIt, MPhi->getDebugLoc(),
263260
TII->get(TargetOpcode::IMPLICIT_DEF), DestReg);
264261
else {
265262
// Can we reuse an earlier PHI node? This only happens for critical edges,
@@ -276,13 +273,15 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
276273
const TargetRegisterClass *RC = MF.getRegInfo().getRegClass(DestReg);
277274
entry = IncomingReg = MF.getRegInfo().createVirtualRegister(RC);
278275
}
279-
// Give the target possiblity to handle special cases fallthrough otherwise
280-
PHICopy = TII->createPHIDestinationCopy(MBB, AfterPHIsIt, MPhi->getDebugLoc(),
281-
IncomingReg, DestReg);
276+
BuildMI(MBB, AfterPHIsIt, MPhi->getDebugLoc(),
277+
TII->get(TargetOpcode::COPY), DestReg)
278+
.addReg(IncomingReg);
282279
}
283280

284281
// Update live variable information if there is any.
285282
if (LV) {
283+
MachineInstr &PHICopy = *std::prev(AfterPHIsIt);
284+
286285
if (IncomingReg) {
287286
LiveVariables::VarInfo &VI = LV->getVarInfo(IncomingReg);
288287

@@ -303,7 +302,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
303302
// killed. Note that because the value is defined in several places (once
304303
// each for each incoming block), the "def" block and instruction fields
305304
// for the VarInfo is not filled in.
306-
LV->addVirtualRegisterKilled(IncomingReg, *PHICopy);
305+
LV->addVirtualRegisterKilled(IncomingReg, PHICopy);
307306
}
308307

309308
// Since we are going to be deleting the PHI node, if it is the last use of
@@ -313,14 +312,15 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
313312

314313
// If the result is dead, update LV.
315314
if (isDead) {
316-
LV->addVirtualRegisterDead(DestReg, *PHICopy);
315+
LV->addVirtualRegisterDead(DestReg, PHICopy);
317316
LV->removeVirtualRegisterDead(DestReg, *MPhi);
318317
}
319318
}
320319

321320
// Update LiveIntervals for the new copy or implicit def.
322321
if (LIS) {
323-
SlotIndex DestCopyIndex = LIS->InsertMachineInstrInMaps(*PHICopy);
322+
SlotIndex DestCopyIndex =
323+
LIS->InsertMachineInstrInMaps(*std::prev(AfterPHIsIt));
324324

325325
SlotIndex MBBStartIndex = LIS->getMBBStartIdx(&MBB);
326326
if (IncomingReg) {
@@ -406,9 +406,9 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
406406
if (DefMI->isImplicitDef())
407407
ImpDefs.insert(DefMI);
408408
} else {
409-
NewSrcInstr =
410-
TII->createPHISourceCopy(opBlock, InsertPos, MPhi->getDebugLoc(),
411-
SrcReg, SrcSubReg, IncomingReg);
409+
NewSrcInstr = BuildMI(opBlock, InsertPos, MPhi->getDebugLoc(),
410+
TII->get(TargetOpcode::COPY), IncomingReg)
411+
.addReg(SrcReg, 0, SrcSubReg);
412412
}
413413
}
414414

@@ -457,7 +457,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
457457
}
458458
} else {
459459
// We just inserted this copy.
460-
KillInst = NewSrcInstr;
460+
KillInst = std::prev(InsertPos);
461461
}
462462
}
463463
assert(KillInst->readsRegister(SrcReg) && "Cannot find kill instruction");

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6410,33 +6410,3 @@ bool llvm::execMayBeModifiedBeforeAnyUse(const MachineRegisterInfo &MRI,
64106410
return true;
64116411
}
64126412
}
6413-
6414-
MachineInstr *SIInstrInfo::createPHIDestinationCopy(
6415-
MachineBasicBlock &MBB, MachineBasicBlock::iterator LastPHIIt,
6416-
const DebugLoc &DL, Register Src, Register Dst) const {
6417-
auto Cur = MBB.begin();
6418-
while (Cur != MBB.end()) {
6419-
if (!Cur->isPHI() && Cur->readsRegister(Dst))
6420-
return BuildMI(MBB, Cur, DL, get(TargetOpcode::COPY), Dst).addReg(Src);
6421-
++Cur;
6422-
if (Cur == LastPHIIt)
6423-
break;
6424-
}
6425-
6426-
return TargetInstrInfo::createPHIDestinationCopy(MBB, LastPHIIt, DL, Src,
6427-
Dst);
6428-
}
6429-
6430-
MachineInstr *SIInstrInfo::createPHISourceCopy(
6431-
MachineBasicBlock &MBB, MachineBasicBlock::iterator InsPt,
6432-
const DebugLoc &DL, Register Src, Register SrcSubReg, Register Dst) const {
6433-
if (InsPt != MBB.end() && InsPt->isPseudo() && InsPt->definesRegister(Src)) {
6434-
InsPt++;
6435-
return BuildMI(MBB, InsPt, InsPt->getDebugLoc(), get(TargetOpcode::COPY),
6436-
Dst)
6437-
.addReg(Src, 0, SrcSubReg)
6438-
.addReg(AMDGPU::EXEC, RegState::Implicit);
6439-
}
6440-
return TargetInstrInfo::createPHISourceCopy(MBB, InsPt, DL, Src, SrcSubReg,
6441-
Dst);
6442-
}

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -954,17 +954,6 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
954954

955955
bool isBasicBlockPrologue(const MachineInstr &MI) const override;
956956

957-
MachineInstr *createPHIDestinationCopy(MachineBasicBlock &MBB,
958-
MachineBasicBlock::iterator InsPt,
959-
const DebugLoc &DL, Register Src,
960-
Register Dst) const override;
961-
962-
MachineInstr *createPHISourceCopy(MachineBasicBlock &MBB,
963-
MachineBasicBlock::iterator InsPt,
964-
const DebugLoc &DL, Register Src,
965-
Register SrcSubReg,
966-
Register Dst) const override;
967-
968957
/// Return a partially built integer add instruction without carry.
969958
/// Caller must add source operands.
970959
/// For pre-GFX9 it will generate unused carry destination operand.

llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,17 +400,13 @@ void SILowerControlFlow::emitLoop(MachineInstr &MI) {
400400

401401
void SILowerControlFlow::emitEndCf(MachineInstr &MI) {
402402
MachineBasicBlock &MBB = *MI.getParent();
403-
MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
404-
unsigned CFMask = MI.getOperand(0).getReg();
405-
MachineInstr *Def = MRI.getUniqueVRegDef(CFMask);
406403
const DebugLoc &DL = MI.getDebugLoc();
407404

408-
MachineBasicBlock::iterator InsPt =
409-
Def && Def->getParent() == &MBB ? std::next(MachineBasicBlock::iterator(Def))
410-
: MBB.begin();
411-
MachineInstr *NewMI = BuildMI(MBB, InsPt, DL, TII->get(OrOpc), Exec)
412-
.addReg(Exec)
413-
.add(MI.getOperand(0));
405+
MachineBasicBlock::iterator InsPt = MBB.begin();
406+
MachineInstr *NewMI =
407+
BuildMI(MBB, InsPt, DL, TII->get(OrOpc), Exec)
408+
.addReg(Exec)
409+
.add(MI.getOperand(0));
414410

415411
if (LIS)
416412
LIS->ReplaceMachineInstrInMaps(MI, *NewMI);

llvm/test/CodeGen/AMDGPU/phi-elimination-assertion.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ body: |
2626

2727
# CHECK-LABEL: name: foo
2828
# CHECK: bb.3:
29-
# CHECK-NEXT: dead %2:sreg_32_xm0 = IMPLICIT_DEF
3029
# CHECK-NEXT: %3:sreg_32_xm0 = COPY killed %4
30+
# CHECK-NEXT: dead %2:sreg_32_xm0 = IMPLICIT_DEF
3131
# CHECK-NEXT: S_NOP 0, implicit killed %3
3232

3333

llvm/test/CodeGen/AMDGPU/phi-elimination-end-cf.mir

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)