Hello all,
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20110507/b987ae10/attachment.html>
On 5/7/11 11:14 AM, neda 8664 wrote:> Hello all, > > I am a LLVM newer whowant to obtain the use-def chain for all > instruction of a sample code, for this purpose i use the following code.Disassemble the LLVM bitcode for the file and see what the function looks like after optimization. It's possible that the optimizations removed all the computation. -- John T.> > ///////////////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 > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110507/279e5d09/attachment.html>
Reasonably Related Threads
- [LLVMdev] subtle problem with inst_iterator
- [LLVMdev] subtle problem with inst_iterator
- [LLVMdev] a question of the simple constant propagation pass
- [LLVMdev] subtle problem with inst_iterator
- RFC: faster simplifyInstructionsInBlock/SimplifyInstructions pass