Skip to content

Commit 963f1c8

Browse files
committed
Fix remaining LLVM deprecations wrt. instructions as insert positions
1 parent f572bfa commit 963f1c8

File tree

7 files changed

+55
-33
lines changed

7 files changed

+55
-33
lines changed

gen/funcgenstate.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ class FuncGenState {
187187
/// Tracks basic blocks corresponding to switch cases.
188188
SwitchCaseTargets switchTargets;
189189

190-
/// The marker at which to insert `alloca`s in the function entry bb.
191-
llvm::Instruction *allocapoint = nullptr;
192-
193190
/// alloca for the nested context of this function
194191
llvm::Value *nestedVar = nullptr;
195192

gen/functions.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,15 +1222,6 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
12221222
return;
12231223
}
12241224

1225-
// create alloca point
1226-
// this gets erased when the function is complete, so alignment etc does not
1227-
// matter at all
1228-
llvm::Instruction *allocaPoint =
1229-
new llvm::AllocaInst(LLType::getInt32Ty(gIR->context()),
1230-
0, // Address space
1231-
"alloca_point", beginbb);
1232-
funcGen.allocapoint = allocaPoint;
1233-
12341225
emitInstrumentationFnEnter(fd);
12351226

12361227
if (global.params.trace && fd->emitInstrumentation && !fd->isCMain() &&
@@ -1339,13 +1330,6 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
13391330
}
13401331
}
13411332

