Skip to content

Commit

Permalink
Fixup new LLVM 16 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaraldi committed Nov 2, 2023
1 parent 66ee579 commit 9ba6de9
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 241 deletions.
216 changes: 108 additions & 108 deletions deps/checksums/clang

Large diffs are not rendered by default.

216 changes: 108 additions & 108 deletions deps/checksums/lld

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@ static SmallVector<AOTOutputs, 16> add_output(Module &M, TargetMachine &TM, Stri
for (unsigned i = 0; i < threads; i++) {
workers[i] = std::thread([&, i]() {
LLVMContext ctx;
SetOpaquePointer(ctx);
// Lazily deserialize the entire module
timers[i].deserialize.startTimer();
auto M = cantFail(getLazyBitcodeModule(MemoryBufferRef(StringRef(serialized.data(), serialized.size()), "Optimized"), ctx), "Error loading module");
Expand Down Expand Up @@ -1546,6 +1547,7 @@ void jl_dump_native_impl(void *native_code,
if (z) {
JL_TIMING(NATIVE_AOT, NATIVE_Sysimg);
LLVMContext Context;
SetOpaquePointer(Context);
Module sysimgM("sysimg", Context);
sysimgM.setTargetTriple(TheTriple.str());
sysimgM.setDataLayout(DL);
Expand Down Expand Up @@ -1682,6 +1684,7 @@ void jl_dump_native_impl(void *native_code,
{
JL_TIMING(NATIVE_AOT, NATIVE_Metadata);
LLVMContext Context;
SetOpaquePointer(Context);
Module metadataM("metadata", Context);
metadataM.setTargetTriple(TheTriple.str());
metadataM.setDataLayout(DL);
Expand Down
8 changes: 4 additions & 4 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4020,12 +4020,12 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg
Value *mlen = emit_genericmemorylen(ctx, mem, ref.typ);
Value *inbound = ctx.builder.CreateICmpULT(newdata, mlen);
ctx.builder.CreateCondBr(inbound, endBB, failBB);
ctx.f->getBasicBlockList().push_back(failBB);
failBB->insertInto(ctx.f);
ctx.builder.SetInsertPoint(failBB);
ctx.builder.CreateCall(prepare_call(jlboundserror_func),
{ mark_callee_rooted(ctx, boxed(ctx, ref)), i });
ctx.builder.CreateUnreachable();
ctx.f->getBasicBlockList().push_back(endBB);
endBB->insertInto(ctx.f);
ctx.builder.SetInsertPoint(endBB);
}
}
Expand Down Expand Up @@ -4093,12 +4093,12 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg
Value *inbound = ctx.builder.CreateICmpULT(idx0, mlen);
#endif
ctx.builder.CreateCondBr(inbound, endBB, failBB);
ctx.f->getBasicBlockList().push_back(failBB);
failBB->insertInto(ctx.f);
ctx.builder.SetInsertPoint(failBB);
ctx.builder.CreateCall(prepare_call(jlboundserror_func),
{ mark_callee_rooted(ctx, boxed(ctx, ref)), i });
ctx.builder.CreateUnreachable();
ctx.f->getBasicBlockList().push_back(endBB);
endBB->insertInto(ctx.f);
ctx.builder.SetInsertPoint(endBB);
}
}
Expand Down
42 changes: 28 additions & 14 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,11 +1336,24 @@ static const auto gc_loaded_func = new JuliaFunction<>{
[](LLVMContext &C) { return FunctionType::get(PointerType::get(JuliaType::get_prjlvalue_ty(C), AddressSpace::Loaded),
{JuliaType::get_prjlvalue_ty(C), PointerType::get(JuliaType::get_prjlvalue_ty(C), 0)}, false); },
[](LLVMContext &C) {
AttributeSet FnAttrs = Attributes(C, {Attribute::ReadNone, Attribute::NoSync, Attribute::NoUnwind, Attribute::Speculatable, Attribute::WillReturn, Attribute::NoRecurse});
AttributeSet RetAttrs = Attributes(C, {Attribute::NonNull, Attribute::NoUndef});
return AttributeList::get(C, FnAttrs, RetAttrs,
AttrBuilder FnAttrs(C);
FnAttrs.addAttribute(Attribute::NoSync);
FnAttrs.addAttribute(Attribute::NoUnwind);
FnAttrs.addAttribute(Attribute::Speculatable);
FnAttrs.addAttribute(Attribute::WillReturn);
FnAttrs.addAttribute(Attribute::NoRecurse);
#if JL_LLVM_VERSION >= 160000
FnAttrs.addMemoryAttr(MemoryEffects::none());
#else
FnAttrs.addAttribute(Attribute::ReadNone);
#endif
AttrBuilder RetAttrs(C);
RetAttrs.addAttribute(Attribute::NonNull);
RetAttrs.addAttribute(Attribute::NoUndef);
return AttributeList::get(C, AttributeSet::get(C,FnAttrs), AttributeSet::get(C,RetAttrs),
{ Attributes(C, {Attribute::NonNull, Attribute::NoUndef, Attribute::ReadNone, Attribute::NoCapture}),
Attributes(C, {Attribute::NonNull, Attribute::NoUndef, Attribute::ReadNone}) }); },
Attributes(C, {Attribute::NonNull, Attribute::NoUndef, Attribute::ReadNone}) });
},
};

// julia.call represents a call with julia calling convention, it is used as
Expand Down Expand Up @@ -3627,11 +3640,11 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
failBB = BasicBlock::Create(ctx.builder.getContext(), "oob");
endBB = BasicBlock::Create(ctx.builder.getContext(), "load");
ctx.builder.CreateCondBr(ctx.builder.CreateIsNull(mlen), failBB, endBB);
ctx.f->getBasicBlockList().push_back(failBB);
failBB->insertInto(ctx.f);
ctx.builder.SetInsertPoint(failBB);
ctx.builder.CreateCall(prepare_call(jlboundserror_func), { mark_callee_rooted(ctx, mem), ConstantInt::get(ctx.types().T_size, 1) });
ctx.builder.CreateUnreachable();
ctx.f->getBasicBlockList().push_back(endBB);
endBB->insertInto(ctx.f);
ctx.builder.SetInsertPoint(endBB);
}
bool isboxed = layout->flags.arrayelem_isboxed;
Expand Down Expand Up @@ -3700,11 +3713,11 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
failBB = BasicBlock::Create(ctx.builder.getContext(), "oob");
endBB = BasicBlock::Create(ctx.builder.getContext(), "load");
ctx.builder.CreateCondBr(ctx.builder.CreateIsNull(mlen), failBB, endBB);
ctx.f->getBasicBlockList().push_back(failBB);
failBB->insertInto(ctx.f);
ctx.builder.SetInsertPoint(failBB);
ctx.builder.CreateCall(prepare_call(jlboundserror_func), { mark_callee_rooted(ctx, mem), ConstantInt::get(ctx.types().T_size, 1) });
ctx.builder.CreateUnreachable();
ctx.f->getBasicBlockList().push_back(endBB);
endBB->insertInto(ctx.f);
ctx.builder.SetInsertPoint(endBB);
}
emit_typecheck(ctx, val, ety, "memoryset");
Expand Down Expand Up @@ -3804,8 +3817,9 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
BasicBlock *passBB, *endBB, *fromBB;
passBB = BasicBlock::Create(ctx.builder.getContext(), "load");
endBB = BasicBlock::Create(ctx.builder.getContext(), "oob");
ctx.f->getBasicBlockList().push_back(passBB);
ctx.f->getBasicBlockList().push_back(endBB);

