Fix LLVM 5.0 build. (#2050)

llvm::AttributeSet was renamed to llvm::AttributeList
This commit is contained in:
Johan Engelen 2017-03-29 22:26:17 +02:00 committed by kinke
parent 9bb7ada8e0
commit 9e394e4f99
8 changed files with 33 additions and 27 deletions

View file

@ -66,19 +66,17 @@ AttrSet::AttrSet(const AttrSet &base, unsigned index, LLAttribute attribute)
AttrSet
AttrSet::extractFunctionAndReturnAttributes(const llvm::Function *function) {
AttrSet r;
llvm::AttributeSet old = function->getAttributes();
llvm::AttributeSet existingAttrs[] = {old.getFnAttributes(),
auto old = function->getAttributes();
LLAttributeSet existingAttrs[] = {old.getFnAttributes(),
old.getRetAttributes()};
r.set = llvm::AttributeSet::get(gIR->context(), existingAttrs);
AttrSet r(LLAttributeSet::get(gIR->context(), existingAttrs));
return r;
}
AttrSet &AttrSet::add(unsigned index, const AttrBuilder &builder) {
if (builder.hasAttributes()) {
auto as = llvm::AttributeSet::get(gIR->context(), index, builder);
auto as = LLAttributeSet::get(gIR->context(), index, builder);
set = set.addAttributes(gIR->context(), index, as);
}
return *this;

View file

@ -13,6 +13,11 @@
#include "gen/llvm.h"
using LLAttribute = llvm::Attribute::AttrKind;
#if LDC_LLVM_VER >= 500
using LLAttributeSet = llvm::AttributeList;
#else
using LLAttributeSet = llvm::AttributeSet;
#endif
class AttrBuilder {
llvm::AttrBuilder builder;
@ -37,11 +42,11 @@ public:
};
class AttrSet {
llvm::AttributeSet set;
LLAttributeSet set;
public:
AttrSet() = default;
AttrSet(const llvm::AttributeSet &nativeSet) : set(nativeSet) {}
AttrSet(const LLAttributeSet &nativeSet) : set(nativeSet) {}
AttrSet(const AttrSet &base, unsigned index, LLAttribute attribute);
static AttrSet
@ -50,8 +55,8 @@ public:
AttrSet &add(unsigned index, const AttrBuilder &builder);
AttrSet &merge(const AttrSet &other);
operator llvm::AttributeSet &() { return set; }
operator const llvm::AttributeSet &() const { return set; }
operator LLAttributeSet &() { return set; }
operator const LLAttributeSet &() const { return set; }
};
#endif

View file

@ -38,7 +38,7 @@ struct TempDisableDiscardValueNames {
void copyFnAttributes(llvm::Function *wannabe, llvm::Function *idol) {
auto attrSet = idol->getAttributes();
auto fnAttrSet = attrSet.getFnAttributes();
wannabe->addAttributes(llvm::AttributeSet::FunctionIndex, fnAttrSet);
wannabe->addAttributes(LLAttributeSet::FunctionIndex, fnAttrSet);
}
} // anonymous namespace

View file

@ -143,8 +143,12 @@ public:
// Finalize the MD5 and return the hash.
llvm::MD5::MD5Result Result;
MD5.final(Result);
#if LDC_LLVM_VER >= 500
return Result.low();
#else
using namespace llvm::support;
return endian::read<uint64_t, little, unaligned>(Result);
#endif
}
};

View file

@ -306,17 +306,16 @@ static void buildRuntimeModule() {
//////////////////////////////////////////////////////////////////////////////
// Construct some attribute lists used below (possibly multiple times)
AttrSet NoAttrs, Attr_NoAlias(NoAttrs, llvm::AttributeSet::ReturnIndex,
AttrSet NoAttrs, Attr_NoAlias(NoAttrs, LLAttributeSet::ReturnIndex,
llvm::Attribute::NoAlias),
Attr_NoUnwind(NoAttrs, llvm::AttributeSet::FunctionIndex,
Attr_NoUnwind(NoAttrs, LLAttributeSet::FunctionIndex,
llvm::Attribute::NoUnwind),
Attr_ReadOnly(NoAttrs, llvm::AttributeSet::FunctionIndex,
Attr_ReadOnly(NoAttrs, LLAttributeSet::FunctionIndex,
llvm::Attribute::ReadOnly),
Attr_Cold(NoAttrs, llvm::AttributeSet::FunctionIndex,
llvm::Attribute::Cold),
Attr_Cold_NoReturn(Attr_Cold, llvm::AttributeSet::FunctionIndex,
Attr_Cold(NoAttrs, LLAttributeSet::FunctionIndex, llvm::Attribute::Cold),
Attr_Cold_NoReturn(Attr_Cold, LLAttributeSet::FunctionIndex,
llvm::Attribute::NoReturn),
Attr_ReadOnly_NoUnwind(Attr_ReadOnly, llvm::AttributeSet::FunctionIndex,
Attr_ReadOnly_NoUnwind(Attr_ReadOnly, LLAttributeSet::FunctionIndex,
llvm::Attribute::NoUnwind),
Attr_ReadOnly_1_NoCapture(Attr_ReadOnly, 1, llvm::Attribute::NoCapture),
Attr_ReadOnly_1_3_NoCapture(Attr_ReadOnly_1_NoCapture, 3,

View file

@ -979,7 +979,7 @@ DValue *DtoCallFunctionImpl(Loc &loc, Type *resulttype, DValue *fnval,
}
// set calling convention and parameter attributes
llvm::AttributeSet &attrlist = attrs;
LLAttributeSet &attrlist = attrs;
if (dfnval && dfnval->func) {
LLFunction *llfunc = llvm::dyn_cast<LLFunction>(DtoRVal(dfnval));
if (llfunc && llfunc->isIntrinsic()) // override intrinsic attrs
@ -995,7 +995,7 @@ DValue *DtoCallFunctionImpl(Loc &loc, Type *resulttype, DValue *fnval,
}
// merge in function attributes set in callOrInvoke
attrlist = attrlist.addAttributes(
gIR->context(), llvm::AttributeSet::FunctionIndex, call.getAttributes());
gIR->context(), LLAttributeSet::FunctionIndex, call.getAttributes());
call.setAttributes(attrlist);

View file

@ -186,9 +186,9 @@ void applyAttrAllocSize(StructLiteralExp *sle, IrFunction *irFunc) {
} else {
builder.addAllocSizeAttr(llvmSizeIdx, llvm::Optional<unsigned>());
}
func->addAttributes(llvm::AttributeSet::FunctionIndex,
llvm::AttributeSet::get(func->getContext(),
llvm::AttributeSet::FunctionIndex,
func->addAttributes(LLAttributeSet::FunctionIndex,
LLAttributeSet::get(func->getContext(),
LLAttributeSet::FunctionIndex,
builder));
#endif
}

View file

@ -25,14 +25,14 @@ IrFunction::IrFunction(FuncDeclaration *fd) : FMF(opts::defaultFMF) {
}
void IrFunction::setNeverInline() {
assert(!func->getAttributes().hasAttribute(llvm::AttributeSet::FunctionIndex,
assert(!func->getAttributes().hasAttribute(LLAttributeSet::FunctionIndex,
llvm::Attribute::AlwaysInline) &&
"function can't be never- and always-inline at the same time");
func->addFnAttr(llvm::Attribute::NoInline);
}
void IrFunction::setAlwaysInline() {
assert(!func->getAttributes().hasAttribute(llvm::AttributeSet::FunctionIndex,
assert(!func->getAttributes().hasAttribute(LLAttributeSet::FunctionIndex,
llvm::Attribute::NoInline) &&
"function can't be never- and always-inline at the same time");
func->addFnAttr(llvm::Attribute::AlwaysInline);