[LLVMdev] Problem with missing support for non-zero contant initializers.
Tomas Lindquist Olsen
tomas.l.olsen at gmail.com
Sun Aug 19 21:17:45 PDT 2007
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
More information about the llvm-dev
mailing list