Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
BasicBlock.h
Go to the documentation of this file.
1//===- BasicBlock.h ---------------------------------------------*- 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#ifndef LLVM_SANDBOXIR_BASICBLOCK_H
10#define LLVM_SANDBOXIR_BASICBLOCK_H
11
12#include "llvm/IR/BasicBlock.h"
15
16namespace llvm::sandboxir {
17
18class BasicBlock;
19class Function;
20class Instruction;
21
22/// Iterator for `Instruction`s in a `BasicBlock.
23/// \Returns an sandboxir::Instruction & when derereferenced.
24class BBIterator {
25public:
26 using difference_type = std::ptrdiff_t;
27 using value_type = Instruction;
28 using pointer = value_type *;
29 using reference = value_type &;
30 using iterator_category = std::bidirectional_iterator_tag;
31
32private:
33 llvm::BasicBlock *BB;
35 Context *Ctx;
36 LLVM_ABI pointer getInstr(llvm::BasicBlock::iterator It) const;
37
38public:
39 BBIterator() : BB(nullptr), Ctx(nullptr) {}
40 BBIterator(llvm::BasicBlock *BB, llvm::BasicBlock::iterator It, Context *Ctx)
41 : BB(BB), It(It), Ctx(Ctx) {}
42 reference operator*() const { return *getInstr(It); }
43 LLVM_ABI BBIterator &operator++();
44 BBIterator operator++(int) {
45 auto Copy = *this;
46 ++*this;
47 return Copy;
48 }
49 LLVM_ABI BBIterator &operator--();
50 BBIterator operator--(int) {
51 auto Copy = *this;
52 --*this;
53 return Copy;
54 }
55 bool operator==(const BBIterator &Other) const {
56 assert(Ctx == Other.Ctx && "BBIterators in different context!");
57 return It == Other.It;
58 }
59 bool operator!=(const BBIterator &Other) const { return !(*this == Other); }
60 /// \Returns the SBInstruction that corresponds to this iterator, or null if
61 /// the instruction is not found in the IR-to-SandboxIR tables.
62 pointer get() const { return getInstr(It); }
63 /// \Returns the parent BB.
64 LLVM_ABI BasicBlock *getNodeParent() const;
65};
66
67/// Contains a list of sandboxir::Instruction's.
68class BasicBlock : public Value {
69 /// Builds a graph that contains all values in \p BB in their original form
70 /// i.e., no vectorization is taking place here.
71 LLVM_ABI void buildBasicBlockFromLLVMIR(llvm::BasicBlock *LLVMBB);
72 friend class Context; // For `buildBasicBlockFromIR`
73 friend class Instruction; // For LLVM Val.
74
76 : Value(ClassID::Block, BB, SBCtx) {
77 buildBasicBlockFromLLVMIR(BB);
78 }
79
80public:
81 ~BasicBlock() = default;
82 /// For isa/dyn_cast.
83 static bool classof(const Value *From) {
84 return From->getSubclassID() == Value::ClassID::Block;
85 }
87 using iterator = BBIterator;
89 iterator end() const {
90 auto *BB = cast<llvm::BasicBlock>(Val);
91 return iterator(BB, BB->end(), &Ctx);
92 }
93 std::reverse_iterator<iterator> rbegin() const {
94 return std::make_reverse_iterator(end());
95 }
96 std::reverse_iterator<iterator> rend() const {
97 return std::make_reverse_iterator(begin());
98 }
99 Context &getContext() const { return Ctx; }
101 bool empty() const { return begin() == end(); }
104
105#ifndef NDEBUG
106 void verify() const final;
107 void dumpOS(raw_ostream &OS) const final;
108#endif
109};
110
111} // namespace llvm::sandboxir
112
113#endif // LLVM_SANDBOXIR_BASICBLOCK_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
#define LLVM_ABI
Definition Compiler.h:213
bool operator==(const MergedFunctionsInfo &LHS, const MergedFunctionsInfo &RHS)
LLVM Basic Block Representation.
Definition BasicBlock.h:62
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Definition Instruction.h:43
A SandboxIR Value has users. This is the base class.
Definition Value.h:66
ClassID getSubclassID() const
Definition Value.h:191
ArchKind & operator--(ArchKind &Kind)
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:81
LLVM_ABI Function * getParent() const
bool empty() const
Definition BasicBlock.h:101
Context & getContext() const
Definition BasicBlock.h:99
std::reverse_iterator< iterator > rbegin() const
Definition BasicBlock.h:93
~BasicBlock()=default
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
Definition BasicBlock.h:75
iterator end() const
Definition BasicBlock.h:89
static bool classof(const Value *From)
For isa/dyn_cast.
Definition BasicBlock.h:83
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
LLVM_ABI Instruction & back() const
BBIterator iterator
Definition BasicBlock.h:87
std::reverse_iterator< iterator > rend() const
Definition BasicBlock.h:96
void dumpOS(raw_ostream &OS) const final
void verify() const final
LLVM_ABI iterator begin() const
LLVM_ABI Instruction * getTerminator() const
LLVM_ABI Instruction & front() const
APInt operator*(APInt a, uint64_t RHS)
Definition APInt.h:2235
bool operator!=(uint64_t V1, const APInt &V2)
Definition APInt.h:2113
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565