(original) (raw)
On Jul 24, 2015, at 10:46 AM, Zhoulai <zell08v@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.
thanks,
chen
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_Original program:
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.
----------------------------------------
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 likeif (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@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev