@@ -173,13 +173,37 @@ class IRBuilderBase {
173173 BasicBlock::iterator GetInsertPoint () const { return InsertPt; }
174174 LLVMContext &getContext () const { return Context; }
175175
176+ // / This specifies that created instructions should be appended to the
177+ // / end of the specified block.
178+ void SetInsertPoint (BasicBlock *TheBB) {
179+ BB = TheBB;
180+ InsertPt = BB->end ();
181+ }
182+
183+ // / This specifies that created instructions should be inserted before
184+ // / the specified instruction.
185+ void SetInsertPoint (Instruction *I) {
186+ BB = I->getParent ();
187+ InsertPt = I->getIterator ();
188+ assert (InsertPt != BB->end () && " Can't read debug loc from end()" );
189+ SetCurrentDebugLocation (I->getStableDebugLoc ());
190+ }
191+
176192 // / This specifies that created instructions should be inserted at the
177- // / specified insert position.
178- void SetInsertPoint (InsertPosition IP) {
179- BB = IP.getBasicBlock ();
193+ // / specified point.
194+ void SetInsertPoint (BasicBlock *TheBB, BasicBlock::iterator IP) {
195+ BB = TheBB;
196+ InsertPt = IP;
197+ if (IP != TheBB->end ())
198+ SetCurrentDebugLocation (IP->getStableDebugLoc ());
199+ }
200+
201+ // / This specifies that created instructions should be inserted at
202+ // / the specified point, but also requires that \p IP is dereferencable.
203+ void SetInsertPoint (BasicBlock::iterator IP) {
204+ BB = IP->getParent ();
180205 InsertPt = IP;
181- if (InsertPt != BB->end ())
182- SetCurrentDebugLocation (InsertPt->getStableDebugLoc ());
206+ SetCurrentDebugLocation (IP->getStableDebugLoc ());
183207 }
184208
185209 // / This specifies that created instructions should inserted at the beginning
@@ -262,7 +286,7 @@ class IRBuilderBase {
262286 // / Sets the current insert point to a previously-saved location.
263287 void restoreIP (InsertPoint IP) {
264288 if (IP.isSet ())
265- SetInsertPoint (IP.getPoint ());
289+ SetInsertPoint (IP.getBlock (), IP. getPoint ());
266290 else
267291 ClearInsertionPoint ();
268292 }
@@ -2653,22 +2677,46 @@ class IRBuilder : public IRBuilderBase {
26532677 ArrayRef<OperandBundleDef> OpBundles = std::nullopt )
26542678 : IRBuilderBase(C, this ->Folder, this ->Inserter, FPMathTag, OpBundles) {}
26552679
2656- explicit IRBuilder (InsertPosition IP, MDNode *FPMathTag = nullptr ,
2680+ explicit IRBuilder (BasicBlock *TheBB, FolderTy Folder,
2681+ MDNode *FPMathTag = nullptr ,
26572682 ArrayRef<OperandBundleDef> OpBundles = std::nullopt )
2658- : IRBuilderBase(IP.getBasicBlock()->getContext(), this->Folder,
2659- this->Inserter, FPMathTag, OpBundles) {
2660- SetInsertPoint (IP);
2683+ : IRBuilderBase(TheBB->getContext (), this->Folder, this->Inserter,
2684+ FPMathTag, OpBundles),
2685+ Folder(Folder) {
2686+ SetInsertPoint (TheBB);
26612687 }
26622688
2663- explicit IRBuilder (InsertPosition IP, FolderTy Folder,
2664- MDNode *FPMathTag = nullptr ,
2689+ explicit IRBuilder (BasicBlock *TheBB, MDNode *FPMathTag = nullptr ,
26652690 ArrayRef<OperandBundleDef> OpBundles = std::nullopt )
2666- : IRBuilderBase(IP.getBasicBlock()->getContext(), this->Folder,
2667- this->Inserter, FPMathTag, OpBundles),
2668- Folder(Folder) {
2691+ : IRBuilderBase(TheBB->getContext (), this->Folder, this->Inserter,
2692+ FPMathTag, OpBundles) {
2693+ SetInsertPoint (TheBB);
2694+ }
2695+
2696+ explicit IRBuilder (Instruction *IP, MDNode *FPMathTag = nullptr ,
2697+ ArrayRef<OperandBundleDef> OpBundles = std::nullopt )
2698+ : IRBuilderBase(IP->getContext (), this->Folder, this->Inserter, FPMathTag,
2699+ OpBundles) {
26692700 SetInsertPoint (IP);
26702701 }
26712702
2703+ IRBuilder (BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder,
2704+ MDNode *FPMathTag = nullptr ,
2705+ ArrayRef<OperandBundleDef> OpBundles = std::nullopt )
2706+ : IRBuilderBase(TheBB->getContext (), this->Folder, this->Inserter,
2707+ FPMathTag, OpBundles),
2708+ Folder(Folder) {
2709+ SetInsertPoint (TheBB, IP);
2710+ }
2711+
2712+ IRBuilder (BasicBlock *TheBB, BasicBlock::iterator IP,
2713+ MDNode *FPMathTag = nullptr ,
2714+ ArrayRef<OperandBundleDef> OpBundles = std::nullopt )
2715+ : IRBuilderBase(TheBB->getContext (), this->Folder, this->Inserter,
2716+ FPMathTag, OpBundles) {
2717+ SetInsertPoint (TheBB, IP);
2718+ }
2719+
26722720 // / Avoid copying the full IRBuilder. Prefer using InsertPointGuard
26732721 // / or FastMathFlagGuard instead.
26742722 IRBuilder (const IRBuilder &) = delete;
0 commit comments