[llvm] r270263 - [esan] Use ModulePass for EfficiencySanitizerPass.
Derek Bruening via llvm-commits
llvm-commits at lists.llvm.org
Fri May 20 13:00:06 PDT 2016
Author: bruening
Date: Fri May 20 15:00:05 2016
New Revision: 270263
URL: http://llvm.org/viewvc/llvm-project?rev=270263&view=rev
Log:
[esan] Use ModulePass for EfficiencySanitizerPass.
Summary:
Uses ModulePass instead of FunctionPass for EfficiencySanitizerPass to
better support global variable creation for a forthcoming struct field
counter tool.
Patch by Qin Zhao.
Reviewers: aizatsky
Subscribers: llvm-commits, eugenis, vitalybuka, bruening, kcc
Differential Revision: http://reviews.llvm.org/D20458
Modified:
llvm/trunk/include/llvm/Transforms/Instrumentation.h
llvm/trunk/lib/Transforms/Instrumentation/EfficiencySanitizer.cpp
Modified: llvm/trunk/include/llvm/Transforms/Instrumentation.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Instrumentation.h?rev=270263&r1=270262&r2=270263&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Instrumentation.h (original)
+++ llvm/trunk/include/llvm/Transforms/Instrumentation.h Fri May 20 15:00:05 2016
@@ -127,7 +127,7 @@ struct EfficiencySanitizerOptions {
};
// Insert EfficiencySanitizer instrumentation.
-FunctionPass *createEfficiencySanitizerPass(
+ModulePass *createEfficiencySanitizerPass(
const EfficiencySanitizerOptions &Options = EfficiencySanitizerOptions());
// Options for sanitizer coverage instrumentation.
Modified: llvm/trunk/lib/Transforms/Instrumentation/EfficiencySanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/EfficiencySanitizer.cpp?rev=270263&r1=270262&r2=270263&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/EfficiencySanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/EfficiencySanitizer.cpp Fri May 20 15:00:05 2016
@@ -78,18 +78,19 @@ OverrideOptionsFromCL(EfficiencySanitize
}
/// EfficiencySanitizer: instrument each module to find performance issues.
-class EfficiencySanitizer : public FunctionPass {
+class EfficiencySanitizer : public ModulePass {
public:
EfficiencySanitizer(
const EfficiencySanitizerOptions &Opts = EfficiencySanitizerOptions())
- : FunctionPass(ID), Options(OverrideOptionsFromCL(Opts)) {}
+ : ModulePass(ID), Options(OverrideOptionsFromCL(Opts)) {}
const char *getPassName() const override;
- bool runOnFunction(Function &F) override;
- bool doInitialization(Module &M) override;
+ bool runOnModule(Module &M) override;
static char ID;
private:
+ bool initOnModule(Module &M);
void initializeCallbacks(Module &M);
+ bool runOnFunction(Function &F, Module &M);
bool instrumentLoadOrStore(Instruction *I, const DataLayout &DL);
bool instrumentMemIntrinsic(MemIntrinsic *MI);
bool shouldIgnoreMemoryAccess(Instruction *I);
@@ -125,7 +126,7 @@ const char *EfficiencySanitizer::getPass
return "EfficiencySanitizer";
}
-FunctionPass *
+ModulePass *
llvm::createEfficiencySanitizerPass(const EfficiencySanitizerOptions &Options) {
return new EfficiencySanitizer(Options);
}
@@ -172,7 +173,7 @@ void EfficiencySanitizer::initializeCall
IRB.getInt32Ty(), IntptrTy, nullptr));
}
-bool EfficiencySanitizer::doInitialization(Module &M) {
+bool EfficiencySanitizer::initOnModule(Module &M) {
Ctx = &M.getContext();
const DataLayout &DL = M.getDataLayout();
IRBuilder<> IRB(M.getContext());
@@ -198,13 +199,20 @@ bool EfficiencySanitizer::shouldIgnoreMe
return false;
}
-bool EfficiencySanitizer::runOnFunction(Function &F) {
+bool EfficiencySanitizer::runOnModule(Module &M) {
+ bool Res = initOnModule(M);
+ initializeCallbacks(M);
+ for (auto &F : M) {
+ Res |= runOnFunction(F, M);
+ }
+ return Res;
+}
+
+bool EfficiencySanitizer::runOnFunction(Function &F, Module &M) {
// This is required to prevent instrumenting the call to __esan_init from
// within the module constructor.
if (&F == EsanCtorFunction)
return false;
- // As a function pass, we must re-initialize every time.
- initializeCallbacks(*F.getParent());
SmallVector<Instruction *, 8> LoadsAndStores;
SmallVector<Instruction *, 8> MemIntrinCalls;
bool Res = false;
More information about the llvm-commits
mailing list