annotate graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/BasicPTXTest.java @ 8463:b2161263e9f2

Cleanup unit tests : they should not print to stdout/stderr
author Gilles Duboscq <duboscq@ssw.jku.at>
date Mon, 25 Mar 2013 19:22:03 +0100
parents dce9cefed571
children 1d12b11e80c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.compiler.ptx.test;
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import org.junit.*;
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
7838
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
27 import com.oracle.graal.api.code.*;
7929
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
28 import com.oracle.graal.api.meta.*;
7838
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
29 import com.oracle.graal.api.runtime.*;
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
30 import com.oracle.graal.compiler.*;
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
31 import com.oracle.graal.compiler.ptx.*;
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.compiler.test.*;
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.debug.*;
7838
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
34 import com.oracle.graal.java.*;
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.nodes.*;
7929
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
36 import com.oracle.graal.nodes.type.*;
7838
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
37 import com.oracle.graal.phases.*;
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
38 import com.oracle.graal.phases.PhasePlan.*;
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
39 import com.oracle.graal.ptx.*;
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 /**
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 * Test class for small Java methods compiled to PTX kernels.
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 */
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 public class BasicPTXTest extends GraalCompilerTest {
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 @Test
7928
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
47 public void testAdd() {
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
48 test("testAddSnippet");
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
49 }
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
50
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
51 public static int testAddSnippet(int a) {
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
52 return a + 1;
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 }
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54
7928
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
55 @Test
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
56 public void testArray() {
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
57 test("testArraySnippet");
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
58 }
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
59
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
60 public static int testArraySnippet(int[] array) {
47a7e8d80536 Added new basic array PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7841
diff changeset
61 return array[0];
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 }
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63
8463
b2161263e9f2 Cleanup unit tests : they should not print to stdout/stderr
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8217
diff changeset
64 private CompilationResult test(String snippet) {
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 StructuredGraph graph = parse(snippet);
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 Debug.dump(graph, "Graph");
7841
674a8b9e62f8 Remove unused fields in TargetDescription. Use Unsafe.pageSize().
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7838
diff changeset
67 TargetDescription target = new TargetDescription(new PTX(), true, 1, 0, true);
7838
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
68 PTXBackend ptxBackend = new PTXBackend(Graal.getRequiredCapability(CodeCacheProvider.class), target);
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
69 PhasePlan phasePlan = new PhasePlan();
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
70 GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.NONE);
a063308816d9 Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7834
diff changeset
71 phasePlan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase);
7929
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
72 phasePlan.addPhase(PhasePosition.AFTER_PARSING, new PTXPhase());
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
73 new PTXPhase().apply(graph);
8217
dce9cefed571 Draft speculation log.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7929
diff changeset
74 CompilationResult result = GraalCompiler.compileMethod(runtime, ptxBackend, target, graph.method(), graph, null, phasePlan, OptimisticOptimizations.NONE, new SpeculationLog());
8463
b2161263e9f2 Cleanup unit tests : they should not print to stdout/stderr
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8217
diff changeset
75 return result;
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 }
7929
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
77
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
78 private static class PTXPhase extends Phase {
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
79
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
80 @Override
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
81 protected void run(StructuredGraph graph) {
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
82 for (LocalNode local : graph.getNodes(LocalNode.class)) {
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
83 if (local.kind() == Kind.Object) {
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
84 local.setStamp(StampFactory.declaredNonNull(local.objectStamp().type()));
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
85 }
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
86 }
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
87 }
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
88
9ac11c77d128 Mark PTX parameters as non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7928
diff changeset
89 }
8463
b2161263e9f2 Cleanup unit tests : they should not print to stdout/stderr
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8217
diff changeset
90
b2161263e9f2 Cleanup unit tests : they should not print to stdout/stderr
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8217
diff changeset
91 public static void main(String[] args) {
b2161263e9f2 Cleanup unit tests : they should not print to stdout/stderr
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8217
diff changeset
92 BasicPTXTest basicPTXTest = new BasicPTXTest();
b2161263e9f2 Cleanup unit tests : they should not print to stdout/stderr
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8217
diff changeset
93 System.out.println("testAddSnippet: \n" + new String(basicPTXTest.test("testAddSnippet").getTargetCode()));
b2161263e9f2 Cleanup unit tests : they should not print to stdout/stderr
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8217
diff changeset
94 System.out.println("testArraySnippet: \n" + new String(basicPTXTest.test("testArraySnippet").getTargetCode()));
b2161263e9f2 Cleanup unit tests : they should not print to stdout/stderr
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8217
diff changeset
95 }
7834
13344e69455e Added basic PTX test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96 }