Skip to content

Commit 348cfaf

Browse files
committed
[BOLT][NFC] Add allocator id to createInstrIncMemory
On RISC-V, this function will have to insert `auipc`+`lw`/`sw` pairs where the `auipc` needs a label annotation (see llvm#66395). In order to do this correctly within the context of `ParallelUtilities`, we need an allocator id when setting the label. This patch adds this allocator id argument and wires it through to all call sites. Note that this function is also made non-const since `setLabel` is non-const.
1 parent 49cb159 commit 348cfaf

File tree

5 files changed

+42
-37
lines changed

5 files changed

+42
-37
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,10 @@ class MCPlusBuilder {
504504
}
505505

506506
/// Create increment contents of target by 1 for Instrumentation
507-
virtual InstructionListType
508-
createInstrIncMemory(const MCSymbol *Target, MCContext *Ctx, bool IsLeaf,
509-
unsigned CodePointerSize) const {
507+
virtual InstructionListType createInstrIncMemory(const MCSymbol *Target,
508+
MCContext *Ctx, bool IsLeaf,
509+
unsigned CodePointerSize,
510+
AllocatorIdTy AllocatorId) {
510511
llvm_unreachable("not implemented");
511512
return InstructionListType();
512513
}

bolt/include/bolt/Passes/Instrumentation.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ class Instrumentation : public BinaryFunctionPass {
6464
void createLeafNodeDescription(FunctionDescription &FuncDesc, uint32_t Node);
6565

6666
/// Create the sequence of instructions to increment a counter
67-
InstructionListType createInstrumentationSnippet(BinaryContext &BC,
68-
bool IsLeaf);
67+
InstructionListType
68+
createInstrumentationSnippet(BinaryContext &BC, bool IsLeaf,
69+
MCPlusBuilder::AllocatorIdTy AllocatorId);
6970

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

9493
void instrumentLeafNode(BinaryBasicBlock &BB, BinaryBasicBlock::iterator Iter,
9594
bool IsLeaf, FunctionDescription &FuncDesc,
96-
uint32_t Node);
95+
uint32_t Node,
96+
MCPlusBuilder::AllocatorIdTy AllocatorId);
9797

9898
void instrumentIndirectTarget(BinaryBasicBlock &BB,
9999
BinaryBasicBlock::iterator &Iter,

bolt/lib/Passes/Instrumentation.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,14 @@ void Instrumentation::createLeafNodeDescription(FunctionDescription &FuncDesc,
190190
FuncDesc.LeafNodes.emplace_back(IN);
191191
}
192192

193-
InstructionListType
194-
Instrumentation::createInstrumentationSnippet(BinaryContext &BC, bool IsLeaf) {
193+
InstructionListType Instrumentation::createInstrumentationSnippet(
194+
BinaryContext &BC, bool IsLeaf, MCPlusBuilder::AllocatorIdTy AllocatorId) {
195195
auto L = BC.scopeLock();
196196
MCSymbol *Label = BC.Ctx->createNamedTempSymbol("InstrEntry");
197197
Summary->Counters.emplace_back(Label);
198198
return BC.MIB->createInstrIncMemory(Label, BC.Ctx.get(), IsLeaf,
199-
BC.AsmInfo->getCodePointerSize());
199+
BC.AsmInfo->getCodePointerSize(),
200+
AllocatorId);
200201
}
201202

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

213-
void Instrumentation::instrumentLeafNode(BinaryBasicBlock &BB,
214-
BinaryBasicBlock::iterator Iter,
215-
bool IsLeaf,
216-
FunctionDescription &FuncDesc,
217-
uint32_t Node) {
214+
void Instrumentation::instrumentLeafNode(
215+
BinaryBasicBlock &BB, BinaryBasicBlock::iterator Iter, bool IsLeaf,
216+
FunctionDescription &FuncDesc, uint32_t Node,
217+
MCPlusBuilder::AllocatorIdTy AllocatorId) {
218218
createLeafNodeDescription(FuncDesc, Node);
219219
InstructionListType CounterInstrs = createInstrumentationSnippet(
220-
BB.getFunction()->getBinaryContext(), IsLeaf);
220+
BB.getFunction()->getBinaryContext(), IsLeaf, AllocatorId);
221221
insertInstructions(CounterInstrs, BB, Iter);
222222
}
223223

@@ -247,7 +247,8 @@ bool Instrumentation::instrumentOneTarget(
247247
BinaryBasicBlock::iterator &Iter, BinaryFunction &FromFunction,
248248
BinaryBasicBlock &FromBB, uint32_t From, BinaryFunction &ToFunc,
249249
BinaryBasicBlock *TargetBB, uint32_t ToOffset, bool IsLeaf, bool IsInvoke,
250-
FunctionDescription *FuncDesc, uint32_t FromNodeID, uint32_t ToNodeID) {
250+
FunctionDescription *FuncDesc, uint32_t FromNodeID, uint32_t ToNodeID,
251+
MCPlusBuilder::AllocatorIdTy AllocatorId) {
251252
BinaryContext &BC = FromFunction.getBinaryContext();
252253
{
253254
auto L = BC.scopeLock();
@@ -263,7 +264,8 @@ bool Instrumentation::instrumentOneTarget(
263264
return false;
264265
}
265266

266-
InstructionListType CounterInstrs = createInstrumentationSnippet(BC, IsLeaf);
267+
InstructionListType CounterInstrs =
268+
createInstrumentationSnippet(BC, IsLeaf, AllocatorId);
267269

268270
const MCInst &Inst = *Iter;
269271
if (BC.MIB->isCall(Inst)) {
@@ -422,7 +424,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
422424
instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB,
423425
FromOffset, *TargetFunc, TargetBB, ToOffset,
424426
IsLeafFunction, IsInvokeBlock, FuncDesc,
425-
BBToID[&BB]);
427+
BBToID[&BB], 0, AllocId);
426428
}
427429
continue;
428430
}
@@ -438,7 +440,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
438440
instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB,
439441
FromOffset, *TargetFunc, TargetBB, ToOffset,
440442
IsLeafFunction, IsInvokeBlock, FuncDesc,
441-
BBToID[&BB], BBToID[TargetBB]);
443+
BBToID[&BB], BBToID[TargetBB], AllocId);
442444
continue;
443445
}
444446

