V8 Project
hydrogen-osr.cc
Go to the documentation of this file.
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/hydrogen.h"
6 #include "src/hydrogen-osr.h"
7 
8 namespace v8 {
9 namespace internal {
10 
11 // True iff. we are compiling for OSR and the statement is the entry.
13  return statement->OsrEntryId() == builder_->current_info()->osr_ast_id();
14 }
15 
16 
18  DCHECK(HasOsrEntryAt(statement));
19 
20  Zone* zone = builder_->zone();
21  HGraph* graph = builder_->graph();
22 
23  // only one OSR point per compile is allowed.
24  DCHECK(graph->osr() == NULL);
25 
26  // remember this builder as the one OSR builder in the graph.
27  graph->set_osr(this);
28 
29  HBasicBlock* non_osr_entry = graph->CreateBasicBlock();
30  osr_entry_ = graph->CreateBasicBlock();
31  HValue* true_value = graph->GetConstantTrue();
32  HBranch* test = builder_->New<HBranch>(true_value, ToBooleanStub::Types(),
33  non_osr_entry, osr_entry_);
35 
36  HBasicBlock* loop_predecessor = graph->CreateBasicBlock();
37  builder_->Goto(non_osr_entry, loop_predecessor);
38 
40  osr_entry_->set_osr_entry();
41  BailoutId osr_entry_id = statement->OsrEntryId();
42 
43  HEnvironment *environment = builder_->environment();
44  int first_expression_index = environment->first_expression_index();
45  int length = environment->length();
46  osr_values_ = new(zone) ZoneList<HUnknownOSRValue*>(length, zone);
47 
48  for (int i = 0; i < first_expression_index; ++i) {
49  HUnknownOSRValue* osr_value
50  = builder_->Add<HUnknownOSRValue>(environment, i);
51  environment->Bind(i, osr_value);
52  osr_values_->Add(osr_value, zone);
53  }
54 
55  if (first_expression_index != length) {
56  environment->Drop(length - first_expression_index);
57  for (int i = first_expression_index; i < length; ++i) {
58  HUnknownOSRValue* osr_value
59  = builder_->Add<HUnknownOSRValue>(environment, i);
60  environment->Push(osr_value);
61  osr_values_->Add(osr_value, zone);
62  }
63  }
64 
66  environment->local_count() + environment->push_count();
67 
68  // Keep a copy of the old environment, since the OSR values need it
69  // to figure out where exactly they are located in the unoptimized frame.
70  environment = environment->Copy();
71  builder_->current_block()->UpdateEnvironment(environment);
72 
73  builder_->Add<HSimulate>(osr_entry_id);
74  builder_->Add<HOsrEntry>(osr_entry_id);
75  HContext* context = builder_->Add<HContext>();
76  environment->BindContext(context);
77  builder_->Goto(loop_predecessor);
78  loop_predecessor->SetJoinId(statement->EntryId());
79  builder_->set_current_block(loop_predecessor);
80 
81  // Create the final loop entry
83  return osr_loop_entry_;
84 }
85 
86 
88  // do nothing for now.
89 }
90 
91 
93  const ZoneList<HPhi*>* phis = osr_loop_entry_->phis();
94  for (int j = 0; j < phis->length(); j++) {
95  HPhi* phi = phis->at(j);
96  if (phi->HasMergedIndex()) {
97  osr_values_->at(phi->merged_index())->set_incoming_value(phi);
98  }
99  }
100 }
101 
102 } } // namespace v8::internal
BailoutId EntryId() const
Definition: ast.h:425
BailoutId osr_ast_id() const
Definition: compiler.h:128
HEnvironment * environment() const
Definition: hydrogen.h:1059
void set_current_block(HBasicBlock *block)
Definition: hydrogen.h:1058
void Goto(HBasicBlock *from, HBasicBlock *target, FunctionState *state=NULL, bool add_simulate=true)
Definition: hydrogen.h:1080
HGraph * graph() const
Definition: hydrogen.h:1063
HBasicBlock * current_block() const
Definition: hydrogen.h:1057
void FinishCurrentBlock(HControlInstruction *last)
Definition: hydrogen.cc:1198
CompilationInfo * current_info() const
Definition: hydrogen.h:2167
HBasicBlock * BuildOsrLoopEntry(IterationStatement *statement)
Definition: hydrogen-osr.cc:17
HBasicBlock * osr_loop_entry_
Definition: hydrogen-osr.h:48
HBasicBlock * osr_entry_
Definition: hydrogen-osr.h:47
HOptimizedGraphBuilder * builder_
Definition: hydrogen-osr.h:46
ZoneList< HUnknownOSRValue * > * osr_values_
Definition: hydrogen-osr.h:49
bool HasOsrEntryAt(IterationStatement *statement)
Definition: hydrogen-osr.cc:12
BailoutId OsrEntryId() const
Definition: ast.h:734
void Add(const T &element, AllocationPolicy allocator=AllocationPolicy())
Definition: list-inl.h:17
T & at(int i) const
Definition: list.h:69
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK(condition)
Definition: logging.h:205
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20