| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifndef LLVM_CODEGEN_SLOTINDEXES_H |
| 19 |
#define LLVM_CODEGEN_SLOTINDEXES_H |
| 20 |
|
| 21 |
#include "llvm/ADT/DenseMap.h" |
| 22 |
#include "llvm/ADT/IntervalMap.h" |
| 23 |
#include "llvm/ADT/PointerIntPair.h" |
| 24 |
#include "llvm/ADT/SmallVector.h" |
| 25 |
#include "llvm/ADT/ilist.h" |
| 26 |
#include "llvm/CodeGen/MachineBasicBlock.h" |
| 27 |
#include "llvm/CodeGen/MachineFunction.h" |
| 28 |
#include "llvm/CodeGen/MachineFunctionPass.h" |
| 29 |
#include "llvm/CodeGen/MachineInstr.h" |
| 30 |
#include "llvm/CodeGen/MachineInstrBundle.h" |
| 31 |
#include "llvm/Pass.h" |
| 32 |
#include "llvm/Support/Allocator.h" |
| 33 |
#include <algorithm> |
| 34 |
#include <cassert> |
| 35 |
#include <iterator> |
| 36 |
#include <utility> |
| 37 |
|
| 38 |
namespace llvm { |
| 39 |
|
| 40 |
class raw_ostream; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
class IndexListEntry : public ilist_node<IndexListEntry> { |
| 47 |
MachineInstr *mi; |
| 48 |
unsigned index; |
| 49 |
|
| 50 |
public: |
| 51 |
IndexListEntry(MachineInstr *mi, unsigned index) : mi(mi), index(index) {} |
| 52 |
|
| 53 |
MachineInstr* getInstr() const { return mi; } |
| 54 |
void setInstr(MachineInstr *mi) { |
| 55 |
this->mi = mi; |
| 56 |
} |
| 57 |
|
| 58 |
unsigned getIndex() const { return index; } |
| 59 |
void setIndex(unsigned index) { |
| 60 |
this->index = index; |
| 61 |
} |
| 62 |
|
| 63 |
#ifdef EXPENSIVE_CHECKS |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
void setPoison() { |
| 68 |
intptr_t tmp = reinterpret_cast<intptr_t>(mi); |
| 69 |
assert(((tmp & 0x1) == 0x0) && "Pointer already poisoned?"); |
| 70 |
tmp |= 0x1; |
| 71 |
mi = reinterpret_cast<MachineInstr*>(tmp); |
| 72 |
} |
| 73 |
|
| 74 |
bool isPoisoned() const { return (reinterpret_cast<intptr_t>(mi) & 0x1) == 0x1; } |
| 75 |
#endif |
| 76 |
}; |
| 77 |
|
| 78 |
template <> |
| 79 |
struct ilist_alloc_traits<IndexListEntry> |
| 80 |
: public ilist_noalloc_traits<IndexListEntry> {}; |
| 81 |
|
| 82 |
|
| 83 |
class SlotIndex { |
| 84 |
friend class SlotIndexes; |
| 85 |
|
| 86 |
enum Slot { |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
Slot_Block, |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
Slot_EarlyClobber, |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
Slot_Register, |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
Slot_Dead, |
| 106 |
|
| 107 |
Slot_Count |
| 108 |
}; |
| 109 |
|
| 110 |
PointerIntPair<IndexListEntry*, 2, unsigned> lie; |
| 111 |
|
| 112 |
SlotIndex(IndexListEntry *entry, unsigned slot) |
| 113 |
: lie(entry, slot) {} |
| 114 |
|
| 115 |
IndexListEntry* listEntry() const { |
| 116 |
assert(isValid() && "Attempt to compare reserved index."); |
| 117 |
#ifdef EXPENSIVE_CHECKS |
| 118 |
assert(!lie.getPointer()->isPoisoned() && |
| 119 |
"Attempt to access deleted list-entry."); |
| 120 |
#endif |
| 121 |
return lie.getPointer(); |
| 122 |
} |
| 123 |
|
| 124 |
unsigned getIndex() const { |
| 125 |
return listEntry()->getIndex() | getSlot(); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
Slot getSlot() const { |
| 130 |
return static_cast<Slot>(lie.getInt()); |
| 131 |
} |
| 132 |
|
| 133 |
public: |
| 134 |
enum { |
| 135 |
|
| 136 |
|
| 137 |
InstrDist = 4 * Slot_Count |
| 138 |
}; |
| 139 |
|
| 140 |
|
| 141 |
SlotIndex() = default; |
| 142 |
|
| 143 |
|
| 144 |
SlotIndex(const SlotIndex &li, Slot s) : lie(li.listEntry(), unsigned(s)) { |
| 145 |
assert(lie.getPointer() != nullptr && |
| 146 |
"Attempt to construct index with 0 pointer."); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
bool isValid() const { |
| 152 |
return lie.getPointer(); |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
explicit operator bool() const { return isValid(); } |
| 157 |
|
| 158 |
|
| 159 |
void print(raw_ostream &os) const; |
| 160 |
|
| 161 |
|
| 162 |
void dump() const; |
| 163 |
|
| 164 |
|
| 165 |
bool operator==(SlotIndex other) const { |
| 166 |
return lie == other.lie; |
| 167 |
} |
| 168 |
|
| 169 |
bool operator!=(SlotIndex other) const { |
| 170 |
return lie != other.lie; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
bool operator<(SlotIndex other) const { |
| 176 |
return getIndex() < other.getIndex(); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
bool operator<=(SlotIndex other) const { |
| 181 |
return getIndex() <= other.getIndex(); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
bool operator>(SlotIndex other) const { |
| 187 |
return getIndex() > other.getIndex(); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
bool operator>=(SlotIndex other) const { |
| 193 |
return getIndex() >= other.getIndex(); |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
static bool isSameInstr(SlotIndex A, SlotIndex B) { |
| 198 |
return A.lie.getPointer() == B.lie.getPointer(); |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
static bool isEarlierInstr(SlotIndex A, SlotIndex B) { |
| 204 |
return A.listEntry()->getIndex() < B.listEntry()->getIndex(); |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
static bool isEarlierEqualInstr(SlotIndex A, SlotIndex B) { |
| 210 |
return !isEarlierInstr(B, A); |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
int distance(SlotIndex other) const { |
| 215 |
return other.getIndex() - getIndex(); |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
int getInstrDistance(SlotIndex other) const { |
| 221 |
return (other.listEntry()->getIndex() - listEntry()->getIndex()) |
| 222 |
/ Slot_Count; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
bool isBlock() const { return getSlot() == Slot_Block; } |
| 227 |
|
| 228 |
|
| 229 |
bool isEarlyClobber() const { return getSlot() == Slot_EarlyClobber; } |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
bool isRegister() const { return getSlot() == Slot_Register; } |
| 234 |
|
| 235 |
|
| 236 |
bool isDead() const { return getSlot() == Slot_Dead; } |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
SlotIndex getBaseIndex() const { |
| 242 |
return SlotIndex(listEntry(), Slot_Block); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
SlotIndex getBoundaryIndex() const { |
| 249 |
return SlotIndex(listEntry(), Slot_Dead); |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
SlotIndex getRegSlot(bool EC = false) const { |
| 255 |
return SlotIndex(listEntry(), EC ? Slot_EarlyClobber : Slot_Register); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
SlotIndex getDeadSlot() const { |
| 260 |
return SlotIndex(listEntry(), Slot_Dead); |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
SlotIndex getNextSlot() const { |
| 270 |
Slot s = getSlot(); |
| 271 |
if (s == Slot_Dead) { |
| 272 |
return SlotIndex(&*++listEntry()->getIterator(), Slot_Block); |
| 273 |
} |
| 274 |
return SlotIndex(listEntry(), s + 1); |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
SlotIndex getNextIndex() const { |
| 280 |
return SlotIndex(&*++listEntry()->getIterator(), getSlot()); |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
SlotIndex getPrevSlot() const { |
| 290 |
Slot s = getSlot(); |
| 291 |
if (s == Slot_Block) { |
| 292 |
return SlotIndex(&*--listEntry()->getIterator(), Slot_Dead); |
| 293 |
} |
| 294 |
return SlotIndex(listEntry(), s - 1); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
SlotIndex getPrevIndex() const { |
| 300 |
return SlotIndex(&*--listEntry()->getIterator(), getSlot()); |
| 301 |
} |
| 302 |
}; |
| 303 |
|
| 304 |
inline raw_ostream& operator<<(raw_ostream &os, SlotIndex li) { |
| 305 |
li.print(os); |
| 306 |
return os; |
| 307 |
} |
| 308 |
|
| 309 |
using IdxMBBPair = std::pair<SlotIndex, MachineBasicBlock *>; |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
class SlotIndexes : public MachineFunctionPass { |
| 315 |
private: |
| 316 |
|
| 317 |
BumpPtrAllocator ileAllocator; |
| 318 |
|
| 319 |
using IndexList = ilist<IndexListEntry>; |
| 320 |
IndexList indexList; |
| 321 |
|
| 322 |
MachineFunction *mf = nullptr; |
| 323 |
|
| 324 |
using Mi2IndexMap = DenseMap<const MachineInstr *, SlotIndex>; |
| 325 |
Mi2IndexMap mi2iMap; |
| 326 |
|
| 327 |
|
| 328 |
SmallVector<std::pair<SlotIndex, SlotIndex>, 8> MBBRanges; |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
SmallVector<IdxMBBPair, 8> idx2MBBMap; |
| 333 |
|
| 334 |
IndexListEntry* createEntry(MachineInstr *mi, unsigned index) { |
| 335 |
IndexListEntry *entry = |
| 336 |
static_cast<IndexListEntry *>(ileAllocator.Allocate( |
| 337 |
sizeof(IndexListEntry), alignof(IndexListEntry))); |
| 338 |
|
| 339 |
new (entry) IndexListEntry(mi, index); |
| 340 |
|
| 341 |
return entry; |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
void renumberIndexes(IndexList::iterator curItr); |
| 346 |
|
| 347 |
public: |
| 348 |
static char ID; |
| 349 |
|
| 350 |
SlotIndexes(); |
| 351 |
|
| 352 |
~SlotIndexes() override; |
| 353 |
|
| 354 |
void getAnalysisUsage(AnalysisUsage &au) const override; |
| 355 |
void releaseMemory() override; |
| 356 |
|
| 357 |
bool runOnMachineFunction(MachineFunction &fn) override; |
| 358 |
|
| 359 |
|
| 360 |
void dump() const; |
| 361 |
|
| 362 |
|
| 363 |
void repairIndexesInRange(MachineBasicBlock *MBB, |
| 364 |
MachineBasicBlock::iterator Begin, |
| 365 |
MachineBasicBlock::iterator End); |
| 366 |
|
| 367 |
|
| 368 |
SlotIndex getZeroIndex() { |
| 369 |
assert(indexList.front().getIndex() == 0 && "First index is not 0?"); |
| 370 |
return SlotIndex(&indexList.front(), 0); |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
SlotIndex getLastIndex() { |
| 375 |
return SlotIndex(&indexList.back(), 0); |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
bool hasIndex(const MachineInstr &instr) const { |
| 381 |
return mi2iMap.count(&instr); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
SlotIndex getInstructionIndex(const MachineInstr &MI, |
| 386 |
bool IgnoreBundle = false) const { |
| 387 |
|
| 388 |
auto BundleStart = getBundleStart(MI.getIterator()); |
| 389 |
auto BundleEnd = getBundleEnd(MI.getIterator()); |
| 390 |
|
| 391 |
const MachineInstr &BundleNonDebug = |
| 392 |
IgnoreBundle ? MI |
| 393 |
: *skipDebugInstructionsForward(BundleStart, BundleEnd); |
| 394 |
assert(!BundleNonDebug.isDebugInstr() && |
| 395 |
"Could not use a debug instruction to query mi2iMap."); |
| 396 |
Mi2IndexMap::const_iterator itr = mi2iMap.find(&BundleNonDebug); |
| 397 |
assert(itr != mi2iMap.end() && "Instruction not found in maps."); |
| 398 |
return itr->second; |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
MachineInstr* getInstructionFromIndex(SlotIndex index) const { |
| 404 |
return index.isValid() ? index.listEntry()->getInstr() : nullptr; |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
SlotIndex getNextNonNullIndex(SlotIndex Index) { |
| 410 |
IndexList::iterator I = Index.listEntry()->getIterator(); |
| 411 |
IndexList::iterator E = indexList.end(); |
| 412 |
while (++I != E) |
| 413 |
if (I->getInstr()) |
| 414 |
return SlotIndex(&*I, Index.getSlot()); |
| 415 |
|
| 416 |
return getLastIndex(); |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
SlotIndex getIndexBefore(const MachineInstr &MI) const { |
| 423 |
const MachineBasicBlock *MBB = MI.getParent(); |
| 424 |
assert(MBB && "MI must be inserted in a basic block"); |
| 425 |
MachineBasicBlock::const_iterator I = MI, B = MBB->begin(); |
| 426 |
while (true) { |
| 427 |
if (I == B) |
| 428 |
return getMBBStartIdx(MBB); |
| 429 |
--I; |
| 430 |
Mi2IndexMap::const_iterator MapItr = mi2iMap.find(&*I); |
| 431 |
if (MapItr != mi2iMap.end()) |
| 432 |
return MapItr->second; |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
SlotIndex getIndexAfter(const MachineInstr &MI) const { |
| 440 |
const MachineBasicBlock *MBB = MI.getParent(); |
| 441 |
assert(MBB && "MI must be inserted in a basic block"); |
| 442 |
MachineBasicBlock::const_iterator I = MI, E = MBB->end(); |
| 443 |
while (true) { |
| 444 |
++I; |
| 445 |
if (I == E) |
| 446 |
return getMBBEndIdx(MBB); |
| 447 |
Mi2IndexMap::const_iterator MapItr = mi2iMap.find(&*I); |
| 448 |
if (MapItr != mi2iMap.end()) |
| 449 |
return MapItr->second; |
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
const std::pair<SlotIndex, SlotIndex> & |
| 455 |
getMBBRange(unsigned Num) const { |
| 456 |
return MBBRanges[Num]; |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
const std::pair<SlotIndex, SlotIndex> & |
| 461 |
getMBBRange(const MachineBasicBlock *MBB) const { |
| 462 |
return getMBBRange(MBB->getNumber()); |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
SlotIndex getMBBStartIdx(unsigned Num) const { |
| 467 |
return getMBBRange(Num).first; |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const { |
| 472 |
return getMBBRange(mbb).first; |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
SlotIndex getMBBEndIdx(unsigned Num) const { |
| 477 |
return getMBBRange(Num).second; |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const { |
| 482 |
return getMBBRange(mbb).second; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
using MBBIndexIterator = SmallVectorImpl<IdxMBBPair>::const_iterator; |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
MBBIndexIterator advanceMBBIndex(MBBIndexIterator I, SlotIndex To) const { |
| 492 |
return std::partition_point( |
| 493 |
I, idx2MBBMap.end(), |
| 494 |
[=](const IdxMBBPair &IM) { return IM.first < To; }); |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
MBBIndexIterator findMBBIndex(SlotIndex Idx) const { |
| 500 |
return advanceMBBIndex(idx2MBBMap.begin(), Idx); |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
MBBIndexIterator MBBIndexBegin() const { |
| 505 |
return idx2MBBMap.begin(); |
| 506 |
} |
| 507 |
|
| 508 |
|
| 509 |
MBBIndexIterator MBBIndexEnd() const { |
| 510 |
return idx2MBBMap.end(); |
| 511 |
} |
| 512 |
|
| 513 |
|
| 514 |
MachineBasicBlock* getMBBFromIndex(SlotIndex index) const { |
| 515 |
if (MachineInstr *MI = getInstructionFromIndex(index)) |
| 516 |
return MI->getParent(); |
| 517 |
|
| 518 |
MBBIndexIterator I = findMBBIndex(index); |
| 519 |
|
| 520 |
MBBIndexIterator J = |
| 521 |
((I != MBBIndexEnd() && I->first > index) || |
| 522 |
(I == MBBIndexEnd() && !idx2MBBMap.empty())) ? std::prev(I) : I; |
| 523 |
|
| 524 |
assert(J != MBBIndexEnd() && J->first <= index && |
| 525 |
index < getMBBEndIdx(J->second) && |
| 526 |
"index does not correspond to an MBB"); |
| 527 |
return J->second; |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late = false) { |
| 536 |
assert(!MI.isInsideBundle() && |
| 537 |
"Instructions inside bundles should use bundle start's slot."); |
| 538 |
assert(mi2iMap.find(&MI) == mi2iMap.end() && "Instr already indexed."); |
| 539 |
|
| 540 |
|
| 541 |
assert(!MI.isDebugInstr() && "Cannot number debug instructions."); |
| 542 |
|
| 543 |
assert(MI.getParent() != nullptr && "Instr must be added to function."); |
| 544 |
|
| 545 |
|
| 546 |
IndexList::iterator prevItr, nextItr; |
| 547 |
if (Late) { |
| 548 |
|
| 549 |
nextItr = getIndexAfter(MI).listEntry()->getIterator(); |
| 550 |
prevItr = std::prev(nextItr); |
| 551 |
} else { |
| 552 |
|
| 553 |
prevItr = getIndexBefore(MI).listEntry()->getIterator(); |
| 554 |
nextItr = std::next(prevItr); |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
unsigned dist = ((nextItr->getIndex() - prevItr->getIndex())/2) & ~3u; |
| 560 |
unsigned newNumber = prevItr->getIndex() + dist; |
| 561 |
|
| 562 |
|
| 563 |
IndexList::iterator newItr = |
| 564 |
indexList.insert(nextItr, createEntry(&MI, newNumber)); |
| 565 |
|
| 566 |
|
| 567 |
if (dist == 0) |
| 568 |
renumberIndexes(newItr); |
| 569 |
|
| 570 |
SlotIndex newIndex(&*newItr, SlotIndex::Slot_Block); |
| 571 |
mi2iMap.insert(std::make_pair(&MI, newIndex)); |
| 572 |
return newIndex; |
| 573 |
} |
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
void removeMachineInstrFromMaps(MachineInstr &MI, |
| 582 |
bool AllowBundled = false); |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
void removeSingleMachineInstrFromMaps(MachineInstr &MI); |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
SlotIndex replaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI) { |
| 593 |
Mi2IndexMap::iterator mi2iItr = mi2iMap.find(&MI); |
| 594 |
if (mi2iItr == mi2iMap.end()) |
| 595 |
return SlotIndex(); |
| 596 |
SlotIndex replaceBaseIndex = mi2iItr->second; |
| 597 |
IndexListEntry *miEntry(replaceBaseIndex.listEntry()); |
| 598 |
assert(miEntry->getInstr() == &MI && |
| 599 |
"Mismatched instruction in index tables."); |
| 600 |
miEntry->setInstr(&NewMI); |
| 601 |
mi2iMap.erase(mi2iItr); |
| 602 |
mi2iMap.insert(std::make_pair(&NewMI, replaceBaseIndex)); |
| 603 |
return replaceBaseIndex; |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
void insertMBBInMaps(MachineBasicBlock *mbb) { |
| 611 |
assert(mbb != &mbb->getParent()->front() && |
| 612 |
"Can't insert a new block at the beginning of a function."); |
| 613 |
auto prevMBB = std::prev(MachineFunction::iterator(mbb)); |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
IndexListEntry *startEntry = createEntry(nullptr, 0); |
| 618 |
IndexListEntry *endEntry = getMBBEndIdx(&*prevMBB).listEntry(); |
| 619 |
IndexListEntry *insEntry = |
| 620 |
mbb->empty() ? endEntry |
| 621 |
: getInstructionIndex(mbb->front()).listEntry(); |
| 622 |
IndexList::iterator newItr = |
| 623 |
indexList.insert(insEntry->getIterator(), startEntry); |
| 624 |
|
| 625 |
SlotIndex startIdx(startEntry, SlotIndex::Slot_Block); |
| 626 |
SlotIndex endIdx(endEntry, SlotIndex::Slot_Block); |
| 627 |
|
| 628 |
MBBRanges[prevMBB->getNumber()].second = startIdx; |
| 629 |
|
| 630 |
assert(unsigned(mbb->getNumber()) == MBBRanges.size() && |
| 631 |
"Blocks must be added in order"); |
| 632 |
MBBRanges.push_back(std::make_pair(startIdx, endIdx)); |
| 633 |
idx2MBBMap.push_back(IdxMBBPair(startIdx, mbb)); |
| 634 |
|
| 635 |
renumberIndexes(newItr); |
| 636 |
llvm::sort(idx2MBBMap, less_first()); |
| 637 |
} |
| 638 |
}; |
| 639 |
|
| 640 |
|
| 641 |
template <> |
| 642 |
struct IntervalMapInfo<SlotIndex> : IntervalMapHalfOpenInfo<SlotIndex> { |
| 643 |
}; |
| 644 |
|
| 645 |
} |
| 646 |
|
| 647 |
#endif |