forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OpenMP] OpenMP 5.1 "assume" directive parsing support
This is a minimal patch to support parsing for "omp assume" directives. These are meant to be hints to a compiler' optimisers: as such, it is legitimate (if not very useful) to ignore them. The patch builds on top of the existing support for "omp assumes" directives (note spelling!). Unlike the "omp [begin/end] assumes" directives, "omp assume" is associated with a compound statement, i.e. it can appear within a function. The "holds" assumption could (theoretically) be mapped onto the existing builtin "__builtin_assume", though the latter applies to a single point in the program, and the former to a range (i.e. the whole of the associated compound statement). This patch fixes sollve's OpenMP 5.1 "omp assume"-based tests. Change-Id: Ibd4a0e2af82c4ac818eaa3de8867a006307361ec
- Loading branch information
Showing
7 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -ast-print %s | FileCheck %s | ||
// expected-no-diagnostics | ||
|
||
extern int bar(int); | ||
|
||
int foo(int arg) | ||
{ | ||
#pragma omp assume no_openmp_routines | ||
{ | ||
auto fn = [](int x) { return bar(x); }; | ||
// CHECK: auto fn = [](int x) { | ||
return fn(5); | ||
} | ||
} | ||
|
||
class C { | ||
public: | ||
int foo(int a); | ||
}; | ||
|
||
// We're really just checking that this parses. All the assumptions are thrown | ||
// away immediately for now. | ||
int C::foo(int a) | ||
{ | ||
#pragma omp assume holds(sizeof(T) == 8) absent(parallel) | ||
{ | ||
auto fn = [](int x) { return bar(x); }; | ||
// CHECK: auto fn = [](int x) { | ||
return fn(5); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// RUN: %clang_cc1 -triple=x86_64-linux-gnu -verify -fopenmp -x c -std=c99 %s | ||
// RUN: %clang_cc1 -triple=x86_64-linux-gnu -verify -fopenmp-simd -x c -std=c99 %s | ||
|
||
#pragma omp assume no_openmp // expected-error {{unexpected OpenMP directive '#pragma omp assume'}} | ||
|
||
void foo(void) { | ||
#pragma omp assume hold(1==1) // expected-warning {{valid assume clauses start with 'ext_', 'absent', 'contains', 'holds', 'no_openmp', 'no_openmp_routines', 'no_parallelism'; tokens will be ignored}} expected-note {{the ignored tokens spans until here}} | ||
{} | ||
} | ||
|
||
void bar(void) { | ||
#pragma omp assume absent(target) | ||
} // expected-error {{expected statement}} | ||
|
||
void qux(void) { | ||
#pragma omp assume extra_bits // expected-warning {{valid assume clauses start with 'ext_', 'absent', 'contains', 'holds', 'no_openmp', 'no_openmp_routines', 'no_parallelism'; token will be ignored}} | ||
{} | ||
} | ||
|
||
void quux(void) { | ||
#pragma omp assume ext_spelled_properly | ||
{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// RUN: %clang_cc1 -triple=x86_64-linux-gnu -verify -fopenmp -x c -std=c99 %s | ||
// RUN: %clang_cc1 -triple=x86_64-linux-gnu -verify -fopenmp-simd -x c -std=c99 %s | ||
|
||
[[omp::directive(assume no_openmp)]] // expected-error {{unexpected OpenMP directive '#pragma omp assume'}} | ||
|
||
void foo(void) { | ||
[[omp::directive(assume hold(1==1))]] // expected-warning {{valid assume clauses start with 'ext_', 'absent', 'contains', 'holds', 'no_openmp', 'no_openmp_routines', 'no_parallelism'; tokens will be ignored}} expected-note {{the ignored tokens spans until here}} | ||
{} | ||
} | ||
|
||
void bar(void) { | ||
[[omp::directive(assume absent(target))]] | ||
} // expected-error {{expected statement}} | ||
|
||
void qux(void) { | ||
[[omp::directive(assume extra_bits)]] // expected-warning {{valid assume clauses start with 'ext_', 'absent', 'contains', 'holds', 'no_openmp', 'no_openmp_routines', 'no_parallelism'; token will be ignored}} | ||
{} | ||
} | ||
|
||
void quux(void) { | ||
[[omp::directive(assume ext_spelled_properly)]] | ||
{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s | ||
// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s | ||
// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s | ||
// expected-no-diagnostics | ||
|
||
#ifndef HEADER | ||
#define HEADER | ||
|
||
extern int qux(int); | ||
|
||
template<typename T> | ||
int foo(T arg) | ||
{ | ||
#pragma omp assume no_openmp_routines | ||
{ | ||
auto fn = [](int x) { return qux(x); }; | ||
// CHECK: auto fn = [](int x) { | ||
return fn(5); | ||
} | ||
} | ||
|
||
template<typename T> | ||
class C { | ||
T m; | ||
|
||
public: | ||
T bar(T a); | ||
}; | ||
|
||
// We're really just checking this parses. All the assumptions are thrown | ||
// away immediately for now. | ||
template<typename T> | ||
T C<T>::bar(T a) | ||
{ | ||
#pragma omp assume holds(sizeof(T) == 8) absent(parallel) | ||
{ | ||
return (T)qux((int)a); | ||
// CHECK: return (T)qux((int)a); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters