blob: c6689d8e18bff1af44fee0f57f5495390a5d1cd5 [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 Bernier958fae72015-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 Bernier958fae72015-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 Murdoch014dc512016-03-22 12:00:34 +000022#elif V8_TARGET_ARCH_PPC
23#include "src/compiler/ppc/instruction-codes-ppc.h"
Ben Murdoch3b9bc312016-06-02 14:46:10 +010024#elif V8_TARGET_ARCH_S390
25#include "src/compiler/s390/instruction-codes-s390.h"
Ben Murdoch014dc512016-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 Murdoch014dc512016-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 Murdoch3b9bc312016-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 Murdochbcf72ee2016-08-08 18:44:38 +010051 V(ArchTailCallAddress) \
Ben Murdoch3b9bc312016-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) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +010059 V(ArchDebugBreak) \
Ben Murdochf91f0612016-11-29 16:50:11 +000060 V(ArchImpossible) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +010061 V(ArchComment) \
Ben Murdoch3b9bc312016-06-02 14:46:10 +010062 V(ArchThrowTerminator) \
63 V(ArchDeoptimize) \
64 V(ArchRet) \
65 V(ArchStackPointer) \
66 V(ArchFramePointer) \
67 V(ArchParentFramePointer) \
68 V(ArchTruncateDoubleToI) \
69 V(ArchStoreWithWriteBarrier) \
70 V(CheckedLoadInt8) \
71 V(CheckedLoadUint8) \
72 V(CheckedLoadInt16) \
73 V(CheckedLoadUint16) \
74 V(CheckedLoadWord32) \
75 V(CheckedLoadWord64) \
76 V(CheckedLoadFloat32) \
77 V(CheckedLoadFloat64) \
78 V(CheckedStoreWord8) \
79 V(CheckedStoreWord16) \
80 V(CheckedStoreWord32) \
81 V(CheckedStoreWord64) \
82 V(CheckedStoreFloat32) \
83 V(CheckedStoreFloat64) \
Ben Murdochbcf72ee2016-08-08 18:44:38 +010084 V(ArchStackSlot) \
85 V(AtomicLoadInt8) \
86 V(AtomicLoadUint8) \
87 V(AtomicLoadInt16) \
88 V(AtomicLoadUint16) \
89 V(AtomicLoadWord32) \
90 V(AtomicStoreWord8) \
91 V(AtomicStoreWord16) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +010092 V(AtomicStoreWord32) \
Ben Murdochf91f0612016-11-29 16:50:11 +000093 V(Ieee754Float64Acos) \
94 V(Ieee754Float64Acosh) \
95 V(Ieee754Float64Asin) \
96 V(Ieee754Float64Asinh) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +010097 V(Ieee754Float64Atan) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +010098 V(Ieee754Float64Atanh) \
Ben Murdochf91f0612016-11-29 16:50:11 +000099 V(Ieee754Float64Atan2) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100100 V(Ieee754Float64Cbrt) \
101 V(Ieee754Float64Cos) \
Ben Murdochf91f0612016-11-29 16:50:11 +0000102 V(Ieee754Float64Cosh) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100103 V(Ieee754Float64Exp) \
104 V(Ieee754Float64Expm1) \
105 V(Ieee754Float64Log) \
106 V(Ieee754Float64Log1p) \
107 V(Ieee754Float64Log10) \
108 V(Ieee754Float64Log2) \
Ben Murdochf91f0612016-11-29 16:50:11 +0000109 V(Ieee754Float64Pow) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100110 V(Ieee754Float64Sin) \
Ben Murdochf91f0612016-11-29 16:50:11 +0000111 V(Ieee754Float64Sinh) \
112 V(Ieee754Float64Tan) \
113 V(Ieee754Float64Tanh)
Ben Murdoch014dc512016-03-22 12:00:34 +0000114
115#define ARCH_OPCODE_LIST(V) \
116 COMMON_ARCH_OPCODE_LIST(V) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000117 TARGET_ARCH_OPCODE_LIST(V)
118
119enum ArchOpcode {
120#define DECLARE_ARCH_OPCODE(Name) k##Name,
121 ARCH_OPCODE_LIST(DECLARE_ARCH_OPCODE)
122#undef DECLARE_ARCH_OPCODE
123#define COUNT_ARCH_OPCODE(Name) +1
124 kLastArchOpcode = -1 ARCH_OPCODE_LIST(COUNT_ARCH_OPCODE)
125#undef COUNT_ARCH_OPCODE
126};
127
Emily Bernier958fae72015-03-24 16:35:39 -0400128std::ostream& operator<<(std::ostream& os, const ArchOpcode& ao);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000129
130// Addressing modes represent the "shape" of inputs to an instruction.
131// Many instructions support multiple addressing modes. Addressing modes
132// are encoded into the InstructionCode of the instruction and tell the
133// code generator after register allocation which assembler method to call.
134#define ADDRESSING_MODE_LIST(V) \
135 V(None) \
136 TARGET_ADDRESSING_MODE_LIST(V)
137
138enum AddressingMode {
139#define DECLARE_ADDRESSING_MODE(Name) kMode_##Name,
140 ADDRESSING_MODE_LIST(DECLARE_ADDRESSING_MODE)
141#undef DECLARE_ADDRESSING_MODE
142#define COUNT_ADDRESSING_MODE(Name) +1
143 kLastAddressingMode = -1 ADDRESSING_MODE_LIST(COUNT_ADDRESSING_MODE)
144#undef COUNT_ADDRESSING_MODE
145};
146
Emily Bernier958fae72015-03-24 16:35:39 -0400147std::ostream& operator<<(std::ostream& os, const AddressingMode& am);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000148
149// The mode of the flags continuation (see below).
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100150enum FlagsMode {
151 kFlags_none = 0,
152 kFlags_branch = 1,
153 kFlags_deoptimize = 2,
154 kFlags_set = 3
155};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000156
Emily Bernier958fae72015-03-24 16:35:39 -0400157std::ostream& operator<<(std::ostream& os, const FlagsMode& fm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000158
159// The condition of flags continuation (see below).
160enum FlagsCondition {
161 kEqual,
162 kNotEqual,
163 kSignedLessThan,
164 kSignedGreaterThanOrEqual,
165 kSignedLessThanOrEqual,
166 kSignedGreaterThan,
167 kUnsignedLessThan,
168 kUnsignedGreaterThanOrEqual,
169 kUnsignedLessThanOrEqual,
170 kUnsignedGreaterThan,
Ben Murdoch014dc512016-03-22 12:00:34 +0000171 kFloatLessThanOrUnordered,
172 kFloatGreaterThanOrEqual,
173 kFloatLessThanOrEqual,
174 kFloatGreaterThanOrUnordered,
175 kFloatLessThan,
176 kFloatGreaterThanOrEqualOrUnordered,
177 kFloatLessThanOrEqualOrUnordered,
178 kFloatGreaterThan,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000179 kUnorderedEqual,
180 kUnorderedNotEqual,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000181 kOverflow,
Ben Murdochf91f0612016-11-29 16:50:11 +0000182 kNotOverflow,
183 kPositiveOrZero,
184 kNegative
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000185};
186
Emily Bernier958fae72015-03-24 16:35:39 -0400187inline FlagsCondition NegateFlagsCondition(FlagsCondition condition) {
188 return static_cast<FlagsCondition>(condition ^ 1);
189}
190
Ben Murdoch014dc512016-03-22 12:00:34 +0000191FlagsCondition CommuteFlagsCondition(FlagsCondition condition);
192
Emily Bernier958fae72015-03-24 16:35:39 -0400193std::ostream& operator<<(std::ostream& os, const FlagsCondition& fc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000194
195// The InstructionCode is an opaque, target-specific integer that encodes
196// what code to emit for an instruction in the code generator. It is not
197// interesting to the register allocator, as the inputs and flags on the
198// instructions specify everything of interest.
199typedef int32_t InstructionCode;
200
201// Helpers for encoding / decoding InstructionCode into the fields needed
202// for code generation. We encode the instruction, addressing mode, and flags
203// continuation into a single InstructionCode which is stored as part of
204// the instruction.
Ben Murdoch014dc512016-03-22 12:00:34 +0000205typedef BitField<ArchOpcode, 0, 8> ArchOpcodeField;
206typedef BitField<AddressingMode, 8, 5> AddressingModeField;
207typedef BitField<FlagsMode, 13, 2> FlagsModeField;
208typedef BitField<FlagsCondition, 15, 5> FlagsConditionField;
209typedef BitField<int, 20, 12> MiscField;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000210
211} // namespace compiler
212} // namespace internal
213} // namespace v8
214
215#endif // V8_COMPILER_INSTRUCTION_CODES_H_