@@ -2257,18 +2257,45 @@ class SILBuilderWithScope : public SILBuilder {
2257
2257
};
2258
2258
2259
2259
class SavedInsertionPointRAII {
2260
- SILBuilder &Builder ;
2261
- PointerUnion<SILInstruction *, SILBasicBlock *> SavedIP ;
2260
+ SILBuilder &builder ;
2261
+ PointerUnion<SILInstruction *, SILBasicBlock *> savedInsertionPoint ;
2262
2262
2263
2263
public:
2264
- SavedInsertionPointRAII (SILBuilder &B, SILInstruction *NewIP)
2265
- : Builder(B), SavedIP(&*B.getInsertionPoint()) {
2266
- Builder.setInsertionPoint (NewIP);
2264
+ // / Constructor that saves a Builder's insertion point without changing the
2265
+ // / builder's underlying insertion point.
2266
+ SavedInsertionPointRAII (SILBuilder &B) : builder(B), savedInsertionPoint() {
2267
+ // If our builder does not have a valid insertion point, just put nullptr
2268
+ // into SavedIP.
2269
+ if (!builder.hasValidInsertionPoint ()) {
2270
+ savedInsertionPoint = static_cast <SILBasicBlock *>(nullptr );
2271
+ return ;
2272
+ }
2273
+
2274
+ // If we are inserting into the end of the block, stash the insertion block.
2275
+ if (builder.insertingAtEndOfBlock ()) {
2276
+ savedInsertionPoint = builder.getInsertionBB ();
2277
+ return ;
2278
+ }
2279
+
2280
+ // Otherwise, stash the instruction.
2281
+ SILInstruction *i = &*builder.getInsertionPoint ();
2282
+ savedInsertionPoint = i;
2283
+ }
2284
+
2285
+ SavedInsertionPointRAII (SILBuilder &b, SILInstruction *insertionPoint)
2286
+ : SavedInsertionPointRAII(b) {
2287
+ builder.setInsertionPoint (insertionPoint);
2288
+ }
2289
+
2290
+ SavedInsertionPointRAII (SILBuilder &b, SILBasicBlock *block,
2291
+ SILBasicBlock::iterator iter)
2292
+ : SavedInsertionPointRAII(b) {
2293
+ builder.setInsertionPoint (block, iter);
2267
2294
}
2268
2295
2269
- SavedInsertionPointRAII (SILBuilder &B , SILBasicBlock *NewIP )
2270
- : Builder(B), SavedIP(B.getInsertionBB() ) {
2271
- Builder .setInsertionPoint (NewIP );
2296
+ SavedInsertionPointRAII (SILBuilder &b , SILBasicBlock *insertionBlock )
2297
+ : SavedInsertionPointRAII(b ) {
2298
+ builder .setInsertionPoint (insertionBlock );
2272
2299
}
2273
2300
2274
2301
SavedInsertionPointRAII (const SavedInsertionPointRAII &) = delete ;
@@ -2277,12 +2304,12 @@ class SavedInsertionPointRAII {
2277
2304
SavedInsertionPointRAII &operator =(SavedInsertionPointRAII &&) = delete ;
2278
2305
2279
2306
~SavedInsertionPointRAII () {
2280
- if (SavedIP .isNull ()) {
2281
- Builder .clearInsertionPoint ();
2282
- } else if (SavedIP .is <SILInstruction *>()) {
2283
- Builder .setInsertionPoint (SavedIP .get <SILInstruction *>());
2307
+ if (savedInsertionPoint .isNull ()) {
2308
+ builder .clearInsertionPoint ();
2309
+ } else if (savedInsertionPoint .is <SILInstruction *>()) {
2310
+ builder .setInsertionPoint (savedInsertionPoint .get <SILInstruction *>());
2284
2311
} else {
2285
- Builder .setInsertionPoint (SavedIP .get <SILBasicBlock *>());
2312
+ builder .setInsertionPoint (savedInsertionPoint .get <SILBasicBlock *>());
2286
2313
}
2287
2314
}
2288
2315
};
0 commit comments