comparison graal/Compiler/src/com/sun/c1x/lir/LIRXirInstruction.java @ 2507:9ec15d6914ca

Pull over of compiler from maxine repository.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 11:43:22 +0200
parents
children
comparison
equal deleted inserted replaced
2506:4a3bf8a5bf41 2507:9ec15d6914ca
1 /*
2 * Copyright (c) 2009, 2011, 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.sun.c1x.lir;
24
25 import java.util.*;
26
27 import com.sun.c1x.*;
28 import com.sun.c1x.gen.*;
29 import com.sun.cri.ci.*;
30 import com.sun.cri.ri.*;
31 import com.sun.cri.xir.*;
32
33 public class LIRXirInstruction extends LIRInstruction {
34
35 public final CiValue[] originalOperands;
36 public final int outputOperandIndex;
37 public final int[] operandIndices;
38 public final XirSnippet snippet;
39 public final RiMethod method;
40 public final int inputTempCount;
41 public final int tempCount;
42 public final int inputCount;
43 public final List<CiValue> pointerSlots;
44 public final LIRDebugInfo infoAfter;
45
46 public LIRXirInstruction(XirSnippet snippet,
47 CiValue[] originalOperands,
48 CiValue outputOperand,
49 int inputTempCount,
50 int tempCount,
51 CiValue[] operands,
52 int[] operandIndices,
53 int outputOperandIndex,
54 LIRDebugInfo info,
55 LIRDebugInfo infoAfter,
56 RiMethod method,
57 List<CiValue> pointerSlots) {
58 super(LIROpcode.Xir, outputOperand, info, false, inputTempCount, tempCount, operands);
59 this.infoAfter = infoAfter;
60 this.pointerSlots = pointerSlots;
61 assert this.pointerSlots == null || this.pointerSlots.size() >= 0;
62 this.method = method;
63 this.snippet = snippet;
64 this.operandIndices = operandIndices;
65 this.outputOperandIndex = outputOperandIndex;
66 this.originalOperands = originalOperands;
67 this.inputTempCount = inputTempCount;
68 this.tempCount = tempCount;
69 this.inputCount = operands.length - inputTempCount - tempCount;
70
71 C1XMetrics.LIRXIRInstructions++;
72 }
73
74 public CiValue[] getOperands() {
75 for (int i = 0; i < operandIndices.length; i++) {
76 originalOperands[operandIndices[i]] = operand(i);
77 }
78 if (outputOperandIndex != -1) {
79 originalOperands[outputOperandIndex] = result();
80 }
81 return originalOperands;
82 }
83
84 /**
85 * Emits target assembly code for this instruction.
86 *
87 * @param masm the target assembler
88 */
89 @Override
90 public void emitCode(LIRAssembler masm) {
91 masm.emitXir(this);
92 }
93
94 /**
95 * Prints this instruction.
96 */
97 @Override
98 public String operationString(OperandFormatter operandFmt) {
99 return toString(operandFmt);
100 }
101
102 @Override
103 public String toString(OperandFormatter operandFmt) {
104 StringBuilder sb = new StringBuilder();
105 sb.append("XIR: ");
106
107 if (result().isLegal()) {
108 sb.append(operandFmt.format(result()) + " = ");
109 }
110
111 sb.append(snippet.template);
112 sb.append("(");
113 for (int i = 0; i < snippet.arguments.length; i++) {
114 XirArgument a = snippet.arguments[i];
115 if (i > 0) {
116 sb.append(", ");
117 }
118 if (a.constant != null) {
119 sb.append(operandFmt.format(a.constant));
120 } else {
121 Object o = a.object;
122 if (o instanceof LIRItem) {
123 sb.append(operandFmt.format(((LIRItem) o).result()));
124 } else if (o instanceof CiValue) {
125 sb.append(operandFmt.format((CiValue) o));
126 } else {
127 sb.append(o);
128 }
129 }
130 }
131 sb.append(')');
132
133 if (method != null) {
134 sb.append(" method=");
135 sb.append(method.toString());
136 }
137
138
139 for (LIRInstruction.OperandMode mode : LIRInstruction.OPERAND_MODES) {
140 int n = operandCount(mode);
141 if (mode == OperandMode.Output && n <= 1) {
142 // Already printed single output (i.e. result())
143 continue;
144 }
145 if (n != 0) {
146 sb.append(' ').append(mode.name().toLowerCase()).append("=(");
147 HashSet<String> operands = new HashSet<String>();
148 for (int i = 0; i < n; i++) {
149 String operand = operandFmt.format(operandAt(mode, i));
150 if (!operands.contains(operand)) {
151 if (!operands.isEmpty()) {
152 sb.append(", ");
153 }
154 operands.add(operand);
155 sb.append(operand);
156 }
157 }
158 sb.append(')');
159 }
160 }
161
162 appendDebugInfo(sb, operandFmt, info);
163
164 return sb.toString();
165 }
166 }