Remove the final bits of Attributes being declared in the Attribute

namespace. Use the attribute's enum value instead. No functionality change
intended.

llvm-svn: 165611
This commit is contained in:
Bill Wendling 2012-10-10 07:36:56 +00:00
parent bbcdf4e2a5
commit a7912f8894
6 changed files with 82 additions and 58 deletions

View File

@ -924,50 +924,50 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
const Decl *TargetDecl, const Decl *TargetDecl,
AttributeListType &PAL, AttributeListType &PAL,
unsigned &CallingConv) { unsigned &CallingConv) {
llvm::Attributes FuncAttrs; llvm::Attributes::Builder FuncAttrs;
llvm::Attributes RetAttrs; llvm::Attributes::Builder RetAttrs;
CallingConv = FI.getEffectiveCallingConvention(); CallingConv = FI.getEffectiveCallingConvention();
if (FI.isNoReturn()) if (FI.isNoReturn())
FuncAttrs |= llvm::Attribute::NoReturn; FuncAttrs.addAttribute(llvm::Attributes::NoReturn);
// FIXME: handle sseregparm someday... // FIXME: handle sseregparm someday...
if (TargetDecl) { if (TargetDecl) {
if (TargetDecl->hasAttr<ReturnsTwiceAttr>()) if (TargetDecl->hasAttr<ReturnsTwiceAttr>())
FuncAttrs |= llvm::Attribute::ReturnsTwice; FuncAttrs.addAttribute(llvm::Attributes::ReturnsTwice);
if (TargetDecl->hasAttr<NoThrowAttr>()) if (TargetDecl->hasAttr<NoThrowAttr>())
FuncAttrs |= llvm::Attribute::NoUnwind; FuncAttrs.addAttribute(llvm::Attributes::NoUnwind);
else if (const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) { else if (const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
const FunctionProtoType *FPT = Fn->getType()->getAs<FunctionProtoType>(); const FunctionProtoType *FPT = Fn->getType()->getAs<FunctionProtoType>();
if (FPT && FPT->isNothrow(getContext())) if (FPT && FPT->isNothrow(getContext()))
FuncAttrs |= llvm::Attribute::NoUnwind; FuncAttrs.addAttribute(llvm::Attributes::NoUnwind);
} }
if (TargetDecl->hasAttr<NoReturnAttr>()) if (TargetDecl->hasAttr<NoReturnAttr>())
FuncAttrs |= llvm::Attribute::NoReturn; FuncAttrs.addAttribute(llvm::Attributes::NoReturn);
if (TargetDecl->hasAttr<ReturnsTwiceAttr>()) if (TargetDecl->hasAttr<ReturnsTwiceAttr>())
FuncAttrs |= llvm::Attribute::ReturnsTwice; FuncAttrs.addAttribute(llvm::Attributes::ReturnsTwice);
// 'const' and 'pure' attribute functions are also nounwind. // 'const' and 'pure' attribute functions are also nounwind.
if (TargetDecl->hasAttr<ConstAttr>()) { if (TargetDecl->hasAttr<ConstAttr>()) {
FuncAttrs |= llvm::Attribute::ReadNone; FuncAttrs.addAttribute(llvm::Attributes::ReadNone);
FuncAttrs |= llvm::Attribute::NoUnwind; FuncAttrs.addAttribute(llvm::Attributes::NoUnwind);
} else if (TargetDecl->hasAttr<PureAttr>()) { } else if (TargetDecl->hasAttr<PureAttr>()) {
FuncAttrs |= llvm::Attribute::ReadOnly; FuncAttrs.addAttribute(llvm::Attributes::ReadOnly);
FuncAttrs |= llvm::Attribute::NoUnwind; FuncAttrs.addAttribute(llvm::Attributes::NoUnwind);
} }
if (TargetDecl->hasAttr<MallocAttr>()) if (TargetDecl->hasAttr<MallocAttr>())
RetAttrs |= llvm::Attribute::NoAlias; RetAttrs.addAttribute(llvm::Attributes::NoAlias);
} }
if (CodeGenOpts.OptimizeSize) if (CodeGenOpts.OptimizeSize)
FuncAttrs |= llvm::Attribute::OptimizeForSize; FuncAttrs.addAttribute(llvm::Attributes::OptimizeForSize);
if (CodeGenOpts.DisableRedZone) if (CodeGenOpts.DisableRedZone)
FuncAttrs |= llvm::Attribute::NoRedZone; FuncAttrs.addAttribute(llvm::Attributes::NoRedZone);
if (CodeGenOpts.NoImplicitFloat) if (CodeGenOpts.NoImplicitFloat)
FuncAttrs |= llvm::Attribute::NoImplicitFloat; FuncAttrs.addAttribute(llvm::Attributes::NoImplicitFloat);
QualType RetTy = FI.getReturnType(); QualType RetTy = FI.getReturnType();
unsigned Index = 1; unsigned Index = 1;
@ -975,24 +975,27 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
switch (RetAI.getKind()) { switch (RetAI.getKind()) {
case ABIArgInfo::Extend: case ABIArgInfo::Extend:
if (RetTy->hasSignedIntegerRepresentation()) if (RetTy->hasSignedIntegerRepresentation())
RetAttrs |= llvm::Attribute::SExt; RetAttrs.addAttribute(llvm::Attributes::SExt);
else if (RetTy->hasUnsignedIntegerRepresentation()) else if (RetTy->hasUnsignedIntegerRepresentation())
RetAttrs |= llvm::Attribute::ZExt; RetAttrs.addAttribute(llvm::Attributes::ZExt);
break; break;
case ABIArgInfo::Direct: case ABIArgInfo::Direct:
case ABIArgInfo::Ignore: case ABIArgInfo::Ignore:
break; break;
case ABIArgInfo::Indirect: { case ABIArgInfo::Indirect: {
llvm::Attributes SRETAttrs = llvm::Attribute::StructRet; llvm::Attributes::Builder SRETAttrs;
SRETAttrs.addAttribute(llvm::Attributes::StructRet);
if (RetAI.getInReg()) if (RetAI.getInReg())
SRETAttrs |= llvm::Attribute::InReg; SRETAttrs.addAttribute(llvm::Attributes::InReg);
PAL.push_back(llvm::AttributeWithIndex::get(Index, SRETAttrs)); PAL.push_back(llvm::
AttributeWithIndex::get(Index,
llvm::Attributes::get(SRETAttrs)));
++Index; ++Index;
// sret disables readnone and readonly // sret disables readnone and readonly
FuncAttrs &= ~(llvm::Attribute::ReadOnly | FuncAttrs.removeAttribute(llvm::Attributes::ReadOnly)
llvm::Attribute::ReadNone); .removeAttribute(llvm::Attributes::ReadNone);
break; break;
} }
@ -1000,14 +1003,16 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
llvm_unreachable("Invalid ABI kind for return argument"); llvm_unreachable("Invalid ABI kind for return argument");
} }
if (RetAttrs) if (RetAttrs.hasAttributes())
PAL.push_back(llvm::AttributeWithIndex::get(0, RetAttrs)); PAL.push_back(llvm::
AttributeWithIndex::get(0,
llvm::Attributes::get(RetAttrs)));
for (CGFunctionInfo::const_arg_iterator it = FI.arg_begin(), for (CGFunctionInfo::const_arg_iterator it = FI.arg_begin(),
ie = FI.arg_end(); it != ie; ++it) { ie = FI.arg_end(); it != ie; ++it) {
QualType ParamType = it->type; QualType ParamType = it->type;
const ABIArgInfo &AI = it->info; const ABIArgInfo &AI = it->info;
llvm::Attributes Attrs; llvm::Attributes::Builder Attrs;
// 'restrict' -> 'noalias' is done in EmitFunctionProlog when we // 'restrict' -> 'noalias' is done in EmitFunctionProlog when we
// have the corresponding parameter variable. It doesn't make // have the corresponding parameter variable. It doesn't make
@ -1015,13 +1020,13 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
switch (AI.getKind()) { switch (AI.getKind()) {
case ABIArgInfo::Extend: case ABIArgInfo::Extend:
if (ParamType->isSignedIntegerOrEnumerationType()) if (ParamType->isSignedIntegerOrEnumerationType())
Attrs |= llvm::Attribute::SExt; Attrs.addAttribute(llvm::Attributes::SExt);
else if (ParamType->isUnsignedIntegerOrEnumerationType()) else if (ParamType->isUnsignedIntegerOrEnumerationType())
Attrs |= llvm::Attribute::ZExt; Attrs.addAttribute(llvm::Attributes::ZExt);
// FALL THROUGH // FALL THROUGH
case ABIArgInfo::Direct: case ABIArgInfo::Direct:
if (AI.getInReg()) if (AI.getInReg())
Attrs |= llvm::Attribute::InReg; Attrs.addAttribute(llvm::Attributes::InReg);
// FIXME: handle sseregparm someday... // FIXME: handle sseregparm someday...
@ -1031,22 +1036,23 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
if (llvm::StructType *STy = if (llvm::StructType *STy =
dyn_cast<llvm::StructType>(AI.getCoerceToType())) { dyn_cast<llvm::StructType>(AI.getCoerceToType())) {
unsigned Extra = STy->getNumElements()-1; // 1 will be added below. unsigned Extra = STy->getNumElements()-1; // 1 will be added below.
if (Attrs != llvm::Attribute::None) if (Attrs.hasAttributes())
for (unsigned I = 0; I < Extra; ++I) for (unsigned I = 0; I < Extra; ++I)
PAL.push_back(llvm::AttributeWithIndex::get(Index + I, Attrs)); PAL.push_back(llvm::AttributeWithIndex::get(Index + I,
llvm::Attributes::get(Attrs)));
Index += Extra; Index += Extra;
} }
break; break;
case ABIArgInfo::Indirect: case ABIArgInfo::Indirect:
if (AI.getIndirectByVal()) if (AI.getIndirectByVal())
Attrs |= llvm::Attribute::ByVal; Attrs.addAttribute(llvm::Attributes::ByVal);
Attrs.addAlignmentAttr(AI.getIndirectAlign());
Attrs |=
llvm::Attributes::constructAlignmentFromInt(AI.getIndirectAlign());
// byval disables readnone and readonly. // byval disables readnone and readonly.
FuncAttrs &= ~(llvm::Attribute::ReadOnly | FuncAttrs.removeAttribute(llvm::Attributes::ReadOnly)
llvm::Attribute::ReadNone); .removeAttribute(llvm::Attributes::ReadNone);
break; break;
case ABIArgInfo::Ignore: case ABIArgInfo::Ignore:
@ -1064,12 +1070,14 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
} }
} }
if (Attrs) if (Attrs.hasAttributes())
PAL.push_back(llvm::AttributeWithIndex::get(Index, Attrs)); PAL.push_back(llvm::AttributeWithIndex::get(Index,
llvm::Attributes::get(Attrs)));
++Index; ++Index;
} }
if (FuncAttrs) if (FuncAttrs.hasAttributes())
PAL.push_back(llvm::AttributeWithIndex::get(~0, FuncAttrs)); PAL.push_back(llvm::AttributeWithIndex::get(~0,
llvm::Attributes::get(FuncAttrs)));
} }
/// An argument came in as a promoted argument; demote it back to its /// An argument came in as a promoted argument; demote it back to its
@ -1117,7 +1125,9 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
// Name the struct return argument. // Name the struct return argument.
if (CGM.ReturnTypeUsesSRet(FI)) { if (CGM.ReturnTypeUsesSRet(FI)) {
AI->setName("agg.result"); AI->setName("agg.result");
AI->addAttr(llvm::Attribute::NoAlias); llvm::Attributes::Builder B;
B.addAttribute(llvm::Attributes::NoAlias);
AI->addAttr(llvm::Attributes::get(B));
++AI; ++AI;
} }
@ -1186,8 +1196,11 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
assert(AI != Fn->arg_end() && "Argument mismatch!"); assert(AI != Fn->arg_end() && "Argument mismatch!");
llvm::Value *V = AI; llvm::Value *V = AI;
if (Arg->getType().isRestrictQualified()) if (Arg->getType().isRestrictQualified()) {
AI->addAttr(llvm::Attribute::NoAlias); llvm::Attributes::Builder B;
B.addAttribute(llvm::Attributes::NoAlias);
AI->addAttr(llvm::Attributes::get(B));
}
// Ensure the argument is the correct type. // Ensure the argument is the correct type.
if (V->getType() != ArgI.getCoerceToType()) if (V->getType() != ArgI.getCoerceToType())
@ -2127,7 +2140,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
llvm::AttrListPtr Attrs = llvm::AttrListPtr::get(AttributeList); llvm::AttrListPtr Attrs = llvm::AttrListPtr::get(AttributeList);
llvm::BasicBlock *InvokeDest = 0; llvm::BasicBlock *InvokeDest = 0;
if (!(Attrs.getFnAttributes() & llvm::Attribute::NoUnwind)) if (!Attrs.getFnAttributes().hasAttribute(llvm::Attributes::NoUnwind))
InvokeDest = getInvokeDest(); InvokeDest = getInvokeDest();
llvm::CallSite CS; llvm::CallSite CS;

