[LLVMdev] string constant propagation

Andrew Clinton andrew at sidefx.com
Wed Nov 10 16:50:09 PST 2010


I'm wondering what is the best way to handle constant propagation for 
complex types in LLVM.  For example, my language needs to be able to 
simplify expressions involving strings by precomputing (in my own 
constant propagation pass) various external function calls.  Here's an 
example program:

----------------

; ModuleID = 'LFunction'

declare i8* @"set at SS"([5 x i8])

declare void @"printf at S"([4 x i8], i8*)

define void @strings() {
entry:
   %0 = tail call i8* @"set at SS"([5 x i8] c"abcd\00") ; <i8*> [#uses=1]
   tail call void @"printf at S"([4 x i8] c"%s\0A\00", i8* %0)
   ret void
}

---------------

I can evaluate the "set at SS" call in my constant folder, which will 
return a new string array Constant.  The problem is that the folded 
strings will create a new type for every different array length.  This 
causes problems with PHINodes (all the incoming values need the same 
type) and with instructions (I need to manually overload function calls 
to take the new string size, or change i8* to the new constant array type).

Is there a clean way to handle strings as first class types LLVM, 
without the need to add new types in LLVM itself?  I'm currently working 
under the assumption that we can link with unmodified releases of the 
LLVM library.

Andrew



More information about the llvm-dev mailing list