1 //===- StandardInstrumentations.h ------------------------------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This header defines a class that provides bookkeeping for all standard
12 /// (i.e in-tree) pass instrumentations.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_PASSES_STANDARDINSTRUMENTATIONS_H
17 #define LLVM_PASSES_STANDARDINSTRUMENTATIONS_H
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/IR/PassInstrumentation.h"
21 #include "llvm/IR/PassTimingInfo.h"
30 /// Instrumentation to print IR before/after passes.
32 /// Needs state to be able to print module after pass that invalidates IR unit
33 /// (typically Loop or SCC).
34 class PrintIRInstrumentation {
36 PrintIRInstrumentation() = default;
37 ~PrintIRInstrumentation();
39 void registerCallbacks(PassInstrumentationCallbacks &PIC);
42 bool printBeforePass(StringRef PassID, Any IR);
43 void printAfterPass(StringRef PassID, Any IR);
44 void printAfterPassInvalidated(StringRef PassID);
46 using PrintModuleDesc = std::tuple<const Module *, std::string, StringRef>;
48 void pushModuleDesc(StringRef PassID, Any IR);
49 PrintModuleDesc popModuleDesc(StringRef PassID);
51 /// Stack of Module description, enough to print the module after a given
53 SmallVector<PrintModuleDesc, 2> ModuleDescStack;
54 bool StoreModuleDesc = false;
57 /// This class provides an interface to register all the standard pass
58 /// instrumentations and manages their state (if any).
59 class StandardInstrumentations {
60 PrintIRInstrumentation PrintIR;
61 TimePassesHandler TimePasses;
64 StandardInstrumentations() = default;
66 void registerCallbacks(PassInstrumentationCallbacks &PIC);