1342-
// erase alloca point
1343-
if (allocaPoint->getParent()) {
1344-
funcGen.allocapoint = nullptr;
1345-
allocaPoint->eraseFromParent();
1346-
allocaPoint = nullptr;
1347-
}
1348-
13491333
if (gIR->dcomputetarget) {
13501334
auto kernAttr = getKernelAttr(fd);
13511335
if (kernAttr) {

gen/irstate.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,18 @@ IrFunction *IRState::func() { return &funcGen().irFunc; }
4545

4646
llvm::Function *IRState::topfunc() { return func()->getLLVMFunc(); }
4747

48-
llvm::Instruction *IRState::topallocapoint() { return funcGen().allocapoint; }
48+
#if LDC_LLVM_VER >= 1900
49+
llvm::BasicBlock::iterator IRState::nextAllocaPos() {
50+
#else
51+
llvm::Instruction *IRState::nextAllocaPos() {
52+
#endif
53+
auto it = topfunc()->getEntryBlock().getFirstNonPHIOrDbgOrAlloca();
54+
#if LDC_LLVM_VER >= 1900
55+
return it;
56+
#else
57+
return &(*it);
58+
#endif
59+
}
4960

5061
std::unique_ptr<IRBuilderScope> IRState::setInsertPoint(llvm::BasicBlock *bb) {
5162
auto savedScope = std::make_unique<IRBuilderScope>(builder);

gen/irstate.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,12 @@ struct IRState {
155155
FuncGenState &funcGen();
156156
IrFunction *func();
157157
llvm::Function *topfunc();
158-
llvm::Instruction *topallocapoint();
158+
159+
#if LDC_LLVM_VER >= 1900
160+
llvm::BasicBlock::iterator nextAllocaPos();
161+
#else
162+
llvm::Instruction *nextAllocaPos();
163+
#endif
159164

160165
// Use this to set the IRBuilder's insertion point for a new function.
161166
// The previous IRBuilder state is restored when the returned value is

gen/llvmhelpers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ llvm::AllocaInst *DtoArrayAlloca(Type *type, unsigned arraysize,
174174
LLType *lltype = DtoType(type);
175175
auto ai = new llvm::AllocaInst(
176176
lltype, gIR->module.getDataLayout().getAllocaAddrSpace(),
177-
DtoConstUint(arraysize), name, gIR->topallocapoint());
177+
DtoConstUint(arraysize), name, gIR->nextAllocaPos());
178178
if (auto alignment = DtoAlignment(type)) {
179179
ai->setAlignment(llvm::Align(alignment));
180180
}
@@ -185,7 +185,7 @@ llvm::AllocaInst *DtoRawAlloca(LLType *lltype, size_t alignment,
185185
const char *name) {
186186
auto ai = new llvm::AllocaInst(
187187
lltype, gIR->module.getDataLayout().getAllocaAddrSpace(), name,
188-
gIR->topallocapoint());
188+
gIR->nextAllocaPos());
189189
if (alignment) {
190190
ai->setAlignment(llvm::Align(alignment));
191191
}

gen/passes/GarbageCollect2Stack.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,16 @@ Value* FunctionInfo::promote(CallBase *CB, IRBuilder<> &B, const G2StackAnalysis
9696
NumGcToStack++;
9797

9898
auto &BB = CB->getCaller()->getEntryBlock();
99-
Instruction *Begin = &(*BB.begin());
10099

101100
// FIXME: set alignment on alloca?
102-
return new AllocaInst(Ty,
103-
BB.getModule()->getDataLayout().getAllocaAddrSpace(),
104-
".nongc_mem", Begin);
101+
return new AllocaInst(
102+
Ty, BB.getModule()->getDataLayout().getAllocaAddrSpace(), ".nongc_mem",
103+
#if LDC_LLVM_VER >= 1900
104+
BB.begin()
105+
#else
106+
&(*BB.begin())
107+
#endif
108+
);
105109
}
106110

107111
static bool isKnownLessThan(Value *Val, uint64_t Limit, const G2StackAnalysis &A) {
@@ -347,7 +351,13 @@ static void RemoveCall(CallBase *CB, const G2StackAnalysis &A) {
347351
// immediately before it. Ideally, we would find a way to not invalidate
348352
// the dominator tree here.
349353
if (auto Invoke = dyn_cast<InvokeInst>(static_cast<Instruction *>(CB))) {
350-
BranchInst::Create(Invoke->getNormalDest(), Invoke);
354+
BranchInst::Create(Invoke->getNormalDest(),
355+
#if LDC_LLVM_VER >= 1900
356+
Invoke->getIterator()
357+
#else
358+
Invoke
359+
#endif
360+
);
351361
Invoke->getUnwindDest()->removePredecessor(CB->getParent());
352362
}
353363

gen/trycatchfinally.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch,
213213
// redirect scope to avoid the generation of debug info before the
214214
// catchpad
215215
const auto savedInsertPoint = irs.saveInsertPoint();
216-
irs.ir->SetInsertPoint(gIR->topallocapoint());
216+
irs.ir->SetInsertPoint(irs.nextAllocaPos());
217217
DtoVarDeclaration(var);
218218

219219
// catch handler will be outlined, so always treat as a nested reference
@@ -332,6 +332,20 @@ CleanupScope::CleanupScope(llvm::BasicBlock *beginBlock,
332332
blocks.push_back(endBlock);
333333
}
334334

335+
namespace {
336+
#if LDC_LLVM_VER >= 1900
337+
llvm::BasicBlock::iterator getTerminatorPos(llvm::BasicBlock *bb) {
338+
auto it = bb->rbegin().getReverse();
339+
assert(it->isTerminator());
340+
return it;
341+
}
342+
#else
343+
llvm::Instruction *getTerminatorPos(llvm::BasicBlock *bb) {
344+
return bb->getTerminator();
345+
}
346+
#endif
347+
} // anonymous namespace
348+
335349
llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock,
336350
llvm::BasicBlock *continueWith) {
337351
if (useMSVCEH())
@@ -359,12 +373,13 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock,
359373
branchSelector = new llvm::AllocaInst(
360374
branchSelectorType, irs.module.getDataLayout().getAllocaAddrSpace(),
361375
llvm::Twine("branchsel.") + beginBlock()->getName(),
362-
irs.topallocapoint());
376+
irs.nextAllocaPos());
363377

364378
// Now we also need to store 0 to it to keep the paths that go to the
365379
// only existing branch target the same.
366380
for (auto bb : exitTargets.front().sourceBlocks) {
367-
new llvm::StoreInst(DtoConstUint(0), branchSelector, bb->getTerminator());
381+
new llvm::StoreInst(DtoConstUint(0), branchSelector,
382+
getTerminatorPos(bb));
368383
}
369384

370385
// And convert the BranchInst to the existing branch target to a
@@ -385,7 +400,7 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock,
385400
CleanupExitTarget &t = exitTargets[i];
386401
if (t.branchTarget == continueWith) {
387402
new llvm::StoreInst(DtoConstUint(i), branchSelector,
388-
sourceBlock->getTerminator());
403+
getTerminatorPos(sourceBlock));
389404

390405
// Note: Strictly speaking, keeping this up to date would not be
391406
// needed right now, because we never to any optimizations that
@@ -405,7 +420,7 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock,
405420

406421
// ... insert the store into the source block...
407422
new llvm::StoreInst(selectorVal, branchSelector,
408-
sourceBlock->getTerminator());
423+
getTerminatorPos(sourceBlock));
409424

410425
// ... and keep track of it (again, this is unnecessary right now as
411426
// discussed in the above note).

0 commit comments

Comments
 (0)