Skip to content

Commit 33f0cce

Browse files
committed
Drive profile validator from opt
1 parent df2d2d1 commit 33f0cce

File tree

8 files changed

+26
-4
lines changed

8 files changed

+26
-4
lines changed

llvm/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,8 @@ if (LLVM_HAVE_TFLITE)
11901190
find_package(tensorflow-lite REQUIRED)
11911191
endif()
11921192

1193+
set(LLVM_ENABLE_PROFCHECK OFF CACHE BOOL "Enable profile checking in test tools")
1194+
11931195
# For up-to-date instructions for installing the Tensorflow dependency, refer to
11941196
# the bot setup script: https://github.com/google/ml-compiler-opt/blob/main/buildbot/buildbot_init.sh
11951197
# Specifically, assuming python3 is installed:

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@
101101
/* Define if LLVM is using tflite */
102102
#cmakedefine LLVM_HAVE_TFLITE
103103

104+
/* Define if we want to check profile consistency in lit tests */
105+
#cmakedefine LLVM_ENABLE_PROFCHECK
106+
104107
/* Define to 1 if you have the <sysexits.h> header file. */
105108
#cmakedefine HAVE_SYSEXITS_H ${HAVE_SYSEXITS_H}
106109

llvm/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ llvm_canonicalize_cmake_booleans(
1919
LLVM_EXAMPLEIRTRANSFORMS_LINK_INTO_TOOLS
2020
LLVM_HAVE_TF_AOT
2121
LLVM_HAVE_TFLITE
22+
LLVM_ENABLE_PROFCHECK
2223
LLVM_INLINER_MODEL_AUTOGENERATED
2324
LLVM_RAEVICT_MODEL_AUTOGENERATED
2425
LLVM_ENABLE_EXPENSIVE_CHECKS

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/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ config.linked_bye_extension = @LLVM_BYE_LINK_INTO_TOOLS@
5555
config.linked_exampleirtransforms_extension = @LLVM_EXAMPLEIRTRANSFORMS_LINK_INTO_TOOLS@
5656
config.have_tf_aot = @LLVM_HAVE_TF_AOT@
5757
config.have_tflite = @LLVM_HAVE_TFLITE@
58+
config.enable_profcheck = @LLVM_ENABLE_PROFCHECK@
5859
config.llvm_inliner_model_autogenerated = @LLVM_INLINER_MODEL_AUTOGENERATED@
5960
config.llvm_raevict_model_autogenerated = @LLVM_RAEVICT_MODEL_AUTOGENERATED@
6061
config.expensive_checks = @LLVM_ENABLE_EXPENSIVE_CHECKS@

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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ 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",
222+
#if defined(LLVM_ENABLE_PROFCHECK)
223+
cl::init(true),
224+
#else
225+
cl::init(false),
226+
#endif
227+
cl::desc("Start the pipeline with prof-inject and end it with prof-check"));
228+
220229
static cl::opt<std::string> ClDataLayout("data-layout",
221230
cl::desc("data layout string to use"),
222231
cl::value_desc("layout-string"),
@@ -746,7 +755,8 @@ extern "C" int optMain(
746755
RemarksFile.get(), Pipeline, PluginList, PassBuilderCallbacks,
747756
OK, VK, PreserveAssemblyUseListOrder,
748757
PreserveBitcodeUseListOrder, EmitSummaryIndex, EmitModuleHash,
749-
EnableDebugify, VerifyDebugInfoPreserve, UnifiedLTO)
758+
EnableDebugify, VerifyDebugInfoPreserve,
759+
EnableProfileVerification, UnifiedLTO)
750760
? 0
751761
: 1;
752762
}

0 commit comments

Comments
 (0)