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

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: drop empty line ;) 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
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // End the control flow with returning 0xdeadbeef 237 // End the control flow with returning 0xdeadbeef
238 Node* ret_value = GetTrapValue(builder_->GetFunctionSignature()); 238 Node* ret_value = GetTrapValue(builder_->GetFunctionSignature());
239 end = graph()->NewNode(jsgraph()->common()->Return(), ret_value, 239 end = graph()->NewNode(jsgraph()->common()->Return(), ret_value,
240 *effect_ptr, *control_ptr); 240 *effect_ptr, *control_ptr);
241 } 241 }
242 242
243 MergeControlToEnd(jsgraph(), end); 243 MergeControlToEnd(jsgraph(), end);
244 } 244 }
245 }; 245 };
246 246
247 WasmGraphBuilder::WasmGraphBuilder(Zone* zone, JSGraph* jsgraph, 247 WasmGraphBuilder::WasmGraphBuilder(
248 wasm::FunctionSig* function_signature) 248 Zone* zone, JSGraph* jsgraph, wasm::FunctionSig* function_signature,
249 compiler::SourcePositionTable* source_position_table)
249 : zone_(zone), 250 : zone_(zone),
250 jsgraph_(jsgraph), 251 jsgraph_(jsgraph),
251 module_(nullptr), 252 module_(nullptr),
252 mem_buffer_(nullptr), 253 mem_buffer_(nullptr),
253 mem_size_(nullptr), 254 mem_size_(nullptr),
254 function_table_(nullptr), 255 function_table_(nullptr),
255 control_(nullptr), 256 control_(nullptr),
256 effect_(nullptr), 257 effect_(nullptr),
257 cur_buffer_(def_buffer_), 258 cur_buffer_(def_buffer_),
258 cur_bufsize_(kDefaultBufferSize), 259 cur_bufsize_(kDefaultBufferSize),
259 trap_(new (zone) WasmTrapHelper(this)), 260 trap_(new (zone) WasmTrapHelper(this)),
260 function_signature_(function_signature) { 261 function_signature_(function_signature),
262 source_position_table_(source_position_table) {
261 DCHECK_NOT_NULL(jsgraph_); 263 DCHECK_NOT_NULL(jsgraph_);
262 } 264 }
263 265
264 266
265 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } 267 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); }
266 268
267 269
268 Node* WasmGraphBuilder::Start(unsigned params) { 270 Node* WasmGraphBuilder::Start(unsigned params) {
269 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); 271 Node* start = graph()->NewNode(jsgraph()->common()->Start(params));
270 graph()->SetStart(start); 272 graph()->SetStart(start);
(...skipping 2385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2656 2658
2657 void WasmGraphBuilder::Int64LoweringForTesting() { 2659 void WasmGraphBuilder::Int64LoweringForTesting() {
2658 if (jsgraph()->machine()->Is32()) { 2660 if (jsgraph()->machine()->Is32()) {
2659 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(), 2661 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(),
2660 jsgraph()->common(), jsgraph()->zone(), 2662 jsgraph()->common(), jsgraph()->zone(),
2661 function_signature_); 2663 function_signature_);
2662 r.LowerGraph(); 2664 r.LowerGraph();
2663 } 2665 }
2664 } 2666 }
2665 2667
2668 void WasmGraphBuilder::SetSourcePosition(Node* node, int position) {
2669 compiler::SourcePosition pos(position);
2670 if (source_position_table_)
2671 source_position_table_->SetSourcePosition(node, pos);
2672 }
2673
2666 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, 2674 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
2667 CompilationInfo* info, 2675 CompilationInfo* info,
2668 const char* message, uint32_t index, 2676 const char* message, uint32_t index,
2669 wasm::WasmName func_name) { 2677 wasm::WasmName func_name) {
2670 Isolate* isolate = info->isolate(); 2678 Isolate* isolate = info->isolate();
2671 if (isolate->logger()->is_logging_code_events() || 2679 if (isolate->logger()->is_logging_code_events() ||
2672 isolate->cpu_profiler()->is_profiling()) { 2680 isolate->cpu_profiler()->is_profiling()) {
2673 ScopedVector<char> buffer(128); 2681 ScopedVector<char> buffer(128);
2674 SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length, 2682 SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length,
2675 func_name.name); 2683 func_name.name);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2748 static unsigned id = 0; 2756 static unsigned id = 0;
2749 Vector<char> buffer; 2757 Vector<char> buffer;
2750 if (debugging) { 2758 if (debugging) {
2751 buffer = Vector<char>::New(128); 2759 buffer = Vector<char>::New(128);
2752 SNPrintF(buffer, "js-to-wasm#%d", id); 2760 SNPrintF(buffer, "js-to-wasm#%d", id);
2753 func_name = buffer.start(); 2761 func_name = buffer.start();
2754 } 2762 }
2755 2763
2756 CompilationInfo info(func_name, isolate, &zone, flags); 2764 CompilationInfo info(func_name, isolate, &zone, flags);
2757 Handle<Code> code = 2765 Handle<Code> code =
2758 Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); 2766 Pipeline::GenerateCodeForTesting(&info, incoming, &graph);
2759 #ifdef ENABLE_DISASSEMBLER 2767 #ifdef ENABLE_DISASSEMBLER
2760 if (FLAG_print_opt_code && !code.is_null()) { 2768 if (FLAG_print_opt_code && !code.is_null()) {
2761 OFStream os(stdout); 2769 OFStream os(stdout);
2762 code->Disassemble(buffer.start(), os); 2770 code->Disassemble(buffer.start(), os);
2763 } 2771 }
2764 #endif 2772 #endif
2765 if (debugging) { 2773 if (debugging) {
2766 buffer.Dispose(); 2774 buffer.Dispose();
2767 } 2775 }
2768 2776
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2867 } 2875 }
2868 2876
2869 // Create a TF graph during decoding. 2877 // Create a TF graph during decoding.
2870 Zone zone(isolate->allocator()); 2878 Zone zone(isolate->allocator());
2871 Graph graph(&zone); 2879 Graph graph(&zone);
2872 CommonOperatorBuilder common(&zone); 2880 CommonOperatorBuilder common(&zone);
2873 MachineOperatorBuilder machine( 2881 MachineOperatorBuilder machine(
2874 &zone, MachineType::PointerRepresentation(), 2882 &zone, MachineType::PointerRepresentation(),
2875 InstructionSelector::SupportedMachineOperatorFlags()); 2883 InstructionSelector::SupportedMachineOperatorFlags());
2876 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); 2884 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine);
2877 WasmGraphBuilder builder(&zone, &jsgraph, function.sig); 2885 SourcePositionTable source_position_table(&graph);
2886 WasmGraphBuilder builder(&zone, &jsgraph, function.sig,
2887 &source_position_table);
2878 wasm::FunctionBody body = { 2888 wasm::FunctionBody body = {
2879 module_env, function.sig, module_env->module->module_start, 2889 module_env, function.sig, module_env->module->module_start,
2880 module_env->module->module_start + function.code_start_offset, 2890 module_env->module->module_start + function.code_start_offset,
2881 module_env->module->module_start + function.code_end_offset}; 2891 module_env->module->module_start + function.code_end_offset};
2882 wasm::TreeResult result = 2892 wasm::TreeResult result =
2883 wasm::BuildTFGraph(isolate->allocator(), &builder, body); 2893 wasm::BuildTFGraph(isolate->allocator(), &builder, body);
2884 2894
2885 if (machine.Is32()) { 2895 if (machine.Is32()) {
2886 Int64Lowering r(&graph, &machine, &common, &zone, function.sig); 2896 Int64Lowering r(&graph, &machine, &common, &zone, function.sig);
2887 r.LowerGraph(); 2897 r.LowerGraph();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2934 if (debugging) { 2944 if (debugging) {
2935 buffer = Vector<char>::New(128); 2945 buffer = Vector<char>::New(128);
2936 wasm::WasmName name = 2946 wasm::WasmName name =
2937 module_env->module->GetName(function.name_offset, function.name_length); 2947 module_env->module->GetName(function.name_offset, function.name_length);
2938 SNPrintF(buffer, "WASM_function_#%d:%.*s", function.func_index, name.length, 2948 SNPrintF(buffer, "WASM_function_#%d:%.*s", function.func_index, name.length,
2939 name.name); 2949 name.name);
2940 func_name = buffer.start(); 2950 func_name = buffer.start();
2941 } 2951 }
2942 CompilationInfo info(func_name, isolate, &zone, flags); 2952 CompilationInfo info(func_name, isolate, &zone, flags);
2943 2953
2944 Handle<Code> code = 2954 Handle<Code> code = Pipeline::GenerateWASMCode(&info, descriptor, &graph,
2945 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph); 2955 &source_position_table);
2946 if (debugging) { 2956 if (debugging) {
2947 buffer.Dispose(); 2957 buffer.Dispose();
2948 } 2958 }
2949 if (!code.is_null()) { 2959 if (!code.is_null()) {
2950 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function", 2960 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function",
2951 function.func_index, 2961 function.func_index,
2952 module_env->module->GetName( 2962 module_env->module->GetName(
2953 function.name_offset, function.name_length)); 2963 function.name_offset, function.name_length));
2954 } 2964 }
2955 2965
2956 if (FLAG_trace_wasm_decode_time) { 2966 if (FLAG_trace_wasm_decode_time) {
2957 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); 2967 double compile_ms = compile_timer.Elapsed().InMillisecondsF();
2958 PrintF( 2968 PrintF(
2959 "wasm-compile ok: %d bytes, %0.3f ms decode, %d nodes, %0.3f ms " 2969 "wasm-compile ok: %d bytes, %0.3f ms decode, %d nodes, %0.3f ms "
2960 "compile\n", 2970 "compile\n",
2961 static_cast<int>(function.code_end_offset - function.code_start_offset), 2971 static_cast<int>(function.code_end_offset - function.code_start_offset),
2962 decode_ms, static_cast<int>(graph.NodeCount()), compile_ms); 2972 decode_ms, static_cast<int>(graph.NodeCount()), compile_ms);
2963 } 2973 }
2964 // TODO(bradnelson): Improve histogram handling of size_t. 2974 // TODO(bradnelson): Improve histogram handling of size_t.
2965 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( 2975 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample(
2966 static_cast<int>(zone.allocation_size())); 2976 static_cast<int>(zone.allocation_size()));
2967 return code; 2977 return code;
2968 } 2978 }
2969 2979
2970 2980
2971 } // namespace compiler 2981 } // namespace compiler
2972 } // namespace internal 2982 } // namespace internal
2973 } // namespace v8 2983 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698