Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
935 changes: 490 additions & 445 deletions src/aotcompile.cpp

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,13 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, jl_aliasinfo_t const
// above problem won't be as serious.

auto merged_ai = dst_ai.merge(src_ai);
#if JL_LLVM_VERSION < 210000
ctx.builder.CreateMemCpy(dst, align_dst, src, align_src, sz, is_volatile,
merged_ai.tbaa, merged_ai.tbaa_struct, merged_ai.scope, merged_ai.noalias);
#else
ctx.builder.CreateMemCpy(dst, align_dst, src, align_src, sz, is_volatile,
merged_ai.toAAMDNodes());
#endif
}

static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, jl_aliasinfo_t const &dst_ai, Value *src,
Expand All @@ -1023,8 +1028,13 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, jl_aliasinfo_t const
++EmittedMemcpys;

auto merged_ai = dst_ai.merge(src_ai);
#if JL_LLVM_VERSION < 210000
ctx.builder.CreateMemCpy(dst, align_dst, src, align_src, sz, is_volatile,
merged_ai.tbaa, merged_ai.tbaa_struct, merged_ai.scope, merged_ai.noalias);
#else
ctx.builder.CreateMemCpy(dst, align_dst, src, align_src, sz, is_volatile,
merged_ai.toAAMDNodes());
#endif
}

template<typename T1>
Expand Down
57 changes: 45 additions & 12 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,24 @@ AttributeSet Attributes(LLVMContext &C, std::initializer_list<Attribute::AttrKin
return AttributeSet::get(C, ArrayRef<Attribute>(attrs));
}

static inline Attribute NoCaptureAttr(LLVMContext &C)
{
#if JL_LLVM_VERSION < 210000
return Attribute::get(C, Attribute::NoCapture);
#else
return Attribute::getWithCaptureInfo(C, CaptureInfo(CaptureComponents::None));
#endif
}

static inline void addNoCaptureAttr(AttrBuilder &param)
{
#if JL_LLVM_VERSION < 210000
param.addAttribute(Attribute::NoCapture);
#else
param.addCapturesAttr(CaptureInfo(CaptureComponents::None));
#endif
}

static Type *get_pjlvalue(LLVMContext &C) { return JuliaType::get_pjlvalue_ty(C); }

static FunctionType *get_func_sig(LLVMContext &C) { return JuliaType::get_jlfunc_ty(C); }
Expand All @@ -617,7 +635,7 @@ static AttributeList get_func_attrs(LLVMContext &C)
AttributeSet(),
Attributes(C, {Attribute::NonNull}),
{AttributeSet(),
Attributes(C, {Attribute::NoAlias, Attribute::ReadOnly, Attribute::NoCapture, Attribute::NoUndef})});
Attributes(C, {Attribute::NoAlias, Attribute::ReadOnly, Attribute::NoUndef}, {NoCaptureAttr(C)})});
}

