81 "Display patch-like changes"),
83 "Display patch-like changes in quiet mode"),
85 "Display patch-like changes with color"),
87 "Display patch-like changes in quiet mode with color"),
89 "Create a website with graphical changes"),
91 "Create a website with graphical changes in quiet mode"),
98 cl::desc(
"system diff used by change reporters"));
102 cl::desc(
"When printing IR for print-[before|after]{-all} "
103 "always print a module IR"),
107 "print-loop-func-scope",
108 cl::desc(
"When printing IR for print-[before|after]{-all} "
109 "for a loop pass, always print function IR"),
116 cl::desc(
"Only consider IR changes for passes whose names "
117 "match the specified value. No-op without -print-changed"),
122 cl::desc(
"Only print IR for functions whose name "
123 "match this for all print-[before|after][-all] "
128 "filter-print-source-locs",
cl::value_desc(
"file:line[,line-line][,line]"),
173 return Set.empty() || Set.contains(
PassName);
180 return PrintFuncNames.
empty() || PrintFuncNames.
contains(FunctionName) ||
186struct PrintLineRange {
191struct PrintSourceLocFilter {
198 Filter +
"'. Expected file:line[,line-line][,line].");
201std::string normalizeSlashes(
StringRef Path) {
205bool parseLineNumber(
StringRef LineText,
unsigned &Line) {
210 auto [FirstText, LastText] = RangeText.
split(
'-');
213 if (!parseLineNumber(FirstText,
First))
214 reportBadSourceLocFilter(FullFilter);
221 reportBadSourceLocFilter(FullFilter);
226std::vector<PrintSourceLocFilter> parseSourceLocFilters() {
227 std::vector<PrintSourceLocFilter>
Result;
231 if (
File.empty() || LineList.empty())
232 reportBadSourceLocFilter(
Filter);
234 PrintSourceLocFilter Parsed;
235 Parsed.File = normalizeSlashes(File);
237 Parsed.Lines.push_back(parseLineRange(RangeText,
Filter));
239 Result.push_back(std::move(Parsed));
245 static const std::vector<PrintSourceLocFilter> Filters =
246 parseSourceLocFilters();
251 std::string NormalizedFilename = normalizeSlashes(
Filename);
253 return NormalizedFilename;
255 std::string NormalizedDirectory = normalizeSlashes(Directory);
256 if (NormalizedDirectory.empty())
257 return NormalizedFilename;
258 if (NormalizedDirectory.back() ==
'/')
259 return NormalizedDirectory + NormalizedFilename;
260 return NormalizedDirectory +
"/" + NormalizedFilename;
265 std::string LocFile = normalizeSlashes(
Filename);
266 std::string LocPath = makeDebugLocPath(Directory,
Filename);
270 if (FilterFile == LocFile || FilterFile == LocPath)
278 std::string Suffix = (
Twine(
"/") + FilterFile).str();
279 return LocFileRef.ends_with(Suffix) || LocPathRef.ends_with(Suffix);
283 return any_of(Ranges, [Line](
const PrintLineRange &
Range) {
284 return Range.First <= Line && Line <=
Range.Last;
289 const PrintSourceLocFilter &
Filter) {
292 matchesFile(
Filter.File, Scope->getDirectory(),
293 Scope->getFilename()) &&
294 matchesLine(
Filter.Lines,
Loc.getLine());
304 for (
DebugLoc CurLoc =
Loc; CurLoc; CurLoc = CurLoc.getInlinedAt()) {
305 if (
any_of(Filters, [&CurLoc](
const PrintSourceLocFilter &
Filter) {
306 return matchesSourceLocFilter(CurLoc,
Filter);
324 if (SourceLocFilterEmpty)
337 for (
unsigned I = 0;
I <
N; ++
I) {
349 "Unexpected array sizes");
352 for (;
I < FD.
size(); ++
I) {
393 return "Unable to create temporary file.";
397 return "Unable to find diff executable.";
400 (
"--old-line-format=" + OldLineFormat).toVector(OLF);
401 (
"--new-line-format=" + NewLineFormat).toVector(NLF);
402 (
"--unchanged-line-format=" + UnchangedLineFormat).toVector(ULF);
405 NLF, ULF, FileName[0], FileName[1]};
406 std::optional<StringRef> Redirects[] = {std::nullopt,
StringRef(FileName[2]),
410 return "Error executing system diff.";
414 Diff = (*B)->getBuffer().str();
416 return "Unable to read result.";
419 return "Unable to remove temporary file.";
428 if (!ShouldReport && IsInteresting)
431 if (IsInteresting && Before != After) {
434 ChangePrinter::DotCfgQuiet,
435 ChangePrinter::DotCfgVerbose},
437 errs() << (
"*** IR Deleted After " +
PassName +
" (" + PassID +
") on " +
442 errs() << (
"*** IR Dump After " +
PassName +
" (" + PassID +
") on " +
460 StringRef Removed = Color ?
"\033[31m-%l\033[0m\n" :
"-%l\n";
461 StringRef Added = Color ?
"\033[32m+%l\033[0m\n" :
"+%l\n";
472 IsInteresting ?
" omitted because no change" :
" filtered out";
475 errs() <<
" (" << PassID <<
")";
476 errs() <<
" on " << IRName + Reason +
" ***\n";
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static constexpr StringLiteral Filename
static bool shouldPrintBeforeOrAfterPass(StringRef PassID, ArrayRef< std::string > PassesToPrint)
static cl::opt< bool > PrintBeforeAll("print-before-all", llvm::cl::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::cl::desc("Print IR before specified passes"), cl::CommaSeparated, cl::Hidden)
static cl::list< std::string > PrintSourceLocs("filter-print-source-locs", cl::value_desc("file:line[,line-line][,line]"), cl::desc("Only print IR containing matching source locations"), 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::cl::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::cl::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)
This file defines the SmallVector class.
StringSet - A set-like wrapper for the StringMap.
static const char PassName[]
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
LLVM Basic Block Representation.
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.
Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr bool empty() const
Check if the string is empty.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
StringSet - A wrapper for StringMap that provides set-like functionality.
bool contains(StringRef key) const
Check if the set contains the given key.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
A raw_ostream that writes to a file descriptor.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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)
LLVM_ABI 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...
LLVM_ABI 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.
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
LLVM_ABI std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
ScopedSetting scopedDisable()
LLVM_ABI ErrorOr< std::string > findProgramByName(StringRef Name, ArrayRef< StringRef > Paths={})
Find the first executable file Name in Paths.
LLVM_ABI 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.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool isSourceLocInPrintList(const DebugLoc &Loc)
LLVM_ABI std::error_code prepareTempFiles(SmallVector< int > &FD, ArrayRef< StringRef > SR, SmallVector< std::string > &FileName)
LLVM_ABI bool forcePrintModuleIR()
std::error_code make_error_code(BitcodeError E)
LLVM_ABI std::vector< std::string > printAfterPasses()
LLVM_ABI void reportChangedIR(StringRef Before, StringRef After, StringRef PassName, StringRef PassID, StringRef IRName, bool IsInteresting, bool ShouldReport)
constexpr from_range_t from_range
LLVM_ABI bool shouldPrintBeforeAll()
LLVM_ABI bool shouldPrintAfterAll()
LLVM_ABI cl::opt< ChangePrinter > PrintChanged
auto dyn_cast_or_null(const Y &Val)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI std::vector< std::string > printBeforePasses()
LLVM_ABI bool shouldPrintBeforeSomePass()
This is a helper to determine whether to print IR before or after a pass.
LLVM_ABI bool shouldPrintAfterSomePass()
LLVM_ABI bool isFunctionInPrintList(StringRef FunctionName)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI bool isPassInPrintList(StringRef PassName)
LLVM_ABI bool isSourceLocFilterEmpty()
iterator_range< SplittingIterator > split(StringRef Str, StringRef Separator)
Split the specified string over a separator and return a range-compatible iterable over its partition...
LLVM_ABI bool shouldPrintFunction(const Function &F)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI std::error_code cleanUpTempFiles(ArrayRef< std::string > FileName)
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
LLVM_ABI 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.
LLVM_ABI bool shouldPrintBeforePass(StringRef PassID)
LLVM_ABI bool shouldPrintAfterPass(StringRef PassID)
LLVM_ABI bool isFilterPassesEmpty()
LLVM_ABI bool shouldPrintAllFunctions()
LLVM_ABI bool forcePrintFuncIR()