[llvm-branch-commits] [llvm] ddd8783 - [OpenMP] Add match_{all, any, none} declare variant selector extensions.

Johannes Doerfert via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Apr 3 23:58:48 PDT 2020


Author: Johannes Doerfert
Date: 2020-04-04T01:56:19-05:00
New Revision: ddd878365b31d31264cb46fdd4e2f0f708ab8548

URL: https://github.com/llvm/llvm-project/commit/ddd878365b31d31264cb46fdd4e2f0f708ab8548
DIFF: https://github.com/llvm/llvm-project/commit/ddd878365b31d31264cb46fdd4e2f0f708ab8548.diff

LOG: [OpenMP] Add match_{all,any,none} declare variant selector extensions.

Summary:
By default, all traits in the OpenMP context selector have to match for
it to be acceptable. Though, we sometimes want a single property out of
multiple to match (=any) or no match at all (=none). We offer these
choices as extensions via
  `implementation={extension(match_{all,any,none})}`
to the user. The choice will affect the entire context selector not only
the traits following the match property.

The first user will be D75788. There we can replace
```
  #pragma omp begin declare variant match(device={arch(nvptx64)})
  #define __CUDA__

  #include <__clang_cuda_cmath.h>

  // TODO: Hack until we support an extension to the match clause that allows "or".
  #undef __CLANG_CUDA_CMATH_H__

  #undef __CUDA__
  #pragma omp end declare variant

  #pragma omp begin declare variant match(device={arch(nvptx)})
  #define __CUDA__

  #include <__clang_cuda_cmath.h>

  #undef __CUDA__
  #pragma omp end declare variant
```
with the much simpler
```
  #pragma omp begin declare variant match(device={arch(nvptx, nvptx64)}, implementation={extension(match_any)})
  #define __CUDA__

  #include <__clang_cuda_cmath.h>

  #undef __CUDA__
  #pragma omp end declare variant
```

Reviewers: mikerice, kiranchandramohan, ABataev, RaviNarayanaswamy, gtbercea, grokos, sdmitriev, JonChesterfield, hfinkel, fghanim, aaron.ballman

Subscribers: yaxunl, hiraditya, bollu, guansong, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77414

Added: 
    clang/test/AST/ast-dump-openmp-declare-variant-extensions-messages.c
    clang/test/AST/ast-dump-openmp-declare-variant-extensions.c

Modified: 
    clang/include/clang/AST/OpenMPClause.h
    clang/include/clang/Basic/AttrDocs.td
    clang/include/clang/Basic/DiagnosticParseKinds.td
    clang/lib/AST/OpenMPClause.cpp
    clang/lib/Parse/ParseOpenMP.cpp
    clang/lib/Sema/SemaOpenMP.cpp
    clang/test/OpenMP/declare_variant_ast_print.c
    clang/test/OpenMP/declare_variant_messages.c
    llvm/include/llvm/Frontend/OpenMP/OMPContext.h
    llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
    llvm/lib/Frontend/OpenMP/OMPContext.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h
index 9f5ff5a85182..f276611e3d0c 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -7229,11 +7229,9 @@ class OMPTraitInfo {
   /// former is a flat representation the actual main 
diff erence is that the
   /// latter uses clang::Expr to store the score/condition while the former is
   /// independent of clang. Thus, expressions and conditions are evaluated in
-  /// this method. If \p DeviceSetOnly is true, only the device selector set, if
-  /// present, is put in \p VMI, otherwise all selector sets are put in \p VMI.
+  /// this method.
   void getAsVariantMatchInfo(ASTContext &ASTCtx,
-                             llvm::omp::VariantMatchInfo &VMI,
-                             bool DeviceSetOnly) const;
+                             llvm::omp::VariantMatchInfo &VMI) const;
 
   /// Return a string representation identifying this context selector.
   std::string getMangledName() const;

diff  --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index fb1c82a80115..9a35bea6e58e 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3394,6 +3394,20 @@ where clause is one of the following:
 and where `variant-func-id` is the name of a function variant that is either a
 base language identifier or, for C++, a template-id.
 
+Clang provides the following context selector extensions, used via `implementation={extension(EXTENSION)}`:
+
+  .. code-block:: none
+
+    match_all
+    match_any
+    match_none
+
+The match extensions change when the *entire* context selector is considered a
+match for an OpenMP context. The default is `all`, with `none` no trait in the
+selector is allowed to be in the OpenMP context, with `any` a single trait in
+both the selector and OpenMP context is sufficient. Only a single match
+extension trait is allowed per context selector.
+
   }];
 }
 

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index f3741531c8b5..a1311d7776c6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1313,6 +1313,8 @@ def warn_omp_ctx_incompatible_score_for_property
 def warn_omp_more_one_device_type_clause
     : Warning<"more than one 'device_type' clause is specified">,
       InGroup<OpenMPClauses>;
+def err_omp_variant_ctx_second_match_extension : Error<
+  "only a single match extension allowed per OpenMP context selector">;
 
 // Pragma loop support.
 def err_pragma_loop_missing_argument : Error<

diff  --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index 0fdbec634103..893656b4c34c 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -1883,11 +1883,8 @@ void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) {
 }
 
 void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx,
