diff options
| author | Fangrui Song <i@maskray.me> | 2022-08-01 12:56:15 -0700 |
|---|---|---|
| committer | Fangrui Song <i@maskray.me> | 2022-08-01 12:56:15 -0700 |
| commit | 2b70bebc6d7b9d452a032ca48a59a2e72a4934f8 (patch) | |
| tree | 07a30ad85b265a1fed88b7a9b11f0641ddbe429f /llvm/lib/CodeGen/MachineFunctionPass.cpp | |
| parent | 995ab92964d667123efd90d1f8016602c4a9df01 (diff) | |
[MachineFunctionPass] Support -print-changed={,c}diff{,-quiet}
Follow-up to D130434.
Move doSystemDiff to PrintPasses.cpp and call it in MachineFunctionPass.cpp.
Reviewed By: aeubanks
Differential Revision: https://reviews.llvm.org/D130833
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunctionPass.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/MachineFunctionPass.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/MachineFunctionPass.cpp b/llvm/lib/CodeGen/MachineFunctionPass.cpp index 477310f59112..c6f7393338e8 100644 --- a/llvm/lib/CodeGen/MachineFunctionPass.cpp +++ b/llvm/lib/CodeGen/MachineFunctionPass.cpp @@ -120,8 +120,34 @@ bool MachineFunctionPass::runOnFunction(Function &F) { 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) { + 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())) { errs() << ("*** IR Dump After " + getPassName() + " on " + MF.getName() + " omitted because no change ***\n"); } |
