Skip to content

Commit

Permalink
Initial support for LLVM 7.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vettoreldaniele committed Mar 27, 2019
1 parent 7b45b7b commit 4e8bae3
Show file tree
Hide file tree
Showing 14 changed files with 264 additions and 82 deletions.
1 change: 1 addition & 0 deletions deps/checksums/llvm-7.0.1.src.tar.xz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
79f1256f97d52a054da8660706deb5f6
1 change: 1 addition & 0 deletions deps/checksums/llvm-7.0.1.src.tar.xz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ac43a3cb71a53deb55e3693653847cf20bf6f5d9056f224e6956c96d63bc59ebee9404f088eec9cabe65337b4607a905ef931354b373cf64e0004c6905a6b5df
9 changes: 6 additions & 3 deletions deps/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,12 @@ $(eval $(call LLVM_PATCH,llvm-D57118-powerpc))
$(eval $(call LLVM_PATCH,llvm-r355582-avxminmax)) # remove for 8.0
endif # LLVM_VER

# Independent to the llvm version add a JL prefix to the version map
$(eval $(call LLVM_PATCH,llvm-symver-jlprefix)) # DO NOT REMOVE

# Add a JL prefix to the version map. DO NOT REMOVE
ifeq ($(LLVM_VER_SHORT), 6.0)
$(eval $(call LLVM_PATCH,llvm6-symver-jlprefix))
else
$(eval $(call LLVM_PATCH,llvm7-symver-jlprefix))
endif

# declare that all patches must be applied before running ./configure
$(LLVM_BUILDDIR_withtype)/build-configured: | $(LLVM_PATCH_PREV)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ index e9515fe7862..af082581627 100644
@@ -1 +1 @@
-LLVM_@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@ { global: *; };
+JL_LLVM_@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@ { global: *; };
--
--
2.15.1

18 changes: 18 additions & 0 deletions deps/patches/llvm7-symver-jlprefix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
From f23277bb91a4925ba8763337137a3123a7600557 Mon Sep 17 00:00:00 2001
From: Valentin Churavy <[email protected]>
Date: Tue, 16 Jan 2018 17:29:05 -0500
Subject: [PATCH] add JL prefix to all LLVM version suffixes

---
tools/llvm-shlib/simple_version_script.map.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/llvm-shlib/simple_version_script.map.in b/tools/llvm-shlib/simple_version_script.map.in
index e9515fe7862..af082581627 100644
--- a/tools/llvm-shlib/simple_version_script.map.in
+++ b/tools/llvm-shlib/simple_version_script.map.in
@@ -1 +1 @@
-LLVM_@LLVM_VERSION_MAJOR@ { global: *; };
+JL_LLVM_@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@ { global: *; };
--
2.15.1
19 changes: 19 additions & 0 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,14 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
std::string ir_string = ir_stream.str();
// Do not enable update debug info since it runs the verifier on the whole module
// and will error on the function we are currently emitting.
#if JL_LLVM_VERSION >= 70000
ModuleSummaryIndex index = ModuleSummaryIndex(true);
bool failed = parseAssemblyInto(llvm::MemoryBufferRef(ir_string, "llvmcall"),
jl_Module, &index, Err, nullptr, /* UpdateDebugInfo */ false);
#else
bool failed = parseAssemblyInto(llvm::MemoryBufferRef(ir_string, "llvmcall"),
*jl_Module, Err, nullptr, /* UpdateDebugInfo */ false);
#endif
if (failed) {
std::string message = "Failed to parse LLVM Assembly: \n";
llvm::raw_string_ostream stream(message);
Expand Down Expand Up @@ -1781,13 +1787,26 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
const jl_cgval_t &dst = argv[0];
const jl_cgval_t &src = argv[1];
const jl_cgval_t &n = argv[2];

#if JL_LLVM_VERSION >= 70000
ctx.builder.CreateMemCpy(
ctx.builder.CreateIntToPtr(
emit_unbox(ctx, T_size, dst, (jl_value_t*)jl_voidpointer_type), T_pint8),
1,
ctx.builder.CreateIntToPtr(
emit_unbox(ctx, T_size, src, (jl_value_t*)jl_voidpointer_type), T_pint8),
0,
emit_unbox(ctx, T_size, n, (jl_value_t*)jl_ulong_type),
false);
#else
ctx.builder.CreateMemCpy(
ctx.builder.CreateIntToPtr(
emit_unbox(ctx, T_size, dst, (jl_value_t*)jl_voidpointer_type), T_pint8),
ctx.builder.CreateIntToPtr(
emit_unbox(ctx, T_size, src, (jl_value_t*)jl_voidpointer_type), T_pint8),
emit_unbox(ctx, T_size, n, (jl_value_t*)jl_ulong_type), 1,
false);
#endif
JL_GC_POP();
return ghostValue(jl_void_type);
}
Expand Down
8 changes: 8 additions & 0 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,11 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, MDNode *tbaa_dst, Va
// for the load part (x.tbaa) and the store part (tbaa_stack).
// since the tbaa lattice has to be a tree we have unfortunately
// x.tbaa ∪ tbaa_stack = tbaa_root if x.tbaa != tbaa_stack
#if JL_LLVM_VERSION >= 70000
ctx.builder.CreateMemCpy(dst, align, src, 0, sz, is_volatile, MDNode::getMostGenericTBAA(tbaa_dst, tbaa_src));
#else
ctx.builder.CreateMemCpy(dst, src, sz, align, is_volatile, MDNode::getMostGenericTBAA(tbaa_dst, tbaa_src));
#endif
}

