[llvm-commits] llvm-gcc: support arrays with non-zero lower bound

Duncan Sands baldrick at free.fr
Wed Feb 28 10:14:08 PST 2007


Ada arrays need not be indexed from zero: the indexing can
start from any number, positive or negative.  While some
parts of llvm-gcc had support for non-zero lower bounds,
not everywhere did.  This patch adds consistent support
everywhere.  Also, it considers an array to have dynamic
size if the length is not constant, rather than when the
maximum index is not constant, which is the current test.
Thus an array with index range n..n+4 is considered to
have length 5, a constant [*].  This notion of array size
is also used consistently everywhere.

The impact on non-Ada code should be insignificant.
The potential additional costs come from: (1) converting
array bounds to sizetype; (2) having gcc subtract off
the lower bound; and (3) having gcc add one.  In C it
seems that array bounds are already of type sizetype
(I added an assert and it didn't trigger when building
the C compiler); fold_convert instantly exits in this
case, so the cost of (1) is infinitesimal.  In C the
lower bound is always 0; size_binop does a quick
return in this case, so the cost of (2) is also
infinitesimal.  For C, (3) involves adding one to a
constant, which does not involve any heavy operations
like memory allocation, just a two word integer plus
operation.  So this can also be considered to be zero.

The attachment array_test.diff adds an LLVM testcase
to test/AdaFrontend.  This is currently useless since
the Ada compiler does not build.  There is also no LLVM
build support for test/AdaFrontend yet.

Best wishes,

Duncan.

[*] this optimization is currently of no benefit to
the Ada compiler: it generates n..max(n-1,n+4) as
the array bounds.  Fold fails to simplify max(n-1,n+4)
to n+4 for obscure reasons which I am looking into
(a fold guru tells me it is supposed to work).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arrays.diff
Type: text/x-diff
Size: 9081 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20070228/f405f91d/attachment.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: array_test.diff
Type: text/x-diff
Size: 423 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20070228/f405f91d/attachment-0001.diff>


More information about the llvm-commits mailing list