<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 17 May 2016 at 15:45, John Criswell via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><span class="">
<div>On 5/17/16 4:13 AM, PeiLIU via llvm-dev
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Now, I am using LLVM-3.3 do some process with
functions, however there are some difficult things I can't
handle by myself. So,
<div><br>
</div>
<div>I want get your help to get it down properly.</div>
<div><br>
</div>
<div>Q1. There is a function declaration:</div>
<div><br>
</div>
<div>call i32 @create(i64* %tid, %union.t* %pab, i8* (i8*)*
@worker, i8* null) // callInst<br>
</div>
<div><br>
</div>
<div>Store instruction goes like this:</div>
<div><br>
</div>
<div>store i8* (i32, double, i32*)* %fp, i8* (i32, double,
i32*)** %fp.addr // storeInst<br>
</div>
<div><br>
</div>
<div>I want to determine the type of the operands are function
pointer or not? (That's what I want)</div>
<div><br>
</div>
<div>However,
callInst->getOperand(2)->getType()->getTypeID()
always return 14 that'a the enum number of</div>
<div><br>
</div>
<div>PointerTypeID. For the store instruction, first operand is
the same as the operation with call instruction.</div>
<div><br>
</div>
<div>How can I get the function pointer properly?</div>
</div>
</blockquote>
<br></span>
Instead of looking at the Type ID, you should use
isa<FunctionType> to determine if the value has function type:<br>
<br>
if
(isa<FunctionType>(callInst->getOperand(2)->getType()) {<br>
... <second operand has function type><br>
}<br>
<br>
In LLVM, functions are global variables and therefore are a pointer
type.<span class=""><br>
<br>
<blockquote type="cite">
<div dir="ltr">
<div><br>
</div>
<div>Q2. Function arguments can be passed by value or by pointer
in C-programming language.</div>
<div><br>
</div>
<div>
<div>int arr[10];</div>
<div>struct node {</div>
<div><span> </span>int a;</div>
<div><span> </span>int att[10];</div>
<div><span> </span>double ul;</div>
<div>};</div>
<div><br>
</div>
<div>struct node Node;</div>
</div>
<div><br>
</div>
<div>testStruct(Node);<br>
</div>
<div><br>
</div>
<div>
<div>testStructPointer(&Node);</div>
</div>
<div><br>
</div>
<div>After compiled and change it to .ll file, it looks like
this:</div>
<div><br>
</div>
<div>call void @testStruct(%struct.node* byval align 8 @Node),
!dbg !160<br>
</div>
<div><br>
</div>
<div>call void @testStructPointer(%struct.node* @Node), !dbg
!161<br>
</div>
<div><br>
</div>
<div>You can see that function named testStruction's parameter
is passed by value while the testStructPointer passed by
pointer.</div>
<div><br>
</div>
<div>I used callInst->getOperand(0)->getType()->dump(),
it always return the same %struct.node*.</div>
<div><br>
</div>
<div>I want to know is there some properly library functions can
be used to get the precise parameters type?</div>
<div><br>
</div>
<div>I want to know the functions arguments are passed by value
or by pointer?</div>
</div>
</blockquote>
<br></span>
In LLVM, all parameters are passed by value unless they have the
byval attribute. There's probably a method in the Argument class
that will tell you whether the argument has the byval attribute. If
it's not an attribute of the Argument class, it's probably part of
the type of the Function.<br></div></blockquote><div>I think you mean that they are "by reference unless they have a byval" attribute?<br></div><div><br></div><div>The "ByVal" is an attribute on the call instruction.<br><br>Here's where my compiler sets that:<br><a href="https://github.com/Leporacanthicus/lacsap/blob/master/expr.cpp#L1260">https://github.com/Leporacanthicus/lacsap/blob/master/expr.cpp#L1260</a><br></div><div>(The "ByVal" attribute itself is stored in the attribute container on line 1235)<br></div><div><br>--<br></div><div>Mats<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000">
<br>
Just out of curiosity, are you using the doxygen documentation? The
doxygen documentation is invaluable; if you have a basic
understanding of how LLVM uses its class hierarchy to represent the
IR, you can usually find what you need via the doxygen docs.<br>
<br>
Regards,<br>
<br>
John Criswell<br>
<blockquote type="cite"><span class="">
<div dir="ltr">
<div><br>
</div>
<div>Any advice would be appreciate. Thanks a lot.:)</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
</span><pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><span class=""><font color="#888888">
</font></span></pre><span class=""><font color="#888888">
</font></span></blockquote><span class=""><font color="#888888">
<br>
<br>
<pre cols="72">--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a href="http://www.cs.rochester.edu/u/criswell" target="_blank">http://www.cs.rochester.edu/u/criswell</a></pre>
</font></span></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>