From 2b70bebc6d7b9d452a032ca48a59a2e72a4934f8 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Aug 2022 12:56:15 -0700 Subject: [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 --- llvm/lib/CodeGen/MachineFunctionPass.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'llvm/lib/CodeGen/MachineFunctionPass.cpp') 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"); } -- cgit v1.2.3