static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, MDNode *tbaa_dst, Value *src, MDNode *tbaa_src,
Expand All @@ -1433,7 +1437,11 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, MDNode *tbaa_dst, Va
emit_memcpy_llvm(ctx, dst, tbaa_dst, src, tbaa_src, const_sz->getZExtValue(), align, is_volatile);
return;
}
#if JL_LLVM_VERSION >= 70000
ctx.builder.CreateMemCpy(dst, align, src, 0, sz, is_volatile, MDNode::getMostGenericTBAA(tbaa_dst, tbaa_src));
#else
ctx.builder.CreateMemCpy(dst, src, sz, align, is_volatile, MDNode::getMostGenericTBAA(tbaa_dst, tbaa_src));
#endif
}

template<typename T1>
Expand Down
29 changes: 28 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3594,7 +3594,11 @@ static void emit_phinode_assign(jl_codectx_t &ctx, ssize_t idx, jl_value_t *r)
Value *isboxed = ctx.builder.CreateICmpNE(
ctx.builder.CreateAnd(Tindex_phi, ConstantInt::get(T_int8, 0x80)),
ConstantInt::get(T_int8, 0));
#if JL_LLVM_VERSION >= 70000
ctx.builder.CreateMemCpy(phi, min_align, dest, 0, nbytes, false);
#else
ctx.builder.CreateMemCpy(phi, dest, nbytes, min_align, false);
#endif
ctx.builder.CreateLifetimeEnd(dest);
ptr = ctx.builder.CreateSelect(isboxed,
maybe_bitcast(ctx, decay_derived(ptr_phi), T_pint8),
Expand Down Expand Up @@ -3634,8 +3638,14 @@ static void emit_phinode_assign(jl_codectx_t &ctx, ssize_t idx, jl_value_t *r)
if (vtype->isAggregateType()) {
dest = emit_static_alloca(ctx, vtype);
Value *phi = emit_static_alloca(ctx, vtype);
#if JL_LLVM_VERSION >= 70000
ctx.builder.CreateMemCpy(phi, jl_datatype_align(phiType),
dest, 0,
jl_datatype_size(phiType), false);
#else
ctx.builder.CreateMemCpy(phi, dest, jl_datatype_size(phiType),
jl_datatype_align(phiType), false);
jl_datatype_align(phiType), false);
#endif
ctx.builder.CreateLifetimeEnd(dest);
slot = mark_julia_slot(phi, phiType, NULL, tbaa_stack);
}
Expand Down Expand Up @@ -6503,11 +6513,20 @@ static std::unique_ptr<Module> emit_function(
VN->addIncoming(V, ctx.builder.GetInsertBlock());
assert(!TindexN);
} else if (dest && val.typ != (jl_value_t*)jl_bottom_type) {
#if JL_LLVM_VERSION >= 70000
ctx.builder.CreateMemCpy(maybe_decay_tracked(dest),
jl_datatype_align(phiType),
maybe_decay_tracked(data_pointer(ctx, val)),
0,
jl_datatype_size(phiType),
false);
#else
ctx.builder.CreateMemCpy(maybe_decay_tracked(dest),
maybe_decay_tracked(data_pointer(ctx, val)),
jl_datatype_size(phiType),
jl_datatype_align(phiType),
false);
#endif
}
}
else {
Expand Down Expand Up @@ -7652,11 +7671,19 @@ extern "C" void jl_dump_llvm_debugloc(void *v)
extern void jl_write_bitcode_func(void *F, char *fname) {
std::error_code EC;
raw_fd_ostream OS(fname, EC, sys::fs::F_None);
#if JL_LLVM_VERSION >= 70000
llvm::WriteBitcodeToFile(*((llvm::Function*)F)->getParent(), OS);
#else
llvm::WriteBitcodeToFile(((llvm::Function*)F)->getParent(), OS);
#endif
}

extern void jl_write_bitcode_module(void *M, char *fname) {
std::error_code EC;
raw_fd_ostream OS(fname, EC, sys::fs::F_None);
#if JL_LLVM_VERSION >= 70000
llvm::WriteBitcodeToFile(*(llvm::Module*)M, OS);
#else
llvm::WriteBitcodeToFile((llvm::Module*)M, OS);
#endif
}
20 changes: 18 additions & 2 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,22 +791,38 @@ static void jl_dump_asm_internal(
MCInstPrinter *IP =
TheTarget->createMCInstPrinter(TheTriple, OutputAsmVariant, *MAI, *MCII, *MRI);
//IP->setPrintImmHex(true); // prefer hex or decimal immediates
MCCodeEmitter *CE = 0;
MCAsmBackend *MAB = 0;
#if JL_LLVM_VERSION >= 70000
std::unique_ptr<MCCodeEmitter> CE = 0;
std::unique_ptr<MCAsmBackend> MAB = 0;
if (ShowEncoding) {
CE = std::unique_ptr<MCCodeEmitter>(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx));
MCTargetOptions Options;
MAB = std::unique_ptr<MCAsmBackend>(TheTarget->createMCAsmBackend(*STI, *MRI, Options));
}
#else
MCCodeEmitter* CE = 0;
MCAsmBackend* MAB = 0;
if (ShowEncoding) {
CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx);
MCTargetOptions Options;
MAB = TheTarget->createMCAsmBackend(*STI, *MRI, Options);
}
#endif

