Skip to content

Commit 9ead58d

Browse files
committed
Use common register class
Remove target hook. Instead, use common register class to check if two phis are allowed to reuse the same temp.
1 parent a4bb8a1 commit 9ead58d

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,7 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
21582158
return TargetOpcode::COPY;
21592159
}
21602160

2161-
/// During PHI elimination lets target to make necessary checks and
2161+
/// During PHI eleimination lets target to make necessary checks and
21622162
/// insert the copy to the PHI destination register in a target specific
21632163
/// manner.
21642164
virtual MachineInstr *createPHIDestinationCopy(
@@ -2168,7 +2168,7 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
21682168
.addReg(Src);
21692169
}
21702170

2171-
/// During PHI elimination lets target to make necessary checks and
2171+
/// During PHI eleimination lets target to make necessary checks and
21722172
/// insert the copy to the PHI destination register in a target specific
21732173
/// manner.
21742174
virtual MachineInstr *createPHISourceCopy(MachineBasicBlock &MBB,
@@ -2180,17 +2180,6 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
21802180
.addReg(Src, 0, SrcSubReg);
21812181
}
21822182

2183-
/// During PHI elimination lets target to decide if two phis can use the
2184-
/// same register \p Reg when they have the same rhs. Register \p Reg has
2185-
/// been used for the first phi and \p PHIReg is the DestReg of the second
2186-
/// Phi. This function is to check if the second phi can reuse \p Reg as
2187-
/// its temporary register.
2188-
/// The default is to allow reuse.
2189-
virtual bool allowPHIReuse(Register Reg, Register PHIReg,
2190-
const MachineFunction &MF) const {
2191-
return true;
2192-
}
2193-
21942183
/// Returns a \p outliner::OutlinedFunction struct containing target-specific
21952184
/// information for a set of outlining candidates. Returns std::nullopt if the
21962185
/// candidates are not suitable for outlining. \p MinRepeats is the minimum

llvm/lib/CodeGen/PHIElimination.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,21 @@ void PHIEliminationImpl::LowerPHINode(MachineBasicBlock &MBB,
377377
// typically those created by tail duplication. Typically, an identical PHI
378378
// node can't occur, so avoid hashing/storing such PHIs, which is somewhat
379379
// expensive.
380+
381+
// canReuse() checks if two phis of the same rhs have the common sub class
382+
// for their lhs's and allow reuse if so. (useful for some GPU targets)
383+
auto canReuse = [](Register Reg0, Register Reg1, MachineFunction &MF) {
384+
auto &MRI = MF.getRegInfo();
385+
auto *RC0 = MRI.getRegClass(Reg0);
386+
auto *RC1 = MRI.getRegClass(Reg1);
387+
return MF.getSubtarget().getRegisterInfo()->getCommonSubClass(RC0, RC1) !=
388+
nullptr;
389+
};
390+
380391
Register *Entry = nullptr;
381392
if (AllEdgesCritical)
382393
Entry = &LoweredPHIs[MPhi];
383-
if (Entry && *Entry && TII->allowPHIReuse(*Entry, DestReg, MF)) {
394+
if (Entry && *Entry && canReuse(*Entry, DestReg, MF)) {
384395
// An identical PHI node was already lowered. Reuse the incoming register.
385396
IncomingReg = *Entry;
386397
reusedIncoming = true;

0 commit comments

Comments
 (0)