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

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: minor 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 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_);
264 DCHECK_IMPLIES(source_position_table != nullptr,
265 source_position_table->GetGraph() == graph());
262 } 266 }
263 267
264 268
265 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } 269 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); }
266 270
267 271
268 Node* WasmGraphBuilder::Start(unsigned params) { 272 Node* WasmGraphBuilder::Start(unsigned params) {
269 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); 273 Node* start = graph()->NewNode(jsgraph()->common()->Start(params));
270 graph()->SetStart(start); 274 graph()->SetStart(start);
271 return start; 275 return start;
(...skipping 2391 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 2667
2664 void WasmGraphBuilder::Int64LoweringForTesting() { 2668 void WasmGraphBuilder::Int64LoweringForTesting() {
2665 if (jsgraph()->machine()->Is32()) { 2669 if (jsgraph()->machine()->Is32()) {
2666 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(), 2670 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(),
2667 jsgraph()->common(), jsgraph()->zone(), 2671 jsgraph()->common(), jsgraph()->zone(),
2668 function_signature_); 2672 function_signature_);
2669 r.LowerGraph(); 2673 r.LowerGraph();
2670 } 2674 }
2671 } 2675 }
2672 2676
2677 void WasmGraphBuilder::SetSourcePosition(Node* node, int position) {
2678 compiler::SourcePosition pos(position);
2679 if (source_position_table_)
2680 source_position_table_->SetSourcePosition(node, pos);
2681 }
2682
2673 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, 2683 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
2674 CompilationInfo* info, 2684 CompilationInfo* info,
2675 const char* message, uint32_t index, 2685 const char* message, uint32_t index,
2676 wasm::WasmName func_name) { 2686 wasm::WasmName func_name) {
2677 Isolate* isolate = info->isolate(); 2687 Isolate* isolate = info->isolate();
2678 if (isolate->logger()->is_logging_code_events() || 2688 if (isolate->logger()->is_logging_code_events() ||
2679 isolate->cpu_profiler()->is_profiling()) { 2689 isolate->cpu_profiler()->is_profiling()) {
2680 ScopedVector<char> buffer(128); 2690 ScopedVector<char> buffer(128);
2681 SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length, 2691 SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length,
2682 func_name.name); 2692 func_name.name);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2755 static unsigned id = 0; 2765 static unsigned id = 0;
2756 Vector<char> buffer; 2766 Vector<char> buffer;
2757 if (debugging) { 2767 if (debugging) {
2758 buffer = Vector<char>::New(128); 2768 buffer = Vector<char>::New(128);
2759 SNPrintF(buffer, "js-to-wasm#%d", id); 2769 SNPrintF(buffer, "js-to-wasm#%d", id);
2760 func_name = buffer.start(); 2770 func_name = buffer.start();
2761 } 2771 }
2762 2772
2763 CompilationInfo info(func_name, isolate, &zone, flags); 2773 CompilationInfo info(func_name, isolate, &zone, flags);
2764 Handle<Code> code = 2774 Handle<Code> code =
2765 Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); 2775 Pipeline::GenerateCodeForTesting(&info, incoming, &graph);
2766 #ifdef ENABLE_DISASSEMBLER 2776 #ifdef ENABLE_DISASSEMBLER
2767 if (FLAG_print_opt_code && !code.is_null()) { 2777 if (FLAG_print_opt_code && !code.is_null()) {
2768 OFStream os(stdout); 2778 OFStream os(stdout);
2769 code->Disassemble(buffer.start(), os); 2779 code->Disassemble(buffer.start(), os);
2770 } 2780 }
2771 #endif 2781 #endif
2772 if (debugging) { 2782 if (debugging) {
2773 buffer.Dispose(); 2783 buffer.Dispose();
2774 } 2784 }
2775 2785
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 } 2884 }
2875 2885
2876 // Create a TF graph during decoding. 2886 // Create a TF graph during decoding.
2877 Zone zone(isolate->allocator()); 2887 Zone zone(isolate->allocator());
2878 Graph graph(&zone); 2888 Graph graph(&zone);
2879 CommonOperatorBuilder common(&zone); 2889 CommonOperatorBuilder common(&zone);
2880 MachineOperatorBuilder machine( 2890 MachineOperatorBuilder machine(
2881 &zone, MachineType::PointerRepresentation(), 2891 &zone, MachineType::PointerRepresentation(),
2882 InstructionSelector::SupportedMachineOperatorFlags()); 2892 InstructionSelector::SupportedMachineOperatorFlags());
2883 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); 2893 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine);
2884 WasmGraphBuilder builder(&zone, &jsgraph, function.sig); 2894 SourcePositionTable source_position_table(&graph);
2895 WasmGraphBuilder builder(&zone, &jsgraph, function.sig,
2896 &source_position_table);
2885 wasm::FunctionBody body = { 2897 wasm::FunctionBody body = {
2886 module_env, function.sig, module_env->module->module_start, 2898 module_env, function.sig, module_env->module->module_start,
2887 module_env->module->module_start + function.code_start_offset, 2899 module_env->module->module_start + function.code_start_offset,
2888 module_env->module->module_start + function.code_end_offset}; 2900 module_env->module->module_start + function.code_end_offset};
2901
2889 wasm::TreeResult result = 2902 wasm::TreeResult result =
2890 wasm::BuildTFGraph(isolate->allocator(), &builder, body); 2903 wasm::BuildTFGraph(isolate->allocator(), &builder, body);
2891 2904
2892 if (machine.Is32()) { 2905 if (machine.Is32()) {
2893 Int64Lowering r(&graph, &machine, &common, &zone, function.sig); 2906 Int64Lowering r(&graph, &machine, &common, &zone, function.sig);
2894 r.LowerGraph(); 2907 r.LowerGraph();
2895 } 2908 }
2896 2909
2897 if (result.failed()) { 2910 if (result.failed()) {
2898 if (FLAG_trace_wasm_compiler) { 2911 if (FLAG_trace_wasm_compiler) {
(...skipping 22 matching lines...) Expand all
2921 base::ElapsedTimer compile_timer; 2934 base::ElapsedTimer compile_timer;
2922 if (FLAG_trace_wasm_decode_time) { 2935 if (FLAG_trace_wasm_decode_time) {
2923 compile_timer.Start(); 2936 compile_timer.Start();
2924 } 2937 }
2925 // Run the compiler pipeline to generate machine code. 2938 // Run the compiler pipeline to generate machine code.
2926 CallDescriptor* descriptor = 2939 CallDescriptor* descriptor =
2927 wasm::ModuleEnv::GetWasmCallDescriptor(&zone, function.sig); 2940 wasm::ModuleEnv::GetWasmCallDescriptor(&zone, function.sig);
2928 if (machine.Is32()) { 2941 if (machine.Is32()) {
2929 descriptor = module_env->GetI32WasmCallDescriptor(&zone, descriptor); 2942 descriptor = module_env->GetI32WasmCallDescriptor(&zone, descriptor);
2930 } 2943 }
2944
2931 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); 2945 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION);
2932 // add flags here if a meaningful name is helpful for debugging. 2946 // add flags here if a meaningful name is helpful for debugging.
2933 bool debugging = 2947 bool debugging =
2934 #if DEBUG 2948 #if DEBUG
2935 true; 2949 true;
2936 #else 2950 #else
2937 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; 2951 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
2938 #endif 2952 #endif
2939 const char* func_name = "wasm"; 2953 const char* func_name = "wasm";
2940 Vector<char> buffer; 2954 Vector<char> buffer;
2941 if (debugging) { 2955 if (debugging) {
2942 buffer = Vector<char>::New(128); 2956 buffer = Vector<char>::New(128);
2943 wasm::WasmName name = 2957 wasm::WasmName name =
2944 module_env->module->GetName(function.name_offset, function.name_length); 2958 module_env->module->GetName(function.name_offset, function.name_length);
2945 SNPrintF(buffer, "WASM_function_#%d:%.*s", function.func_index, name.length, 2959 SNPrintF(buffer, "WASM_function_#%d:%.*s", function.func_index, name.length,
2946 name.name); 2960 name.name);
2947 func_name = buffer.start(); 2961 func_name = buffer.start();
2948 } 2962 }
2949 CompilationInfo info(func_name, isolate, &zone, flags); 2963 CompilationInfo info(func_name, isolate, &zone, flags);
2950 2964
2951 Handle<Code> code = 2965 Handle<Code> code = Pipeline::GenerateWASMCode(&info, descriptor, &graph,
2952 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph); 2966 &source_position_table);
2953 if (debugging) { 2967 if (debugging) {
2954 buffer.Dispose(); 2968 buffer.Dispose();
2955 } 2969 }
2956 if (!code.is_null()) { 2970 if (!code.is_null()) {
2957 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function", 2971 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function",
2958 function.func_index, 2972 function.func_index,
2959 module_env->module->GetName( 2973 module_env->module->GetName(
2960 function.name_offset, function.name_length)); 2974 function.name_offset, function.name_length));
2961 } 2975 }
2962 2976
2963 if (FLAG_trace_wasm_decode_time) { 2977 if (FLAG_trace_wasm_decode_time) {
2964 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); 2978 double compile_ms = compile_timer.Elapsed().InMillisecondsF();
2965 PrintF( 2979 PrintF(
2966 "wasm-compile ok: %d bytes, %0.3f ms decode, %d nodes, %0.3f ms " 2980 "wasm-compile ok: %d bytes, %0.3f ms decode, %d nodes, %0.3f ms "
2967 "compile\n", 2981 "compile\n",
2968 static_cast<int>(function.code_end_offset - function.code_start_offset), 2982 static_cast<int>(function.code_end_offset - function.code_start_offset),
2969 decode_ms, static_cast<int>(graph.NodeCount()), compile_ms); 2983 decode_ms, static_cast<int>(graph.NodeCount()), compile_ms);
2970 } 2984 }
2971 // TODO(bradnelson): Improve histogram handling of size_t. 2985 // TODO(bradnelson): Improve histogram handling of size_t.
2972 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( 2986 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample(
2973 static_cast<int>(zone.allocation_size())); 2987 static_cast<int>(zone.allocation_size()));
2974 return code; 2988 return code;
2975 } 2989 }
2976 2990
2977 2991
2978 } // namespace compiler 2992 } // namespace compiler
2979 } // namespace internal 2993 } // namespace internal
2980 } // namespace v8 2994 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698