<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 5/20/15 1:05 PM, Zhoulai wrote:<br>
</div>
<blockquote
cite="mid:CAKV0nkd3K1hT8p-KkMLLL4wqW6Ho82keGgnPq6vOGuaokxymmA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>Hi, <br>
<br>
I have a naive question in using LLVM. <br>
<br>
Given an llvm::Function*, and an llvm::BranchInst* of the
function, is their a simple, off-the-shelf procedure in LLVM
for me to determine whether there is dependency between the
branch instruction and the function’s input parameters? For
example:<br>
</div>
</div>
</blockquote>
<br>
For data-dependences through SSA virtual registers, all you need to
do is follow the def-use chain of the function parameter to see if
it is used by a branch instruction.<br>
<br>
For control-dependence, I think there's a Reverse Dominance Frontier
analysis pass that you can use to determine if a branch is
control-dependent on a value. You might need to do some work to
handle indirect control dependences (the branch control-depends on a
value which control-depends on the function parameter), but that is
easy enough to do.<br>
<br>
If the value of the BranchInst is loaded from memory, then you've
got a much more difficult task. In that case, you'd need to use an
AliasAnalysis pass combined with your own reaching-definitions
data-flow analysis to determine that the Function parameter is
stored into memory and can potentially reach the use in the
BranchInst. <br>
<br>
Regards,<br>
<br>
John Criswell<br>
<br>
<blockquote
cite="mid:CAKV0nkd3K1hT8p-KkMLLL4wqW6Ho82keGgnPq6vOGuaokxymmA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
</div>
<div><i>void foo(int n){</i></div>
<div><i> i=0; </i></div>
<div><i> if (i<=n){ //B1</i></div>
<div><i> i++;</i></div>
<div><i> }</i></div>
<div><i> int j=0</i></div>
<div><i> if (j<=2*j){ //B2</i></div>
<div><i> j++;</i></div>
<div><i> }</i></div>
<div><i> if (i+j>=1){ //B3</i></div>
<div><i> return;</i></div>
<div><i> }</i></div>
<div><i>return;</i></div>
<div><i>}</i></div>
<div><br>
</div>
<div>Here, the first branch B1 depends on the input ’n’; the
second branch B2 does not depends on ’n’; and the third B3
depends (indirectly) on input ’n’ as it uses ‘i’. </div>
<div><br>
</div>
<div>Such static analysis can quickly become complicated, but
maybe LLVM provides a simple, conservative solution for us.
Can anyone tell me the right LLVM API to use. A simple example
of the use would be the most helpful. <br>
<br>
Thanks in advance. </div>
<div>
<div>
<div class="gmail_signature">Zhoulai</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.cs.rochester.edu_u_criswell&d=AwMD-g&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=IeV0PfA0SL7ovKfMWK8vDhV-wM5mP13ij6tzBFcEkbM&s=ituXnPkOiWQ1IOSqZ6FwnAmc7wuJcLzeggJBuJdv5wc&e=">http://www.cs.rochester.edu/u/criswell</a></pre>
</body>
</html>