->getFirstInsertionPt().getNonConst();
}
+ /// Returns an iterator to the first instruction in this block that is
+ /// not a PHINode, a debug intrinsic, a static alloca or any pseudo operation.
+ const_iterator getFirstNonPHIOrDbgOrAlloca() const;
+ iterator getFirstNonPHIOrDbgOrAlloca() {
+ return static_cast<const BasicBlock *>(this)
+ ->getFirstNonPHIOrDbgOrAlloca()
+ .getNonConst();
+ }
+
/// Return a const iterator range over the instructions in the block, skipping
/// any debug instructions. Skip any pseudo operations as well if \c
/// SkipPseudoOp is true.
SetCurrentDebugLocation(IP->getDebugLoc());
}
+ /// This specifies that created instructions should inserted at the beginning
+ /// end of the specified function, but after already existing static alloca
+ /// instructions that are at the start.
+ void SetInsertPointPastAllocas(Function *F) {
+ BB = &F->getEntryBlock();
+ InsertPt = BB->getFirstNonPHIOrDbgOrAlloca();
+ }
+
/// Set location information used by debugging information.
void SetCurrentDebugLocation(DebugLoc L) {
AddOrRemoveMetadataToCopy(LLVMContext::MD_dbg, L.getAsMDNode());
Instruction *StackEntry =
AtEntry.CreateAlloca(ConcreteStackEntryTy, nullptr, "gc_frame");
- while (isa<AllocaInst>(IP))
- ++IP;
- AtEntry.SetInsertPoint(IP->getParent(), IP);
+ AtEntry.SetInsertPointPastAllocas(&F);
+ IP = AtEntry.GetInsertPoint();
// Initialize the map pointer and load the current head of the shadow stack.
Instruction *CurrentHead =
return InsertPt;
}
+BasicBlock::const_iterator BasicBlock::getFirstNonPHIOrDbgOrAlloca() const {
+ const Instruction *FirstNonPHI = getFirstNonPHI();
+ if (!FirstNonPHI)
+ return end();
+
+ const_iterator InsertPt = FirstNonPHI->getIterator();
+ if (InsertPt->isEHPad())
+ ++InsertPt;
+
+ if (isEntryBlock()) {
+ const_iterator End = end();
+ while (InsertPt != End &&
+ (isa<AllocaInst>(*InsertPt) || isa<DbgInfoIntrinsic>(*InsertPt) ||
+ isa<PseudoProbeInst>(*InsertPt))) {
+ if (const AllocaInst *AI = dyn_cast<AllocaInst>(&*InsertPt)) {
+ if (!AI->isStaticAlloca())
+ break;
+ }
+ ++InsertPt;
+ }
+ }
+ return InsertPt;
+}
+
void BasicBlock::dropAllReferences() {
for (Instruction &I : *this)
I.dropAllReferences();
// replacement below is still necessary.
Instruction *MoveBefore;
if (isa<Argument>(Op)) {
- MoveBefore = &FI.getFunction()->getEntryBlock().front();
- while (isa<AllocaInst>(MoveBefore))
- MoveBefore = MoveBefore->getNextNode();
+ MoveBefore =
+ &*FI.getFunction()->getEntryBlock().getFirstNonPHIOrDbgOrAlloca();
} else {
MoveBefore = cast<Instruction>(Op)->getInsertionPointAfterDef();
if (!MoveBefore)