@@ -455,7 +457,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
455457
instrumentOneTarget(
456458
SplitWorklist, SplitInstrs, I, Function, BB, FromOffset, Function,
457459
&*Succ, Succ->getInputOffset(), IsLeafFunction, IsInvokeBlock,
458-
FuncDesc, BBToID[&BB], BBToID[&*Succ]);
460+
FuncDesc, BBToID[&BB], BBToID[&*Succ], AllocId);
459461
}
460462
continue;
461463
}
@@ -498,7 +500,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
498500
instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB,
499501
FromOffset, Function, FTBB, FTBB->getInputOffset(),
500502
IsLeafFunction, IsInvokeBlock, FuncDesc, BBToID[&BB],
501-
BBToID[FTBB]);
503+
BBToID[FTBB], AllocId);
502504
}
503505
} // End of BBs loop
504506

@@ -508,7 +510,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
508510
BinaryBasicBlock &BB = *BBI;
509511
if (STOutSet[&BB].size() == 0)
510512
instrumentLeafNode(BB, BB.begin(), IsLeafFunction, *FuncDesc,
511-
BBToID[&BB]);
513+
BBToID[&BB], AllocId);
512514
}
513515
}
514516

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,9 +1542,10 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
15421542
return Insts;
15431543
}
15441544

1545-
InstructionListType
1546-
createInstrIncMemory(const MCSymbol *Target, MCContext *Ctx, bool IsLeaf,
1547-
unsigned CodePointerSize) const override {
1545+
InstructionListType createInstrIncMemory(const MCSymbol *Target,
1546+
MCContext *Ctx, bool IsLeaf,
1547+
unsigned CodePointerSize,
1548+
AllocatorIdTy AllocatorId) override {
15481549
unsigned int I = 0;
15491550
InstructionListType Instrs(IsLeaf ? 12 : 10);
15501551

bolt/lib/Target/X86/X86MCPlusBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,9 +3025,10 @@ class X86MCPlusBuilder : public MCPlusBuilder {
30253025
Inst.clear();
30263026
}
30273027

3028-
InstructionListType
3029-
createInstrIncMemory(const MCSymbol *Target, MCContext *Ctx, bool IsLeaf,
3030-
unsigned CodePointerSize) const override {
3028+
InstructionListType createInstrIncMemory(const MCSymbol *Target,
3029+
MCContext *Ctx, bool IsLeaf,
3030+
unsigned CodePointerSize,
3031+
AllocatorIdTy AllocatorId) override {
30313032
InstructionListType Instrs(IsLeaf ? 13 : 11);
30323033
unsigned int I = 0;
30333034

0 commit comments

Comments
 (0)