diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp index 7d168a6ceb17c..042ed027639bc 100644 --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -40,6 +40,7 @@ #include "llvm/Transforms/Instrumentation/AddressSanitizer.h" #include "llvm/Transforms/Scalar/LoopPassManager.h" #include "llvm/Transforms/Utils/Debugify.h" +#include "llvm/Transforms/Utils/ProfileValidation.h" using namespace llvm; using namespace opt_tool; @@ -356,7 +357,7 @@ bool llvm::runPassPipeline( OutputKind OK, VerifierKind VK, bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex, bool EmitModuleHash, bool EnableDebugify, bool VerifyDIPreserve, - bool UnifiedLTO) { + bool EnableProfcheck, bool UnifiedLTO) { auto FS = vfs::getRealFileSystem(); std::optional P; switch (PGOKindFlag) { @@ -487,7 +488,8 @@ bool llvm::runPassPipeline( if (VerifyDIPreserve) MPM.addPass(NewPMDebugifyPass(DebugifyMode::OriginalDebugInfo, "", &DebugInfoBeforePass)); - + if (EnableProfcheck) + MPM.addPass(createModuleToFunctionPassAdaptor(ProfileInjectorPass())); // Add passes according to the -passes options. if (!PassPipeline.empty()) { if (auto Err = PB.parsePassPipeline(MPM, PassPipeline)) { @@ -504,6 +506,8 @@ bool llvm::runPassPipeline( MPM.addPass(NewPMCheckDebugifyPass( false, "", nullptr, DebugifyMode::OriginalDebugInfo, &DebugInfoBeforePass, VerifyDIPreserveExport)); + if (EnableProfcheck) + MPM.addPass(createModuleToFunctionPassAdaptor(ProfileVerifierPass())); // Add any relevant output pass at the end of the pipeline. switch (OK) { diff --git a/llvm/tools/opt/NewPMDriver.h b/llvm/tools/opt/NewPMDriver.h index 2daae571e72c2..6c21d6cae4e75 100644 --- a/llvm/tools/opt/NewPMDriver.h +++ b/llvm/tools/opt/NewPMDriver.h @@ -75,7 +75,7 @@ bool runPassPipeline( bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex, bool EmitModuleHash, bool EnableDebugify, bool VerifyDIPreserve, - bool UnifiedLTO = false); + bool EnableProfcheck, bool UnifiedLTO = false); } // namespace llvm #endif diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp index de46efa13025d..9b60ae6543336 100644 --- a/llvm/tools/opt/optdriver.cpp +++ b/llvm/tools/opt/optdriver.cpp @@ -213,6 +213,10 @@ static cl::opt VerifyDebugInfoPreserve( cl::desc("Start the pipeline with collecting and end it with checking of " "debug info preservation.")); +static cl::opt EnableProfileVerification( + "enable-profcheck", cl::init(false), + cl::desc("Start the pipeline with prof-inject and end it with prof-check")); + static cl::opt ClDataLayout("data-layout", cl::desc("data layout string to use"), cl::value_desc("layout-string"), @@ -731,7 +735,8 @@ extern "C" int optMain( RemarksFile.get(), Pipeline, PluginList, PassBuilderCallbacks, OK, VK, PreserveAssemblyUseListOrder, PreserveBitcodeUseListOrder, EmitSummaryIndex, EmitModuleHash, - EnableDebugify, VerifyDebugInfoPreserve, UnifiedLTO) + EnableDebugify, VerifyDebugInfoPreserve, + EnableProfileVerification, UnifiedLTO) ? 0 : 1; }