21 "We are in the middle of creating another change!");
31 return It -
Parent.Changes.begin();
41 assert(Changes.empty() &&
"You must accept or revert changes!");
47 auto *
I = cast<Instruction>(this->ErasedIPtr.get());
48 auto LLVMInstrs =
I->getLLVMInstrs();
50 for (
auto *LLVMI :
reverse(LLVMInstrs)) {
52 Operands.reserve(LLVMI->getNumOperands());
58 [](
const auto &D0,
const auto &D1) {
59 return D0.LLVMI->comesBefore(D1.LLVMI);
61 "Expected reverse program order!");
62 auto *BotLLVMI = cast<llvm::Instruction>(
I->Val);
63 if (BotLLVMI->getNextNode() !=
nullptr)
64 NextLLVMIOrBB = BotLLVMI->getNextNode();
66 NextLLVMIOrBB = BotLLVMI->getParent();
70 for (
const auto &IData : InstrData)
71 IData.LLVMI->deleteValue();
76 auto [
Operands, BotLLVMI] = InstrData[0];
78 BotLLVMI->insertBefore(NextLLVMI);
84 BotLLVMI->setOperand(OpNum,
Op);
88 LLVMI->insertBefore(BotLLVMI);
90 LLVMI->setOperand(OpNum,
Op);
106 NextInstrOrBB = NextI;
112 if (
auto *NextI = NextInstrOrBB.dyn_cast<
Instruction *>()) {
130 NextInstrOrBB = NextI;
136 if (
auto *NextI = NextInstrOrBB.dyn_cast<
Instruction *>()) {
153 Changes.push_back(std::move(Change));
165 for (
auto &Change :
reverse(Changes))
173 for (
auto &Change : Changes)
180 for (
const auto &ChangePtr : Changes) {
mir Rename Register Operands
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Basic Block Representation.
void insertInto(Function *Parent, BasicBlock *InsertBefore=nullptr)
Insert unlinked basic block into a function.
This class represents an Operation in the Expression.
T get() const
Returns the value of the specified pointer type.
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class implements an extremely fast bulk output stream that can only output to a stream.
Contains a list of sandboxir::Instruction's.
Value * registerValue(std::unique_ptr< Value > &&VPtr)
Take ownership of VPtr and store it in LLVMValueToValueMap.
EraseFromParent(std::unique_ptr< sandboxir::Value > &&IPtr, Tracker &Tracker)
void accept() final
This runs when changes get accepted.
LLVM_DUMP_METHOD void dump() const final
void revert() final
This runs when changes get reverted.
The base class for IR Change classes.
IRChangeBase(Tracker &Parent)
unsigned getIdx() const
\Returns the index of this change by iterating over all changes in the tracker.
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
void insertInto(BasicBlock *BB, const BBIterator &WhereIt)
Insert this detached instruction into BB at WhereIt.
Instruction * getNextNode() const
\Returns the next sandboxir::Instruction in the block, or nullptr if at the end of the block.
void moveBefore(BasicBlock &BB, const BBIterator &WhereIt)
Move this instruction to WhereIt.
void insertBefore(Instruction *BeforeI)
Insert this detached instruction before BeforeI.
BasicBlock * getParent() const
\Returns the BasicBlock containing this Instruction, or null if it is detached.
LLVM_DUMP_METHOD void dump() const final
void revert() final
This runs when changes get reverted.
MoveInstr(sandboxir::Instruction *I, Tracker &Tracker)
void revert() final
This runs when changes get reverted.
RemoveFromParent(Instruction *RemovedI, Tracker &Tracker)
LLVM_DUMP_METHOD void dump() const final
The tracker collects all the change objects and implements the main API for saving / reverting / acce...
@ Record
ā€¨Tracking is disabled
void revert()
Stops tracking and reverts to saved state.
bool isTracking() const
\Returns true if the tracker is recording changes.
void save()
Turns on IR tracking.
bool InMiddleOfCreatingChange
Helps catch bugs where we are creating new change objects while in the middle of creating other chang...
Context & getContext() const
void track(std::unique_ptr< IRChangeBase > &&Change)
Record Change and take ownership.
void accept()
Stops tracking and accept changes.
LLVM_DUMP_METHOD void dump() const
LLVM_DUMP_METHOD void dump() const final
Represents a Def-use/Use-def edge in SandboxIR.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
auto reverse(ContainerTy &&C)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.