[LLVMdev] Question about Instruction comparison

Chris Lattner sabre at nondot.org
Mon Nov 24 18:37:02 PST 2003


On Mon, 24 Nov 2003, Misha Brukman wrote:

> On Mon, Nov 24, 2003 at 02:13:04PM -0600, Tanya Brethour wrote:
> > > I have been looking over the doxygen documentation as well as the
> > > llvm code.  Is there a standard way to check to see if two
> > > instructions are identical (i.e., Inst1 == Inst2 does not work)?
> >
> Since (I'm assuming) the instructions he's comparing do not come from
> the same Module, they cannot be the "SAME" instruction, and hence (Inst1
> == Inst2) will always be false.

If that's true, then there is no simple way to do this.  You really are
looking at comparing/diffing two different SSA graphs for two functions.
What you will need to do is build up an equivalence map.  For the two
functions you want to diff, you would insert the arguments into the map,
the first of each mapping to each other, the second of each mapping to
each other, etc.

then you process the instructions.  When you get to an 'add' for example,
you would have to check the map to see if the operands are equivalent
after the mapping has taken effect.  This is not trivial, but it is very
possible to implement.  Similar functionality exists in the function
cloning routines (lib/Transforms/Utils/*Cloning*), I would take a look at
how that handles the ValueMap stuff.

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/




More information about the llvm-dev mailing list