Skip to content

Upgrade to LLVM 14.0.2 #45195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 14, 2022
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ else
JL_PRIVATE_LIBS-$(USE_SYSTEM_ZLIB) += libz
endif
ifeq ($(USE_LLVM_SHLIB),1)
JL_PRIVATE_LIBS-$(USE_SYSTEM_LLVM) += libLLVM libLLVM-13jl
JL_PRIVATE_LIBS-$(USE_SYSTEM_LLVM) += libLLVM libLLVM-14jl
endif
JL_PRIVATE_LIBS-$(USE_SYSTEM_LIBUNWIND) += libunwind

Expand Down
2 changes: 1 addition & 1 deletion base/binaryplatforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ function detect_cxxstring_abi()
end

function open_libllvm(f::Function)
for lib_name in ("libLLVM-13jl", "libLLVM", "LLVM", "libLLVMSupport")
for lib_name in ("libLLVM-14jl", "libLLVM", "LLVM", "libLLVMSupport")
hdl = Libdl.dlopen_e(lib_name)
if hdl != C_NULL
try
Expand Down
6 changes: 5 additions & 1 deletion contrib/refresh_checksums.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ NON_CLANG_TRIPLETS=$(filter-out %-darwin %-freebsd,$(TRIPLETS))
# These are the projects currently using BinaryBuilder; both GCC-expanded and non-GCC-expanded:
BB_PROJECTS=mbedtls libssh2 nghttp2 mpfr curl libgit2 pcre libuv unwind llvmunwind dsfmt objconv p7zip zlib libsuitesparse openlibm blastrampoline
BB_GCC_EXPANDED_PROJECTS=openblas csl
BB_CXX_EXPANDED_PROJECTS=gmp llvm clang llvm-tools
BB_CXX_EXPANDED_PROJECTS=gmp llvm clang llvm-tools lld
# These are non-BB source-only deps
NON_BB_PROJECTS=patchelf mozillacert lapack libwhich utf8proc

