blob: 57868c6507f3dba36dd338ab0a89f386d74b3f7d [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"
Ben Murdochda12d292016-06-02 14:46:10 +010024#elif V8_TARGET_ARCH_S390
25#include "src/compiler/s390/instruction-codes-s390.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026#elif V8_TARGET_ARCH_X87
27#include "src/compiler/x87/instruction-codes-x87.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000028#else
29#define TARGET_ARCH_OPCODE_LIST(V)
30#define TARGET_ADDRESSING_MODE_LIST(V)
31#endif
32#include "src/utils.h"
33
34namespace v8 {
35namespace internal {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036namespace compiler {
37
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000038// Modes for ArchStoreWithWriteBarrier below.
39enum class RecordWriteMode { kValueIsMap, kValueIsPointer, kValueIsAny };
40
41
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042// Target-specific opcodes that specify which assembly sequence to emit.
43// Most opcodes specify a single instruction.
Ben Murdochda12d292016-06-02 14:46:10 +010044#define COMMON_ARCH_OPCODE_LIST(V) \
45 V(ArchCallCodeObject) \
46 V(ArchTailCallCodeObjectFromJSFunction) \
47 V(ArchTailCallCodeObject) \
48 V(ArchCallJSFunction) \
49 V(ArchTailCallJSFunctionFromJSFunction) \
50 V(ArchTailCallJSFunction) \
Ben Murdochc5610432016-08-08 18:44:38 +010051 V(ArchTailCallAddress) \
Ben Murdochda12d292016-06-02 14:46:10 +010052 V(ArchPrepareCallCFunction) \
53 V(ArchCallCFunction) \
54 V(ArchPrepareTailCall) \
55 V(ArchJmp) \
56 V(ArchLookupSwitch) \
57 V(ArchTableSwitch) \
58 V(ArchNop) \
59 V(ArchThrowTerminator) \
60 V(ArchDeoptimize) \
61 V(ArchRet) \
62 V(ArchStackPointer) \
63 V(ArchFramePointer) \
64 V(ArchParentFramePointer) \
65 V(ArchTruncateDoubleToI) \
66 V(ArchStoreWithWriteBarrier) \
67 V(CheckedLoadInt8) \
68 V(CheckedLoadUint8) \
69 V(CheckedLoadInt16) \
70 V(CheckedLoadUint16) \
71 V(CheckedLoadWord32) \
72 V(CheckedLoadWord64) \
73 V(CheckedLoadFloat32) \
74 V(CheckedLoadFloat64) \
75 V(CheckedStoreWord8) \
76 V(CheckedStoreWord16) \
77 V(CheckedStoreWord32) \
78 V(CheckedStoreWord64) \
79 V(CheckedStoreFloat32) \
80 V(CheckedStoreFloat64) \
Ben Murdochc5610432016-08-08 18:44:38 +010081 V(ArchStackSlot) \
82 V(AtomicLoadInt8) \
83 V(AtomicLoadUint8) \
84 V(AtomicLoadInt16) \
85 V(AtomicLoadUint16) \
86 V(AtomicLoadWord32) \
87 V(AtomicStoreWord8) \
88 V(AtomicStoreWord16) \
89 V(AtomicStoreWord32)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000090
91#define ARCH_OPCODE_LIST(V) \
92 COMMON_ARCH_OPCODE_LIST(V) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000093 TARGET_ARCH_OPCODE_LIST(V)
94
95enum ArchOpcode {
96#define DECLARE_ARCH_OPCODE(Name) k##Name,
97 ARCH_OPCODE_LIST(DECLARE_ARCH_OPCODE)
98#undef DECLARE_ARCH_OPCODE
99#define COUNT_ARCH_OPCODE(Name) +1
100 kLastArchOpcode = -1 ARCH_OPCODE_LIST(COUNT_ARCH_OPCODE)
101#undef COUNT_ARCH_OPCODE
102};
103
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400104std::ostream& operator<<(std::ostream& os, const ArchOpcode& ao);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105
106// Addressing modes represent the "shape" of inputs to an instruction.
107// Many instructions support multiple addressing modes. Addressing modes
108// are encoded into the InstructionCode of the instruction and tell the
109// code generator after register allocation which assembler method to call.
110#define ADDRESSING_MODE_LIST(V) \
111 V(None) \
112 TARGET_ADDRESSING_MODE_LIST(V)
113
114enum AddressingMode {
115#define DECLARE_ADDRESSING_MODE(Name) kMode_##Name,
116 ADDRESSING_MODE_LIST(DECLARE_ADDRESSING_MODE)
117#undef DECLARE_ADDRESSING_MODE
118#define COUNT_ADDRESSING_MODE(Name) +1
119 kLastAddressingMode = -1 ADDRESSING_MODE_LIST(COUNT_ADDRESSING_MODE)
120#undef COUNT_ADDRESSING_MODE
121};
122
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400123std::ostream& operator<<(std::ostream& os, const AddressingMode& am);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000124
125// The mode of the flags continuation (see below).
Ben Murdochda12d292016-06-02 14:46:10 +0100126enum FlagsMode {
127 kFlags_none = 0,
128 kFlags_branch = 1,
129 kFlags_deoptimize = 2,
130 kFlags_set = 3
131};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000132
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400133std::ostream& operator<<(std::ostream& os, const FlagsMode& fm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000134
135// The condition of flags continuation (see below).
136enum FlagsCondition {
137 kEqual,
138 kNotEqual,
139 kSignedLessThan,
140 kSignedGreaterThanOrEqual,
141 kSignedLessThanOrEqual,
142 kSignedGreaterThan,
143 kUnsignedLessThan,
144 kUnsignedGreaterThanOrEqual,
145 kUnsignedLessThanOrEqual,
146 kUnsignedGreaterThan,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000147 kFloatLessThanOrUnordered,
148 kFloatGreaterThanOrEqual,
149 kFloatLessThanOrEqual,
150 kFloatGreaterThanOrUnordered,
151 kFloatLessThan,
152 kFloatGreaterThanOrEqualOrUnordered,
153 kFloatLessThanOrEqualOrUnordered,
154 kFloatGreaterThan,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000155 kUnorderedEqual,
156 kUnorderedNotEqual,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000157 kOverflow,
158 kNotOverflow
159};
160
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400161inline FlagsCondition NegateFlagsCondition(FlagsCondition condition) {
162 return static_cast<FlagsCondition>(condition ^ 1);
163}
164
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000165FlagsCondition CommuteFlagsCondition(FlagsCondition condition);
166
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400167std::ostream& operator<<(std::ostream& os, const FlagsCondition& fc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000168
169// The InstructionCode is an opaque, target-specific integer that encodes
170// what code to emit for an instruction in the code generator. It is not
171// interesting to the register allocator, as the inputs and flags on the
172// instructions specify everything of interest.
173typedef int32_t InstructionCode;
174
175// Helpers for encoding / decoding InstructionCode into the fields needed
176// for code generation. We encode the instruction, addressing mode, and flags
177// continuation into a single InstructionCode which is stored as part of
178// the instruction.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000179typedef BitField<ArchOpcode, 0, 8> ArchOpcodeField;
180typedef BitField<AddressingMode, 8, 5> AddressingModeField;
181typedef BitField<FlagsMode, 13, 2> FlagsModeField;
182typedef BitField<FlagsCondition, 15, 5> FlagsConditionField;
183typedef BitField<int, 20, 12> MiscField;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000184
185} // namespace compiler
186} // namespace internal
187} // namespace v8
188
189#endif // V8_COMPILER_INSTRUCTION_CODES_H_