0

So I am trying to keep a count of how many times certain call instructions are called and I am struggling with identifying the instructions uniquely. I couldn't find something as an instruction ID in the documentation. I want to get the ID and pass it on to an external function that knows how to do the job.

So the question is how can I get a unique ID for those instructions (preferably as an integer)?

Dev2017
  • 857
  • 9
  • 31
  • 1
    I suspect, you can simply use pointer value of your `Instruction*` as ID. – arrowd Jan 21 '17 at 12:01
  • Hi @arrowd! Thanks for the comment. So you mean the address of the instruction? Moreover, can't addresses change? – Dev2017 Jan 21 '17 at 12:35
  • Also, the second part of the question, how can I get it as Int or any other primitive data type (not as pointer to instruction type)? – Dev2017 Jan 21 '17 at 13:00

2 Answers2

3

I take it you perform counting on runtime, and in the pass you are just inserting code that performs that counting near call instructions you are interested in. In this case Instruction pointer should work just fine. The pointer would not change if you move an Instruction around, it can only become invalid if you delete Instruction.

To convert a pointer into an integer use static_cast<uintptr_t>(i).

arrowd
  • 33,231
  • 8
  • 79
  • 110
0

If you know the type of call instructions that are possible then you can just declare an enum for all possible type of call instructions and pass the enum value to the counting function whenever you come across that type of call instruction based on the parameter value.

If you don't know all the possible call instructions, then you can pass the name of the function that is being called by the call instruction to the counting function. In this case you would have to implement the counting function in such a way that it maintains a map of function names and the count for that function.

Since a call instruction returns a value (Value*) for that particular call, I think all the Instruction* pointers that you get would be unique. So it won't serve your purpose if you use the pointer value as ID.

deLta
  • 561
  • 2
  • 12