Skip to content

llvm-profgen: Options cleanup / fixes #147632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions llvm/tools/llvm-profgen/CSPreInliner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
4 changes: 3 additions & 1 deletion llvm/tools/llvm-profgen/ErrorHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -53,4 +53,6 @@ inline void emitWarningSummary(uint64_t Num, uint64_t Total, StringRef Msg) {
<< "%(" << Num << "/" << Total << ") " << Msg << "\n";
}

} // end namespace llvm

#endif
4 changes: 3 additions & 1 deletion llvm/tools/llvm-profgen/MissingFrameInferrer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "MissingFrameInferrer.h"
#include "Options.h"
#include "PerfReader.h"
#include "ProfiledBinary.h"
#include "llvm/ADT/SCCIterator.h"
Expand Down Expand Up @@ -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) {
Expand Down
28 changes: 28 additions & 0 deletions llvm/tools/llvm-profgen/Options.h
Original file line number Diff line number Diff line change
@@ -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
31 changes: 18 additions & 13 deletions llvm/tools/llvm-profgen/PerfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
#include "PerfReader.h"

#include "Options.h"
#include "ProfileGenerator.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
Expand All @@ -15,44 +17,47 @@

#define DEBUG_TYPE "perf-reader"

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> PerfTraceFilename;
extern cl::opt<bool> ShowDisassemblyOnly;
extern cl::opt<bool> ShowSourceLocations;
extern cl::opt<std::string> OutputFilename;

namespace llvm {
namespace sampleprof {

void VirtualUnwinder::unwindCall(UnwindState &State) {
Expand Down
3 changes: 0 additions & 3 deletions llvm/tools/llvm-profgen/PerfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#include <fstream>
#include <map>

using namespace llvm;
using namespace sampleprof;

namespace llvm {

class CleanupInstaller;
Expand Down
70 changes: 37 additions & 33 deletions llvm/tools/llvm-profgen/ProfileGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -17,20 +18,24 @@
#include <unordered_set>
#include <utility>

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,
Expand All @@ -56,58 +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);

using namespace llvm;
using namespace sampleprof;

namespace llvm {
cl::Optional, cl::cat(ProfGenCategory));

namespace sampleprof {

Expand Down
3 changes: 0 additions & 3 deletions llvm/tools/llvm-profgen/ProfileGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#include <memory>
#include <unordered_set>

using namespace llvm;
using namespace sampleprof;

namespace llvm {
namespace sampleprof {

Expand Down
35 changes: 21 additions & 14 deletions llvm/tools/llvm-profgen/ProfiledBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,46 +26,51 @@

#define DEBUG_TYPE "load-binary"

using namespace llvm;
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) {
Expand Down
Loading