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