Skip to content

Commit 2e34f1b

Browse files
committed
Update API
1 parent 1d324d5 commit 2e34f1b

File tree

5 files changed

+46
-10
lines changed

5 files changed

+46
-10
lines changed

llvm/include/llvm/CodeGen/LiveVariables.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class LiveVariables : public MachineFunctionPass {
147147
bool HandlePhysRegKill(Register Reg, MachineInstr *MI);
148148

149149
/// HandleRegMask - Call HandlePhysRegKill for all registers clobbered by Mask.
150-
void HandleRegMask(const MachineOperand&);
150+
void HandleRegMask(const MachineOperand&, unsigned);
151151

152152
void HandlePhysRegUse(Register Reg, MachineInstr &MI);
153153
void HandlePhysRegDef(Register Reg, MachineInstr *MI,
@@ -170,7 +170,7 @@ class LiveVariables : public MachineFunctionPass {
170170
/// is coming from.
171171
void analyzePHINodes(const MachineFunction& Fn);
172172

173-
void runOnInstr(MachineInstr &MI, SmallVectorImpl<unsigned> &Defs);
173+
void runOnInstr(MachineInstr &MI, SmallVectorImpl<unsigned> &Defs, unsigned NumRegs);
174174

175175
void runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs);
176176
public:

llvm/include/llvm/CodeGen/TargetRegisterInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ class TargetRegisterInfo : public MCRegisterInfo {
266266
virtual ~TargetRegisterInfo();
267267

268268
public:
269+
/// Return the number of registers for the function. (may overestimate)
270+
virtual unsigned getNumSupportedRegs(const MachineFunction &) const {
271+
return getNumRegs();
272+
}
273+
269274
// Register numbers can represent physical registers, virtual registers, and
270275
// sometimes stack slots. The unsigned values are divided into these ranges:
271276
//

llvm/lib/CodeGen/LiveVariables.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@ bool LiveVariables::HandlePhysRegKill(Register Reg, MachineInstr *MI) {
406406
return true;
407407
}
408408

409-
void LiveVariables::HandleRegMask(const MachineOperand &MO) {
409+
void LiveVariables::HandleRegMask(const MachineOperand &MO, unsigned NumRegs) {
410410
// Call HandlePhysRegKill() for all live registers clobbered by Mask.
411411
// Clobbered registers are always dead, sp there is no need to use
412412
// HandlePhysRegDef().
413-
for (unsigned Reg = 1, NumRegs = TRI->getNumRegs(); Reg != NumRegs; ++Reg) {
413+
for (unsigned Reg = 1; Reg != NumRegs; ++Reg) {
414414
// Skip dead regs.
415415
if (!PhysRegDef[Reg] && !PhysRegUse[Reg])
416416
continue;
@@ -421,7 +421,8 @@ void LiveVariables::HandleRegMask(const MachineOperand &MO) {
421421
// This avoids needless implicit operands.
422422
unsigned Super = Reg;
423423
for (MCPhysReg SR : TRI->superregs(Reg))
424-
if ((PhysRegDef[SR] || PhysRegUse[SR]) && MO.clobbersPhysReg(SR))
424+
if (SR < NumRegs && (PhysRegDef[SR] || PhysRegUse[SR]) &&
425+
MO.clobbersPhysReg(SR))
425426
Super = SR;
426427
HandlePhysRegKill(Super, nullptr);
427428
}
@@ -478,7 +479,8 @@ void LiveVariables::UpdatePhysRegDefs(MachineInstr &MI,
478479
}
479480

480481
void LiveVariables::runOnInstr(MachineInstr &MI,
481-
SmallVectorImpl<unsigned> &Defs) {
482+
SmallVectorImpl<unsigned> &Defs,
483+
unsigned NumRegs) {
482484
assert(!MI.isDebugOrPseudoInstr());
483485
// Process all of the operands of the instruction...
484486
unsigned NumOperandsToProcess = MI.getNumOperands();
@@ -527,7 +529,7 @@ void LiveVariables::runOnInstr(MachineInstr &MI,
527529

528530
// Process all masked registers. (Call clobbers).
529531
for (unsigned Mask : RegMasks)
530-
HandleRegMask(MI.getOperand(Mask));
532+
HandleRegMask(MI.getOperand(Mask), NumRegs);
531533

532534
// Process all defs.
533535
for (unsigned MOReg : DefRegs) {
@@ -539,7 +541,7 @@ void LiveVariables::runOnInstr(MachineInstr &MI,
539541
UpdatePhysRegDefs(MI, Defs);
540542
}
541543

542-
void LiveVariables::runOnBlock(MachineBasicBlock *MBB, const unsigned NumRegs) {
544+
void LiveVariables::runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs) {
543545
// Mark live-in registers as live-in.
544546
SmallVector<unsigned, 4> Defs;
545547
for (const auto &LI : MBB->liveins()) {
@@ -556,7 +558,7 @@ void LiveVariables::runOnBlock(MachineBasicBlock *MBB, const unsigned NumRegs) {
556558
continue;
557559
DistanceMap.insert(std::make_pair(&MI, Dist++));
558560

559-
runOnInstr(MI, Defs);
561+
runOnInstr(MI, Defs, NumRegs);
560562
}
561563

562564
// Handle any virtual assignments from PHI nodes which might be at the
@@ -597,7 +599,7 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &mf) {
597599
MRI = &mf.getRegInfo();
598600
TRI = MF->getSubtarget().getRegisterInfo();
599601

600-
const unsigned NumRegs = TRI->getNumRegs();
602+
const unsigned NumRegs = TRI->getNumSupportedRegs(mf);
601603
PhysRegDef.assign(NumRegs, nullptr);
602604
PhysRegUse.assign(NumRegs, nullptr);
603605
PHIVarInfo.resize(MF->getNumBlockIDs());

llvm/lib/Target/X86/X86RegisterInfo.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,32 @@ BitVector X86RegisterInfo::getReservedRegs(const MachineFunction &MF) const {
616616
return Reserved;
617617
}
618618

619+
unsigned X86RegisterInfo::getNumSupportedRegs(const MachineFunction &MF) const {
620+
const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
621+
// All existing Intel CPUs that support AMX support AVX512 and all existing
622+
// Intel CPUs that support APX support AMX. AVX512 implies AVX.
623+
//
624+
// We enumerate the registers in X86GenRegisterInfo.inc in this order:
625+
//
626+
// Registers before AVX512,
627+
// AVX512 registers (X/YMM16-31, ZMM0-31, K registers)
628+
// AMX registers (TMM)
629+
// APX registers (R16-R31)
630+
//
631+
// and try to return the minimum number of registers supported by the target.
632+
633+
bool HasAVX = ST.hasAVX();
634+
bool HasAVX512 = ST.hasAVX512();
635+
bool HasAMX = ST.hasAMXTILE();
636+
if (HasAMX)
637+
return X86::TMM7 + 1;
638+
if (HasAVX512)
639+
return X86::K6_K7 + 1;
640+
if (HasAVX)
641+
return X86::YMM15 + 1;
642+
return X86::YMM0;
643+
}
644+
619645
bool X86RegisterInfo::isArgumentRegister(const MachineFunction &MF,
620646
MCRegister Reg) const {
621647
const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();

llvm/lib/Target/X86/X86RegisterInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class X86RegisterInfo final : public X86GenRegisterInfo {
5151
public:
5252
explicit X86RegisterInfo(const Triple &TT);
5353

54+
/// Return the number of registers for the function.
55+
unsigned getNumSupportedRegs(const MachineFunction &MF) const override;
56+
5457
// FIXME: This should be tablegen'd like getDwarfRegNum is
5558
int getSEHRegNum(unsigned i) const;
5659

0 commit comments

Comments
 (0)