static AttributeList get_attrs_noreturn(LLVMContext &C)
Expand Down Expand Up @@ -996,7 +1014,7 @@ static const auto jllockvalue_func = new JuliaFunction<>{
[](LLVMContext &C) { return AttributeList::get(C,
AttributeSet(),
AttributeSet(),
{Attributes(C, {Attribute::NoCapture})}); },
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
};
static const auto jlunlockvalue_func = new JuliaFunction<>{
XSTR(jl_unlock_value),
Expand All @@ -1005,7 +1023,7 @@ static const auto jlunlockvalue_func = new JuliaFunction<>{
[](LLVMContext &C) { return AttributeList::get(C,
AttributeSet(),
AttributeSet(),
{Attributes(C, {Attribute::NoCapture})}); },
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
};
static const auto jllockfield_func = new JuliaFunction<>{
XSTR(jl_lock_field),
Expand All @@ -1014,7 +1032,7 @@ static const auto jllockfield_func = new JuliaFunction<>{
[](LLVMContext &C) { return AttributeList::get(C,
AttributeSet(),
AttributeSet(),
{Attributes(C, {Attribute::NoCapture})}); },
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
};
static const auto jlunlockfield_func = new JuliaFunction<>{
XSTR(jl_unlock_field),
Expand All @@ -1023,7 +1041,7 @@ static const auto jlunlockfield_func = new JuliaFunction<>{
[](LLVMContext &C) { return AttributeList::get(C,
AttributeSet(),
AttributeSet(),
{Attributes(C, {Attribute::NoCapture})}); },
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
};
static const auto jlenter_func = new JuliaFunction<>{
XSTR(jl_enter_handler),
Expand Down Expand Up @@ -1489,7 +1507,7 @@ static const auto gc_loaded_func = new JuliaFunction<>{
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}, {NoCaptureAttr(C)}),
Attributes(C, {Attribute::NonNull, Attribute::NoUndef, Attribute::ReadNone}) });
},
};
Expand Down Expand Up @@ -1684,6 +1702,15 @@ struct jl_aliasinfo_t {
// memory region non-aliasing. It should be deleted once the TBAA metadata
// is improved to encode only memory layout and *not* memory regions.
static jl_aliasinfo_t fromTBAA(jl_codectx_t &ctx, MDNode *tbaa);

AAMDNodes toAAMDNodes() const
{
#if JL_LLVM_VERSION < 220000
return AAMDNodes(tbaa, tbaa_struct, scope, noalias);
#else
return AAMDNodes(tbaa, tbaa_struct, scope, noalias, nullptr);
#endif
}
};

// metadata tracking for a llvm Value* during codegen
Expand Down Expand Up @@ -2681,7 +2708,11 @@ std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &conte
m->addModuleFlag(llvm::Module::Warning, "Debug Info Version",
llvm::DEBUG_METADATA_VERSION);
m->setDataLayout(DL);
#if JL_LLVM_VERSION < 210000
m->setTargetTriple(triple.str());
#else
m->setTargetTriple(triple);
#endif

