Book Image

LLVM Cookbook

Book Image

LLVM Cookbook

Overview of this book

Table of Contents (16 chapters)
LLVM Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Using other analysis passes


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.

Getting ready…

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

How to do it…

Follow the steps given to use other analysis passes:

  1. Use the alias analysis evaluator pass by passing –aa-eval as a command-line option to the opt tool:

    $ opt -aa-eval -disable-output testcode1.bc
    ===== Alias Analysis Evaluator...