Skip to content

Commit 2f50b28

Browse files
authored
[DebugInfo] Enable deprecation of iterator-insertion methods (llvm#102608)
This is an almost-final step in eliminating debug-intrinsics -- read more about that here: https://llvm.org/docs/RemoveDIsDebugInfo.html . To correctly update variable location information in the background when inserting instructions, we need some information carried at runtime in BasicBlock::iterator, hence deprecating pointer-insertion. An immediate fix for any deprecation warnings is to call "getIterator" on the insertion position pointer. If you intend on inserting at the start of a block, use BB->begin() or similar methods to fetch the appropriate iterator.
1 parent 1808fc1 commit 2f50b28

File tree

4 files changed

+43
-132
lines changed

4 files changed

+43
-132
lines changed

llvm/examples/IRTransforms/SimplifyCFG.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static bool eliminateCondBranches_v1(Function &F) {
158158
// Replace the conditional branch with an unconditional one, by creating
159159
// a new unconditional branch to the selected successor and removing the
160160
// conditional one.
161-
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI);
161+
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI->getIterator());
162162
BI->eraseFromParent();
163163
Changed = true;
164164
}
@@ -195,7 +195,7 @@ static bool eliminateCondBranches_v2(Function &F, DominatorTree &DT) {
195195
// a new unconditional branch to the selected successor and removing the
196196
// conditional one.
197197
BranchInst *NewBranch =
198-
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI);
198+
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI->getIterator());
199199
BI->eraseFromParent();
200200

201201
// Delete the edge between BB and RemovedSucc in the DominatorTree, iff
@@ -242,7 +242,8 @@ static bool eliminateCondBranches_v3(Function &F, DominatorTree &DT) {
242242
// a new unconditional branch to the selected successor and removing the
243243
// conditional one.
244244

245-
BranchInst *NewBranch = BranchInst::Create(TakenSucc, BB.getTerminator());
245+
BranchInst *NewBranch =
246+
BranchInst::Create(TakenSucc, BB.getTerminator()->getIterator());
246247
BB.getTerminator()->eraseFromParent();
247248

248249
// Delete the edge between BB and RemovedSucc in the DominatorTree, iff

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 34 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,9 @@ class UnaryInstruction : public Instruction {
5858
constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
5959

6060
protected:
61-
UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock::iterator IB)
62-
: Instruction(Ty, iType, AllocMarker, IB) {
63-
Op<0>() = V;
64-
}
6561
UnaryInstruction(Type *Ty, unsigned iType, Value *V,
66-
Instruction *IB = nullptr)
67-
: Instruction(Ty, iType, AllocMarker, IB) {
68-
Op<0>() = V;
69-
}
70-
UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
71-
: Instruction(Ty, iType, AllocMarker, IAE) {
62+
InsertPosition InsertBefore = nullptr)
63+
: Instruction(Ty, iType, AllocMarker, InsertBefore) {
7264
Op<0>() = V;
7365
}
7466

@@ -130,27 +122,15 @@ class UnaryOperator : public UnaryInstruction {
130122
/// These methods just forward to Create, and are useful when you
131123
/// statically know what type of instruction you're going to create. These
132124
/// helpers just save some typing.
133-
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
134-
static UnaryOperator *Create##OPC(Value *V, const Twine &Name = "") {\
135-
return Create(Instruction::OPC, V, Name);\
136-
}
137-
#include "llvm/IR/Instruction.def"
138-
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
139-
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
140-
BasicBlock *BB) {\
141-
return Create(Instruction::OPC, V, Name, BB);\
142-
}
143-
#include "llvm/IR/Instruction.def"
144-
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
145-
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
146-
Instruction *I) {\
147-
return Create(Instruction::OPC, V, Name, I);\
125+
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
126+
static UnaryOperator *Create##OPC(Value *V, const Twine &Name = "") { \
127+
return Create(Instruction::OPC, V, Name); \
148128
}
149129
#include "llvm/IR/Instruction.def"
150-
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
151-
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
152-
BasicBlock::iterator It) {\
153-
return Create(Instruction::OPC, V, Name, It);\
130+
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
131+
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
132+
InsertPosition InsertBefore = nullptr) { \
133+
return Create(Instruction::OPC, V, Name, InsertBefore); \
154134
}
155135
#include "llvm/IR/Instruction.def"
156136

@@ -221,28 +201,16 @@ class BinaryOperator : public Instruction {
221201
/// These methods just forward to Create, and are useful when you
222202
/// statically know what type of instruction you're going to create. These
223203
/// helpers just save some typing.
224-
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
225-
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
226-
const Twine &Name = "") {\
227-
return Create(Instruction::OPC, V1, V2, Name);\
204+
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
205+
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
206+
const Twine &Name = "") { \
207+
return Create(Instruction::OPC, V1, V2, Name); \
228208
}
229209
#include "llvm/IR/Instruction.def"
230-
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
231-
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
232-
const Twine &Name, BasicBlock *BB) {\
233-
return Create(Instruction::OPC, V1, V2, Name, BB);\
234-
}
235-
#include "llvm/IR/Instruction.def"
236-
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
237-
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
238-
const Twine &Name, Instruction *I) {\
239-
return Create(Instruction::OPC, V1, V2, Name, I);\
240-
}
241-
#include "llvm/IR/Instruction.def"
242-
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
243-
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
244-
const Twine &Name, BasicBlock::iterator It) {\
245-
return Create(Instruction::OPC, V1, V2, Name, It);\
210+
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
211+
static BinaryOperator *Create##OPC(Value *V1, Value *V2, const Twine &Name, \
212+
InsertPosition InsertBefore) { \
213+
return Create(Instruction::OPC, V1, V2, Name, InsertBefore); \
246214
}
247215
#include "llvm/IR/Instruction.def"
248216

@@ -313,21 +281,11 @@ class BinaryOperator : public Instruction {
313281
BO->setHasNoSignedWrap(true);
314282
return BO;
315283
}
284+
316285
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
317-
const Twine &Name, BasicBlock *BB) {
318-
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
319-
BO->setHasNoSignedWrap(true);
320-
return BO;
321-
}
322-
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
323-
const Twine &Name, Instruction *I) {
324-
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
325-
BO->setHasNoSignedWrap(true);
326-
return BO;
327-
}
328-
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
329-
const Twine &Name, BasicBlock::iterator It) {
330-
BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
286+
const Twine &Name,
287+
InsertPosition InsertBefore) {
288+
BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
331289
BO->setHasNoSignedWrap(true);
332290
return BO;
333291
}
@@ -338,21 +296,11 @@ class BinaryOperator : public Instruction {
338296
BO->setHasNoUnsignedWrap(true);
339297
return BO;
340298
}
299+
341300
static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
342-
const Twine &Name, BasicBlock *BB) {
343-
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
344-
BO->setHasNoUnsignedWrap(true);
345-
return BO;
346-
}
347-
static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
348-
const Twine &Name, Instruction *I) {
349-
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
350-
BO->setHasNoUnsignedWrap(true);
351-
return BO;
352-
}
353-
static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
354-
const Twine &Name, BasicBlock::iterator It) {
355-
BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
301+
const Twine &Name,
302+
InsertPosition InsertBefore) {
303+
BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
356304
BO->setHasNoUnsignedWrap(true);
357305
return BO;
358306
}
@@ -363,22 +311,11 @@ class BinaryOperator : public Instruction {
363311
BO->setIsExact(true);
364312
return BO;
365313
}
366-
static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
367-
const Twine &Name, BasicBlock *BB) {
368-
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
369-
BO->setIsExact(true);
370-
return BO;
371-
}
372-
static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
373-
const Twine &Name, Instruction *I) {
374-
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
375-
BO->setIsExact(true);
376-
return BO;
377-
}
314+
378315
static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
379316
const Twine &Name,
380-
BasicBlock::iterator It) {
381-
BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
317+
InsertPosition InsertBefore) {
318+
BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
382319
BO->setIsExact(true);
383320
return BO;
384321
}
@@ -387,30 +324,17 @@ class BinaryOperator : public Instruction {
387324
CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name = "");
388325
static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
389326
Value *V2, const Twine &Name,
390-
BasicBlock *BB);
391-
static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
392-
Value *V2, const Twine &Name,
393-
Instruction *I);
394-
static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
395-
Value *V2, const Twine &Name,
396-
BasicBlock::iterator It);
327+
InsertPosition InsertBefore);
397328

