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
2 changes: 1 addition & 1 deletion doc/src/devdocs/build/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ The most complicated dependency is LLVM, for which we require additional patches
For packaging Julia with LLVM, we recommend either:
- bundling a Julia-only LLVM library inside the Julia package, or
- adding the patches to the LLVM package of the distribution.
* A complete list of patches is available in on [Github](https://github.com/JuliaLang/llvm-project) see the `julia-release/15.x` branch.
* A complete list of patches is available in on [Github](https://github.com/JuliaLang/llvm-project) see the `julia-release/18.x` branch.
* The only Julia-specific patch is the lib renaming (`llvm7-symver-jlprefix.patch`), which should _not_ be applied to a system LLVM.
* The remaining patches are all upstream bug fixes, and have been contributed into upstream LLVM.

Expand Down
54 changes: 0 additions & 54 deletions src/APInt-C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ void LLVMTrunc(jl_datatype_t *ty, integerPart *pa, jl_datatype_t *otys, integerP
memcpy(pr, pa, onumbytes);
}

#if JL_LLVM_VERSION >= 170000
extern "C" JL_DLLEXPORT
unsigned countr_zero_8(uint8_t Val) {
return countr_zero(Val);
Expand All @@ -495,27 +494,6 @@ extern "C" JL_DLLEXPORT
unsigned countr_zero_64(uint64_t Val) {
return countr_zero(Val);
}
#else
extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_8(uint8_t Val) {
return countTrailingZeros(Val);
}

extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_16(uint16_t Val) {
return countTrailingZeros(Val);
}

extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_32(uint32_t Val) {
return countTrailingZeros(Val);
}

extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_64(uint64_t Val) {
return countTrailingZeros(Val);
}
#endif

extern "C" JL_DLLEXPORT
void jl_LLVMSMod(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr) {
Expand Down Expand Up @@ -545,7 +523,6 @@ void jl_LLVMFlipSign(unsigned numbits, integerPart *pa, integerPart *pb, integer
memcpy(pr, pa, numbytes);
}

#if JL_LLVM_VERSION >= 170000
extern "C" JL_DLLEXPORT
unsigned LLVMPopcount(unsigned numbits, integerPart *pa) {
CREATE(a)
Expand Down Expand Up @@ -575,34 +552,3 @@ unsigned LLVMCountl_zero(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countl_zero();
}
#else
extern "C" JL_DLLEXPORT
unsigned LLVMCountPopulation(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countPopulation();
}

extern "C" JL_DLLEXPORT
unsigned LLVMCountTrailingOnes(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countTrailingOnes();
}

extern "C" JL_DLLEXPORT
unsigned LLVMCountTrailingZeros(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countTrailingZeros();
}

extern "C" JL_DLLEXPORT
unsigned LLVMCountLeadingOnes(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countLeadingOnes();
}

extern "C" JL_DLLEXPORT
unsigned LLVMCountLeadingZeros(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countLeadingZeros();
}
#endif
15 changes: 0 additions & 15 deletions src/APInt-C.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,11 @@ JL_DLLEXPORT int LLVMDiv_uov(unsigned numbits, integerPart *pa, integerPart *pb,
JL_DLLEXPORT int LLVMRem_sov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
JL_DLLEXPORT int LLVMRem_uov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);

#if JL_LLVM_VERSION >= 170000
JL_DLLEXPORT unsigned LLVMPopcount(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountr_one(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountr_zero(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountl_one(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountl_zero(unsigned numbits, integerPart *pa);
#else
JL_DLLEXPORT unsigned LLVMCountPopulation(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountTrailingOnes(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountTrailingZeros(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountLeadingOnes(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountLeadingZeros(unsigned numbits, integerPart *pa);
#endif

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

#if JL_LLVM_VERSION >= 170000
JL_DLLEXPORT unsigned countr_zero_8(uint8_t Val);
JL_DLLEXPORT unsigned countr_zero_16(uint16_t Val);
JL_DLLEXPORT unsigned countr_zero_32(uint32_t Val);
JL_DLLEXPORT unsigned countr_zero_64(uint64_t Val);
#else
JL_DLLEXPORT unsigned countTrailingZeros_8(uint8_t Val);
JL_DLLEXPORT unsigned countTrailingZeros_16(uint16_t Val);
JL_DLLEXPORT unsigned countTrailingZeros_32(uint32_t Val);
JL_DLLEXPORT unsigned countTrailingZeros_64(uint64_t Val);
#endif

//uint8_t getSwappedBytes_8(uint8_t Value); // no-op
//uint16_t getSwappedBytes_16(uint16_t Value);
Expand Down
6 changes: 1 addition & 5 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ else
# JULIACODEGEN != LLVM
endif

RT_LLVM_LIBS := support

ifeq ($(shell test $(LLVM_VER_MAJ) -ge 16 && echo true),true)
RT_LLVM_LIBS += targetparser
endif
RT_LLVM_LIBS := support targetparser

ifeq ($(OS),WINNT)
SRCS += win32_ucontext
Expand Down
30 changes: 2 additions & 28 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
#include "platform.h"

// target support
#if JL_LLVM_VERSION >= 170000
#include <llvm/TargetParser/Triple.h>
#else
#include <llvm/ADT/Triple.h>
#endif
#include "llvm/Support/CodeGen.h"
#include <llvm/ADT/Statistic.h>
#include <llvm/Analysis/TargetLibraryInfo.h>
Expand Down Expand Up @@ -963,11 +959,7 @@ static FunctionInfo getFunctionWeight(const Function &F)
auto val = F.getFnAttribute("julia.mv.clones").getValueAsString();
// base16, so must be at most 4 * length bits long
// popcount gives number of clones
#if JL_LLVM_VERSION >= 170000
info.clones = APInt(val.size() * 4, val, 16).popcount() + 1;
#else
info.clones = APInt(val.size() * 4, val, 16).countPopulation() + 1;
#endif
}
info.weight += info.insts;
// more basic blocks = more complex than just sum of insts,
Expand Down Expand Up @@ -1372,7 +1364,7 @@ static AOTOutputs add_output_impl(Module &M, TargetMachine &SourceTM, ShardTimer
// So for now we inject a definition of these functions that calls our runtime
// functions. We do so after optimization to avoid cloning these functions.
// Float16 conversion routines
#if defined(_CPU_X86_64_) && defined(_OS_DARWIN_) && JL_LLVM_VERSION >= 160000
#if defined(_CPU_X86_64_) && defined(_OS_DARWIN_)
// LLVM 16 reverted to soft-float ABI for passing half on x86_64 Darwin
// https://github.com/llvm/llvm-project/commit/2bcf51c7f82ca7752d1bba390a2e0cb5fdd05ca9
injectCRTAlias(M, "__gnu_h2f_ieee", "julia_half_to_float",
Expand Down Expand Up @@ -1721,9 +1713,6 @@ static SmallVector<AOTOutputs, 16> add_output(Module &M, TargetMachine &TM, Stri
std::function<void()> func = [&, i]() {
LLVMContext ctx;
ctx.setDiscardValueNames(true);
#if JL_LLVM_VERSION < 170000
SetOpaquePointer(ctx);
#endif
// Lazily deserialize the entire module
timers[i].deserialize.startTimer();
auto EM = getLazyBitcodeModule(MemoryBufferRef(StringRef(serialized.data(), serialized.size()), "Optimized"), ctx);
Expand Down Expand Up @@ -1888,7 +1877,7 @@ void jl_dump_native_impl(void *native_code,
Str += "10.14.0";
TheTriple.setOSName(Str);
}
Optional<Reloc::Model> RelocModel;
std::optional<Reloc::Model> RelocModel;
if (TheTriple.isOSLinux() || TheTriple.isOSFreeBSD() || TheTriple.isOSOpenBSD()) {
RelocModel = Reloc::PIC_;
}
Expand Down Expand Up @@ -1933,9 +1922,6 @@ void jl_dump_native_impl(void *native_code,
JL_TIMING(NATIVE_AOT, NATIVE_Sysimg);
LLVMContext Context;
Context.setDiscardValueNames(true);
#if JL_LLVM_VERSION < 170000
SetOpaquePointer(Context);
#endif
Module sysimgM("sysimg", Context);
sysimgM.setTargetTriple(TheTriple.str());
sysimgM.setDataLayout(DL);
Expand Down Expand Up @@ -2081,9 +2067,6 @@ void jl_dump_native_impl(void *native_code,
JL_TIMING(NATIVE_AOT, NATIVE_Metadata);
LLVMContext Context;
Context.setDiscardValueNames(true);
#if JL_LLVM_VERSION < 170000
SetOpaquePointer(Context);
#endif
Module metadataM("metadata", Context);
metadataM.setTargetTriple(TheTriple.str());
metadataM.setDataLayout(DL);
Expand Down Expand Up @@ -2299,16 +2282,7 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, jl_
}
else {
auto p = literal_static_pointer_val(global.first, global.second->getValueType());
#if JL_LLVM_VERSION >= 170000
Type *elty = PointerType::get(output.getContext(), 0);
#else
Type *elty;
if (p->getType()->isOpaquePointerTy()) {
elty = PointerType::get(output.getContext(), 0);
} else {
elty = p->getType()->getNonOpaquePointerElementType();
}
#endif
// For pretty printing, when LLVM inlines the global initializer into its loads
auto alias = GlobalAlias::create(elty, 0, GlobalValue::PrivateLinkage, global.second->getName() + ".jit", p, global.second->getParent());
global.second->setInitializer(ConstantExpr::getBitCast(alias, global.second->getValueType()));
Expand Down
3 changes: 0 additions & 3 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ static GlobalVariable *emit_plt_thunk(
SmallVector<Value*, 16> args;
for (auto &arg : plt->args())
args.push_back(&arg);
#if JL_LLVM_VERSION < 170000
assert(cast<PointerType>(ptr->getType())->isOpaqueOrPointeeTypeMatches(functype));
#endif
CallInst *ret = irbuilder.CreateCall(
functype,
ptr, ArrayRef<Value*>(args));
Expand Down
66 changes: 1 addition & 65 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ static Value *decay_derived(jl_codectx_t &ctx, Value *V)
if (T->getPointerAddressSpace() == AddressSpace::Derived)
return V;
// Once llvm deletes pointer element types, we won't need it here any more either.
#if JL_LLVM_VERSION >= 170000
Type *NewT = PointerType::get(T, AddressSpace::Derived);
#else
Type *NewT = PointerType::getWithSamePointeeType(cast<PointerType>(T), AddressSpace::Derived);
#endif
return ctx.builder.CreateAddrSpaceCast(V, NewT);
}

Expand All @@ -74,11 +70,7 @@ static Value *maybe_decay_tracked(jl_codectx_t &ctx, Value *V)
Type *T = V->getType();
if (T->getPointerAddressSpace() != AddressSpace::Tracked)
return V;
#if JL_LLVM_VERSION >= 170000
Type *NewT = PointerType::get(T, AddressSpace::Derived);
#else
Type *NewT = PointerType::getWithSamePointeeType(cast<PointerType>(T), AddressSpace::Derived);
#endif
return ctx.builder.CreateAddrSpaceCast(V, NewT);
}

Expand Down Expand Up @@ -1010,54 +1002,6 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, jl_aliasinfo_t const
{
if (sz == 0)
return;
#if JL_LLVM_VERSION < 170000
// If the types are small and simple, use load and store directly.
// Going through memcpy can cause LLVM (e.g. SROA) to create bitcasts between float and int
// that interferes with other optimizations.
// TODO: Restore this for opaque pointers? Needs extra type information from the caller.
if (ctx.builder.getContext().supportsTypedPointers() && sz <= 64) {
// The size limit is arbitrary but since we mainly care about floating points and
// machine size vectors this should be enough.
const DataLayout &DL = jl_Module->getDataLayout();
auto srcty = cast<PointerType>(src->getType());
//TODO unsafe nonopaque pointer
auto srcel = srcty->getNonOpaquePointerElementType();
auto dstty = cast<PointerType>(dst->getType());
//TODO unsafe nonopaque pointer
auto dstel = dstty->getNonOpaquePointerElementType();
while (srcel->isArrayTy() && srcel->getArrayNumElements() == 1) {
src = ctx.builder.CreateConstInBoundsGEP2_32(srcel, src, 0, 0);
srcel = srcel->getArrayElementType();
srcty = srcel->getPointerTo();
}
while (dstel->isArrayTy() && dstel->getArrayNumElements() == 1) {
dst = ctx.builder.CreateConstInBoundsGEP2_32(dstel, dst, 0, 0);
dstel = dstel->getArrayElementType();
dstty = dstel->getPointerTo();
}

llvm::Type *directel = nullptr;
if (srcel->isSized() && srcel->isSingleValueType() && DL.getTypeStoreSize(srcel) == sz) {
directel = srcel;
dst = emit_bitcast(ctx, dst, srcty);
}
else if (dstel->isSized() && dstel->isSingleValueType() &&
DL.getTypeStoreSize(dstel) == sz) {
directel = dstel;
src = emit_bitcast(ctx, src, dstty);
}
if (directel) {
if (isa<Instruction>(src) && !src->hasName())
setName(ctx.emission_context, src, "memcpy_refined_src");
if (isa<Instruction>(dst) && !dst->hasName())
setName(ctx.emission_context, dst, "memcpy_refined_dst");
auto val = src_ai.decorateInst(ctx.builder.CreateAlignedLoad(directel, src, MaybeAlign(align_src), is_volatile));
dst_ai.decorateInst(ctx.builder.CreateAlignedStore(val, dst, align_dst, is_volatile));
++SkippedMemcpys;
return;
}
}
#endif
++EmittedMemcpys;

// the memcpy intrinsic does not allow to specify different alias tags
Expand Down Expand Up @@ -1940,7 +1884,7 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
// actual `isa` calls, this optimization should already have been performed upstream
// anyway, but having this optimization in codegen might still be beneficial for
// `typeassert`s if we can make it correct.
Optional<bool> known_isa;
std::optional<bool> known_isa;
jl_value_t *intersected_type = type;
if (x.constant)
known_isa = jl_isa(x.constant, type);
Expand Down Expand Up @@ -3786,11 +3730,7 @@ static void recursively_adjust_ptr_type(llvm::Value *Val, unsigned FromAS, unsig
for (auto *User : Val->users()) {
if (isa<GetElementPtrInst>(User)) {
GetElementPtrInst *Inst = cast<GetElementPtrInst>(User);
#if JL_LLVM_VERSION >= 170000
Inst->mutateType(PointerType::get(Inst->getType(), ToAS));
#else
Inst->mutateType(PointerType::getWithSamePointeeType(cast<PointerType>(Inst->getType()), ToAS));
#endif
recursively_adjust_ptr_type(Inst, FromAS, ToAS);
}
else if (isa<IntrinsicInst>(User)) {
Expand All @@ -3799,11 +3739,7 @@ static void recursively_adjust_ptr_type(llvm::Value *Val, unsigned FromAS, unsig
}
else if (isa<BitCastInst>(User)) {
BitCastInst *Inst = cast<BitCastInst>(User);
#if JL_LLVM_VERSION >= 170000
Inst->mutateType(PointerType::get(Inst->getType(), ToAS));
#else
Inst->mutateType(PointerType::getWithSamePointeeType(cast<PointerType>(Inst->getType()), ToAS));
#endif
recursively_adjust_ptr_type(Inst, FromAS, ToAS);
}
}
Expand Down
Loading
Loading