[LLVMdev] Transforming SwitchInst to BranchInst

Zhoulai zell08v at gmail.com
Fri Jul 24 10:46:41 PDT 2015


Hi,

Are there some built-in LLVM transformation pass, or written library code
that transforms LLVM::SwitchInst into if-condition statements (LLVM::
BranchInst)?

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.

To illustrate, I give a simple C snippet with 'switch' and the expected
transformation.
----------------------------------------
Original program:














* char grade; ...  switch(grade)    {    case 'A' :
printf("Excellent!\n" );      break;    case 'B' :      printf("Well
done\n" );      break;      default :      printf("Invalid grade\n" );    }*

may be transformed to something like



*if (grad=='A')           printf("Excellent!\n" );*


*else if (grad=='B')      printf("Well done\n" );*

*else        printf("Invalid grade\n" );*
-------------------------------------------------

Are you aware of such a transformation pass ? Thanks.
Zhoulai
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150724/178db13e/attachment.html>


More information about the llvm-dev mailing list