Skip to content

Commit 48f3f84

Browse files
authored
[MLIR][mlir-link] Properly resolve LLVM dialect bitwidth for linkage (#39)
1 parent 535025d commit 48f3f84

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

mlir/lib/Dialect/LLVMIR/IR/LLVMLinkerInterface.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ bool mlir::LLVM::LLVMSymbolLinkerInterface::isDeclaration(Operation *op) {
7070
}
7171

7272
unsigned mlir::LLVM::LLVMSymbolLinkerInterface::getBitWidth(Operation *op) {
73-
if (auto gv = dyn_cast<LLVM::GlobalOp>(op))
74-
return gv.getType().getIntOrFloatBitWidth();
73+
if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) {
74+
auto type = gv.getType();
75+
auto dataLayout = DataLayout::closest(op);
76+
return dataLayout.getTypeSizeInBits(type);
77+
}
7578
llvm_unreachable("unexpected operation");
7679
}
7780

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: mlir-link -sort-symbols -split-input-file %s | FileCheck %s
2+
3+
// CHECK: llvm.mlir.global common @common_arr{{.*}}!llvm.array<18 x i32>
4+
5+
llvm.mlir.global common @common_arr(dense<0> : tensor<17xi32>) {addr_space = 0 : i32, alignment = 16 : i64, dso_local} : !llvm.array<17 x i32>
6+
7+
// -----
8+
9+
llvm.mlir.global common local_unnamed_addr @common_arr(dense<0> : tensor<18xi32>) {addr_space = 0 : i32, alignment = 16 : i64, dso_local} : !llvm.array<18 x i32>

0 commit comments

Comments
 (0)