Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: src/compiler/js-operator.cc

Issue 613683002: [turbofan] Some javascript operators are globally shared singletons. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/js-operator.h ('k') | src/compiler/js-operator-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // 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 #include "src/compiler/js-operator.h"
6
7 #include <limits>
8
9 #include "src/base/lazy-instance.h"
10 #include "src/compiler/opcodes.h"
11 #include "src/compiler/operator.h"
12
13 namespace v8 {
14 namespace internal {
15 namespace compiler {
16
17 const CallFunctionParameters& CallFunctionParametersOf(const Operator* op) {
18 DCHECK_EQ(IrOpcode::kJSCallFunction, op->opcode());
19 return OpParameter<CallFunctionParameters>(op);
20 }
21
22
23 const CallRuntimeParameters& CallRuntimeParametersOf(const Operator* op) {
24 DCHECK_EQ(IrOpcode::kJSCallRuntime, op->opcode());
25 return OpParameter<CallRuntimeParameters>(op);
26 }
27
28
29 ContextAccess::ContextAccess(size_t depth, size_t index, bool immutable)
30 : immutable_(immutable),
31 depth_(static_cast<uint16_t>(depth)),
32 index_(static_cast<uint32_t>(index)) {
33 DCHECK(depth <= std::numeric_limits<uint16_t>::max());
34 DCHECK(index <= std::numeric_limits<uint32_t>::max());
35 }
36
37
38 bool operator==(const ContextAccess& lhs, const ContextAccess& rhs) {
39 return lhs.depth() == rhs.depth() && lhs.index() == rhs.index() &&
40 lhs.immutable() == rhs.immutable();
41 }
42
43
44 bool operator!=(const ContextAccess& lhs, const ContextAccess& rhs) {
45 return !(lhs == rhs);
46 }
47
48
49 const ContextAccess& ContextAccessOf(const Operator* op) {
50 DCHECK(op->opcode() == IrOpcode::kJSLoadContext ||
51 op->opcode() == IrOpcode::kJSStoreContext);
52 return OpParameter<ContextAccess>(op);
53 }
54
55
56 const LoadNamedParameters& LoadNamedParametersOf(const Operator* op) {
57 DCHECK_EQ(IrOpcode::kJSLoadNamed, op->opcode());
58 return OpParameter<LoadNamedParameters>(op);
59 }
60
61
62 const StoreNamedParameters& StoreNamedParametersOf(const Operator* op) {
63 DCHECK_EQ(IrOpcode::kJSStoreNamed, op->opcode());
64 return OpParameter<StoreNamedParameters>(op);
65 }
66
67
68 // Specialization for static parameters of type {ContextAccess}.
69 template <>
70 struct StaticParameterTraits<ContextAccess> {
71 static std::ostream& PrintTo(std::ostream& os, const ContextAccess& access) {
72 return os << access.depth() << "," << access.index()
73 << (access.immutable() ? ",imm" : "");
74 }
75 static int HashCode(const ContextAccess& access) {
76 return static_cast<int>((access.depth() << 16) | (access.index() & 0xffff));
77 }
78 static bool Equals(const ContextAccess& lhs, const ContextAccess& rhs) {
79 return lhs == rhs;
80 }
81 };
82
83
84 // Specialization for static parameters of type {Runtime::FunctionId}.
85 template <>
86 struct StaticParameterTraits<Runtime::FunctionId> {
87 static std::ostream& PrintTo(std::ostream& os, Runtime::FunctionId val) {
88 const Runtime::Function* f = Runtime::FunctionForId(val);
89 return os << (f->name ? f->name : "?Runtime?");
90 }
91 static int HashCode(Runtime::FunctionId val) { return static_cast<int>(val); }
92 static bool Equals(Runtime::FunctionId a, Runtime::FunctionId b) {
93 return a == b;
94 }
95 };
96
97
98 #define SHARED_OP_LIST(V) \
99 V(Equal, Operator::kNoProperties, 2, 1) \
100 V(NotEqual, Operator::kNoProperties, 2, 1) \
101 V(StrictEqual, Operator::kPure, 2, 1) \
102 V(StrictNotEqual, Operator::kPure, 2, 1) \
103 V(LessThan, Operator::kNoProperties, 2, 1) \
104 V(GreaterThan, Operator::kNoProperties, 2, 1) \
105 V(LessThanOrEqual, Operator::kNoProperties, 2, 1) \
106 V(GreaterThanOrEqual, Operator::kNoProperties, 2, 1) \
107 V(BitwiseOr, Operator::kNoProperties, 2, 1) \
108 V(BitwiseXor, Operator::kNoProperties, 2, 1) \
109 V(BitwiseAnd, Operator::kNoProperties, 2, 1) \
110 V(ShiftLeft, Operator::kNoProperties, 2, 1) \
111 V(ShiftRight, Operator::kNoProperties, 2, 1) \
112 V(ShiftRightLogical, Operator::kNoProperties, 2, 1) \
113 V(Add, Operator::kNoProperties, 2, 1) \
114 V(Subtract, Operator::kNoProperties, 2, 1) \
115 V(Multiply, Operator::kNoProperties, 2, 1) \
116 V(Divide, Operator::kNoProperties, 2, 1) \
117 V(Modulus, Operator::kNoProperties, 2, 1) \
118 V(UnaryNot, Operator::kNoProperties, 1, 1) \
119 V(ToBoolean, Operator::kNoProperties, 1, 1) \
120 V(ToNumber, Operator::kNoProperties, 1, 1) \
121 V(ToString, Operator::kNoProperties, 1, 1) \
122 V(ToName, Operator::kNoProperties, 1, 1) \
123 V(ToObject, Operator::kNoProperties, 1, 1) \
124 V(Yield, Operator::kNoProperties, 1, 1) \
125 V(Create, Operator::kEliminatable, 0, 1) \
126 V(LoadProperty, Operator::kNoProperties, 2, 1) \
127 V(HasProperty, Operator::kNoProperties, 2, 1) \
128 V(TypeOf, Operator::kPure, 1, 1) \
129 V(InstanceOf, Operator::kNoProperties, 2, 1) \
130 V(Debugger, Operator::kNoProperties, 0, 0) \
131 V(CreateFunctionContext, Operator::kNoProperties, 1, 1) \
132 V(CreateWithContext, Operator::kNoProperties, 2, 1) \
133 V(CreateBlockContext, Operator::kNoProperties, 2, 1) \
134 V(CreateModuleContext, Operator::kNoProperties, 2, 1) \
135 V(CreateGlobalContext, Operator::kNoProperties, 2, 1)
136
137
138 struct JSOperatorBuilderImpl FINAL {
139 #define SHARED(Name, properties, value_input_count, value_output_count) \
140 struct Name##Operator FINAL : public SimpleOperator { \
141 Name##Operator() \
142 : SimpleOperator(IrOpcode::kJS##Name, properties, value_input_count, \
143 value_output_count, "JS" #Name) {} \
144 }; \
145 Name##Operator k##Name##Operator;
146 SHARED_OP_LIST(SHARED)
147 #undef SHARED
148 };
149
150
151 static base::LazyInstance<JSOperatorBuilderImpl>::type kImpl =
152 LAZY_INSTANCE_INITIALIZER;
153
154
155 JSOperatorBuilder::JSOperatorBuilder(Zone* zone)
156 : impl_(kImpl.Get()), zone_(zone) {}
157
158
159 #define SHARED(Name, properties, value_input_count, value_output_count) \
160 const Operator* JSOperatorBuilder::Name() { return &impl_.k##Name##Operator; }
161 SHARED_OP_LIST(SHARED)
162 #undef SHARED
163
164
165 const Operator* JSOperatorBuilder::CallFunction(size_t arity,
166 CallFunctionFlags flags) {
167 CallFunctionParameters parameters(arity, flags);
168 return new (zone()) Operator1<CallFunctionParameters>(
169 IrOpcode::kJSCallFunction, Operator::kNoProperties,
170 static_cast<int>(parameters.arity()), 1, "JSCallFunction", parameters);
171 }
172
173
174 const Operator* JSOperatorBuilder::CallRuntime(Runtime::FunctionId id,
175 size_t arity) {
176 CallRuntimeParameters parameters(id, arity);
177 const Runtime::Function* f = Runtime::FunctionForId(parameters.id());
178 int arguments = static_cast<int>(parameters.arity());
179 DCHECK(f->nargs == -1 || f->nargs == arguments);
180 return new (zone()) Operator1<CallRuntimeParameters>(
181 IrOpcode::kJSCallRuntime, Operator::kNoProperties, arguments,
182 f->result_size, "JSCallRuntime", parameters);
183 }
184
185
186 const Operator* JSOperatorBuilder::CallConstruct(int arguments) {
187 return new (zone())
188 Operator1<int>(IrOpcode::kJSCallConstruct, Operator::kNoProperties,
189 arguments, 1, "JSCallConstruct", arguments);
190 }
191
192
193 const Operator* JSOperatorBuilder::LoadNamed(const Unique<Name>& name,
194 ContextualMode contextual_mode) {
195 LoadNamedParameters parameters(name, contextual_mode);
196 return new (zone()) Operator1<LoadNamedParameters>(
197 IrOpcode::kJSLoadNamed, Operator::kNoProperties, 1, 1, "JSLoadNamed",
198 parameters);
199 }
200
201
202 const Operator* JSOperatorBuilder::StoreProperty(StrictMode strict_mode) {
203 return new (zone())
204 Operator1<StrictMode>(IrOpcode::kJSStoreProperty, Operator::kNoProperties,
205 3, 0, "JSStoreProperty", strict_mode);
206 }
207
208
209 const Operator* JSOperatorBuilder::StoreNamed(StrictMode strict_mode,
210 const Unique<Name>& name) {
211 StoreNamedParameters parameters(strict_mode, name);
212 return new (zone()) Operator1<StoreNamedParameters>(
213 IrOpcode::kJSStoreNamed, Operator::kNoProperties, 2, 0, "JSStoreNamed",
214 parameters);
215 }
216
217
218 const Operator* JSOperatorBuilder::DeleteProperty(StrictMode strict_mode) {
219 return new (zone()) Operator1<StrictMode>(IrOpcode::kJSDeleteProperty,
220 Operator::kNoProperties, 2, 1,
221 "JSDeleteProperty", strict_mode);
222 }
223
224
225 const Operator* JSOperatorBuilder::LoadContext(size_t depth, size_t index,
226 bool immutable) {
227 ContextAccess access(depth, index, immutable);
228 return new (zone()) Operator1<ContextAccess>(
229 IrOpcode::kJSLoadContext, Operator::kEliminatable | Operator::kNoWrite, 1,
230 1, "JSLoadContext", access);
231 }
232
233
234 const Operator* JSOperatorBuilder::StoreContext(size_t depth, size_t index) {
235 ContextAccess access(depth, index, false);
236 return new (zone()) Operator1<ContextAccess>(IrOpcode::kJSStoreContext,
237 Operator::kNoProperties, 2, 0,
238 "JSStoreContext", access);
239 }
240
241
242 const Operator* JSOperatorBuilder::CreateCatchContext(
243 const Unique<String>& name) {
244 return new (zone()) Operator1<Unique<String> >(
245 IrOpcode::kJSCreateCatchContext, Operator::kNoProperties, 1, 1,
246 "JSCreateCatchContext", name);
247 }
248
249 } // namespace compiler
250 } // namespace internal
251 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-operator.h ('k') | src/compiler/js-operator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698