[LLVMdev] Transforming SwitchInst to BranchInst
Chen Li
meloli87 at gmail.com
Fri Jul 24 11:15:26 PDT 2015
>
> On Jul 24, 2015, at 10:46 AM, Zhoulai <zell08v at gmail.com> wrote:
>
> Hi,
>
> Are there some built-in LLVM transformation pass, or written library code that transforms LLVM::SwitchInst into if-condition statements (LLVM:: BranchInst)?
There is a -lowerswitch pass that rewrites switch instructions with a sequence of branches.
http://llvm.org/docs/Passes.html#lowerswitch-lower-switchinsts-to-branches <http://llvm.org/docs/Passes.html#lowerswitch-lower-switchinsts-to-branches>
thanks,
chen
>
> 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
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150724/fcd14acf/attachment.html>
More information about the llvm-dev
mailing list