43972
|
1 |
/*
|
58877
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
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
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.core.test;
|
|
26 |
|
|
27 |
import jdk.vm.ci.meta.JavaConstant;
|
|
28 |
|
|
29 |
import org.junit.Assert;
|
|
30 |
import org.junit.Test;
|
46640
|
31 |
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
|
32 |
import org.graalvm.compiler.debug.DebugContext;
|
43972
|
33 |
import org.graalvm.compiler.nodes.ConstantNode;
|
|
34 |
import org.graalvm.compiler.nodes.ReturnNode;
|
|
35 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
36 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
37 |
import org.graalvm.compiler.nodes.calc.AddNode;
|
52578
|
38 |
import org.graalvm.compiler.nodes.extended.OpaqueNode;
|
46640
|
39 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
40 |
import org.graalvm.compiler.phases.schedule.SchedulePhase;
|
|
41 |
import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
|
|
42 |
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
|
43 |
|
|
44 |
public class LongNodeChainTest extends GraalCompilerTest {
|
|
45 |
|
|
46 |
public static final int N = 10000;
|
|
47 |
|
48861
|
48 |
private static final SchedulingStrategy[] Strategies = new SchedulingStrategy[]{SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER};
|
43972
|
49 |
|
|
50 |
@Test
|
|
51 |
public void testLongAddChain() {
|
|
52 |
longAddChain(true);
|
|
53 |
longAddChain(false);
|
|
54 |
}
|
|
55 |
|
|
56 |
private void longAddChain(boolean reverse) {
|
|
57 |
HighTierContext context = getDefaultHighTierContext();
|
46640
|
58 |
OptionValues options = getInitialOptions();
|
|
59 |
StructuredGraph graph = new StructuredGraph.Builder(options, DebugContext.create(options, DebugHandlersFactory.LOADER)).build();
|
43972
|
60 |
ValueNode constant = graph.unique(ConstantNode.forPrimitive(JavaConstant.INT_1));
|
|
61 |
ValueNode value = null;
|
|
62 |
if (reverse) {
|
|
63 |
// Make sure the constant's stamp is not used to infer the add node's stamp.
|
|
64 |
OpaqueNode opaque = graph.unique(new OpaqueNode(constant));
|
|
65 |
constant = opaque;
|
|
66 |
AddNode addNode = graph.unique(new AddNode(constant, constant));
|
|
67 |
value = addNode;
|
|
68 |
for (int i = 1; i < N; ++i) {
|
|
69 |
AddNode newAddNode = graph.addWithoutUnique(new AddNode(constant, constant));
|
|
70 |
addNode.setY(newAddNode);
|
|
71 |
addNode = newAddNode;
|
|
72 |
}
|
52578
|
73 |
opaque.remove();
|
43972
|
74 |
} else {
|
|
75 |
value = constant;
|
|
76 |
for (int i = 0; i < N; ++i) {
|
|
77 |
value = graph.unique(new AddNode(constant, value));
|
|
78 |
}
|
|
79 |
}
|
|
80 |
ReturnNode returnNode = graph.add(new ReturnNode(value));
|
|
81 |
graph.start().setNext(returnNode);
|
|
82 |
|
|
83 |
for (SchedulingStrategy s : Strategies) {
|
|
84 |
new SchedulePhase(s).apply(graph);
|
|
85 |
}
|
|
86 |
|
58877
|
87 |
this.createCanonicalizerPhase().apply(graph, context);
|
43972
|
88 |
JavaConstant asConstant = (JavaConstant) returnNode.result().asConstant();
|
|
89 |
Assert.assertEquals(N + 1, asConstant.asInt());
|
|
90 |
}
|
|
91 |
}
|