blob: e716a8eeaae5bcc4364ee36d4c8fc5fb42820bf5 [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_JS_OPERATOR_H_
6#define V8_COMPILER_JS_OPERATOR_H_
7
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008#include "src/runtime/runtime.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/unique.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010
11namespace v8 {
12namespace internal {
13namespace compiler {
14
Emily Bernierd0a1eb72015-03-24 16:35:39 -040015// Forward declarations.
16class Operator;
17struct JSOperatorGlobalCache;
18
19
20// Defines the arity and the call flags for a JavaScript function call. This is
21// used as a parameter by JSCallFunction operators.
22class CallFunctionParameters FINAL {
23 public:
24 CallFunctionParameters(size_t arity, CallFunctionFlags flags)
25 : arity_(arity), flags_(flags) {}
26
27 size_t arity() const { return arity_; }
28 CallFunctionFlags flags() const { return flags_; }
29
30 private:
31 const size_t arity_;
32 const CallFunctionFlags flags_;
33};
34
35bool operator==(CallFunctionParameters const&, CallFunctionParameters const&);
36bool operator!=(CallFunctionParameters const&, CallFunctionParameters const&);
37
38size_t hash_value(CallFunctionParameters const&);
39
40std::ostream& operator<<(std::ostream&, CallFunctionParameters const&);
41
42const CallFunctionParameters& CallFunctionParametersOf(const Operator* op);
43
44
45// Defines the arity and the ID for a runtime function call. This is used as a
46// parameter by JSCallRuntime operators.
47class CallRuntimeParameters FINAL {
48 public:
49 CallRuntimeParameters(Runtime::FunctionId id, size_t arity)
50 : id_(id), arity_(arity) {}
51
52 Runtime::FunctionId id() const { return id_; }
53 size_t arity() const { return arity_; }
54
55 private:
56 const Runtime::FunctionId id_;
57 const size_t arity_;
58};
59
60bool operator==(CallRuntimeParameters const&, CallRuntimeParameters const&);
61bool operator!=(CallRuntimeParameters const&, CallRuntimeParameters const&);
62
63size_t hash_value(CallRuntimeParameters const&);
64
65std::ostream& operator<<(std::ostream&, CallRuntimeParameters const&);
66
67const CallRuntimeParameters& CallRuntimeParametersOf(const Operator* op);
68
69
Ben Murdochb8a8cc12014-11-26 15:28:44 +000070// Defines the location of a context slot relative to a specific scope. This is
71// used as a parameter by JSLoadContext and JSStoreContext operators and allows
72// accessing a context-allocated variable without keeping track of the scope.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040073class ContextAccess FINAL {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000074 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -040075 ContextAccess(size_t depth, size_t index, bool immutable);
76
77 size_t depth() const { return depth_; }
78 size_t index() const { return index_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079 bool immutable() const { return immutable_; }
80
81 private:
82 // For space reasons, we keep this tightly packed, otherwise we could just use
83 // a simple int/int/bool POD.
84 const bool immutable_;
85 const uint16_t depth_;
86 const uint32_t index_;
87};
88
Emily Bernierd0a1eb72015-03-24 16:35:39 -040089bool operator==(ContextAccess const&, ContextAccess const&);
90bool operator!=(ContextAccess const&, ContextAccess const&);
91
92size_t hash_value(ContextAccess const&);
93
94std::ostream& operator<<(std::ostream&, ContextAccess const&);
95
96ContextAccess const& ContextAccessOf(Operator const*);
97
98
99class VectorSlotPair {
100 public:
101 VectorSlotPair(Handle<TypeFeedbackVector> vector, FeedbackVectorICSlot slot)
102 : vector_(vector), slot_(slot) {}
103
104 Handle<TypeFeedbackVector> vector() const { return vector_; }
105 FeedbackVectorICSlot slot() const { return slot_; }
106
107 int index() const { return vector_->GetIndex(slot_); }
108
109 private:
110 const Handle<TypeFeedbackVector> vector_;
111 const FeedbackVectorICSlot slot_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000112};
113
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400114
115bool operator==(VectorSlotPair const& lhs, VectorSlotPair const& rhs);
116
117
118// Defines the property being loaded from an object by a named load. This is
119// used as a parameter by JSLoadNamed operators.
120class LoadNamedParameters FINAL {
121 public:
122 LoadNamedParameters(const Unique<Name>& name, const VectorSlotPair& feedback,
123 ContextualMode contextual_mode)
124 : name_(name), contextual_mode_(contextual_mode), feedback_(feedback) {}
125
126 const Unique<Name>& name() const { return name_; }
127 ContextualMode contextual_mode() const { return contextual_mode_; }
128
129 const VectorSlotPair& feedback() const { return feedback_; }
130
131 private:
132 const Unique<Name> name_;
133 const ContextualMode contextual_mode_;
134 const VectorSlotPair feedback_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000135};
136
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400137bool operator==(LoadNamedParameters const&, LoadNamedParameters const&);
138bool operator!=(LoadNamedParameters const&, LoadNamedParameters const&);
139
140size_t hash_value(LoadNamedParameters const&);
141
142std::ostream& operator<<(std::ostream&, LoadNamedParameters const&);
143
144const LoadNamedParameters& LoadNamedParametersOf(const Operator* op);
145
146
147// Defines the property being loaded from an object. This is
148// used as a parameter by JSLoadProperty operators.
149class LoadPropertyParameters FINAL {
150 public:
151 explicit LoadPropertyParameters(const VectorSlotPair& feedback)
152 : feedback_(feedback) {}
153
154 const VectorSlotPair& feedback() const { return feedback_; }
155
156 private:
157 const VectorSlotPair feedback_;
158};
159
160bool operator==(LoadPropertyParameters const&, LoadPropertyParameters const&);
161bool operator!=(LoadPropertyParameters const&, LoadPropertyParameters const&);
162
163size_t hash_value(LoadPropertyParameters const&);
164
165std::ostream& operator<<(std::ostream&, LoadPropertyParameters const&);
166
167const LoadPropertyParameters& LoadPropertyParametersOf(const Operator* op);
168
169
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000170// Defines the property being stored to an object by a named store. This is
171// used as a parameter by JSStoreNamed operators.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400172class StoreNamedParameters FINAL {
173 public:
174 StoreNamedParameters(StrictMode strict_mode, const Unique<Name>& name)
175 : strict_mode_(strict_mode), name_(name) {}
176
177 StrictMode strict_mode() const { return strict_mode_; }
178 const Unique<Name>& name() const { return name_; }
179
180 private:
181 const StrictMode strict_mode_;
182 const Unique<Name> name_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000183};
184
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400185bool operator==(StoreNamedParameters const&, StoreNamedParameters const&);
186bool operator!=(StoreNamedParameters const&, StoreNamedParameters const&);
187
188size_t hash_value(StoreNamedParameters const&);
189
190std::ostream& operator<<(std::ostream&, StoreNamedParameters const&);
191
192const StoreNamedParameters& StoreNamedParametersOf(const Operator* op);
193
194
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000195// Interface for building JavaScript-level operators, e.g. directly from the
196// AST. Most operators have no parameters, thus can be globally shared for all
197// graphs.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400198class JSOperatorBuilder FINAL : public ZoneObject {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000199 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400200 explicit JSOperatorBuilder(Zone* zone);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000201
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400202 const Operator* Equal();
203 const Operator* NotEqual();
204 const Operator* StrictEqual();
205 const Operator* StrictNotEqual();
206 const Operator* LessThan();
207 const Operator* GreaterThan();
208 const Operator* LessThanOrEqual();
209 const Operator* GreaterThanOrEqual();
210 const Operator* BitwiseOr();
211 const Operator* BitwiseXor();
212 const Operator* BitwiseAnd();
213 const Operator* ShiftLeft();
214 const Operator* ShiftRight();
215 const Operator* ShiftRightLogical();
216 const Operator* Add();
217 const Operator* Subtract();
218 const Operator* Multiply();
219 const Operator* Divide();
220 const Operator* Modulus();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000221
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400222 const Operator* UnaryNot();
223 const Operator* ToBoolean();
224 const Operator* ToNumber();
225 const Operator* ToString();
226 const Operator* ToName();
227 const Operator* ToObject();
228 const Operator* Yield();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000229
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400230 const Operator* Create();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000231
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400232 const Operator* CallFunction(size_t arity, CallFunctionFlags flags);
233 const Operator* CallRuntime(Runtime::FunctionId id, size_t arity);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000234
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400235 const Operator* CallConstruct(int arguments);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000236
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400237 const Operator* LoadProperty(const VectorSlotPair& feedback);
238 const Operator* LoadNamed(const Unique<Name>& name,
239 const VectorSlotPair& feedback,
240 ContextualMode contextual_mode = NOT_CONTEXTUAL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000241
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400242 const Operator* StoreProperty(StrictMode strict_mode);
243 const Operator* StoreNamed(StrictMode strict_mode, const Unique<Name>& name);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000244
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400245 const Operator* DeleteProperty(StrictMode strict_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000246
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400247 const Operator* HasProperty();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000248
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400249 const Operator* LoadContext(size_t depth, size_t index, bool immutable);
250 const Operator* StoreContext(size_t depth, size_t index);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000251
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400252 const Operator* TypeOf();
253 const Operator* InstanceOf();
254 const Operator* Debugger();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000255
256 // TODO(titzer): nail down the static parts of each of these context flavors.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400257 const Operator* CreateFunctionContext();
258 const Operator* CreateCatchContext(const Unique<String>& name);
259 const Operator* CreateWithContext();
260 const Operator* CreateBlockContext();
261 const Operator* CreateModuleContext();
262 const Operator* CreateScriptContext();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000263
264 private:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400265 Zone* zone() const { return zone_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000266
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400267 const JSOperatorGlobalCache& cache_;
268 Zone* const zone_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000269
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400270 DISALLOW_COPY_AND_ASSIGN(JSOperatorBuilder);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000271};
272
273} // namespace compiler
274} // namespace internal
275} // namespace v8
276
277#endif // V8_COMPILER_JS_OPERATOR_H_