[PATCH] D26668: [OpenCL] Minor cleanup to access attributes on images

Joey Gouly via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 15 07:05:39 PST 2016


joey created this revision.
joey added a subscriber: cfe-commits.
joey set the repository for this revision to rL LLVM.
Herald added a subscriber: yaxunl.

Use the semantic spelling (an enum) rather than a string, to determine what access qualifier is used.


Repository:
  rL LLVM

https://reviews.llvm.org/D26668

Files:
  lib/Sema/SemaType.cpp


Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1209,19 +1209,19 @@
   return CreateParsedType(Result, ResultTInfo);
 }
 
-static StringRef getImageAccessAttrStr(AttributeList *attrs) {
+static OpenCLAccessAttr::Spelling getImageAccessAttr(AttributeList *attrs) {
   if (attrs) {
-
     AttributeList *Next;
     do {
       AttributeList &Attr = *attrs;
       Next = Attr.getNext();
       if (Attr.getKind() == AttributeList::AT_OpenCLAccess) {
-        return Attr.getName()->getName();
+        return static_cast<OpenCLAccessAttr::Spelling>(
+            Attr.getSemanticSpelling());
       }
     } while (Next);
   }
-  return "";
+  return OpenCLAccessAttr::Keyword_read_only;
 }
 
 /// \brief Convert the specified declspec to the appropriate type
@@ -1619,11 +1619,15 @@
 
 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
   case DeclSpec::TST_##ImgType##_t: \
-    Result = llvm::StringSwitch<QualType>( \
-                 getImageAccessAttrStr(DS.getAttributes().getList())) \
-                 .Cases("write_only", "__write_only", Context.Id##WOTy) \
-                 .Cases("read_write", "__read_write", Context.Id##RWTy) \
-                 .Default(Context.Id##ROTy); \
+    switch (getImageAccessAttr(DS.getAttributes().getList())) { \
+    case OpenCLAccessAttr::Keyword_write_only: \
+      Result = Context.Id##WOTy; break; \
+    case OpenCLAccessAttr::Keyword_read_write: \
+      Result = Context.Id##RWTy; break; \
+    case OpenCLAccessAttr::Keyword_read_only: \
+      Result = Context.Id##ROTy; break; \
+    default: assert(0 && "Unknown access attribute!"); \
+    } \
     break;
 #include "clang/Basic/OpenCLImageTypes.def"
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26668.77995.patch
Type: text/x-patch
Size: 1759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161115/61e09363/attachment.bin>


More information about the cfe-commits mailing list