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/platform.h" | 9 #include "src/base/platform/platform.h" |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "src/compiler/machine-operator.h" | 22 #include "src/compiler/machine-operator.h" |
23 #include "src/compiler/node-matchers.h" | 23 #include "src/compiler/node-matchers.h" |
24 #include "src/compiler/pipeline.h" | 24 #include "src/compiler/pipeline.h" |
25 #include "src/compiler/simplified-lowering.h" | 25 #include "src/compiler/simplified-lowering.h" |
26 #include "src/compiler/simplified-operator.h" | 26 #include "src/compiler/simplified-operator.h" |
27 #include "src/compiler/source-position.h" | 27 #include "src/compiler/source-position.h" |
28 #include "src/compiler/typer.h" | 28 #include "src/compiler/typer.h" |
29 | 29 |
30 #include "src/code-factory.h" | 30 #include "src/code-factory.h" |
31 #include "src/code-stubs.h" | 31 #include "src/code-stubs.h" |
32 #include "src/factory.h" | |
33 #include "src/log-inl.h" | |
34 #include "src/profiler/cpu-profiler.h" | |
32 | 35 |
33 #include "src/wasm/ast-decoder.h" | 36 #include "src/wasm/ast-decoder.h" |
34 #include "src/wasm/wasm-module.h" | 37 #include "src/wasm/wasm-module.h" |
35 #include "src/wasm/wasm-opcodes.h" | 38 #include "src/wasm/wasm-opcodes.h" |
36 | 39 |
37 // TODO(titzer): pull WASM_64 up to a common header. | 40 // TODO(titzer): pull WASM_64 up to a common header. |
38 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 | 41 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 |
39 #define WASM_64 1 | 42 #define WASM_64 1 |
40 #else | 43 #else |
41 #define WASM_64 0 | 44 #define WASM_64 0 |
(...skipping 1875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1917 // Schedule and compile to machine code. | 1920 // Schedule and compile to machine code. |
1918 int params = static_cast<int>( | 1921 int params = static_cast<int>( |
1919 module->GetFunctionSignature(index)->parameter_count()); | 1922 module->GetFunctionSignature(index)->parameter_count()); |
1920 CallDescriptor* incoming = Linkage::GetJSCallDescriptor( | 1923 CallDescriptor* incoming = Linkage::GetJSCallDescriptor( |
1921 &zone, false, params + 1, CallDescriptor::kNoFlags); | 1924 &zone, false, params + 1, CallDescriptor::kNoFlags); |
1922 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. | 1925 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. |
1923 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); | 1926 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
1924 CompilationInfo info("js-to-wasm", isolate, &zone, flags); | 1927 CompilationInfo info("js-to-wasm", isolate, &zone, flags); |
1925 Handle<Code> code = | 1928 Handle<Code> code = |
1926 Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); | 1929 Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); |
1927 | 1930 if (info.isolate()->logger()->is_logging_code_events() || |
1928 #ifdef ENABLE_DISASSEMBLER | 1931 info.isolate()->cpu_profiler()->is_profiling()) { |
1929 // Disassemble the wrapper code for debugging. | 1932 ScopedVector<char> buffer(128); |
1930 if (!code.is_null() && FLAG_print_opt_code) { | 1933 SNPrintF(buffer, "JS->WASM_function_wrapper_#%d:%s", index, |
1931 Vector<char> buffer; | 1934 module->module->GetName(func->name_offset)); |
1932 const char* name = ""; | 1935 Handle<String> name_str = |
1933 if (func->name_offset > 0) { | 1936 isolate->factory()->NewStringFromAsciiChecked(buffer.start()); |
1934 const byte* ptr = module->module->module_start + func->name_offset; | 1937 Handle<SharedFunctionInfo> shared = |
titzer
2016/01/26 15:42:31
You should probably use the shared function info f
Weiliang
2016/01/28 14:03:35
the shared function info here is the js-to-wasm tr
| |
1935 name = reinterpret_cast<const char*>(ptr); | 1938 isolate->factory()->NewSharedFunctionInfo(name_str, code, false); |
1936 } | 1939 PROFILE(info.isolate(), CodeCreateEvent(Logger::FUNCTION_TAG, *code, |
1937 SNPrintF(buffer, "JS->WASM function wrapper #%d:%s", index, name); | 1940 *shared, &info, *name_str, 0, 0)); |
1938 OFStream os(stdout); | |
1939 code->Disassemble(buffer.start(), os); | |
1940 } | 1941 } |
1941 #endif | |
1942 // Set the JSFunction's machine code. | 1942 // Set the JSFunction's machine code. |
1943 function->set_code(*code); | 1943 function->set_code(*code); |
1944 } | 1944 } |
1945 return function; | 1945 return function; |
1946 } | 1946 } |
1947 | 1947 |
1948 | 1948 |
1949 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module, | 1949 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module, |
1950 Handle<JSFunction> function, | 1950 Handle<JSFunction> function, |
1951 uint32_t index) { | 1951 uint32_t index) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1992 os << AsRPO(graph); | 1992 os << AsRPO(graph); |
1993 } | 1993 } |
1994 | 1994 |
1995 // Schedule and compile to machine code. | 1995 // Schedule and compile to machine code. |
1996 CallDescriptor* incoming = module->GetWasmCallDescriptor(&zone, func->sig); | 1996 CallDescriptor* incoming = module->GetWasmCallDescriptor(&zone, func->sig); |
1997 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. | 1997 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. |
1998 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); | 1998 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
1999 CompilationInfo info("wasm-to-js", isolate, &zone, flags); | 1999 CompilationInfo info("wasm-to-js", isolate, &zone, flags); |
2000 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); | 2000 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); |
2001 | 2001 |
2002 #ifdef ENABLE_DISASSEMBLER | 2002 if (info.isolate()->logger()->is_logging_code_events() || |
2003 // Disassemble the wrapper code for debugging. | 2003 info.isolate()->cpu_profiler()->is_profiling()) { |
2004 if (!code.is_null() && FLAG_print_opt_code) { | 2004 ScopedVector<char> buffer(128); |
2005 Vector<char> buffer; | 2005 SNPrintF(buffer, "WASM->JS_function_wrapper_#%d:%s", index, |
2006 const char* name = ""; | 2006 module->module->GetName(func->name_offset)); |
2007 if (func->name_offset > 0) { | 2007 Handle<String> name_str = |
2008 const byte* ptr = module->module->module_start + func->name_offset; | 2008 isolate->factory()->NewStringFromAsciiChecked(buffer.start()); |
2009 name = reinterpret_cast<const char*>(ptr); | 2009 Handle<SharedFunctionInfo> shared = |
2010 } | 2010 isolate->factory()->NewSharedFunctionInfo(name_str, code, false); |
2011 SNPrintF(buffer, "WASM->JS function wrapper #%d:%s", index, name); | 2011 PROFILE(info.isolate(), CodeCreateEvent(Logger::FUNCTION_TAG, *code, |
2012 OFStream os(stdout); | 2012 *shared, &info, *name_str, 0, 0)); |
2013 code->Disassemble(buffer.start(), os); | |
2014 } | 2013 } |
2015 #endif | |
2016 } | 2014 } |
2017 return code; | 2015 return code; |
2018 } | 2016 } |
2019 | 2017 |
2020 | 2018 |
2021 // Helper function to compile a single function. | 2019 // Helper function to compile a single function. |
2022 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, | 2020 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, |
2023 wasm::ModuleEnv* module_env, | 2021 wasm::ModuleEnv* module_env, |
2024 const wasm::WasmFunction& function, | 2022 const wasm::WasmFunction& function, |
2025 int index) { | 2023 int index) { |
2024 ScopedVector<char> buffer(128); | |
titzer
2016/01/26 15:42:31
This will always build this string, even when it i
Weiliang
2016/01/28 14:03:35
Done.
| |
2025 SNPrintF(buffer, "WASM_function_#%d:%s", index, | |
2026 module_env->module->GetName(function.name_offset)); | |
2026 if (FLAG_trace_wasm_compiler || FLAG_trace_wasm_decode_time) { | 2027 if (FLAG_trace_wasm_compiler || FLAG_trace_wasm_decode_time) { |
2027 // TODO(titzer): clean me up a bit. | 2028 // TODO(titzer): clean me up a bit. |
2028 OFStream os(stdout); | 2029 OFStream os(stdout); |
2029 os << "Compiling WASM function #" << index << ":"; | 2030 os << "Compiling " << buffer.start() << std::endl; |
2030 if (function.name_offset > 0) { | |
2031 os << module_env->module->GetName(function.name_offset); | |
2032 } | |
2033 os << std::endl; | |
2034 } | 2031 } |
2035 // Initialize the function environment for decoding. | 2032 // Initialize the function environment for decoding. |
2036 wasm::FunctionEnv env; | 2033 wasm::FunctionEnv env; |
2037 env.module = module_env; | 2034 env.module = module_env; |
2038 env.sig = function.sig; | 2035 env.sig = function.sig; |
2039 env.local_int32_count = function.local_int32_count; | 2036 env.local_int32_count = function.local_int32_count; |
2040 env.local_int64_count = function.local_int64_count; | 2037 env.local_int64_count = function.local_int64_count; |
2041 env.local_float32_count = function.local_float32_count; | 2038 env.local_float32_count = function.local_float32_count; |
2042 env.local_float64_count = function.local_float64_count; | 2039 env.local_float64_count = function.local_float64_count; |
2043 env.SumLocals(); | 2040 env.SumLocals(); |
(...skipping 12 matching lines...) Expand all Loading... | |
2056 module_env->module->module_start, // -- | 2053 module_env->module->module_start, // -- |
2057 module_env->module->module_start + function.code_start_offset, // -- | 2054 module_env->module->module_start + function.code_start_offset, // -- |
2058 module_env->module->module_start + function.code_end_offset); // -- | 2055 module_env->module->module_start + function.code_end_offset); // -- |
2059 | 2056 |
2060 if (result.failed()) { | 2057 if (result.failed()) { |
2061 if (FLAG_trace_wasm_compiler) { | 2058 if (FLAG_trace_wasm_compiler) { |
2062 OFStream os(stdout); | 2059 OFStream os(stdout); |
2063 os << "Compilation failed: " << result << std::endl; | 2060 os << "Compilation failed: " << result << std::endl; |
2064 } | 2061 } |
2065 // Add the function as another context for the exception | 2062 // Add the function as another context for the exception |
2066 Vector<char> buffer; | 2063 SNPrintF(buffer, "Compiling %s failed:", buffer.start()); |
titzer
2016/01/26 15:42:31
This probably corrupts the buffer, since it uses t
Weiliang
2016/01/28 14:03:35
Done.
| |
2067 SNPrintF(buffer, "Compiling WASM function #%d:%s failed:", index, | |
2068 module_env->module->GetName(function.name_offset)); | |
2069 thrower.Failed(buffer.start(), result); | 2064 thrower.Failed(buffer.start(), result); |
2070 return Handle<Code>::null(); | 2065 return Handle<Code>::null(); |
2071 } | 2066 } |
2072 | 2067 |
2073 // Run the compiler pipeline to generate machine code. | 2068 // Run the compiler pipeline to generate machine code. |
2074 CallDescriptor* descriptor = const_cast<CallDescriptor*>( | 2069 CallDescriptor* descriptor = const_cast<CallDescriptor*>( |
2075 module_env->GetWasmCallDescriptor(&zone, function.sig)); | 2070 module_env->GetWasmCallDescriptor(&zone, function.sig)); |
2076 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); | 2071 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
2077 CompilationInfo info("wasm", isolate, &zone, flags); | 2072 CompilationInfo info(buffer.start(), isolate, &zone, flags); |
2078 Handle<Code> code = | 2073 Handle<Code> code = |
2079 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph); | 2074 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph); |
2080 | 2075 |
2081 #ifdef ENABLE_DISASSEMBLER | 2076 if (info.isolate()->logger()->is_logging_code_events() || |
danno
2016/01/26 08:40:06
Could you please turn this combined test into a se
Weiliang
2016/01/28 14:03:35
Done.
| |
2082 // Disassemble the code for debugging. | 2077 info.isolate()->cpu_profiler()->is_profiling()) { |
2083 if (!code.is_null() && FLAG_print_opt_code) { | 2078 Handle<String> name_str = |
2084 Vector<char> buffer; | 2079 isolate->factory()->NewStringFromAsciiChecked(buffer.start()); |
2085 const char* name = ""; | 2080 Handle<String> script_str = |
2086 if (function.name_offset > 0) { | 2081 isolate->factory()->NewStringFromAsciiChecked("(WASM)"); |
2087 const byte* ptr = module_env->module->module_start + function.name_offset; | 2082 Handle<SharedFunctionInfo> shared = |
2088 name = reinterpret_cast<const char*>(ptr); | 2083 isolate->factory()->NewSharedFunctionInfo(name_str, code, false); |
2089 } | 2084 PROFILE(info.isolate(), CodeCreateEvent(Logger::FUNCTION_TAG, *code, |
2090 SNPrintF(buffer, "WASM function #%d:%s", index, name); | 2085 *shared, &info, *script_str, 0, 0)); |
2091 OFStream os(stdout); | |
2092 code->Disassemble(buffer.start(), os); | |
2093 } | 2086 } |
2094 #endif | 2087 |
2088 | |
2095 return code; | 2089 return code; |
2096 } | 2090 } |
2097 | 2091 |
2098 | 2092 |
2099 } // namespace compiler | 2093 } // namespace compiler |
2100 } // namespace internal | 2094 } // namespace internal |
2101 } // namespace v8 | 2095 } // namespace v8 |
OLD | NEW |