Skip to content

Commit 78b09d3

Browse files
committed
[CIR][LowerToLLVM] Make type converter aware of addrspace
1 parent 66ae6ca commit 78b09d3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3178,7 +3178,8 @@ void prepareTypeConverter(mlir::LLVMTypeConverter &converter,
31783178
mlir::DataLayout &dataLayout) {
31793179
converter.addConversion([&](mlir::cir::PointerType type) -> mlir::Type {
31803180
// Drop pointee type since LLVM dialect only allows opaque pointers.
3181-
return mlir::LLVM::LLVMPointerType::get(type.getContext());
3181+
return mlir::LLVM::LLVMPointerType::get(type.getContext(),
3182+
type.getAddrSpace());
31823183
});
31833184
converter.addConversion([&](mlir::cir::ArrayType type) -> mlir::Type {
31843185
auto ty = converter.convertType(type.getEltType());
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: cir-translate %s -cir-to-llvmir -o %t.ll
2+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
3+
4+
!s32i = !cir.int<s, 32>
5+
6+
module {
7+
// LLVM: define void @foo(ptr %0)
8+
cir.func @foo(%arg0: !cir.ptr<!s32i>) {
9+
// LLVM-NEXT: alloca ptr,
10+
%0 = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["arg", init] {alignment = 8 : i64}
11+
cir.return
12+
}
13+
14+
// LLVM: define void @bar(ptr addrspace(1) %0)
15+
cir.func @bar(%arg0: !cir.ptr<!s32i, 1>) {
16+
// LLVM-NEXT: alloca ptr addrspace(1)
17+
%0 = cir.alloca !cir.ptr<!s32i, 1>, !cir.ptr<!cir.ptr<!s32i, 1>>, ["arg", init] {alignment = 8 : i64}
18+
cir.return
19+
}
20+
}

0 commit comments

Comments
 (0)