Index: include/llvm/Passes/StandardInstrumentations.h =================================================================== --- /dev/null +++ include/llvm/Passes/StandardInstrumentations.h @@ -0,0 +1,36 @@ +//===- StandardInstrumentations.h ------------------------------*- C++ -*--===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// \file +/// +/// This header defines a class that provides bookkeeping for all standard +/// (i.e in-tree) pass instrumentations. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_PASSES_STANDARDINSTRUMENTATIONS_H +#define LLVM_PASSES_STANDARDINSTRUMENTATIONS_H + +#include "llvm/IR/PassInstrumentation.h" +#include "llvm/IR/PassTimingInfo.h" + +namespace llvm { + + /// This class provides an interface to register all the standard pass + /// instrumentations and manages their state (if any). + class StandardInstrumentations { + TimePassesHandler TimePasses; + + public: + StandardInstrumentations() = default; + + void registerCallbacks(PassInstrumentationCallbacks& PIC); + }; +} + +#endif Index: lib/Passes/CMakeLists.txt =================================================================== --- lib/Passes/CMakeLists.txt +++ lib/Passes/CMakeLists.txt @@ -1,6 +1,7 @@ add_llvm_library(LLVMPasses PassBuilder.cpp PassPlugin.cpp + StandardInstrumentations.cpp ADDITIONAL_HEADER_DIRS ${LLVM_MAIN_INCLUDE_DIR}/llvm/Passes Index: lib/Passes/StandardInstrumentations.cpp =================================================================== --- /dev/null +++ lib/Passes/StandardInstrumentations.cpp @@ -0,0 +1,29 @@ +//===- Bookkeeping for standard pass instrumentations ----------*- C++ -*--===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// \file +/// +/// This file defines StandardInstrumentations class that manages standard +/// pass instrumentations defined in-tree. +/// +//===----------------------------------------------------------------------===// + +#include "llvm/Passes/StandardInstrumentations.h" +#include "llvm/Analysis/PrintIR.h" +#include "llvm/IR/PassTimingInfo.h" +#include "llvm/IR/IRPrintingPasses.h" + +using namespace llvm; + +void StandardInstrumentations::registerCallbacks(PassInstrumentationCallbacks& PIC) { + if (llvm::shouldPrintBeforePass()) + PIC.registerBeforePassCallback(PrintIR::printBeforePass); + if (llvm::shouldPrintAfterPass()) + PIC.registerAfterPassCallback(PrintIR::printAfterPass); + TimePasses.registerCallbacks(PIC); +} Index: tools/opt/NewPMDriver.cpp =================================================================== --- tools/opt/NewPMDriver.cpp +++ tools/opt/NewPMDriver.cpp @@ -19,7 +19,6 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CGSCCPassManager.h" -#include "llvm/Analysis/PrintIR.h" #include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/Config/llvm-config.h" #include "llvm/IR/Dominators.h" @@ -30,6 +29,7 @@ #include "llvm/IR/Verifier.h" #include "llvm/Passes/PassBuilder.h" #include "llvm/Passes/PassPlugin.h" +#include "llvm/Passes/StandardInstrumentations.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ToolOutputFile.h" @@ -215,16 +215,11 @@ P = None; } PassInstrumentationCallbacks PIC; - if (llvm::shouldPrintBeforePass()) - PIC.registerBeforePassCallback(PrintIR::printBeforePass); - if (llvm::shouldPrintAfterPass()) - PIC.registerAfterPassCallback(PrintIR::printAfterPass); - TimePassesHandler TimePasses; - TimePasses.registerCallbacks(PIC); + StandardInstrumentations SI; + SI.registerCallbacks(PIC); PassBuilder PB(TM, P, &PIC); registerEPCallbacks(PB, VerifyEachPass, DebugPM); - PB.registerDefaultInstrumentations(); // Load requested pass plugins and let them register pass builder callbacks for (auto &PluginFN : PassPlugins) {