[PATCH] D120781: [IRLinker] materialize Functions before moving any
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 4 16:22:41 PST 2022
nickdesaulniers updated this revision to Diff 413166.
nickdesaulniers marked an inline comment as done.
nickdesaulniers added a comment.
- update test to check for good blockaddresses, as per @dexonsmith
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120781/new/
https://reviews.llvm.org/D120781
Files:
llvm/lib/Linker/IRMover.cpp
llvm/test/Linker/blockaddress.ll
Index: llvm/test/Linker/blockaddress.ll
===================================================================
--- /dev/null
+++ llvm/test/Linker/blockaddress.ll
@@ -0,0 +1,67 @@
+; RUN: llvm-as %s -o %t.bc
+; RUN: llvm-link %t.bc -S | FileCheck %s
+
+declare void @f(i8*)
+
+; Test that a blockaddress in @y referring to %label in @x can be moved when @y
+; appears after @x.
+define void @x() {
+ br label %label
+
+label:
+ call void @y()
+ ret void
+}
+
+define void @y() {
+; CHECK: define void @y() {
+; CHECK-NEXT: call void @f(i8* blockaddress(@x, %label))
+ call void @f(i8* blockaddress(@x, %label))
+ ret void
+}
+
+; Test that a blockaddress in @a referring to %label in @b can be moved when @a
+; appears before @b.
+define void @a() {
+; CHECK: define void @a() {
+; CHECK-NEXT: call void @f(i8* blockaddress(@b, %label))
+ call void @f(i8* blockaddress(@b, %label))
+ ret void
+}
+
+define void @b() {
+ br label %label
+
+label:
+ call void @a()
+ ret void
+}
+
+; Test that @c and @d can both have blockaddress Constants that refer to one
+; another.
+
+define void @c() {
+; CHECK: define void @c() {
+; CHECK-NEXT: br label %label
+; CHECK-EMPTY:
+; CHECK-NEXT: label:
+; CHECK-NEXT: call void @f(i8* blockaddress(@d, %label))
+ br label %label
+
+label:
+ call void @f(i8* blockaddress(@d, %label))
+ ret void
+}
+
+define void @d() {
+; CHECK: define void @d() {
+; CHECK-NEXT: br label %label
+; CHECK-EMPTY:
+; CHECK-NEXT: label:
+; CHECK-NEXT: call void @f(i8* blockaddress(@c, %label))
+ br label %label
+
+label:
+ call void @f(i8* blockaddress(@c, %label))
+ ret void
+}
Index: llvm/lib/Linker/IRMover.cpp
===================================================================
--- llvm/lib/Linker/IRMover.cpp
+++ llvm/lib/Linker/IRMover.cpp
@@ -1516,6 +1516,15 @@
computeTypeMapping();
std::reverse(Worklist.begin(), Worklist.end());
+
+ // Materialize all Functions in Worklist prior to remapping otherwise
+ // blockaddress Constants may fail to materialize during IR moving.
+ for (GlobalValue *GV : Worklist)
+ if (auto *F = dyn_cast<Function>(GV))
+ if (!F->isDeclaration())
+ if (Error E = F->materialize())
+ return E;
+
while (!Worklist.empty()) {
GlobalValue *GV = Worklist.back();
Worklist.pop_back();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120781.413166.patch
Type: text/x-patch
Size: 2299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220305/681bdffd/attachment-0001.bin>
More information about the llvm-commits
mailing list