-                                         VariantMatchInfo &VMI,
-                                         bool DeviceSetOnly) const {
+                                         VariantMatchInfo &VMI) const {
   for (const OMPTraitSet &Set : Sets) {
-    if (DeviceSetOnly && Set.Kind != TraitSet::device)
-      continue;
     for (const OMPTraitSelector &Selector : Set.Selectors) {
 
       // User conditions are special as we evaluate the condition here.

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 4da1b4146af3..2dd58f71106c 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -935,6 +935,41 @@ void Parser::parseOMPTraitPropertyKind(
       << CONTEXT_TRAIT_LVL << listOpenMPContextTraitProperties(Set, Selector);
 }
 
+static void checkExtensionProperty(Parser &P, SourceLocation Loc,
+                                   OMPTraitInfo::OMPTraitProperty &TIProperty,
+                                   OMPTraitInfo::OMPTraitSelector &TISelector,
+                                   llvm::StringMap<SourceLocation> &Seen) {
+  assert(TISelector.Kind ==
+             llvm::omp::TraitSelector::implementation_extension &&
+         "Only for extension properties, e.g., "
+         "`implementation={extension(PROPERTY)}`");
+
+  if (TIProperty.Kind ==
+          llvm::omp::TraitProperty::implementation_extension_match_all ||
+      TIProperty.Kind ==
+          llvm::omp::TraitProperty::implementation_extension_match_any ||
+      TIProperty.Kind ==
+          llvm::omp::TraitProperty::implementation_extension_match_none) {
+    for (OMPTraitInfo::OMPTraitProperty &SeenProp : TISelector.Properties)
+      if (SeenProp.Kind ==
+              llvm::omp::TraitProperty::implementation_extension_match_all ||
+          SeenProp.Kind ==
+              llvm::omp::TraitProperty::implementation_extension_match_any ||
+          SeenProp.Kind ==
+              llvm::omp::TraitProperty::implementation_extension_match_none) {
+        P.Diag(Loc, diag::err_omp_variant_ctx_second_match_extension);
+        StringRef SeenName =
+            llvm::omp::getOpenMPContextTraitPropertyName(SeenProp.Kind);
+        SourceLocation SeenLoc = Seen[SeenName];
+        P.Diag(SeenLoc, diag::note_omp_declare_variant_ctx_used_here)
+            << CONTEXT_TRAIT_LVL << SeenName;
+      }
+    return;
+  }
+
+  llvm_unreachable("Unknown extension property!");
+}
+
 void Parser::parseOMPContextProperty(OMPTraitSelector &TISelector,
                                      llvm::omp::TraitSet Set,
                                      llvm::StringMap<SourceLocation> &Seen) {
@@ -955,6 +990,10 @@ void Parser::parseOMPContextProperty(OMPTraitSelector &TISelector,
 
   if (isValidTraitPropertyForTraitSetAndSelector(TIProperty.Kind,
                                                  TISelector.Kind, Set)) {
+    if (TISelector.Kind == llvm::omp::TraitSelector::implementation_extension)
+      checkExtensionProperty(*this, Tok.getLocation(), TIProperty, TISelector,
+                             Seen);
+
     // If we make it here the property, selector, set, score, condition, ... are
     // all valid (or have been corrected). Thus we can record the property.
     TISelector.Properties.push_back(TIProperty);
@@ -1783,11 +1822,11 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
 
     VariantMatchInfo VMI;
     ASTContext &ASTCtx = Actions.getASTContext();
-    TI.getAsVariantMatchInfo(ASTCtx, VMI, /* DeviceSetOnly */ true);
+    TI.getAsVariantMatchInfo(ASTCtx, VMI);
     OMPContext OMPCtx(ASTCtx.getLangOpts().OpenMPIsDevice,
                       ASTCtx.getTargetInfo().getTriple());
 
-    if (isVariantApplicableInContext(VMI, OMPCtx)) {
+    if (isVariantApplicableInContext(VMI, OMPCtx, /* DeviceSetOnly */ true)) {
       Actions.ActOnOpenMPBeginDeclareVariant(Loc, TI);
       break;
     }

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 52687888af2d..bb63db31d042 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5674,8 +5674,8 @@ ExprResult Sema::ActOnOpenMPCall(ExprResult Call, Scope *Scope,
 
       VariantMatchInfo VMI;
       OMPTraitInfo &TI = A->getTraitInfo();
-      TI.getAsVariantMatchInfo(Context, VMI, /* DeviceSetOnly */ false);
-      if (!isVariantApplicableInContext(VMI, OMPCtx))
+      TI.getAsVariantMatchInfo(Context, VMI);
+      if (!isVariantApplicableInContext(VMI, OMPCtx, /* DeviceSetOnly */ false))
         continue;
 
       VMIs.push_back(VMI);

diff  --git a/clang/test/AST/ast-dump-openmp-declare-variant-extensions-messages.c b/clang/test/AST/ast-dump-openmp-declare-variant-extensions-messages.c
new file mode 100644
index 000000000000..ee4d18f76c92
--- /dev/null
+++ b/clang/test/AST/ast-dump-openmp-declare-variant-extensions-messages.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify %s -x c++
+
+int dummy() { return 1; }
+
+#pragma omp declare variant(dummy) match(implementation={extension(match_any,match_all)}, device={kind(cpu, gpu)}) // expected-error {{only a single match extension allowed per OpenMP context selector}} expected-note {{the previous context property 'match_any' used here}}
+int base1() { return 2; }
+
+#pragma omp declare variant(dummy) match(implementation={extension(match_none,match_none)}, device={kind(gpu, fpga)}) // expected-warning {{the context property 'match_none' was used already in the same 'omp declare variant' directive; property ignored}} expected-note {{the previous context property 'match_none' used here}} expected-note {{the ignored property spans until here}}
+int base2() { return 3; }
+
+#pragma omp declare variant(dummy) match(implementation={vendor(pgi), extension(match_none,match_any)}, device={kind(cpu, gpu)}) // expected-error {{only a single match extension allowed per OpenMP context selector}} expected-note {{the previous context property 'match_none' used here}}
+int base3() { return 4; }
+
+
+int test() {
+  return base1() + base2() + base3();
+}

diff  --git a/clang/test/AST/ast-dump-openmp-declare-variant-extensions.c b/clang/test/AST/ast-dump-openmp-declare-variant-extensions.c
new file mode 100644
index 000000000000..9de53965a114
--- /dev/null
+++ b/clang/test/AST/ast-dump-openmp-declare-variant-extensions.c
@@ -0,0 +1,343 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s       | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s -x c++| FileCheck %s
+// expected-no-diagnostics
+
+int picked1() { return 0; }
+int picked2() { return 0; }
+int picked3();
+int picked4();
+int picked5() { return 0; }
+int picked6() { return 0; }
+int picked7() { return 0; }
+int not_picked1() { return 1; }
+int not_picked2() { return 2; }
+int not_picked3();
+int not_picked4();
+int not_picked5();
+int not_picked6();
+
+#pragma omp declare variant(picked1) match(implementation={extension(match_any)}, device={kind(cpu, gpu)})
+int base1() { return 3; }
+
+#pragma omp declare variant(picked2) match(implementation={extension(match_none)}, device={kind(gpu, fpga)})
+int base2() { return 4; }
+
+#pragma omp declare variant(picked3) match(implementation={vendor(pgi), extension(match_any)}, device={kind(cpu, gpu)})
+int base3() { return 5; }
+
+#pragma omp declare variant(picked4) match(user={condition(0)}, implementation={extension(match_none)}, device={kind(gpu, fpga)})
+int base4() { return 6; }
+
+#pragma omp declare variant(picked5) match(user={condition(1)}, implementation={extension(match_all)}, device={kind(cpu)})
+int base5() { return 7; }
+
+#pragma omp declare variant(not_picked1) match(implementation={extension(match_any)}, device={kind(gpu, fpga)})
+int base6() { return 0; }
+
+#pragma omp declare variant(not_picked2) match(implementation={extension(match_none)}, device={kind(gpu, cpu)})
+int base7() { return 0; }
+
+#pragma omp declare variant(not_picked3) match(implementation={vendor(llvm), extension(match_any)}, device={kind(fpga, gpu)})
+int base8() { return 0; }
+
+#pragma omp declare variant(not_picked4) match(user={condition(1)}, implementation={extension(match_none)}, device={kind(gpu, fpga)})
+int base9() { return 0; }
+
+#pragma omp declare variant(not_picked5) match(user={condition(1)}, implementation={extension(match_all)}, device={kind(cpu, gpu)})
+int base10() { return 0; }
+
+#pragma omp declare variant(not_picked6) match(implementation={extension(match_any)})
+int base11() { return 0; }
+
+#pragma omp declare variant(picked6) match(implementation={extension(match_all)})
+int base12() { return 8; }
+
+#pragma omp declare variant(picked7) match(implementation={extension(match_none)})
+int base13() { return 9; }
+
+#pragma omp begin declare variant match(implementation={extension(match_any)}, device={kind(cpu, gpu)})
+int overloaded1() { return 0; }
+#pragma omp end declare variant
+
+int overloaded2() { return 1; }
+#pragma omp begin declare variant match(implementation={extension(match_none)}, device={kind(fpga, gpu)})
+int overloaded2() { return 0; }
+#pragma omp end declare variant
+
+#pragma omp begin declare variant match(implementation={extension(match_none)}, device={kind(cpu)})
+NOT PARSED
+#pragma omp end declare variant
+
+
+int picked3() { return 0; }
+int picked4() { return 0; }
+int not_picked3() { return 10; }
+int not_picked4() { return 11; }
+int not_picked5() { return 12; }
+int not_picked6() { return 13; }
+
+int test() {
+  // Should return 0.
+  return base1() + base2() + base3() + base4() + base5() + base6() + base7() +
+         base8() + base9() + base10() + base11() + base12() + base13() +
+         overloaded1() + overloaded2();
+}
+
+// 1) All "picked" versions are called but none of the "non_picked" ones is.
+// 2) The overloaded functions that return 0 are called.
+
+// CHECK:      |-FunctionDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, col:27> col:5 referenced picked1 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_1:0x[a-z0-9]*]] <col:15, col:27>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_2:0x[a-z0-9]*]] <col:17, col:24>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_3:0x[a-z0-9]*]] <col:24> 'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_4:0x[a-z0-9]*]] <line:6:1, col:27> col:5 referenced picked2 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_5:0x[a-z0-9]*]] <col:15, col:27>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_6:0x[a-z0-9]*]] <col:17, col:24>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_7:0x[a-z0-9]*]] <col:24> 'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_8:0x[a-z0-9]*]] <line:7:1, col:13> col:5 referenced picked3 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_9:0x[a-z0-9]*]] <line:8:1, col:13> col:5 referenced picked4 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_10:0x[a-z0-9]*]] <line:9:1, col:27> col:5 referenced picked5 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_11:0x[a-z0-9]*]] <col:15, col:27>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_12:0x[a-z0-9]*]] <col:17, col:24>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_13:0x[a-z0-9]*]] <col:24> 'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_14:0x[a-z0-9]*]] <line:10:1, col:27> col:5 referenced picked6 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_15:0x[a-z0-9]*]] <col:15, col:27>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_16:0x[a-z0-9]*]] <col:17, col:24>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_17:0x[a-z0-9]*]] <col:24> 'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_18:0x[a-z0-9]*]] <line:11:1, col:27> col:5 referenced picked7 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_19:0x[a-z0-9]*]] <col:15, col:27>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_20:0x[a-z0-9]*]] <col:17, col:24>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_21:0x[a-z0-9]*]] <col:24> 'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_22:0x[a-z0-9]*]] <line:12:1, col:31> col:5 referenced not_picked1 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_23:0x[a-z0-9]*]] <col:19, col:31>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_24:0x[a-z0-9]*]] <col:21, col:28>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_25:0x[a-z0-9]*]] <col:28> 'int' 1
+// CHECK-NEXT: |-FunctionDecl [[ADDR_26:0x[a-z0-9]*]] <line:13:1, col:31> col:5 referenced not_picked2 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_27:0x[a-z0-9]*]] <col:19, col:31>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_28:0x[a-z0-9]*]] <col:21, col:28>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_29:0x[a-z0-9]*]] <col:28> 'int' 2
+// CHECK-NEXT: |-FunctionDecl [[ADDR_30:0x[a-z0-9]*]] <line:14:1, col:17> col:5 referenced not_picked3 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_31:0x[a-z0-9]*]] <line:15:1, col:17> col:5 referenced not_picked4 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_32:0x[a-z0-9]*]] <line:16:1, col:17> col:5 referenced not_picked5 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_33:0x[a-z0-9]*]] <line:17:1, col:17> col:5 referenced not_picked6 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_34:0x[a-z0-9]*]] <line:20:1, col:25> col:5 used base1 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_35:0x[a-z0-9]*]] <col:13, col:25>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_36:0x[a-z0-9]*]] <col:15, col:22>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_37:0x[a-z0-9]*]] <col:22> 'int' 3
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_38:0x[a-z0-9]*]] <line:19:1, col:107> Implicit implementation={extension(match_any)}, device={kind(cpu, gpu)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_39:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_0]] 'picked1' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_40:0x[a-z0-9]*]] <line:23:1, col:25> col:5 used base2 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_41:0x[a-z0-9]*]] <col:13, col:25>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_42:0x[a-z0-9]*]] <col:15, col:22>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_43:0x[a-z0-9]*]] <col:22> 'int' 4
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_44:0x[a-z0-9]*]] <line:22:1, col:109> Implicit implementation={extension(match_none)}, device={kind(gpu, fpga)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_45:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_4]] 'picked2' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_46:0x[a-z0-9]*]] <line:26:1, col:25> col:5 used base3 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_47:0x[a-z0-9]*]] <col:13, col:25>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_48:0x[a-z0-9]*]] <col:15, col:22>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_49:0x[a-z0-9]*]] <col:22> 'int' 5
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_50:0x[a-z0-9]*]] <line:25:1, col:120> Implicit implementation={vendor(pgi), extension(match_any)}, device={kind(cpu, gpu)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_51:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_8]] 'picked3' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_52:0x[a-z0-9]*]] <line:29:1, col:25> col:5 used base4 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_53:0x[a-z0-9]*]] <col:13, col:25>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_54:0x[a-z0-9]*]] <col:15, col:22>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_55:0x[a-z0-9]*]] <col:22> 'int' 6
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_56:0x[a-z0-9]*]] <line:28:1, col:130> Implicit user={condition(0)}, implementation={extension(match_none)}, device={kind(gpu, fpga)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_57:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_9]] 'picked4' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_58:0x[a-z0-9]*]] <line:32:1, col:25> col:5 used base5 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_59:0x[a-z0-9]*]] <col:13, col:25>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_60:0x[a-z0-9]*]] <col:15, col:22>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_61:0x[a-z0-9]*]] <col:22> 'int' 7
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_62:0x[a-z0-9]*]] <line:31:1, col:123> Implicit user={condition(1)}, implementation={extension(match_all)}, device={kind(cpu)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_63:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_10]] 'picked5' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_64:0x[a-z0-9]*]] <line:35:1, col:25> col:5 used base6 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_65:0x[a-z0-9]*]] <col:13, col:25>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_66:0x[a-z0-9]*]] <col:15, col:22>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_67:0x[a-z0-9]*]] <col:22> 'int' 0
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_68:0x[a-z0-9]*]] <line:34:1, col:112> Implicit implementation={extension(match_any)}, device={kind(gpu, fpga)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_69:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_22]] 'not_picked1' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_70:0x[a-z0-9]*]] <line:38:1, col:25> col:5 used base7 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_71:0x[a-z0-9]*]] <col:13, col:25>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_72:0x[a-z0-9]*]] <col:15, col:22>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_73:0x[a-z0-9]*]] <col:22> 'int' 0
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_74:0x[a-z0-9]*]] <line:37:1, col:112> Implicit implementation={extension(match_none)}, device={kind(gpu, cpu)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_75:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_26]] 'not_picked2' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_76:0x[a-z0-9]*]] <line:41:1, col:25> col:5 used base8 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_77:0x[a-z0-9]*]] <col:13, col:25>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_78:0x[a-z0-9]*]] <col:15, col:22>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_79:0x[a-z0-9]*]] <col:22> 'int' 0
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_80:0x[a-z0-9]*]] <line:40:1, col:126> Implicit implementation={vendor(llvm), extension(match_any)}, device={kind(fpga, gpu)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_81:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_30]] 'not_picked3' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_82:0x[a-z0-9]*]] <line:44:1, col:25> col:5 used base9 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_83:0x[a-z0-9]*]] <col:13, col:25>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_84:0x[a-z0-9]*]] <col:15, col:22>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_85:0x[a-z0-9]*]] <col:22> 'int' 0
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_86:0x[a-z0-9]*]] <line:43:1, col:134> Implicit user={condition(1)}, implementation={extension(match_none)}, device={kind(gpu, fpga)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_87:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_31]] 'not_picked4' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_88:0x[a-z0-9]*]] <line:47:1, col:26> col:5 used base10 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_89:0x[a-z0-9]*]] <col:14, col:26>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_90:0x[a-z0-9]*]] <col:16, col:23>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_91:0x[a-z0-9]*]] <col:23> 'int' 0
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_92:0x[a-z0-9]*]] <line:46:1, col:132> Implicit user={condition(1)}, implementation={extension(match_all)}, device={kind(cpu, gpu)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_93:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_32]] 'not_picked5' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_94:0x[a-z0-9]*]] <line:50:1, col:26> col:5 used base11 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_95:0x[a-z0-9]*]] <col:14, col:26>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_96:0x[a-z0-9]*]] <col:16, col:23>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_97:0x[a-z0-9]*]] <col:23> 'int' 0
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_98:0x[a-z0-9]*]] <line:49:1, col:86> Implicit implementation={extension(match_any)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_99:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_33]] 'not_picked6' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_100:0x[a-z0-9]*]] <line:53:1, col:26> col:5 used base12 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_101:0x[a-z0-9]*]] <col:14, col:26>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_102:0x[a-z0-9]*]] <col:16, col:23>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_103:0x[a-z0-9]*]] <col:23> 'int' 8
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_104:0x[a-z0-9]*]] <line:52:1, col:82> Implicit implementation={extension(match_all)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_105:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_14]] 'picked6' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_106:0x[a-z0-9]*]] <line:56:1, col:26> col:5 used base13 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_107:0x[a-z0-9]*]] <col:14, col:26>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_108:0x[a-z0-9]*]] <col:16, col:23>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_109:0x[a-z0-9]*]] <col:23> 'int' 9
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_110:0x[a-z0-9]*]] <line:55:1, col:83> Implicit implementation={extension(match_none)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_111:0x[a-z0-9]*]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_18]] 'picked7' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT: |-FunctionDecl [[ADDR_112:0x[a-z0-9]*]] <line:59:1, col:31> col:5 overloaded1[implementation={extension(match_any)}] 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_113:0x[a-z0-9]*]] <col:19, col:31>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_114:0x[a-z0-9]*]] <col:21, col:28>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_115:0x[a-z0-9]*]] <col:28> 'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_116:0x[a-z0-9]*]] <col:5> col:5 implicit used overloaded1 'int ({{.*}})'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_117:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={extension(match_any)}, device={kind(cpu, gpu)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_118:0x[a-z0-9]*]] <col:5> 'int ({{.*}})' Function [[ADDR_112]] 'overloaded1[implementation={extension(match_any)}]' 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_119:0x[a-z0-9]*]] <line:62:1, col:31> col:5 implicit used overloaded2 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_120:0x[a-z0-9]*]] <col:19, col:31>
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_121:0x[a-z0-9]*]] <col:21, col:28>
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_122:0x[a-z0-9]*]] <col:28> 'int' 1
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_123:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={extension(match_none)}, device={kind(fpga, gpu)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_124:0x[a-z0-9]*]] <line:64:5> 'int ({{.*}})' Function [[ADDR_125:0x[a-z0-9]*]] 'overloaded2[implementation={extension(match_none)}]' 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_125]] <col:1, col:31> col:5 overloaded2[implementation={extension(match_none)}] 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_126:0x[a-z0-9]*]] <col:19, col:31>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_127:0x[a-z0-9]*]] <col:21, col:28>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_128:0x[a-z0-9]*]] <col:28> 'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_129:0x[a-z0-9]*]] prev [[ADDR_8]] <line:72:1, col:27> col:5 picked3 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_130:0x[a-z0-9]*]] <col:15, col:27>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_131:0x[a-z0-9]*]] <col:17, col:24>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_132:0x[a-z0-9]*]] <col:24> 'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_133:0x[a-z0-9]*]] prev [[ADDR_9]] <line:73:1, col:27> col:5 picked4 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_134:0x[a-z0-9]*]] <col:15, col:27>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_135:0x[a-z0-9]*]] <col:17, col:24>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_136:0x[a-z0-9]*]] <col:24> 'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_137:0x[a-z0-9]*]] prev [[ADDR_30]] <line:74:1, col:32> col:5 not_picked3 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_138:0x[a-z0-9]*]] <col:19, col:32>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_139:0x[a-z0-9]*]] <col:21, col:28>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_140:0x[a-z0-9]*]] <col:28> 'int' 10
+// CHECK-NEXT: |-FunctionDecl [[ADDR_141:0x[a-z0-9]*]] prev [[ADDR_31]] <line:75:1, col:32> col:5 not_picked4 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_142:0x[a-z0-9]*]] <col:19, col:32>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_143:0x[a-z0-9]*]] <col:21, col:28>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_144:0x[a-z0-9]*]] <col:28> 'int' 11
+// CHECK-NEXT: |-FunctionDecl [[ADDR_145:0x[a-z0-9]*]] prev [[ADDR_32]] <line:76:1, col:32> col:5 not_picked5 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_146:0x[a-z0-9]*]] <col:19, col:32>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_147:0x[a-z0-9]*]] <col:21, col:28>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_148:0x[a-z0-9]*]] <col:28> 'int' 12
+// CHECK-NEXT: |-FunctionDecl [[ADDR_149:0x[a-z0-9]*]] prev [[ADDR_33]] <line:77:1, col:32> col:5 not_picked6 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_150:0x[a-z0-9]*]] <col:19, col:32>
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_151:0x[a-z0-9]*]] <col:21, col:28>
+// CHECK-NEXT: |     `-IntegerLiteral [[ADDR_152:0x[a-z0-9]*]] <col:28> 'int' 13
+// CHECK-NEXT: `-FunctionDecl [[ADDR_153:0x[a-z0-9]*]] <line:79:1, line:84:1> line:79:5 test 'int ({{.*}})'
+// CHECK-NEXT:   `-CompoundStmt [[ADDR_154:0x[a-z0-9]*]] <col:12, line:84:1>
+// CHECK-NEXT:     `-ReturnStmt [[ADDR_155:0x[a-z0-9]*]] <line:81:3, line:83:38>
+// CHECK-NEXT:       `-BinaryOperator [[ADDR_156:0x[a-z0-9]*]] <line:81:10, line:83:38> 'int' '+'
+// CHECK-NEXT:         |-BinaryOperator [[ADDR_157:0x[a-z0-9]*]] <line:81:10, line:83:22> 'int' '+'
+// CHECK-NEXT:         | |-BinaryOperator [[ADDR_158:0x[a-z0-9]*]] <line:81:10, line:82:70> 'int' '+'
+// CHECK-NEXT:         | | |-BinaryOperator [[ADDR_159:0x[a-z0-9]*]] <line:81:10, line:82:59> 'int' '+'
+// CHECK-NEXT:         | | | |-BinaryOperator [[ADDR_160:0x[a-z0-9]*]] <line:81:10, line:82:48> 'int' '+'
+// CHECK-NEXT:         | | | | |-BinaryOperator [[ADDR_161:0x[a-z0-9]*]] <line:81:10, line:82:37> 'int' '+'
+// CHECK-NEXT:         | | | | | |-BinaryOperator [[ADDR_162:0x[a-z0-9]*]] <line:81:10, line:82:26> 'int' '+'
+// CHECK-NEXT:         | | | | | | |-BinaryOperator [[ADDR_163:0x[a-z0-9]*]] <line:81:10, line:82:16> 'int' '+'
+// CHECK-NEXT:         | | | | | | | |-BinaryOperator [[ADDR_164:0x[a-z0-9]*]] <line:81:10, col:76> 'int' '+'
+// CHECK-NEXT:         | | | | | | | | |-BinaryOperator [[ADDR_165:0x[a-z0-9]*]] <col:10, col:66> 'int' '+'
+// CHECK-NEXT:         | | | | | | | | | |-BinaryOperator [[ADDR_166:0x[a-z0-9]*]] <col:10, col:56> 'int' '+'
+// CHECK-NEXT:         | | | | | | | | | | |-BinaryOperator [[ADDR_167:0x[a-z0-9]*]] <col:10, col:46> 'int' '+'
+// CHECK-NEXT:         | | | | | | | | | | | |-BinaryOperator [[ADDR_168:0x[a-z0-9]*]] <col:10, col:36> 'int' '+'
+// CHECK-NEXT:         | | | | | | | | | | | | |-BinaryOperator [[ADDR_169:0x[a-z0-9]*]] <col:10, col:26> 'int' '+'
+// CHECK-NEXT:         | | | | | | | | | | | | | |-PseudoObjectExpr [[ADDR_170:0x[a-z0-9]*]] <col:10, col:16> 'int'
+// CHECK-NEXT:         | | | | | | | | | | | | | | |-CallExpr [[ADDR_171:0x[a-z0-9]*]] <col:10, col:16> 'int'
+// CHECK-NEXT:         | | | | | | | | | | | | | | | `-ImplicitCastExpr [[ADDR_172:0x[a-z0-9]*]] <col:10> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | | | | | | | | |   `-DeclRefExpr [[ADDR_173:0x[a-z0-9]*]] <col:10> 'int ({{.*}})' {{.*}}Function [[ADDR_34]] 'base1' 'int ({{.*}})'
+// CHECK-NEXT:         | | | | | | | | | | | | | | `-CallExpr [[ADDR_174:0x[a-z0-9]*]] <line:19:29, line:81:16> 'int'
+// CHECK-NEXT:         | | | | | | | | | | | | | |   `-ImplicitCastExpr [[ADDR_175:0x[a-z0-9]*]] <line:19:29> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | | | | | | | |     `-DeclRefExpr [[ADDR_39]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_0]] 'picked1' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT:         | | | | | | | | | | | | | `-PseudoObjectExpr [[ADDR_176:0x[a-z0-9]*]] <line:81:20, col:26> 'int'
+// CHECK-NEXT:         | | | | | | | | | | | | |   |-CallExpr [[ADDR_177:0x[a-z0-9]*]] <col:20, col:26> 'int'
+// CHECK-NEXT:         | | | | | | | | | | | | |   | `-ImplicitCastExpr [[ADDR_178:0x[a-z0-9]*]] <col:20> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | | | | | | |   |   `-DeclRefExpr [[ADDR_179:0x[a-z0-9]*]] <col:20> 'int ({{.*}})' {{.*}}Function [[ADDR_40]] 'base2' 'int ({{.*}})'
+// CHECK-NEXT:         | | | | | | | | | | | | |   `-CallExpr [[ADDR_180:0x[a-z0-9]*]] <line:22:29, line:81:26> 'int'
+// CHECK-NEXT:         | | | | | | | | | | | | |     `-ImplicitCastExpr [[ADDR_181:0x[a-z0-9]*]] <line:22:29> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | | | | | | |       `-DeclRefExpr [[ADDR_45]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_4]] 'picked2' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT:         | | | | | | | | | | | | `-PseudoObjectExpr [[ADDR_182:0x[a-z0-9]*]] <line:81:30, col:36> 'int'
+// CHECK-NEXT:         | | | | | | | | | | | |   |-CallExpr [[ADDR_183:0x[a-z0-9]*]] <col:30, col:36> 'int'
+// CHECK-NEXT:         | | | | | | | | | | | |   | `-ImplicitCastExpr [[ADDR_184:0x[a-z0-9]*]] <col:30> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | | | | | |   |   `-DeclRefExpr [[ADDR_185:0x[a-z0-9]*]] <col:30> 'int ({{.*}})' {{.*}}Function [[ADDR_46]] 'base3' 'int ({{.*}})'
+// CHECK-NEXT:         | | | | | | | | | | | |   `-CallExpr [[ADDR_186:0x[a-z0-9]*]] <line:25:29, line:81:36> 'int'
+// CHECK-NEXT:         | | | | | | | | | | | |     `-ImplicitCastExpr [[ADDR_187:0x[a-z0-9]*]] <line:25:29> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | | | | | |       `-DeclRefExpr [[ADDR_51]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_8]] 'picked3' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT:         | | | | | | | | | | | `-PseudoObjectExpr [[ADDR_188:0x[a-z0-9]*]] <line:81:40, col:46> 'int'
+// CHECK-NEXT:         | | | | | | | | | | |   |-CallExpr [[ADDR_189:0x[a-z0-9]*]] <col:40, col:46> 'int'
+// CHECK-NEXT:         | | | | | | | | | | |   | `-ImplicitCastExpr [[ADDR_190:0x[a-z0-9]*]] <col:40> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | | | | |   |   `-DeclRefExpr [[ADDR_191:0x[a-z0-9]*]] <col:40> 'int ({{.*}})' {{.*}}Function [[ADDR_52]] 'base4' 'int ({{.*}})'
+// CHECK-NEXT:         | | | | | | | | | | |   `-CallExpr [[ADDR_192:0x[a-z0-9]*]] <line:28:29, line:81:46> 'int'
+// CHECK-NEXT:         | | | | | | | | | | |     `-ImplicitCastExpr [[ADDR_193:0x[a-z0-9]*]] <line:28:29> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | | | | |       `-DeclRefExpr [[ADDR_57]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_9]] 'picked4' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT:         | | | | | | | | | | `-PseudoObjectExpr [[ADDR_194:0x[a-z0-9]*]] <line:81:50, col:56> 'int'
+// CHECK-NEXT:         | | | | | | | | | |   |-CallExpr [[ADDR_195:0x[a-z0-9]*]] <col:50, col:56> 'int'
+// CHECK-NEXT:         | | | | | | | | | |   | `-ImplicitCastExpr [[ADDR_196:0x[a-z0-9]*]] <col:50> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | | | |   |   `-DeclRefExpr [[ADDR_197:0x[a-z0-9]*]] <col:50> 'int ({{.*}})' {{.*}}Function [[ADDR_58]] 'base5' 'int ({{.*}})'
+// CHECK-NEXT:         | | | | | | | | | |   `-CallExpr [[ADDR_198:0x[a-z0-9]*]] <line:31:29, line:81:56> 'int'
+// CHECK-NEXT:         | | | | | | | | | |     `-ImplicitCastExpr [[ADDR_199:0x[a-z0-9]*]] <line:31:29> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | | | |       `-DeclRefExpr [[ADDR_63]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_10]] 'picked5' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT:         | | | | | | | | | `-CallExpr [[ADDR_200:0x[a-z0-9]*]] <line:81:60, col:66> 'int'
+// CHECK-NEXT:         | | | | | | | | |   `-ImplicitCastExpr [[ADDR_201:0x[a-z0-9]*]] <col:60> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | | |     `-DeclRefExpr [[ADDR_202:0x[a-z0-9]*]] <col:60> 'int ({{.*}})' {{.*}}Function [[ADDR_64]] 'base6' 'int ({{.*}})'
+// CHECK-NEXT:         | | | | | | | | `-CallExpr [[ADDR_203:0x[a-z0-9]*]] <col:70, col:76> 'int'
+// CHECK-NEXT:         | | | | | | | |   `-ImplicitCastExpr [[ADDR_204:0x[a-z0-9]*]] <col:70> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | | |     `-DeclRefExpr [[ADDR_205:0x[a-z0-9]*]] <col:70> 'int ({{.*}})' {{.*}}Function [[ADDR_70]] 'base7' 'int ({{.*}})'
+// CHECK-NEXT:         | | | | | | | `-PseudoObjectExpr [[ADDR_206:0x[a-z0-9]*]] <line:82:10, col:16> 'int'
+// CHECK-NEXT:         | | | | | | |   |-CallExpr [[ADDR_207:0x[a-z0-9]*]] <col:10, col:16> 'int'
+// CHECK-NEXT:         | | | | | | |   | `-ImplicitCastExpr [[ADDR_208:0x[a-z0-9]*]] <col:10> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | |   |   `-DeclRefExpr [[ADDR_209:0x[a-z0-9]*]] <col:10> 'int ({{.*}})' {{.*}}Function [[ADDR_76]] 'base8' 'int ({{.*}})'
+// CHECK-NEXT:         | | | | | | |   `-CallExpr [[ADDR_210:0x[a-z0-9]*]] <line:40:29, line:82:16> 'int'
+// CHECK-NEXT:         | | | | | | |     `-ImplicitCastExpr [[ADDR_211:0x[a-z0-9]*]] <line:40:29> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | | |       `-DeclRefExpr [[ADDR_81]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_30]] 'not_picked3' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT:         | | | | | | `-CallExpr [[ADDR_212:0x[a-z0-9]*]] <line:82:20, col:26> 'int'
+// CHECK-NEXT:         | | | | | |   `-ImplicitCastExpr [[ADDR_213:0x[a-z0-9]*]] <col:20> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | | |     `-DeclRefExpr [[ADDR_214:0x[a-z0-9]*]] <col:20> 'int ({{.*}})' {{.*}}Function [[ADDR_82]] 'base9' 'int ({{.*}})'
+// CHECK-NEXT:         | | | | | `-CallExpr [[ADDR_215:0x[a-z0-9]*]] <col:30, col:37> 'int'
+// CHECK-NEXT:         | | | | |   `-ImplicitCastExpr [[ADDR_216:0x[a-z0-9]*]] <col:30> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | | |     `-DeclRefExpr [[ADDR_217:0x[a-z0-9]*]] <col:30> 'int ({{.*}})' {{.*}}Function [[ADDR_88]] 'base10' 'int ({{.*}})'
+// CHECK-NEXT:         | | | | `-CallExpr [[ADDR_218:0x[a-z0-9]*]] <col:41, col:48> 'int'
+// CHECK-NEXT:         | | | |   `-ImplicitCastExpr [[ADDR_219:0x[a-z0-9]*]] <col:41> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | | |     `-DeclRefExpr [[ADDR_220:0x[a-z0-9]*]] <col:41> 'int ({{.*}})' {{.*}}Function [[ADDR_94]] 'base11' 'int ({{.*}})'
+// CHECK-NEXT:         | | | `-PseudoObjectExpr [[ADDR_221:0x[a-z0-9]*]] <col:52, col:59> 'int'
+// CHECK-NEXT:         | | |   |-CallExpr [[ADDR_222:0x[a-z0-9]*]] <col:52, col:59> 'int'
+// CHECK-NEXT:         | | |   | `-ImplicitCastExpr [[ADDR_223:0x[a-z0-9]*]] <col:52> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | |   |   `-DeclRefExpr [[ADDR_224:0x[a-z0-9]*]] <col:52> 'int ({{.*}})' {{.*}}Function [[ADDR_100]] 'base12' 'int ({{.*}})'
+// CHECK-NEXT:         | | |   `-CallExpr [[ADDR_225:0x[a-z0-9]*]] <line:52:29, line:82:59> 'int'
+// CHECK-NEXT:         | | |     `-ImplicitCastExpr [[ADDR_226:0x[a-z0-9]*]] <line:52:29> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | | |       `-DeclRefExpr [[ADDR_105]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_14]] 'picked6' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT:         | | `-PseudoObjectExpr [[ADDR_227:0x[a-z0-9]*]] <line:82:63, col:70> 'int'
+// CHECK-NEXT:         | |   |-CallExpr [[ADDR_228:0x[a-z0-9]*]] <col:63, col:70> 'int'
+// CHECK-NEXT:         | |   | `-ImplicitCastExpr [[ADDR_229:0x[a-z0-9]*]] <col:63> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | |   |   `-DeclRefExpr [[ADDR_230:0x[a-z0-9]*]] <col:63> 'int ({{.*}})' {{.*}}Function [[ADDR_106]] 'base13' 'int ({{.*}})'
+// CHECK-NEXT:         | |   `-CallExpr [[ADDR_231:0x[a-z0-9]*]] <line:55:29, line:82:70> 'int'
+// CHECK-NEXT:         | |     `-ImplicitCastExpr [[ADDR_232:0x[a-z0-9]*]] <line:55:29> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         | |       `-DeclRefExpr [[ADDR_111]] <col:29> 'int ({{.*}})' {{.*}}Function [[ADDR_18]] 'picked7' 'int ({{.*}})' non_odr_use_unevaluated
+// CHECK-NEXT:         | `-PseudoObjectExpr [[ADDR_233:0x[a-z0-9]*]] <line:83:10, col:22> 'int'
+// CHECK-NEXT:         |   |-CallExpr [[ADDR_234:0x[a-z0-9]*]] <col:10, col:22> 'int'
+// CHECK-NEXT:         |   | `-ImplicitCastExpr [[ADDR_235:0x[a-z0-9]*]] <col:10> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         |   |   `-DeclRefExpr [[ADDR_236:0x[a-z0-9]*]] <col:10> 'int ({{.*}})' {{.*}}Function [[ADDR_116]] 'overloaded1' 'int ({{.*}})'
+// CHECK-NEXT:         |   `-CallExpr [[ADDR_237:0x[a-z0-9]*]] <line:59:5, line:83:22> 'int'
+// CHECK-NEXT:         |     `-ImplicitCastExpr [[ADDR_238:0x[a-z0-9]*]] <line:59:5> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:         |       `-DeclRefExpr [[ADDR_118]] <col:5> 'int ({{.*}})' Function [[ADDR_112]] 'overloaded1[implementation={extension(match_any)}]' 'int ({{.*}})'
+// CHECK-NEXT:         `-PseudoObjectExpr [[ADDR_239:0x[a-z0-9]*]] <line:83:26, col:38> 'int'
+// CHECK-NEXT:           |-CallExpr [[ADDR_240:0x[a-z0-9]*]] <col:26, col:38> 'int'
+// CHECK-NEXT:           | `-ImplicitCastExpr [[ADDR_241:0x[a-z0-9]*]] <col:26> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:           |   `-DeclRefExpr [[ADDR_242:0x[a-z0-9]*]] <col:26> 'int ({{.*}})' {{.*}}Function [[ADDR_119]] 'overloaded2' 'int ({{.*}})'
+// CHECK-NEXT:           `-CallExpr [[ADDR_243:0x[a-z0-9]*]] <line:64:5, line:83:38> 'int'
+// CHECK-NEXT:             `-ImplicitCastExpr [[ADDR_244:0x[a-z0-9]*]] <line:64:5> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// CHECK-NEXT:               `-DeclRefExpr [[ADDR_124]] <col:5> 'int ({{.*}})' Function [[ADDR_125]] 'overloaded2[implementation={extension(match_none)}]' 'int ({{.*}})'

