Skip to content

Commit 668bbc8

Browse files
committed
Drive profile validator from opt
1 parent df2d2d1 commit 668bbc8

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

llvm/test/Transforms/PGOProfile/prof-verify.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
; RUN: opt -passes=prof-inject %s -S -o - | FileCheck %s --check-prefix=INJECT
44
; RUN: not opt -passes=prof-verify %s -S -o - 2>&1 | FileCheck %s --check-prefix=VERIFY
55
; RUN: opt -passes=prof-inject,prof-verify %s --disable-output
6+
; RUN: opt -enable-profcheck %s -S -o - | FileCheck %s --check-prefix=INJECT
67

78
define void @foo(i32 %i) {
89
%c = icmp eq i32 %i, 0

llvm/tools/opt/NewPMDriver.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
4141
#include "llvm/Transforms/Scalar/LoopPassManager.h"
4242
#include "llvm/Transforms/Utils/Debugify.h"
43+
#include "llvm/Transforms/Utils/ProfileVerify.h"
4344

4445
using namespace llvm;
4546
using namespace opt_tool;
@@ -356,7 +357,7 @@ bool llvm::runPassPipeline(
356357
OutputKind OK, VerifierKind VK, bool ShouldPreserveAssemblyUseListOrder,
357358
bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex,
358359
bool EmitModuleHash, bool EnableDebugify, bool VerifyDIPreserve,
359-
bool UnifiedLTO) {
360+
bool EnableProfcheck, bool UnifiedLTO) {
360361
auto FS = vfs::getRealFileSystem();
361362
std::optional<PGOOptions> P;
362363
switch (PGOKindFlag) {
@@ -487,7 +488,8 @@ bool llvm::runPassPipeline(
487488
if (VerifyDIPreserve)
488489
MPM.addPass(NewPMDebugifyPass(DebugifyMode::OriginalDebugInfo, "",
489490
&DebugInfoBeforePass));
490-
491+
if (EnableProfcheck)
492+
MPM.addPass(createModuleToFunctionPassAdaptor(ProfileInjectorPass()));
491493
// Add passes according to the -passes options.
492494
if (!PassPipeline.empty()) {
493495
if (auto Err = PB.parsePassPipeline(MPM, PassPipeline)) {
@@ -504,6 +506,8 @@ bool llvm::runPassPipeline(
504506
MPM.addPass(NewPMCheckDebugifyPass(
505507
false, "", nullptr, DebugifyMode::OriginalDebugInfo,
506508
&DebugInfoBeforePass, VerifyDIPreserveExport));
509+
if (EnableProfcheck)
510+
MPM.addPass(createModuleToFunctionPassAdaptor(ProfileVerifierPass()));
507511

508512
// Add any relevant output pass at the end of the pipeline.
509513
switch (OK) {

llvm/tools/opt/NewPMDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool runPassPipeline(
7575
bool ShouldPreserveAssemblyUseListOrder,
7676
bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex,
7777
bool EmitModuleHash, bool EnableDebugify, bool VerifyDIPreserve,
78-
bool UnifiedLTO = false);
78+
bool EnableProfcheck, bool UnifiedLTO = false);
7979
} // namespace llvm
8080

8181
#endif

llvm/tools/opt/optdriver.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ static cl::opt<bool> VerifyDebugInfoPreserve(
217217
cl::desc("Start the pipeline with collecting and end it with checking of "
218218
"debug info preservation."));
219219

220+
static cl::opt<bool> EnableProfileVerification(
221+
"enable-profcheck", cl::init(false),
222+
cl::desc("Start the pipeline with prof-inject and end it with prof-check"));
223+
220224
static cl::opt<std::string> ClDataLayout("data-layout",
221225
cl::desc("data layout string to use"),
222226
cl::value_desc("layout-string"),
@@ -746,7 +750,8 @@ extern "C" int optMain(
746750
RemarksFile.get(), Pipeline, PluginList, PassBuilderCallbacks,
747751
OK, VK, PreserveAssemblyUseListOrder,
748752
PreserveBitcodeUseListOrder, EmitSummaryIndex, EmitModuleHash,
749-
EnableDebugify, VerifyDebugInfoPreserve, UnifiedLTO)
753+
EnableDebugify, VerifyDebugInfoPreserve,
754+
EnableProfileVerification, UnifiedLTO)
750755
? 0
751756
: 1;
752757
}

0 commit comments

Comments
 (0)