My optimizer is progressing nicely. But I'm stuck with something:
occasionally I cache some expressions in synthetic method-local
variables, and I want to replace other occurences of these
expressions/trees with Ident(varName) of the variable where the tree is
already cached.
I'm trying to use for this purpose an extended HashMap:
val cache = new collection.mutable.HashMap[Tree, Name] {
override def elemEquals(key1: Tree, key2: Tree) = key1
equalsStructure key2
override def elemHashCode(key: Tree) = key.hashCodeStructure
}
However, it seems that even if the trees I want to replace produce equal
hashCodes with the one cached (using hashCodeStructure), they do not
equal (using equalsStructure). Is this correct? And if so, is there
something else I can use or must I implement my own tree comparison?
Erkki L
Erkki Lindpere wrote:
> I want to create a plug-in that does vector math optimizations*, but
> I've never studied compilers and many things in the compiler seem
> really foreign to me.
>
> * I think scalar replacement is what it's called -- given the type
> Vector2(x: Float, y: Float) { /* operations */ }, I want to replace
> 1) local variables:
> val v = new Vector2(1f, 2f) --> val v$x = 1f; val v$y = 2f
> 2) any operations on Vectors with operations on Floats
> 3) any escaping vectors with new Vector2(v$x, v$y) -- most of the time
> they will not escape
>
> Or should I just wait until JIT can do this better? :)
>
> Erkki
>