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

View File

@@ -1514,12 +1514,12 @@ llvm::Function *swift::irgen::createFunction(IRGenModule &IGM,
IGM.Module.getFunctionList().push_back(fn);
}
auto initialAttrs = IGM.constructInitialAttributes();
// Merge initialAttrs with attrs.
auto updatedAttrs = attrs.addAttributes(
IGM.getLLVMContext(), llvm::AttributeList::FunctionIndex, initialAttrs);
if (!updatedAttrs.isEmpty())
fn->setAttributes(updatedAttrs);
if (!attrs.isEmpty())
fn->setAttributes(attrs);
// Merge initial attributes with attrs.
llvm::AttrBuilder b;
IGM.constructInitialFnAttributes(b);
fn->addAttributes(llvm::AttributeList::FunctionIndex, b);
// Everything externally visible is considered used in Swift.
// 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(
expandCallingConv(IGM, SILFunctionTypeRepresentation::Thick));
auto initialAttrs = IGM.constructInitialAttributes();
// Merge initialAttrs with outAttrs.
auto updatedAttrs = outAttrs.addAttributes(
IGM.getLLVMContext(), llvm::AttributeList::FunctionIndex, initialAttrs);
fwd->setAttributes(updatedAttrs);
fwd->setAttributes(outAttrs);
// Merge initial attributes with outAttrs.
llvm::AttrBuilder b;
IGM.constructInitialFnAttributes(b);
fwd->addAttributes(llvm::AttributeList::FunctionIndex, b);
IRGenFunction subIGF(IGM, fwd);
if (IGM.DebugInfo)

View File

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

View File

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

View File

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