Mercurial > hg > truffle
comparison graal/com.oracle.graal.api.directives.test/src/com/oracle/graal/api/directives/test/IterationDirectiveTest.java @ 19046:2358c0e65b9e
Unit tests for GraalDirectives API.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Thu, 29 Jan 2015 16:49:03 +0100 |
parents | |
children | 61d3cb8e1280 |
comparison
equal
deleted
inserted
replaced
19045:862997951c0a | 19046:2358c0e65b9e |
---|---|
1 /* | |
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. | |
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 */ | |
23 package com.oracle.graal.api.directives.test; | |
24 | |
25 import org.junit.*; | |
26 | |
27 import com.oracle.graal.api.directives.*; | |
28 import com.oracle.graal.compiler.test.*; | |
29 import com.oracle.graal.graph.iterators.*; | |
30 import com.oracle.graal.nodes.*; | |
31 | |
32 public class IterationDirectiveTest extends GraalCompilerTest { | |
33 | |
34 public static int loopFrequencySnippet(int arg) { | |
35 int x = arg; | |
36 while (GraalDirectives.injectIterationCount(128, x > 1)) { | |
37 GraalDirectives.controlFlowAnchor(); // prevent loop peeling or unrolling | |
38 if (x % 2 == 0) { | |
39 x /= 2; | |
40 } else { | |
41 x = 3 * x + 1; | |
42 } | |
43 } | |
44 return x; | |
45 } | |
46 | |
47 @Test | |
48 public void testLoopFrequency() { | |
49 test("loopFrequencySnippet", 7); | |
50 } | |
51 | |
52 @Override | |
53 protected boolean checkLowTierGraph(StructuredGraph graph) { | |
54 NodeIterable<LoopBeginNode> loopBeginNodes = graph.getNodes(LoopBeginNode.class); | |
55 Assert.assertEquals("LoopBeginNode count", 1, loopBeginNodes.count()); | |
56 | |
57 LoopBeginNode loopBeginNode = loopBeginNodes.first(); | |
58 Assert.assertEquals("loop frequency of " + loopBeginNode, 128, loopBeginNode.loopFrequency(), 0); | |
59 | |
60 return true; | |
61 } | |
62 } |