View File

@ -2079,11 +2079,13 @@ void CodeGenFunction::EmitCheck(llvm::Value *Checked, StringRef CheckName,
llvm::FunctionType *FnType = llvm::FunctionType *FnType =
llvm::FunctionType::get(CGM.VoidTy, ArgTypes, false); llvm::FunctionType::get(CGM.VoidTy, ArgTypes, false);
llvm::Attributes::Builder B;
B.addAttribute(llvm::Attributes::NoReturn)
.addAttribute(llvm::Attributes::NoUnwind)
.addAttribute(llvm::Attributes::UWTable);
llvm::Value *Fn = CGM.CreateRuntimeFunction(FnType, llvm::Value *Fn = CGM.CreateRuntimeFunction(FnType,
("__ubsan_handle_" + CheckName).str(), ("__ubsan_handle_" + CheckName).str(),
llvm::Attribute::NoReturn | llvm::Attributes::get(B));
llvm::Attribute::NoUnwind |
llvm::Attribute::UWTable);
llvm::CallInst *HandlerCall = Builder.CreateCall(Fn, Args); llvm::CallInst *HandlerCall = Builder.CreateCall(Fn, Args);
HandlerCall->setDoesNotReturn(); HandlerCall->setDoesNotReturn();
HandlerCall->setDoesNotThrow(); HandlerCall->setDoesNotThrow();

View File

@ -63,10 +63,12 @@ private:
// Add the non-lazy-bind attribute, since objc_msgSend is likely to // Add the non-lazy-bind attribute, since objc_msgSend is likely to
// be called a lot. // be called a lot.
llvm::Type *params[] = { ObjectPtrTy, SelectorPtrTy }; llvm::Type *params[] = { ObjectPtrTy, SelectorPtrTy };
llvm::Attributes::Builder B;
B.addAttribute(llvm::Attributes::NonLazyBind);
return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy,
params, true), params, true),
"objc_msgSend", "objc_msgSend",
llvm::Attribute::NonLazyBind); llvm::Attributes::get(B));
} }
/// void objc_msgSend_stret (id, SEL, ...) /// void objc_msgSend_stret (id, SEL, ...)
@ -580,10 +582,12 @@ public:
llvm::Constant *getSetJmpFn() { llvm::Constant *getSetJmpFn() {
// This is specifically the prototype for x86. // This is specifically the prototype for x86.
llvm::Type *params[] = { CGM.Int32Ty->getPointerTo() }; llvm::Type *params[] = { CGM.Int32Ty->getPointerTo() };
llvm::Attributes::Builder B;
B.addAttribute(llvm::Attributes::NonLazyBind);
return CGM.CreateRuntimeFunction(llvm::FunctionType::get(CGM.Int32Ty, return CGM.CreateRuntimeFunction(llvm::FunctionType::get(CGM.Int32Ty,
params, false), params, false),
"_setjmp", "_setjmp",
llvm::Attribute::ReturnsTwice); llvm::Attributes::get(B));
} }
public: public:

View File

@ -1632,7 +1632,9 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
llvm::InlineAsm::get(FTy, AsmString, Constraints, HasSideEffect, llvm::InlineAsm::get(FTy, AsmString, Constraints, HasSideEffect,
/* IsAlignStack */ false, AsmDialect); /* IsAlignStack */ false, AsmDialect);
llvm::CallInst *Result = Builder.CreateCall(IA, Args); llvm::CallInst *Result = Builder.CreateCall(IA, Args);
Result->addAttribute(~0, llvm::Attribute::NoUnwind); llvm::Attributes::Builder B;
B.addAttribute(llvm::Attributes::NoUnwind);
Result->addAttribute(~0, llvm::Attributes::get(B));
// Slap the source location of the inline asm into a !srcloc metadata on the // Slap the source location of the inline asm into a !srcloc metadata on the
// call. FIXME: Handle metadata for MS-style inline asms. // call. FIXME: Handle metadata for MS-style inline asms.

View File

@ -702,7 +702,7 @@ public:
llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty, llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty,
StringRef Name, StringRef Name,
llvm::Attributes ExtraAttrs = llvm::Attributes ExtraAttrs =
llvm::Attribute::None); llvm::Attributes());
/// CreateRuntimeVariable - Create a new runtime global variable with the /// CreateRuntimeVariable - Create a new runtime global variable with the
/// specified type and name. /// specified type and name.
llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty, llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
@ -881,7 +881,7 @@ private:
GlobalDecl D, GlobalDecl D,
bool ForVTable, bool ForVTable,
llvm::Attributes ExtraAttrs = llvm::Attributes ExtraAttrs =
llvm::Attribute::None); llvm::Attributes());
llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
llvm::PointerType *PTy, llvm::PointerType *PTy,
const VarDecl *D, const VarDecl *D,