if (triple.isOSWindows() && triple.getArch() == Triple::x86) {
// tell Win32 to assume the stack is always 16-byte aligned,
Expand Down Expand Up @@ -7759,7 +7790,7 @@ const char *jl_generate_ccallable(Module *llvmmod, jl_value_t *nameval, jl_value
crt = (jl_value_t*)jl_any_type;
}
bool toboxed;
Type *lcrt = _julia_struct_to_llvm(&params, *params.tsctx.getContext(), crt, &toboxed);
Type *lcrt = _julia_struct_to_llvm(&params, params.getContext(), crt, &toboxed);
if (toboxed)
lcrt = JuliaType::get_prjlvalue_ty(lcrt->getContext());
size_t nargs = jl_nparams(sigt)-1;
Expand Down Expand Up @@ -7937,15 +7968,15 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t &params, Module
AttrBuilder param(M->getContext());
param.addStructRetAttr(srt);
param.addAttribute(Attribute::NoAlias);
param.addAttribute(Attribute::NoCapture);
addNoCaptureAttr(param);
param.addAttribute(Attribute::NoUndef);
attrs.push_back(AttributeSet::get(M->getContext(), param));
assert(fsig.size() == 1);
}
if (props.cc == jl_returninfo_t::Union) {
AttrBuilder param(M->getContext());
param.addAttribute(Attribute::NoAlias);
param.addAttribute(Attribute::NoCapture);
addNoCaptureAttr(param);
param.addAttribute(Attribute::NoUndef);
attrs.push_back(AttributeSet::get(M->getContext(), param));
assert(fsig.size() == 1);
Expand All @@ -7954,7 +7985,7 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t &params, Module
if (props.return_roots) {
AttrBuilder param(M->getContext());
param.addAttribute(Attribute::NoAlias);
param.addAttribute(Attribute::NoCapture);
addNoCaptureAttr(param);
param.addAttribute(Attribute::NoUndef);
attrs.push_back(AttributeSet::get(M->getContext(), param));
fsig.push_back(getPointerTy(M->getContext()));
Expand Down Expand Up @@ -7988,7 +8019,7 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t &params, Module
AttrBuilder param(M->getContext());
Type *ty = et;
if (et == nullptr || et->isAggregateType()) { // aggregate types are passed by pointer
param.addAttribute(Attribute::NoCapture);
addNoCaptureAttr(param);
param.addAttribute(Attribute::ReadOnly);
ty = PointerType::get(M->getContext(), AddressSpace::Derived);
}
Expand Down Expand Up @@ -8119,7 +8150,7 @@ static jl_llvm_functions_t
size_t min_world = src->min_world;
size_t max_world = src->max_world;
jl_llvm_functions_t declarations;
jl_codectx_t ctx(*params.tsctx.getContext(), params, min_world, max_world);
jl_codectx_t ctx(params.getContext(), params, min_world, max_world);
jl_datatype_t *vatyp = NULL;
JL_GC_PUSH2(&ctx.code, &vatyp);
ctx.code = src->code;
Expand Down Expand Up @@ -9884,7 +9915,9 @@ void linkFunctionBody(Function &Dst, Function &Src)
Dst.setPersonalityFn(Src.getPersonalityFn());
if (Src.hasPersonalityFn())
Dst.setPersonalityFn(Src.getPersonalityFn());
#if JL_LLVM_VERSION < 210000
assert(Src.IsNewDbgInfoFormat == Dst.IsNewDbgInfoFormat);
#endif

// Copy over the metadata attachments without remapping.
Dst.copyMetadata(&Src, 0);
Expand Down
7 changes: 6 additions & 1 deletion src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,13 @@ static int lookup_pointer(
else {
int havelock = jl_lock_profile_wr();
assert(havelock); (void)havelock;
info = context->getLineInfoForAddress(makeAddress(Section, pointer + slide), infoSpec);
auto lineinfo = context->getLineInfoForAddress(makeAddress(Section, pointer + slide), infoSpec);
jl_unlock_profile_wr();
#if JL_LLVM_VERSION < 210000
info = std::move(lineinfo);
#else
info = std::move(lineinfo.value());
#endif
}

jl_frame_t *frame = &(*frames)[i];
Expand Down
73 changes: 40 additions & 33 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,37 +506,38 @@ jl_value_t *jl_dump_function_ir_impl(jl_llvmf_dump_t *dump, char strip_ir_metada
auto TSM = std::unique_ptr<orc::ThreadSafeModule>(unwrap(dump->TSM));
//If TSM is not passed in, then the context MUST be locked externally.
//RAII will release the lock
std::optional<orc::ThreadSafeContext::Lock> lock;
if (TSM) {
lock.emplace(TSM->getContext().getLock());
}
Function *llvmf = cast<Function>(unwrap(dump->F));
if (!llvmf || (!llvmf->isDeclaration() && !llvmf->getParent()))
jl_error("jl_dump_function_ir: Expected Function* in a temporary Module");

LineNumberAnnotatedWriter AAW{"; ", false, debuginfo};
if (!llvmf->getParent()) {
// print the function declaration as-is
llvmf->print(stream, &AAW);
delete llvmf;
}
else {
assert(TSM && TSM->getModuleUnlocked() == llvmf->getParent() && "Passed module was not the same as function parent!");
auto m = TSM->getModuleUnlocked();
if (strip_ir_metadata) {
std::string llvmfn(llvmf->getName());
jl_strip_llvm_addrspaces(m);
jl_strip_llvm_debug(m, true, &AAW);
// rewriting the function type creates a new function, so look it up again
llvmf = m->getFunction(llvmfn);
}
if (dump_module) {
m->print(stream, &AAW);
orc::ThreadSafeContext TSCtx;
if (TSM)
TSCtx = TSM->getContext();
withContextDo(TSCtx, [&] (LLVMContext*) {
Function *llvmf = cast<Function>(unwrap(dump->F));
if (!llvmf || (!llvmf->isDeclaration() && !llvmf->getParent()))
jl_error("jl_dump_function_ir: Expected Function* in a temporary Module");

LineNumberAnnotatedWriter AAW{"; ", false, debuginfo};
if (!llvmf->getParent()) {
// print the function declaration as-is
llvmf->print(stream, &AAW);
delete llvmf;
}
else {
llvmf->print(stream, &AAW);
assert(TSM && TSM->getModuleUnlocked() == llvmf->getParent() && "Passed module was not the same as function parent!");
auto m = TSM->getModuleUnlocked();
if (strip_ir_metadata) {
std::string llvmfn(llvmf->getName());
jl_strip_llvm_addrspaces(m);
jl_strip_llvm_debug(m, true, &AAW);
// rewriting the function type creates a new function, so look it up again
llvmf = m->getFunction(llvmfn);
}
if (dump_module) {
m->print(stream, &AAW);
}
else {
llvmf->print(stream, &AAW);
}
}
}
});
}

return jl_pchar_to_string(stream.str().data(), stream.str().size());
Expand Down Expand Up @@ -924,7 +925,11 @@ static void jl_dump_asm_internal(
// LLVM will destroy the formatted stream, and we keep the raw stream.
std::unique_ptr<formatted_raw_ostream> ustream(new formatted_raw_ostream(rstream));
std::unique_ptr<MCStreamer> Streamer(
#if JL_LLVM_VERSION >= 190000
#if JL_LLVM_VERSION >= 210000
TheTarget->createAsmStreamer(Ctx, std::move(ustream),

std::move(IP), std::move(CE), std::move(MAB))
#elif JL_LLVM_VERSION >= 190000
TheTarget->createAsmStreamer(Ctx, std::move(ustream),

IP.release(), std::move(CE), std::move(MAB))
Expand Down Expand Up @@ -1268,8 +1273,8 @@ jl_value_t *jl_dump_function_asm_impl(jl_llvmf_dump_t* dump, char emit_mc, const
OutputAsmDialect = 0;
if (!strcmp(asm_variant, "intel"))
OutputAsmDialect = 1;
MCInstPrinter *InstPrinter = TM->getTarget().createMCInstPrinter(
jl_ExecutionEngine->getTargetTriple(), OutputAsmDialect, MAI, MII, MRI);
std::unique_ptr<MCInstPrinter> InstPrinter(TM->getTarget().createMCInstPrinter(
jl_ExecutionEngine->getTargetTriple(), OutputAsmDialect, MAI, MII, MRI));
std::unique_ptr<MCAsmBackend> MAB(TM->getTarget().createMCAsmBackend(
STI, MRI, Options));
std::unique_ptr<MCCodeEmitter> MCE;
Expand All @@ -1278,8 +1283,10 @@ jl_value_t *jl_dump_function_asm_impl(jl_llvmf_dump_t* dump, char emit_mc, const
}
auto FOut = std::make_unique<formatted_raw_ostream>(asmfile);
std::unique_ptr<MCStreamer> S(TM->getTarget().createAsmStreamer(
#if JL_LLVM_VERSION >= 190000
*Context, std::move(FOut), InstPrinter, std::move(MCE), std::move(MAB)
#if JL_LLVM_VERSION >= 210000
*Context, std::move(FOut), std::move(InstPrinter), std::move(MCE), std::move(MAB)
#elif JL_LLVM_VERSION >= 190000
*Context, std::move(FOut), InstPrinter.release(), std::move(MCE), std::move(MAB)
#else
*Context, std::move(FOut), true, true, InstPrinter, std::move(MCE),
std::move(MAB), false
Expand Down
Loading