Skip to content

Commit 389939a

Browse files
committed
Fix new deprecations and changes for LLVM 23
1 parent 8880fdc commit 389939a

11 files changed

Lines changed: 95 additions & 61 deletions

driver/cl_options-llvm.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ std::string getFeaturesStr() {
7272

7373
void setFunctionAttributes(StringRef cpu, StringRef features,
7474
Function &function) {
75+
#if LLVM_VERSION_MAJOR >= 23
76+
return codegen::setFunctionAttributes(function, cpu, features);
77+
#else
7578
return codegen::setFunctionAttributes(cpu, features, function);
79+
#endif
7680
}
7781
} // namespace opts
7882

gen/arrays.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static void DtoArrayInit(Loc loc, LLValue *ptr, LLValue *length,
8989

9090
// move into the for condition block, ie. start the loop
9191
assert(!gIR->scopereturned());
92-
llvm::BranchInst::Create(condbb, gIR->scopebb());
92+
createBranch(condbb, gIR->scopebb());
9393

9494
// replace current scope
9595
gIR->ir->SetInsertPoint(condbb);
@@ -101,7 +101,7 @@ static void DtoArrayInit(Loc loc, LLValue *ptr, LLValue *length,
101101

102102
// conditional branch
103103
assert(!gIR->scopereturned());
104-
llvm::BranchInst::Create(bodybb, endbb, cond_val, gIR->scopebb());
104+
createBranch(cond_val, bodybb, endbb, gIR->scopebb());
105105

106106
// rewrite scope
107107
gIR->ir->SetInsertPoint(bodybb);
@@ -117,7 +117,7 @@ static void DtoArrayInit(Loc loc, LLValue *ptr, LLValue *length,
117117
itr);
118118

119119
// loop
120-
llvm::BranchInst::Create(condbb, gIR->scopebb());
120+
createBranch(condbb, gIR->scopebb());
121121

122122
// rewrite the scope
123123
gIR->ir->SetInsertPoint(endbb);

gen/classes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void DtoFinalizeScopeClass(Loc loc, DValue *dval,
221221
const auto hasMonitor =
222222
gIR->ir->CreateICmp(llvm::CmpInst::ICMP_NE, monitor,
223223
getNullValue(monitor->getType()), ".hasMonitor");
224-
llvm::BranchInst::Create(ifbb, endbb, hasMonitor, gIR->scopebb());
224+
createBranch(hasMonitor, ifbb, endbb, gIR->scopebb());
225225

226226
gIR->ir->SetInsertPoint(ifbb);
227227
DtoFinalizeClass(loc, inst);

gen/llvmhelpers.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,11 @@ void printLabelName(std::ostream &target, const char *func_mangle,
13641364
const char *label_name) {
13651365
// note: quotes needed for Unicode
13661366
target << '"'
1367+
#if LLVM_VERSION_MAJOR >= 23
1368+
<< gTargetMachine->getMCAsmInfo()->getPrivateLabelPrefix().str()
1369+
#else
13671370
<< gTargetMachine->getMCAsmInfo()->getPrivateGlobalPrefix().str()
1371+
#endif
13681372
<< func_mangle << "_" << label_name << '"';
13691373
}
13701374

@@ -1431,6 +1435,24 @@ LLValue *createIPairCmp(EXP op, LLValue *lhs1, LLValue *lhs2, LLValue *rhs1,
14311435
return r;
14321436
}
14331437

1438+
llvm::Instruction *createBranch(LLValue* cond,
1439+
llvm::BasicBlock * _if,
1440+
llvm::BasicBlock * _else,
1441+
llvm::BasicBlock *insertAfter) {
1442+
#if LLVM_VERSION_MAJOR >= 23
1443+
return llvm::CondBrInst::Create(cond, _if, _else, insertAfter);
1444+
#else
1445+
return llvm::BranchInst::Create(_if, _else, cond, insertAfter);
1446+
#endif
1447+
}
1448+
llvm::Instruction *createBranch(llvm::BasicBlock *label, llvm::BasicBlock *insertAfter) {
1449+
#if LLVM_VERSION_MAJOR >= 23
1450+
return llvm::UncondBrInst::Create(label, insertAfter);
1451+
#else
1452+
return llvm::BranchInst::Create(label, insertAfter);
1453+
#endif
1454+
}
1455+
14341456
///////////////////////////////////////////////////////////////////////////////
14351457
DValue *DtoSymbolAddress(Loc loc, Type *type, Declaration *decl) {
14361458
IF_LOG Logger::println("DtoSymbolAddress ('%s' of type '%s')",

gen/llvmhelpers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ llvm::ICmpInst::Predicate eqTokToICmpPred(EXP op, bool invert = false);
186186
/// `(lhs1 != rhs1) | (lhs2 != rhs2)` for inequality/not-identity.
187187
LLValue *createIPairCmp(EXP op, LLValue *lhs1, LLValue *lhs2, LLValue *rhs1,
188188
LLValue *rhs2);
189+
llvm::Instruction *createBranch(LLValue* cond,
190+
llvm::BasicBlock * _if,
191+
llvm::BasicBlock * _else,
192+
llvm::BasicBlock *insertAfter = nullptr);
193+
llvm::Instruction *createBranch(llvm::BasicBlock *label, llvm::BasicBlock *insertAfter = nullptr);
189194

190195
////////////////////////////////////////////
191196
// gen/tocall.cpp stuff below

gen/ms-cxx-helper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void cloneBlocks(const std::vector<llvm::BasicBlock *> &srcblocks,
107107
CInst, llvm::OperandBundleDef("funclet", funclet));
108108
newInst = call;
109109
} else if (funclet && llvm::isa<llvm::UnreachableInst>(Inst)) {
110-
newInst = llvm::BranchInst::Create(continueWith); // to cleanupret
110+
newInst = createBranch(continueWith);
111111
}
112112
}
113113
if (!newInst)

gen/optimizer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,13 @@ static OptimizationLevel getOptimizationLevel(){
194194
case 3:
195195
case 4:
196196
case 5: return OptimizationLevel::O3;
197+
#if LLVM_VERSION_MAJOR >= 23
198+
case -1: return OptimizationLevel::O2;
199+
case -2: return OptimizationLevel::O2;
200+
#else
197201
case -1: return OptimizationLevel::Os;
198202
case -2: return OptimizationLevel::Oz;
203+
#endif
199204
}
200205
//This should never be reached
201206
llvm_unreachable("Unexpected optimizeLevel.");

gen/passes/GarbageCollect2Stack.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,13 @@ static void RemoveCall(CallBase *CB, const G2StackAnalysis &A) {
351351
// immediately before it. Ideally, we would find a way to not invalidate
352352
// the dominator tree here.
353353
if (auto Invoke = dyn_cast<InvokeInst>(static_cast<Instruction *>(CB))) {
354-
BranchInst::Create(Invoke->getNormalDest(),
355-
#if LLVM_VERSION_MAJOR >= 19
356-
Invoke->getIterator()
354+
#if LLVM_VERSION_MAJOR >= 23
355+
UncondBrInst::Create(Invoke->getNormalDest(), Invoke->getIterator());
356+
#elif LLVM_VERSION_MAJOR >= 19
357+
BranchInst::Create(Invoke->getNormalDest(), Invoke->getIterator());
357358
#else
358-
Invoke
359+
BranchInst::Create(Invoke->getNormalDest(), Invoke);
359360
#endif
360-
);
361361
Invoke->getUnwindDest()->removePredecessor(CB->getParent());
362362
}
363363

0 commit comments

Comments
 (0)