Skip to content
Merged
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
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
27 changes: 16 additions & 11 deletions llvm/tools/llvm-profgen/PerfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "PerfReader.h"
#include "Options.h"
#include "ProfileGenerator.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
Expand All @@ -15,43 +16,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."));

extern cl::opt<std::string> OutputFilename;
"means no depth limit."),
cl::cat(ProfGenCategory));

namespace llvm {
namespace sampleprof {

void VirtualUnwinder::unwindCall(UnwindState &State) {
Expand Down
68 changes: 36 additions & 32 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,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,
Expand All @@ -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 {

Expand Down
35 changes: 20 additions & 15 deletions llvm/tools/llvm-profgen/ProfiledBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#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,47 +25,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) {
Expand Down
4 changes: 0 additions & 4 deletions llvm/tools/llvm-profgen/ProfiledBinary.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
#include <vector>

namespace llvm {

extern cl::opt<bool> EnableCSPreInliner;
extern cl::opt<bool> UseContextCostForPreInliner;

namespace sampleprof {

class ProfiledBinary;
Expand Down
11 changes: 6 additions & 5 deletions llvm/tools/llvm-profgen/llvm-profgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "ErrorHandling.h"
#include "Options.h"
#include "PerfReader.h"
#include "ProfileGenerator.h"
#include "ProfiledBinary.h"
Expand All @@ -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"),
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -138,6 +137,8 @@ static PerfInputFile getPerfInputFile() {
return File;
}

} // end namespace llvm

int main(int argc, const char *argv[]) {
InitLLVM X(argc, argv);

Expand Down