Fix LLVM 5.0 compilation.

This commit is contained in:
Johan Engelen 2017-04-13 22:00:00 +02:00
parent 3c297dcc06
commit 64df1687a8
8 changed files with 52 additions and 15 deletions

View file

@ -67,11 +67,14 @@ AttrSet::AttrSet(const AttrSet &base, unsigned index, LLAttribute attribute)
AttrSet
AttrSet::extractFunctionAndReturnAttributes(const llvm::Function *function) {
auto old = function->getAttributes();
LLAttributeSet existingAttrs[] = {old.getFnAttributes(),
#if LDC_LLVM_VER >= 500
return {LLAttributeSet::get(gIR->context(), old.getFnAttributes(),
old.getRetAttributes(), {})};
#else
llvm::AttributeSet existingAttrs[] = {old.getFnAttributes(),
old.getRetAttributes()};
AttrSet r(LLAttributeSet::get(gIR->context(), existingAttrs));
return r;
return {LLAttributeSet::get(gIR->context(), existingAttrs)};
#endif
}
AttrSet &AttrSet::add(unsigned index, const AttrBuilder &builder) {

View file

@ -978,8 +978,12 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
// create alloca point
// this gets erased when the function is complete, so alignment etc does not
// matter at all
llvm::Instruction *allocaPoint = new llvm::AllocaInst(
LLType::getInt32Ty(gIR->context()), "alloca point", beginbb);
llvm::Instruction *allocaPoint =
new llvm::AllocaInst(LLType::getInt32Ty(gIR->context()),
#if LDC_LLVM_VER >= 500
0, // Address space
#endif
"alloca point", beginbb);
funcGen.allocapoint = allocaPoint;
// debug info - after all allocas, but before any llvm.dbg.declare etc

View file

@ -35,10 +35,18 @@ struct TempDisableDiscardValueNames {
};
/// Adds the idol's function attributes to the wannabe
/// Note: don't add function _parameter_ attributes
void copyFnAttributes(llvm::Function *wannabe, llvm::Function *idol) {
auto attrSet = idol->getAttributes();
auto fnAttrSet = attrSet.getFnAttributes();
#if LDC_LLVM_VER >= 500
wannabe->addAttributes(LLAttributeSet::FunctionIndex,
LLAttributeSet::get(gIR->context(),
LLAttributeSet::FunctionIndex,
fnAttrSet));
#else
wannabe->addAttributes(LLAttributeSet::FunctionIndex, fnAttrSet);
#endif
}
} // anonymous namespace

View file

@ -180,15 +180,24 @@ llvm::AllocaInst *DtoAlloca(VarDeclaration *vd, const char *name) {
llvm::AllocaInst *DtoArrayAlloca(Type *type, unsigned arraysize,
const char *name) {
LLType *lltype = DtoType(type);
auto ai = new llvm::AllocaInst(lltype, DtoConstUint(arraysize), name,
gIR->topallocapoint());
auto ai = new llvm::AllocaInst(
lltype,
#if LDC_LLVM_VER >= 500
gIR->module.getDataLayout().getAllocaAddrSpace(),
#endif
DtoConstUint(arraysize), name, gIR->topallocapoint());
ai->setAlignment(DtoAlignment(type));
return ai;
}
llvm::AllocaInst *DtoRawAlloca(LLType *lltype, size_t alignment,
const char *name) {
auto ai = new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
auto ai =
new llvm::AllocaInst(lltype,
#if LDC_LLVM_VER >= 500
gIR->module.getDataLayout().getAllocaAddrSpace(),
#endif
name, gIR->topallocapoint());
if (alignment) {
ai->setAlignment(alignment);
}

View file

@ -115,8 +115,16 @@ public:
virtual Value *promote(CallSite CS, IRBuilder<> &B, const Analysis &A) {
NumGcToStack++;
Instruction *Begin = &(*CS.getCaller()->getEntryBlock().begin());
return new AllocaInst(Ty, ".nongc_mem", Begin); // FIXME: align?
auto &BB = CS.getCaller()->getEntryBlock();
Instruction *Begin = &(*BB.begin());
// FIXME: set alignment on alloca?
return new AllocaInst(
Ty,
#if LDC_LLVM_VER >= 500
BB.getModule()->getDataLayout().getAllocaAddrSpace(),
#endif
".nongc_mem", Begin);
}
explicit FunctionInfo(ReturnType::Type returnType) : ReturnType(returnType) {}

View file

@ -320,11 +320,13 @@ static void buildRuntimeModule() {
Attr_ReadOnly_1_NoCapture(Attr_ReadOnly, 1, llvm::Attribute::NoCapture),
Attr_ReadOnly_1_3_NoCapture(Attr_ReadOnly_1_NoCapture, 3,
llvm::Attribute::NoCapture),
Attr_ReadOnly_NoUnwind_1_NoCapture(Attr_ReadOnly_1_NoCapture, ~0U,
Attr_ReadOnly_NoUnwind_1_NoCapture(Attr_ReadOnly_1_NoCapture,
LLAttributeSet::FunctionIndex,
llvm::Attribute::NoUnwind),
Attr_ReadOnly_NoUnwind_1_2_NoCapture(Attr_ReadOnly_NoUnwind_1_NoCapture,
2, llvm::Attribute::NoCapture),
Attr_ReadNone(NoAttrs, ~0U, llvm::Attribute::ReadNone),
Attr_ReadNone(NoAttrs, LLAttributeSet::FunctionIndex,
llvm::Attribute::ReadNone),
Attr_1_NoCapture(NoAttrs, 1, llvm::Attribute::NoCapture),
Attr_NoAlias_1_NoCapture(Attr_1_NoCapture, 0, llvm::Attribute::NoAlias),
Attr_1_2_NoCapture(Attr_1_NoCapture, 2, llvm::Attribute::NoCapture),

View file

@ -826,7 +826,7 @@ DValue *DtoCallFunctionImpl(Loc &loc, Type *resulttype, DValue *fnval,
AttrSet attrs;
// return attrs
attrs.add(0, irFty.ret->attrs);
attrs.add(LLAttributeSet::ReturnIndex, irFty.ret->attrs);
std::vector<LLValue *> args;
args.reserve(irFty.args.size());

View file

@ -306,6 +306,9 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock,
if (!branchSelector) {
// ... and have not created one yet, so do so now.
branchSelector = new llvm::AllocaInst(llvm::Type::getInt32Ty(irs.context()),
#if LDC_LLVM_VER >= 500
irs.module.getDataLayout().getAllocaAddrSpace(),
#endif
llvm::Twine("branchsel.") +
beginBlock()->getName(),
irs.topallocapoint());