clang 20.0.0git
|
Representation of an OpenMP canonical loop. More...
#include "clang/AST/StmtOpenMP.h"
Public Member Functions | |
SourceLocation | getBeginLoc () const |
SourceLocation | getEndLoc () const |
child_range | children () |
Return this AST node's children. | |
const_child_range | children () const |
Stmt * | getLoopStmt () |
The wrapped syntactic loop statement (ForStmt or CXXForRangeStmt). | |
const Stmt * | getLoopStmt () const |
void | setLoopStmt (Stmt *S) |
CapturedStmt * | getDistanceFunc () |
The function that computes the number of loop iterations. | |
const CapturedStmt * | getDistanceFunc () const |
void | setDistanceFunc (CapturedStmt *S) |
CapturedStmt * | getLoopVarFunc () |
The function that computes the loop user variable from a logical iteration counter. | |
const CapturedStmt * | getLoopVarFunc () const |
void | setLoopVarFunc (CapturedStmt *S) |
DeclRefExpr * | getLoopVarRef () |
Reference to the loop user variable as accessed in the loop body. | |
const DeclRefExpr * | getLoopVarRef () const |
void | setLoopVarRef (DeclRefExpr *E) |
Public Member Functions inherited from clang::Stmt | |
void * | operator new (size_t bytes, const ASTContext &C, unsigned alignment=8) |
void * | operator new (size_t bytes, const ASTContext *C, unsigned alignment=8) |
void * | operator new (size_t bytes, void *mem) noexcept |
void | operator delete (void *, const ASTContext &, unsigned) noexcept |
void | operator delete (void *, const ASTContext *, unsigned) noexcept |
void | operator delete (void *, size_t) noexcept |
void | operator delete (void *, void *) noexcept |
Stmt ()=delete | |
Stmt (const Stmt &)=delete | |
Stmt (Stmt &&)=delete | |
Stmt & | operator= (const Stmt &)=delete |
Stmt & | operator= (Stmt &&)=delete |
Stmt (StmtClass SC) | |
StmtClass | getStmtClass () const |
const char * | getStmtClassName () const |
SourceRange | getSourceRange () const LLVM_READONLY |
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpreted by SourceManager. | |
SourceLocation | getBeginLoc () const LLVM_READONLY |
SourceLocation | getEndLoc () const LLVM_READONLY |
void | dump () const |
Dumps the specified AST fragment and all subtrees to llvm::errs() . | |
void | dump (raw_ostream &OS, const ASTContext &Context) const |
int64_t | getID (const ASTContext &Context) const |
void | dumpColor () const |
dumpColor - same as dump(), but forces color highlighting. | |
void | dumpPretty (const ASTContext &Context) const |
dumpPretty/printPretty - These two methods do a "pretty print" of the AST back to its original source language syntax. | |
void | printPretty (raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const |
void | printPrettyControlled (raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const |
void | printJson (raw_ostream &Out, PrinterHelper *Helper, const PrintingPolicy &Policy, bool AddQuotes) const |
Pretty-prints in JSON format. | |
void | viewAST () const |
viewAST - Visualize an AST rooted at this Stmt* using GraphViz. | |
Stmt * | IgnoreContainers (bool IgnoreCaptured=false) |
Skip no-op (attributed, compound) container stmts and skip captured stmt at the top, if IgnoreCaptured is true. | |
const Stmt * | IgnoreContainers (bool IgnoreCaptured=false) const |
const Stmt * | stripLabelLikeStatements () const |
Strip off all label-like statements. | |
Stmt * | stripLabelLikeStatements () |
child_range | children () |
const_child_range | children () const |
child_iterator | child_begin () |
child_iterator | child_end () |
const_child_iterator | child_begin () const |
const_child_iterator | child_end () const |
void | Profile (llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const |
Produce a unique representation of the given statement. | |
void | ProcessODRHash (llvm::FoldingSetNodeID &ID, ODRHash &Hash) const |
Calculate a unique representation for a statement that is stable across compiler invocations. | |
Static Public Member Functions | |
static OMPCanonicalLoop * | create (const ASTContext &Ctx, Stmt *LoopStmt, CapturedStmt *DistanceFunc, CapturedStmt *LoopVarFunc, DeclRefExpr *LoopVarRef) |
Create a new OMPCanonicalLoop. | |
static OMPCanonicalLoop * | createEmpty (const ASTContext &Ctx) |
Create an empty OMPCanonicalLoop for deserialization. | |
static bool | classof (const Stmt *S) |
Static Public Member Functions inherited from clang::Stmt | |
static void | addStmtClass (const StmtClass s) |
static void | EnableStatistics () |
static void | PrintStats () |
static Likelihood | getLikelihood (ArrayRef< const Attr * > Attrs) |
static Likelihood | getLikelihood (const Stmt *S) |
static const Attr * | getLikelihoodAttr (const Stmt *S) |
static Likelihood | getLikelihood (const Stmt *Then, const Stmt *Else) |
static std::tuple< bool, const Attr *, const Attr * > | determineLikelihoodConflict (const Stmt *Then, const Stmt *Else) |
Friends | |
class | ASTStmtReader |
class | ASTStmtWriter |
Representation of an OpenMP canonical loop.
OpenMP 1.0 C/C++, section 2.4.1 for Construct; canonical-shape OpenMP 2.0 C/C++, section 2.4.1 for Construct; canonical-shape OpenMP 2.5, section 2.5.1 Loop Construct; canonical form OpenMP 3.1, section 2.5.1 Loop Construct; canonical form OpenMP 4.0, section 2.6 Canonical Loop Form OpenMP 4.5, section 2.6 Canonical Loop Form OpenMP 5.0, section 2.9.1 Canonical Loop Form OpenMP 5.1, section 2.11.1 Canonical Loop Nest Form
An OpenMP canonical loop is a for-statement or range-based for-statement with additional requirements that ensure that the number of iterations is known before entering the loop and allow skipping to an arbitrary iteration. The OMPCanonicalLoop AST node wraps a ForStmt or CXXForRangeStmt that is known to fulfill OpenMP's canonical loop requirements because of being associated to an OMPLoopBasedDirective. That is, the general structure is:
OMPLoopBasedDirective [- CapturedStmt ] [
- CapturedDecl] OMPCanonicalLoop
- ForStmt/CXXForRangeStmt `- Stmt
One or multiple CapturedStmt/CapturedDecl pairs may be inserted by some directives such as OMPParallelForDirective, but others do not need them (such as OMPTileDirective). In The OMPCanonicalLoop and ForStmt/CXXForRangeStmt pair is repeated for loop associated with the directive. A OMPCanonicalLoop must not appear in the AST unless associated with a OMPLoopBasedDirective. In an imperfectly nested loop nest, the OMPCanonicalLoop may also be wrapped in a CompoundStmt:
[...] OMPCanonicalLoop
- ForStmt/CXXForRangeStmt `- CompoundStmt |- Leading in-between code (if any) |- OMPCanonicalLoop | - ForStmt/CXXForRangeStmt |
- ... `- Trailing in-between code (if any)
The leading/trailing in-between code must not itself be a OMPCanonicalLoop to avoid confusion which loop belongs to the nesting.
There are three different kinds of iteration variables for different purposes:
This AST node provides two captured statements:
These captured statements provide the link between C/C++ semantics and the logical iteration counters used by the OpenMPIRBuilder which is language-agnostic and therefore does not know e.g. how to advance a random-access iterator. The OpenMPIRBuilder will use this information to apply simd, workshare-loop, distribute, taskloop and loop directives to the loop. For compatibility with the non-OpenMPIRBuilder codegen path, an OMPCanonicalLoop can itself also be wrapped into the CapturedStmts of an OMPLoopDirective and skipped when searching for the associated syntactical loop.
Example: std::vector<std::string> Container{1,2,3}; for (std::string Str : Container) Body(Str);
which is syntactic sugar for approximately: auto &&__range = Container; auto __begin = std::begin(__range); auto __end = std::end(__range); for (; __begin != __end; ++__begin) { std::String Str = *__begin; Body(Str); }
In this example, the loop user variable is Str
, the loop iteration variable is __begin
of type std::vector<std::string>::iterator
and the logical iteration number type is size_t
(unsigned version of std::vector<std::string>::iterator::difference_type
aka ptrdiff_t
). Therefore, the distance function will be [&](size_t &Result) { Result = __end - __begin; }
and the loop variable function is [&,__begin](std::vector<std::string>::iterator &Result, size_t Logical) { Result = __begin + Logical; }
The variable __begin
, aka the loop iteration variable, is captured by value because it is modified in the loop body, but both functions require the initial value. The OpenMP specification explicitly leaves unspecified when the loop expressions are evaluated such that a capture by reference is sufficient.
Definition at line 142 of file StmtOpenMP.h.
|
inline |
Return this AST node's children.
Definition at line 189 of file StmtOpenMP.h.
|
inline |
Definition at line 192 of file StmtOpenMP.h.
Definition at line 180 of file StmtOpenMP.h.
|
inlinestatic |
Create a new OMPCanonicalLoop.
Definition at line 163 of file StmtOpenMP.h.
Referenced by clang::SemaOpenMP::ActOnOpenMPCanonicalLoop().
|
inlinestatic |
Create an empty OMPCanonicalLoop for deserialization.
Definition at line 176 of file StmtOpenMP.h.
|
inline |
Definition at line 184 of file StmtOpenMP.h.
References clang::Stmt::getBeginLoc(), and getLoopStmt().
|
inline |
The function that computes the number of loop iterations.
Can be evaluated before entering the loop but after the syntactical loop's init statement(s).
Function signature: void(LogicalTy &Result) Any values necessary to compute the distance are captures of the closure.
Definition at line 215 of file StmtOpenMP.h.
|
inline |
Definition at line 218 of file StmtOpenMP.h.
|
inline |
Definition at line 185 of file StmtOpenMP.h.
References clang::Stmt::getEndLoc(), and getLoopStmt().
|
inline |
The wrapped syntactic loop statement (ForStmt or CXXForRangeStmt).
Definition at line 199 of file StmtOpenMP.h.
Referenced by getBeginLoc(), and getEndLoc().
|
inline |
Definition at line 200 of file StmtOpenMP.h.
|
inline |
The function that computes the loop user variable from a logical iteration counter.
Can be evaluated as first statement in the loop.
Function signature: void(LoopVarTy &Result, LogicalTy Number) Any other values required to compute the loop user variable (such as start value, step size) are captured by the closure. In particular, the initial value of loop iteration variable is captured by value to be unaffected by previous iterations.
Definition at line 236 of file StmtOpenMP.h.
|
inline |
Definition at line 239 of file StmtOpenMP.h.
|
inline |
Reference to the loop user variable as accessed in the loop body.
Definition at line 250 of file StmtOpenMP.h.
|
inline |
Definition at line 253 of file StmtOpenMP.h.
|
inline |
Definition at line 221 of file StmtOpenMP.h.
|
inline |
Definition at line 201 of file StmtOpenMP.h.
|
inline |
Definition at line 242 of file StmtOpenMP.h.
|
inline |
Definition at line 256 of file StmtOpenMP.h.
References E.
|
friend |
Definition at line 143 of file StmtOpenMP.h.
|
friend |
Definition at line 144 of file StmtOpenMP.h.