Author: Johannes Doerfert
Date: 2021-01-07T14:31:18-06:00
New Revision: d970a285b8567b93aea39e7e4d10965fe8b7340c

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

LOG: [OpenMP][Fix] Make the arch selector for x86_64 work

The triple uses a bar "x86-64" instead of an underscore. Since we
have troubles accepting x86-64 as an identifier, we stick with
x86_64 in the frontend and translate it explicitly.

Reviewed By: tianshilei1992

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

Added: 
    clang/test/OpenMP/declare_variant_ast_x86_64.c

Modified: 
    llvm/lib/Frontend/OpenMP/OMPContext.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/OpenMP/declare_variant_ast_x86_64.c 
b/clang/test/OpenMP/declare_variant_ast_x86_64.c
new file mode 100644
index 0000000000000..c0be89a1c6127
--- /dev/null
+++ b/clang/test/OpenMP/declare_variant_ast_x86_64.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown %s 
-ast-dump | FileCheck %s
+// expected-no-diagnostics
+
+#pragma omp begin declare variant match(device={arch(x86_64)})
+
+void bar() {}
+
+// CHECK: FunctionDecl {{.*}} bar[device={arch(x86_64)}] 'void ()'
+
+#pragma omp end declare variant

diff  --git a/llvm/lib/Frontend/OpenMP/OMPContext.cpp 
b/llvm/lib/Frontend/OpenMP/OMPContext.cpp
index e252c964e647c..39f047015d192 100644
--- a/llvm/lib/Frontend/OpenMP/OMPContext.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPContext.cpp
@@ -14,7 +14,9 @@
 
 #include "llvm/Frontend/OpenMP/OMPContext.h"
 #include "llvm/ADT/SetOperations.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -58,9 +60,12 @@ OMPContext::OMPContext(bool IsDeviceCompilation, Triple 
TargetTriple) {
 
   // Add the appropriate device architecture trait based on the triple.
 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str)         
\
-  if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch)          
\
+  if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch) {        
\
     if (TargetTriple.getArch() == TargetTriple.getArchTypeForLLVMName(Str))    
\
-      ActiveTraits.set(unsigned(TraitProperty::Enum));
+      ActiveTraits.set(unsigned(TraitProperty::Enum));                         
\
+    if (Str == "x86_64" && TargetTriple.getArch() == Triple::x86_64)           
\
+      ActiveTraits.set(unsigned(TraitProperty::Enum));                         
\
+  }
 #include "llvm/Frontend/OpenMP/OMPKinds.def"
 
   // TODO: What exactly do we want to see as device ISA trait?


        
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to