2018-05-31 20:13:51 +00:00
|
|
|
//===-- SIFormMemoryClauses.cpp -------------------------------------------===//
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// 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
|
2018-05-31 20:13:51 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
/// This pass creates bundles of SMEM and VMEM instructions forming memory
|
|
|
|
/// clauses if XNACK is enabled. Def operands of clauses are marked as early
|
|
|
|
/// clobber to make sure we will not override any source within a clause.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPU.h"
|
|
|
|
#include "GCNRegPressure.h"
|
|
|
|
#include "SIMachineFunctionInfo.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-13 13:15:01 -08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2018-05-31 20:13:51 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "si-form-memory-clauses"
|
|
|
|
|
|
|
|
// Clauses longer then 15 instructions would overflow one of the counters
|
|
|
|
// and stall. They can stall even earlier if there are outstanding counters.
|
|
|
|
static cl::opt<unsigned>
|
|
|
|
MaxClause("amdgpu-max-memory-clause", cl::Hidden, cl::init(15),
|
|
|
|
cl::desc("Maximum length of a memory clause, instructions"));
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class SIFormMemoryClauses : public MachineFunctionPass {
|
|
|
|
typedef DenseMap<unsigned, std::pair<unsigned, LaneBitmask>> RegUse;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SIFormMemoryClauses() : MachineFunctionPass(ID) {
|
|
|
|
initializeSIFormMemoryClausesPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
|
|
|
|
StringRef getPassName() const override {
|
|
|
|
return "SI Form memory clauses";
|
|
|
|
}
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.addRequired<LiveIntervals>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
2021-01-18 10:49:48 -05:00
|
|
|
MachineFunctionProperties getClearedProperties() const override {
|
|
|
|
return MachineFunctionProperties().set(
|
|
|
|
MachineFunctionProperties::Property::IsSSA);
|
|
|
|
}
|
|
|
|
|
2018-05-31 20:13:51 +00:00
|
|
|
private:
|
|
|
|
template <typename Callable>
|
2020-08-20 17:46:16 +01:00
|
|
|
void forAllLanes(Register Reg, LaneBitmask LaneMask, Callable Func) const;
|
2018-05-31 20:13:51 +00:00
|
|
|
|
2021-01-28 15:40:38 -05:00
|
|
|
bool canBundle(const MachineInstr &MI, const RegUse &Defs,
|
|
|
|
const RegUse &Uses) const;
|
2021-02-03 13:19:09 -05:00
|
|
|
bool checkPressure(const MachineInstr &MI, GCNDownwardRPTracker &RPT);
|
2018-05-31 20:13:51 +00:00
|
|
|
void collectRegUses(const MachineInstr &MI, RegUse &Defs, RegUse &Uses) const;
|
|
|
|
bool processRegUses(const MachineInstr &MI, RegUse &Defs, RegUse &Uses,
|
2021-02-03 13:19:09 -05:00
|
|
|
GCNDownwardRPTracker &RPT);
|
2018-05-31 20:13:51 +00:00
|
|
|
|
2018-07-11 20:59:01 +00:00
|
|
|
const GCNSubtarget *ST;
|
2018-05-31 20:13:51 +00:00
|
|
|
const SIRegisterInfo *TRI;
|
|
|
|
const MachineRegisterInfo *MRI;
|
|
|
|
SIMachineFunctionInfo *MFI;
|
|
|
|
|
|
|
|
unsigned LastRecordedOccupancy;
|
|
|
|
unsigned MaxVGPRs;
|
|
|
|
unsigned MaxSGPRs;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End anonymous namespace.
|
|
|
|
|
|
|
|
INITIALIZE_PASS_BEGIN(SIFormMemoryClauses, DEBUG_TYPE,
|
|
|
|
"SI Form memory clauses", false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(LiveIntervals)
|
|
|
|
INITIALIZE_PASS_END(SIFormMemoryClauses, DEBUG_TYPE,
|
|
|
|
"SI Form memory clauses", false, false)
|
|
|
|
|
|
|
|
|
|
|
|
char SIFormMemoryClauses::ID = 0;
|
|
|
|
|
|
|
|
char &llvm::SIFormMemoryClausesID = SIFormMemoryClauses::ID;
|
|
|
|
|
|
|
|
FunctionPass *llvm::createSIFormMemoryClausesPass() {
|
|
|
|
return new SIFormMemoryClauses();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isVMEMClauseInst(const MachineInstr &MI) {
|
|
|
|
return SIInstrInfo::isFLAT(MI) || SIInstrInfo::isVMEM(MI);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isSMEMClauseInst(const MachineInstr &MI) {
|
|
|
|
return SIInstrInfo::isSMRD(MI);
|
|
|
|
}
|
|
|
|
|
|
|
|
// There no sense to create store clauses, they do not define anything,
|
|
|
|
// thus there is nothing to set early-clobber.
|
|
|
|
static bool isValidClauseInst(const MachineInstr &MI, bool IsVMEMClause) {
|
2021-01-30 17:10:51 -05:00
|
|
|
assert(!MI.isDebugInstr() && "debug instructions should not reach here");
|
|
|
|
if (MI.isBundled())
|
2018-05-31 20:13:51 +00:00
|
|
|
return false;
|
|
|
|
if (!MI.mayLoad() || MI.mayStore())
|
|
|
|
return false;
|
2021-02-12 14:19:10 -08:00
|
|
|
if (SIInstrInfo::isAtomic(MI))
|
2018-05-31 20:13:51 +00:00
|
|
|
return false;
|
|
|
|
if (IsVMEMClause && !isVMEMClauseInst(MI))
|
|
|
|
return false;
|
|
|
|
if (!IsVMEMClause && !isSMEMClauseInst(MI))
|
|
|
|
return false;
|
2019-01-23 13:38:06 +00:00
|
|
|
// If this is a load instruction where the result has been coalesced with an operand, then we cannot clause it.
|
|
|
|
for (const MachineOperand &ResMO : MI.defs()) {
|
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-15 19:22:08 +00:00
|
|
|
Register ResReg = ResMO.getReg();
|
2019-01-23 13:38:06 +00:00
|
|
|
for (const MachineOperand &MO : MI.uses()) {
|
|
|
|
if (!MO.isReg() || MO.isDef())
|
|
|
|
continue;
|
|
|
|
if (MO.getReg() == ResReg)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break; // Only check the first def.
|
|
|
|
}
|
2018-05-31 20:13:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned getMopState(const MachineOperand &MO) {
|
|
|
|
unsigned S = 0;
|
|
|
|
if (MO.isImplicit())
|
|
|
|
S |= RegState::Implicit;
|
|
|
|
if (MO.isDead())
|
|
|
|
S |= RegState::Dead;
|
|
|
|
if (MO.isUndef())
|
|
|
|
S |= RegState::Undef;
|
|
|
|
if (MO.isKill())
|
|
|
|
S |= RegState::Kill;
|
|
|
|
if (MO.isEarlyClobber())
|
|
|
|
S |= RegState::EarlyClobber;
|
2020-08-20 17:46:16 +01:00
|
|
|
if (MO.getReg().isPhysical() && MO.isRenamable())
|
2018-05-31 20:13:51 +00:00
|
|
|
S |= RegState::Renamable;
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Callable>
|
2020-08-20 17:46:16 +01:00
|
|
|
void SIFormMemoryClauses::forAllLanes(Register Reg, LaneBitmask LaneMask,
|
2018-05-31 20:13:51 +00:00
|
|
|
Callable Func) const {
|
2020-08-20 17:46:16 +01:00
|
|
|
if (LaneMask.all() || Reg.isPhysical() ||
|
2018-05-31 20:13:51 +00:00
|
|
|
LaneMask == MRI->getMaxLaneMaskForVReg(Reg)) {
|
|
|
|
Func(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TargetRegisterClass *RC = MRI->getRegClass(Reg);
|
|
|
|
unsigned E = TRI->getNumSubRegIndices();
|
|
|
|
SmallVector<unsigned, AMDGPU::NUM_TARGET_SUBREGS> CoveringSubregs;
|
|
|
|
for (unsigned Idx = 1; Idx < E; ++Idx) {
|
|
|
|
// Is this index even compatible with the given class?
|
|
|
|
if (TRI->getSubClassWithSubReg(RC, Idx) != RC)
|
|
|
|
continue;
|
|
|
|
LaneBitmask SubRegMask = TRI->getSubRegIndexLaneMask(Idx);
|
|
|
|
// Early exit if we found a perfect match.
|
|
|
|
if (SubRegMask == LaneMask) {
|
|
|
|
Func(Idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((SubRegMask & ~LaneMask).any() || (SubRegMask & LaneMask).none())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CoveringSubregs.push_back(Idx);
|
|
|
|
}
|
|
|
|
|
llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.
Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb
Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits
Differential Revision: https://reviews.llvm.org/D52573
llvm-svn: 343163
2018-09-27 02:13:45 +00:00
|
|
|
llvm::sort(CoveringSubregs, [this](unsigned A, unsigned B) {
|
|
|
|
LaneBitmask MaskA = TRI->getSubRegIndexLaneMask(A);
|
|
|
|
LaneBitmask MaskB = TRI->getSubRegIndexLaneMask(B);
|
|
|
|
unsigned NA = MaskA.getNumLanes();
|
|
|
|
unsigned NB = MaskB.getNumLanes();
|
|
|
|
if (NA != NB)
|
|
|
|
return NA > NB;
|
|
|
|
return MaskA.getHighestLane() > MaskB.getHighestLane();
|
|
|
|
});
|
2018-05-31 20:13:51 +00:00
|
|
|
|
2021-02-17 13:37:46 -08:00
|
|
|
MCRegister RepReg;
|
|
|
|
for (MCRegister R : *MRI->getRegClass(Reg)) {
|
|
|
|
if (!MRI->isReserved(R)) {
|
|
|
|
RepReg = R;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!RepReg)
|
|
|
|
llvm_unreachable("Failed to find required allocatable register");
|
|
|
|
|
2018-05-31 20:13:51 +00:00
|
|
|
for (unsigned Idx : CoveringSubregs) {
|
|
|
|
LaneBitmask SubRegMask = TRI->getSubRegIndexLaneMask(Idx);
|
|
|
|
if ((SubRegMask & ~LaneMask).any() || (SubRegMask & LaneMask).none())
|
|
|
|
continue;
|
|
|
|
|
2021-02-17 13:37:46 -08:00
|
|
|
if (MRI->isReserved(TRI->getSubReg(RepReg, Idx)))
|
|
|
|
continue;
|
|
|
|
|
2018-05-31 20:13:51 +00:00
|
|
|
Func(Idx);
|
|
|
|
LaneMask &= ~SubRegMask;
|
|
|
|
if (LaneMask.none())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Failed to find all subregs to cover lane mask");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns false if there is a use of a def already in the map.
|
|
|
|
// In this case we must break the clause.
|
2021-01-28 15:40:38 -05:00
|
|
|
bool SIFormMemoryClauses::canBundle(const MachineInstr &MI, const RegUse &Defs,
|
|
|
|
const RegUse &Uses) const {
|
2018-05-31 20:13:51 +00:00
|
|
|
// Check interference with defs.
|
|
|
|
for (const MachineOperand &MO : MI.operands()) {
|
|
|
|
// TODO: Prologue/Epilogue Insertion pass does not process bundled
|
|
|
|
// instructions.
|
|
|
|
if (MO.isFI())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!MO.isReg())
|
|
|
|
continue;
|
|
|
|
|
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-15 19:22:08 +00:00
|
|
|
Register Reg = MO.getReg();
|
2018-05-31 20:13:51 +00:00
|
|
|
|
|
|
|
// If it is tied we will need to write same register as we read.
|
|
|
|
if (MO.isTied())
|
|
|
|
return false;
|
|
|
|
|
2021-01-28 15:40:38 -05:00
|
|
|
const RegUse &Map = MO.isDef() ? Uses : Defs;
|
2018-05-31 20:13:51 +00:00
|
|
|
auto Conflict = Map.find(Reg);
|
|
|
|
if (Conflict == Map.end())
|
|
|
|
continue;
|
|
|
|
|
2020-08-20 17:46:16 +01:00
|
|
|
if (Reg.isPhysical())
|
2018-05-31 20:13:51 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
LaneBitmask Mask = TRI->getSubRegIndexLaneMask(MO.getSubReg());
|
|
|
|
if ((Conflict->second.second & Mask).any())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since all defs in the clause are early clobber we can run out of registers.
|
|
|
|
// Function returns false if pressure would hit the limit if instruction is
|
|
|
|
// bundled into a memory clause.
|
|
|
|
bool SIFormMemoryClauses::checkPressure(const MachineInstr &MI,
|
2021-02-03 13:19:09 -05:00
|
|
|
GCNDownwardRPTracker &RPT) {
|
2018-05-31 20:13:51 +00:00
|
|
|
// NB: skip advanceBeforeNext() call. Since all defs will be marked
|
|
|
|
// early-clobber they will all stay alive at least to the end of the
|
2021-02-03 13:19:09 -05:00
|
|
|
// clause. Therefor we should not decrease pressure even if load
|
|
|
|
// pointer becomes dead and could otherwise be reused for destination.
|
2018-05-31 20:13:51 +00:00
|
|
|
RPT.advanceToNext();
|
2021-02-03 13:19:09 -05:00
|
|
|
GCNRegPressure MaxPressure = RPT.moveMaxPressure();
|
|
|
|
unsigned Occupancy = MaxPressure.getOccupancy(*ST);
|
2021-01-14 10:30:55 -05:00
|
|
|
|
|
|
|
// Don't push over half the register budget. We don't want to introduce
|
|
|
|
// spilling just to form a soft clause.
|
|
|
|
//
|
|
|
|
// FIXME: This pressure check is fundamentally broken. First, this is checking
|
|
|
|
// the global pressure, not the pressure at this specific point in the
|
|
|
|
// program. Second, it's not accounting for the increased liveness of the use
|
|
|
|
// operands due to the early clobber we will introduce. Third, the pressure
|
|
|
|
// tracking does not account for the alignment requirements for SGPRs, or the
|
|
|
|
// fragmentation of registers the allocator will need to satisfy.
|
2021-02-03 13:19:09 -05:00
|
|
|
if (Occupancy >= MFI->getMinAllowedOccupancy() &&
|
2021-02-17 13:37:46 -08:00
|
|
|
MaxPressure.getVGPRNum(ST->hasGFX90AInsts()) <= MaxVGPRs / 2 &&
|
2021-01-14 10:30:55 -05:00
|
|
|
MaxPressure.getSGPRNum() <= MaxSGPRs / 2) {
|
2021-02-03 13:19:09 -05:00
|
|
|
LastRecordedOccupancy = Occupancy;
|
|
|
|
return true;
|
2018-05-31 20:13:51 +00:00
|
|
|
}
|
2021-02-03 13:19:09 -05:00
|
|
|
return false;
|
2018-05-31 20:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collect register defs and uses along with their lane masks and states.
|
|
|
|
void SIFormMemoryClauses::collectRegUses(const MachineInstr &MI,
|
|
|
|
RegUse &Defs, RegUse &Uses) const {
|
|
|
|
for (const MachineOperand &MO : MI.operands()) {
|
|
|
|
if (!MO.isReg())
|
|
|
|
continue;
|
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-15 19:22:08 +00:00
|
|
|
Register Reg = MO.getReg();
|
2018-05-31 20:13:51 +00:00
|
|
|
if (!Reg)
|
|
|
|
continue;
|
|
|
|
|
2020-08-20 17:46:16 +01:00
|
|
|
LaneBitmask Mask = Reg.isVirtual()
|
2019-08-01 23:27:28 +00:00
|
|
|
? TRI->getSubRegIndexLaneMask(MO.getSubReg())
|
|
|
|
: LaneBitmask::getAll();
|
2018-05-31 20:13:51 +00:00
|
|
|
RegUse &Map = MO.isDef() ? Defs : Uses;
|
|
|
|
|
|
|
|
auto Loc = Map.find(Reg);
|
|
|
|
unsigned State = getMopState(MO);
|
|
|
|
if (Loc == Map.end()) {
|
|
|
|
Map[Reg] = std::make_pair(State, Mask);
|
|
|
|
} else {
|
|
|
|
Loc->second.first |= State;
|
|
|
|
Loc->second.second |= Mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check register def/use conflicts, occupancy limits and collect def/use maps.
|
|
|
|
// Return true if instruction can be bundled with previous. It it cannot
|
|
|
|
// def/use maps are not updated.
|
2021-02-03 13:19:09 -05:00
|
|
|
bool SIFormMemoryClauses::processRegUses(const MachineInstr &MI,
|
|
|
|
RegUse &Defs, RegUse &Uses,
|
|
|
|
GCNDownwardRPTracker &RPT) {
|
2018-05-31 20:13:51 +00:00
|
|
|
if (!canBundle(MI, Defs, Uses))
|
|
|
|
return false;
|
|
|
|
|
2021-02-03 13:19:09 -05:00
|
|
|
if (!checkPressure(MI, RPT))
|
2018-05-31 20:13:51 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
collectRegUses(MI, Defs, Uses);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SIFormMemoryClauses::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
if (skipFunction(MF.getFunction()))
|
|
|
|
return false;
|
|
|
|
|
2018-07-11 20:59:01 +00:00
|
|
|
ST = &MF.getSubtarget<GCNSubtarget>();
|
2018-05-31 20:13:51 +00:00
|
|
|
if (!ST->isXNACKEnabled())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const SIInstrInfo *TII = ST->getInstrInfo();
|
|
|
|
TRI = ST->getRegisterInfo();
|
|
|
|
MRI = &MF.getRegInfo();
|
|
|
|
MFI = MF.getInfo<SIMachineFunctionInfo>();
|
|
|
|
LiveIntervals *LIS = &getAnalysis<LiveIntervals>();
|
|
|
|
SlotIndexes *Ind = LIS->getSlotIndexes();
|
|
|
|
bool Changed = false;
|
|
|
|
|
|
|
|
MaxVGPRs = TRI->getAllocatableSet(MF, &AMDGPU::VGPR_32RegClass).count();
|
|
|
|
MaxSGPRs = TRI->getAllocatableSet(MF, &AMDGPU::SGPR_32RegClass).count();
|
2019-05-30 18:46:34 +00:00
|
|
|
unsigned FuncMaxClause = AMDGPU::getIntegerAttribute(
|
|
|
|
MF.getFunction(), "amdgpu-max-memory-clause", MaxClause);
|
2018-05-31 20:13:51 +00:00
|
|
|
|
2021-01-30 17:10:51 -05:00
|
|
|
SmallVector<MachineInstr *> DbgInstrs;
|
|
|
|
|
2018-05-31 20:13:51 +00:00
|
|
|
for (MachineBasicBlock &MBB : MF) {
|
2021-01-25 16:08:08 -08:00
|
|
|
GCNDownwardRPTracker RPT(*LIS);
|
2018-05-31 20:13:51 +00:00
|
|
|
MachineBasicBlock::instr_iterator Next;
|
|
|
|
for (auto I = MBB.instr_begin(), E = MBB.instr_end(); I != E; I = Next) {
|
|
|
|
MachineInstr &MI = *I;
|
|
|
|
Next = std::next(I);
|
|
|
|
|
2021-01-30 17:10:51 -05:00
|
|
|
if (MI.isDebugInstr())
|
|
|
|
continue;
|
|
|
|
|
2018-05-31 20:13:51 +00:00
|
|
|
bool IsVMEM = isVMEMClauseInst(MI);
|
|
|
|
|
|
|
|
if (!isValidClauseInst(MI, IsVMEM))
|
|
|
|
continue;
|
|
|
|
|
2021-01-25 16:08:08 -08:00
|
|
|
if (!RPT.getNext().isValid())
|
|
|
|
RPT.reset(MI);
|
|
|
|
else { // Advance the state to the current MI.
|
|
|
|
RPT.advance(MachineBasicBlock::const_iterator(MI));
|
|
|
|
RPT.advanceBeforeNext();
|
|
|
|
}
|
2018-05-31 20:13:51 +00:00
|
|
|
|
2021-01-25 16:08:08 -08:00
|
|
|
const GCNRPTracker::LiveRegSet LiveRegsCopy(RPT.getLiveRegs());
|
|
|
|
RegUse Defs, Uses;
|
2021-02-03 13:19:09 -05:00
|
|
|
if (!processRegUses(MI, Defs, Uses, RPT)) {
|
2021-01-25 16:08:08 -08:00
|
|
|
RPT.reset(MI, &LiveRegsCopy);
|
2018-05-31 20:13:51 +00:00
|
|
|
continue;
|
2021-01-25 16:08:08 -08:00
|
|
|
}
|
2018-05-31 20:13:51 +00:00
|
|
|
|
|
|
|
unsigned Length = 1;
|
2019-05-30 18:46:34 +00:00
|
|
|
for ( ; Next != E && Length < FuncMaxClause; ++Next) {
|
2021-01-30 17:10:51 -05:00
|
|
|
// Debug instructions should not change the bundling. We need to move
|
|
|
|
// these after the bundle
|
|
|
|
if (Next->isDebugInstr())
|
|
|
|
continue;
|
|
|
|
|
2018-05-31 20:13:51 +00:00
|
|
|
if (!isValidClauseInst(*Next, IsVMEM))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// A load from pointer which was loaded inside the same bundle is an
|
|
|
|
// impossible clause because we will need to write and read the same
|
|
|
|
// register inside. In this case processRegUses will return false.
|
2021-02-03 13:19:09 -05:00
|
|
|
if (!processRegUses(*Next, Defs, Uses, RPT))
|
2018-05-31 20:13:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
++Length;
|
|
|
|
}
|
2021-01-25 16:08:08 -08:00
|
|
|
if (Length < 2) {
|
|
|
|
RPT.reset(MI, &LiveRegsCopy);
|
2018-05-31 20:13:51 +00:00
|
|
|
continue;
|
2021-01-25 16:08:08 -08:00
|
|
|
}
|
2018-05-31 20:13:51 +00:00
|
|
|
|
|
|
|
Changed = true;
|
|
|
|
MFI->limitOccupancy(LastRecordedOccupancy);
|
|
|
|
|
|
|
|
auto B = BuildMI(MBB, I, DebugLoc(), TII->get(TargetOpcode::BUNDLE));
|
|
|
|
Ind->insertMachineInstrInMaps(*B);
|
|
|
|
|
2021-01-25 16:08:08 -08:00
|
|
|
// Restore the state after processing the bundle.
|
|
|
|
RPT.reset(*B, &LiveRegsCopy);
|
2021-01-30 17:10:51 -05:00
|
|
|
DbgInstrs.clear();
|
|
|
|
|
|
|
|
auto BundleNext = I;
|
|
|
|
for (auto BI = I; BI != Next; BI = BundleNext) {
|
|
|
|
BundleNext = std::next(BI);
|
|
|
|
|
|
|
|
if (BI->isDebugValue()) {
|
|
|
|
DbgInstrs.push_back(BI->removeFromParent());
|
|
|
|
continue;
|
|
|
|
}
|
2021-01-25 16:08:08 -08:00
|
|
|
|
2018-05-31 20:13:51 +00:00
|
|
|
BI->bundleWithPred();
|
|
|
|
Ind->removeSingleMachineInstrFromMaps(*BI);
|
|
|
|
|
|
|
|
for (MachineOperand &MO : BI->defs())
|
|
|
|
if (MO.readsReg())
|
|
|
|
MO.setIsInternalRead(true);
|
|
|
|
}
|
|
|
|
|
2021-01-30 17:10:51 -05:00
|
|
|
// Replace any debug instructions after the new bundle.
|
|
|
|
for (MachineInstr *DbgInst : DbgInstrs)
|
|
|
|
MBB.insert(Next, DbgInst);
|
|
|
|
|
2018-05-31 20:13:51 +00:00
|
|
|
for (auto &&R : Defs) {
|
|
|
|
forAllLanes(R.first, R.second.second, [&R, &B](unsigned SubReg) {
|
|
|
|
unsigned S = R.second.first | RegState::EarlyClobber;
|
|
|
|
if (!SubReg)
|
|
|
|
S &= ~(RegState::Undef | RegState::Dead);
|
|
|
|
B.addDef(R.first, S, SubReg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &&R : Uses) {
|
|
|
|
forAllLanes(R.first, R.second.second, [&R, &B](unsigned SubReg) {
|
|
|
|
B.addUse(R.first, R.second.first & ~RegState::Kill, SubReg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &&R : Defs) {
|
2020-08-20 17:46:16 +01:00
|
|
|
Register Reg = R.first;
|
2018-05-31 20:13:51 +00:00
|
|
|
Uses.erase(Reg);
|
2020-08-20 17:46:16 +01:00
|
|
|
if (Reg.isPhysical())
|
2018-05-31 20:13:51 +00:00
|
|
|
continue;
|
|
|
|
LIS->removeInterval(Reg);
|
|
|
|
LIS->createAndComputeVirtRegInterval(Reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &&R : Uses) {
|
2020-08-20 17:46:16 +01:00
|
|
|
Register Reg = R.first;
|
|
|
|
if (Reg.isPhysical())
|
2018-05-31 20:13:51 +00:00
|
|
|
continue;
|
|
|
|
LIS->removeInterval(Reg);
|
|
|
|
LIS->createAndComputeVirtRegInterval(Reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|