blob: d2144cf638a9e6fb60fddfbcc5e770f7972c707a [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_COMPILER_INSTRUCTION_CODES_H_
6#define V8_COMPILER_INSTRUCTION_CODES_H_
7
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008#include <iosfwd>
9
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010#if V8_TARGET_ARCH_ARM
11#include "src/compiler/arm/instruction-codes-arm.h"
12#elif V8_TARGET_ARCH_ARM64
13#include "src/compiler/arm64/instruction-codes-arm64.h"
14#elif V8_TARGET_ARCH_IA32
15#include "src/compiler/ia32/instruction-codes-ia32.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040016#elif V8_TARGET_ARCH_MIPS
17#include "src/compiler/mips/instruction-codes-mips.h"
18#elif V8_TARGET_ARCH_MIPS64
19#include "src/compiler/mips64/instruction-codes-mips64.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020#elif V8_TARGET_ARCH_X64
21#include "src/compiler/x64/instruction-codes-x64.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000022#elif V8_TARGET_ARCH_PPC
23#include "src/compiler/ppc/instruction-codes-ppc.h"
24#elif V8_TARGET_ARCH_X87
25#include "src/compiler/x87/instruction-codes-x87.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000026#else
27#define TARGET_ARCH_OPCODE_LIST(V)
28#define TARGET_ADDRESSING_MODE_LIST(V)
29#endif
30#include "src/utils.h"
31
32namespace v8 {
33namespace internal {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000034namespace compiler {
35
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000036// Modes for ArchStoreWithWriteBarrier below.
37enum class RecordWriteMode { kValueIsMap, kValueIsPointer, kValueIsAny };
38
39
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040// Target-specific opcodes that specify which assembly sequence to emit.
41// Most opcodes specify a single instruction.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000042#define COMMON_ARCH_OPCODE_LIST(V) \
43 V(ArchCallCodeObject) \
44 V(ArchTailCallCodeObject) \
45 V(ArchCallJSFunction) \
46 V(ArchTailCallJSFunction) \
47 V(ArchPrepareCallCFunction) \
48 V(ArchCallCFunction) \
49 V(ArchPrepareTailCall) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000050 V(ArchJmp) \
51 V(ArchLookupSwitch) \
52 V(ArchTableSwitch) \
53 V(ArchNop) \
54 V(ArchThrowTerminator) \
55 V(ArchDeoptimize) \
56 V(ArchRet) \
57 V(ArchStackPointer) \
58 V(ArchFramePointer) \
Ben Murdoch097c5b22016-05-18 11:27:45 +010059 V(ArchParentFramePointer) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000060 V(ArchTruncateDoubleToI) \
61 V(ArchStoreWithWriteBarrier) \
62 V(CheckedLoadInt8) \
63 V(CheckedLoadUint8) \
64 V(CheckedLoadInt16) \
65 V(CheckedLoadUint16) \
66 V(CheckedLoadWord32) \
67 V(CheckedLoadWord64) \
68 V(CheckedLoadFloat32) \
69 V(CheckedLoadFloat64) \
70 V(CheckedStoreWord8) \
71 V(CheckedStoreWord16) \
72 V(CheckedStoreWord32) \
73 V(CheckedStoreWord64) \
74 V(CheckedStoreFloat32) \
Ben Murdoch097c5b22016-05-18 11:27:45 +010075 V(CheckedStoreFloat64) \
76 V(ArchStackSlot)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000077
78#define ARCH_OPCODE_LIST(V) \
79 COMMON_ARCH_OPCODE_LIST(V) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000080 TARGET_ARCH_OPCODE_LIST(V)
81
82enum ArchOpcode {
83#define DECLARE_ARCH_OPCODE(Name) k##Name,
84 ARCH_OPCODE_LIST(DECLARE_ARCH_OPCODE)
85#undef DECLARE_ARCH_OPCODE
86#define COUNT_ARCH_OPCODE(Name) +1
87 kLastArchOpcode = -1 ARCH_OPCODE_LIST(COUNT_ARCH_OPCODE)
88#undef COUNT_ARCH_OPCODE
89};
90
Emily Bernierd0a1eb72015-03-24 16:35:39 -040091std::ostream& operator<<(std::ostream& os, const ArchOpcode& ao);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000092
93// Addressing modes represent the "shape" of inputs to an instruction.
94// Many instructions support multiple addressing modes. Addressing modes
95// are encoded into the InstructionCode of the instruction and tell the
96// code generator after register allocation which assembler method to call.
97#define ADDRESSING_MODE_LIST(V) \
98 V(None) \
99 TARGET_ADDRESSING_MODE_LIST(V)
100
101enum AddressingMode {
102#define DECLARE_ADDRESSING_MODE(Name) kMode_##Name,
103 ADDRESSING_MODE_LIST(DECLARE_ADDRESSING_MODE)
104#undef DECLARE_ADDRESSING_MODE
105#define COUNT_ADDRESSING_MODE(Name) +1
106 kLastAddressingMode = -1 ADDRESSING_MODE_LIST(COUNT_ADDRESSING_MODE)
107#undef COUNT_ADDRESSING_MODE
108};
109
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400110std::ostream& operator<<(std::ostream& os, const AddressingMode& am);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000111
112// The mode of the flags continuation (see below).
113enum FlagsMode { kFlags_none = 0, kFlags_branch = 1, kFlags_set = 2 };
114
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400115std::ostream& operator<<(std::ostream& os, const FlagsMode& fm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000116
117// The condition of flags continuation (see below).
118enum FlagsCondition {
119 kEqual,
120 kNotEqual,
121 kSignedLessThan,
122 kSignedGreaterThanOrEqual,
123 kSignedLessThanOrEqual,
124 kSignedGreaterThan,
125 kUnsignedLessThan,
126 kUnsignedGreaterThanOrEqual,
127 kUnsignedLessThanOrEqual,
128 kUnsignedGreaterThan,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000129 kFloatLessThanOrUnordered,
130 kFloatGreaterThanOrEqual,
131 kFloatLessThanOrEqual,
132 kFloatGreaterThanOrUnordered,
133 kFloatLessThan,
134 kFloatGreaterThanOrEqualOrUnordered,
135 kFloatLessThanOrEqualOrUnordered,
136 kFloatGreaterThan,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000137 kUnorderedEqual,
138 kUnorderedNotEqual,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000139 kOverflow,
140 kNotOverflow
141};
142
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400143inline FlagsCondition NegateFlagsCondition(FlagsCondition condition) {
144 return static_cast<FlagsCondition>(condition ^ 1);
145}
146
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000147FlagsCondition CommuteFlagsCondition(FlagsCondition condition);
148
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400149std::ostream& operator<<(std::ostream& os, const FlagsCondition& fc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000150
151// The InstructionCode is an opaque, target-specific integer that encodes
152// what code to emit for an instruction in the code generator. It is not
153// interesting to the register allocator, as the inputs and flags on the
154// instructions specify everything of interest.
155typedef int32_t InstructionCode;
156
157// Helpers for encoding / decoding InstructionCode into the fields needed
158// for code generation. We encode the instruction, addressing mode, and flags
159// continuation into a single InstructionCode which is stored as part of
160// the instruction.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000161typedef BitField<ArchOpcode, 0, 8> ArchOpcodeField;
162typedef BitField<AddressingMode, 8, 5> AddressingModeField;
163typedef BitField<FlagsMode, 13, 2> FlagsModeField;
164typedef BitField<FlagsCondition, 15, 5> FlagsConditionField;
165typedef BitField<int, 20, 12> MiscField;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000166
167} // namespace compiler
168} // namespace internal
169} // namespace v8
170
171#endif // V8_COMPILER_INSTRUCTION_CODES_H_