1 //===- StandardInstrumentations.h ------------------------------*- C++ -*--===//
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
7 //===----------------------------------------------------------------------===//
10 /// This header defines a class that provides bookkeeping for all standard
11 /// (i.e in-tree) pass instrumentations.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_PASSES_STANDARDINSTRUMENTATIONS_H
16 #define LLVM_PASSES_STANDARDINSTRUMENTATIONS_H
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/IR/PassInstrumentation.h"
20 #include "llvm/IR/PassTimingInfo.h"
29 /// Instrumentation to print IR before/after passes.
31 /// Needs state to be able to print module after pass that invalidates IR unit
32 /// (typically Loop or SCC).
33 class PrintIRInstrumentation
{
35 PrintIRInstrumentation() = default;
36 ~PrintIRInstrumentation();
38 void registerCallbacks(PassInstrumentationCallbacks
&PIC
);
41 bool printBeforePass(StringRef PassID
, Any IR
);
42 void printAfterPass(StringRef PassID
, Any IR
);
43 void printAfterPassInvalidated(StringRef PassID
);
45 using PrintModuleDesc
= std::tuple
<const Module
*, std::string
, StringRef
>;
47 void pushModuleDesc(StringRef PassID
, Any IR
);
48 PrintModuleDesc
popModuleDesc(StringRef PassID
);
50 /// Stack of Module description, enough to print the module after a given
52 SmallVector
<PrintModuleDesc
, 2> ModuleDescStack
;
53 bool StoreModuleDesc
= false;
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
;
63 StandardInstrumentations() = default;
65 void registerCallbacks(PassInstrumentationCallbacks
&PIC
);
67 TimePassesHandler
&getTimePasses() { return TimePasses
; }