[antlr-interest] Non-local optimizations with treewalker?

Andy Tripp antlr at jazillian.com
Mon Sep 17 07:39:43 PDT 2007


Sohail Somani wrote:
> I'm not sure you entirely understood what I was trying to do. The idea
> is that computing f(x) is expensive. If the language has no
> side-effects, then calling f(x) always gives the same result. Therefore,
> if you can "match" (I'm not entirely sure that I want to use that term)
> f(x) in more than one subexpression within some lexical scope, then you
> can replace all computations of f(x) with t where t = f(x).
>   
I was talking about how you "match". Surely you don't mean you're only 
going to look for
calls to a function named "f", you "match" any function call. And you 
don't mean passing
an argument "x", you mean...some non-trivial "match" algorithm that 
decides whether two
arguments are "the same". So, maybe all these calls "match" (or maybe not):

f(1);

int i=1; f(i);

#define ONE 1
f(ONE);

f(0+1);

i = someRandomNumber();
if (i == 1) {
    f(i);
}


...all I was saying was that the treewalker approach doesn't help you do 
any of this "matching",
and the other code you'll need to write. And this code is probably 
non-trivial.
> Oh I've definitely seen that one :-)
>
> Sohail
>
>   



More information about the antlr-interest mailing list