In this recipe, we will take a brief look into the other analysis passes that are provided by LLVM and can be used to get analysis information about a basic block, function, module, and so on. We will look into passes that have already been implemented in LLVM, and how we can use them for our purpose. We will not go through all the passes but take a look at only some of them.
Write the test code in the testcode1.c
file, which will be used for analysis purposes:
$ cat testcode1.c void func() { int i; char C[2]; char A[10]; for(i = 0; i != 10; ++i) { ((short*)C)[0] = A[i]; C[1] = A[9-i]; } }
Convert the C code to bitcode format, using the following command line:
$ clang -c -emit-llvm testcode1.c -o testcode1.bc
Follow the steps given to use other analysis passes:
–aa-eval
as a command-line option to the opt tool:$ opt -aa-eval -disable-output testcode1.bc ===== Alias Analysis Evaluator Report ===== 36 Total Alias Queries Performed 0 no alias responses (0.0%) 36 may alias responses (100.0%) 0 partial alias responses (0.0%) 0 must alias responses (0.0%) Alias Analysis Evaluator Pointer Alias Summary: 0%/100%/0%/0% Alias Analysis Mod/Ref Evaluator Summary: no mod/ref!
–print-dom-info
command-line option along with opt:$ opt -print-dom-info -disable-output testcode1.bc =============================-------------------------------- Inorder Dominator Tree: [1] %0 {0,9} [2] %1 {1,8} [3] %4 {2,5} [4] %19 {3,4} [3] %22 {6,7}
–count-aa
command-line option along with opt:$ opt -count-aa -basicaa -licm -disable-output testcode1.bc No alias: [4B] i32* %i, [1B] i8* %7 No alias: [4B] i32* %i, [2B] i16* %12 No alias: [1B] i8* %7, [2B] i16* %12 No alias: [4B] i32* %i, [1B] i8* %16 Partial alias: [1B] i8* %7, [1B] i8* %16 No alias: [2B] i16* %12, [1B] i8* %16 Partial alias: [1B] i8* %7, [1B] i8* %16 No alias: [4B] i32* %i, [1B] i8* %18 No alias: [1B] i8* %18, [1B] i8* %7 No alias: [1B] i8* %18, [1B] i8* %16 Partial alias: [2B] i16* %12, [1B] i8* %18 Partial alias: [2B] i16* %12, [1B] i8* %18 ===== Alias Analysis Counter Report ===== Analysis counted: 12 Total Alias Queries Performed 8 no alias responses (66%) 0 may alias responses (0%) 4 partial alias responses (33%) 0 must alias responses (0%) Alias Analysis Counter Summary: 66%/0%/33%/0% 0 Total Mod/Ref Queries Performed
-print-alias-sets
command-line option with opt:$ opt -basicaa -print-alias-sets -disable-output testcode1.bc Alias Set Tracker: 3 alias sets for 5 pointer values. AliasSet[0x336b120, 1] must alias, Mod/Ref Pointers: (i32* %i, 4) AliasSet[0x336b1c0, 2] may alias, Ref Pointers: (i8* %7, 1), (i8* %16, 1) AliasSet[0x338b670, 2] may alias, Mod Pointers: (i16* %12, 2), (i8* %18, 1)
In the first case, where we use the -aa-eval
option, the opt tool runs the alias analysis evaluator pass, which outputs the analysis on the screen. It iterates through all pairs of pointers in the function and queries whether the two are aliases of each other or not.
Using the -print-dom-info
option, the pass for printing the dominator tree is run, through which information about the dominator tree can be obtained.
In the third case, we execute the opt -count-aa -basicaa –licm
command. The count-aa
command option counts the number of queries made by the licm
pass to the basicaa
pass. This information is obtained by the count alias analysis pass using the opt tool.
To print all the alias sets within a program, we use the - print-alias-sets
command-line option. In this case, it prints the alias sets obtained after analyzing with the basicaa
pass.
Refer to http://llvm.org/docs/Passes.html#anal to know about more passes not mentioned here.
3.131.38.14