diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2013-12-02 22:38:33 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2013-12-02 22:38:33 +0000 |
commit | 1d0d2a48e794dbf321a646559e7d5119a6849e5e (patch) | |
tree | 4a977312762152487667396f294bc084a8260e0e /clang/lib/Sema/SemaDeclAttr.cpp | |
parent | d7b00cac1050c649c66334899ae7fdf9bedc1951 (diff) | |
download | bcm5719-llvm-1d0d2a48e794dbf321a646559e7d5119a6849e5e.tar.gz bcm5719-llvm-1d0d2a48e794dbf321a646559e7d5119a6849e5e.zip |
Refactored the work group-related attributes to use a template, which reduces the amount of duplicate code in the handler. No functional change intended.
llvm-svn: 196165
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 43 |
1 files changed, 10 insertions, 33 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 60bc7b79ada..24f9f5fd252 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2277,6 +2277,7 @@ static void handleWeakImportAttr(Sema &S, Decl *D, const AttributeList &Attr) { } // Handles reqd_work_group_size and work_group_size_hint. +template <typename WorkGroupAttr> static void handleWorkGroupSize(Sema &S, Decl *D, const AttributeList &Attr) { uint32_t WGSize[3]; @@ -2284,37 +2285,14 @@ static void handleWorkGroupSize(Sema &S, Decl *D, if (!checkUInt32Argument(S, Attr, Attr.getArgAsExpr(i), WGSize[i], i)) return; - if (Attr.getKind() == AttributeList::AT_ReqdWorkGroupSize - && D->hasAttr<ReqdWorkGroupSizeAttr>()) { - ReqdWorkGroupSizeAttr *A = D->getAttr<ReqdWorkGroupSizeAttr>(); - if (!(A->getXDim() == WGSize[0] && - A->getYDim() == WGSize[1] && - A->getZDim() == WGSize[2])) { - S.Diag(Attr.getLoc(), diag::warn_duplicate_attribute) << - Attr.getName(); - } - } - - if (Attr.getKind() == AttributeList::AT_WorkGroupSizeHint - && D->hasAttr<WorkGroupSizeHintAttr>()) { - WorkGroupSizeHintAttr *A = D->getAttr<WorkGroupSizeHintAttr>(); - if (!(A->getXDim() == WGSize[0] && - A->getYDim() == WGSize[1] && - A->getZDim() == WGSize[2])) { - S.Diag(Attr.getLoc(), diag::warn_duplicate_attribute) << - Attr.getName(); - } - } + WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>(); + if (Existing && !(Existing->getXDim() == WGSize[0] && + Existing->getYDim() == WGSize[1] && + Existing->getZDim() == WGSize[2])) + S.Diag(Attr.getLoc(), diag::warn_duplicate_attribute) << Attr.getName(); - if (Attr.getKind() == AttributeList::AT_ReqdWorkGroupSize) - D->addAttr(::new (S.Context) - ReqdWorkGroupSizeAttr(Attr.getRange(), S.Context, - WGSize[0], WGSize[1], WGSize[2], - Attr.getAttributeSpellingListIndex())); - else - D->addAttr(::new (S.Context) - WorkGroupSizeHintAttr(Attr.getRange(), S.Context, - WGSize[0], WGSize[1], WGSize[2], + D->addAttr(::new (S.Context) WorkGroupAttr(Attr.getRange(), S.Context, + WGSize[0], WGSize[1], WGSize[2], Attr.getAttributeSpellingListIndex())); } @@ -4002,11 +3980,10 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, case AttributeList::AT_NSReturnsRetained: case AttributeList::AT_CFReturnsRetained: handleNSReturnsRetainedAttr(S, D, Attr); break; - case AttributeList::AT_WorkGroupSizeHint: + handleWorkGroupSize<WorkGroupSizeHintAttr>(S, D, Attr); break; case AttributeList::AT_ReqdWorkGroupSize: - handleWorkGroupSize(S, D, Attr); break; - + handleWorkGroupSize<ReqdWorkGroupSizeAttr>(S, D, Attr); break; case AttributeList::AT_VecTypeHint: handleVecTypeHint(S, D, Attr); break; |