Skip to content

Commit

Permalink
Excise support for LLVM 13 (#49722)
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed May 10, 2023
1 parent 21d4c2f commit 7757e46
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 225 deletions.
4 changes: 0 additions & 4 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
#include <llvm/Analysis/TargetLibraryInfo.h>
#include <llvm/Analysis/TargetTransformInfo.h>
#include <llvm/IR/DataLayout.h>
#if JL_LLVM_VERSION >= 140000
#include <llvm/MC/TargetRegistry.h>
#else
#include <llvm/Support/TargetRegistry.h>
#endif
#include <llvm/Target/TargetMachine.h>

// analysis passes
Expand Down
10 changes: 0 additions & 10 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,10 +958,8 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
// copy module properties that should always match
Mod->setTargetTriple(jl_Module->getTargetTriple());
Mod->setDataLayout(jl_Module->getDataLayout());
#if JL_LLVM_VERSION >= 130000
Mod->setStackProtectorGuard(jl_Module->getStackProtectorGuard());
Mod->setOverrideStackAlignment(jl_Module->getOverrideStackAlignment());
#endif

// verify the definition
Function *def = Mod->getFunction(ir_name);
Expand Down Expand Up @@ -1097,11 +1095,7 @@ std::string generate_func_sig(const char *fname)
abi->use_sret(jl_voidpointer_type, LLVMCtx);
}
else if (abi->use_sret((jl_datatype_t*)rt, LLVMCtx)) {
#if JL_LLVM_VERSION >= 140000
AttrBuilder retattrs(LLVMCtx);
#else
AttrBuilder retattrs;
#endif
if (!ctx->TargetTriple.isOSWindows()) {
// llvm used to use the old mingw ABI, skipping this marking works around that difference
retattrs.addStructRetAttr(lrt);
Expand All @@ -1120,11 +1114,7 @@ std::string generate_func_sig(const char *fname)
}

for (size_t i = 0; i < nccallargs; ++i) {
#if JL_LLVM_VERSION >= 140000
AttrBuilder ab(LLVMCtx);
#else
AttrBuilder ab;
#endif
jl_value_t *tti = jl_svecref(at, i);
Type *t = NULL;
bool isboxed;
Expand Down
18 changes: 0 additions & 18 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1768,12 +1768,8 @@ std::vector<unsigned> first_ptr(Type *T)
num_elements = AT->getNumElements();
else {
VectorType *VT = cast<VectorType>(T);
#if JL_LLVM_VERSION >= 120000
ElementCount EC = VT->getElementCount();
num_elements = EC.getKnownMinValue();
#else
num_elements = VT->getNumElements();
#endif
}
if (num_elements == 0)
return {};
Expand Down Expand Up @@ -2015,12 +2011,7 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
assert(Order != AtomicOrdering::NotAtomic && r);
// we can't handle isboxed here as a workaround for really bad LLVM
// design issue: plain Xchg only works with integers
#if JL_LLVM_VERSION >= 130000
auto *store = ctx.builder.CreateAtomicRMW(AtomicRMWInst::Xchg, ptr, r, Align(alignment), Order);
#else
auto *store = ctx.builder.CreateAtomicRMW(AtomicRMWInst::Xchg, ptr, r, Order);
store->setAlignment(Align(alignment));
#endif
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, tbaa);
ai.noalias = MDNode::concatenate(aliasscope, ai.noalias);
ai.decorateInst(store);
Expand Down Expand Up @@ -2170,12 +2161,7 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
FailOrder = AtomicOrdering::Monotonic;
else if (FailOrder == AtomicOrdering::Unordered)
FailOrder = AtomicOrdering::Monotonic;
#if JL_LLVM_VERSION >= 130000
auto *store = ctx.builder.CreateAtomicCmpXchg(ptr, Compare, r, Align(alignment), Order, FailOrder);
#else
auto *store = ctx.builder.CreateAtomicCmpXchg(ptr, Compare, r, Order, FailOrder);
store->setAlignment(Align(alignment));
#endif
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, tbaa);
ai.noalias = MDNode::concatenate(aliasscope, ai.noalias);
ai.decorateInst(store);
Expand Down Expand Up @@ -3052,12 +3038,8 @@ static jl_value_t *static_constant_instance(const llvm::DataLayout &DL, Constant
if (const auto *CC = dyn_cast<ConstantAggregate>(constant))
nargs = CC->getNumOperands();
else if (const auto *CAZ = dyn_cast<ConstantAggregateZero>(constant)) {
#if JL_LLVM_VERSION >= 130000
// SVE: Elsewhere we use `getMinKownValue`
nargs = CAZ->getElementCount().getFixedValue();
#else
nargs = CAZ->getNumElements();
#endif
}
else if (const auto *CDS = dyn_cast<ConstantDataSequential>(constant))
nargs = CDS->getNumElements();
Expand Down
59 changes: 1 addition & 58 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@

// target machine computation
#include <llvm/CodeGen/TargetSubtargetInfo.h>
#if JL_LLVM_VERSION >= 140000
#include <llvm/MC/TargetRegistry.h>
#else
#include <llvm/Support/TargetRegistry.h>
#endif
#include <llvm/Target/TargetOptions.h>
#include <llvm/Support/Host.h>
#include <llvm/Support/TargetSelect.h>
Expand Down Expand Up @@ -2338,7 +2334,7 @@ std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &conte
m->setOverrideStackAlignment(16);
}

