v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
phase.cc
Go to the documentation of this file.
1// Copyright 2023 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
12#include "src/utils/ostreams.h"
13#ifdef V8_ENABLE_WEBASSEMBLY
15#endif
16
18
20 const RegisterConfiguration* config, CallDescriptor* call_descriptor) {
21 DCHECK(!register_component_.has_value());
23 auto& zone = register_component_->zone;
24 register_component_->allocation_data = zone.New<RegisterAllocationData>(
25 config, zone, frame(), sequence(), &info()->tick_counter(),
26 debug_name_.get());
27}
28
30 if (isolate_) return isolate_->allocator();
31#ifdef V8_ENABLE_WEBASSEMBLY
32 if (auto e = wasm::GetWasmEngine()) {
33 return e->allocator();
34 }
35#endif
36 return nullptr;
37}
38
39void PrintTurboshaftGraph(PipelineData* data, Zone* temp_zone,
40 CodeTracer* code_tracer, const char* phase_name) {
41 if (data->info()->trace_turbo_json()) {
42 UnparkedScopeIfNeeded scope(data->broker());
43 AllowHandleDereference allow_deref;
44 turboshaft::Graph& graph = data->graph();
45
46 TurboJsonFile json_of(data->info(), std::ios_base::app);
47 PrintTurboshaftGraphForTurbolizer(json_of, graph, phase_name,
48 data->node_origins(), temp_zone);
49 }
50
51 if (data->info()->trace_turbo_graph()) {
52 DCHECK(code_tracer);
53 UnparkedScopeIfNeeded scope(data->broker());
54 AllowHandleDereference allow_deref;
55
56 CodeTracer::StreamScope tracing_scope(code_tracer);
57 tracing_scope.stream() << "\n----- " << phase_name << " -----\n"
58 << data->graph();
59 }
60}
61
62void PrintTurboshaftGraphForTurbolizer(std::ofstream& stream,
63 const Graph& graph,
64 const char* phase_name,
65 NodeOriginTable* node_origins,
66 Zone* temp_zone) {
67 stream << "{\"name\":\"" << phase_name
68 << "\",\"type\":\"turboshaft_graph\",\"data\":"
69 << AsJSON(graph, node_origins, temp_zone) << "},\n";
70
72 stream, "Properties", graph,
73 [](std::ostream& stream, const turboshaft::Graph& graph,
74 turboshaft::OpIndex index) -> bool {
75 const auto& op = graph.Get(index);
76 op.PrintOptions(stream);
77 return true;
78 });
80 stream, "Types", graph,
81 [](std::ostream& stream, const turboshaft::Graph& graph,
82 turboshaft::OpIndex index) -> bool {
83 turboshaft::Type type = graph.operation_types()[index];
84 if (!type.IsInvalid() && !type.IsNone()) {
85 type.PrintTo(stream);
86 return true;
87 }
88 return false;
89 });
91 stream, "Representations", graph,
92 [](std::ostream& stream, const turboshaft::Graph& graph,
93 turboshaft::OpIndex index) -> bool {
94 const Operation& op = graph.Get(index);
95 stream << PrintCollection(op.outputs_rep());
96 return true;
97 });
99 stream, "Use Count (saturated)", graph,
100 [](std::ostream& stream, const turboshaft::Graph& graph,
101 turboshaft::OpIndex index) -> bool {
102 stream << static_cast<int>(graph.Get(index).saturated_use_count.Get());
103 return true;
104 });
105#ifdef DEBUG
107 stream, "Type Refinements", graph,
108 [](std::ostream& stream, const turboshaft::Graph& graph,
109 turboshaft::BlockIndex index) -> bool {
110 const std::vector<std::pair<turboshaft::OpIndex, turboshaft::Type>>&
111 refinements = graph.block_type_refinement()[index];
112 if (refinements.empty()) return false;
113 stream << "\\n";
114 for (const auto& [op, type] : refinements) {
115 stream << op << " : " << type << "\\n";
116 }
117 return true;
118 });
119#endif // DEBUG
120}
121
123#if V8_ENABLE_WEBASSEMBLY
124 if (info_->IsWasm() || info_->IsWasmBuiltin()) {
126 }
127#endif // V8_ENABLE_WEBASSEMBLY
129 return isolate_->GetCodeTracer();
130}
131
132} // namespace v8::internal::compiler::turboshaft
AccountingAllocator * allocator()
Definition isolate.h:1979
CodeTracer * GetCodeTracer()
Definition isolate.cc:6124
AccountingAllocator * allocator() const
Definition phase.cc:29
void InitializeRegisterComponent(const RegisterConfiguration *config, CallDescriptor *call_descriptor)
Definition phase.cc:19
InstructionSequence * sequence() const
Definition phase.h:377
std::optional< RegisterComponent > register_component_
Definition phase.h:529
OptimizedCompilationInfo * info() const
Definition phase.h:329
void PrintTurboshaftGraph(PipelineData *data, Zone *temp_zone, CodeTracer *code_tracer, const char *phase_name)
Definition phase.cc:39
void PrintTurboshaftGraphForTurbolizer(std::ofstream &stream, const Graph &graph, const char *phase_name, NodeOriginTable *node_origins, Zone *temp_zone)
Definition phase.cc:62
V8_INLINE V8_EXPORT_PRIVATE TurboshaftGraphAsJSON AsJSON(const Graph &graph, NodeOriginTable *origins, Zone *temp_zone)
void PrintTurboshaftCustomDataPerBlock(std::ofstream &stream, const char *data_name, const Graph &graph, std::function< bool(std::ostream &, const Graph &, BlockIndex)> printer)
void PrintTurboshaftCustomDataPerOperation(std::ofstream &stream, const char *data_name, const Graph &graph, std::function< bool(std::ostream &, const Graph &, OpIndex)> printer)
WasmEngine * GetWasmEngine()
auto PrintCollection(const T &collection) -> PrintIteratorRange< typename std::common_type< decltype(std::begin(collection)), decltype(std::end(collection))>::type >
Definition ostreams.h:186
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK(condition)
Definition logging.h:482
base::Vector< const RegisterRepresentation > outputs_rep() const