2019-05-02 00:40:49 +08:00
|
|
|
//===-- GCNNSAReassign.cpp - Reassign registers in NSA unstructions -------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
/// \brief Try to reassign registers on GFX10+ from non-sequential to sequential
|
|
|
|
/// in NSA image instructions. Later SIShrinkInstructions pass will relace NSA
|
|
|
|
/// with sequential versions where possible.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPU.h"
|
2021-01-20 20:48:02 +08:00
|
|
|
#include "GCNSubtarget.h"
|
2019-05-02 00:40:49 +08:00
|
|
|
#include "SIMachineFunctionInfo.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/CodeGen/LiveIntervals.h"
|
|
|
|
#include "llvm/CodeGen/LiveRegMatrix.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-14 05:15:01 +08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2019-05-02 00:40:49 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "amdgpu-nsa-reassign"
|
|
|
|
|
|
|
|
STATISTIC(NumNSAInstructions,
|
|
|
|
"Number of NSA instructions with non-sequential address found");
|
|
|
|
STATISTIC(NumNSAConverted,
|
|
|
|
"Number of NSA instructions changed to sequential");
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class GCNNSAReassign : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
GCNNSAReassign() : MachineFunctionPass(ID) {
|
|
|
|
initializeGCNNSAReassignPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
|
|
|
|
StringRef getPassName() const override { return "GCN NSA Reassign"; }
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.addRequired<LiveIntervals>();
|
|
|
|
AU.addRequired<VirtRegMap>();
|
|
|
|
AU.addRequired<LiveRegMatrix>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef enum {
|
|
|
|
NOT_NSA, // Not an NSA instruction
|
|
|
|
FIXED, // NSA which we cannot modify
|
|
|
|
NON_CONTIGUOUS, // NSA with non-sequential address which we can try
|
|
|
|
// to optimize.
|
|
|
|
CONTIGUOUS // NSA with all sequential address registers
|
|
|
|
} NSA_Status;
|
|
|
|
|
|
|
|
const GCNSubtarget *ST;
|
|
|
|
|
|
|
|
const MachineRegisterInfo *MRI;
|
|
|
|
|
|
|
|
const SIRegisterInfo *TRI;
|
|
|
|
|
|
|
|
VirtRegMap *VRM;
|
|
|
|
|
|
|
|
LiveRegMatrix *LRM;
|
|
|
|
|
|
|
|
LiveIntervals *LIS;
|
|
|
|
|
|
|
|
unsigned MaxNumVGPRs;
|
|
|
|
|
|
|
|
const MCPhysReg *CSRegs;
|
|
|
|
|
|
|
|
NSA_Status CheckNSA(const MachineInstr &MI, bool Fast = false) const;
|
|
|
|
|
|
|
|
bool tryAssignRegisters(SmallVectorImpl<LiveInterval *> &Intervals,
|
|
|
|
unsigned StartReg) const;
|
|
|
|
|
|
|
|
bool canAssign(unsigned StartReg, unsigned NumRegs) const;
|
|
|
|
|
|
|
|
bool scavengeRegs(SmallVectorImpl<LiveInterval *> &Intervals) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End anonymous namespace.
|
|
|
|
|
|
|
|
INITIALIZE_PASS_BEGIN(GCNNSAReassign, DEBUG_TYPE, "GCN NSA Reassign",
|
|
|
|
false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(LiveIntervals)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(VirtRegMap)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(LiveRegMatrix)
|
|
|
|
INITIALIZE_PASS_END(GCNNSAReassign, DEBUG_TYPE, "GCN NSA Reassign",
|
|
|
|
false, false)
|
|
|
|
|
|
|
|
|
|
|
|
char GCNNSAReassign::ID = 0;
|
|
|
|
|
|
|
|
char &llvm::GCNNSAReassignID = GCNNSAReassign::ID;
|
|
|
|
|
|
|
|
bool
|
|
|
|
GCNNSAReassign::tryAssignRegisters(SmallVectorImpl<LiveInterval *> &Intervals,
|
|
|
|
unsigned StartReg) const {
|
|
|
|
unsigned NumRegs = Intervals.size();
|
|
|
|
|
|
|
|
for (unsigned N = 0; N < NumRegs; ++N)
|
2020-09-16 05:54:38 +08:00
|
|
|
if (VRM->hasPhys(Intervals[N]->reg()))
|
2019-05-02 00:40:49 +08:00
|
|
|
LRM->unassign(*Intervals[N]);
|
|
|
|
|
|
|
|
for (unsigned N = 0; N < NumRegs; ++N)
|
2020-10-10 01:04:29 +08:00
|
|
|
if (LRM->checkInterference(*Intervals[N], MCRegister::from(StartReg + N)))
|
2019-05-02 00:40:49 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
for (unsigned N = 0; N < NumRegs; ++N)
|
2020-10-10 01:04:29 +08:00
|
|
|
LRM->assign(*Intervals[N], MCRegister::from(StartReg + N));
|
2019-05-02 00:40:49 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GCNNSAReassign::canAssign(unsigned StartReg, unsigned NumRegs) const {
|
|
|
|
for (unsigned N = 0; N < NumRegs; ++N) {
|
|
|
|
unsigned Reg = StartReg + N;
|
|
|
|
if (!MRI->isAllocatable(Reg))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (unsigned I = 0; CSRegs[I]; ++I)
|
|
|
|
if (TRI->isSubRegisterEq(Reg, CSRegs[I]) &&
|
|
|
|
!LRM->isPhysRegUsed(CSRegs[I]))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GCNNSAReassign::scavengeRegs(SmallVectorImpl<LiveInterval *> &Intervals) const {
|
|
|
|
unsigned NumRegs = Intervals.size();
|
|
|
|
|
|
|
|
if (NumRegs > MaxNumVGPRs)
|
|
|
|
return false;
|
|
|
|
unsigned MaxReg = MaxNumVGPRs - NumRegs + AMDGPU::VGPR0;
|
|
|
|
|
|
|
|
for (unsigned Reg = AMDGPU::VGPR0; Reg <= MaxReg; ++Reg) {
|
|
|
|
if (!canAssign(Reg, NumRegs))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (tryAssignRegisters(Intervals, Reg))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GCNNSAReassign::NSA_Status
|
|
|
|
GCNNSAReassign::CheckNSA(const MachineInstr &MI, bool Fast) const {
|
|
|
|
const AMDGPU::MIMGInfo *Info = AMDGPU::getMIMGInfo(MI.getOpcode());
|
|
|
|
if (!Info || Info->MIMGEncoding != AMDGPU::MIMGEncGfx10NSA)
|
|
|
|
return NSA_Status::NOT_NSA;
|
|
|
|
|
|
|
|
int VAddr0Idx =
|
|
|
|
AMDGPU::getNamedOperandIdx(MI.getOpcode(), AMDGPU::OpName::vaddr0);
|
|
|
|
|
|
|
|
unsigned VgprBase = 0;
|
|
|
|
bool NSA = false;
|
|
|
|
for (unsigned I = 0; I < Info->VAddrDwords; ++I) {
|
|
|
|
const MachineOperand &Op = MI.getOperand(VAddr0Idx + I);
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register Reg = Op.getReg();
|
2020-08-21 00:46:16 +08:00
|
|
|
if (Reg.isPhysical() || !VRM->isAssignedReg(Reg))
|
2019-05-02 00:40:49 +08:00
|
|
|
return NSA_Status::FIXED;
|
|
|
|
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register PhysReg = VRM->getPhys(Reg);
|
2019-05-02 00:40:49 +08:00
|
|
|
|
|
|
|
if (!Fast) {
|
|
|
|
if (!PhysReg)
|
|
|
|
return NSA_Status::FIXED;
|
|
|
|
|
|
|
|
// Bail if address is not a VGPR32. That should be possible to extend the
|
|
|
|
// optimization to work with subregs of a wider register tuples, but the
|
|
|
|
// logic to find free registers will be much more complicated with much
|
|
|
|
// less chances for success. That seems reasonable to assume that in most
|
|
|
|
// cases a tuple is used because a vector variable contains different
|
|
|
|
// parts of an address and it is either already consequitive or cannot
|
|
|
|
// be reassigned if not. If needed it is better to rely on register
|
|
|
|
// coalescer to process such address tuples.
|
|
|
|
if (MRI->getRegClass(Reg) != &AMDGPU::VGPR_32RegClass || Op.getSubReg())
|
|
|
|
return NSA_Status::FIXED;
|
2021-01-28 05:02:43 +08:00
|
|
|
|
|
|
|
// InlineSpiller does not call LRM::assign() after an LI split leaving
|
|
|
|
// it in an inconsistent state, so we cannot call LRM::unassign().
|
|
|
|
// See llvm bug #48911.
|
|
|
|
// Skip reassign if a register has originated from such split.
|
|
|
|
// FIXME: Remove the workaround when bug #48911 is fixed.
|
|
|
|
if (VRM->getPreSplitReg(Reg))
|
|
|
|
return NSA_Status::FIXED;
|
2019-05-02 00:40:49 +08:00
|
|
|
|
|
|
|
const MachineInstr *Def = MRI->getUniqueVRegDef(Reg);
|
|
|
|
|
|
|
|
if (Def && Def->isCopy() && Def->getOperand(1).getReg() == PhysReg)
|
|
|
|
return NSA_Status::FIXED;
|
|
|
|
|
|
|
|
for (auto U : MRI->use_nodbg_operands(Reg)) {
|
|
|
|
if (U.isImplicit())
|
|
|
|
return NSA_Status::FIXED;
|
|
|
|
const MachineInstr *UseInst = U.getParent();
|
|
|
|
if (UseInst->isCopy() && UseInst->getOperand(0).getReg() == PhysReg)
|
|
|
|
return NSA_Status::FIXED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LIS->hasInterval(Reg))
|
|
|
|
return NSA_Status::FIXED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (I == 0)
|
|
|
|
VgprBase = PhysReg;
|
|
|
|
else if (VgprBase + I != PhysReg)
|
|
|
|
NSA = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSA ? NSA_Status::NON_CONTIGUOUS : NSA_Status::CONTIGUOUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GCNNSAReassign::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
ST = &MF.getSubtarget<GCNSubtarget>();
|
|
|
|
if (ST->getGeneration() < GCNSubtarget::GFX10)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MRI = &MF.getRegInfo();
|
|
|
|
TRI = ST->getRegisterInfo();
|
|
|
|
VRM = &getAnalysis<VirtRegMap>();
|
|
|
|
LRM = &getAnalysis<LiveRegMatrix>();
|
|
|
|
LIS = &getAnalysis<LiveIntervals>();
|
|
|
|
|
|
|
|
const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
|
|
|
|
MaxNumVGPRs = ST->getMaxNumVGPRs(MF);
|
|
|
|
MaxNumVGPRs = std::min(ST->getMaxNumVGPRs(MFI->getOccupancy()), MaxNumVGPRs);
|
2019-06-26 21:39:29 +08:00
|
|
|
CSRegs = MRI->getCalleeSavedRegs();
|
2019-05-02 00:40:49 +08:00
|
|
|
|
|
|
|
using Candidate = std::pair<const MachineInstr*, bool>;
|
|
|
|
SmallVector<Candidate, 32> Candidates;
|
|
|
|
for (const MachineBasicBlock &MBB : MF) {
|
|
|
|
for (const MachineInstr &MI : MBB) {
|
|
|
|
switch (CheckNSA(MI)) {
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
case NSA_Status::CONTIGUOUS:
|
|
|
|
Candidates.push_back(std::make_pair(&MI, true));
|
|
|
|
break;
|
|
|
|
case NSA_Status::NON_CONTIGUOUS:
|
|
|
|
Candidates.push_back(std::make_pair(&MI, false));
|
|
|
|
++NumNSAInstructions;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Changed = false;
|
|
|
|
for (auto &C : Candidates) {
|
|
|
|
if (C.second)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const MachineInstr *MI = C.first;
|
|
|
|
if (CheckNSA(*MI, true) == NSA_Status::CONTIGUOUS) {
|
|
|
|
// Already happen to be fixed.
|
|
|
|
C.second = true;
|
|
|
|
++NumNSAConverted;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const AMDGPU::MIMGInfo *Info = AMDGPU::getMIMGInfo(MI->getOpcode());
|
|
|
|
int VAddr0Idx =
|
|
|
|
AMDGPU::getNamedOperandIdx(MI->getOpcode(), AMDGPU::OpName::vaddr0);
|
|
|
|
|
|
|
|
SmallVector<LiveInterval *, 16> Intervals;
|
2020-10-10 01:04:29 +08:00
|
|
|
SmallVector<MCRegister, 16> OrigRegs;
|
2019-05-02 00:40:49 +08:00
|
|
|
SlotIndex MinInd, MaxInd;
|
|
|
|
for (unsigned I = 0; I < Info->VAddrDwords; ++I) {
|
|
|
|
const MachineOperand &Op = MI->getOperand(VAddr0Idx + I);
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register Reg = Op.getReg();
|
2019-05-02 00:40:49 +08:00
|
|
|
LiveInterval *LI = &LIS->getInterval(Reg);
|
2020-12-05 13:42:54 +08:00
|
|
|
if (llvm::is_contained(Intervals, LI)) {
|
2019-05-02 00:40:49 +08:00
|
|
|
// Same register used, unable to make sequential
|
|
|
|
Intervals.clear();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Intervals.push_back(LI);
|
|
|
|
OrigRegs.push_back(VRM->getPhys(Reg));
|
AMDGPU/GFX10: Fix NSA reassign pass when operands are undef
Summary:
Virtual registers that are undef have an empty LiveInterval at this
point, which means beginIndex() and endIndex() cannot be used. We
only need those indices to determine the range in which to scan for
affected other NSA instructions, and undef operands cannot contribute
to that range.
Reviewers: arsenm, rampitec, mareko
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73831
2020-02-01 22:12:24 +08:00
|
|
|
if (LI->empty()) {
|
|
|
|
// The address input is undef, so it doesn't contribute to the relevant
|
|
|
|
// range. Seed a reasonable index range if required.
|
|
|
|
if (I == 0)
|
|
|
|
MinInd = MaxInd = LIS->getInstructionIndex(*MI);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MinInd = I != 0 ? std::min(MinInd, LI->beginIndex()) : LI->beginIndex();
|
|
|
|
MaxInd = I != 0 ? std::max(MaxInd, LI->endIndex()) : LI->endIndex();
|
2019-05-02 00:40:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Intervals.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LLVM_DEBUG(dbgs() << "Attempting to reassign NSA: " << *MI
|
|
|
|
<< "\tOriginal allocation:\t";
|
2020-09-16 05:54:38 +08:00
|
|
|
for (auto *LI
|
|
|
|
: Intervals) dbgs()
|
|
|
|
<< " " << llvm::printReg((VRM->getPhys(LI->reg())), TRI);
|
2019-05-02 00:40:49 +08:00
|
|
|
dbgs() << '\n');
|
|
|
|
|
|
|
|
bool Success = scavengeRegs(Intervals);
|
|
|
|
if (!Success) {
|
|
|
|
LLVM_DEBUG(dbgs() << "\tCannot reallocate.\n");
|
2020-09-16 05:54:38 +08:00
|
|
|
if (VRM->hasPhys(Intervals.back()->reg())) // Did not change allocation.
|
2019-05-02 00:40:49 +08:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// Check we did not make it worse for other instructions.
|
|
|
|
auto I = std::lower_bound(Candidates.begin(), &C, MinInd,
|
|
|
|
[this](const Candidate &C, SlotIndex I) {
|
|
|
|
return LIS->getInstructionIndex(*C.first) < I;
|
|
|
|
});
|
|
|
|
for (auto E = Candidates.end(); Success && I != E &&
|
|
|
|
LIS->getInstructionIndex(*I->first) < MaxInd; ++I) {
|
|
|
|
if (I->second && CheckNSA(*I->first, true) < NSA_Status::CONTIGUOUS) {
|
|
|
|
Success = false;
|
|
|
|
LLVM_DEBUG(dbgs() << "\tNSA conversion conflict with " << *I->first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Success) {
|
|
|
|
for (unsigned I = 0; I < Info->VAddrDwords; ++I)
|
2020-09-16 05:54:38 +08:00
|
|
|
if (VRM->hasPhys(Intervals[I]->reg()))
|
2019-05-02 00:40:49 +08:00
|
|
|
LRM->unassign(*Intervals[I]);
|
|
|
|
|
|
|
|
for (unsigned I = 0; I < Info->VAddrDwords; ++I)
|
|
|
|
LRM->assign(*Intervals[I], OrigRegs[I]);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
C.second = true;
|
|
|
|
++NumNSAConverted;
|
2020-09-16 05:54:38 +08:00
|
|
|
LLVM_DEBUG(
|
|
|
|
dbgs() << "\tNew allocation:\t\t ["
|
|
|
|
<< llvm::printReg((VRM->getPhys(Intervals.front()->reg())), TRI)
|
|
|
|
<< " : "
|
|
|
|
<< llvm::printReg((VRM->getPhys(Intervals.back()->reg())), TRI)
|
|
|
|
<< "]\n");
|
2019-05-02 00:40:49 +08:00
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|