LLVM: lib/IR/PrintPasses.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

15#include <unordered_set>

16

17using namespace llvm;

18

19

24

28

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

64 clEnumValN(ChangePrinter::Quiet, "quiet", "Run in quiet mode"),

65 clEnumValN(ChangePrinter::DiffVerbose, "diff",

66 "Display patch-like changes"),

67 clEnumValN(ChangePrinter::DiffQuiet, "diff-quiet",

68 "Display patch-like changes in quiet mode"),

69 clEnumValN(ChangePrinter::ColourDiffVerbose, "cdiff",

70 "Display patch-like changes with color"),

71 clEnumValN(ChangePrinter::ColourDiffQuiet, "cdiff-quiet",

72 "Display patch-like changes in quiet mode with color"),

73 clEnumValN(ChangePrinter::DotCfgVerbose, "dot-cfg",

74 "Create a website with graphical changes"),

75 clEnumValN(ChangePrinter::DotCfgQuiet, "dot-cfg-quiet",

76 "Create a website with graphical changes in quiet mode"),

77

78 clEnumValN(ChangePrinter::Verbose, "", "")));

79

80

83 cl::desc("system diff used by change reporters"));

84

87 cl::desc("When printing IR for print-[before|after]{-all} "

88 "always print a module IR"),

90

92 "print-loop-func-scope",

93 cl::desc("When printing IR for print-[before|after]{-all} "

94 "for a loop pass, always print function IR"),

96

97

98

101 cl::desc("Only consider IR changes for passes whose names "

102 "match the specified value. No-op without -print-changed"),

104

107 cl::desc("Only print IR for functions whose name "

108 "match this for all print-[before|after][-all] "

109 "options"),

111

112

113

114

117}

118

121}

122

126}

127

129

131

134}

135

138}

139

141 return std::vectorstd::string(PrintBefore);

142}

143

145 return std::vectorstd::string(PrintAfter);

146}

147

149

151

153 static std::unordered_setstd::string Set(FilterPasses.begin(),

155 return Set.empty() || Set.count(std::string(PassName));

156}

157

159

161 static std::unordered_setstd::string PrintFuncNames(PrintFuncsList.begin(),

163 return PrintFuncNames.empty() ||

164 PrintFuncNames.count(std::string(FunctionName));

165}

166

168 unsigned N) {

169 std::error_code RC;

170 for (unsigned I = 0; I < N; ++I) {

172 if (EC)

173 RC = EC;

174 }

175 return RC;

176}

177

182 "Unexpected array sizes");

183 std::error_code EC;

184 unsigned I = 0;

185 for (; I < FD.size(); ++I) {

186 if (FD[I] == -1) {

189 if (EC)

190 break;

192 }

193 if (I < SR.size()) {

195 if (EC)

196 break;

198 if (FD[I] == -1) {

200 break;

201 }

202 OutStream << SR[I];

203 }

204 }

205 if (EC && I > 0)

206

208 return EC;

209}

210

213}

214

218

219

224 return "Unable to create temporary file.";

225

227 if (!DiffExe)

228 return "Unable to find diff executable.";

229

231 ("--old-line-format=" + OldLineFormat).toVector(OLF);

232 ("--new-line-format=" + NewLineFormat).toVector(NLF);

233 ("--unchanged-line-format=" + UnchangedLineFormat).toVector(ULF);

234

236 NLF, ULF, FileName[0], FileName[1]};

237 std::optional Redirects[] = {std::nullopt, StringRef(FileName[2]),

238 std::nullopt};

239 int Result = sys::ExecuteAndWait(*DiffExe, Args, std::nullopt, Redirects);

240 if (Result < 0)

241 return "Error executing system diff.";

242 std::string Diff;

244 if (B && *B)

245 Diff = (*B)->getBuffer().str();

246 else

247 return "Unable to read result.";

248

250 return "Unable to remove temporary file.";

251

252 return Diff;

253}

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

#define clEnumValN(ENUMVAL, FLAGNAME, DESC)

static bool shouldPrintBeforeOrAfterPass(StringRef PassID, ArrayRef< std::string > PassesToPrint)

