This is an archive of the discontinued LLVM Phabricator instance.

[Clang][OpenMP] Allow loop-transformations with template parameters.
ClosedPublic

Authored by Meinersbur on Oct 5 2021, 12:37 AM.

Details

Summary

Clang would reject

#pragma omp for
#pragma omp tile sizes(P)
for (int i = 0; i < 128; ++i) {}

where P is a template parameter, but the loop itself is not template-dependent. Because P context-dependent, the TransformedStmt cannot be generated and therefore nullptr (until the template is instantiated). The OMPForDirective would still expect the a loop is the dependent context and trigger an error.

Fix by introducing a NumGeneratedLoops field to OMPLoopTransformation. This is used to distinguish the case where no TransformedStmt will be generated at all (e.g. #pragma omp unroll full) and template instantiation is needed. In the later case, delay resolving the iteration space like when the for-loop itself is template-dependent until the template instatiation.

A more radical solution would always delay the iteration space analysis until template instantiation, but would also break many test cases.

Diff Detail