ArithmeticLIRGeneratorTool.java revision 12657:6ef01bd40ce2
1/*
2 * Copyright (c) 2013, 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 */
23package org.graalvm.compiler.lir.gen;
24
25import org.graalvm.compiler.core.common.LIRKind;
26import org.graalvm.compiler.core.common.calc.FloatConvert;
27import org.graalvm.compiler.debug.GraalError;
28import org.graalvm.compiler.lir.LIRFrameState;
29import org.graalvm.compiler.lir.Variable;
30
31import jdk.vm.ci.meta.Value;
32import jdk.vm.ci.meta.ValueKind;
33
34/**
35 * This interface can be used to generate LIR for arithmetic and simple memory access operations.
36 *
37 * The setFlags flag in emitAdd, emitSub and emitMul indicates, that the instruction must set the
38 * flags register to be used for a later branch. (On AMD64, the condition codes are set in every
39 * arithmetic instruction, but other architectures optionally set the flags register) If setFlags is
40 * set, the instruction must set the flags register; if false, the instruction may or may not set
41 * the flags register.
42 */
43public interface ArithmeticLIRGeneratorTool {
44
45    Value emitNegate(Value input);
46
47    Value emitAdd(Value a, Value b, boolean setFlags);
48
49    Value emitSub(Value a, Value b, boolean setFlags);
50
51    Value emitMul(Value a, Value b, boolean setFlags);
52
53    Value emitMulHigh(Value a, Value b);
54
55    Value emitUMulHigh(Value a, Value b);
56
57    Value emitDiv(Value a, Value b, LIRFrameState state);
58
59    Value emitRem(Value a, Value b, LIRFrameState state);
60
61    Value emitUDiv(Value a, Value b, LIRFrameState state);
62
63    Value emitURem(Value a, Value b, LIRFrameState state);
64
65    Value emitNot(Value input);
66
67    Value emitAnd(Value a, Value b);
68
69    Value emitOr(Value a, Value b);
70
71    Value emitXor(Value a, Value b);
72
73    Value emitShl(Value a, Value b);
74
75    Value emitShr(Value a, Value b);
76
77    Value emitUShr(Value a, Value b);
78
79    Value emitFloatConvert(FloatConvert op, Value inputVal);
80
81    Value emitReinterpret(LIRKind to, Value inputVal);
82
83    Value emitNarrow(Value inputVal, int bits);
84
85    Value emitSignExtend(Value inputVal, int fromBits, int toBits);
86
87    Value emitZeroExtend(Value inputVal, int fromBits, int toBits);
88
89    Value emitMathAbs(Value input);
90
91    Value emitMathSqrt(Value input);
92
93    Value emitBitCount(Value operand);
94
95    Value emitBitScanForward(Value operand);
96
97    Value emitBitScanReverse(Value operand);
98
99    Variable emitLoad(LIRKind kind, Value address, LIRFrameState state);
100
101    void emitStore(ValueKind<?> kind, Value address, Value input, LIRFrameState state);
102
103    @SuppressWarnings("unused")
104    default Value emitMathLog(Value input, boolean base10) {
105        throw GraalError.unimplemented("No specialized implementation available");
106    }
107
108    @SuppressWarnings("unused")
109    default Value emitMathCos(Value input) {
110        throw GraalError.unimplemented("No specialized implementation available");
111    }
112
113    @SuppressWarnings("unused")
114    default Value emitMathSin(Value input) {
115        throw GraalError.unimplemented("No specialized implementation available");
116    }
117
118    @SuppressWarnings("unused")
119    default Value emitMathTan(Value input) {
120        throw GraalError.unimplemented("No specialized implementation available");
121    }
122
123    @SuppressWarnings("unused")
124    default Value emitMathExp(Value input) {
125        throw GraalError.unimplemented("No specialized implementation available");
126    }
127
128    @SuppressWarnings("unused")
129    default Value emitMathPow(Value x, Value y) {
130        throw GraalError.unimplemented("No specialized implementation available");
131    }
132
133}
134