Skip to content

[BOLT][NFC] Add allocator id to createInstrIncMemory #68709

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

Closed
wants to merge 2 commits into from
Closed
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: 2 additions & 1 deletion bolt/include/bolt/Core/MCPlusBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ class MCPlusBuilder {
/// Create increment contents of target by 1 for Instrumentation
virtual InstructionListType
createInstrIncMemory(const MCSymbol *Target, MCContext *Ctx, bool IsLeaf,
unsigned CodePointerSize) const {
unsigned CodePointerSize,
AllocatorIdTy AllocatorId = 0) {
llvm_unreachable("not implemented");
return InstructionListType();
}
Expand Down
24 changes: 12 additions & 12 deletions bolt/include/bolt/Passes/Instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ class Instrumentation : public BinaryFunctionPass {
void createLeafNodeDescription(FunctionDescription &FuncDesc, uint32_t Node);

/// Create the sequence of instructions to increment a counter
InstructionListType createInstrumentationSnippet(BinaryContext &BC,
bool IsLeaf);
InstructionListType
createInstrumentationSnippet(BinaryContext &BC, bool IsLeaf,
MCPlusBuilder::AllocatorIdTy AllocatorId);

// Critical edges worklist
// This worklist keeps track of CFG edges <From-To> that needs to be split.
Expand All @@ -81,19 +82,18 @@ class Instrumentation : public BinaryFunctionPass {
/// if this is a local branch and null if it is a call. Return true if the
/// location was instrumented with an explicit counter or false if it just
/// created the description, but no explicit counters were necessary.
bool instrumentOneTarget(SplitWorklistTy &SplitWorklist,
SplitInstrsTy &SplitInstrs,
BinaryBasicBlock::iterator &Iter,
BinaryFunction &FromFunction,
BinaryBasicBlock &FromBB, uint32_t From,
BinaryFunction &ToFunc, BinaryBasicBlock *TargetBB,
uint32_t ToOffset, bool IsLeaf, bool IsInvoke,
FunctionDescription *FuncDesc, uint32_t FromNodeID,
uint32_t ToNodeID = 0);
bool instrumentOneTarget(
SplitWorklistTy &SplitWorklist, SplitInstrsTy &SplitInstrs,
BinaryBasicBlock::iterator &Iter, BinaryFunction &FromFunction,
BinaryBasicBlock &FromBB, uint32_t From, BinaryFunction &ToFunc,
BinaryBasicBlock *TargetBB, uint32_t ToOffset, bool IsLeaf, bool IsInvoke,
FunctionDescription *FuncDesc, uint32_t FromNodeID, uint32_t ToNodeID,
MCPlusBuilder::AllocatorIdTy AllocatorId);

void instrumentLeafNode(BinaryBasicBlock &BB, BinaryBasicBlock::iterator Iter,
bool IsLeaf, FunctionDescription &FuncDesc,
uint32_t Node);
uint32_t Node,
MCPlusBuilder::AllocatorIdTy AllocatorId);

void instrumentIndirectTarget(BinaryBasicBlock &BB,
BinaryBasicBlock::iterator &Iter,
Expand Down
34 changes: 18 additions & 16 deletions bolt/lib/Passes/Instrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ void Instrumentation::createLeafNodeDescription(FunctionDescription &FuncDesc,
FuncDesc.LeafNodes.emplace_back(IN);
}

InstructionListType
Instrumentation::createInstrumentationSnippet(BinaryContext &BC, bool IsLeaf) {
InstructionListType Instrumentation::createInstrumentationSnippet(
BinaryContext &BC, bool IsLeaf, MCPlusBuilder::AllocatorIdTy AllocatorId) {
auto L = BC.scopeLock();
MCSymbol *Label = BC.Ctx->createNamedTempSymbol("InstrEntry");
Summary->Counters.emplace_back(Label);
return BC.MIB->createInstrIncMemory(Label, BC.Ctx.get(), IsLeaf,
BC.AsmInfo->getCodePointerSize());
BC.AsmInfo->getCodePointerSize(),
AllocatorId);
}

// Helper instruction sequence insertion function
Expand All @@ -210,14 +211,13 @@ insertInstructions(InstructionListType &Instrs, BinaryBasicBlock &BB,
return Iter;
}

void Instrumentation::instrumentLeafNode(BinaryBasicBlock &BB,
BinaryBasicBlock::iterator Iter,
bool IsLeaf,
FunctionDescription &FuncDesc,
uint32_t Node) {
void Instrumentation::instrumentLeafNode(
BinaryBasicBlock &BB, BinaryBasicBlock::iterator Iter, bool IsLeaf,
FunctionDescription &FuncDesc, uint32_t Node,
MCPlusBuilder::AllocatorIdTy AllocatorId) {
createLeafNodeDescription(FuncDesc, Node);
InstructionListType CounterInstrs = createInstrumentationSnippet(
BB.getFunction()->getBinaryContext(), IsLeaf);
BB.getFunction()->getBinaryContext(), IsLeaf, AllocatorId);
insertInstructions(CounterInstrs, BB, Iter);
}

Expand Down Expand Up @@ -247,7 +247,8 @@ bool Instrumentation::instrumentOneTarget(
BinaryBasicBlock::iterator &Iter, BinaryFunction &FromFunction,
BinaryBasicBlock &FromBB, uint32_t From, BinaryFunction &ToFunc,
BinaryBasicBlock *TargetBB, uint32_t ToOffset, bool IsLeaf, bool IsInvoke,
FunctionDescription *FuncDesc, uint32_t FromNodeID, uint32_t ToNodeID) {
FunctionDescription *FuncDesc, uint32_t FromNodeID, uint32_t ToNodeID,
MCPlusBuilder::AllocatorIdTy AllocatorId) {
BinaryContext &BC = FromFunction.getBinaryContext();
{
auto L = BC.scopeLock();
Expand All @@ -263,7 +264,8 @@ bool Instrumentation::instrumentOneTarget(
return false;
}

InstructionListType CounterInstrs = createInstrumentationSnippet(BC, IsLeaf);
InstructionListType CounterInstrs =
createInstrumentationSnippet(BC, IsLeaf, AllocatorId);

const MCInst &Inst = *Iter;
if (BC.MIB->isCall(Inst)) {
Expand Down Expand Up @@ -422,7 +424,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB,
FromOffset, *TargetFunc, TargetBB, ToOffset,
IsLeafFunction, IsInvokeBlock, FuncDesc,
BBToID[&BB]);
BBToID[&BB], 0, AllocId);
}
continue;
}
Expand All @@ -438,7 +440,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB,
FromOffset, *TargetFunc, TargetBB, ToOffset,
IsLeafFunction, IsInvokeBlock, FuncDesc,
BBToID[&BB], BBToID[TargetBB]);
BBToID[&BB], BBToID[TargetBB], AllocId);
continue;
}

