[llvm] llvm-profgen: Options cleanup / fixes (PR #147632)

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 8 18:11:49 PDT 2025


https://github.com/MatzeB updated https://github.com/llvm/llvm-project/pull/147632

>From efcedbf9d18df6ff3ff5d1ed371f10606f4fd315 Mon Sep 17 00:00:00 2001
From: Matthias Braun <matze at braunis.de>
Date: Tue, 8 Jul 2025 17:25:52 -0700
Subject: [PATCH 1/2] llvm-profgen: Avoid "using namespace" in headers

(global) `using namespace` directives in headers are bad style.
---
 llvm/tools/llvm-profgen/CSPreInliner.h       |  3 --
 llvm/tools/llvm-profgen/ErrorHandling.h      |  4 ++-
 llvm/tools/llvm-profgen/PerfReader.cpp       |  5 ++-
 llvm/tools/llvm-profgen/PerfReader.h         |  3 --
 llvm/tools/llvm-profgen/ProfileGenerator.cpp |  6 ++--
 llvm/tools/llvm-profgen/ProfileGenerator.h   |  3 --
 llvm/tools/llvm-profgen/ProfiledBinary.cpp   |  1 +
 llvm/tools/llvm-profgen/ProfiledBinary.h     | 34 +++++++++-----------
 llvm/tools/llvm-profgen/llvm-profgen.cpp     |  6 ++--
 9 files changed, 27 insertions(+), 38 deletions(-)

diff --git a/llvm/tools/llvm-profgen/CSPreInliner.h b/llvm/tools/llvm-profgen/CSPreInliner.h
index 8a3f16a4f13cb..022c3f8d0daed 100644
--- a/llvm/tools/llvm-profgen/CSPreInliner.h
+++ b/llvm/tools/llvm-profgen/CSPreInliner.h
@@ -16,9 +16,6 @@
 #include "llvm/Transforms/IPO/ProfiledCallGraph.h"
 #include "llvm/Transforms/IPO/SampleContextTracker.h"
 
-using namespace llvm;
-using namespace sampleprof;
-
 namespace llvm {
 namespace sampleprof {
 
diff --git a/llvm/tools/llvm-profgen/ErrorHandling.h b/llvm/tools/llvm-profgen/ErrorHandling.h
index b797add8a892f..17084bd785e64 100644
--- a/llvm/tools/llvm-profgen/ErrorHandling.h
+++ b/llvm/tools/llvm-profgen/ErrorHandling.h
@@ -16,7 +16,7 @@
 #include "llvm/Support/WithColor.h"
 #include <system_error>
 
-using namespace llvm;
+namespace llvm {
 
 [[noreturn]] inline void exitWithError(const Twine &Message,
                                        StringRef Whence = StringRef(),
@@ -53,4 +53,6 @@ inline void emitWarningSummary(uint64_t Num, uint64_t Total, StringRef Msg) {
                        << "%(" << Num << "/" << Total << ") " << Msg << "\n";
 }
 
+} // end namespace llvm
+
 #endif
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index ad113eda27914..4ab5f2e63fd12 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -15,6 +15,8 @@
 
 #define DEBUG_TYPE "perf-reader"
 
+using namespace llvm;
+
 cl::opt<bool> SkipSymbolization("skip-symbolization",
                                 cl::desc("Dump the unsymbolized profile to the "
                                          "output file. It will show unwinder "
@@ -47,9 +49,6 @@ static cl::opt<int> CSProfMaxUnsymbolizedCtxDepth(
     cl::desc("Keep the last K contexts while merging unsymbolized profile. -1 "
              "means no depth limit."));
 
-extern cl::opt<std::string> PerfTraceFilename;
-extern cl::opt<bool> ShowDisassemblyOnly;
-extern cl::opt<bool> ShowSourceLocations;
 extern cl::opt<std::string> OutputFilename;
 
 namespace llvm {
diff --git a/llvm/tools/llvm-profgen/PerfReader.h b/llvm/tools/llvm-profgen/PerfReader.h
index 4b3ac8f569755..19451915812e1 100644
--- a/llvm/tools/llvm-profgen/PerfReader.h
+++ b/llvm/tools/llvm-profgen/PerfReader.h
@@ -17,9 +17,6 @@
 #include <fstream>
 #include <map>
 
-using namespace llvm;
-using namespace sampleprof;
-
 namespace llvm {
 
 class CleanupInstaller;
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index db686c3b597eb..9468228acc427 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -17,6 +17,9 @@
 #include <unordered_set>
 #include <utility>
 
+using namespace llvm;
+using namespace sampleprof;
+
 cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
                                     cl::Required,
                                     cl::desc("Output profile file"));
@@ -104,9 +107,6 @@ cl::opt<bool> InferMissingFrames(
         "Infer missing call frames due to compiler tail call elimination."),
     llvm::cl::Optional);
 
-using namespace llvm;
-using namespace sampleprof;
-
 namespace llvm {
 
 namespace sampleprof {
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.h b/llvm/tools/llvm-profgen/ProfileGenerator.h
index 5e36128530cd9..d3e04563a81c2 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.h
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.h
@@ -17,9 +17,6 @@
 #include <memory>
 #include <unordered_set>
 
-using namespace llvm;
-using namespace sampleprof;
-
 namespace llvm {
 namespace sampleprof {
 
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index 6847ba1b21b1f..beef4338d5f89 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -25,6 +25,7 @@
 #define DEBUG_TYPE "load-binary"
 
 using namespace llvm;
+using namespace llvm::object;
 using namespace sampleprof;
 
 cl::opt<bool> ShowDisassemblyOnly("show-disassembly-only",
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h
index 0588cb48b2af6..5b35c040b2c4b 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.h
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.h
@@ -42,15 +42,10 @@
 #include <vector>
 
 namespace llvm {
+
 extern cl::opt<bool> EnableCSPreInliner;
 extern cl::opt<bool> UseContextCostForPreInliner;
-} // namespace llvm
-
-using namespace llvm;
-using namespace sampleprof;
-using namespace llvm::object;
 
-namespace llvm {
 namespace sampleprof {
 
 class ProfiledBinary;
@@ -303,34 +298,34 @@ class ProfiledBinary {
 
   bool IsCOFF = false;
 
-  void setPreferredTextSegmentAddresses(const ObjectFile *O);
+  void setPreferredTextSegmentAddresses(const object::ObjectFile *O);
 
   template <class ELFT>
-  void setPreferredTextSegmentAddresses(const ELFFile<ELFT> &Obj,
+  void setPreferredTextSegmentAddresses(const object::ELFFile<ELFT> &Obj,
                                         StringRef FileName);
-  void setPreferredTextSegmentAddresses(const COFFObjectFile *Obj,
+  void setPreferredTextSegmentAddresses(const object::COFFObjectFile *Obj,
                                         StringRef FileName);
 
-  void checkPseudoProbe(const ELFObjectFileBase *Obj);
+  void checkPseudoProbe(const object::ELFObjectFileBase *Obj);
 
-  void decodePseudoProbe(const ELFObjectFileBase *Obj);
+  void decodePseudoProbe(const object::ELFObjectFileBase *Obj);
 
-  void
-  checkUseFSDiscriminator(const ObjectFile *Obj,
-                          std::map<SectionRef, SectionSymbolsTy> &AllSymbols);
+  void checkUseFSDiscriminator(
+      const object::ObjectFile *Obj,
+      std::map<object::SectionRef, SectionSymbolsTy> &AllSymbols);
 
   // Set up disassembler and related components.
-  void setUpDisassembler(const ObjectFile *Obj);
+  void setUpDisassembler(const object::ObjectFile *Obj);
   symbolize::LLVMSymbolizer::Options getSymbolizerOpts() const;
 
   // Load debug info of subprograms from DWARF section.
-  void loadSymbolsFromDWARF(ObjectFile &Obj);
+  void loadSymbolsFromDWARF(object::ObjectFile &Obj);
 
   // Load debug info from DWARF unit.
   void loadSymbolsFromDWARFUnit(DWARFUnit &CompilationUnit);
 
   // Create elf symbol to its start address mapping.
-  void populateElfSymbolAddressList(const ELFObjectFileBase *O);
+  void populateElfSymbolAddressList(const object::ELFObjectFileBase *O);
 
   // A function may be spilt into multiple non-continuous address ranges. We use
   // this to set whether start a function range is the real entry of the
@@ -341,11 +336,12 @@ class ProfiledBinary {
   void warnNoFuncEntry();
 
   /// Dissassemble the text section and build various address maps.
-  void disassemble(const ObjectFile *O);
+  void disassemble(const object::ObjectFile *O);
 
   /// Helper function to dissassemble the symbol and extract info for unwinding
   bool dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
-                          SectionSymbolsTy &Symbols, const SectionRef &Section);
+                          SectionSymbolsTy &Symbols,
+                          const object::SectionRef &Section);
   /// Symbolize a given instruction pointer and return a full call context.
   SampleContextFrameVector symbolize(const InstructionPointer &IP,
                                      bool UseCanonicalFnName = false,
diff --git a/llvm/tools/llvm-profgen/llvm-profgen.cpp b/llvm/tools/llvm-profgen/llvm-profgen.cpp
index 3b974e25103ad..5464888e77ad5 100644
--- a/llvm/tools/llvm-profgen/llvm-profgen.cpp
+++ b/llvm/tools/llvm-profgen/llvm-profgen.cpp
@@ -21,6 +21,9 @@
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/VirtualFileSystem.h"
 
+using namespace llvm;
+using namespace sampleprof;
+
 static cl::OptionCategory ProfGenCategory("ProfGen Options");
 
 static cl::opt<std::string> PerfScriptFilename(
@@ -71,9 +74,6 @@ extern cl::opt<bool> ShowDisassemblyOnly;
 extern cl::opt<bool> ShowSourceLocations;
 extern cl::opt<bool> SkipSymbolization;
 
-using namespace llvm;
-using namespace sampleprof;
-
 // Validate the command line input.
 static void validateCommandLine() {
   // Allow the missing perfscript if we only use to show binary disassembly.

>From 6a1ba86baaa6af49293cddbff2f7736690dfca48 Mon Sep 17 00:00:00 2001
From: Matthias Braun <matze at braunis.de>
Date: Tue, 8 Jul 2025 16:56:20 -0700
Subject: [PATCH 2/2] llvm-profgen: Options cleanup / fixes

- Add cl::cat(ProfGenCategory) where missing so the options show up
  in --help output.
- Introduce `Options.h` to shared declarations for options referenced in
  multiple files.
---
 .../llvm-profgen/MissingFrameInferrer.cpp     |  4 +-
 llvm/tools/llvm-profgen/Options.h             | 28 ++++++++
 llvm/tools/llvm-profgen/PerfReader.cpp        | 28 +++++---
 llvm/tools/llvm-profgen/ProfileGenerator.cpp  | 68 ++++++++++---------
 llvm/tools/llvm-profgen/ProfiledBinary.cpp    | 36 ++++++----
 llvm/tools/llvm-profgen/ProfiledBinary.h      |  4 --
 llvm/tools/llvm-profgen/llvm-profgen.cpp      | 11 +--
 7 files changed, 111 insertions(+), 68 deletions(-)
 create mode 100644 llvm/tools/llvm-profgen/Options.h

diff --git a/llvm/tools/llvm-profgen/MissingFrameInferrer.cpp b/llvm/tools/llvm-profgen/MissingFrameInferrer.cpp
index edfe8979c7121..7ebca23ba7956 100644
--- a/llvm/tools/llvm-profgen/MissingFrameInferrer.cpp
+++ b/llvm/tools/llvm-profgen/MissingFrameInferrer.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "MissingFrameInferrer.h"
+#include "Options.h"
 #include "PerfReader.h"
 #include "ProfiledBinary.h"
 #include "llvm/ADT/SCCIterator.h"
@@ -37,7 +38,8 @@ STATISTIC(TailCallMaxTailCallPath, "Length of the longest tail call path");
 static cl::opt<uint32_t>
     MaximumSearchDepth("max-search-depth", cl::init(UINT32_MAX - 1),
                        cl::desc("The maximum levels the DFS-based missing "
-                                "frame search should go with"));
+                                "frame search should go with"),
+                       cl::cat(ProfGenCategory));
 
 void MissingFrameInferrer::initialize(
     const ContextSampleCounterMap *SampleCounters) {
diff --git a/llvm/tools/llvm-profgen/Options.h b/llvm/tools/llvm-profgen/Options.h
new file mode 100644
index 0000000000000..f94cf9118c06a
--- /dev/null
+++ b/llvm/tools/llvm-profgen/Options.h
@@ -0,0 +1,28 @@
+//===-- Options.h -----------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_LLVM_PROFGEN_OPTIONS_H
+#define LLVM_TOOLS_LLVM_PROFGEN_OPTIONS_H
+
+#include "llvm/Support/CommandLine.h"
+
+namespace llvm {
+
+extern cl::OptionCategory ProfGenCategory;
+
+extern cl::opt<std::string> OutputFilename;
+extern cl::opt<bool> ShowDisassemblyOnly;
+extern cl::opt<bool> ShowSourceLocations;
+extern cl::opt<bool> SkipSymbolization;
+extern cl::opt<bool> ShowDetailedWarning;
+extern cl::opt<bool> InferMissingFrames;
+extern cl::opt<bool> EnableCSPreInliner;
+extern cl::opt<bool> UseContextCostForPreInliner;
+
+} // end namespace llvm
+
+#endif
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index 4ab5f2e63fd12..7e045b0c06229 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -6,6 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 #include "PerfReader.h"
+
+#include "Options.h"
 #include "ProfileGenerator.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
@@ -15,43 +17,47 @@
 
 #define DEBUG_TYPE "perf-reader"
 
-using namespace llvm;
+namespace llvm {
 
 cl::opt<bool> SkipSymbolization("skip-symbolization",
                                 cl::desc("Dump the unsymbolized profile to the "
                                          "output file. It will show unwinder "
-                                         "output for CS profile generation."));
+                                         "output for CS profile generation."),
+                                cl::cat(ProfGenCategory));
 
 static cl::opt<bool> ShowMmapEvents("show-mmap-events",
-                                    cl::desc("Print binary load events."));
+                                    cl::desc("Print binary load events."),
+                                    cl::cat(ProfGenCategory));
 
 static cl::opt<bool>
     UseOffset("use-offset", cl::init(true),
               cl::desc("Work with `--skip-symbolization` or "
                        "`--unsymbolized-profile` to write/read the "
-                       "offset instead of virtual address."));
+                       "offset instead of virtual address."),
+              cl::cat(ProfGenCategory));
 
 static cl::opt<bool> UseLoadableSegmentAsBase(
     "use-first-loadable-segment-as-base",
     cl::desc("Use first loadable segment address as base address "
              "for offsets in unsymbolized profile. By default "
-             "first executable segment address is used"));
+             "first executable segment address is used"),
+    cl::cat(ProfGenCategory));
 
 static cl::opt<bool>
     IgnoreStackSamples("ignore-stack-samples",
                        cl::desc("Ignore call stack samples for hybrid samples "
-                                "and produce context-insensitive profile."));
+                                "and produce context-insensitive profile."),
+                       cl::cat(ProfGenCategory));
 cl::opt<bool> ShowDetailedWarning("show-detailed-warning",
-                                  cl::desc("Show detailed warning message."));
+                                  cl::desc("Show detailed warning message."),
+                                  cl::cat(ProfGenCategory));
 
 static cl::opt<int> CSProfMaxUnsymbolizedCtxDepth(
     "csprof-max-unsymbolized-context-depth", cl::init(-1),
     cl::desc("Keep the last K contexts while merging unsymbolized profile. -1 "
-             "means no depth limit."));
+             "means no depth limit."),
+    cl::cat(ProfGenCategory));
 
-extern cl::opt<std::string> OutputFilename;
-
-namespace llvm {
 namespace sampleprof {
 
 void VirtualUnwinder::unwindCall(UnwindState &State) {
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index 9468228acc427..33575b9c67625 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -8,6 +8,7 @@
 #include "ProfileGenerator.h"
 #include "ErrorHandling.h"
 #include "MissingFrameInferrer.h"
+#include "Options.h"
 #include "PerfReader.h"
 #include "ProfiledBinary.h"
 #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
@@ -17,23 +18,24 @@
 #include <unordered_set>
 #include <utility>
 
-using namespace llvm;
-using namespace sampleprof;
+namespace llvm {
 
 cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
                                     cl::Required,
-                                    cl::desc("Output profile file"));
+                                    cl::desc("Output profile file"),
+                                    cl::cat(ProfGenCategory));
 static cl::alias OutputA("o", cl::desc("Alias for --output"),
                          cl::aliasopt(OutputFilename));
 
 static cl::opt<SampleProfileFormat> OutputFormat(
     "format", cl::desc("Format of output profile"), cl::init(SPF_Ext_Binary),
-    cl::values(
-        clEnumValN(SPF_Binary, "binary", "Binary encoding (default)"),
-        clEnumValN(SPF_Ext_Binary, "extbinary", "Extensible binary encoding"),
-        clEnumValN(SPF_Text, "text", "Text encoding"),
-        clEnumValN(SPF_GCC, "gcc",
-                   "GCC encoding (only meaningful for -sample)")));
+    cl::values(clEnumValN(SPF_Binary, "binary", "Binary encoding (default)"),
+               clEnumValN(SPF_Ext_Binary, "extbinary",
+                          "Extensible binary encoding"),
+               clEnumValN(SPF_Text, "text", "Text encoding"),
+               clEnumValN(SPF_GCC, "gcc",
+                          "GCC encoding (only meaningful for -sample)")),
+    cl::cat(ProfGenCategory));
 
 static cl::opt<bool> UseMD5(
     "use-md5", cl::Hidden,
@@ -59,55 +61,57 @@ static cl::opt<int32_t, true> RecursionCompression(
 static cl::opt<bool>
     TrimColdProfile("trim-cold-profile",
                     cl::desc("If the total count of the profile is smaller "
-                             "than threshold, it will be trimmed."));
+                             "than threshold, it will be trimmed."),
+                    cl::cat(ProfGenCategory));
 
 static cl::opt<bool> CSProfMergeColdContext(
     "csprof-merge-cold-context", cl::init(true),
     cl::desc("If the total count of context profile is smaller than "
              "the threshold, it will be merged into context-less base "
-             "profile."));
+             "profile."),
+    cl::cat(ProfGenCategory));
 
 static cl::opt<uint32_t> CSProfMaxColdContextDepth(
     "csprof-max-cold-context-depth", cl::init(1),
     cl::desc("Keep the last K contexts while merging cold profile. 1 means the "
-             "context-less base profile"));
+             "context-less base profile"),
+    cl::cat(ProfGenCategory));
 
 static cl::opt<int, true> CSProfMaxContextDepth(
     "csprof-max-context-depth",
     cl::desc("Keep the last K contexts while merging profile. -1 means no "
              "depth limit."),
-    cl::location(llvm::sampleprof::CSProfileGenerator::MaxContextDepth));
+    cl::location(llvm::sampleprof::CSProfileGenerator::MaxContextDepth),
+    cl::cat(ProfGenCategory));
 
 static cl::opt<double> ProfileDensityThreshold(
-    "profile-density-threshold", llvm::cl::init(50),
-    llvm::cl::desc("If the profile density is below the given threshold, it "
-                   "will be suggested to increase the sampling rate."),
-    llvm::cl::Optional);
-static cl::opt<bool> ShowDensity("show-density", llvm::cl::init(false),
-                                 llvm::cl::desc("show profile density details"),
-                                 llvm::cl::Optional);
+    "profile-density-threshold", cl::init(50),
+    cl::desc("If the profile density is below the given threshold, it "
+             "will be suggested to increase the sampling rate."),
+    cl::Optional, cl::cat(ProfGenCategory));
+static cl::opt<bool> ShowDensity("show-density", cl::init(false),
+                                 cl::desc("show profile density details"),
+                                 cl::Optional, cl::cat(ProfGenCategory));
 static cl::opt<int> ProfileDensityCutOffHot(
-    "profile-density-cutoff-hot", llvm::cl::init(990000),
-    llvm::cl::desc("Total samples cutoff for functions used to calculate "
-                   "profile density."));
+    "profile-density-cutoff-hot", cl::init(990000),
+    cl::desc("Total samples cutoff for functions used to calculate "
+             "profile density."),
+    cl::cat(ProfGenCategory));
 
 static cl::opt<bool> UpdateTotalSamples(
-    "update-total-samples", llvm::cl::init(false),
-    llvm::cl::desc(
-        "Update total samples by accumulating all its body samples."),
-    llvm::cl::Optional);
+    "update-total-samples", cl::init(false),
+    cl::desc("Update total samples by accumulating all its body samples."),
+    cl::Optional, cl::cat(ProfGenCategory));
 
 static cl::opt<bool> GenCSNestedProfile(
     "gen-cs-nested-profile", cl::Hidden, cl::init(true),
     cl::desc("Generate nested function profiles for CSSPGO"));
 
 cl::opt<bool> InferMissingFrames(
-    "infer-missing-frames", llvm::cl::init(true),
-    llvm::cl::desc(
+    "infer-missing-frames", cl::init(true),
+    cl::desc(
         "Infer missing call frames due to compiler tail call elimination."),
-    llvm::cl::Optional);
-
-namespace llvm {
+    cl::Optional, cl::cat(ProfGenCategory));
 
 namespace sampleprof {
 
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index beef4338d5f89..7dd5d3f773733 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -7,8 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "ProfiledBinary.h"
+
 #include "ErrorHandling.h"
 #include "MissingFrameInferrer.h"
+#include "Options.h"
 #include "ProfileGenerator.h"
 #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
 #include "llvm/Demangle/Demangle.h"
@@ -24,47 +26,51 @@
 
 #define DEBUG_TYPE "load-binary"
 
-using namespace llvm;
-using namespace llvm::object;
-using namespace sampleprof;
+namespace llvm {
+
+using namespace object;
 
 cl::opt<bool> ShowDisassemblyOnly("show-disassembly-only",
-                                  cl::desc("Print disassembled code."));
+                                  cl::desc("Print disassembled code."),
+                                  cl::cat(ProfGenCategory));
 
 cl::opt<bool> ShowSourceLocations("show-source-locations",
-                                  cl::desc("Print source locations."));
+                                  cl::desc("Print source locations."),
+                                  cl::cat(ProfGenCategory));
 
 static cl::opt<bool>
     ShowCanonicalFnName("show-canonical-fname",
-                        cl::desc("Print canonical function name."));
+                        cl::desc("Print canonical function name."),
+                        cl::cat(ProfGenCategory));
 
 static cl::opt<bool> ShowPseudoProbe(
     "show-pseudo-probe",
-    cl::desc("Print pseudo probe section and disassembled info."));
+    cl::desc("Print pseudo probe section and disassembled info."),
+    cl::cat(ProfGenCategory));
 
 static cl::opt<bool> UseDwarfCorrelation(
     "use-dwarf-correlation",
     cl::desc("Use dwarf for profile correlation even when binary contains "
-             "pseudo probe."));
+             "pseudo probe."),
+    cl::cat(ProfGenCategory));
 
 static cl::opt<std::string>
     DWPPath("dwp", cl::init(""),
             cl::desc("Path of .dwp file. When not specified, it will be "
-                     "<binary>.dwp in the same directory as the main binary."));
+                     "<binary>.dwp in the same directory as the main binary."),
+            cl::cat(ProfGenCategory));
 
 static cl::list<std::string> DisassembleFunctions(
     "disassemble-functions", cl::CommaSeparated,
     cl::desc("List of functions to print disassembly for. Accept demangled "
-             "names only. Only work with show-disassembly-only"));
+             "names only. Only work with show-disassembly-only"),
+    cl::cat(ProfGenCategory));
 
 static cl::opt<bool>
     KernelBinary("kernel",
-                 cl::desc("Generate the profile for Linux kernel binary."));
+                 cl::desc("Generate the profile for Linux kernel binary."),
+                 cl::cat(ProfGenCategory));
 