diff  --git a/clang/test/OpenMP/declare_variant_ast_print.c b/clang/test/OpenMP/declare_variant_ast_print.c
index 515d3167627c..5184557a8071 100644
--- a/clang/test/OpenMP/declare_variant_ast_print.c
+++ b/clang/test/OpenMP/declare_variant_ast_print.c
@@ -14,9 +14,15 @@ int foo(void);
 #pragma omp declare variant(foo) match(implementation={vendor(score(5): ibm, xxx, ibm)}, device={kind(cpu, nohost)})
 #pragma omp declare variant(foo) match(device={kind(host)})
 #pragma omp declare variant(foo) match(device={kind(nohost), xxx})
+#pragma omp declare variant(foo) match(implementation={extension(match_all)})
+#pragma omp declare variant(foo) match(implementation={extension(match_any)})
+#pragma omp declare variant(foo) match(implementation={extension(match_none)})
 int bar(void);
 
 // CHECK:      int foo();
+// CHECK-NEXT: #pragma omp declare variant(foo) match(implementation={extension(match_none)})
+// CHECK-NEXT: #pragma omp declare variant(foo) match(implementation={extension(match_any)})
+// CHECK-NEXT: #pragma omp declare variant(foo) match(implementation={extension(match_all)})
 // CHECK-NEXT: #pragma omp declare variant(foo) match(device={kind(nohost)})
 // CHECK-NEXT: #pragma omp declare variant(foo) match(device={kind(host)})
 // CHECK-NEXT: #pragma omp declare variant(foo) match(implementation={vendor(score(5): ibm)}, device={kind(cpu, nohost)})

