instruction-codes.h 13.6 KB
Newer Older
1 2 3 4
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_COMPILER_BACKEND_INSTRUCTION_CODES_H_
#define V8_COMPILER_BACKEND_INSTRUCTION_CODES_H_
7

8 9
#include <iosfwd>

10
#if V8_TARGET_ARCH_ARM
11
#include "src/compiler/backend/arm/instruction-codes-arm.h"
12
#elif V8_TARGET_ARCH_ARM64
13
#include "src/compiler/backend/arm64/instruction-codes-arm64.h"
14
#elif V8_TARGET_ARCH_IA32
15
#include "src/compiler/backend/ia32/instruction-codes-ia32.h"
16
#elif V8_TARGET_ARCH_MIPS
17
#include "src/compiler/backend/mips/instruction-codes-mips.h"
18
#elif V8_TARGET_ARCH_MIPS64
19
#include "src/compiler/backend/mips64/instruction-codes-mips64.h"
20
#elif V8_TARGET_ARCH_X64
21
#include "src/compiler/backend/x64/instruction-codes-x64.h"
22
#elif V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64
23
#include "src/compiler/backend/ppc/instruction-codes-ppc.h"
24
#elif V8_TARGET_ARCH_S390
25
#include "src/compiler/backend/s390/instruction-codes-s390.h"
26
#else
27 28
#define TARGET_ARCH_OPCODE_LIST(V)
#define TARGET_ADDRESSING_MODE_LIST(V)
29
#endif
30
#include "src/base/bit-field.h"
31
#include "src/compiler/write-barrier-kind.h"
32 33 34 35 36

