blob: af6066b1330ab5c2bac4f9839afab8d68168b83c [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2013 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_COMMON_OPERATOR_H_
6#define V8_COMPILER_COMMON_OPERATOR_H_
7
8#include "src/compiler/machine-type.h"
9#include "src/unique.h"
10
11namespace v8 {
12namespace internal {
13
14// Forward declarations.
15class ExternalReference;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000016
17
18namespace compiler {
19
20// Forward declarations.
21class CallDescriptor;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040022struct CommonOperatorGlobalCache;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000023class Operator;
24
25
Emily Bernierd0a1eb72015-03-24 16:35:39 -040026// Prediction hint for branches.
27enum class BranchHint : uint8_t { kNone, kTrue, kFalse };
28
29inline size_t hash_value(BranchHint hint) { return static_cast<size_t>(hint); }
30
31std::ostream& operator<<(std::ostream&, BranchHint);
32
33BranchHint BranchHintOf(const Operator* const);
34
35
36class SelectParameters FINAL {
37 public:
38 explicit SelectParameters(MachineType type,
39 BranchHint hint = BranchHint::kNone)
40 : type_(type), hint_(hint) {}
41
42 MachineType type() const { return type_; }
43 BranchHint hint() const { return hint_; }
44
45 private:
46 const MachineType type_;
47 const BranchHint hint_;
48};
49
50bool operator==(SelectParameters const&, SelectParameters const&);
51bool operator!=(SelectParameters const&, SelectParameters const&);
52
53size_t hash_value(SelectParameters const& p);
54
55std::ostream& operator<<(std::ostream&, SelectParameters const& p);
56
57SelectParameters const& SelectParametersOf(const Operator* const);
58
59
Ben Murdochb8a8cc12014-11-26 15:28:44 +000060// Flag that describes how to combine the current environment with
61// the output of a node to obtain a framestate for lazy bailout.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040062class OutputFrameStateCombine {
63 public:
64 enum Kind {
65 kPushOutput, // Push the output on the expression stack.
66 kPokeAt // Poke at the given environment location,
67 // counting from the top of the stack.
68 };
69
70 static OutputFrameStateCombine Ignore() {
71 return OutputFrameStateCombine(kPushOutput, 0);
72 }
73 static OutputFrameStateCombine Push(size_t count = 1) {
74 return OutputFrameStateCombine(kPushOutput, count);
75 }
76 static OutputFrameStateCombine PokeAt(size_t index) {
77 return OutputFrameStateCombine(kPokeAt, index);
78 }
79
80 Kind kind() const { return kind_; }
81 size_t GetPushCount() const {
82 DCHECK_EQ(kPushOutput, kind());
83 return parameter_;
84 }
85 size_t GetOffsetToPokeAt() const {
86 DCHECK_EQ(kPokeAt, kind());
87 return parameter_;
88 }
89
90 bool IsOutputIgnored() const {
91 return kind_ == kPushOutput && parameter_ == 0;
92 }
93
94 size_t ConsumedOutputCount() const {
95 return kind_ == kPushOutput ? GetPushCount() : 1;
96 }
97
98 bool operator==(OutputFrameStateCombine const& other) const {
99 return kind_ == other.kind_ && parameter_ == other.parameter_;
100 }
101 bool operator!=(OutputFrameStateCombine const& other) const {
102 return !(*this == other);
103 }
104
105 friend size_t hash_value(OutputFrameStateCombine const&);
106 friend std::ostream& operator<<(std::ostream&,
107 OutputFrameStateCombine const&);
108
109 private:
110 OutputFrameStateCombine(Kind kind, size_t parameter)
111 : kind_(kind), parameter_(parameter) {}
112
113 Kind const kind_;
114 size_t const parameter_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000115};
116
117
118// The type of stack frame that a FrameState node represents.
119enum FrameStateType {
120 JS_FRAME, // Represents an unoptimized JavaScriptFrame.
121 ARGUMENTS_ADAPTOR // Represents an ArgumentsAdaptorFrame.
122};
123
124
125class FrameStateCallInfo FINAL {
126 public:
127 FrameStateCallInfo(
128 FrameStateType type, BailoutId bailout_id,
129 OutputFrameStateCombine state_combine,
130 MaybeHandle<JSFunction> jsfunction = MaybeHandle<JSFunction>())
131 : type_(type),
132 bailout_id_(bailout_id),
133 frame_state_combine_(state_combine),
134 jsfunction_(jsfunction) {}
135
136 FrameStateType type() const { return type_; }
137 BailoutId bailout_id() const { return bailout_id_; }
138 OutputFrameStateCombine state_combine() const { return frame_state_combine_; }
139 MaybeHandle<JSFunction> jsfunction() const { return jsfunction_; }
140
141 private:
142 FrameStateType type_;
143 BailoutId bailout_id_;
144 OutputFrameStateCombine frame_state_combine_;
145 MaybeHandle<JSFunction> jsfunction_;
146};
147
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400148bool operator==(FrameStateCallInfo const&, FrameStateCallInfo const&);
149bool operator!=(FrameStateCallInfo const&, FrameStateCallInfo const&);
150
151size_t hash_value(FrameStateCallInfo const&);
152
153std::ostream& operator<<(std::ostream&, FrameStateCallInfo const&);
154
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000155
156// Interface for building common operators that can be used at any level of IR,
157// including JavaScript, mid-level, and low-level.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400158class CommonOperatorBuilder FINAL : public ZoneObject {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000159 public:
160 explicit CommonOperatorBuilder(Zone* zone);
161
162 const Operator* Dead();
163 const Operator* End();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400164 const Operator* Branch(BranchHint = BranchHint::kNone);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000165 const Operator* IfTrue();
166 const Operator* IfFalse();
167 const Operator* Throw();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400168 const Operator* Terminate(int effects);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000169 const Operator* Return();
170
171 const Operator* Start(int num_formal_parameters);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400172 const Operator* Loop(int control_input_count);
173 const Operator* Merge(int control_input_count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000174 const Operator* Parameter(int index);
175
176 const Operator* Int32Constant(int32_t);
177 const Operator* Int64Constant(int64_t);
178 const Operator* Float32Constant(volatile float);
179 const Operator* Float64Constant(volatile double);
180 const Operator* ExternalConstant(const ExternalReference&);
181 const Operator* NumberConstant(volatile double);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400182 const Operator* HeapConstant(const Unique<HeapObject>&);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000183
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400184 const Operator* Select(MachineType, BranchHint = BranchHint::kNone);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000185 const Operator* Phi(MachineType type, int arguments);
186 const Operator* EffectPhi(int arguments);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000187 const Operator* ValueEffect(int arguments);
188 const Operator* Finish(int arguments);
189 const Operator* StateValues(int arguments);
190 const Operator* FrameState(
191 FrameStateType type, BailoutId bailout_id,
192 OutputFrameStateCombine state_combine,
193 MaybeHandle<JSFunction> jsfunction = MaybeHandle<JSFunction>());
194 const Operator* Call(const CallDescriptor* descriptor);
195 const Operator* Projection(size_t index);
196
197 private:
198 Zone* zone() const { return zone_; }
199
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400200 const CommonOperatorGlobalCache& cache_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000201 Zone* const zone_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400202
203 DISALLOW_COPY_AND_ASSIGN(CommonOperatorBuilder);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000204};
205
206} // namespace compiler
207} // namespace internal
208} // namespace v8
209
210#endif // V8_COMPILER_COMMON_OPERATOR_H_