Skip to content

Commit

Permalink
Bump LLVM to v17 (#53070)
Browse files Browse the repository at this point in the history
Co-authored-by: Mosè Giordano <[email protected]>
Co-authored-by: Gabriel Baraldi <[email protected]>
Co-authored-by: Zentrik <[email protected]>
  • Loading branch information
4 people authored May 1, 2024
1 parent e25ce08 commit 1959349
Show file tree
Hide file tree
Showing 76 changed files with 951 additions and 981 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ endif
ifeq ($(OS), Linux)
-$(PATCHELF) $(PATCHELF_SET_RPATH_ARG) '$$ORIGIN' $(DESTDIR)$(private_shlibdir)/libLLVM.$(SHLIB_EXT)
endif

ifneq ($(LOADER_BUILD_DEP_LIBS),$(LOADER_INSTALL_DEP_LIBS))
# Next, overwrite relative path to libjulia-internal in our loader if $$(LOADER_BUILD_DEP_LIBS) != $$(LOADER_INSTALL_DEP_LIBS)
ifeq ($(JULIA_BUILD_MODE),release)
Expand Down
216 changes: 108 additions & 108 deletions deps/checksums/clang

Large diffs are not rendered by default.

216 changes: 108 additions & 108 deletions deps/checksums/lld

Large diffs are not rendered by default.

436 changes: 218 additions & 218 deletions deps/checksums/llvm

Large diffs are not rendered by default.

Empty file added deps/checksums/llvmunwind
Empty file.
4 changes: 3 additions & 1 deletion deps/clang.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- makefile -*-

## jll artifact
# Clang (paired with LLVM, only here as a JLL download)
CLANG_JLL_NAME := Clang
CLANG_JLL_VER := 16.0.6+4
CLANG_JLL_VER := 17.0.6+3
4 changes: 3 additions & 1 deletion deps/lld.version
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- makefile -*-

## jll artifact
LLD_JLL_NAME := LLD
LLD_JLL_VER := 16.0.6+4
LLD_JLL_VER := 17.0.6+3
6 changes: 4 additions & 2 deletions deps/llvm-tools.version
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- makefile -*-

## jll artifact
# LLVM_tools (downloads LLVM_jll to get things like `lit` and `opt`)
LLVM_TOOLS_JLL_NAME := LLVM
LLVM_TOOLS_JLL_VER := 16.0.6+4
LLVM_TOOLS_ASSERT_JLL_VER := 16.0.6+4
LLVM_TOOLS_JLL_VER := 17.0.6+3
LLVM_TOOLS_ASSERT_JLL_VER := 17.0.6+3
12 changes: 6 additions & 6 deletions deps/llvm.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

## jll artifact
LLVM_JLL_NAME := libLLVM
LLVM_ASSERT_JLL_VER := 16.0.6+4
LLVM_ASSERT_JLL_VER := 17.0.6+3
## source build
# Version number of LLVM
LLVM_VER := 16.0.6
LLVM_VER := 17.0.6
# Git branch name in `LLVM_GIT_URL` repository
LLVM_BRANCH=julia-16.0.6-2
LLVM_BRANCH=julia-17.0.6-3
# Git ref in `LLVM_GIT_URL` repository
LLVM_SHA1=julia-16.0.6-2
LLVM_SHA1=julia-17.0.6-3

## Following options are used to automatically fetch patchset from Julia's fork. This is
## useful if you want to build an external LLVM while still applying Julia's patches.
Expand All @@ -18,6 +18,6 @@ LLVM_APPLY_JULIA_PATCHES := 0
# GitHub repository to use for fetching the Julia patches to apply to LLVM source code.
LLVM_JULIA_DIFF_GITHUB_REPO := https://github.com/llvm/llvm-project
# Base GitHub ref for generating the diff.
LLVM_BASE_REF := llvm:llvmorg-16.0.6
LLVM_BASE_REF := llvm:llvmorg-17.0.6
# Julia fork's GitHub ref for generating the diff.
LLVM_JULIA_REF := JuliaLang:julia-16.0.6-0
LLVM_JULIA_REF := JuliaLang:julia-17.0.6-3
2 changes: 1 addition & 1 deletion deps/sanitizers.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ install-sanitizers: $$(addprefix $$(build_libdir)/, $$(notdir $$(call pathsearch
$$(addprefix $$(build_shlibdir)/,$(2)): $$(addprefix $$(SANITIZER_LIB_PATH)/,$(2)) | $$(build_shlibdir)
-cp $$< $$@
$(if $(filter $(OS), Linux), \
-$(PATCHELF) $(PATCHELF_SET_RPATH_ARG) '$$$$ORIGIN' $$@ , 0)
-$(PATCHELF) $(PATCHELF_SET_RPATH_ARG) '$$$$ORIGIN' $$@ , 0)
endef

ifeq ($(USECLANG),1)
Expand Down
54 changes: 54 additions & 0 deletions src/APInt-C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,27 @@ 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);
}

extern "C" JL_DLLEXPORT
unsigned countr_zero_16(uint16_t Val) {
return countr_zero(Val);
}

extern "C" JL_DLLEXPORT
unsigned countr_zero_32(uint32_t Val) {
return countr_zero(Val);
}

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);
Expand All @@ -494,6 +515,7 @@ 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 @@ -523,6 +545,37 @@ 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)
return a.popcount();
}

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

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

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

