Mercurial > hg > truffle
annotate graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopPolicies.java @ 15457:c0e1a8693e0e
mx: added --jdt-warning-as-error when building annotation processor jars
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 01 May 2014 11:51:45 +0200 |
parents | d90e5c22ba55 |
children | c55f44b3c5e5 |
rev | line source |
---|---|
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
1 /* |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
4 * |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
8 * |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
14 * |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
18 * |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
21 * questions. |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
22 */ |
6523
c8763a2deb0c
rename packages in graal.loop to match project name
Doug Simon <doug.simon@oracle.com>
parents:
6522
diff
changeset
|
23 package com.oracle.graal.loop; |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
24 |
15259
d90e5c22ba55
Move GraalOptions to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15145
diff
changeset
|
25 import static com.oracle.graal.compiler.common.GraalOptions.*; |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9436
diff
changeset
|
26 |
5732
e1d5c642d022
Started to draft a loop unswitching policy
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5696
diff
changeset
|
27 import com.oracle.graal.debug.*; |
7283
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
28 import com.oracle.graal.graph.*; |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
29 import com.oracle.graal.nodes.*; |
6529
2e96dc4eb8e2
renamed package: com.oracle.graal.lir.cfg -> com.oracle.graal.nodes.cfg
Doug Simon <doug.simon@oracle.com>
parents:
6525
diff
changeset
|
30 import com.oracle.graal.nodes.cfg.*; |
9238
8f01fe16e473
refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9234
diff
changeset
|
31 import com.oracle.graal.nodes.util.*; |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
32 |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7283
diff
changeset
|
33 public abstract class LoopPolicies { |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
34 |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
35 private LoopPolicies() { |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
36 // does not need to be instantiated |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
37 } |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
38 |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
39 // TODO (gd) change when inversion is available |
9238
8f01fe16e473
refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9234
diff
changeset
|
40 public static boolean shouldPeel(LoopEx loop, NodesToDoubles probabilities) { |
13215
dca16b3416ab
Don't peel counted loops.
Roland Schatz <roland.schatz@oracle.com>
parents:
11841
diff
changeset
|
41 if (loop.detectCounted()) { |
dca16b3416ab
Don't peel counted loops.
Roland Schatz <roland.schatz@oracle.com>
parents:
11841
diff
changeset
|
42 return false; |
dca16b3416ab
Don't peel counted loops.
Roland Schatz <roland.schatz@oracle.com>
parents:
11841
diff
changeset
|
43 } |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
44 LoopBeginNode loopBegin = loop.loopBegin(); |
9238
8f01fe16e473
refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9234
diff
changeset
|
45 double entryProbability = probabilities.get(loopBegin.forwardEnd()); |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9436
diff
changeset
|
46 return entryProbability > MinimumPeelProbability.getValue() && loop.size() + loopBegin.graph().getNodeCount() < MaximumDesiredSize.getValue(); |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
47 } |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
48 |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
49 public static boolean shouldFullUnroll(LoopEx loop) { |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
50 if (!loop.isCounted() || !loop.counted().isConstantMaxTripCount()) { |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
51 return false; |
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
52 } |
5887
e8628cb6296b
fix to FullUnroll changes
Lukas Stadler <lukas.stadler@jku.at>
parents:
5884
diff
changeset
|
53 CountedLoopInfo counted = loop.counted(); |
11841
6157a71e0a36
Fix wrong local variable name in LoopPolicies.shouldFullUnroll
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9864
diff
changeset
|
54 long maxTrips = counted.constantMaxTripCount(); |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9436
diff
changeset
|
55 int maxNodes = (counted.isExactTripCount() && counted.isConstantExactTripCount()) ? ExactFullUnrollMaxNodes.getValue() : FullUnrollMaxNodes.getValue(); |
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9436
diff
changeset
|
56 maxNodes = Math.min(maxNodes, MaximumDesiredSize.getValue() - loop.loopBegin().graph().getNodeCount()); |
5688
9bb0ba9e8ba6
Adjust loop unroll policy a bit
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5675
diff
changeset
|
57 int size = Math.max(1, loop.size() - 1 - loop.loopBegin().phis().count()); |
11841
6157a71e0a36
Fix wrong local variable name in LoopPolicies.shouldFullUnroll
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9864
diff
changeset
|
58 return size * maxTrips <= maxNodes; |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
59 } |
5696
f592c22421e7
Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5688
diff
changeset
|
60 |
6309
6f8b6fc03c96
Add a maximum number of unswitching per loop
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5887
diff
changeset
|
61 public static boolean shouldTryUnswitch(LoopEx loop) { |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9436
diff
changeset
|
62 return loop.loopBegin().unswitches() <= LoopMaxUnswitch.getValue(); |
5696
f592c22421e7
Look for LoopUnswitch opportunities (LoopUnswitch currently disabled)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5688
diff
changeset
|
63 } |
5732
e1d5c642d022
Started to draft a loop unswitching policy
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5696
diff
changeset
|
64 |
7283
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
65 public static boolean shouldUnswitch(LoopEx loop, ControlSplitNode controlSplit) { |
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
66 Block postDomBlock = loop.loopsData().controlFlowGraph().blockFor(controlSplit).getPostdominator(); |
15145
df2ef5204f2b
Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
13215
diff
changeset
|
67 BeginNode postDom = postDomBlock != null ? postDomBlock.getBeginNode() : null; |
5732
e1d5c642d022
Started to draft a loop unswitching policy
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5696
diff
changeset
|
68 int loopTotal = loop.size(); |
7283
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
69 int inBranchTotal = 0; |
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
70 double maxProbability = 0; |
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
71 for (Node successor : controlSplit.successors()) { |
15145
df2ef5204f2b
Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
13215
diff
changeset
|
72 BeginNode branch = (BeginNode) successor; |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7283
diff
changeset
|
73 inBranchTotal += loop.nodesInLoopFrom(branch, postDom).cardinality(); // this may count |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7283
diff
changeset
|
74 // twice because |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7283
diff
changeset
|
75 // of fall-through |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7283
diff
changeset
|
76 // in switches |
7283
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
77 double probability = controlSplit.probability(branch); |
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
78 if (probability > maxProbability) { |
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
79 maxProbability = probability; |
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
80 } |
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
81 } |
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
82 int netDiff = loopTotal - (inBranchTotal); |
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
83 double uncertainty = 1 - maxProbability; |
9864
063a712fe8d8
converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents:
9436
diff
changeset
|
84 int maxDiff = LoopUnswitchMaxIncrease.getValue() + (int) (LoopUnswitchUncertaintyBoost.getValue() * loop.loopBegin().loopFrequency() * uncertainty); |
7283
3964f3d4eb18
Extend loop unswicthing to Switch nodes (integer or type)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7257
diff
changeset
|
85 Debug.log("shouldUnswitch(%s, %s) : delta=%d, max=%d, %.2f%% inside of branches", loop, controlSplit, netDiff, maxDiff, (double) (inBranchTotal) / loopTotal * 100); |
5732
e1d5c642d022
Started to draft a loop unswitching policy
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5696
diff
changeset
|
86 return netDiff <= maxDiff; |
e1d5c642d022
Started to draft a loop unswitching policy
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5696
diff
changeset
|
87 } |
e1d5c642d022
Started to draft a loop unswitching policy
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5696
diff
changeset
|
88 |
5675
776366f3a41a
A bit of work on counted loops
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
89 } |