@@ -2212,6 +2212,34 @@ 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+ assert (op.getNumResults () <= 1 );
2231+ if (op.getNumResults () > 0 ) {
2232+ mlir::DictionaryAttr resultAttrs = op.getResultAttrDict (0 );
2233+ if (resultAttrs) {
2234+ if (resultAttrs.get (cir::CIRDialect::getZExtAttrName ()))
2235+ fn.setResultAttr (0 , mlir::LLVM::LLVMDialect::getZExtAttrName (),
2236+ rewriter.getUnitAttr ());
2237+ if (resultAttrs.get (cir::CIRDialect::getSExtAttrName ()))
2238+ fn.setResultAttr (0 , mlir::LLVM::LLVMDialect::getSExtAttrName (),
2239+ rewriter.getUnitAttr ());
2240+ }
2241+ }
2242+
22152243 fn.setVisibility_Attr (mlir::LLVM::VisibilityAttr::get (
22162244 getContext (), lowerCIRVisibilityToLLVMVisibility (
22172245 op.getGlobalVisibilityAttr ().getValue ())));
0 commit comments