1//===- BasicBlock.cpp - The BasicBlock class of Sandbox IR ----------------===// 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 7//===----------------------------------------------------------------------===// 18assert(It != ItE &&
"Already at end!");
24assert(Num > 0 &&
"Bad getNumOfIRInstrs()");
25 It = std::next(It, Num - 1);
36unsigned Num = CurrI.getNumOfIRInstrs();
37assert(Num > 0 &&
"Bad getNumOfIRInstrs()");
38assert(std::prev(It, Num - 1) != BB->
begin() &&
"Already at begin!");
39 It = std::prev(It, Num);
45return cast<BasicBlock>(Ctx->
getValue(Parent));
50return cast_or_null<Instruction>(Ctx->
getValue(&*It));
54auto *BB = cast<llvm::BasicBlock>(
Val);
55auto *
F = BB->getParent();
67// Skip instruction's label operands 68if (isa<llvm::BasicBlock>(
Op))
71if (isa<llvm::MetadataAsValue>(
Op))
74if (isa<llvm::InlineAsm>(
Op))
89assert(V !=
nullptr &&
"No SandboxIR for BB->begin()!");
90auto *
I = cast<Instruction>(V);
91unsigned Num =
I->getNumOfIRInstrs();
92assert(Num >= 1u &&
"Bad getNumOfIRInstrs()");
93 It = std::next(It, Num - 1);
101return cast_or_null<Instruction>(TerminatorV);
105auto *BB = cast<llvm::BasicBlock>(
Val);
106assert(!BB->empty() &&
"Empty block!");
107auto *SBI = cast<Instruction>(
getContext().getValue(&*BB->begin()));
108assert(SBI !=
nullptr &&
"Expected Instr!");
113auto *BB = cast<llvm::BasicBlock>(
Val);
114assert(!BB->empty() &&
"Empty block!");
115auto *SBI = cast<Instruction>(
getContext().getValue(&*BB->rbegin()));
116assert(SBI !=
nullptr &&
"Expected Instr!");
127// If there are Instructions in the BB that are not mapped to SandboxIR, then 128// use a crash-proof dump. 132OS <<
"<Crash-proof mode!>\n";
137OS << IRef <<
" *** No SandboxIR ***\n";
139auto *SBI = dyn_cast<Instruction>(SBV);
141OS << IRef <<
" *** Not a SBInstruction!!! ***\n";
143if (Visited.
insert(SBI).second)
149for (
auto &SBI : *
this) {
157assert(isa<llvm::BasicBlock>(
Val) &&
"Expected BasicBlock!");
158for (
constauto &
I : *
this) {
164}
// namespace llvm::sandboxir 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)