namespace v8 {
namespace internal {
namespace compiler {

37
// Modes for ArchStoreWithWriteBarrier below.
38 39 40 41 42 43
enum class RecordWriteMode {
  kValueIsMap,
  kValueIsPointer,
  kValueIsEphemeronKey,
  kValueIsAny,
};
44

45 46 47 48 49 50 51
inline RecordWriteMode WriteBarrierKindToRecordWriteMode(
    WriteBarrierKind write_barrier_kind) {
  switch (write_barrier_kind) {
    case kMapWriteBarrier:
      return RecordWriteMode::kValueIsMap;
    case kPointerWriteBarrier:
      return RecordWriteMode::kValueIsPointer;
52 53
    case kEphemeronKeyWriteBarrier:
      return RecordWriteMode::kValueIsEphemeronKey;
54 55 56 57 58 59 60 61 62 63
    case kFullWriteBarrier:
      return RecordWriteMode::kValueIsAny;
    case kNoWriteBarrier:
    // Should not be passed as argument.
    default:
      break;
  }
  UNREACHABLE();
}

64 65
// Target-specific opcodes that specify which assembly sequence to emit.
// Most opcodes specify a single instruction.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
#define COMMON_ARCH_OPCODE_LIST(V)                                         \
  /* Tail call opcodes are grouped together to make IsTailCall fast */     \
  /* and Arch call opcodes are grouped together to make */                 \
  /* IsCallWithDescriptorFlags fast */                                     \
  V(ArchTailCallCodeObject)                                                \
  V(ArchTailCallAddress)                                                   \
  V(ArchTailCallWasm)                                                      \
  /* Update IsTailCall if further TailCall opcodes are added */            \
                                                                           \
  V(ArchCallCodeObject)                                                    \
  V(ArchCallJSFunction)                                                    \
  V(ArchCallWasmFunction)                                                  \
  V(ArchCallBuiltinPointer)                                                \
  /* Update IsCallWithDescriptorFlags if further Call opcodes are added */ \
                                                                           \
  V(ArchPrepareCallCFunction)                                              \
  V(ArchSaveCallerRegisters)                                               \
  V(ArchRestoreCallerRegisters)                                            \
  V(ArchCallCFunction)                                                     \
  V(ArchPrepareTailCall)                                                   \
  V(ArchJmp)                                                               \
  V(ArchBinarySearchSwitch)                                                \
  V(ArchTableSwitch)                                                       \
  V(ArchNop)                                                               \
  V(ArchAbortCSAAssert)                                                    \
  V(ArchDebugBreak)                                                        \
  V(ArchComment)                                                           \
  V(ArchThrowTerminator)                                                   \
  V(ArchDeoptimize)                                                        \
  V(ArchRet)                                                               \
  V(ArchFramePointer)                                                      \
  V(ArchParentFramePointer)                                                \
  V(ArchTruncateDoubleToI)                                                 \
  V(ArchStoreWithWriteBarrier)                                             \
  V(ArchStackSlot)                                                         \
  V(ArchWordPoisonOnSpeculation)                                           \
  V(ArchStackPointerGreaterThan)                                           \
  V(ArchStackCheckOffset)                                                  \
  V(Word32AtomicLoadInt8)                                                  \
  V(Word32AtomicLoadUint8)                                                 \
  V(Word32AtomicLoadInt16)                                                 \
  V(Word32AtomicLoadUint16)                                                \
  V(Word32AtomicLoadWord32)                                                \
  V(Word32AtomicStoreWord8)                                                \
  V(Word32AtomicStoreWord16)                                               \
  V(Word32AtomicStoreWord32)                                               \
  V(Word32AtomicExchangeInt8)                                              \
  V(Word32AtomicExchangeUint8)                                             \
  V(Word32AtomicExchangeInt16)                                             \
  V(Word32AtomicExchangeUint16)                                            \
  V(Word32AtomicExchangeWord32)                                            \
  V(Word32AtomicCompareExchangeInt8)                                       \
  V(Word32AtomicCompareExchangeUint8)                                      \
  V(Word32AtomicCompareExchangeInt16)                                      \
  V(Word32AtomicCompareExchangeUint16)                                     \
  V(Word32AtomicCompareExchangeWord32)                                     \
  V(Word32AtomicAddInt8)                                                   \
  V(Word32AtomicAddUint8)                                                  \
  V(Word32AtomicAddInt16)                                                  \
  V(Word32AtomicAddUint16)                                                 \
  V(Word32AtomicAddWord32)                                                 \
  V(Word32AtomicSubInt8)                                                   \
  V(Word32AtomicSubUint8)                                                  \
  V(Word32AtomicSubInt16)                                                  \
  V(Word32AtomicSubUint16)                                                 \
  V(Word32AtomicSubWord32)                                                 \
  V(Word32AtomicAndInt8)                                                   \
  V(Word32AtomicAndUint8)                                                  \
  V(Word32AtomicAndInt16)                                                  \
  V(Word32AtomicAndUint16)                                                 \
  V(Word32AtomicAndWord32)                                                 \
  V(Word32AtomicOrInt8)                                                    \
  V(Word32AtomicOrUint8)                                                   \
  V(Word32AtomicOrInt16)                                                   \
  V(Word32AtomicOrUint16)                                                  \
  V(Word32AtomicOrWord32)                                                  \
  V(Word32AtomicXorInt8)                                                   \
  V(Word32AtomicXorUint8)                                                  \
  V(Word32AtomicXorInt16)                                                  \
  V(Word32AtomicXorUint16)                                                 \
  V(Word32AtomicXorWord32)                                                 \
  V(Ieee754Float64Acos)                                                    \
  V(Ieee754Float64Acosh)                                                   \
  V(Ieee754Float64Asin)                                                    \
  V(Ieee754Float64Asinh)                                                   \
  V(Ieee754Float64Atan)                                                    \
  V(Ieee754Float64Atanh)                                                   \
  V(Ieee754Float64Atan2)                                                   \
  V(Ieee754Float64Cbrt)                                                    \
  V(Ieee754Float64Cos)                                                     \
  V(Ieee754Float64Cosh)                                                    \
  V(Ieee754Float64Exp)                                                     \
  V(Ieee754Float64Expm1)                                                   \
  V(Ieee754Float64Log)                                                     \
  V(Ieee754Float64Log1p)                                                   \
  V(Ieee754Float64Log10)                                                   \
  V(Ieee754Float64Log2)                                                    \
  V(Ieee754Float64Pow)                                                     \
  V(Ieee754Float64Sin)                                                     \
  V(Ieee754Float64Sinh)                                                    \
  V(Ieee754Float64Tan)                                                     \
167
  V(Ieee754Float64Tanh)
168 169 170

#define ARCH_OPCODE_LIST(V)  \
  COMMON_ARCH_OPCODE_LIST(V) \
171 172 173 174 175 176 177
  TARGET_ARCH_OPCODE_LIST(V)

enum ArchOpcode {
#define DECLARE_ARCH_OPCODE(Name) k##Name,
  ARCH_OPCODE_LIST(DECLARE_ARCH_OPCODE)
#undef DECLARE_ARCH_OPCODE
#define COUNT_ARCH_OPCODE(Name) +1
178
      kLastArchOpcode = -1 ARCH_OPCODE_LIST(COUNT_ARCH_OPCODE)
179 180 181
#undef COUNT_ARCH_OPCODE
};

182 183
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
                                           const ArchOpcode& ao);
184 185 186 187 188 189 190 191 192 193 194 195 196 197

// Addressing modes represent the "shape" of inputs to an instruction.
// Many instructions support multiple addressing modes. Addressing modes
// are encoded into the InstructionCode of the instruction and tell the
// code generator after register allocation which assembler method to call.
#define ADDRESSING_MODE_LIST(V) \
  V(None)                       \
  TARGET_ADDRESSING_MODE_LIST(V)

enum AddressingMode {
#define DECLARE_ADDRESSING_MODE(Name) kMode_##Name,
  ADDRESSING_MODE_LIST(DECLARE_ADDRESSING_MODE)
#undef DECLARE_ADDRESSING_MODE
#define COUNT_ADDRESSING_MODE(Name) +1
198
      kLastAddressingMode = -1 ADDRESSING_MODE_LIST(COUNT_ADDRESSING_MODE)
199 200 201
#undef COUNT_ADDRESSING_MODE
};

202 203
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
                                           const AddressingMode& am);
204 205

// The mode of the flags continuation (see below).
206 207 208
enum FlagsMode {
  kFlags_none = 0,
  kFlags_branch = 1,
209 210 211 212 213
  kFlags_branch_and_poison = 2,
  kFlags_deoptimize = 3,
  kFlags_deoptimize_and_poison = 4,
  kFlags_set = 5,
  kFlags_trap = 6
214
};
215

216 217
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
                                           const FlagsMode& fm);
