Skip to content

Commit a9acd43

Browse files
authored
(Mostly) Trivial part of LLVM 21 support (#60356)
Split out of #59946 to make it hopefully easier to review.
1 parent 42d461a commit a9acd43

File tree

7 files changed

+115
-18
lines changed

7 files changed

+115
-18
lines changed

src/aotcompile.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,9 @@ Function *IRLinker_copyFunctionProto(Module *DstM, Function *SF) {
565565
auto *F = Function::Create(SF->getFunctionType(), SF->getLinkage(),
566566
SF->getAddressSpace(), SF->getName(), DstM);
567567
F->copyAttributesFrom(SF);
568+
#if JL_LLVM_VERSION < 210000
568569
F->IsNewDbgInfoFormat = SF->IsNewDbgInfoFormat;
570+
#endif
569571

570572
// Remove these copied constants since they point to the source module.
571573
F->setPersonalityFn(nullptr);
@@ -1557,7 +1559,11 @@ static AOTOutputs add_output_impl(Module &M, TargetMachine &SourceTM, ShardTimer
15571559
AOTOutputs out;
15581560
auto TM = std::unique_ptr<TargetMachine>(
15591561
SourceTM.getTarget().createTargetMachine(
1562+
#if JL_LLVM_VERSION < 210000
15601563
SourceTM.getTargetTriple().str(),
1564+
#else
1565+
SourceTM.getTargetTriple(),
1566+
#endif
15611567
SourceTM.getTargetCPU(),
15621568
SourceTM.getTargetFeatureString(),
15631569
SourceTM.Options,
@@ -1585,7 +1591,11 @@ static AOTOutputs add_output_impl(Module &M, TargetMachine &SourceTM, ShardTimer
15851591

15861592
auto PMTM = std::unique_ptr<TargetMachine>(
15871593
SourceTM.getTarget().createTargetMachine(
1594+
#if JL_LLVM_VERSION < 210000
15881595
SourceTM.getTargetTriple().str(),
1596+
#else
1597+
SourceTM.getTargetTriple(),
1598+
#endif
15891599
SourceTM.getTargetCPU(),
15901600
SourceTM.getTargetFeatureString(),
15911601
SourceTM.Options,
@@ -2141,7 +2151,11 @@ void jl_dump_native_impl(void *native_code,
21412151
}
21422152
std::unique_ptr<TargetMachine> SourceTM(
21432153
jl_ExecutionEngine->getTarget().createTargetMachine(
2154+
#if JL_LLVM_VERSION < 210000
21442155
TheTriple.getTriple(),
2156+
#else
2157+
TheTriple,
2158+
#endif
21452159
jl_ExecutionEngine->getTargetCPU(),
21462160
jl_ExecutionEngine->getTargetFeatureString(),
21472161
jl_ExecutionEngine->getTargetOptions(),
@@ -2174,7 +2188,11 @@ void jl_dump_native_impl(void *native_code,
21742188
LLVMContext Context;
21752189
Context.setDiscardValueNames(true);
21762190
Module sysimgM("sysimg", Context);
2191+
#if JL_LLVM_VERSION < 210000
21772192
sysimgM.setTargetTriple(TheTriple.str());
2193+
#else
2194+
sysimgM.setTargetTriple(TheTriple);
2195+
#endif
21782196
sysimgM.setDataLayout(DL);
21792197
sysimgM.setStackProtectorGuard(StackProtectorGuard);
21802198
sysimgM.setOverrideStackAlignment(OverrideStackAlignment);
@@ -2242,7 +2260,11 @@ void jl_dump_native_impl(void *native_code,
22422260

22432261
data->M.withModuleDo([&](Module &dataM) {
22442262
JL_TIMING(NATIVE_AOT, NATIVE_Setup);
2263+
#if JL_LLVM_VERSION < 210000
22452264
dataM.setTargetTriple(TheTriple.str());
2265+
#else
2266+
dataM.setTargetTriple(TheTriple);
2267+
#endif
22462268
dataM.setDataLayout(DL);
22472269
dataM.setPICLevel(PICLevel::BigPIC);
22482270
auto &Context = dataM.getContext();
@@ -2343,7 +2365,11 @@ void jl_dump_native_impl(void *native_code,
23432365
LLVMContext Context;
23442366
Context.setDiscardValueNames(true);
23452367
Module metadataM("metadata", Context);
2368+
#if JL_LLVM_VERSION < 210000
23462369
metadataM.setTargetTriple(TheTriple.str());
2370+
#else
2371+
metadataM.setTargetTriple(TheTriple);
2372+
#endif
23472373
metadataM.setDataLayout(DL);
23482374
metadataM.setStackProtectorGuard(StackProtectorGuard);
23492375
metadataM.setOverrideStackAlignment(OverrideStackAlignment);

src/cgmemmgr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,10 +1013,19 @@ class JLJITLinkMemoryManager::InFlightAlloc
10131013
if (!FA)
10141014
return OnFinalized(FA.takeError());
10151015
// Need to handle dealloc actions when we GC code
1016+
#if JL_LLVM_VERSION >= 210000 && JL_LLVM_VERSION < 220000
1017+
// This change was reverted before llvm 22 is branched off
1018+
orc::shared::runFinalizeActions(GP->allocActions(), [&] (auto E) {
1019+
if (!E)
1020+
return OnFinalized(E.takeError());
1021+
OnFinalized(std::move(FA));
1022+
});
1023+
#else
10161024
auto E = orc::shared::runFinalizeActions(GP->allocActions());
10171025
if (!E)
10181026
return OnFinalized(E.takeError());
10191027
OnFinalized(std::move(FA));
1028+
#endif
10201029
});
10211030
}
10221031
};

src/cgutils.cpp

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

11791179
auto merged_ai = dst_ai.merge(src_ai);
1180+
#if JL_LLVM_VERSION < 210000
11801181
ctx.builder.CreateMemCpy(dst, align_dst, src, align_src, sz, is_volatile,
11811182
merged_ai.tbaa, merged_ai.tbaa_struct, merged_ai.scope, merged_ai.noalias);
1183+
#else
1184+
ctx.builder.CreateMemCpy(dst, align_dst, src, align_src, sz, is_volatile,
1185+
merged_ai.toAAMDNodes());
1186+
#endif
11821187
}
11831188

11841189
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)
@@ -996,7 +1014,7 @@ static const auto jllockvalue_func = new JuliaFunction<>{
9961014
[](LLVMContext &C) { return AttributeList::get(C,
9971015
AttributeSet(),
9981016
AttributeSet(),
999-
{Attributes(C, {Attribute::NoCapture})}); },
1017+
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
10001018
};
10011019
static const auto jlunlockvalue_func = new JuliaFunction<>{
10021020
XSTR(jl_unlock_value),
@@ -1005,7 +1023,7 @@ static const auto jlunlockvalue_func = new JuliaFunction<>{
10051023
[](LLVMContext &C) { return AttributeList::get(C,
10061024
AttributeSet(),
10071025
AttributeSet(),
1008-
{Attributes(C, {Attribute::NoCapture})}); },
1026+
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
10091027
};
10101028
static const auto jllockfield_func = new JuliaFunction<>{
10111029
XSTR(jl_lock_field),
@@ -1014,7 +1032,7 @@ static const auto jllockfield_func = new JuliaFunction<>{
10141032
[](LLVMContext &C) { return AttributeList::get(C,
10151033
AttributeSet(),
10161034
AttributeSet(),
1017-
{Attributes(C, {Attribute::NoCapture})}); },
1035+
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
10181036
};
10191037
static const auto jlunlockfield_func = new JuliaFunction<>{
10201038
XSTR(jl_unlock_field),
@@ -1023,7 +1041,7 @@ static const auto jlunlockfield_func = new JuliaFunction<>{
10231041
[](LLVMContext &C) { return AttributeList::get(C,
10241042
AttributeSet(),
10251043
AttributeSet(),
1026-
{Attributes(C, {Attribute::NoCapture})}); },
1044+
{Attributes(C, {}, {NoCaptureAttr(C)})}); },
10271045
};
10281046
static const auto jlenter_func = new JuliaFunction<>{
10291047
XSTR(jl_enter_handler),
@@ -1489,7 +1507,7 @@ static const auto gc_loaded_func = new JuliaFunction<>{
14891507
RetAttrs.addAttribute(Attribute::NonNull);
14901508
RetAttrs.addAttribute(Attribute::NoUndef);
14911509
return AttributeList::get(C, AttributeSet::get(C,FnAttrs), AttributeSet::get(C,RetAttrs),
1492-
{ Attributes(C, {Attribute::NonNull, Attribute::NoUndef, Attribute::ReadNone, Attribute::NoCapture}),
1510+
{ Attributes(C, {Attribute::NonNull, Attribute::NoUndef, Attribute::ReadNone}, {NoCaptureAttr(C)}),
14931511
Attributes(C, {Attribute::NonNull, Attribute::NoUndef, Attribute::ReadNone}) });
14941512
},
14951513
};
@@ -1703,6 +1721,15 @@ struct jl_aliasinfo_t {
17031721
// memory region non-aliasing. It should be deleted once the TBAA metadata
17041722
// is improved to encode only memory layout and *not* memory regions.
17051723
static jl_aliasinfo_t fromTBAA(jl_codectx_t &ctx, MDNode *tbaa);
1724+
1725+
AAMDNodes toAAMDNodes() const
1726+
{
1727+
#if JL_LLVM_VERSION < 220000
1728+
return AAMDNodes(tbaa, tbaa_struct, scope, noalias);
1729+
#else
1730+
return AAMDNodes(tbaa, tbaa_struct, scope, noalias, nullptr);
1731+
#endif
1732+
}
17061733
};
17071734

17081735
// metadata tracking for a llvm Value* during codegen
@@ -2826,7 +2853,11 @@ std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &conte
28262853
m->addModuleFlag(llvm::Module::Warning, "Debug Info Version",
28272854
llvm::DEBUG_METADATA_VERSION);
28282855
m->setDataLayout(DL);
2856+
#if JL_LLVM_VERSION < 210000
28292857
m->setTargetTriple(triple.str());
2858+
#else
2859+
m->setTargetTriple(triple);
2860+
#endif
28302861

28312862
if (triple.isOSWindows() && triple.getArch() == Triple::x86) {
28322863
// tell Win32 to assume the stack is always 16-byte aligned,
@@ -8120,7 +8151,7 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t &params, Module
81208151
param.addAttribute("julia.return_roots", std::to_string(tracked_count));
81218152
}
81228153
param.addAttribute(Attribute::NoAlias);
8123-
param.addAttribute(Attribute::NoCapture);
8154+
addNoCaptureAttr(param);
81248155
param.addAttribute(Attribute::NoUndef);
81258156
attrs.push_back(AttributeSet::get(M->getContext(), param));
81268157
assert(fsig.size() == 1);
@@ -8132,7 +8163,7 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t &params, Module
81328163
param.addAttribute("julia.return_roots", std::to_string(tracked_count));
81338164
}
81348165
param.addAttribute(Attribute::NoAlias);
8135-
param.addAttribute(Attribute::NoCapture);
8166+
addNoCaptureAttr(param);
81368167
param.addAttribute(Attribute::NoUndef);
81378168
attrs.push_back(AttributeSet::get(M->getContext(), param));
81388169
assert(fsig.size() == 1);
@@ -8141,7 +8172,7 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t &params, Module
81418172
if (props.return_roots) {
81428173
AttrBuilder param(M->getContext());
81438174
param.addAttribute(Attribute::NoAlias);
8144-
param.addAttribute(Attribute::NoCapture);
8175+
addNoCaptureAttr(param);
81458176
param.addAttribute(Attribute::NoUndef);
81468177
param.addAttribute("julia.return_roots", std::to_string(props.return_roots));
81478178
attrs.push_back(AttributeSet::get(M->getContext(), param));
@@ -8176,7 +8207,7 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t &params, Module
81768207
AttrBuilder param(M->getContext());
81778208
Type *ty = et;
81788209
if (et == nullptr || et->isAggregateType()) { // aggregate types are passed by pointer
8179-
param.addAttribute(Attribute::NoCapture);
8210+
addNoCaptureAttr(param);
81808211
param.addAttribute(Attribute::ReadOnly);
81818212
ty = PointerType::get(M->getContext(), AddressSpace::Derived);
81828213
}
@@ -10058,7 +10089,9 @@ void linkFunctionBody(Function &Dst, Function &Src)
1005810089
Dst.setPersonalityFn(Src.getPersonalityFn());
1005910090
if (Src.hasPersonalityFn())
1006010091
Dst.setPersonalityFn(Src.getPersonalityFn());
10092+
#if JL_LLVM_VERSION < 210000
1006110093
assert(Src.IsNewDbgInfoFormat == Dst.IsNewDbgInfoFormat);
10094+
#endif
1006210095

1006310096
// Copy over the metadata attachments without remapping.
1006410097
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: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include <llvm/ExecutionEngine/Orc/CompileUtils.h>
1515
#include <llvm/ExecutionEngine/Orc/ExecutionUtils.h>
1616
#include <llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h>
17+
#if JL_LLVM_VERSION >= 210000
18+
# include <llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h>
19+
#endif
1720
#include <llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h>
1821
#if JL_LLVM_VERSION >= 200000
1922
#include <llvm/ExecutionEngine/Orc/AbsoluteSymbols.h>
@@ -1396,7 +1399,12 @@ namespace {
13961399
}
13971400
auto optlevel = CodeGenOptLevelFor(jl_options.opt_level);
13981401
auto TM = TheTarget->createTargetMachine(
1399-
TheTriple.getTriple(), TheCPU, FeaturesStr,
1402+
#if JL_LLVM_VERSION < 210000
1403+
TheTriple.getTriple(),
1404+
#else
1405+
TheTriple,
1406+
#endif
1407+
TheCPU, FeaturesStr,
14001408
options,
14011409
relocmodel,
14021410
codemodel,
@@ -1926,7 +1934,8 @@ JuliaOJIT::JuliaOJIT()
19261934
MemMgr(createRTDyldMemoryManager()),
19271935
UnlockedObjectLayer(
19281936
ES,
1929-
[this]() {
1937+
[this](auto&&...) {
1938+
// LLVM 21+ passes in a memory buffer
19301939
std::unique_ptr<RuntimeDyld::MemoryManager> result(new ForwardingMemoryManager(MemMgr));
19311940
return result;
19321941
}
@@ -2382,7 +2391,11 @@ std::unique_ptr<TargetMachine> JuliaOJIT::cloneTargetMachine() const
23822391
{
23832392
auto NewTM = std::unique_ptr<TargetMachine>(getTarget()
23842393
.createTargetMachine(
2394+
#if JL_LLVM_VERSION < 210000
23852395
getTargetTriple().str(),
2396+
#else
2397+
getTargetTriple(),
2398+
#endif
23862399
getTargetCPU(),
23872400
getTargetFeatureString(),
23882401
getTargetOptions(),

0 commit comments

Comments
 (0)