41 template <
class Ptr,
class USE_iterator>
42 class PredIterator :
public std::iterator<std::forward_iterator_tag,
43 Ptr, ptrdiff_t, Ptr*, Ptr*> {
45 std::iterator<std::forward_iterator_tag, Ptr, ptrdiff_t, Ptr*, Ptr*>;
49 inline void advancePastNonTerminators() {
52 if (
auto *Inst = dyn_cast<Instruction>(*It))
53 if (Inst->isTerminator())
66 advancePastNonTerminators();
74 assert(!It.atEnd() &&
"pred_iterator out of range!");
75 return cast<Instruction>(*It)->getParent();
80 assert(!It.atEnd() &&
"pred_iterator out of range!");
81 ++It; advancePastNonTerminators();
86 Self tmp = *
this; ++*
this;
return tmp;
92 return It.getOperandNo();
135 template <
class InstructionT,
class BlockT>
138 std::random_access_iterator_tag, BlockT, int,
139 BlockT *, BlockT *> {
150 inline bool index_is_valid(
int Idx) {
153 return Idx >= 0 && (Idx == 0 || Idx <= (int)Inst->getNumSuccessors());
157 class SuccessorProxy {
161 explicit SuccessorProxy(
const Self &It) : It(It) {}
163 SuccessorProxy(
const SuccessorProxy &) =
default;
165 SuccessorProxy &operator=(SuccessorProxy RHS) {
170 SuccessorProxy &operator=(
reference RHS) {
171 It.Inst->setSuccessor(It.Idx, RHS);
175 operator reference()
const {
return *It; }
180 explicit inline SuccIterator(InstructionT *Inst) : Inst(Inst), Idx(0) {}
184 Idx = Inst->getNumSuccessors();
199 inline bool operator==(
const Self &x)
const {
return Idx == x.Idx; }
201 inline BlockT *
operator*()
const {
return Inst->getSuccessor(Idx); }
207 assert(Inst == RHS.Inst &&
"Cannot compare iterators of different blocks!");
208 return Idx < RHS.Idx;
212 assert(Inst == RHS.Inst &&
"Cannot compare iterators of different blocks!");
213 return Idx - RHS.Idx;
217 int NewIdx = Idx + RHS;
218 assert(index_is_valid(NewIdx) &&
"Iterator index out of bound");
230 return SuccessorProxy(TmpIt);
235 assert(Inst &&
"Source not available, if basic block was malformed");
236 return Inst->getParent();
390 return &G.
Graph->getEntryBlock();
396 return &G.
Graph->getEntryBlock();
402 #endif // LLVM_IR_CFG_H
std::string & operator+=(std::string &buffer, StringRef string)
static NodeRef getEntryNode(const BasicBlock *BB)
This class represents lattice values for constants.
iterator_range< succ_iterator > succ_range
static NodeRef getEntryNode(Inverse< BasicBlock *> G)
int operator-(const Self &RHS) const
PredIterator< BasicBlock, Value::user_iterator > pred_iterator
static NodeRef getEntryNode(BasicBlock *BB)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
static ChildIteratorType child_begin(NodeRef N)
int getSuccessorIndex() const
This is used to interface between code that wants to operate on terminator instructions directly...
static ChildIteratorType child_end(NodeRef N)
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
SuccIterator< const Instruction, const BasicBlock > succ_const_iterator
static NodeRef getEntryNode(Inverse< const Function *> G)
SuccIterator(InstructionT *Inst)
PredIterator(Ptr *bb, bool)
static ChildIteratorType child_end(NodeRef N)
iterator_range< const_pred_iterator > pred_const_range
A Use represents the edge between a Value definition and its users.
SuccIterator(InstructionT *Inst, bool)
pointer * operator->() const
bool operator==(const Self &x) const
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
reference operator*() const
static ChildIteratorType child_begin(NodeRef N)
BlockT * operator*() const
iterator_range< succ_const_iterator > succ_const_range
static ChildIteratorType child_end(NodeRef N)
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
static ChildIteratorType child_begin(NodeRef N)
Interval::succ_iterator succ_end(Interval *I)
Use & getUse() const
getUse - Return the operand Use in the predecessor's terminator of the successor. ...
static nodes_iterator nodes_begin(const Function *F)
const BasicBlock & getEntryBlock() const
typename super::reference reference
typename BasicBlock *::UnknownGraphTypeError NodeRef
static NodeRef getEntryNode(Inverse< Function *> G)
LLVM Basic Block Representation.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
iterator_range< pred_iterator > pred_range
Interval::pred_iterator pred_end(Interval *I)
static ChildIteratorType child_end(NodeRef N)
bool pred_empty(const BasicBlock *BB)
static NodeRef getEntryNode(Inverse< const BasicBlock *> G)
bool succ_empty(const Instruction *I)
unsigned getOperandNo() const
getOperandNo - Return the operand number in the predecessor's terminator of the successor.
static nodes_iterator nodes_end(const Function *F)
BlockT * getSource()
Get the source BlockT of this iterator.
Self & operator-=(int RHS)
bool operator<(const Self &RHS) const
static NodeRef getEntryNode(Function *F)
pred_range predecessors(BasicBlock *BB)
A range adaptor for a pair of iterators.
static size_t size(const Function *F)
static NodeRef getEntryNode(const Function *F)
unsigned succ_size(const Instruction *I)
Self & operator+=(int RHS)
BlockT * operator->() const
static ChildIteratorType child_begin(NodeRef N)
SuccIterator< Instruction, BasicBlock > succ_iterator
PredIterator< const BasicBlock, Value::const_user_iterator > const_pred_iterator
typename super::pointer pointer
unsigned pred_size(const BasicBlock *BB)
Get the number of predecessors of BB.
static nodes_iterator nodes_end(Function *F)
bool operator!=(const Self &x) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator==(const Self &x) const
static nodes_iterator nodes_begin(Function *F)
succ_range successors(Instruction *I)
static size_t size(Function *F)
SuccessorProxy operator[](int Offset)