Problem with missing support for non-zero contant initializers.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with missing support for non-zero contant initializers.

Tomas Lindquist Olsen
Hi all.

I'm working on a LLVM based compiler for the D programming language by
Walter Bright.

D allows static arrays up to 16MB in size. I'm initializing global
static arrays with a constant initializer. But D requires that (per
default) static arrays are initialized with the default initializer
for the element type. For float this happens to be NaN, so I cannot
use a 'zeroinitializer'.

This is problematic as D code like:
*******************************************************************
module arrayinit;
float[32] table;
*******************************************************************

generates LLVM like:
*******************************************************************
; ModuleID = 'test/arrayinit.bc'
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
target triple = "x86_64-unknown-linux-gnu"
@_D9arrayinit5tableG32f = global [32 x float] [ float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000, float
0x7FF8000000000000, float 0x7FF8000000000000 ]              ; <[32 x
float]*> [#uses=0]
*******************************************************************

Imagine a 16MB array of this..
First, I have to allocate an array of Constant*'s the size of the
final array during compile time and initialize it properly.
Second, the .bc files become huge.
Third, the time for any of the llvm tools to work on the files is at
best *extremely slow*.

Also any array in D can have an explicit initializer. For example:
*******************************************************************
float[1024] = 3.1415;
int[10000] = 42;
*******************************************************************
and so on...

I did some simple timings on llc for arrays with different sizes and
it looks something like this:

elements / time
32k / 39 sek
16k / 9.5 sek
8k / 1.5 sek
4k / 0.3 sek
2k / 0.07 sek

So far I have only been using LLVM at the user level. And I'm not sure
how this problem should be solved. It would be really nice if there
was a way to specify something like:
*******************************************************************
@_D9arrayinit5tableG32f = global [32 x float] [ 32 x float 0x7FF8000000000000 ]
*******************************************************************

Regards,
- Tomas
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Problem with missing support for non-zero contant initializers.

Ralph Corderoy

Hi Tomas,

> I did some simple timings on llc for arrays with different sizes and
> it looks something like this:
>
> elements / time
> 32k / 39 sek
> 16k / 9.5 sek
> 8k / 1.5 sek
> 4k / 0.3 sek
> 2k / 0.07 sek

Anton's reply gives you a work around for the moment, but I'd suggest
raising a bug on the above;  there's clearly something in the
implementation that's not linear.

Cheers,


Ralph.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Problem with missing support for non-zero contant initializers.

Chris Lattner
In reply to this post by Tomas Lindquist Olsen
On Mon, 20 Aug 2007, Tomas Lindquist Olsen wrote:
> I'm working on a LLVM based compiler for the D programming language by
> Walter Bright.

Nifty.

> D allows static arrays up to 16MB in size. I'm initializing global
> static arrays with a constant initializer. But D requires that (per
> default) static arrays are initialized with the default initializer
> for the element type. For float this happens to be NaN, so I cannot
> use a 'zeroinitializer'.

Wow, this *is* bad.  I think the solution to this is to add a new
ConstantFillArray node.  It would always have array type, would take a
single Constant* value, and would give you the filled array with that
constant.  Please file a bug if you're interested.

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Problem with missing support for non-zero contant initializers.

Nick Lewycky
Chris Lattner wrote:

>> D allows static arrays up to 16MB in size. I'm initializing global
>> static arrays with a constant initializer. But D requires that (per
>> default) static arrays are initialized with the default initializer
>> for the element type. For float this happens to be NaN, so I cannot
>> use a 'zeroinitializer'.
>
> Wow, this *is* bad.  I think the solution to this is to add a new
> ConstantFillArray node.  It would always have array type, would take a
> single Constant* value, and would give you the filled array with that
> constant.  Please file a bug if you're interested.

I believe this is already bug 1324.

Nick
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Problem with missing support for non-zero contant initializers.

Duncan Sands
In reply to this post by Chris Lattner
> > D allows static arrays up to 16MB in size. I'm initializing global
> > static arrays with a constant initializer. But D requires that (per
> > default) static arrays are initialized with the default initializer
> > for the element type. For float this happens to be NaN, so I cannot
> > use a 'zeroinitializer'.
>
> Wow, this *is* bad.  I think the solution to this is to add a new
> ConstantFillArray node.  It would always have array type, would take a
> single Constant* value, and would give you the filled array with that
> constant.  Please file a bug if you're interested.

In Ada, global variables should in general be default initialized to undef
(not zero) so this could also be useful for Ada.

Ciao,

Duncan.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Problem with missing support for non-zero contant initializers.

Tomas Lindquist Olsen
In reply to this post by Chris Lattner
Thanx for all the responses, I'm very glad that this issue is not ignored.

I have submitted a bugzilla ticket for it:
http://llvm.org/bugs/show_bug.cgi?id=1616

Regards,
Tomas
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Problem with missing support for non-zero contant initializers.

Chris Lattner
In reply to this post by Duncan Sands
In that case, Ada should just use UndefValue, which should work  
today.  :)

-Chris

http://nondot.org/sabre
http://llvm.org

On Aug 20, 2007, at 12:03 PM, Duncan Sands <[hidden email]> wrote:

>>> D allows static arrays up to 16MB in size. I'm initializing global
>>> static arrays with a constant initializer. But D requires that (per
>>> default) static arrays are initialized with the default initializer
>>> for the element type. For float this happens to be NaN, so I cannot
>>> use a 'zeroinitializer'.
>>
>> Wow, this *is* bad.  I think the solution to this is to add a new
>> ConstantFillArray node.  It would always have array type, would  
>> take a
>> single Constant* value, and would give you the filled array with that
>> constant.  Please file a bug if you're interested.
>
> In Ada, global variables should in general be default initialized to  
> undef
> (not zero) so this could also be useful for Ada.
>
> Ciao,
>
> Duncan.
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Problem with missing support for non-zero contant initializers.

Chris Lattner
In reply to this post by Nick Lewycky
On Mon, 20 Aug 2007, Nick Lewycky wrote:
>> Wow, this *is* bad.  I think the solution to this is to add a new
>> ConstantFillArray node.  It would always have array type, would take a
>> single Constant* value, and would give you the filled array with that
>> constant.  Please file a bug if you're interested.
>
> I believe this is already bug 1324.

It is definitely related.  I think that ConstantFillArray should replace
ConstantAggregateZero (CAZ = CFA<0>).  PR1324 is useful when you have
structs or arrays that are not filled with the same value, for example the
string in comment #1.

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev