1 // Copyright 2014 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_COMPILER_PIPELINE_H_ 6 #define V8_COMPILER_PIPELINE_H_ 7 8 #include <memory> 9 10 // Clients of this interface shouldn't depend on lots of compiler internals. 11 // Do not include anything from src/compiler here! 12 #include "src/common/globals.h" 13 #include "src/objects/code.h" 14 #include "src/objects/objects.h" 15 16 namespace v8 { 17 namespace internal { 18 19 struct AssemblerOptions; 20 class OptimizedCompilationInfo; 21 class TurbofanCompilationJob; 22 class ProfileDataFromFile; 23 class RegisterConfiguration; 24 25 namespace wasm { 26 struct CompilationEnv; 27 struct FunctionBody; 28 class NativeModule; 29 struct WasmCompilationResult; 30 class WasmEngine; 31 struct WasmModule; 32 class WireBytesStorage; 33 } // namespace wasm 34 35 namespace compiler { 36 37 class CallDescriptor; 38 class Graph; 39 class InstructionSequence; 40 class JSGraph; 41 class JSHeapBroker; 42 class MachineGraph; 43 class NodeOriginTable; 44 class Schedule; 45 class SourcePositionTable; 46 struct WasmLoopInfo; 47 48 class Pipeline : public AllStatic { 49 public: 50 // Returns a new compilation job for the given JavaScript function. 51 static V8_EXPORT_PRIVATE std::unique_ptr<TurbofanCompilationJob> 52 NewCompilationJob(Isolate* isolate, Handle<JSFunction> function, 53 CodeKind code_kind, bool has_script, 54 BytecodeOffset osr_offset = BytecodeOffset::None(), 55 JavaScriptFrame* osr_frame = nullptr); 56 57 // Run the pipeline for the WebAssembly compilation info. 58 static void GenerateCodeForWasmFunction( 59 OptimizedCompilationInfo* info, wasm::CompilationEnv* env, 60 const wasm::WireBytesStorage* wire_bytes_storage, MachineGraph* mcgraph, 61 CallDescriptor* call_descriptor, SourcePositionTable* source_positions, 62 NodeOriginTable* node_origins, wasm::FunctionBody function_body, 63 const wasm::WasmModule* module, int function_index, 64 std::vector<compiler::WasmLoopInfo>* loop_infos); 65 66 // Run the pipeline on a machine graph and generate code. 67 static wasm::WasmCompilationResult GenerateCodeForWasmNativeStub( 68 CallDescriptor* call_descriptor, MachineGraph* mcgraph, CodeKind kind, 69 const char* debug_name, const AssemblerOptions& assembler_options, 70 SourcePositionTable* source_positions = nullptr); 71 72 // Returns a new compilation job for a wasm heap stub. 73 static std::unique_ptr<TurbofanCompilationJob> NewWasmHeapStubCompilationJob( 74 Isolate* isolate, CallDescriptor* call_descriptor, 75 std::unique_ptr<Zone> zone, Graph* graph, CodeKind kind, 76 std::unique_ptr<char[]> debug_name, const AssemblerOptions& options, 77 SourcePositionTable* source_positions = nullptr); 78 79 // Run the pipeline on a machine graph and generate code. 80 static MaybeHandle<Code> GenerateCodeForCodeStub( 81 Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph, 82 JSGraph* jsgraph, SourcePositionTable* source_positions, CodeKind kind, 83 const char* debug_name, Builtin builtin, const AssemblerOptions& options, 84 const ProfileDataFromFile* profile_data); 85 86 // --------------------------------------------------------------------------- 87 // The following methods are for testing purposes only. Avoid production use. 88 // --------------------------------------------------------------------------- 89 90 // Run the pipeline on JavaScript bytecode and generate code. If requested, 91 // hands out the heap broker on success, transferring its ownership to the 92 // caller. 93 V8_EXPORT_PRIVATE static MaybeHandle<Code> GenerateCodeForTesting( 94 OptimizedCompilationInfo* info, Isolate* isolate, 95 std::unique_ptr<JSHeapBroker>* out_broker = nullptr); 96 97 // Run the pipeline on a machine graph and generate code. If {schedule} is 98 // {nullptr}, then compute a new schedule for code generation. 99 V8_EXPORT_PRIVATE static MaybeHandle<Code> GenerateCodeForTesting( 100 OptimizedCompilationInfo* info, Isolate* isolate, 101 CallDescriptor* call_descriptor, Graph* graph, 102 const AssemblerOptions& options, Schedule* schedule = nullptr); 103 104 // Run just the register allocator phases. 105 V8_EXPORT_PRIVATE static bool AllocateRegistersForTesting( 106 const RegisterConfiguration* config, InstructionSequence* sequence, 107 bool use_fast_register_allocator, bool run_verifier); 108 109 private: 110 DISALLOW_IMPLICIT_CONSTRUCTORS(Pipeline); 111 }; 112 113 } // namespace compiler 114 } // namespace internal 115 } // namespace v8 116 117 #endif // V8_COMPILER_PIPELINE_H_ 118