code hoisting and optimization
Josef Eisl
josef.eisl at jku.at
Tue Sep 12 07:56:41 UTC 2017
Hello Haluk!
(I move the discussion to the list since it seems related to your
previous post.)
On 11/09/17 17:27, Haluk Dogan wrote:
> Dear Josef,
>
> I'm playing with Graal compiler. I've some applications in my mind, and
> hopefully I can proceed with Graal for these applications.
>
> I'm particular interested in applying specific code optimizations. I
> have this dummy code to play with:
>
> https://gist.github.com/anonymous/e546ee6db622976f109f71b70ade856b
>
> I defined a code hoisting example to see the optimization effect. In
> fact, target code size is different for with and without optimizations.
>
> My question is, how can I apply a specific optimization technique in
> Graal? I don't know much about GCC but I think in GCC we can apply
> particular optimization technique with -f parameter.
>
> http://gcc.gnu.org/onlinedocs/gcc-4.6.2/gcc/Optimize-Options.html
First off a little bit of background, just in case your are not yet
familiar with the terms used in the project. In Graal optimizations are
organized as `Phases` and phases are organized in `PhaseSuites`. There
are 3 suites: `HighTier`, `MidTier`, and `LowTier`. Those capture
roughly the state transformation of the Graph, i.e., from a high level
(Java'ish) point of view to a low level one (closer to the machine
level). Then there are also `CompilerConfigurations` which select the
set of suites used for a compilation.
Now to your question: the programmatic way of changing the behavior is
to modify the `PhaseSuites`, e.g. with PhaseSuite#appendPhase.
Many phases can also be switched on and off via command line options,
however there is no "default" switch for that. Have a look at the
`HighTier`, `MidTier`, `LowTier` classes to get to know the option
names. For example the HighTier makes use of the `FullUnroll` option
which means you can turn of the `LoopFullUnrollPhase` with the
`-Dgraal.FullUnroll=false` command line flag.
I hope that gives you a few pointers. Feel free to ask if there are
further questions.
Josef
>
> Thanks.
>
> Best,
> Haluk
>
> --
On 07/09/17 03:48, Haluk Dogan wrote:
> Hello,
>
> I'm trying to see the optimization steps by using Graal. I defined a
> codeHoisting method in my Example class as in the following:
>
> public class Example {
>
> public int[] codeHoisting(int x, int y, int n) {
> int[] result = new int[n];
> for (int i = 0; i < n; i++) {
> result[i] = x + y;
> }
> return result;
> }
>
> }
>
> Then, I used *compileAndInstallMethod* as shown in the Tutorial slides to
> get the compiled code of given method. However, the resulting byte array is
> different no matter we apply ALL or NONE optimizations.
>
> I would expect the same byte array after we apply
> OptimisticOptimizations.ALL.
>
> Why the resulting byte arrays are different? Also, how can I print the
> bytecode?
>
> I put the gist of the code in the following link:
>
> https://gist.github.com/anonymous/20c385bfbac1dfebffd648d88761274e
>
> Thanks.
>
More information about the graal-dev
mailing list