blob: 22279fea7a7ec583f3162901f6625bd02303f206 [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) \
60 V(ArchComment) \
Ben Murdoch3b9bc312016-06-02 14:46:10 +010061 V(ArchThrowTerminator) \
62 V(ArchDeoptimize) \
63 V(ArchRet) \
64 V(ArchStackPointer) \
65 V(ArchFramePointer) \
66 V(ArchParentFramePointer) \
67 V(ArchTruncateDoubleToI) \
68 V(ArchStoreWithWriteBarrier) \
69 V(CheckedLoadInt8) \
70 V(CheckedLoadUint8) \
71 V(CheckedLoadInt16) \
72 V(CheckedLoadUint16) \
73 V(CheckedLoadWord32) \
74 V(CheckedLoadWord64) \
75 V(CheckedLoadFloat32) \
76 V(CheckedLoadFloat64) \
77 V(CheckedStoreWord8) \
78 V(CheckedStoreWord16) \
79 V(CheckedStoreWord32) \
80 V(CheckedStoreWord64) \
81 V(CheckedStoreFloat32) \
82 V(CheckedStoreFloat64) \
Ben Murdochbcf72ee2016-08-08 18:44:38 +010083 V(ArchStackSlot) \
84 V(AtomicLoadInt8) \
85 V(AtomicLoadUint8) \
86 V(AtomicLoadInt16) \
87 V(AtomicLoadUint16) \
88 V(AtomicLoadWord32) \
89 V(AtomicStoreWord8) \
90 V(AtomicStoreWord16) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +010091 V(AtomicStoreWord32) \
Ben Murdochf91f0612016-11-29 16:50:11 +000092 V(Ieee754Float64Acos) \
93 V(Ieee754Float64Acosh) \
94 V(Ieee754Float64Asin) \
95 V(Ieee754Float64Asinh) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +010096 V(Ieee754Float64Atan) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +010097 V(Ieee754Float64Atanh) \
Ben Murdochf91f0612016-11-29 16:50:11 +000098 V(Ieee754Float64Atan2) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +010099 V(Ieee754Float64Cbrt) \
100 V(Ieee754Float64Cos) \
Ben Murdochf91f0612016-11-29 16:50:11 +0000101 V(Ieee754Float64Cosh) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100102 V(Ieee754Float64Exp) \
103 V(Ieee754Float64Expm1) \
104 V(Ieee754Float64Log) \
105 V(Ieee754Float64Log1p) \
106 V(Ieee754Float64Log10) \
107 V(Ieee754Float64Log2) \
Ben Murdochf91f0612016-11-29 16:50:11 +0000108 V(Ieee754Float64Pow) \
Ben Murdoch13e2dad2016-09-16 13:49:30 +0100109 V(Ieee754Float64Sin) \
Ben Murdochf91f0612016-11-29 16:50:11 +0000110 V(Ieee754Float64Sinh) \
111 V(Ieee754Float64Tan) \
112 V(Ieee754Float64Tanh)
Ben Murdoch014dc512016-03-22 12:00:34 +0000113
114#define ARCH_OPCODE_LIST(V) \
115 COMMON_ARCH_OPCODE_LIST(V) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000116 TARGET_ARCH_OPCODE_LIST(V)
117
118enum ArchOpcode {
119#define DECLARE_ARCH_OPCODE(Name) k##Name,
120 ARCH_OPCODE_LIST(DECLARE_ARCH_OPCODE)
121#undef DECLARE_ARCH_OPCODE
122#define COUNT_ARCH_OPCODE(Name) +1
123 kLastArchOpcode = -1 ARCH_OPCODE_LIST(COUNT_ARCH_OPCODE)
124#undef COUNT_ARCH_OPCODE
125};
126
Emily Bernier958fae72015-03-24 16:35:39 -0400127std::ostream& operator<<(std::ostream& os, const ArchOpcode& ao);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128
129// Addressing modes represent the "shape" of inputs to an instruction.
130// Many instructions support multiple addressing modes. Addressing modes
131// are encoded into the InstructionCode of the instruction and tell the
132// code generator after register allocation which assembler method to call.
133#define ADDRESSING_MODE_LIST(V) \
134 V(None) \
135 TARGET_ADDRESSING_MODE_LIST(V)
136
137enum AddressingMode {
138#define DECLARE_ADDRESSING_MODE(Name) kMode_##Name,
139 ADDRESSING_MODE_LIST(DECLARE_ADDRESSING_MODE)
140#undef DECLARE_ADDRESSING_MODE
141#define COUNT_ADDRESSING_MODE(Name) +1
142 kLastAddressingMode = -1 ADDRESSING_MODE_LIST(COUNT_ADDRESSING_MODE)
143#undef COUNT_ADDRESSING_MODE
144};
145
Emily Bernier958fae72015-03-24 16:35:39 -0400146std::ostream& operator<<(std::ostream& os, const AddressingMode& am);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000147
148// The mode of the flags continuation (see below).
Ben Murdoch3b9bc312016-06-02 14:46:10 +0100149enum FlagsMode {
150 kFlags_none = 0,
151 kFlags_branch = 1,
152 kFlags_deoptimize = 2,
153 kFlags_set = 3
154};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000155
Emily Bernier958fae72015-03-24 16:35:39 -0400156std::ostream& operator<<(std::ostream& os, const FlagsMode& fm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000157
158// The condition of flags continuation (see below).
159enum FlagsCondition {
160 kEqual,
161 kNotEqual,
162 kSignedLessThan,
163 kSignedGreaterThanOrEqual,
164 kSignedLessThanOrEqual,
165 kSignedGreaterThan,
166 kUnsignedLessThan,
167 kUnsignedGreaterThanOrEqual,
168 kUnsignedLessThanOrEqual,
169 kUnsignedGreaterThan,
Ben Murdoch014dc512016-03-22 12:00:34 +0000170 kFloatLessThanOrUnordered,
171 kFloatGreaterThanOrEqual,
172 kFloatLessThanOrEqual,
173 kFloatGreaterThanOrUnordered,
174 kFloatLessThan,
175 kFloatGreaterThanOrEqualOrUnordered,
176 kFloatLessThanOrEqualOrUnordered,
177 kFloatGreaterThan,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000178 kUnorderedEqual,
179 kUnorderedNotEqual,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000180 kOverflow,
Ben Murdochf91f0612016-11-29 16:50:11 +0000181 kNotOverflow,
182 kPositiveOrZero,
183 kNegative
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000184};
185
Emily Bernier958fae72015-03-24 16:35:39 -0400186inline FlagsCondition NegateFlagsCondition(FlagsCondition condition) {
187 return static_cast<FlagsCondition>(condition ^ 1);
188}
189
Ben Murdoch014dc512016-03-22 12:00:34 +0000190FlagsCondition CommuteFlagsCondition(FlagsCondition condition);
191
Emily Bernier958fae72015-03-24 16:35:39 -0400192std::ostream& operator<<(std::ostream& os, const FlagsCondition& fc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000193
194// The InstructionCode is an opaque, target-specific integer that encodes
195// what code to emit for an instruction in the code generator. It is not
196// interesting to the register allocator, as the inputs and flags on the
197// instructions specify everything of interest.
198typedef int32_t InstructionCode;
199
200// Helpers for encoding / decoding InstructionCode into the fields needed
201// for code generation. We encode the instruction, addressing mode, and flags
202// continuation into a single InstructionCode which is stored as part of
203// the instruction.
Ben Murdoch014dc512016-03-22 12:00:34 +0000204typedef BitField<ArchOpcode, 0, 8> ArchOpcodeField;
205typedef BitField<AddressingMode, 8, 5> AddressingModeField;
206typedef BitField<FlagsMode, 13, 2> FlagsModeField;
207typedef BitField<FlagsCondition, 15, 5> FlagsConditionField;
208typedef BitField<int, 20, 12> MiscField;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000209
210} // namespace compiler
211} // namespace internal
212} // namespace v8
213
214#endif // V8_COMPILER_INSTRUCTION_CODES_H_