Expand Down Expand Up @@ -80,8 +80,12 @@ $(foreach project,$(BB_CXX_EXPANDED_PROJECTS),$(foreach triplet,$(CLANG_TRIPLETS

# Special libLLVM_asserts_jll/LLVM_assert_jll targets
$(foreach triplet,$(NON_CLANG_TRIPLETS),$(foreach cxxstring_abi,cxx11 cxx03,$(eval $(call checksum_dep,llvm,$(triplet)-$(cxxstring_abi),assert))))
$(foreach triplet,$(NON_CLANG_TRIPLETS),$(foreach cxxstring_abi,cxx11 cxx03,$(eval $(call checksum_dep,clang,$(triplet)-$(cxxstring_abi),assert))))
$(foreach triplet,$(NON_CLANG_TRIPLETS),$(foreach cxxstring_abi,cxx11 cxx03,$(eval $(call checksum_dep,lld,$(triplet)-$(cxxstring_abi),assert))))
$(foreach triplet,$(NON_CLANG_TRIPLETS),$(foreach cxxstring_abi,cxx11 cxx03,$(eval $(call checksum_dep,llvm-tools,$(triplet)-$(cxxstring_abi),assert))))
$(foreach triplet,$(CLANG_TRIPLETS),$(eval $(call checksum_dep,llvm,$(triplet),assert)))
$(foreach triplet,$(CLANG_TRIPLETS),$(eval $(call checksum_dep,clang,$(triplet),assert)))
$(foreach triplet,$(CLANG_TRIPLETS),$(eval $(call checksum_dep,lld,$(triplet),assert)))
$(foreach triplet,$(CLANG_TRIPLETS),$(eval $(call checksum_dep,llvm-tools,$(triplet),assert)))

# External stdlibs
Expand Down
14 changes: 9 additions & 5 deletions deps/Versions.make
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CSL_JLL_NAME := CompilerSupportLibraries

# Clang (paired with LLVM, only here as a JLL download)
CLANG_JLL_NAME := Clang
CLANG_JLL_VER := 13.0.1+0
CLANG_JLL_VER := 14.0.2+1

# DSFMT
DSFMT_VER := 2.2.4
Expand Down Expand Up @@ -44,14 +44,18 @@ LIBUV_VER := 2
LIBUV_JLL_NAME := LibUV

# LLVM
LLVM_VER := 13.0.1
LLVM_ASSERT_JLL_VER := 13.0.1+0
LLVM_VER := 14.0.2
LLVM_ASSERT_JLL_VER := 14.0.2+1
LLVM_JLL_NAME := libLLVM

# LLVM_tools (downloads LLVM_jll to get things like `lit` and `opt`)
LLVM_TOOLS_JLL_NAME := LLVM
LLVM_TOOLS_JLL_VER := 13.0.1+0
LLVM_TOOLS_ASSERT_JLL_VER := 13.0.1+0
LLVM_TOOLS_JLL_VER := 14.0.2+1
LLVM_TOOLS_ASSERT_JLL_VER := 14.0.2+1

# LLD
LLD_JLL_NAME := LLD
LLD_JLL_VER := 14.0.2+1

# LLVM libunwind
LLVMUNWIND_VER := 12.0.1
Expand Down
174 changes: 116 additions & 58 deletions deps/checksums/clang

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions deps/checksums/lld

Large diffs are not rendered by default.

502 changes: 268 additions & 234 deletions deps/checksums/llvm

Large diffs are not rendered by default.

23 changes: 18 additions & 5 deletions deps/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ LLVM_CMAKE += -DLLVM_EXTERNAL_RV_SOURCE_DIR=$(LLVM_MONOSRC_DIR)/rv
LLVM_CMAKE += -DLLVM_CXX_STD=c++14
endif

# Otherwise LLVM will translate \\ to / on mingw
LLVM_CMAKE += -DLLVM_WINDOWS_PREFER_FORWARD_SLASH=False

# Allow adding LLVM specific flags
LLVM_CFLAGS += $(CFLAGS)
LLVM_CXXFLAGS += $(CXXFLAGS)
Expand Down Expand Up @@ -285,16 +288,26 @@ else # USE_BINARYBUILDER_LLVM

# We provide a way to subversively swap out which LLVM JLL we pull artifacts from
ifeq ($(LLVM_ASSERTIONS), 1)
LLVM_JLL_DOWNLOAD_NAME := libLLVM_assert
LLVM_JLL_VER := $(LLVM_ASSERT_JLL_VER)
LLVM_TOOLS_JLL_DOWNLOAD_NAME := LLVM_assert
LLVM_TOOLS_JLL_VER := $(LLVM_TOOLS_ASSERT_JLL_VER)
# LLVM_JLL_DOWNLOAD_NAME := libLLVM_assert
# LLVM_JLL_VER := $(LLVM_ASSERT_JLL_VER)
# LLVM_TOOLS_JLL_DOWNLOAD_NAME := LLVM_assert
# LLVM_TOOLS_JLL_VER := $(LLVM_TOOLS_ASSERT_JLL_VER)
LLVM_JLL_TAGS := -llvm_version+$(LLVM_VER_MAJ).asserts
CLANG_JLL_TAGS := -llvm_version+$(LLVM_VER_MAJ).asserts
LLD_JLL_TAGS := -llvm_version+$(LLVM_VER_MAJ).asserts
LLVM_TOOLS_JLL_TAGS := -llvm_version+$(LLVM_VER_MAJ).asserts
else
LLVM_JLL_TAGS := -llvm_version+$(LLVM_VER_MAJ)
CLANG_JLL_TAGS := -llvm_version+$(LLVM_VER_MAJ)
LLD_JLL_TAGS := -llvm_version+$(LLVM_VER_MAJ)
LLVM_TOOLS_JLL_TAGS := -llvm_version+$(LLVM_VER_MAJ)
endif

$(eval $(call bb-install,llvm,LLVM,false,true))
$(eval $(call bb-install,clang,CLANG,false,true))
$(eval $(call bb-install,lld,LLD,false,true))
$(eval $(call bb-install,llvm-tools,LLVM_TOOLS,false,true))

install-clang install-llvm-tools: install-llvm
install-lld install-clang install-llvm-tools: install-llvm

endif # USE_BINARYBUILDER_LLVM
4 changes: 2 additions & 2 deletions deps/llvm.version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
LLVM_BRANCH=julia-13.0.1-0
LLVM_SHA1=julia-13.0.1-0
LLVM_BRANCH=julia-14.0.2-1
LLVM_SHA1=julia-14.0.2-1
7 changes: 5 additions & 2 deletions deps/tools/bb-install.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ $(2)_JLL_VER ?= $$(shell [ -f $$($(2)_STDLIB_PATH)/Project.toml ] && grep "^vers
# Allow things to override which JLL we pull from, e.g. libLLVM_jll vs. libLLVM_assert_jll
$(2)_JLL_DOWNLOAD_NAME ?= $$($(2)_JLL_NAME)

# Allow things to provide platform tags
$(2)_JLL_TAGS ?=

$(2)_BB_TRIPLET := $$($$(TRIPLET_VAR))
$(2)_JLL_VER_NOPLUS := $$(firstword $$(subst +,$(SPACE),$$($(2)_JLL_VER)))
$(2)_JLL_BASENAME := $$($(2)_JLL_DOWNLOAD_NAME).v$$($(2)_JLL_VER).$$($(2)_BB_TRIPLET).tar.gz
$(2)_BB_URL := https://github.com/JuliaBinaryWrappers/$$($(2)_JLL_DOWNLOAD_NAME)_jll.jl/releases/download/$$($(2)_JLL_DOWNLOAD_NAME)-v$$($(2)_JLL_VER)/$$($(2)_JLL_DOWNLOAD_NAME).v$$($(2)_JLL_VER_NOPLUS).$$($(2)_BB_TRIPLET).tar.gz
$(2)_JLL_BASENAME := $$($(2)_JLL_DOWNLOAD_NAME).v$$($(2)_JLL_VER).$$($(2)_BB_TRIPLET)$$($(2)_JLL_TAGS).tar.gz
$(2)_BB_URL := https://github.com/JuliaBinaryWrappers/$$($(2)_JLL_DOWNLOAD_NAME)_jll.jl/releases/download/$$($(2)_JLL_DOWNLOAD_NAME)-v$$($(2)_JLL_VER)/$$($(2)_JLL_DOWNLOAD_NAME).v$$($(2)_JLL_VER_NOPLUS).$$($(2)_BB_TRIPLET)$$($(2)_JLL_TAGS).tar.gz

$$(SRCCACHE)/$$($(2)_JLL_BASENAME): | $$(SRCCACHE)
$$(JLDOWNLOAD) $$@ $$($(2)_BB_URL)
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ else
ifeq ($(OS), Darwin)
CG_LLVMLINK += $(LLVM_LDFLAGS) -lLLVM
else
CG_LLVMLINK += $(LLVM_LDFLAGS) -lLLVM-13jl
CG_LLVMLINK += $(LLVM_LDFLAGS) -lLLVM-14jl
endif
endif
endif
Expand Down
40 changes: 24 additions & 16 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,19 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
// to merge allocations and sometimes eliminate them,
// since AllocOpt does not handle PhiNodes.
// Enable this instruction hoisting because of this and Union benchmarks.
auto simplifyCFGOptions = SimplifyCFGOptions().hoistCommonInsts(true);
auto basicSimplifyCFGOptions = SimplifyCFGOptions()
.convertSwitchRangeToICmp(true)
.convertSwitchToLookupTable(true)
.forwardSwitchCondToPhi(true);
auto aggressiveSimplifyCFGOptions = SimplifyCFGOptions()
.convertSwitchRangeToICmp(true)
.convertSwitchToLookupTable(true)
.forwardSwitchCondToPhi(true)
//These mess with loop rotation, so only do them after that
.hoistCommonInsts(true)
// Causes an SRET assertion error in late-gc-lowering
// .sinkCommonInsts(true)
;
#ifdef JL_DEBUG_BUILD
PM->add(createGCInvariantVerifierPass(true));
PM->add(createVerifierPass());
Expand All @@ -646,7 +658,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
if (opt_level == 1)
PM->add(createInstSimplifyLegacyPass());
}
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
if (opt_level == 1) {
PM->add(createSROAPass());
PM->add(createInstructionCombiningPass());
Expand Down Expand Up @@ -676,7 +688,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
// minimal clean-up to get rid of CPU feature checks
if (opt_level == 1) {
PM->add(createInstSimplifyLegacyPass());
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
}
}
#if defined(_COMPILER_ASAN_ENABLED_)
Expand All @@ -697,7 +709,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
PM->add(createBasicAAWrapperPass());
}

PM->add(createCFGSimplificationPass(simplifyCFGOptions));
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
PM->add(createDeadCodeEliminationPass());
PM->add(createSROAPass());

Expand All @@ -711,7 +723,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
PM->add(createAllocOptPass());
// consider AggressiveInstCombinePass at optlevel > 2
PM->add(createInstructionCombiningPass());
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
if (dump_native)
PM->add(createMultiVersioningPass(external_use));
PM->add(createCPUFeaturesPass());
Expand Down Expand Up @@ -781,27 +793,23 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
PM->add(createGVNPass()); // Must come after JumpThreading and before LoopVectorize
}
PM->add(createDeadStoreEliminationPass());
// see if all of the constant folding has exposed more loops
// to simplification and deletion
// this helps significantly with cleaning up iteration
PM->add(createCFGSimplificationPass(aggressiveSimplifyCFGOptions));

// More dead allocation (store) deletion before loop optimization
// consider removing this:
// Moving this after aggressive CFG simplification helps deallocate when allocations are hoisted
PM->add(createAllocOptPass());
// see if all of the constant folding has exposed more loops
// to simplification and deletion
// this helps significantly with cleaning up iteration
PM->add(createCFGSimplificationPass()); // See note above, don't hoist instructions before LV
PM->add(createLoopDeletionPass());
PM->add(createInstructionCombiningPass());
PM->add(createLoopVectorizePass());
PM->add(createLoopLoadEliminationPass());
// Cleanup after LV pass
PM->add(createInstructionCombiningPass());
PM->add(createCFGSimplificationPass( // Aggressive CFG simplification
SimplifyCFGOptions()
.forwardSwitchCondToPhi(true)
.convertSwitchToLookupTable(true)
.needCanonicalLoops(false)
.hoistCommonInsts(true)
// .sinkCommonInsts(true) // FIXME: Causes assertion in llvm-late-lowering
aggressiveSimplifyCFGOptions
));
PM->add(createSLPVectorizerPass());
// might need this after LLVM 11:
Expand All @@ -812,7 +820,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
if (lower_intrinsics) {
// LowerPTLS removes an indirect call. As a result, it is likely to trigger
// LLVM's devirtualization heuristics, which would result in the entire
// pass pipeline being re-exectuted. Prevent this by inserting a barrier.
// pass pipeline being re-executed. Prevent this by inserting a barrier.
PM->add(createBarrierNoopPass());
PM->add(createLowerExcHandlersPass());
PM->add(createGCInvariantVerifierPass(false));
Expand Down
4 changes: 3 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2090,12 +2090,14 @@ static void jl_init_function(Function *F)
// i686 Windows (which uses a 4-byte-aligned stack)
#if JL_LLVM_VERSION >= 140000
AttrBuilder attr(F->getContext());
attr.addStackAlignmentAttr(16);
F->addFnAttrs(attr);
#else
AttrBuilder attr;
#endif
attr.addStackAlignmentAttr(16);
F->addAttributes(AttributeList::FunctionIndex, attr);
#endif
#endif
#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
F->setHasUWTable(); // force NeedsWinEH
#endif
Expand Down
1 change: 1 addition & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3754,6 +3754,7 @@ static void *gc_perm_alloc_large(size_t sz, int zero, unsigned align, unsigned o
#endif
errno = last_errno;
jl_may_leak(base);
assert(align > 0);
unsigned diff = (offset - base) % align;
return (void*)(base + diff);
}
Expand Down
5 changes: 5 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,13 @@ void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
struct rlimit rl;
getrlimit(RLIMIT_STACK, &rl);
size_t stacksize = rl.rlim_cur;
// We intentionally leak a stack address here core.StackAddressEscape
#ifndef __clang_analyzer__
*stack_hi = (void*)&stacksize;
*stack_lo = (void*)((char*)*stack_hi - stacksize);
#endif
*stack_hi = 0;
*stack_lo = 0;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ static jl_cgval_t generic_cast(
// rounding first instead of carrying around incorrect low bits.
Value *jlfloattemp_var = emit_static_alloca(ctx, from->getType());
ctx.builder.CreateStore(from, jlfloattemp_var);
from = ctx.builder.CreateLoad(jlfloattemp_var, /*force this to load from the stack*/true);
from = ctx.builder.CreateLoad(from->getType(), jlfloattemp_var, /*force this to load from the stack*/true);
#endif
}
Value *ans = ctx.builder.CreateCast(Op, from, to);
Expand Down
26 changes: 15 additions & 11 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1459,17 +1459,21 @@ TargetIRAnalysis JuliaOJIT::getTargetIRAnalysis() const {
static void jl_decorate_module(Module &M) {
#if defined(_CPU_X86_64_) && defined(_OS_WINDOWS_)
// Add special values used by debuginfo to build the UnwindData table registration for Win64
ArrayType *atype = ArrayType::get(Type::getInt32Ty(M.getContext()), 3); // want 4-byte alignment of 12-bytes of data
GlobalVariable *gvs[2] = {
new GlobalVariable(M, atype,
false, GlobalVariable::InternalLinkage,
ConstantAggregateZero::get(atype), "__UnwindData"),
new GlobalVariable(M, atype,
false, GlobalVariable::InternalLinkage,
ConstantAggregateZero::get(atype), "__catchjmp") };
gvs[0]->setSection(".text");
gvs[1]->setSection(".text");
appendToCompilerUsed(M, makeArrayRef((GlobalValue**)gvs, 2));
// This used to be GV, but with https://reviews.llvm.org/D100944 we no longer can emit GV into `.text`
// TODO: The data is set in debuginfo.cpp but it should be okay to actually emit it here.
M.appendModuleInlineAsm("\
.section .text \n\
.type __UnwindData,@object \n\
.p2align 2, 0x90 \n\
__UnwindData: \n\
.zero 12 \n\
.size __UnwindData, 12 \n\
\n\
.type __catchjmp,@object \n\
.p2align 2, 0x90 \n\
__catchjmp: \n\
.zero 12 \n\
.size __catchjmp, 12");
#endif
}

Expand Down
5 changes: 3 additions & 2 deletions src/llvm-muladd.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// This file is a part of Julia. License is MIT: https://julialang.org/license

#undef DEBUG
#include "llvm-version.h"
#include "passes.h"

Expand All @@ -20,11 +19,13 @@
#include <llvm/IR/Verifier.h>
#include <llvm/Pass.h>
#include <llvm/Support/Debug.h>
#define DEBUG_TYPE "combine_muladd"

#include "julia.h"
#include "julia_assert.h"

#define DEBUG_TYPE "combine_muladd"
#undef DEBUG

using namespace llvm;
STATISTIC(TotalContracted, "Total number of multiplies marked for FMA");

Expand Down
6 changes: 3 additions & 3 deletions src/llvm-multiversioning.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// This file is a part of Julia. License is MIT: https://julialang.org/license

// Function multi-versioning
#define DEBUG_TYPE "julia_multiversioning"
#undef DEBUG

// LLVM pass to clone function for different archs

#include "llvm-version.h"
Expand Down Expand Up @@ -41,6 +38,9 @@
#include "codegen_shared.h"
#include "julia_assert.h"

#define DEBUG_TYPE "julia_multiversioning"
#undef DEBUG

using namespace llvm;

extern Optional<bool> always_have_fma(Function&);
Expand Down
7 changes: 3 additions & 4 deletions src/llvm-ptls.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// This file is a part of Julia. License is MIT: https://julialang.org/license

#define DEBUG_TYPE "lower_ptls"
#undef DEBUG

// LLVM pass to lower TLS access and remove references to julia intrinsics

#include "llvm-version.h"
Expand All @@ -29,6 +25,9 @@
#include "codegen_shared.h"
#include "julia_assert.h"

#define DEBUG_TYPE "lower_ptls"
#undef DEBUG

using namespace llvm;

typedef Instruction TerminatorInst;
Expand Down
Loading