[compiler-rt] 3129aa5 - [NFC][sanitizers] Add StackDepotBase Node::hash_type
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 5 21:30:33 PDT 2021
Author: Vitaly Buka
Date: 2021-10-05T20:54:06-07:00
New Revision: 3129aa5caf1f9b5c48ab708f43cb3fc5173dd021
URL: https://github.com/llvm/llvm-project/commit/3129aa5caf1f9b5c48ab708f43cb3fc5173dd021
DIFF: https://github.com/llvm/llvm-project/commit/3129aa5caf1f9b5c48ab708f43cb3fc5173dd021.diff
LOG: [NFC][sanitizers] Add StackDepotBase Node::hash_type
Depends on D111177.
Differential Revision: https://reviews.llvm.org/D111182
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.cpp
compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.h
compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.cpp
index 57e0a6e27cd7..7fe9cd78d1d9 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.cpp
@@ -14,7 +14,7 @@
namespace __sanitizer {
bool ChainedOriginDepot::ChainedOriginDepotNode::eq(
- u32 hash, const args_type &args) const {
+ hash_type hash, const args_type &args) const {
return here_id == args.here_id && prev_id == args.prev_id;
}
@@ -36,7 +36,8 @@ uptr ChainedOriginDepot::ChainedOriginDepotNode::storage_size(
split, or one of two reserved values (-1) or (-2). Either case can
dominate depending on the workload.
*/
-u32 ChainedOriginDepot::ChainedOriginDepotNode::hash(const args_type &args) {
+ChainedOriginDepot::ChainedOriginDepotNode::hash_type
+ChainedOriginDepot::ChainedOriginDepotNode::hash(const args_type &args) {
const u32 m = 0x5bd1e995;
const u32 seed = 0x9747b28c;
const u32 r = 24;
@@ -67,7 +68,7 @@ bool ChainedOriginDepot::ChainedOriginDepotNode::is_valid(
}
void ChainedOriginDepot::ChainedOriginDepotNode::store(const args_type &args,
- u32 other_hash) {
+ hash_type other_hash) {
here_id = args.here_id;
prev_id = args.prev_id;
}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.h b/compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.h
index c1302a0abb8c..73a10e114f9b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.h
@@ -43,6 +43,7 @@ class ChainedOriginDepot {
};
struct ChainedOriginDepotNode {
+ using hash_type = u32;
ChainedOriginDepotNode *link;
u32 id;
u32 here_id;
@@ -50,15 +51,15 @@ class ChainedOriginDepot {
typedef ChainedOriginDepotDesc args_type;
- bool eq(u32 hash, const args_type &args) const;
+ bool eq(hash_type hash, const args_type &args) const;
static uptr storage_size(const args_type &args);
- static u32 hash(const args_type &args);
+ static hash_type hash(const args_type &args);
static bool is_valid(const args_type &args);
- void store(const args_type &args, u32 other_hash);
+ void store(const args_type &args, hash_type other_hash);
args_type load() const;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
index e7fd580ab969..fc2ea2fc768f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
@@ -19,9 +19,10 @@
namespace __sanitizer {
struct StackDepotNode {
+ using hash_type = u32;
StackDepotNode *link;
u32 id;
- u32 stack_hash;
+ hash_type stack_hash;
u32 size;
atomic_uint32_t tag_and_use_count; // tag : 12 high bits; use_count : 20;
uptr stack[1]; // [size]
@@ -32,7 +33,7 @@ struct StackDepotNode {
static const u32 kUseCountMask = (1 << kUseCountBits) - 1;
typedef StackTrace args_type;
- bool eq(u32 hash, const args_type &args) const {
+ bool eq(hash_type hash, const args_type &args) const {
u32 tag =
atomic_load(&tag_and_use_count, memory_order_relaxed) >> kUseCountBits;
if (stack_hash != hash || args.size != size || args.tag != tag)
@@ -46,7 +47,7 @@ struct StackDepotNode {
static uptr storage_size(const args_type &args) {
return sizeof(StackDepotNode) + (args.size - 1) * sizeof(uptr);
}
- static u32 hash(const args_type &args) {
+ static hash_type hash(const args_type &args) {
MurMur2HashBuilder H(args.size * sizeof(uptr));
for (uptr i = 0; i < args.size; i++) H.add(args.trace[i]);
return H.get();
@@ -54,7 +55,7 @@ struct StackDepotNode {
static bool is_valid(const args_type &args) {
return args.size > 0 && args.trace;
}
- void store(const args_type &args, u32 hash) {
+ void store(const args_type &args, hash_type hash) {
CHECK_EQ(args.tag & (~kUseCountMask >> kUseCountBits), args.tag);
atomic_store(&tag_and_use_count, args.tag << kUseCountBits,
memory_order_relaxed);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
index 592df4b5d47f..435f634cd11f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
@@ -27,6 +27,7 @@ class StackDepotBase {
public:
typedef typename Node::args_type args_type;
typedef typename Node::handle_type handle_type;
+ typedef typename Node::hash_type hash_type;
// Maps stack trace to an unique id.
handle_type Put(args_type args, bool *inserted = nullptr);
// Retrieves a stored stack trace by the id.
@@ -39,7 +40,7 @@ class StackDepotBase {
void PrintAll();
private:
- static Node *find(Node *s, args_type args, u32 hash);
+ static Node *find(Node *s, args_type args, hash_type hash);
static Node *lock(atomic_uintptr_t *p);
static void unlock(atomic_uintptr_t *p, Node *s);
@@ -62,7 +63,7 @@ class StackDepotBase {
template <class Node, int kReservedBits, int kTabSizeLog>
Node *StackDepotBase<Node, kReservedBits, kTabSizeLog>::find(Node *s,
args_type args,
- u32 hash) {
+ hash_type hash) {
// Searches linked list s for the stack, returns its id.
for (; s; s = s->link) {
if (s->eq(hash, args)) {
@@ -101,7 +102,7 @@ StackDepotBase<Node, kReservedBits, kTabSizeLog>::Put(args_type args,
bool *inserted) {
if (inserted) *inserted = false;
if (!Node::is_valid(args)) return handle_type();
- uptr h = Node::hash(args);
+ hash_type h = Node::hash(args);
atomic_uintptr_t *p = &tab[h % kTabSize];
uptr v = atomic_load(p, memory_order_consume);
Node *s = (Node *)(v & ~1);
More information about the llvm-commits
mailing list