Lines Matching +full:stack +full:- +full:utils
1 //===- DemoteRegToStack.cpp - Move a virtual register to the stack --------===//
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
16 #include "llvm/Transforms/Utils/Local.h"
19 /// DemoteRegToStack - This function takes a virtual register computed by an
20 /// Instruction and replaces it with a slot in the stack frame, allocated via
23 /// the alloca inserted to create a stack slot for I.
31 // Create a stack slot to hold the value. in DemoteRegToStack()
37 Function *F = I.getParent()->getParent(); in DemoteRegToStack()
39 &F->getEntryBlock().front()); in DemoteRegToStack()
42 // We cannot demote invoke instructions to the stack if their normal edge in DemoteRegToStack()
46 if (!II->getNormalDest()->getSinglePredecessor()) { in DemoteRegToStack()
47 unsigned SuccNum = GetSuccessorNumber(II->getParent(), II->getNormalDest()); in DemoteRegToStack()
55 // Change all of the users of the instruction to read from the stack slot. in DemoteRegToStack()
69 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) in DemoteRegToStack()
70 if (PN->getIncomingValue(i) == &I) { in DemoteRegToStack()
71 Value *&V = Loads[PN->getIncomingBlock(i)]; in DemoteRegToStack()
75 PN->getIncomingBlock(i)->getTerminator()); in DemoteRegToStack()
77 PN->setIncomingValue(i, V); in DemoteRegToStack()
83 U->replaceUsesOfWith(&I, V); in DemoteRegToStack()
87 // Insert stores of the computed value into the stack slot. We have to be in DemoteRegToStack()
93 for (; isa<PHINode>(InsertPt) || InsertPt->isEHPad(); ++InsertPt) in DemoteRegToStack()
97 InsertPt = II.getNormalDest()->getFirstInsertionPt(); in DemoteRegToStack()
104 /// DemotePHIToStack - This function takes a virtual register computed by a PHI
105 /// node and replaces it with a slot in the stack frame allocated via alloca.
108 if (P->use_empty()) { in DemotePHIToStack()
109 P->eraseFromParent(); in DemotePHIToStack()
113 // Create a stack slot to hold the value. in DemotePHIToStack()
116 Slot = new AllocaInst(P->getType(), nullptr, in DemotePHIToStack()
117 P->getName()+".reg2mem", AllocaPoint); in DemotePHIToStack()
119 Function *F = P->getParent()->getParent(); in DemotePHIToStack()
120 Slot = new AllocaInst(P->getType(), nullptr, P->getName() + ".reg2mem", in DemotePHIToStack()
121 &F->getEntryBlock().front()); in DemotePHIToStack()
125 for (unsigned i = 0, e = P->getNumIncomingValues(); i < e; ++i) { in DemotePHIToStack()
126 if (InvokeInst *II = dyn_cast<InvokeInst>(P->getIncomingValue(i))) { in DemotePHIToStack()
127 assert(II->getParent() != P->getIncomingBlock(i) && in DemotePHIToStack()
130 new StoreInst(P->getIncomingValue(i), Slot, in DemotePHIToStack()
131 P->getIncomingBlock(i)->getTerminator()); in DemotePHIToStack()
135 BasicBlock::iterator InsertPt = P->getIterator(); in DemotePHIToStack()
137 for (; isa<PHINode>(InsertPt) || InsertPt->isEHPad(); ++InsertPt) in DemotePHIToStack()
140 Value *V = new LoadInst(Slot, P->getName() + ".reload", &*InsertPt); in DemotePHIToStack()
141 P->replaceAllUsesWith(V); in DemotePHIToStack()
144 P->eraseFromParent(); in DemotePHIToStack()