Yeah, that's the fault...got the answer...... Thanks James for the help... Struggling with this for so many days.......<br><br><div class="gmail_quote">On Thu, Sep 22, 2011 at 4:02 PM, James Molloy <span dir="ltr"><<a href="mailto:James.Molloy@arm.com">James.Molloy@arm.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div link="blue" vlink="purple" lang="EN-GB">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">Hi Sarath,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">It would have really helped if you had removed the commented out code and inlined the calls to your homemade helper functions before sending it...<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">You are doing this, in LLVM IR:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">%0 = getelementptr %Value* %firstArg, i32 0 ; i8**<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">%1 = load i8** %0 ; i8*<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">%2 = bitcast i8* %1 to i64*<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">%3 = getelementptr %Value* %secondArg, i32 0 ; i8**<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">%4 = load i8** %3; i8*<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">%5 = bitcast i8* %4 to i64*<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">%6 = load i64* %2<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">%7 = load i64* %5<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">Then you call convertDoubleToInt64(). What does this actually do?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">It’s in trouble by this point because it needs to do a fptosi on a double operand, but you’ve got an i64 operand and you can’t reinterpret-cast ints to floats
in LLVM IR (AFAIK)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">I can’t see what your code is doing afterwards as it uses calls to helper functions that you haven’t included.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">The main point I’d raise is: if your value is stored as a
<b>double</b> inside the Value structure, then why are you bitcasting to <b>i64*</b>? Why not bitcast to
<b>double</b>* then load and perform a proper fptosi?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">Cheers,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">James<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><u></u> <u></u></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt" lang="EN-US">From:</span></b><span style="font-size:10.0pt" lang="EN-US"> sarath chandra [mailto:<a href="mailto:sarathcse19@gmail.com" target="_blank">sarathcse19@gmail.com</a>]
<br>
<b>Sent:</b> 22 September 2011 11:18<br>
<b>To:</b> James Molloy; <a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a></span></p><div><div></div><div class="h5"><br>
<b>Subject:</b> Re: [LLVMdev] Need help in converting int to double<u></u><u></u></div></div><p></p>
</div><div><div></div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Thu, Sep 22, 2011 at 3:46 PM, sarath chandra <<a href="mailto:sarathcse19@gmail.com" target="_blank">sarathcse19@gmail.com</a>> wrote:<u></u><u></u></p>
<p class="MsoNormal">Hi James,<br>
<br>
First i converted the void * to int* and then did FPToSI...then did SHL...( because CreateShl only accepts integers... i pointer casted it to int64 type first)... Below is the code snippet....<br>
<br>
<br>
lhs = mBuilder.CreateStructGEP(firstArg, 0);<br>
lhs = mBuilder.CreateLoad(lhs);<br>
lhs = mBuilder.CreatePointerCast(lhs, PointerType::get(<br>
mBuilder.getInt64Ty(), 0));<br>
int typelhs = getValueType(lhs);<br>
rhs = mBuilder.CreateStructGEP(secondArg, 0);<br>
rhs = mBuilder.CreateLoad(rhs);<br>
rhs = mBuilder.CreatePointerCast(rhs, PointerType::get(<br>
mBuilder.getInt64Ty(), 0));<br>
<br>
lhs = mBuilder.CreateLoad(lhs);<br>
rhs = mBuilder.CreateLoad(rhs);<br>
<br>
lhs = convertDoubleToInt64(lhs); // used FPToSI<br>
rhs = convertDoubleToInt64(rhs);// " "<br>
<br>
//lhs = mBuilder.CreateLoad(lhs);<br>
//rhs = mBuilder.CreateLoad(rhs);<br>
<br>
lhs = mBuilder.CreateShl(lhs, rhs);<br>
//lhs = mBuilder.CreatePointerCast(lhs, PointerType::get(mBuilder.getDoubleTy(),0));<br>
lhs = convertIntToDouble(lhs);<br>
typelhs = getValueType(lhs);<br>
<br>
<br>
<br>
llvm::Value* returnValue = mBuilder.CreateAlloca(PointerType::get(<br>
mModule->getTypeByName("Value"), 0));<br>
<br>
llvm::Value* valueStructSize = getValueStructSize();<br>
llvm::Value* memory = insertCallToMalloc(valueStructSize);<br>
<br>
memory = mBuilder.CreatePointerCast(memory, PointerType::get(<br>
mModule->getTypeByName("Value"), 0));<br>
<br>
mBuilder.CreateStore(memory, returnValue);<br>
<br>
allocateAndAssignDoubleTypeVar(mBuilder.CreateLoad(returnValue), lhs);<br>
<br>
//return the value<br>
mBuilder.CreateRet(mBuilder.CreateLoad(returnValue));<br>
<br>
<br>
/*<br>
* create call to SHL function<br>
*/<br>
mCurrentFunction = previousFunction;<br>
mBuilder.SetInsertPoint(previousBlock);<br>
<br>
return mBuilder.CreateCall2(shlFunction, aLHS, aRHS);<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
<br>
<u></u><u></u></p>
<div>
<p class="MsoNormal">On Thu, Sep 22, 2011 at 3:40 PM, James Molloy <<a href="mailto:James.Molloy@arm.com" target="_blank">James.Molloy@arm.com</a>> wrote:<u></u><u></u></p>
<p class="MsoNormal">Hi Sarath,<br>
<br>
Your example will break.<br>
<br>
If the values are held internally as doubles casted to void* (which incidentally will only work on 64-bit systems), just casting void* -> int* will not get you a valid integer value. It will get you the double's internal representation as an integer. For example
(actual values are made up):<br>
<br>
double a = 42.0;<br>
void *v = (void*)&a;<br>
int b = *(int*)v;<br>
<br>
"b" will not contain 42. It will contain what looks like random garbage (although it is the IEE754 floating point representation of "42.0").<br>
<br>
You need to perform an actual cast:<br>
<br>
double a = 42.0;<br>
void *v = (void*)&a;<br>
double b = *(double*)v;<br>
int c = (int)b;<br>
<br>
"c" will contain 42.<br>
<br>
In LLVM speak, you need to LOAD as a double*, perform a fptosi to create an int64, perform the shift, then sitofp and store:<br>
<br>
%1 = load bitcast i8* %arg0 to double* ; Cast the void* to double*, then load it.<br>
%2 = load bitcast i8* %arg1 to double*<br>
<br>
%3 = fptosi double %1 to i64 ; Perform explicit double -> int conversion.<br>
%4 = fptosi double %2 to i64<br>
<br>
%5 = shr i64 %3, %4 ; Perform your operation.<br>
<br>
%6 = sitofp i64 %5 to double ; Convert explicitly back to integer representation.<br>
<br>
%7 = store bitcast i8* %dest to double*, double %6 ; Store back, reinterpreting your void* (which is i8* in LLVM) as a double*.<br>
<br>
<br>
Hopefully this makes sense, especially if you know how you would have to do it in C.<br>
<br>
Cheers,<br>
<br>
James<br>
<br>
From: sarath chandra [mailto:<a href="mailto:sarathcse19@gmail.com" target="_blank">sarathcse19@gmail.com</a>]<br>
Sent: 22 September 2011 10:49<br>
To: James Molloy<br>
Subject: Re: [LLVMdev] Need help in converting int to double<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
Hi James,<br>
<br>
CreateShl() accepts only integers or vectors as arguments. At the starting my arguments , let us suppose LHS,RHS, are double values. To pass them as arguments to CreateShl(), i used Pointer Casting to convert the Void* to Int*. Now the problem is after getting
the result is, the result variable which captures the output is Int*.. i wanted to make it Double*..(so that i can accomadate it in value structure)<br>
On Thu, Sep 22, 2011 at 3:12 PM, James Molloy <<a href="mailto:James.Molloy@arm.com" target="_blank">James.Molloy@arm.com</a>> wrote:<br>
Hi Sarath,<br>
<br>
If you can only hold doubles (not integers), and you originally converted the doubles to integers to do an integer shift, why can you not just convert the result back to a double using CreateFPToSI ?<br>
<br>
CreateFPToSI(CreateShr(CreateSIToFP(arg0), CreateSIToFP(arg1)))<br>
<br>
Cheers,<br>
<br>
James<br>
<br>
From: <a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank">llvmdev-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank">llvmdev-bounces@cs.uiuc.edu</a>] On Behalf Of sarath chandra<br>
Sent: 22 September 2011 10:37<br>
To: <a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a><br>
Subject: [LLVMdev] Need help in converting int to double<br>
<br>
Hi,<br>
<br>
I'm pursuing M.Tech course. As a part of the project work i'm using LLVM as back-end. My project area is "Enhancing the performance of V8 javascript engine using LLVM as a back-end".<br>
<br>
Now i'm writing code for shift left(SHL) operator. I had my own Value Structure .. it's like this<br>
<br>
Struct Value<br>
{<br>
void *val ;<br>
char type;<br>
}<br>
<br>
The "char type" holds DoubleType,DoubleConst,StringType,StringConst...<br>
<br>
when i'm executing the IrBuilder.CreateShl(LHS,RHS) instruction it is returning an integer value as output.. i'm unable to store the value in my structure....(because my structure can hold Doubles,Strings).<br>
<br>
Is there any way to store the integer output in my structure( i used CreateSIToFP() to change int to double)........<br>
<br>
Thanks in advance<br>
<br>
Regards,<br>
<br>
(¨`·.·´¨)<br>
`·.¸(¨`·.·´¨)<br>
(¨`·.·´¨)¸.·´ Sarath!!!<br>
`·.¸.·´<br>
<br>
-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any
purpose, or store or copy the information in any medium. Thank you.<br>
<br>
<br>
<br>
--<br>
Sairam,<br>
<br>
(¨`·.·´¨)<br>
`·.¸(¨`·.·´¨)<br>
(¨`·.·´¨)¸.·´ Sarath!!!<br>
`·.¸.·´<br>
<br>
-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any
purpose, or store or copy the information in any medium. Thank you.<u></u><u></u></p>
</div>
</div>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><span style="color:#888888">-- <br>
Sairam,<br>
<br>
(¨`·.·´¨) <br>
`·.¸(¨`·.·´¨) <br>
(¨`·.·´¨)¸.·´ Sarath!!!<br>
`·.¸.·´</span><u></u><u></u></p>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<br>
-- <br>
Sairam,<br>
<br>
(¨`·.·´¨) <br>
`·.¸(¨`·.·´¨) <br>
(¨`·.·´¨)¸.·´ Sarath!!!<br>
`·.¸.·´<u></u><u></u></p>
</div></div></div><div><div></div><div class="h5">
<br>
<font color="Black" face="Arial" size="2">-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents
to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.<br>
</font>
</div></div></div>
</blockquote></div><br><br clear="all"><br>-- <br>Sairam,<br><br> (¨`·.·´¨) <br> `·.¸(¨`·.·´¨) <br> (¨`·.·´¨)¸.·´ Sarath!!!<br> `·.¸.·´<br>