Skip to content

[MLIR][LLVM] Add weak_odr to allowed linkage for alias #132840

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

Merged
merged 1 commit into from
Mar 25, 2025
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
1 change: 1 addition & 0 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,7 @@ LogicalResult AliasOp::verify() {
case Linkage::Internal:
case Linkage::Private:
case Linkage::Weak:
case Linkage::WeakODR:
case Linkage::Linkonce:
case Linkage::LinkonceODR:
case Linkage::AvailableExternally:
Expand Down
10 changes: 5 additions & 5 deletions mlir/test/Dialect/LLVMIR/alias.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ llvm.mlir.alias external @_ZTV1D : !llvm.struct<(array<3 x ptr>)> {

// -----

llvm.mlir.global external @zed(42 : i32) : i32
llvm.mlir.global weak_odr @zed(42 : i32) : i32

llvm.mlir.alias external @foo : i32 {
llvm.mlir.alias weak_odr @foo : i32 {
%0 = llvm.mlir.addressof @zed : !llvm.ptr
llvm.return %0 : !llvm.ptr
}

llvm.mlir.alias external @foo2 : i16 {
llvm.mlir.alias weak_odr @foo2 : i16 {
%0 = llvm.mlir.addressof @zed : !llvm.ptr
llvm.return %0 : !llvm.ptr
}

// CHECK: llvm.mlir.alias external @foo : i32 {
// CHECK: llvm.mlir.alias weak_odr @foo : i32 {
// CHECK: %[[ADDR:.*]] = llvm.mlir.addressof @zed : !llvm.ptr
// CHECK: llvm.return %[[ADDR]] : !llvm.ptr
// CHECK: }
// CHECK: llvm.mlir.alias external @foo2 : i16 {
// CHECK: llvm.mlir.alias weak_odr @foo2 : i16 {
// CHECK: %[[ADDR:.*]] = llvm.mlir.addressof @zed : !llvm.ptr
// CHECK: llvm.return %[[ADDR]] : !llvm.ptr
// CHECK: }
Expand Down
7 changes: 7 additions & 0 deletions mlir/test/Target/LLVMIR/Import/alias.ll
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ entry:

; // -----

@glob.private2 = private constant [32 x i32] zeroinitializer
@glob2 = weak_odr hidden alias [32 x i32], inttoptr (i64 add (i64 ptrtoint (ptr @glob.private2 to i64), i64 1234) to ptr)

; CHECK: llvm.mlir.alias weak_odr hidden @glob2 {dso_local} : !llvm.array<32 x i32> {

; // -----

@g1 = private global i32 0
@g2 = internal constant ptr @a1
@g3 = internal constant ptr @a2
Expand Down