Skip to content

Commit 30b9363

Browse files
committed
Fix some compiler error on LLVM 21
Remaining issues are the removal of EHFrameRegistrar class and manual locking interface for ThreadSafeContext. Some other deprecation warnings are also left as is for now.
1 parent 7dfa7d1 commit 30b9363

File tree

6 files changed

+87
-17
lines changed

6 files changed

+87
-17
lines changed

src/aotcompile.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,9 @@ Function *IRLinker_copyFunctionProto(Module *DstM, Function *SF) {
541541
auto *F = Function::Create(SF->getFunctionType(), SF->getLinkage(),
542542
SF->getAddressSpace(), SF->getName(), DstM);
543543
F->copyAttributesFrom(SF);
544+
#if JL_LLVM_VERSION < 210000
544545
F->IsNewDbgInfoFormat = SF->IsNewDbgInfoFormat;
546+
#endif
545547

546548
// Remove these copied constants since they point to the source module.
547549
F->setPersonalityFn(nullptr);
@@ -2138,7 +2140,11 @@ void jl_dump_native_impl(void *native_code,
21382140
LLVMContext Context;
21392141
Context.setDiscardValueNames(true);
21402142
Module sysimgM("sysimg", Context);
2143+
#if JL_LLVM_VERSION < 210000
21412144
sysimgM.setTargetTriple(TheTriple.str());
2145+
#else
2146+
sysimgM.setTargetTriple(TheTriple);
2147+
#endif
21422148
sysimgM.setDataLayout(DL);
21432149
sysimgM.setStackProtectorGuard(StackProtectorGuard);
21442150
sysimgM.setOverrideStackAlignment(OverrideStackAlignment);
@@ -2206,7 +2212,11 @@ void jl_dump_native_impl(void *native_code,
22062212

22072213
data->M.withModuleDo([&](Module &dataM) {
22082214
JL_TIMING(NATIVE_AOT, NATIVE_Setup);
2215+
#if JL_LLVM_VERSION < 210000
22092216
dataM.setTargetTriple(TheTriple.str());
2217+
#else
2218+
dataM.setTargetTriple(TheTriple);
2219+
#endif
22102220
dataM.setDataLayout(DL);
22112221
dataM.setPICLevel(PICLevel::BigPIC);
22122222
auto &Context = dataM.getContext();
@@ -2307,7 +2317,11 @@ void jl_dump_native_impl(void *native_code,
23072317
LLVMContext Context;
23082318
Context.setDiscardValueNames(true);
23092319
Module metadataM("metadata", Context);
2320+
#if JL_LLVM_VERSION < 210000
23102321
metadataM.setTargetTriple(TheTriple.str());
2322+
#else
2323+
metadataM.setTargetTriple(TheTriple);
2324+
#endif
23112325
metadataM.setDataLayout(DL);
23122326
metadataM.setStackProtectorGuard(StackProtectorGuard);
23132327
metadataM.setOverrideStackAlignment(OverrideStackAlignment);

src/cgutils.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,13 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, jl_aliasinfo_t const
10091009
// above problem won't be as serious.
10101010

10111011
auto merged_ai = dst_ai.merge(src_ai);
1012+
#if JL_LLVM_VERSION < 210000
10121013
ctx.builder.CreateMemCpy(dst, align_dst, src, align_src, sz, is_volatile,
10131014
merged_ai.tbaa, merged_ai.tbaa_struct, merged_ai.scope, merged_ai.noalias);
1015+
#else
1016+
ctx.builder.CreateMemCpy(dst, align_dst, src, align_src, sz, is_volatile,
1017+
merged_ai.toAAMDNodes());
1018+
#endif
10141019
}
10151020

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

10251030
auto merged_ai = dst_ai.merge(src_ai);
1031+
#if JL_LLVM_VERSION < 210000
10261032
ctx.builder.CreateMemCpy(dst, align_dst, src, align_src, sz, is_volatile,
10271033
merged_ai.tbaa, merged_ai.tbaa_struct, merged_ai.scope, merged_ai.noalias);
1034+
#else
1035+
ctx.builder.CreateMemCpy(dst, align_dst, src, align_src, sz, is_volatile,
1036+
merged_ai.toAAMDNodes());
1037+
#endif
10281038
}
10291039

10301040
template<typename T1>

src/codegen.cpp

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,24 @@ AttributeSet Attributes(LLVMContext &C, std::initializer_list<Attribute::AttrKin
605605
return AttributeSet::get(C, ArrayRef<Attribute>(attrs));
606606
}
607607

608+
static inline Attribute NoCaptureAttr(LLVMContext &C)
609+
{
610+
#if JL_LLVM_VERSION < 210000
611+
return Attribute::get(C, Attribute::NoCapture);
612+
#else
613+
return Attribute::getWithCaptureInfo(C, CaptureInfo(CaptureComponents::None));
614+
#endif
615+
}
616+
617+
static inline void addNoCaptureAttr(AttrBuilder &param)
618+
{
619+
#if JL_LLVM_VERSION < 210000
620+
param.addAttribute(Attribute::NoCapture);
621+
#else
622+
param.addCapturesAttr(CaptureInfo(CaptureComponents::None));
623+
#endif
624+
}
625+
608626
static Type *get_pjlvalue(LLVMContext &C) { return JuliaType::get_pjlvalue_ty(C); }
609627

610628
static FunctionType *get_func_sig(LLVMContext &C) { return JuliaType::get_jlfunc_ty(C); }
@@ -617,7 +635,7 @@ static AttributeList get_func_attrs(LLVMContext &C)
617635
AttributeSet(),
618636
Attributes(C, {Attribute::NonNull}),
619637
{AttributeSet(),
620-
Attributes(C, {Attribute::NoAlias, Attribute::ReadOnly, Attribute::NoCapture, Attribute::NoUndef})});
638+
Attributes(C, {Attribute::NoAlias, Attribute::ReadOnly, Attribute::NoUndef}, {NoCaptureAttr(C)})});
621639
}
622640

