34 OrigValueOrBB =
PHI->getIncomingValue(
Idx);
37 OrigValueOrBB =
PHI->getIncomingBlock(
Idx);
43 if (
auto *V = OrigValueOrBB.dyn_cast<
Value *>())
57 :
PHI(
PHI), RemovedIdx(RemovedIdx) {
58 RemovedV =
PHI->getIncomingValue(RemovedIdx);
59 RemovedBB =
PHI->getIncomingBlock(RemovedIdx);
66 if (NumIncoming == 0) {
72 unsigned LastIdx = NumIncoming - 1;
75 for (
unsigned Idx = LastIdx;
Idx > RemovedIdx; --
Idx) {
105 assert(Changes.empty() &&
"You must accept or revert changes!");
109 : ErasedIPtr(
std::
move(ErasedIPtr)) {
110 auto *
I = cast<Instruction>(this->ErasedIPtr.get());
111 auto LLVMInstrs =
I->getLLVMInstrs();
113 for (
auto *LLVMI :
reverse(LLVMInstrs)) {
115 Operands.reserve(LLVMI->getNumOperands());
121 [](
const auto &D0,
const auto &D1) {
122 return D0.LLVMI->comesBefore(D1.LLVMI);
124 "Expected reverse program order!");
125 auto *BotLLVMI = cast<llvm::Instruction>(
I->Val);
126 if (BotLLVMI->getNextNode() !=
nullptr)
127 NextLLVMIOrBB = BotLLVMI->getNextNode();
129 NextLLVMIOrBB = BotLLVMI->getParent();
133 for (
const auto &IData : InstrData)
134 IData.LLVMI->deleteValue();
139 auto [
Operands, BotLLVMI] = InstrData[0];
141 BotLLVMI->insertBefore(NextLLVMI);
147 BotLLVMI->setOperand(OpNum,
Op);
151 LLVMI->insertBefore(BotLLVMI);
153 LLVMI->setOperand(OpNum,
Op);
168 NextInstrOrBB = NextI;
174 if (
auto *NextI = NextInstrOrBB.dyn_cast<
Instruction *>()) {
191 : CallBr(CallBr),
Idx(
Idx) {
206 NextInstrOrBB = NextI;
212 if (
auto *NextI = NextInstrOrBB.dyn_cast<
Instruction *>()) {
252 for (
auto &Change :
reverse(Changes))
253 Change->revert(*
this);
260 for (
auto &Change : Changes)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
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.
void revert(Tracker &Tracker) final
This runs when changes get reverted.
CallBrInstSetIndirectDest(CallBrInst *CallBr, unsigned Idx)
LLVM_DUMP_METHOD void dump() const final
BasicBlock * getIndirectDest(unsigned Idx) const
void setIndirectDest(unsigned Idx, BasicBlock *BB)
Value * registerValue(std::unique_ptr< Value > &&VPtr)
Take ownership of VPtr and store it in LLVMValueToValueMap.
LLVM_DUMP_METHOD void dump() const final
void revert(Tracker &Tracker) final
This runs when changes get reverted.
void accept() final
This runs when changes get accepted.
LLVM_DUMP_METHOD void dump() const final
void revert(Tracker &Tracker) final
This runs when changes get reverted.
EraseFromParent(std::unique_ptr< sandboxir::Value > &&IPtr)
LLVM_DUMP_METHOD void dump() const final
InsertIntoBB(Instruction *InsertedI)
void revert(Tracker &Tracker) final
This runs when changes get reverted.
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
void removeFromParent()
Detach this from its parent BasicBlock without deleting it.
void insertInto(BasicBlock *BB, const BBIterator &WhereIt)
Insert this detached instruction into BB at WhereIt.
void eraseFromParent()
Detach this Value from its parent and delete it.
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
MoveInstr(sandboxir::Instruction *I)
void revert(Tracker &Tracker) final
This runs when changes get reverted.
PHIAddIncoming(PHINode *PHI)
void revert(Tracker &Tracker) final
This runs when changes get reverted.
LLVM_DUMP_METHOD void dump() const final
void setIncomingBlock(unsigned Idx, BasicBlock *BB)
void setIncomingValue(unsigned Idx, Value *V)
unsigned getNumIncomingValues() const
void addIncoming(Value *V, BasicBlock *BB)
Value * removeIncomingValue(unsigned Idx)
BasicBlock * getIncomingBlock(unsigned Idx) const
Value * getIncomingValue(unsigned Idx) const
LLVM_DUMP_METHOD void dump() const final
PHIRemoveIncoming(PHINode *PHI, unsigned RemovedIdx)
void revert(Tracker &Tracker) final
This runs when changes get reverted.
PHISetIncoming(PHINode *PHI, unsigned Idx, What What)
void revert(Tracker &Tracker) final
This runs when changes get reverted.
LLVM_DUMP_METHOD void dump() const final
void revert(Tracker &Tracker) final
This runs when changes get reverted.
RemoveFromParent(Instruction *RemovedI)
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.
void save()
Turns on IR tracking.
Context & getContext() const
void accept()
Stops tracking and accept changes.
LLVM_DUMP_METHOD void dump() const
LLVM_DUMP_METHOD void dump() const final
LLVM_DUMP_METHOD void dump() const final
Represents a Def-use/Use-def edge in SandboxIR.
A SandboxIR Value has users. This is the base class.
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 tuples (A, B,...
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.
Implement std::hash so that hash_code can be used in STL containers.