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

Side by Side Diff: src/crankshaft/hydrogen.cc

Issue 1872483002: [compiler] Make OptimizedCompileJob agnostic from backend. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Prevent endless recompile. Created 4 years, 8 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
« no previous file with comments | « src/crankshaft/hydrogen.h ('k') | src/crankshaft/lithium-codegen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/crankshaft/hydrogen.h" 5 #include "src/crankshaft/hydrogen.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "src/allocation-site-scopes.h" 9 #include "src/allocation-site-scopes.h"
10 #include "src/ast/ast-numbering.h" 10 #include "src/ast/ast-numbering.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "src/crankshaft/s390/lithium-codegen-s390.h" // NOLINT 61 #include "src/crankshaft/s390/lithium-codegen-s390.h" // NOLINT
62 #elif V8_TARGET_ARCH_X87 62 #elif V8_TARGET_ARCH_X87
63 #include "src/crankshaft/x87/lithium-codegen-x87.h" // NOLINT 63 #include "src/crankshaft/x87/lithium-codegen-x87.h" // NOLINT
64 #else 64 #else
65 #error Unsupported target architecture. 65 #error Unsupported target architecture.
66 #endif 66 #endif
67 67
68 namespace v8 { 68 namespace v8 {
69 namespace internal { 69 namespace internal {
70 70
71 class HOptimizedGraphBuilderWithPositions : public HOptimizedGraphBuilder {
72 public:
73 explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info)
74 : HOptimizedGraphBuilder(info) {}
75
76 #define DEF_VISIT(type) \
77 void Visit##type(type* node) override { \
78 SourcePosition old_position = SourcePosition::Unknown(); \
79 if (node->position() != RelocInfo::kNoPosition) { \
80 old_position = source_position(); \
81 SetSourcePosition(node->position()); \
82 } \
83 HOptimizedGraphBuilder::Visit##type(node); \
84 if (!old_position.IsUnknown()) { \
85 set_source_position(old_position); \
86 } \
87 }
88 EXPRESSION_NODE_LIST(DEF_VISIT)
89 #undef DEF_VISIT
90
91 #define DEF_VISIT(type) \
92 void Visit##type(type* node) override { \
93 SourcePosition old_position = SourcePosition::Unknown(); \
94 if (node->position() != RelocInfo::kNoPosition) { \
95 old_position = source_position(); \
96 SetSourcePosition(node->position()); \
97 } \
98 HOptimizedGraphBuilder::Visit##type(node); \
99 if (!old_position.IsUnknown()) { \
100 set_source_position(old_position); \
101 } \
102 }
103 STATEMENT_NODE_LIST(DEF_VISIT)
104 #undef DEF_VISIT
105
106 #define DEF_VISIT(type) \
107 void Visit##type(type* node) override { \
108 HOptimizedGraphBuilder::Visit##type(node); \
109 }
110 DECLARATION_NODE_LIST(DEF_VISIT)
111 #undef DEF_VISIT
112 };
113
114 HCompilationJob::Status HCompilationJob::CreateGraphImpl() {
115 bool dont_crankshaft = info()->shared_info()->dont_crankshaft();
116
117 if (!isolate()->use_crankshaft() || dont_crankshaft) {
118 // Crankshaft is entirely disabled.
119 return FAILED;
120 }
121
122 Scope* scope = info()->scope();
123 if (LUnallocated::TooManyParameters(scope->num_parameters())) {
124 // Crankshaft would require too many Lithium operands.
125 return AbortOptimization(kTooManyParameters);
126 }
127
128 if (info()->is_osr() &&
129 LUnallocated::TooManyParametersOrStackSlots(scope->num_parameters(),
130 scope->num_stack_slots())) {
131 // Crankshaft would require too many Lithium operands.
132 return AbortOptimization(kTooManyParametersLocals);
133 }
134
135 if (FLAG_trace_opt) {
136 OFStream os(stdout);
137 os << "[compiling method " << Brief(*info()->closure())
138 << " using Crankshaft";
139 if (info()->is_osr()) os << " OSR";
140 os << "]" << std::endl;
141 }
142
143 if (FLAG_trace_hydrogen) {
144 isolate()->GetHTracer()->TraceCompilation(info());
145 }
146
147 // Type-check the function.
148 AstTyper(info()->isolate(), info()->zone(), info()->closure(),
149 info()->scope(), info()->osr_ast_id(), info()->literal())
150 .Run();
151
152 // Optimization could have been disabled by the parser. Note that this check
153 // is only needed because the Hydrogen graph builder is missing some bailouts.
154 if (info()->shared_info()->optimization_disabled()) {
155 return AbortOptimization(
156 info()->shared_info()->disable_optimization_reason());
157 }
158
159 HOptimizedGraphBuilder* graph_builder =
160 (info()->is_tracking_positions() || FLAG_trace_ic)
161 ? new (info()->zone()) HOptimizedGraphBuilderWithPositions(info())
162 : new (info()->zone()) HOptimizedGraphBuilder(info());
163
164 graph_ = graph_builder->CreateGraph();
165
166 if (isolate()->has_pending_exception()) {
167 return FAILED;
168 }
169
170 if (graph_ == NULL) return BAILED_OUT;
171
172 if (info()->dependencies()->HasAborted()) {
173 // Dependency has changed during graph creation. Let's try again later.
174 return RetryOptimization(kBailedOutDueToDependencyChange);
175 }
176
177 return SUCCEEDED;
178 }
179
180 HCompilationJob::Status HCompilationJob::OptimizeGraphImpl() {
181 DCHECK(graph_ != NULL);
182 BailoutReason bailout_reason = kNoReason;
183
184 if (graph_->Optimize(&bailout_reason)) {
185 chunk_ = LChunk::NewChunk(graph_);
186 if (chunk_ != NULL) return SUCCEEDED;
187 } else if (bailout_reason != kNoReason) {
188 info()->AbortOptimization(bailout_reason);
189 }
190
191 return BAILED_OUT;
192 }
193
194 HCompilationJob::Status HCompilationJob::GenerateCodeImpl() {
195 DCHECK(chunk_ != NULL);
196 DCHECK(graph_ != NULL);
197 {
198 // Deferred handles reference objects that were accessible during
199 // graph creation. To make sure that we don't encounter inconsistencies
200 // between graph creation and code generation, we disallow accessing
201 // objects through deferred handles during the latter, with exceptions.
202 DisallowDeferredHandleDereference no_deferred_handle_deref;
203 Handle<Code> optimized_code = chunk_->Codegen();
204 if (optimized_code.is_null()) {
205 if (info()->bailout_reason() == kNoReason) {
206 return AbortOptimization(kCodeGenerationFailed);
207 }
208 return BAILED_OUT;
209 }
210 RegisterWeakObjectsInOptimizedCode(optimized_code);
211 info()->SetCode(optimized_code);
212 }
213 // Add to the weak list of optimized code objects.
214 info()->context()->native_context()->AddOptimizedCode(*info()->code());
215 return SUCCEEDED;
216 }
217
71 HBasicBlock::HBasicBlock(HGraph* graph) 218 HBasicBlock::HBasicBlock(HGraph* graph)
72 : block_id_(graph->GetNextBlockID()), 219 : block_id_(graph->GetNextBlockID()),
73 graph_(graph), 220 graph_(graph),
74 phis_(4, graph->zone()), 221 phis_(4, graph->zone()),
75 first_(NULL), 222 first_(NULL),
76 last_(NULL), 223 last_(NULL),
77 end_(NULL), 224 end_(NULL),
78 loop_information_(NULL), 225 loop_information_(NULL),
79 predecessors_(2, graph->zone()), 226 predecessors_(2, graph->zone()),
80 dominator_(NULL), 227 dominator_(NULL),
(...skipping 13499 matching lines...) Expand 10 before | Expand all | Expand 10 after
13580 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 13727 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
13581 } 13728 }
13582 13729
13583 #ifdef DEBUG 13730 #ifdef DEBUG
13584 graph_->Verify(false); // No full verify. 13731 graph_->Verify(false); // No full verify.
13585 #endif 13732 #endif
13586 } 13733 }
13587 13734
13588 } // namespace internal 13735 } // namespace internal
13589 } // namespace v8 13736 } // namespace v8
OLDNEW
« no previous file with comments | « src/crankshaft/hydrogen.h ('k') | src/crankshaft/lithium-codegen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698