LLVM: lib/CodeGen/SlotIndexes.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

12#include "llvm/Config/llvm-config.h"

16

17using namespace llvm;

18

19#define DEBUG_TYPE "slotindexes"

20

22

27}

28

32 OS << "Slot indexes in machine function: " << MF.getName() << '\n';

35}

37

40}

41

43

44 indexList.clear();

45}

46

48 false, false)

49

51

53 au.setPreservesAll();

55}

56

57void SlotIndexes::clear() {

59 MBBRanges.clear();

60 idx2MBBMap.clear();

61 indexList.clear();

62 ileAllocator.Reset();

63}

64

66

67

68

69

70

71

72

73

74

75

76

77

78 mf = &fn;

79

80

81 assert(indexList.empty() && "Index list non-empty at initial numbering?");

83 "Index -> MBB mapping non-empty at initial numbering?");

84 assert(MBBRanges.empty() &&

85 "MBB -> Index mapping non-empty at initial numbering?");

87 "MachineInstr -> Index mapping non-empty at initial numbering?");

88

89 unsigned index = 0;

92

93 indexList.push_back(*createEntry(nullptr, index));

94

95

97

98 SlotIndex blockStartIndex(&indexList.back(), SlotIndex::Slot_Block);

99

101 if (MI.isDebugOrPseudoInstr())

102 continue;

103

104

106

107

108 mi2iMap.insert(std::make_pair(

109 &MI, SlotIndex(&indexList.back(), SlotIndex::Slot_Block)));

110 }

111

112

114

115 MBBRanges[MBB.getNumber()].first = blockStartIndex;

117 SlotIndex::Slot_Block);

119 }

120

121

123

125}

126

128 bool AllowBundled) {

129 assert((AllowBundled || MI.isBundledWithPred()) &&

130 "Use removeSingleMachineInstrFromMaps() instead");

132 if (mi2iItr == mi2iMap.end())

133 return;

134

135 SlotIndex MIIndex = mi2iItr->second;

137 assert(MIEntry.getInstr() == &MI && "Instruction indexes broken.");

138 mi2iMap.erase(mi2iItr);

139

141}

142

145 if (mi2iItr == mi2iMap.end())

146 return;

147

148 SlotIndex MIIndex = mi2iItr->second;

150 assert(MIEntry.getInstr() == &MI && "Instruction indexes broken.");

151 mi2iMap.erase(mi2iItr);

152

153

154

155 if (MI.isBundledWithSucc()) {

156

157 assert(MI.isBundledWithPred() && "Should be first bundle instruction");

158

162 mi2iMap.insert(std::make_pair(&NextMI, MIIndex));

163 return;

164 } else {

165

167 }

168}

169

170

171

172void SlotIndexes::renumberIndexes(IndexList::iterator curItr) {

173

175 static_assert((Space & 3) == 0, "InstrDist must be a multiple of 2*NUM");

176

178 unsigned index = startItr->getIndex();

179 do {

180 curItr->setIndex(index += Space);

181 ++curItr;

182

183 } while (curItr != indexList.end() && curItr->getIndex() <= index);

184

185 LLVM_DEBUG(dbgs() << "\n*** Renumbered SlotIndexes " << startItr->getIndex()

186 << '-' << index << " ***\n");

187 ++NumLocalRenum;

188}

189

190

194 bool includeStart = (Begin == MBB->begin());

196 if (includeStart)

198 else

200

204 else

206

207

208

209

210

214 bool pastStart = false;

215 while (ListI != ListB || MBBI != Begin || (includeStart && !pastStart)) {

216 assert(ListI->getIndex() >= startIdx.getIndex() &&

217 (includeStart || !pastStart) &&

218 "Decremented past the beginning of region to repair.");

219

222 bool MBBIAtBegin = MBBI == Begin && (!includeStart || pastStart);

223

224 if (SlotMI == MI && !MBBIAtBegin) {

225 --ListI;

226 if (MBBI != Begin)

228 else

229 pastStart = true;

231 if (MBBI != Begin)

233 else

234 pastStart = true;

235 } else {

236 --ListI;

237 if (SlotMI)

239 }

240 }

