2

Assume my target .bc file has two instruction,

%3 = load volatile i32* %i, align 4
%4 = load i32** %sum, align 8

Both of them are Load instruction. I would like to know how to extract the different variables %i and %sum for some conditional compare. I have tried to print something like:

errs()<< instruction->getOperand(i)->getName();   // print out the ith operand's name

But it turns out that the things returned are garbled. Hope anyone with same experience could help me.

3
  • Turns our the variable locates on instruction->getOperand(0)->getName(); Commented Dec 19, 2014 at 5:30
  • What is the output you get? Commented Dec 19, 2014 at 10:35
  • The operands' name i and sum. Commented Dec 19, 2014 at 18:54

1 Answer 1

1

This won't work in general - in particular either: a) release mode can avoid putting names on individual instructions, they'll just be the next number in sequence (as you can see from the load instructions above), or b) optimization passes will occasionally change the name as well.

The only way to do this is to either keep track of the variables as you emit them, or perform some analysis that tells you where you want to perform the compare.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.