| 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 1831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 OFStream os(stdout); | 1842 OFStream os(stdout); |
| 1843 os << "-- Graph after change lowering -- " << std::endl; | 1843 os << "-- Graph after change lowering -- " << std::endl; |
| 1844 os << AsRPO(graph); | 1844 os << AsRPO(graph); |
| 1845 } | 1845 } |
| 1846 | 1846 |
| 1847 // Schedule and compile to machine code. | 1847 // Schedule and compile to machine code. |
| 1848 int params = static_cast<int>( | 1848 int params = static_cast<int>( |
| 1849 module->GetFunctionSignature(index)->parameter_count()); | 1849 module->GetFunctionSignature(index)->parameter_count()); |
| 1850 CallDescriptor* incoming = Linkage::GetJSCallDescriptor( | 1850 CallDescriptor* incoming = Linkage::GetJSCallDescriptor( |
| 1851 &zone, false, params + 1, CallDescriptor::kNoFlags); | 1851 &zone, false, params + 1, CallDescriptor::kNoFlags); |
| 1852 CompilationInfo info("js-to-wasm", isolate, &zone); | |
| 1853 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. | 1852 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. |
| 1854 info.set_output_code_kind(Code::WASM_FUNCTION); | 1853 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
| 1854 CompilationInfo info("js-to-wasm", isolate, &zone, flags); |
| 1855 Handle<Code> code = | 1855 Handle<Code> code = |
| 1856 Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); | 1856 Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); |
| 1857 | 1857 |
| 1858 #ifdef ENABLE_DISASSEMBLER | 1858 #ifdef ENABLE_DISASSEMBLER |
| 1859 // Disassemble the wrapper code for debugging. | 1859 // Disassemble the wrapper code for debugging. |
| 1860 if (!code.is_null() && FLAG_print_opt_code) { | 1860 if (!code.is_null() && FLAG_print_opt_code) { |
| 1861 Vector<char> buffer; | 1861 Vector<char> buffer; |
| 1862 const char* name = ""; | 1862 const char* name = ""; |
| 1863 if (func->name_offset > 0) { | 1863 if (func->name_offset > 0) { |
| 1864 const byte* ptr = module->module->module_start + func->name_offset; | 1864 const byte* ptr = module->module->module_start + func->name_offset; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1917 graph_reducer.ReduceGraph(); | 1917 graph_reducer.ReduceGraph(); |
| 1918 | 1918 |
| 1919 if (FLAG_trace_turbo_graph) { // Simple textual RPO. | 1919 if (FLAG_trace_turbo_graph) { // Simple textual RPO. |
| 1920 OFStream os(stdout); | 1920 OFStream os(stdout); |
| 1921 os << "-- Graph after change lowering -- " << std::endl; | 1921 os << "-- Graph after change lowering -- " << std::endl; |
| 1922 os << AsRPO(graph); | 1922 os << AsRPO(graph); |
| 1923 } | 1923 } |
| 1924 | 1924 |
| 1925 // Schedule and compile to machine code. | 1925 // Schedule and compile to machine code. |
| 1926 CallDescriptor* incoming = module->GetWasmCallDescriptor(&zone, func->sig); | 1926 CallDescriptor* incoming = module->GetWasmCallDescriptor(&zone, func->sig); |
| 1927 CompilationInfo info("wasm-to-js", isolate, &zone); | |
| 1928 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. | 1927 // TODO(titzer): this is technically a WASM wrapper, not a wasm function. |
| 1929 info.set_output_code_kind(Code::WASM_FUNCTION); | 1928 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
| 1929 CompilationInfo info("wasm-to-js", isolate, &zone, flags); |
| 1930 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); | 1930 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); |
| 1931 | 1931 |
| 1932 #ifdef ENABLE_DISASSEMBLER | 1932 #ifdef ENABLE_DISASSEMBLER |
| 1933 // Disassemble the wrapper code for debugging. | 1933 // Disassemble the wrapper code for debugging. |
| 1934 if (!code.is_null() && FLAG_print_opt_code) { | 1934 if (!code.is_null() && FLAG_print_opt_code) { |
| 1935 Vector<char> buffer; | 1935 Vector<char> buffer; |
| 1936 const char* name = ""; | 1936 const char* name = ""; |
| 1937 if (func->name_offset > 0) { | 1937 if (func->name_offset > 0) { |
| 1938 const byte* ptr = module->module->module_start + func->name_offset; | 1938 const byte* ptr = module->module->module_start + func->name_offset; |
| 1939 name = reinterpret_cast<const char*>(ptr); | 1939 name = reinterpret_cast<const char*>(ptr); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 Vector<char> buffer; | 1996 Vector<char> buffer; |
| 1997 SNPrintF(buffer, "Compiling WASM function #%d:%s failed:", index, | 1997 SNPrintF(buffer, "Compiling WASM function #%d:%s failed:", index, |
| 1998 module_env->module->GetName(function.name_offset)); | 1998 module_env->module->GetName(function.name_offset)); |
| 1999 thrower.Failed(buffer.start(), result); | 1999 thrower.Failed(buffer.start(), result); |
| 2000 return Handle<Code>::null(); | 2000 return Handle<Code>::null(); |
| 2001 } | 2001 } |
| 2002 | 2002 |
| 2003 // Run the compiler pipeline to generate machine code. | 2003 // Run the compiler pipeline to generate machine code. |
| 2004 CallDescriptor* descriptor = const_cast<CallDescriptor*>( | 2004 CallDescriptor* descriptor = const_cast<CallDescriptor*>( |
| 2005 module_env->GetWasmCallDescriptor(&zone, function.sig)); | 2005 module_env->GetWasmCallDescriptor(&zone, function.sig)); |
| 2006 CompilationInfo info("wasm", isolate, &zone); | 2006 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
| 2007 info.set_output_code_kind(Code::WASM_FUNCTION); | 2007 CompilationInfo info("wasm", isolate, &zone, flags); |
| 2008 Handle<Code> code = | 2008 Handle<Code> code = |
| 2009 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph); | 2009 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph); |
| 2010 | 2010 |
| 2011 #ifdef ENABLE_DISASSEMBLER | 2011 #ifdef ENABLE_DISASSEMBLER |
| 2012 // Disassemble the code for debugging. | 2012 // Disassemble the code for debugging. |
| 2013 if (!code.is_null() && FLAG_print_opt_code) { | 2013 if (!code.is_null() && FLAG_print_opt_code) { |
| 2014 Vector<char> buffer; | 2014 Vector<char> buffer; |
| 2015 const char* name = ""; | 2015 const char* name = ""; |
| 2016 if (function.name_offset > 0) { | 2016 if (function.name_offset > 0) { |
| 2017 const byte* ptr = module_env->module->module_start + function.name_offset; | 2017 const byte* ptr = module_env->module->module_start + function.name_offset; |
| 2018 name = reinterpret_cast<const char*>(ptr); | 2018 name = reinterpret_cast<const char*>(ptr); |
| 2019 } | 2019 } |
| 2020 SNPrintF(buffer, "WASM function #%d:%s", index, name); | 2020 SNPrintF(buffer, "WASM function #%d:%s", index, name); |
| 2021 OFStream os(stdout); | 2021 OFStream os(stdout); |
| 2022 code->Disassemble(buffer.start(), os); | 2022 code->Disassemble(buffer.start(), os); |
| 2023 } | 2023 } |
| 2024 #endif | 2024 #endif |
| 2025 return code; | 2025 return code; |
| 2026 } | 2026 } |
| 2027 | 2027 |
| 2028 | 2028 |
| 2029 } // namespace compiler | 2029 } // namespace compiler |
| 2030 } // namespace internal | 2030 } // namespace internal |
| 2031 } // namespace v8 | 2031 } // namespace v8 |
| OLD | NEW |