v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
pipelines.cc
Go to the documentation of this file.
1// Copyright 2024 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
6
13
15
16#define RUN_MAYBE_ABORT(phase, ...) \
17 if (V8_UNLIKELY(!Run<phase>(__VA_ARGS__))) return {};
18
24
26 CallDescriptor* call_descriptor,
27 bool run_verifier) {
28 // Don't track usage for this zone in compiler stats.
29 std::unique_ptr<Zone> verifier_zone;
30 RegisterAllocatorVerifier* verifier = nullptr;
31 if (run_verifier) {
32 AccountingAllocator* allocator = data()->allocator();
33 DCHECK_NOT_NULL(allocator);
34 verifier_zone.reset(
36 verifier = verifier_zone->New<RegisterAllocatorVerifier>(
37 verifier_zone.get(), config, data()->sequence(), data()->frame());
38 }
39
40#ifdef DEBUG
44#endif
45
46 data_->InitializeRegisterComponent(config, call_descriptor);
47
52
53 TraceSequence("before register allocation");
54 if (verifier != nullptr) {
58 }
59
60 if (data_->info()->trace_turbo_json() && !MayHaveUnverifiableGraph()) {
62 tcf << AsC1VRegisterAllocationData("PreAllocation",
64 }
65
67
70 }
71
75 return false;
76 }
77
81
82 // TODO(chromium:725559): remove this check once
83 // we understand the cause of the bug. We keep just the
84 // check at the end of the allocation.
85 if (verifier != nullptr) {
86 verifier->VerifyAssignment("Immediately after CommitAssignmentPhase.");
87 }
88
90
92
94
95 if (v8_flags.turbo_move_optimization) {
97 }
98
99 TraceSequence("after register allocation");
100
101 if (verifier != nullptr) {
102 verifier->VerifyAssignment("End of regalloc pipeline.");
103 verifier->VerifyGapMoves();
104 }
105
106 if (data_->info()->trace_turbo_json() && !MayHaveUnverifiableGraph()) {
107 TurboCfgFile tcf(data_->isolate());
108 tcf << AsC1VRegisterAllocationData("CodeGen",
110 }
111
113 return true;
114}
115
116[[nodiscard]] bool Pipeline::GenerateCode(
117 Linkage* linkage, std::shared_ptr<OsrHelper> osr_helper,
118 JumpOptimizationInfo* jump_optimization_info,
119 const ProfileDataFromFile* profile, int initial_graph_hash) {
120 // Run code generation. If we optimize jumps, we repeat this a second time.
121 data()->InitializeCodegenComponent(osr_helper, jump_optimization_info);
122
123 // Perform instruction selection and register allocation.
124 if (!PrepareForInstructionSelection(profile)) return false;
125 if (!SelectInstructions(linkage)) return false;
126 if (!AllocateRegisters(linkage->GetIncomingDescriptor())) return false;
127 if (!AssembleCode(linkage)) return false;
128
129 if (v8_flags.turbo_profiling) {
130 info()->profiler_data()->SetHash(initial_graph_hash);
131 }
132
133 if (jump_optimization_info && jump_optimization_info->is_optimizable()) {
134 // Reset data for a second run of instruction selection.
136 jump_optimization_info->set_optimizing();
137
138 // Perform instruction selection and register allocation.
139 data()->InitializeCodegenComponent(osr_helper, jump_optimization_info);
141 return false;
142 }
143 if (!AllocateRegisters(linkage->GetIncomingDescriptor())) return false;
144 // Generate the final machine code.
145 if (!AssembleCode(linkage)) return false;
146 }
147 return true;
148}
149
165
166} // namespace v8::internal::compiler::turboshaft
friend Zone
Definition asm-types.cc:195
BasicBlockProfilerData * profiler_data() const
AccountingAllocator * allocator() const
Definition phase.cc:29
void InitializeCodegenComponent(std::shared_ptr< OsrHelper > osr_helper, JumpOptimizationInfo *jump_optimization_info=nullptr)
Definition phase.h:256
void InitializeRegisterComponent(const RegisterConfiguration *config, CallDescriptor *call_descriptor)
Definition phase.cc:19
RegisterAllocationData * register_allocation_data() const
Definition phase.h:363
InstructionSequence * sequence() const
Definition phase.h:377
OptimizedCompilationInfo * info() const
Definition phase.h:329
V8_WARN_UNUSED_RESULT bool PrepareForInstructionSelection(const ProfileDataFromFile *profile=nullptr)
Definition pipelines.h:230
MaybeHandle< Code > GenerateCode(CallDescriptor *call_descriptor)
Definition pipelines.h:423
V8_WARN_UNUSED_RESULT bool AssembleCode(Linkage *linkage)
Definition pipelines.h:401
OptimizedCompilationInfo * info()
Definition pipelines.h:439
void TraceSequence(const char *phase_name)
Definition pipelines.h:112
V8_WARN_UNUSED_RESULT bool AllocateRegisters(CallDescriptor *call_descriptor)
Definition pipelines.h:333
V8_WARN_UNUSED_RESULT auto Run(Args &&... args)
Definition pipelines.h:68
Linkage * linkage
constexpr char kRegisterAllocatorVerifierZoneName[]
Definition phase.h:43
constexpr AliasingKind kFPAliasing
V8_EXPORT_PRIVATE FlagValues v8_flags
#define RUN_MAYBE_ABORT(phase,...)
Definition pipeline.cc:152
#define CHECK(condition)
Definition logging.h:124
#define DCHECK_NOT_NULL(val)
Definition logging.h:492