Skip to content
Merged
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
26 changes: 26 additions & 0 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,9 @@ Function *IRLinker_copyFunctionProto(Module *DstM, Function *SF) {
auto *F = Function::Create(SF->getFunctionType(), SF->getLinkage(),
SF->getAddressSpace(), SF->getName(), DstM);
F->copyAttributesFrom(SF);
#if JL_LLVM_VERSION < 210000
F->IsNewDbgInfoFormat = SF->IsNewDbgInfoFormat;
#endif

// Remove these copied constants since they point to the source module.
F->setPersonalityFn(nullptr);
Expand Down Expand Up @@ -1557,7 +1559,11 @@ static AOTOutputs add_output_impl(Module &M, TargetMachine &SourceTM, ShardTimer
AOTOutputs out;
auto TM = std::unique_ptr<TargetMachine>(
SourceTM.getTarget().createTargetMachine(
#if JL_LLVM_VERSION < 210000
SourceTM.getTargetTriple().str(),
#else
SourceTM.getTargetTriple(),
#endif
SourceTM.getTargetCPU(),
SourceTM.getTargetFeatureString(),
SourceTM.Options,
Expand Down Expand Up @@ -1585,7 +1591,11 @@ static AOTOutputs add_output_impl(Module &M, TargetMachine &SourceTM, ShardTimer

auto PMTM = std::unique_ptr<TargetMachine>(
SourceTM.getTarget().createTargetMachine(
#if JL_LLVM_VERSION < 210000
SourceTM.getTargetTriple().str(),
#else
SourceTM.getTargetTriple(),
#endif
SourceTM.getTargetCPU(),
SourceTM.getTargetFeatureString(),
SourceTM.Options,
Expand Down Expand Up @@ -2141,7 +2151,11 @@ void jl_dump_native_impl(void *native_code,
}
std::unique_ptr<TargetMachine> SourceTM(
jl_ExecutionEngine->getTarget().createTargetMachine(
#if JL_LLVM_VERSION < 210000
TheTriple.getTriple(),
#else
TheTriple,
#endif
jl_ExecutionEngine->getTargetCPU(),
jl_ExecutionEngine->getTargetFeatureString(),
jl_ExecutionEngine->getTargetOptions(),
Expand Down Expand Up @@ -2174,7 +2188,11 @@ void jl_dump_native_impl(void *native_code,
LLVMContext Context;
Context.setDiscardValueNames(true);
Module sysimgM("sysimg", Context);
#if JL_LLVM_VERSION < 210000
sysimgM.setTargetTriple(TheTriple.str());
#else
sysimgM.setTargetTriple(TheTriple);
#endif
sysimgM.setDataLayout(DL);
sysimgM.setStackProtectorGuard(StackProtectorGuard);
sysimgM.setOverrideStackAlignment(OverrideStackAlignment);
Expand Down Expand Up @@ -2242,7 +2260,11 @@ void jl_dump_native_impl(void *native_code,

data->M.withModuleDo([&](Module &dataM) {
JL_TIMING(NATIVE_AOT, NATIVE_Setup);
#if JL_LLVM_VERSION < 210000
dataM.setTargetTriple(TheTriple.str());
#else
dataM.setTargetTriple(TheTriple);
#endif
dataM.setDataLayout(DL);
dataM.setPICLevel(PICLevel::BigPIC);
auto &Context = dataM.getContext();
Expand Down Expand Up @@ -2343,7 +2365,11 @@ void jl_dump_native_impl(void *native_code,
LLVMContext Context;
Context.setDiscardValueNames(true);
Module metadataM("metadata", Context);
#if JL_LLVM_VERSION < 210000
metadataM.setTargetTriple(TheTriple.str());
#else
metadataM.setTargetTriple(TheTriple);
#endif
metadataM.setDataLayout(DL);
metadataM.setStackProtectorGuard(StackProtectorGuard);
metadataM.setOverrideStackAlignment(OverrideStackAlignment);
Expand Down
9 changes: 9 additions & 0 deletions src/cgmemmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,19 @@ class JLJITLinkMemoryManager::InFlightAlloc
if (!FA)
return OnFinalized(FA.takeError());
// Need to handle dealloc actions when we GC code
#if JL_LLVM_VERSION >= 210000 && JL_LLVM_VERSION < 220000
// This change was reverted before llvm 22 is branched off
orc::shared::runFinalizeActions(GP->allocActions(), [&] (auto E) {
if (!E)
return OnFinalized(E.takeError());
OnFinalized(std::move(FA));
});
#else
auto E = orc::shared::runFinalizeActions(GP->allocActions());
if (!E)
return OnFinalized(E.takeError());
OnFinalized(std::move(FA));
#endif
});
}
};
Expand Down
5 changes: 5 additions & 0 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,8 +1158,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
}

template<typename T1>
Expand Down
53 changes: 43 additions & 10 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 @@ -1703,6 +1721,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 @@ -2812,7 +2839,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 @@ -8105,15 +8136,15 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t &params, Module
param.addAttribute("julia.return_roots", std::to_string(tracked_count));
}
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 @@ -8122,7 +8153,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);
param.addAttribute("julia.return_roots", std::to_string(props.return_roots));
attrs.push_back(AttributeSet::get(M->getContext(), param));
Expand Down Expand Up @@ -8157,7 +8188,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 @@ -10038,7 +10069,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
16 changes: 11 additions & 5 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,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 +1272,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 +1282,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
17 changes: 15 additions & 2 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include <llvm/ExecutionEngine/Orc/CompileUtils.h>
#include <llvm/ExecutionEngine/Orc/ExecutionUtils.h>
#include <llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h>
#if JL_LLVM_VERSION >= 210000
# include <llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h>
#endif
#include <llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h>
#if JL_LLVM_VERSION >= 200000
#include <llvm/ExecutionEngine/Orc/AbsoluteSymbols.h>
Expand Down Expand Up @@ -1396,7 +1399,12 @@ namespace {
}
auto optlevel = CodeGenOptLevelFor(jl_options.opt_level);
auto TM = TheTarget->createTargetMachine(
TheTriple.getTriple(), TheCPU, FeaturesStr,
#if JL_LLVM_VERSION < 210000
TheTriple.getTriple(),
#else
TheTriple,
#endif
TheCPU, FeaturesStr,
options,
relocmodel,
codemodel,
Expand Down Expand Up @@ -1926,7 +1934,8 @@ JuliaOJIT::JuliaOJIT()
MemMgr(createRTDyldMemoryManager()),
UnlockedObjectLayer(
ES,
[this]() {
[this](auto&&...) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++ syntax sometimes is something else

// LLVM 21+ passes in a memory buffer
std::unique_ptr<RuntimeDyld::MemoryManager> result(new ForwardingMemoryManager(MemMgr));
return result;
}
Expand Down Expand Up @@ -2382,7 +2391,11 @@ std::unique_ptr<TargetMachine> JuliaOJIT::cloneTargetMachine() const
{
auto NewTM = std::unique_ptr<TargetMachine>(getTarget()
.createTargetMachine(
#if JL_LLVM_VERSION < 210000
getTargetTriple().str(),
#else
getTargetTriple(),
#endif
getTargetCPU(),
getTargetFeatureString(),
getTargetOptions(),
Expand Down