IRPrintingPasses.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #ifndef LLVM_IR_IRPRINTINGPASSES_H
  18. #define LLVM_IR_IRPRINTINGPASSES_H
  19. #include "llvm/IR/PassManager.h"
  20. #include <string>
  21. namespace llvm {
  22. class raw_ostream;
  23. class StringRef;
  24. /// Create and return a pass that writes the module to the specified
  25. /// \c raw_ostream.
  26. ModulePass *createPrintModulePass(raw_ostream &OS,
  27. const std::string &Banner = "",
  28. bool ShouldPreserveUseListOrder = false);
  29. /// Create and return a pass that prints functions to the specified
  30. /// \c raw_ostream as they are processed.
  31. FunctionPass *createPrintFunctionPass(raw_ostream &OS,
  32. const std::string &Banner = "");
  33. /// Print out a name of an LLVM value without any prefixes.
  34. ///
  35. /// The name is surrounded with ""'s and escaped if it has any special or
  36. /// non-printable characters in it.
  37. void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name);
  38. /// Return true if a pass is for IR printing.
  39. bool isIRPrintingPass(Pass *P);
  40. /// Pass for printing a Module as LLVM's text IR assembly.
  41. ///
  42. /// Note: This pass is for use with the new pass manager. Use the create...Pass
  43. /// functions above to create passes for use with the legacy pass manager.
  44. class PrintModulePass : public PassInfoMixin<PrintModulePass> {
  45. raw_ostream &OS;
  46. std::string Banner;
  47. bool ShouldPreserveUseListOrder;
  48. public:
  49. PrintModulePass();
  50. PrintModulePass(raw_ostream &OS, const std::string &Banner = "",
  51. bool ShouldPreserveUseListOrder = false);
  52. PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
  53. static bool isRequired() { return true; }
  54. };
  55. /// Pass for printing a Function as LLVM's text IR assembly.
  56. ///
  57. /// Note: This pass is for use with the new pass manager. Use the create...Pass
  58. /// functions above to create passes for use with the legacy pass manager.
  59. class PrintFunctionPass : public PassInfoMixin<PrintFunctionPass> {
  60. raw_ostream &OS;
  61. std::string Banner;
  62. public:
  63. PrintFunctionPass();
  64. PrintFunctionPass(raw_ostream &OS, const std::string &Banner = "");
  65. PreservedAnalyses run(Function &F, AnalysisManager<Function> &);
  66. static bool isRequired() { return true; }
  67. };
  68. } // namespace llvm
  69. #endif