LLVM: lib/SandboxIR/BasicBlock.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
13
15
17 auto ItE = BB->end();
18 assert(It != ItE && "Already at end!");
19 ++It;
20 if (It == ItE)
21 return *this;
24 assert(Num > 0 && "Bad getNumOfIRInstrs()");
25 It = std::next(It, Num - 1);
26 return *this;
27}
28
30 assert(It != BB->begin() && "Already at begin!");
32 --It;
33 return *this;
34 }
36 unsigned Num = CurrI.getNumOfIRInstrs();
37 assert(Num > 0 && "Bad getNumOfIRInstrs()");
38 assert(std::prev(It, Num - 1) != BB->begin() && "Already at begin!");
39 It = std::prev(It, Num);
40 return *this;
41}
42
45 return cast(Ctx->getValue(Parent));
46}
50 return cast_or_null(Ctx->getValue(&*It));
51}
54 auto *BB = castllvm::BasicBlock(Val);
55 auto *F = BB->getParent();
56 if (F == nullptr)
57
58 return nullptr;
59 return cast_or_null(Ctx.getValue(F));
60}
61
62void BasicBlock::buildBasicBlockFromLLVMIR(llvm::BasicBlock *LLVMBB) {
66 for (auto [OpIdx, Op] : enumerate(I->operands())) {
67
68 if (isallvm::BasicBlock(Op))
69 continue;
70
71 if (isallvm::MetadataAsValue(Op))
72 continue;
73
74 if (isallvm::InlineAsm(Op))
75 continue;
77 }
78 }
79#if !defined(NDEBUG)
81#endif
82}
83
87 if (!BB->empty()) {
89 assert(V != nullptr && "No SandboxIR for BB->begin()!");
90 auto *I = cast(V);
91 unsigned Num = I->getNumOfIRInstrs();
92 assert(Num >= 1u && "Bad getNumOfIRInstrs()");
93 It = std::next(It, Num - 1);
94 }
96}
97
99 auto *TerminatorV =
101 return cast_or_null(TerminatorV);
102}
103
105 auto *BB = castllvm::BasicBlock(Val);
106 assert(!BB->empty() && "Empty block!");
107 auto *SBI = cast(getContext().getValue(&*BB->begin()));
108 assert(SBI != nullptr && "Expected Instr!");
109 return *SBI;
110}
111
113 auto *BB = castllvm::BasicBlock(Val);
114 assert(!BB->empty() && "Empty block!");
115 auto *SBI = cast(getContext().getValue(&*BB->rbegin()));
116 assert(SBI != nullptr && "Expected Instr!");
117 return *SBI;
118}
119
120#ifndef NDEBUG
125 if (.empty())
126 OS << ":\n";
127
128
131 })) {
132 OS << "<Crash-proof mode!>\n";
136 if (SBV == nullptr)
137 OS << IRef << " *** No SandboxIR ***\n";
138 else {
139 auto *SBI = dyn_cast(SBV);
140 if (SBI == nullptr) {
141 OS << IRef << " *** Not a SBInstruction!!! ***\n";
142 } else {
143 if (Visited.insert(SBI).second)
144 OS << *SBI << "\n";
145 }
146 }
147 }
148 } else {
149 for (auto &SBI : *this) {
150 SBI.dumpOS(OS);
151 OS << "\n";
153 }
154}
155
157 assert(isallvm::BasicBlock(Val) && "Expected BasicBlock!");
158 for (const auto &I : *this) {
159 I.verify();
160 }
161}
162#endif
163
164}
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
InstListType::iterator iterator
Instruction iterators...
This class represents an Operation in the Expression.
Implements a dense probed hash-table based set.
StringRef getName() const
Return a constant reference to the value's name.
std::pair< iterator, bool > insert(const ValueT &V)
This class implements an extremely fast bulk output stream that can only output to a stream.
Iterator for Instructions in a `BasicBlock.
BasicBlock * getNodeParent() const
\Returns the parent BB.
BBIterator & operator++()
BBIterator & operator--()
Contains a list of sandboxir::Instruction's.
Function * getParent() const
void verify() const final
Should crash if there is something wrong with the instruction.
Instruction & back() const
Instruction * getTerminator() const
Instruction & front() const
Context & getContext() const
void dumpOS(raw_ostream &OS) const final
sandboxir::Value * getValue(llvm::Value *V) const
Value * getOrCreateValue(llvm::Value *LLVMV)
Get or create a sandboxir::Value for an existing LLVM IR LLVMV.
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
virtual unsigned getNumOfIRInstrs() const =0
This is used by BasicBlock::iterator.
A SandboxIR Value has users. This is the base class.
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Context & Ctx
All values point to the context.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)