Adjust addAttributes calls for LLVM r301981

These now take an AttrBuilder argument instead of an AttributeList.
This commit is contained in:
Bob Wilson
2017-05-06 18:12:29 -07:00
parent e55cc83fa6
commit e24a6f1d30
6 changed files with 49 additions and 80 deletions

View File

@@ -86,8 +86,7 @@ static void addIndirectValueParameterAttributes(IRGenModule &IGM,
// The parameter must reference dereferenceable memory of the type. // The parameter must reference dereferenceable memory of the type.
addDereferenceableAttributeToBuilder(IGM, b, ti); addDereferenceableAttributeToBuilder(IGM, b, ti);
auto resultAttrs = llvm::AttributeList::get(IGM.LLVMContext, argIndex + 1, b); attrs = attrs.addAttributes(IGM.LLVMContext, argIndex+1, b);
attrs = attrs.addAttributes(IGM.LLVMContext, argIndex+1, resultAttrs);
} }
static void addInoutParameterAttributes(IRGenModule &IGM, static void addInoutParameterAttributes(IRGenModule &IGM,
@@ -102,8 +101,7 @@ static void addInoutParameterAttributes(IRGenModule &IGM,
// The inout must reference dereferenceable memory of the type. // The inout must reference dereferenceable memory of the type.
addDereferenceableAttributeToBuilder(IGM, b, ti); addDereferenceableAttributeToBuilder(IGM, b, ti);
auto resultAttrs = llvm::AttributeList::get(IGM.LLVMContext, argIndex + 1, b); attrs = attrs.addAttributes(IGM.LLVMContext, argIndex+1, b);
attrs = attrs.addAttributes(IGM.LLVMContext, argIndex+1, resultAttrs);
} }
static llvm::CallingConv::ID getFreestandingConvention(IRGenModule &IGM) { static llvm::CallingConv::ID getFreestandingConvention(IRGenModule &IGM) {
@@ -134,32 +132,21 @@ llvm::CallingConv::ID irgen::expandCallingConv(IRGenModule &IGM,
static void addIndirectResultAttributes(IRGenModule &IGM, static void addIndirectResultAttributes(IRGenModule &IGM,
llvm::AttributeList &attrs, llvm::AttributeList &attrs,
unsigned paramIndex, bool allowSRet) { unsigned paramIndex, bool allowSRet) {
static const llvm::Attribute::AttrKind attrKindsWithSRet[] = { llvm::AttrBuilder b;
llvm::Attribute::StructRet, b.addAttribute(llvm::Attribute::NoAlias);
llvm::Attribute::NoAlias, b.addAttribute(llvm::Attribute::NoCapture);
llvm::Attribute::NoCapture, if (allowSRet)
}; b.addAttribute(llvm::Attribute::StructRet);
static const llvm::Attribute::AttrKind attrKindsWithoutSRet[] = { attrs = attrs.addAttributes(IGM.LLVMContext, paramIndex + 1, b);
llvm::Attribute::NoAlias,
llvm::Attribute::NoCapture,
};
auto resultAttrs = llvm::AttributeList::get(
IGM.LLVMContext, paramIndex + 1,
(allowSRet ? makeArrayRef(attrKindsWithSRet)
: makeArrayRef(attrKindsWithoutSRet)));
attrs = attrs.addAttributes(IGM.LLVMContext, paramIndex + 1, resultAttrs);
} }
void IRGenModule::addSwiftSelfAttributes(llvm::AttributeList &attrs, void IRGenModule::addSwiftSelfAttributes(llvm::AttributeList &attrs,
unsigned argIndex) { unsigned argIndex) {
if (!UseSwiftCC) if (!UseSwiftCC)
return; return;
static const llvm::Attribute::AttrKind attrKinds[] = { llvm::AttrBuilder b;
llvm::Attribute::SwiftSelf, b.addAttribute(llvm::Attribute::SwiftSelf);
}; attrs = attrs.addAttributes(this->LLVMContext, argIndex + 1, b);
auto argAttrs =
llvm::AttributeList::get(this->LLVMContext, argIndex + 1, attrKinds);
attrs = attrs.addAttributes(this->LLVMContext, argIndex + 1, argAttrs);
} }
void IRGenModule::addSwiftErrorAttributes(llvm::AttributeList &attrs, void IRGenModule::addSwiftErrorAttributes(llvm::AttributeList &attrs,
@@ -171,12 +158,9 @@ void IRGenModule::addSwiftErrorAttributes(llvm::AttributeList &attrs,
if (!UseSwiftCC || !this->IsSwiftErrorInRegister) if (!UseSwiftCC || !this->IsSwiftErrorInRegister)
return; return;
static const llvm::Attribute::AttrKind attrKinds[] = { llvm::AttrBuilder b;
llvm::Attribute::SwiftError, b.addAttribute(llvm::Attribute::SwiftError);
}; attrs = attrs.addAttributes(this->LLVMContext, argIndex + 1, b);
auto argAttrs =
llvm::AttributeList::get(this->LLVMContext, argIndex + 1, attrKinds);
attrs = attrs.addAttributes(this->LLVMContext, argIndex + 1, argAttrs);
} }
void irgen::addByvalArgumentAttributes(IRGenModule &IGM, void irgen::addByvalArgumentAttributes(IRGenModule &IGM,
@@ -186,10 +170,7 @@ void irgen::addByvalArgumentAttributes(IRGenModule &IGM,
b.addAttribute(llvm::Attribute::ByVal); b.addAttribute(llvm::Attribute::ByVal);
b.addAttribute(llvm::Attribute::getWithAlignment(IGM.LLVMContext, b.addAttribute(llvm::Attribute::getWithAlignment(IGM.LLVMContext,
align.getValue())); align.getValue()));
auto resultAttrs = llvm::AttributeList::get(IGM.LLVMContext, argIndex + 1, b); attrs = attrs.addAttributes(IGM.LLVMContext, argIndex+1, b);
attrs = attrs.addAttributes(IGM.LLVMContext,
argIndex+1,
resultAttrs);
} }
void irgen::addExtendAttribute(IRGenModule &IGM, llvm::AttributeList &attrs, void irgen::addExtendAttribute(IRGenModule &IGM, llvm::AttributeList &attrs,
@@ -199,8 +180,7 @@ void irgen::addExtendAttribute(IRGenModule &IGM, llvm::AttributeList &attrs,
b.addAttribute(llvm::Attribute::SExt); b.addAttribute(llvm::Attribute::SExt);
else else
b.addAttribute(llvm::Attribute::ZExt); b.addAttribute(llvm::Attribute::ZExt);
auto resultAttrs = llvm::AttributeList::get(IGM.LLVMContext, index, b); attrs = attrs.addAttributes(IGM.LLVMContext, index, b);
attrs = attrs.addAttributes(IGM.LLVMContext, index, resultAttrs);
} }
namespace { namespace {

View File

@@ -1514,12 +1514,12 @@ llvm::Function *swift::irgen::createFunction(IRGenModule &IGM,
IGM.Module.getFunctionList().push_back(fn); IGM.Module.getFunctionList().push_back(fn);
} }
auto initialAttrs = IGM.constructInitialAttributes(); if (!attrs.isEmpty())
// Merge initialAttrs with attrs. fn->setAttributes(attrs);
auto updatedAttrs = attrs.addAttributes( // Merge initial attributes with attrs.
IGM.getLLVMContext(), llvm::AttributeList::FunctionIndex, initialAttrs); llvm::AttrBuilder b;
if (!updatedAttrs.isEmpty()) IGM.constructInitialFnAttributes(b);
fn->setAttributes(updatedAttrs); fn->addAttributes(llvm::AttributeList::FunctionIndex, b);
// Everything externally visible is considered used in Swift. // Everything externally visible is considered used in Swift.
// That mostly means we need to be good at not marking things external. // That mostly means we need to be good at not marking things external.

View File

@@ -728,11 +728,11 @@ static llvm::Function *emitPartialApplicationForwarder(
fwd->setCallingConv( fwd->setCallingConv(
expandCallingConv(IGM, SILFunctionTypeRepresentation::Thick)); expandCallingConv(IGM, SILFunctionTypeRepresentation::Thick));
auto initialAttrs = IGM.constructInitialAttributes(); fwd->setAttributes(outAttrs);
// Merge initialAttrs with outAttrs. // Merge initial attributes with outAttrs.
auto updatedAttrs = outAttrs.addAttributes( llvm::AttrBuilder b;
IGM.getLLVMContext(), llvm::AttributeList::FunctionIndex, initialAttrs); IGM.constructInitialFnAttributes(b);
fwd->setAttributes(updatedAttrs); fwd->addAttributes(llvm::AttributeList::FunctionIndex, b);
IRGenFunction subIGF(IGM, fwd); IRGenFunction subIGF(IGM, fwd);
if (IGM.DebugInfo) if (IGM.DebugInfo)

View File

@@ -774,11 +774,11 @@ static llvm::Function *emitObjCPartialApplicationForwarder(IRGenModule &IGM,
fwd->setCallingConv( fwd->setCallingConv(
expandCallingConv(IGM, SILFunctionTypeRepresentation::Thick)); expandCallingConv(IGM, SILFunctionTypeRepresentation::Thick));
auto initialAttrs = IGM.constructInitialAttributes(); fwd->setAttributes(attrs);
// Merge initialAttrs with attrs. // Merge initial attributes with attrs.
auto updatedAttrs = attrs.addAttributes( llvm::AttrBuilder b;
IGM.getLLVMContext(), llvm::AttributeList::FunctionIndex, initialAttrs); IGM.constructInitialFnAttributes(b);
fwd->setAttributes(updatedAttrs); fwd->addAttributes(llvm::AttributeList::FunctionIndex, b);
IRGenFunction subIGF(IGM, fwd); IRGenFunction subIGF(IGM, fwd);
if (IGM.DebugInfo) if (IGM.DebugInfo)

View File

@@ -461,16 +461,8 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
} }
// FIXME: getting attributes here without setting them does // FIXME: getting attributes here without setting them does
// nothing. This cannot be fixed until the attributes are correctly specified. // nothing. This cannot be fixed until the attributes are correctly specified.
fn->getAttributes().addAttributes( fn->addAttributes(llvm::AttributeList::FunctionIndex, buildFnAttr);
Module.getContext(), llvm::AttributeList::FunctionIndex, fn->addAttributes(llvm::AttributeList::ReturnIndex, buildRetAttr);
llvm::AttributeList::get(Module.getContext(),
llvm::AttributeList::FunctionIndex,
buildFnAttr));
fn->getAttributes().addAttributes(
Module.getContext(), llvm::AttributeList::ReturnIndex,
llvm::AttributeList::get(Module.getContext(),
llvm::AttributeList::ReturnIndex,
buildRetAttr));
} }
return cache; return cache;
@@ -759,21 +751,14 @@ llvm::AttributeList IRGenModule::getAllocAttrs() {
return AllocAttrs; return AllocAttrs;
} }
/// Construct initial attributes from options. /// Construct initial function attributes from options.
llvm::AttributeList IRGenModule::constructInitialAttributes() { void IRGenModule::constructInitialFnAttributes(llvm::AttrBuilder &Attrs) {
llvm::AttributeList attrsUpdated;
// Add DisableFPElim. // Add DisableFPElim.
if (!IRGen.Opts.DisableFPElim) { if (!IRGen.Opts.DisableFPElim) {
attrsUpdated = attrsUpdated.addAttribute(LLVMContext, Attrs.addAttribute("no-frame-pointer-elim", "false");
llvm::AttributeList::FunctionIndex,
"no-frame-pointer-elim", "false");
} else { } else {
attrsUpdated = attrsUpdated.addAttribute( Attrs.addAttribute("no-frame-pointer-elim", "true");
LLVMContext, llvm::AttributeList::FunctionIndex, Attrs.addAttribute("no-frame-pointer-elim-non-leaf");
"no-frame-pointer-elim", "true");
attrsUpdated = attrsUpdated.addAttribute(
LLVMContext, llvm::AttributeList::FunctionIndex,
"no-frame-pointer-elim-non-leaf");
} }
// Add target-cpu and target-features if they are non-null. // Add target-cpu and target-features if they are non-null.
@@ -782,8 +767,7 @@ llvm::AttributeList IRGenModule::constructInitialAttributes() {
std::string &CPU = ClangOpts.CPU; std::string &CPU = ClangOpts.CPU;
if (CPU != "") if (CPU != "")
attrsUpdated = attrsUpdated.addAttribute( Attrs.addAttribute("target-cpu", CPU);
LLVMContext, llvm::AttributeList::FunctionIndex, "target-cpu", CPU);
std::vector<std::string> &Features = ClangOpts.Features; std::vector<std::string> &Features = ClangOpts.Features;
if (!Features.empty()) { if (!Features.empty()) {
@@ -793,11 +777,15 @@ llvm::AttributeList IRGenModule::constructInitialAttributes() {
}, [&]{ }, [&]{
allFeatures.push_back(','); allFeatures.push_back(',');
}); });
attrsUpdated = attrsUpdated.addAttribute(LLVMContext, Attrs.addAttribute("target-features", allFeatures);
llvm::AttributeList::FunctionIndex, "target-features",
allFeatures);
} }
return attrsUpdated; }
llvm::AttributeList IRGenModule::constructInitialAttributes() {
llvm::AttrBuilder b;
constructInitialFnAttributes(b);
return llvm::AttributeList::get(LLVMContext,
llvm::AttributeList::FunctionIndex, b);
} }
llvm::Constant *IRGenModule::getSize(Size size) { llvm::Constant *IRGenModule::getSize(Size size) {

View File

@@ -902,6 +902,7 @@ public:
/// invalid. /// invalid.
bool finalize(); bool finalize();
void constructInitialFnAttributes(llvm::AttrBuilder &Attrs);
llvm::AttributeList constructInitialAttributes(); llvm::AttributeList constructInitialAttributes();
void emitProtocolDecl(ProtocolDecl *D); void emitProtocolDecl(ProtocolDecl *D);