Graal Optimization Question
Roland Schatz
roland.schatz at oracle.com
Wed Nov 20 01:47:44 PST 2013
Hi Curt,
> I have a Java API that i would like to optimize grail for. I have a method
> that when called I would like graal to vectorize it. The solution is two
> different parts.
>
> 1. Is it possible to add an optimization to graal that would look for a
> certain method call and optimize it in a specific way? If so where would I
> add this code to graal?
Have a look at e.g. the MathSubstitutionsX86 class. It defines method
substitutions for the java.lang.Math class.
Another possibility would be to directly replace the call with a single
MacroNode. For an example of that, look at e.g.
SystemSubstitutions.arraycopy or ClassSubstitutions.cast.
These substitutions are registered in the GraalMethodSubstitutions
class. You can register your own substitutions by creating a new class
implementing the ReplacementsProvider interface and annotating it with
the @ServiceProvider(ReplacementsProvider.class) annotation.
>
> 2. Once graal has the method it needs to compile it using vector
> instructions. Where in graal does it compile byte code to assembly?
If you look at the implementation of e.g. MathSubstitutionsX86.sqrt, it
calls MathIntrinsicNode.compute. That is a @NodeIntrinsic method, so the
compiler inserts a MathIntrinsicNode at this point in the graph.
MathIntrinsicNode implements LIRLowerable and defines a method
"generate", which generates platform dependent LIR code (see
AMD64LIRGenerator.emitMathSqrt). After register allocation, the LIR code
is turned into assembly (see Unary2Op.emitCode).
I hope that helps get you started.
- Roland
>
> Thanks,
> Curt Albert
More information about the graal-dev
mailing list