43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2013, 2016, 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 org.graalvm.compiler.core.aarch64;
|
|
24 |
|
|
25 |
import static org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant;
|
|
26 |
import static org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant;
|
|
27 |
|
|
28 |
import java.util.function.Function;
|
|
29 |
|
|
30 |
import org.graalvm.compiler.asm.aarch64.AArch64Address.AddressingMode;
|
|
31 |
import org.graalvm.compiler.asm.aarch64.AArch64Assembler.ConditionFlag;
|
|
32 |
import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
|
|
33 |
import org.graalvm.compiler.core.common.LIRKind;
|
|
34 |
import org.graalvm.compiler.core.common.calc.Condition;
|
|
35 |
import org.graalvm.compiler.core.common.spi.LIRKindTool;
|
|
36 |
import org.graalvm.compiler.debug.GraalError;
|
|
37 |
import org.graalvm.compiler.lir.LIRFrameState;
|
|
38 |
import org.graalvm.compiler.lir.LIRValueUtil;
|
|
39 |
import org.graalvm.compiler.lir.LabelRef;
|
|
40 |
import org.graalvm.compiler.lir.StandardOp;
|
|
41 |
import org.graalvm.compiler.lir.SwitchStrategy;
|
|
42 |
import org.graalvm.compiler.lir.Variable;
|
|
43 |
import org.graalvm.compiler.lir.aarch64.AArch64AddressValue;
|
|
44 |
import org.graalvm.compiler.lir.aarch64.AArch64ArithmeticOp;
|
49873
|
45 |
import org.graalvm.compiler.lir.aarch64.AArch64ArrayCompareToOp;
|
46344
|
46 |
import org.graalvm.compiler.lir.aarch64.AArch64ArrayEqualsOp;
|
|
47 |
import org.graalvm.compiler.lir.aarch64.AArch64ByteSwapOp;
|
43972
|
48 |
import org.graalvm.compiler.lir.aarch64.AArch64Compare;
|
|
49 |
import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow;
|
|
50 |
import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.BranchOp;
|
|
51 |
import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.CondMoveOp;
|
|
52 |
import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.StrategySwitchOp;
|
46344
|
53 |
import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.TableSwitchOp;
|
43972
|
54 |
import org.graalvm.compiler.lir.aarch64.AArch64Move;
|
49873
|
55 |
import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.CompareAndSwapOp;
|
43972
|
56 |
import org.graalvm.compiler.lir.aarch64.AArch64Move.MembarOp;
|
|
57 |
import org.graalvm.compiler.lir.aarch64.AArch64PauseOp;
|
|
58 |
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
|
|
59 |
import org.graalvm.compiler.lir.gen.LIRGenerator;
|
|
60 |
import org.graalvm.compiler.phases.util.Providers;
|
|
61 |
|
49873
|
62 |
import jdk.vm.ci.aarch64.AArch64;
|
43972
|
63 |
import jdk.vm.ci.aarch64.AArch64Kind;
|
46344
|
64 |
import jdk.vm.ci.code.CallingConvention;
|
43972
|
65 |
import jdk.vm.ci.code.RegisterValue;
|
|
66 |
import jdk.vm.ci.meta.AllocatableValue;
|
|
67 |
import jdk.vm.ci.meta.JavaConstant;
|
|
68 |
import jdk.vm.ci.meta.JavaKind;
|
|
69 |
import jdk.vm.ci.meta.PlatformKind;
|
|
70 |
import jdk.vm.ci.meta.PrimitiveConstant;
|
|
71 |
import jdk.vm.ci.meta.Value;
|
|
72 |
import jdk.vm.ci.meta.ValueKind;
|
|
73 |
|
|
74 |
public abstract class AArch64LIRGenerator extends LIRGenerator {
|
|
75 |
|
|
76 |
public AArch64LIRGenerator(LIRKindTool lirKindTool, AArch64ArithmeticLIRGenerator arithmeticLIRGen, MoveFactory moveFactory, Providers providers, LIRGenerationResult lirGenRes) {
|
|
77 |
super(lirKindTool, arithmeticLIRGen, moveFactory, providers, lirGenRes);
|
|
78 |
}
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Checks whether the supplied constant can be used without loading it into a register for store
|
|
82 |
* operations, i.e., on the right hand side of a memory access.
|
|
83 |
*
|
|
84 |
* @param c The constant to check.
|
|
85 |
* @return True if the constant can be used directly, false if the constant needs to be in a
|
|
86 |
* register.
|
|
87 |
*/
|
|
88 |
protected static final boolean canStoreConstant(JavaConstant c) {
|
|
89 |
// Our own code never calls this since we can't make a definite statement about whether or
|
|
90 |
// not we can inline a constant without knowing what kind of operation we execute. Let's be
|
|
91 |
// optimistic here and fix up mistakes later.
|
|
92 |
return true;
|
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
* AArch64 cannot use anything smaller than a word in any instruction other than load and store.
|
|
97 |
*/
|
|
98 |
@Override
|
|
99 |
public <K extends ValueKind<K>> K toRegisterKind(K kind) {
|
|
100 |
switch ((AArch64Kind) kind.getPlatformKind()) {
|
|
101 |
case BYTE:
|
|
102 |
case WORD:
|
|
103 |
return kind.changeType(AArch64Kind.DWORD);
|
|
104 |
default:
|
|
105 |
return kind;
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
@Override
|
|
110 |
public void emitNullCheck(Value address, LIRFrameState state) {
|
|
111 |
append(new AArch64Move.NullCheckOp(asAddressValue(address), state));
|
|
112 |
}
|
|
113 |
|
|
114 |
@Override
|
|
115 |
public Variable emitAddress(AllocatableValue stackslot) {
|
|
116 |
Variable result = newVariable(LIRKind.value(target().arch.getWordKind()));
|
|
117 |
append(new AArch64Move.StackLoadAddressOp(result, stackslot));
|
|
118 |
return result;
|
|
119 |
}
|
|
120 |
|
|
121 |
public AArch64AddressValue asAddressValue(Value address) {
|
|
122 |
if (address instanceof AArch64AddressValue) {
|
|
123 |
return (AArch64AddressValue) address;
|
|
124 |
} else {
|
46536
|
125 |
return new AArch64AddressValue(address.getValueKind(), asAllocatable(address), Value.ILLEGAL, 0, 1, AddressingMode.BASE_REGISTER_ONLY);
|
43972
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
@Override
|
46344
|
130 |
public Variable emitLogicCompareAndSwap(Value address, Value expectedValue, Value newValue, Value trueValue, Value falseValue) {
|
|
131 |
Variable prevValue = newVariable(expectedValue.getValueKind());
|
|
132 |
Variable scratch = newVariable(LIRKind.value(AArch64Kind.DWORD));
|
|
133 |
append(new CompareAndSwapOp(prevValue, loadReg(expectedValue), loadReg(newValue), asAllocatable(address), scratch));
|
|
134 |
assert trueValue.getValueKind().equals(falseValue.getValueKind());
|
43972
|
135 |
Variable result = newVariable(trueValue.getValueKind());
|
46344
|
136 |
append(new CondMoveOp(result, ConditionFlag.EQ, asAllocatable(trueValue), asAllocatable(falseValue)));
|
|
137 |
return result;
|
|
138 |
}
|
|
139 |
|
|
140 |
@Override
|
|
141 |
public Variable emitValueCompareAndSwap(Value address, Value expectedValue, Value newValue) {
|
|
142 |
Variable result = newVariable(newValue.getValueKind());
|
43972
|
143 |
Variable scratch = newVariable(LIRKind.value(AArch64Kind.WORD));
|
|
144 |
append(new CompareAndSwapOp(result, loadNonCompareConst(expectedValue), loadReg(newValue), asAllocatable(address), scratch));
|
|
145 |
return result;
|
|
146 |
}
|
|
147 |
|
|
148 |
@Override
|
|
149 |
public void emitMembar(int barriers) {
|
|
150 |
int necessaryBarriers = target().arch.requiredBarriers(barriers);
|
|
151 |
if (target().isMP && necessaryBarriers != 0) {
|
|
152 |
append(new MembarOp(necessaryBarriers));
|
|
153 |
}
|
|
154 |
}
|
|
155 |
|
|
156 |
@Override
|
|
157 |
public void emitJump(LabelRef label) {
|
|
158 |
assert label != null;
|
|
159 |
append(new StandardOp.JumpOp(label));
|
|
160 |
}
|
|
161 |
|
|
162 |
@Override
|
|
163 |
public void emitOverflowCheckBranch(LabelRef overflow, LabelRef noOverflow, LIRKind cmpKind, double overflowProbability) {
|
|
164 |
append(new AArch64ControlFlow.BranchOp(ConditionFlag.VS, overflow, noOverflow, overflowProbability));
|
|
165 |
}
|
|
166 |
|
|
167 |
/**
|
|
168 |
* Branches to label if (left & right) == 0. If negated is true branchse on non-zero instead.
|
|
169 |
*
|
|
170 |
* @param left Integer kind. Non null.
|
|
171 |
* @param right Integer kind. Non null.
|
|
172 |
* @param trueDestination destination if left & right == 0. Non null.
|
|
173 |
* @param falseDestination destination if left & right != 0. Non null
|
|
174 |
* @param trueSuccessorProbability hoistoric probability that comparison is true
|
|
175 |
*/
|
|
176 |
@Override
|
|
177 |
public void emitIntegerTestBranch(Value left, Value right, LabelRef trueDestination, LabelRef falseDestination, double trueSuccessorProbability) {
|
|
178 |
assert ((AArch64Kind) left.getPlatformKind()).isInteger() && left.getPlatformKind() == right.getPlatformKind();
|
|
179 |
((AArch64ArithmeticLIRGenerator) getArithmetic()).emitBinary(LIRKind.combine(left, right), AArch64ArithmeticOp.ANDS, true, left, right);
|
|
180 |
append(new AArch64ControlFlow.BranchOp(ConditionFlag.EQ, trueDestination, falseDestination, trueSuccessorProbability));
|
|
181 |
}
|
|
182 |
|
|
183 |
/**
|
|
184 |
* Conditionally move trueValue into new variable if cond + unorderedIsTrue is true, else
|
|
185 |
* falseValue.
|
|
186 |
*
|
|
187 |
* @param left Arbitrary value. Has to have same type as right. Non null.
|
|
188 |
* @param right Arbitrary value. Has to have same type as left. Non null.
|
|
189 |
* @param cond condition that decides whether to move trueValue or falseValue into result. Non
|
|
190 |
* null.
|
|
191 |
* @param unorderedIsTrue defines whether floating-point comparisons consider unordered true or
|
|
192 |
* not. Ignored for integer comparisons.
|
|
193 |
* @param trueValue arbitrary value same type as falseValue. Non null.
|
|
194 |
* @param falseValue arbitrary value same type as trueValue. Non null.
|
|
195 |
* @return value containing trueValue if cond + unorderedIsTrue is true, else falseValue. Non
|
|
196 |
* null.
|
|
197 |
*/
|
|
198 |
@Override
|
|
199 |
public Variable emitConditionalMove(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue) {
|
|
200 |
boolean mirrored = emitCompare(cmpKind, left, right, cond, unorderedIsTrue);
|
|
201 |
Condition finalCondition = mirrored ? cond.mirror() : cond;
|
|
202 |
boolean finalUnorderedIsTrue = mirrored ? !unorderedIsTrue : unorderedIsTrue;
|
|
203 |
ConditionFlag cmpCondition = toConditionFlag(((AArch64Kind) cmpKind).isInteger(), finalCondition, finalUnorderedIsTrue);
|
|
204 |
Variable result = newVariable(trueValue.getValueKind());
|
|
205 |
append(new CondMoveOp(result, cmpCondition, loadReg(trueValue), loadReg(falseValue)));
|
|
206 |
return result;
|
|
207 |
}
|
|
208 |
|
|
209 |
@Override
|
|
210 |
public void emitCompareBranch(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination,
|
|
211 |
double trueDestinationProbability) {
|
|
212 |
boolean mirrored = emitCompare(cmpKind, left, right, cond, unorderedIsTrue);
|
|
213 |
Condition finalCondition = mirrored ? cond.mirror() : cond;
|
|
214 |
boolean finalUnorderedIsTrue = mirrored ? !unorderedIsTrue : unorderedIsTrue;
|
|
215 |
ConditionFlag cmpCondition = toConditionFlag(((AArch64Kind) cmpKind).isInteger(), finalCondition, finalUnorderedIsTrue);
|
|
216 |
append(new BranchOp(cmpCondition, trueDestination, falseDestination, trueDestinationProbability));
|
|
217 |
}
|
|
218 |
|
|
219 |
private static ConditionFlag toConditionFlag(boolean isInt, Condition cond, boolean unorderedIsTrue) {
|
|
220 |
return isInt ? toIntConditionFlag(cond) : toFloatConditionFlag(cond, unorderedIsTrue);
|
|
221 |
}
|
|
222 |
|
|
223 |
/**
|
|
224 |
* Takes a Condition and unorderedIsTrue flag and returns the correct Aarch64 specific
|
|
225 |
* ConditionFlag. Note: This is only correct if the emitCompare code for floats has correctly
|
|
226 |
* handled the case of 'EQ && unorderedIsTrue', respectively 'NE && !unorderedIsTrue'!
|
|
227 |
*/
|
|
228 |
private static ConditionFlag toFloatConditionFlag(Condition cond, boolean unorderedIsTrue) {
|
|
229 |
switch (cond) {
|
|
230 |
case LT:
|
|
231 |
return unorderedIsTrue ? ConditionFlag.LT : ConditionFlag.LO;
|
|
232 |
case LE:
|
|
233 |
return unorderedIsTrue ? ConditionFlag.LE : ConditionFlag.LS;
|
|
234 |
case GE:
|
|
235 |
return unorderedIsTrue ? ConditionFlag.PL : ConditionFlag.GE;
|
|
236 |
case GT:
|
|
237 |
return unorderedIsTrue ? ConditionFlag.HI : ConditionFlag.GT;
|
|
238 |
case EQ:
|
|
239 |
return ConditionFlag.EQ;
|
|
240 |
case NE:
|
|
241 |
return ConditionFlag.NE;
|
|
242 |
default:
|
|
243 |
throw GraalError.shouldNotReachHere();
|
|
244 |
}
|
|
245 |
}
|
|
246 |
|
|
247 |
/**
|
|
248 |
* Takes a Condition and returns the correct Aarch64 specific ConditionFlag.
|
|
249 |
*/
|
|
250 |
private static ConditionFlag toIntConditionFlag(Condition cond) {
|
|
251 |
switch (cond) {
|
|
252 |
case EQ:
|
|
253 |
return ConditionFlag.EQ;
|
|
254 |
case NE:
|
|
255 |
return ConditionFlag.NE;
|
|
256 |
case LT:
|
|
257 |
return ConditionFlag.LT;
|
|
258 |
case LE:
|
|
259 |
return ConditionFlag.LE;
|
|
260 |
case GT:
|
|
261 |
return ConditionFlag.GT;
|
|
262 |
case GE:
|
|
263 |
return ConditionFlag.GE;
|
|
264 |
case AE:
|
|
265 |
return ConditionFlag.HS;
|
|
266 |
case BE:
|
|
267 |
return ConditionFlag.LS;
|
|
268 |
case AT:
|
|
269 |
return ConditionFlag.HI;
|
|
270 |
case BT:
|
|
271 |
return ConditionFlag.LO;
|
|
272 |
default:
|
|
273 |
throw GraalError.shouldNotReachHere();
|
|
274 |
}
|
|
275 |
}
|
|
276 |
|
|
277 |
/**
|
|
278 |
* This method emits the compare instruction, and may reorder the operands. It returns true if
|
|
279 |
* it did so.
|
|
280 |
*
|
|
281 |
* @param a the left operand of the comparison. Has to have same type as b. Non null.
|
|
282 |
* @param b the right operand of the comparison. Has to have same type as a. Non null.
|
|
283 |
* @return true if mirrored (i.e. "b cmp a" instead of "a cmp b" was done).
|
|
284 |
*/
|
|
285 |
protected boolean emitCompare(PlatformKind cmpKind, Value a, Value b, Condition condition, boolean unorderedIsTrue) {
|
|
286 |
Value left;
|
|
287 |
Value right;
|
|
288 |
boolean mirrored;
|
|
289 |
AArch64Kind kind = (AArch64Kind) cmpKind;
|
|
290 |
if (kind.isInteger()) {
|
46344
|
291 |
Value aExt = a;
|
|
292 |
Value bExt = b;
|
|
293 |
|
|
294 |
int compareBytes = cmpKind.getSizeInBytes();
|
|
295 |
// AArch64 compares 32 or 64 bits: sign extend a and b as required.
|
|
296 |
if (compareBytes < a.getPlatformKind().getSizeInBytes()) {
|
|
297 |
aExt = arithmeticLIRGen.emitSignExtend(a, compareBytes * 8, 64);
|
|
298 |
}
|
|
299 |
if (compareBytes < b.getPlatformKind().getSizeInBytes()) {
|
|
300 |
bExt = arithmeticLIRGen.emitSignExtend(b, compareBytes * 8, 64);
|
|
301 |
}
|
|
302 |
|
|
303 |
if (LIRValueUtil.isVariable(bExt)) {
|
|
304 |
left = load(bExt);
|
|
305 |
right = loadNonConst(aExt);
|
43972
|
306 |
mirrored = true;
|
|
307 |
} else {
|
46344
|
308 |
left = load(aExt);
|
|
309 |
right = loadNonConst(bExt);
|
43972
|
310 |
mirrored = false;
|
|
311 |
}
|
|
312 |
append(new AArch64Compare.CompareOp(left, loadNonCompareConst(right)));
|
|
313 |
} else if (kind.isSIMD()) {
|
|
314 |
if (AArch64Compare.FloatCompareOp.isFloatCmpConstant(a, condition, unorderedIsTrue)) {
|
|
315 |
left = load(b);
|
|
316 |
right = a;
|
|
317 |
mirrored = true;
|
|
318 |
} else if (AArch64Compare.FloatCompareOp.isFloatCmpConstant(b, condition, unorderedIsTrue)) {
|
|
319 |
left = load(a);
|
|
320 |
right = b;
|
|
321 |
mirrored = false;
|
|
322 |
} else {
|
|
323 |
left = load(a);
|
|
324 |
right = loadReg(b);
|
|
325 |
mirrored = false;
|
|
326 |
}
|
|
327 |
append(new AArch64Compare.FloatCompareOp(left, asAllocatable(right), condition, unorderedIsTrue));
|
|
328 |
} else {
|
|
329 |
throw GraalError.shouldNotReachHere();
|
|
330 |
}
|
|
331 |
return mirrored;
|
|
332 |
}
|
|
333 |
|
|
334 |
/**
|
|
335 |
* If value is a constant that cannot be used directly with a gpCompare instruction load it into
|
|
336 |
* a register and return the register, otherwise return constant value unchanged.
|
|
337 |
*/
|
|
338 |
protected Value loadNonCompareConst(Value value) {
|
|
339 |
if (!isCompareConstant(value)) {
|
|
340 |
return loadReg(value);
|
|
341 |
}
|
|
342 |
return value;
|
|
343 |
}
|
|
344 |
|
|
345 |
/**
|
|
346 |
* Checks whether value can be used directly with a gpCompare instruction. This is <b>not</b>
|
|
347 |
* the same as {@link AArch64ArithmeticLIRGenerator#isArithmeticConstant(JavaConstant)}, because
|
|
348 |
* 0.0 is a valid compare constant for floats, while there are no arithmetic constants for
|
|
349 |
* floats.
|
|
350 |
*
|
|
351 |
* @param value any type. Non null.
|
|
352 |
* @return true if value can be used directly in comparison instruction, false otherwise.
|
|
353 |
*/
|
|
354 |
public boolean isCompareConstant(Value value) {
|
|
355 |
if (isJavaConstant(value)) {
|
|
356 |
JavaConstant constant = asJavaConstant(value);
|
|
357 |
if (constant instanceof PrimitiveConstant) {
|
|
358 |
final long longValue = constant.asLong();
|
|
359 |
long maskedValue;
|
|
360 |
switch (constant.getJavaKind()) {
|
|
361 |
case Boolean:
|
|
362 |
case Byte:
|
|
363 |
maskedValue = longValue & 0xFF;
|
|
364 |
break;
|
|
365 |
case Char:
|
|
366 |
case Short:
|
|
367 |
maskedValue = longValue & 0xFFFF;
|
|
368 |
break;
|
|
369 |
case Int:
|
|
370 |
maskedValue = longValue & 0xFFFF_FFFF;
|
|
371 |
break;
|
|
372 |
case Long:
|
|
373 |
maskedValue = longValue;
|
|
374 |
break;
|
|
375 |
default:
|
|
376 |
throw GraalError.shouldNotReachHere();
|
|
377 |
}
|
|
378 |
return AArch64MacroAssembler.isArithmeticImmediate(maskedValue);
|
|
379 |
} else {
|
|
380 |
return constant.isDefaultForKind();
|
|
381 |
}
|
|
382 |
}
|
|
383 |
return false;
|
|
384 |
}
|
|
385 |
|
|
386 |
/**
|
|
387 |
* Moves trueValue into result if (left & right) == 0, else falseValue.
|
|
388 |
*
|
|
389 |
* @param left Integer kind. Non null.
|
|
390 |
* @param right Integer kind. Non null.
|
|
391 |
* @param trueValue Integer kind. Non null.
|
|
392 |
* @param falseValue Integer kind. Non null.
|
|
393 |
* @return virtual register containing trueValue if (left & right) == 0, else falseValue.
|
|
394 |
*/
|
|
395 |
@Override
|
|
396 |
public Variable emitIntegerTestMove(Value left, Value right, Value trueValue, Value falseValue) {
|
|
397 |
assert ((AArch64Kind) left.getPlatformKind()).isInteger() && ((AArch64Kind) right.getPlatformKind()).isInteger();
|
|
398 |
assert ((AArch64Kind) trueValue.getPlatformKind()).isInteger() && ((AArch64Kind) falseValue.getPlatformKind()).isInteger();
|
46344
|
399 |
((AArch64ArithmeticLIRGenerator) getArithmetic()).emitBinary(left.getValueKind(), AArch64ArithmeticOp.ANDS, true, left, right);
|
43972
|
400 |
Variable result = newVariable(trueValue.getValueKind());
|
|
401 |
append(new CondMoveOp(result, ConditionFlag.EQ, load(trueValue), load(falseValue)));
|
|
402 |
return result;
|
|
403 |
}
|
|
404 |
|
|
405 |
@Override
|
|
406 |
public void emitStrategySwitch(SwitchStrategy strategy, Variable key, LabelRef[] keyTargets, LabelRef defaultTarget) {
|
|
407 |
append(createStrategySwitchOp(strategy, keyTargets, defaultTarget, key, newVariable(key.getValueKind()), AArch64LIRGenerator::toIntConditionFlag));
|
|
408 |
}
|
|
409 |
|
|
410 |
protected StrategySwitchOp createStrategySwitchOp(SwitchStrategy strategy, LabelRef[] keyTargets, LabelRef defaultTarget, Variable key, AllocatableValue scratchValue,
|
|
411 |
Function<Condition, ConditionFlag> converter) {
|
|
412 |
return new StrategySwitchOp(strategy, keyTargets, defaultTarget, key, scratchValue, converter);
|
|
413 |
}
|
|
414 |
|
|
415 |
@Override
|
|
416 |
protected void emitTableSwitch(int lowKey, LabelRef defaultTarget, LabelRef[] targets, Value key) {
|
46344
|
417 |
append(new TableSwitchOp(lowKey, defaultTarget, targets, key, newVariable(LIRKind.value(target().arch.getWordKind())), newVariable(key.getValueKind())));
|
43972
|
418 |
}
|
|
419 |
|
|
420 |
@Override
|
46344
|
421 |
public Variable emitByteSwap(Value input) {
|
|
422 |
Variable result = newVariable(LIRKind.combine(input));
|
|
423 |
append(new AArch64ByteSwapOp(result, input));
|
|
424 |
return result;
|
43972
|
425 |
}
|
|
426 |
|
|
427 |
@Override
|
49873
|
428 |
public Variable emitArrayCompareTo(JavaKind kind1, JavaKind kind2, Value array1, Value array2, Value length1, Value length2) {
|
|
429 |
LIRKind resultKind = LIRKind.value(AArch64Kind.DWORD);
|
|
430 |
// DMS TODO: check calling conversion and registers used
|
|
431 |
RegisterValue res = AArch64.r0.asValue(resultKind);
|
|
432 |
RegisterValue cnt1 = AArch64.r1.asValue(length1.getValueKind());
|
|
433 |
RegisterValue cnt2 = AArch64.r2.asValue(length2.getValueKind());
|
|
434 |
emitMove(cnt1, length1);
|
|
435 |
emitMove(cnt2, length2);
|
|
436 |
append(new AArch64ArrayCompareToOp(this, kind1, kind2, res, array1, array2, cnt1, cnt2));
|
|
437 |
Variable result = newVariable(resultKind);
|
|
438 |
emitMove(result, res);
|
|
439 |
return result;
|
|
440 |
}
|
|
441 |
|
|
442 |
@Override
|
43972
|
443 |
public Variable emitArrayEquals(JavaKind kind, Value array1, Value array2, Value length) {
|
46344
|
444 |
Variable result = newVariable(LIRKind.value(AArch64Kind.DWORD));
|
|
445 |
append(new AArch64ArrayEqualsOp(this, kind, result, array1, array2, asAllocatable(length)));
|
|
446 |
return result;
|
43972
|
447 |
}
|
|
448 |
|
|
449 |
@Override
|
|
450 |
protected JavaConstant zapValueForKind(PlatformKind kind) {
|
|
451 |
long dead = 0xDEADDEADDEADDEADL;
|
|
452 |
switch ((AArch64Kind) kind) {
|
|
453 |
case BYTE:
|
|
454 |
return JavaConstant.forByte((byte) dead);
|
|
455 |
case WORD:
|
|
456 |
return JavaConstant.forShort((short) dead);
|
|
457 |
case DWORD:
|
|
458 |
return JavaConstant.forInt((int) dead);
|
|
459 |
case QWORD:
|
|
460 |
return JavaConstant.forLong(dead);
|
|
461 |
case SINGLE:
|
|
462 |
return JavaConstant.forFloat(Float.intBitsToFloat((int) dead));
|
|
463 |
case DOUBLE:
|
|
464 |
return JavaConstant.forDouble(Double.longBitsToDouble(dead));
|
|
465 |
default:
|
|
466 |
throw GraalError.shouldNotReachHere();
|
|
467 |
}
|
|
468 |
}
|
|
469 |
|
|
470 |
/**
|
|
471 |
* Loads value into virtual register. Contrary to {@link #load(Value)} this handles
|
|
472 |
* RegisterValues (i.e. values corresponding to fixed physical registers) correctly, by not
|
|
473 |
* creating an unnecessary move into a virtual register.
|
|
474 |
*
|
|
475 |
* This avoids generating the following code: mov x0, x19 # x19 is fixed thread register ldr x0,
|
|
476 |
* [x0] instead of: ldr x0, [x19].
|
|
477 |
*/
|
|
478 |
protected AllocatableValue loadReg(Value val) {
|
|
479 |
if (!(val instanceof Variable || val instanceof RegisterValue)) {
|
|
480 |
return emitMove(val);
|
|
481 |
}
|
|
482 |
return (AllocatableValue) val;
|
|
483 |
}
|
|
484 |
|
|
485 |
@Override
|
|
486 |
public void emitPause() {
|
|
487 |
append(new AArch64PauseOp());
|
|
488 |
}
|
46344
|
489 |
|
|
490 |
public abstract void emitCCall(long address, CallingConvention nativeCallingConvention, Value[] args);
|
43972
|
491 |
}
|