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
25 changes: 13 additions & 12 deletions compiler-rt/lib/ctx_profile/CtxInstrContextNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,19 @@ using GUID = uint64_t;
class ContextNode final {
const GUID Guid;
ContextNode *const Next;
const uint32_t NrCounters;
const uint32_t NrCallsites;
const uint32_t NumCounters;
const uint32_t NumCallsites;

public:
ContextNode(GUID Guid, uint32_t NrCounters, uint32_t NrCallsites,
ContextNode(GUID Guid, uint32_t NumCounters, uint32_t NumCallsites,
ContextNode *Next = nullptr)
: Guid(Guid), Next(Next), NrCounters(NrCounters),
NrCallsites(NrCallsites) {}
: Guid(Guid), Next(Next), NumCounters(NumCounters),
NumCallsites(NumCallsites) {}

static inline size_t getAllocSize(uint32_t NrCounters, uint32_t NrCallsites) {
return sizeof(ContextNode) + sizeof(uint64_t) * NrCounters +
sizeof(ContextNode *) * NrCallsites;
static inline size_t getAllocSize(uint32_t NumCounters,
uint32_t NumCallsites) {
return sizeof(ContextNode) + sizeof(uint64_t) * NumCounters +
sizeof(ContextNode *) * NumCallsites;
}

// The counters vector starts right after the static header.
Expand All @@ -88,16 +89,16 @@ class ContextNode final {
return reinterpret_cast<uint64_t *>(addr_after);
}

uint32_t counters_size() const { return NrCounters; }
uint32_t callsites_size() const { return NrCallsites; }
uint32_t counters_size() const { return NumCounters; }
uint32_t callsites_size() const { return NumCallsites; }

const uint64_t *counters() const {
return const_cast<ContextNode *>(this)->counters();
}

// The subcontexts vector starts right after the end of the counters vector.
ContextNode **subContexts() {
return reinterpret_cast<ContextNode **>(&(counters()[NrCounters]));
return reinterpret_cast<ContextNode **>(&(counters()[NumCounters]));
}

ContextNode *const *subContexts() const {
Expand All @@ -107,7 +108,7 @@ class ContextNode final {
GUID guid() const { return Guid; }
ContextNode *next() const { return Next; }

size_t size() const { return getAllocSize(NrCounters, NrCallsites); }
size_t size() const { return getAllocSize(NumCounters, NumCallsites); }

uint64_t entrycount() const { return counters()[0]; }
};
Expand Down
41 changes: 21 additions & 20 deletions compiler-rt/lib/ctx_profile/CtxInstrProfiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ bool validate(const ContextRoot *Root) {
}

inline ContextNode *allocContextNode(char *Place, GUID Guid,
uint32_t NrCounters, uint32_t NrCallsites,
uint32_t NumCounters,
uint32_t NumCallsites,
ContextNode *Next = nullptr) {
assert(reinterpret_cast<uint64_t>(Place) % ExpectedAlignment == 0);
return new (Place) ContextNode(Guid, NrCounters, NrCallsites, Next);
return new (Place) ContextNode(Guid, NumCounters, NumCallsites, Next);
}

void resetContextNode(ContextNode &Node) {
Expand Down Expand Up @@ -161,8 +162,8 @@ void Arena::freeArenaList(Arena *&A) {
// If this is the first time we hit a callsite with this (Guid) particular
// callee, we need to allocate.
ContextNode *getCallsiteSlow(GUID Guid, ContextNode **InsertionPoint,
uint32_t NrCounters, uint32_t NrCallsites) {
auto AllocSize = ContextNode::getAllocSize(NrCounters, NrCallsites);
uint32_t NumCounters, uint32_t NumCallsites) {
auto AllocSize = ContextNode::getAllocSize(NumCounters, NumCallsites);
auto *Mem = __llvm_ctx_profile_current_context_root->CurrentMem;
char *AllocPlace = Mem->tryBumpAllocate(AllocSize);
if (!AllocPlace) {
Expand All @@ -175,15 +176,15 @@ ContextNode *getCallsiteSlow(GUID Guid, ContextNode **InsertionPoint,
Mem->allocateNewArena(getArenaAllocSize(AllocSize), Mem);
AllocPlace = Mem->tryBumpAllocate(AllocSize);
}
auto *Ret = allocContextNode(AllocPlace, Guid, NrCounters, NrCallsites,
auto *Ret = allocContextNode(AllocPlace, Guid, NumCounters, NumCallsites,
*InsertionPoint);
*InsertionPoint = Ret;
return Ret;
}

ContextNode *__llvm_ctx_profile_get_context(void *Callee, GUID Guid,
uint32_t NrCounters,
uint32_t NrCallsites) {
uint32_t NumCounters,
uint32_t NumCallsites) {
// fast "out" if we're not even doing contextual collection.
if (!__llvm_ctx_profile_current_context_root)
return TheScratchContext;
Expand Down Expand Up @@ -222,34 +223,34 @@ ContextNode *__llvm_ctx_profile_get_context(void *Callee, GUID Guid,
Callsite = Callsite->next();
}
auto *Ret = Callsite ? Callsite
: getCallsiteSlow(Guid, CallsiteContext, NrCounters,
NrCallsites);
if (Ret->callsites_size() != NrCallsites ||
Ret->counters_size() != NrCounters)
: getCallsiteSlow(Guid, CallsiteContext, NumCounters,
NumCallsites);
if (Ret->callsites_size() != NumCallsites ||
Ret->counters_size() != NumCounters)
__sanitizer::Printf("[ctxprof] Returned ctx differs from what's asked: "
"Context: %p, Asked: %lu %u %u, Got: %lu %u %u \n",
reinterpret_cast<void *>(Ret), Guid, NrCallsites,
NrCounters, Ret->guid(), Ret->callsites_size(),
reinterpret_cast<void *>(Ret), Guid, NumCallsites,
NumCounters, Ret->guid(), Ret->callsites_size(),
Ret->counters_size());
onContextEnter(*Ret);
return Ret;
}

// This should be called once for a Root. Allocate the first arena, set up the
// first context.
void setupContext(ContextRoot *Root, GUID Guid, uint32_t NrCounters,
uint32_t NrCallsites) {
void setupContext(ContextRoot *Root, GUID Guid, uint32_t NumCounters,
uint32_t NumCallsites) {
__sanitizer::GenericScopedLock<__sanitizer::SpinMutex> Lock(
&AllContextsMutex);
// Re-check - we got here without having had taken a lock.
if (Root->FirstMemBlock)
return;
const auto Needed = ContextNode::getAllocSize(NrCounters, NrCallsites);
const auto Needed = ContextNode::getAllocSize(NumCounters, NumCallsites);
auto *M = Arena::allocateNewArena(getArenaAllocSize(Needed));
Root->FirstMemBlock = M;
Root->CurrentMem = M;
Root->FirstNode = allocContextNode(M->tryBumpAllocate(Needed), Guid,
NrCounters, NrCallsites);
NumCounters, NumCallsites);
AllContextRoots.PushBack(Root);
}

Expand Down Expand Up @@ -278,19 +279,19 @@ void __llvm_ctx_profile_release_context(ContextRoot *Root)
}

void __llvm_ctx_profile_start_collection() {
size_t NrMemUnits = 0;
size_t NumMemUnits = 0;
__sanitizer::GenericScopedLock<__sanitizer::SpinMutex> Lock(
&AllContextsMutex);
for (uint32_t I = 0; I < AllContextRoots.Size(); ++I) {
auto *Root = AllContextRoots[I];
__sanitizer::GenericScopedLock<__sanitizer::StaticSpinMutex> Lock(
&Root->Taken);
for (auto *Mem = Root->FirstMemBlock; Mem; Mem = Mem->next())
++NrMemUnits;
++NumMemUnits;

resetContextNode(*Root->FirstNode);
}
__sanitizer::Printf("[ctxprof] Initial NrMemUnits: %zu \n", NrMemUnits);
__sanitizer::Printf("[ctxprof] Initial NumMemUnits: %zu \n", NumMemUnits);
}

bool __llvm_ctx_profile_fetch(void *Data,
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/ctx_profile/CtxInstrProfiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ void __llvm_ctx_profile_release_context(__ctx_profile::ContextRoot *Root);
/// called for any other function than entry points, in the entry BB of such
/// function. Same consideration about LSB of returned value as .._start_context
ContextNode *__llvm_ctx_profile_get_context(void *Callee, GUID Guid,
uint32_t NrCounters,
uint32_t NrCallsites);
uint32_t NumCounters,
uint32_t NumCallsites);

/// Prepares for collection. Currently this resets counter values but preserves
/// internal context tree structure.
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Analysis/MLModelRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class MLModelRunner {
virtual void switchContext(StringRef Name) {}

protected:
MLModelRunner(LLVMContext &Ctx, Kind Type, size_t NrInputs)
: Ctx(Ctx), Type(Type), InputBuffers(NrInputs) {
MLModelRunner(LLVMContext &Ctx, Kind Type, size_t NumInputs)
: Ctx(Ctx), Type(Type), InputBuffers(NumInputs) {
assert(Type != Kind::Unknown);
}
virtual void *evaluateUntyped() = 0;
Expand Down
25 changes: 13 additions & 12 deletions llvm/include/llvm/ProfileData/CtxInstrContextNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,19 @@ using GUID = uint64_t;
class ContextNode final {
const GUID Guid;
ContextNode *const Next;
const uint32_t NrCounters;
const uint32_t NrCallsites;
const uint32_t NumCounters;
const uint32_t NumCallsites;

public:
ContextNode(GUID Guid, uint32_t NrCounters, uint32_t NrCallsites,
ContextNode(GUID Guid, uint32_t NumCounters, uint32_t NumCallsites,
ContextNode *Next = nullptr)
: Guid(Guid), Next(Next), NrCounters(NrCounters),
NrCallsites(NrCallsites) {}
: Guid(Guid), Next(Next), NumCounters(NumCounters),
NumCallsites(NumCallsites) {}

static inline size_t getAllocSize(uint32_t NrCounters, uint32_t NrCallsites) {
return sizeof(ContextNode) + sizeof(uint64_t) * NrCounters +
sizeof(ContextNode *) * NrCallsites;
static inline size_t getAllocSize(uint32_t NumCounters,
uint32_t NumCallsites) {
return sizeof(ContextNode) + sizeof(uint64_t) * NumCounters +
sizeof(ContextNode *) * NumCallsites;
}

// The counters vector starts right after the static header.
Expand All @@ -88,16 +89,16 @@ class ContextNode final {
return reinterpret_cast<uint64_t *>(addr_after);
}

uint32_t counters_size() const { return NrCounters; }
uint32_t callsites_size() const { return NrCallsites; }
uint32_t counters_size() const { return NumCounters; }
uint32_t callsites_size() const { return NumCallsites; }

const uint64_t *counters() const {
return const_cast<ContextNode *>(this)->counters();
}

// The subcontexts vector starts right after the end of the counters vector.
ContextNode **subContexts() {
return reinterpret_cast<ContextNode **>(&(counters()[NrCounters]));
return reinterpret_cast<ContextNode **>(&(counters()[NumCounters]));
}

ContextNode *const *subContexts() const {
Expand All @@ -107,7 +108,7 @@ class ContextNode final {
GUID guid() const { return Guid; }
ContextNode *next() const { return Next; }

size_t size() const { return getAllocSize(NrCounters, NrCallsites); }
size_t size() const { return getAllocSize(NumCounters, NumCallsites); }

uint64_t entrycount() const { return counters()[0]; }
};
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static cl::opt<unsigned> CallWithManyArgumentsThreshold(
"it is considered having many arguments."));

namespace {
int64_t getNrBlocksFromCond(const BasicBlock &BB) {
int64_t getNumBlocksFromCond(const BasicBlock &BB) {
int64_t Ret = 0;
if (const auto *BI = dyn_cast<BranchInst>(BB.getTerminator())) {
if (BI->isConditional())
Expand All @@ -72,7 +72,7 @@ void FunctionPropertiesInfo::updateForBB(const BasicBlock &BB,
assert(Direction == 1 || Direction == -1);
BasicBlockCount += Direction;
BlocksReachedFromConditionalInstruction +=
(Direction * getNrBlocksFromCond(BB));
(Direction * getNumBlocksFromCond(BB));
for (const auto &I : BB) {
if (auto *CS = dyn_cast<CallBase>(&I)) {
const auto *Callee = CS->getCalledFunction();
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Analysis/MLInlineAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ std::unique_ptr<InlineAdvice> MLInlineAdvisor::getAdviceImpl(CallBase &CB) {
if (Mandatory)
return getMandatoryAdvice(CB, true);

auto NrCtantParams = 0;
auto NumCtantParams = 0;
for (auto I = CB.arg_begin(), E = CB.arg_end(); I != E; ++I) {
NrCtantParams += (isa<Constant>(*I));
NumCtantParams += (isa<Constant>(*I));
}

auto &CallerBefore = getCachedFPI(Caller);
Expand All @@ -414,7 +414,7 @@ std::unique_ptr<InlineAdvice> MLInlineAdvisor::getAdviceImpl(CallBase &CB) {
getInitialFunctionLevel(Caller);
*ModelRunner->getTensor<int64_t>(FeatureIndex::node_count) = NodeCount;
*ModelRunner->getTensor<int64_t>(FeatureIndex::nr_ctant_params) =
NrCtantParams;
NumCtantParams;
*ModelRunner->getTensor<int64_t>(FeatureIndex::edge_count) = EdgeCount;
*ModelRunner->getTensor<int64_t>(FeatureIndex::caller_users) =
CallerBefore.Uses;
Expand Down
Loading