annotate graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/backend/AllocatorTest.java @ 13217:210f58e992a1

Use separate method profile for OSR compilations.
author Roland Schatz <roland.schatz@oracle.com>
date Tue, 03 Dec 2013 11:28:56 +0100
parents 8569b9e047cd
children f4f0a8a01ce0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
1 /*
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
4 *
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
8 *
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
13 * accompanied this code).
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
14 *
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
18 *
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
21 * questions.
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
22 */
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.compiler.test.backend;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
24
9612
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 8636
diff changeset
25 import static com.oracle.graal.api.code.CodeUtil.*;
9864
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9626
diff changeset
26 import static com.oracle.graal.phases.GraalOptions.*;
9612
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 8636
diff changeset
27
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
28 import java.util.*;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
29
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
30 import org.junit.*;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
31
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.api.code.*;
9612
66db0353f55a compilation is explicitly given a CallingConvention for the graph being compiled instead of deriving it from a method
Doug Simon <doug.simon@oracle.com>
parents: 8636
diff changeset
33 import com.oracle.graal.api.code.CallingConvention.Type;
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.api.meta.*;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.compiler.*;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.compiler.test.*;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.debug.*;
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
38 import com.oracle.graal.debug.Debug.Scope;
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
39 import com.oracle.graal.lir.*;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
40 import com.oracle.graal.lir.LIRInstruction.ValueProcedure;
8143
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
41 import com.oracle.graal.lir.StandardOp.MoveOp;
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
42 import com.oracle.graal.nodes.*;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
43 import com.oracle.graal.nodes.cfg.*;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
44 import com.oracle.graal.phases.*;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
45
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
46 public class AllocatorTest extends GraalCompilerTest {
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
47
8190
87cb93643a47 Move platform specific assumptions from AllocatorTest to a separate project.
Roland Schatz <roland.schatz@oracle.com>
parents: 8143
diff changeset
48 protected void test(String snippet, final int expectedRegisters, final int expectedRegRegMoves, final int expectedSpillMoves) {
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
49 final StructuredGraph graph = parse(snippet);
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
50 try (Scope s = Debug.scope("AllocatorTest", graph, graph.method(), getCodeCache())) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
51 final RegisterStats stats = getRegisterStats(graph);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
52 try (Scope s2 = Debug.scope("Assertions", stats.lir)) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
53 Assert.assertEquals("register count", expectedRegisters, stats.registers.size());
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
54 Assert.assertEquals("reg-reg moves", expectedRegRegMoves, stats.regRegMoves);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
55 Assert.assertEquals("spill moves", expectedSpillMoves, stats.spillMoves);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
56 } catch (Throwable e) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
57 throw Debug.handle(e);
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
58 }
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
59 } catch (Throwable e) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
60 throw Debug.handle(e);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
61 }
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
62 }
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
63
8190
87cb93643a47 Move platform specific assumptions from AllocatorTest to a separate project.
Roland Schatz <roland.schatz@oracle.com>
parents: 8143
diff changeset
64 private class RegisterStats {
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
65
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
66 public final LIR lir;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
67 public HashSet<Register> registers = new HashSet<>();
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
68 public int regRegMoves;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
69 public int spillMoves;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
70
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
71 public RegisterStats(LIR lir) {
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
72 this.lir = lir;
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
73
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
74 for (Block block : lir.codeEmittingOrder()) {
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
75 for (LIRInstruction instr : lir.lir(block)) {
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
76 collectStats(instr);
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
77 }
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
78 }
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
79 }
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
80
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
81 private void collectStats(final LIRInstruction instr) {
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
82 instr.forEachOutput(new ValueProcedure() {
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
83
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
84 @Override
8143
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
85 public Value doValue(Value value) {
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
86 if (ValueUtil.isRegister(value)) {
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
87 final Register reg = ValueUtil.asRegister(value);
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
88 registers.add(reg);
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
89 }
8143
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
90 return value;
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
91 }
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
92 });
8143
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
93
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
94 if (instr instanceof MoveOp) {
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
95 MoveOp move = (MoveOp) instr;
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
96 Value def = move.getResult();
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
97 Value use = move.getInput();
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
98 if (ValueUtil.isRegister(def)) {
9626
29abc1e22280 AllocatorTest: relax counting-condition for MoveOp
Bernhard Urban <bernhard.urban@jku.at>
parents: 9614
diff changeset
99 if (ValueUtil.isRegister(use)) {
8143
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
100 regRegMoves++;
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
101 }
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
102 } else if (ValueUtil.isStackSlot(def)) {
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
103 spillMoves++;
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
104 }
569b7d482918 Use MoveOp marker interface in AllocatorTest.
Roland Schatz <roland.schatz@oracle.com>
parents: 8126
diff changeset
105 }
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
106 }
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
107 }
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
108
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
109 private RegisterStats getRegisterStats(final StructuredGraph graph) {
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
110 final PhasePlan phasePlan = getDefaultPhasePlan();
9864
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9626
diff changeset
111 final Assumptions assumptions = new Assumptions(OptAssumptions.getValue());
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
112
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
113 LIR lir = null;
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
114 try (Scope s = Debug.scope("FrontEnd")) {
13217
210f58e992a1 Use separate method profile for OSR compilations.
Roland Schatz <roland.schatz@oracle.com>
parents: 13197
diff changeset
115 lir = GraalCompiler.emitHIR(getProviders(), getBackend().getTarget(), graph, assumptions, null, phasePlan, OptimisticOptimizations.NONE, graph.method().getProfilingInfo(),
210f58e992a1 Use separate method profile for OSR compilations.
Roland Schatz <roland.schatz@oracle.com>
parents: 13197
diff changeset
116 new SpeculationLog(), getSuites());
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
117 } catch (Throwable e) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
118 throw Debug.handle(e);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
119 }
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
120
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
121 try (Scope s = Debug.scope("BackEnd", lir)) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
122 CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graph.method(), false);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
123 GraalCompiler.emitLIR(getBackend(), getBackend().getTarget(), lir, graph, cc);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
124 return new RegisterStats(lir);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
125 } catch (Throwable e) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
126 throw Debug.handle(e);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 12456
diff changeset
127 }
8126
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
128 }
22bbd34705ed Unit tests for register allocator.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
129 }