class OMPCanonicalLoop
Declaration
class OMPCanonicalLoop : public Stmt { /* full declaration omitted */ };
Description
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: * Loop user variable: The user-accessible variable with different value for each iteration. * Loop iteration variable: The variable used to identify a loop iteration; for range-based for-statement, this is the hidden iterator '__begin'. For other loops, it is identical to the loop user variable. Must be a random-access iterator, pointer or integer type. * Logical iteration counter: Normalized loop counter starting at 0 and incrementing by one at each iteration. Allows abstracting over the type of the loop iteration variable and is always an unsigned integer type appropriate to represent the range of the loop iteration variable. Its value corresponds to the logical iteration number in the OpenMP specification. This AST node provides two captured statements: * The distance function which computes the number of iterations. * The loop user variable function that computes the loop user variable when given a logical iteration number. 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.
Declared at: clang/include/clang/AST/StmtOpenMP.h:142
Inherits from: Stmt
Member Variables
- private clang::Stmt* [4] SubStmts = {}
- This AST node's children.
Inherited from Stmt:
Method Overview
- private OMPCanonicalLoop()
- public clang::Stmt::child_range children()
- public clang::Stmt::const_child_range children() const
- public static bool classof(const clang::Stmt * S)
- public static clang::OMPCanonicalLoop * create(const clang::ASTContext & Ctx, clang::Stmt * LoopStmt, clang::CapturedStmt * DistanceFunc, clang::CapturedStmt * LoopVarFunc, clang::DeclRefExpr * LoopVarRef)
- public static clang::OMPCanonicalLoop * createEmpty(const clang::ASTContext & Ctx)
- public clang::SourceLocation getBeginLoc() const
- public const clang::CapturedStmt * getDistanceFunc() const
- public clang::CapturedStmt * getDistanceFunc()
- public clang::SourceLocation getEndLoc() const
- public const clang::Stmt * getLoopStmt() const
- public clang::Stmt * getLoopStmt()
- public clang::CapturedStmt * getLoopVarFunc()
- public const clang::CapturedStmt * getLoopVarFunc() const
- public const clang::DeclRefExpr * getLoopVarRef() const
- public clang::DeclRefExpr * getLoopVarRef()
- public void setDistanceFunc(clang::CapturedStmt * S)
- public void setLoopStmt(clang::Stmt * S)
- public void setLoopVarFunc(clang::CapturedStmt * S)
- public void setLoopVarRef(clang::DeclRefExpr * E)
Inherited from Stmt:
- public EnableStatistics
- public IgnoreContainers
- public IgnoreContainers
- public PrintStats
- public ProcessODRHash
- public Profile
- public addStmtClass
- public child_begin
- public child_begin
- public child_end
- public child_end
- public children
- public children
- public determineLikelihoodConflict
- public dump
- public dump
- public dumpColor
- public dumpPretty
- public getBeginLoc
- public getEndLoc
- public getID
- public getLikelihood
- public getLikelihood
- public getLikelihood
- public getLikelihoodAttr
- public getSourceRange
- public getStmtClass
- public getStmtClassName
- public printJson
- public printPretty
- public printPrettyControlled
- public stripLabelLikeStatements
- public stripLabelLikeStatements
- public viewAST
Methods
¶OMPCanonicalLoop()
OMPCanonicalLoop()
Declared at: clang/include/clang/AST/StmtOpenMP.h:159
¶clang::Stmt::child_range children()
clang::Stmt::child_range children()
Description
Return this AST node's children. @ {
Declared at: clang/include/clang/AST/StmtOpenMP.h:189
¶clang::Stmt::const_child_range children() const
clang::Stmt::const_child_range children() const
Declared at: clang/include/clang/AST/StmtOpenMP.h:192
¶static bool classof(const clang::Stmt* S)
static bool classof(const clang::Stmt* S)
Declared at: clang/include/clang/AST/StmtOpenMP.h:180
Parameters
- const clang::Stmt* S
¶static clang::OMPCanonicalLoop* create(
const clang::ASTContext& Ctx,
clang::Stmt* LoopStmt,
clang::CapturedStmt* DistanceFunc,
clang::CapturedStmt* LoopVarFunc,
clang::DeclRefExpr* LoopVarRef)
static clang::OMPCanonicalLoop* create(
const clang::ASTContext& Ctx,
clang::Stmt* LoopStmt,
clang::CapturedStmt* DistanceFunc,
clang::CapturedStmt* LoopVarFunc,
clang::DeclRefExpr* LoopVarRef)
Description
Create a new OMPCanonicalLoop.
Declared at: clang/include/clang/AST/StmtOpenMP.h:163
Parameters
- const clang::ASTContext& Ctx
- clang::Stmt* LoopStmt
- clang::CapturedStmt* DistanceFunc
- clang::CapturedStmt* LoopVarFunc
- clang::DeclRefExpr* LoopVarRef
¶static clang::OMPCanonicalLoop* createEmpty(
const clang::ASTContext& Ctx)
static clang::OMPCanonicalLoop* createEmpty(
const clang::ASTContext& Ctx)
Description
Create an empty OMPCanonicalLoop for deserialization.
Declared at: clang/include/clang/AST/StmtOpenMP.h:176
Parameters
- const clang::ASTContext& Ctx
¶clang::SourceLocation getBeginLoc() const
clang::SourceLocation getBeginLoc() const
Declared at: clang/include/clang/AST/StmtOpenMP.h:184
¶const clang::CapturedStmt* getDistanceFunc() const
const clang::CapturedStmt* getDistanceFunc() const
Declared at: clang/include/clang/AST/StmtOpenMP.h:218
¶clang::CapturedStmt* getDistanceFunc()
clang::CapturedStmt* getDistanceFunc()
Description
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. @ {
Declared at: clang/include/clang/AST/StmtOpenMP.h:215
¶clang::SourceLocation getEndLoc() const
clang::SourceLocation getEndLoc() const
Declared at: clang/include/clang/AST/StmtOpenMP.h:185
¶const clang::Stmt* getLoopStmt() const
const clang::Stmt* getLoopStmt() const
Declared at: clang/include/clang/AST/StmtOpenMP.h:200
¶clang::Stmt* getLoopStmt()
clang::Stmt* getLoopStmt()
Description
The wrapped syntactic loop statement (ForStmt or CXXForRangeStmt). @ {
Declared at: clang/include/clang/AST/StmtOpenMP.h:199
¶clang::CapturedStmt* getLoopVarFunc()
clang::CapturedStmt* getLoopVarFunc()
Description
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. @ {
Declared at: clang/include/clang/AST/StmtOpenMP.h:236
¶const clang::CapturedStmt* getLoopVarFunc() const
const clang::CapturedStmt* getLoopVarFunc() const
Declared at: clang/include/clang/AST/StmtOpenMP.h:239
¶const clang::DeclRefExpr* getLoopVarRef() const
const clang::DeclRefExpr* getLoopVarRef() const
Declared at: clang/include/clang/AST/StmtOpenMP.h:253
¶clang::DeclRefExpr* getLoopVarRef()
clang::DeclRefExpr* getLoopVarRef()
Description
Reference to the loop user variable as accessed in the loop body. @ {
Declared at: clang/include/clang/AST/StmtOpenMP.h:250
¶void setDistanceFunc(clang::CapturedStmt* S)
void setDistanceFunc(clang::CapturedStmt* S)
Declared at: clang/include/clang/AST/StmtOpenMP.h:221
Parameters
¶void setLoopStmt(clang::Stmt* S)
void setLoopStmt(clang::Stmt* S)
Declared at: clang/include/clang/AST/StmtOpenMP.h:201
Parameters
- clang::Stmt* S
¶void setLoopVarFunc(clang::CapturedStmt* S)
void setLoopVarFunc(clang::CapturedStmt* S)
Declared at: clang/include/clang/AST/StmtOpenMP.h:242
Parameters
¶void setLoopVarRef(clang::DeclRefExpr* E)
void setLoopVarRef(clang::DeclRefExpr* E)
Declared at: clang/include/clang/AST/StmtOpenMP.h:256