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 OptimizedCompilationJob; 22 class ProfileDataFromFile; 23 class RegisterConfiguration; 24 25 namespace wasm { 26 struct FunctionBody; 27 class NativeModule; 28 struct WasmCompilationResult; 29 class WasmEngine; 30 struct WasmModule; 31 } // namespace wasm 32 33 namespace compiler { 34 35 class CallDescriptor; 36 class Graph; 37 class InstructionSequence; 38 class JSGraph; 39 class JSHeapBroker; 40 class MachineGraph; 41 class NodeOriginTable; 42 class Schedule; 43 class SourcePositionTable; 44 45 class Pipeline : public AllStatic { 46 public: 47 // Returns a new compilation job for the given JavaScript function. 48 static std::unique_ptr<OptimizedCompilationJob> NewCompilationJob( 49 Isolate* isolate, Handle<JSFunction> function, CodeKind code_kind, 50 bool has_script, BailoutId osr_offset = BailoutId::None(), 51 JavaScriptFrame* osr_frame = nullptr); 52 53 // Run the pipeline for the WebAssembly compilation info. 54 static void GenerateCodeForWasmFunction( 55 OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine, 56 MachineGraph* mcgraph, CallDescriptor* call_descriptor, 57 SourcePositionTable* source_positions, NodeOriginTable* node_origins, 58 wasm::FunctionBody function_body, const wasm::WasmModule* module, 59 int function_index); 60 61 // Run the pipeline on a machine graph and generate code. 62 static wasm::WasmCompilationResult GenerateCodeForWasmNativeStub( 63 wasm::WasmEngine* wasm_engine, CallDescriptor* call_descriptor, 64 MachineGraph* mcgraph, CodeKind kind, int wasm_kind, 65 const char* debug_name, const AssemblerOptions& assembler_options, 66 SourcePositionTable* source_positions = nullptr); 67 68 // Returns a new compilation job for a wasm heap stub. 69 static std::unique_ptr<OptimizedCompilationJob> NewWasmHeapStubCompilationJob( 70 Isolate* isolate, wasm::WasmEngine* wasm_engine, 71 CallDescriptor* call_descriptor, std::unique_ptr<Zone> zone, Graph* graph, 72 CodeKind kind, std::unique_ptr<char[]> debug_name, 73 const AssemblerOptions& options, 74 SourcePositionTable* source_positions = nullptr); 75 76 // Run the pipeline on a machine graph and generate code. 77 static MaybeHandle<Code> GenerateCodeForCodeStub( 78 Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph, 79 JSGraph* jsgraph, SourcePositionTable* source_positions, CodeKind kind, 80 const char* debug_name, int32_t builtin_index, 81 PoisoningMitigationLevel poisoning_level, const AssemblerOptions& options, 82 const ProfileDataFromFile* profile_data); 83 84 // --------------------------------------------------------------------------- 85 // The following methods are for testing purposes only. Avoid production use. 86 // --------------------------------------------------------------------------- 87 88 // Run the pipeline on JavaScript bytecode and generate code. If requested, 89 // hands out the heap broker on success, transferring its ownership to the 90 // caller. 91 V8_EXPORT_PRIVATE static MaybeHandle<Code> GenerateCodeForTesting( 92 OptimizedCompilationInfo* info, Isolate* isolate, 93 std::unique_ptr<JSHeapBroker>* out_broker = nullptr); 94 95 // Run the pipeline on a machine graph and generate code. If {schedule} is 96 // {nullptr}, then compute a new schedule for code generation. 97 V8_EXPORT_PRIVATE static MaybeHandle<Code> GenerateCodeForTesting( 98 OptimizedCompilationInfo* info, Isolate* isolate, 99 CallDescriptor* call_descriptor, Graph* graph, 100 const AssemblerOptions& options, Schedule* schedule = nullptr); 101 102 // Run just the register allocator phases. 103 V8_EXPORT_PRIVATE static bool AllocateRegistersForTesting( 104 const RegisterConfiguration* config, InstructionSequence* sequence, 105 bool use_fast_register_allocator, bool run_verifier); 106 107 private: 108 DISALLOW_IMPLICIT_CONSTRUCTORS(Pipeline); 109 }; 110 111 } // namespace compiler 112 } // namespace internal 113 } // namespace v8 114 115 #endif // V8_COMPILER_PIPELINE_H_ 116