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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

20

21using namespace llvm;

22

23#define DEBUG_TYPE "si-post-ra-bundler"

24

25namespace {

26

28public:

29 static char ID;

30

31public:

34 }

35

37

38 StringRef getPassName() const override {

39 return "SI post-RA bundler";

40 }

41

42 void getAnalysisUsage(AnalysisUsage &AU) const override {

45 }

46};

47

48class SIPostRABundler {

49public:

51

52private:

54

56

59

63};

64

69

70}

71

73 false)

74

75char SIPostRABundlerLegacy::ID = 0;

76

78

80 return new SIPostRABundlerLegacy();

81}

82

83bool SIPostRABundler::isDependentLoad(const MachineInstr &MI) const {

84 if (MI.mayLoad())

85 return false;

86

88 if (Op.isReg())

89 continue;

92 if (TRI->regsOverlap(Reg, Def))

93 return true;

94 }

95

96 return false;

97}

98

99void SIPostRABundler::collectUsedRegUnits(const MachineInstr &MI,

100 BitVector &UsedRegUnits) const {

101 if (MI.isDebugInstr())

102 return;

103

104 for (const MachineOperand &Op : MI.operands()) {

105 if (Op.isReg() || Op.readsReg())

106 continue;

107

110 "subregister indexes should not be present after RA");

111

112 for (MCRegUnit Unit : TRI->regunits(Reg))

113 UsedRegUnits.set(static_cast<unsigned>(Unit));

114 }

115}

116

117bool SIPostRABundler::isBundleCandidate(const MachineInstr &MI) const {

118 const uint64_t IMemFlags = MI.getDesc().TSFlags & MemFlags;

119 return IMemFlags != 0 && MI.mayLoadOrStore() && MI.isBundled();

120}

121

122bool SIPostRABundler::canBundle(const MachineInstr &MI,

123 const MachineInstr &NextMI) const {

124 const uint64_t IMemFlags = MI.getDesc().TSFlags & MemFlags;

125

126 return (IMemFlags != 0 && MI.mayLoadOrStore() && !NextMI.isBundled() &&

127 NextMI.mayLoad() == MI.mayLoad() && NextMI.mayStore() == MI.mayStore() &&

128 ((NextMI.getDesc().TSFlags & MemFlags) == IMemFlags) &&

129 !isDependentLoad(NextMI));

130}

131

132bool SIPostRABundlerLegacy::runOnMachineFunction(MachineFunction &MF) {

134 return false;

135 return SIPostRABundler().run(MF);

136}

137

140 SIPostRABundler().run(MF);

142}

143

145

147 BitVector BundleUsedRegUnits(TRI->getNumRegUnits());

148 BitVector KillUsedRegUnits(TRI->getNumRegUnits());

149

153 unsigned Opc = MI.getOpcode();

154 return Opc == AMDGPU::SCHED_GROUP_BARRIER || Opc == AMDGPU::IGLP_OPT;

155 });

156

157

158 if (HasIGLPInstrs)

159 continue;

160

164

165 for (auto I = B; I != E; I = Next) {

166 Next = std::next(I);

167 if (!isBundleCandidate(*I))

168 continue;

169

171

172 if (I->getNumExplicitDefs() != 0)

173 Defs.insert(I->defs().begin()->getReg());

174

177 unsigned ClauseLength = 1;

179 Next = std::next(I);

180

182 if (canBundle(*BundleEnd, *I)) {

183 BundleEnd = I;

184 if (I->getNumExplicitDefs() != 0)

185 Defs.insert(I->defs().begin()->getReg());

186 ++ClauseLength;

187 } else if (I->isMetaInstruction() ||

188 I->getOpcode() == AMDGPU::SCHED_BARRIER) {

189

190

191

192

193

194

195

196 break;

197 }

198 }

199

200 Next = std::next(BundleEnd);

201 if (ClauseLength > 1) {

203

204

205

206

207 if (Next != E && Next->isKill()) {

208

209

210 for (const MachineInstr &BundleMI : make_range(BundleStart, Next))

211 collectUsedRegUnits(BundleMI, BundleUsedRegUnits);

212

213 BundleUsedRegUnits.flip();

214

215 while (Next != E && Next->isKill()) {

217 collectUsedRegUnits(Kill, KillUsedRegUnits);

218

219 KillUsedRegUnits &= BundleUsedRegUnits;

220

221

222

223

224

225 if (KillUsedRegUnits.none()) {

227 Kill.eraseFromParent();

228 } else

229 break;

230

231 KillUsedRegUnits.reset();

232 }

233

234 BundleUsedRegUnits.reset();

235 }

236

238 }

239

241 }

242 }

243

245}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

AMD GCN specific subclass of TargetSubtarget.

Register const TargetRegisterInfo * TRI

Promote Memory to Register

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

This file defines the SmallSet class.

Represent the analysis usage information of a pass.

void setPreservesAll()

Set by analyses that do not transform their input at all.

FunctionPass class - This class is used to implement most global optimizations.

Instructions::iterator instr_iterator

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.

Function & getFunction()

Return the LLVM function that this machine code represents.

Representation of each machine instruction.

bool mayLoad(QueryType Type=AnyInBundle) const

Return true if this instruction could possibly read memory.

const MCInstrDesc & getDesc() const

Returns the target instruction descriptor of this MachineInstr.

bool mayStore(QueryType Type=AnyInBundle) const

Return true if this instruction could possibly modify memory.

bool isBundled() const

Return true if this instruction part of a bundle.

MachineOperand class - Representation of each machine instruction operand.

static LLVM_ABI PassRegistry * getPassRegistry()

getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

Wrapper class representing virtual and physical registers.

PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)

Definition SIPostRABundler.cpp:138

SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...

std::pair< const_iterator, bool > insert(const T &V)

insert - Insert an element into the set if it isn't already there.

StringRef - Represent a constant reference to a string, i.e.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

@ Kill

The last use of a register.

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI void finalizeBundle(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)

finalizeBundle - Finalize a machine instruction bundle which includes a sequence of instructions star...

iterator_range< T > make_range(T x, T y)

Convenience function for iterating over sub-ranges.

AnalysisManager< MachineFunction > MachineFunctionAnalysisManager

bool any_of(R &&range, UnaryPredicate P)

Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.

FunctionPass * createSIPostRABundlerPass()

Definition SIPostRABundler.cpp:79

char & SIPostRABundlerLegacyID

void initializeSIPostRABundlerLegacyPass(PassRegistry &)

FunctionAddr VTableAddr Next

DWARFExpression::Operation Op