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

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

Issue 1092353002: [strong] Disallow implicit conversions for binary arithmetic operations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cl feedback 5 Created 5 years, 8 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/js-operator.h" 5 #include "src/compiler/js-operator.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "src/base/lazy-instance.h" 9 #include "src/base/lazy-instance.h"
10 #include "src/compiler/opcodes.h" 10 #include "src/compiler/opcodes.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 DCHECK_EQ(IrOpcode::kJSStoreNamed, op->opcode()); 206 DCHECK_EQ(IrOpcode::kJSStoreNamed, op->opcode());
207 return OpParameter<StoreNamedParameters>(op); 207 return OpParameter<StoreNamedParameters>(op);
208 } 208 }
209 209
210 210
211 #define CACHED_OP_LIST(V) \ 211 #define CACHED_OP_LIST(V) \
212 V(Equal, Operator::kNoProperties, 2, 1) \ 212 V(Equal, Operator::kNoProperties, 2, 1) \
213 V(NotEqual, Operator::kNoProperties, 2, 1) \ 213 V(NotEqual, Operator::kNoProperties, 2, 1) \
214 V(StrictEqual, Operator::kPure, 2, 1) \ 214 V(StrictEqual, Operator::kPure, 2, 1) \
215 V(StrictNotEqual, Operator::kPure, 2, 1) \ 215 V(StrictNotEqual, Operator::kPure, 2, 1) \
216 V(LessThan, Operator::kNoProperties, 2, 1) \
217 V(GreaterThan, Operator::kNoProperties, 2, 1) \
218 V(LessThanOrEqual, Operator::kNoProperties, 2, 1) \
219 V(GreaterThanOrEqual, Operator::kNoProperties, 2, 1) \
220 V(BitwiseOr, Operator::kNoProperties, 2, 1) \
221 V(BitwiseXor, Operator::kNoProperties, 2, 1) \
222 V(BitwiseAnd, Operator::kNoProperties, 2, 1) \
223 V(ShiftLeft, Operator::kNoProperties, 2, 1) \
224 V(ShiftRight, Operator::kNoProperties, 2, 1) \
225 V(ShiftRightLogical, Operator::kNoProperties, 2, 1) \
226 V(Add, Operator::kNoProperties, 2, 1) \
227 V(Subtract, Operator::kNoProperties, 2, 1) \
228 V(Multiply, Operator::kNoProperties, 2, 1) \
229 V(Divide, Operator::kNoProperties, 2, 1) \
230 V(Modulus, Operator::kNoProperties, 2, 1) \
231 V(UnaryNot, Operator::kPure, 1, 1) \ 216 V(UnaryNot, Operator::kPure, 1, 1) \
232 V(ToBoolean, Operator::kPure, 1, 1) \ 217 V(ToBoolean, Operator::kPure, 1, 1) \
233 V(ToNumber, Operator::kNoProperties, 1, 1) \ 218 V(ToNumber, Operator::kNoProperties, 1, 1) \
234 V(ToString, Operator::kNoProperties, 1, 1) \ 219 V(ToString, Operator::kNoProperties, 1, 1) \
235 V(ToName, Operator::kNoProperties, 1, 1) \ 220 V(ToName, Operator::kNoProperties, 1, 1) \
236 V(ToObject, Operator::kNoProperties, 1, 1) \ 221 V(ToObject, Operator::kNoProperties, 1, 1) \
237 V(Yield, Operator::kNoProperties, 1, 1) \ 222 V(Yield, Operator::kNoProperties, 1, 1) \
238 V(Create, Operator::kEliminatable, 0, 1) \ 223 V(Create, Operator::kEliminatable, 0, 1) \
239 V(HasProperty, Operator::kNoProperties, 2, 1) \ 224 V(HasProperty, Operator::kNoProperties, 2, 1) \
240 V(TypeOf, Operator::kPure, 1, 1) \ 225 V(TypeOf, Operator::kPure, 1, 1) \
241 V(InstanceOf, Operator::kNoProperties, 2, 1) \ 226 V(InstanceOf, Operator::kNoProperties, 2, 1) \
242 V(StackCheck, Operator::kNoProperties, 0, 0) \ 227 V(StackCheck, Operator::kNoProperties, 0, 0) \
243 V(CreateFunctionContext, Operator::kNoProperties, 1, 1) \ 228 V(CreateFunctionContext, Operator::kNoProperties, 1, 1) \
244 V(CreateWithContext, Operator::kNoProperties, 2, 1) \ 229 V(CreateWithContext, Operator::kNoProperties, 2, 1) \
245 V(CreateBlockContext, Operator::kNoProperties, 2, 1) \ 230 V(CreateBlockContext, Operator::kNoProperties, 2, 1) \
246 V(CreateModuleContext, Operator::kNoProperties, 2, 1) \ 231 V(CreateModuleContext, Operator::kNoProperties, 2, 1) \
247 V(CreateScriptContext, Operator::kNoProperties, 2, 1) 232 V(CreateScriptContext, Operator::kNoProperties, 2, 1)
248 233
249 234
235 #define CACHED_OP_LIST_WITH_LANGUAGE_MODE(V) \
236 V(LessThan, Operator::kNoProperties, 2, 1) \
237 V(GreaterThan, Operator::kNoProperties, 2, 1) \
238 V(LessThanOrEqual, Operator::kNoProperties, 2, 1) \
239 V(GreaterThanOrEqual, Operator::kNoProperties, 2, 1) \
240 V(BitwiseOr, Operator::kNoProperties, 2, 1) \
241 V(BitwiseXor, Operator::kNoProperties, 2, 1) \
242 V(BitwiseAnd, Operator::kNoProperties, 2, 1) \
243 V(ShiftLeft, Operator::kNoProperties, 2, 1) \
244 V(ShiftRight, Operator::kNoProperties, 2, 1) \
245 V(ShiftRightLogical, Operator::kNoProperties, 2, 1) \
246 V(Add, Operator::kNoProperties, 2, 1) \
247 V(Subtract, Operator::kNoProperties, 2, 1) \
248 V(Multiply, Operator::kNoProperties, 2, 1) \
249 V(Divide, Operator::kNoProperties, 2, 1) \
250 V(Modulus, Operator::kNoProperties, 2, 1)
251
252
250 struct JSOperatorGlobalCache final { 253 struct JSOperatorGlobalCache final {
251 #define CACHED(Name, properties, value_input_count, value_output_count) \ 254 #define CACHED(Name, properties, value_input_count, value_output_count) \
252 struct Name##Operator final : public Operator { \ 255 struct Name##Operator final : public Operator { \
253 Name##Operator() \ 256 Name##Operator() \
254 : Operator(IrOpcode::kJS##Name, properties, "JS" #Name, \ 257 : Operator(IrOpcode::kJS##Name, properties, "JS" #Name, \
255 value_input_count, Operator::ZeroIfPure(properties), \ 258 value_input_count, Operator::ZeroIfPure(properties), \
256 Operator::ZeroIfEliminatable(properties), \ 259 Operator::ZeroIfEliminatable(properties), \
257 value_output_count, Operator::ZeroIfPure(properties), \ 260 value_output_count, Operator::ZeroIfPure(properties), \
258 Operator::ZeroIfNoThrow(properties)) {} \ 261 Operator::ZeroIfNoThrow(properties)) {} \
259 }; \ 262 }; \
260 Name##Operator k##Name##Operator; 263 Name##Operator k##Name##Operator;
261 CACHED_OP_LIST(CACHED) 264 CACHED_OP_LIST(CACHED)
262 #undef CACHED 265 #undef CACHED
263 266
267
268 #define CACHED_WITH_STRONG(Name, properties, value_input_count, \
269 value_output_count) \
270 template <LanguageMode kLanguageMode> \
271 struct Name##Operator final : public Operator1<LanguageMode> { \
272 Name##Operator() \
273 : Operator1<LanguageMode>(IrOpcode::kJS##Name, properties, "JS" #Name, \
274 value_input_count, Operator::ZeroIfPure(properties), \
275 Operator::ZeroIfEliminatable(properties), \
276 value_output_count, Operator::ZeroIfPure(properties), \
277 Operator::ZeroIfNoThrow(properties), kLanguageMode) {} \
278 }; \
279 Name##Operator<SLOPPY> k##Name##SloppyOperator; \
280 Name##Operator<STRONG> k##Name##StrongOperator;
281 CACHED_OP_LIST_WITH_LANGUAGE_MODE(CACHED_WITH_STRONG)
282 #undef CACHED_WITH_STRONG
283
284
264 template <LanguageMode kLanguageMode> 285 template <LanguageMode kLanguageMode>
265 struct StorePropertyOperator final : public Operator1<LanguageMode> { 286 struct StorePropertyOperator final : public Operator1<LanguageMode> {
266 StorePropertyOperator() 287 StorePropertyOperator()
267 : Operator1<LanguageMode>(IrOpcode::kJSStoreProperty, 288 : Operator1<LanguageMode>(IrOpcode::kJSStoreProperty,
268 Operator::kNoProperties, "JSStoreProperty", 3, 289 Operator::kNoProperties, "JSStoreProperty", 3,
269 1, 1, 0, 1, 2, kLanguageMode) {} 290 1, 1, 0, 1, 2, kLanguageMode) {}
270 }; 291 };
271 StorePropertyOperator<SLOPPY> kStorePropertySloppyOperator; 292 StorePropertyOperator<SLOPPY> kStorePropertySloppyOperator;
272 StorePropertyOperator<STRICT> kStorePropertyStrictOperator; 293 StorePropertyOperator<STRICT> kStorePropertyStrictOperator;
273 }; 294 };
274 295
275 296
276 static base::LazyInstance<JSOperatorGlobalCache>::type kCache = 297 static base::LazyInstance<JSOperatorGlobalCache>::type kCache =
277 LAZY_INSTANCE_INITIALIZER; 298 LAZY_INSTANCE_INITIALIZER;
278 299
279 300
280 JSOperatorBuilder::JSOperatorBuilder(Zone* zone) 301 JSOperatorBuilder::JSOperatorBuilder(Zone* zone)
281 : cache_(kCache.Get()), zone_(zone) {} 302 : cache_(kCache.Get()), zone_(zone) {}
282 303
283 304
284 #define CACHED(Name, properties, value_input_count, value_output_count) \ 305 #define CACHED(Name, properties, value_input_count, value_output_count) \
285 const Operator* JSOperatorBuilder::Name() { \ 306 const Operator* JSOperatorBuilder::Name() { \
286 return &cache_.k##Name##Operator; \ 307 return &cache_.k##Name##Operator; \
287 } 308 }
288 CACHED_OP_LIST(CACHED) 309 CACHED_OP_LIST(CACHED)
289 #undef CACHED 310 #undef CACHED
290 311
291 312
313 #define CACHED_WITH_STRONG(Name, properties, value_input_count, \
314 value_output_count) \
315 const Operator* JSOperatorBuilder::Name(LanguageMode language_mode) { \
316 if (is_strong(language_mode)) { \
317 return &cache_.k##Name##StrongOperator; \
318 } else { \
319 return &cache_.k##Name##SloppyOperator; \
320 } \
321 UNREACHABLE(); \
322 return nullptr; \
323 }
324 CACHED_OP_LIST_WITH_LANGUAGE_MODE(CACHED_WITH_STRONG)
325 #undef CACHED_WITH_STRONG
326
327
292 const Operator* JSOperatorBuilder::CallFunction(size_t arity, 328 const Operator* JSOperatorBuilder::CallFunction(size_t arity,
293 CallFunctionFlags flags) { 329 CallFunctionFlags flags) {
294 CallFunctionParameters parameters(arity, flags); 330 CallFunctionParameters parameters(arity, flags);
295 return new (zone()) Operator1<CallFunctionParameters>( // -- 331 return new (zone()) Operator1<CallFunctionParameters>( // --
296 IrOpcode::kJSCallFunction, Operator::kNoProperties, // opcode 332 IrOpcode::kJSCallFunction, Operator::kNoProperties, // opcode
297 "JSCallFunction", // name 333 "JSCallFunction", // name
298 parameters.arity(), 1, 1, 1, 1, 2, // inputs/outputs 334 parameters.arity(), 1, 1, 1, 1, 2, // inputs/outputs
299 parameters); // parameter 335 parameters); // parameter
300 } 336 }
301 337
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 return new (zone()) Operator1<Unique<String>>( // -- 442 return new (zone()) Operator1<Unique<String>>( // --
407 IrOpcode::kJSCreateCatchContext, Operator::kNoProperties, // opcode 443 IrOpcode::kJSCreateCatchContext, Operator::kNoProperties, // opcode
408 "JSCreateCatchContext", // name 444 "JSCreateCatchContext", // name
409 2, 1, 1, 1, 1, 2, // counts 445 2, 1, 1, 1, 1, 2, // counts
410 name); // parameter 446 name); // parameter
411 } 447 }
412 448
413 } // namespace compiler 449 } // namespace compiler
414 } // namespace internal 450 } // namespace internal
415 } // namespace v8 451 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-operator.h ('k') | src/compiler/js-typed-lowering.cc » ('j') | src/ic/ic.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698