Tomas Lindquist Olsen
2007-Aug-20 04:17 UTC
[LLVMdev] Problem with missing support for non-zero contant initializers.
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
Ralph Corderoy
2007-Aug-20 11:45 UTC
[LLVMdev] Problem with missing support for non-zero contant initializers.
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 sekAnton'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.
Nick Lewycky
2007-Aug-20 18:11 UTC
[LLVMdev] Problem with missing support for non-zero contant initializers.
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
Duncan Sands
2007-Aug-20 19:03 UTC
[LLVMdev] Problem with missing support for non-zero contant initializers.
> > 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.
Chris Lattner
2007-Aug-20 19:13 UTC
[LLVMdev] Problem with missing support for non-zero contant initializers.
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/
Tomas Lindquist Olsen
2007-Aug-20 19:17 UTC
[LLVMdev] Problem with missing support for non-zero contant initializers.
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
Apparently Analagous Threads
- [LLVMdev] Problem with missing support for non-zero contant initializers.
- [LLVMdev] Problem with missing support for non-zero contant initializers.
- [LLVMdev] Problem with missing support for non-zero contant initializers.
- [LLVMdev] Problem with missing support for non-zero contant initializers.
- [LLVMdev] Problem with missing support for non-zero contant initializers.