From 2e1373febc5dcfe5215d03f5c060dd3893919fa9 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Mon, 2 Dec 2013 22:38:33 +0000 Subject: [PATCH] Refactored the work group-related attributes to use a template, which reduces the amount of duplicate code in the handler. No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196165 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclAttr.cpp | 43 +++++++++------------------------------ 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 60bc7b79ad..24f9f5fd25 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/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 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 *A = D->getAttr(); - 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 *A = D->getAttr(); - 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(); + 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(S, D, Attr); break; case AttributeList::AT_ReqdWorkGroupSize: - handleWorkGroupSize(S, D, Attr); break; - + handleWorkGroupSize(S, D, Attr); break; case AttributeList::AT_VecTypeHint: handleVecTypeHint(S, D, Attr); break; -- 2.40.0