From 206a66de5902b2b6dc0c62c4a25526d7e7f24186 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Wed, 9 Jun 2021 14:37:56 +0100 Subject: [PATCH] Sanitizers.h - remove MathExtras.h include dependency The MathExtras.h header is included purely for the countPopulation() method - by moving this into Sanitizers.cpp we can remove the use of this costly header. We only ever use isPowerOf2() / countPopulation() inside asserts so this shouldn't have any performance effects on production code. Differential Revision: https://reviews.llvm.org/D103953 --- clang/include/clang/Basic/Sanitizers.h | 8 +------- clang/lib/Basic/Sanitizers.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Basic/Sanitizers.h b/clang/include/clang/Basic/Sanitizers.h index 1acce0a..82e5a73 100644 --- a/clang/include/clang/Basic/Sanitizers.h +++ b/clang/include/clang/Basic/Sanitizers.h @@ -16,7 +16,6 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Support/MathExtras.h" #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h" #include #include @@ -60,12 +59,7 @@ public: return SanitizerMask(mask1, mask2); } - unsigned countPopulation() const { - unsigned total = 0; - for (const auto &Val : maskLoToHigh) - total += llvm::countPopulation(Val); - return total; - } + unsigned countPopulation() const; void flipAllBits() { for (auto &Val : maskLoToHigh) diff --git a/clang/lib/Basic/Sanitizers.cpp b/clang/lib/Basic/Sanitizers.cpp index d8de850..3a3b24a 100644 --- a/clang/lib/Basic/Sanitizers.cpp +++ b/clang/lib/Basic/Sanitizers.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/Hashing.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/Support/MathExtras.h" using namespace clang; @@ -57,6 +58,13 @@ llvm::hash_code SanitizerMask::hash_value() const { } namespace clang { +unsigned SanitizerMask::countPopulation() const { + unsigned total = 0; + for (const auto &Val : maskLoToHigh) + total += llvm::countPopulation(Val); + return total; +} + llvm::hash_code hash_value(const clang::SanitizerMask &Arg) { return Arg.hash_value(); } -- 2.7.4