[llvm] e86bd32 - [NFC] [HWASan] [MTE] Use function_ref over template.
Florian Mayer via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 8 15:50:09 PST 2022
Author: Florian Mayer
Date: 2022-03-08T15:49:55-08:00
New Revision: e86bd32b71e17ca0183e17324486c83428026b1c
URL: https://github.com/llvm/llvm-project/commit/e86bd32b71e17ca0183e17324486c83428026b1c
DIFF: https://github.com/llvm/llvm-project/commit/e86bd32b71e17ca0183e17324486c83428026b1c.diff
LOG: [NFC] [HWASan] [MTE] Use function_ref over template.
Added:
Modified:
llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h b/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
index b429f413b7120..0c3c566680577 100644
--- a/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
+++ b/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
@@ -29,42 +29,11 @@ namespace memtag {
// Returns whether Ends covered all possible exits. If they did not,
// the caller should remove Ends to ensure that work done at the other
// exits does not happen outside of the lifetime.
-template <typename F>
bool forAllReachableExits(const DominatorTree &DT, const PostDominatorTree &PDT,
const Instruction *Start,
const SmallVectorImpl<IntrinsicInst *> &Ends,
const SmallVectorImpl<Instruction *> &RetVec,
- F Callback) {
- if (Ends.size() == 1 && PDT.dominates(Ends[0], Start)) {
- Callback(Ends[0]);
- return true;
- }
- SmallVector<Instruction *, 8> ReachableRetVec;
- unsigned NumCoveredExits = 0;
- for (auto *RI : RetVec) {
- if (!isPotentiallyReachable(Start, RI, nullptr, &DT))
- continue;
- ReachableRetVec.push_back(RI);
- // TODO(fmayer): We don't support diamond shapes, where multiple lifetime
- // ends together dominate the RI, but none of them does by itself.
- // Check how often this happens and decide whether to support this here.
- if (llvm::any_of(Ends, [&](auto *End) { return DT.dominates(End, RI); }))
- ++NumCoveredExits;
- }
- // If there's a mix of covered and non-covered exits, just put the untag
- // on exits, so we avoid the redundancy of untagging twice.
- if (NumCoveredExits == ReachableRetVec.size()) {
- for (auto *End : Ends)
- Callback(End);
- } else {
- for (auto *RI : ReachableRetVec)
- Callback(RI);
- // We may have inserted untag outside of the lifetime interval.
- // Signal the caller to remove the lifetime end call for this alloca.
- return false;
- }
- return true;
-}
+ llvm::function_ref<void(Instruction *)> Callback);
bool isStandardLifetime(const SmallVectorImpl<IntrinsicInst *> &LifetimeStart,
const SmallVectorImpl<IntrinsicInst *> &LifetimeEnd,
diff --git a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
index 641dd58456f6f..5e3e90fe4ba2b 100644
--- a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
+++ b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
@@ -34,6 +34,42 @@ bool maybeReachableFromEachOther(const SmallVectorImpl<IntrinsicInst *> &Insts,
}
} // namespace
+bool forAllReachableExits(const DominatorTree &DT, const PostDominatorTree &PDT,
+ const Instruction *Start,
+ const SmallVectorImpl<IntrinsicInst *> &Ends,
+ const SmallVectorImpl<Instruction *> &RetVec,
+ llvm::function_ref<void(Instruction *)> Callback) {
+ if (Ends.size() == 1 && PDT.dominates(Ends[0], Start)) {
+ Callback(Ends[0]);
+ return true;
+ }
+ SmallVector<Instruction *, 8> ReachableRetVec;
+ unsigned NumCoveredExits = 0;
+ for (auto *RI : RetVec) {
+ if (!isPotentiallyReachable(Start, RI, nullptr, &DT))
+ continue;
+ ReachableRetVec.push_back(RI);
+ // TODO(fmayer): We don't support diamond shapes, where multiple lifetime
+ // ends together dominate the RI, but none of them does by itself.
+ // Check how often this happens and decide whether to support this here.
+ if (llvm::any_of(Ends, [&](auto *End) { return DT.dominates(End, RI); }))
+ ++NumCoveredExits;
+ }
+ // If there's a mix of covered and non-covered exits, just put the untag
+ // on exits, so we avoid the redundancy of untagging twice.
+ if (NumCoveredExits == ReachableRetVec.size()) {
+ for (auto *End : Ends)
+ Callback(End);
+ } else {
+ for (auto *RI : ReachableRetVec)
+ Callback(RI);
+ // We may have inserted untag outside of the lifetime interval.
+ // Signal the caller to remove the lifetime end call for this alloca.
+ return false;
+ }
+ return true;
+}
+
bool isStandardLifetime(const SmallVectorImpl<IntrinsicInst *> &LifetimeStart,
const SmallVectorImpl<IntrinsicInst *> &LifetimeEnd,
const DominatorTree *DT, size_t MaxLifetimes) {
More information about the llvm-commits
mailing list