Skip to content

Commit

Permalink
fix more LLVM 11 compatibility issues
Browse files Browse the repository at this point in the history
- deprecated overloads of `IRBuilder::CreateCall` and `CallInst::Create` have
  been removed
  • Loading branch information
yhls committed Apr 14, 2020
1 parent 0722cb3 commit 29232a0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 35 deletions.
6 changes: 4 additions & 2 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ static GlobalVariable *emit_plt_thunk(
SmallVector<Value*, 16> args;
for (Function::arg_iterator arg = plt->arg_begin(), arg_e = plt->arg_end(); arg != arg_e; ++arg)
args.push_back(&*arg);
CallInst *ret = irbuilder.CreateCall(ptr, ArrayRef<Value*>(args));
CallInst *ret = irbuilder.CreateCall(
cast<FunctionType>(ptr->getType()->getPointerElementType()),
ptr, ArrayRef<Value*>(args));
ret->setAttributes(attrs);
if (cc != CallingConv::C)
ret->setCallingConv(cc);
Expand Down Expand Up @@ -1029,7 +1031,7 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
std::stringstream name;
name << "jl_llvmcall" << llvmcallnumbering++;
f->setName(name.str());
f = cast<Function>(prepare_call(function_proto(f)));
f = cast<Function>(prepare_call(function_proto(f)).getCallee());
}
else {
f->setLinkage(GlobalValue::LinkOnceODRLinkage);
Expand Down
8 changes: 5 additions & 3 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ static Function *function_proto(Function *F, Module *M = nullptr)
}

#define prepare_call(Callee) prepare_call_in(jl_Module, (Callee))
static Value *prepare_call_in(Module *M, Value *Callee)
static FunctionCallee prepare_call_in(Module *M, Value *Callee)
{
if (Function *F = dyn_cast<Function>(Callee)) {
GlobalValue *local = M->getNamedValue(Callee->getName());
if (!local) {
local = function_proto(F, M);
}
return local;
Callee = local;
}
return Callee;
FunctionType *FnTy = cast<FunctionType>(
Callee->getType()->getPointerElementType());
return {FnTy, Callee};
}

