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
13 changes: 6 additions & 7 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2931,7 +2931,7 @@ class AssemblyWriter {

// printInfoComment - Print a little comment after the instruction indicating
// which slot it occupies.
void printInfoComment(const Value &V);
void printInfoComment(const Value &V, bool isMaterializable = false);

// printGCRelocateComment - print comment after call to the gc.relocate
// intrinsic indicating base and derived pointer names.
Expand Down Expand Up @@ -3963,7 +3963,7 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
if (Attrs.hasAttributes())
Out << " #" << Machine.getAttributeGroupSlot(Attrs);

printInfoComment(*GV);
printInfoComment(*GV, GV->isMaterializable());
}

void AssemblyWriter::printAlias(const GlobalAlias *GA) {
Expand Down Expand Up @@ -4001,7 +4001,7 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) {
Out << '"';
}

printInfoComment(*GA);
printInfoComment(*GA, GA->isMaterializable());
Out << '\n';
}

Expand Down Expand Up @@ -4040,7 +4040,7 @@ void AssemblyWriter::printIFunc(const GlobalIFunc *GI) {
printMetadataAttachments(MDs, ", ");
}

printInfoComment(*GI);
printInfoComment(*GI, GI->isMaterializable());
Out << '\n';
}

Expand Down Expand Up @@ -4319,13 +4319,12 @@ void AssemblyWriter::printGCRelocateComment(const GCRelocateInst &Relocate) {

/// printInfoComment - Print a little comment after the instruction indicating
/// which slot it occupies.
void AssemblyWriter::printInfoComment(const Value &V) {
void AssemblyWriter::printInfoComment(const Value &V, bool isMaterializable) {
if (const auto *Relocate = dyn_cast<GCRelocateInst>(&V))
printGCRelocateComment(*Relocate);

if (AnnotationWriter) {
if (AnnotationWriter && !isMaterializable)
AnnotationWriter->printInfoComment(V, Out);
}

if (PrintInstDebugLocs) {
if (auto *I = dyn_cast<Instruction>(&V)) {
Expand Down
22 changes: 18 additions & 4 deletions llvm/test/Assembler/metadata-annotations.ll
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
; RUN: llvm-as < %s | llvm-dis --materialize-metadata --show-annotations | FileCheck %s

; CHECK: @global_var = global i32 1
; CHECK: @alias = alias i32, ptr @global_var
; CHECK: @ifunc = ifunc i32 (), ptr @ifunc_resolver
@global_var = global i32 1
@alias = alias i32, ptr @global_var
@ifunc = ifunc i32 (), ptr @ifunc_resolver

; CHECK: ; Materializable
; CHECK-NEXT: define ptr @ifunc_resolver() {}
define ptr @ifunc_resolver() {
ret ptr @defined_function
}

; CHECK: ; Materializable
; CHECK-NEXT: define dso_local i32 @test() {}
define dso_local i32 @test() {
entry:
ret i32 0
; CHECK-NEXT: define void @defined_function() {}
define void @defined_function() {
ret void
}

; CHECK: declare void @declared_function()
declare void @declared_function()
13 changes: 13 additions & 0 deletions llvm/tools/llvm-dis/llvm-dis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,26 @@ static void printDebugLoc(const DebugLoc &DL, formatted_raw_ostream &OS) {
}
}
class CommentWriter : public AssemblyAnnotationWriter {
private:
bool canSafelyAccessUses(const Value &V) {
// Can't safely access uses, if module not materialized.
const GlobalValue *GV = dyn_cast<GlobalValue>(&V);
return !GV || (GV->getParent() && GV->getParent()->isMaterialized());
}

public:
void emitFunctionAnnot(const Function *F,
formatted_raw_ostream &OS) override {
if (!canSafelyAccessUses(*F))
return;

OS << "; [#uses=" << F->getNumUses() << ']'; // Output # uses
OS << '\n';
}
void printInfoComment(const Value &V, formatted_raw_ostream &OS) override {
if (!canSafelyAccessUses(V))
return;

bool Padded = false;
if (!V.getType()->isVoidTy()) {
OS.PadToColumn(50);
Expand Down
Loading