extern "C" JL_DLLEXPORT
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)
Expand Down Expand Up @@ -552,3 +605,4 @@ unsigned LLVMCountLeadingZeros(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countLeadingZeros();
}
#endif
18 changes: 17 additions & 1 deletion src/APInt-C.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

#include "julia.h"
#include "dtypes.h"
#include "llvm-version.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef LLVM_VERSION_MAJOR
#if defined(__cplusplus) && defined(LLVM_VERSION_MAJOR)
using integerPart = llvm::APInt::WordType;
#else
typedef void integerPart;
Expand Down Expand Up @@ -53,11 +54,19 @@ 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 @@ -73,10 +82,17 @@ 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
7 changes: 4 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ else
# JULIACODEGEN != LLVM
endif

RT_LLVM_LIBS := support # for APMath and some other useful ADT
ifneq ($(LLVM_VER_MAJ),15)
RT_LLVM_LIBS += targetparser # for getHostCPUName on LLVM 16+
RT_LLVM_LIBS := support

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

ifeq ($(OS),WINNT)
Expand Down
21 changes: 20 additions & 1 deletion src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
#include "platform.h"

// target support
#include "llvm/Support/CodeGen.h"
#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>
#include <llvm/Analysis/TargetTransformInfo.h>
Expand Down Expand Up @@ -696,7 +700,11 @@ 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 @@ -1439,7 +1447,9 @@ static SmallVector<AOTOutputs, 16> add_output(Module &M, TargetMachine &TM, Stri
for (unsigned i = 0; i < threads; i++) {
std::function<void()> func = [&, i]() {
LLVMContext ctx;
#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 @@ -1643,7 +1653,9 @@ void jl_dump_native_impl(void *native_code,
if (z) {
JL_TIMING(NATIVE_AOT, NATIVE_Sysimg);
LLVMContext Context;
#if JL_LLVM_VERSION < 170000
SetOpaquePointer(Context);
#endif
Module sysimgM("sysimg", Context);
sysimgM.setTargetTriple(TheTriple.str());
sysimgM.setDataLayout(DL);
Expand Down Expand Up @@ -1690,6 +1702,7 @@ void jl_dump_native_impl(void *native_code,
JL_TIMING(NATIVE_AOT, NATIVE_Setup);
dataM.setTargetTriple(TheTriple.str());
dataM.setDataLayout(DL);
dataM.setPICLevel(PICLevel::BigPIC);
auto &Context = dataM.getContext();

Type *T_psize = dataM.getDataLayout().getIntPtrType(Context)->getPointerTo();
Expand Down Expand Up @@ -1786,7 +1799,9 @@ void jl_dump_native_impl(void *native_code,
{
JL_TIMING(NATIVE_AOT, NATIVE_Metadata);
LLVMContext Context;
#if JL_LLVM_VERSION < 170000
SetOpaquePointer(Context);
#endif
Module metadataM("metadata", Context);
metadataM.setTargetTriple(TheTriple.str());
metadataM.setDataLayout(DL);
Expand Down Expand Up @@ -2036,12 +2051,16 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, siz
global.second->setLinkage(GlobalValue::ExternalLinkage);
} 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
2 changes: 2 additions & 0 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ 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
Loading

0 comments on commit 1959349

Please sign in to comment.