3

I am trying to extract what operands are being used in an if instruction in LLVM IR. For example: for an instruction like if(x==10), I want x and 10 as output.

Is this not how it should be done:

if (ICmpInst* iCmpInst = dyn_cast<ICmpInst>(&*i))
{
  errs() << "Conditional Instruction found: ";
  errs() << iCmpInst->getOpcodeName() << '\t';
  errs() << iCmpInst->getPredicate() << '\t';

  MDNode* metadata = iCmpInst->getMetadata("dbg");
  llvm::MDNode::op_iterator o_begin = metadata->op_begin();
  llvm::MDNode::op_iterator o_end = metadata->op_end();

  for(; o_begin != o_end; ++o_begin)
  {
    errs() << o_begin << "\n";
  }
}

For literals such as x, I have to scan `store instructions I think...

AlexDenisov
  • 4,022
  • 25
  • 31
  • Side note: Use `isa<>` instead of `dyn_cast<>`. – arrowd May 19 '16 at 07:44
  • @arrowd I refer [this](https://llvm.org/svn/llvm-project/llvm/branches/GSoC/adaptive-compilation/lib/Analysis/DbgInfoPrinter.cpp) and [this](http://stackoverflow.com/questions/21410675/getting-the-original-variable-name-for-an-llvm-value/21488105#21488105) for the solution to my problem, can you please tell why the line `DDI->getAddress() == V` does not work?? – Dhriti Khanna May 26 '16 at 17:16

1 Answers1

1

if you just want to get the operands ,may be you can try,

Value* opl = iCmpInst -> getOperand(0);
Value* opr = iCmpInst -> getOperand(1);
zjwu
  • 77
  • 1
  • 8