LLVM 20.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"
14
15namespace llvm::sandboxir {
16
17class BasicBlock;
18class Function;
19class Instruction;
20
21/// Iterator for `Instruction`s in a `BasicBlock.
22/// \Returns an sandboxir::Instruction & when derereferenced.
24public:
25 using difference_type = std::ptrdiff_t;
29 using iterator_category = std::bidirectional_iterator_tag;
30
31private:
34 Context *Ctx;
35 pointer getInstr(llvm::BasicBlock::iterator It) const;
36
37public:
38 BBIterator() : BB(nullptr), Ctx(nullptr) {}
40 : BB(BB), It(It), Ctx(Ctx) {}
41 reference operator*() const { return *getInstr(It); }
44 auto Copy = *this;
45 ++*this;
46 return Copy;
47 }
50 auto Copy = *this;
51 --*this;
52 return Copy;
53 }
54 bool operator==(const BBIterator &Other) const {
55 assert(Ctx == Other.Ctx && "BBIterators in different context!");
56 return It == Other.It;
57 }
58 bool operator!=(const BBIterator &Other) const { return !(*this == Other); }
59 /// \Returns the SBInstruction that corresponds to this iterator, or null if
60 /// the instruction is not found in the IR-to-SandboxIR tables.
61 pointer get() const { return getInstr(It); }
62 /// \Returns the parent BB.
64};
65
66/// Contains a list of sandboxir::Instruction's.
67class BasicBlock : public Value {
68 /// Builds a graph that contains all values in \p BB in their original form
69 /// i.e., no vectorization is taking place here.
70 void buildBasicBlockFromLLVMIR(llvm::BasicBlock *LLVMBB);
71 friend class Context; // For `buildBasicBlockFromIR`
72 friend class Instruction; // For LLVM Val.
73
75 : Value(ClassID::Block, BB, SBCtx) {
76 buildBasicBlockFromLLVMIR(BB);
77 }
78
79public:
80 ~BasicBlock() = default;
81 /// For isa/dyn_cast.
82 static bool classof(const Value *From) {
83 return From->getSubclassID() == Value::ClassID::Block;
84 }
85 Function *getParent() const;
87 iterator begin() const;
88 iterator end() const {
89 auto *BB = cast<llvm::BasicBlock>(Val);
90 return iterator(BB, BB->end(), &Ctx);
91 }
92 std::reverse_iterator<iterator> rbegin() const {
93 return std::make_reverse_iterator(end());
94 }
95 std::reverse_iterator<iterator> rend() const {
96 return std::make_reverse_iterator(begin());
97 }
98 Context &getContext() const { return Ctx; }
100 bool empty() const { return begin() == end(); }
101 Instruction &front() const;
102 Instruction &back() const;
103
104#ifndef NDEBUG
105 void verify() const final;
106 void dumpOS(raw_ostream &OS) const final;
107#endif
108};
109
110} // namespace llvm::sandboxir
111
112#endif // LLVM_SANDBOXIR_BASICBLOCK_H
aarch64 promote const
BlockVerifier::State From
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:177
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
Iterator for Instructions in a `BasicBlock.
Definition: BasicBlock.h:23
BasicBlock * getNodeParent() const
\Returns the parent BB.
Definition: BasicBlock.cpp:43
BBIterator operator++(int)
Definition: BasicBlock.h:43
bool operator!=(const BBIterator &Other) const
Definition: BasicBlock.h:58
BBIterator operator--(int)
Definition: BasicBlock.h:49
pointer get() const
\Returns the SBInstruction that corresponds to this iterator, or null if the instruction is not found...
Definition: BasicBlock.h:61
reference operator*() const
Definition: BasicBlock.h:41
std::bidirectional_iterator_tag iterator_category
Definition: BasicBlock.h:29
std::ptrdiff_t difference_type
Definition: BasicBlock.h:25
BBIterator(llvm::BasicBlock *BB, llvm::BasicBlock::iterator It, Context *Ctx)
Definition: BasicBlock.h:39
bool operator==(const BBIterator &Other) const
Definition: BasicBlock.h:54
Contains a list of sandboxir::Instruction's.
Definition: BasicBlock.h:67
std::reverse_iterator< iterator > rbegin() const
Definition: BasicBlock.h:92
static bool classof(const Value *From)
For isa/dyn_cast.
Definition: BasicBlock.h:82
Function * getParent() const
Definition: BasicBlock.cpp:53
void verify() const final
Should crash if there is something wrong with the instruction.
Definition: BasicBlock.cpp:156
Instruction & back() const
Definition: BasicBlock.cpp:112
std::reverse_iterator< iterator > rend() const
Definition: BasicBlock.h:95
Instruction * getTerminator() const
Definition: BasicBlock.cpp:98
Instruction & front() const
Definition: BasicBlock.cpp:104
iterator begin() const
Definition: BasicBlock.cpp:84
Context & getContext() const
Definition: BasicBlock.h:98
iterator end() const
Definition: BasicBlock.h:88
void dumpOS(raw_ostream &OS) const final
Definition: BasicBlock.cpp:121
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Definition: Instruction.h:42
A SandboxIR Value has users. This is the base class.
Definition: Value.h:63
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition: Value.h:103
Context & Ctx
All values point to the context.
Definition: Value.h:172
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
@ Other
Any other memory.