diff  --git a/clang/test/OpenMP/declare_variant_messages.c b/clang/test/OpenMP/declare_variant_messages.c
index fc9f5eb32cf2..ecbf022351a7 100644
--- a/clang/test/OpenMP/declare_variant_messages.c
+++ b/clang/test/OpenMP/declare_variant_messages.c
@@ -46,7 +46,7 @@ int foo(void);
 #pragma omp declare variant(foo) match(device={kind(score(foo()) ibm)}) // expected-warning {{expected '':'' after the score expression; '':'' assumed}} expected-warning {{the context selector 'kind' in the context set 'device' cannot have a score ('foo()'); score ignored}} expected-warning {{'ibm' is not a valid context property for the context selector 'kind' and the context set 'device'; property ignored}} expected-note {{try 'match(implementation={vendor(ibm)})'}} expected-note {{the ignored property spans until here}}
 #pragma omp declare variant(foo) match(device={kind(score(5): host), kind(llvm)}) // expected-warning {{the context selector 'kind' in the context set 'device' cannot have a score ('5'); score ignored}} expected-warning {{the context selector 'kind' was used already in the same 'omp declare variant' directive; selector ignored}} expected-note {{the previous context selector 'kind' used here}} expected-note {{the ignored selector spans until here}}
 #pragma omp declare variant(foo) match(device={kind(score(5): nohost), vendor(llvm)}) // expected-warning {{the context selector 'kind' in the context set 'device' cannot have a score ('5'); score ignored}} expected-warning {{the context selector 'vendor' is not valid for the context set 'device'; selector ignored}} expected-note {{the context selector 'vendor' can be nested in the context set 'implementation'; try 'match(implementation={vendor(property)})'}} expected-note {{the ignored selector spans until here}}
