HOME
| OPENMP API Specification: "Version 5.2 -- GIT rev 95b2e3a44"

4.4.1  Canonical Loop Nest Form

A loop nest has canonical loop nest form if it conforms to loop-nest in the following grammar:

Symbol

Meaning

  

loop-nest

One of the following:

 
for (init-exprtest-exprincr-expr
  loop-body  

or

 
for (range-declrange-expr
  loop-body  

A range-based for loop is equivalent to a regular for loop using iterators, as defined in the base language. A range-based for loop has no iteration variable.

or

 
DO [ label ] var = lb , ub [ , incr ] 
  [intervening-code] 
  loop-body 
  [intervening-code] 
[ label ] END DO  

If the loop-nest is a nonblock-do-construct, it is treated as a block-do-construct for each DO construct.

The value of incr is the increment of the loop. If not specified, its value is assumed to be 1.

or  

 
loop-transformation-construct  

or  

 
generated-canonical-loop  

loop-body

One of the following:  

 
loop-nest  

or

 

  [intervening-code] 
  loop-body 
  [intervening-code] 
}  

or

 
BLOCK 
  [intervening-code] 
  loop-body 
  [intervening-code] 
END BLOCK  

or if none of the previous productions match  

 
final-loop-body  

loop-transformation-construct

A loop transformation construct.

generated-canonical-loop

A generated loop from a loop transformation construct that has canonical loop nest form and for which the loop body matches loop-body.

intervening-code

A non-empty structured block sequence that does not contain OpenMP directives or calls to the OpenMP runtime API in its corresponding region, referred to as intervening code. If intervening code is present, then a loop at the same depth within the loop nest is not a perfectly nested loop.

It must not contain iteration statements, continue statements or break statements that apply to the enclosing loop.

It must not contain loops, array expressions, CYCLE statements or EXIT statements.

final-loop-body

A structured block that terminates the scope of loops in the loop nest. If the loop nest is associated with a loop-associated directive, loops in this structured block cannot be associated with that directive.

init-expr

One of the following:

  • var = lb
  • integer-type var = lb
  • pointer-type var = lb
  • random-access-iterator-type var = lb

test-expr

One of the following:

  • var relational-op ub
  • ub relational-op var

relational-op

One of the following:

  • <
  • <=
  • >
  • >=
  • !=

incr-expr

One of the following:

  • ++var
  • var++
  • - - var
  • var - -
  • var += incr
  • var - = incr
  • var = var + incr
  • var = incr + var
  • var = var - incr

The value of incr, respectively 1 and -1 for the increment and decrement operators, is the increment of the loop.

var

One of the following:

  • A variable of a signed or unsigned integer type.
  • A variable of a pointer type.
  • A variable of a random access iterator type.
  • A scalar variable of integer type.

var is the iteration variable of the loop. It must not be modified during the execution of intervening-code or loop-body in the loop.

lb, ub

One of the following:

Expressions of a type compatible with the type of var that are loop invariant with respect to the outermost loop.

or

One of the following:

where var-outer is of a type compatible with the type of var.

or

If var is of an integer type, one of the following:

where var-outer is of an integer type.

lb and ub are loop bounds. A loop for which lb or ub refers to var-outer is a non-rectangular loop. If var is of an integer type, var-outer must be of an integer type with the same signedness and bit precision as the type of var.

The coefficient in a loop bound is 0 if the bound does not refer to var-outer. If a loop bound matches a form in which a1 appears, the coefficient is -a1 if the product of var-outer and a1 is subtracted from a2, and otherwise the coefficient is a1. For other matched forms where a1 does not appear, the coefficient is 1 if var-outer is subtracted from a2, and otherwise the coefficient is 1.

a1, a2, incr

Integer expressions that are loop invariant with respect to the outermost loop of the loop nest.

If the loop is associated with a loop-associated directive, the expressions are evaluated before the construct formed from that directive.

var-outer

The loop iteration variable of a surrounding loop in the loop nest.

range-decl

A declaration of a variable as defined by the base language for range-based for loops.

range-expr

An expression that is valid as defined by the base language for range-based for loops. It must be invariant with respect to the outermost loop of the loop nest and the iterator derived from it must be a random access iterator.

Restrictions

Restrictions to canonical loop nests are as follows:

Cross References