// Take an arbitrary untracked value and make it gc-tracked
Expand Down
27 changes: 12 additions & 15 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ static CallInst *emit_jlcall(jl_codectx_t &ctx, Value *theFptr, Value *theF,
}
FunctionType *FTy = FunctionType::get(T_prjlvalue, argsT, false);
CallInst *result = ctx.builder.CreateCall(FTy,
ctx.builder.CreateBitCast(prepare_call(theFptr), FTy->getPointerTo()),
ctx.builder.CreateBitCast(prepare_call(theFptr).getCallee(), FTy->getPointerTo()),
theArgs);
add_return_attr(result, Attribute::NonNull);
result->setCallingConv(cc);
Expand Down Expand Up @@ -2836,7 +2836,7 @@ static jl_cgval_t emit_invoke(jl_codectx_t &ctx, jl_expr_t *ex, jl_value_t *rt)
}
}
if (!handled) {
Value *r = emit_jlcall(ctx, prepare_call(jlinvoke_func), boxed(ctx, lival), argv, nargs, JLCALL_F2_CC);
Value *r = emit_jlcall(ctx, prepare_call(jlinvoke_func).getCallee(), boxed(ctx, lival), argv, nargs, JLCALL_F2_CC);
result = mark_julia_type(ctx, r, true, rt);
}
if (result.typ == jl_bottom_type)
Expand Down Expand Up @@ -3901,26 +3901,21 @@ static Function *emit_tojlinvoke(jl_code_instance_t *codeinst, Module *M, jl_cod
ctx.f = f; // for jl_Module
BasicBlock *b0 = BasicBlock::Create(jl_LLVMContext, "top", f);
ctx.builder.SetInsertPoint(b0);
Value *theFptr;
FunctionCallee theFunc;
Value *theFarg;
if (codeinst->invoke != NULL) {
StringRef theFptrName = jl_ExecutionEngine->getFunctionAtAddress((uintptr_t)codeinst->invoke, codeinst);
theFptr = M->getOrInsertFunction(theFptrName, jlinvoke_func->getFunctionType())
#if JL_LLVM_VERSION >= 90000
.getCallee();
#else
;
#endif
theFunc = M->getOrInsertFunction(theFptrName, jlinvoke_func->getFunctionType());
theFarg = literal_pointer_val(ctx, (jl_value_t*)codeinst);
}
else {
theFptr = prepare_call(jlinvoke_func);
theFunc = prepare_call(jlinvoke_func);
theFarg = literal_pointer_val(ctx, (jl_value_t*)codeinst->def);
}
theFarg = maybe_decay_untracked(theFarg);
auto args = f->arg_begin();
CallInst *r = ctx.builder.CreateCall(theFptr, { &*args, &*++args, &*++args, theFarg });
r->setAttributes(cast<Function>(theFptr)->getAttributes());
CallInst *r = ctx.builder.CreateCall(theFunc, { &*args, &*++args, &*++args, theFarg });
r->setAttributes(cast<Function>(theFunc.getCallee())->getAttributes());
ctx.builder.CreateRet(r);
return f;
}
Expand Down Expand Up @@ -4344,7 +4339,7 @@ static Function* gen_cfun_wrapper(
ctx.builder.CreateBr(b_after);
ctx.builder.SetInsertPoint(b_generic);
}
Value *ret = emit_jlcall(ctx, prepare_call(jlapplygeneric_func), NULL, inputargs, nargs + 1, JLCALL_F_CC);
Value *ret = emit_jlcall(ctx, prepare_call(jlapplygeneric_func).getCallee(), NULL, inputargs, nargs + 1, JLCALL_F_CC);
if (age_ok) {
ctx.builder.CreateBr(b_after);
ctx.builder.SetInsertPoint(b_after);
Expand Down Expand Up @@ -4426,7 +4421,9 @@ static Function* gen_cfun_wrapper(
emit_cfunc_invalidate(gf_thunk, returninfo.cc, returninfo.return_roots, lam->specTypes, codeinst->rettype, nargs + 1, ctx.emission_context);
theFptr = ctx.builder.CreateSelect(age_ok, theFptr, gf_thunk);
}
CallInst *call = ctx.builder.CreateCall(theFptr, ArrayRef<Value*>(args));
CallInst *call = ctx.builder.CreateCall(
cast<FunctionType>(theFptr->getType()->getPointerElementType()),
theFptr, ArrayRef<Value*>(args));
call->setAttributes(returninfo.decl->getAttributes());
switch (returninfo.cc) {
case jl_returninfo_t::Boxed:
Expand Down Expand Up @@ -5693,7 +5690,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
emit_varinfo_assign(ctx, vi, tuple);
}
else {
restTuple = emit_jlcall(ctx, prepare_call(jltuple_func), maybe_decay_untracked(V_null),
restTuple = emit_jlcall(ctx, prepare_call(jltuple_func).getCallee(), maybe_decay_untracked(V_null),
vargs, ctx.nvargs, JLCALL_F_CC);
jl_cgval_t tuple = mark_julia_type(ctx, restTuple, true, vi.value.typ);
emit_varinfo_assign(ctx, vi, tuple);
Expand Down
28 changes: 14 additions & 14 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ static jl_value_t *staticeval_bitstype(const jl_cgval_t &targ)

static jl_cgval_t emit_runtime_call(jl_codectx_t &ctx, JL_I::intrinsic f, const jl_cgval_t *argv, size_t nargs)
{
Value *func = prepare_call(runtime_func[f]);
FunctionCallee func = prepare_call(runtime_func[f]);
Value **argvalues = (Value**)alloca(sizeof(Value*) * nargs);
for (size_t i = 0; i < nargs; ++i) {
argvalues[i] = boxed(ctx, argv[i]);
Expand Down Expand Up @@ -1059,7 +1059,7 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, Value **arg
case fma_float: {
assert(y->getType() == x->getType());
assert(z->getType() == y->getType());
Value *fmaintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::fma, makeArrayRef(t));
FunctionCallee fmaintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::fma, makeArrayRef(t));
return ctx.builder.CreateCall(fmaintr, {x, y, z});
}
case muladd_float: {
Expand Down Expand Up @@ -1089,7 +1089,7 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, Value **arg
(f == checked_smul_int ?
Intrinsic::smul_with_overflow :
Intrinsic::umul_with_overflow)))));
Value *intr = Intrinsic::getDeclaration(jl_Module, intr_id, makeArrayRef(t));
FunctionCallee intr = Intrinsic::getDeclaration(jl_Module, intr_id, makeArrayRef(t));
Value *res = ctx.builder.CreateCall(intr, {x, y});
Value *val = ctx.builder.CreateExtractValue(res, ArrayRef<unsigned>(0));
Value *obit = ctx.builder.CreateExtractValue(res, ArrayRef<unsigned>(1));
Expand Down Expand Up @@ -1206,26 +1206,26 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, Value **arg
ctx.builder.CreateAShr(x, uint_cnvt(ctx, t, y)));

