@@ -274,7 +274,9 @@ void CIRGenModule::constructAttributeList(
274274 // TODO(cir): add alloc size attr.
275275 }
276276
277- if (TargetDecl->hasAttr <DeviceKernelAttr>() && DeviceKernelAttr::isOpenCLSpelling (TargetDecl->getAttr <DeviceKernelAttr>())) {
277+ if (TargetDecl->hasAttr <DeviceKernelAttr>() &&
278+ DeviceKernelAttr::isOpenCLSpelling (
279+ TargetDecl->getAttr <DeviceKernelAttr>())) {
278280 auto cirKernelAttr = cir::OpenCLKernelAttr::get (&getMLIRContext ());
279281 funcAttrs.set (cirKernelAttr.getMnemonic (), cirKernelAttr);
280282
@@ -476,7 +478,7 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &CallInfo,
476478 I != E; ++I, ++type_it, ++ArgNo) {
477479
478480 mlir::Type argType = convertType (*type_it);
479- if (!mlir::isa<cir::RecordType>(argType)) {
481+ if (!mlir::isa<cir::RecordType, cir::ComplexType >(argType)) {
480482 mlir::Value V;
481483 assert (!I->isAggregate () && " Aggregate NYI" );
482484 V = I->getKnownRValue ().getScalarVal ();
@@ -496,16 +498,16 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &CallInfo,
496498 // FIXME: Avoid the conversion through memory if possible.
497499 Address Src = Address::invalid ();
498500 if (!I->isAggregate ()) {
499- llvm_unreachable (" NYI" );
501+ Src = CreateMemTemp (I->Ty , loc, " coerce" );
502+ I->copyInto (*this , Src, loc);
500503 } else {
501504 Src = I->hasLValue () ? I->getKnownLValue ().getAddress ()
502505 : I->getKnownRValue ().getAggregateAddress ();
503506 }
504507
505508 // Fast-isel and the optimizer generally like scalar values better than
506509 // FCAs, so we flatten them if this is safe to do for this argument.
507- auto STy = cast<cir::RecordType>(argType);
508- auto SrcTy = Src.getElementType ();
510+ auto srcTy = Src.getElementType ();
509511 // FIXME(cir): get proper location for each argument.
510512 auto argLoc = loc;
511513
@@ -519,13 +521,13 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &CallInfo,
519521 // uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
520522 // uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(STy);
521523 // if (SrcSize < DstSize) {
522- if (SrcTy != STy )
524+ if (srcTy != argType )
523525 llvm_unreachable (" NYI" );
524526 else {
525527 // FIXME(cir): this currently only runs when the types are different,
526528 // but should be when alloc sizes are different, fix this as soon as
527529 // datalayout gets introduced.
528- Src = builder.createElementBitCast (argLoc, Src, STy );
530+ Src = builder.createElementBitCast (argLoc, Src, argType );
529531 }
530532
531533 // assert(NumCIRArgs == STy.getMembers().size());
@@ -757,6 +759,18 @@ mlir::Value CIRGenFunction::emitRuntimeCall(mlir::Location loc,
757759 return call->getResult (0 );
758760}
759761
762+ void CallArg::copyInto (CIRGenFunction &cgf, Address addr,
763+ mlir::Location loc) const {
764+ LValue dst = cgf.makeAddrLValue (addr, Ty);
765+ if (!HasLV && RV.isScalar ())
766+ llvm_unreachable (" copyInto scalar value" );
767+ else if (!HasLV && RV.isComplex ())
768+ cgf.emitStoreOfComplex (loc, RV.getComplexVal (), dst, /* isInit=*/ true );
769+ else
770+ llvm_unreachable (" copyInto hasLV" );
771+ IsUsed = true ;
772+ }
773+
760774void CIRGenFunction::emitCallArg (CallArgList &args, const Expr *E,
761775 QualType type) {
762776 // TODO: Add the DisableDebugLocationUpdates helper
@@ -982,7 +996,8 @@ static void appendParameterTypes(
982996 for (unsigned I = 0 , E = FPT->getNumParams (); I != E; ++I) {
983997 prefix.push_back (FPT->getParamType (I));
984998 if (ExtInfos[I].hasPassObjectSize ())
985- prefix.push_back (CGT.getContext ().getCanonicalType (CGT.getContext ().getSizeType ()));
999+ prefix.push_back (
1000+ CGT.getContext ().getCanonicalType (CGT.getContext ().getSizeType ()));
9861001 }
9871002
9881003 addExtParameterInfosForCall (paramInfos, FPT.getTypePtr (), PrefixSize,
0 commit comments