Skip to content

Commit

Permalink
[CIR][LowerToLLVM] Make type converter aware of addrspace
Browse files Browse the repository at this point in the history
  • Loading branch information
seven-mile committed May 15, 2024
1 parent 66ae6ca commit 78b09d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3178,7 +3178,8 @@ void prepareTypeConverter(mlir::LLVMTypeConverter &converter,
mlir::DataLayout &dataLayout) {
converter.addConversion([&](mlir::cir::PointerType type) -> mlir::Type {
// Drop pointee type since LLVM dialect only allows opaque pointers.
return mlir::LLVM::LLVMPointerType::get(type.getContext());
return mlir::LLVM::LLVMPointerType::get(type.getContext(),
type.getAddrSpace());
});
converter.addConversion([&](mlir::cir::ArrayType type) -> mlir::Type {
auto ty = converter.convertType(type.getEltType());
Expand Down
20 changes: 20 additions & 0 deletions clang/test/CIR/Lowering/address-space.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: cir-translate %s -cir-to-llvmir -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM

!s32i = !cir.int<s, 32>

module {
// LLVM: define void @foo(ptr %0)
cir.func @foo(%arg0: !cir.ptr<!s32i>) {
// LLVM-NEXT: alloca ptr,
%0 = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["arg", init] {alignment = 8 : i64}
cir.return
}

// LLVM: define void @bar(ptr addrspace(1) %0)
cir.func @bar(%arg0: !cir.ptr<!s32i, 1>) {
// LLVM-NEXT: alloca ptr addrspace(1)
%0 = cir.alloca !cir.ptr<!s32i, 1>, !cir.ptr<!cir.ptr<!s32i, 1>>, ["arg", init] {alignment = 8 : i64}
cir.return
}
}

0 comments on commit 78b09d3

Please sign in to comment.