clang  14.0.0git
Public Member Functions | Static Public Member Functions | Friends | List of all members
clang::OMPCanonicalLoop Class Reference

Representation of an OpenMP canonical loop. More...

#include "clang/AST/StmtOpenMP.h"

Inheritance diagram for clang::OMPCanonicalLoop:
Inheritance graph
[legend]
Collaboration diagram for clang::OMPCanonicalLoop:
Collaboration graph
[legend]

Public Member Functions

SourceLocation getBeginLoc () const
 
SourceLocation getEndLoc () const
 
child_range children ()
 Return this AST node's children. More...
 
const_child_range children () const
 
StmtgetLoopStmt ()
 The wrapped syntactic loop statement (ForStmt or CXXForRangeStmt). More...
 
const StmtgetLoopStmt () const
 
void setLoopStmt (Stmt *S)
 
CapturedStmtgetDistanceFunc ()
 The function that computes the number of loop iterations. More...
 
const CapturedStmtgetDistanceFunc () const
 
void setDistanceFunc (CapturedStmt *S)
 
CapturedStmtgetLoopVarFunc ()
 The function that computes the loop user variable from a logical iteration counter. More...
 
const CapturedStmtgetLoopVarFunc () const
 
void setLoopVarFunc (CapturedStmt *S)
 
DeclRefExprgetLoopVarRef ()
 Reference to the loop user variable as accessed in the loop body. More...
 
const DeclRefExprgetLoopVarRef () 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
 
Stmtoperator= (const Stmt &)=delete
 
