Skip to content

Commit 3129aa5

Browse files
committed
[NFC][sanitizers] Add StackDepotBase Node::hash_type
Depends on D111177. Differential Revision: https://reviews.llvm.org/D111182
1 parent 5ae9a3e commit 3129aa5

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace __sanitizer {
1515

1616
bool ChainedOriginDepot::ChainedOriginDepotNode::eq(
17-
u32 hash, const args_type &args) const {
17+
hash_type hash, const args_type &args) const {
1818
return here_id == args.here_id && prev_id == args.prev_id;
1919
}
2020

@@ -36,7 +36,8 @@ uptr ChainedOriginDepot::ChainedOriginDepotNode::storage_size(
3636
split, or one of two reserved values (-1) or (-2). Either case can
3737
dominate depending on the workload.
3838
*/
39-
u32 ChainedOriginDepot::ChainedOriginDepotNode::hash(const args_type &args) {
39+
ChainedOriginDepot::ChainedOriginDepotNode::hash_type
40+
ChainedOriginDepot::ChainedOriginDepotNode::hash(const args_type &args) {
4041
const u32 m = 0x5bd1e995;
4142
const u32 seed = 0x9747b28c;
4243
const u32 r = 24;
@@ -67,7 +68,7 @@ bool ChainedOriginDepot::ChainedOriginDepotNode::is_valid(
6768
}
6869

6970
void ChainedOriginDepot::ChainedOriginDepotNode::store(const args_type &args,
70-
u32 other_hash) {
71+
hash_type other_hash) {
7172
here_id = args.here_id;
7273
prev_id = args.prev_id;
7374
}

compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,23 @@ class ChainedOriginDepot {
4343
};
4444

4545
struct ChainedOriginDepotNode {
46+
using hash_type = u32;
4647
ChainedOriginDepotNode *link;
4748
u32 id;
4849
u32 here_id;
4950
u32 prev_id;
5051

5152
typedef ChainedOriginDepotDesc args_type;
5253

53-
bool eq(u32 hash, const args_type &args) const;
54+
bool eq(hash_type hash, const args_type &args) const;
5455

5556
static uptr storage_size(const args_type &args);
5657

57-
static u32 hash(const args_type &args);
58+
static hash_type hash(const args_type &args);
5859

5960
static bool is_valid(const args_type &args);
6061

61-
void store(const args_type &args, u32 other_hash);
62+
void store(const args_type &args, hash_type other_hash);
6263

6364
args_type load() const;
6465

compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
namespace __sanitizer {
2020

2121
struct StackDepotNode {
22+
using hash_type = u32;
2223
StackDepotNode *link;
2324
u32 id;
24-
u32 stack_hash;
25+
hash_type stack_hash;
2526
u32 size;
2627
atomic_uint32_t tag_and_use_count; // tag : 12 high bits; use_count : 20;
2728
uptr stack[1]; // [size]
@@ -32,7 +33,7 @@ struct StackDepotNode {
3233
static const u32 kUseCountMask = (1 << kUseCountBits) - 1;
3334

3435
typedef StackTrace args_type;
35-
bool eq(u32 hash, const args_type &args) const {
36+
bool eq(hash_type hash, const args_type &args) const {
3637
u32 tag =
3738
atomic_load(&tag_and_use_count, memory_order_relaxed) >> kUseCountBits;
3839
if (stack_hash != hash || args.size != size || args.tag != tag)
@@ -46,15 +47,15 @@ struct StackDepotNode {
4647
static uptr storage_size(const args_type &args) {
4748
return sizeof(StackDepotNode) + (args.size - 1) * sizeof(uptr);
4849
}
49-
static u32 hash(const args_type &args) {
50+
static hash_type hash(const args_type &args) {
5051
MurMur2HashBuilder H(args.size * sizeof(uptr));
5152
for (uptr i = 0; i < args.size; i++) H.add(args.trace[i]);
5253
return H.get();
5354
}
5455
static bool is_valid(const args_type &args) {
5556
return args.size > 0 && args.trace;
5657
}
57-
void store(const args_type &args, u32 hash) {
58+
void store(const args_type &args, hash_type hash) {
5859
CHECK_EQ(args.tag & (~kUseCountMask >> kUseCountBits), args.tag);
5960
atomic_store(&tag_and_use_count, args.tag << kUseCountBits,
6061
memory_order_relaxed);

compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class StackDepotBase {
2727
public:
2828
typedef typename Node::args_type args_type;
2929
typedef typename Node::handle_type handle_type;
30+
typedef typename Node::hash_type hash_type;
3031
// Maps stack trace to an unique id.
3132
handle_type Put(args_type args, bool *inserted = nullptr);
3233
// Retrieves a stored stack trace by the id.
@@ -39,7 +40,7 @@ class StackDepotBase {
3940
void PrintAll();
4041

4142
private:
42-
static Node *find(Node *s, args_type args, u32 hash);
43+
static Node *find(Node *s, args_type args, hash_type hash);
4344
static Node *lock(atomic_uintptr_t *p);
4445
static void unlock(atomic_uintptr_t *p, Node *s);
4546

@@ -62,7 +63,7 @@ class StackDepotBase {
6263
template <class Node, int kReservedBits, int kTabSizeLog>
6364
Node *StackDepotBase<Node, kReservedBits, kTabSizeLog>::find(Node *s,
6465
args_type args,
65-
u32 hash) {
66+
hash_type hash) {
6667
// Searches linked list s for the stack, returns its id.
6768
for (; s; s = s->link) {
6869
if (s->eq(hash, args)) {
@@ -101,7 +102,7 @@ StackDepotBase<Node, kReservedBits, kTabSizeLog>::Put(args_type args,
101102
bool *inserted) {
102103
if (inserted) *inserted = false;
103104
if (!Node::is_valid(args)) return handle_type();
104-
uptr h = Node::hash(args);
105+
hash_type h = Node::hash(args);
105106
atomic_uintptr_t *p = &tab[h % kTabSize];
106107
uptr v = atomic_load(p, memory_order_consume);
107108
Node *s = (Node *)(v & ~1);

0 commit comments

Comments
 (0)