[PATCH] D137576: [pgo] Improve check for enablesValueProfiling

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 7 11:03:17 PST 2022


paulkirth created this revision.
Herald added subscribers: Enna1, wenlei, hiraditya.
Herald added a project: All.
paulkirth requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently, the check for enablesValueProfiling only considers if it was
specifically added, or is enabled by default under IR profiling. However, we
allow value profiling to be disabled through the DisableValueProfiling flag,
but do not account for this path in InstrProfiling. This change exposes that
flag from PGOInstrumentation.cpp, and uses it as part of its check for whether
value profiling is enabled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137576

Files:
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/test/Instrumentation/InstrProfiling/comdat.ll


Index: llvm/test/Instrumentation/InstrProfiling/comdat.ll
===================================================================
--- llvm/test/Instrumentation/InstrProfiling/comdat.ll
+++ llvm/test/Instrumentation/InstrProfiling/comdat.ll
@@ -10,6 +10,7 @@
 ; RUN: cat %t/main.ll %t/enable.ll > %t1.ll
 ; RUN: opt < %t0.ll -mtriple=x86_64-linux -passes=instrprof -S | FileCheck %s --check-prefixes=ELF,ELF0
 ; RUN: opt < %t1.ll -mtriple=x86_64-linux -passes=instrprof -S | FileCheck %s --check-prefixes=ELF,ELF1
+; RUN: opt < %t1.ll -mtriple=x86_64-linux -passes=instrprof -disable-vp -S | FileCheck %s --check-prefixes=ELF,ELF0
 ; RUN: opt < %t0.ll -mtriple=x86_64-windows -passes=instrprof -S | FileCheck %s --check-prefixes=COFF,COFF0
 ; RUN: opt < %t1.ll -mtriple=x86_64-windows -passes=instrprof -S | FileCheck %s --check-prefixes=COFF,COFF1
 
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -172,12 +172,6 @@
     cl::desc("Specify the path of profile remapping file. This is mainly for "
              "test purpose."));
 
-// Command line option to disable value profiling. The default is false:
-// i.e. value profiling is enabled by default. This is for debug purpose.
-static cl::opt<bool> DisableValueProfiling("disable-vp", cl::init(false),
-                                           cl::Hidden,
-                                           cl::desc("Disable Value Profiling"));
-
 // Command line option to set the maximum number of VP annotations to write to
 // the metadata for a single indirect call callsite.
 static cl::opt<unsigned> MaxNumAnnotations(
@@ -214,6 +208,11 @@
     NoPGOWarnMismatch("no-pgo-warn-mismatch", cl::init(false), cl::Hidden,
                       cl::desc("Use this option to turn off/on "
                                "warnings about profile cfg mismatch."));
+// Command line option to disable value profiling. The default is false:
+// i.e. value profiling is enabled by default. This is for debug purpose.
+cl::opt<bool> DisableValueProfiling("disable-vp", cl::init(false), cl::Hidden,
+                                    cl::desc("Disable Value Profiling"));
+
 } // namespace llvm
 
 // Command line option to enable/disable the warning about a hash mismatch in
Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -63,6 +63,7 @@
     DebugInfoCorrelate("debug-info-correlate",
                        cl::desc("Use debug info to correlate profiles."),
                        cl::init(false));
+extern cl::opt<bool> DisableValueProfiling;
 } // namespace llvm
 
 namespace {
@@ -777,8 +778,9 @@
 }
 
 static bool enablesValueProfiling(const Module &M) {
-  return isIRPGOFlagSet(&M) ||
-         getIntModuleFlagOrZero(M, "EnableValueProfiling") != 0;
+  return (isIRPGOFlagSet(&M) ||
+          getIntModuleFlagOrZero(M, "EnableValueProfiling") != 0) &&
+         !DisableValueProfiling;
 }
 
 // Conservatively returns true if data variables may be referenced by code.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137576.473748.patch
Type: text/x-patch
Size: 3338 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221107/50c9b412/attachment.bin>


More information about the llvm-commits mailing list