[PATCH] D94973: [clang][OpenMP] Use OpenMPIRBuilder for workshare loops.

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 19 08:17:27 PST 2021


Meinersbur created this revision.
Meinersbur added reviewers: jdoerfert, AMDChirag, anchu-rajendran, kiranchandramohan, SouraVX, ftynse, kiranktp, fghanim, ABataev.
Meinersbur added projects: OpenMP, clang.
Herald added subscribers: dexonsmith, rriddle, arphaman, guansong, hiraditya, yaxunl.
Meinersbur requested review of this revision.
Herald added subscribers: llvm-commits, sstefan1, stephenneuendorffer.
Herald added a project: LLVM.

Initial support for using the OpenMPIRBuilder by clang to generate loops using the OpenMPIRBuilder. This initial support is intentionally limited to:

- Only the worksharing-loop directive.
- Recognizes only the nowait clause.
- No loop nests with more than one loop.
- Untested with templates, exceptions.
- Semantic checking left to the existing infrastructure.

This patch introduces a new AST node, OMPCanonicalLoop, which becomes parent of any loop that has to adheres to the restrictions as specified by the OpenMP standard. These restrictions allow OMPCanonicalLoop to provide the following additional information that depends on base language semantics:

- The distance function: How many loop iterations there will be before entering the loop nest.
- The loop variable function: Conversion from a logical iteration number to the loop variable.

These allow the OpenMPIRBuilder to act solely using logical iteration numbers without needing to be concerned with iterator semantics between calling the distance function and determining what the value of the loop variable ought to be. Any OpenMP logical should be done by the OpenMPIRBuilder such that it can be reused MLIR OpenMP dialect and thus by flang.

The distance and loop variable function are implemented using lambdas (or more exactly: CapturedStmt because lambda implementation is more interviewed with the parser). It is up to the OpenMPIRBuilder how they are called which depends on what is done with the loop. By default, these are emitted as outlined functions but we might think about emitting them inline as the OpenMPRuntime does.

For compatibility with the current OpenMP implementation, even though not necessary for the OpenMPIRBuilder, OMPCanonicalLoop can still be nested within OMPLoopDirectives' CapturedStmt. Although OMPCanonicalLoop's are not currently generated when the OpenMPIRBuilder is not enabled, these can just be skipped when not using the OpenMPIRBuilder in case we don't want to make the AST dependent on the EnableOMPBuilder setting.

Loop nests with more than one loop require support by the OpenMPIRBuilder (D93268 <https://reviews.llvm.org/D93268>). A simple implementation of non-rectangular loop nests would add another lambda function that returns whether a loop iteration of the rectangular overapproximation is also within its non-rectangular subset.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94973

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/Stmt.cpp
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/OpenMP/irbuilder_for_iterator.cpp
  clang/test/OpenMP/irbuilder_for_rangefor.cpp
  clang/test/OpenMP/irbuilder_for_unsigned.c
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94973.317562.patch
Type: text/x-patch
Size: 88704 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210119/4fe7080f/attachment.bin>


More information about the llvm-commits mailing list