<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class=""><br class="">On Jul 24, 2015, at 10:46 AM, Zhoulai <<a href="mailto:zell08v@gmail.com" class="">zell08v@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="">Hi, <br class=""><br class=""></div>Are there some built-in LLVM transformation pass, or written library code that transforms LLVM::SwitchInst into if-condition statements (LLVM:: BranchInst)?<br class=""></div></div></div></div></blockquote><div><br class=""></div><div>There is a -lowerswitch pass that rewrites switch instructions with a sequence of branches. </div><div><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_Passes.html-23lowerswitch-2Dlower-2Dswitchinsts-2Dto-2Dbranches&d=AwMFAg&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=NIC7bBx3MEX4lys4J7-uaYz3QqEOYrSObd0Jj3eK288&s=KE5z1XyzaswASlcm1t2C3tWTXRUUp9gZBrsIke12qy8&e=" class="">http://llvm.org/docs/Passes.html#lowerswitch-lower-switchinsts-to-branches</a></div><div><br class=""></div><div>thanks,</div><div>chen</div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><br class="">The purpose of the transformation is that we have a legacy program analyzer that includes an LLVM pass manipulating if-condition statements. Statements of LLVM::SwithchInst should have 
been handled in the same manner but was not done. Thus to transform these SwitchInst to if-condition looks a viable alternative for us.  <br class=""><br class="">To illustrate, I give a simple C snippet with 'switch' and the expected transformation.<br class="">---------------------------------------- <br class=""></div>Original program: <br class=""><br class=""><i class=""> char grade;<br class=""> ...<br class="">  switch(grade)<br class="">    {<br class="">    case 'A' :<br class="">      printf("Excellent!\n" );<br class="">      break;<br class="">    case 'B' :<br class="">      printf("Well done\n" );<br class="">      break;<br class="">  <br class="">    default :<br class="">      printf("Invalid grade\n" );<br class="">    }</i><br class=""><br class=""></div><div class="">may be transformed to something like<br class=""><br class=""></div><div class=""><i class="">if (grad=='A') <br class="">          printf("Excellent!\n" );<br class=""></i></div><div class=""><i class="">else if (grad=='B')<br class="">      printf("Well done\n" );<br class=""></i></div><div class=""><i class="">else <br class="">       printf("Invalid grade\n" );</i></div><div class="">-------------------------------------------------<br class=""></div><div class=""> <br class="">Are you aware of such a transformation pass ? Thanks.<br clear="all" class=""></div><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class="gmail_signature">Zhoulai</div></div>
</div>
</div></div></div></div></div></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:LLVMdev@cs.uiuc.edu" class="">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" class="">http://llvm.cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br class=""></div></blockquote></div><br class=""></body></html>