Expand All @@ -455,7 +457,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
instrumentOneTarget(
SplitWorklist, SplitInstrs, I, Function, BB, FromOffset, Function,
&*Succ, Succ->getInputOffset(), IsLeafFunction, IsInvokeBlock,
FuncDesc, BBToID[&BB], BBToID[&*Succ]);
FuncDesc, BBToID[&BB], BBToID[&*Succ], AllocId);
}
continue;
}
Expand Down Expand Up @@ -498,7 +500,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB,
FromOffset, Function, FTBB, FTBB->getInputOffset(),
IsLeafFunction, IsInvokeBlock, FuncDesc, BBToID[&BB],
BBToID[FTBB]);
BBToID[FTBB], AllocId);
}
} // End of BBs loop

Expand All @@ -508,7 +510,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
BinaryBasicBlock &BB = *BBI;
if (STOutSet[&BB].size() == 0)
instrumentLeafNode(BB, BB.begin(), IsLeafFunction, *FuncDesc,
BBToID[&BB]);
BBToID[&BB], AllocId);
}
}

Expand Down
7 changes: 4 additions & 3 deletions bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1542,9 +1542,10 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
return Insts;
}

InstructionListType
createInstrIncMemory(const MCSymbol *Target, MCContext *Ctx, bool IsLeaf,
unsigned CodePointerSize) const override {
InstructionListType createInstrIncMemory(const MCSymbol *Target,
MCContext *Ctx, bool IsLeaf,
unsigned CodePointerSize,
AllocatorIdTy AllocatorId) override {
unsigned int I = 0;
InstructionListType Instrs(IsLeaf ? 12 : 10);

Expand Down
7 changes: 4 additions & 3 deletions bolt/lib/Target/X86/X86MCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3025,9 +3025,10 @@ class X86MCPlusBuilder : public MCPlusBuilder {
Inst.clear();
}

InstructionListType
createInstrIncMemory(const MCSymbol *Target, MCContext *Ctx, bool IsLeaf,
unsigned CodePointerSize) const override {
InstructionListType createInstrIncMemory(const MCSymbol *Target,
MCContext *Ctx, bool IsLeaf,
unsigned CodePointerSize,
AllocatorIdTy AllocatorId) override {
InstructionListType Instrs(IsLeaf ? 13 : 11);
unsigned int I = 0;

Expand Down