passBB->insertInto(ctx.f);
endBB->insertInto(ctx.f);
fromBB = ctx.builder.CreateCondBr(oob, endBB, passBB)->getParent();
ctx.builder.SetInsertPoint(endBB);
result = ctx.builder.CreatePHI(getInt1Ty(ctx.builder.getContext()), 2);
Expand Down Expand Up @@ -5196,9 +5210,9 @@ static void emit_phinode_assign(jl_codectx_t &ctx, ssize_t idx, jl_value_t *r)
Instruction *phi = dest->clone();
phi->insertAfter(dest);
PHINode *Tindex_phi = PHINode::Create(getInt8Ty(ctx.builder.getContext()), jl_array_nrows(edges), "tindex_phi");
BB->getInstList().insert(InsertPt, Tindex_phi);
Tindex_phi->insertInto(BB, InsertPt);
PHINode *ptr_phi = PHINode::Create(ctx.types().T_prjlvalue, jl_array_nrows(edges), "ptr_phi");
BB->getInstList().insert(InsertPt, ptr_phi);
ptr_phi->insertInto(BB, InsertPt);
Value *isboxed = ctx.builder.CreateICmpNE(
ctx.builder.CreateAnd(Tindex_phi, ConstantInt::get(getInt8Ty(ctx.builder.getContext()), 0x80)),
ConstantInt::get(getInt8Ty(ctx.builder.getContext()), 0));
Expand All @@ -5216,7 +5230,7 @@ static void emit_phinode_assign(jl_codectx_t &ctx, ssize_t idx, jl_value_t *r)
}
else if (allunbox) {
PHINode *Tindex_phi = PHINode::Create(getInt8Ty(ctx.builder.getContext()), jl_array_nrows(edges), "tindex_phi");
BB->getInstList().insert(InsertPt, Tindex_phi);
Tindex_phi->insertInto(BB, InsertPt);
jl_cgval_t val = mark_julia_slot(NULL, phiType, Tindex_phi, ctx.tbaa().tbaa_stack);
ctx.PhiNodes.push_back(std::make_tuple(val, BB, dest, (PHINode*)NULL, r));
ctx.SAvalues[idx] = val;
Expand Down Expand Up @@ -5250,7 +5264,7 @@ static void emit_phinode_assign(jl_codectx_t &ctx, ssize_t idx, jl_value_t *r)
}
else {
value_phi = PHINode::Create(vtype, jl_array_nrows(edges), "value_phi");
BB->getInstList().insert(InsertPt, value_phi);
value_phi->insertInto(BB, InsertPt);
slot = mark_julia_type(ctx, value_phi, isboxed, phiType);
}
ctx.PhiNodes.push_back(std::make_tuple(slot, BB, dest, value_phi, r));
Expand Down
26 changes: 19 additions & 7 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ void optimizeDLSyms(Module &M) {
JuliaOJIT::DLSymOptimizer(true)(M);
}

