Mercurial > hg > truffle
annotate graal/com.oracle.graal.lir/src/com/oracle/graal/lir/profiling/MoveProfiling.java @ 21543:93c50cefb9e8
moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 25 May 2015 23:30:34 +0200 |
parents | 422e60a2f4b9 |
children | 48c1ebd24120 |
rev | line source |
---|---|
19913 | 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.lir.profiling; | |
24 | |
25 import static com.oracle.graal.api.code.ValueUtil.*; | |
26 | |
27 import java.util.*; | |
28 | |
29 import com.oracle.graal.api.code.*; | |
30 import com.oracle.graal.api.meta.*; | |
31 import com.oracle.graal.compiler.common.cfg.*; | |
32 import com.oracle.graal.lir.*; | |
33 import com.oracle.graal.lir.StandardOp.BlockEndOp; | |
34 import com.oracle.graal.lir.StandardOp.LabelOp; | |
35 import com.oracle.graal.lir.StandardOp.MoveOp; | |
36 import com.oracle.graal.lir.gen.*; | |
37 import com.oracle.graal.lir.phases.*; | |
21543
93c50cefb9e8
moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
20003
diff
changeset
|
38 import com.oracle.jvmci.common.*; |
19913 | 39 |
40 public class MoveProfiling extends PostAllocationOptimizationPhase { | |
41 | |
42 @Override | |
43 protected <B extends AbstractBlockBase<B>> void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, | |
44 BenchmarkCounterFactory counterFactory) { | |
45 new Analyzer(lirGenRes.getLIR(), counterFactory).run(); | |
46 } | |
47 | |
48 private static enum MoveType { | |
49 REG2REG("Reg", "Reg"), | |
50 STACK2REG("Reg", "Stack"), | |
51 CONST2REG("Reg", "Const"), | |
52 REG2STACK("Stack", "Reg"), | |
53 CONST2STACK("Stack", "Const"); | |
54 | |
55 private final String name; | |
56 | |
57 MoveType(String dst, String src) { | |
58 this.name = String.format("%5s <- %s", dst, src); | |
59 } | |
60 | |
61 @Override | |
62 public String toString() { | |
63 return name; | |
64 } | |
65 | |
66 public static MoveType get(MoveOp move) { | |
67 AllocatableValue dst = move.getResult(); | |
68 Value src = move.getInput(); | |
69 if (isRegister(dst)) { | |
70 if (isRegister(src)) { | |
71 return REG2REG; | |
72 } | |
73 if (isStackSlot(src)) { | |
74 return STACK2REG; | |
75 } | |
76 if (isConstant(src)) { | |
77 return CONST2REG; | |
78 } | |
79 } else if (isStackSlot(dst)) { | |
80 if (isRegister(src)) { | |
81 return REG2STACK; | |
82 } | |
83 if (isConstant(src)) { | |
84 return CONST2STACK; | |
85 } | |
86 } | |
21543
93c50cefb9e8
moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
20003
diff
changeset
|
87 throw JVMCIError.shouldNotReachHere(String.format("Unrecognized Move: %s dst=%s, src=%s", move, dst, src)); |
19913 | 88 } |
89 } | |
90 | |
91 private static class Analyzer { | |
92 private final LIR lir; | |
93 private final BenchmarkCounterFactory counterFactory; | |
94 private final LIRInsertionBuffer buffer; | |
95 private final int[] cnt; | |
96 | |
97 public Analyzer(LIR lir, BenchmarkCounterFactory counterFactory) { | |
98 this.lir = lir; | |
99 this.counterFactory = counterFactory; | |
100 this.buffer = new LIRInsertionBuffer(); | |
101 cnt = new int[MoveType.values().length]; | |
102 } | |
103 | |
104 public void run() { | |
105 for (AbstractBlockBase<?> block : lir.getControlFlowGraph().getBlocks()) { | |
106 doBlock(block); | |
107 } | |
108 } | |
109 | |
110 public void doBlock(AbstractBlockBase<?> block) { | |
111 List<LIRInstruction> instructions = lir.getLIRforBlock(block); | |
112 assert instructions.size() >= 2 : "Malformed block: " + block + ", " + instructions; | |
113 assert instructions.get(instructions.size() - 1) instanceof BlockEndOp : "Not a BlockEndOp: " + instructions.get(instructions.size() - 1); | |
114 assert !(instructions.get(instructions.size() - 2) instanceof BlockEndOp) : "Is a BlockEndOp: " + instructions.get(instructions.size() - 2); | |
115 assert instructions.get(0) instanceof LabelOp : "Not a LabelOp: " + instructions.get(0); | |
116 assert !(instructions.get(1) instanceof LabelOp) : "Is a LabelOp: " + instructions.get(1); | |
117 | |
118 // reset counters | |
119 Arrays.fill(cnt, 0); | |
120 // analysis phase | |
121 for (LIRInstruction inst : instructions) { | |
122 if (inst instanceof MoveOp) { | |
123 cnt[MoveType.get((MoveOp) inst).ordinal()]++; | |
124 } | |
125 } | |
126 | |
127 // counter insertion phase | |
128 List<String> names = new ArrayList<>(); | |
129 List<Value> increments = new ArrayList<>(); | |
130 for (MoveType type : MoveType.values()) { | |
131 int i = cnt[type.ordinal()]; | |
132 if (i > 0) { | |
133 names.add(type.toString()); | |
134 increments.add(JavaConstant.forInt(i)); | |
135 } | |
136 } | |
137 String[] groups = new String[names.size()]; | |
138 Arrays.fill(groups, "Move Operations"); | |
20003
422e60a2f4b9
Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
19913
diff
changeset
|
139 if (names.size() > 0) { // Don't pollute LIR when nothing has to be done |
422e60a2f4b9
Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
19913
diff
changeset
|
140 LIRInstruction inst = counterFactory.createMultiBenchmarkCounter(names.toArray(new String[0]), groups, increments.toArray(new Value[0])); |
422e60a2f4b9
Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
19913
diff
changeset
|
141 assert inst != null; |
422e60a2f4b9
Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
19913
diff
changeset
|
142 buffer.init(instructions); |
422e60a2f4b9
Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
19913
diff
changeset
|
143 buffer.append(1, inst); |
422e60a2f4b9
Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
19913
diff
changeset
|
144 buffer.finish(); |
422e60a2f4b9
Implement dynamic instruction counters on assembly level
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
19913
diff
changeset
|
145 } |
19913 | 146 } |
147 } | |
148 | |
149 } |