Skip to content

Commit 3e2194f

Browse files
committed
[clang][SME] Emit error for OpemMP captured regions in streaming functions
Currently, these generate incorrect code, as streaming attributes are not propagated to the outlined function. As we've yet to work on mixing OpenMP and streaming functions (and determine how they should interact with OpenMP's runtime), we think it is best to disallow this for now.
1 parent 038b42b commit 3e2194f

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,6 +3864,8 @@ def err_sme_definition_using_za_in_non_sme_target : Error<
38643864
"function using ZA state requires 'sme'">;
38653865
def err_sme_definition_using_zt0_in_non_sme2_target : Error<
38663866
"function using ZT0 state requires 'sme2'">;
3867+
def err_sme_openmp_captured_region : Error<
3868+
"OpenMP captured regions are not yet supported in streaming functions">;
38673869
def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning<
38683870
"%select{returning|passing}0 a VL-dependent argument %select{from|to}0 a function with a different"
38693871
" streaming-mode is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime">,

clang/lib/Sema/SemaStmt.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4568,9 +4568,23 @@ buildCapturedStmtCaptureList(Sema &S, CapturedRegionScopeInfo *RSI,
45684568
return false;
45694569
}
45704570

4571+
static bool
4572+
isOpenMPCapturedRegionInArmStreamingFunction(Sema const &S,
4573+
CapturedRegionKind Kind) {
4574+
if (!S.getLangOpts().OpenMP || Kind != CR_OpenMP)
4575+
return false;
4576+
FunctionDecl *FD = S.getCurFunctionDecl(/*AllowLambda=*/true);
4577+
if (!FD)
4578+
return false;
4579+
return IsArmStreamingFunction(FD, /*IncludeLocallyStreaming=*/true);
4580+
}
4581+
45714582
void Sema::ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
45724583
CapturedRegionKind Kind,
45734584
unsigned NumParams) {
4585+
if (isOpenMPCapturedRegionInArmStreamingFunction(*this, Kind))
4586+
Diag(Loc, diag::err_sme_openmp_captured_region);
4587+
45744588
CapturedDecl *CD = nullptr;
45754589
RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, NumParams);
45764590

@@ -4602,6 +4616,9 @@ void Sema::ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
46024616
CapturedRegionKind Kind,
46034617
ArrayRef<CapturedParamNameType> Params,
46044618
unsigned OpenMPCaptureLevel) {
4619+
if (isOpenMPCapturedRegionInArmStreamingFunction(*this, Kind))
4620+
Diag(Loc, diag::err_sme_openmp_captured_region);
4621+
46054622
CapturedDecl *CD = nullptr;
46064623
RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, Params.size());
46074624

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fopenmp -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fopenmp -fsyntax-only -verify=expected-cpp -x c++ %s
3+
4+
int compute(int);
5+
6+
void streaming_openmp_captured_region(int* out) __arm_streaming
7+
{
8+
// expected-error@+2 {{OpenMP captured regions are not yet supported in streaming functions}}
9+
// expected-cpp-error@+1 {{OpenMP captured regions are not yet supported in streaming functions}}
10+
#pragma omp parallel for num_threads(32)
11+
for(int ci =0;ci< 8;ci++)
12+
{
13+
out[ci] =compute(ci);
14+
}
15+
}
16+
17+
__arm_locally_streaming void locally_streaming_openmp_captured_region(int* out)
18+
{
19+
// expected-error@+2 {{OpenMP captured regions are not yet supported in streaming functions}}
20+
// expected-cpp-error@+1 {{OpenMP captured regions are not yet supported in streaming functions}}
21+
#pragma omp parallel for num_threads(32)
22+
for(int ci =0;ci< 8;ci++)
23+
{
24+
out[ci] = compute(ci);
25+
}
26+
}
27+
28+
/// OpenMP directives that don't create a captured region are okay:
29+
30+
void streaming_function_openmp(int* out) __arm_streaming
31+
{
32+
#pragma omp unroll full
33+
for(int ci =0;ci< 8;ci++)
34+
{
35+
out[ci] =compute(ci);
36+
}
37+
}
38+
39+
__arm_locally_streaming void locally_streaming_openmp(int* out)
40+
{
41+
#pragma omp unroll full
42+
for(int ci =0;ci< 8;ci++)
43+
{
44+
out[ci] = compute(ci);
45+
}
46+
}

0 commit comments

Comments
 (0)