v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hydrogen-osr.cc
Go to the documentation of this file.
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #include "hydrogen.h"
29 #include "hydrogen-osr.h"
30 
31 namespace v8 {
32 namespace internal {
33 
34 // True iff. we are compiling for OSR and the statement is the entry.
36  return statement->OsrEntryId() == builder_->current_info()->osr_ast_id();
37 }
38 
39 
41  ASSERT(HasOsrEntryAt(statement));
42 
43  Zone* zone = builder_->zone();
44  HGraph* graph = builder_->graph();
45 
46  // only one OSR point per compile is allowed.
47  ASSERT(graph->osr() == NULL);
48 
49  // remember this builder as the one OSR builder in the graph.
50  graph->set_osr(this);
51 
52  HBasicBlock* non_osr_entry = graph->CreateBasicBlock();
53  osr_entry_ = graph->CreateBasicBlock();
54  HValue* true_value = graph->GetConstantTrue();
55  HBranch* test = builder_->New<HBranch>(true_value, ToBooleanStub::Types(),
56  non_osr_entry, osr_entry_);
57  builder_->FinishCurrentBlock(test);
58 
59  HBasicBlock* loop_predecessor = graph->CreateBasicBlock();
60  builder_->Goto(non_osr_entry, loop_predecessor);
61 
62  builder_->set_current_block(osr_entry_);
63  osr_entry_->set_osr_entry();
64  BailoutId osr_entry_id = statement->OsrEntryId();
65 
66  HEnvironment *environment = builder_->environment();
67  int first_expression_index = environment->first_expression_index();
68  int length = environment->length();
69  osr_values_ = new(zone) ZoneList<HUnknownOSRValue*>(length, zone);
70 
71  for (int i = 0; i < first_expression_index; ++i) {
72  HUnknownOSRValue* osr_value
73  = builder_->Add<HUnknownOSRValue>(environment, i);
74  environment->Bind(i, osr_value);
75  osr_values_->Add(osr_value, zone);
76  }
77 
78  if (first_expression_index != length) {
79  environment->Drop(length - first_expression_index);
80  for (int i = first_expression_index; i < length; ++i) {
81  HUnknownOSRValue* osr_value
82  = builder_->Add<HUnknownOSRValue>(environment, i);
83  environment->Push(osr_value);
84  osr_values_->Add(osr_value, zone);
85  }
86  }
87 
88  unoptimized_frame_slots_ =
89  environment->local_count() + environment->push_count();
90 
91  // Keep a copy of the old environment, since the OSR values need it
92  // to figure out where exactly they are located in the unoptimized frame.
93  environment = environment->Copy();
94  builder_->current_block()->UpdateEnvironment(environment);
95 
96  builder_->Add<HSimulate>(osr_entry_id);
97  builder_->Add<HOsrEntry>(osr_entry_id);
98  HContext* context = builder_->Add<HContext>();
99  environment->BindContext(context);
100  builder_->Goto(loop_predecessor);
101  loop_predecessor->SetJoinId(statement->EntryId());
102  builder_->set_current_block(loop_predecessor);
103 
104  // Create the final loop entry
105  osr_loop_entry_ = builder_->BuildLoopEntry();
106  return osr_loop_entry_;
107 }
108 
109 
111  // do nothing for now.
112 }
113 
114 
116  const ZoneList<HPhi*>* phis = osr_loop_entry_->phis();
117  for (int j = 0; j < phis->length(); j++) {
118  HPhi* phi = phis->at(j);
119  if (phi->HasMergedIndex()) {
120  osr_values_->at(phi->merged_index())->set_incoming_value(phi);
121  }
122  }
123 }
124 
125 } } // namespace v8::internal
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
Definition: flags.cc:269
T & at(int i) const
Definition: list.h:90
#define ASSERT(condition)
Definition: checks.h:329
HBasicBlock * current_block() const
Definition: hydrogen.h:1066
HEnvironment * environment() const
Definition: hydrogen.h:1068
CompilationInfo * current_info() const
Definition: hydrogen.h:2103
BailoutId osr_ast_id() const
Definition: compiler.h:91
void set_current_block(HBasicBlock *block)
Definition: hydrogen.h:1067
BailoutId OsrEntryId() const
Definition: ast.h:734
HBasicBlock * BuildOsrLoopEntry(IterationStatement *statement)
Definition: hydrogen-osr.cc:40
bool HasOsrEntryAt(IterationStatement *statement)
Definition: hydrogen-osr.cc:35
void Add(const T &element, AllocationPolicy allocator=AllocationPolicy())
Definition: list-inl.h:39
BailoutId EntryId() const
Definition: ast.h:421
void FinishCurrentBlock(HControlInstruction *last)
Definition: hydrogen.cc:1193
HGraph * graph() const
Definition: hydrogen.h:1072
void Goto(HBasicBlock *from, HBasicBlock *target, FunctionState *state=NULL, bool add_simulate=true)
Definition: hydrogen.h:1089
Zone * zone() const
Definition: hydrogen.h:1071