From: Aaron Ballman Date: Thu, 19 Dec 2013 03:09:10 +0000 (+0000) Subject: Switched code from using hasAttr followed by getAttr to simply call getAttr directly... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e5e1f3542355ee4fe00de867ddea7d15f872bb1d;p=clang Switched code from using hasAttr followed by getAttr to simply call getAttr directly and check the resulting value. No functional changes intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197652 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 46e2edd916..cebd6a7df1 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -404,8 +404,8 @@ static void GenOpenCLArgMetadata(const FunctionDecl *FD, llvm::Function *Fn, // Get image access qualifier: if (ty->isImageType()) { - if (parm->hasAttr() && - parm->getAttr()->getAccess() == CLIA_write_only) + const OpenCLImageAccessAttr *A = parm->getAttr(); + if (A && A->getAccess() == CLIA_write_only) accessQuals.push_back(llvm::MDString::get(Context, "write_only")); else accessQuals.push_back(llvm::MDString::get(Context, "read_only")); @@ -438,16 +438,15 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, GenOpenCLArgMetadata(FD, Fn, CGM, Context, kernelMDArgs, Builder, getContext()); - if (FD->hasAttr()) { - VecTypeHintAttr *attr = FD->getAttr(); - QualType hintQTy = attr->getTypeHint(); + if (const VecTypeHintAttr *A = FD->getAttr()) { + QualType hintQTy = A->getTypeHint(); const ExtVectorType *hintEltQTy = hintQTy->getAs(); bool isSignedInteger = hintQTy->isSignedIntegerType() || (hintEltQTy && hintEltQTy->getElementType()->isSignedIntegerType()); llvm::Value *attrMDArgs[] = { llvm::MDString::get(Context, "vec_type_hint"), - llvm::UndefValue::get(CGM.getTypes().ConvertType(attr->getTypeHint())), + llvm::UndefValue::get(CGM.getTypes().ConvertType(A->getTypeHint())), llvm::ConstantInt::get( llvm::IntegerType::get(Context, 32), llvm::APInt(32, (uint64_t)(isSignedInteger ? 1 : 0))) @@ -455,24 +454,22 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, kernelMDArgs.push_back(llvm::MDNode::get(Context, attrMDArgs)); } - if (FD->hasAttr()) { - WorkGroupSizeHintAttr *attr = FD->getAttr(); + if (const WorkGroupSizeHintAttr *A = FD->getAttr()) { llvm::Value *attrMDArgs[] = { llvm::MDString::get(Context, "work_group_size_hint"), - Builder.getInt32(attr->getXDim()), - Builder.getInt32(attr->getYDim()), - Builder.getInt32(attr->getZDim()) + Builder.getInt32(A->getXDim()), + Builder.getInt32(A->getYDim()), + Builder.getInt32(A->getZDim()) }; kernelMDArgs.push_back(llvm::MDNode::get(Context, attrMDArgs)); } - if (FD->hasAttr()) { - ReqdWorkGroupSizeAttr *attr = FD->getAttr(); + if (const ReqdWorkGroupSizeAttr *A = FD->getAttr()) { llvm::Value *attrMDArgs[] = { llvm::MDString::get(Context, "reqd_work_group_size"), - Builder.getInt32(attr->getXDim()), - Builder.getInt32(attr->getYDim()), - Builder.getInt32(attr->getZDim()) + Builder.getInt32(A->getXDim()), + Builder.getInt32(A->getYDim()), + Builder.getInt32(A->getZDim()) }; kernelMDArgs.push_back(llvm::MDNode::get(Context, attrMDArgs)); } diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index e72abb10a4..718998b7ab 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -409,8 +409,7 @@ void CodeGenModule::setTLSMode(llvm::GlobalVariable *GV, TLM = GetLLVMTLSModel(CodeGenOpts.getDefaultTLSModel()); // Override the TLS model if it is explicitly specified. - if (D.hasAttr()) { - const TLSModelAttr *Attr = D.getAttr(); + if (const TLSModelAttr *Attr = D.getAttr()) { TLM = GetLLVMTLSModel(Attr->getModel()); }