diff options
| author | River Riddle <riverriddle@google.com> | 2019-03-18 11:56:18 -0700 |
|---|---|---|
| committer | jpienaar <jpienaar@google.com> | 2019-03-29 17:23:53 -0700 |
| commit | 6e983ae8df4a35723e7994bf74bd9b7bb1e5df25 (patch) | |
| tree | cc814718667cd6c2ef5ecb550583c82789626d3a /mlir/lib | |
| parent | 81d25bb894d8ce0e1c245e7296bd994199e79e4e (diff) | |
| download | bcm5719-llvm-6e983ae8df4a35723e7994bf74bd9b7bb1e5df25.tar.gz bcm5719-llvm-6e983ae8df4a35723e7994bf74bd9b7bb1e5df25.zip | |
Give PassInstrumentor a SmartMutex to lock access to the held instrumentations.
PiperOrigin-RevId: 239031524
Diffstat (limited to 'mlir/lib')
| -rw-r--r-- | mlir/lib/Pass/Pass.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp index 4d75c45229b..1420f4a83d6 100644 --- a/mlir/lib/Pass/Pass.cpp +++ b/mlir/lib/Pass/Pass.cpp @@ -23,6 +23,7 @@ #include "PassDetail.h" #include "mlir/IR/Module.h" #include "mlir/Pass/PassManager.h" +#include "llvm/Support/Mutex.h" using namespace mlir; using namespace mlir::detail; @@ -279,3 +280,66 @@ void ModuleAnalysisManager::invalidate(const detail::PreservedAnalyses &pa) { //===----------------------------------------------------------------------===// PassInstrumentation::~PassInstrumentation() {} + +//===----------------------------------------------------------------------===// +// PassInstrumentor +//===----------------------------------------------------------------------===// + +namespace mlir { +namespace detail { +struct PassInstrumentorImpl { + /// Mutex to keep instrumentation access thread-safe. + llvm::sys::SmartMutex<true> mutex; + + /// Set of registered instrumentations. + std::vector<std::unique_ptr<PassInstrumentation>> instrumentations; +}; +} // end namespace detail +} // end namespace mlir + +PassInstrumentor::PassInstrumentor() : impl(new PassInstrumentorImpl()) {} +PassInstrumentor::~PassInstrumentor() {} + +/// See PassInstrumentation::runBeforePass for details. +void PassInstrumentor::runBeforePass(Pass *pass, const llvm::Any &ir) { + llvm::sys::SmartScopedLock<true> instrumentationLock(impl->mutex); + for (auto &instr : impl->instrumentations) + instr->runBeforePass(pass, ir); +} + +/// See PassInstrumentation::runAfterPass for details. +void PassInstrumentor::runAfterPass(Pass *pass, const llvm::Any &ir) { + llvm::sys::SmartScopedLock<true> instrumentationLock(impl->mutex); + for (auto &instr : llvm::reverse(impl->instrumentations)) + instr->runAfterPass(pass, ir); +} + +/// See PassInstrumentation::runAfterPassFailed for details. +void PassInstrumentor::runAfterPassFailed(Pass *pass, const llvm::Any &ir) { + llvm::sys::SmartScopedLock<true> instrumentationLock(impl->mutex); + for (auto &instr : llvm::reverse(impl->instrumentations)) + instr->runAfterPassFailed(pass, ir); +} + +/// See PassInstrumentation::runBeforeAnalysis for details. +void PassInstrumentor::runBeforeAnalysis(llvm::StringRef name, AnalysisID *id, + const llvm::Any &ir) { + llvm::sys::SmartScopedLock<true> instrumentationLock(impl->mutex); + for (auto &instr : impl->instrumentations) + instr->runBeforeAnalysis(name, id, ir); +} + +/// See PassInstrumentation::runAfterAnalysis for details. +void PassInstrumentor::runAfterAnalysis(llvm::StringRef name, AnalysisID *id, + const llvm::Any &ir) { + llvm::sys::SmartScopedLock<true> instrumentationLock(impl->mutex); + for (auto &instr : llvm::reverse(impl->instrumentations)) + instr->runAfterAnalysis(name, id, ir); +} + +/// Add the given instrumentation to the collection. This takes ownership over +/// the given pointer. +void PassInstrumentor::addInstrumentation(PassInstrumentation *pi) { + llvm::sys::SmartScopedLock<true> instrumentationLock(impl->mutex); + impl->instrumentations.emplace_back(pi); +} |

