Download Nios II C2H Compiler User Guide

Transcript
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.
Example 3–28 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;
Figure 3–15 shows the dependency graph for Example 3–29, 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;
}
3–34
Nios II C2H Compiler User Guide
9.1
Altera Corporation
November 2009