]> 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 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This header defines a class that provides bookkeeping for all standard
11 /// (i.e in-tree) pass instrumentations.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_PASSES_STANDARDINSTRUMENTATIONS_H
16 #define LLVM_PASSES_STANDARDINSTRUMENTATIONS_H
17
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/IR/PassInstrumentation.h"
20 #include "llvm/IR/PassTimingInfo.h"
21
22 #include <string>
23 #include <utility>
24
25 namespace llvm {
26
27 class Module;
28
29 /// Instrumentation to print IR before/after passes.
30 ///
31 /// Needs state to be able to print module after pass that invalidates IR unit
32 /// (typically Loop or SCC).
33 class PrintIRInstrumentation {
34 public:
35   PrintIRInstrumentation() = default;
36   ~PrintIRInstrumentation();
37
38   void registerCallbacks(PassInstrumentationCallbacks &PIC);
39
40 private:
41   bool printBeforePass(StringRef PassID, Any IR);
42   void printAfterPass(StringRef PassID, Any IR);
43   void printAfterPassInvalidated(StringRef PassID);
44
45   using PrintModuleDesc = std::tuple<const Module *, std::string, StringRef>;
46
47   void pushModuleDesc(StringRef PassID, Any IR);
48   PrintModuleDesc popModuleDesc(StringRef PassID);
49
50   /// Stack of Module description, enough to print the module after a given
51   /// pass.
52   SmallVector<PrintModuleDesc, 2> ModuleDescStack;
53   bool StoreModuleDesc = false;
54 };
55
56 /// This class provides an interface to register all the standard pass
57 /// instrumentations and manages their state (if any).
58 class StandardInstrumentations {
59   PrintIRInstrumentation PrintIR;
60   TimePassesHandler TimePasses;
61
62 public:
63   StandardInstrumentations() = default;
64
65   void registerCallbacks(PassInstrumentationCallbacks &PIC);
66
67   TimePassesHandler &getTimePasses() { return TimePasses; }
68 };
69 } // namespace llvm
70
71 #endif