[LLVMdev] FP emulation (continued)

Roman Levenstein romixlev at yahoo.com
Tue Nov 28 05:34:19 PST 2006


Chris Lattner wrote:
> > P.S. A minor off-topic question: Is it possible to explain the LLVM
> > backend that "float" is the same type as "double" on my target? I
> > managed to explain it for immediates and also told to promote f32
> > to  f64. But it does not work for float variables or parameters,
> > because LLVM considers them to be float in any case and to have a 
> > 32bit representation in memory. Or do I need to handle this 
>> equivalence in the front-end only?
> 
> If you tell the code generator to promote f32 to f64, it will handle
> 90% of the work for you.  The remaining pieces are in the 
> lowercall/lowerarguments/lower return code, where you do need to
> specify how these are passed.  Usually just saying they are in f64 
> registers  should be enough.

Yes. I have done almost all of that already a while ago and it solves
almost all problems, as you say. But the problem is a code like:

float f;

float float_addition(float a, float b)
{
  return a+b;
}

which is translated by LLVM into:

target endian = little
target pointersize = 32
target triple = "i686-pc-linux-gnu"
deplibs = [ "c", "crtend" ]
%f = weak global float 0.000000e+00		; <float*> [#uses=0]

implementation   ; Functions:

float %float_addition(float %a, float %b) {
entry:
	%tmp.2 = add float %a, %b		; <float> [#uses=1]
	ret float %tmp.2
}

The global variable f is still considered to be "float" and therefore
occupies 4 bytes and handled as a 32bit float. Due to expansion from
f32 to f64, codegen tries to load it from a 32bit memory cell and then
expand into f64. But I have no 32bit FP type on my target and no 32bit
FP representation in memory. So, I really want "float" to be just an
alias for "double". "f" should be trated in the same way, as if it is a
64bit double. This was the reason, why I asked if something should be
done in the front-end to achieve this, additionally to the actions that
you describe. Or may be there is a way to have an LLVM pass that just
traverses the module and changes the types of all float variables to
double?

- Roman


 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com



More information about the llvm-dev mailing list