PrintPasses.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- PrintPasses.h - Determining whether/when to print IR ---------------===//
  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. #ifndef LLVM_IR_PRINTPASSES_H
  14. #define LLVM_IR_PRINTPASSES_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/Support/CommandLine.h"
  17. #include <vector>
  18. namespace llvm {
  19. enum class ChangePrinter {
  20. None,
  21. Verbose,
  22. Quiet,
  23. DiffVerbose,
  24. DiffQuiet,
  25. ColourDiffVerbose,
  26. ColourDiffQuiet,
  27. DotCfgVerbose,
  28. DotCfgQuiet
  29. };
  30. extern cl::opt<ChangePrinter> PrintChanged;
  31. // Returns true if printing before/after some pass is enabled, whether all
  32. // passes or a specific pass.
  33. bool shouldPrintBeforeSomePass();
  34. bool shouldPrintAfterSomePass();
  35. // Returns true if we should print before/after a specific pass. The argument
  36. // should be the pass ID, e.g. "instcombine".
  37. bool shouldPrintBeforePass(StringRef PassID);
  38. bool shouldPrintAfterPass(StringRef PassID);
  39. // Returns true if we should print before/after all passes.
  40. bool shouldPrintBeforeAll();
  41. bool shouldPrintAfterAll();
  42. // The list of passes to print before/after, if we only want to print
  43. // before/after specific passes.
  44. std::vector<std::string> printBeforePasses();
  45. std::vector<std::string> printAfterPasses();
  46. // Returns true if we should always print the entire module.
  47. bool forcePrintModuleIR();
  48. // Return true if -filter-passes is empty or contains the pass name.
  49. bool isPassInPrintList(StringRef PassName);
  50. bool isFilterPassesEmpty();
  51. // Returns true if we should print the function.
  52. bool isFunctionInPrintList(StringRef FunctionName);
  53. // Ensure temporary files exist, creating or re-using them. \p FD contains
  54. // file descriptors (-1 indicates that the file should be created) and
  55. // \p SR contains the corresponding initial content. \p FileName will have
  56. // the filenames filled in when creating files. Return first error code (if
  57. // any) and stop.
  58. std::error_code prepareTempFiles(SmallVector<int> &FD, ArrayRef<StringRef> SR,
  59. SmallVector<std::string> &FileName);
  60. // Remove the temporary files in \p FileName. Typically used in conjunction
  61. // with prepareTempFiles. Return first error code (if any) and stop..
  62. std::error_code cleanUpTempFiles(ArrayRef<std::string> FileName);
  63. // Perform a system based diff between \p Before and \p After, using \p
  64. // OldLineFormat, \p NewLineFormat, and \p UnchangedLineFormat to control the
  65. // formatting of the output. Return an error message for any failures instead
  66. // of the diff.
  67. std::string doSystemDiff(StringRef Before, StringRef After,
  68. StringRef OldLineFormat, StringRef NewLineFormat,
  69. StringRef UnchangedLineFormat);
  70. } // namespace llvm
  71. #endif // LLVM_IR_PRINTPASSES_H
  72. #ifdef __GNUC__
  73. #pragma GCC diagnostic pop
  74. #endif