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

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: avoid using std::tie 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/ast-decoder.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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // End the control flow with returning 0xdeadbeef 238 // End the control flow with returning 0xdeadbeef
239 Node* ret_value = GetTrapValue(builder_->GetFunctionSignature()); 239 Node* ret_value = GetTrapValue(builder_->GetFunctionSignature());
240 end = graph()->NewNode(jsgraph()->common()->Return(), ret_value, 240 end = graph()->NewNode(jsgraph()->common()->Return(), ret_value,
241 *effect_ptr, *control_ptr); 241 *effect_ptr, *control_ptr);
242 } 242 }
243 243
244 MergeControlToEnd(jsgraph(), end); 244 MergeControlToEnd(jsgraph(), end);
245 } 245 }
246 }; 246 };
247 247
248 WasmGraphBuilder::WasmGraphBuilder(Zone* zone, JSGraph* jsgraph, 248 WasmGraphBuilder::WasmGraphBuilder(
249 wasm::FunctionSig* function_signature) 249 Zone* zone, JSGraph* jsgraph, wasm::FunctionSig* function_signature,
250 compiler::SourcePositionTable* source_position_table)
250 : zone_(zone), 251 : zone_(zone),
251 jsgraph_(jsgraph), 252 jsgraph_(jsgraph),
252 module_(nullptr), 253 module_(nullptr),
253 mem_buffer_(nullptr), 254 mem_buffer_(nullptr),
254 mem_size_(nullptr), 255 mem_size_(nullptr),
255 function_table_(nullptr), 256 function_table_(nullptr),
256 control_(nullptr), 257 control_(nullptr),
257 effect_(nullptr), 258 effect_(nullptr),
258 cur_buffer_(def_buffer_), 259 cur_buffer_(def_buffer_),
259 cur_bufsize_(kDefaultBufferSize), 260 cur_bufsize_(kDefaultBufferSize),
260 trap_(new (zone) WasmTrapHelper(this)), 261 trap_(new (zone) WasmTrapHelper(this)),
261 function_signature_(function_signature) { 262 function_signature_(function_signature),
263 source_position_table_(source_position_table) {
262 DCHECK_NOT_NULL(jsgraph_); 264 DCHECK_NOT_NULL(jsgraph_);
263 } 265 }
264 266
265 267
266 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } 268 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); }
267 269
268 270
269 Node* WasmGraphBuilder::Start(unsigned params) { 271 Node* WasmGraphBuilder::Start(unsigned params) {
270 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); 272 Node* start = graph()->NewNode(jsgraph()->common()->Start(params));
271 graph()->SetStart(start); 273 graph()->SetStart(start);
(...skipping 2385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2657 2659
2658 void WasmGraphBuilder::Int64LoweringForTesting() { 2660 void WasmGraphBuilder::Int64LoweringForTesting() {
2659 if (jsgraph()->machine()->Is32()) { 2661 if (jsgraph()->machine()->Is32()) {
2660 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(), 2662 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(),
2661 jsgraph()->common(), jsgraph()->zone(), 2663 jsgraph()->common(), jsgraph()->zone(),
2662 function_signature_); 2664 function_signature_);
2663 r.LowerGraph(); 2665 r.LowerGraph();
2664 } 2666 }
2665 } 2667 }
2666 2668
2669 void WasmGraphBuilder::SetSourcePosition(Node* node, int position) {
2670 compiler::SourcePosition pos(position);
2671 if (source_position_table_)
2672 source_position_table_->SetSourcePosition(node, pos);
2673 }
2674
2667 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, 2675 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
2668 CompilationInfo* info, 2676 CompilationInfo* info,
2669 const char* message, uint32_t index, 2677 const char* message, uint32_t index,
2670 wasm::WasmName func_name) { 2678 wasm::WasmName func_name) {
2671 Isolate* isolate = info->isolate(); 2679 Isolate* isolate = info->isolate();
2672 if (isolate->logger()->is_logging_code_events() || 2680 if (isolate->logger()->is_logging_code_events() ||
2673 isolate->cpu_profiler()->is_profiling()) { 2681 isolate->cpu_profiler()->is_profiling()) {
2674 ScopedVector<char> buffer(128); 2682 ScopedVector<char> buffer(128);
2675 SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length, 2683 SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length,
2676 func_name.name); 2684 func_name.name);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2749 static unsigned id = 0; 2757 static unsigned id = 0;
2750 Vector<char> buffer; 2758 Vector<char> buffer;
2751 if (debugging) { 2759 if (debugging) {
2752 buffer = Vector<char>::New(128); 2760 buffer = Vector<char>::New(128);
2753 SNPrintF(buffer, "js-to-wasm#%d", id); 2761 SNPrintF(buffer, "js-to-wasm#%d", id);
2754 func_name = buffer.start(); 2762 func_name = buffer.start();
2755 } 2763 }
2756 2764
2757 CompilationInfo info(func_name, isolate, &zone, flags); 2765 CompilationInfo info(func_name, isolate, &zone, flags);
2758 Handle<Code> code = 2766 Handle<Code> code =
2759 Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); 2767 Pipeline::GenerateCodeForTesting(&info, incoming, &graph);
2760 #ifdef ENABLE_DISASSEMBLER 2768 #ifdef ENABLE_DISASSEMBLER
2761 if (FLAG_print_opt_code && !code.is_null()) { 2769 if (FLAG_print_opt_code && !code.is_null()) {
2762 OFStream os(stdout); 2770 OFStream os(stdout);
2763 code->Disassemble(buffer.start(), os); 2771 code->Disassemble(buffer.start(), os);
2764 } 2772 }
2765 #endif 2773 #endif
2766 if (debugging) { 2774 if (debugging) {
2767 buffer.Dispose(); 2775 buffer.Dispose();
2768 } 2776 }
2769 2777
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2840 if (debugging) { 2848 if (debugging) {
2841 buffer.Dispose(); 2849 buffer.Dispose();
2842 } 2850 }
2843 2851
2844 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", 0, 2852 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", 0,
2845 module_name); 2853 module_name);
2846 } 2854 }
2847 return code; 2855 return code;
2848 } 2856 }
2849 2857
2850 JSGraph* BuildGraphForWasmFunction(Zone* zone, wasm::ErrorThrower& thrower, 2858 std::pair<JSGraph*, SourcePositionTable*> BuildGraphForWasmFunction(
2851 Isolate* isolate, 2859 Zone* zone, wasm::ErrorThrower& thrower, Isolate* isolate,
2852 wasm::ModuleEnv*& module_env, 2860 wasm::ModuleEnv*& module_env, const wasm::WasmFunction& function,
2853 const wasm::WasmFunction& function, 2861 double* decode_ms) {
2854 double* decode_ms) {
2855 base::ElapsedTimer decode_timer; 2862 base::ElapsedTimer decode_timer;
2856 if (FLAG_trace_wasm_decode_time) { 2863 if (FLAG_trace_wasm_decode_time) {
2857 decode_timer.Start(); 2864 decode_timer.Start();
2858 } 2865 }
2859 // Create a TF graph during decoding. 2866 // Create a TF graph during decoding.
2860 Graph* graph = new (zone) Graph(zone); 2867 Graph* graph = new (zone) Graph(zone);
2861 CommonOperatorBuilder* common = new (zone) CommonOperatorBuilder(zone); 2868 CommonOperatorBuilder* common = new (zone) CommonOperatorBuilder(zone);
2862 MachineOperatorBuilder* machine = new (zone) MachineOperatorBuilder( 2869 MachineOperatorBuilder* machine = new (zone) MachineOperatorBuilder(
2863 zone, MachineType::PointerRepresentation(), 2870 zone, MachineType::PointerRepresentation(),
2864 InstructionSelector::SupportedMachineOperatorFlags()); 2871 InstructionSelector::SupportedMachineOperatorFlags());
2865 JSGraph* jsgraph = 2872 JSGraph* jsgraph =
2866 new (zone) JSGraph(isolate, graph, common, nullptr, nullptr, machine); 2873 new (zone) JSGraph(isolate, graph, common, nullptr, nullptr, machine);
2867 WasmGraphBuilder builder(zone, jsgraph, function.sig); 2874 SourcePositionTable* source_position_table =
2875 new (zone) SourcePositionTable(graph);
2876 WasmGraphBuilder builder(zone, jsgraph, function.sig, source_position_table);
2868 wasm::FunctionBody body = { 2877 wasm::FunctionBody body = {
2869 module_env, function.sig, module_env->module->module_start, 2878 module_env, function.sig, module_env->module->module_start,
2870 module_env->module->module_start + function.code_start_offset, 2879 module_env->module->module_start + function.code_start_offset,
2871 module_env->module->module_start + function.code_end_offset}; 2880 module_env->module->module_start + function.code_end_offset};
2872 wasm::TreeResult result = 2881 wasm::TreeResult result =
2873 wasm::BuildTFGraph(isolate->allocator(), &builder, body); 2882 wasm::BuildTFGraph(isolate->allocator(), &builder, body);
2874 2883
2875 if (machine->Is32()) { 2884 if (machine->Is32()) {
2876 Int64Lowering r(graph, machine, common, zone, function.sig); 2885 Int64Lowering r(graph, machine, common, zone, function.sig);
2877 r.LowerGraph(); 2886 r.LowerGraph();
2878 } 2887 }
2879 2888
2880 if (result.failed()) { 2889 if (result.failed()) {
2881 if (FLAG_trace_wasm_compiler) { 2890 if (FLAG_trace_wasm_compiler) {
2882 OFStream os(stdout); 2891 OFStream os(stdout);
2883 os << "Compilation failed: " << result << std::endl; 2892 os << "Compilation failed: " << result << std::endl;
2884 } 2893 }
2885 // Add the function as another context for the exception 2894 // Add the function as another context for the exception
2886 ScopedVector<char> buffer(128); 2895 ScopedVector<char> buffer(128);
2887 wasm::WasmName name = 2896 wasm::WasmName name =
2888 module_env->module->GetName(function.name_offset, function.name_length); 2897 module_env->module->GetName(function.name_offset, function.name_length);
2889 SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:", 2898 SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:",
2890 function.func_index, name.length, name.name); 2899 function.func_index, name.length, name.name);
2891 thrower.Failed(buffer.start(), result); 2900 thrower.Failed(buffer.start(), result);
2892 return nullptr; 2901 return std::make_pair(nullptr, nullptr);
2893 } 2902 }
2894 int index = static_cast<int>(function.func_index); 2903 int index = static_cast<int>(function.func_index);
2895 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { 2904 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) {
2896 PrintAst(isolate->allocator(), body); 2905 PrintAst(isolate->allocator(), body);
2897 } 2906 }
2898 if (FLAG_trace_wasm_decode_time) { 2907 if (FLAG_trace_wasm_decode_time) {
2899 *decode_ms = decode_timer.Elapsed().InMillisecondsF(); 2908 *decode_ms = decode_timer.Elapsed().InMillisecondsF();
2900 } 2909 }
2901 return jsgraph; 2910 return std::make_pair(jsgraph, source_position_table);
2902 } 2911 }
2903 2912
2904 // Helper function to compile a single function. 2913 // Helper function to compile a single function.
2905 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, 2914 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
2906 wasm::ModuleEnv* module_env, 2915 wasm::ModuleEnv* module_env,
2907 const wasm::WasmFunction& function) { 2916 const wasm::WasmFunction& function) {
2908 HistogramTimerScope wasm_compile_function_time_scope( 2917 HistogramTimerScope wasm_compile_function_time_scope(
2909 isolate->counters()->wasm_compile_function_time()); 2918 isolate->counters()->wasm_compile_function_time());
2910 if (FLAG_trace_wasm_compiler) { 2919 if (FLAG_trace_wasm_compiler) {
2911 OFStream os(stdout); 2920 OFStream os(stdout);
2912 os << "Compiling WASM function " 2921 os << "Compiling WASM function "
2913 << wasm::WasmFunctionName(&function, module_env) << std::endl; 2922 << wasm::WasmFunctionName(&function, module_env) << std::endl;
2914 os << std::endl; 2923 os << std::endl;
2915 } 2924 }
2916 2925
2917 compiler::ZonePool zone_pool(isolate->allocator()); 2926 compiler::ZonePool zone_pool(isolate->allocator());
2918 compiler::ZonePool::Scope graph_zone_scope(&zone_pool); 2927 compiler::ZonePool::Scope graph_zone_scope(&zone_pool);
2919 double decode_ms = 0; 2928 double decode_ms = 0;
2920 JSGraph* jsgraph = 2929 std::pair<JSGraph*, SourcePositionTable*> graph_result =
2921 BuildGraphForWasmFunction(graph_zone_scope.zone(), thrower, isolate, 2930 BuildGraphForWasmFunction(graph_zone_scope.zone(), thrower, isolate,
2922 module_env, function, &decode_ms); 2931 module_env, function, &decode_ms);
2932 JSGraph* jsgraph = graph_result.first;
2933 SourcePositionTable* source_positions = graph_result.second;
2923 2934
2924 if (jsgraph == nullptr) { 2935 if (jsgraph == nullptr) {
2925 return Handle<Code>::null(); 2936 return Handle<Code>::null();
2926 } 2937 }
2927 2938
2928 base::ElapsedTimer compile_timer; 2939 base::ElapsedTimer compile_timer;
2929 if (FLAG_trace_wasm_decode_time) { 2940 if (FLAG_trace_wasm_decode_time) {
2930 compile_timer.Start(); 2941 compile_timer.Start();
2931 } 2942 }
2932 // Run the compiler pipeline to generate machine code. 2943 // Run the compiler pipeline to generate machine code.
(...skipping 18 matching lines...) Expand all
2951 wasm::WasmName name = 2962 wasm::WasmName name =
2952 module_env->module->GetName(function.name_offset, function.name_length); 2963 module_env->module->GetName(function.name_offset, function.name_length);
2953 SNPrintF(buffer, "WASM_function_#%d:%.*s", function.func_index, name.length, 2964 SNPrintF(buffer, "WASM_function_#%d:%.*s", function.func_index, name.length,
2954 name.name); 2965 name.name);
2955 func_name = buffer.start(); 2966 func_name = buffer.start();
2956 } 2967 }
2957 CompilationInfo info(func_name, isolate, jsgraph->graph()->zone(), flags); 2968 CompilationInfo info(func_name, isolate, jsgraph->graph()->zone(), flags);
2958 compiler::ZonePool::Scope pipeline_zone_scope(&zone_pool); 2969 compiler::ZonePool::Scope pipeline_zone_scope(&zone_pool);
2959 Pipeline pipeline(&info); 2970 Pipeline pipeline(&info);
2960 pipeline.InitializeWasmCompilation(pipeline_zone_scope.zone(), &zone_pool, 2971 pipeline.InitializeWasmCompilation(pipeline_zone_scope.zone(), &zone_pool,
2961 jsgraph->graph()); 2972 jsgraph->graph(), source_positions);
2962 Handle<Code> code; 2973 Handle<Code> code;
2963 if (pipeline.ExecuteWasmCompilation(descriptor)) { 2974 if (pipeline.ExecuteWasmCompilation(descriptor)) {
2964 code = pipeline.FinalizeWasmCompilation(descriptor); 2975 code = pipeline.FinalizeWasmCompilation(descriptor);
2965 } else { 2976 } else {
2966 code = Handle<Code>::null(); 2977 code = Handle<Code>::null();
2967 } 2978 }
2968 2979
2969 if (debugging) { 2980 if (debugging) {
2970 buffer.Dispose(); 2981 buffer.Dispose();
2971 } 2982 }
(...skipping 16 matching lines...) Expand all
2988 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( 2999 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample(
2989 static_cast<int>(jsgraph->graph()->zone()->allocation_size())); 3000 static_cast<int>(jsgraph->graph()->zone()->allocation_size()));
2990 graph_zone_scope.Destroy(); 3001 graph_zone_scope.Destroy();
2991 return code; 3002 return code;
2992 } 3003 }
2993 3004
2994 3005
2995 } // namespace compiler 3006 } // namespace compiler
2996 } // namespace internal 3007 } // namespace internal
2997 } // namespace v8 3008 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/wasm/ast-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698