Conversation
Member
|
@llvm/pr-subscribers-llvm-ir Author: Timur Baydyusenov (t-baydyusenov) ChangesAdded handling the case of a non-materialized module Full diff: https://github.com/llvm/llvm-project/pull/167487.diff 3 Files Affected:
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 0c8565c927a24..4d4ffe93a8067 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -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.
@@ -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) {
@@ -4001,7 +4001,7 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) {
Out << '"';
}
- printInfoComment(*GA);
+ printInfoComment(*GA, GA->isMaterializable());
Out << '\n';
}
@@ -4040,7 +4040,7 @@ void AssemblyWriter::printIFunc(const GlobalIFunc *GI) {
printMetadataAttachments(MDs, ", ");
}
- printInfoComment(*GI);
+ printInfoComment(*GI, GI->isMaterializable());
Out << '\n';
}
@@ -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)) {
diff --git a/llvm/test/Assembler/metadata-annotations.ll b/llvm/test/Assembler/metadata-annotations.ll
index 4fd471338cd0a..2a08a17849dbd 100644
--- a/llvm/test/Assembler/metadata-annotations.ll
+++ b/llvm/test/Assembler/metadata-annotations.ll
@@ -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()
diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp
index 35c540963a487..d6ef11b5c8ad9 100644
--- a/llvm/tools/llvm-dis/llvm-dis.cpp
+++ b/llvm/tools/llvm-dis/llvm-dis.cpp
@@ -101,13 +101,28 @@ 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.
+ if (!isa<GlobalValue>(&V))
+ return true;
+ const GlobalValue *GV = cast<GlobalValue>(&V);
+ return 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);
|
mtrofin
approved these changes
Nov 11, 2025
arsenm
reviewed
Nov 11, 2025
llvm/tools/llvm-dis/llvm-dis.cpp
Outdated
Comment on lines
107
to
110
| if (!isa<GlobalValue>(&V)) | ||
| return true; | ||
| const GlobalValue *GV = cast<GlobalValue>(&V); | ||
| return GV->getParent() && GV->getParent()->isMaterialized(); |
Contributor
There was a problem hiding this comment.
Suggested change
| if (!isa<GlobalValue>(&V)) | |
| return true; | |
| const GlobalValue *GV = cast<GlobalValue>(&V); | |
| return GV->getParent() && GV->getParent()->isMaterialized(); | |
| const GlobalValue *GV = dyn_cast<GlobalValue>(&V); | |
| return !GV || (GV->getParent() && GV->getParent()->isMaterialized()); |
…nnotations' crashes Added handling the case of a non-materialized module
b8df4ea to
6ccd912
Compare
arsenm
approved these changes
Nov 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added handling the case of a non-materialized module, also don't call printInfoComment for immaterializable values