blob: 6c31ac8f9d91f9ff7d5b0399ee8c32afb3e6b78f [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) \
50 V(ArchLazyBailout) \
51 V(ArchJmp) \
52 V(ArchLookupSwitch) \
53 V(ArchTableSwitch) \
54 V(ArchNop) \
55 V(ArchThrowTerminator) \
56 V(ArchDeoptimize) \
57 V(ArchRet) \
58 V(ArchStackPointer) \
59 V(ArchFramePointer) \
60 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) \
75 V(CheckedStoreFloat64)
76
77#define ARCH_OPCODE_LIST(V) \
78 COMMON_ARCH_OPCODE_LIST(V) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079 TARGET_ARCH_OPCODE_LIST(V)
80
81enum ArchOpcode {
82#define DECLARE_ARCH_OPCODE(Name) k##Name,
83 ARCH_OPCODE_LIST(DECLARE_ARCH_OPCODE)
84#undef DECLARE_ARCH_OPCODE
85#define COUNT_ARCH_OPCODE(Name) +1
86 kLastArchOpcode = -1 ARCH_OPCODE_LIST(COUNT_ARCH_OPCODE)
87#undef COUNT_ARCH_OPCODE
88};
89
Emily Bernierd0a1eb72015-03-24 16:35:39 -040090std::ostream& operator<<(std::ostream& os, const ArchOpcode& ao);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000091
92// Addressing modes represent the "shape" of inputs to an instruction.
93// Many instructions support multiple addressing modes. Addressing modes
94// are encoded into the InstructionCode of the instruction and tell the
95// code generator after register allocation which assembler method to call.
96#define ADDRESSING_MODE_LIST(V) \
97 V(None) \
98 TARGET_ADDRESSING_MODE_LIST(V)
99
100enum AddressingMode {
101#define DECLARE_ADDRESSING_MODE(Name) kMode_##Name,
102 ADDRESSING_MODE_LIST(DECLARE_ADDRESSING_MODE)
103#undef DECLARE_ADDRESSING_MODE
104#define COUNT_ADDRESSING_MODE(Name) +1
105 kLastAddressingMode = -1 ADDRESSING_MODE_LIST(COUNT_ADDRESSING_MODE)
106#undef COUNT_ADDRESSING_MODE
107};
108
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400109std::ostream& operator<<(std::ostream& os, const AddressingMode& am);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000110
111// The mode of the flags continuation (see below).
112enum FlagsMode { kFlags_none = 0, kFlags_branch = 1, kFlags_set = 2 };
113
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400114std::ostream& operator<<(std::ostream& os, const FlagsMode& fm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000115
116// The condition of flags continuation (see below).
117enum FlagsCondition {
118 kEqual,
119 kNotEqual,
120 kSignedLessThan,
121 kSignedGreaterThanOrEqual,
122 kSignedLessThanOrEqual,
123 kSignedGreaterThan,
124 kUnsignedLessThan,
125 kUnsignedGreaterThanOrEqual,
126 kUnsignedLessThanOrEqual,
127 kUnsignedGreaterThan,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000128 kFloatLessThanOrUnordered,
129 kFloatGreaterThanOrEqual,
130 kFloatLessThanOrEqual,
131 kFloatGreaterThanOrUnordered,
132 kFloatLessThan,
133 kFloatGreaterThanOrEqualOrUnordered,
134 kFloatLessThanOrEqualOrUnordered,
135 kFloatGreaterThan,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000136 kUnorderedEqual,
137 kUnorderedNotEqual,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000138 kOverflow,
139 kNotOverflow
140};
141
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400142inline FlagsCondition NegateFlagsCondition(FlagsCondition condition) {
143 return static_cast<FlagsCondition>(condition ^ 1);
144}
145
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000146FlagsCondition CommuteFlagsCondition(FlagsCondition condition);
147
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400148std::ostream& operator<<(std::ostream& os, const FlagsCondition& fc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000149
150// The InstructionCode is an opaque, target-specific integer that encodes
151// what code to emit for an instruction in the code generator. It is not
152// interesting to the register allocator, as the inputs and flags on the
153// instructions specify everything of interest.
154typedef int32_t InstructionCode;
155
156// Helpers for encoding / decoding InstructionCode into the fields needed
157// for code generation. We encode the instruction, addressing mode, and flags
158// continuation into a single InstructionCode which is stored as part of
159// the instruction.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000160typedef BitField<ArchOpcode, 0, 8> ArchOpcodeField;
161typedef BitField<AddressingMode, 8, 5> AddressingModeField;
162typedef BitField<FlagsMode, 13, 2> FlagsModeField;
163typedef BitField<FlagsCondition, 15, 5> FlagsConditionField;
164typedef BitField<int, 20, 12> MiscField;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000165
166} // namespace compiler
167} // namespace internal
168} // namespace v8
169
170#endif // V8_COMPILER_INSTRUCTION_CODES_H_