void fixupTM(TargetMachine &TM){
void fixupTM(TargetMachine &TM) {
auto TheTriple = TM.getTargetTriple();
if (jl_options.opt_level < 2) {
if (!TheTriple.isARM() && !TheTriple.isPPC64() && !TheTriple.isAArch64())
Expand All @@ -1651,6 +1651,23 @@ void fixupTM(TargetMachine &TM){
}
}

void SetOpaquePointer(LLVMContext &ctx) {
#ifndef JL_LLVM_OPAQUE_POINTERS
ctx.setOpaquePointers(false);
#else
ctx.setOpaquePointers(true);
#endif
}

extern "C" JL_DLLEXPORT_CODEGEN
int JuliaUsesOpaquePtrs() {
#ifndef JL_LLVM_OPAQUE_POINTERS
return 0;
#else
return 1;
#endif
}

llvm::DataLayout jl_create_datalayout(TargetMachine &TM) {
// Mark our address spaces as non-integral
auto jl_data_layout = TM.createDataLayout();
Expand All @@ -1672,12 +1689,7 @@ JuliaOJIT::JuliaOJIT()
DLSymOpt(std::make_unique<DLSymOptimizer>(false)),
ContextPool([](){
auto ctx = std::make_unique<LLVMContext>();
if (!ctx->hasSetOpaquePointersValue())
#ifndef JL_LLVM_OPAQUE_POINTERS
ctx->setOpaquePointers(false);
#else
ctx->setOpaquePointers(true);
#endif
SetOpaquePointer(*ctx);
return orc::ThreadSafeContext(std::move(ctx));
}),
#ifdef JL_USE_JITLINK
Expand Down
1 change: 1 addition & 0 deletions src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ Module &jl_codegen_params_t::shared_module() JL_NOTSAFEPOINT {
return *_shared_module;
}
void fixupTM(TargetMachine &TM) JL_NOTSAFEPOINT;
void SetOpaquePointer(LLVMContext &ctx) JL_NOTSAFEPOINT;

void optimizeDLSyms(Module &M);

Expand Down

0 comments on commit 9ba6de9

Please sign in to comment.