Skip to content

Commit b336d74

Browse files
authored
[BOLT] Use direct storage for Label annotations. NFCI. (#70147)
Store the Label annotation directly in the operand and avoid the extra allocation and indirection overheads associated with MCSimpleAnnotation.
1 parent 2400c54 commit b336d74

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ class MCPlusBuilder {
11811181

11821182
/// Set the label of \p Inst. This label will be emitted right before \p Inst
11831183
/// is emitted to MCStreamer.
1184-
bool setLabel(MCInst &Inst, MCSymbol *Label, AllocatorIdTy AllocatorId = 0);
1184+
bool setLabel(MCInst &Inst, MCSymbol *Label) const;
11851185

11861186
/// Return MCSymbol that represents a target of this instruction at a given
11871187
/// operand number \p OpNum. If there's no symbol associated with
@@ -1816,6 +1816,8 @@ class MCPlusBuilder {
18161816
const ValueType &addAnnotation(MCInst &Inst, unsigned Index,
18171817
const ValueType &Val,
18181818
AllocatorIdTy AllocatorId = 0) {
1819+
assert(Index >= MCPlus::MCAnnotation::kGeneric &&
1820+
"Generic annotation type expected.");
18191821
assert(!hasAnnotation(Inst, Index));
18201822
AnnotationAllocator &Allocator = getAnnotationAllocator(AllocatorId);
18211823
auto *A = new (Allocator.ValueAllocator)

bolt/lib/Core/MCPlusBuilder.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,15 @@ bool MCPlusBuilder::clearOffset(MCInst &Inst) const {
267267
}
268268

269269
MCSymbol *MCPlusBuilder::getLabel(const MCInst &Inst) const {
270-
if (auto Label = tryGetAnnotationAs<MCSymbol *>(Inst, MCAnnotation::kLabel))
271-
return *Label;
270+
if (std::optional<int64_t> Label =
271+
getAnnotationOpValue(Inst, MCAnnotation::kLabel))
272+
return reinterpret_cast<MCSymbol *>(*Label);
272273
return nullptr;
273274
}
274275

275-
bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label,
276-
AllocatorIdTy AllocatorId) {
277-
getOrCreateAnnotationAs<MCSymbol *>(Inst, MCAnnotation::kLabel, AllocatorId) =
278-
Label;
276+
bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label) const {
277+
setAnnotationOpValue(Inst, MCAnnotation::kLabel,
278+
reinterpret_cast<int64_t>(Label));
279279
return true;
280280
}
281281

0 commit comments

Comments
 (0)