#include "llvm/ProfileData/InstrProf.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/config.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/TargetParser/Triple.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
#include <string>
#include <system_error>
#include <type_traits>
#include <utility>
#include <vector>
usingnamespacellvm;
#define DEBUG_TYPE …
static cl::opt<bool> StaticFuncFullModulePrefix(
"static-func-full-module-prefix", cl::init(true), cl::Hidden,
cl::desc("Use full module build paths in the profile counter names for "
"static functions."));
static cl::opt<unsigned> StaticFuncStripDirNamePrefix(
"static-func-strip-dirname-prefix", cl::init(0), cl::Hidden,
cl::desc("Strip specified level of directory name from source path in "
"the profile counter name for static functions."));
static std::string getInstrProfErrString(instrprof_error Err,
const std::string &ErrMsg = "") { … }
namespace {
class InstrProfErrorCategoryType : public std::error_category { … };
}
const std::error_category &llvm::instrprof_category() { … }
namespace {
const char *InstrProfSectNameCommon[] = …;
const char *InstrProfSectNameCoff[] = …;
const char *InstrProfSectNamePrefix[] = …;
}
namespace llvm {
cl::opt<bool> DoInstrProfNameCompression(
"enable-name-compression",
cl::desc("Enable name/filename string compression"), cl::init(true));
cl::opt<bool> EnableVTableValueProfiling(
"enable-vtable-value-profiling", cl::init(false),
cl::desc("If true, the virtual table address will be instrumented to know "
"the types of a C++ pointer. The information is used in indirect "
"call promotion to do selective vtable-based comparison."));
cl::opt<bool> EnableVTableProfileUse(
"enable-vtable-profile-use", cl::init(false),
cl::desc("If ThinLTO and WPD is enabled and this option is true, vtable "
"profiles will be used by ICP pass for more efficient indirect "
"call sequence. If false, type profiles won't be used."));
std::string getInstrProfSectionName(InstrProfSectKind IPSK,
Triple::ObjectFormatType OF,
bool AddSegmentInfo) { … }
std::string InstrProfError::message() const { … }
char InstrProfError::ID = …;
std::string getPGOFuncName(StringRef Name, GlobalValue::LinkageTypes Linkage,
StringRef FileName,
uint64_t Version LLVM_ATTRIBUTE_UNUSED) { … }
static StringRef stripDirPrefix(StringRef PathNameStr, uint32_t NumPrefix) { … }
static StringRef getStrippedSourceFileName(const GlobalObject &GO) { … }
static std::string
getIRPGONameForGlobalObject(const GlobalObject &GO,
GlobalValue::LinkageTypes Linkage,
StringRef FileName) { … }
static std::optional<std::string> lookupPGONameFromMetadata(MDNode *MD) { … }
static std::string getIRPGOObjectName(const GlobalObject &GO, bool InLTO,
MDNode *PGONameMetadata) { … }
std::string getIRPGOFuncName(const Function &F, bool InLTO) { … }
std::string getPGOFuncName(const Function &F, bool InLTO, uint64_t Version) { … }
std::string getPGOName(const GlobalVariable &V, bool InLTO) { … }
std::pair<StringRef, StringRef> getParsedIRPGOName(StringRef IRPGOName) { … }
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) { … }
std::string getPGOFuncNameVarName(StringRef FuncName,
GlobalValue::LinkageTypes Linkage) { … }
bool isGPUProfTarget(const Module &M) { … }
void setPGOFuncVisibility(Module &M, GlobalVariable *FuncNameVar) { … }
GlobalVariable *createPGOFuncNameVar(Module &M,
GlobalValue::LinkageTypes Linkage,
StringRef PGOFuncName) { … }
GlobalVariable *createPGOFuncNameVar(Function &F, StringRef PGOFuncName) { … }
Error InstrProfSymtab::create(Module &M, bool InLTO) { … }
Error InstrProfSymtab::addVTableWithName(GlobalVariable &VTable,
StringRef VTablePGOName) { … }
static Error
readAndDecodeStrings(StringRef NameStrings,
std::function<Error(StringRef)> NameCallback) { … }
Error InstrProfSymtab::create(StringRef NameStrings) { … }
Error InstrProfSymtab::create(StringRef FuncNameStrings,
StringRef VTableNameStrings) { … }
Error InstrProfSymtab::initVTableNamesFromCompressedStrings(
StringRef CompressedVTableStrings) { … }
StringRef InstrProfSymtab::getCanonicalName(StringRef PGOName) { … }
Error InstrProfSymtab::addFuncWithName(Function &F, StringRef PGOFuncName) { … }
uint64_t InstrProfSymtab::getVTableHashFromAddress(uint64_t Address) { … }
uint64_t InstrProfSymtab::getFunctionHashFromAddress(uint64_t Address) { … }
void InstrProfSymtab::dumpNames(raw_ostream &OS) const { … }
Error collectGlobalObjectNameStrings(ArrayRef<std::string> NameStrs,
bool DoCompression, std::string &Result) { … }
StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar) { … }
Error collectPGOFuncNameStrings(ArrayRef<GlobalVariable *> NameVars,
std::string &Result, bool DoCompression) { … }
Error collectVTableStrings(ArrayRef<GlobalVariable *> VTables,
std::string &Result, bool DoCompression) { … }
void InstrProfRecord::accumulateCounts(CountSumOrPercent &Sum) const { … }
void InstrProfValueSiteRecord::overlap(InstrProfValueSiteRecord &Input,
uint32_t ValueKind,
OverlapStats &Overlap,
OverlapStats &FuncLevelOverlap) { … }
void InstrProfRecord::overlapValueProfData(uint32_t ValueKind,
InstrProfRecord &Other,
OverlapStats &Overlap,
OverlapStats &FuncLevelOverlap) { … }
void InstrProfRecord::overlap(InstrProfRecord &Other, OverlapStats &Overlap,
OverlapStats &FuncLevelOverlap,
uint64_t ValueCutoff) { … }
void InstrProfValueSiteRecord::merge(InstrProfValueSiteRecord &Input,
uint64_t Weight,
function_ref<void(instrprof_error)> Warn) { … }
void InstrProfValueSiteRecord::scale(uint64_t N, uint64_t D,
function_ref<void(instrprof_error)> Warn) { … }
void InstrProfRecord::mergeValueProfData(
uint32_t ValueKind, InstrProfRecord &Src, uint64_t Weight,
function_ref<void(instrprof_error)> Warn) { … }
void InstrProfRecord::merge(InstrProfRecord &Other, uint64_t Weight,
function_ref<void(instrprof_error)> Warn) { … }
void InstrProfRecord::scaleValueProfData(
uint32_t ValueKind, uint64_t N, uint64_t D,
function_ref<void(instrprof_error)> Warn) { … }
void InstrProfRecord::scale(uint64_t N, uint64_t D,
function_ref<void(instrprof_error)> Warn) { … }
uint64_t InstrProfRecord::remapValue(uint64_t Value, uint32_t ValueKind,
InstrProfSymtab *SymTab) { … }
void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site,
ArrayRef<InstrProfValueData> VData,
InstrProfSymtab *ValueMap) { … }
void TemporalProfTraceTy::createBPFunctionNodes(
ArrayRef<TemporalProfTraceTy> Traces, std::vector<BPFunctionNode> &Nodes,
bool RemoveOutlierUNs) { … }
#define INSTR_PROF_COMMON_API_IMPL
#include "llvm/ProfileData/InstrProfData.inc"
uint32_t getNumValueKindsInstrProf(const void *Record) { … }
uint32_t getNumValueSitesInstrProf(const void *Record, uint32_t VKind) { … }
uint32_t getNumValueDataInstrProf(const void *Record, uint32_t VKind) { … }
uint32_t getNumValueDataForSiteInstrProf(const void *R, uint32_t VK,
uint32_t S) { … }
void getValueForSiteInstrProf(const void *R, InstrProfValueData *Dst,
uint32_t K, uint32_t S) { … }
ValueProfData *allocValueProfDataInstrProf(size_t TotalSizeInBytes) { … }
static ValueProfRecordClosure InstrProfRecordClosure = …;
uint32_t ValueProfData::getSize(const InstrProfRecord &Record) { … }
std::unique_ptr<ValueProfData>
ValueProfData::serializeFrom(const InstrProfRecord &Record) { … }
void ValueProfRecord::deserializeTo(InstrProfRecord &Record,
InstrProfSymtab *SymTab) { … }
void ValueProfRecord::swapBytes(llvm::endianness Old, llvm::endianness New) { … }
void ValueProfData::deserializeTo(InstrProfRecord &Record,
InstrProfSymtab *SymTab) { … }
static std::unique_ptr<ValueProfData> allocValueProfData(uint32_t TotalSize) { … }
Error ValueProfData::checkIntegrity() { … }
Expected<std::unique_ptr<ValueProfData>>
ValueProfData::getValueProfData(const unsigned char *D,
const unsigned char *const BufferEnd,
llvm::endianness Endianness) { … }
void ValueProfData::swapBytesToHost(llvm::endianness Endianness) { … }
void ValueProfData::swapBytesFromHost(llvm::endianness Endianness) { … }
void annotateValueSite(Module &M, Instruction &Inst,
const InstrProfRecord &InstrProfR,
InstrProfValueKind ValueKind, uint32_t SiteIdx,
uint32_t MaxMDCount) { … }
void annotateValueSite(Module &M, Instruction &Inst,
ArrayRef<InstrProfValueData> VDs,
uint64_t Sum, InstrProfValueKind ValueKind,
uint32_t MaxMDCount) { … }
MDNode *mayHaveValueProfileOfKind(const Instruction &Inst,
InstrProfValueKind ValueKind) { … }
SmallVector<InstrProfValueData, 4>
getValueProfDataFromInst(const Instruction &Inst, InstrProfValueKind ValueKind,
uint32_t MaxNumValueData, uint64_t &TotalC,
bool GetNoICPValue) { … }
MDNode *getPGOFuncNameMetadata(const Function &F) { … }
static void createPGONameMetadata(GlobalObject &GO, StringRef MetadataName,
StringRef PGOName) { … }
void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName) { … }
void createPGONameMetadata(GlobalObject &GO, StringRef PGOName) { … }
bool needsComdatForCounter(const GlobalObject &GO, const Module &M) { … }
bool isIRPGOFlagSet(const Module *M) { … }
bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken) { … }
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput) { … }
Error OverlapStats::accumulateCounts(const std::string &BaseFilename,
const std::string &TestFilename,
bool IsCS) { … }
void OverlapStats::addOneMismatch(const CountSumOrPercent &MismatchFunc) { … }
void OverlapStats::addOneUnique(const CountSumOrPercent &UniqueFunc) { … }
void OverlapStats::dump(raw_fd_ostream &OS) const { … }
namespace IndexedInstrProf {
Expected<Header> Header::readFromBuffer(const unsigned char *Buffer) { … }
uint64_t Header::getIndexedProfileVersion() const { … }
size_t Header::size() const { … }
}
}