LLVM 17.0.0git
BasicBlock.h
Go to the documentation of this file.
1//===- llvm/BasicBlock.h - Represent a basic block in the VM ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the declaration of the BasicBlock class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_IR_BASICBLOCK_H
14#define LLVM_IR_BASICBLOCK_H
15
16#include "llvm-c/Types.h"
17#include "llvm/ADT/Twine.h"
18#include "llvm/ADT/ilist.h"
19#include "llvm/ADT/ilist_node.h"
20#include "llvm/ADT/iterator.h"
22#include "llvm/IR/Instruction.h"
24#include "llvm/IR/Value.h"
25#include <cassert>
26#include <cstddef>
27#include <iterator>
28
29namespace llvm {
30
31class AssemblyAnnotationWriter;
32class CallInst;
33class Function;
34class LandingPadInst;
35class LLVMContext;
36class Module;
37class PHINode;
38class ValueSymbolTable;
39
40/// LLVM Basic Block Representation
41///
42/// This represents a single basic block in LLVM. A basic block is simply a
43/// container of instructions that execute sequentially. Basic blocks are Values
44/// because they are referenced by instructions such as branches and switch
45/// tables. The type of a BasicBlock is "Type::LabelTy" because the basic block
46/// represents a label to which a branch can jump.
47///
48/// A well formed basic block is formed of a list of non-terminating
49/// instructions followed by a single terminator instruction. Terminator
50/// instructions may not occur in the middle of basic blocks, and must terminate
51/// the blocks. The BasicBlock class allows malformed basic blocks to occur
52/// because it may be useful in the intermediate stage of constructing or
53/// modifying a program. However, the verifier will ensure that basic blocks are
54/// "well formed".
55class BasicBlock final : public Value, // Basic blocks are data objects also
56 public ilist_node_with_parent<BasicBlock, Function> {
57public:
59
60private:
61 friend class BlockAddress;
63
64 InstListType InstList;
65 Function *Parent;
66
67 void setParent(Function *parent);
68
69 /// Constructor.
70 ///
71 /// If the function parameter is specified, the basic block is automatically
72 /// inserted at either the end of the function (if InsertBefore is null), or
73 /// before the specified basic block.
74 explicit BasicBlock(LLVMContext &C, const Twine &Name = "",
75 Function *Parent = nullptr,
76 BasicBlock *InsertBefore = nullptr);
77
78public:
79 BasicBlock(const BasicBlock &) = delete;
80 BasicBlock &operator=(const BasicBlock &) = delete;
82
83 /// Get the context in which this basic block lives.
84 LLVMContext &getContext() const;
85
86 /// Instruction iterators...
91
92 // These functions and classes need access to the instruction list.
98 friend class llvm::ilist_node_with_parent<llvm::Instruction, llvm::BasicBlock>;
99
100 /// Creates a new BasicBlock.
101 ///
102 /// If the Parent parameter is specified, the basic block is automatically
103 /// inserted at either the end of the function (if InsertBefore is 0), or
104 /// before the specified basic block.
105 static BasicBlock *Create(LLVMContext &Context, const Twine &Name = "",
106 Function *Parent = nullptr,
107 BasicBlock *InsertBefore = nullptr) {
108 return new BasicBlock(Context, Name, Parent, InsertBefore);
109 }
110
111 /// Return the enclosing method, or null if none.
112 const Function *getParent() const { return Parent; }
113 Function *getParent() { return Parent; }
114
115 /// Return the module owning the function this basic block belongs to, or
116 /// nullptr if the function does not have a module.
117 ///
118 /// Note: this is undefined behavior if the block does not have a parent.
119 const Module *getModule() const;
121 return const_cast<Module *>(
122 static_cast<const BasicBlock *>(this)->getModule());
123 }
124
125 /// Returns the terminator instruction if the block is well formed or null
126 /// if the block is not well formed.
128 if (InstList.empty() || !InstList.back().isTerminator())
129 return nullptr;
130 return &InstList.back();
131 }
133 return const_cast<Instruction *>(
134 static_cast<const BasicBlock *>(this)->getTerminator());
135 }
136
137 /// Returns the call instruction calling \@llvm.experimental.deoptimize
138 /// prior to the terminating return instruction of this basic block, if such
139 /// a call is present. Otherwise, returns null.
142 return const_cast<CallInst *>(
143 static_cast<const BasicBlock *>(this)->getTerminatingDeoptimizeCall());
144 }
145
146 /// Returns the call instruction calling \@llvm.experimental.deoptimize
147 /// that is present either in current basic block or in block that is a unique
148 /// successor to current block, if such call is present. Otherwise, returns null.
151 return const_cast<CallInst *>(
152 static_cast<const BasicBlock *>(this)->getPostdominatingDeoptimizeCall());
153 }
154
155 /// Returns the call instruction marked 'musttail' prior to the terminating
156 /// return instruction of this basic block, if such a call is present.
157 /// Otherwise, returns null.
160 return const_cast<CallInst *>(
161 static_cast<const BasicBlock *>(this)->getTerminatingMustTailCall());
162 }
163
164 /// Returns a pointer to the first instruction in this block that is not a
165 /// PHINode instruction.
166 ///
167 /// When adding instructions to the beginning of the basic block, they should
168 /// be added before the returned value, not before the first instruction,
169 /// which might be PHI. Returns 0 is there's no non-PHI instruction.
170 const Instruction* getFirstNonPHI() const;
172 return const_cast<Instruction *>(
173 static_cast<const BasicBlock *>(this)->getFirstNonPHI());
174 }
175
176 /// Returns a pointer to the first instruction in this block that is not a
177 /// PHINode or a debug intrinsic, or any pseudo operation if \c SkipPseudoOp
178 /// is true.
179 const Instruction *getFirstNonPHIOrDbg(bool SkipPseudoOp = true) const;
180 Instruction *getFirstNonPHIOrDbg(bool SkipPseudoOp = true) {
181 return const_cast<Instruction *>(
182 static_cast<const BasicBlock *>(this)->getFirstNonPHIOrDbg(
183 SkipPseudoOp));
184 }
185
186 /// Returns a pointer to the first instruction in this block that is not a
187 /// PHINode, a debug intrinsic, or a lifetime intrinsic, or any pseudo
188 /// operation if \c SkipPseudoOp is true.
189 const Instruction *
190 getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp = true) const;
191 Instruction *getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp = true) {
192 return const_cast<Instruction *>(
193 static_cast<const BasicBlock *>(this)->getFirstNonPHIOrDbgOrLifetime(
194 SkipPseudoOp));
195 }
196
197 /// Returns an iterator to the first instruction in this block that is
198 /// suitable for inserting a non-PHI instruction.
199 ///
200 /// In particular, it skips all PHIs and LandingPad instructions.
203 return static_cast<const BasicBlock *>(this)
204 ->getFirstInsertionPt().getNonConst();
205 }
206
207 /// Returns an iterator to the first instruction in this block that is
208 /// not a PHINode, a debug intrinsic, a static alloca or any pseudo operation.
211 return static_cast<const BasicBlock *>(this)
213 .getNonConst();
214 }
215
216 /// Returns the first potential AsynchEH faulty instruction
217 /// currently it checks for loads/stores (which may dereference a null
218 /// pointer) and calls/invokes (which may propagate exceptions)
219 const Instruction* getFirstMayFaultInst() const;
221 return const_cast<Instruction*>(
222 static_cast<const BasicBlock*>(this)->getFirstMayFaultInst());
223 }
224
225 /// Return a const iterator range over the instructions in the block, skipping
226 /// any debug instructions. Skip any pseudo operations as well if \c
227 /// SkipPseudoOp is true.
229 std::function<bool(const Instruction &)>>>
230 instructionsWithoutDebug(bool SkipPseudoOp = true) const;
231
232 /// Return an iterator range over the instructions in the block, skipping any
233 /// debug instructions. Skip and any pseudo operations as well if \c
234 /// SkipPseudoOp is true.
237 instructionsWithoutDebug(bool SkipPseudoOp = true);
238
239 /// Return the size of the basic block ignoring debug instructions
241 std::function<bool(const Instruction &)>>::difference_type
242 sizeWithoutDebug() const;
243
244 /// Unlink 'this' from the containing function, but do not delete it.
245 void removeFromParent();
246
247 /// Unlink 'this' from the containing function and delete it.
248 ///
249 // \returns an iterator pointing to the element after the erased one.
251
252 /// Unlink this basic block from its current function and insert it into
253 /// the function that \p MovePos lives in, right before \p MovePos.
254 inline void moveBefore(BasicBlock *MovePos) {
255 moveBefore(MovePos->getIterator());
256 }
258
259 /// Unlink this basic block from its current function and insert it
260 /// right after \p MovePos in the function \p MovePos lives in.
261 void moveAfter(BasicBlock *MovePos);
262
263 /// Insert unlinked basic block into a function.
264 ///
265 /// Inserts an unlinked basic block into \c Parent. If \c InsertBefore is
266 /// provided, inserts before that basic block, otherwise inserts at the end.
267 ///
268 /// \pre \a getParent() is \c nullptr.
269 void insertInto(Function *Parent, BasicBlock *InsertBefore = nullptr);
270
271 /// Return the predecessor of this block if it has a single predecessor
272 /// block. Otherwise return a null pointer.
273 const BasicBlock *getSinglePredecessor() const;
275 return const_cast<BasicBlock *>(
276 static_cast<const BasicBlock *>(this)->getSinglePredecessor());
277 }
278
279 /// Return the predecessor of this block if it has a unique predecessor
280 /// block. Otherwise return a null pointer.
281 ///
282 /// Note that unique predecessor doesn't mean single edge, there can be
283 /// multiple edges from the unique predecessor to this block (for example a
284 /// switch statement with multiple cases having the same destination).
285 const BasicBlock *getUniquePredecessor() const;
287 return const_cast<BasicBlock *>(
288 static_cast<const BasicBlock *>(this)->getUniquePredecessor());
289 }
290
291 /// Return true if this block has exactly N predecessors.
292 bool hasNPredecessors(unsigned N) const;
293
294 /// Return true if this block has N predecessors or more.
295 bool hasNPredecessorsOrMore(unsigned N) const;
296
297 /// Return the successor of this block if it has a single successor.
298 /// Otherwise return a null pointer.
299 ///
300 /// This method is analogous to getSinglePredecessor above.
301 const BasicBlock *getSingleSuccessor() const;
303 return const_cast<BasicBlock *>(
304 static_cast<const BasicBlock *>(this)->getSingleSuccessor());
305 }
306
307 /// Return the successor of this block if it has a unique successor.
308 /// Otherwise return a null pointer.
309 ///
310 /// This method is analogous to getUniquePredecessor above.
311 const BasicBlock *getUniqueSuccessor() const;
313 return const_cast<BasicBlock *>(
314 static_cast<const BasicBlock *>(this)->getUniqueSuccessor());
315 }
316
317 /// Print the basic block to an output stream with an optional
318 /// AssemblyAnnotationWriter.
319 void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW = nullptr,
320 bool ShouldPreserveUseListOrder = false,
321 bool IsForDebug = false) const;
322
323 //===--------------------------------------------------------------------===//
324 /// Instruction iterator methods
325 ///
326 inline iterator begin() { return InstList.begin(); }
327 inline const_iterator begin() const { return InstList.begin(); }
328 inline iterator end () { return InstList.end(); }
329 inline const_iterator end () const { return InstList.end(); }
330
331 inline reverse_iterator rbegin() { return InstList.rbegin(); }
332 inline const_reverse_iterator rbegin() const { return InstList.rbegin(); }
333 inline reverse_iterator rend () { return InstList.rend(); }
334 inline const_reverse_iterator rend () const { return InstList.rend(); }
335
336 inline size_t size() const { return InstList.size(); }
337 inline bool empty() const { return InstList.empty(); }
338 inline const Instruction &front() const { return InstList.front(); }
339 inline Instruction &front() { return InstList.front(); }
340 inline const Instruction &back() const { return InstList.back(); }
341 inline Instruction &back() { return InstList.back(); }
342
343 /// Iterator to walk just the phi nodes in the basic block.
344 template <typename PHINodeT = PHINode, typename BBIteratorT = iterator>
346 : public iterator_facade_base<phi_iterator_impl<PHINodeT, BBIteratorT>,
347 std::forward_iterator_tag, PHINodeT> {
348 friend BasicBlock;
349
350 PHINodeT *PN;
351
352 phi_iterator_impl(PHINodeT *PN) : PN(PN) {}
353
354 public:
355 // Allow default construction to build variables, but this doesn't build
356 // a useful iterator.
357 phi_iterator_impl() = default;
358
359 // Allow conversion between instantiations where valid.
360 template <typename PHINodeU, typename BBIteratorU,
361 typename = std::enable_if_t<
362 std::is_convertible<PHINodeU *, PHINodeT *>::value>>
364 : PN(Arg.PN) {}
365
366 bool operator==(const phi_iterator_impl &Arg) const { return PN == Arg.PN; }
367
368 PHINodeT &operator*() const { return *PN; }
369
370 using phi_iterator_impl::iterator_facade_base::operator++;
372 assert(PN && "Cannot increment the end iterator!");
373 PN = dyn_cast<PHINodeT>(std::next(BBIteratorT(PN)));
374 return *this;
375 }
376 };
380
381 /// Returns a range that iterates over the phis in the basic block.
382 ///
383 /// Note that this cannot be used with basic blocks that have no terminator.
385 return const_cast<BasicBlock *>(this)->phis();
386 }
388
389private:
390 /// Return the underlying instruction list container.
391 /// This is deliberately private because we have implemented an adequate set
392 /// of functions to modify the list, including BasicBlock::splice(),
393 /// BasicBlock::erase(), Instruction::insertInto() etc.
394 const InstListType &getInstList() const { return InstList; }
395 InstListType &getInstList() { return InstList; }
396
397 /// Returns a pointer to a member of the instruction list.
398 /// This is private on purpose, just like `getInstList()`.
399 static InstListType BasicBlock::*getSublistAccess(Instruction *) {
400 return &BasicBlock::InstList;
401 }
402
403public:
404 /// Returns a pointer to the symbol table if one exists.
405 ValueSymbolTable *getValueSymbolTable();
406
407 /// Methods for support type inquiry through isa, cast, and dyn_cast.
408 static bool classof(const Value *V) {
409 return V->getValueID() == Value::BasicBlockVal;
410 }
411
412 /// Cause all subinstructions to "let go" of all the references that said
413 /// subinstructions are maintaining.
414 ///
415 /// This allows one to 'delete' a whole class at a time, even though there may
416 /// be circular references... first all references are dropped, and all use
417 /// counts go to zero. Then everything is delete'd for real. Note that no
418 /// operations are valid on an object that has "dropped all references",
419 /// except operator delete.
420 void dropAllReferences();
421
422 /// Update PHI nodes in this BasicBlock before removal of predecessor \p Pred.
423 /// Note that this function does not actually remove the predecessor.
424 ///
425 /// If \p KeepOneInputPHIs is true then don't remove PHIs that are left with
426 /// zero or one incoming values, and don't simplify PHIs with all incoming
427 /// values the same.
428 void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs = false);
429
430 bool canSplitPredecessors() const;
431
432 /// Split the basic block into two basic blocks at the specified instruction.
433 ///
434 /// If \p Before is true, splitBasicBlockBefore handles the
435 /// block splitting. Otherwise, execution proceeds as described below.
436 ///
437 /// Note that all instructions BEFORE the specified iterator
438 /// stay as part of the original basic block, an unconditional branch is added
439 /// to the original BB, and the rest of the instructions in the BB are moved
440 /// to the new BB, including the old terminator. The newly formed basic block
441 /// is returned. This function invalidates the specified iterator.
442 ///
443 /// Note that this only works on well formed basic blocks (must have a
444 /// terminator), and \p 'I' must not be the end of instruction list (which
445 /// would cause a degenerate basic block to be formed, having a terminator
446 /// inside of the basic block).
447 ///
448 /// Also note that this doesn't preserve any passes. To split blocks while
449 /// keeping loop information consistent, use the SplitBlock utility function.
450 BasicBlock *splitBasicBlock(iterator I, const Twine &BBName = "",
451 bool Before = false);
453 bool Before = false) {
454 return splitBasicBlock(I->getIterator(), BBName, Before);
455 }
456
457 /// Split the basic block into two basic blocks at the specified instruction
458 /// and insert the new basic blocks as the predecessor of the current block.
459 ///
460 /// This function ensures all instructions AFTER and including the specified
461 /// iterator \p I are part of the original basic block. All Instructions
462 /// BEFORE the iterator \p I are moved to the new BB and an unconditional
463 /// branch is added to the new BB. The new basic block is returned.
464 ///
465 /// Note that this only works on well formed basic blocks (must have a
466 /// terminator), and \p 'I' must not be the end of instruction list (which
467 /// would cause a degenerate basic block to be formed, having a terminator
468 /// inside of the basic block). \p 'I' cannot be a iterator for a PHINode
469 /// with multiple incoming blocks.
470 ///
471 /// Also note that this doesn't preserve any passes. To split blocks while
472 /// keeping loop information consistent, use the SplitBlockBefore utility
473 /// function.
474 BasicBlock *splitBasicBlockBefore(iterator I, const Twine &BBName = "");
476 return splitBasicBlockBefore(I->getIterator(), BBName);
477 }
478
479 /// Transfer all instructions from \p FromBB to this basic block at \p ToIt.
481 splice(ToIt, FromBB, FromBB->begin(), FromBB->end());
482 }
483
484 /// Transfer one instruction from \p FromBB at \p FromIt to this basic block
485 /// at \p ToIt.
487 BasicBlock::iterator FromIt) {
488 auto FromItNext = std::next(FromIt);
489 // Single-element splice is a noop if destination == source.
490 if (ToIt == FromIt || ToIt == FromItNext)
491 return;
492 splice(ToIt, FromBB, FromIt, FromItNext);
493 }
494
495 /// Transfer a range of instructions that belong to \p FromBB from \p
496 /// FromBeginIt to \p FromEndIt, to this basic block at \p ToIt.
497 void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB,
498 BasicBlock::iterator FromBeginIt,
499 BasicBlock::iterator FromEndIt);
500
501 /// Erases a range of instructions from \p FromIt to (not including) \p ToIt.
502 /// \Returns \p ToIt.
504
505 /// Returns true if there are any uses of this basic block other than
506 /// direct branches, switches, etc. to it.
507 bool hasAddressTaken() const {
508 return getBasicBlockBits().BlockAddressRefCount != 0;
509 }
510
511 /// Update all phi nodes in this basic block to refer to basic block \p New
512 /// instead of basic block \p Old.
514
515 /// Update all phi nodes in this basic block's successors to refer to basic
516 /// block \p New instead of basic block \p Old.
518
519 /// Update all phi nodes in this basic block's successors to refer to basic
520 /// block \p New instead of to it.
522
523 /// Return true if this basic block is an exception handling block.
524 bool isEHPad() const { return getFirstNonPHI()->isEHPad(); }
525
526 /// Return true if this basic block is a landing pad.
527 ///
528 /// Being a ``landing pad'' means that the basic block is the destination of
529 /// the 'unwind' edge of an invoke instruction.
530 bool isLandingPad() const;
531
532 /// Return the landingpad instruction associated with the landing pad.
533 const LandingPadInst *getLandingPadInst() const;
535 return const_cast<LandingPadInst *>(
536 static_cast<const BasicBlock *>(this)->getLandingPadInst());
537 }
538
539 /// Return true if it is legal to hoist instructions into this block.
540 bool isLegalToHoistInto() const;
541
542 /// Return true if this is the entry block of the containing function.
543 /// This method can only be used on blocks that have a parent function.
544 bool isEntryBlock() const;
545
546 std::optional<uint64_t> getIrrLoopHeaderWeight() const;
547
548 /// Returns true if the Order field of child Instructions is valid.
549 bool isInstrOrderValid() const {
550 return getBasicBlockBits().InstrOrderValid;
551 }
552
553 /// Mark instruction ordering invalid. Done on every instruction insert.
556 BasicBlockBits Bits = getBasicBlockBits();
557 Bits.InstrOrderValid = false;
558 setBasicBlockBits(Bits);
559 }
560
561 /// Renumber instructions and mark the ordering as valid.
563
564 /// Asserts that instruction order numbers are marked invalid, or that they
565 /// are in ascending order. This is constant time if the ordering is invalid,
566 /// and linear in the number of instructions if the ordering is valid. Callers
567 /// should be careful not to call this in ways that make common operations
568 /// O(n^2). For example, it takes O(n) time to assign order numbers to
569 /// instructions, so the order should be validated no more than once after
570 /// each ordering to ensure that transforms have the same algorithmic
571 /// complexity when asserts are enabled as when they are disabled.
572 void validateInstrOrdering() const;
573
574private:
575#if defined(_AIX) && (!defined(__GNUC__) || defined(__clang__))
576// Except for GCC; by default, AIX compilers store bit-fields in 4-byte words
577// and give the `pack` pragma push semantics.
578#define BEGIN_TWO_BYTE_PACK() _Pragma("pack(2)")
579#define END_TWO_BYTE_PACK() _Pragma("pack(pop)")
580#else
581#define BEGIN_TWO_BYTE_PACK()
582#define END_TWO_BYTE_PACK()
583#endif
584
586 /// Bitfield to help interpret the bits in Value::SubclassData.
587 struct BasicBlockBits {
588 unsigned short BlockAddressRefCount : 15;
589 unsigned short InstrOrderValid : 1;
590 };
592
593#undef BEGIN_TWO_BYTE_PACK
594#undef END_TWO_BYTE_PACK
595
596 /// Safely reinterpret the subclass data bits to a more useful form.
597 BasicBlockBits getBasicBlockBits() const {
598 static_assert(sizeof(BasicBlockBits) == sizeof(unsigned short),
599 "too many bits for Value::SubclassData");
600 unsigned short ValueData = getSubclassDataFromValue();
601 BasicBlockBits AsBits;
602 memcpy(&AsBits, &ValueData, sizeof(AsBits));
603 return AsBits;
604 }
605
606 /// Reinterpret our subclass bits and store them back into Value.
607 void setBasicBlockBits(BasicBlockBits AsBits) {
608 unsigned short D;
609 memcpy(&D, &AsBits, sizeof(D));
611 }
612
613 /// Increment the internal refcount of the number of BlockAddresses
614 /// referencing this BasicBlock by \p Amt.
615 ///
616 /// This is almost always 0, sometimes one possibly, but almost never 2, and
617 /// inconceivably 3 or more.
618 void AdjustBlockAddressRefCount(int Amt) {
619 BasicBlockBits Bits = getBasicBlockBits();
620 Bits.BlockAddressRefCount += Amt;
621 setBasicBlockBits(Bits);
622 assert(Bits.BlockAddressRefCount < 255 && "Refcount wrap-around");
623 }
624
625 /// Shadow Value::setValueSubclassData with a private forwarding method so
626 /// that any future subclasses cannot accidentally use it.
627 void setValueSubclassData(unsigned short D) {
629 }
630};
631
632// Create wrappers for C Binding types (see CBindingWrapping.h).
634
635/// Advance \p It while it points to a debug instruction and return the result.
636/// This assumes that \p It is not at the end of a block.
638
639#ifdef NDEBUG
640/// In release builds, this is a no-op. For !NDEBUG builds, the checks are
641/// implemented in the .cpp file to avoid circular header deps.
642inline void BasicBlock::validateInstrOrdering() const {}
643#endif
644
645} // end namespace llvm
646
647#endif // LLVM_IR_BASICBLOCK_H
aarch64 promote const
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
#define LLVM_READONLY
Definition: Compiler.h:196
std::string Name
#define I(x, y, z)
Definition: MD5.cpp:58
Machine Check Debug Module
LLVMContext & Context
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
#define END_TWO_BYTE_PACK()
#define BEGIN_TWO_BYTE_PACK()
Iterator to walk just the phi nodes in the basic block.
Definition: BasicBlock.h:347
bool operator==(const phi_iterator_impl &Arg) const
Definition: BasicBlock.h:366
phi_iterator_impl(const phi_iterator_impl< PHINodeU, BBIteratorU > &Arg)
Definition: BasicBlock.h:363
phi_iterator_impl & operator++()
Definition: BasicBlock.h:371
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
BasicBlock::iterator erase(BasicBlock::iterator FromIt, BasicBlock::iterator ToIt)
Erases a range of instructions from FromIt to (not including) ToIt.
Definition: BasicBlock.cpp:490
void replaceSuccessorsPhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block's successors to refer to basic block New instead of basic bl...
Definition: BasicBlock.cpp:506
BasicBlock(const BasicBlock &)=delete
iterator end()
Definition: BasicBlock.h:328
Instruction * getFirstMayFaultInst()
Definition: BasicBlock.h:220
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:326
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:384
const_iterator begin() const
Definition: BasicBlock.h:327
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
Definition: BasicBlock.cpp:525
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Definition: BasicBlock.cpp:253
SymbolTableList< Instruction > InstListType
Definition: BasicBlock.h:58
reverse_iterator rbegin()
Definition: BasicBlock.h:331
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast.
Definition: BasicBlock.h:408
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
Definition: BasicBlock.cpp:548
iterator_range< filter_iterator< BasicBlock::const_iterator, std::function< bool(const Instruction &)> > > instructionsWithoutDebug(bool SkipPseudoOp=true) const
Return a const iterator range over the instructions in the block, skipping any debug instructions.
Definition: BasicBlock.cpp:103
bool empty() const
Definition: BasicBlock.h:337
BasicBlock * splitBasicBlock(Instruction *I, const Twine &BBName="", bool Before=false)
Definition: BasicBlock.h:452
BasicBlock * splitBasicBlockBefore(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction and insert the new basic blo...
Definition: BasicBlock.cpp:440
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
Definition: BasicBlock.h:507
BasicBlock * splitBasicBlockBefore(Instruction *I, const Twine &BBName="")
Definition: BasicBlock.h:475
void invalidateOrders()
Mark instruction ordering invalid. Done on every instruction insert.
Definition: BasicBlock.h:554
friend void Instruction::removeFromParent()
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the basic block to an output stream with an optional AssemblyAnnotationWriter.
Definition: AsmWriter.cpp:4601
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:88
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:216
BasicBlock * getUniqueSuccessor()
Definition: BasicBlock.h:312
const Instruction & front() const
Definition: BasicBlock.h:338
Module * getModule()
Definition: BasicBlock.h:120
Instruction & front()
Definition: BasicBlock.h:339
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:105
BasicBlock * getSingleSuccessor()
Definition: BasicBlock.h:302
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
Definition: BasicBlock.cpp:403
ValueSymbolTable * getValueSymbolTable()
Returns a pointer to the symbol table if one exists.
Definition: BasicBlock.cpp:29
BasicBlock * getUniquePredecessor()
Definition: BasicBlock.h:286
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
Definition: BasicBlock.cpp:140
bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
Definition: BasicBlock.cpp:314
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:409
BasicBlock * getSinglePredecessor()
Definition: BasicBlock.h:274
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
Definition: BasicBlock.cpp:330
friend iplist< Instruction >::iterator Instruction::eraseFromParent()
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
Definition: BasicBlock.cpp:292
std::optional< uint64_t > getIrrLoopHeaderWeight() const
Definition: BasicBlock.cpp:529
Instruction * getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp=true)
Definition: BasicBlock.h:191
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
Definition: BasicBlock.cpp:180
Instruction & back()
Definition: BasicBlock.h:341
InstListType::reverse_iterator reverse_iterator
Definition: BasicBlock.h:89
void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block to refer to basic block New instead of basic block Old.
Definition: BasicBlock.cpp:495
const Instruction * getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic,...
Definition: BasicBlock.cpp:237
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
Definition: BasicBlock.cpp:300
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:322
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB, BasicBlock::iterator FromIt)
Transfer one instruction from FromBB at FromIt to this basic block at ToIt.
Definition: BasicBlock.h:486
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:112
Function * getParent()
Definition: BasicBlock.h:113
const_reverse_iterator rend() const
Definition: BasicBlock.h:334
reverse_iterator rend()
Definition: BasicBlock.h:333
void validateInstrOrdering() const
Asserts that instruction order numbers are marked invalid, or that they are in ascending order.
Definition: BasicBlock.cpp:564
const Instruction * getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
Definition: BasicBlock.cpp:223
filter_iterator< BasicBlock::const_iterator, std::function< bool(constInstruction &)> >::difference_type sizeWithoutDebug() const
Return the size of the basic block ignoring debug instructions.
Definition: BasicBlock.cpp:123
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:87
Instruction * getFirstNonPHI()
Definition: BasicBlock.h:171
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:35
CallInst * getPostdominatingDeoptimizeCall()
Definition: BasicBlock.h:150
const_iterator getFirstNonPHIOrDbgOrAlloca() const
Returns an iterator to the first instruction in this block that is not a PHINode, a debug intrinsic,...
Definition: BasicBlock.cpp:263
Instruction * getTerminator()
Definition: BasicBlock.h:132
BasicBlock & operator=(const BasicBlock &)=delete
iterator getFirstNonPHIOrDbgOrAlloca()
Definition: BasicBlock.h:210
CallInst * getTerminatingDeoptimizeCall()
Definition: BasicBlock.h:141
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
Definition: BasicBlock.cpp:287
size_t size() const
Definition: BasicBlock.h:336
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
Definition: BasicBlock.h:254
bool isLandingPad() const
Return true if this basic block is a landing pad.
Definition: BasicBlock.cpp:521
InstListType::const_reverse_iterator const_reverse_iterator
Definition: BasicBlock.h:90
bool isEHPad() const
Return true if this basic block is an exception handling block.
Definition: BasicBlock.h:524
CallInst * getTerminatingMustTailCall()
Definition: BasicBlock.h:159
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...
Definition: BasicBlock.h:127
bool canSplitPredecessors() const
Definition: BasicBlock.cpp:378
const_iterator end() const
Definition: BasicBlock.h:329
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
Definition: BasicBlock.cpp:149
friend BasicBlock::iterator Instruction::insertInto(BasicBlock *BB, BasicBlock::iterator It)
bool isLegalToHoistInto() const
Return true if it is legal to hoist instructions into this block.
Definition: BasicBlock.cpp:390
Instruction * getFirstNonPHIOrDbg(bool SkipPseudoOp=true)
Definition: BasicBlock.h:180
bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
Definition: BasicBlock.cpp:318
bool isInstrOrderValid() const
Returns true if the Order field of child Instructions is valid.
Definition: BasicBlock.h:549
const CallInst * getPostdominatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize that is present either in current ...
Definition: BasicBlock.cpp:195
const Instruction * getFirstMayFaultInst() const
Returns the first potential AsynchEH faulty instruction currently it checks for loads/stores (which m...
Definition: BasicBlock.cpp:207
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
Definition: BasicBlock.h:480
const_reverse_iterator rbegin() const
Definition: BasicBlock.h:332
LandingPadInst * getLandingPadInst()
Definition: BasicBlock.h:534
const Instruction & back() const
Definition: BasicBlock.h:340
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Definition: BasicBlock.cpp:145
iterator getFirstInsertionPt()
Definition: BasicBlock.h:202
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
Definition: BasicBlock.cpp:349
The address of a basic block.
Definition: Constants.h:874
This class represents a function call, abstracting a target machine's calling convention.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
Definition: Instruction.cpp:78
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:700
SymbolTableList< Instruction >::iterator insertInto(BasicBlock *ParentBB, SymbolTableList< Instruction >::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
Definition: Instruction.cpp:98
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:82
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
The landingpad instruction holds all of the information necessary to generate correct exception handl...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
unsigned short getSubclassDataFromValue() const
Definition: Value.h:854
void setValueSubclassData(unsigned short D)
Definition: Value.h:855
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:589
Iterator for intrusive lists based on ilist_node.
self_iterator getIterator()
Definition: ilist_node.h:82
An ilist node that can access its parent list.
Definition: ilist_node.h:257
base_list_type::const_reverse_iterator const_reverse_iterator
Definition: ilist.h:125
base_list_type::reverse_iterator reverse_iterator
Definition: ilist.h:123
base_list_type::const_iterator const_iterator
Definition: ilist.h:122
base_list_type::iterator iterator
Definition: ilist.h:121
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:80
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
struct LLVMOpaqueBasicBlock * LLVMBasicBlockRef
Represents a basic block of instructions in LLVM IR.
Definition: Types.h:82
This file defines classes to implement an intrusive doubly linked list class (i.e.
This file defines the ilist_node class template, which is a convenient base class for creating classe...
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
BasicBlock::iterator skipDebugIntrinsics(BasicBlock::iterator It)
Advance It while it points to a debug instruction and return the result.
Definition: BasicBlock.cpp:542
#define N