annotate graal/com.oracle.graal.api.directives.test/src/com/oracle/graal/api/directives/test/IterationDirectiveTest.java @ 19403:61d3cb8e1280

Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 16 Feb 2015 17:47:43 +0100
parents 2358c0e65b9e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19046
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
1 /*
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
4 *
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
8 *
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
13 * accompanied this code).
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
14 *
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
18 *
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
21 * questions.
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
22 */
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.api.directives.test;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
24
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
25 import org.junit.*;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
26
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
27 import com.oracle.graal.api.directives.*;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.compiler.test.*;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.graph.iterators.*;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.nodes.*;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
31
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
32 public class IterationDirectiveTest extends GraalCompilerTest {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
33
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
34 public static int loopFrequencySnippet(int arg) {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
35 int x = arg;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
36 while (GraalDirectives.injectIterationCount(128, x > 1)) {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
37 GraalDirectives.controlFlowAnchor(); // prevent loop peeling or unrolling
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
38 if (x % 2 == 0) {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
39 x /= 2;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
40 } else {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
41 x = 3 * x + 1;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
42 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
43 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
44 return x;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
45 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
46
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
47 @Test
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
48 public void testLoopFrequency() {
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
49 test("loopFrequencySnippet", 7);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
50 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
51
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
52 @Override
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
53 protected boolean checkLowTierGraph(StructuredGraph graph) {
19403
61d3cb8e1280 Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19046
diff changeset
54 NodeIterable<LoopBeginNode> loopBeginNodes = graph.getNodes(LoopBeginNode.TYPE);
19046
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
55 Assert.assertEquals("LoopBeginNode count", 1, loopBeginNodes.count());
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
56
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
57 LoopBeginNode loopBeginNode = loopBeginNodes.first();
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
58 Assert.assertEquals("loop frequency of " + loopBeginNode, 128, loopBeginNode.loopFrequency(), 0);
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
59
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
60 return true;
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
61 }
2358c0e65b9e Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
62 }