Stmtoperator= (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. More...
 
SourceLocation getBeginLoc () const LLVM_READONLY
 
SourceLocation getEndLoc () const LLVM_READONLY
 
void dump () const
 Dumps the specified AST fragment and all subtrees to llvm::errs(). More...
 
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. More...
 
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. More...
 
void printPretty (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. More...
 
void viewAST () const
 viewAST - Visualize an AST rooted at this Stmt* using GraphViz. More...
 
StmtIgnoreContainers (bool IgnoreCaptured=false)
 Skip no-op (attributed, compound) container stmts and skip captured stmt at the top, if IgnoreCaptured is true. More...
 
const StmtIgnoreContainers (bool IgnoreCaptured=false) const
 
const StmtstripLabelLikeStatements () const
 Strip off all label-like statements. More...
 
StmtstripLabelLikeStatements ()
 
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) const
 Produce a unique representation of the given statement. More...
 
void ProcessODRHash (llvm::FoldingSetNodeID &ID, ODRHash &Hash) const
 Calculate a unique representation for a statement that is stable across compiler invocations. More...
 

Static Public Member Functions

static OMPCanonicalLoopcreate (const ASTContext &Ctx, Stmt *LoopStmt, CapturedStmt *DistanceFunc, CapturedStmt *LoopVarFunc, DeclRefExpr *LoopVarRef)
 Create a new OMPCanonicalLoop. More...
 
static OMPCanonicalLoopcreateEmpty (const ASTContext &Ctx)
 Create an empty OMPCanonicalLoop for deserialization. More...
 
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 AttrgetLikelihoodAttr (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
 

Additional Inherited Members

- Public Types inherited from clang::Stmt
enum  StmtClass { NoStmtClass = 0 }
 
enum  Likelihood { LH_Unlikely = -1, LH_None, LH_Likely }
 The likelihood of a branch being taken. More...
 
using child_iterator = StmtIterator
 Child Iterators: All subclasses must implement 'children' to permit easy iteration over the substatements/subexpessions of an AST node. More...
 
using const_child_iterator = ConstStmtIterator
 
using child_range = llvm::iterator_range< child_iterator >
 
using const_child_range = llvm::iterator_range< const_child_iterator >
 
- Protected Types inherited from clang::Stmt
enum  { NumStmtBits = 8 }
 
enum  { NumExprBits = NumStmtBits + 5 + llvm::BitWidth<ExprDependence> }
 
enum  { NumCallExprBits = 32 }
 
enum  { NumOverloadExprBits = NumExprBits + 1 }
 
template<typename T >
using ConstCastIterator = CastIterator< T, const T *const, const Stmt *const >
 Const iterator for iterating over Stmt * arrays that contain only T *. More...
 
using ExprIterator = CastIterator< Expr >
 
using ConstExprIterator = ConstCastIterator< Expr >
 
- Protected Member Functions inherited from clang::Stmt
void * operator new (size_t bytes) noexcept
 
void operator delete (void *data) noexcept
 
 Stmt (StmtClass SC, EmptyShell)
 Construct an empty statement. More...
 
- Protected Attributes inherited from clang::Stmt
union {
   StmtBitfields   StmtBits
 
   NullStmtBitfields   NullStmtBits
 
   CompoundStmtBitfields   CompoundStmtBits
 
   LabelStmtBitfields   LabelStmtBits
 
   AttributedStmtBitfields   AttributedStmtBits
 
   IfStmtBitfields   IfStmtBits
 
   SwitchStmtBitfields   SwitchStmtBits
 
   WhileStmtBitfields   WhileStmtBits
 
   DoStmtBitfields   DoStmtBits
 
   ForStmtBitfields   ForStmtBits
 
   GotoStmtBitfields   GotoStmtBits
 
   ContinueStmtBitfields   ContinueStmtBits
 
   BreakStmtBitfields   BreakStmtBits
 
   ReturnStmtBitfields   ReturnStmtBits
 
   SwitchCaseBitfields   SwitchCaseBits
 
   ExprBitfields   ExprBits
 
   ConstantExprBitfields   ConstantExprBits
 
   PredefinedExprBitfields   PredefinedExprBits
 
   DeclRefExprBitfields   DeclRefExprBits
 
   FloatingLiteralBitfields   FloatingLiteralBits
 
   StringLiteralBitfields   StringLiteralBits
 
   CharacterLiteralBitfields   CharacterLiteralBits
 
   UnaryOperatorBitfields   UnaryOperatorBits
 
   UnaryExprOrTypeTraitExprBitfields   UnaryExprOrTypeTraitExprBits
 
   ArrayOrMatrixSubscriptExprBitfields   ArrayOrMatrixSubscriptExprBits
 
   CallExprBitfields   CallExprBits
 
   MemberExprBitfields   MemberExprBits
 
   CastExprBitfields   CastExprBits
 
   BinaryOperatorBitfields   BinaryOperatorBits
 
   InitListExprBitfields   InitListExprBits
 
   ParenListExprBitfields   ParenListExprBits
 
   GenericSelectionExprBitfields   GenericSelectionExprBits
 
   PseudoObjectExprBitfields   PseudoObjectExprBits
 
   SourceLocExprBitfields   SourceLocExprBits
 
   StmtExprBitfields   StmtExprBits
 
   CXXOperatorCallExprBitfields   CXXOperatorCallExprBits
 
   CXXRewrittenBinaryOperatorBitfields   CXXRewrittenBinaryOperatorBits
 
   CXXBoolLiteralExprBitfields   CXXBoolLiteralExprBits
 
   CXXNullPtrLiteralExprBitfields   CXXNullPtrLiteralExprBits
 
   CXXThisExprBitfields   CXXThisExprBits
 
   CXXThrowExprBitfields   CXXThrowExprBits
 
   CXXDefaultArgExprBitfields   CXXDefaultArgExprBits
 
   CXXDefaultInitExprBitfields   CXXDefaultInitExprBits
 
   CXXScalarValueInitExprBitfields   CXXScalarValueInitExprBits
 
   CXXNewExprBitfields   CXXNewExprBits
 
   CXXDeleteExprBitfields   CXXDeleteExprBits
 
   TypeTraitExprBitfields   TypeTraitExprBits
 
   DependentScopeDeclRefExprBitfields   DependentScopeDeclRefExprBits
 
   CXXConstructExprBitfields   CXXConstructExprBits
 
   ExprWithCleanupsBitfields   ExprWithCleanupsBits
 
   CXXUnresolvedConstructExprBitfields   CXXUnresolvedConstructExprBits
 
   CXXDependentScopeMemberExprBitfields   CXXDependentScopeMemberExprBits
 
   OverloadExprBitfields   OverloadExprBits
 
   UnresolvedLookupExprBitfields   UnresolvedLookupExprBits
 
   UnresolvedMemberExprBitfields   UnresolvedMemberExprBits
 
   CXXNoexceptExprBitfields   CXXNoexceptExprBits
 
   SubstNonTypeTemplateParmExprBitfields   SubstNonTypeTemplateParmExprBits
 
   LambdaExprBitfields   LambdaExprBits
 
   RequiresExprBitfields   RequiresExprBits
 
   CoawaitExprBitfields   CoawaitBits
 
   ObjCIndirectCopyRestoreExprBitfields   ObjCIndirectCopyRestoreExprBits
 
   OpaqueValueExprBitfields   OpaqueValueExprBits
 
}; 
 

Detailed 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:

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.

Member Function Documentation

◆ children() [1/2]

child_range clang::OMPCanonicalLoop::children ( )
inline

Return this AST node's children.

Definition at line 189 of file StmtOpenMP.h.

◆ children() [2/2]

const_child_range clang::OMPCanonicalLoop::children ( ) const
inline

Definition at line 192 of file StmtOpenMP.h.

◆ classof()

static bool clang::OMPCanonicalLoop::classof ( const Stmt S)
inlinestatic

Definition at line 180 of file StmtOpenMP.h.

◆ create()

static OMPCanonicalLoop* clang::OMPCanonicalLoop::create ( const ASTContext Ctx,
Stmt LoopStmt,
CapturedStmt DistanceFunc,
CapturedStmt LoopVarFunc,
DeclRefExpr LoopVarRef 
)
inlinestatic

Create a new OMPCanonicalLoop.

Definition at line 163 of file StmtOpenMP.h.

Referenced by clang::Sema::ActOnOpenMPCanonicalLoop().

◆ createEmpty()

static OMPCanonicalLoop* clang::OMPCanonicalLoop::createEmpty ( const ASTContext Ctx)
inlinestatic

Create an empty OMPCanonicalLoop for deserialization.

Definition at line 176 of file StmtOpenMP.h.

◆ getBeginLoc()

SourceLocation clang::OMPCanonicalLoop::getBeginLoc ( ) const
inline

Definition at line 184 of file StmtOpenMP.h.

References clang::Stmt::getBeginLoc(), and getLoopStmt().

◆ getDistanceFunc() [1/2]

CapturedStmt* clang::OMPCanonicalLoop::getDistanceFunc ( )
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.

◆ getDistanceFunc() [2/2]

const CapturedStmt* clang::OMPCanonicalLoop::getDistanceFunc ( ) const
inline

Definition at line 218 of file StmtOpenMP.h.

◆ getEndLoc()

SourceLocation clang::OMPCanonicalLoop::getEndLoc ( ) const
inline

Definition at line 185 of file StmtOpenMP.h.

References clang::Stmt::getEndLoc(), and getLoopStmt().

◆ getLoopStmt() [1/2]

Stmt* clang::OMPCanonicalLoop::getLoopStmt ( )
inline

The wrapped syntactic loop statement (ForStmt or CXXForRangeStmt).

Definition at line 199 of file StmtOpenMP.h.

Referenced by getBeginLoc(), and getEndLoc().

◆ getLoopStmt() [2/2]

const Stmt* clang::OMPCanonicalLoop::getLoopStmt ( ) const
inline

Definition at line 200 of file StmtOpenMP.h.

◆ getLoopVarFunc() [1/2]

CapturedStmt* clang::OMPCanonicalLoop::getLoopVarFunc ( )
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.

◆ getLoopVarFunc() [2/2]

const CapturedStmt* clang::OMPCanonicalLoop::getLoopVarFunc ( ) const
inline

Definition at line 239 of file StmtOpenMP.h.

◆ getLoopVarRef() [1/2]

DeclRefExpr* clang::OMPCanonicalLoop::getLoopVarRef ( )
inline

Reference to the loop user variable as accessed in the loop body.

Definition at line 250 of file StmtOpenMP.h.

◆ getLoopVarRef() [2/2]

const DeclRefExpr* clang::OMPCanonicalLoop::getLoopVarRef ( ) const
inline

Definition at line 253 of file StmtOpenMP.h.

◆ setDistanceFunc()

void clang::OMPCanonicalLoop::setDistanceFunc ( CapturedStmt S)
inline

Definition at line 221 of file StmtOpenMP.h.

◆ setLoopStmt()

void clang::OMPCanonicalLoop::setLoopStmt ( Stmt S)
inline

Definition at line 201 of file StmtOpenMP.h.

◆ setLoopVarFunc()

void clang::OMPCanonicalLoop::setLoopVarFunc ( CapturedStmt S)
inline

Definition at line 242 of file StmtOpenMP.h.

◆ setLoopVarRef()

void clang::OMPCanonicalLoop::setLoopVarRef ( DeclRefExpr E)
inline

Definition at line 256 of file StmtOpenMP.h.

Friends And Related Function Documentation

◆ ASTStmtReader

friend class ASTStmtReader
friend

Definition at line 143 of file StmtOpenMP.h.

◆ ASTStmtWriter

friend class ASTStmtWriter
friend

Definition at line 144 of file StmtOpenMP.h.


The documentation for this class was generated from the following file: