Skip to content

Commit

Permalink
Use JL_LLVM_VERSION instead of LLVMxx in the preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Sep 16, 2016
1 parent f30c949 commit 038abd2
Show file tree
Hide file tree
Showing 16 changed files with 371 additions and 392 deletions.
10 changes: 5 additions & 5 deletions src/APInt-C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

using namespace llvm;

#ifdef LLVM39
#if JL_LLVM_VERSION >= 30900
inline uint64_t RoundUpToAlignment(uint64_t Value, uint64_t Align, uint64_t Skew = 0) {
return alignTo(Value, Align, Skew);
}
Expand Down Expand Up @@ -448,7 +448,7 @@ void LLVMTrunc(unsigned inumbits, integerPart *pa, unsigned onumbits, integerPar

extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_8(uint8_t Val) {
#ifdef LLVM35
#if JL_LLVM_VERSION >= 30500
return countTrailingZeros(Val);
#else
return CountTrailingZeros_32(Val);
Expand All @@ -457,7 +457,7 @@ unsigned countTrailingZeros_8(uint8_t Val) {

extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_16(uint16_t Val) {
#ifdef LLVM35
#if JL_LLVM_VERSION >= 30500
return countTrailingZeros(Val);
#else
return CountTrailingZeros_32(Val);
Expand All @@ -466,7 +466,7 @@ unsigned countTrailingZeros_16(uint16_t Val) {

extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_32(uint32_t Val) {
#ifdef LLVM35
#if JL_LLVM_VERSION >= 30500
return countTrailingZeros(Val);
#else
return CountTrailingZeros_32(Val);
Expand All @@ -475,7 +475,7 @@ unsigned countTrailingZeros_32(uint32_t Val) {

extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_64(uint64_t Val) {
#ifdef LLVM35
#if JL_LLVM_VERSION >= 30500
return countTrailingZeros(Val);
#else
return CountTrailingZeros_64(Val);
Expand Down
22 changes: 11 additions & 11 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ static Value *runtime_sym_lookup(PointerType *funcptype, const char *f_lib,
else {
libname = literal_static_pointer_val(f_lib, T_pint8);
}
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
Value *llvmf = builder.CreateCall(prepare_call(jldlsym_func), { libname, stringConstPtr(f_name), libptrgv });
#else
Value *llvmf = builder.CreateCall3(prepare_call(jldlsym_func), libname, stringConstPtr(f_name), libptrgv);
#endif
auto store = builder.CreateAlignedStore(llvmf, llvmgv, sizeof(void*));
# ifdef LLVM39
# if JL_LLVM_VERSION >= 30900
store->setAtomic(AtomicOrdering::Release);
# else
store->setAtomic(Release);
Expand Down Expand Up @@ -267,7 +267,7 @@ static Value *emit_plt(FunctionType *functype, const AttributeSet &attrs,
Value *ptr = runtime_sym_lookup(funcptype, f_lib, f_name, plt, libptrgv,
llvmgv, runtime_lib);
auto store = builder.CreateAlignedStore(builder.CreateBitCast(ptr, T_pvoidfunc), got, sizeof(void*));
# ifdef LLVM39
# if JL_LLVM_VERSION >= 30900
store->setAtomic(AtomicOrdering::Release);
# else
store->setAtomic(Release);
Expand All @@ -289,7 +289,7 @@ static Value *emit_plt(FunctionType *functype, const AttributeSet &attrs,
else {
// musttail support is very bad on ARM, PPC, PPC64 (as of LLVM 3.9)
// Known failures includes vararg (not needed here) and sret.
#if defined(LLVM37) && (defined(_CPU_X86_) || defined(_CPU_X86_64_) || \
#if JL_LLVM_VERSION >= 30700 && (defined(_CPU_X86_) || defined(_CPU_X86_64_) || \
defined(_CPU_AARCH64_))
ret->setTailCallKind(CallInst::TCK_MustTail);
#endif
Expand Down Expand Up @@ -742,7 +742,7 @@ class FunctionMover : public ValueMaterializer
VMap[&*I] = &*(DestI++); // Add mapping to VMap
}

#ifdef LLVM36
#if JL_LLVM_VERSION >= 30600
// Clone debug info - Not yet public API
// llvm::CloneDebugInfoMetadata(NewF,F,VMap);
#endif
Expand Down Expand Up @@ -781,9 +781,9 @@ class FunctionMover : public ValueMaterializer
return NewF;
}

#if defined(LLVM39)
#if JL_LLVM_VERSION >= 30900
virtual Value *materialize(Value *V) override
#elif defined(LLVM38)
#elif JL_LLVM_VERSION >= 30800
virtual Value *materializeDeclFor(Value *V) override
#else
virtual Value *materializeValueFor (Value *V) override
Expand Down Expand Up @@ -980,7 +980,7 @@ static jl_cgval_t emit_llvmcall(jl_value_t **args, size_t nargs, jl_codectx_t *c
<< jl_string_data(ir) << "\n}";
SMDiagnostic Err = SMDiagnostic();
std::string ir_string = ir_stream.str();
#ifdef LLVM36
#if JL_LLVM_VERSION >= 30600
Module *m = NULL;
bool failed = parseAssemblyInto(llvm::MemoryBufferRef(ir_string,"llvmcall"),*jl_Module,Err);
if (!failed)
Expand Down Expand Up @@ -1014,7 +1014,7 @@ static jl_cgval_t emit_llvmcall(jl_value_t **args, size_t nargs, jl_codectx_t *c
#endif

//f->dump();
#ifndef LLVM35
#if JL_LLVM_VERSION < 30500
if (verifyFunction(*f,PrintMessageAction)) {
#else
llvm::raw_fd_ostream out(1,false);
Expand Down Expand Up @@ -1125,7 +1125,7 @@ static std::string generate_func_sig(
else if (use_sret(&abi, (jl_datatype_t*)rt)) {
paramattrs.push_back(AttrBuilder());
paramattrs[0].clear();
#if !defined(_OS_WINDOWS_) || defined(LLVM35) // llvm used to use the old mingw ABI, skipping this marking works around that difference
#if !defined(_OS_WINDOWS_) || JL_LLVM_VERSION >= 30500 // llvm used to use the old mingw ABI, skipping this marking works around that difference
paramattrs[0].addAttribute(Attribute::StructRet);
#endif
paramattrs[0].addAttribute(Attribute::NoAlias);
Expand Down Expand Up @@ -1781,7 +1781,7 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
stacksave = CallInst::Create(Intrinsic::getDeclaration(jl_Module,
Intrinsic::stacksave));
if (savespot) {
#ifdef LLVM38
#if JL_LLVM_VERSION >= 30800
instList.insertAfter(savespot->getIterator(), (Instruction*)stacksave);
#else
instList.insertAfter((Instruction*)savespot, (Instruction*)stacksave);
Expand Down
14 changes: 7 additions & 7 deletions src/cgmemmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "julia.h"
#include "julia_internal.h"

#ifdef LLVM37
#ifndef LLVM38
#if JL_LLVM_VERSION >= 30700
#if JL_LLVM_VERSION < 30800
# include <llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h>
#endif
#ifdef _OS_LINUX_
Expand Down Expand Up @@ -727,7 +727,7 @@ class RTDyldMemoryManagerJL : public SectionMemoryManager {
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID, StringRef SectionName,
bool isReadOnly) override;
#ifdef LLVM38
#if JL_LLVM_VERSION >= 30800
void notifyObjectLoaded(RuntimeDyld &Dyld,
const object::ObjectFile &Obj) override;
#endif
Expand Down Expand Up @@ -802,7 +802,7 @@ uint8_t *RTDyldMemoryManagerJL::allocateDataSection(uintptr_t Size,
SectionName, isReadOnly);
}

#ifdef LLVM38
#if JL_LLVM_VERSION >= 30800
void RTDyldMemoryManagerJL::notifyObjectLoaded(RuntimeDyld &Dyld,
const object::ObjectFile &Obj)
{
Expand Down Expand Up @@ -855,7 +855,7 @@ void RTDyldMemoryManagerJL::deregisterEHFrames(uint8_t *Addr,

}

#ifndef LLVM38
#if JL_LLVM_VERSION < 30800
void notifyObjectLoaded(RTDyldMemoryManager *memmgr,
llvm::orc::ObjectLinkingLayerBase::ObjSetHandleT H)
{
Expand All @@ -870,9 +870,9 @@ void *lookupWriteAddressFor(RTDyldMemoryManager *memmgr, void *rt_addr)
}
#endif

#else // LLVM37
#else // JL_LLVM_VERSION >= 30700
typedef SectionMemoryManager RTDyldMemoryManagerJL;
#endif // LLVM37
#endif // JL_LLVM_VERSION >= 30700

RTDyldMemoryManager* createRTDyldMemoryManager()
{
Expand Down
42 changes: 21 additions & 21 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static StringMap<GlobalVariable*> stringConstants;
static Value *stringConstPtr(const std::string &txt)
{
StringRef ctxt(txt.c_str(), strlen(txt.c_str()) + 1);
#ifdef LLVM36
#if JL_LLVM_VERSION >= 30600
StringMap<GlobalVariable*>::iterator pooledval =
stringConstants.insert(std::pair<StringRef, GlobalVariable*>(ctxt, NULL)).first;
#else
Expand All @@ -48,7 +48,7 @@ static Value *stringConstPtr(const std::string &txt)
(const unsigned char*)pooledtxt.data(),
pooledtxt.size())),
ssno.str());
#ifdef LLVM39
#if JL_LLVM_VERSION >= 30900
gv->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
#else
gv->setUnnamedAddr(true);
Expand All @@ -60,7 +60,7 @@ static Value *stringConstPtr(const std::string &txt)
GlobalVariable *v = prepare_global(pooledval->second);
Value *zero = ConstantInt::get(Type::getInt32Ty(jl_LLVMContext), 0);
Value *Args[] = { zero, zero };
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
return builder.CreateInBoundsGEP(v->getValueType(), v, Args);
#else
return builder.CreateInBoundsGEP(v, Args);
Expand All @@ -76,7 +76,7 @@ static Value *stringConstPtr(const std::string &txt)

// --- Debug info ---

#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
static DIType *julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed = false)
#else
static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed = false)
Expand All @@ -95,9 +95,9 @@ static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed
assert(jl_is_datatype(jt));
jl_datatype_t *jdt = (jl_datatype_t*)jt;
if (jdt->ditype != NULL) {
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
DIType* t = (DIType*)jdt->ditype;
#ifndef LLVM39
#if JL_LLVM_VERSION < 30900
// On LLVM 3.7 and 3.8, DICompositeType with a unique name
// are ref'd by their unique name and needs to be explicitly
// retained in order to be used in the module.
Expand All @@ -114,7 +114,7 @@ static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed
}
if (jl_is_bitstype(jt)) {
uint64_t SizeInBits = 8*jdt->size;
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
llvm::DIType *t = dbuilder->createBasicType(
jl_symbol_name(jdt->name->name),
SizeInBits,
Expand All @@ -133,7 +133,7 @@ static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed
return t;
#endif
}
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
else if (!jl_is_leaf_type(jt)) {
jdt->ditype = jl_pvalue_dillvmt;
return jl_pvalue_dillvmt;
Expand Down Expand Up @@ -422,7 +422,7 @@ static Type *julia_struct_to_llvm(jl_value_t *jt, bool *isboxed)
#ifndef NDEBUG
// If LLVM and Julia disagree about alignment, much trouble ensues, so check it!
const DataLayout &DL =
#ifdef LLVM36
#if JL_LLVM_VERSION >= 30600
jl_ExecutionEngine->getDataLayout();
#else
*jl_ExecutionEngine->getDataLayout();
Expand Down Expand Up @@ -644,7 +644,7 @@ static void error_unless(Value *cond, const std::string &msg, jl_codectx_t *ctx)
static void raise_exception(Value *exc, jl_codectx_t *ctx,
BasicBlock *contBB=nullptr)
{
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
builder.CreateCall(prepare_call(jlthrow_func), { exc });
#else
builder.CreateCall(prepare_call(jlthrow_func), exc);
Expand Down Expand Up @@ -687,7 +687,7 @@ static void emit_type_error(const jl_cgval_t &x, jl_value_t *type, const std::st
{
Value *fname_val = stringConstPtr(ctx->funcName);
Value *msg_val = stringConstPtr(msg);
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
builder.CreateCall(prepare_call(jltypeerror_func),
{ fname_val, msg_val,
literal_pointer_val(type), boxed(x, ctx, false)}); // x is rooted by jl_type_error_rt
Expand Down Expand Up @@ -717,7 +717,7 @@ static void emit_typecheck(const jl_cgval_t &x, jl_value_t *type, const std::str
Value *vx = boxed(x, ctx);
istype = builder.
CreateICmpNE(
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
builder.CreateCall(prepare_call(jlsubtype_func), { vx, literal_pointer_val(type),
ConstantInt::get(T_int32,1) }),
#else
Expand Down Expand Up @@ -755,14 +755,14 @@ static Value *emit_bounds_check(const jl_cgval_t &ainfo, jl_value_t *ty, Value *
builder.CreateCondBr(ok, passBB, failBB);
builder.SetInsertPoint(failBB);
if (!ty) { // jl_value_t** tuple (e.g. the vararg)
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
builder.CreateCall(prepare_call(jlvboundserror_func), { ainfo.V, len, i });
#else
builder.CreateCall3(prepare_call(jlvboundserror_func), ainfo.V, len, i);
#endif
}
else if (ainfo.isboxed) { // jl_datatype_t or boxed jl_value_t
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
builder.CreateCall(prepare_call(jlboundserror_func), { boxed(ainfo, ctx), i });
#else
builder.CreateCall2(prepare_call(jlboundserror_func), boxed(ainfo, ctx), i);
Expand All @@ -779,7 +779,7 @@ static Value *emit_bounds_check(const jl_cgval_t &ainfo, jl_value_t *ty, Value *
builder.CreateStore(a, tempSpace);
a = tempSpace;
}
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
builder.CreateCall(prepare_call(jluboundserror_func), {
builder.CreatePointerCast(a, T_pint8),
literal_pointer_val(ty),
Expand Down Expand Up @@ -1009,7 +1009,7 @@ static bool emit_getfield_unknownidx(jl_cgval_t *ret, const jl_cgval_t &strct, V
}
else if (strct.isboxed) {
idx = builder.CreateSub(idx, ConstantInt::get(T_size, 1));
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
Value *fld = builder.CreateCall(prepare_call(jlgetnthfieldchecked_func), { boxed(strct, ctx), idx });
#else
Value *fld = builder.CreateCall2(prepare_call(jlgetnthfieldchecked_func), boxed(strct, ctx), idx);
Expand Down Expand Up @@ -1158,7 +1158,7 @@ static Value *emit_arraylen_prim(const jl_cgval_t &tinfo, jl_codectx_t *ctx)
jl_value_t *ty = tinfo.typ;
#ifdef STORE_ARRAY_LEN
Value *addr = builder.CreateStructGEP(
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
nullptr,
#endif
emit_bitcast(t,jl_parray_llvmt),
Expand Down Expand Up @@ -1198,7 +1198,7 @@ static Value *emit_arrayptr(const jl_cgval_t &tinfo, jl_codectx_t *ctx)
{
Value *t = boxed(tinfo, ctx);
Value *addr = builder.CreateStructGEP(
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
nullptr,
#endif
emit_bitcast(t,jl_parray_llvmt),
Expand Down Expand Up @@ -1233,7 +1233,7 @@ static Value *emit_arrayflags(const jl_cgval_t &tinfo, jl_codectx_t *ctx)
int arrayflag_field = 1;
#endif
Value *addr = builder.CreateStructGEP(
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
nullptr,
#endif
emit_bitcast(t, jl_parray_llvmt),
Expand Down Expand Up @@ -1322,7 +1322,7 @@ static Value *emit_array_nd_index(const jl_cgval_t &ainfo, jl_value_t *ex, size_
for(size_t k=0; k < nidxs; k++) {
builder.CreateStore(idxs[k], builder.CreateGEP(tmp, ConstantInt::get(T_size, k)));
}
#ifdef LLVM37
#if JL_LLVM_VERSION >= 30700
builder.CreateCall(prepare_call(jlboundserrorv_func), { a, tmp, ConstantInt::get(T_size, nidxs) });
#else
builder.CreateCall3(prepare_call(jlboundserrorv_func), a, tmp, ConstantInt::get(T_size, nidxs));
Expand Down Expand Up @@ -1801,7 +1801,7 @@ static void emit_signal_fence(void)
builder.CreateCall(InlineAsm::get(FunctionType::get(T_void, false), "",
"~{memory}", true));
#else
# ifdef LLVM39
# if JL_LLVM_VERSION >= 30900
builder.CreateFence(AtomicOrdering::SequentiallyConsistent, SingleThread);
# else
builder.CreateFence(SequentiallyConsistent, SingleThread);
Expand Down
Loading

0 comments on commit 038abd2

Please sign in to comment.