| OLD | NEW |
| 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 2734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2745 module->GetFunctionSignature(index)->parameter_count()); | 2745 module->GetFunctionSignature(index)->parameter_count()); |
| 2746 CallDescriptor* incoming = Linkage::GetJSCallDescriptor( | 2746 CallDescriptor* incoming = Linkage::GetJSCallDescriptor( |
| 2747 &zone, false, params + 1, CallDescriptor::kNoFlags); | 2747 &zone, false, params + 1, CallDescriptor::kNoFlags); |
| 2748 Code::Flags flags = Code::ComputeFlags(Code::JS_TO_WASM_FUNCTION); | 2748 Code::Flags flags = Code::ComputeFlags(Code::JS_TO_WASM_FUNCTION); |
| 2749 bool debugging = | 2749 bool debugging = |
| 2750 #if DEBUG | 2750 #if DEBUG |
| 2751 true; | 2751 true; |
| 2752 #else | 2752 #else |
| 2753 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; | 2753 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; |
| 2754 #endif | 2754 #endif |
| 2755 const char* func_name = "js-to-wasm"; | 2755 Vector<const char> func_name = ArrayVector("js-to-wasm"); |
| 2756 | 2756 |
| 2757 static unsigned id = 0; | 2757 static unsigned id = 0; |
| 2758 Vector<char> buffer; | 2758 Vector<char> buffer; |
| 2759 if (debugging) { | 2759 if (debugging) { |
| 2760 buffer = Vector<char>::New(128); | 2760 buffer = Vector<char>::New(128); |
| 2761 SNPrintF(buffer, "js-to-wasm#%d", id); | 2761 int chars = SNPrintF(buffer, "js-to-wasm#%d", id); |
| 2762 func_name = buffer.start(); | 2762 func_name = Vector<const char>::cast(buffer.SubVector(0, chars)); |
| 2763 } | 2763 } |
| 2764 | 2764 |
| 2765 CompilationInfo info(func_name, isolate, &zone, flags); | 2765 CompilationInfo info(func_name, isolate, &zone, flags); |
| 2766 Handle<Code> code = | 2766 Handle<Code> code = |
| 2767 Pipeline::GenerateCodeForTesting(&info, incoming, &graph); | 2767 Pipeline::GenerateCodeForTesting(&info, incoming, &graph); |
| 2768 #ifdef ENABLE_DISASSEMBLER | 2768 #ifdef ENABLE_DISASSEMBLER |
| 2769 if (FLAG_print_opt_code && !code.is_null()) { | 2769 if (FLAG_print_opt_code && !code.is_null()) { |
| 2770 OFStream os(stdout); | 2770 OFStream os(stdout); |
| 2771 code->Disassemble(buffer.start(), os); | 2771 code->Disassemble(buffer.start(), os); |
| 2772 } | 2772 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2821 if (machine.Is32()) { | 2821 if (machine.Is32()) { |
| 2822 incoming = wasm::ModuleEnv::GetI32WasmCallDescriptor(&zone, incoming); | 2822 incoming = wasm::ModuleEnv::GetI32WasmCallDescriptor(&zone, incoming); |
| 2823 } | 2823 } |
| 2824 Code::Flags flags = Code::ComputeFlags(Code::WASM_TO_JS_FUNCTION); | 2824 Code::Flags flags = Code::ComputeFlags(Code::WASM_TO_JS_FUNCTION); |
| 2825 bool debugging = | 2825 bool debugging = |
| 2826 #if DEBUG | 2826 #if DEBUG |
| 2827 true; | 2827 true; |
| 2828 #else | 2828 #else |
| 2829 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; | 2829 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; |
| 2830 #endif | 2830 #endif |
| 2831 const char* func_name = "wasm-to-js"; | 2831 Vector<const char> func_name = ArrayVector("wasm-to-js"); |
| 2832 static unsigned id = 0; | 2832 static unsigned id = 0; |
| 2833 Vector<char> buffer; | 2833 Vector<char> buffer; |
| 2834 if (debugging) { | 2834 if (debugging) { |
| 2835 buffer = Vector<char>::New(128); | 2835 buffer = Vector<char>::New(128); |
| 2836 SNPrintF(buffer, "wasm-to-js#%d", id); | 2836 int chars = SNPrintF(buffer, "wasm-to-js#%d", id); |
| 2837 func_name = buffer.start(); | 2837 func_name = Vector<const char>::cast(buffer.SubVector(0, chars)); |
| 2838 } | 2838 } |
| 2839 | 2839 |
| 2840 CompilationInfo info(func_name, isolate, &zone, flags); | 2840 CompilationInfo info(func_name, isolate, &zone, flags); |
| 2841 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); | 2841 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); |
| 2842 #ifdef ENABLE_DISASSEMBLER | 2842 #ifdef ENABLE_DISASSEMBLER |
| 2843 if (FLAG_print_opt_code && !code.is_null()) { | 2843 if (FLAG_print_opt_code && !code.is_null()) { |
| 2844 OFStream os(stdout); | 2844 OFStream os(stdout); |
| 2845 code->Disassemble(buffer.start(), os); | 2845 code->Disassemble(buffer.start(), os); |
| 2846 } | 2846 } |
| 2847 #endif | 2847 #endif |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2948 descriptor); | 2948 descriptor); |
| 2949 } | 2949 } |
| 2950 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); | 2950 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
| 2951 // add flags here if a meaningful name is helpful for debugging. | 2951 // add flags here if a meaningful name is helpful for debugging. |
| 2952 bool debugging = | 2952 bool debugging = |
| 2953 #if DEBUG | 2953 #if DEBUG |
| 2954 true; | 2954 true; |
| 2955 #else | 2955 #else |
| 2956 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; | 2956 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; |
| 2957 #endif | 2957 #endif |
| 2958 const char* func_name = "wasm"; | 2958 Vector<const char> func_name = |
| 2959 module_env->module |
| 2960 ->GetNameOrNull(function.name_offset, function.name_length) |
| 2961 .toVec(); |
| 2959 Vector<char> buffer; | 2962 Vector<char> buffer; |
| 2960 if (debugging) { | 2963 if (func_name.is_empty()) { |
| 2961 buffer = Vector<char>::New(128); | 2964 if (debugging) { |
| 2962 wasm::WasmName name = | 2965 buffer = Vector<char>::New(128); |
| 2963 module_env->module->GetName(function.name_offset, function.name_length); | 2966 int chars = SNPrintF(buffer, "WASM_function_#%d", function.func_index); |
| 2964 SNPrintF(buffer, "WASM_function_#%d:%.*s", function.func_index, name.length, | 2967 func_name = Vector<const char>::cast(buffer.SubVector(0, chars)); |
| 2965 name.name); | 2968 } else { |
| 2966 func_name = buffer.start(); | 2969 func_name = ArrayVector("wasm"); |
| 2970 } |
| 2967 } | 2971 } |
| 2968 CompilationInfo info(func_name, isolate, jsgraph->graph()->zone(), flags); | 2972 CompilationInfo info(func_name, isolate, jsgraph->graph()->zone(), flags); |
| 2969 compiler::ZonePool::Scope pipeline_zone_scope(&zone_pool); | 2973 compiler::ZonePool::Scope pipeline_zone_scope(&zone_pool); |
| 2970 Pipeline pipeline(&info); | 2974 Pipeline pipeline(&info); |
| 2971 pipeline.InitializeWasmCompilation(pipeline_zone_scope.zone(), &zone_pool, | 2975 pipeline.InitializeWasmCompilation(pipeline_zone_scope.zone(), &zone_pool, |
| 2972 jsgraph->graph(), source_positions); | 2976 jsgraph->graph(), source_positions); |
| 2973 Handle<Code> code; | 2977 Handle<Code> code; |
| 2974 if (pipeline.ExecuteWasmCompilation(descriptor)) { | 2978 if (pipeline.ExecuteWasmCompilation(descriptor)) { |
| 2975 code = pipeline.FinalizeWasmCompilation(descriptor); | 2979 code = pipeline.FinalizeWasmCompilation(descriptor); |
| 2976 } else { | 2980 } else { |
| 2977 code = Handle<Code>::null(); | 2981 code = Handle<Code>::null(); |
| 2978 } | 2982 } |
| 2979 | 2983 |
| 2980 if (debugging) { | 2984 buffer.Dispose(); |
| 2981 buffer.Dispose(); | |
| 2982 } | |
| 2983 if (!code.is_null()) { | 2985 if (!code.is_null()) { |
| 2984 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function", | 2986 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function", |
| 2985 function.func_index, | 2987 function.func_index, |
| 2986 module_env->module->GetName( | 2988 module_env->module->GetName( |
| 2987 function.name_offset, function.name_length)); | 2989 function.name_offset, function.name_length)); |
| 2988 } | 2990 } |
| 2989 | 2991 |
| 2990 if (FLAG_trace_wasm_decode_time) { | 2992 if (FLAG_trace_wasm_decode_time) { |
| 2991 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); | 2993 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); |
| 2992 PrintF( | 2994 PrintF( |
| 2993 "wasm-compile ok: %d bytes, %0.3f ms decode, %d nodes, %0.3f ms " | 2995 "wasm-compile ok: %d bytes, %0.3f ms decode, %d nodes, %0.3f ms " |
| 2994 "compile\n", | 2996 "compile\n", |
| 2995 static_cast<int>(function.code_end_offset - function.code_start_offset), | 2997 static_cast<int>(function.code_end_offset - function.code_start_offset), |
| 2996 decode_ms, static_cast<int>(jsgraph->graph()->NodeCount()), compile_ms); | 2998 decode_ms, static_cast<int>(jsgraph->graph()->NodeCount()), compile_ms); |
| 2997 } | 2999 } |
| 2998 // TODO(bradnelson): Improve histogram handling of size_t. | 3000 // TODO(bradnelson): Improve histogram handling of size_t. |
| 2999 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( | 3001 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( |
| 3000 static_cast<int>(jsgraph->graph()->zone()->allocation_size())); | 3002 static_cast<int>(jsgraph->graph()->zone()->allocation_size())); |
| 3001 graph_zone_scope.Destroy(); | 3003 graph_zone_scope.Destroy(); |
| 3002 return code; | 3004 return code; |
| 3003 } | 3005 } |
| 3004 | 3006 |
| 3005 | 3007 |
| 3006 } // namespace compiler | 3008 } // namespace compiler |
| 3007 } // namespace internal | 3009 } // namespace internal |
| 3008 } // namespace v8 | 3010 } // namespace v8 |
| OLD | NEW |