398329
#define DEFINE_HELPERS(OPC, NUWNSWEXACT) \
399330
static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2, \
400331
const Twine &Name = "") { \
401332
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name); \
402333
} \
403334
static BinaryOperator *Create##NUWNSWEXACT##OPC( \
404-
Value *V1, Value *V2, const Twine &Name, BasicBlock *BB) { \
405-
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, BB); \
406-
} \
407-
static BinaryOperator *Create##NUWNSWEXACT##OPC( \
408-
Value *V1, Value *V2, const Twine &Name, Instruction *I) { \
409-
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, I); \
410-
} \
411-
static BinaryOperator *Create##NUWNSWEXACT##OPC( \
412-
Value *V1, Value *V2, const Twine &Name, BasicBlock::iterator It) { \
413-
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, It); \
335+
Value *V1, Value *V2, const Twine &Name, \
336+
InsertPosition InsertBefore = nullptr) { \
337+
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, InsertBefore); \
414338
}
415339

416340
DEFINE_HELPERS(Add, NSW) // CreateNSWAdd
@@ -501,22 +425,8 @@ BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
501425
}
502426
BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
503427
Value *V2, const Twine &Name,
504-
BasicBlock *BB) {
505-
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
506-
cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
507-
return BO;
508-
}
509-
BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
510-
Value *V2, const Twine &Name,
511-
Instruction *I) {
512-
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
513-
cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
514-
return BO;
515-
}
516-
BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
517-
Value *V2, const Twine &Name,
518-
BasicBlock::iterator It) {
519-
BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
428+
InsertPosition InsertBefore) {
429+
BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
520430
cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
521431
return BO;
522432
}

llvm/include/llvm/IR/Instruction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class InsertPosition {
5252

5353
public:
5454
InsertPosition(std::nullptr_t) : InsertAt() {}
55-
// LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
56-
// "BasicBlock::iterator")
55+
LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
56+
"BasicBlock::iterator")
5757
InsertPosition(Instruction *InsertBefore);
5858
InsertPosition(BasicBlock *InsertAtEnd);
5959
InsertPosition(InstListType::iterator InsertAt) : InsertAt(InsertAt) {}

llvm/lib/SandboxIR/SandboxIR.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,9 +1362,9 @@ BasicBlock *PHINode::LLVMBBToBB::operator()(llvm::BasicBlock *LLVMBB) const {
13621362
PHINode *PHINode::create(Type *Ty, unsigned NumReservedValues,
13631363
Instruction *InsertBefore, Context &Ctx,
13641364
const Twine &Name) {
1365-
llvm::PHINode *NewPHI =
1366-
llvm::PHINode::Create(Ty->LLVMTy, NumReservedValues, Name,
1367-
InsertBefore->getTopmostLLVMInstruction());
1365+
llvm::PHINode *NewPHI = llvm::PHINode::Create(
1366+
Ty->LLVMTy, NumReservedValues, Name,
1367+
InsertBefore->getTopmostLLVMInstruction()->getIterator());
13681368
return Ctx.createPHINode(NewPHI);
13691369
}
13701370

0 commit comments

Comments
 (0)