#include "src/compiler/pipeline.h"
#include <fstream>
#include <iostream>
#include <memory>
#include <optional>
#include <sstream>
#include "src/builtins/builtins.h"
#include "src/builtins/profile-data-reader.h"
#include "src/codegen/assembler-inl.h"
#include "src/codegen/bailout-reason.h"
#include "src/codegen/compiler.h"
#include "src/codegen/optimized-compilation-info.h"
#include "src/codegen/register-configuration.h"
#include "src/codegen/reloc-info.h"
#include "src/common/globals.h"
#include "src/common/high-allocation-throughput-scope.h"
#include "src/compiler/add-type-assertions-reducer.h"
#include "src/compiler/all-nodes.h"
#include "src/compiler/backend/bitcast-elider.h"
#include "src/compiler/backend/code-generator.h"
#include "src/compiler/backend/frame-elider.h"
#include "src/compiler/backend/instruction-selector.h"
#include "src/compiler/backend/instruction.h"
#include "src/compiler/backend/jump-threading.h"
#include "src/compiler/backend/move-optimizer.h"
#include "src/compiler/backend/register-allocator-verifier.h"
#include "src/compiler/backend/register-allocator.h"
#include "src/compiler/basic-block-instrumentor.h"
#include "src/compiler/branch-condition-duplicator.h"
#include "src/compiler/branch-elimination.h"
#include "src/compiler/bytecode-graph-builder.h"
#include "src/compiler/checkpoint-elimination.h"
#include "src/compiler/common-operator-reducer.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/compilation-dependencies.h"
#include "src/compiler/compiler-source-position-table.h"
#include "src/compiler/constant-folding-reducer.h"
#include "src/compiler/csa-load-elimination.h"
#include "src/compiler/dead-code-elimination.h"
#include "src/compiler/decompression-optimizer.h"
#include "src/compiler/escape-analysis-reducer.h"
#include "src/compiler/escape-analysis.h"
#include "src/compiler/graph-trimmer.h"
#include "src/compiler/graph-visualizer.h"
#include "src/compiler/js-call-reducer.h"
#include "src/compiler/js-context-specialization.h"
#include "src/compiler/js-create-lowering.h"
#include "src/compiler/js-generic-lowering.h"
#include "src/compiler/js-heap-broker.h"
#include "src/compiler/js-inlining-heuristic.h"
#include "src/compiler/js-intrinsic-lowering.h"
#include "src/compiler/js-native-context-specialization.h"
#include "src/compiler/js-typed-lowering.h"
#include "src/compiler/late-escape-analysis.h"
#include "src/compiler/linkage.h"
#include "src/compiler/load-elimination.h"
#include "src/compiler/loop-analysis.h"
#include "src/compiler/loop-peeling.h"
#include "src/compiler/loop-unrolling.h"
#include "src/compiler/loop-variable-optimizer.h"
#include "src/compiler/machine-graph-verifier.h"
#include "src/compiler/machine-operator-reducer.h"
#include "src/compiler/memory-optimizer.h"
#include "src/compiler/node-observer.h"
#include "src/compiler/node-origin-table.h"
#include "src/compiler/osr.h"
#include "src/compiler/pair-load-store-reducer.h"
#include "src/compiler/phase.h"
#include "src/compiler/pipeline-data-inl.h"
#include "src/compiler/pipeline-statistics.h"
#include "src/compiler/redundancy-elimination.h"
#include "src/compiler/schedule.h"
#include "src/compiler/scheduler.h"
#include "src/compiler/select-lowering.h"
#include "src/compiler/simplified-lowering.h"
#include "src/compiler/simplified-operator-reducer.h"
#include "src/compiler/simplified-operator.h"
#include "src/compiler/turboshaft/build-graph-phase.h"
#include "src/compiler/turboshaft/code-elimination-and-simplification-phase.h"
#include "src/compiler/turboshaft/csa-optimize-phase.h"
#include "src/compiler/turboshaft/debug-feature-lowering-phase.h"
#include "src/compiler/turboshaft/decompression-optimization-phase.h"
#include "src/compiler/turboshaft/instruction-selection-phase.h"
#include "src/compiler/turboshaft/loop-peeling-phase.h"
#include "src/compiler/turboshaft/loop-unrolling-phase.h"
#include "src/compiler/turboshaft/machine-lowering-phase.h"
#include "src/compiler/turboshaft/maglev-graph-building-phase.h"
#include "src/compiler/turboshaft/optimize-phase.h"
#include "src/compiler/turboshaft/phase.h"
#include "src/compiler/turboshaft/pipelines.h"
#include "src/compiler/turboshaft/recreate-schedule-phase.h"
#include "src/compiler/turboshaft/register-allocation-phase.h"
#include "src/compiler/turboshaft/simplified-lowering-phase.h"
#include "src/compiler/turboshaft/simplify-tf-loops.h"
#include "src/compiler/turboshaft/store-store-elimination-phase.h"
#include "src/compiler/turboshaft/tracing.h"
#include "src/compiler/turboshaft/type-assertions-phase.h"
#include "src/compiler/turboshaft/typed-optimizations-phase.h"
#include "src/compiler/type-narrowing-reducer.h"
#include "src/compiler/typed-optimization.h"
#include "src/compiler/typer.h"
#include "src/compiler/value-numbering-reducer.h"
#include "src/compiler/verifier.h"
#include "src/compiler/zone-stats.h"
#include "src/diagnostics/code-tracer.h"
#include "src/diagnostics/disassembler.h"
#include "src/flags/flags.h"
#include "src/handles/handles-inl.h"
#include "src/heap/local-heap.h"
#include "src/logging/code-events.h"
#include "src/logging/counters.h"
#include "src/logging/runtime-call-stats-scope.h"
#include "src/logging/runtime-call-stats.h"
#include "src/objects/code-kind.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/string-inl.h"
#include "src/tracing/trace-event.h"
#include "src/utils/ostreams.h"
#include "src/utils/utils.h"
#if V8_ENABLE_WEBASSEMBLY
#include "src/compiler/int64-lowering.h"
#include "src/compiler/turboshaft/int64-lowering-phase.h"
#include "src/compiler/turboshaft/wasm-dead-code-elimination-phase.h"
#include "src/compiler/turboshaft/wasm-gc-optimize-phase.h"
#include "src/compiler/turboshaft/wasm-lowering-phase.h"
#include "src/compiler/turboshaft/wasm-optimize-phase.h"
#include "src/compiler/turboshaft/wasm-turboshaft-compiler.h"
#include "src/compiler/wasm-compiler.h"
#include "src/compiler/wasm-escape-analysis.h"
#include "src/compiler/wasm-gc-lowering.h"
#include "src/compiler/wasm-gc-operator-reducer.h"
#include "src/compiler/wasm-inlining.h"
#include "src/compiler/wasm-js-lowering.h"
#include "src/compiler/wasm-load-elimination.h"
#include "src/compiler/wasm-loop-peeling.h"
#include "src/compiler/wasm-typer.h"
#include "src/wasm/function-body-decoder.h"
#include "src/wasm/function-compiler.h"
#include "src/wasm/turboshaft-graph-interface.h"
#include "src/wasm/wasm-builtin-list.h"
#include "src/wasm/wasm-disassembler.h"
#include "src/wasm/wasm-engine.h"
#endif
#if V8_ENABLE_WASM_SIMD256_REVEC
#include "src/compiler/revectorizer.h"
#include "src/compiler/turboshaft/wasm-revec-phase.h"
#endif
#define TARGET_SUPPORTS_TURBOSHAFT_INSTRUCTION_SELECTION …
namespace v8 {
namespace internal {
namespace compiler {
static constexpr char kMachineGraphVerifierZoneName[] = …;
static constexpr char kPipelineCompilationJobZoneName[] = …;
class PipelineImpl final { … };
namespace {
class SourcePositionWrapper final : public Reducer { … };
class NodeOriginsWrapper final : public Reducer { … };
class V8_NODISCARD PipelineRunScope { … };
class V8_NODISCARD LocalIsolateScope { … };
void PrintFunctionSource(OptimizedCompilationInfo* info, Isolate* isolate,
int source_id,
DirectHandle<SharedFunctionInfo> shared) { … }
void PrintInlinedFunctionInfo(
OptimizedCompilationInfo* info, Isolate* isolate, int source_id,
int inlining_id, const OptimizedCompilationInfo::InlinedFunctionHolder& h) { … }
void PrintParticipatingSource(OptimizedCompilationInfo* info,
Isolate* isolate) { … }
void TraceScheduleAndVerify(OptimizedCompilationInfo* info,
TFPipelineData* data, Schedule* schedule,
const char* phase_name) { … }
void AddReducer(TFPipelineData* data, GraphReducer* graph_reducer,
Reducer* reducer) { … }
TurbofanPipelineStatistics* CreatePipelineStatistics(
Handle<Script> script, OptimizedCompilationInfo* info, Isolate* isolate,
ZoneStats* zone_stats) { … }
#if V8_ENABLE_WEBASSEMBLY
TurbofanPipelineStatistics* CreatePipelineStatistics(
WasmCompilationData& compilation_data, const wasm::WasmModule* wasm_module,
OptimizedCompilationInfo* info, ZoneStats* zone_stats) { … }
#endif
[[nodiscard]] bool GenerateCodeFromTurboshaftGraph(
bool use_turboshaft_instruction_selection, Linkage* linkage,
turboshaft::Pipeline& turboshaft_pipeline,
PipelineImpl* turbofan_pipeline = nullptr,
std::shared_ptr<OsrHelper> osr_helper = { … }
}
class PipelineCompilationJob final : public TurbofanCompilationJob { … };
PipelineCompilationJob::PipelineCompilationJob(
Isolate* isolate, Handle<SharedFunctionInfo> shared_info,
Handle<JSFunction> function, BytecodeOffset osr_offset, CodeKind code_kind)
: … { … }
PipelineCompilationJob::~PipelineCompilationJob() = default;
void TraceSchedule(OptimizedCompilationInfo* info, TFPipelineData* data,
Schedule* schedule, const char* phase_name) { … }
void PrintCode(Isolate* isolate, DirectHandle<Code> code,
OptimizedCompilationInfo* info) { … }
bool CheckNoDeprecatedMaps(DirectHandle<Code> code, Isolate* isolate) { … }
namespace {
class V8_NODISCARD PipelineJobScope { … };
}
PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl(
Isolate* isolate) { … }
PipelineCompilationJob::Status PipelineCompilationJob::ExecuteJobImpl(
RuntimeCallStats* stats, LocalIsolate* local_isolate) { … }
PipelineCompilationJob::Status PipelineCompilationJob::FinalizeJobImpl(
Isolate* isolate) { … }
template <CONCEPT(turboshaft::TurbofanPhase) Phase, typename... Args>
auto PipelineImpl::Run(Args&&... args) { … }
struct GraphBuilderPhase { … };
struct InliningPhase { … };
#if V8_ENABLE_WEBASSEMBLY
struct JSWasmInliningPhase { … };
struct JSWasmLoweringPhase { … };
#endif
struct EarlyGraphTrimmingPhase { … };
struct TyperPhase { … };
struct UntyperPhase { … };
struct HeapBrokerInitializationPhase { … };
struct TypedLoweringPhase { … };
struct EscapeAnalysisPhase { … };
struct TypeAssertionsPhase { … };
struct SimplifiedLoweringPhase { … };
struct LoopPeelingPhase { … };
#if V8_ENABLE_WEBASSEMBLY
struct WasmInliningPhase { … };
namespace {
void EliminateLoopExits(std::vector<compiler::WasmLoopInfo>* loop_infos) { … }
}
struct WasmLoopUnrollingPhase { … };
struct WasmLoopPeelingPhase { … };
#endif
struct LoopExitEliminationPhase { … };
struct GenericLoweringPhase { … };
struct EarlyOptimizationPhase { … };
struct LoadEliminationPhase { … };
struct MemoryOptimizationPhase { … };
struct MachineOperatorOptimizationPhase { … };
struct WasmBaseOptimizationPhase { … };
struct DecompressionOptimizationPhase { … };
struct BranchConditionDuplicationPhase { … };
#if V8_ENABLE_WEBASSEMBLY
struct WasmTypingPhase { … };
struct WasmGCOptimizationPhase { … };
struct SimplifyLoopsPhase { … };
struct WasmGCLoweringPhase { … };
struct WasmOptimizationPhase { … };
struct WasmJSLoweringPhase { … };
#endif
struct CsaEarlyOptimizationPhase { … };
struct CsaOptimizationPhase { … };
struct ComputeSchedulePhase { … };
#if V8_ENABLE_WASM_SIMD256_REVEC
struct RevectorizePhase { … };
#endif
struct InstructionSelectionPhase { … };
struct BitcastElisionPhase { … };
struct MeetRegisterConstraintsPhase { … };
struct ResolvePhisPhase { … };
struct BuildLiveRangesPhase { … };
struct BuildBundlesPhase { … };
template <typename RegAllocator>
struct AllocateGeneralRegistersPhase { … };
template <typename RegAllocator>
struct AllocateFPRegistersPhase { … };
template <typename RegAllocator>
struct AllocateSimd128RegistersPhase { … };
struct DecideSpillingModePhase { … };
struct AssignSpillSlotsPhase { … };
struct CommitAssignmentPhase { … };
struct PopulateReferenceMapsPhase { … };
struct ConnectRangesPhase { … };
struct ResolveControlFlowPhase { … };
struct OptimizeMovesPhase { … };
struct FrameElisionPhase { … };
struct JumpThreadingPhase { … };
struct AssembleCodePhase { … };
struct FinalizeCodePhase { … };
struct PrintGraphPhase { … };
struct VerifyGraphPhase { … };
#undef DECL_MAIN_THREAD_PIPELINE_PHASE_CONSTANTS
#undef DECL_PIPELINE_PHASE_CONSTANTS
#undef DECL_PIPELINE_PHASE_CONSTANTS_HELPER
#if V8_ENABLE_WEBASSEMBLY
class WasmHeapStubCompilationJob final : public TurbofanCompilationJob { … };
#if V8_ENABLE_WEBASSEMBLY
class WasmTurboshaftWrapperCompilationJob final
: public turboshaft::TurboshaftCompilationJob { … };
std::unique_ptr<TurbofanCompilationJob> Pipeline::NewWasmHeapStubCompilationJob(
Isolate* isolate, CallDescriptor* call_descriptor,
std::unique_ptr<Zone> zone, Graph* graph, CodeKind kind,
std::unique_ptr<char[]> debug_name, const AssemblerOptions& options) { … }
std::unique_ptr<turboshaft::TurboshaftCompilationJob>
Pipeline::NewWasmTurboshaftWrapperCompilationJob(
Isolate* isolate, const wasm::FunctionSig* sig,
wasm::WrapperCompilationInfo wrapper_info, const wasm::WasmModule* module,
std::unique_ptr<char[]> debug_name, const AssemblerOptions& options) { … }
#endif
CompilationJob::Status WasmHeapStubCompilationJob::PrepareJobImpl(
Isolate* isolate) { … }
namespace {
void TraceWrapperCompilation(const char* compiler,
OptimizedCompilationInfo* info,
TFPipelineData* data) { … }
void TraceWrapperCompilation(OptimizedCompilationInfo* info,
turboshaft::PipelineData* data) { … }
CompilationJob::Status FinalizeWrapperCompilation(
PipelineImpl* pipeline, OptimizedCompilationInfo* info,
CallDescriptor* call_descriptor, Isolate* isolate,
const char* method_name) { … }
CompilationJob::Status FinalizeWrapperCompilation(
turboshaft::PipelineData* turboshaft_data, OptimizedCompilationInfo* info,
CallDescriptor* call_descriptor, Isolate* isolate,
const char* method_name) { … }
}
CompilationJob::Status WasmHeapStubCompilationJob::ExecuteJobImpl(
RuntimeCallStats* stats, LocalIsolate* local_isolate) { … }
CompilationJob::Status WasmHeapStubCompilationJob::FinalizeJobImpl(
Isolate* isolate) { … }
CompilationJob::Status WasmTurboshaftWrapperCompilationJob::PrepareJobImpl(
Isolate* isolate) { … }
CompilationJob::Status WasmTurboshaftWrapperCompilationJob::ExecuteJobImpl(
RuntimeCallStats* stats, LocalIsolate* local_isolate) { … }
CompilationJob::Status WasmTurboshaftWrapperCompilationJob::FinalizeJobImpl(
Isolate* isolate) { … }
#endif
void PipelineImpl::RunPrintAndVerify(const char* phase, bool untyped) { … }
void PipelineImpl::InitializeHeapBroker() { … }
bool PipelineImpl::CreateGraph() { … }
bool PipelineImpl::OptimizeTurbofanGraph(Linkage* linkage) { … }
namespace {
int HashGraphForPGO(const turboshaft::Graph* graph) { … }
int HashGraphForPGO(const Graph* graph) { … }
template <typename Graph>
int ComputeInitialGraphHash(Builtin builtin,
const ProfileDataFromFile* profile_data,
const Graph* graph) { … }
const ProfileDataFromFile* ValidateProfileData(
const ProfileDataFromFile* profile_data, int initial_graph_hash,
const char* debug_name) { … }
}
MaybeHandle<Code> Pipeline::GenerateCodeForCodeStub(
Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph,
JSGraph* jsgraph, SourcePositionTable* source_positions, CodeKind kind,
const char* debug_name, Builtin builtin, const AssemblerOptions& options,
const ProfileDataFromFile* profile_data) { … }
MaybeHandle<Code> Pipeline::GenerateCodeForTurboshaftBuiltin(
turboshaft::PipelineData* turboshaft_data, CallDescriptor* call_descriptor,
Builtin builtin, const char* debug_name,
const ProfileDataFromFile* profile_data) { … }
#if V8_ENABLE_WEBASSEMBLY
namespace {
wasm::WasmCompilationResult WrapperCompilationResult(
CodeGenerator* code_generator, CallDescriptor* call_descriptor,
CodeKind kind) { … }
void TraceFinishWrapperCompilation(OptimizedCompilationInfo& info,
CodeTracer* code_tracer,
const wasm::WasmCompilationResult& result,
CodeGenerator* code_generator) { … }
}
wasm::WasmCompilationResult Pipeline::GenerateCodeForWasmNativeStub(
CallDescriptor* call_descriptor, MachineGraph* mcgraph, CodeKind kind,
const char* debug_name, const AssemblerOptions& options,
SourcePositionTable* source_positions) { … }
wasm::WasmCompilationResult
Pipeline::GenerateCodeForWasmNativeStubFromTurboshaft(
const wasm::WasmModule* module, const wasm::FunctionSig* sig,
wasm::WrapperCompilationInfo wrapper_info, const char* debug_name,
const AssemblerOptions& options, SourcePositionTable* source_positions) { … }
namespace {
void LowerInt64(const wasm::FunctionSig* sig, MachineGraph* mcgraph,
SimplifiedOperatorBuilder* simplified, PipelineImpl& pipeline) { … }
base::OwnedVector<uint8_t> SerializeInliningPositions(
const ZoneVector<WasmInliningPosition>& positions) { … }
}
void Pipeline::GenerateCodeForWasmFunction(
OptimizedCompilationInfo* info, wasm::CompilationEnv* env,
WasmCompilationData& compilation_data, MachineGraph* mcgraph,
CallDescriptor* call_descriptor,
ZoneVector<WasmInliningPosition>* inlining_positions,
wasm::WasmDetectedFeatures* detected) { … }
bool Pipeline::GenerateWasmCodeFromTurboshaftGraph(
OptimizedCompilationInfo* info, wasm::CompilationEnv* env,
WasmCompilationData& compilation_data, MachineGraph* mcgraph,
wasm::WasmDetectedFeatures* detected, CallDescriptor* call_descriptor) { … }
#endif
MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
OptimizedCompilationInfo* info, Isolate* isolate) { … }
MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
OptimizedCompilationInfo* info, Isolate* isolate,
CallDescriptor* call_descriptor, Graph* graph,
const AssemblerOptions& options, Schedule* schedule) { … }
MaybeHandle<Code> Pipeline::GenerateTurboshaftCodeForTesting(
CallDescriptor* call_descriptor, turboshaft::PipelineData* data) { … }
std::unique_ptr<TurbofanCompilationJob> Pipeline::NewCompilationJob(
Isolate* isolate, Handle<JSFunction> function, CodeKind code_kind,
bool has_script, BytecodeOffset osr_offset) { … }
void Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config,
InstructionSequence* sequence,
bool run_verifier) { … }
void PipelineImpl::ComputeScheduledGraph() { … }
#if V8_ENABLE_WASM_SIMD256_REVEC
void PipelineImpl::Revectorize() { … }
#endif
bool PipelineImpl::SelectInstructions(Linkage* linkage) { … }
bool PipelineImpl::AllocateRegisters(CallDescriptor* call_descriptor,
bool has_dummy_end_block) { … }
void PipelineImpl::VerifyGeneratedCodeIsIdempotent() { … }
void PipelineImpl::AssembleCode(Linkage* linkage) { … }
MaybeHandle<Code> PipelineImpl::FinalizeCode(bool retire_broker) { … }
bool PipelineImpl::SelectInstructionsAndAssemble(
CallDescriptor* call_descriptor) { … }
MaybeHandle<Code> PipelineImpl::GenerateCode(CallDescriptor* call_descriptor) { … }
bool PipelineImpl::CommitDependencies(Handle<Code> code) { … }
namespace {
void TraceSequence(OptimizedCompilationInfo* info, TFPipelineData* data,
const char* phase_name) { … }
}
void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config,
CallDescriptor* call_descriptor,
bool run_verifier) { … }
OptimizedCompilationInfo* PipelineImpl::info() const { … }
Isolate* PipelineImpl::isolate() const { … }
CodeGenerator* PipelineImpl::code_generator() const { … }
ObserveNodeManager* PipelineImpl::observe_node_manager() const { … }
std::ostream& operator<<(std::ostream& out, const InstructionRangesAsJSON& s) { … }
}
}
}