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

Side by Side Diff: src/code-stubs.cc

Issue 25571002: Revert "Hydrogenisation of binops" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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/code-stubs.h ('k') | src/code-stubs-hydrogen.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 131
132 Handle<Code> CodeStub::GetCode(Isolate* isolate) { 132 Handle<Code> CodeStub::GetCode(Isolate* isolate) {
133 Factory* factory = isolate->factory(); 133 Factory* factory = isolate->factory();
134 Heap* heap = isolate->heap(); 134 Heap* heap = isolate->heap();
135 Code* code; 135 Code* code;
136 if (UseSpecialCache() 136 if (UseSpecialCache()
137 ? FindCodeInSpecialCache(&code, isolate) 137 ? FindCodeInSpecialCache(&code, isolate)
138 : FindCodeInCache(&code, isolate)) { 138 : FindCodeInCache(&code, isolate)) {
139 ASSERT(IsPregenerated(isolate) == code->is_pregenerated()); 139 ASSERT(IsPregenerated(isolate) == code->is_pregenerated());
140 ASSERT(GetCodeKind() == code->kind());
141 return Handle<Code>(code); 140 return Handle<Code>(code);
142 } 141 }
143 142
144 { 143 {
145 HandleScope scope(isolate); 144 HandleScope scope(isolate);
146 145
147 Handle<Code> new_object = GenerateCode(isolate); 146 Handle<Code> new_object = GenerateCode(isolate);
148 new_object->set_major_key(MajorKey()); 147 new_object->set_major_key(MajorKey());
149 FinishCode(new_object); 148 FinishCode(new_object);
150 RecordCodeGeneration(*new_object, isolate); 149 RecordCodeGeneration(*new_object, isolate);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 stream->Add("%s", MajorName(MajorKey(), false)); 196 stream->Add("%s", MajorName(MajorKey(), false));
198 } 197 }
199 198
200 199
201 void CodeStub::PrintName(StringStream* stream) { 200 void CodeStub::PrintName(StringStream* stream) {
202 PrintBaseName(stream); 201 PrintBaseName(stream);
203 PrintState(stream); 202 PrintState(stream);
204 } 203 }
205 204
206 205
207 void BinaryOpStub::PrintBaseName(StringStream* stream) { 206 void BinaryOpStub::Generate(MacroAssembler* masm) {
208 const char* op_name = Token::Name(op_); 207 // Explicitly allow generation of nested stubs. It is safe here because
209 const char* ovr = ""; 208 // generation code does not use any raw pointers.
210 if (mode_ == OVERWRITE_LEFT) ovr = "_ReuseLeft"; 209 AllowStubCallsScope allow_stub_calls(masm, true);
211 if (mode_ == OVERWRITE_RIGHT) ovr = "_ReuseRight";
212 stream->Add("BinaryOpStub_%s%s", op_name, ovr);
213 }
214 210
215 211 BinaryOpIC::TypeInfo operands_type = Max(left_type_, right_type_);
216 void BinaryOpStub::PrintState(StringStream* stream) { 212 if (left_type_ == BinaryOpIC::ODDBALL && right_type_ == BinaryOpIC::ODDBALL) {
217 stream->Add("("); 213 // The OddballStub handles a number and an oddball, not two oddballs.
218 stream->Add(StateToName(left_state_)); 214 operands_type = BinaryOpIC::GENERIC;
219 if (left_bool_) {
220 stream->Add(",Boolean");
221 } 215 }
222 stream->Add("*"); 216 switch (operands_type) {
223 if (fixed_right_arg_.has_value) { 217 case BinaryOpIC::UNINITIALIZED:
224 stream->Add("%d", fixed_right_arg_.value); 218 GenerateTypeTransition(masm);
225 } else { 219 break;
226 stream->Add(StateToName(right_state_)); 220 case BinaryOpIC::SMI:
227 if (right_bool_) { 221 GenerateSmiStub(masm);
228 stream->Add(",Boolean"); 222 break;
229 } 223 case BinaryOpIC::INT32:
230 } 224 GenerateInt32Stub(masm);
231 stream->Add("->"); 225 break;
232 stream->Add(StateToName(result_state_)); 226 case BinaryOpIC::NUMBER:
233 stream->Add(")"); 227 GenerateNumberStub(masm);
234 } 228 break;
235 229 case BinaryOpIC::ODDBALL:
236 230 GenerateOddballStub(masm);
237 Maybe<Handle<Object> > BinaryOpStub::Result(Handle<Object> left, 231 break;
238 Handle<Object> right, 232 case BinaryOpIC::STRING:
239 Isolate* isolate) { 233 GenerateStringStub(masm);
240 Handle<JSBuiltinsObject> builtins(isolate->js_builtins_object()); 234 break;
241 Builtins::JavaScript func = BinaryOpIC::TokenToJSBuiltin(op_); 235 case BinaryOpIC::GENERIC:
242 Object* builtin = builtins->javascript_builtin(func); 236 GenerateGeneric(masm);
243 Handle<JSFunction> builtin_function = 237 break;
244 Handle<JSFunction>(JSFunction::cast(builtin), isolate); 238 default:
245 bool caught_exception; 239 UNREACHABLE();
246 Handle<Object> result = Execution::Call(isolate, builtin_function, left,
247 1, &right, &caught_exception);
248 return Maybe<Handle<Object> >(!caught_exception, result);
249 }
250
251
252 void BinaryOpStub::Initialize() {
253 fixed_right_arg_.has_value = false;
254 left_state_ = right_state_ = result_state_ = NONE;
255 left_bool_ = right_bool_ = false;
256 }
257
258
259 void BinaryOpStub::Generate(Token::Value op,
260 State left,
261 State right,
262 State result,
263 Isolate* isolate) {
264 BinaryOpStub stub(INITIALIZED);
265 stub.op_ = op;
266 stub.left_state_ = left;
267 stub.right_state_ = right;
268 stub.result_state_ = result;
269 stub.mode_ = NO_OVERWRITE;
270 stub.GetCode(isolate);
271 stub.mode_ = OVERWRITE_LEFT;
272 stub.GetCode(isolate);
273 }
274
275
276 void BinaryOpStub::GenerateAheadOfTime(Isolate* isolate) {
277 Token::Value binop[] = {Token::SUB, Token::MOD, Token::DIV, Token::MUL,
278 Token::ADD, Token::SAR, Token::BIT_OR, Token::BIT_AND,
279 Token::BIT_XOR, Token::SHL, Token::SHR};
280 // TODO(olivf) NumberTagU is not snapshot safe yet so we have to skip SHR
281 // since that produces a unsigned int32.
282 Token::Value bitop[] = {Token::BIT_OR, Token::BIT_AND, Token::BIT_XOR,
283 Token::SAR, Token::SHL /* Token::SHR */};
284 Token::Value arithop[] = {Token::ADD, Token::SUB, Token::MOD,
285 Token::DIV, Token::MUL};
286 for (unsigned i = 0; i < ARRAY_SIZE(binop); i++) {
287 BinaryOpStub stub(UNINITIALIZED);
288 stub.op_ = binop[i];
289 stub.GetCode(isolate);
290 }
291 for (unsigned i = 0; i < ARRAY_SIZE(arithop); i++) {
292 Generate(arithop[i], SMI, SMI, SMI, isolate);
293 Generate(arithop[i], SMI, SMI, INT32, isolate);
294 Generate(arithop[i], SMI, SMI, NUMBER, isolate);
295 Generate(arithop[i], INT32, INT32, INT32, isolate);
296 Generate(arithop[i], NUMBER, SMI, SMI, isolate);
297 Generate(arithop[i], NUMBER, SMI, NUMBER, isolate);
298 Generate(arithop[i], NUMBER, INT32, NUMBER, isolate);
299 Generate(arithop[i], NUMBER, NUMBER, NUMBER, isolate);
300 }
301 Generate(Token::SHR, SMI, SMI, SMI, isolate);
302 for (unsigned i = 0; i < ARRAY_SIZE(bitop); i++) {
303 Generate(bitop[i], SMI, SMI, SMI, isolate);
304 Generate(bitop[i], SMI, INT32, INT32, isolate);
305 Generate(bitop[i], INT32, INT32, INT32, isolate);
306 Generate(bitop[i], NUMBER, INT32, INT32, isolate);
307 Generate(bitop[i], NUMBER, NUMBER, INT32, isolate);
308 }
309 Generate(Token::ADD, STRING, STRING, STRING, isolate);
310
311 BinaryOpStub stub(INITIALIZED);
312 stub.op_ = Token::MOD;
313 stub.left_state_ = SMI;
314 stub.right_state_ = SMI;
315 stub.result_state_ = SMI;
316 stub.fixed_right_arg_.has_value = true;
317 stub.fixed_right_arg_.value = 4;
318 stub.mode_ = NO_OVERWRITE;
319 stub.GetCode(isolate);
320 stub.fixed_right_arg_.value = 8;
321 stub.GetCode(isolate);
322 }
323
324
325 bool BinaryOpStub::can_encode_arg_value(int32_t value) const {
326 return op_ == Token::MOD && value > 0 && IsPowerOf2(value) &&
327 FixedRightArgValueBits::is_valid(WhichPowerOf2(value));
328 }
329
330
331 int BinaryOpStub::encode_arg_value(int32_t value) const {
332 ASSERT(can_encode_arg_value(value));
333 return WhichPowerOf2(value);
334 }
335
336
337 int32_t BinaryOpStub::decode_arg_value(int value) const {
338 return 1 << value;
339 }
340
341
342 int BinaryOpStub::encode_token(Token::Value op) const {
343 ASSERT(op >= FIRST_TOKEN && op <= LAST_TOKEN);
344 return op - FIRST_TOKEN;
345 }
346
347
348 Token::Value BinaryOpStub::decode_token(int op) const {
349 int res = op + FIRST_TOKEN;
350 ASSERT(res >= FIRST_TOKEN && res <= LAST_TOKEN);
351 return static_cast<Token::Value>(res);
352 }
353
354
355 const char* BinaryOpStub::StateToName(State state) {
356 switch (state) {
357 case NONE:
358 return "None";
359 case SMI:
360 return "Smi";
361 case INT32:
362 return "Int32";
363 case NUMBER:
364 return "Number";
365 case STRING:
366 return "String";
367 case GENERIC:
368 return "Generic";
369 }
370 return "";
371 }
372
373
374 void BinaryOpStub::UpdateStatus(Handle<Object> left,
375 Handle<Object> right,
376 Maybe<Handle<Object> > result) {
377 int old_state = GetExtraICState();
378
379 UpdateStatus(left, &left_state_, &left_bool_);
380 UpdateStatus(right, &right_state_, &right_bool_);
381
382 int32_t value;
383 bool new_has_fixed_right_arg =
384 right->ToInt32(&value) && can_encode_arg_value(value) &&
385 (left_state_ == SMI || left_state_ == INT32) &&
386 (result_state_ == NONE || !fixed_right_arg_.has_value);
387
388 fixed_right_arg_ = Maybe<int32_t>(new_has_fixed_right_arg, value);
389
390 if (result.has_value) UpdateStatus(result.value, &result_state_, NULL);
391
392 State max_result = has_int_result() ? INT32 : NUMBER;
393 State max_input = Max(left_state_, right_state_);
394
395 // Avoid unnecessary Representation changes.
396 if (left_state_ == STRING && right_state_ < STRING) {
397 right_state_ = GENERIC;
398 } else if (right_state_ == STRING && left_state_ < STRING) {
399 left_state_ = GENERIC;
400 } else if ((right_state_ == GENERIC && left_state_ != STRING) ||
401 (left_state_ == GENERIC && right_state_ != STRING)) {
402 left_state_ = right_state_ = GENERIC;
403 } else if (max_input <= NUMBER && max_input > result_state_) {
404 result_state_ = Min(max_result, max_input);
405 }
406
407 ASSERT(result_state_ <= max_result || op_ == Token::ADD);
408
409 if (old_state == GetExtraICState()) {
410 // Since the fpu is to precise, we might bail out on numbers which
411 // actually would truncate with 64 bit precision.
412 ASSERT(!CpuFeatures::IsSupported(SSE2) &&
413 result_state_ <= INT32);
414 result_state_ = NUMBER;
415 } 240 }
416 } 241 }
417 242
418 243
419 void BinaryOpStub::UpdateStatus(Handle<Object> object, 244 #define __ ACCESS_MASM(masm)
420 State* state, 245
421 bool* bool_state) { 246
422 if (object->IsBoolean() && bool_state != NULL) { 247 void BinaryOpStub::GenerateCallRuntime(MacroAssembler* masm) {
423 *bool_state = true; 248 switch (op_) {
424 return; 249 case Token::ADD:
250 __ InvokeBuiltin(Builtins::ADD, CALL_FUNCTION);
251 break;
252 case Token::SUB:
253 __ InvokeBuiltin(Builtins::SUB, CALL_FUNCTION);
254 break;
255 case Token::MUL:
256 __ InvokeBuiltin(Builtins::MUL, CALL_FUNCTION);
257 break;
258 case Token::DIV:
259 __ InvokeBuiltin(Builtins::DIV, CALL_FUNCTION);
260 break;
261 case Token::MOD:
262 __ InvokeBuiltin(Builtins::MOD, CALL_FUNCTION);
263 break;
264 case Token::BIT_OR:
265 __ InvokeBuiltin(Builtins::BIT_OR, CALL_FUNCTION);
266 break;
267 case Token::BIT_AND:
268 __ InvokeBuiltin(Builtins::BIT_AND, CALL_FUNCTION);
269 break;
270 case Token::BIT_XOR:
271 __ InvokeBuiltin(Builtins::BIT_XOR, CALL_FUNCTION);
272 break;
273 case Token::SAR:
274 __ InvokeBuiltin(Builtins::SAR, CALL_FUNCTION);
275 break;
276 case Token::SHR:
277 __ InvokeBuiltin(Builtins::SHR, CALL_FUNCTION);
278 break;
279 case Token::SHL:
280 __ InvokeBuiltin(Builtins::SHL, CALL_FUNCTION);
281 break;
282 default:
283 UNREACHABLE();
425 } 284 }
426 v8::internal::TypeInfo type = v8::internal::TypeInfo::FromValue(object);
427 if (object->IsUndefined()) {
428 // Undefined will be automatically truncated for us by HChange.
429 type = (op_ == Token::BIT_AND || op_ == Token::BIT_OR ||
430 op_ == Token::BIT_XOR || op_ == Token::SAR ||
431 op_ == Token::SHL || op_ == Token::SHR)
432 ? TypeInfo::Integer32()
433 : TypeInfo::Double();
434 }
435 State int_state = SmiValuesAre32Bits() ? NUMBER : INT32;
436 State new_state = NONE;
437 if (type.IsSmi()) {
438 new_state = SMI;
439 } else if (type.IsInteger32()) {
440 new_state = int_state;
441 } else if (type.IsNumber()) {
442 new_state = NUMBER;
443 } else if (object->IsString() && operation() == Token::ADD) {
444 new_state = STRING;
445 } else {
446 new_state = GENERIC;
447 }
448 if ((new_state <= NUMBER && *state > NUMBER) ||
449 (new_state > NUMBER && *state <= NUMBER && *state != NONE)) {
450 new_state = GENERIC;
451 }
452 *state = Max(*state, new_state);
453 } 285 }
454 286
455 287
456 Handle<Type> BinaryOpStub::StateToType(State state, 288 #undef __
457 bool seen_bool,
458 Isolate* isolate) {
459 Handle<Type> t = handle(Type::None(), isolate);
460 switch (state) {
461 case NUMBER:
462 t = handle(Type::Union(t, handle(Type::Double(), isolate)), isolate);
463 // Fall through.
464 case INT32:
465 t = handle(Type::Union(t, handle(Type::Signed32(), isolate)), isolate);
466 // Fall through.
467 case SMI:
468 t = handle(Type::Union(t, handle(Type::Smi(), isolate)), isolate);
469 break;
470 289
471 case STRING: 290
472 t = handle(Type::Union(t, handle(Type::String(), isolate)), isolate); 291 void BinaryOpStub::PrintName(StringStream* stream) {
473 break; 292 const char* op_name = Token::Name(op_);
474 case GENERIC: 293 const char* overwrite_name;
475 return handle(Type::Any(), isolate); 294 switch (mode_) {
476 break; 295 case NO_OVERWRITE: overwrite_name = "Alloc"; break;
477 case NONE: 296 case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break;
478 break; 297 case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break;
298 default: overwrite_name = "UnknownOverwrite"; break;
479 } 299 }
480 if (seen_bool) { 300 stream->Add("BinaryOpStub_%s_%s_%s+%s",
481 t = handle(Type::Union(t, handle(Type::Boolean(), isolate)), isolate); 301 op_name,
482 } 302 overwrite_name,
483 return t; 303 BinaryOpIC::GetName(left_type_),
304 BinaryOpIC::GetName(right_type_));
484 } 305 }
485 306
486 307
487 Handle<Type> BinaryOpStub::GetLeftType(Isolate* isolate) const { 308 void BinaryOpStub::GenerateStringStub(MacroAssembler* masm) {
488 return StateToType(left_state_, left_bool_, isolate); 309 ASSERT(left_type_ == BinaryOpIC::STRING || right_type_ == BinaryOpIC::STRING);
310 ASSERT(op_ == Token::ADD);
311 if (left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING) {
312 GenerateBothStringStub(masm);
313 return;
314 }
315 // Try to add arguments as strings, otherwise, transition to the generic
316 // BinaryOpIC type.
317 GenerateAddStrings(masm);
318 GenerateTypeTransition(masm);
489 } 319 }
490 320
491 321
492 Handle<Type> BinaryOpStub::GetRightType(Isolate* isolate) const {
493 return StateToType(right_state_, right_bool_, isolate);
494 }
495
496
497 Handle<Type> BinaryOpStub::GetResultType(Isolate* isolate) const {
498 if (HasSideEffects(isolate)) return StateToType(NONE, false, isolate);
499 if (result_state_ == GENERIC && op_ == Token::ADD) {
500 return handle(Type::Union(handle(Type::Number(), isolate),
501 handle(Type::String(), isolate)), isolate);
502 }
503 ASSERT(result_state_ != GENERIC);
504 if (result_state_ == NUMBER && op_ == Token::SHR) {
505 return handle(Type::Unsigned32(), isolate);
506 }
507 return StateToType(result_state_, false, isolate);
508 }
509
510
511 InlineCacheState ICCompareStub::GetICState() { 322 InlineCacheState ICCompareStub::GetICState() {
512 CompareIC::State state = Max(left_, right_); 323 CompareIC::State state = Max(left_, right_);
513 switch (state) { 324 switch (state) {
514 case CompareIC::UNINITIALIZED: 325 case CompareIC::UNINITIALIZED:
515 return ::v8::internal::UNINITIALIZED; 326 return ::v8::internal::UNINITIALIZED;
516 case CompareIC::SMI: 327 case CompareIC::SMI:
517 case CompareIC::NUMBER: 328 case CompareIC::NUMBER:
518 case CompareIC::INTERNALIZED_STRING: 329 case CompareIC::INTERNALIZED_STRING:
519 case CompareIC::STRING: 330 case CompareIC::STRING:
520 case CompareIC::UNIQUE_NAME: 331 case CompareIC::UNIQUE_NAME:
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 InstallDescriptor(isolate, &stub3); 795 InstallDescriptor(isolate, &stub3);
985 } 796 }
986 797
987 InternalArrayConstructorStub::InternalArrayConstructorStub( 798 InternalArrayConstructorStub::InternalArrayConstructorStub(
988 Isolate* isolate) { 799 Isolate* isolate) {
989 InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); 800 InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
990 } 801 }
991 802
992 803
993 } } // namespace v8::internal 804 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/code-stubs.h ('k') | src/code-stubs-hydrogen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698