// createAsmStreamer expects a unique_ptr to a formatted stream, which means
// it will destruct the stream when it is done. We cannot have this, so we
// start out with a raw stream, and create formatted stream from it here.
// LLVM will desctruct the formatted stream, and we keep the raw stream.
auto ustream = llvm::make_unique<formatted_raw_ostream>(rstream);
#if JL_LLVM_VERSION >= 70000
Streamer.reset(TheTarget->createAsmStreamer(Ctx, std::move(ustream), /*asmverbose*/true,
/*useDwarfDirectory*/ true,
IP, std::move(CE), std::move(MAB), /*ShowInst*/ false));
#else
Streamer.reset(TheTarget->createAsmStreamer(Ctx, std::move(ustream), /*asmverbose*/true,
/*useDwarfDirectory*/ true,
IP, CE, MAB, /*ShowInst*/ false));
#endif
Streamer->InitSections(true);

// Make the MemoryObject wrapper
Expand Down
Loading

2 comments on commit 4e8bae3

@barracuda156
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vettoreldaniele Could you please say which was the last version of Julia to support LLVM 7.x?

@vchuravy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we ever released a version of Julia with LLVM 7.

1.4 used LLVM 8 and 1.3 used LLVM 6. So I think we ended up skipping LLVM 7.

Please ask questions like these on discourse/slack and not as a comment on Github.

Please sign in to comment.