This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by jdoerfert on Apr 3 2020, 9:50 AM.

Details

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

Diff Detail

Event Timeline

jdoerfert created this revision.Apr 3 2020, 9:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2020, 9:50 AM
jdoerfert updated this revision to Diff 254983.Apr 3 2020, 7:21 PM

Allow the new match clauses to be used in begin/end declare variant as well (with their respective effect)

mikerice added inline comments.Apr 5 2020, 4:42 PM
clang/lib/Parse/ParseOpenMP.cpp
1829

One of the lit tests fails because this is called before semantic checks on the score expression. This function tries to evaluate the score as a constant and if it isn't will crash. Probably not specific to this change but how can we deal with that?

int foo(void);
#pragma omp begin declare variant match(implementation={vendor(score(foo()) ibm)})
#pragma omp end declare variant
llvm/lib/Frontend/OpenMP/OMPContext.cpp
161

Line too long?

252

Comment on nullptr would be nice.

jdoerfert updated this revision to Diff 255212.Apr 5 2020, 5:23 PM

Rebase and fix a problem with evaluation of non-constants

jdoerfert marked an inline comment as done.Apr 5 2020, 8:37 PM

Will fix the other two nits too.

clang/lib/Parse/ParseOpenMP.cpp
1829

Saw that too late but it's fixed now. We will ignore non-constant scores and evaluae non-constant user conditions as false. Note that both are not valid inputs we will diagnose later anyway.

mikerice accepted this revision.Apr 6 2020, 9:34 AM

Looks okay to me.

This revision is now accepted and ready to land.Apr 6 2020, 9:34 AM
This revision was automatically updated to reflect the committed changes.