Skip to content

Commit

Permalink
remove support for LLVM prior to v8
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Jan 23, 2020
1 parent c2abaee commit 5393e4c
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 228 deletions.
14 changes: 0 additions & 14 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,14 +952,9 @@ 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 @@ -1660,7 +1655,6 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
const jl_cgval_t &n = argv[2];
Value *destp = emit_unbox(ctx, T_size, dst, (jl_value_t*)jl_voidpointer_type);

#if JL_LLVM_VERSION >= 70000
ctx.builder.CreateMemCpy(
ctx.builder.CreateIntToPtr(destp, T_pint8),
1,
Expand All @@ -1669,14 +1663,6 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
0,
emit_unbox(ctx, T_size, n, (jl_value_t*)jl_ulong_type),
false);
#else
ctx.builder.CreateMemCpy(
ctx.builder.CreateIntToPtr(destp, 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 rt == (jl_value_t*)jl_void_type ? ghostValue(jl_void_type) :
mark_or_box_ccall_result(ctx, destp, retboxed, rt, unionall, static_rt);
Expand Down
8 changes: 0 additions & 8 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1468,11 +1468,7 @@ 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 @@ -1482,11 +1478,7 @@ 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
44 changes: 0 additions & 44 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@

using namespace llvm;

#if JL_LLVM_VERSION >= 80000
typedef Instruction TerminatorInst;
#endif

#if defined(_OS_WINDOWS_) && !defined(NOMINMAX)
#define NOMINMAX
Expand Down Expand Up @@ -3778,11 +3776,7 @@ 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);
Value *ptr = ctx.builder.CreateSelect(isboxed,
maybe_bitcast(ctx, decay_derived(ptr_phi), T_pint8),
Expand Down Expand Up @@ -3822,14 +3816,9 @@ static void emit_phinode_assign(jl_codectx_t &ctx, ssize_t idx, jl_value_t *r)
// here it's moved into phi in the successor (from dest)
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);
#endif
ctx.builder.CreateLifetimeEnd(dest);
slot = mark_julia_slot(phi, phiType, NULL, tbaa_stack);
}
Expand Down Expand Up @@ -5800,8 +5789,6 @@ static std::unique_ptr<Module> emit_function(
DebugLoc noDbg, topdebugloc;
if (ctx.debug_enabled) {
DICompileUnit::DebugEmissionKind emissionKind = (DICompileUnit::DebugEmissionKind) ctx.params->debug_info_kind;

#if JL_LLVM_VERSION >= 80000
DICompileUnit::DebugNameTableKind tableKind;

if (JL_FEAT_TEST(ctx, gnu_pubnames)) {
Expand All @@ -5810,7 +5797,6 @@ static std::unique_ptr<Module> emit_function(
else {
tableKind = DICompileUnit::DebugNameTableKind::None;
}
#endif
topfile = dbuilder.createFile(ctx.file, ".");
DICompileUnit *CU =
dbuilder.createCompileUnit(llvm::dwarf::DW_LANG_Julia
Expand All @@ -5824,9 +5810,7 @@ static std::unique_ptr<Module> emit_function(
,0 // DWOId
,true // SplitDebugInlining
,false // DebugInfoForProfiling
#if JL_LLVM_VERSION >= 80000
,tableKind // NameTableKind
#endif
);

DISubroutineType *subrty;
Expand All @@ -5845,21 +5829,12 @@ static std::unique_ptr<Module> emit_function(
,topfile // File
,toplineno // LineNo
,subrty // Ty
#if JL_LLVM_VERSION < 80000
,false // isLocalToUnit
,true // isDefinition
#endif
,toplineno // ScopeLine
,DIFlagZero // Flags
#if JL_LLVM_VERSION < 80000
,true // isOptimized
,nullptr // Template Parameters
#else
,DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized // SPFlags
,nullptr // Template Parameters
,nullptr // Template Declaration
,nullptr // ThrownTypes
#endif
);
topdebugloc = DebugLoc::get(toplineno, 0, SP, NULL);
f->setSubprogram(SP);
Expand Down Expand Up @@ -6281,21 +6256,12 @@ static std::unique_ptr<Module> emit_function(
,difile // File
,0 // LineNo
,jl_di_func_null_sig // Ty
#if JL_LLVM_VERSION < 80000
,false // isLocalToUnit
,true // isDefinition
#endif
,0 // ScopeLine
,DIFlagZero // Flags
#if JL_LLVM_VERSION < 80000
,true // isOptimized
,nullptr // Template Parameters
#else
,DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized // SPFlags
,nullptr // Template Parameters
,nullptr // Template Declaration
,nullptr // ThrownTypes
#endif
);
}
DebugLoc inl_loc = (info.inlined_at == 0) ? DebugLoc::get(0, 0, SP, NULL) : linetable.at(info.inlined_at).loc;
Expand Down Expand Up @@ -7778,11 +7744,9 @@ extern "C" void *jl_init_llvm(void)
const char *const argv_copyprop[] = {"", "-disable-copyprop"}; // llvm bug 21743
cl::ParseCommandLineOptions(sizeof(argv_copyprop)/sizeof(argv_copyprop[0]), argv_copyprop, "disable-copyprop\n");
#endif
#if JL_LLVM_VERSION >= 70000
#if defined(_CPU_X86_) || defined(_CPU_X86_64_)
const char *const argv_avoidsfb[] = {"", "-x86-disable-avoid-SFB"}; // llvm bug 41629, see https://gist.github.com/vtjnash/192cab72a6cfc00256ff118238163b55
cl::ParseCommandLineOptions(sizeof(argv_avoidsfb)/sizeof(argv_avoidsfb[0]), argv_avoidsfb, "disable-avoidsfb\n");
#endif
#endif
cl::ParseEnvironmentOptions("Julia", "JULIA_LLVM_ARGS");

Expand Down Expand Up @@ -7957,19 +7921,11 @@ 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
}
15 changes: 0 additions & 15 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,36 +780,21 @@ static void jl_dump_asm_internal(
MCInstPrinter *IP =
TheTarget->createMCInstPrinter(TheTriple, OutputAsmVariant, *MAI, *MCII, *MRI);
//IP->setPrintImmHex(true); // prefer hex or decimal immediates
#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));
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);
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 destroy the formatted stream, and we keep the raw stream.
std::unique_ptr<formatted_raw_ostream> ustream(new 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
59 changes: 0 additions & 59 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@
#include <llvm/Transforms/Vectorize.h>
#include <llvm/Transforms/Scalar/GVN.h>
#include <llvm/Transforms/IPO/AlwaysInliner.h>

#if JL_LLVM_VERSION >= 70000
#include <llvm/Transforms/InstCombine/InstCombine.h>
#include <llvm/Support/SmallVectorMemoryBuffer.h>
#endif

#if JL_LLVM_VERSION >= 100000
#include <llvm/Support/CodeGen.h>
Expand Down Expand Up @@ -221,11 +218,6 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,

// Run instcombine after redundancy elimination to exploit opportunities
// opened up by them.
#if JL_LLVM_VERSION < 70000
// This pass is a subset of InstructionCombiningPass in LLVM 7
// and therefore not required.
PM->add(createInstructionSimplifierPass());///////// ****
#endif
PM->add(createInstructionCombiningPass());
PM->add(createJumpThreadingPass()); // Thread jumps
PM->add(createDeadStoreEliminationPass()); // Delete dead stores
Expand Down Expand Up @@ -306,11 +298,7 @@ template <typename ObjT, typename LoadResult>
void JuliaOJIT::DebugObjectRegistrar::registerObject(RTDyldObjHandleT H, const ObjT &Obj,
const LoadResult &LO)
{
#if JL_LLVM_VERSION >= 70000
const ObjT* Object = &Obj;
#else
const ObjT& Object = Obj;
#endif

JIT.NotifyFinalizer(H, *Object, *LO);
ORCNotifyObjectEmitted(JuliaListener.get(), *Object,
Expand Down Expand Up @@ -340,27 +328,17 @@ template <typename ObjSetT, typename LoadResult>
void JuliaOJIT::DebugObjectRegistrar::operator()(RTDyldObjHandleT H,
const ObjSetT &Object, const LoadResult &LOS)
{
#if JL_LLVM_VERSION >= 70000
registerObject(H, Object,
static_cast<const RuntimeDyld::LoadedObjectInfo*>(&LOS));
#else
registerObject(H, Object->getBinary(),
static_cast<const RuntimeDyld::LoadedObjectInfo*>(&LOS));
#endif
}


CompilerResultT JuliaOJIT::CompilerT::operator()(Module &M)
{
JL_TIMING(LLVM_OPT);
jit.PM.run(M);
#if JL_LLVM_VERSION >= 70000
std::unique_ptr<MemoryBuffer> ObjBuffer(
new SmallVectorMemoryBuffer(std::move(jit.ObjBufferSV)));
#else
std::unique_ptr<MemoryBuffer> ObjBuffer(
new ObjectMemoryBuffer(std::move(jit.ObjBufferSV)));
#endif
auto Obj = object::ObjectFile::createObjectFile(ObjBuffer->getMemBufferRef());

if (!Obj) {
Expand All @@ -373,11 +351,7 @@ CompilerResultT JuliaOJIT::CompilerT::operator()(Module &M)
"The module's content was printed above. Please file a bug report");
}

#if JL_LLVM_VERSION >= 70000
return ObjBuffer;
#else
return OwningObj(std::move(*Obj), std::move(ObjBuffer));
#endif
}

JuliaOJIT::JuliaOJIT(TargetMachine &TM)
Expand All @@ -386,7 +360,6 @@ JuliaOJIT::JuliaOJIT(TargetMachine &TM)
ObjStream(ObjBufferSV),
MemMgr(createRTDyldMemoryManager()),
registrar(*this),
#if JL_LLVM_VERSION >= 70000
ES(),
SymbolResolver(llvm::orc::createLegacyLookupResolver(
ES,
Expand All @@ -406,12 +379,6 @@ JuliaOJIT::JuliaOJIT(TargetMachine &TM)
},
std::ref(registrar)
),
#else
ObjectLayer(
[&] { return MemMgr; },
std::ref(registrar)
),
#endif
CompileLayer(
ObjectLayer,
CompilerT(this)
Expand Down Expand Up @@ -480,19 +447,8 @@ void JuliaOJIT::addModule(std::unique_ptr<Module> M)
#endif
JL_TIMING(LLVM_MODULE_FINISH);

#if JL_LLVM_VERSION >= 70000
auto key = ES.allocateVModule();
cantFail(CompileLayer.addModule(key, std::move(M)));
#else
auto Resolver = orc::createLambdaResolver(
[&](const std::string &Name) {
return this->resolveSymbol(Name);
},
[](const std::string &S) { return nullptr; }
);

auto key = cantFail(CompileLayer.addModule(std::move(M), std::move(Resolver)));
#endif
// Force LLVM to emit the module so that we can register the symbols
// in our lookup table.
Error Err = CompileLayer.emitAndFinalize(key);
Expand Down Expand Up @@ -573,12 +529,7 @@ void JuliaOJIT::NotifyFinalizer(RTDyldObjHandleT Key,
const RuntimeDyld::LoadedObjectInfo &LoadedObjectInfo)
{
for (auto &Listener : EventListeners)
#if JL_LLVM_VERSION >= 80000
Listener->notifyObjectLoaded(Key, Obj, LoadedObjectInfo);
#else
Listener->NotifyObjectEmitted(Obj, LoadedObjectInfo);
(void)Key;
#endif
}

const DataLayout& JuliaOJIT::getDataLayout() const
Expand Down Expand Up @@ -935,11 +886,7 @@ void jl_add_to_shadow(Module *m)
return;
#endif
ValueToValueMapTy VMap;
#if JL_LLVM_VERSION >= 70000
std::unique_ptr<Module> clone(CloneModule(*m, VMap));
#else
std::unique_ptr<Module> clone(CloneModule(m, VMap));
#endif
for (Module::iterator I = clone->begin(), E = clone->end(); I != E; ++I) {
Function *F = &*I;
if (!F->isDeclaration()) {
Expand Down Expand Up @@ -1045,15 +992,9 @@ void jl_dump_native(const char *bc_fname, const char *unopt_bc_fname, const char
addOptimizationPasses(&PM, jl_options.opt_level, true, true);
if (bc_fname)
PM.add(createBitcodeWriterPass(bc_OS));
#if JL_LLVM_VERSION >= 70000
if (obj_fname)
if (TM->addPassesToEmitFile(PM, obj_OS, nullptr, CGFT_ObjectFile, false))
jl_safe_printf("ERROR: target does not support generation of object files\n");
#else
if (obj_fname)
if (TM->addPassesToEmitFile(PM, obj_OS, CGFT_ObjectFile, false))
jl_safe_printf("ERROR: target does not support generation of object files\n");
#endif

// Reset the target triple to make sure it matches the new target machine
shadow_output->setTargetTriple(TM->getTargetTriple().str());
Expand Down
Loading

0 comments on commit 5393e4c

Please sign in to comment.