[LLVMdev] Cloning a function

Zack Rusin zack at tungstengraphics.com
Mon Mar 3 05:21:05 PST 2008


we have two modules, one that we basically use as a library in which we store 
a lot of simple function calls, the other is small program generated at 

Whenever a function call for to one of the builtin functions is being called 
we use CloneFunction to clone the instruction from the library module and 
insert it in the generated module.

The problem is for example when we have something like:
declare float @powf(float, float)
define void @pow(<4 x float>* %res, /*other args*/...) {
	%call = tail call float @powf( float %tmp1, float %tmp3 )
while powf has a similar extern declaration in the generated module, the 
cloned function after the CloneFunction call obviously refers to the powf 
from the library module and asserts as an invalid module. To solve that we 
add a mapping to DenseMap from the powf declaration in the library module to 
the powf declaration in the generated module, as in:

DenseMap<const Value*, Value *> val;
val[m_builtins->getFunction("powf")] = currentModule()->getFunction("powf");
func = CloneFunction(originalFunc, val);

unfortunately after this we get an assert:
vp-tris: /home/zack/projects/general/llvm/lib/Target/X86/X86CodeEmitter.cpp:412: 
unsigned int sizeOfImm(const llvm::TargetInstrDesc*): Assertion `0 
&& "Immediate size not set!"' failed.

which I'm a little confused about. Any idea what might be causing this and how 
to fix it?


More information about the llvm-dev mailing list