diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:04 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:11 +0000 |
| commit | e3b557809604d036af6e00c60f012c2025b59a5e (patch) | |
| tree | 8a11ba2269a3b669601e2fd41145b174008f4da8 /llvm/lib/CodeGen/MachineFunctionPass.cpp | |
| parent | 08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff) | |
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunctionPass.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/MachineFunctionPass.cpp | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/llvm/lib/CodeGen/MachineFunctionPass.cpp b/llvm/lib/CodeGen/MachineFunctionPass.cpp index 477310f59112..3a1e1720be9c 100644 --- a/llvm/lib/CodeGen/MachineFunctionPass.cpp +++ b/llvm/lib/CodeGen/MachineFunctionPass.cpp @@ -73,10 +73,16 @@ bool MachineFunctionPass::runOnFunction(Function &F) { // For --print-changed, if the function name is a candidate, save the // serialized MF to be compared later. - // TODO Implement --filter-passes. SmallString<0> BeforeStr, AfterStr; - bool ShouldPrintChanged = PrintChanged != ChangePrinter::None && - isFunctionInPrintList(MF.getName()); + StringRef PassID; + if (PrintChanged != ChangePrinter::None) { + if (const PassInfo *PI = Pass::lookupPassInfo(getPassID())) + PassID = PI->getPassArgument(); + } + const bool IsInterestingPass = isPassInPrintList(PassID); + const bool ShouldPrintChanged = PrintChanged != ChangePrinter::None && + IsInterestingPass && + isFunctionInPrintList(MF.getName()); if (ShouldPrintChanged) { raw_svector_ostream OS(BeforeStr); MF.print(OS); @@ -112,18 +118,47 @@ bool MachineFunctionPass::runOnFunction(Function &F) { // For --print-changed, print if the serialized MF has changed. Modes other // than quiet/verbose are unimplemented and treated the same as 'quiet'. - if (ShouldPrintChanged) { - raw_svector_ostream OS(AfterStr); - MF.print(OS); - if (BeforeStr != AfterStr) { - StringRef Arg; - if (const PassInfo *PI = Pass::lookupPassInfo(getPassID())) - Arg = PI->getPassArgument(); - errs() << ("*** IR Dump After " + getPassName() + " (" + Arg + ") on " + - MF.getName() + " ***\n" + AfterStr); - } else if (PrintChanged == ChangePrinter::Verbose) { - errs() << ("*** IR Dump After " + getPassName() + " on " + MF.getName() + - " omitted because no change ***\n"); + if (ShouldPrintChanged || !IsInterestingPass) { + if (ShouldPrintChanged) { + raw_svector_ostream OS(AfterStr); + MF.print(OS); + } + if (IsInterestingPass && BeforeStr != AfterStr) { + errs() << ("*** IR Dump After " + getPassName() + " (" + PassID + + ") on " + MF.getName() + " ***\n"); + switch (PrintChanged) { + case ChangePrinter::None: + llvm_unreachable(""); + case ChangePrinter::Quiet: + case ChangePrinter::Verbose: + case ChangePrinter::DotCfgQuiet: // unimplemented + case ChangePrinter::DotCfgVerbose: // unimplemented + errs() << AfterStr; + break; + case ChangePrinter::DiffQuiet: + case ChangePrinter::DiffVerbose: + case ChangePrinter::ColourDiffQuiet: + case ChangePrinter::ColourDiffVerbose: { + bool Color = llvm::is_contained( + {ChangePrinter::ColourDiffQuiet, ChangePrinter::ColourDiffVerbose}, + PrintChanged.getValue()); + StringRef Removed = Color ? "\033[31m-%l\033[0m\n" : "-%l\n"; + StringRef Added = Color ? "\033[32m+%l\033[0m\n" : "+%l\n"; + StringRef NoChange = " %l\n"; + errs() << doSystemDiff(BeforeStr, AfterStr, Removed, Added, NoChange); + break; + } + } + } else if (llvm::is_contained({ChangePrinter::Verbose, + ChangePrinter::DiffVerbose, + ChangePrinter::ColourDiffVerbose}, + PrintChanged.getValue())) { + const char *Reason = + IsInterestingPass ? " omitted because no change" : " filtered out"; + errs() << "*** IR Dump After " << getPassName(); + if (!PassID.empty()) + errs() << " (" << PassID << ")"; + errs() << " on " << MF.getName() + Reason + " ***\n"; } } return RV; |
