[llvm] 9110673 - [nfc][msan] Group checks per instruction
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 1 13:10:35 PDT 2022
Author: Vitaly Buka
Date: 2022-09-01T13:10:16-07:00
New Revision: 91106730625341223c39aab2f21373f25ff872f5
URL: https://github.com/llvm/llvm-project/commit/91106730625341223c39aab2f21373f25ff872f5
DIFF: https://github.com/llvm/llvm-project/commit/91106730625341223c39aab2f21373f25ff872f5.diff
LOG: [nfc][msan] Group checks per instruction
It's a preparation of to combine shadow checks of the same instruction
Reviewed By: kda, kstoimenov
Differential Revision: https://reviews.llvm.org/D133065
Added:
Modified:
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index ce7a80ccbf11..df9057f1e935 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -1274,8 +1274,10 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
bool InstrumentWithCalls,
ArrayRef<ShadowOriginAndInsertPoint> InstructionChecks) {
const DataLayout &DL = F.getParent()->getDataLayout();
+ Instruction *Instruction = InstructionChecks.front().OrigIns;
for (const auto &ShadowData : InstructionChecks) {
- IRBuilder<> IRB(ShadowData.OrigIns);
+ assert(ShadowData.OrigIns == Instruction);
+ IRBuilder<> IRB(Instruction);
LLVM_DEBUG(dbgs() << " SHAD0 : " << *ShadowData.Shadow << "\n");
Value *ConvertedShadow = convertShadowToScalar(ShadowData.Shadow, IRB);
@@ -1300,7 +1302,25 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
}
void materializeChecks(bool InstrumentWithCalls) {
- materializeInstructionChecks(InstrumentWithCalls, InstrumentationList);
+ llvm::stable_sort(InstrumentationList,
+ [](const ShadowOriginAndInsertPoint &L,
+ const ShadowOriginAndInsertPoint &R) {
+ return L.OrigIns < R.OrigIns;
+ });
+
+ for (auto I = InstrumentationList.begin();
+ I != InstrumentationList.end();) {
+ auto J =
+ std::find_if(I + 1, InstrumentationList.end(),
+ [L = I->OrigIns](const ShadowOriginAndInsertPoint &R) {
+ return L != R.OrigIns;
+ });
+ // Process all checks of instruction at once.
+ materializeInstructionChecks(InstrumentWithCalls,
+ ArrayRef<ShadowOriginAndInsertPoint>(I, J));
+ I = J;
+ }
+
LLVM_DEBUG(dbgs() << "DONE:\n" << F);
}
More information about the llvm-commits
mailing list