| 1 | //===- IRPrintingPasses.h - Passes to print out IR constructs ---*- 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 file defines passes to print out IR in various granularities. The |
| 11 | /// PrintModulePass pass simply prints out the entire module when it is |
| 12 | /// executed. The PrintFunctionPass class is designed to be pipelined with |
| 13 | /// other FunctionPass's, and prints out the functions of the module as they |
| 14 | /// are processed. |
| 15 | /// |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | #ifndef LLVM_IR_IRPRINTINGPASSES_H |
| 19 | #define LLVM_IR_IRPRINTINGPASSES_H |
| 20 | |
| 21 | #include "llvm/IR/PassManager.h" |
| 22 | #include <string> |
| 23 | |
| 24 | namespace llvm { |
| 25 | class raw_ostream; |
| 26 | class StringRef; |
| 27 | class Function; |
| 28 | class FunctionPass; |
| 29 | class Module; |
| 30 | class ModulePass; |
| 31 | class Pass; |
| 32 | |
| 33 | /// Create and return a pass that writes the module to the specified |
| 34 | /// \c raw_ostream. |
| 35 | ModulePass *createPrintModulePass(raw_ostream &OS, |
| 36 | const std::string &Banner = "", |
| 37 | bool ShouldPreserveUseListOrder = false); |
| 38 | |
| 39 | /// Create and return a pass that prints functions to the specified |
| 40 | /// \c raw_ostream as they are processed. |
| 41 | FunctionPass *createPrintFunctionPass(raw_ostream &OS, |
| 42 | const std::string &Banner = ""); |
| 43 | |
| 44 | /// Print out a name of an LLVM value without any prefixes. |
| 45 | /// |
| 46 | /// The name is surrounded with ""'s and escaped if it has any special or |
| 47 | /// non-printable characters in it. |
| 48 | void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name); |
| 49 | |
| 50 | /// Return true if a pass is for IR printing. |
| 51 | bool isIRPrintingPass(Pass *P); |
| 52 | |
| 53 | /// Pass for printing a Module as LLVM's text IR assembly. |
| 54 | /// |
| 55 | /// Note: This pass is for use with the new pass manager. Use the create...Pass |
| 56 | /// functions above to create passes for use with the legacy pass manager. |
| 57 | class PrintModulePass : public PassInfoMixin<PrintModulePass> { |
| 58 | raw_ostream &OS; |
| 59 | std::string Banner; |
| 60 | bool ShouldPreserveUseListOrder; |
| 61 | |
| 62 | public: |
| 63 | PrintModulePass(); |
| 64 | PrintModulePass(raw_ostream &OS, const std::string &Banner = "", |
| 65 | bool ShouldPreserveUseListOrder = false); |
| 66 | |
| 67 | PreservedAnalyses run(Module &M, AnalysisManager<Module> &); |
| 68 | static bool isRequired() { return true; } |
| 69 | }; |
| 70 | |
| 71 | /// Pass for printing a Function as LLVM's text IR assembly. |
| 72 | /// |
| 73 | /// Note: This pass is for use with the new pass manager. Use the create...Pass |
| 74 | /// functions above to create passes for use with the legacy pass manager. |
| 75 | class PrintFunctionPass : public PassInfoMixin<PrintFunctionPass> { |
| 76 | raw_ostream &OS; |
| 77 | std::string Banner; |
| 78 | |
| 79 | public: |
| 80 | PrintFunctionPass(); |
| 81 | PrintFunctionPass(raw_ostream &OS, const std::string &Banner = ""); |
| 82 | |
| 83 | PreservedAnalyses run(Function &F, AnalysisManager<Function> &); |
| 84 | static bool isRequired() { return true; } |
| 85 | }; |
| 86 | |
| 87 | } // namespace llvm |
| 88 | |
| 89 | #endif |