Sanitizers.h - remove MathExtras.h include dependency
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 9 Jun 2021 13:37:56 +0000 (14:37 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 9 Jun 2021 13:38:20 +0000 (14:38 +0100)
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
clang/lib/Basic/Sanitizers.cpp

index 1acce0a..82e5a73 100644 (file)
@@ -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 @@ 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)
index d8de850..3a3b24a 100644 (file)
@@ -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();
 }