(SPARC) Treats pointer-valued function parameters as restricted pointers . f must be one of the following values:
Table A–46 The -xrestrict Values
Value |
Meaning |
---|---|
%all |
All pointer parameters in the entire file are treated as restricted. |
%none |
No pointer parameters in the file are treated as restricted. |
%source |
Only functions defined within the main source file are restricted. Functions defined within included files are not restricted. |
fn[,fn...] |
A comma-separated list of one or more function names. If you specify a function list, the compiler treats pointer parameters in the specified functions as restricted; Refer to the following section, A.2.175.1 Restricted Pointers, for more information. |
This command-line option can be used on its own, but it is best used with optimization. For example, the command:
%CC -xO3 -xrestrict=%all prog.cc |
treats all pointer parameters in the file prog.c as restricted pointers. The command:
%CC -xO3 -xrestrict=agc prog.cc |
treats all pointer parameters in the function agc in the file prog.c as restricted pointers.
The default is %none; specifying -xrestrict is equivalent to specifying -xrestrict=%source.
In order for a compiler to effectively perform parallel execution of a loop, it needs to determine if certain lvalues designate distinct regions of storage. Aliases are lvalues whose regions of storage are not distinct. Determining if two pointers to objects are aliases is a difficult and time consuming process because it could require analysis of the entire program. Consider function vsq() below:
extern "C" void vsq(int n, double *a, double *b) { int i; for (i=0; i<n; i++) { b[i] = a[i] * a[i]; } } |
The compiler can parallelize the execution of the different iterations of the loops if it knows that pointers a and b access different objects. If there is an overlap in objects accessed through pointers a and b then it would be unsafe for the compiler to execute the loops in parallel.
At compile time, the compiler does not know if the objects accessed by a and b overlap by simply analyzing the function vsq(); the compiler may need to analyze the whole program to get this information. You can specify that pointer-valued function parameters be treated as restricted pointers by using the following command line option: -xrestrict[=func1,...,funcn] If a function list is specified, pointer parameters in the specified functions are treated as restricted; otherwise, all pointer parameters in the entire source file are treated as restricted (not recommended). For example, -xrestrict=vsq qualifies the pointers a and b given in the example of the function vsq().
Declaring the pointer arguments as restricted states that the pointers designate distinct objects. The compiler can assume that a and b point to distinct regions of storage. With this alias information, the compiler is able to parallelize the loop.
It is critical that you use -xrestrict correctly. If pointers qualified as restricted pointers point to objects that are not distinct, the compiler can incorrectly parallelize loops resulting in undefined behavior. For example, assume that pointers a and b of function vsq() point to objects that overlap, such that b[i] and a[i+1] are the same object. If a and b are not declared as restricted pointers the loops will be executed serially. If a and b are incorrectly qualified as restricted pointers the compiler may parallelize the execution of the loops, which is not safe, because b[i+1] should only be computed after b[i] is computed