Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/GuardsTest.java @ 9007:bd2ace51ba04
GRAAL-221 - PTX array load and store support
author | Morris Meyer <morris.meyer@oracle.com> |
---|---|
date | Thu, 11 Apr 2013 13:47:12 -0400 |
parents | 6ef9fc7375c7 |
children | 5f7f0d3e3638 |
rev | line source |
---|---|
8596
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.codegen.test; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import static com.oracle.truffle.api.codegen.test.TestHelper.*; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import static junit.framework.Assert.*; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import org.junit.*; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.codegen.*; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.codegen.test.GuardsTestFactory.GlobalFlagGuardFactory; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.codegen.test.GuardsTestFactory.InvocationGuardFactory; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.codegen.test.TypeSystemTest.ChildrenNode; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.codegen.test.TypeSystemTest.TestRootNode; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.codegen.test.TypeSystemTest.ValueNode; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 @SuppressWarnings("unused") |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 public class GuardsTest { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 private static final Object NULL = new Object(); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 @Test |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 public void testGuardInvocations() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 TestRootNode<InvocationGuard> root = create(InvocationGuardFactory.getInstance()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 assertEquals(Integer.MAX_VALUE, executeWith(root, Integer.MAX_VALUE - 1, 1)); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 assertEquals(1, InvocationGuard.specializedInvocations); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 assertEquals(0, InvocationGuard.genericInvocations); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 assertEquals(42, executeWith(root, Integer.MAX_VALUE, 1)); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 assertEquals(1, InvocationGuard.specializedInvocations); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 assertEquals(1, InvocationGuard.genericInvocations); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 public abstract static class InvocationGuard extends ChildrenNode { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 static int specializedInvocations = 0; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 static int genericInvocations = 0; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 public InvocationGuard(ValueNode... children) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 super(children); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 public InvocationGuard(InvocationGuard node) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 super(node); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 boolean guard(int value0, int value1) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 return value0 != Integer.MAX_VALUE; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 @Specialization(guards = "guard") |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 int doSpecialized(int value0, int value1) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 specializedInvocations++; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 return value0 + value1; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 @Generic |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 int doGeneric(Object value0, Object value1) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 genericInvocations++; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 return 42; // the generic answer to all questions |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
85 @Test |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 public void testGuardGlobal() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 TestRootNode<GlobalFlagGuard> root = create(GlobalFlagGuardFactory.getInstance()); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 assertEquals(42, executeWith(root, NULL)); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
91 GlobalFlagGuard.globalFlag = true; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 assertEquals(41, executeWith(root, NULL)); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
94 GlobalFlagGuard.globalFlag = false; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
95 assertEquals(42, executeWith(root, NULL)); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
96 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 public abstract static class GlobalFlagGuard extends ChildrenNode { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 static boolean globalFlag = false; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
102 public GlobalFlagGuard(ValueNode... children) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
103 super(children); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 public GlobalFlagGuard(GlobalFlagGuard node) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 super(node); |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 static boolean globalFlagGuard() { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
111 return globalFlag; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
112 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
113 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
114 @Specialization(guards = "globalFlagGuard") |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 int doSpecialized(Object value0) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 return 41; |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 @Generic |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
120 int doGeneric(Object value0) { |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
121 return 42; // the generic answer to all questions |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
122 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
123 } |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
124 |
6ef9fc7375c7
Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
125 } |