@@ -173,13 +173,37 @@ class IRBuilderBase {
173
173
BasicBlock::iterator GetInsertPoint() const { return InsertPt; }
174
174
LLVMContext &getContext() const { return Context; }
175
175
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
+
176
192
/// 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();
180
205
InsertPt = IP;
181
- if (InsertPt != BB->end())
182
- SetCurrentDebugLocation(InsertPt->getStableDebugLoc());
206
+ SetCurrentDebugLocation(IP->getStableDebugLoc());
183
207
}
184
208
185
209
/// This specifies that created instructions should inserted at the beginning
@@ -262,7 +286,7 @@ class IRBuilderBase {
262
286
/// Sets the current insert point to a previously-saved location.
263
287
void restoreIP(InsertPoint IP) {
264
288
if (IP.isSet())
265
- SetInsertPoint(IP.getPoint());
289
+ SetInsertPoint(IP.getBlock(), IP. getPoint());
266
290
else
267
291
ClearInsertionPoint();
268
292
}
@@ -2653,22 +2677,46 @@ class IRBuilder : public IRBuilderBase {
2653
2677
ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2654
2678
: IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles) {}
2655
2679
2656
- explicit IRBuilder(InsertPosition IP, MDNode *FPMathTag = nullptr,
2680
+ explicit IRBuilder(BasicBlock *TheBB, FolderTy Folder,
2681
+ MDNode *FPMathTag = nullptr,
2657
2682
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);
2661
2687
}
2662
2688
2663
- explicit IRBuilder(InsertPosition IP, FolderTy Folder,
2664
- MDNode *FPMathTag = nullptr,
2689
+ explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
2665
2690
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) {
2669
2700
SetInsertPoint(IP);
2670
2701
}
2671
2702
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
+
2672
2720
/// Avoid copying the full IRBuilder. Prefer using InsertPointGuard
2673
2721
/// or FastMathFlagGuard instead.
2674
2722
IRBuilder(const IRBuilder &) = delete;
0 commit comments