-#pragma omp declare variant(foo) match(implementation={extension("aaa")}) // expected-warning {{'aaa' is not a valid context property for the context selector 'extension' and the context set 'implementation'; property ignored}} expected-note {{context property options are: <none>}} expected-note {{the ignored property spans until here}}
+#pragma omp declare variant(foo) match(implementation={extension("aaa")}) // expected-warning {{'aaa' is not a valid context property for the context selector 'extension' and the context set 'implementation'; property ignored}} expected-note {{context property options are: 'match_all' 'match_any' 'match_none'}} expected-note {{the ignored property spans until here}}
 int bar(void);
 
 #pragma omp declare variant(foo) match(implementation = {vendor(score(foo) :llvm)}) // expected-warning {{score expressions in the OpenMP context selector need to be constant; foo is not and will be ignored}}

diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMPContext.h b/llvm/include/llvm/Frontend/OpenMP/OMPContext.h
index 0a9d9c277d99..1a42d189db44 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPContext.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPContext.h
@@ -154,9 +154,12 @@ struct OMPContext {
 };
 
 /// Return true if \p VMI is applicable in \p Ctx, that is, all traits required
-/// by \p VMI are available in the OpenMP context \p Ctx.
+/// by \p VMI are available in the OpenMP context \p Ctx. If \p DeviceSetOnly is
+/// true, only the device selector set, if present, are checked. Note that we
+/// still honor extension traits provided by the user.
 bool isVariantApplicableInContext(const VariantMatchInfo &VMI,
-                                  const OMPContext &Ctx);
+                                  const OMPContext &Ctx,
+                                  bool DeviceSetOnly = false);
 
 /// Return the index (into \p VMIs) of the variant with the highest score
 /// from the ones applicble in \p Ctx. See llvm::isVariantApplicableInContext.

diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
index 7ac614e99201..1a82d772d26a 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -664,6 +664,9 @@ __OMP_TRAIT_PROPERTY(implementation, vendor, ti)
 __OMP_TRAIT_PROPERTY(implementation, vendor, unknown)
 
 __OMP_TRAIT_SELECTOR(implementation, extension, true)
+__OMP_TRAIT_PROPERTY(implementation, extension, match_all)
+__OMP_TRAIT_PROPERTY(implementation, extension, match_any)
+__OMP_TRAIT_PROPERTY(implementation, extension, match_none)
 
 __OMP_TRAIT_SET(user)
 

diff  --git a/llvm/lib/Frontend/OpenMP/OMPContext.cpp b/llvm/lib/Frontend/OpenMP/OMPContext.cpp
index dd3292ab776e..6d2cf41f904c 100644
--- a/llvm/lib/Frontend/OpenMP/OMPContext.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPContext.cpp
@@ -137,52 +137,119 @@ static bool isStrictSubset(const VariantMatchInfo &VMI0,
 
 static int isVariantApplicableInContextHelper(
     const VariantMatchInfo &VMI, const OMPContext &Ctx,
-    SmallVectorImpl<unsigned> *ConstructMatches) {
+    SmallVectorImpl<unsigned> *ConstructMatches, bool DeviceSetOnly) {
+
+  // The match kind determines if we need to match all traits, any of the
+  // traits, or none of the traits for it to be an applicable context.
+  enum MatchKind { MK_ALL, MK_ANY, MK_NONE };
+
+  MatchKind MK = MK_ALL;
+  // Determine the match kind the user wants, "all" is the default and provided
+  // to the user only for completeness.
+  if (VMI.RequiredTraits.test(
+          unsigned(TraitProperty::implementation_extension_match_any)))
+    MK = MK_ANY;
+  if (VMI.RequiredTraits.test(
+          unsigned(TraitProperty::implementation_extension_match_none)))
+    MK = MK_NONE;
+
+  // Helper to deal with a single property that was (not) found in the OpenMP
+  // context based on the match kind selected by the user via
+  // `implementation={extensions(match_[all,any,none])}'
+  auto HandleTrait = [MK](TraitProperty Property,
+                          bool WasFound) -> Optional<bool> /* Result */ {
+    // For kind "any" a single match is enough but we ignore non-matched properties.
+    if (MK == MK_ANY) {
+      if (WasFound)
+        return true;
+      return None;
+    }
+
+    // In "all" or "none" mode we accept a matching or non-matching property
+    // respectively and move on. We are not done yet!
+    if ((WasFound && MK == MK_ALL) || (!WasFound && MK == MK_NONE))
+      return None;
+
+    // We missed a property, provide some debug output and indicate failure.
+    LLVM_DEBUG({
+      if (MK == MK_ALL)
+        dbgs() << "[" << DEBUG_TYPE << "] Property "
+               << getOpenMPContextTraitPropertyName(Property)
+               << " was not in the OpenMP context but match kind is all.\n";
+      if (MK == MK_NONE)
+        dbgs() << "[" << DEBUG_TYPE << "] Property "
+               << getOpenMPContextTraitPropertyName(Property)
+               << " was in the OpenMP context but match kind is none.\n";
+    });
+    return false;
+  };
 
   for (unsigned Bit : VMI.RequiredTraits.set_bits()) {
     TraitProperty Property = TraitProperty(Bit);
+    if (DeviceSetOnly &&
+        getOpenMPContextTraitSetForProperty(Property) != TraitSet::device)
+      continue;
+
+    // So far all extensions are handled elsewhere, we skip them here as they
+    // are not part of the OpenMP context.
+    if (getOpenMPContextTraitSelectorForProperty(Property) ==
+        TraitSelector::implementation_extension)
+      continue;
 
     bool IsActiveTrait = Ctx.ActiveTraits.test(unsigned(Property));
-    if (!IsActiveTrait) {
-      LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE << "] Property "
-                        << getOpenMPContextTraitPropertyName(Property)
-                        << " was not in the OpenMP context.\n");
-      return false;
-    }
+    Optional<bool> Result = HandleTrait(Property, IsActiveTrait);
+    if (Result.hasValue())
+      return Result.getValue();
   }
 
-  // We could use isSubset here but we also want to record the match locations.
-  unsigned ConstructIdx = 0, NoConstructTraits = Ctx.ConstructTraits.size();
-  for (TraitProperty Property : VMI.ConstructTraits) {
-    assert(getOpenMPContextTraitSetForProperty(Property) ==
-               TraitSet::construct &&
-           "Variant context is ill-formed!");
-
-    // Verify the nesting.
-    bool FoundInOrder = false;
-    while (!FoundInOrder && ConstructIdx != NoConstructTraits)
-      FoundInOrder = (Ctx.ConstructTraits[ConstructIdx++] == Property);
-    if (ConstructMatches)
-      ConstructMatches->push_back(ConstructIdx - 1);
-
-    if (!FoundInOrder) {
-      LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE << "] Construct property "
-                        << getOpenMPContextTraitPropertyName(Property)
-                        << " was not nested properly.\n");
-      return false;
+  if (!DeviceSetOnly) {
+    // We could use isSubset here but we also want to record the match
+    // locations.
+    unsigned ConstructIdx = 0, NoConstructTraits = Ctx.ConstructTraits.size();
+    for (TraitProperty Property : VMI.ConstructTraits) {
+      assert(getOpenMPContextTraitSetForProperty(Property) ==
+                 TraitSet::construct &&
+             "Variant context is ill-formed!");
+
+      // Verify the nesting.
+      bool FoundInOrder = false;
+      while (!FoundInOrder && ConstructIdx != NoConstructTraits)
+        FoundInOrder = (Ctx.ConstructTraits[ConstructIdx++] == Property);
+      if (ConstructMatches)
+        ConstructMatches->push_back(ConstructIdx - 1);
+
+      Optional<bool> Result = HandleTrait(Property, FoundInOrder);
+      if (Result.hasValue())
+        return Result.getValue();
+
+      if (!FoundInOrder) {
+        LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE << "] Construct property "
+                          << getOpenMPContextTraitPropertyName(Property)
+                          << " was not nested properly.\n");
+        return false;
+      }
+
+      // TODO: Verify SIMD
     }
 
-    // TODO: Verify SIMD
+    assert(isSubset<TraitProperty>(VMI.ConstructTraits, Ctx.ConstructTraits) &&
+           "Broken invariant!");
+  }
+
+  if (MK == MK_ANY) {
+    LLVM_DEBUG(dbgs() << "[" << DEBUG_TYPE
+                      << "] None of the properties was in the OpenMP context "
+                         "but match kind is any.\n");
+    return false;
   }
 
-  assert(isSubset<TraitProperty>(VMI.ConstructTraits, Ctx.ConstructTraits) &&
-         "Broken invariant!");
   return true;
 }
 
 bool llvm::omp::isVariantApplicableInContext(const VariantMatchInfo &VMI,
-                                             const OMPContext &Ctx) {
-  return isVariantApplicableInContextHelper(VMI, Ctx, nullptr);
+                                             const OMPContext &Ctx,
+                                             bool DeviceSetOnly) {
+  return isVariantApplicableInContextHelper(VMI, Ctx, nullptr, DeviceSetOnly);
 }
 
 static APInt getVariantMatchScore(const VariantMatchInfo &VMI,
@@ -267,7 +334,8 @@ int llvm::omp::getBestVariantMatchForContext(
 
     SmallVector<unsigned, 8> ConstructMatches;
     // If the variant is not applicable its not the best.
-    if (!isVariantApplicableInContextHelper(VMI, Ctx, &ConstructMatches))
+    if (!isVariantApplicableInContextHelper(VMI, Ctx, &ConstructMatches,
+                                            /* DeviceSetOnly */ false))
       continue;
     // Check if its clearly not the best.
     APInt Score = getVariantMatchScore(VMI, Ctx, ConstructMatches);


        


More information about the llvm-branch-commits mailing list