开发者

def-use chain for Instruction

I am a LLVM newer who want to obtain the use-def chain for all instruction of a sample code, for this purpose i use the following code.

sample code:

#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;

}

pass 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;
}

output: def: ret void

but my output isn't my aim, can anyone help me?

Thanks


main() in your sample code does nothing except changing the values of local variables - it can't possibly have any externally visible effect on anything, as it doesn't call any external functions, change any global variables, or dereference any pointers.

So I suspect that it is all being optimised away to nothing except a return, before your pass code is run.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