From 339aa765265e88f0737bc45f75a53b812604dddb Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Mon, 16 Aug 2021 13:06:54 -0400 Subject: [PATCH] [OpenMP][NFC] Add option to print module after OpenMPOpt for debugging This patch adds an extra option to print the module after running one of the OpenMPOpt passes if debugging is enabled. This makes it much easier to inspect the effects of this pass when doing debugging. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D108146 --- llvm/lib/Transforms/IPO/OpenMPOpt.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp index b69d06c..fd83bdd 100644 --- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -92,6 +92,11 @@ static cl::opt DisableOpenMPOptStateMachineRewrite( cl::desc("Disable OpenMP optimizations that replace the state machine."), cl::Hidden, cl::init(false)); +static cl::opt PrintModuleAfterOptimizations( + "openmp-opt-print-module", cl::ZeroOrMore, + cl::desc("Print the current module after OpenMP optimizations."), + cl::Hidden, cl::init(false)); + STATISTIC(NumOpenMPRuntimeCallsDeduplicated, "Number of OpenMP runtime calls deduplicated"); STATISTIC(NumOpenMPParallelRegionsDeleted, @@ -4473,6 +4478,10 @@ PreservedAnalyses OpenMPOptPass::run(Module &M, ModuleAnalysisManager &AM) { OpenMPOpt OMPOpt(SCC, CGUpdater, OREGetter, InfoCache, A); bool Changed = OMPOpt.run(true); + + if (PrintModuleAfterOptimizations) + LLVM_DEBUG(dbgs() << TAG << "Module after OpenMPOpt Module Pass:\n" << M); + if (Changed) return PreservedAnalyses::none(); @@ -4525,6 +4534,10 @@ PreservedAnalyses OpenMPOptCGSCCPass::run(LazyCallGraph::SCC &C, OpenMPOpt OMPOpt(SCC, CGUpdater, OREGetter, InfoCache, A); bool Changed = OMPOpt.run(false); + + if (PrintModuleAfterOptimizations) + LLVM_DEBUG(dbgs() << TAG << "Module after OpenMPOpt CGSCC Pass:\n" << M); + if (Changed) return PreservedAnalyses::none(); @@ -4590,7 +4603,12 @@ struct OpenMPOptCGSCCLegacyPass : public CallGraphSCCPass { MaxFixpointIterations, OREGetter, DEBUG_TYPE); OpenMPOpt OMPOpt(SCC, CGUpdater, OREGetter, InfoCache, A); - return OMPOpt.run(false); + bool Result = OMPOpt.run(false); + + if (PrintModuleAfterOptimizations) + LLVM_DEBUG(dbgs() << TAG << "Module after OpenMPOpt CGSCC Pass:\n" << M); + + return Result; } bool doFinalization(CallGraph &CG) override { return CGUpdater.finalize(); } -- 2.7.4