Skip to content

Commit d970a28

Browse files
committed
[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
1 parent 9ae171b commit d970a28

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown %s -ast-dump | FileCheck %s
2+
// expected-no-diagnostics
3+
4+
#pragma omp begin declare variant match(device={arch(x86_64)})
5+
6+
void bar() {}
7+
8+
// CHECK: FunctionDecl {{.*}} bar[device={arch(x86_64)}] 'void ()'
9+
10+
#pragma omp end declare variant

llvm/lib/Frontend/OpenMP/OMPContext.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
#include "llvm/Frontend/OpenMP/OMPContext.h"
1616
#include "llvm/ADT/SetOperations.h"
17+
#include "llvm/ADT/StringRef.h"
1718
#include "llvm/ADT/StringSwitch.h"
19+
#include "llvm/ADT/Triple.h"
1820
#include "llvm/Support/Debug.h"
1921
#include "llvm/Support/raw_ostream.h"
2022

@@ -58,9 +60,12 @@ OMPContext::OMPContext(bool IsDeviceCompilation, Triple TargetTriple) {
5860

5961
// Add the appropriate device architecture trait based on the triple.
6062
#define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \
61-
if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch) \
63+
if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch) { \
6264
if (TargetTriple.getArch() == TargetTriple.getArchTypeForLLVMName(Str)) \
63-
ActiveTraits.set(unsigned(TraitProperty::Enum));
65+
ActiveTraits.set(unsigned(TraitProperty::Enum)); \
66+
if (Str == "x86_64" && TargetTriple.getArch() == Triple::x86_64) \
67+
ActiveTraits.set(unsigned(TraitProperty::Enum)); \
68+
}
6469
#include "llvm/Frontend/OpenMP/OMPKinds.def"
6570

6671
// TODO: What exactly do we want to see as device ISA trait?

0 commit comments

Comments
 (0)