IRPrintingPasses.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- IRPrintingPasses.h - Passes to print out IR constructs ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. /// \file
  14. ///
  15. /// This file defines passes to print out IR in various granularities. The
  16. /// PrintModulePass pass simply prints out the entire module when it is
  17. /// executed. The PrintFunctionPass class is designed to be pipelined with
  18. /// other FunctionPass's, and prints out the functions of the module as they
  19. /// are processed.
  20. ///
  21. //===----------------------------------------------------------------------===//
  22. #ifndef LLVM_IR_IRPRINTINGPASSES_H
  23. #define LLVM_IR_IRPRINTINGPASSES_H
  24. #include "llvm/IR/PassManager.h"
  25. #include <string>
  26. namespace llvm {
  27. class raw_ostream;
  28. class StringRef;
  29. class Function;
  30. class FunctionPass;
  31. class Module;
  32. class ModulePass;
  33. class Pass;
  34. /// Create and return a pass that writes the module to the specified
  35. /// \c raw_ostream.
  36. ModulePass *createPrintModulePass(raw_ostream &OS,
  37. const std::string &Banner = "",
  38. bool ShouldPreserveUseListOrder = false);
  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. /// Print out a name of an LLVM value without any prefixes.
  44. ///
  45. /// The name is surrounded with ""'s and escaped if it has any special or
  46. /// non-printable characters in it.
  47. void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name);
  48. /// Return true if a pass is for IR printing.
  49. bool isIRPrintingPass(Pass *P);
  50. /// Pass for printing a Module as LLVM's text IR assembly.
  51. ///
  52. /// Note: This pass is for use with the new pass manager. Use the create...Pass
  53. /// functions above to create passes for use with the legacy pass manager.
  54. class PrintModulePass : public PassInfoMixin<PrintModulePass> {
  55. raw_ostream &OS;
  56. std::string Banner;
  57. bool ShouldPreserveUseListOrder;
  58. public:
  59. PrintModulePass();
  60. PrintModulePass(raw_ostream &OS, const std::string &Banner = "",
  61. bool ShouldPreserveUseListOrder = false);
  62. PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
  63. static bool isRequired() { return true; }
  64. };
  65. /// Pass for printing a Function as LLVM's text IR assembly.
  66. ///
  67. /// Note: This pass is for use with the new pass manager. Use the create...Pass
  68. /// functions above to create passes for use with the legacy pass manager.
  69. class PrintFunctionPass : public PassInfoMixin<PrintFunctionPass> {
  70. raw_ostream &OS;
  71. std::string Banner;
  72. public:
  73. PrintFunctionPass();
  74. PrintFunctionPass(raw_ostream &OS, const std::string &Banner = "");
  75. PreservedAnalyses run(Function &F, AnalysisManager<Function> &);
  76. static bool isRequired() { return true; }
  77. };
  78. } // namespace llvm
  79. #endif
  80. #ifdef __GNUC__
  81. #pragma GCC diagnostic pop
  82. #endif