Skip to content

Commit aede7c4

Browse files
committed
[CIR] Lower signext and zeroext attributes
1 parent fa5b07c commit aede7c4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

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

+27
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,33 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewrite(
22122212
Loc, op.getName(), llvmFnTy, linkage, isDsoLocal, cconv,
22132213
mlir::SymbolRefAttr(), attributes);
22142214

2215+
// Lower CIR attributes for arguments.
2216+
for (unsigned index = 0; index < fnType.getNumInputs(); index++) {
2217+
mlir::DictionaryAttr cirAttrs = op.getArgAttrDict(index);
2218+
if (cirAttrs) {
2219+
if (cirAttrs.get(cir::CIRDialect::getZExtAttrName()))
2220+
fn.setArgAttr(index, mlir::LLVM::LLVMDialect::getZExtAttrName(),
2221+
rewriter.getUnitAttr());
2222+
if (cirAttrs.get(cir::CIRDialect::getSExtAttrName()))
2223+
fn.setArgAttr(index, mlir::LLVM::LLVMDialect::getSExtAttrName(),
2224+
rewriter.getUnitAttr());
2225+
}
2226+
}
2227+
2228+
// Lower CIR attributes for return value.
2229+
// Each function has no more than one result in CIR, so no need for a loop.
2230+
if (op.getNumResults() > 0) {
2231+
mlir::DictionaryAttr resultAttrs = op.getResultAttrDict(0);
2232+
if (resultAttrs) {
2233+
if (resultAttrs.get(cir::CIRDialect::getZExtAttrName()))
2234+
fn.setResultAttr(0, mlir::LLVM::LLVMDialect::getZExtAttrName(),
2235+
rewriter.getUnitAttr());
2236+
if (resultAttrs.get(cir::CIRDialect::getSExtAttrName()))
2237+
fn.setResultAttr(0, mlir::LLVM::LLVMDialect::getSExtAttrName(),
2238+
rewriter.getUnitAttr());
2239+
}
2240+
}
2241+
22152242
fn.setVisibility_Attr(mlir::LLVM::VisibilityAttr::get(
22162243
getContext(), lowerCIRVisibilityToLLVMVisibility(
22172244
op.getGlobalVisibilityAttr().getValue())));
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM
22

33
!s32i = !cir.int<s, 32>
4+
!s8i = !cir.int<u, 8>
5+
!u8i = !cir.int<u, 8>
46

57
module {
68
cir.global "private" internal @const_array = #cir.const_array<[#cir.int<1> : !s32i]> : !cir.array<!s32i x 1> {section = ".abc"}
79
// LLVM: @const_array = internal global [1 x i32] [i32 1], section ".abc"
810

911
cir.global "private" internal @const_struct = #cir.const_struct<{#cir.int<1> : !s32i}> : !cir.struct<struct {!s32i}> {section = ".abc"}
1012
// LLVM: @const_struct = internal global { i32 } { i32 1 }, section ".abc"
13+
14+
cir.func @func_zeroext(%arg0: !u8i {cir.zeroext}) -> (!u8i {cir.zeroext}) {
15+
cir.return %arg0 : !u8i
16+
}
17+
// LLVM: define zeroext i8 @func_zeroext(i8 zeroext %0)
18+
19+
cir.func @func_signext(%arg0: !s8i {cir.signext}) -> (!s8i {cir.signext}) {
20+
cir.return %arg0 : !s8i
21+
}
22+
// LLVM: define signext i8 @func_signext(i8 signext %0)
1123
}

0 commit comments

Comments
 (0)