blob: 2d7ad3255b9d46c72e5b7c762d22f637afa6d91d [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2012 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/full-codegen/full-codegen.h"
6
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007#include "src/ast/ast-numbering.h"
Ben Murdochda12d292016-06-02 14:46:10 +01008#include "src/ast/ast.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009#include "src/ast/prettyprinter.h"
10#include "src/ast/scopeinfo.h"
11#include "src/ast/scopes.h"
12#include "src/code-factory.h"
13#include "src/codegen.h"
14#include "src/compiler.h"
15#include "src/debug/debug.h"
16#include "src/debug/liveedit.h"
Ben Murdochda12d292016-06-02 14:46:10 +010017#include "src/frames-inl.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000018#include "src/isolate-inl.h"
19#include "src/macro-assembler.h"
20#include "src/snapshot/snapshot.h"
Ben Murdoch097c5b22016-05-18 11:27:45 +010021#include "src/tracing/trace-event.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000022
23namespace v8 {
24namespace internal {
25
26#define __ ACCESS_MASM(masm())
27
28bool FullCodeGenerator::MakeCode(CompilationInfo* info) {
29 Isolate* isolate = info->isolate();
30
Ben Murdochc5610432016-08-08 18:44:38 +010031 RuntimeCallTimerScope runtimeTimer(isolate,
32 &RuntimeCallStats::CompileFullCode);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000033 TimerEventScope<TimerEventCompileFullCode> timer(info->isolate());
Ben Murdoch097c5b22016-05-18 11:27:45 +010034 TRACE_EVENT0("v8", "V8.CompileFullCode");
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000035
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000036 Handle<Script> script = info->script();
37 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
38 int len = String::cast(script->source())->length();
39 isolate->counters()->total_full_codegen_source_size()->Increment(len);
40 }
41 CodeGenerator::MakeCodePrologue(info, "full");
42 const int kInitialBufferSize = 4 * KB;
43 MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize,
44 CodeObjectRequired::kYes);
45 if (info->will_serialize()) masm.enable_serializer();
46
47 LOG_CODE_EVENT(isolate,
48 CodeStartLinePosInfoRecordEvent(masm.positions_recorder()));
49
50 FullCodeGenerator cgen(&masm, info);
51 cgen.Generate();
52 if (cgen.HasStackOverflow()) {
53 DCHECK(!isolate->has_pending_exception());
54 return false;
55 }
56 unsigned table_offset = cgen.EmitBackEdgeTable();
57
58 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, info);
59 cgen.PopulateDeoptimizationData(code);
60 cgen.PopulateTypeFeedbackInfo(code);
61 cgen.PopulateHandlerTable(code);
62 code->set_has_deoptimization_support(info->HasDeoptimizationSupport());
63 code->set_has_reloc_info_for_serialization(info->will_serialize());
64 code->set_allow_osr_at_loop_nesting_level(0);
65 code->set_profiler_ticks(0);
66 code->set_back_edge_table_offset(table_offset);
67 CodeGenerator::PrintCode(code, info);
68 info->SetCode(code);
69 void* line_info = masm.positions_recorder()->DetachJITHandlerData();
Ben Murdochda12d292016-06-02 14:46:10 +010070 LOG_CODE_EVENT(isolate, CodeEndLinePosInfoRecordEvent(
71 AbstractCode::cast(*code), line_info));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000072
73#ifdef DEBUG
74 // Check that no context-specific object has been embedded.
75 code->VerifyEmbeddedObjects(Code::kNoContextSpecificPointers);
76#endif // DEBUG
77 return true;
78}
79
80
81unsigned FullCodeGenerator::EmitBackEdgeTable() {
82 // The back edge table consists of a length (in number of entries)
83 // field, and then a sequence of entries. Each entry is a pair of AST id
84 // and code-relative pc offset.
85 masm()->Align(kPointerSize);
86 unsigned offset = masm()->pc_offset();
87 unsigned length = back_edges_.length();
88 __ dd(length);
89 for (unsigned i = 0; i < length; ++i) {
90 __ dd(back_edges_[i].id.ToInt());
91 __ dd(back_edges_[i].pc);
92 __ dd(back_edges_[i].loop_depth);
93 }
94 return offset;
95}
96
97
98void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) {
99 // Fill in the deoptimization information.
100 DCHECK(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty());
101 if (!info_->HasDeoptimizationSupport()) return;
102 int length = bailout_entries_.length();
103 Handle<DeoptimizationOutputData> data =
104 DeoptimizationOutputData::New(isolate(), length, TENURED);
105 for (int i = 0; i < length; i++) {
106 data->SetAstId(i, bailout_entries_[i].id);
107 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state));
108 }
109 code->set_deoptimization_data(*data);
110}
111
112
113void FullCodeGenerator::PopulateTypeFeedbackInfo(Handle<Code> code) {
114 Handle<TypeFeedbackInfo> info = isolate()->factory()->NewTypeFeedbackInfo();
115 info->set_ic_total_count(ic_total_count_);
116 DCHECK(!isolate()->heap()->InNewSpace(*info));
117 code->set_type_feedback_info(*info);
118}
119
120
121void FullCodeGenerator::PopulateHandlerTable(Handle<Code> code) {
122 int handler_table_size = static_cast<int>(handler_table_.size());
123 Handle<HandlerTable> table =
124 Handle<HandlerTable>::cast(isolate()->factory()->NewFixedArray(
125 HandlerTable::LengthForRange(handler_table_size), TENURED));
126 for (int i = 0; i < handler_table_size; ++i) {
127 HandlerTable::CatchPrediction prediction =
128 handler_table_[i].try_catch_depth > 0 ? HandlerTable::CAUGHT
129 : HandlerTable::UNCAUGHT;
130 table->SetRangeStart(i, handler_table_[i].range_start);
131 table->SetRangeEnd(i, handler_table_[i].range_end);
132 table->SetRangeHandler(i, handler_table_[i].handler_offset, prediction);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100133 table->SetRangeData(i, handler_table_[i].stack_depth);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000134 }
135 code->set_handler_table(*table);
136}
137
138
139int FullCodeGenerator::NewHandlerTableEntry() {
140 int index = static_cast<int>(handler_table_.size());
141 HandlerTableEntry entry = {0, 0, 0, 0, 0};
142 handler_table_.push_back(entry);
143 return index;
144}
145
146
147bool FullCodeGenerator::MustCreateObjectLiteralWithRuntime(
148 ObjectLiteral* expr) const {
Ben Murdochc5610432016-08-08 18:44:38 +0100149 return masm()->serializer_enabled() ||
150 !FastCloneShallowObjectStub::IsSupported(expr);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000151}
152
153
154bool FullCodeGenerator::MustCreateArrayLiteralWithRuntime(
155 ArrayLiteral* expr) const {
Ben Murdochda12d292016-06-02 14:46:10 +0100156 return expr->depth() > 1 ||
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000157 expr->values()->length() > JSArray::kInitialMaxFastElementArray;
158}
159
160
161void FullCodeGenerator::Initialize() {
162 InitializeAstVisitor(info_->isolate());
Ben Murdoch097c5b22016-05-18 11:27:45 +0100163 masm_->set_emit_debug_code(FLAG_debug_code);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000164 masm_->set_predictable_code_size(true);
165}
166
Ben Murdochc5610432016-08-08 18:44:38 +0100167void FullCodeGenerator::PrepareForBailout(Expression* node,
168 BailoutState state) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000169 PrepareForBailoutForId(node->id(), state);
170}
171
172
173void FullCodeGenerator::CallLoadIC(TypeofMode typeof_mode,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000174 TypeFeedbackId id) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100175 Handle<Code> ic = CodeFactory::LoadIC(isolate(), typeof_mode).code();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000176 CallIC(ic, id);
177}
178
179
180void FullCodeGenerator::CallStoreIC(TypeFeedbackId id) {
181 Handle<Code> ic = CodeFactory::StoreIC(isolate(), language_mode()).code();
182 CallIC(ic, id);
183}
184
185
186void FullCodeGenerator::RecordJSReturnSite(Call* call) {
187 // We record the offset of the function return so we can rebuild the frame
188 // if the function was inlined, i.e., this is the return address in the
189 // inlined function's frame.
190 //
Ben Murdochc5610432016-08-08 18:44:38 +0100191 // The bailout state is ignored. We defensively set it to TOS_REGISTER, which
192 // is the real state of the unoptimized code at the return site.
193 PrepareForBailoutForId(call->ReturnId(), BailoutState::TOS_REGISTER);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000194#ifdef DEBUG
195 // In debug builds, mark the return so we can verify that this function
196 // was called.
197 DCHECK(!call->return_is_recorded_);
198 call->return_is_recorded_ = true;
199#endif
200}
201
Ben Murdochc5610432016-08-08 18:44:38 +0100202void FullCodeGenerator::PrepareForBailoutForId(BailoutId id,
203 BailoutState state) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000204 // There's no need to prepare this code for bailouts from already optimized
205 // code or code that can't be optimized.
206 if (!info_->HasDeoptimizationSupport()) return;
207 unsigned pc_and_state =
Ben Murdochc5610432016-08-08 18:44:38 +0100208 BailoutStateField::encode(state) | PcField::encode(masm_->pc_offset());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000209 DCHECK(Smi::IsValid(pc_and_state));
210#ifdef DEBUG
211 for (int i = 0; i < bailout_entries_.length(); ++i) {
212 DCHECK(bailout_entries_[i].id != id);
213 }
214#endif
215 BailoutEntry entry = { id, pc_and_state };
216 bailout_entries_.Add(entry, zone());
217}
218
219
220void FullCodeGenerator::RecordBackEdge(BailoutId ast_id) {
221 // The pc offset does not need to be encoded and packed together with a state.
222 DCHECK(masm_->pc_offset() > 0);
223 DCHECK(loop_depth() > 0);
224 uint8_t depth = Min(loop_depth(), Code::kMaxLoopNestingMarker);
225 BackEdgeEntry entry =
226 { ast_id, static_cast<unsigned>(masm_->pc_offset()), depth };
227 back_edges_.Add(entry, zone());
228}
229
230
231bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) {
232 // Inline smi case inside loops, but not division and modulo which
233 // are too complicated and take up too much space.
234 if (op == Token::DIV ||op == Token::MOD) return false;
235 if (FLAG_always_inline_smi_code) return true;
236 return loop_depth_ > 0;
237}
238
239
240void FullCodeGenerator::EffectContext::Plug(Variable* var) const {
241 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
242}
243
244
245void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const {
246 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
247 codegen()->GetVar(result_register(), var);
248}
249
250
251void FullCodeGenerator::TestContext::Plug(Variable* var) const {
252 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
253 // For simplicity we always test the accumulator register.
254 codegen()->GetVar(result_register(), var);
255 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
256 codegen()->DoTest(this);
257}
258
259
260void FullCodeGenerator::EffectContext::Plug(Register reg) const {
261}
262
263
264void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const {
265 __ Move(result_register(), reg);
266}
267
268
269void FullCodeGenerator::StackValueContext::Plug(Register reg) const {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100270 codegen()->PushOperand(reg);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000271}
272
273
274void FullCodeGenerator::TestContext::Plug(Register reg) const {
275 // For simplicity we always test the accumulator register.
276 __ Move(result_register(), reg);
277 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
278 codegen()->DoTest(this);
279}
280
281
282void FullCodeGenerator::EffectContext::Plug(bool flag) const {}
283
Ben Murdoch097c5b22016-05-18 11:27:45 +0100284void FullCodeGenerator::EffectContext::DropAndPlug(int count,
285 Register reg) const {
286 DCHECK(count > 0);
287 codegen()->DropOperands(count);
288}
289
290void FullCodeGenerator::AccumulatorValueContext::DropAndPlug(
291 int count, Register reg) const {
292 DCHECK(count > 0);
293 codegen()->DropOperands(count);
294 __ Move(result_register(), reg);
295}
296
297void FullCodeGenerator::TestContext::DropAndPlug(int count,
298 Register reg) const {
299 DCHECK(count > 0);
300 // For simplicity we always test the accumulator register.
301 codegen()->DropOperands(count);
302 __ Move(result_register(), reg);
303 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
304 codegen()->DoTest(this);
305}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000306
307void FullCodeGenerator::EffectContext::PlugTOS() const {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100308 codegen()->DropOperands(1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000309}
310
311
312void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100313 codegen()->PopOperand(result_register());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000314}
315
316
317void FullCodeGenerator::StackValueContext::PlugTOS() const {
318}
319
320
321void FullCodeGenerator::TestContext::PlugTOS() const {
322 // For simplicity we always test the accumulator register.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100323 codegen()->PopOperand(result_register());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000324 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
325 codegen()->DoTest(this);
326}
327
328
329void FullCodeGenerator::EffectContext::PrepareTest(
330 Label* materialize_true,
331 Label* materialize_false,
332 Label** if_true,
333 Label** if_false,
334 Label** fall_through) const {
335 // In an effect context, the true and the false case branch to the
336 // same label.
337 *if_true = *if_false = *fall_through = materialize_true;
338}
339
340
341void FullCodeGenerator::AccumulatorValueContext::PrepareTest(
342 Label* materialize_true,
343 Label* materialize_false,
344 Label** if_true,
345 Label** if_false,
346 Label** fall_through) const {
347 *if_true = *fall_through = materialize_true;
348 *if_false = materialize_false;
349}
350
351
352void FullCodeGenerator::StackValueContext::PrepareTest(
353 Label* materialize_true,
354 Label* materialize_false,
355 Label** if_true,
356 Label** if_false,
357 Label** fall_through) const {
358 *if_true = *fall_through = materialize_true;
359 *if_false = materialize_false;
360}
361
362
363void FullCodeGenerator::TestContext::PrepareTest(
364 Label* materialize_true,
365 Label* materialize_false,
366 Label** if_true,
367 Label** if_false,
368 Label** fall_through) const {
369 *if_true = true_label_;
370 *if_false = false_label_;
371 *fall_through = fall_through_;
372}
373
374
375void FullCodeGenerator::DoTest(const TestContext* context) {
376 DoTest(context->condition(),
377 context->true_label(),
378 context->false_label(),
379 context->fall_through());
380}
381
382
383void FullCodeGenerator::VisitDeclarations(
384 ZoneList<Declaration*>* declarations) {
385 ZoneList<Handle<Object> >* saved_globals = globals_;
386 ZoneList<Handle<Object> > inner_globals(10, zone());
387 globals_ = &inner_globals;
388
389 AstVisitor::VisitDeclarations(declarations);
390
391 if (!globals_->is_empty()) {
392 // Invoke the platform-dependent code generator to do the actual
393 // declaration of the global functions and variables.
394 Handle<FixedArray> array =
395 isolate()->factory()->NewFixedArray(globals_->length(), TENURED);
396 for (int i = 0; i < globals_->length(); ++i)
397 array->set(i, *globals_->at(i));
398 DeclareGlobals(array);
399 }
400
401 globals_ = saved_globals;
402}
403
404
405void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) {
406 VariableProxy* proxy = declaration->proxy();
407 Variable* variable = proxy->var();
408 switch (variable->location()) {
409 case VariableLocation::GLOBAL:
410 case VariableLocation::UNALLOCATED:
411 // TODO(rossberg)
412 break;
413
414 case VariableLocation::CONTEXT: {
415 Comment cmnt(masm_, "[ ImportDeclaration");
416 EmitDebugCheckDeclarationContext(variable);
417 // TODO(rossberg)
418 break;
419 }
420
421 case VariableLocation::PARAMETER:
422 case VariableLocation::LOCAL:
423 case VariableLocation::LOOKUP:
424 UNREACHABLE();
425 }
426}
427
428
429void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) {
430 // TODO(rossberg)
431}
432
433
434void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) {
435 Comment cmnt(masm_, "[ VariableProxy");
436 EmitVariableLoad(expr);
437}
438
439
440void FullCodeGenerator::VisitSloppyBlockFunctionStatement(
441 SloppyBlockFunctionStatement* declaration) {
442 Visit(declaration->statement());
443}
444
445
446int FullCodeGenerator::DeclareGlobalsFlags() {
Ben Murdochc5610432016-08-08 18:44:38 +0100447 return info_->GetDeclareGlobalsFlags();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000448}
449
Ben Murdoch097c5b22016-05-18 11:27:45 +0100450void FullCodeGenerator::PushOperand(Handle<Object> handle) {
451 OperandStackDepthIncrement(1);
452 __ Push(handle);
453}
454
455void FullCodeGenerator::PushOperand(Smi* smi) {
456 OperandStackDepthIncrement(1);
457 __ Push(smi);
458}
459
460void FullCodeGenerator::PushOperand(Register reg) {
461 OperandStackDepthIncrement(1);
462 __ Push(reg);
463}
464
465void FullCodeGenerator::PopOperand(Register reg) {
466 OperandStackDepthDecrement(1);
467 __ Pop(reg);
468}
469
470void FullCodeGenerator::DropOperands(int count) {
471 OperandStackDepthDecrement(count);
472 __ Drop(count);
473}
474
475void FullCodeGenerator::CallRuntimeWithOperands(Runtime::FunctionId id) {
476 OperandStackDepthDecrement(Runtime::FunctionForId(id)->nargs);
477 __ CallRuntime(id);
478}
479
480void FullCodeGenerator::OperandStackDepthIncrement(int count) {
Ben Murdochda12d292016-06-02 14:46:10 +0100481 DCHECK_IMPLIES(!HasStackOverflow(), operand_stack_depth_ >= 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100482 DCHECK_GE(count, 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100483 operand_stack_depth_ += count;
484}
485
486void FullCodeGenerator::OperandStackDepthDecrement(int count) {
Ben Murdochda12d292016-06-02 14:46:10 +0100487 DCHECK_IMPLIES(!HasStackOverflow(), operand_stack_depth_ >= count);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100488 DCHECK_GE(count, 0);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100489 operand_stack_depth_ -= count;
490}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000491
492void FullCodeGenerator::EmitSubString(CallRuntime* expr) {
493 // Load the arguments on the stack and call the stub.
494 SubStringStub stub(isolate());
495 ZoneList<Expression*>* args = expr->arguments();
496 DCHECK(args->length() == 3);
497 VisitForStackValue(args->at(0));
498 VisitForStackValue(args->at(1));
499 VisitForStackValue(args->at(2));
500 __ CallStub(&stub);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100501 OperandStackDepthDecrement(3);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000502 context()->Plug(result_register());
503}
504
505
506void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) {
507 // Load the arguments on the stack and call the stub.
508 RegExpExecStub stub(isolate());
509 ZoneList<Expression*>* args = expr->arguments();
510 DCHECK(args->length() == 4);
511 VisitForStackValue(args->at(0));
512 VisitForStackValue(args->at(1));
513 VisitForStackValue(args->at(2));
514 VisitForStackValue(args->at(3));
515 __ CallStub(&stub);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100516 OperandStackDepthDecrement(4);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000517 context()->Plug(result_register());
518}
519
520
521void FullCodeGenerator::EmitMathPow(CallRuntime* expr) {
522 // Load the arguments on the stack and call the runtime function.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100523 MathPowStub stub(isolate(), MathPowStub::ON_STACK);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000524 ZoneList<Expression*>* args = expr->arguments();
525 DCHECK(args->length() == 2);
526 VisitForStackValue(args->at(0));
527 VisitForStackValue(args->at(1));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000528 __ CallStub(&stub);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100529 OperandStackDepthDecrement(2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000530 context()->Plug(result_register());
531}
532
533
534void FullCodeGenerator::EmitIntrinsicAsStubCall(CallRuntime* expr,
535 const Callable& callable) {
536 ZoneList<Expression*>* args = expr->arguments();
537 int param_count = callable.descriptor().GetRegisterParameterCount();
538 DCHECK_EQ(args->length(), param_count);
539
540 if (param_count > 0) {
541 int last = param_count - 1;
542 // Put all but last arguments on stack.
543 for (int i = 0; i < last; i++) {
544 VisitForStackValue(args->at(i));
545 }
546 // The last argument goes to the accumulator.
547 VisitForAccumulatorValue(args->at(last));
548
549 // Move the arguments to the registers, as required by the stub.
550 __ Move(callable.descriptor().GetRegisterParameter(last),
551 result_register());
552 for (int i = last; i-- > 0;) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100553 PopOperand(callable.descriptor().GetRegisterParameter(i));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000554 }
555 }
556 __ Call(callable.code(), RelocInfo::CODE_TARGET);
Ben Murdochda12d292016-06-02 14:46:10 +0100557
558 // Reload the context register after the call as i.e. TurboFan code stubs
559 // won't preserve the context register.
560 LoadFromFrameField(StandardFrameConstants::kContextOffset,
561 context_register());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000562 context()->Plug(result_register());
563}
564
Ben Murdochda12d292016-06-02 14:46:10 +0100565void FullCodeGenerator::EmitNewObject(CallRuntime* expr) {
566 EmitIntrinsicAsStubCall(expr, CodeFactory::FastNewObject(isolate()));
567}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000568
569void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) {
570 EmitIntrinsicAsStubCall(expr, CodeFactory::NumberToString(isolate()));
571}
572
573
574void FullCodeGenerator::EmitToString(CallRuntime* expr) {
575 EmitIntrinsicAsStubCall(expr, CodeFactory::ToString(isolate()));
576}
577
578
Ben Murdoch097c5b22016-05-18 11:27:45 +0100579void FullCodeGenerator::EmitToName(CallRuntime* expr) {
580 EmitIntrinsicAsStubCall(expr, CodeFactory::ToName(isolate()));
581}
582
583
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000584void FullCodeGenerator::EmitToLength(CallRuntime* expr) {
585 EmitIntrinsicAsStubCall(expr, CodeFactory::ToLength(isolate()));
586}
587
Ben Murdochda12d292016-06-02 14:46:10 +0100588void FullCodeGenerator::EmitToInteger(CallRuntime* expr) {
589 EmitIntrinsicAsStubCall(expr, CodeFactory::ToInteger(isolate()));
590}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000591
592void FullCodeGenerator::EmitToNumber(CallRuntime* expr) {
593 EmitIntrinsicAsStubCall(expr, CodeFactory::ToNumber(isolate()));
594}
595
596
597void FullCodeGenerator::EmitToObject(CallRuntime* expr) {
598 EmitIntrinsicAsStubCall(expr, CodeFactory::ToObject(isolate()));
599}
600
601
602void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) {
603 EmitIntrinsicAsStubCall(expr, CodeFactory::RegExpConstructResult(isolate()));
604}
605
Ben Murdochc5610432016-08-08 18:44:38 +0100606void FullCodeGenerator::EmitHasProperty() {
607 Callable callable = CodeFactory::HasProperty(isolate());
608 PopOperand(callable.descriptor().GetRegisterParameter(1));
609 PopOperand(callable.descriptor().GetRegisterParameter(0));
610 __ Call(callable.code(), RelocInfo::CODE_TARGET);
611 RestoreContext();
612}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000613
614bool RecordStatementPosition(MacroAssembler* masm, int pos) {
615 if (pos == RelocInfo::kNoPosition) return false;
616 masm->positions_recorder()->RecordStatementPosition(pos);
617 masm->positions_recorder()->RecordPosition(pos);
618 return masm->positions_recorder()->WriteRecordedPositions();
619}
620
621
622bool RecordPosition(MacroAssembler* masm, int pos) {
623 if (pos == RelocInfo::kNoPosition) return false;
624 masm->positions_recorder()->RecordPosition(pos);
625 return masm->positions_recorder()->WriteRecordedPositions();
626}
627
628
629void FullCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) {
630 RecordPosition(masm_, fun->start_position());
631}
632
633
634void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) {
635 // For default constructors, start position equals end position, and there
636 // is no source code besides the class literal.
637 int pos = std::max(fun->start_position(), fun->end_position() - 1);
638 RecordStatementPosition(masm_, pos);
639 if (info_->is_debug()) {
640 // Always emit a debug break slot before a return.
641 DebugCodegen::GenerateSlot(masm_, RelocInfo::DEBUG_BREAK_SLOT_AT_RETURN);
642 }
643}
644
645
646void FullCodeGenerator::SetStatementPosition(
647 Statement* stmt, FullCodeGenerator::InsertBreak insert_break) {
648 if (stmt->position() == RelocInfo::kNoPosition) return;
649 bool recorded = RecordStatementPosition(masm_, stmt->position());
650 if (recorded && insert_break == INSERT_BREAK && info_->is_debug() &&
651 !stmt->IsDebuggerStatement()) {
652 DebugCodegen::GenerateSlot(masm_, RelocInfo::DEBUG_BREAK_SLOT_AT_POSITION);
653 }
654}
655
Ben Murdochc5610432016-08-08 18:44:38 +0100656void FullCodeGenerator::SetExpressionPosition(Expression* expr) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000657 if (expr->position() == RelocInfo::kNoPosition) return;
Ben Murdochc5610432016-08-08 18:44:38 +0100658 RecordPosition(masm_, expr->position());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000659}
660
661
662void FullCodeGenerator::SetExpressionAsStatementPosition(Expression* expr) {
663 if (expr->position() == RelocInfo::kNoPosition) return;
664 bool recorded = RecordStatementPosition(masm_, expr->position());
665 if (recorded && info_->is_debug()) {
666 DebugCodegen::GenerateSlot(masm_, RelocInfo::DEBUG_BREAK_SLOT_AT_POSITION);
667 }
668}
669
Ben Murdochda12d292016-06-02 14:46:10 +0100670void FullCodeGenerator::SetCallPosition(Expression* expr,
671 TailCallMode tail_call_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000672 if (expr->position() == RelocInfo::kNoPosition) return;
673 RecordPosition(masm_, expr->position());
674 if (info_->is_debug()) {
Ben Murdochda12d292016-06-02 14:46:10 +0100675 RelocInfo::Mode mode = (tail_call_mode == TailCallMode::kAllow)
676 ? RelocInfo::DEBUG_BREAK_SLOT_AT_TAIL_CALL
677 : RelocInfo::DEBUG_BREAK_SLOT_AT_CALL;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000678 // Always emit a debug break slot before a call.
Ben Murdochda12d292016-06-02 14:46:10 +0100679 DebugCodegen::GenerateSlot(masm_, mode);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000680 }
681}
682
683
684void FullCodeGenerator::VisitSuperPropertyReference(
685 SuperPropertyReference* super) {
686 __ CallRuntime(Runtime::kThrowUnsupportedSuperError);
Ben Murdochc5610432016-08-08 18:44:38 +0100687 // Even though this expression doesn't produce a value, we need to simulate
688 // plugging of the value context to ensure stack depth tracking is in sync.
689 if (context()->IsStackValue()) OperandStackDepthIncrement(1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000690}
691
692
693void FullCodeGenerator::VisitSuperCallReference(SuperCallReference* super) {
Ben Murdochc5610432016-08-08 18:44:38 +0100694 // Handled by VisitCall
695 UNREACHABLE();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000696}
697
698
699void FullCodeGenerator::EmitDebugBreakInOptimizedCode(CallRuntime* expr) {
700 context()->Plug(handle(Smi::FromInt(0), isolate()));
701}
702
703
704void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) {
705 switch (expr->op()) {
706 case Token::COMMA:
707 return VisitComma(expr);
708 case Token::OR:
709 case Token::AND:
710 return VisitLogicalExpression(expr);
711 default:
712 return VisitArithmeticExpression(expr);
713 }
714}
715
716
717void FullCodeGenerator::VisitInDuplicateContext(Expression* expr) {
718 if (context()->IsEffect()) {
719 VisitForEffect(expr);
720 } else if (context()->IsAccumulatorValue()) {
721 VisitForAccumulatorValue(expr);
722 } else if (context()->IsStackValue()) {
723 VisitForStackValue(expr);
724 } else if (context()->IsTest()) {
725 const TestContext* test = TestContext::cast(context());
726 VisitForControl(expr, test->true_label(), test->false_label(),
727 test->fall_through());
728 }
729}
730
731
732void FullCodeGenerator::VisitComma(BinaryOperation* expr) {
733 Comment cmnt(masm_, "[ Comma");
734 VisitForEffect(expr->left());
735 VisitInDuplicateContext(expr->right());
736}
737
738
739void FullCodeGenerator::VisitLogicalExpression(BinaryOperation* expr) {
740 bool is_logical_and = expr->op() == Token::AND;
741 Comment cmnt(masm_, is_logical_and ? "[ Logical AND" : "[ Logical OR");
742 Expression* left = expr->left();
743 Expression* right = expr->right();
744 BailoutId right_id = expr->RightId();
745 Label done;
746
747 if (context()->IsTest()) {
748 Label eval_right;
749 const TestContext* test = TestContext::cast(context());
750 if (is_logical_and) {
751 VisitForControl(left, &eval_right, test->false_label(), &eval_right);
752 } else {
753 VisitForControl(left, test->true_label(), &eval_right, &eval_right);
754 }
Ben Murdochc5610432016-08-08 18:44:38 +0100755 PrepareForBailoutForId(right_id, BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000756 __ bind(&eval_right);
757
758 } else if (context()->IsAccumulatorValue()) {
759 VisitForAccumulatorValue(left);
760 // We want the value in the accumulator for the test, and on the stack in
761 // case we need it.
762 __ Push(result_register());
763 Label discard, restore;
764 if (is_logical_and) {
765 DoTest(left, &discard, &restore, &restore);
766 } else {
767 DoTest(left, &restore, &discard, &restore);
768 }
769 __ bind(&restore);
770 __ Pop(result_register());
771 __ jmp(&done);
772 __ bind(&discard);
773 __ Drop(1);
Ben Murdochc5610432016-08-08 18:44:38 +0100774 PrepareForBailoutForId(right_id, BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000775
776 } else if (context()->IsStackValue()) {
777 VisitForAccumulatorValue(left);
778 // We want the value in the accumulator for the test, and on the stack in
779 // case we need it.
780 __ Push(result_register());
781 Label discard;
782 if (is_logical_and) {
783 DoTest(left, &discard, &done, &discard);
784 } else {
785 DoTest(left, &done, &discard, &discard);
786 }
787 __ bind(&discard);
788 __ Drop(1);
Ben Murdochc5610432016-08-08 18:44:38 +0100789 PrepareForBailoutForId(right_id, BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000790
791 } else {
792 DCHECK(context()->IsEffect());
793 Label eval_right;
794 if (is_logical_and) {
795 VisitForControl(left, &eval_right, &done, &eval_right);
796 } else {
797 VisitForControl(left, &done, &eval_right, &eval_right);
798 }
Ben Murdochc5610432016-08-08 18:44:38 +0100799 PrepareForBailoutForId(right_id, BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000800 __ bind(&eval_right);
801 }
802
803 VisitInDuplicateContext(right);
804 __ bind(&done);
805}
806
807
808void FullCodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) {
809 Token::Value op = expr->op();
810 Comment cmnt(masm_, "[ ArithmeticExpression");
811 Expression* left = expr->left();
812 Expression* right = expr->right();
813
814 VisitForStackValue(left);
815 VisitForAccumulatorValue(right);
816
817 SetExpressionPosition(expr);
818 if (ShouldInlineSmiCase(op)) {
819 EmitInlineSmiBinaryOp(expr, op, left, right);
820 } else {
821 EmitBinaryOp(expr, op);
822 }
823}
824
Ben Murdochc5610432016-08-08 18:44:38 +0100825void FullCodeGenerator::VisitProperty(Property* expr) {
826 Comment cmnt(masm_, "[ Property");
827 SetExpressionPosition(expr);
828
829 Expression* key = expr->key();
830
831 if (key->IsPropertyName()) {
832 if (!expr->IsSuperAccess()) {
833 VisitForAccumulatorValue(expr->obj());
834 __ Move(LoadDescriptor::ReceiverRegister(), result_register());
835 EmitNamedPropertyLoad(expr);
836 } else {
837 VisitForStackValue(expr->obj()->AsSuperPropertyReference()->this_var());
838 VisitForStackValue(
839 expr->obj()->AsSuperPropertyReference()->home_object());
840 EmitNamedSuperPropertyLoad(expr);
841 }
842 } else {
843 if (!expr->IsSuperAccess()) {
844 VisitForStackValue(expr->obj());
845 VisitForAccumulatorValue(expr->key());
846 __ Move(LoadDescriptor::NameRegister(), result_register());
847 PopOperand(LoadDescriptor::ReceiverRegister());
848 EmitKeyedPropertyLoad(expr);
849 } else {
850 VisitForStackValue(expr->obj()->AsSuperPropertyReference()->this_var());
851 VisitForStackValue(
852 expr->obj()->AsSuperPropertyReference()->home_object());
853 VisitForStackValue(expr->key());
854 EmitKeyedSuperPropertyLoad(expr);
855 }
856 }
857 PrepareForBailoutForId(expr->LoadId(), BailoutState::TOS_REGISTER);
858 context()->Plug(result_register());
859}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000860
861void FullCodeGenerator::VisitForTypeofValue(Expression* expr) {
862 VariableProxy* proxy = expr->AsVariableProxy();
863 DCHECK(!context()->IsEffect());
864 DCHECK(!context()->IsTest());
865
866 if (proxy != NULL && (proxy->var()->IsUnallocatedOrGlobalSlot() ||
867 proxy->var()->IsLookupSlot())) {
868 EmitVariableLoad(proxy, INSIDE_TYPEOF);
Ben Murdochc5610432016-08-08 18:44:38 +0100869 PrepareForBailout(proxy, BailoutState::TOS_REGISTER);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000870 } else {
871 // This expression cannot throw a reference error at the top level.
872 VisitInDuplicateContext(expr);
873 }
874}
875
876
877void FullCodeGenerator::VisitBlock(Block* stmt) {
878 Comment cmnt(masm_, "[ Block");
879 NestedBlock nested_block(this, stmt);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000880
881 {
882 EnterBlockScopeIfNeeded block_scope_state(
883 this, stmt->scope(), stmt->EntryId(), stmt->DeclsId(), stmt->ExitId());
884 VisitStatements(stmt->statements());
885 __ bind(nested_block.break_label());
886 }
887}
888
889
890void FullCodeGenerator::VisitDoExpression(DoExpression* expr) {
891 Comment cmnt(masm_, "[ Do Expression");
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000892 SetExpressionPosition(expr);
893 VisitBlock(expr->block());
894 EmitVariableLoad(expr->result());
895}
896
897
898void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) {
899 Comment cmnt(masm_, "[ ExpressionStatement");
900 SetStatementPosition(stmt);
901 VisitForEffect(stmt->expression());
902}
903
904
905void FullCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) {
906 Comment cmnt(masm_, "[ EmptyStatement");
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000907}
908
909
910void FullCodeGenerator::VisitIfStatement(IfStatement* stmt) {
911 Comment cmnt(masm_, "[ IfStatement");
912 SetStatementPosition(stmt);
913 Label then_part, else_part, done;
914
915 if (stmt->HasElseStatement()) {
916 VisitForControl(stmt->condition(), &then_part, &else_part, &then_part);
Ben Murdochc5610432016-08-08 18:44:38 +0100917 PrepareForBailoutForId(stmt->ThenId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000918 __ bind(&then_part);
919 Visit(stmt->then_statement());
920 __ jmp(&done);
921
Ben Murdochc5610432016-08-08 18:44:38 +0100922 PrepareForBailoutForId(stmt->ElseId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000923 __ bind(&else_part);
924 Visit(stmt->else_statement());
925 } else {
926 VisitForControl(stmt->condition(), &then_part, &done, &then_part);
Ben Murdochc5610432016-08-08 18:44:38 +0100927 PrepareForBailoutForId(stmt->ThenId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000928 __ bind(&then_part);
929 Visit(stmt->then_statement());
930
Ben Murdochc5610432016-08-08 18:44:38 +0100931 PrepareForBailoutForId(stmt->ElseId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000932 }
933 __ bind(&done);
Ben Murdochc5610432016-08-08 18:44:38 +0100934 PrepareForBailoutForId(stmt->IfId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000935}
936
Ben Murdoch097c5b22016-05-18 11:27:45 +0100937void FullCodeGenerator::EmitContinue(Statement* target) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000938 NestedStatement* current = nesting_stack_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000939 int context_length = 0;
940 // When continuing, we clobber the unpredictable value in the accumulator
941 // with one that's safe for GC. If we hit an exit from the try block of
942 // try...finally on our way out, we will unconditionally preserve the
943 // accumulator on the stack.
944 ClearAccumulator();
Ben Murdoch097c5b22016-05-18 11:27:45 +0100945 while (!current->IsContinueTarget(target)) {
946 if (current->IsTryFinally()) {
947 Comment cmnt(masm(), "[ Deferred continue through finally");
Ben Murdochda12d292016-06-02 14:46:10 +0100948 current->Exit(&context_length);
949 DCHECK_EQ(-1, context_length);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100950 current->AsTryFinally()->deferred_commands()->RecordContinue(target);
951 return;
952 }
Ben Murdochda12d292016-06-02 14:46:10 +0100953 current = current->Exit(&context_length);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000954 }
Ben Murdochda12d292016-06-02 14:46:10 +0100955 int stack_depth = current->GetStackDepthAtTarget();
956 int stack_drop = operand_stack_depth_ - stack_depth;
957 DCHECK_GE(stack_drop, 0);
958 __ Drop(stack_drop);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000959 if (context_length > 0) {
960 while (context_length > 0) {
961 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
962 --context_length;
963 }
964 StoreToFrameField(StandardFrameConstants::kContextOffset,
965 context_register());
966 }
967
968 __ jmp(current->AsIteration()->continue_label());
969}
970
Ben Murdoch097c5b22016-05-18 11:27:45 +0100971void FullCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) {
972 Comment cmnt(masm_, "[ ContinueStatement");
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000973 SetStatementPosition(stmt);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100974 EmitContinue(stmt->target());
975}
976
977void FullCodeGenerator::EmitBreak(Statement* target) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000978 NestedStatement* current = nesting_stack_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000979 int context_length = 0;
980 // When breaking, we clobber the unpredictable value in the accumulator
981 // with one that's safe for GC. If we hit an exit from the try block of
982 // try...finally on our way out, we will unconditionally preserve the
983 // accumulator on the stack.
984 ClearAccumulator();
Ben Murdoch097c5b22016-05-18 11:27:45 +0100985 while (!current->IsBreakTarget(target)) {
986 if (current->IsTryFinally()) {
987 Comment cmnt(masm(), "[ Deferred break through finally");
Ben Murdochda12d292016-06-02 14:46:10 +0100988 current->Exit(&context_length);
989 DCHECK_EQ(-1, context_length);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100990 current->AsTryFinally()->deferred_commands()->RecordBreak(target);
991 return;
992 }
Ben Murdochda12d292016-06-02 14:46:10 +0100993 current = current->Exit(&context_length);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000994 }
Ben Murdochda12d292016-06-02 14:46:10 +0100995 int stack_depth = current->GetStackDepthAtTarget();
996 int stack_drop = operand_stack_depth_ - stack_depth;
997 DCHECK_GE(stack_drop, 0);
998 __ Drop(stack_drop);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000999 if (context_length > 0) {
1000 while (context_length > 0) {
1001 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
1002 --context_length;
1003 }
1004 StoreToFrameField(StandardFrameConstants::kContextOffset,
1005 context_register());
1006 }
1007
1008 __ jmp(current->AsBreakable()->break_label());
1009}
1010
Ben Murdoch097c5b22016-05-18 11:27:45 +01001011void FullCodeGenerator::VisitBreakStatement(BreakStatement* stmt) {
1012 Comment cmnt(masm_, "[ BreakStatement");
1013 SetStatementPosition(stmt);
1014 EmitBreak(stmt->target());
1015}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001016
Ben Murdoch097c5b22016-05-18 11:27:45 +01001017void FullCodeGenerator::EmitUnwindAndReturn() {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001018 NestedStatement* current = nesting_stack_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001019 int context_length = 0;
1020 while (current != NULL) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001021 if (current->IsTryFinally()) {
1022 Comment cmnt(masm(), "[ Deferred return through finally");
Ben Murdochda12d292016-06-02 14:46:10 +01001023 current->Exit(&context_length);
1024 DCHECK_EQ(-1, context_length);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001025 current->AsTryFinally()->deferred_commands()->RecordReturn();
1026 return;
1027 }
Ben Murdochda12d292016-06-02 14:46:10 +01001028 current = current->Exit(&context_length);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001029 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01001030 EmitReturnSequence();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001031}
1032
Ben Murdochda12d292016-06-02 14:46:10 +01001033void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info,
1034 bool pretenure) {
1035 // Use the fast case closure allocation code that allocates in new
1036 // space for nested functions that don't need literals cloning. If
1037 // we're running with the --always-opt or the --prepare-always-opt
1038 // flag, we need to use the runtime function so that the new function
1039 // we are creating here gets a chance to have its code optimized and
1040 // doesn't just get a copy of the existing unoptimized code.
1041 if (!FLAG_always_opt &&
1042 !FLAG_prepare_always_opt &&
1043 !pretenure &&
1044 scope()->is_function_scope() &&
1045 info->num_literals() == 0) {
1046 FastNewClosureStub stub(isolate(), info->language_mode(), info->kind());
1047 __ Move(stub.GetCallInterfaceDescriptor().GetRegisterParameter(0), info);
1048 __ CallStub(&stub);
1049 } else {
1050 __ Push(info);
1051 __ CallRuntime(pretenure ? Runtime::kNewClosure_Tenured
1052 : Runtime::kNewClosure);
1053 }
1054 context()->Plug(result_register());
1055}
1056
1057void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) {
1058 SetExpressionPosition(prop);
1059 Literal* key = prop->key()->AsLiteral();
1060 DCHECK(!key->value()->IsSmi());
1061 DCHECK(!prop->IsSuperAccess());
1062
1063 __ Move(LoadDescriptor::NameRegister(), key->value());
1064 __ Move(LoadDescriptor::SlotRegister(),
1065 SmiFromSlot(prop->PropertyFeedbackSlot()));
1066 CallLoadIC(NOT_INSIDE_TYPEOF);
1067}
1068
Ben Murdoch097c5b22016-05-18 11:27:45 +01001069void FullCodeGenerator::EmitNamedSuperPropertyLoad(Property* prop) {
1070 // Stack: receiver, home_object
1071 SetExpressionPosition(prop);
1072 Literal* key = prop->key()->AsLiteral();
1073 DCHECK(!key->value()->IsSmi());
1074 DCHECK(prop->IsSuperAccess());
1075
1076 PushOperand(key->value());
1077 CallRuntimeWithOperands(Runtime::kLoadFromSuper);
1078}
1079
1080void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) {
1081 SetExpressionPosition(prop);
1082 Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code();
1083 __ Move(LoadDescriptor::SlotRegister(),
1084 SmiFromSlot(prop->PropertyFeedbackSlot()));
1085 CallIC(ic);
1086}
1087
1088void FullCodeGenerator::EmitKeyedSuperPropertyLoad(Property* prop) {
1089 // Stack: receiver, home_object, key.
1090 SetExpressionPosition(prop);
1091 CallRuntimeWithOperands(Runtime::kLoadKeyedFromSuper);
1092}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001093
1094void FullCodeGenerator::EmitPropertyKey(ObjectLiteralProperty* property,
1095 BailoutId bailout_id) {
1096 VisitForStackValue(property->key());
Ben Murdoch097c5b22016-05-18 11:27:45 +01001097 CallRuntimeWithOperands(Runtime::kToName);
Ben Murdochc5610432016-08-08 18:44:38 +01001098 PrepareForBailoutForId(bailout_id, BailoutState::NO_REGISTERS);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001099 PushOperand(result_register());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001100}
1101
Ben Murdochda12d292016-06-02 14:46:10 +01001102void FullCodeGenerator::EmitLoadStoreICSlot(FeedbackVectorSlot slot) {
1103 DCHECK(!slot.IsInvalid());
1104 __ Move(VectorStoreICTrampolineDescriptor::SlotRegister(), SmiFromSlot(slot));
1105}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001106
1107void FullCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
1108 Comment cmnt(masm_, "[ ReturnStatement");
1109 SetStatementPosition(stmt);
1110 Expression* expr = stmt->expression();
1111 VisitForAccumulatorValue(expr);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001112 EmitUnwindAndReturn();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001113}
1114
1115
1116void FullCodeGenerator::VisitWithStatement(WithStatement* stmt) {
1117 Comment cmnt(masm_, "[ WithStatement");
1118 SetStatementPosition(stmt);
1119
1120 VisitForAccumulatorValue(stmt->expression());
1121 Callable callable = CodeFactory::ToObject(isolate());
1122 __ Move(callable.descriptor().GetRegisterParameter(0), result_register());
1123 __ Call(callable.code(), RelocInfo::CODE_TARGET);
Ben Murdochc5610432016-08-08 18:44:38 +01001124 PrepareForBailoutForId(stmt->ToObjectId(), BailoutState::NO_REGISTERS);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001125 PushOperand(result_register());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001126 PushFunctionArgumentForContextAllocation();
Ben Murdoch097c5b22016-05-18 11:27:45 +01001127 CallRuntimeWithOperands(Runtime::kPushWithContext);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001128 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
Ben Murdochc5610432016-08-08 18:44:38 +01001129 PrepareForBailoutForId(stmt->EntryId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001130
1131 Scope* saved_scope = scope();
1132 scope_ = stmt->scope();
1133 { WithOrCatch body(this);
1134 Visit(stmt->statement());
1135 }
1136 scope_ = saved_scope;
1137
1138 // Pop context.
1139 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
1140 // Update local stack frame context field.
1141 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
1142}
1143
1144
1145void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
1146 Comment cmnt(masm_, "[ DoWhileStatement");
1147 // Do not insert break location as we do that below.
1148 SetStatementPosition(stmt, SKIP_BREAK);
1149
1150 Label body, book_keeping;
1151
1152 Iteration loop_statement(this, stmt);
1153 increment_loop_depth();
1154
1155 __ bind(&body);
1156 Visit(stmt->body());
1157
1158 // Record the position of the do while condition and make sure it is
1159 // possible to break on the condition.
1160 __ bind(loop_statement.continue_label());
Ben Murdochc5610432016-08-08 18:44:38 +01001161 PrepareForBailoutForId(stmt->ContinueId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001162
1163 // Here is the actual 'while' keyword.
1164 SetExpressionAsStatementPosition(stmt->cond());
1165 VisitForControl(stmt->cond(),
1166 &book_keeping,
1167 loop_statement.break_label(),
1168 &book_keeping);
1169
1170 // Check stack before looping.
Ben Murdochc5610432016-08-08 18:44:38 +01001171 PrepareForBailoutForId(stmt->BackEdgeId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001172 __ bind(&book_keeping);
1173 EmitBackEdgeBookkeeping(stmt, &body);
1174 __ jmp(&body);
1175
Ben Murdochc5610432016-08-08 18:44:38 +01001176 PrepareForBailoutForId(stmt->ExitId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001177 __ bind(loop_statement.break_label());
1178 decrement_loop_depth();
1179}
1180
1181
1182void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) {
1183 Comment cmnt(masm_, "[ WhileStatement");
1184 Label loop, body;
1185
1186 Iteration loop_statement(this, stmt);
1187 increment_loop_depth();
1188
1189 __ bind(&loop);
1190
1191 SetExpressionAsStatementPosition(stmt->cond());
1192 VisitForControl(stmt->cond(),
1193 &body,
1194 loop_statement.break_label(),
1195 &body);
1196
Ben Murdochc5610432016-08-08 18:44:38 +01001197 PrepareForBailoutForId(stmt->BodyId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001198 __ bind(&body);
1199 Visit(stmt->body());
1200
1201 __ bind(loop_statement.continue_label());
1202
1203 // Check stack before looping.
1204 EmitBackEdgeBookkeeping(stmt, &loop);
1205 __ jmp(&loop);
1206
Ben Murdochc5610432016-08-08 18:44:38 +01001207 PrepareForBailoutForId(stmt->ExitId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001208 __ bind(loop_statement.break_label());
1209 decrement_loop_depth();
1210}
1211
1212
1213void FullCodeGenerator::VisitForStatement(ForStatement* stmt) {
1214 Comment cmnt(masm_, "[ ForStatement");
1215 // Do not insert break location as we do it below.
1216 SetStatementPosition(stmt, SKIP_BREAK);
1217
1218 Label test, body;
1219
1220 Iteration loop_statement(this, stmt);
1221
1222 if (stmt->init() != NULL) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001223 Visit(stmt->init());
1224 }
1225
1226 increment_loop_depth();
1227 // Emit the test at the bottom of the loop (even if empty).
1228 __ jmp(&test);
1229
Ben Murdochc5610432016-08-08 18:44:38 +01001230 PrepareForBailoutForId(stmt->BodyId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001231 __ bind(&body);
1232 Visit(stmt->body());
1233
Ben Murdochc5610432016-08-08 18:44:38 +01001234 PrepareForBailoutForId(stmt->ContinueId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001235 __ bind(loop_statement.continue_label());
1236 if (stmt->next() != NULL) {
1237 SetStatementPosition(stmt->next());
1238 Visit(stmt->next());
1239 }
1240
1241 // Check stack before looping.
1242 EmitBackEdgeBookkeeping(stmt, &body);
1243
1244 __ bind(&test);
1245 if (stmt->cond() != NULL) {
1246 SetExpressionAsStatementPosition(stmt->cond());
1247 VisitForControl(stmt->cond(),
1248 &body,
1249 loop_statement.break_label(),
1250 loop_statement.break_label());
1251 } else {
1252 __ jmp(&body);
1253 }
1254
Ben Murdochc5610432016-08-08 18:44:38 +01001255 PrepareForBailoutForId(stmt->ExitId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001256 __ bind(loop_statement.break_label());
1257 decrement_loop_depth();
1258}
1259
1260
1261void FullCodeGenerator::VisitForOfStatement(ForOfStatement* stmt) {
1262 Comment cmnt(masm_, "[ ForOfStatement");
1263
1264 Iteration loop_statement(this, stmt);
1265 increment_loop_depth();
1266
1267 // var iterator = iterable[Symbol.iterator]();
Ben Murdochc5610432016-08-08 18:44:38 +01001268 SetExpressionAsStatementPosition(stmt->assign_iterator());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001269 VisitForEffect(stmt->assign_iterator());
1270
1271 // Loop entry.
1272 __ bind(loop_statement.continue_label());
1273
1274 // result = iterator.next()
1275 SetExpressionAsStatementPosition(stmt->next_result());
1276 VisitForEffect(stmt->next_result());
1277
1278 // if (result.done) break;
1279 Label result_not_done;
1280 VisitForControl(stmt->result_done(), loop_statement.break_label(),
1281 &result_not_done, &result_not_done);
1282 __ bind(&result_not_done);
1283
1284 // each = result.value
1285 VisitForEffect(stmt->assign_each());
1286
1287 // Generate code for the body of the loop.
1288 Visit(stmt->body());
1289
1290 // Check stack before looping.
Ben Murdochc5610432016-08-08 18:44:38 +01001291 PrepareForBailoutForId(stmt->BackEdgeId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001292 EmitBackEdgeBookkeeping(stmt, loop_statement.continue_label());
1293 __ jmp(loop_statement.continue_label());
1294
1295 // Exit and decrement the loop depth.
Ben Murdochc5610432016-08-08 18:44:38 +01001296 PrepareForBailoutForId(stmt->ExitId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001297 __ bind(loop_statement.break_label());
1298 decrement_loop_depth();
1299}
1300
Ben Murdochda12d292016-06-02 14:46:10 +01001301void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) {
1302 LoadFromFrameField(JavaScriptFrameConstants::kFunctionOffset,
1303 result_register());
1304 context()->Plug(result_register());
1305}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001306
1307void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
1308 Comment cmnt(masm_, "[ TryCatchStatement");
1309 SetStatementPosition(stmt, SKIP_BREAK);
1310
1311 // The try block adds a handler to the exception handler chain before
1312 // entering, and removes it again when exiting normally. If an exception
1313 // is thrown during execution of the try block, the handler is consumed
1314 // and control is passed to the catch block with the exception in the
1315 // result register.
1316
1317 Label try_entry, handler_entry, exit;
1318 __ jmp(&try_entry);
1319 __ bind(&handler_entry);
Ben Murdochda12d292016-06-02 14:46:10 +01001320 if (stmt->clear_pending_message()) ClearPendingMessage();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001321
1322 // Exception handler code, the exception is in the result register.
1323 // Extend the context before executing the catch block.
1324 { Comment cmnt(masm_, "[ Extend catch context");
Ben Murdoch097c5b22016-05-18 11:27:45 +01001325 PushOperand(stmt->variable()->name());
1326 PushOperand(result_register());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001327 PushFunctionArgumentForContextAllocation();
Ben Murdoch097c5b22016-05-18 11:27:45 +01001328 CallRuntimeWithOperands(Runtime::kPushCatchContext);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001329 StoreToFrameField(StandardFrameConstants::kContextOffset,
1330 context_register());
1331 }
1332
1333 Scope* saved_scope = scope();
1334 scope_ = stmt->scope();
1335 DCHECK(scope_->declarations()->is_empty());
1336 { WithOrCatch catch_body(this);
1337 Visit(stmt->catch_block());
1338 }
1339 // Restore the context.
1340 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
1341 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
1342 scope_ = saved_scope;
1343 __ jmp(&exit);
1344
1345 // Try block code. Sets up the exception handler chain.
1346 __ bind(&try_entry);
1347
1348 try_catch_depth_++;
1349 int handler_index = NewHandlerTableEntry();
1350 EnterTryBlock(handler_index, &handler_entry);
Ben Murdochda12d292016-06-02 14:46:10 +01001351 {
1352 Comment cmnt_try(masm(), "[ Try block");
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001353 Visit(stmt->try_block());
1354 }
1355 ExitTryBlock(handler_index);
1356 try_catch_depth_--;
1357 __ bind(&exit);
1358}
1359
1360
1361void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
1362 Comment cmnt(masm_, "[ TryFinallyStatement");
1363 SetStatementPosition(stmt, SKIP_BREAK);
1364
1365 // Try finally is compiled by setting up a try-handler on the stack while
1366 // executing the try body, and removing it again afterwards.
1367 //
1368 // The try-finally construct can enter the finally block in three ways:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001369 // 1. By exiting the try-block normally. This exits the try block,
1370 // pushes the continuation token and falls through to the finally
1371 // block.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001372 // 2. By exiting the try-block with a function-local control flow transfer
Ben Murdoch097c5b22016-05-18 11:27:45 +01001373 // (break/continue/return). The site of the, e.g., break exits the
1374 // try block, pushes the continuation token and jumps to the
1375 // finally block. After the finally block executes, the execution
1376 // continues based on the continuation token to a block that
1377 // continues with the control flow transfer.
1378 // 3. By exiting the try-block with a thrown exception. In the handler,
1379 // we push the exception and continuation token and jump to the
1380 // finally block (which will again dispatch based on the token once
1381 // it is finished).
1382
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001383 Label try_entry, handler_entry, finally_entry;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001384 DeferredCommands deferred(this, &finally_entry);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001385
1386 // Jump to try-handler setup and try-block code.
1387 __ jmp(&try_entry);
1388 __ bind(&handler_entry);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001389
1390 // Exception handler code. This code is only executed when an exception
Ben Murdoch097c5b22016-05-18 11:27:45 +01001391 // is thrown. Record the continuation and jump to the finally block.
1392 {
Ben Murdochda12d292016-06-02 14:46:10 +01001393 Comment cmnt_handler(masm(), "[ Finally handler");
Ben Murdoch097c5b22016-05-18 11:27:45 +01001394 deferred.RecordThrow();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001395 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001396
1397 // Set up try handler.
1398 __ bind(&try_entry);
1399 int handler_index = NewHandlerTableEntry();
1400 EnterTryBlock(handler_index, &handler_entry);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001401 {
Ben Murdochda12d292016-06-02 14:46:10 +01001402 Comment cmnt_try(masm(), "[ Try block");
Ben Murdoch097c5b22016-05-18 11:27:45 +01001403 TryFinally try_body(this, &deferred);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001404 Visit(stmt->try_block());
1405 }
1406 ExitTryBlock(handler_index);
1407 // Execute the finally block on the way out. Clobber the unpredictable
1408 // value in the result register with one that's safe for GC because the
1409 // finally block will unconditionally preserve the result register on the
1410 // stack.
1411 ClearAccumulator();
Ben Murdoch097c5b22016-05-18 11:27:45 +01001412 deferred.EmitFallThrough();
1413 // Fall through to the finally block.
1414
1415 // Finally block implementation.
1416 __ bind(&finally_entry);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001417 {
Ben Murdochda12d292016-06-02 14:46:10 +01001418 Comment cmnt_finally(masm(), "[ Finally block");
1419 OperandStackDepthIncrement(2); // Token and accumulator are on stack.
1420 EnterFinallyBlock();
Ben Murdoch097c5b22016-05-18 11:27:45 +01001421 Visit(stmt->finally_block());
Ben Murdochda12d292016-06-02 14:46:10 +01001422 ExitFinallyBlock();
1423 OperandStackDepthDecrement(2); // Token and accumulator were on stack.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001424 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01001425
1426 {
1427 Comment cmnt_deferred(masm(), "[ Post-finally dispatch");
1428 deferred.EmitCommands(); // Return to the calling code.
1429 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001430}
1431
1432
1433void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
1434 Comment cmnt(masm_, "[ DebuggerStatement");
1435 SetStatementPosition(stmt);
1436
1437 __ DebugBreak();
1438 // Ignore the return value.
1439
Ben Murdochc5610432016-08-08 18:44:38 +01001440 PrepareForBailoutForId(stmt->DebugBreakId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001441}
1442
1443
1444void FullCodeGenerator::VisitCaseClause(CaseClause* clause) {
1445 UNREACHABLE();
1446}
1447
1448
1449void FullCodeGenerator::VisitConditional(Conditional* expr) {
1450 Comment cmnt(masm_, "[ Conditional");
1451 Label true_case, false_case, done;
1452 VisitForControl(expr->condition(), &true_case, &false_case, &true_case);
1453
Ben Murdoch097c5b22016-05-18 11:27:45 +01001454 int original_stack_depth = operand_stack_depth_;
Ben Murdochc5610432016-08-08 18:44:38 +01001455 PrepareForBailoutForId(expr->ThenId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001456 __ bind(&true_case);
1457 SetExpressionPosition(expr->then_expression());
1458 if (context()->IsTest()) {
1459 const TestContext* for_test = TestContext::cast(context());
1460 VisitForControl(expr->then_expression(),
1461 for_test->true_label(),
1462 for_test->false_label(),
1463 NULL);
1464 } else {
1465 VisitInDuplicateContext(expr->then_expression());
1466 __ jmp(&done);
1467 }
1468
Ben Murdoch097c5b22016-05-18 11:27:45 +01001469 operand_stack_depth_ = original_stack_depth;
Ben Murdochc5610432016-08-08 18:44:38 +01001470 PrepareForBailoutForId(expr->ElseId(), BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001471 __ bind(&false_case);
1472 SetExpressionPosition(expr->else_expression());
1473 VisitInDuplicateContext(expr->else_expression());
1474 // If control flow falls through Visit, merge it with true case here.
1475 if (!context()->IsTest()) {
1476 __ bind(&done);
1477 }
1478}
1479
1480
1481void FullCodeGenerator::VisitLiteral(Literal* expr) {
1482 Comment cmnt(masm_, "[ Literal");
1483 context()->Plug(expr->value());
1484}
1485
1486
1487void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
1488 Comment cmnt(masm_, "[ FunctionLiteral");
1489
1490 // Build the function boilerplate and instantiate it.
1491 Handle<SharedFunctionInfo> function_info =
1492 Compiler::GetSharedFunctionInfo(expr, script(), info_);
1493 if (function_info.is_null()) {
1494 SetStackOverflow();
1495 return;
1496 }
1497 EmitNewClosure(function_info, expr->pretenure());
1498}
1499
1500
1501void FullCodeGenerator::VisitClassLiteral(ClassLiteral* lit) {
1502 Comment cmnt(masm_, "[ ClassLiteral");
1503
1504 {
Ben Murdochda12d292016-06-02 14:46:10 +01001505 NestedClassLiteral nested_class_literal(this, lit);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001506 EnterBlockScopeIfNeeded block_scope_state(
1507 this, lit->scope(), lit->EntryId(), lit->DeclsId(), lit->ExitId());
1508
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001509 if (lit->extends() != NULL) {
1510 VisitForStackValue(lit->extends());
1511 } else {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001512 PushOperand(isolate()->factory()->the_hole_value());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001513 }
1514
1515 VisitForStackValue(lit->constructor());
1516
Ben Murdoch097c5b22016-05-18 11:27:45 +01001517 PushOperand(Smi::FromInt(lit->start_position()));
1518 PushOperand(Smi::FromInt(lit->end_position()));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001519
Ben Murdoch097c5b22016-05-18 11:27:45 +01001520 CallRuntimeWithOperands(Runtime::kDefineClass);
Ben Murdochc5610432016-08-08 18:44:38 +01001521 PrepareForBailoutForId(lit->CreateLiteralId(), BailoutState::TOS_REGISTER);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001522 PushOperand(result_register());
1523
1524 // Load the "prototype" from the constructor.
1525 __ Move(LoadDescriptor::ReceiverRegister(), result_register());
1526 __ LoadRoot(LoadDescriptor::NameRegister(),
1527 Heap::kprototype_stringRootIndex);
1528 __ Move(LoadDescriptor::SlotRegister(), SmiFromSlot(lit->PrototypeSlot()));
1529 CallLoadIC(NOT_INSIDE_TYPEOF);
Ben Murdochc5610432016-08-08 18:44:38 +01001530 PrepareForBailoutForId(lit->PrototypeId(), BailoutState::TOS_REGISTER);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001531 PushOperand(result_register());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001532
1533 EmitClassDefineProperties(lit);
Ben Murdochc5610432016-08-08 18:44:38 +01001534 DropOperands(1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001535
Ben Murdochc5610432016-08-08 18:44:38 +01001536 // Set the constructor to have fast properties.
1537 CallRuntimeWithOperands(Runtime::kToFastProperties);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001538
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001539 if (lit->class_variable_proxy() != nullptr) {
1540 EmitVariableAssignment(lit->class_variable_proxy()->var(), Token::INIT,
1541 lit->ProxySlot());
1542 }
1543 }
1544
1545 context()->Plug(result_register());
1546}
1547
1548
1549void FullCodeGenerator::VisitNativeFunctionLiteral(
1550 NativeFunctionLiteral* expr) {
1551 Comment cmnt(masm_, "[ NativeFunctionLiteral");
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001552 Handle<SharedFunctionInfo> shared =
Ben Murdoch097c5b22016-05-18 11:27:45 +01001553 Compiler::GetSharedFunctionInfoForNative(expr->extension(), expr->name());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001554 EmitNewClosure(shared, false);
1555}
1556
1557
1558void FullCodeGenerator::VisitThrow(Throw* expr) {
1559 Comment cmnt(masm_, "[ Throw");
1560 VisitForStackValue(expr->exception());
1561 SetExpressionPosition(expr);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001562 CallRuntimeWithOperands(Runtime::kThrow);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001563 // Never returns here.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001564
1565 // Even though this expression doesn't produce a value, we need to simulate
1566 // plugging of the value context to ensure stack depth tracking is in sync.
1567 if (context()->IsStackValue()) OperandStackDepthIncrement(1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001568}
1569
1570
1571void FullCodeGenerator::EnterTryBlock(int handler_index, Label* handler) {
1572 HandlerTableEntry* entry = &handler_table_[handler_index];
1573 entry->range_start = masm()->pc_offset();
1574 entry->handler_offset = handler->pos();
1575 entry->try_catch_depth = try_catch_depth_;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001576 entry->stack_depth = operand_stack_depth_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001577
Ben Murdoch097c5b22016-05-18 11:27:45 +01001578 // We are using the operand stack depth, check for accuracy.
1579 EmitOperandStackDepthCheck();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001580
1581 // Push context onto operand stack.
1582 STATIC_ASSERT(TryBlockConstant::kElementCount == 1);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001583 PushOperand(context_register());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001584}
1585
1586
1587void FullCodeGenerator::ExitTryBlock(int handler_index) {
1588 HandlerTableEntry* entry = &handler_table_[handler_index];
1589 entry->range_end = masm()->pc_offset();
1590
1591 // Drop context from operand stack.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001592 DropOperands(TryBlockConstant::kElementCount);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001593}
1594
1595
1596void FullCodeGenerator::VisitCall(Call* expr) {
1597#ifdef DEBUG
1598 // We want to verify that RecordJSReturnSite gets called on all paths
1599 // through this function. Avoid early returns.
1600 expr->return_is_recorded_ = false;
1601#endif
1602
Ben Murdoch097c5b22016-05-18 11:27:45 +01001603 Comment cmnt(masm_, (expr->tail_call_mode() == TailCallMode::kAllow)
1604 ? "[ TailCall"
1605 : "[ Call");
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001606 Expression* callee = expr->expression();
1607 Call::CallType call_type = expr->GetCallType(isolate());
1608
1609 switch (call_type) {
1610 case Call::POSSIBLY_EVAL_CALL:
1611 EmitPossiblyEvalCall(expr);
1612 break;
1613 case Call::GLOBAL_CALL:
1614 EmitCallWithLoadIC(expr);
1615 break;
1616 case Call::LOOKUP_SLOT_CALL:
1617 // Call to a lookup slot (dynamically introduced variable).
1618 PushCalleeAndWithBaseObject(expr);
1619 EmitCall(expr);
1620 break;
1621 case Call::NAMED_PROPERTY_CALL: {
1622 Property* property = callee->AsProperty();
1623 VisitForStackValue(property->obj());
1624 EmitCallWithLoadIC(expr);
1625 break;
1626 }
1627 case Call::KEYED_PROPERTY_CALL: {
1628 Property* property = callee->AsProperty();
1629 VisitForStackValue(property->obj());
1630 EmitKeyedCallWithLoadIC(expr, property->key());
1631 break;
1632 }
1633 case Call::NAMED_SUPER_PROPERTY_CALL:
1634 EmitSuperCallWithLoadIC(expr);
1635 break;
1636 case Call::KEYED_SUPER_PROPERTY_CALL:
1637 EmitKeyedSuperCallWithLoadIC(expr);
1638 break;
1639 case Call::SUPER_CALL:
1640 EmitSuperConstructorCall(expr);
1641 break;
1642 case Call::OTHER_CALL:
1643 // Call to an arbitrary expression not handled specially above.
1644 VisitForStackValue(callee);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001645 OperandStackDepthIncrement(1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001646 __ PushRoot(Heap::kUndefinedValueRootIndex);
1647 // Emit function call.
1648 EmitCall(expr);
1649 break;
1650 }
1651
1652#ifdef DEBUG
1653 // RecordJSReturnSite should have been called.
1654 DCHECK(expr->return_is_recorded_);
1655#endif
1656}
1657
Ben Murdochda12d292016-06-02 14:46:10 +01001658void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
1659 ZoneList<Expression*>* args = expr->arguments();
1660 int arg_count = args->length();
1661
1662 if (expr->is_jsruntime()) {
1663 Comment cmnt(masm_, "[ CallRuntime");
1664 EmitLoadJSRuntimeFunction(expr);
1665
1666 // Push the arguments ("left-to-right").
1667 for (int i = 0; i < arg_count; i++) {
1668 VisitForStackValue(args->at(i));
1669 }
1670
Ben Murdochc5610432016-08-08 18:44:38 +01001671 PrepareForBailoutForId(expr->CallId(), BailoutState::NO_REGISTERS);
Ben Murdochda12d292016-06-02 14:46:10 +01001672 EmitCallJSRuntimeFunction(expr);
1673 context()->DropAndPlug(1, result_register());
1674
1675 } else {
1676 const Runtime::Function* function = expr->function();
1677 switch (function->function_id) {
1678#define CALL_INTRINSIC_GENERATOR(Name) \
1679 case Runtime::kInline##Name: { \
1680 Comment cmnt(masm_, "[ Inline" #Name); \
1681 return Emit##Name(expr); \
1682 }
1683 FOR_EACH_FULL_CODE_INTRINSIC(CALL_INTRINSIC_GENERATOR)
1684#undef CALL_INTRINSIC_GENERATOR
1685 default: {
1686 Comment cmnt(masm_, "[ CallRuntime for unhandled intrinsic");
1687 // Push the arguments ("left-to-right").
1688 for (int i = 0; i < arg_count; i++) {
1689 VisitForStackValue(args->at(i));
1690 }
1691
1692 // Call the C runtime function.
Ben Murdochc5610432016-08-08 18:44:38 +01001693 PrepareForBailoutForId(expr->CallId(), BailoutState::NO_REGISTERS);
Ben Murdochda12d292016-06-02 14:46:10 +01001694 __ CallRuntime(expr->function(), arg_count);
1695 OperandStackDepthDecrement(arg_count);
1696 context()->Plug(result_register());
1697 }
1698 }
1699 }
1700}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001701
1702void FullCodeGenerator::VisitSpread(Spread* expr) { UNREACHABLE(); }
1703
1704
1705void FullCodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) {
1706 UNREACHABLE();
1707}
1708
1709
Ben Murdoch097c5b22016-05-18 11:27:45 +01001710void FullCodeGenerator::VisitRewritableExpression(RewritableExpression* expr) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001711 Visit(expr->expression());
1712}
1713
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001714FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit(
Ben Murdochda12d292016-06-02 14:46:10 +01001715 int* context_length) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001716 // The macros used here must preserve the result register.
1717
Ben Murdochda12d292016-06-02 14:46:10 +01001718 // Calculate how many operands to drop to get down to handler block.
1719 int stack_drop = codegen_->operand_stack_depth_ - GetStackDepthAtTarget();
1720 DCHECK_GE(stack_drop, 0);
1721
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001722 // Because the handler block contains the context of the finally
1723 // code, we can restore it directly from there for the finally code
1724 // rather than iteratively unwinding contexts via their previous
1725 // links.
1726 if (*context_length > 0) {
Ben Murdochda12d292016-06-02 14:46:10 +01001727 __ Drop(stack_drop); // Down to the handler block.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001728 // Restore the context to its dedicated register and the stack.
Ben Murdochda12d292016-06-02 14:46:10 +01001729 STATIC_ASSERT(TryBlockConstant::kElementCount == 1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001730 __ Pop(codegen_->context_register());
1731 codegen_->StoreToFrameField(StandardFrameConstants::kContextOffset,
1732 codegen_->context_register());
1733 } else {
1734 // Down to the handler block and also drop context.
Ben Murdochda12d292016-06-02 14:46:10 +01001735 __ Drop(stack_drop + TryBlockConstant::kElementCount);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001736 }
Ben Murdochda12d292016-06-02 14:46:10 +01001737
1738 // The caller will ignore outputs.
1739 *context_length = -1;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001740 return previous_;
1741}
1742
Ben Murdoch097c5b22016-05-18 11:27:45 +01001743void FullCodeGenerator::DeferredCommands::RecordBreak(Statement* target) {
1744 TokenId token = dispenser_.GetBreakContinueToken();
1745 commands_.push_back({kBreak, token, target});
1746 EmitJumpToFinally(token);
1747}
1748
1749void FullCodeGenerator::DeferredCommands::RecordContinue(Statement* target) {
1750 TokenId token = dispenser_.GetBreakContinueToken();
1751 commands_.push_back({kContinue, token, target});
1752 EmitJumpToFinally(token);
1753}
1754
1755void FullCodeGenerator::DeferredCommands::RecordReturn() {
1756 if (return_token_ == TokenDispenserForFinally::kInvalidToken) {
1757 return_token_ = TokenDispenserForFinally::kReturnToken;
1758 commands_.push_back({kReturn, return_token_, nullptr});
1759 }
1760 EmitJumpToFinally(return_token_);
1761}
1762
1763void FullCodeGenerator::DeferredCommands::RecordThrow() {
1764 if (throw_token_ == TokenDispenserForFinally::kInvalidToken) {
1765 throw_token_ = TokenDispenserForFinally::kThrowToken;
1766 commands_.push_back({kThrow, throw_token_, nullptr});
1767 }
1768 EmitJumpToFinally(throw_token_);
1769}
1770
1771void FullCodeGenerator::DeferredCommands::EmitFallThrough() {
1772 __ Push(Smi::FromInt(TokenDispenserForFinally::kFallThroughToken));
1773 __ Push(result_register());
1774}
1775
1776void FullCodeGenerator::DeferredCommands::EmitJumpToFinally(TokenId token) {
1777 __ Push(Smi::FromInt(token));
1778 __ Push(result_register());
1779 __ jmp(finally_entry_);
1780}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001781
1782bool FullCodeGenerator::TryLiteralCompare(CompareOperation* expr) {
1783 Expression* sub_expr;
1784 Handle<String> check;
1785 if (expr->IsLiteralCompareTypeof(&sub_expr, &check)) {
Ben Murdochc5610432016-08-08 18:44:38 +01001786 SetExpressionPosition(expr);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001787 EmitLiteralCompareTypeof(expr, sub_expr, check);
1788 return true;
1789 }
1790
Ben Murdochda12d292016-06-02 14:46:10 +01001791 if (expr->IsLiteralCompareUndefined(&sub_expr)) {
Ben Murdochc5610432016-08-08 18:44:38 +01001792 SetExpressionPosition(expr);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001793 EmitLiteralCompareNil(expr, sub_expr, kUndefinedValue);
1794 return true;
1795 }
1796
1797 if (expr->IsLiteralCompareNull(&sub_expr)) {
Ben Murdochc5610432016-08-08 18:44:38 +01001798 SetExpressionPosition(expr);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001799 EmitLiteralCompareNil(expr, sub_expr, kNullValue);
1800 return true;
1801 }
1802
1803 return false;
1804}
1805
1806
1807void BackEdgeTable::Patch(Isolate* isolate, Code* unoptimized) {
1808 DisallowHeapAllocation no_gc;
1809 Code* patch = isolate->builtins()->builtin(Builtins::kOnStackReplacement);
1810
1811 // Increment loop nesting level by one and iterate over the back edge table
1812 // to find the matching loops to patch the interrupt
1813 // call to an unconditional call to the replacement code.
1814 int loop_nesting_level = unoptimized->allow_osr_at_loop_nesting_level() + 1;
1815 if (loop_nesting_level > Code::kMaxLoopNestingMarker) return;
1816
1817 BackEdgeTable back_edges(unoptimized, &no_gc);
1818 for (uint32_t i = 0; i < back_edges.length(); i++) {
1819 if (static_cast<int>(back_edges.loop_depth(i)) == loop_nesting_level) {
1820 DCHECK_EQ(INTERRUPT, GetBackEdgeState(isolate,
1821 unoptimized,
1822 back_edges.pc(i)));
1823 PatchAt(unoptimized, back_edges.pc(i), ON_STACK_REPLACEMENT, patch);
1824 }
1825 }
1826
1827 unoptimized->set_allow_osr_at_loop_nesting_level(loop_nesting_level);
1828 DCHECK(Verify(isolate, unoptimized));
1829}
1830
1831
1832void BackEdgeTable::Revert(Isolate* isolate, Code* unoptimized) {
1833 DisallowHeapAllocation no_gc;
1834 Code* patch = isolate->builtins()->builtin(Builtins::kInterruptCheck);
1835
1836 // Iterate over the back edge table and revert the patched interrupt calls.
1837 int loop_nesting_level = unoptimized->allow_osr_at_loop_nesting_level();
1838
1839 BackEdgeTable back_edges(unoptimized, &no_gc);
1840 for (uint32_t i = 0; i < back_edges.length(); i++) {
1841 if (static_cast<int>(back_edges.loop_depth(i)) <= loop_nesting_level) {
1842 DCHECK_NE(INTERRUPT, GetBackEdgeState(isolate,
1843 unoptimized,
1844 back_edges.pc(i)));
1845 PatchAt(unoptimized, back_edges.pc(i), INTERRUPT, patch);
1846 }
1847 }
1848
1849 unoptimized->set_allow_osr_at_loop_nesting_level(0);
1850 // Assert that none of the back edges are patched anymore.
1851 DCHECK(Verify(isolate, unoptimized));
1852}
1853
1854
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001855#ifdef DEBUG
1856bool BackEdgeTable::Verify(Isolate* isolate, Code* unoptimized) {
1857 DisallowHeapAllocation no_gc;
1858 int loop_nesting_level = unoptimized->allow_osr_at_loop_nesting_level();
1859 BackEdgeTable back_edges(unoptimized, &no_gc);
1860 for (uint32_t i = 0; i < back_edges.length(); i++) {
1861 uint32_t loop_depth = back_edges.loop_depth(i);
1862 CHECK_LE(static_cast<int>(loop_depth), Code::kMaxLoopNestingMarker);
1863 // Assert that all back edges for shallower loops (and only those)
1864 // have already been patched.
1865 CHECK_EQ((static_cast<int>(loop_depth) <= loop_nesting_level),
1866 GetBackEdgeState(isolate,
1867 unoptimized,
1868 back_edges.pc(i)) != INTERRUPT);
1869 }
1870 return true;
1871}
1872#endif // DEBUG
1873
1874
1875FullCodeGenerator::EnterBlockScopeIfNeeded::EnterBlockScopeIfNeeded(
1876 FullCodeGenerator* codegen, Scope* scope, BailoutId entry_id,
1877 BailoutId declarations_id, BailoutId exit_id)
1878 : codegen_(codegen), exit_id_(exit_id) {
1879 saved_scope_ = codegen_->scope();
1880
1881 if (scope == NULL) {
Ben Murdochc5610432016-08-08 18:44:38 +01001882 codegen_->PrepareForBailoutForId(entry_id, BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001883 needs_block_context_ = false;
1884 } else {
1885 needs_block_context_ = scope->NeedsContext();
1886 codegen_->scope_ = scope;
1887 {
1888 if (needs_block_context_) {
1889 Comment cmnt(masm(), "[ Extend block context");
Ben Murdoch097c5b22016-05-18 11:27:45 +01001890 codegen_->PushOperand(scope->GetScopeInfo(codegen->isolate()));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001891 codegen_->PushFunctionArgumentForContextAllocation();
Ben Murdoch097c5b22016-05-18 11:27:45 +01001892 codegen_->CallRuntimeWithOperands(Runtime::kPushBlockContext);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001893
1894 // Replace the context stored in the frame.
1895 codegen_->StoreToFrameField(StandardFrameConstants::kContextOffset,
1896 codegen_->context_register());
1897 }
1898 CHECK_EQ(0, scope->num_stack_slots());
Ben Murdochc5610432016-08-08 18:44:38 +01001899 codegen_->PrepareForBailoutForId(entry_id, BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001900 }
1901 {
1902 Comment cmnt(masm(), "[ Declarations");
1903 codegen_->VisitDeclarations(scope->declarations());
Ben Murdochc5610432016-08-08 18:44:38 +01001904 codegen_->PrepareForBailoutForId(declarations_id,
1905 BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001906 }
1907 }
1908}
1909
1910
1911FullCodeGenerator::EnterBlockScopeIfNeeded::~EnterBlockScopeIfNeeded() {
1912 if (needs_block_context_) {
1913 codegen_->LoadContextField(codegen_->context_register(),
1914 Context::PREVIOUS_INDEX);
1915 // Update local stack frame context field.
1916 codegen_->StoreToFrameField(StandardFrameConstants::kContextOffset,
1917 codegen_->context_register());
1918 }
Ben Murdochc5610432016-08-08 18:44:38 +01001919 codegen_->PrepareForBailoutForId(exit_id_, BailoutState::NO_REGISTERS);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001920 codegen_->scope_ = saved_scope_;
1921}
1922
1923
1924bool FullCodeGenerator::NeedsHoleCheckForLoad(VariableProxy* proxy) {
1925 Variable* var = proxy->var();
1926
1927 if (!var->binding_needs_init()) {
1928 return false;
1929 }
1930
1931 // var->scope() may be NULL when the proxy is located in eval code and
1932 // refers to a potential outside binding. Currently those bindings are
1933 // always looked up dynamically, i.e. in that case
1934 // var->location() == LOOKUP.
1935 // always holds.
1936 DCHECK(var->scope() != NULL);
1937 DCHECK(var->location() == VariableLocation::PARAMETER ||
1938 var->location() == VariableLocation::LOCAL ||
1939 var->location() == VariableLocation::CONTEXT);
1940
1941 // Check if the binding really needs an initialization check. The check
1942 // can be skipped in the following situation: we have a LET or CONST
1943 // binding in harmony mode, both the Variable and the VariableProxy have
1944 // the same declaration scope (i.e. they are both in global code, in the
1945 // same function or in the same eval code), the VariableProxy is in
1946 // the source physically located after the initializer of the variable,
1947 // and that the initializer cannot be skipped due to a nonlinear scope.
1948 //
1949 // We cannot skip any initialization checks for CONST in non-harmony
1950 // mode because const variables may be declared but never initialized:
1951 // if (false) { const x; }; var y = x;
1952 //
1953 // The condition on the declaration scopes is a conservative check for
1954 // nested functions that access a binding and are called before the
1955 // binding is initialized:
1956 // function() { f(); let x = 1; function f() { x = 2; } }
1957 //
1958 // The check cannot be skipped on non-linear scopes, namely switch
1959 // scopes, to ensure tests are done in cases like the following:
1960 // switch (1) { case 0: let x = 2; case 1: f(x); }
1961 // The scope of the variable needs to be checked, in case the use is
1962 // in a sub-block which may be linear.
1963 if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) {
1964 return true;
1965 }
1966
1967 if (var->is_this()) {
1968 DCHECK(literal() != nullptr &&
1969 (literal()->kind() & kSubclassConstructor) != 0);
1970 // TODO(littledan): implement 'this' hole check elimination.
1971 return true;
1972 }
1973
1974 // Check that we always have valid source position.
1975 DCHECK(var->initializer_position() != RelocInfo::kNoPosition);
1976 DCHECK(proxy->position() != RelocInfo::kNoPosition);
1977
Ben Murdochc5610432016-08-08 18:44:38 +01001978 return var->scope()->is_nonlinear() ||
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001979 var->initializer_position() >= proxy->position();
1980}
1981
1982
1983#undef __
1984
1985
1986} // namespace internal
1987} // namespace v8