43972
|
1 |
/*
|
54601
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
|
50858
|
24 |
|
|
25 |
|
43972
|
26 |
package org.graalvm.compiler.core.aarch64;
|
|
27 |
|
54601
|
28 |
import jdk.vm.ci.aarch64.AArch64Kind;
|
55509
|
29 |
import jdk.vm.ci.code.CodeUtil;
|
52910
|
30 |
import jdk.vm.ci.meta.AllocatableValue;
|
|
31 |
import jdk.vm.ci.meta.JavaKind;
|
|
32 |
import jdk.vm.ci.meta.Value;
|
|
33 |
import jdk.internal.vm.compiler.collections.EconomicMap;
|
|
34 |
import jdk.internal.vm.compiler.collections.Equivalence;
|
52578
|
35 |
import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
|
52910
|
36 |
import org.graalvm.compiler.core.common.LIRKind;
|
54601
|
37 |
import org.graalvm.compiler.core.common.calc.CanonicalCondition;
|
43972
|
38 |
import org.graalvm.compiler.core.gen.NodeMatchRules;
|
52578
|
39 |
import org.graalvm.compiler.core.match.ComplexMatchResult;
|
|
40 |
import org.graalvm.compiler.core.match.MatchRule;
|
43972
|
41 |
import org.graalvm.compiler.lir.LIRFrameState;
|
54084
|
42 |
import org.graalvm.compiler.lir.LabelRef;
|
52910
|
43 |
import org.graalvm.compiler.lir.Variable;
|
52578
|
44 |
import org.graalvm.compiler.lir.aarch64.AArch64ArithmeticOp;
|
55509
|
45 |
import org.graalvm.compiler.lir.aarch64.AArch64BitFieldOp;
|
54084
|
46 |
import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow;
|
43972
|
47 |
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
|
52578
|
48 |
import org.graalvm.compiler.nodes.ConstantNode;
|
43972
|
49 |
import org.graalvm.compiler.nodes.DeoptimizingNode;
|
54601
|
50 |
import org.graalvm.compiler.nodes.FixedNode;
|
54084
|
51 |
import org.graalvm.compiler.nodes.IfNode;
|
48190
|
52 |
import org.graalvm.compiler.nodes.NodeView;
|
52578
|
53 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
54 |
import org.graalvm.compiler.nodes.calc.AddNode;
|
52910
|
55 |
import org.graalvm.compiler.nodes.calc.AndNode;
|
52578
|
56 |
import org.graalvm.compiler.nodes.calc.BinaryNode;
|
54601
|
57 |
import org.graalvm.compiler.nodes.calc.IntegerLessThanNode;
|
52578
|
58 |
import org.graalvm.compiler.nodes.calc.LeftShiftNode;
|
58877
|
59 |
import org.graalvm.compiler.nodes.calc.MulNode;
|
59095
|
60 |
import org.graalvm.compiler.nodes.calc.NarrowNode;
|
|
61 |
import org.graalvm.compiler.nodes.calc.NegateNode;
|
52910
|
62 |
import org.graalvm.compiler.nodes.calc.NotNode;
|
|
63 |
import org.graalvm.compiler.nodes.calc.OrNode;
|
52578
|
64 |
import org.graalvm.compiler.nodes.calc.RightShiftNode;
|
52910
|
65 |
import org.graalvm.compiler.nodes.calc.SubNode;
|
59095
|
66 |
import org.graalvm.compiler.nodes.calc.UnaryNode;
|
52578
|
67 |
import org.graalvm.compiler.nodes.calc.UnsignedRightShiftNode;
|
52910
|
68 |
import org.graalvm.compiler.nodes.calc.XorNode;
|
43972
|
69 |
import org.graalvm.compiler.nodes.memory.Access;
|
|
70 |
|
|
71 |
public class AArch64NodeMatchRules extends NodeMatchRules {
|
59095
|
72 |
private static final EconomicMap<Class<? extends BinaryNode>, AArch64ArithmeticOp> binaryOpMap;
|
55509
|
73 |
private static final EconomicMap<Class<? extends BinaryNode>, AArch64BitFieldOp.BitFieldOpCode> bitFieldOpMap;
|
52910
|
74 |
private static final EconomicMap<Class<? extends BinaryNode>, AArch64MacroAssembler.ShiftType> shiftTypeMap;
|
|
75 |
|
|
76 |
static {
|
59095
|
77 |
binaryOpMap = EconomicMap.create(Equivalence.IDENTITY, 9);
|
|
78 |
binaryOpMap.put(AddNode.class, AArch64ArithmeticOp.ADD);
|
|
79 |
binaryOpMap.put(SubNode.class, AArch64ArithmeticOp.SUB);
|
|
80 |
binaryOpMap.put(MulNode.class, AArch64ArithmeticOp.MUL);
|
|
81 |
binaryOpMap.put(AndNode.class, AArch64ArithmeticOp.AND);
|
|
82 |
binaryOpMap.put(OrNode.class, AArch64ArithmeticOp.OR);
|
|
83 |
binaryOpMap.put(XorNode.class, AArch64ArithmeticOp.XOR);
|
|
84 |
binaryOpMap.put(LeftShiftNode.class, AArch64ArithmeticOp.SHL);
|
|
85 |
binaryOpMap.put(RightShiftNode.class, AArch64ArithmeticOp.ASHR);
|
|
86 |
binaryOpMap.put(UnsignedRightShiftNode.class, AArch64ArithmeticOp.LSHR);
|
52910
|
87 |
|
55509
|
88 |
bitFieldOpMap = EconomicMap.create(Equivalence.IDENTITY, 2);
|
|
89 |
bitFieldOpMap.put(UnsignedRightShiftNode.class, AArch64BitFieldOp.BitFieldOpCode.UBFX);
|
|
90 |
bitFieldOpMap.put(LeftShiftNode.class, AArch64BitFieldOp.BitFieldOpCode.UBFIZ);
|
|
91 |
|
52910
|
92 |
shiftTypeMap = EconomicMap.create(Equivalence.IDENTITY, 3);
|
|
93 |
shiftTypeMap.put(LeftShiftNode.class, AArch64MacroAssembler.ShiftType.LSL);
|
|
94 |
shiftTypeMap.put(RightShiftNode.class, AArch64MacroAssembler.ShiftType.ASR);
|
|
95 |
shiftTypeMap.put(UnsignedRightShiftNode.class, AArch64MacroAssembler.ShiftType.LSR);
|
|
96 |
}
|
43972
|
97 |
|
|
98 |
public AArch64NodeMatchRules(LIRGeneratorTool gen) {
|
|
99 |
super(gen);
|
|
100 |
}
|
|
101 |
|
|
102 |
protected LIRFrameState getState(Access access) {
|
|
103 |
if (access instanceof DeoptimizingNode) {
|
|
104 |
return state((DeoptimizingNode) access);
|
|
105 |
}
|
|
106 |
return null;
|
|
107 |
}
|
|
108 |
|
|
109 |
protected AArch64Kind getMemoryKind(Access access) {
|
48190
|
110 |
return (AArch64Kind) gen.getLIRKind(access.asNode().stamp(NodeView.DEFAULT)).getPlatformKind();
|
43972
|
111 |
}
|
|
112 |
|
52910
|
113 |
private AllocatableValue moveSp(AllocatableValue value) {
|
|
114 |
return getLIRGeneratorTool().moveSp(value);
|
|
115 |
}
|
|
116 |
|
55509
|
117 |
private ComplexMatchResult emitBitField(AArch64BitFieldOp.BitFieldOpCode op, ValueNode value, int lsb, int width) {
|
|
118 |
assert op != null;
|
|
119 |
assert value.getStackKind().isNumericInteger();
|
|
120 |
|
|
121 |
return builder -> {
|
|
122 |
Value a = operand(value);
|
|
123 |
Variable result = gen.newVariable(LIRKind.combine(a));
|
|
124 |
AllocatableValue src = moveSp(gen.asAllocatable(a));
|
|
125 |
gen.append(new AArch64BitFieldOp(op, result, src, lsb, width));
|
|
126 |
return result;
|
|
127 |
};
|
|
128 |
}
|
|
129 |
|
54601
|
130 |
private ComplexMatchResult emitBinaryShift(AArch64ArithmeticOp op, ValueNode value, BinaryNode shift,
|
|
131 |
boolean isShiftNot) {
|
52910
|
132 |
AArch64MacroAssembler.ShiftType shiftType = shiftTypeMap.get(shift.getClass());
|
|
133 |
assert shiftType != null;
|
|
134 |
assert value.getStackKind().isNumericInteger();
|
|
135 |
assert shift.getX().getStackKind().isNumericInteger();
|
52578
|
136 |
assert shift.getY() instanceof ConstantNode;
|
|
137 |
|
52910
|
138 |
return builder -> {
|
|
139 |
Value a = operand(value);
|
|
140 |
Value b = operand(shift.getX());
|
|
141 |
Variable result = gen.newVariable(LIRKind.combine(a, b));
|
|
142 |
AllocatableValue x = moveSp(gen.asAllocatable(a));
|
|
143 |
AllocatableValue y = moveSp(gen.asAllocatable(b));
|
|
144 |
int shiftAmount = shift.getY().asJavaConstant().asInt();
|
|
145 |
gen.append(new AArch64ArithmeticOp.BinaryShiftOp(op, result, x, y, shiftType, shiftAmount, isShiftNot));
|
|
146 |
return result;
|
|
147 |
};
|
52578
|
148 |
}
|
|
149 |
|
54601
|
150 |
private ComplexMatchResult emitBitTestAndBranch(FixedNode trueSuccessor, FixedNode falseSuccessor,
|
|
151 |
ValueNode value, double trueProbability, int nbits) {
|
|
152 |
return builder -> {
|
|
153 |
LabelRef trueDestination = getLIRBlock(trueSuccessor);
|
|
154 |
LabelRef falseDestination = getLIRBlock(falseSuccessor);
|
|
155 |
AllocatableValue src = moveSp(gen.asAllocatable(operand(value)));
|
|
156 |
gen.append(new AArch64ControlFlow.BitTestAndBranchOp(trueDestination, falseDestination, src,
|
|
157 |
trueProbability, nbits));
|
|
158 |
return null;
|
|
159 |
};
|
|
160 |
}
|
|
161 |
|
59095
|
162 |
private static boolean isNarrowingLongToInt(NarrowNode narrow) {
|
|
163 |
return narrow.getInputBits() == 64 && narrow.getResultBits() == 32;
|
|
164 |
}
|
|
165 |
|
55509
|
166 |
@MatchRule("(And (UnsignedRightShift=shift a Constant=b) Constant=c)")
|
|
167 |
@MatchRule("(LeftShift=shift (And a Constant=c) Constant=b)")
|
|
168 |
public ComplexMatchResult unsignedBitField(BinaryNode shift, ValueNode a, ConstantNode b, ConstantNode c) {
|
|
169 |
JavaKind srcKind = a.getStackKind();
|
|
170 |
assert srcKind.isNumericInteger();
|
|
171 |
AArch64BitFieldOp.BitFieldOpCode op = bitFieldOpMap.get(shift.getClass());
|
|
172 |
assert op != null;
|
|
173 |
int distance = b.asJavaConstant().asInt();
|
|
174 |
long mask = c.asJavaConstant().asLong();
|
|
175 |
|
|
176 |
// The Java(R) Language Specification CHAPTER 15.19 Shift Operators says:
|
|
177 |
// "If the promoted type of the left-hand operand is int(long), then only the five(six)
|
|
178 |
// lowest-order bits of the right-hand operand are used as the shift distance."
|
|
179 |
distance = distance & (srcKind == JavaKind.Int ? 0x1f : 0x3f);
|
|
180 |
|
|
181 |
// Constraint 1: Mask plus one should be a power-of-2 integer.
|
|
182 |
if (!CodeUtil.isPowerOf2(mask + 1)) {
|
|
183 |
return null;
|
|
184 |
}
|
|
185 |
int width = CodeUtil.log2(mask + 1);
|
|
186 |
int srcBits = srcKind.getBitCount();
|
|
187 |
// Constraint 2: Bit field width is less than 31(63) for int(long) as any bit field move
|
|
188 |
// operations can be done by a single shift instruction if the width is 31(63).
|
|
189 |
if (width >= srcBits - 1) {
|
|
190 |
return null;
|
|
191 |
}
|
|
192 |
// Constraint 3: Sum of bit field width and the shift distance is less or equal to 32(64)
|
|
193 |
// for int(long) as the specification of AArch64 bit field instructions.
|
|
194 |
if (width + distance > srcBits) {
|
|
195 |
return null;
|
|
196 |
}
|
|
197 |
return emitBitField(op, a, distance, width);
|
|
198 |
}
|
|
199 |
|
52578
|
200 |
@MatchRule("(Add=binary a (LeftShift=shift b Constant))")
|
|
201 |
@MatchRule("(Add=binary a (RightShift=shift b Constant))")
|
|
202 |
@MatchRule("(Add=binary a (UnsignedRightShift=shift b Constant))")
|
|
203 |
@MatchRule("(Sub=binary a (LeftShift=shift b Constant))")
|
|
204 |
@MatchRule("(Sub=binary a (RightShift=shift b Constant))")
|
|
205 |
@MatchRule("(Sub=binary a (UnsignedRightShift=shift b Constant))")
|
|
206 |
public ComplexMatchResult addSubShift(BinaryNode binary, ValueNode a, BinaryNode shift) {
|
59095
|
207 |
AArch64ArithmeticOp op = binaryOpMap.get(binary.getClass());
|
52910
|
208 |
assert op != null;
|
|
209 |
return emitBinaryShift(op, a, shift, false);
|
|
210 |
}
|
|
211 |
|
|
212 |
@MatchRule("(And=binary a (LeftShift=shift b Constant))")
|
|
213 |
@MatchRule("(And=binary a (RightShift=shift b Constant))")
|
|
214 |
@MatchRule("(And=binary a (UnsignedRightShift=shift b Constant))")
|
|
215 |
@MatchRule("(Or=binary a (LeftShift=shift b Constant))")
|
|
216 |
@MatchRule("(Or=binary a (RightShift=shift b Constant))")
|
|
217 |
@MatchRule("(Or=binary a (UnsignedRightShift=shift b Constant))")
|
|
218 |
@MatchRule("(Xor=binary a (LeftShift=shift b Constant))")
|
|
219 |
@MatchRule("(Xor=binary a (RightShift=shift b Constant))")
|
|
220 |
@MatchRule("(Xor=binary a (UnsignedRightShift=shift b Constant))")
|
|
221 |
@MatchRule("(And=binary a (Not (LeftShift=shift b Constant)))")
|
|
222 |
@MatchRule("(And=binary a (Not (RightShift=shift b Constant)))")
|
|
223 |
@MatchRule("(And=binary a (Not (UnsignedRightShift=shift b Constant)))")
|
|
224 |
@MatchRule("(Or=binary a (Not (LeftShift=shift b Constant)))")
|
|
225 |
@MatchRule("(Or=binary a (Not (RightShift=shift b Constant)))")
|
|
226 |
@MatchRule("(Or=binary a (Not (UnsignedRightShift=shift b Constant)))")
|
|
227 |
@MatchRule("(Xor=binary a (Not (LeftShift=shift b Constant)))")
|
|
228 |
@MatchRule("(Xor=binary a (Not (RightShift=shift b Constant)))")
|
|
229 |
@MatchRule("(Xor=binary a (Not (UnsignedRightShift=shift b Constant)))")
|
|
230 |
public ComplexMatchResult logicShift(BinaryNode binary, ValueNode a, BinaryNode shift) {
|
59095
|
231 |
AArch64ArithmeticOp op = binaryOpMap.get(binary.getClass());
|
52910
|
232 |
assert op != null;
|
|
233 |
ValueNode operand = binary.getX() == a ? binary.getY() : binary.getX();
|
|
234 |
boolean isShiftNot = operand instanceof NotNode;
|
|
235 |
return emitBinaryShift(op, a, shift, isShiftNot);
|
|
236 |
}
|
|
237 |
|
58877
|
238 |
@MatchRule("(Add=binary (Mul (SignExtend a) (SignExtend b)) c)")
|
|
239 |
@MatchRule("(Sub=binary c (Mul (SignExtend a) (SignExtend b)))")
|
|
240 |
public ComplexMatchResult signedMultiplyAddSubLong(BinaryNode binary, ValueNode a, ValueNode b, ValueNode c) {
|
|
241 |
assert a.getStackKind() == JavaKind.Int && b.getStackKind() == JavaKind.Int && c.getStackKind() == JavaKind.Long;
|
|
242 |
if (binary instanceof AddNode) {
|
|
243 |
return builder -> getArithmeticLIRGenerator().emitIntegerMAdd(operand(a), operand(b), operand(c), true);
|
|
244 |
}
|
|
245 |
return builder -> getArithmeticLIRGenerator().emitIntegerMSub(operand(a), operand(b), operand(c), true);
|
|
246 |
}
|
|
247 |
|
|
248 |
@MatchRule("(Negate (Mul=mul (SignExtend a) (SignExtend b)))")
|
|
249 |
@MatchRule("(Mul=mul (Negate (SignExtend a)) (SignExtend b))")
|
|
250 |
public ComplexMatchResult signedMultiplyNegLong(MulNode mul, ValueNode a, ValueNode b) {
|
|
251 |
assert a.getStackKind() == JavaKind.Int && b.getStackKind() == JavaKind.Int;
|
|
252 |
LIRKind resultKind = LIRKind.fromJavaKind(gen.target().arch, mul.getStackKind());
|
|
253 |
return builder -> getArithmeticLIRGenerator().emitBinary(
|
|
254 |
resultKind, AArch64ArithmeticOp.SMNEGL, true, operand(a), operand(b));
|
|
255 |
}
|
|
256 |
|
|
257 |
@MatchRule("(Mul=mul (SignExtend a) (SignExtend b))")
|
|
258 |
public ComplexMatchResult signedMultiplyLong(MulNode mul, ValueNode a, ValueNode b) {
|
|
259 |
assert a.getStackKind() == JavaKind.Int && b.getStackKind() == JavaKind.Int;
|
|
260 |
LIRKind resultKind = LIRKind.fromJavaKind(gen.target().arch, mul.getStackKind());
|
|
261 |
return builder -> getArithmeticLIRGenerator().emitBinary(
|
|
262 |
resultKind, AArch64ArithmeticOp.SMULL, true, operand(a), operand(b));
|
|
263 |
}
|
|
264 |
|
59095
|
265 |
@MatchRule("(Add=binary (Narrow=narrow a) (Narrow b))")
|
|
266 |
@MatchRule("(Sub=binary (Narrow=narrow a) (Narrow b))")
|
|
267 |
@MatchRule("(Mul=binary (Narrow=narrow a) (Narrow b))")
|
|
268 |
@MatchRule("(And=binary (Narrow=narrow a) (Narrow b))")
|
|
269 |
@MatchRule("(Or=binary (Narrow=narrow a) (Narrow b))")
|
|
270 |
@MatchRule("(Xor=binary (Narrow=narrow a) (Narrow b))")
|
|
271 |
@MatchRule("(LeftShift=binary (Narrow=narrow a) (Narrow b))")
|
|
272 |
@MatchRule("(RightShift=binary (Narrow=narrow a) (Narrow b))")
|
|
273 |
@MatchRule("(UnsignedRightShift=binary (Narrow=narrow a) (Narrow b))")
|
|
274 |
@MatchRule("(Add=binary a (Narrow=narrow b))")
|
|
275 |
@MatchRule("(Sub=binary a (Narrow=narrow b))")
|
|
276 |
@MatchRule("(Mul=binary a (Narrow=narrow b))")
|
|
277 |
@MatchRule("(And=binary a (Narrow=narrow b))")
|
|
278 |
@MatchRule("(Or=binary a (Narrow=narrow b))")
|
|
279 |
@MatchRule("(Xor=binary a (Narrow=narrow b))")
|
|
280 |
@MatchRule("(LeftShift=binary a (Narrow=narrow b))")
|
|
281 |
@MatchRule("(RightShift=binary a (Narrow=narrow b))")
|
|
282 |
@MatchRule("(UnsignedRightShift=binary a (Narrow=narrow b))")
|
|
283 |
@MatchRule("(Sub=binary (Narrow=narrow a) b)")
|
|
284 |
@MatchRule("(LeftShift=binary (Narrow=narrow a) b)")
|
|
285 |
@MatchRule("(RightShift=binary (Narrow=narrow a) b)")
|
|
286 |
@MatchRule("(UnsignedRightShift=binary (Narrow=narrow a) b)")
|
|
287 |
public ComplexMatchResult elideL2IForBinary(BinaryNode binary, NarrowNode narrow) {
|
|
288 |
assert binary.getStackKind().isNumericInteger();
|
|
289 |
|
|
290 |
ValueNode a = narrow;
|
|
291 |
ValueNode b = binary.getX() == narrow ? binary.getY() : binary.getX();
|
|
292 |
boolean isL2Ia = isNarrowingLongToInt((NarrowNode) a);
|
|
293 |
boolean isL2Ib = (b instanceof NarrowNode) && isNarrowingLongToInt((NarrowNode) b);
|
|
294 |
if (!isL2Ia && !isL2Ib) {
|
|
295 |
return null;
|
|
296 |
}
|
|
297 |
// Get the value of L2I NarrowNode as the src value.
|
|
298 |
ValueNode src1 = isL2Ia ? ((NarrowNode) a).getValue() : a;
|
|
299 |
ValueNode src2 = isL2Ib ? ((NarrowNode) b).getValue() : b;
|
|
300 |
|
|
301 |
AArch64ArithmeticOp op = binaryOpMap.get(binary.getClass());
|
|
302 |
assert op != null;
|
|
303 |
boolean commutative = binary.getNodeClass().isCommutative();
|
|
304 |
LIRKind resultKind = LIRKind.fromJavaKind(gen.target().arch, binary.getStackKind());
|
|
305 |
|
|
306 |
// Must keep the right operator order for un-commutative binary operations.
|
|
307 |
if (a == binary.getX()) {
|
|
308 |
return builder -> getArithmeticLIRGenerator().emitBinary(
|
|
309 |
resultKind, op, commutative, operand(src1), operand(src2));
|
|
310 |
}
|
|
311 |
return builder -> getArithmeticLIRGenerator().emitBinary(
|
|
312 |
resultKind, op, commutative, operand(src2), operand(src1));
|
|
313 |
}
|
|
314 |
|
|
315 |
@MatchRule("(Negate=unary (Narrow=narrow value))")
|
|
316 |
@MatchRule("(Not=unary (Narrow=narrow value))")
|
|
317 |
public ComplexMatchResult elideL2IForUnary(UnaryNode unary, NarrowNode narrow) {
|
|
318 |
assert unary.getStackKind().isNumericInteger();
|
|
319 |
if (!isNarrowingLongToInt(narrow)) {
|
|
320 |
return null;
|
|
321 |
}
|
|
322 |
|
|
323 |
AArch64ArithmeticOp op = unary instanceof NegateNode ? AArch64ArithmeticOp.NEG
|
|
324 |
: AArch64ArithmeticOp.NOT;
|
|
325 |
return builder -> {
|
|
326 |
AllocatableValue input = gen.asAllocatable(operand(narrow.getValue()));
|
|
327 |
LIRKind resultKind = LIRKind.fromJavaKind(gen.target().arch, unary.getStackKind());
|
|
328 |
Variable result = gen.newVariable(resultKind);
|
|
329 |
gen.append(new AArch64ArithmeticOp.UnaryOp(op, result, moveSp(input)));
|
|
330 |
return result;
|
|
331 |
};
|
|
332 |
}
|
|
333 |
|
52910
|
334 |
@MatchRule("(Mul (Negate a) b)")
|
|
335 |
@MatchRule("(Negate (Mul a b))")
|
|
336 |
public ComplexMatchResult multiplyNegate(ValueNode a, ValueNode b) {
|
|
337 |
if (a.getStackKind().isNumericInteger() && b.getStackKind().isNumericInteger()) {
|
|
338 |
return builder -> getArithmeticLIRGenerator().emitMNeg(operand(a), operand(b));
|
|
339 |
}
|
|
340 |
return null;
|
|
341 |
}
|
|
342 |
|
|
343 |
@MatchRule("(Add=binary (Mul a b) c)")
|
|
344 |
@MatchRule("(Sub=binary c (Mul a b))")
|
|
345 |
public ComplexMatchResult multiplyAddSub(BinaryNode binary, ValueNode a, ValueNode b, ValueNode c) {
|
|
346 |
JavaKind kindA = a.getStackKind();
|
|
347 |
JavaKind kindB = b.getStackKind();
|
|
348 |
JavaKind kindC = c.getStackKind();
|
|
349 |
if (!kindA.isNumericInteger() || !kindB.isNumericInteger() || !kindC.isNumericInteger()) {
|
|
350 |
return null;
|
|
351 |
}
|
|
352 |
|
52578
|
353 |
if (binary instanceof AddNode) {
|
58877
|
354 |
return builder -> getArithmeticLIRGenerator().emitIntegerMAdd(operand(a), operand(b), operand(c), false);
|
52578
|
355 |
}
|
58877
|
356 |
return builder -> getArithmeticLIRGenerator().emitIntegerMSub(operand(a), operand(b), operand(c), false);
|
52578
|
357 |
}
|
|
358 |
|
54084
|
359 |
/**
|
|
360 |
* ((x & (1 << n)) == 0) -> tbz/tbnz n label.
|
|
361 |
*/
|
|
362 |
@MatchRule("(If (IntegerTest value Constant=a))")
|
|
363 |
public ComplexMatchResult testBitAndBranch(IfNode root, ValueNode value, ConstantNode a) {
|
|
364 |
if (value.getStackKind().isNumericInteger()) {
|
|
365 |
long constant = a.asJavaConstant().asLong();
|
|
366 |
if (Long.bitCount(constant) == 1) {
|
54601
|
367 |
return emitBitTestAndBranch(root.trueSuccessor(), root.falseSuccessor(), value,
|
|
368 |
root.getTrueSuccessorProbability(), Long.numberOfTrailingZeros(constant));
|
54084
|
369 |
}
|
|
370 |
}
|
|
371 |
return null;
|
|
372 |
}
|
|
373 |
|
54601
|
374 |
/**
|
|
375 |
* if x < 0 <=> tbz x, sizeOfBits(x) - 1, label.
|
|
376 |
*/
|
|
377 |
@MatchRule("(If (IntegerLessThan=lessNode x Constant=y))")
|
|
378 |
public ComplexMatchResult checkNegativeAndBranch(IfNode root, IntegerLessThanNode lessNode, ValueNode x, ConstantNode y) {
|
|
379 |
JavaKind xKind = x.getStackKind();
|
|
380 |
assert xKind.isNumericInteger();
|
|
381 |
if (y.isJavaConstant() && (0 == y.asJavaConstant().asLong()) && lessNode.condition().equals(CanonicalCondition.LT)) {
|
|
382 |
return emitBitTestAndBranch(root.falseSuccessor(), root.trueSuccessor(), x,
|
|
383 |
1.0 - root.getTrueSuccessorProbability(), xKind.getBitCount() - 1);
|
|
384 |
}
|
|
385 |
return null;
|
|
386 |
}
|
|
387 |
|
43972
|
388 |
@Override
|
|
389 |
public AArch64LIRGenerator getLIRGeneratorTool() {
|
|
390 |
return (AArch64LIRGenerator) gen;
|
|
391 |
}
|
|
392 |
|
|
393 |
protected AArch64ArithmeticLIRGenerator getArithmeticLIRGenerator() {
|
|
394 |
return (AArch64ArithmeticLIRGenerator) getLIRGeneratorTool().getArithmetic();
|
|
395 |
}
|
|
396 |
}
|