241

242

243

245 --I;

247 if (MI.isDebugOrPseudoInstr() && !mi2iMap.contains(&MI))

249 }

250}

251

253 for (auto [Index, Entry] : enumerate(indexList))

255}

256

259 OS << ILE.getIndex() << ' ';

260

261 if (ILE.getInstr())

262 OS << *ILE.getInstr();

263 else

264 OS << '\n';

265 }

266

267 for (unsigned i = 0, e = MBBRanges.size(); i != e; ++i)

268 OS << "%bb." << i << "\t[" << MBBRanges[i].first << ';'

269 << MBBRanges[i].second << ")\n";

270}

271

272#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

274#endif

275

276

279 os << listEntry()->getIndex() << "Berd"[getSlot()];

280 else

281 os << "invalid";

282}

283

284#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

285

288 dbgs() << "\n";

289}

290#endif

MachineBasicBlock MachineBasicBlock::iterator MBBI

#define LLVM_DUMP_METHOD

Mark debug helper function definitions like dump() that should not be stripped from debug builds.

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

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...

#define STATISTIC(VARNAME, DESC)

A container for analyses that lazily runs them and caches their results.

PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)

Get the result of an analysis pass for a given IR unit.

Represent the analysis usage information of a pass.

void Reset()

Deallocate all but the current slab and reset the current pointer to the beginning of it,...

iterator find(const_arg_type_t< KeyT > Val)

bool erase(const KeyT &Val)

bool contains(const_arg_type_t< KeyT > Val) const

Return true if the specified key is in the map, false otherwise.

std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)

This class represents an entry in the slot index list held in the SlotIndexes pass.

void setInstr(MachineInstr *mi)

MachineInstr * getInstr() const

unsigned getIndex() const

int getNumber() const

MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...

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.

StringRef getName() const

getName - Return the name of the corresponding LLVM function.

unsigned getNumBlockIDs() const

getNumBlockIDs - Return the number of MBB ID's allocated.

Representation of each machine instruction.

static 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.

SlotIndex - An opaque wrapper around machine indexes.

bool isValid() const

Returns true if this is a valid index.

void dump() const

Dump this index to stderr.

@ InstrDist

The default distance between instructions as returned by distance().

void print(raw_ostream &os) const

Print this index to the given raw_ostream.

Result run(MachineFunction &MF, MachineFunctionAnalysisManager &)

PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)

SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)

Insert the given machine instruction into the mapping.

void removeMachineInstrFromMaps(MachineInstr &MI, bool AllowBundled=false)

Removes machine instruction (bundle) MI from the mapping.

void dump() const

Dump the indexes.

void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)

Repair indexes after adding and removing instructions.

SlotIndex getMBBEndIdx(unsigned Num) const

Returns the last index in the given basic block number.

void removeSingleMachineInstrFromMaps(MachineInstr &MI)

Removes a single machine instruction MI from the mapping.

SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const

Returns the base index for the given instruction.

SlotIndex getMBBStartIdx(unsigned Num) const

Returns the first index in the given basic block number.

void packIndexes()

Renumber all indexes using the default instruction distance.

void print(raw_ostream &OS) const

void reserve(size_type N)

void push_back(const T &Elt)

self_iterator getIterator()

This class implements an extremely fast bulk output stream that can only output to a stream.

void clear()

Clear the list; never deletes.

typename ilist_select_iterator_type< OptionsT::has_iterator_bits, OptionsT, false, false >::type iterator

bool empty() const

Check if the list is empty in constant time.

void push_back(reference Node)

Insert a node at the back; never copies.

This is an optimization pass for GlobalISel generic memory operations.

auto enumerate(FirstRange &&First, RestRanges &&...Rest)

Given two or more input ranges, returns a new range whose values are tuples (A, B,...

std::pair< SlotIndex, MachineBasicBlock * > IdxMBBPair

Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)

void sort(IteratorTy Start, IteratorTy End)

raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

void initializeSlotIndexesWrapperPassPass(PassRegistry &)

A special type used by analysis passes to provide an address that identifies that particular analysis...

Function object to check whether the first component of a container supported by std::get (like std::...