[clang] 206a66d - Sanitizers.h - remove MathExtras.h include dependency

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 9 06:38:30 PDT 2021


Author: Simon Pilgrim
Date: 2021-06-09T14:38:20+01:00
New Revision: 206a66de5902b2b6dc0c62c4a25526d7e7f24186

URL: https://github.com/llvm/llvm-project/commit/206a66de5902b2b6dc0c62c4a25526d7e7f24186
DIFF: https://github.com/llvm/llvm-project/commit/206a66de5902b2b6dc0c62c4a25526d7e7f24186.diff

LOG: 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

Added: 
    

Modified: 
    clang/include/clang/Basic/Sanitizers.h
    clang/lib/Basic/Sanitizers.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/Sanitizers.h b/clang/include/clang/Basic/Sanitizers.h
index 1acce0a6e09e..82e5a73dee2e 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 <cassert>
 #include <cstdint>
@@ -60,12 +59,7 @@ class SanitizerMask {
     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 d8de850485eb..3a3b24a62e11 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();
 }


        


More information about the cfe-commits mailing list