[llvm-dev] Computing unique ID of IR instructions that can be mapped back

James Courtier-Dutton via llvm-dev llvm-dev at lists.llvm.org
Wed May 10 05:38:54 PDT 2017


On 5 May 2017 at 00:47, Dipanjan Das via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
>
> I am writing an analysis pass on LLVM which requires to:
>
>    [1] generate unique, positive ID corresponding to each instruction
>    [2] the ID must survive across runs
>    [3] given the ID, corresponding instruction has to be mapped back
>
> For [1], the general suggestion is to use the Value* instr_ptr associated to
> each instruction. The instr_ptr points to specific instruction in memory,
> hence unique. However, it does change at every run, thus violating [2]. I
> have a hacking workaround of getting the first instruction of 'main' method
> and computing the offset. The problem is, this gives me negative offset for
> instructions lying in lower memory region than 'main'. Even if I circumvent
> the problem by adding a positive bias high enough, I have no clue how can I
> map the instr_ptr back to corresponding IR instruction. Can anyone suggest
> any elegant workaround?
>

Why not have your analysis pass build its own map.
The map would map between the Instruction and an integer index or offset.
I.e.
int index, Value *, Node *, Mod *
Where "Value *" is the reference to the instruction itself, "Node *"
is the BB that the instruction is contained in. "Mod *" is the module
containing all the Nodes.
The index will be the same every time you build the table if the IR
has not changed.
The analysis code then uses the index to refer back to the
instruction's context.


More information about the llvm-dev mailing list