26#define DEBUG_TYPE "amdgpu-pre-ra-long-branch-reg"
32 cl::desc(
"Factor to apply to what qualifies as a long branch "
33 "to reserve a pair of scalar registers. If this value "
34 "is 0 the long branch registers are never reserved. As this "
35 "value grows the greater chance the branch distance will fall "
36 "within the threshold and the registers will be marked to be "
37 "reserved. We lean towards always reserving a register for "
40class GCNPreRALongBranchReg {
53 GCNPreRALongBranchReg() =
default;
65 return GCNPreRALongBranchReg().run(MF);
69 return "AMDGPU Pre-RA Long Branch Reg";
79char GCNPreRALongBranchRegLegacy::ID = 0;
82 "AMDGPU Pre-RA Long Branch Reg",
false,
false)
85void GCNPreRALongBranchReg::generateBlockInfo(
88 BlockInfo.resize(MF.getNumBlockIDs());
98 if (
MI.isMetaInstruction())
103 BlockInfo[
MBB.getNumber()].Size = 8 * NumInstr;
105 uint64_t PrevNum = (&MF)->begin()->getNumber();
111 BlockInfo[Num].Offset = BlockInfo[PrevNum].Offset + BlockInfo[PrevNum].Size;
117 const GCNSubtarget &STM = MF.
getSubtarget<GCNSubtarget>();
120 SIMachineFunctionInfo *MFI = MF.
getInfo<SIMachineFunctionInfo>();
127 constexpr bool ReserveHighestRegister =
true;
128 Register LongBranchReservedReg =
TRI->findUnusedRegister(
129 MRI, &AMDGPU::SGPR_64RegClass, MF, ReserveHighestRegister);
130 if (!LongBranchReservedReg)
135 generateBlockInfo(MF, BlockInfo);
137 for (
const MachineBasicBlock &
MBB : MF) {
141 MachineBasicBlock *DestBB =
TII->getBranchDestBlock(*
Last);
142 uint64_t BlockDistance =
static_cast<uint64_t
>(
146 if (!
TII->isBranchOffsetInRange(
Last->getOpcode(), BlockDistance)) {
157 GCNPreRALongBranchReg().run(MF);
unsigned const MachineRegisterInfo * MRI
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
AMD GCN specific subclass of TargetSubtarget.
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
const SIInstrInfo * getInstrInfo() const override
const SIRegisterInfo * getRegisterInfo() const override
MachineInstrBundleIterator< const MachineInstr > const_iterator
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
LLVM_ABI iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
BasicBlockListType::iterator iterator
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Representation of each machine instruction.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void setLongBranchReservedReg(Register Reg)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
LLVM_ABI iterator begin() const
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
void initializeGCNPreRALongBranchRegLegacyPass(PassRegistry &)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
char & GCNPreRALongBranchRegID
BasicBlockInfo - Information about the offset and size of a single basic block.