Skip to content

Commit 91725a5

Browse files
vtjnashvchuravy
authored andcommitted
drop llvm 16 support (#56751)
Co-authored-by: Valentin Churavy <[email protected]>
1 parent 849519f commit 91725a5

28 files changed

+19
-634
lines changed

doc/src/devdocs/build/build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ The most complicated dependency is LLVM, for which we require additional patches
249249
For packaging Julia with LLVM, we recommend either:
250250
- bundling a Julia-only LLVM library inside the Julia package, or
251251
- adding the patches to the LLVM package of the distribution.
252-
* A complete list of patches is available in on [Github](https://github.com/JuliaLang/llvm-project) see the `julia-release/15.x` branch.
252+
* A complete list of patches is available in on [Github](https://github.com/JuliaLang/llvm-project) see the `julia-release/18.x` branch.
253253
* The only Julia-specific patch is the lib renaming (`llvm7-symver-jlprefix.patch`), which should _not_ be applied to a system LLVM.
254254
* The remaining patches are all upstream bug fixes, and have been contributed into upstream LLVM.
255255

src/APInt-C.cpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ void LLVMTrunc(jl_datatype_t *ty, integerPart *pa, jl_datatype_t *otys, integerP
475475
memcpy(pr, pa, onumbytes);
476476
}
477477

478-
#if JL_LLVM_VERSION >= 170000
479478
extern "C" JL_DLLEXPORT
480479
unsigned countr_zero_8(uint8_t Val) {
481480
return countr_zero(Val);
@@ -495,27 +494,6 @@ extern "C" JL_DLLEXPORT
495494
unsigned countr_zero_64(uint64_t Val) {
496495
return countr_zero(Val);
497496
}
498-
#else
499-
extern "C" JL_DLLEXPORT
500-
unsigned countTrailingZeros_8(uint8_t Val) {
501-
return countTrailingZeros(Val);
502-
}
503-
504-
extern "C" JL_DLLEXPORT
505-
unsigned countTrailingZeros_16(uint16_t Val) {
506-
return countTrailingZeros(Val);
507-
}
508-
509-
extern "C" JL_DLLEXPORT
510-
unsigned countTrailingZeros_32(uint32_t Val) {
511-
return countTrailingZeros(Val);
512-
}
513-
514-
extern "C" JL_DLLEXPORT
515-
unsigned countTrailingZeros_64(uint64_t Val) {
516-
return countTrailingZeros(Val);
517-
}
518-
#endif
519497

520498
extern "C" JL_DLLEXPORT
521499
void jl_LLVMSMod(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr) {
@@ -545,7 +523,6 @@ void jl_LLVMFlipSign(unsigned numbits, integerPart *pa, integerPart *pb, integer
545523
memcpy(pr, pa, numbytes);
546524
}
547525

548-
#if JL_LLVM_VERSION >= 170000
549526
extern "C" JL_DLLEXPORT
550527
unsigned LLVMPopcount(unsigned numbits, integerPart *pa) {
551528
CREATE(a)
@@ -575,34 +552,3 @@ unsigned LLVMCountl_zero(unsigned numbits, integerPart *pa) {
575552
CREATE(a)
576553
return a.countl_zero();
577554
}
578-
#else
579-
extern "C" JL_DLLEXPORT
580-
unsigned LLVMCountPopulation(unsigned numbits, integerPart *pa) {
581-
CREATE(a)
582-
return a.countPopulation();
583-
}
584-
585-
extern "C" JL_DLLEXPORT
586-
unsigned LLVMCountTrailingOnes(unsigned numbits, integerPart *pa) {
587-
CREATE(a)
588-
return a.countTrailingOnes();
589-
}
590-
591-
extern "C" JL_DLLEXPORT
592-
unsigned LLVMCountTrailingZeros(unsigned numbits, integerPart *pa) {
593-
CREATE(a)
594-
return a.countTrailingZeros();
595-
}
596-
597-
extern "C" JL_DLLEXPORT
598-
unsigned LLVMCountLeadingOnes(unsigned numbits, integerPart *pa) {
599-
CREATE(a)
600-
return a.countLeadingOnes();
601-
}
602-
603-
extern "C" JL_DLLEXPORT
604-
unsigned LLVMCountLeadingZeros(unsigned numbits, integerPart *pa) {
605-
CREATE(a)
606-
return a.countLeadingZeros();
607-
}
608-
#endif

src/APInt-C.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,11 @@ JL_DLLEXPORT int LLVMDiv_uov(unsigned numbits, integerPart *pa, integerPart *pb,
5454
JL_DLLEXPORT int LLVMRem_sov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
5555
JL_DLLEXPORT int LLVMRem_uov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
5656

57-
#if JL_LLVM_VERSION >= 170000
5857
JL_DLLEXPORT unsigned LLVMPopcount(unsigned numbits, integerPart *pa);
5958
JL_DLLEXPORT unsigned LLVMCountr_one(unsigned numbits, integerPart *pa);
6059
JL_DLLEXPORT unsigned LLVMCountr_zero(unsigned numbits, integerPart *pa);
6160
JL_DLLEXPORT unsigned LLVMCountl_one(unsigned numbits, integerPart *pa);
6261
JL_DLLEXPORT unsigned LLVMCountl_zero(unsigned numbits, integerPart *pa);
63-
#else
64-
JL_DLLEXPORT unsigned LLVMCountPopulation(unsigned numbits, integerPart *pa);
65-
JL_DLLEXPORT unsigned LLVMCountTrailingOnes(unsigned numbits, integerPart *pa);
66-
JL_DLLEXPORT unsigned LLVMCountTrailingZeros(unsigned numbits, integerPart *pa);
67-
JL_DLLEXPORT unsigned LLVMCountLeadingOnes(unsigned numbits, integerPart *pa);
68-
JL_DLLEXPORT unsigned LLVMCountLeadingZeros(unsigned numbits, integerPart *pa);
69-
#endif
7062

7163
JL_DLLEXPORT void LLVMFPtoSI(jl_datatype_t *ty, integerPart *pa, jl_datatype_t *oty, integerPart *pr);
7264
JL_DLLEXPORT void LLVMFPtoUI(jl_datatype_t *ty, integerPart *pa, jl_datatype_t *oty, integerPart *pr);
@@ -82,17 +74,10 @@ JL_DLLEXPORT int LLVMFPtoUI_exact(jl_datatype_t *ty, integerPart *pa, jl_datatyp
8274
JL_DLLEXPORT void jl_LLVMSMod(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
8375
JL_DLLEXPORT void jl_LLVMFlipSign(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
8476

85-
#if JL_LLVM_VERSION >= 170000
8677
JL_DLLEXPORT unsigned countr_zero_8(uint8_t Val);
8778
JL_DLLEXPORT unsigned countr_zero_16(uint16_t Val);
8879
JL_DLLEXPORT unsigned countr_zero_32(uint32_t Val);
8980
JL_DLLEXPORT unsigned countr_zero_64(uint64_t Val);
90-
#else
91-
JL_DLLEXPORT unsigned countTrailingZeros_8(uint8_t Val);
92-
JL_DLLEXPORT unsigned countTrailingZeros_16(uint16_t Val);
93-
JL_DLLEXPORT unsigned countTrailingZeros_32(uint32_t Val);
94-
JL_DLLEXPORT unsigned countTrailingZeros_64(uint64_t Val);
95-
#endif
9681

9782
//uint8_t getSwappedBytes_8(uint8_t Value); // no-op
9883
//uint16_t getSwappedBytes_16(uint16_t Value);

src/Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ else
7777
# JULIACODEGEN != LLVM
7878
endif
7979

80-
RT_LLVM_LIBS := support
81-
82-
ifeq ($(shell test $(LLVM_VER_MAJ) -ge 16 && echo true),true)
83-
RT_LLVM_LIBS += targetparser
84-
endif
80+
RT_LLVM_LIBS := support targetparser
8581

8682
ifeq ($(OS),WINNT)
8783
SRCS += win32_ucontext

src/aotcompile.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
#include "platform.h"
55

66
// target support
7-
#if JL_LLVM_VERSION >= 170000
87
#include <llvm/TargetParser/Triple.h>
9-
#else
10-
#include <llvm/ADT/Triple.h>
11-
#endif
128
#include "llvm/Support/CodeGen.h"
139
#include <llvm/ADT/Statistic.h>
1410
#include <llvm/Analysis/TargetLibraryInfo.h>
@@ -963,11 +959,7 @@ static FunctionInfo getFunctionWeight(const Function &F)
963959
auto val = F.getFnAttribute("julia.mv.clones").getValueAsString();
964960
// base16, so must be at most 4 * length bits long
965961
// popcount gives number of clones
966-
#if JL_LLVM_VERSION >= 170000
967962
info.clones = APInt(val.size() * 4, val, 16).popcount() + 1;
968-
#else
969-
info.clones = APInt(val.size() * 4, val, 16).countPopulation() + 1;
970-
#endif
971963
}
972964
info.weight += info.insts;
973965
// more basic blocks = more complex than just sum of insts,
@@ -1372,7 +1364,7 @@ static AOTOutputs add_output_impl(Module &M, TargetMachine &SourceTM, ShardTimer
13721364
// So for now we inject a definition of these functions that calls our runtime
13731365
// functions. We do so after optimization to avoid cloning these functions.
13741366
// Float16 conversion routines
1375-
#if defined(_CPU_X86_64_) && defined(_OS_DARWIN_) && JL_LLVM_VERSION >= 160000
1367+
#if defined(_CPU_X86_64_) && defined(_OS_DARWIN_)
13761368
// LLVM 16 reverted to soft-float ABI for passing half on x86_64 Darwin
13771369
// https://github.com/llvm/llvm-project/commit/2bcf51c7f82ca7752d1bba390a2e0cb5fdd05ca9
13781370
injectCRTAlias(M, "__gnu_h2f_ieee", "julia_half_to_float",
@@ -1721,9 +1713,6 @@ static SmallVector<AOTOutputs, 16> add_output(Module &M, TargetMachine &TM, Stri
17211713
std::function<void()> func = [&, i]() {
17221714
LLVMContext ctx;
17231715
ctx.setDiscardValueNames(true);
1724-
#if JL_LLVM_VERSION < 170000
1725-
SetOpaquePointer(ctx);
1726-
#endif
17271716
// Lazily deserialize the entire module
17281717
timers[i].deserialize.startTimer();
17291718
auto EM = getLazyBitcodeModule(MemoryBufferRef(StringRef(serialized.data(), serialized.size()), "Optimized"), ctx);
@@ -1888,7 +1877,7 @@ void jl_dump_native_impl(void *native_code,
18881877
Str += "10.14.0";
18891878
TheTriple.setOSName(Str);
18901879
}
1891-
Optional<Reloc::Model> RelocModel;
1880+
std::optional<Reloc::Model> RelocModel;
18921881
if (TheTriple.isOSLinux() || TheTriple.isOSFreeBSD() || TheTriple.isOSOpenBSD()) {
18931882
RelocModel = Reloc::PIC_;
18941883
}
@@ -1933,9 +1922,6 @@ void jl_dump_native_impl(void *native_code,
19331922
JL_TIMING(NATIVE_AOT, NATIVE_Sysimg);
19341923
LLVMContext Context;
19351924
Context.setDiscardValueNames(true);
1936-
#if JL_LLVM_VERSION < 170000
1937-
SetOpaquePointer(Context);
1938-
#endif
19391925
Module sysimgM("sysimg", Context);
19401926
sysimgM.setTargetTriple(TheTriple.str());
19411927
sysimgM.setDataLayout(DL);
@@ -2081,9 +2067,6 @@ void jl_dump_native_impl(void *native_code,
20812067
JL_TIMING(NATIVE_AOT, NATIVE_Metadata);
20822068
LLVMContext Context;
20832069
Context.setDiscardValueNames(true);
2084-
#if JL_LLVM_VERSION < 170000
2085-
SetOpaquePointer(Context);
2086-
#endif
20872070
Module metadataM("metadata", Context);
20882071
metadataM.setTargetTriple(TheTriple.str());
20892072
metadataM.setDataLayout(DL);
@@ -2299,16 +2282,7 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, jl_
22992282
}
23002283
else {
23012284
auto p = literal_static_pointer_val(global.first, global.second->getValueType());
2302-
#if JL_LLVM_VERSION >= 170000
23032285
Type *elty = PointerType::get(output.getContext(), 0);
2304-
#else
2305-
Type *elty;
2306-
if (p->getType()->isOpaquePointerTy()) {
2307-
elty = PointerType::get(output.getContext(), 0);
2308-
} else {
2309-
elty = p->getType()->getNonOpaquePointerElementType();
2310-
}
2311-
#endif
23122286
// For pretty printing, when LLVM inlines the global initializer into its loads
23132287
auto alias = GlobalAlias::create(elty, 0, GlobalValue::PrivateLinkage, global.second->getName() + ".jit", p, global.second->getParent());
23142288
global.second->setInitializer(ConstantExpr::getBitCast(alias, global.second->getValueType()));

src/ccall.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,6 @@ static GlobalVariable *emit_plt_thunk(
264264
SmallVector<Value*, 16> args;
265265
for (auto &arg : plt->args())
266266
args.push_back(&arg);
267-
#if JL_LLVM_VERSION < 170000
268-
assert(cast<PointerType>(ptr->getType())->isOpaqueOrPointeeTypeMatches(functype));
269-
#endif
270267
CallInst *ret = irbuilder.CreateCall(
271268
functype,
272269
ptr, ArrayRef<Value*>(args));

src/cgutils.cpp

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ static Value *decay_derived(jl_codectx_t &ctx, Value *V)
6060
if (T->getPointerAddressSpace() == AddressSpace::Derived)
6161
return V;
6262
// Once llvm deletes pointer element types, we won't need it here any more either.
63-
#if JL_LLVM_VERSION >= 170000
6463
Type *NewT = PointerType::get(T, AddressSpace::Derived);
65-
#else
66-
Type *NewT = PointerType::getWithSamePointeeType(cast<PointerType>(T), AddressSpace::Derived);
67-
#endif
6864
return ctx.builder.CreateAddrSpaceCast(V, NewT);
6965
}
7066

@@ -74,11 +70,7 @@ static Value *maybe_decay_tracked(jl_codectx_t &ctx, Value *V)
7470
Type *T = V->getType();
7571
if (T->getPointerAddressSpace() != AddressSpace::Tracked)
7672
return V;
77-
#if JL_LLVM_VERSION >= 170000
7873
Type *NewT = PointerType::get(T, AddressSpace::Derived);
79-
#else
80-
Type *NewT = PointerType::getWithSamePointeeType(cast<PointerType>(T), AddressSpace::Derived);
81-
#endif
8274
return ctx.builder.CreateAddrSpaceCast(V, NewT);
8375
}
8476

@@ -1010,54 +1002,6 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, jl_aliasinfo_t const
10101002
{
10111003
if (sz == 0)
10121004
return;
1013-
#if JL_LLVM_VERSION < 170000
1014-
// If the types are small and simple, use load and store directly.
1015-
// Going through memcpy can cause LLVM (e.g. SROA) to create bitcasts between float and int
1016-
// that interferes with other optimizations.
1017-
// TODO: Restore this for opaque pointers? Needs extra type information from the caller.
1018-
if (ctx.builder.getContext().supportsTypedPointers() && sz <= 64) {
1019-
// The size limit is arbitrary but since we mainly care about floating points and
1020-
// machine size vectors this should be enough.
1021-
const DataLayout &DL = jl_Module->getDataLayout();
1022-
auto srcty = cast<PointerType>(src->getType());
1023-
//TODO unsafe nonopaque pointer
1024-
auto srcel = srcty->getNonOpaquePointerElementType();
1025-
auto dstty = cast<PointerType>(dst->getType());
1026-
//TODO unsafe nonopaque pointer
1027-
auto dstel = dstty->getNonOpaquePointerElementType();
1028-
while (srcel->isArrayTy() && srcel->getArrayNumElements() == 1) {
1029-
src = ctx.builder.CreateConstInBoundsGEP2_32(srcel, src, 0, 0);
1030-
srcel = srcel->getArrayElementType();
1031-
srcty = srcel->getPointerTo();
1032-
}
1033-
while (dstel->isArrayTy() && dstel->getArrayNumElements() == 1) {
1034-
dst = ctx.builder.CreateConstInBoundsGEP2_32(dstel, dst, 0, 0);
1035-
dstel = dstel->getArrayElementType();
1036-
dstty = dstel->getPointerTo();
1037-
}
1038-
1039-
llvm::Type *directel = nullptr;
1040-
if (srcel->isSized() && srcel->isSingleValueType() && DL.getTypeStoreSize(srcel) == sz) {
1041-
directel = srcel;
1042-
dst = emit_bitcast(ctx, dst, srcty);
1043-
}
1044-
else if (dstel->isSized() && dstel->isSingleValueType() &&
1045-
DL.getTypeStoreSize(dstel) == sz) {
1046-
directel = dstel;
1047-
src = emit_bitcast(ctx, src, dstty);
1048-
}
1049-
if (directel) {
1050-
if (isa<Instruction>(src) && !src->hasName())
1051-
setName(ctx.emission_context, src, "memcpy_refined_src");
1052-
if (isa<Instruction>(dst) && !dst->hasName())
1053-
setName(ctx.emission_context, dst, "memcpy_refined_dst");
1054-
auto val = src_ai.decorateInst(ctx.builder.CreateAlignedLoad(directel, src, MaybeAlign(align_src), is_volatile));
1055-
dst_ai.decorateInst(ctx.builder.CreateAlignedStore(val, dst, align_dst, is_volatile));
1056-
++SkippedMemcpys;
1057-
return;
1058-
}
1059-
}
1060-
#endif
10611005
++EmittedMemcpys;
10621006

10631007
// the memcpy intrinsic does not allow to specify different alias tags
@@ -1940,7 +1884,7 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
19401884
// actual `isa` calls, this optimization should already have been performed upstream
19411885
// anyway, but having this optimization in codegen might still be beneficial for
19421886
// `typeassert`s if we can make it correct.
1943-
Optional<bool> known_isa;
1887+
std::optional<bool> known_isa;
19441888
jl_value_t *intersected_type = type;
19451889
if (x.constant)
19461890
known_isa = jl_isa(x.constant, type);
@@ -3786,11 +3730,7 @@ static void recursively_adjust_ptr_type(llvm::Value *Val, unsigned FromAS, unsig
37863730
for (auto *User : Val->users()) {
37873731
if (isa<GetElementPtrInst>(User)) {
37883732
GetElementPtrInst *Inst = cast<GetElementPtrInst>(User);
3789-
#if JL_LLVM_VERSION >= 170000
37903733
Inst->mutateType(PointerType::get(Inst->getType(), ToAS));
3791-
#else
3792-
Inst->mutateType(PointerType::getWithSamePointeeType(cast<PointerType>(Inst->getType()), ToAS));
3793-
#endif
37943734
recursively_adjust_ptr_type(Inst, FromAS, ToAS);
37953735
}
37963736
else if (isa<IntrinsicInst>(User)) {
@@ -3799,11 +3739,7 @@ static void recursively_adjust_ptr_type(llvm::Value *Val, unsigned FromAS, unsig
37993739
}
38003740
else if (isa<BitCastInst>(User)) {
38013741
BitCastInst *Inst = cast<BitCastInst>(User);
3802-
#if JL_LLVM_VERSION >= 170000
38033742
Inst->mutateType(PointerType::get(Inst->getType(), ToAS));
3804-
#else
3805-
Inst->mutateType(PointerType::getWithSamePointeeType(cast<PointerType>(Inst->getType()), ToAS));
3806-
#endif
38073743
recursively_adjust_ptr_type(Inst, FromAS, ToAS);
38083744
}
38093745
}

0 commit comments

Comments
 (0)