218 219 220 221 222 223 224 225 226 227 228 229 230

// The condition of flags continuation (see below).
enum FlagsCondition {
  kEqual,
  kNotEqual,
  kSignedLessThan,
  kSignedGreaterThanOrEqual,
  kSignedLessThanOrEqual,
  kSignedGreaterThan,
  kUnsignedLessThan,
  kUnsignedGreaterThanOrEqual,
  kUnsignedLessThanOrEqual,
  kUnsignedGreaterThan,
231 232 233 234 235 236 237 238
  kFloatLessThanOrUnordered,
  kFloatGreaterThanOrEqual,
  kFloatLessThanOrEqual,
  kFloatGreaterThanOrUnordered,
  kFloatLessThan,
  kFloatGreaterThanOrEqualOrUnordered,
  kFloatLessThanOrEqualOrUnordered,
  kFloatGreaterThan,
239 240
  kUnorderedEqual,
  kUnorderedNotEqual,
241
  kOverflow,
242 243 244
  kNotOverflow,
  kPositiveOrZero,
  kNegative
245 246
};

247 248 249
static constexpr FlagsCondition kStackPointerGreaterThanCondition =
    kUnsignedGreaterThan;

250 251 252 253
inline FlagsCondition NegateFlagsCondition(FlagsCondition condition) {
  return static_cast<FlagsCondition>(condition ^ 1);
}

254 255
FlagsCondition CommuteFlagsCondition(FlagsCondition condition);

256 257
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
                                           const FlagsCondition& fc);
258

259 260 261 262 263 264
enum MemoryAccessMode {
  kMemoryAccessDirect = 0,
  kMemoryAccessProtected = 1,
  kMemoryAccessPoisoned = 2
};

265 266 267 268
// The InstructionCode is an opaque, target-specific integer that encodes
// what code to emit for an instruction in the code generator. It is not
// interesting to the register allocator, as the inputs and flags on the
// instructions specify everything of interest.
269
using InstructionCode = uint32_t;
270 271 272 273 274

// Helpers for encoding / decoding InstructionCode into the fields needed
// for code generation. We encode the instruction, addressing mode, and flags
// continuation into a single InstructionCode which is stored as part of
// the instruction.
275
using ArchOpcodeField = base::BitField<ArchOpcode, 0, 9>;
276 277
static_assert(ArchOpcodeField::is_valid(kLastArchOpcode),
              "All opcodes must fit in the 9-bit ArchOpcodeField.");
278 279 280
using AddressingModeField = base::BitField<AddressingMode, 9, 5>;
using FlagsModeField = base::BitField<FlagsMode, 14, 3>;
using FlagsConditionField = base::BitField<FlagsCondition, 17, 5>;
281 282
using DeoptImmedArgsCountField = base::BitField<int, 22, 2>;
using DeoptFrameStateOffsetField = base::BitField<int, 24, 8>;
283
using MiscField = base::BitField<int, 22, 10>;
284 285 286 287 288

}  // namespace compiler
}  // namespace internal
}  // namespace v8

289
#endif  // V8_COMPILER_BACKEND_INSTRUCTION_CODES_H_