0

The SWL is a map where i have store address as key and the constant as its corresponding value. However when i check this store being used in load i try to replace the uses of the store instruction with the constant. Doing so does not replace the instruction. There is no change in the byte code after running this pass.

std::map<Value*,Value*> SWL;
for (User::op_iterator OI = I.op_begin(); OI != I.op_end();  ++OI)
{
  Value *v = *OI;
   std::map<Value*,Value*> :: iterator re = SWL.find(v);

   if(re != SWL.end() && isa<LoadInst>(&I))
  {
    I.replaceAllUsesWith(re->second);
    bRet = true;
  }
}
user3342227
  • 123
  • 1
  • 5
  • Have you verified that you indeed reach the line containing `replaceAllUsesWith`'s invocation, and that `re->second` does indeed contain what you expect it to contain at that point? – Oak Mar 04 '14 at 05:51
  • yes, it reaches this point of execution and prints if(isa(re->second)) errs()<<" here"; – user3342227 Mar 04 '14 at 06:13
  • I even tried OI->setOperand(re->second) which does not replace anything in other instructions!! – user3342227 Mar 04 '14 at 06:18
  • Let me clarify one thing, to verify that it has changed i have to llvm-dis the .bc file right? – user3342227 Mar 04 '14 at 06:23
  • You can just give `opt` the `-S` command-line option and it would generate an .ll file. – Oak Mar 04 '14 at 06:34
  • Does not help, however printing the instructions shows that values are getting replaced!! – user3342227 Mar 08 '14 at 18:55
  • I was doing opt -load sample.dylib -passname sample.bc >/dev/null instead of indirecting it to other >change.bc. When i do this and do an llvm-dis of change.bc i can see the change. Thanks for the help. – user3342227 Mar 08 '14 at 21:46

1 Answers1

0

I was doing opt -load sample.dylib -passname sample.bc >/dev/null instead of directing it to other file as >change.bc. When i do this and do an llvm-dis of change.bc, i can see the change.

user3342227
  • 123
  • 1
  • 5