]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Passes/StandardInstrumentations.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Passes / StandardInstrumentations.h
1 //===- StandardInstrumentations.h ------------------------------*- C++ -*--===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 ///
11 /// This header defines a class that provides bookkeeping for all standard
12 /// (i.e in-tree) pass instrumentations.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_PASSES_STANDARDINSTRUMENTATIONS_H
17 #define LLVM_PASSES_STANDARDINSTRUMENTATIONS_H
18
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/IR/PassInstrumentation.h"
21 #include "llvm/IR/PassTimingInfo.h"
22
23 #include <string>
24 #include <utility>
25
26 namespace llvm {
27
28 class Module;
29
30 /// Instrumentation to print IR before/after passes.
31 ///
32 /// Needs state to be able to print module after pass that invalidates IR unit
33 /// (typically Loop or SCC).
34 class PrintIRInstrumentation {
35 public:
36   PrintIRInstrumentation() = default;
37   ~PrintIRInstrumentation();
38
39   void registerCallbacks(PassInstrumentationCallbacks &PIC);
40
41 private:
42   bool printBeforePass(StringRef PassID, Any IR);
43   void printAfterPass(StringRef PassID, Any IR);
44   void printAfterPassInvalidated(StringRef PassID);
45
46   using PrintModuleDesc = std::tuple<const Module *, std::string, StringRef>;
47
48   void pushModuleDesc(StringRef PassID, Any IR);
49   PrintModuleDesc popModuleDesc(StringRef PassID);
50
51   /// Stack of Module description, enough to print the module after a given
52   /// pass.
53   SmallVector<PrintModuleDesc, 2> ModuleDescStack;
54   bool StoreModuleDesc = false;
55 };
56
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;
62
63 public:
64   StandardInstrumentations() = default;
65
66   void registerCallbacks(PassInstrumentationCallbacks &PIC);
67 };
68 } // namespace llvm
69
70 #endif