[LLVMdev] matching function call arguments

Frits van Bommel fvbommel at gmail.com
Mon Mar 7 12:02:44 PST 2011


On Mon, Mar 7, 2011 at 8:03 PM, Hari Pyla <harip at vt.edu> wrote:
>  Thank you for your response. In my analysis, I will always have
> entry(2) and exit(2). I will not run into cases involving entry (1+1) or
> entry (fn return values). I am having trouble trying to compare the
> arguments of entry and exit in the following scenario.
>
> #include<stdio.h>
> #include<stdlib.h>
> #include<pthread.h>
>
> struct sa
> {
>   int a;
>   pthread_mutex_t *mutex1;
> };
> struct sa *s;
>
> pthread_mutex_t mutex1;
> int main()
> {
>   s = (struct sa *)malloc(sizeof(struct sa));
>   s->mutex1 = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
>
>  entry(s->mutex1);
>
>   s->a++;
>
>   exit(s->mutex1);
>
>   return 0;
> }

Have you tried just running something like -earlycse before your pass?
It might be overkill, but it'd probably get the job done.

If you want a "lazy" check (as in, just for the values you want to
compare) though, AFAIK there's no public interface for that kind of
functionality. A pass like -earlycse or -mergefunc might have
something you can factor out though.

Other than that, you can probably hack up something with a recursive
function using Instruction::isSameOperationAs(), which checks
everything except operand values (so you'd need to check equivalence
of operands recursively if you want to go more than one instruction
deep).
You'll probably want to keep a mapping of already-checked equivalences
(for performance), and you should definitely be careful not to go into
infinite recursion in the face of PHI nodes.
Also, be careful of side effects, both in the instructions you're
comparing and in anything in between; for example you don't want two
loads to be considered equal if there's a store to that memory in
between them. Instruction::mayHaveSideEffects() and
Instruction::mayReadFromMemory() are probably useful here.

If you go with either of the last two options and create a function to
figure out whether two values are equivalent, it might be interesting
if you submitted a patch for your changes so others can use them too.
Also, you'd likely get some feedback on whether you've made any
mistakes :).




More information about the llvm-dev mailing list