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

Side by Side Diff: src/hydrogen-osr.cc

Issue 18496002: Factor out OSR-related graph-building functionality from hydrogen.cc. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
30 namespace v8 {
31 namespace internal {
32
33 // True iff. we are compiling for OSR and the statement is the entry.
34 bool HOsrBuilder::HasOsrEntryAt(IterationStatement* statement) {
35 return statement->OsrEntryId() == builder_->current_info()->osr_ast_id();
36 }
37
38
39 // Build a new loop header block and set it as the current block.
40 HBasicBlock *HOsrBuilder::BuildLoopEntry() {
41 HBasicBlock* loop_entry = builder_->CreateLoopHeaderBlock();
42 builder_->current_block()->Goto(loop_entry);
43 builder_->set_current_block(loop_entry);
44 return loop_entry;
45 }
46
47
48 HBasicBlock* HOsrBuilder::BuildPossibleOsrLoopEntry(
49 IterationStatement* statement) {
50 // Check if there is an OSR here first.
51 if (!HasOsrEntryAt(statement)) return BuildLoopEntry();
52
53 Zone* zone = builder_->zone();
54 HGraph* graph = builder_->graph();
55
56 // only one OSR point per compile is allowed.
57 ASSERT(graph->osr() == NULL);
58
59 // remember this builder as the one OSR builder in the graph.
60 graph->set_osr(this);
61
62 HBasicBlock* non_osr_entry = graph->CreateBasicBlock();
63 osr_entry_ = graph->CreateBasicBlock();
64 HValue* true_value = graph->GetConstantTrue();
65 HBranch* test = new(zone) HBranch(true_value, non_osr_entry, osr_entry_);
66 builder_->current_block()->Finish(test);
67
68 HBasicBlock* loop_predecessor = graph->CreateBasicBlock();
69 non_osr_entry->Goto(loop_predecessor);
70
71 builder_->set_current_block(osr_entry_);
72 osr_entry_->set_osr_entry();
73 BailoutId osr_entry_id = statement->OsrEntryId();
74
75 HEnvironment *environment = builder_->environment();
76 int first_expression_index = environment->first_expression_index();
77 int length = environment->length();
78 osr_values_ = new(zone) ZoneList<HUnknownOSRValue*>(length, zone);
79
80 for (int i = 0; i < first_expression_index; ++i) {
81 HUnknownOSRValue* osr_value = builder_->Add<HUnknownOSRValue>();
82 environment->Bind(i, osr_value);
83 osr_values_->Add(osr_value, zone);
84 }
85
86 if (first_expression_index != length) {
87 environment->Drop(length - first_expression_index);
88 for (int i = first_expression_index; i < length; ++i) {
89 HUnknownOSRValue* osr_value = builder_->Add<HUnknownOSRValue>();
90 environment->Push(osr_value);
91 osr_values_->Add(osr_value, zone);
92 }
93 }
94
95 builder_->AddSimulate(osr_entry_id);
96 builder_->Add<HOsrEntry>(osr_entry_id);
97 HContext* context = builder_->Add<HContext>();
98 environment->BindContext(context);
99 builder_->current_block()->Goto(loop_predecessor);
100 loop_predecessor->SetJoinId(statement->EntryId());
101 builder_->set_current_block(loop_predecessor);
102
103 // Create the final loop entry
104 osr_loop_entry_ = BuildLoopEntry();
105 return osr_loop_entry_;
106 }
107
108
109 void HOsrBuilder::FinishGraph() {
110 // do nothing for now.
111 }
112
113
114 void HOsrBuilder::FinishOsrValues() {
115 const ZoneList<HPhi*>* phis = osr_loop_entry_->phis();
116 for (int j = 0; j < phis->length(); j++) {
117 HPhi* phi = phis->at(j);
118 osr_values_->at(phi->merged_index())->set_incoming_value(phi);
119 }
120 }
121
122 } } // namespace v8::internal
OLDNEW
« src/hydrogen.h ('K') | « src/hydrogen.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698