v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
use-map.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
8
10
11UseMap::UseMap(const Graph& graph, Zone* zone, FunctionType filter)
12 : table_(graph.op_id_count(), zone, &graph),
13 uses_(zone),
14 saturated_uses_(zone) {
15 ZoneVector<std::pair<OpIndex, OpIndex>> delayed_phi_uses(zone);
16
17 // We preallocate for 2 uses per operation.
18 uses_.reserve(graph.op_id_count() * 2);
19
20 // We skip {offset:0} to use {offset == 0} as uninitialized.
21 uint32_t offset = 1;
22 for (uint32_t index = 0; index < graph.block_count(); ++index) {
23 BlockIndex block_index(index);
24 const Block& block = graph.Get(block_index);
25
26 auto block_ops = graph.OperationIndices(block);
27 for (OpIndex op_index : block_ops) {
28 const Operation& op = graph.Get(op_index);
29 // When we see a definition, we allocate space in the {uses_}.
30 DCHECK_EQ(table_[op_index].offset, 0);
31 DCHECK_EQ(table_[op_index].count, 0);
32
34 table_[op_index].offset =
35 -static_cast<int32_t>(saturated_uses_.size()) - 1;
36 saturated_uses_.emplace_back(zone);
37 saturated_uses_.back().reserve(std::numeric_limits<uint8_t>::max());
38 } else {
39 table_[op_index].offset = offset;
41 uses_.resize(offset);
42 }
43
44 if (filter(op, zone)) continue;
45
46 if (block.IsLoop()) {
47 if (op.Is<PhiOp>()) {
50 AddUse(&graph, op.input(0), op_index);
51 // Delay back edge of loop Phis.
52 delayed_phi_uses.emplace_back(op.input(1), op_index);
53 continue;
54 }
55 }
56
57 // Add uses.
58 for (OpIndex input_index : op.inputs()) {
59 AddUse(&graph, input_index, op_index);
60 }
61 }
62 }
63
64 for (auto [input_index, op_index] : delayed_phi_uses) {
65 AddUse(&graph, input_index, op_index);
66 }
67}
68
70 DCHECK(index.valid());
71 int32_t offset = table_[index].offset;
72 uint32_t count = table_[index].count;
73 DCHECK_NE(offset, 0);
74 if (V8_LIKELY(offset > 0)) {
76 } else {
79 count);
80 }
81}
82
83void UseMap::AddUse(const Graph* graph, OpIndex node, OpIndex use) {
84 int32_t input_offset = table_[node].offset;
85 uint32_t& input_count = table_[node].count;
86 DCHECK_NE(input_offset, 0);
87 if (V8_LIKELY(input_offset > 0)) {
88 DCHECK_LT(input_count, graph->Get(node).saturated_use_count.Get());
89 DCHECK(!uses_[input_offset + input_count].valid());
90 uses_[input_offset + input_count] = use;
91 } else {
92 ZoneVector<OpIndex>& uses = saturated_uses_[-input_offset - 1];
93 DCHECK_EQ(uses.size(), input_count);
94 uses.emplace_back(use);
95 }
96 ++input_count;
97}
98
99} // namespace v8::internal::compiler::turboshaft
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
T & emplace_back(Args &&... args)
ZoneVector< ZoneVector< OpIndex > > saturated_uses_
Definition use-map.h:40
FixedOpIndexSidetable< PerOperationUses > table_
Definition use-map.h:38
base::Vector< const OpIndex > uses(OpIndex index) const
Definition use-map.cc:69
void AddUse(const Graph *graph, OpIndex node, OpIndex use)
Definition use-map.cc:83
UseMap(const Graph &graph, Zone *zone, FunctionType filter)
Definition use-map.cc:11
int32_t offset
Node * node
bool(* FunctionType)(const Operation &op, Zone *zone)
Definition use-map.h:12
other heap size generate builtins concurrently on separate threads in mksnapshot track concurrent recompilation artificial compilation delay in ms max number of threads that concurrent Turbofan can use(0 for unbounded)") DEFINE_BOOL( stress_concurrent_inlining
SourcePositionTable *const table_
Definition pipeline.cc:227
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
V8_INLINE OpIndex input(size_t i) const
Definition operations.h:959
base::Vector< const OpIndex > inputs() const
static constexpr size_t kLoopPhiBackEdgeIndex
#define V8_LIKELY(condition)
Definition v8config.h:661