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