23 std::optional<BasicBlock::iterator> AllocaPoint) {
35 Slot =
new AllocaInst(
I.getType(),
DL.getAllocaAddrSpace(),
nullptr,
36 I.getName()+
".reg2mem", *AllocaPoint);
38 Slot =
new AllocaInst(
I.getType(),
DL.getAllocaAddrSpace(),
nullptr,
39 I.getName() +
".reg2mem",
F->getEntryBlock().begin());
46 if (!II->getNormalDest()->getSinglePredecessor()) {
50 assert(BB &&
"Unable to split critical edge.");
53 }
else if (
CallBrInst *CBI = dyn_cast<CallBrInst>(&
I)) {
54 for (
unsigned i = 0; i < CBI->getNumSuccessors(); i++) {
55 auto *Succ = CBI->getSuccessor(i);
56 if (!Succ->getSinglePredecessor()) {
59 assert(BB &&
"Unable to split critical edge.");
65 while (!
I.use_empty()) {
67 if (
PHINode *PN = dyn_cast<PHINode>(U)) {
78 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
79 if (PN->getIncomingValue(i) == &
I) {
80 Value *&V = Loads[PN->getIncomingBlock(i)];
83 V =
new LoadInst(
I.getType(), Slot,
I.getName() +
".reload",
85 PN->getIncomingBlock(i)->getTerminator()->getIterator());
86 Loads[PN->getIncomingBlock(i)] = V;
88 PN->setIncomingValue(i, V);
94 VolatileLoads, U->getIterator());
95 U->replaceUsesOfWith(&
I, V);
103 if (!
I.isTerminator()) {
104 InsertPt = ++
I.getIterator();
106 for (; isa<PHINode>(InsertPt) || InsertPt->isEHPad(); ++InsertPt)
107 if (isa<CatchSwitchInst>(InsertPt))
109 if (isa<CatchSwitchInst>(InsertPt)) {
111 new StoreInst(&
I, Slot, Handler->getFirstInsertionPt());
114 }
else if (
InvokeInst *II = dyn_cast<InvokeInst>(&
I)) {
115 InsertPt = II->getNormalDest()->getFirstInsertionPt();
116 }
else if (
CallBrInst *CBI = dyn_cast<CallBrInst>(&
I)) {
118 new StoreInst(CBI, Slot, Succ->getFirstInsertionPt());
132 if (
P->use_empty()) {
133 P->eraseFromParent();
142 Slot =
new AllocaInst(
P->getType(),
DL.getAllocaAddrSpace(),
nullptr,
143 P->getName()+
".reg2mem", *AllocaPoint);
146 Slot =
new AllocaInst(
P->getType(),
DL.getAllocaAddrSpace(),
nullptr,
147 P->getName() +
".reg2mem",
148 F->getEntryBlock().begin());
152 for (
unsigned i = 0, e =
P->getNumIncomingValues(); i < e; ++i) {
153 if (
InvokeInst *II = dyn_cast<InvokeInst>(
P->getIncomingValue(i))) {
154 assert(II->getParent() !=
P->getIncomingBlock(i) &&
155 "Invoke edge not supported yet"); (void)II;
158 P->getIncomingBlock(i)->getTerminator()->getIterator());
164 for (; isa<PHINode>(InsertPt) || InsertPt->isEHPad(); ++InsertPt)
165 if (isa<CatchSwitchInst>(InsertPt))
167 if (isa<CatchSwitchInst>(InsertPt)) {
170 for (
User *U :
P->users()) {
176 new LoadInst(
P->getType(), Slot,
P->getName() +
".reload",
User->getIterator());
181 new LoadInst(
P->getType(), Slot,
P->getName() +
".reload", InsertPt);
182 P->replaceAllUsesWith(V);
185 P->eraseFromParent();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the DenseMap class.
iv Induction Variable Users
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.