-extern cl::opt<bool> ShowDetailedWarning;
-extern cl::opt<bool> InferMissingFrames;
-
-namespace llvm {
 namespace sampleprof {
 
 static const Target *getTarget(const ObjectFile *Obj) {
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h
index 5b35c040b2c4b..9c0bff591337a 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.h
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.h
@@ -42,10 +42,6 @@
 #include <vector>
 
 namespace llvm {
-
-extern cl::opt<bool> EnableCSPreInliner;
-extern cl::opt<bool> UseContextCostForPreInliner;
-
 namespace sampleprof {
 
 class ProfiledBinary;
diff --git a/llvm/tools/llvm-profgen/llvm-profgen.cpp b/llvm/tools/llvm-profgen/llvm-profgen.cpp
index 5464888e77ad5..7e070a1ea6489 100644
--- a/llvm/tools/llvm-profgen/llvm-profgen.cpp
+++ b/llvm/tools/llvm-profgen/llvm-profgen.cpp
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "ErrorHandling.h"
+#include "Options.h"
 #include "PerfReader.h"
 #include "ProfileGenerator.h"
 #include "ProfiledBinary.h"
@@ -24,7 +25,9 @@
 using namespace llvm;
 using namespace sampleprof;
 
-static cl::OptionCategory ProfGenCategory("ProfGen Options");
+namespace llvm {
+
+cl::OptionCategory ProfGenCategory("ProfGen Options");
 
 static cl::opt<std::string> PerfScriptFilename(
     "perfscript", cl::value_desc("perfscript"),
@@ -70,10 +73,6 @@ static cl::opt<std::string> DebugBinPath(
              "from it instead of the executable binary."),
     cl::cat(ProfGenCategory));
 
-extern cl::opt<bool> ShowDisassemblyOnly;
-extern cl::opt<bool> ShowSourceLocations;
-extern cl::opt<bool> SkipSymbolization;
-
 // Validate the command line input.
 static void validateCommandLine() {
   // Allow the missing perfscript if we only use to show binary disassembly.
@@ -138,6 +137,8 @@ static PerfInputFile getPerfInputFile() {
   return File;
 }
 
+} // end namespace llvm
+
 int main(int argc, const char *argv[]) {
   InitLLVM X(argc, argv);
 



More information about the llvm-commits mailing list