Skip to content
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

[BOLT] Use direct storage for Label annotations. NFCI. #70147

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion bolt/include/bolt/Core/MCPlusBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,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);

/// 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 @@ -1820,6 +1820,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
16 changes: 9 additions & 7 deletions bolt/lib/Core/MCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,17 @@ bool MCPlusBuilder::clearOffset(MCInst &Inst) {
}

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

return reinterpret_cast<MCSymbol *>(*Label);
}

bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label,
AllocatorIdTy AllocatorId) {
getOrCreateAnnotationAs<MCSymbol *>(Inst, MCAnnotation::kLabel, AllocatorId) =
Label;
bool MCPlusBuilder::setLabel(MCInst &Inst, MCSymbol *Label) {
mtvec marked this conversation as resolved.
Show resolved Hide resolved
setAnnotationOpValue(Inst, MCAnnotation::kLabel,
reinterpret_cast<int64_t>(Label));
return true;
}

Expand Down