#if defined(JL_DEBUG_BUILD) && JL_LLVM_VERSION >= 130000
#if defined(JL_DEBUG_BUILD)
m->setStackProtectorGuard("global");
#endif
return m;
Expand All @@ -2347,11 +2343,7 @@ std::unique_ptr<Module> jl_create_llvm_module(StringRef name, LLVMContext &conte
static void jl_init_function(Function *F, const Triple &TT)
{
// set any attributes that *must* be set on all functions
#if JL_LLVM_VERSION >= 140000
AttrBuilder attr(F->getContext());
#else
AttrBuilder attr;
#endif
if (TT.isOSWindows() && TT.getArch() == Triple::x86) {
// tell Win32 to assume the stack is always 16-byte aligned,
// and to ensure that it is 16-byte aligned for out-going calls,
Expand Down Expand Up @@ -2383,11 +2375,7 @@ static void jl_init_function(Function *F, const Triple &TT)
#if defined(_COMPILER_MSAN_ENABLED_)
attr.addAttribute(Attribute::SanitizeMemory);
#endif
#if JL_LLVM_VERSION >= 140000
F->addFnAttrs(attr);
#else
F->addAttributes(AttributeList::FunctionIndex, attr);
#endif
}

static bool uses_specsig(jl_value_t *sig, bool needsparams, bool va, jl_value_t *rettype, bool prefer_specsig)
Expand Down Expand Up @@ -5978,13 +5966,8 @@ static Function* gen_cfun_wrapper(
// we are adding the extra nest parameter after sret arg.
std::vector<std::pair<unsigned, AttributeSet>> newAttributes;
newAttributes.reserve(attributes.getNumAttrSets() + 1);
#if JL_LLVM_VERSION >= 140000
auto it = *attributes.indexes().begin();
const auto it_end = *attributes.indexes().end();
#else
auto it = attributes.index_begin();
const auto it_end = attributes.index_end();
#endif

// Skip past FunctionIndex
if (it == AttributeList::AttrIndex::FunctionIndex) {
Expand All @@ -5999,11 +5982,7 @@ static Function* gen_cfun_wrapper(
}

// Add the new nest attribute
#if JL_LLVM_VERSION >= 140000
AttrBuilder attrBuilder(M->getContext());
#else
AttrBuilder attrBuilder;
#endif
attrBuilder.addAttribute(Attribute::Nest);
newAttributes.emplace_back(it, AttributeSet::get(M->getContext(), attrBuilder));

Expand Down Expand Up @@ -6868,11 +6847,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
SmallVector<AttributeSet, 8> attrs; // function declaration attributes
if (props.cc == jl_returninfo_t::SRet) {
assert(srt);
#if JL_LLVM_VERSION >= 140000
AttrBuilder param(ctx.builder.getContext());
#else
AttrBuilder param;
#endif
param.addStructRetAttr(srt);
param.addAttribute(Attribute::NoAlias);
param.addAttribute(Attribute::NoCapture);
Expand All @@ -6881,11 +6856,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
assert(fsig.size() == 1);
}
if (props.cc == jl_returninfo_t::Union) {
#if JL_LLVM_VERSION >= 140000
AttrBuilder param(ctx.builder.getContext());
#else
AttrBuilder param;
#endif
param.addAttribute(Attribute::NoAlias);
param.addAttribute(Attribute::NoCapture);
param.addAttribute(Attribute::NoUndef);
Expand All @@ -6894,11 +6865,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
}

if (props.return_roots) {
#if JL_LLVM_VERSION >= 140000
AttrBuilder param(ctx.builder.getContext());
#else
AttrBuilder param;
#endif
param.addAttribute(Attribute::NoAlias);
param.addAttribute(Attribute::NoCapture);
param.addAttribute(Attribute::NoUndef);
Expand All @@ -6922,11 +6889,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
}
if (type_is_ghost(ty))
continue;
#if JL_LLVM_VERSION >= 140000
AttrBuilder param(ctx.builder.getContext());
#else
AttrBuilder param;
#endif
if (ty->isAggregateType()) { // aggregate types are passed by pointer
param.addAttribute(Attribute::NoCapture);
param.addAttribute(Attribute::ReadOnly);
Expand Down Expand Up @@ -7245,16 +7208,8 @@ static jl_llvm_functions_t
declarations.functionObject = needsparams ? "jl_fptr_sparam" : "jl_fptr_args";
}

#if JL_LLVM_VERSION >= 140000
AttrBuilder FnAttrs(ctx.builder.getContext(), f->getAttributes().getFnAttrs());
#else
AttrBuilder FnAttrs(f->getAttributes().getFnAttributes());
#endif
#if JL_LLVM_VERSION >= 140000
AttrBuilder RetAttrs(ctx.builder.getContext(), f->getAttributes().getRetAttrs());
#else
AttrBuilder RetAttrs(f->getAttributes().getRetAttributes());
#endif

if (jlrettype == (jl_value_t*)jl_bottom_type)
FnAttrs.addAttribute(Attribute::NoReturn);
Expand Down Expand Up @@ -7547,11 +7502,7 @@ static jl_llvm_functions_t
}
Argument *Arg = &*AI;
++AI;
#if JL_LLVM_VERSION >= 140000
AttrBuilder param(ctx.builder.getContext(), f->getAttributes().getParamAttrs(Arg->getArgNo()));
#else
AttrBuilder param(f->getAttributes().getParamAttributes(Arg->getArgNo()));
#endif
jl_cgval_t theArg;
if (llvmArgType->isAggregateType()) {
maybe_mark_argument_dereferenceable(param, argType);
Expand All @@ -7571,11 +7522,7 @@ static jl_llvm_functions_t
if (has_sret) {
Argument *Arg = &*AI;
++AI;
#if JL_LLVM_VERSION >= 140000
AttrBuilder param(ctx.builder.getContext(), f->getAttributes().getParamAttrs(Arg->getArgNo()));
#else
AttrBuilder param(f->getAttributes().getParamAttributes(Arg->getArgNo()));
#endif
if (returninfo.cc == jl_returninfo_t::Union) {
param.addAttribute(Attribute::NonNull);
// The `dereferenceable` below does not imply `nonnull` for non addrspace(0) pointers.
Expand All @@ -7597,11 +7544,7 @@ static jl_llvm_functions_t
if (returninfo.return_roots) {
Argument *Arg = &*AI;
++AI;
#if JL_LLVM_VERSION >= 140000
AttrBuilder param(ctx.builder.getContext(), f->getAttributes().getParamAttrs(Arg->getArgNo()));
#else
AttrBuilder param(f->getAttributes().getParamAttributes(Arg->getArgNo()));
#endif
param.addAttribute(Attribute::NonNull);
// The `dereferenceable` below does not imply `nonnull` for non addrspace(0) pointers.
size_t size = returninfo.return_roots * sizeof(jl_value_t*);
Expand Down
10 changes: 0 additions & 10 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Support/NativeFormatting.h>
#include <llvm/Support/SourceMgr.h>
#if JL_LLVM_VERSION >= 140000
#include <llvm/MC/TargetRegistry.h>
#else
#include <llvm/Support/TargetRegistry.h>
#endif
#include <llvm/Support/TargetSelect.h>
#include <llvm/Support/raw_ostream.h>

Expand Down Expand Up @@ -883,16 +879,10 @@ static void jl_dump_asm_internal(
TheTarget->createMCSubtargetInfo(TheTriple.str(), cpu, features));
assert(STI && "Unable to create subtarget info!");

#if JL_LLVM_VERSION >= 130000
MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr);
std::unique_ptr<MCObjectFileInfo> MOFI(
TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false, /*LargeCodeModel=*/ false));
Ctx.setObjectFileInfo(MOFI.get());
#else
std::unique_ptr<MCObjectFileInfo> MOFI(new MCObjectFileInfo());
MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr);
MOFI->InitMCObjectFileInfo(TheTriple, /* PIC */ false, Ctx);
#endif

std::unique_ptr<MCDisassembler> DisAsm(TheTarget->createMCDisassembler(*STI, Ctx));
if (!DisAsm) {
Expand Down
Loading

0 comments on commit 7757e46

Please sign in to comment.