diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h index c9e0e5d599b1f..dfb1f542107f5 100644 --- a/bolt/include/bolt/Core/MCPlusBuilder.h +++ b/bolt/include/bolt/Core/MCPlusBuilder.h @@ -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(); } diff --git a/bolt/include/bolt/Passes/Instrumentation.h b/bolt/include/bolt/Passes/Instrumentation.h index 1a11f9eab5110..67570e04e9cad 100644 --- a/bolt/include/bolt/Passes/Instrumentation.h +++ b/bolt/include/bolt/Passes/Instrumentation.h @@ -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 that needs to be split. @@ -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, diff --git a/bolt/lib/Passes/Instrumentation.cpp b/bolt/lib/Passes/Instrumentation.cpp index 72adb319d71dc..1f68772c4c3a3 100644 --- a/bolt/lib/Passes/Instrumentation.cpp +++ b/bolt/lib/Passes/Instrumentation.cpp @@ -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 @@ -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); } @@ -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(); @@ -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)) { @@ -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; } @@ -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; } @@ -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; } @@ -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 @@ -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); } } diff --git a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp index c2a4607411a49..1aa3fbce52df3 100644 --- a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp +++ b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp @@ -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); diff --git a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp index ce8a4d6914854..fbca503c348db 100644 --- a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp +++ b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp @@ -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;