Skip to content

Commit

Permalink
[BOLT] Use direct storage for Label annotations. NFCI. (#70147)
Browse files Browse the repository at this point in the history
Store the Label annotation directly in the operand and avoid the extra
allocation and indirection overheads associated with MCSimpleAnnotation.
  • Loading branch information
maksfb committed Nov 6, 2023
1 parent 2400c54 commit b336d74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion bolt/include/bolt/Core/MCPlusBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ class MCPlusBuilder {

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

/// Return MCSymbol that represents a target of this instruction at a given
/// operand number \p OpNum. If there's no symbol associated with
Expand Down Expand Up @@ -1816,6 +1816,8 @@ class MCPlusBuilder {
const ValueType &addAnnotation(MCInst &Inst, unsigned Index,
const ValueType &Val,
AllocatorIdTy AllocatorId = 0) {
assert(Index >= MCPlus::MCAnnotation::kGeneric &&
"Generic annotation type expected.");
assert(!hasAnnotation(Inst, Index));
AnnotationAllocator &Allocator = getAnnotationAllocator(AllocatorId);
auto *A = new (Allocator.ValueAllocator)
Expand Down
12 changes: 6 additions & 6 deletions bolt/lib/Core/MCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,15 @@ bool MCPlusBuilder::clearOffset(MCInst &Inst) const {
}

MCSymbol *MCPlusBuilder::getLabel(const MCInst &Inst) const {
if (auto Label = tryGetAnnotationAs<MCSymbol *>(Inst, MCAnnotation::kLabel))
return *Label;
if (std::optional<int64_t> Label =
getAnnotationOpValue(Inst, MCAnnotation::kLabel))
return reinterpret_cast<MCSymbol *>(*Label);
return nullptr;
}

bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label,
AllocatorIdTy AllocatorId) {
getOrCreateAnnotationAs<MCSymbol *>(Inst, MCAnnotation::kLabel, AllocatorId) =
Label;
bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label) const {
setAnnotationOpValue(Inst, MCAnnotation::kLabel,
reinterpret_cast<int64_t>(Label));
return true;
}

Expand Down

0 comments on commit b336d74

Please sign in to comment.