Mercurial > hg > truffle
annotate graal/com.oracle.graal.api.directives.test/src/com/oracle/graal/api/directives/test/ProbabilityDirectiveTest.java @ 21400:33d3be2548d6
removed cache for intermediate graphs in ReplacementsImpl since graph building inlining is now used
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 15 May 2015 13:45:06 +0200 |
parents | 61d3cb8e1280 |
children |
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 ProbabilityDirectiveTest 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 branchProbabilitySnippet(int arg) { |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
35 if (GraalDirectives.injectBranchProbability(0.125, arg > 0)) { |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
36 GraalDirectives.controlFlowAnchor(); // prevent removal of the if |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
37 return 1; |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
38 } else { |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
39 GraalDirectives.controlFlowAnchor(); // prevent removal of the if |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
40 return 2; |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
41 } |
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 @Test |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
45 public void testBranchProbability() { |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
46 test("branchProbabilitySnippet", 5); |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
47 } |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
48 |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
49 @Override |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
50 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
|
51 NodeIterable<IfNode> ifNodes = graph.getNodes(IfNode.TYPE); |
19046
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
52 Assert.assertEquals("IfNode count", 1, ifNodes.count()); |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
53 |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
54 IfNode ifNode = ifNodes.first(); |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
55 AbstractBeginNode trueSuccessor = ifNode.trueSuccessor(); |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
56 Assert.assertEquals("branch probability of " + ifNode, 0.125, ifNode.probability(trueSuccessor), 0); |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
57 |
2358c0e65b9e
Unit tests for GraalDirectives API.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
58 return true; |
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 } |