LLVM: lib/Target/AMDGPU/GCNPreRALongBranchReg.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

23

24using namespace llvm;

25

26#define DEBUG_TYPE "amdgpu-pre-ra-long-branch-reg"

27

28namespace {

29

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 "

38 "long jumps"));

39

40class GCNPreRALongBranchReg {

41

43

44

46

48 };

51

52public:

53 GCNPreRALongBranchReg() = default;

55};

56

58public:

59 static char ID;

62 }

63

65 return GCNPreRALongBranchReg().run(MF);

66 }

67

68 StringRef getPassName() const override {

69 return "AMDGPU Pre-RA Long Branch Reg";

70 }

71

72 void getAnalysisUsage(AnalysisUsage &AU) const override {

75 }

76};

77}

78

79char GCNPreRALongBranchRegLegacy::ID = 0;

80

82 "AMDGPU Pre-RA Long Branch Reg", false, false)

83

85void GCNPreRALongBranchReg::generateBlockInfo(

87

88 BlockInfo.resize(MF.getNumBlockIDs());

89

90

91

94

95

97

98 if (MI.isMetaInstruction())

99 continue;

100 NumInstr += 1;

101 }

102

103 BlockInfo[MBB.getNumber()].Size = 8 * NumInstr;

104 }

105 uint64_t PrevNum = (&MF)->begin()->getNumber();

106 for (auto &MBB :

108 (&MF)->end())) {

110

111 BlockInfo[Num].Offset = BlockInfo[PrevNum].Offset + BlockInfo[PrevNum].Size;

112 PrevNum = Num;

113 }

114}

115

117 const GCNSubtarget &STM = MF.getSubtarget();

120 SIMachineFunctionInfo *MFI = MF.getInfo();

122

123

124

125

126

127 constexpr bool ReserveHighestRegister = true;

128 Register LongBranchReservedReg = TRI->findUnusedRegister(

129 MRI, &AMDGPU::SGPR_64RegClass, MF, ReserveHighestRegister);

130 if (!LongBranchReservedReg)

131 return false;

132

133

135 generateBlockInfo(MF, BlockInfo);

136

137 for (const MachineBasicBlock &MBB : MF) {

139 if (Last == MBB.end() || Last->isUnconditionalBranch())

140 continue;

142 uint64_t BlockDistance = static_cast<uint64_t>(

143 LongBranchFactor * BlockInfo[DestBB->getNumber()].Offset);

144

145

148 return true;

149 }

150 }

151 return false;

152}

153

154PreservedAnalyses

157 GCNPreRALongBranchReg().run(MF);

159}

unsigned const MachineRegisterInfo * MRI

for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))

const TargetInstrInfo & TII

AMD GCN specific subclass of TargetSubtarget.

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)

Definition GCNPreRALongBranchReg.cpp:155

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.

virtual bool isBranchOffsetInRange(unsigned BranchOpc, int64_t BrOffset) const

virtual MachineBasicBlock * getBranchDestBlock(const MachineInstr &MI) const

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.