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

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 2007113004: [wasm] Delay throwing an error until the sequential phase of the compilation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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/compiler/wasm-compiler.h ('k') | src/wasm/wasm-module.cc » ('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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/compiler/wasm-compiler.h" 5 #include "src/compiler/wasm-compiler.h"
6 6
7 #include "src/isolate-inl.h" 7 #include "src/isolate-inl.h"
8 8
9 #include "src/base/platform/elapsed-timer.h" 9 #include "src/base/platform/elapsed-timer.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 3105 matching lines...) Expand 10 before | Expand all | Expand 10 after
3116 if (debugging) { 3116 if (debugging) {
3117 buffer.Dispose(); 3117 buffer.Dispose();
3118 } 3118 }
3119 3119
3120 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", 0, 3120 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", 0,
3121 module_name); 3121 module_name);
3122 } 3122 }
3123 return code; 3123 return code;
3124 } 3124 }
3125 3125
3126 std::pair<JSGraph*, SourcePositionTable*> BuildGraphForWasmFunction( 3126 SourcePositionTable* WasmCompilationUnit::BuildGraphForWasmFunction(
3127 JSGraph* jsgraph, wasm::ErrorThrower* thrower, Isolate* isolate,
3128 wasm::ModuleEnv*& module_env, const wasm::WasmFunction* function,
3129 double* decode_ms) { 3127 double* decode_ms) {
3130 base::ElapsedTimer decode_timer; 3128 base::ElapsedTimer decode_timer;
3131 if (FLAG_trace_wasm_decode_time) { 3129 if (FLAG_trace_wasm_decode_time) {
3132 decode_timer.Start(); 3130 decode_timer.Start();
3133 } 3131 }
3134 // Create a TF graph during decoding. 3132 // Create a TF graph during decoding.
3135 3133
3136 Graph* graph = jsgraph->graph(); 3134 Graph* graph = jsgraph_->graph();
3137 CommonOperatorBuilder* common = jsgraph->common(); 3135 CommonOperatorBuilder* common = jsgraph_->common();
3138 MachineOperatorBuilder* machine = jsgraph->machine(); 3136 MachineOperatorBuilder* machine = jsgraph_->machine();
3139 SourcePositionTable* source_position_table = 3137 SourcePositionTable* source_position_table =
3140 new (jsgraph->zone()) SourcePositionTable(graph); 3138 new (jsgraph_->zone()) SourcePositionTable(graph);
3141 WasmGraphBuilder builder(jsgraph->zone(), jsgraph, function->sig, 3139 WasmGraphBuilder builder(jsgraph_->zone(), jsgraph_, function_->sig,
3142 source_position_table); 3140 source_position_table);
3143 wasm::FunctionBody body = { 3141 wasm::FunctionBody body = {
3144 module_env, function->sig, module_env->module->module_start, 3142 module_env_, function_->sig, module_env_->module->module_start,
3145 module_env->module->module_start + function->code_start_offset, 3143 module_env_->module->module_start + function_->code_start_offset,
3146 module_env->module->module_start + function->code_end_offset}; 3144 module_env_->module->module_start + function_->code_end_offset};
3147 wasm::TreeResult result = 3145 graph_construction_result_ =
3148 wasm::BuildTFGraph(isolate->allocator(), &builder, body); 3146 wasm::BuildTFGraph(isolate_->allocator(), &builder, body);
3147
3148 if (graph_construction_result_.failed()) {
3149 if (FLAG_trace_wasm_compiler) {
3150 OFStream os(stdout);
3151 os << "Compilation failed: " << graph_construction_result_ << std::endl;
3152 }
3153 return nullptr;
3154 }
3149 3155
3150 if (machine->Is32()) { 3156 if (machine->Is32()) {
3151 Int64Lowering r(graph, machine, common, jsgraph->zone(), function->sig); 3157 Int64Lowering r(graph, machine, common, jsgraph_->zone(), function_->sig);
3152 r.LowerGraph(); 3158 r.LowerGraph();
3153 } 3159 }
3154 3160
3155 if (result.failed()) { 3161 int index = static_cast<int>(function_->func_index);
3156 if (FLAG_trace_wasm_compiler) {
3157 OFStream os(stdout);
3158 os << "Compilation failed: " << result << std::endl;
3159 }
3160 // Add the function as another context for the exception
3161 ScopedVector<char> buffer(128);
3162 wasm::WasmName name = module_env->module->GetName(function->name_offset,
3163 function->name_length);
3164 SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:",
3165 function->func_index, name.length(), name.start());
3166 thrower->Failed(buffer.start(), result);
3167 return std::make_pair(nullptr, nullptr);
3168 }
3169 int index = static_cast<int>(function->func_index);
3170 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { 3162 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) {
3171 PrintAst(isolate->allocator(), body); 3163 PrintAst(isolate_->allocator(), body);
3172 } 3164 }
3173 if (FLAG_trace_wasm_decode_time) { 3165 if (FLAG_trace_wasm_decode_time) {
3174 *decode_ms = decode_timer.Elapsed().InMillisecondsF(); 3166 *decode_ms = decode_timer.Elapsed().InMillisecondsF();
3175 } 3167 }
3176 return std::make_pair(jsgraph, source_position_table); 3168 return source_position_table;
3177 } 3169 }
3178 3170
3179 WasmCompilationUnit::WasmCompilationUnit(wasm::ErrorThrower* thrower, 3171 WasmCompilationUnit::WasmCompilationUnit(wasm::ErrorThrower* thrower,
3180 Isolate* isolate, 3172 Isolate* isolate,
3181 wasm::ModuleEnv* module_env, 3173 wasm::ModuleEnv* module_env,
3182 const wasm::WasmFunction* function, 3174 const wasm::WasmFunction* function,
3183 uint32_t index) 3175 uint32_t index)
3184 : thrower_(thrower), 3176 : thrower_(thrower),
3185 isolate_(isolate), 3177 isolate_(isolate),
3186 module_env_(module_env), 3178 module_env_(module_env),
(...skipping 27 matching lines...) Expand all
3214 OFStream os(stdout); 3206 OFStream os(stdout);
3215 os << "Compiling WASM function " 3207 os << "Compiling WASM function "
3216 << wasm::WasmFunctionName(function_, module_env_) << std::endl; 3208 << wasm::WasmFunctionName(function_, module_env_) << std::endl;
3217 os << std::endl; 3209 os << std::endl;
3218 } 3210 }
3219 3211
3220 double decode_ms = 0; 3212 double decode_ms = 0;
3221 size_t node_count = 0; 3213 size_t node_count = 0;
3222 3214
3223 base::SmartPointer<Zone> graph_zone(graph_zone_.Detach()); 3215 base::SmartPointer<Zone> graph_zone(graph_zone_.Detach());
3224 std::pair<JSGraph*, SourcePositionTable*> graph_result = 3216 SourcePositionTable* source_positions = BuildGraphForWasmFunction(&decode_ms);
3225 BuildGraphForWasmFunction(jsgraph_, thrower_, isolate_, module_env_,
3226 function_, &decode_ms);
3227 JSGraph* jsgraph = graph_result.first;
3228 SourcePositionTable* source_positions = graph_result.second;
3229 3217
3230 if (jsgraph == nullptr) { 3218 if (graph_construction_result_.failed()) {
3231 ok_ = false; 3219 ok_ = false;
3232 return; 3220 return;
3233 } 3221 }
3234 3222
3235 base::ElapsedTimer pipeline_timer; 3223 base::ElapsedTimer pipeline_timer;
3236 if (FLAG_trace_wasm_decode_time) { 3224 if (FLAG_trace_wasm_decode_time) {
3237 node_count = jsgraph->graph()->NodeCount(); 3225 node_count = jsgraph_->graph()->NodeCount();
3238 pipeline_timer.Start(); 3226 pipeline_timer.Start();
3239 } 3227 }
3240 3228
3241 // Run the compiler pipeline to generate machine code. 3229 // Run the compiler pipeline to generate machine code.
3242 CallDescriptor* descriptor = wasm::ModuleEnv::GetWasmCallDescriptor( 3230 CallDescriptor* descriptor = wasm::ModuleEnv::GetWasmCallDescriptor(
3243 &compilation_zone_, function_->sig); 3231 &compilation_zone_, function_->sig);
3244 if (jsgraph->machine()->Is32()) { 3232 if (jsgraph_->machine()->Is32()) {
3245 descriptor = 3233 descriptor =
3246 module_env_->GetI32WasmCallDescriptor(&compilation_zone_, descriptor); 3234 module_env_->GetI32WasmCallDescriptor(&compilation_zone_, descriptor);
3247 } 3235 }
3248 job_.Reset(Pipeline::NewWasmCompilationJob(&info_, jsgraph->graph(), 3236 job_.Reset(Pipeline::NewWasmCompilationJob(&info_, jsgraph_->graph(),
3249 descriptor, source_positions)); 3237 descriptor, source_positions));
3238
3239 // The function name {OptimizeGraph()} is misleading but necessary because we
3240 // want to use the CompilationJob interface. A better name would be
3241 // ScheduleGraphAndSelectInstructions.
3250 ok_ = job_->OptimizeGraph() == CompilationJob::SUCCEEDED; 3242 ok_ = job_->OptimizeGraph() == CompilationJob::SUCCEEDED;
3251 // TODO(bradnelson): Improve histogram handling of size_t. 3243 // TODO(bradnelson): Improve histogram handling of size_t.
3252 // TODO(ahaas): The counters are not thread-safe at the moment. 3244 // TODO(ahaas): The counters are not thread-safe at the moment.
3253 // isolate_->counters()->wasm_compile_function_peak_memory_bytes() 3245 // isolate_->counters()->wasm_compile_function_peak_memory_bytes()
3254 // ->AddSample( 3246 // ->AddSample(
3255 // static_cast<int>(jsgraph->graph()->zone()->allocation_size())); 3247 // static_cast<int>(jsgraph->graph()->zone()->allocation_size()));
3256 3248
3257 if (FLAG_trace_wasm_decode_time) { 3249 if (FLAG_trace_wasm_decode_time) {
3258 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); 3250 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF();
3259 PrintF( 3251 PrintF(
3260 "wasm-compilation phase 1 ok: %d bytes, %0.3f ms decode, %zu nodes, " 3252 "wasm-compilation phase 1 ok: %d bytes, %0.3f ms decode, %zu nodes, "
3261 "%0.3f ms pipeline\n", 3253 "%0.3f ms pipeline\n",
3262 static_cast<int>(function_->code_end_offset - 3254 static_cast<int>(function_->code_end_offset -
3263 function_->code_start_offset), 3255 function_->code_start_offset),
3264 decode_ms, node_count, pipeline_ms); 3256 decode_ms, node_count, pipeline_ms);
3265 } 3257 }
3266 } 3258 }
3267 3259
3268 Handle<Code> WasmCompilationUnit::FinishCompilation() { 3260 Handle<Code> WasmCompilationUnit::FinishCompilation() {
3269 if (!ok_) { 3261 if (!ok_) {
3262 if (graph_construction_result_.failed()) {
3263 // Add the function as another context for the exception
3264 ScopedVector<char> buffer(128);
bradnelson 2016/05/25 10:50:12 How do we know this is enough?
bradnelson 2016/05/25 11:18:57 Nevermind, this is fine.
3265 wasm::WasmName name = module_env_->module->GetName(
3266 function_->name_offset, function_->name_length);
3267 SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:",
3268 function_->func_index, name.length(), name.start());
3269 thrower_->Failed(buffer.start(), graph_construction_result_);
3270 }
3271
3270 return Handle<Code>::null(); 3272 return Handle<Code>::null();
3271 } 3273 }
3272 if (job_->GenerateCode() != CompilationJob::SUCCEEDED) { 3274 if (job_->GenerateCode() != CompilationJob::SUCCEEDED) {
3273 return Handle<Code>::null(); 3275 return Handle<Code>::null();
3274 } 3276 }
3275 base::ElapsedTimer compile_timer; 3277 base::ElapsedTimer compile_timer;
3276 if (FLAG_trace_wasm_decode_time) { 3278 if (FLAG_trace_wasm_decode_time) {
3277 compile_timer.Start(); 3279 compile_timer.Start();
3278 } 3280 }
3279 Handle<Code> code = info_.code(); 3281 Handle<Code> code = info_.code();
(...skipping 21 matching lines...) Expand all
3301 function_->code_start_offset), 3303 function_->code_start_offset),
3302 compile_ms); 3304 compile_ms);
3303 } 3305 }
3304 3306
3305 return code; 3307 return code;
3306 } 3308 }
3307 3309
3308 } // namespace compiler 3310 } // namespace compiler
3309 } // namespace internal 3311 } // namespace internal
3310 } // namespace v8 3312 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698