View File

@ -950,9 +950,10 @@ static llvm::Constant *getGuardAcquireFn(CodeGenModule &CGM,
llvm::FunctionType *FTy = llvm::FunctionType *FTy =
llvm::FunctionType::get(CGM.getTypes().ConvertType(CGM.getContext().IntTy), llvm::FunctionType::get(CGM.getTypes().ConvertType(CGM.getContext().IntTy),
GuardPtrTy, /*isVarArg=*/false); GuardPtrTy, /*isVarArg=*/false);
llvm::Attributes::Builder B;
B.addAttribute(llvm::Attributes::NoUnwind);
return CGM.CreateRuntimeFunction(FTy, "__cxa_guard_acquire", return CGM.CreateRuntimeFunction(FTy, "__cxa_guard_acquire",
llvm::Attribute::NoUnwind); llvm::Attributes::get(B));
} }
static llvm::Constant *getGuardReleaseFn(CodeGenModule &CGM, static llvm::Constant *getGuardReleaseFn(CodeGenModule &CGM,
@ -960,9 +961,10 @@ static llvm::Constant *getGuardReleaseFn(CodeGenModule &CGM,
// void __cxa_guard_release(__guard *guard_object); // void __cxa_guard_release(__guard *guard_object);
llvm::FunctionType *FTy = llvm::FunctionType *FTy =
llvm::FunctionType::get(CGM.VoidTy, GuardPtrTy, /*isVarArg=*/false); llvm::FunctionType::get(CGM.VoidTy, GuardPtrTy, /*isVarArg=*/false);
llvm::Attributes::Builder B;
B.addAttribute(llvm::Attributes::NoUnwind);
return CGM.CreateRuntimeFunction(FTy, "__cxa_guard_release", return CGM.CreateRuntimeFunction(FTy, "__cxa_guard_release",
llvm::Attribute::NoUnwind); llvm::Attributes::get(B));
} }
static llvm::Constant *getGuardAbortFn(CodeGenModule &CGM, static llvm::Constant *getGuardAbortFn(CodeGenModule &CGM,
@ -970,9 +972,10 @@ static llvm::Constant *getGuardAbortFn(CodeGenModule &CGM,
// void __cxa_guard_abort(__guard *guard_object); // void __cxa_guard_abort(__guard *guard_object);
llvm::FunctionType *FTy = llvm::FunctionType *FTy =
llvm::FunctionType::get(CGM.VoidTy, GuardPtrTy, /*isVarArg=*/false); llvm::FunctionType::get(CGM.VoidTy, GuardPtrTy, /*isVarArg=*/false);
llvm::Attributes::Builder B;
B.addAttribute(llvm::Attributes::NoUnwind);
return CGM.CreateRuntimeFunction(FTy, "__cxa_guard_abort", return CGM.CreateRuntimeFunction(FTy, "__cxa_guard_abort",
llvm::Attribute::NoUnwind); llvm::Attributes::get(B));
} }
namespace { namespace {