case bswap_int: {
Value *bswapintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::bswap, makeArrayRef(t));
FunctionCallee bswapintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::bswap, makeArrayRef(t));
return ctx.builder.CreateCall(bswapintr, x);
}
case ctpop_int: {
Value *ctpopintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::ctpop, makeArrayRef(t));
FunctionCallee ctpopintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::ctpop, makeArrayRef(t));
return ctx.builder.CreateCall(ctpopintr, x);
}
case ctlz_int: {
Value *ctlz = Intrinsic::getDeclaration(jl_Module, Intrinsic::ctlz, makeArrayRef(t));
FunctionCallee ctlz = Intrinsic::getDeclaration(jl_Module, Intrinsic::ctlz, makeArrayRef(t));
y = ConstantInt::get(T_int1, 0);
return ctx.builder.CreateCall(ctlz, {x, y});
}
case cttz_int: {
Value *cttz = Intrinsic::getDeclaration(jl_Module, Intrinsic::cttz, makeArrayRef(t));
FunctionCallee cttz = Intrinsic::getDeclaration(jl_Module, Intrinsic::cttz, makeArrayRef(t));
y = ConstantInt::get(T_int1, 0);
return ctx.builder.CreateCall(cttz, {x, y});
}

case abs_float: {
Value *absintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::fabs, makeArrayRef(t));
FunctionCallee absintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::fabs, makeArrayRef(t));
return ctx.builder.CreateCall(absintr, x);
}
case copysign_float: {
Expand Down Expand Up @@ -1254,27 +1254,27 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, Value **arg
return ctx.builder.CreateXor(ctx.builder.CreateAdd(x, tmp), tmp);
}
case ceil_llvm: {
Value *ceilintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::ceil, makeArrayRef(t));
FunctionCallee ceilintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::ceil, makeArrayRef(t));
return ctx.builder.CreateCall(ceilintr, x);
}
case floor_llvm: {
Value *floorintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::floor, makeArrayRef(t));
FunctionCallee floorintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::floor, makeArrayRef(t));
return ctx.builder.CreateCall(floorintr, x);
}
case trunc_llvm: {
Value *truncintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::trunc, makeArrayRef(t));
FunctionCallee truncintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::trunc, makeArrayRef(t));
return ctx.builder.CreateCall(truncintr, x);
}
case rint_llvm: {
Value *rintintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::rint, makeArrayRef(t));
FunctionCallee rintintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::rint, makeArrayRef(t));
return ctx.builder.CreateCall(rintintr, x);
}
case sqrt_llvm: {
Value *sqrtintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::sqrt, makeArrayRef(t));
FunctionCallee sqrtintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::sqrt, makeArrayRef(t));
return ctx.builder.CreateCall(sqrtintr, x);
}
case sqrt_llvm_fast: {
Value *sqrtintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::sqrt, makeArrayRef(t));
FunctionCallee sqrtintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::sqrt, makeArrayRef(t));
return math_builder(ctx, true)().CreateCall(sqrtintr, x);
}

Expand Down
2 changes: 1 addition & 1 deletion src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S) {
else // CC == JLCALL_F2_CC // jl_invoke
FTy = FunctionType::get(T_prjlvalue, {T_prjlvalue, T_pprjlvalue, T_int32, T_prjlvalue}, false);
Value *newFptr = Builder.CreateBitCast(callee, FTy->getPointerTo());
CallInst *NewCall = CallInst::Create(newFptr, ReplacementArgs, "", CI);
CallInst *NewCall = CallInst::Create(FTy, newFptr, ReplacementArgs, "", CI);
NewCall->setTailCallKind(CI->getTailCallKind());
auto old_attrs = CI->getAttributes();
NewCall->setAttributes(AttributeList::get(CI->getContext(),
Expand Down

0 comments on commit 29232a0

Please sign in to comment.