Transforming SwitchInst to BranchInst

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.

Hi Zhoulai

If you just don’t want any switch statements, then take a look at LowerSwitch.cpp. I think it will do what you want.

You can also invoke it with ‘opt -lowerswitch …’.

Thanks,
Pete

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

thanks,
chen