]> granicus.if.org Git - clang/commitdiff
[OPENMP50]Register vendor name only once in vendor context selector.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 10 Oct 2019 15:15:26 +0000 (15:15 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 10 Oct 2019 15:15:26 +0000 (15:15 +0000)
No need to store multiple copies of the same vendor names in the context
selector, keep only single copy.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374363 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseOpenMP.cpp
test/OpenMP/declare_variant_ast_print.c
test/OpenMP/declare_variant_ast_print.cpp

index 82a4e700552e1eb0ecc0e791211e03239d80f978..760cec258fd8584fae29c52a522a41ddc92d2cc0 100644 (file)
@@ -17,6 +17,7 @@
 #include "clang/Parse/RAIIObjectsForParser.h"
 #include "clang/Sema/Scope.h"
 #include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/UniqueVector.h"
 
 using namespace clang;
 
@@ -853,7 +854,7 @@ static void parseImplementationSelector(
     (void)T.expectAndConsume(diag::err_expected_lparen_after,
                              CtxSelectorName.data());
     const ExprResult Score = parseContextScore(P);
-    SmallVector<llvm::SmallString<16>, 4> Vendors;
+    llvm::UniqueVector<llvm::SmallString<16>> Vendors;
     do {
       // Parse <vendor>.
       StringRef VendorName;
@@ -862,7 +863,7 @@ static void parseImplementationSelector(
         VendorName = P.getPreprocessor().getSpelling(P.getCurToken(), Buffer);
         (void)P.ConsumeToken();
         if (!VendorName.empty())
-          Vendors.push_back(VendorName);
+          Vendors.insert(VendorName);
       } else {
         P.Diag(Tok.getLocation(), diag::err_omp_declare_variant_item_expected)
             << "vendor identifier"
@@ -878,10 +879,10 @@ static void parseImplementationSelector(
     (void)T.consumeClose();
     if (!Vendors.empty()) {
       SmallVector<StringRef, 4> ImplVendors(Vendors.size());
-      for (int I = 0, E = Vendors.size(); I < E; ++I)
-        ImplVendors[I] = Vendors[I];
+      llvm::copy(Vendors, ImplVendors.begin());
       Sema::OpenMPDeclareVariantCtsSelectorData Data(
-          OMPDeclareVariantAttr::CtxSetImplementation, CSKind, ImplVendors,
+          OMPDeclareVariantAttr::CtxSetImplementation, CSKind,
+          llvm::makeMutableArrayRef(ImplVendors.begin(), ImplVendors.size()),
           Score);
       Callback(SourceRange(Loc, Tok.getLocation()), Data);
     }
index a8a11bc53d3d5b598b91f68264d242d49c440c8d..971211c1e944402bdc1281f28a14d0d77dd23790 100644 (file)
@@ -11,7 +11,7 @@ int foo(void);
 #pragma omp declare variant(foo) match(implementation={vendor(llvm)})
 #pragma omp declare variant(foo) match(implementation={vendor(llvm), xxx})
 #pragma omp declare variant(foo) match(implementation={vendor(unknown)})
-#pragma omp declare variant(foo) match(implementation={vendor(score(5): ibm, xxx)})
+#pragma omp declare variant(foo) match(implementation={vendor(score(5): ibm, xxx, ibm)})
 int bar(void);
 
 // CHECK:      int foo();
index ce67b818f30cd43fab09d4c2127a80b657079018..a026febfb523e197b95b7cd7924e529336aeaf6a 100644 (file)
@@ -40,7 +40,7 @@ int bar();
 #pragma omp declare variant(foofoo <T>) match(user = {condition(<expr>)})
 #pragma omp declare variant(foofoo <T>) match(implementation={vendor(llvm)})
 #pragma omp declare variant(foofoo <T>) match(implementation={vendor(unknown)})
-#pragma omp declare variant(foofoo <T>) match(implementation={vendor(score(C+5): ibm, xxx)})
+#pragma omp declare variant(foofoo <T>) match(implementation={vendor(score(C+5): ibm, xxx, ibm)})
 template <typename T, int C>
 T barbar();