24 std::optional<BasicBlock::iterator> AllocaPoint) {
36 Slot =
new AllocaInst(
I.getType(),
DL.getAllocaAddrSpace(),
nullptr,
37 I.getName()+
".reg2mem", *AllocaPoint);
39 Slot =
new AllocaInst(
I.getType(),
DL.getAllocaAddrSpace(),
nullptr,
40 I.getName() +
".reg2mem",
F->getEntryBlock().begin());
47 if (!
II->getNormalDest()->getSinglePredecessor()) {
51 assert(BB &&
"Unable to split critical edge.");
54 }
else if (
CallBrInst *CBI = dyn_cast<CallBrInst>(&
I)) {
55 for (
unsigned i = 0; i < CBI->getNumSuccessors(); i++) {
56 auto *Succ = CBI->getSuccessor(i);
57 if (!Succ->getSinglePredecessor()) {
60 assert(BB &&
"Unable to split critical edge.");
66 while (!
I.use_empty()) {
68 if (
PHINode *PN = dyn_cast<PHINode>(U)) {
79 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
80 if (PN->getIncomingValue(i) == &
I) {
81 Value *&V = Loads[PN->getIncomingBlock(i)];
84 V =
new LoadInst(
I.getType(), Slot,
I.getName() +
".reload",
86 PN->getIncomingBlock(i)->getTerminator()->getIterator());
87 Loads[PN->getIncomingBlock(i)] = V;
89 PN->setIncomingValue(i, V);
95 VolatileLoads, U->getIterator());
96 U->replaceUsesOfWith(&
I, V);
104 if (!
I.isTerminator()) {
105 InsertPt = ++
I.getIterator();
107 for (; isa<PHINode>(InsertPt) || InsertPt->isEHPad(); ++InsertPt)
108 if (isa<CatchSwitchInst>(InsertPt))
110 if (isa<CatchSwitchInst>(InsertPt)) {
112 new StoreInst(&
I, Slot, Handler->getFirstInsertionPt());
116 InsertPt =
II->getNormalDest()->getFirstInsertionPt();
117 }
else if (
CallBrInst *CBI = dyn_cast<CallBrInst>(&
I)) {
119 new StoreInst(CBI, Slot, Succ->getFirstInsertionPt());
133 if (
P->use_empty()) {
134 P->eraseFromParent();
143 Slot =
new AllocaInst(
P->getType(),
DL.getAllocaAddrSpace(),
nullptr,
144 P->getName()+
".reg2mem", *AllocaPoint);
147 Slot =
new AllocaInst(
P->getType(),
DL.getAllocaAddrSpace(),
nullptr,
148 P->getName() +
".reg2mem",
149 F->getEntryBlock().begin());
153 for (
unsigned i = 0, e =
P->getNumIncomingValues(); i < e; ++i) {
154 if (
InvokeInst *
II = dyn_cast<InvokeInst>(
P->getIncomingValue(i))) {
155 assert(
II->getParent() !=
P->getIncomingBlock(i) &&
156 "Invoke edge not supported yet"); (void)
II;
159 P->getIncomingBlock(i)->getTerminator()->getIterator());
165 for (; isa<PHINode>(InsertPt) || InsertPt->isEHPad(); ++InsertPt)
166 if (isa<CatchSwitchInst>(InsertPt))
168 if (isa<CatchSwitchInst>(InsertPt)) {
171 for (
User *U :
P->users()) {
177 new LoadInst(
P->getType(), Slot,
P->getName() +
".reload",
User->getIterator());
182 new LoadInst(
P->getType(), Slot,
P->getName() +
".reload", InsertPt);
183 P->replaceAllUsesWith(V);
186 P->eraseFromParent();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the DenseMap class.
iv Induction Variable Users
uint64_t IntrinsicInst * II
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
an instruction to allocate memory on the stack
LLVM Basic Block Representation.
InstListType::iterator iterator
Instruction iterators...
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
A parsed version of the target data layout string in and methods for querying it.
An instruction for reading from memory.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
bool replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
unsigned GetSuccessorNumber(const BasicBlock *BB, const BasicBlock *Succ)
Search for the specified successor of basic block BB and return its position in the terminator instru...
auto successors(const MachineBasicBlock *BB)
AllocaInst * DemoteRegToStack(Instruction &X, bool VolatileLoads=false, std::optional< BasicBlock::iterator > AllocaPoint=std::nullopt)
This function takes a virtual register computed by an Instruction and replaces it with a slot in the ...
AllocaInst * DemotePHIToStack(PHINode *P, std::optional< BasicBlock::iterator > AllocaPoint=std::nullopt)
This function takes a virtual register computed by a phi node and replaces it with a slot in the stac...
BasicBlock * SplitCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
If this edge is a critical edge, insert a new node to split the critical edge.
bool isCriticalEdge(const Instruction *TI, unsigned SuccNum, bool AllowIdenticalEdges=false)
Return true if the specified edge is a critical edge.