| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H |
| 14 |
#define LLVM_CODEGEN_MACHINEBASICBLOCK_H |
| 15 |
|
| 16 |
#include "llvm/ADT/GraphTraits.h" |
| 17 |
#include "llvm/ADT/ilist.h" |
| 18 |
#include "llvm/ADT/iterator_range.h" |
| 19 |
#include "llvm/ADT/SparseBitVector.h" |
| 20 |
#include "llvm/CodeGen/MachineInstr.h" |
| 21 |
#include "llvm/CodeGen/MachineInstrBundleIterator.h" |
| 22 |
#include "llvm/IR/DebugLoc.h" |
| 23 |
#include "llvm/MC/LaneBitmask.h" |
| 24 |
#include "llvm/Support/BranchProbability.h" |
| 25 |
#include <cassert> |
| 26 |
#include <cstdint> |
| 27 |
#include <functional> |
| 28 |
#include <iterator> |
| 29 |
#include <string> |
| 30 |
#include <vector> |
| 31 |
|
| 32 |
namespace llvm { |
| 33 |
|
| 34 |
class BasicBlock; |
| 35 |
class MachineFunction; |
| 36 |
class MCSymbol; |
| 37 |
class ModuleSlotTracker; |
| 38 |
class Pass; |
| 39 |
class Printable; |
| 40 |
class SlotIndexes; |
| 41 |
class StringRef; |
| 42 |
class raw_ostream; |
| 43 |
class LiveIntervals; |
| 44 |
class TargetRegisterClass; |
| 45 |
class TargetRegisterInfo; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
struct MBBSectionID { |
| 53 |
enum SectionType { |
| 54 |
Default = 0, |
| 55 |
|
| 56 |
Exception, |
| 57 |
Cold, |
| 58 |
} Type; |
| 59 |
unsigned Number; |
| 60 |
|
| 61 |
MBBSectionID(unsigned N) : Type(Default), Number(N) {} |
| 62 |
|
| 63 |
|
| 64 |
const static MBBSectionID ColdSectionID; |
| 65 |
const static MBBSectionID ExceptionSectionID; |
| 66 |
|
| 67 |
bool operator==(const MBBSectionID &Other) const { |
| 68 |
return Type == Other.Type && Number == Other.Number; |
| 69 |
} |
| 70 |
|
| 71 |
bool operator!=(const MBBSectionID &Other) const { return !(*this == Other); } |
| 72 |
|
| 73 |
private: |
| 74 |
|
| 75 |
MBBSectionID(SectionType T) : Type(T), Number(0) {} |
| 76 |
}; |
| 77 |
|
| 78 |
template <> struct ilist_traits<MachineInstr> { |
| 79 |
private: |
| 80 |
friend class MachineBasicBlock; |
| 81 |
|
| 82 |
MachineBasicBlock *Parent; |
| 83 |
|
| 84 |
using instr_iterator = |
| 85 |
simple_ilist<MachineInstr, ilist_sentinel_tracking<true>>::iterator; |
| 86 |
|
| 87 |
public: |
| 88 |
void addNodeToList(MachineInstr *N); |
| 89 |
void removeNodeFromList(MachineInstr *N); |
| 90 |
void transferNodesFromList(ilist_traits &FromList, instr_iterator First, |
| 91 |
instr_iterator Last); |
| 92 |
void deleteNode(MachineInstr *MI); |
| 93 |
}; |
| 94 |
|
| 95 |
class MachineBasicBlock |
| 96 |
: public ilist_node_with_parent<MachineBasicBlock, MachineFunction> { |
| 97 |
public: |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
struct RegisterMaskPair { |
| 102 |
public: |
| 103 |
MCPhysReg PhysReg; |
| 104 |
LaneBitmask LaneMask; |
| 105 |
|
| 106 |
RegisterMaskPair(MCPhysReg PhysReg, LaneBitmask LaneMask) |
| 107 |
: PhysReg(PhysReg), LaneMask(LaneMask) {} |
| 108 |
}; |
| 109 |
|
| 110 |
private: |
| 111 |
using Instructions = ilist<MachineInstr, ilist_sentinel_tracking<true>>; |
| 112 |
|
| 113 |
Instructions Insts; |
| 114 |
const BasicBlock *BB; |
| 115 |
int Number; |
| 116 |
MachineFunction *xParent; |
| 117 |
|
| 118 |
|
| 119 |
std::vector<MachineBasicBlock *> Predecessors; |
| 120 |
std::vector<MachineBasicBlock *> Successors; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
std::vector<BranchProbability> Probs; |
| 126 |
using probability_iterator = std::vector<BranchProbability>::iterator; |
| 127 |
using const_probability_iterator = |
| 128 |
std::vector<BranchProbability>::const_iterator; |
| 129 |
|
| 130 |
Optional<uint64_t> IrrLoopHeaderWeight; |
| 131 |
|
| 132 |
|
| 133 |
using LiveInVector = std::vector<RegisterMaskPair>; |
| 134 |
LiveInVector LiveIns; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
Align Alignment; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
unsigned MaxBytesForAlignment = 0; |
| 143 |
|
| 144 |
|
| 145 |
bool IsEHPad = false; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
bool AddressTaken = false; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
bool LabelMustBeEmitted = false; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
bool IsEHScopeEntry = false; |
| 159 |
|
| 160 |
|
| 161 |
bool IsEHCatchretTarget = false; |
| 162 |
|
| 163 |
|
| 164 |
bool IsEHFuncletEntry = false; |
| 165 |
|
| 166 |
|
| 167 |
bool IsCleanupFuncletEntry = false; |
| 168 |
|
| 169 |
|
| 170 |
MBBSectionID SectionID{0}; |
| 171 |
|
| 172 |
|
| 173 |
bool IsBeginSection = false; |
| 174 |
|
| 175 |
|
| 176 |
bool IsEndSection = false; |
| 177 |
|
| 178 |
|
| 179 |
bool IsInlineAsmBrIndirectTarget = false; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
mutable MCSymbol *CachedMCSymbol = nullptr; |
| 184 |
|
| 185 |
|
| 186 |
mutable MCSymbol *CachedEHCatchretMCSymbol = nullptr; |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
mutable MCSymbol *CachedEndMCSymbol = nullptr; |
| 191 |
|
| 192 |
|
| 193 |
MachineBasicBlock() = default; |
| 194 |
|
| 195 |
explicit MachineBasicBlock(MachineFunction &MF, const BasicBlock *BB); |
| 196 |
|
| 197 |
~MachineBasicBlock(); |
| 198 |
|
| 199 |
|
| 200 |
friend class MachineFunction; |
| 201 |
|
| 202 |
public: |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
const BasicBlock *getBasicBlock() const { return BB; } |
| 207 |
|
| 208 |
|
| 209 |
StringRef getName() const; |
| 210 |
|
| 211 |
|
| 212 |
std::string getFullName() const; |
| 213 |
|
| 214 |
|
| 215 |
bool hasAddressTaken() const { return AddressTaken; } |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
void setHasAddressTaken() { AddressTaken = true; } |
| 220 |
|
| 221 |
|
| 222 |
bool hasLabelMustBeEmitted() const { return LabelMustBeEmitted; } |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
void setLabelMustBeEmitted() { LabelMustBeEmitted = true; } |
| 227 |
|
| 228 |
|
| 229 |
const MachineFunction *getParent() const { return xParent; } |
| 230 |
MachineFunction *getParent() { return xParent; } |
| 231 |
|
| 232 |
using instr_iterator = Instructions::iterator; |
| 233 |
using const_instr_iterator = Instructions::const_iterator; |
| 234 |
using reverse_instr_iterator = Instructions::reverse_iterator; |
| 235 |
using const_reverse_instr_iterator = Instructions::const_reverse_iterator; |
| 236 |
|
| 237 |
using iterator = MachineInstrBundleIterator<MachineInstr>; |
| 238 |
using const_iterator = MachineInstrBundleIterator<const MachineInstr>; |
| 239 |
using reverse_iterator = MachineInstrBundleIterator<MachineInstr, true>; |
| 240 |
using const_reverse_iterator = |
| 241 |
MachineInstrBundleIterator<const MachineInstr, true>; |
| 242 |
|
| 243 |
unsigned size() const { return (unsigned)Insts.size(); } |
| 244 |
bool empty() const { return Insts.empty(); } |
| 245 |
|
| 246 |
MachineInstr &instr_front() { return Insts.front(); } |
| 247 |
MachineInstr &instr_back() { return Insts.back(); } |
| 248 |
const MachineInstr &instr_front() const { return Insts.front(); } |
| 249 |
const MachineInstr &instr_back() const { return Insts.back(); } |
| 250 |
|
| 251 |
MachineInstr &front() { return Insts.front(); } |
| 252 |
MachineInstr &back() { return *--end(); } |
| 253 |
const MachineInstr &front() const { return Insts.front(); } |
| 254 |
const MachineInstr &back() const { return *--end(); } |
| 255 |
|
| 256 |
instr_iterator instr_begin() { return Insts.begin(); } |
| 257 |
const_instr_iterator instr_begin() const { return Insts.begin(); } |
| 258 |
instr_iterator instr_end() { return Insts.end(); } |
| 259 |
const_instr_iterator instr_end() const { return Insts.end(); } |
| 260 |
reverse_instr_iterator instr_rbegin() { return Insts.rbegin(); } |
| 261 |
const_reverse_instr_iterator instr_rbegin() const { return Insts.rbegin(); } |
| 262 |
reverse_instr_iterator instr_rend () { return Insts.rend(); } |
| 263 |
const_reverse_instr_iterator instr_rend () const { return Insts.rend(); } |
| 264 |
|
| 265 |
using instr_range = iterator_range<instr_iterator>; |
| 266 |
using const_instr_range = iterator_range<const_instr_iterator>; |
| 267 |
instr_range instrs() { return instr_range(instr_begin(), instr_end()); } |
| 268 |
const_instr_range instrs() const { |
| 269 |
return const_instr_range(instr_begin(), instr_end()); |
| 270 |
} |
| 271 |
|
| 272 |
iterator begin() { return instr_begin(); } |
| 273 |
const_iterator begin() const { return instr_begin(); } |
| 274 |
iterator end () { return instr_end(); } |
| 275 |
const_iterator end () const { return instr_end(); } |
| 276 |
reverse_iterator rbegin() { |
| 277 |
return reverse_iterator::getAtBundleBegin(instr_rbegin()); |
| 278 |
} |
| 279 |
const_reverse_iterator rbegin() const { |
| 280 |
return const_reverse_iterator::getAtBundleBegin(instr_rbegin()); |
| 281 |
} |
| 282 |
reverse_iterator rend() { return reverse_iterator(instr_rend()); } |
| 283 |
const_reverse_iterator rend() const { |
| 284 |
return const_reverse_iterator(instr_rend()); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
static Instructions MachineBasicBlock::*getSublistAccess(MachineInstr *) { |
| 289 |
return &MachineBasicBlock::Insts; |
| 290 |
} |
| 291 |
|
| 292 |
inline iterator_range<iterator> terminators() { |
| 293 |
return make_range(getFirstTerminator(), end()); |
| 294 |
} |
| 295 |
inline iterator_range<const_iterator> terminators() const { |
| 296 |
return make_range(getFirstTerminator(), end()); |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
inline iterator_range<iterator> phis() { |
| 301 |
return make_range(begin(), getFirstNonPHI()); |
| 302 |
} |
| 303 |
inline iterator_range<const_iterator> phis() const { |
| 304 |
return const_cast<MachineBasicBlock *>(this)->phis(); |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
using pred_iterator = std::vector<MachineBasicBlock *>::iterator; |
| 309 |
using const_pred_iterator = std::vector<MachineBasicBlock *>::const_iterator; |
| 310 |
using succ_iterator = std::vector<MachineBasicBlock *>::iterator; |
| 311 |
using const_succ_iterator = std::vector<MachineBasicBlock *>::const_iterator; |
| 312 |
using pred_reverse_iterator = |
| 313 |
std::vector<MachineBasicBlock *>::reverse_iterator; |
| 314 |
using const_pred_reverse_iterator = |
| 315 |
std::vector<MachineBasicBlock *>::const_reverse_iterator; |
| 316 |
using succ_reverse_iterator = |
| 317 |
std::vector<MachineBasicBlock *>::reverse_iterator; |
| 318 |
using const_succ_reverse_iterator = |
| 319 |
std::vector<MachineBasicBlock *>::const_reverse_iterator; |
| 320 |
pred_iterator pred_begin() { return Predecessors.begin(); } |
| 321 |
const_pred_iterator pred_begin() const { return Predecessors.begin(); } |
| 322 |
pred_iterator pred_end() { return Predecessors.end(); } |
| 323 |
const_pred_iterator pred_end() const { return Predecessors.end(); } |
| 324 |
pred_reverse_iterator pred_rbegin() |
| 325 |
{ return Predecessors.rbegin();} |
| 326 |
const_pred_reverse_iterator pred_rbegin() const |
| 327 |
{ return Predecessors.rbegin();} |
| 328 |
pred_reverse_iterator pred_rend() |
| 329 |
{ return Predecessors.rend(); } |
| 330 |
const_pred_reverse_iterator pred_rend() const |
| 331 |
{ return Predecessors.rend(); } |
| 332 |
unsigned pred_size() const { |
| 333 |
return (unsigned)Predecessors.size(); |
| 334 |
} |
| 335 |
bool pred_empty() const { return Predecessors.empty(); } |
| 336 |
succ_iterator succ_begin() { return Successors.begin(); } |
| 337 |
const_succ_iterator succ_begin() const { return Successors.begin(); } |
| 338 |
succ_iterator succ_end() { return Successors.end(); } |
| 339 |
const_succ_iterator succ_end() const { return Successors.end(); } |
| 340 |
succ_reverse_iterator succ_rbegin() |
| 341 |
{ return Successors.rbegin(); } |
| 342 |
const_succ_reverse_iterator succ_rbegin() const |
| 343 |
{ return Successors.rbegin(); } |
| 344 |
succ_reverse_iterator succ_rend() |
| 345 |
{ return Successors.rend(); } |
| 346 |
const_succ_reverse_iterator succ_rend() const |
| 347 |
{ return Successors.rend(); } |
| 348 |
unsigned succ_size() const { |
| 349 |
return (unsigned)Successors.size(); |
| 350 |
} |
| 351 |
bool succ_empty() const { return Successors.empty(); } |
| 352 |
|
| 353 |
inline iterator_range<pred_iterator> predecessors() { |
| 354 |
return make_range(pred_begin(), pred_end()); |
| 355 |
} |
| 356 |
inline iterator_range<const_pred_iterator> predecessors() const { |
| 357 |
return make_range(pred_begin(), pred_end()); |
| 358 |
} |
| 359 |
inline iterator_range<succ_iterator> successors() { |
| 360 |
return make_range(succ_begin(), succ_end()); |
| 361 |
} |
| 362 |
inline iterator_range<const_succ_iterator> successors() const { |
| 363 |
return make_range(succ_begin(), succ_end()); |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
void addLiveIn(MCRegister PhysReg, |
| 372 |
LaneBitmask LaneMask = LaneBitmask::getAll()) { |
| 373 |
LiveIns.push_back(RegisterMaskPair(PhysReg, LaneMask)); |
| 374 |
} |
| 375 |
void addLiveIn(const RegisterMaskPair &RegMaskPair) { |
| 376 |
LiveIns.push_back(RegMaskPair); |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
void sortUniqueLiveIns(); |
| 383 |
|
| 384 |
|
| 385 |
void clearLiveIns(); |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
Register addLiveIn(MCRegister PhysReg, const TargetRegisterClass *RC); |
| 391 |
|
| 392 |
|
| 393 |
void removeLiveIn(MCPhysReg Reg, |
| 394 |
LaneBitmask LaneMask = LaneBitmask::getAll()); |
| 395 |
|
| 396 |
|
| 397 |
bool isLiveIn(MCPhysReg Reg, |
| 398 |
LaneBitmask LaneMask = LaneBitmask::getAll()) const; |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
using livein_iterator = LiveInVector::const_iterator; |
| 403 |
#ifndef NDEBUG |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
livein_iterator livein_begin_dbg() const { return LiveIns.begin(); } |
| 409 |
iterator_range<livein_iterator> liveins_dbg() const { |
| 410 |
return make_range(livein_begin_dbg(), livein_end()); |
| 411 |
} |
| 412 |
#endif |
| 413 |
livein_iterator livein_begin() const; |
| 414 |
livein_iterator livein_end() const { return LiveIns.end(); } |
| 415 |
bool livein_empty() const { return LiveIns.empty(); } |
| 416 |
iterator_range<livein_iterator> liveins() const { |
| 417 |
return make_range(livein_begin(), livein_end()); |
| 418 |
} |
| 419 |
|
| 420 |
|
| 421 |
livein_iterator removeLiveIn(livein_iterator I); |
| 422 |
|
| 423 |
class liveout_iterator { |
| 424 |
public: |
| 425 |
using iterator_category = std::input_iterator_tag; |
| 426 |
using difference_type = std::ptrdiff_t; |
| 427 |
using value_type = RegisterMaskPair; |
| 428 |
using pointer = const RegisterMaskPair *; |
| 429 |
using reference = const RegisterMaskPair &; |
| 430 |
|
| 431 |
liveout_iterator(const MachineBasicBlock &MBB, MCPhysReg ExceptionPointer, |
| 432 |
MCPhysReg ExceptionSelector, bool End) |
| 433 |
: ExceptionPointer(ExceptionPointer), |
| 434 |
ExceptionSelector(ExceptionSelector), BlockI(MBB.succ_begin()), |
| 435 |
BlockEnd(MBB.succ_end()) { |
| 436 |
if (End) |
| 437 |
BlockI = BlockEnd; |
| 438 |
else if (BlockI != BlockEnd) { |
| 439 |
LiveRegI = (*BlockI)->livein_begin(); |
| 440 |
if (!advanceToValidPosition()) |
| 441 |
return; |
| 442 |
if (LiveRegI->PhysReg == ExceptionPointer || |
| 443 |
LiveRegI->PhysReg == ExceptionSelector) |
| 444 |
++(*this); |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
liveout_iterator &operator++() { |
| 449 |
do { |
| 450 |
++LiveRegI; |
| 451 |
if (!advanceToValidPosition()) |
| 452 |
return *this; |
| 453 |
} while ((*BlockI)->isEHPad() && |
| 454 |
(LiveRegI->PhysReg == ExceptionPointer || |
| 455 |
LiveRegI->PhysReg == ExceptionSelector)); |
| 456 |
return *this; |
| 457 |
} |
| 458 |
|
| 459 |
liveout_iterator operator++(int) { |
| 460 |
liveout_iterator Tmp = *this; |
| 461 |
++(*this); |
| 462 |
return Tmp; |
| 463 |
} |
| 464 |
|
| 465 |
reference operator*() const { |
| 466 |
return *LiveRegI; |
| 467 |
} |
| 468 |
|
| 469 |
pointer operator->() const { |
| 470 |
return &*LiveRegI; |
| 471 |
} |
| 472 |
|
| 473 |
bool operator==(const liveout_iterator &RHS) const { |
| 474 |
if (BlockI != BlockEnd) |
| 475 |
return BlockI == RHS.BlockI && LiveRegI == RHS.LiveRegI; |
| 476 |
return RHS.BlockI == BlockEnd; |
| 477 |
} |
| 478 |
|
| 479 |
bool operator!=(const liveout_iterator &RHS) const { |
| 480 |
return !(*this == RHS); |
| 481 |
} |
| 482 |
private: |
| 483 |
bool advanceToValidPosition() { |
| 484 |
if (LiveRegI != (*BlockI)->livein_end()) |
| 485 |
return true; |
| 486 |
|
| 487 |
do { |
| 488 |
++BlockI; |
| 489 |
} while (BlockI != BlockEnd && (*BlockI)->livein_empty()); |
| 490 |
if (BlockI == BlockEnd) |
| 491 |
return false; |
| 492 |
|
| 493 |
LiveRegI = (*BlockI)->livein_begin(); |
| 494 |
return true; |
| 495 |
} |
| 496 |
|
| 497 |
MCPhysReg ExceptionPointer, ExceptionSelector; |
| 498 |
const_succ_iterator BlockI; |
| 499 |
const_succ_iterator BlockEnd; |
| 500 |
livein_iterator LiveRegI; |
| 501 |
}; |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
liveout_iterator liveout_begin() const; |
| 507 |
liveout_iterator liveout_end() const { |
| 508 |
return liveout_iterator(*this, 0, 0, true); |
| 509 |
} |
| 510 |
iterator_range<liveout_iterator> liveouts() const { |
| 511 |
return make_range(liveout_begin(), liveout_end()); |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
const uint32_t *getBeginClobberMask(const TargetRegisterInfo *TRI) const; |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
const uint32_t *getEndClobberMask(const TargetRegisterInfo *TRI) const; |
| 521 |
|
| 522 |
|
| 523 |
Align getAlignment() const { return Alignment; } |
| 524 |
|
| 525 |
|
| 526 |
void setAlignment(Align A) { Alignment = A; } |
| 527 |
|
| 528 |
void setAlignment(Align A, unsigned MaxBytes) { |
| 529 |
setAlignment(A); |
| 530 |
setMaxBytesForAlignment(MaxBytes); |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
unsigned getMaxBytesForAlignment() const { return MaxBytesForAlignment; } |
| 535 |
|
| 536 |
|
| 537 |
void setMaxBytesForAlignment(unsigned MaxBytes) { |
| 538 |
MaxBytesForAlignment = MaxBytes; |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
bool isEHPad() const { return IsEHPad; } |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
void setIsEHPad(bool V = true) { IsEHPad = V; } |
| 548 |
|
| 549 |
bool hasEHPadSuccessor() const; |
| 550 |
|
| 551 |
|
| 552 |
bool isEntryBlock() const; |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
bool isEHScopeEntry() const { return IsEHScopeEntry; } |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
void setIsEHScopeEntry(bool V = true) { IsEHScopeEntry = V; } |
| 561 |
|
| 562 |
|
| 563 |
bool isEHCatchretTarget() const { return IsEHCatchretTarget; } |
| 564 |
|
| 565 |
|
| 566 |
void setIsEHCatchretTarget(bool V = true) { IsEHCatchretTarget = V; } |
| 567 |
|
| 568 |
|
| 569 |
bool isEHFuncletEntry() const { return IsEHFuncletEntry; } |
| 570 |
|
| 571 |
|
| 572 |
void setIsEHFuncletEntry(bool V = true) { IsEHFuncletEntry = V; } |
| 573 |
|
| 574 |
|
| 575 |
bool isCleanupFuncletEntry() const { return IsCleanupFuncletEntry; } |
| 576 |
|
| 577 |
|
| 578 |
void setIsCleanupFuncletEntry(bool V = true) { IsCleanupFuncletEntry = V; } |
| 579 |
|
| 580 |
|
| 581 |
bool isBeginSection() const { return IsBeginSection; } |
| 582 |
|
| 583 |
|
| 584 |
bool isEndSection() const { return IsEndSection; } |
| 585 |
|
| 586 |
void setIsBeginSection(bool V = true) { IsBeginSection = V; } |
| 587 |
|
| 588 |
void setIsEndSection(bool V = true) { IsEndSection = V; } |
| 589 |
|
| 590 |
|
| 591 |
MBBSectionID getSectionID() const { return SectionID; } |
| 592 |
|
| 593 |
|
| 594 |
unsigned getSectionIDNum() const { |
| 595 |
return ((unsigned)MBBSectionID::SectionType::Cold) - |
| 596 |
((unsigned)SectionID.Type) + SectionID.Number; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
void setSectionID(MBBSectionID V) { SectionID = V; } |
| 601 |
|
| 602 |
|
| 603 |
MCSymbol *getEndSymbol() const; |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
bool mayHaveInlineAsmBr() const; |
| 609 |
|
| 610 |
|
| 611 |
bool isInlineAsmBrIndirectTarget() const { |
| 612 |
return IsInlineAsmBrIndirectTarget; |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
void setIsInlineAsmBrIndirectTarget(bool V = true) { |
| 617 |
IsInlineAsmBrIndirectTarget = V; |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
bool isLegalToHoistInto() const; |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
void moveBefore(MachineBasicBlock *NewAfter); |
| 629 |
void moveAfter(MachineBasicBlock *NewBefore); |
| 630 |
|
| 631 |
|
| 632 |
bool sameSection(const MachineBasicBlock *MBB) const { |
| 633 |
return getSectionID() == MBB->getSectionID(); |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
void updateTerminator(MachineBasicBlock *PreviousLayoutSuccessor); |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
void addSuccessor(MachineBasicBlock *Succ, |
| 655 |
BranchProbability Prob = BranchProbability::getUnknown()); |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
void addSuccessorWithoutProb(MachineBasicBlock *Succ); |
| 662 |
|
| 663 |
|
| 664 |
void setSuccProbability(succ_iterator I, BranchProbability Prob); |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
void normalizeSuccProbs() { |
| 672 |
BranchProbability::normalizeProbabilities(Probs.begin(), Probs.end()); |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
void validateSuccProbs() const; |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
void removeSuccessor(MachineBasicBlock *Succ, |
| 684 |
bool NormalizeSuccProbs = false); |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
succ_iterator removeSuccessor(succ_iterator I, |
| 692 |
bool NormalizeSuccProbs = false); |
| 693 |
|
| 694 |
|
| 695 |
void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New); |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
void copySuccessor(MachineBasicBlock *Orig, succ_iterator I); |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
void splitSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New, |
| 707 |
bool NormalizeSuccProbs = false); |
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
void transferSuccessors(MachineBasicBlock *FromMBB); |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB); |
| 717 |
|
| 718 |
|
| 719 |
bool hasSuccessorProbabilities() const { return !Probs.empty(); } |
| 720 |
|
| 721 |
|
| 722 |
bool isPredecessor(const MachineBasicBlock *MBB) const; |
| 723 |
|
| 724 |
|
| 725 |
bool isSuccessor(const MachineBasicBlock *MBB) const; |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const; |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
MachineBasicBlock *getFallThrough(); |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
bool canFallThrough(); |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
iterator getFirstNonPHI(); |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
iterator SkipPHIsAndLabels(iterator I); |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
iterator SkipPHIsLabelsAndDebug(iterator I, bool SkipPseudoOp = true); |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
iterator getFirstTerminator(); |
| 768 |
const_iterator getFirstTerminator() const { |
| 769 |
return const_cast<MachineBasicBlock *>(this)->getFirstTerminator(); |
| 770 |
} |
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
instr_iterator getFirstInstrTerminator(); |
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
iterator getFirstNonDebugInstr(bool SkipPseudoOp = true); |
| 793 |
const_iterator getFirstNonDebugInstr(bool SkipPseudoOp = true) const { |
| 794 |
return const_cast<MachineBasicBlock *>(this)->getFirstNonDebugInstr( |
| 795 |
SkipPseudoOp); |
| 796 |
} |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
iterator getLastNonDebugInstr(bool SkipPseudoOp = true); |
| 815 |
const_iterator getLastNonDebugInstr(bool SkipPseudoOp = true) const { |
| 816 |
return const_cast<MachineBasicBlock *>(this)->getLastNonDebugInstr( |
| 817 |
SkipPseudoOp); |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
bool isReturnBlock() const { |
| 823 |
return !empty() && back().isReturn(); |
| 824 |
} |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
bool isEHScopeReturnBlock() const { |
| 829 |
return !empty() && back().isEHScopeReturn(); |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
MachineBasicBlock *splitAt(MachineInstr &SplitInst, bool UpdateLiveIns = true, |
| 841 |
LiveIntervals *LIS = nullptr); |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
MachineBasicBlock * |
| 849 |
SplitCriticalEdge(MachineBasicBlock *Succ, Pass &P, |
| 850 |
std::vector<SparseBitVector<>> *LiveInSets = nullptr); |
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
bool canSplitCriticalEdge(const MachineBasicBlock *Succ) const; |
| 857 |
|
| 858 |
void pop_front() { Insts.pop_front(); } |
| 859 |
void pop_back() { Insts.pop_back(); } |
| 860 |
void push_back(MachineInstr *MI) { Insts.push_back(MI); } |
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
instr_iterator insert(instr_iterator I, MachineInstr *M); |
| 869 |
|
| 870 |
|
| 871 |
template<typename IT> |
| 872 |
void insert(iterator I, IT S, IT E) { |
| 873 |
assert((I == end() || I->getParent() == this) && |
| 874 |
"iterator points outside of basic block"); |
| 875 |
Insts.insert(I.getInstrIterator(), S, E); |
| 876 |
} |
| 877 |
|
| 878 |
|
| 879 |
iterator insert(iterator I, MachineInstr *MI) { |
| 880 |
assert((I == end() || I->getParent() == this) && |
| 881 |
"iterator points outside of basic block"); |
| 882 |
assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() && |
| 883 |
"Cannot insert instruction with bundle flags"); |
| 884 |
return Insts.insert(I.getInstrIterator(), MI); |
| 885 |
} |
| 886 |
|
| 887 |
|
| 888 |
iterator insertAfter(iterator I, MachineInstr *MI) { |
| 889 |
assert((I == end() || I->getParent() == this) && |
| 890 |
"iterator points outside of basic block"); |
| 891 |
assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() && |
| 892 |
"Cannot insert instruction with bundle flags"); |
| 893 |
return Insts.insertAfter(I.getInstrIterator(), MI); |
| 894 |
} |
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
instr_iterator insertAfterBundle(instr_iterator I, MachineInstr *MI) { |
| 899 |
assert((I == instr_end() || I->getParent() == this) && |
| 900 |
"iterator points outside of basic block"); |
| 901 |
assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() && |
| 902 |
"Cannot insert instruction with bundle flags"); |
| 903 |
while (I->isBundledWithSucc()) |
| 904 |
++I; |
| 905 |
return Insts.insertAfter(I, MI); |
| 906 |
} |
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
instr_iterator erase(instr_iterator I); |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
instr_iterator erase_instr(MachineInstr *I) { |
| 919 |
return erase(instr_iterator(I)); |
| 920 |
} |
| 921 |
|
| 922 |
|
| 923 |
iterator erase(iterator I, iterator E) { |
| 924 |
return Insts.erase(I.getInstrIterator(), E.getInstrIterator()); |
| 925 |
} |
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
iterator erase(iterator I) { |
| 931 |
return erase(I, std::next(I)); |
| 932 |
} |
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
iterator erase(MachineInstr *I) { |
| 939 |
return erase(iterator(I)); |
| 940 |
} |
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
MachineInstr *remove(MachineInstr *I) { |
| 948 |
assert(!I->isBundled() && "Cannot remove bundled instructions"); |
| 949 |
return Insts.remove(instr_iterator(I)); |
| 950 |
} |
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
MachineInstr *remove_instr(MachineInstr *I); |
| 958 |
|
| 959 |
void clear() { |
| 960 |
Insts.clear(); |
| 961 |
} |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
void splice(iterator Where, MachineBasicBlock *Other, iterator From) { |
| 968 |
|
| 969 |
if (Where != From) |
| 970 |
splice(Where, Other, From, std::next(From)); |
| 971 |
} |
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
void splice(iterator Where, MachineBasicBlock *Other, |
| 979 |
iterator From, iterator To) { |
| 980 |
Insts.splice(Where.getInstrIterator(), Other->Insts, |
| 981 |
From.getInstrIterator(), To.getInstrIterator()); |
| 982 |
} |
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
MachineBasicBlock *removeFromParent(); |
| 987 |
|
| 988 |
|
| 989 |
void eraseFromParent(); |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New); |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
void replacePhiUsesWith(MachineBasicBlock *Old, MachineBasicBlock *New); |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
DebugLoc findDebugLoc(instr_iterator MBBI); |
| 1002 |
DebugLoc findDebugLoc(iterator MBBI) { |
| 1003 |
return findDebugLoc(MBBI.getInstrIterator()); |
| 1004 |
} |
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
DebugLoc rfindDebugLoc(reverse_instr_iterator MBBI); |
| 1010 |
DebugLoc rfindDebugLoc(reverse_iterator MBBI) { |
| 1011 |
return rfindDebugLoc(MBBI.getInstrIterator()); |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
DebugLoc findPrevDebugLoc(instr_iterator MBBI); |
| 1017 |
DebugLoc findPrevDebugLoc(iterator MBBI) { |
| 1018 |
return findPrevDebugLoc(MBBI.getInstrIterator()); |
| 1019 |
} |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
DebugLoc rfindPrevDebugLoc(reverse_instr_iterator MBBI); |
| 1025 |
DebugLoc rfindPrevDebugLoc(reverse_iterator MBBI) { |
| 1026 |
return rfindPrevDebugLoc(MBBI.getInstrIterator()); |
| 1027 |
} |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
DebugLoc findBranchDebugLoc(); |
| 1032 |
|
| 1033 |
|
| 1034 |
enum LivenessQueryResult { |
| 1035 |
LQR_Live, |
| 1036 |
LQR_Dead, |
| 1037 |
LQR_Unknown |
| 1038 |
}; |
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI, |
| 1049 |
MCRegister Reg, |
| 1050 |
const_iterator Before, |
| 1051 |
unsigned Neighborhood = 10) const; |
| 1052 |
|
| 1053 |
|
| 1054 |
void dump() const; |
| 1055 |
void print(raw_ostream &OS, const SlotIndexes * = nullptr, |
| 1056 |
bool IsStandalone = true) const; |
| 1057 |
void print(raw_ostream &OS, ModuleSlotTracker &MST, |
| 1058 |
const SlotIndexes * = nullptr, bool IsStandalone = true) const; |
| 1059 |
|
| 1060 |
enum PrintNameFlag { |
| 1061 |
PrintNameIr = (1 << 0), |
| 1062 |
PrintNameAttributes = (1 << 1), |
| 1063 |
}; |
| 1064 |
|
| 1065 |
void printName(raw_ostream &os, unsigned printNameFlags = PrintNameIr, |
| 1066 |
ModuleSlotTracker *moduleSlotTracker = nullptr) const; |
| 1067 |
|
| 1068 |
|
| 1069 |
void printAsOperand(raw_ostream &OS, bool PrintType = true) const; |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
int getNumber() const { return Number; } |
| 1074 |
void setNumber(int N) { Number = N; } |
| 1075 |
|
| 1076 |
|
| 1077 |
MCSymbol *getSymbol() const; |
| 1078 |
|
| 1079 |
|
| 1080 |
MCSymbol *getEHCatchretSymbol() const; |
| 1081 |
|
| 1082 |
Optional<uint64_t> getIrrLoopHeaderWeight() const { |
| 1083 |
return IrrLoopHeaderWeight; |
| 1084 |
} |
| 1085 |
|
| 1086 |
void setIrrLoopHeaderWeight(uint64_t Weight) { |
| 1087 |
IrrLoopHeaderWeight = Weight; |
| 1088 |
} |
| 1089 |
|
| 1090 |
private: |
| 1091 |
|
| 1092 |
probability_iterator getProbabilityIterator(succ_iterator I); |
| 1093 |
const_probability_iterator |
| 1094 |
getProbabilityIterator(const_succ_iterator I) const; |
| 1095 |
|
| 1096 |
friend class MachineBranchProbabilityInfo; |
| 1097 |
friend class MIPrinter; |
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
BranchProbability getSuccProbability(const_succ_iterator Succ) const; |
| 1103 |
|
| 1104 |
|
| 1105 |
friend struct ilist_callback_traits<MachineBasicBlock>; |
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
void addPredecessor(MachineBasicBlock *Pred); |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
void removePredecessor(MachineBasicBlock *Pred); |
| 1118 |
}; |
| 1119 |
|
| 1120 |
raw_ostream& operator<<(raw_ostream &OS, const MachineBasicBlock &MBB); |
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
Printable printMBBReference(const MachineBasicBlock &MBB); |
| 1129 |
|
| 1130 |
|
| 1131 |
struct MBB2NumberFunctor { |
| 1132 |
using argument_type = const MachineBasicBlock *; |
| 1133 |
unsigned operator()(const MachineBasicBlock *MBB) const { |
| 1134 |
return MBB->getNumber(); |
| 1135 |
} |
| 1136 |
}; |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
template <> struct GraphTraits<MachineBasicBlock *> { |
| 1147 |
using NodeRef = MachineBasicBlock *; |
| 1148 |
using ChildIteratorType = MachineBasicBlock::succ_iterator; |
| 1149 |
|
| 1150 |
static NodeRef getEntryNode(MachineBasicBlock *BB) { return BB; } |
| 1151 |
static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); } |
| 1152 |
static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); } |
| 1153 |
}; |
| 1154 |
|
| 1155 |
template <> struct GraphTraits<const MachineBasicBlock *> { |
| 1156 |
using NodeRef = const MachineBasicBlock *; |
| 1157 |
using ChildIteratorType = MachineBasicBlock::const_succ_iterator; |
| 1158 |
|
| 1159 |
static NodeRef getEntryNode(const MachineBasicBlock *BB) { return BB; } |
| 1160 |
static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); } |
| 1161 |
static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); } |
| 1162 |
}; |
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
template <> struct GraphTraits<Inverse<MachineBasicBlock*>> { |
| 1171 |
using NodeRef = MachineBasicBlock *; |
| 1172 |
using ChildIteratorType = MachineBasicBlock::pred_iterator; |
| 1173 |
|
| 1174 |
static NodeRef getEntryNode(Inverse<MachineBasicBlock *> G) { |
| 1175 |
return G.Graph; |
| 1176 |
} |
| 1177 |
|
| 1178 |
static ChildIteratorType child_begin(NodeRef N) { return N->pred_begin(); } |
| 1179 |
static ChildIteratorType child_end(NodeRef N) { return N->pred_end(); } |
| 1180 |
}; |
| 1181 |
|
| 1182 |
template <> struct GraphTraits<Inverse<const MachineBasicBlock*>> { |
| 1183 |
using NodeRef = const MachineBasicBlock *; |
| 1184 |
using ChildIteratorType = MachineBasicBlock::const_pred_iterator; |
| 1185 |
|
| 1186 |
static NodeRef getEntryNode(Inverse<const MachineBasicBlock *> G) { |
| 1187 |
return G.Graph; |
| 1188 |
} |
| 1189 |
|
| 1190 |
static ChildIteratorType child_begin(NodeRef N) { return N->pred_begin(); } |
| 1191 |
static ChildIteratorType child_end(NodeRef N) { return N->pred_end(); } |
| 1192 |
}; |
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
class MachineInstrSpan { |
| 1199 |
MachineBasicBlock &MBB; |
| 1200 |
MachineBasicBlock::iterator I, B, E; |
| 1201 |
|
| 1202 |
public: |
| 1203 |
MachineInstrSpan(MachineBasicBlock::iterator I, MachineBasicBlock *BB) |
| 1204 |
: MBB(*BB), I(I), B(I == MBB.begin() ? MBB.end() : std::prev(I)), |
| 1205 |
E(std::next(I)) { |
| 1206 |
assert(I == BB->end() || I->getParent() == BB); |
| 1207 |
} |
| 1208 |
|
| 1209 |
MachineBasicBlock::iterator begin() { |
| 1210 |
return B == MBB.end() ? MBB.begin() : std::next(B); |
| 1211 |
} |
| 1212 |
MachineBasicBlock::iterator end() { return E; } |
| 1213 |
bool empty() { return begin() == end(); } |
| 1214 |
|
| 1215 |
MachineBasicBlock::iterator getInitial() { return I; } |
| 1216 |
}; |
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
template <typename IterT> |
| 1223 |
inline IterT skipDebugInstructionsForward(IterT It, IterT End, |
| 1224 |
bool SkipPseudoOp = true) { |
| 1225 |
while (It != End && |
| 1226 |
(It->isDebugInstr() || (SkipPseudoOp && It->isPseudoProbe()))) |
| 1227 |
++It; |
| 1228 |
return It; |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
template <class IterT> |
| 1236 |
inline IterT skipDebugInstructionsBackward(IterT It, IterT Begin, |
| 1237 |
bool SkipPseudoOp = true) { |
| 1238 |
while (It != Begin && |
| 1239 |
(It->isDebugInstr() || (SkipPseudoOp && It->isPseudoProbe()))) |
| 1240 |
--It; |
| 1241 |
return It; |
| 1242 |
} |
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
template <typename IterT> |
| 1247 |
inline IterT next_nodbg(IterT It, IterT End, bool SkipPseudoOp = true) { |
| 1248 |
return skipDebugInstructionsForward(std::next(It), End, SkipPseudoOp); |
| 1249 |
} |
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
template <typename IterT> |
| 1254 |
inline IterT prev_nodbg(IterT It, IterT Begin, bool SkipPseudoOp = true) { |
| 1255 |
return skipDebugInstructionsBackward(std::prev(It), Begin, SkipPseudoOp); |
| 1256 |
} |
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
template <typename IterT> |
| 1261 |
inline auto instructionsWithoutDebug(IterT It, IterT End, |
| 1262 |
bool SkipPseudoOp = true) { |
| 1263 |
return make_filter_range(make_range(It, End), [=](const MachineInstr &MI) { |
| 1264 |
return !MI.isDebugInstr() && !(SkipPseudoOp && MI.isPseudoProbe()); |
| 1265 |
}); |
| 1266 |
} |
| 1267 |
|
| 1268 |
} |
| 1269 |
|
| 1270 |
#endif |