Skip to content

Commit fa7521e

Browse files
DadaIsCrazyV8 LUCI CQ
authored andcommitted
[turboshaft] Use absl containers instead of std::unordered*
Bug: v8:12783 Change-Id: Ifdb5ae48d6f236ad7ace474c38c1822ebb7930f3 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4681718 Commit-Queue: Darius Mercadier <dmercadier@chromium.org> Reviewed-by: Victor Gomes <victorgomes@chromium.org> Reviewed-by: Toon Verwaest <verwaest@chromium.org> Cr-Commit-Position: refs/heads/main@{#90814}
1 parent bad6f61 commit fa7521e

17 files changed

Lines changed: 98 additions & 18 deletions

BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3968,6 +3968,8 @@ v8_library(
39683968
deps = [
39693969
":v8_libbase",
39703970
"//external:base_trace_event_common",
3971+
"//external:absl_flat_hash_map",
3972+
"//external:absl_flat_hash_set",
39713973
],
39723974
)
39733975

BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,8 @@ config("toolchain") {
14461446
if (v8_enable_slow_dchecks) {
14471447
defines += [ "ENABLE_SLOW_DCHECKS" ]
14481448
}
1449+
} else {
1450+
defines += [ "NDEBUG" ]
14491451
}
14501452

14511453
if (v8_enable_verify_csa) {
@@ -4629,6 +4631,7 @@ v8_header_set("v8_internal_headers") {
46294631
":cppgc_headers",
46304632
":generate_bytecode_builtins_list",
46314633
":run_torque",
4634+
":v8_abseil",
46324635
":v8_heap_base_headers",
46334636
":v8_libbase",
46344637
]

DEPS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ include_rules = [
338338
# the Chromium guidelines (though note that some requirements in V8 may be
339339
# different to Chromium's):
340340
# https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++11.md
341+
'+absl/container/flat_hash_map.h',
342+
'+absl/container/flat_hash_set.h',
341343
'+absl/types/optional.h',
342344
'+absl/types/variant.h',
343345
'+absl/status',

WORKSPACE

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ bind(
4444
actual = "@com_google_absl//absl/types:optional"
4545
)
4646

47+
bind(
48+
name = "absl_flat_hash_map",
49+
actual = "@com_google_absl//absl/container:flat_hash_map"
50+
)
51+
52+
bind(
53+
name = "absl_flat_hash_set",
54+
actual = "@com_google_absl//absl/container:flat_hash_set"
55+
)
56+
4757
new_local_repository(
4858
name = "com_googlesource_chromium_icu",
4959
build_file = "bazel/BUILD.icu",

src/compiler/turboshaft/index.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ class OpIndex {
141141
uint32_t offset_;
142142

143143
static constexpr uint32_t kTurbofanNodeIdFlag = 1;
144+
145+
template <typename H>
146+
friend H AbslHashValue(H h, const OpIndex& idx) {
147+
return H::combine(std::move(h), idx.offset_);
148+
}
144149
};
145150

146151
std::ostream& operator<<(std::ostream& os, OpIndex idx);
@@ -165,6 +170,11 @@ class OptionalOpIndex : protected OpIndex {
165170
return OpIndex(*this);
166171
}
167172
constexpr OpIndex value_or_invalid() const { return OpIndex(*this); }
173+
174+
template <typename H>
175+
friend H AbslHashValue(H h, const OptionalOpIndex& idx) {
176+
return H::combine(std::move(h), idx.offset_);
177+
}
168178
};
169179

170180
V8_INLINE std::ostream& operator<<(std::ostream& os, OptionalOpIndex idx) {

src/compiler/turboshaft/late-escape-analysis-reducer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class LateEscapeAnalysisAnalyzer {
3636
Zone* phase_zone_;
3737

3838
// {alloc_uses_} records all the uses of each AllocateOp.
39-
ZoneUnorderedMap<OpIndex, ZoneVector<OpIndex>> alloc_uses_;
39+
ZoneAbslFlatHashMap<OpIndex, ZoneVector<OpIndex>> alloc_uses_;
4040
// {allocs_} is filled with all of the AllocateOp of the graph, and then
4141
// iterated upon to determine which allocations can be removed and which
4242
// cannot.

src/compiler/turboshaft/late-load-elimination-reducer.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ struct MemoryAddress {
179179
offset == other.offset &&
180180
element_size_log2 == other.element_size_log2 && size == other.size;
181181
}
182+
183+
template <typename H>
184+
friend H AbslHashValue(H h, const MemoryAddress& mem) {
185+
return H::combine(std::move(h), mem.base, mem.index, mem.offset,
186+
mem.element_size_log2, mem.size);
187+
}
182188
};
183189

184190
inline size_t hash_value(MemoryAddress const& mem) {
@@ -530,16 +536,14 @@ class MemoryContentTable
530536
SparseOpIndexSnapshotTable<MapMaskAndOr>& object_maps_;
531537
FixedOpIndexSidetable<OpIndex>& replacements_;
532538

533-
// TODO(dmercadier): consider using a faster datastructure than
534-
// ZoneUnorderedMap for {all_keys_}, {base_keys_} and {offset_keys_}.
535-
536539
// A map containing all of the keys, for fast lookup of a specific
537540
// MemoryAddress.
538-
ZoneUnorderedMap<MemoryAddress, Key> all_keys_;
541+
ZoneAbslFlatHashMap<MemoryAddress, Key> all_keys_;
539542
// Map from base OpIndex to keys associated with this base.
540-
ZoneUnorderedMap<OpIndex, BaseData> base_keys_;
543+
ZoneAbslFlatHashMap<OpIndex, BaseData> base_keys_;
541544
// Map from offsets to keys associated with this offset.
542-
ZoneUnorderedMap<int, DoublyThreadedList<Key, OffsetListTraits>> offset_keys_;
545+
ZoneAbslFlatHashMap<int, DoublyThreadedList<Key, OffsetListTraits>>
546+
offset_keys_;
543547

544548
// List of all of the keys that have a valid index.
545549
DoublyThreadedList<Key, OffsetListTraits> index_keys_;

src/compiler/turboshaft/memory-optimization-reducer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "src/compiler/turboshaft/assembler.h"
1212
#include "src/compiler/turboshaft/phase.h"
1313
#include "src/compiler/turboshaft/utils.h"
14+
#include "src/zone/zone-containers.h"
1415

1516
namespace v8::internal::compiler::turboshaft {
1617

@@ -55,10 +56,10 @@ struct MemoryAnalyzer {
5556
};
5657
FixedBlockSidetable<base::Optional<BlockState>> block_states{
5758
input_graph.block_count(), phase_zone};
58-
ZoneUnorderedMap<const AllocateOp*, const AllocateOp*> folded_into{
59+
ZoneAbslFlatHashMap<const AllocateOp*, const AllocateOp*> folded_into{
5960
phase_zone};
60-
ZoneUnorderedSet<OpIndex> skipped_write_barriers{phase_zone};
61-
ZoneUnorderedMap<const AllocateOp*, uint32_t> reserved_size{phase_zone};
61+
ZoneAbslFlatHashSet<OpIndex> skipped_write_barriers{phase_zone};
62+
ZoneAbslFlatHashMap<const AllocateOp*, uint32_t> reserved_size{phase_zone};
6263
BlockIndex current_block = BlockIndex(0);
6364
BlockState state;
6465

src/compiler/turboshaft/operations.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,7 +2912,13 @@ struct AllocateOp : FixedArityOperationT<1, AllocateOp> {
29122912
void Validate(const Graph& graph) const {
29132913
}
29142914
void PrintOptions(std::ostream& os) const;
2915+
29152916
auto options() const { return std::tuple{type}; }
2917+
2918+
// template <typename H>
2919+
// friend H AbslHashValue(H h, const AllocateOp& op) {
2920+
// return H::combine(std::move(h), op.size(), op.type);
2921+
// }
29162922
};
29172923

29182924
struct DecodeExternalPointerOp

src/compiler/turboshaft/optimization-phase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <algorithm>
99
#include <cstddef>
1010
#include <cstdint>
11-
#include <unordered_map>
1211
#include <utility>
1312

1413
#include "src/base/iterator.h"
@@ -23,6 +22,7 @@
2322
#include "src/compiler/turboshaft/phase.h"
2423
#include "src/compiler/turboshaft/reducer-traits.h"
2524
#include "src/compiler/turboshaft/snapshot-table.h"
25+
#include "src/zone/zone-containers.h"
2626

2727
namespace v8::internal::compiler::turboshaft {
2828

0 commit comments

Comments
 (0)