Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I extract operands from an instruction's metadata from LLVM IR?

Tags:

llvm

llvm-ir

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...

like image 630
Dhriti Khanna Avatar asked Jan 28 '26 22:01

Dhriti Khanna


1 Answers

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

Value* opl = iCmpInst -> getOperand(0);
Value* opr = iCmpInst -> getOperand(1);
like image 55
zjwu Avatar answered Feb 02 '26 15:02

zjwu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!