[PATCH] D103953: Sanitizers.h - remove MathExtras.h include dependency
Simon Pilgrim via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 9 04:01:52 PDT 2021
RKSimon created this revision.
RKSimon added reviewers: pgousseau, filcab, bkramer.
Herald added a subscriber: dexonsmith.
RKSimon requested review of this revision.
Herald added a project: clang.
We include the MathExtras.h header purely for the countPopulation() method - by moving this into Sanitizers.cpp we can remove the use of this costly header.
AFAICT we only ever use isPowerOf2() / countPopulation() insider asserts (see the CGExpr.cpp change which I noticed by altering their access to private) so this shouldn't have any performance effects on production code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103953
Files:
clang/include/clang/Basic/Sanitizers.h
clang/lib/Basic/Sanitizers.cpp
clang/lib/CodeGen/CGExpr.cpp
Index: clang/lib/CodeGen/CGExpr.cpp
===================================================================
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -3126,7 +3126,7 @@
}
static CheckRecoverableKind getRecoverableKind(SanitizerMask Kind) {
- assert(Kind.countPopulation() == 1);
+ assert(Kind.isPowerOf2());
if (Kind == SanitizerKind::Function || Kind == SanitizerKind::Vptr)
return CheckRecoverableKind::AlwaysRecoverable;
else if (Kind == SanitizerKind::Return || Kind == SanitizerKind::Unreachable)
Index: clang/lib/Basic/Sanitizers.cpp
===================================================================
--- clang/lib/Basic/Sanitizers.cpp
+++ 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 @@
}
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();
}
Index: clang/include/clang/Basic/Sanitizers.h
===================================================================
--- clang/include/clang/Basic/Sanitizers.h
+++ 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 @@
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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103953.350845.patch
Type: text/x-patch
Size: 1990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210609/2fea54d6/attachment.bin>
More information about the cfe-commits
mailing list