Altera Nios II C2H Compiler User Manual
Page 74

3–34
9.1
Altera Corporation
Nios II C2H Compiler User Guide
November 2009
Scheduling
compile-time due to the possibility of aliasing. This dependency causes
the read operation from
ptr_b
to be scheduled at State 2, rather than at
State 0.
_ _
restrict
_ _
Pointer Type Qualifier to Break Dependencies
If you know that a pointer never overlaps with another, you can inform
the compiler by declaring the pointer to be a restricted pointer. The
restrict
type qualifier is introduced in the ISO C 99 specification. The
compiler ignores any or all aliasing implications of a pointer qualified by
_ _ restrict_ _
. The C99 specification states that if a pointer “p” is
declared with restrict, and another pointer “q” accesses any location also
accessed by “p,” the behavior is undefined. In other words, a restricted
pointer promises to never alias another pointer.
demonstrates several pointers declared using the
_ _ restrict_ _
type qualifier.
1
The qualifier comes after the
*
;
_ _ restrict_ _
qualifies the
pointer type, not the type that the pointer points to.
Example 3–28. Pointer Declarations with
_ _
restrict
_ _
int * _ _ restrict_ _ my_restricted_pointer_to_integer;
const int * _ _ restrict_ _ my_restricted_pointer_to_constant_integer;
int * const _ _ restrict_ _ my_constant_restricted_pointer_to_integer;
shows the dependency graph for
, which uses
the
_ _ restrict_ _
type qualifier to inform the C2H Compiler that
ptr_a
and
ptr_b
do not alias:
Example 3–29. Using
_ _
restrict
_ _
void foo(int * _ _ restrict_ _ ptr_a,
int * _ _ restrict_ _ ptr_b)
{
int a, b;
a = *ptr_a;
*ptr_a = a + 7;
b = *ptr_b;
*ptr_b = b + 8;
}