clangupc / upc2c

Clang based UPC to C Translator
https://clangupc.github.io/clang-upc2c
Other
4 stars 3 forks source link

fold multi-dimensional array access #86

Closed PHHargrove closed 10 years ago

PHHargrove commented 10 years ago

Given

shared [4] double A[3][5];
shared [4] double *ref(int i, int j) { return & A[i][j]; }

the current translation is

return upcr_add_shared(upcr_add_shared(A, 8UL, ((i) * 5UL), 4UL), 8UL, j, 4UL);

However, since the elemsz (8UL) and blockelems (4UL) agree between the two calls, they can be merged to yield the following:

return upcr_add_shared(A, 8UL, ((i) * 5UL) + j, 4UL);

The same holds true for nested upcr_add_pshared1 or upcr_add_psharedI calls as long as the elemsz values agree (there is no blockelems in these cases)

I will be looking at this if I have time.

PHHargrove commented 10 years ago

While doing this work I found the logic related to PTS address arithmetic was using int for internal representation of both the element size and layout qualifier of array types. I widened the ElementSize of ArrayDimensionT to be int64_t and thus match the internal rep of CharUnits which Clang uses for most sizeof-like purposes. The layout qualifier was already stored in the AST as a uint32_t, and so I changed the type of several temporaries to match.

The type changes seemed sufficiently non-controversial that I've committed them to master.. As a result I've rebased my work on this issue (as a new branch) to use the corrected types: https://github.com/PHHargrove/upc2c/compare/issue-86-v2

I am sufficiently comfortable with what I've done that I will commit to master by the end of today unless there is some objection raised.