1 /* |
1 /* |
2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
38 public class LoopSafepointEliminationPhase extends BasePhase<MidTierContext> { |
38 public class LoopSafepointEliminationPhase extends BasePhase<MidTierContext> { |
39 |
39 |
40 @Override |
40 @Override |
41 protected void run(StructuredGraph graph, MidTierContext context) { |
41 protected void run(StructuredGraph graph, MidTierContext context) { |
42 LoopsData loops = new LoopsData(graph); |
42 LoopsData loops = new LoopsData(graph); |
43 if (context.getOptimisticOptimizations().useLoopLimitChecks(graph.getOptions()) && graph.getGuardsStage().allowsFloatingGuards()) { |
43 loops.detectedCountedLoops(); |
44 loops.detectedCountedLoops(); |
44 for (LoopEx loop : loops.countedLoops()) { |
45 for (LoopEx loop : loops.countedLoops()) { |
45 if (loop.loop().getChildren().isEmpty() && loop.counted().getStamp().getBits() <= 32) { |
46 if (loop.loop().getChildren().isEmpty() && loop.counted().getStamp().getBits() <= 32) { |
46 boolean hasSafepoint = false; |
47 boolean hasSafepoint = false; |
47 for (LoopEndNode loopEnd : loop.loopBegin().loopEnds()) { |
48 for (LoopEndNode loopEnd : loop.loopBegin().loopEnds()) { |
48 hasSafepoint |= loopEnd.canSafepoint(); |
49 hasSafepoint |= loopEnd.canSafepoint(); |
49 } |
|
50 if (hasSafepoint) { |
|
51 if (!loop.counted().counterNeverOverflows()) { |
|
52 // Counter can overflow, need to create a guard. |
|
53 if (context.getOptimisticOptimizations().useLoopLimitChecks(graph.getOptions()) && graph.getGuardsStage().allowsFloatingGuards()) { |
|
54 loop.counted().createOverFlowGuard(); |
|
55 } else { |
|
56 // Cannot disable this safepoint, because the loop could overflow. |
|
57 continue; |
|
58 } |
50 } |
59 } |
51 if (hasSafepoint) { |
60 loop.loopBegin().disableSafepoint(); |
52 loop.counted().createOverFlowGuard(); |
|
53 loop.loopBegin().disableSafepoint(); |
|
54 } |
|
55 } |
61 } |
56 } |
62 } |
57 } |
63 } |
58 for (LoopEx loop : loops.loops()) { |
64 for (LoopEx loop : loops.loops()) { |
59 for (LoopEndNode loopEnd : loop.loopBegin().loopEnds()) { |
65 for (LoopEndNode loopEnd : loop.loopBegin().loopEnds()) { |