[LLVMdev] Hoisting constant arguments from recursive functions
Jon Harrop
jon at ffconsultancy.com
Sun Jan 25 00:21:19 PST 2009
I am just considering various different designs for the code emitted by a HLVM
and one alluring approach is to make all local variables immutable and
replace loops with (tail) recursive functions. This makes it much easier to
reason about injected code such as GC checks. However, I am concerned about
the performance of the generated code.
Specifically, this is likely to result in small recursive functions that
accept a large number of arguments, many of which have values that remain the
same from one application/iteration to the next.
For example, a function to fill an array might become:
let rec fill a i x =
if i < length a then
a.(i) <- x
fill a (i + 1) x
where "a" and "x" have the same value from one call to the next and only the
loop variable "i" changes.
My question is: will LLVM optimize this back into a function containing a loop
that runs inside a single stack frame that contains the constants "a" and "x"
or should my compiler perform this rewrite itself?
Also, would any simple rearrangements help LLVM, such as putting the constant
function arguments to the back of the argument list?
--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e
More information about the llvm-dev
mailing list