Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion bolt/include/bolt/Core/MCPlusBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2190,7 +2190,8 @@ class MCPlusBuilder {
}

/// Print each annotation attached to \p Inst.
void printAnnotations(const MCInst &Inst, raw_ostream &OS) const;
void printAnnotations(const MCInst &Inst, raw_ostream &OS,
bool PrintMemData = false) const;

/// Remove annotation with a given \p Index.
///
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
if (MCSymbol *Label = MIB->getInstLabel(Instruction))
OS << " # Label: " << *Label;

MIB->printAnnotations(Instruction, OS);
MIB->printAnnotations(Instruction, OS, PrintMemData || opts::PrintMemData);

if (opts::PrintDebugInfo)
printDebugInfo(OS, Instruction, Function, DwCtx.get());
Expand Down
10 changes: 7 additions & 3 deletions bolt/lib/Core/MCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ void MCPlusBuilder::stripAnnotations(MCInst &Inst, bool KeepTC) const {
setTailCall(Inst);
}

void MCPlusBuilder::printAnnotations(const MCInst &Inst,
raw_ostream &OS) const {
void MCPlusBuilder::printAnnotations(const MCInst &Inst, raw_ostream &OS,
bool PrintMemData) const {
std::optional<unsigned> FirstAnnotationOp = getFirstAnnotationOpIndex(Inst);
if (!FirstAnnotationOp)
return;
Expand All @@ -390,7 +390,11 @@ void MCPlusBuilder::printAnnotations(const MCInst &Inst,
const int64_t Value = extractAnnotationValue(Imm);
const auto *Annotation = reinterpret_cast<const MCAnnotation *>(Value);
if (Index >= MCAnnotation::kGeneric) {
OS << " # " << AnnotationNames[Index - MCAnnotation::kGeneric] << ": ";
std::string AnnotationName =
AnnotationNames[Index - MCAnnotation::kGeneric];
if (!PrintMemData && AnnotationName == "MemoryAccessProfile")
Copy link
Member

@paschalis-mpeis paschalis-mpeis Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change overrides annotation printing to consider the flag. Previously it looks like those annotations were always printed, but now would only be printed if PrintMemData is true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if PrintMemData is enabled by default, then using a profile that includes memory access infomation will result in excessive printing of memory access details.

continue;
OS << " # " << AnnotationName << ": ";
Annotation->print(OS);
}
}
Expand Down
40 changes: 40 additions & 0 deletions bolt/test/AArch64/print-mem-data.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Check that --print-mem-data option works properly in llvm-bolt

# RUN: split-file %s %t
# RUN: %clang %cflags -fPIC -pie %t/main.s -o %t.exe -nostdlib -Wl,-q
# RUN: llvm-bolt %t.exe -o %t.bolt --print-mem-data=true --print-cfg \
# RUN: --data %t/fdata | FileCheck %s -check-prefix=CHECK-PRINT
# RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg \
# RUN: --data %t/fdata | FileCheck %s -check-prefix=CHECK-DEFAULT

# CHECK-PRINT: ldr w2, [x1], #0x4 # MemoryAccessProfile: 7 total counts :
# CHECK-PRINT-NEXT: { 0x123: 1 },
# CHECK-PRINT-NEXT: { 0x456: 2 },
# CHECK-PRINT-NEXT: { 0xabc: 4 }
# CHECK-DEFAULT-NOT: MemoryAccessProfile

#--- main.s
.text
.align 4
.global main
.type main, %function
main:
sub sp, sp, #48
add x1, sp, 8
add x3, sp, 48
mov w0, 0
.L2:
ldr w2, [x1], 4
add w0, w0, w2
cmp x1, x3
bne .L2
add sp, sp, 48
ret
.size main, .-main

# The three memory access data generated by the load at
# offset 0x10 in the main.
#--- fdata
4 main 10 4 otherSym 123 1
4 main 10 4 otherSym 456 2
4 main 10 4 otherSym abc 4
Loading