User`s guide

Optional Optimizations [9]
9.1 Scalar Replacement of Aggregates
Effective with version 2.0 of the Cray XMT software, the XMT compiler provides
an optional optimization pass that performs a code transformation called scalar
replacement of aggregates. This transformation replaces C++ class objects and C
structures (aggregate data types) with collections of temporary scalar variables.
Values are copied from the aggregate to the temporary variables and back again as
needed. These scalar variables allow the compiler to perform more precise analysis in
later phases, and may enable additional optimizations and parallelization of loops.
For example, consider the following code:
class myTwoInts {
public:
int i;
int j;
};
myTwoInts foobar2(myTwoInts t, int n, int * restrict foo) {
for (int i = 0; i < n; i++) {
t.i += foo[i];
} return t;
}
Without scalar replacement the compiler cannot determine whether the references to
fields of the object t form a loop-carried dependence, thus it is unable to parallelize
this loop. By viewing the canal report you can see that the loop is not parallelized:
| myTwoInts foobar2(myTwoInts t, int n, int * restrict foo) {
| for (int i = 0; i < n; i++){
8S | t.i += foo[i];
|}
| return t;
|}
S247920 95