The whole chain to use for instructions

I'm a LLVM newbie who wants to get a use-def chain for the whole sample code command, for this I use the following code.

code example:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#define ARRAY_SIZE 5

int main() {
 int x, y, holder;
 int k,z,f,i;
  z=0;
  f=0;
  k=0;

  for(x = 0; x < ARRAY_SIZE; x++)
    for(y = 0; y < ARRAY_SIZE-1; y++)
      if(x+y>10) {
        holder = x+y;
        k=z+1;
    f=k+x;
    if (i>k)
        i=i+1;
      }
// return 1;

}

access code:

virtual bool runOnFunction(Function &F) {
    std::vector<Instruction*> worklist;

    for(inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I){
        worklist.push_back(&*I);
    }

    for(std::vector<Instruction*>::iterator iter = worklist.begin(); 
        iter != worklist.end(); ++iter){

        Instruction* instr = *iter;
        errs() << "def: " <<*instr << "\n";

        for(Value::use_iterator i = instr->use_begin(), ie = instr->use_end(); 
            i!=ie; ++i){

            Value *v = *i;
            Instruction *vi = dyn_cast<Instruction>(*i);
            errs() << "\t\t" << *vi << "\n";
        }
    }

    return false;
}

conclusion: def: ret void

but my result is not my goal, can someone help me?

thank

+3
source share
1 answer

main() in your code example, it does nothing but change the values ​​of local variables - it cannot have any externally visible effect on anything, because it does not call any external functions, does not change any global variables, or casts any pointers.

So, I suspect that all of this has been optimized to nothing but return before your run code is run.

+3
source

All Articles