5#ifndef V8_COMPILER_TURBOSHAFT_PHASE_H_
6#define V8_COMPILER_TURBOSHAFT_PHASE_H_
31#define DECL_TURBOSHAFT_PHASE_CONSTANTS_IMPL(Name, CallStatsName) \
32 DECL_PIPELINE_PHASE_CONSTANTS_HELPER(CallStatsName, PhaseKind::kTurboshaft, \
33 RuntimeCallStats::kThreadSpecific) \
34 static constexpr char kPhaseName[] = "V8.TF" #CallStatsName; \
35 static void AssertTurboshaftPhase() { \
36 static_assert(TurboshaftPhase<Name##Phase>); \
39#define DECL_TURBOSHAFT_PHASE_CONSTANTS(Name) \
40 DECL_TURBOSHAFT_PHASE_CONSTANTS_IMPL(Name, Turboshaft##Name)
41#define DECL_TURBOSHAFT_PHASE_CONSTANTS_WITH_LEGACY_NAME(Name) \
42 DECL_TURBOSHAFT_PHASE_CONSTANTS_IMPL(Name, Name)
44#define DECL_TURBOSHAFT_MAIN_THREAD_PIPELINE_PHASE_CONSTANTS_WITH_LEGACY_NAME( \
46 DECL_PIPELINE_PHASE_CONSTANTS_HELPER(Name, PhaseKind::kTurboshaft, \
47 RuntimeCallStats::kExact) \
48 static constexpr char kPhaseName[] = "V8.TF" #Name; \
49 static void AssertTurboshaftPhase() { \
50 static_assert(TurboshaftPhase<Name##Phase>); \
54class RegisterAllocationData;
56class TurbofanPipelineStatistics;
63template <
typename Phase>
68 "Phase::Run needs at least two parameters (PipelineData* and Zone*)");
71 static constexpr bool value = std::is_same_v<parameter0, PipelineData*> &&
72 std::is_same_v<parameter1, Zone*>;
75template <
typename Phase,
typename... Args>
80template <
typename Phase>
83template <
typename Phase>
87template <
typename,
typename =
void>
92 P,
std::void_t<decltype(P::kOutputIsTraceableGraph)>>
93 : std::bool_constant<P::kOutputIsTraceableGraph> {};
95#ifdef HAS_CPP_CLASS_TYPES_AS_TEMPLATE_ARGS
96template <base::tmp::StringLiteral ZoneName>
98template <auto ZoneName>
101 template <
typename T>
106#ifdef HAS_CPP_CLASS_TYPES_AS_TEMPLATE_ARGS
114 :
zone(
std::move(existing_zone)) {}
189 int start_source_position = kNoSourcePosition)
190 : zone_stats_(zone_stats),
196 start_source_position_(start_source_position),
197 assembler_options_(assembler_options) {
198#if V8_ENABLE_WEBASSEMBLY
199 if (info !=
nullptr) {
201 info->IsWasm() || info->IsWasmBuiltin());
213 dependencies_ = dependencies;
218 std::optional<BytecodeHandlerData> bytecode_handler_data = {}) {
219 DCHECK(!builtin_component_.has_value());
220 builtin_component_.emplace(call_descriptor,
221 std::move(bytecode_handler_data));
225 DCHECK(!graph_component_.has_value());
226 graph_component_.emplace(zone_stats_);
227 auto& zone = graph_component_->zone;
228 graph_component_->graph = zone.New<
Graph>(zone);
240 DCHECK(!graph_component_.has_value());
241 graph_component_.emplace(std::move(
graph_zone));
242 auto& zone = graph_component_->zone;
243 graph_component_->graph = zone.New<
Graph>(zone);
245 graph_component_->node_origins = node_origins;
246 if (!graph_component_->node_origins &&
info_ &&
info_->trace_turbo_json()) {
252 DCHECK(graph_component_.has_value());
253 graph_component_.reset();
257 std::shared_ptr<OsrHelper> osr_helper,
259 DCHECK(!codegen_component_.has_value());
260 codegen_component_.emplace(zone_stats_);
261 codegen_component_->osr_helper = std::move(osr_helper);
262 codegen_component_->jump_optimization_info = jump_optimization_info;
266 DCHECK(codegen_component_.has_value());
267 codegen_component_.reset();
271 DCHECK(codegen_component_.has_value());
274#if V8_ENABLE_WEBASSEMBLY
276 info()->IsWasm() ||
info()->IsWasmBuiltin());
278 std::optional<OsrHelper> osr_helper;
282 std::move(osr_helper), start_source_position_,
285 v8_flags.trace_turbo_stack_accesses ? debug_name_.get() :
nullptr);
289 DCHECK(!instruction_component_.has_value());
290 instruction_component_.emplace(zone_stats());
291 auto& zone = instruction_component_->zone;
293 InstructionSequence::InstructionBlocksFor(zone,
graph());
294 instruction_component_->sequence =
297 instruction_component_->sequence->instruction_blocks()[0]
298 ->mark_needs_frame();
306 DCHECK(!instruction_component_.has_value());
307 instruction_component_.emplace(zone_stats());
308 instruction_component_->sequence =
313 DCHECK(instruction_component_.has_value());
314 instruction_component_.reset();
321 DCHECK(register_component_.has_value());
322 register_component_.reset();
334 return assembler_options_;
337 if (!codegen_component_.has_value())
return nullptr;
338 return codegen_component_->jump_optimization_info;
341 DCHECK(builtin_component_.has_value());
342 return builtin_component_->call_descriptor;
345 DCHECK(builtin_component_.has_value());
346 return builtin_component_->bytecode_handler_data;
351 graph_component_->graph !=
nullptr);
352 return graph_component_.has_value();
357 return graph_component_->source_positions;
360 if (!graph_component_.has_value())
return nullptr;
361 return graph_component_->node_origins;
364 return register_component_->allocation_data;
367 return register_component_->zone;
370 return codegen_component_->code_generator.get();
378 return instruction_component_->sequence;
383 return codegen_component_->max_unoptimized_frame_height;
386 return codegen_component_->max_pushed_argument_count;
390 runtime_call_stats_ = stats;
397 return compilation_zone_;
401 return pipeline_statistics_;
405 pipeline_statistics_ = pipeline_statistics;
408#if V8_ENABLE_WEBASSEMBLY
415 return wasm_canonical_sig_;
420 bool wasm_shared()
const {
return wasm_shared_; }
422 void SetIsWasmFunction(
const wasm::WasmModule* module,
423 const wasm::FunctionSig* sig,
bool shared) {
424 wasm_module_ =
module;
425 wasm_module_sig_ = sig;
431 void SetIsWasmWrapper(
const wasm::CanonicalSig* sig) {
432 wasm_canonical_sig_ =
sig;
437#ifdef V8_ENABLE_WASM_SIMD256_REVEC
438 WasmRevecAnalyzer* wasm_revec_analyzer()
const {
440 return wasm_revec_analyzer_;
443 void set_wasm_revec_analyzer(WasmRevecAnalyzer* wasm_revec_analyzer) {
445 wasm_revec_analyzer_ = wasm_revec_analyzer;
448 void clear_wasm_revec_analyzer() { wasm_revec_analyzer_ =
nullptr; }
451 WasmShuffleAnalyzer* wasm_shuffle_analyzer()
const {
453 return wasm_shuffle_analyzer_;
456 void set_wasm_shuffle_analyzer(WasmShuffleAnalyzer* wasm_shuffle_analyzer) {
458 wasm_shuffle_analyzer_ = wasm_shuffle_analyzer;
461 void clear_wasm_shuffle_analyzer() { wasm_shuffle_analyzer_ =
nullptr; }
473 DCHECK(codegen_component_.has_value());
475 int fixed_frame_size = 0;
476 if (call_descriptor !=
nullptr) {
480 codegen_component_->frame = codegen_component_->zone.New<
Frame>(
481 fixed_frame_size, codegen_component_->zone);
482 if (codegen_component_->osr_helper) {
483 codegen_component_->osr_helper->SetupFrame(codegen_component_->frame);
488 source_position_output_ = std::move(source_position_output);
493 return graph_component_->graph_has_special_rpo;
496 graph_component_->graph_has_special_rpo =
true;
499 return graph_component_->graph_has_lowered_fast_api_calls;
502 graph_component_->graph_has_lowered_fast_api_calls =
true;
531#if V8_ENABLE_WEBASSEMBLY
537 bool wasm_shared_ =
false;
539#ifdef V8_ENABLE_WASM_SIMD256_REVEC
547 CodeTracer* code_tracer,
const char* phase_name);
550 const char* phase_name,
constexpr bool is_empty() const
int CalculateFixedFrameSize(CodeKind code_kind) const
DoubleRegList CalleeSavedFPRegisters() const
bool RequiresFrameAsIncoming() const
const GrowingOpIndexSidetable< SourcePosition > & source_positions() const
void InitializeCodeGenerator(Linkage *linkage)
void set_pipeline_statistics(TurbofanPipelineStatistics *pipeline_statistics)
TurboshaftPipelineKind pipeline_kind_
bool graph_has_special_rpo() const
const char * debug_name() const
void ClearGraphComponent()
ZoneWithName< kGraphZoneName > & graph_zone()
void InitializeBuiltinComponent(const CallDescriptor *call_descriptor, std::optional< BytecodeHandlerData > bytecode_handler_data={})
void InitializeCodegenComponent(std::shared_ptr< OsrHelper > osr_helper, JumpOptimizationInfo *jump_optimization_info=nullptr)
TurboshaftPipelineKind pipeline_kind() const
RuntimeCallStats * runtime_call_stats() const
turboshaft::Graph & graph() const
std::unique_ptr< char[]> debug_name_
std::string source_position_output() const
void InitializeBrokerAndDependencies(std::shared_ptr< JSHeapBroker > broker, CompilationDependencies *dependencies)
const AssemblerOptions & assembler_options() const
std::optional< CodegenComponent > codegen_component_
bool is_js_to_wasm() const
void InitializeInstructionComponent(const CallDescriptor *call_descriptor)
RegisterAllocationData * register_allocation_data() const
JumpOptimizationInfo * jump_optimization_info()
void set_graph_has_lowered_fast_api_calls()
std::shared_ptr< JSHeapBroker > broker_
bool graph_has_lowered_fast_api_calls() const
PipelineData(ZoneStats *zone_stats, TurboshaftPipelineKind pipeline_kind, Isolate *isolate, OptimizedCompilationInfo *info, const AssemblerOptions &assembler_options, int start_source_position=kNoSourcePosition)
GraphComponent::Pointer< SourcePositionTable > source_positions() const
void set_source_position_output(std::string source_position_output)
void ClearInstructionComponent()
CodeGenerator * code_generator() const
void set_graph_has_special_rpo()
JSHeapBroker * broker() const
InstructionSequence * sequence() const
TurbofanPipelineStatistics * pipeline_statistics() const
void InitializeGraphComponentWithGraphZone(ZoneWithName< kGraphZoneName > graph_zone, ZoneWithNamePointer< SourcePositionTable, kGraphZoneName > source_positions, ZoneWithNamePointer< NodeOriginTable, kGraphZoneName > node_origins)
void ClearCodegenComponent()
void set_code(MaybeIndirectHandle< Code > code)
std::optional< BuiltinComponent > builtin_component_
MaybeIndirectHandle< Code > code() const
void ClearRegisterComponent()
MaybeIndirectHandle< Code > code_
std::optional< RegisterComponent > register_component_
void InitializeInstructionComponentWithSequence(InstructionSequence *sequence)
void set_runtime_call_stats(RuntimeCallStats *stats)
std::optional< BytecodeHandlerData > & bytecode_handler_data()
GraphComponent::Pointer< NodeOriginTable > node_origins() const
OptimizedCompilationInfo * info() const
std::optional< GraphComponent > graph_component_
void InitializeGraphComponent(SourcePositionTable *source_positions)
size_t & max_pushed_argument_count()
void InitializeFrameData(CallDescriptor *call_descriptor)
const AssemblerOptions assembler_options_
std::string source_position_output_
ZoneStats * zone_stats() const
std::optional< InstructionComponent > instruction_component_
ZoneWithName< kRegisterAllocationZoneName > & register_allocation_zone()
ZoneWithName< kCompilationZoneName > & compilation_zone()
Isolate * isolate() const
ZoneWithName< kCompilationZoneName > compilation_zone_
const CallDescriptor * builtin_call_descriptor() const
size_t & max_unoptimized_frame_height()
CompilationDependencies * depedencies() const
JSHeapBroker *const broker_
Handle< SharedFunctionInfo > info
ZoneList< RegExpInstruction > code_
TurboshaftPipelineKind pipeline_kind
SourcePositionTable * source_positions
SharedFunctionInfoRef shared
constexpr size_t length_v
typename element< List, Index >::type element_t
typename call_parameters< T >::type call_parameters_t
void PrintTurboshaftGraph(PipelineData *data, Zone *temp_zone, CodeTracer *code_tracer, const char *phase_name)
void PrintTurboshaftGraphForTurbolizer(std::ofstream &stream, const Graph &graph, const char *phase_name, NodeOriginTable *node_origins, Zone *temp_zone)
constexpr char kCompilationZoneName[]
base::Vector< const char > GetDebugName(Zone *zone, const wasm::WasmModule *module, const wasm::WireBytesStorage *wire_bytes, int index)
constexpr int kNoSourcePosition
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig
V8_EXPORT_PRIVATE FlagValues v8_flags
OptimizedCompilationInfo * info_
#define DCHECK_NOT_NULL(val)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
#define V8_EXPORT_PRIVATE
base::tmp::call_parameters_t< decltype(&Phase::Run)> parameters
base::tmp::element_t< parameters, 0 > parameter0
static constexpr bool value
base::tmp::element_t< parameters, 1 > parameter1
std::optional< BytecodeHandlerData > bytecode_handler_data
BuiltinComponent(const CallDescriptor *call_descriptor, std::optional< BytecodeHandlerData > bytecode_handler_data)
const CallDescriptor * call_descriptor
size_t max_unoptimized_frame_height
std::shared_ptr< OsrHelper > osr_helper
Pointer< CompilationDependency > dependencies
std::unique_ptr< CodeGenerator > code_generator
JumpOptimizationInfo * jump_optimization_info
size_t max_pushed_argument_count
ZoneWithNamePointer< T, ZoneName > Pointer
ComponentWithZone(ZoneWithName< ZoneName > existing_zone)
ComponentWithZone(ZoneStats *zone_stats)
ZoneWithName< ZoneName > zone
bool graph_has_special_rpo
bool graph_has_lowered_fast_api_calls
Pointer< NodeOriginTable > node_origins
Pointer< SourcePositionTable > source_positions
Pointer< RegisterAllocationData > allocation_data