static cl::opt< bool > PrintBeforeAll("print-before-all", llvm:🆑:desc("Print IR before each pass"), cl::init(false), cl::Hidden)

static cl::opt< bool > PrintModuleScope("print-module-scope", cl::desc("When printing IR for print-[before|after]{-all} " "always print a module IR"), cl::init(false), cl::Hidden)

static cl::list< std::string > PrintBefore("print-before", llvm:🆑:desc("Print IR before specified passes"), cl::CommaSeparated, cl::Hidden)

static cl::list< std::string > FilterPasses("filter-passes", cl::value_desc("pass names"), cl::desc("Only consider IR changes for passes whose names " "match the specified value. No-op without -print-changed"), cl::CommaSeparated, cl::Hidden)

static cl::list< std::string > PrintAfter("print-after", llvm:🆑:desc("Print IR after specified passes"), cl::CommaSeparated, cl::Hidden)

static cl::opt< bool > LoopPrintFuncScope("print-loop-func-scope", cl::desc("When printing IR for print-[before|after]{-all} " "for a loop pass, always print function IR"), cl::init(false), cl::Hidden)

static cl::opt< bool > PrintAfterAll("print-after-all", llvm:🆑:desc("Print IR after each pass"), cl::init(false), cl::Hidden)

static cl::opt< std::string > DiffBinary("print-changed-diff-path", cl::Hidden, cl::init("diff"), cl::desc("system diff used by change reporters"))

std::error_code cleanUpTempFilesImpl(ArrayRef< std::string > FileName, unsigned N)

static cl::list< std::string > PrintFuncsList("filter-print-funcs", cl::value_desc("function names"), cl::desc("Only print IR for functions whose name " "match this for all print-[before|after][-all] " "options"), cl::CommaSeparated, cl::Hidden)

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

static const char PassName[]

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

size_t size() const

size - Get the array size.

Represents either an error or a value T.

static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)

Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

std::string str() const

Return the twine contents as a std::string.

A raw_ostream that writes to a file descriptor.

ValuesClass values(OptsTy... Options)

Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...

initializer< Ty > init(const Ty &Val)

std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)

Remove path.

std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)

Opens the file with the given name in a write-only or read-write mode, returning its open file descri...

std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None)

Create a file in the system temporary directory.

int ExecuteAndWait(StringRef Program, ArrayRef< StringRef > Args, std::optional< ArrayRef< StringRef > > Env=std::nullopt, ArrayRef< std::optional< StringRef > > Redirects={}, unsigned SecondsToWait=0, unsigned MemoryLimit=0, std::string *ErrMsg=nullptr, bool *ExecutionFailed=nullptr, std::optional< ProcessStatistics > *ProcStat=nullptr, BitVector *AffinityMask=nullptr)

This function executes the program using the arguments provided.

ErrorOr< std::string > findProgramByName(StringRef Name, ArrayRef< StringRef > Paths={})

Find the first executable file Name in Paths.

This is an optimization pass for GlobalISel generic memory operations.

std::error_code prepareTempFiles(SmallVector< int > &FD, ArrayRef< StringRef > SR, SmallVector< std::string > &FileName)

bool forcePrintModuleIR()

std::error_code make_error_code(BitcodeError E)

std::vector< std::string > printAfterPasses()

bool shouldPrintBeforeAll()

bool shouldPrintAfterAll()

cl::opt< ChangePrinter > PrintChanged

std::vector< std::string > printBeforePasses()

bool shouldPrintBeforeSomePass()

This is a helper to determine whether to print IR before or after a pass.

bool shouldPrintAfterSomePass()

bool isFunctionInPrintList(StringRef FunctionName)

bool isPassInPrintList(StringRef PassName)

std::error_code cleanUpTempFiles(ArrayRef< std::string > FileName)

std::string doSystemDiff(StringRef Before, StringRef After, StringRef OldLineFormat, StringRef NewLineFormat, StringRef UnchangedLineFormat)

bool is_contained(R &&Range, const E &Element)

Returns true if Element is found in Range.

bool shouldPrintBeforePass(StringRef PassID)

bool shouldPrintAfterPass(StringRef PassID)

bool isFilterPassesEmpty()