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

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

Issue 1890803002: [wasm] Generate source position information (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-throw-error
Patch Set: some doc and fixes 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
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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // End the control flow with returning 0xdeadbeef 241 // End the control flow with returning 0xdeadbeef
242 Node* ret_value = GetTrapValue(builder_->GetFunctionSignature()); 242 Node* ret_value = GetTrapValue(builder_->GetFunctionSignature());
243 end = graph()->NewNode(jsgraph()->common()->Return(), ret_value, 243 end = graph()->NewNode(jsgraph()->common()->Return(), ret_value,
244 *effect_ptr, *control_ptr); 244 *effect_ptr, *control_ptr);
245 } 245 }
246 246
247 MergeControlToEnd(jsgraph(), end); 247 MergeControlToEnd(jsgraph(), end);
248 } 248 }
249 }; 249 };
250 250
251 WasmGraphBuilder::WasmGraphBuilder(Zone* zone, JSGraph* jsgraph, 251 WasmGraphBuilder::WasmGraphBuilder(
252 wasm::FunctionSig* function_signature) 252 Zone* zone, JSGraph* jsgraph, wasm::FunctionSig* function_signature,
253 compiler::SourcePositionTable* source_position_table)
253 : zone_(zone), 254 : zone_(zone),
254 jsgraph_(jsgraph), 255 jsgraph_(jsgraph),
255 module_(nullptr), 256 module_(nullptr),
256 mem_buffer_(nullptr), 257 mem_buffer_(nullptr),
257 mem_size_(nullptr), 258 mem_size_(nullptr),
258 function_table_(nullptr), 259 function_table_(nullptr),
259 control_(nullptr), 260 control_(nullptr),
260 effect_(nullptr), 261 effect_(nullptr),
261 cur_buffer_(def_buffer_), 262 cur_buffer_(def_buffer_),
262 cur_bufsize_(kDefaultBufferSize), 263 cur_bufsize_(kDefaultBufferSize),
263 trap_(new (zone) WasmTrapHelper(this)), 264 trap_(new (zone) WasmTrapHelper(this)),
264 function_signature_(function_signature) { 265 function_signature_(function_signature),
266 source_position_table_(source_position_table) {
265 DCHECK_NOT_NULL(jsgraph_); 267 DCHECK_NOT_NULL(jsgraph_);
268 DCHECK_IMPLIES(source_position_table != nullptr,
269 source_position_table->GetGraph() == graph());
266 } 270 }
267 271
268 272
269 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } 273 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); }
270 274
271 275
272 Node* WasmGraphBuilder::Start(unsigned params) { 276 Node* WasmGraphBuilder::Start(unsigned params) {
273 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); 277 Node* start = graph()->NewNode(jsgraph()->common()->Start(params));
274 graph()->SetStart(start); 278 graph()->SetStart(start);
275 return start; 279 return start;
(...skipping 2196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2472 2476
2473 void WasmGraphBuilder::Int64LoweringForTesting() { 2477 void WasmGraphBuilder::Int64LoweringForTesting() {
2474 if (jsgraph()->machine()->Is32()) { 2478 if (jsgraph()->machine()->Is32()) {
2475 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(), 2479 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(),
2476 jsgraph()->common(), jsgraph()->zone(), 2480 jsgraph()->common(), jsgraph()->zone(),
2477 function_signature_); 2481 function_signature_);
2478 r.LowerGraph(); 2482 r.LowerGraph();
2479 } 2483 }
2480 } 2484 }
2481 2485
2486 void WasmGraphBuilder::EnterSourcePositionScope() {
2487 DCHECK_NULL(source_position_scope_);
2488 if (source_position_table_) {
2489 source_position_table_->AddDecorator();
2490 source_position_scope_ = new SourcePositionScope(source_position_table_);
2491 }
2492 }
2493
2494 void WasmGraphBuilder::LeaveSourcePositionScope() {
2495 DCHECK_EQ(!!source_position_table_, !!source_position_scope_);
2496 if (!source_position_scope_) return;
2497 delete source_position_scope_;
2498 source_position_scope_ = nullptr;
2499 source_position_table_->RemoveDecorator();
2500 }
2501
2502 void WasmGraphBuilder::SetCurrentSourcePosition(int position) {
2503 if (source_position_scope_)
2504 source_position_scope_->SetCurrentPosition(SourcePosition(position));
2505 }
2506
2482 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, 2507 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
2483 CompilationInfo* info, 2508 CompilationInfo* info,
2484 const char* message, uint32_t index, 2509 const char* message, uint32_t index,
2485 wasm::WasmName func_name) { 2510 wasm::WasmName func_name) {
2486 Isolate* isolate = info->isolate(); 2511 Isolate* isolate = info->isolate();
2487 if (isolate->logger()->is_logging_code_events() || 2512 if (isolate->logger()->is_logging_code_events() ||
2488 isolate->cpu_profiler()->is_profiling()) { 2513 isolate->cpu_profiler()->is_profiling()) {
2489 ScopedVector<char> buffer(128); 2514 ScopedVector<char> buffer(128);
2490 SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length, 2515 SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length,
2491 func_name.name); 2516 func_name.name);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
2704 } 2729 }
2705 2730
2706 // Create a TF graph during decoding. 2731 // Create a TF graph during decoding.
2707 Zone zone(isolate->allocator()); 2732 Zone zone(isolate->allocator());
2708 Graph graph(&zone); 2733 Graph graph(&zone);
2709 CommonOperatorBuilder common(&zone); 2734 CommonOperatorBuilder common(&zone);
2710 MachineOperatorBuilder machine( 2735 MachineOperatorBuilder machine(
2711 &zone, MachineType::PointerRepresentation(), 2736 &zone, MachineType::PointerRepresentation(),
2712 InstructionSelector::SupportedMachineOperatorFlags()); 2737 InstructionSelector::SupportedMachineOperatorFlags());
2713 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); 2738 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine);
2714 WasmGraphBuilder builder(&zone, &jsgraph, function.sig); 2739 SourcePositionTable source_position_table(&graph);
2740 WasmGraphBuilder builder(&zone, &jsgraph, function.sig,
2741 &source_position_table);
2715 wasm::FunctionBody body = { 2742 wasm::FunctionBody body = {
2716 module_env, function.sig, module_env->module->module_start, 2743 module_env, function.sig, module_env->module->module_start,
2717 module_env->module->module_start + function.code_start_offset, 2744 module_env->module->module_start + function.code_start_offset,
2718 module_env->module->module_start + function.code_end_offset}; 2745 module_env->module->module_start + function.code_end_offset};
2746
2747 builder.EnterSourcePositionScope();
2719 wasm::TreeResult result = 2748 wasm::TreeResult result =
2720 wasm::BuildTFGraph(isolate->allocator(), &builder, body); 2749 wasm::BuildTFGraph(isolate->allocator(), &builder, body);
2750 builder.LeaveSourcePositionScope();
2721 2751
2722 if (result.failed()) { 2752 if (result.failed()) {
2723 if (FLAG_trace_wasm_compiler) { 2753 if (FLAG_trace_wasm_compiler) {
2724 OFStream os(stdout); 2754 OFStream os(stdout);
2725 os << "Compilation failed: " << result << std::endl; 2755 os << "Compilation failed: " << result << std::endl;
2726 } 2756 }
2727 // Add the function as another context for the exception 2757 // Add the function as another context for the exception
2728 ScopedVector<char> buffer(128); 2758 ScopedVector<char> buffer(128);
2729 wasm::WasmName name = 2759 wasm::WasmName name =
2730 module_env->module->GetName(function.name_offset, function.name_length); 2760 module_env->module->GetName(function.name_offset, function.name_length);
(...skipping 15 matching lines...) Expand all
2746 base::ElapsedTimer compile_timer; 2776 base::ElapsedTimer compile_timer;
2747 if (FLAG_trace_wasm_decode_time) { 2777 if (FLAG_trace_wasm_decode_time) {
2748 compile_timer.Start(); 2778 compile_timer.Start();
2749 } 2779 }
2750 // Run the compiler pipeline to generate machine code. 2780 // Run the compiler pipeline to generate machine code.
2751 CallDescriptor* descriptor = 2781 CallDescriptor* descriptor =
2752 wasm::ModuleEnv::GetWasmCallDescriptor(&zone, function.sig); 2782 wasm::ModuleEnv::GetWasmCallDescriptor(&zone, function.sig);
2753 if (machine.Is32()) { 2783 if (machine.Is32()) {
2754 descriptor = module_env->GetI32WasmCallDescriptor(&zone, descriptor); 2784 descriptor = module_env->GetI32WasmCallDescriptor(&zone, descriptor);
2755 } 2785 }
2786
2756 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); 2787 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION);
2757 // add flags here if a meaningful name is helpful for debugging. 2788 // add flags here if a meaningful name is helpful for debugging.
2758 bool debugging = 2789 bool debugging =
2759 #if DEBUG 2790 #if DEBUG
2760 true; 2791 true;
2761 #else 2792 #else
2762 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; 2793 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
2763 #endif 2794 #endif
2764 const char* func_name = "wasm"; 2795 const char* func_name = "wasm";
2765 Vector<char> buffer; 2796 Vector<char> buffer;
2766 if (debugging) { 2797 if (debugging) {
2767 buffer = Vector<char>::New(128); 2798 buffer = Vector<char>::New(128);
2768 wasm::WasmName name = 2799 wasm::WasmName name =
2769 module_env->module->GetName(function.name_offset, function.name_length); 2800 module_env->module->GetName(function.name_offset, function.name_length);
2770 SNPrintF(buffer, "WASM_function_#%d:%.*s", function.func_index, name.length, 2801 SNPrintF(buffer, "WASM_function_#%d:%.*s", function.func_index, name.length,
2771 name.name); 2802 name.name);
2772 func_name = buffer.start(); 2803 func_name = buffer.start();
2773 } 2804 }
2774 CompilationInfo info(func_name, isolate, &zone, flags); 2805 CompilationInfo info(func_name, isolate, &zone, flags);
2806 // TODO(clemensh): make source position tracking optional
2807 info.MarkAsSourcePositionsEnabled();
2808 info.SetSourcePositionTable(&source_position_table);
2775 2809
2776 Handle<Code> code = 2810 Handle<Code> code =
2777 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph); 2811 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph);
2778 if (debugging) { 2812 if (debugging) {
2779 buffer.Dispose(); 2813 buffer.Dispose();
2780 } 2814 }
2781 if (!code.is_null()) { 2815 if (!code.is_null()) {
2782 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function", 2816 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function",
2783 function.func_index, 2817 function.func_index,
2784 module_env->module->GetName( 2818 module_env->module->GetName(
(...skipping 11 matching lines...) Expand all
2796 // TODO(bradnelson): Improve histogram handling of size_t. 2830 // TODO(bradnelson): Improve histogram handling of size_t.
2797 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( 2831 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample(
2798 static_cast<int>(zone.allocation_size())); 2832 static_cast<int>(zone.allocation_size()));
2799 return code; 2833 return code;
2800 } 2834 }
2801 2835
2802 2836
2803 } // namespace compiler 2837 } // namespace compiler
2804 } // namespace internal 2838 } // namespace internal
2805 } // namespace v8 2839 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698