623641
static AttributeList get_attrs_noreturn(LLVMContext &C)
@@ -998,7 +1016,7 @@ static const auto jllockvalue_func = new JuliaFunction<>{
9981016
[](LLVMContext &C) { return AttributeList::get(C,
9991017
AttributeSet(),
10001018
AttributeSet(),
1001-
{Attributes(C, {Attribute::NoCapture})}); },
1019+
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
10021020
};
10031021
static const auto jlunlockvalue_func = new JuliaFunction<>{
10041022
XSTR(jl_unlock_value),
@@ -1007,7 +1025,7 @@ static const auto jlunlockvalue_func = new JuliaFunction<>{
10071025
[](LLVMContext &C) { return AttributeList::get(C,
10081026
AttributeSet(),
10091027
AttributeSet(),
1010-
{Attributes(C, {Attribute::NoCapture})}); },
1028+
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
10111029
};
10121030
static const auto jllockfield_func = new JuliaFunction<>{
10131031
XSTR(jl_lock_field),
@@ -1016,7 +1034,7 @@ static const auto jllockfield_func = new JuliaFunction<>{
10161034
[](LLVMContext &C) { return AttributeList::get(C,
10171035
AttributeSet(),
10181036
AttributeSet(),
1019-
{Attributes(C, {Attribute::NoCapture})}); },
1037+
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
10201038
};
10211039
static const auto jlunlockfield_func = new JuliaFunction<>{
10221040
XSTR(jl_unlock_field),
@@ -1025,7 +1043,7 @@ static const auto jlunlockfield_func = new JuliaFunction<>{
10251043
[](LLVMContext &C) { return AttributeList::get(C,
10261044
AttributeSet(),
10271045
AttributeSet(),
1028-
{Attributes(C, {Attribute::NoCapture})}); },
1046+
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
10291047
};
10301048
static const auto jlenter_func = new JuliaFunction<>{
10311049
XSTR(jl_enter_handler),
@@ -1493,7 +1511,7 @@ static const auto gc_loaded_func = new JuliaFunction<>{
14931511
RetAttrs.addAttribute(Attribute::NonNull);
14941512
RetAttrs.addAttribute(Attribute::NoUndef);
14951513
return AttributeList::get(C, AttributeSet::get(C,FnAttrs), AttributeSet::get(C,RetAttrs),
1496-
{ Attributes(C, {Attribute::NonNull, Attribute::NoUndef, Attribute::ReadNone, Attribute::NoCapture}),
1514+
{ Attributes(C, {Attribute::NonNull, Attribute::NoUndef, Attribute::ReadNone}, {NoCaptureAttr(C)}),
14971515
Attributes(C, {Attribute::NonNull, Attribute::NoUndef, Attribute::ReadNone}) });
14981516
},
14991517
};
@@ -1688,6 +1706,15 @@ struct jl_aliasinfo_t {
16881706
// memory region non-aliasing. It should be deleted once the TBAA metadata
16891707
// is improved to encode only memory layout and *not* memory regions.
16901708
static jl_aliasinfo_t fromTBAA(jl_codectx_t &ctx, MDNode *tbaa);
1709+
1710+
AAMDNodes toAAMDNodes() const
1711+
{
1712+
#if JL_LLVM_VERSION < 220000
1713+
return AAMDNodes(tbaa, tbaa_struct, scope, noalias);
1714+
#else
1715+
return AAMDNodes(tbaa, tbaa_struct, scope, noalias, nullptr);
1716+
#endif
1717+
}
16911718
};
16921719

16931720
// metadata tracking for a llvm Value* during codegen
@@ -2685,7 +2712,11 @@ std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &conte
26852712
m->addModuleFlag(llvm::Module::Warning, "Debug Info Version",
26862713
llvm::DEBUG_METADATA_VERSION);
26872714
m->setDataLayout(DL);
2715+
#if JL_LLVM_VERSION < 210000
26882716
m->setTargetTriple(triple.str());
2717+
#else
2718+
m->setTargetTriple(triple);
2719+
#endif
26892720

26902721
if (triple.isOSWindows() && triple.getArch() == Triple::x86) {
26912722
// tell Win32 to assume the stack is always 16-byte aligned,
@@ -7944,15 +7975,15 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t &params, Module
79447975
AttrBuilder param(M->getContext());
79457976
param.addStructRetAttr(srt);
79467977
param.addAttribute(Attribute::NoAlias);
7947-
param.addAttribute(Attribute::NoCapture);
7978+
addNoCaptureAttr(param);
79487979
param.addAttribute(Attribute::NoUndef);
79497980
attrs.push_back(AttributeSet::get(M->getContext(), param));
79507981
assert(fsig.size() == 1);
79517982
}
79527983
if (props.cc == jl_returninfo_t::Union) {
79537984
AttrBuilder param(M->getContext());
79547985
param.addAttribute(Attribute::NoAlias);
7955-
param.addAttribute(Attribute::NoCapture);
7986+
addNoCaptureAttr(param);
79567987
param.addAttribute(Attribute::NoUndef);
79577988
attrs.push_back(AttributeSet::get(M->getContext(), param));
79587989
assert(fsig.size() == 1);
@@ -7961,7 +7992,7 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t &params, Module
79617992
if (props.return_roots) {
79627993
AttrBuilder param(M->getContext());
79637994
param.addAttribute(Attribute::NoAlias);
7964-
param.addAttribute(Attribute::NoCapture);
7995+
addNoCaptureAttr(param);
79657996
param.addAttribute(Attribute::NoUndef);
79667997
attrs.push_back(AttributeSet::get(M->getContext(), param));
79677998
fsig.push_back(getPointerTy(M->getContext()));
@@ -7995,7 +8026,7 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t &params, Module
79958026
AttrBuilder param(M->getContext());
79968027
Type *ty = et;
79978028
if (et == nullptr || et->isAggregateType()) { // aggregate types are passed by pointer
7998-
param.addAttribute(Attribute::NoCapture);
8029+
addNoCaptureAttr(param);
79998030
param.addAttribute(Attribute::ReadOnly);
80008031
ty = PointerType::get(M->getContext(), AddressSpace::Derived);
80018032
}
@@ -9888,7 +9919,9 @@ void linkFunctionBody(Function &Dst, Function &Src)
98889919
Dst.setPersonalityFn(Src.getPersonalityFn());
98899920
if (Src.hasPersonalityFn())
98909921
Dst.setPersonalityFn(Src.getPersonalityFn());
9922+
#if JL_LLVM_VERSION < 210000
98919923
assert(Src.IsNewDbgInfoFormat == Dst.IsNewDbgInfoFormat);
9924+
#endif
98929925

98939926
// Copy over the metadata attachments without remapping.
98949927
Dst.copyMetadata(&Src, 0);

src/debuginfo.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,13 @@ static int lookup_pointer(
505505
else {
506506
int havelock = jl_lock_profile_wr();
507507
assert(havelock); (void)havelock;
508-
info = context->getLineInfoForAddress(makeAddress(Section, pointer + slide), infoSpec);
508+
auto lineinfo = context->getLineInfoForAddress(makeAddress(Section, pointer + slide), infoSpec);
509509
jl_unlock_profile_wr();
510+
#if JL_LLVM_VERSION < 210000
511+
info = std::move(lineinfo);
512+
#else
513+
info = std::move(lineinfo.value());
514+
#endif
510515
}
511516

512517
jl_frame_t *frame = &(*frames)[i];

src/disasm.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,11 @@ static void jl_dump_asm_internal(
924924
// LLVM will destroy the formatted stream, and we keep the raw stream.
925925
std::unique_ptr<formatted_raw_ostream> ustream(new formatted_raw_ostream(rstream));
926926
std::unique_ptr<MCStreamer> Streamer(
927-
#if JL_LLVM_VERSION >= 190000
927+
#if JL_LLVM_VERSION >= 210000
928+
TheTarget->createAsmStreamer(Ctx, std::move(ustream),
929+
930+
std::move(IP), std::move(CE), std::move(MAB))
931+
#elif JL_LLVM_VERSION >= 190000
928932
TheTarget->createAsmStreamer(Ctx, std::move(ustream),
929933

930934
IP.release(), std::move(CE), std::move(MAB))
@@ -1268,8 +1272,8 @@ jl_value_t *jl_dump_function_asm_impl(jl_llvmf_dump_t* dump, char emit_mc, const
12681272
OutputAsmDialect = 0;
12691273
if (!strcmp(asm_variant, "intel"))
12701274
OutputAsmDialect = 1;
1271-
MCInstPrinter *InstPrinter = TM->getTarget().createMCInstPrinter(
1272-
jl_ExecutionEngine->getTargetTriple(), OutputAsmDialect, MAI, MII, MRI);
1275+
std::unique_ptr<MCInstPrinter> InstPrinter(TM->getTarget().createMCInstPrinter(
1276+
jl_ExecutionEngine->getTargetTriple(), OutputAsmDialect, MAI, MII, MRI));
12731277
std::unique_ptr<MCAsmBackend> MAB(TM->getTarget().createMCAsmBackend(
12741278
STI, MRI, Options));
12751279
std::unique_ptr<MCCodeEmitter> MCE;
@@ -1278,8 +1282,10 @@ jl_value_t *jl_dump_function_asm_impl(jl_llvmf_dump_t* dump, char emit_mc, const
12781282
}
12791283
auto FOut = std::make_unique<formatted_raw_ostream>(asmfile);
12801284
std::unique_ptr<MCStreamer> S(TM->getTarget().createAsmStreamer(
1281-
#if JL_LLVM_VERSION >= 190000
1282-
*Context, std::move(FOut), InstPrinter, std::move(MCE), std::move(MAB)
1285+
#if JL_LLVM_VERSION >= 210000
1286+
*Context, std::move(FOut), std::move(InstPrinter), std::move(MCE), std::move(MAB)
1287+
#elif JL_LLVM_VERSION >= 190000
1288+
*Context, std::move(FOut), InstPrinter.release(), std::move(MCE), std::move(MAB)
12831289
#else
12841290
*Context, std::move(FOut), true, true, InstPrinter, std::move(MCE),
12851291
std::move(MAB), false

src/jitlayers.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <llvm/ExecutionEngine/Orc/CompileUtils.h>
1515
#include <llvm/ExecutionEngine/Orc/ExecutionUtils.h>
1616
#include <llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h>
17+
#include <llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h>
1718
#include <llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h>
1819
#if JL_LLVM_VERSION >= 200000
1920
#include <llvm/ExecutionEngine/Orc/AbsoluteSymbols.h>
@@ -1931,7 +1932,8 @@ JuliaOJIT::JuliaOJIT()
19311932
MemMgr(createRTDyldMemoryManager()),
19321933
UnlockedObjectLayer(
19331934
ES,
1934-
[this]() {
1935+
[this](auto&&...) {
1936+
// LLVM 21+ passes in a memory buffer
19351937
std::unique_ptr<RuntimeDyld::MemoryManager> result(new ForwardingMemoryManager(MemMgr));
19361938
return result;
19371939
}

0 commit comments

Comments
 (0)