@@ -1602,6 +1602,7 @@ void ClangToLLVMArgMapping::construct(const ASTContext &Context,
16021602 IRArgs.PaddingArgIndex = IRArgNo++;
16031603
16041604 switch (AI.getKind ()) {
1605+ case ABIArgInfo::TargetSpecific:
16051606 case ABIArgInfo::Extend:
16061607 case ABIArgInfo::Direct: {
16071608 // FIXME: handle sseregparm someday...
@@ -1712,6 +1713,7 @@ llvm::FunctionType *CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) {
17121713 case ABIArgInfo::IndirectAliased:
17131714 llvm_unreachable (" Invalid ABI kind for return argument" );
17141715
1716+ case ABIArgInfo::TargetSpecific:
17151717 case ABIArgInfo::Extend:
17161718 case ABIArgInfo::Direct:
17171719 resultType = retAI.getCoerceToType ();
@@ -1784,6 +1786,7 @@ llvm::FunctionType *CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) {
17841786 ArgTypes[FirstIRArg] = llvm::PointerType::get (
17851787 getLLVMContext (), ArgInfo.getIndirectAddrSpace ());
17861788 break ;
1789+ case ABIArgInfo::TargetSpecific:
17871790 case ABIArgInfo::Extend:
17881791 case ABIArgInfo::Direct: {
17891792 // Fast-isel and the optimizer generally like scalar values better than
@@ -2697,6 +2700,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
26972700 else
26982701 RetAttrs.addAttribute (llvm::Attribute::NoExt);
26992702 [[fallthrough]];
2703+ case ABIArgInfo::TargetSpecific:
27002704 case ABIArgInfo::Direct:
27012705 if (RetAI.getInReg ())
27022706 RetAttrs.addAttribute (llvm::Attribute::InReg);
@@ -2838,6 +2842,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
28382842 else
28392843 Attrs.addAttribute (llvm::Attribute::NoExt);
28402844 [[fallthrough]];
2845+ case ABIArgInfo::TargetSpecific:
28412846 case ABIArgInfo::Direct:
28422847 if (ArgNo == 0 && FI.isChainCall ())
28432848 Attrs.addAttribute (llvm::Attribute::Nest);
@@ -3357,17 +3362,6 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
33573362 }
33583363 }
33593364
3360- // Struct of fixed-length vectors and struct of array of fixed-length
3361- // vector in VLS calling convention are coerced to vector tuple
3362- // type(represented as TargetExtType) and scalable vector type
3363- // respectively, they're no longer handled as struct.
3364- if (ArgI.isDirect () && isa<llvm::StructType>(ConvertType (Ty)) &&
3365- (isa<llvm::TargetExtType>(ArgI.getCoerceToType ()) ||
3366- isa<llvm::ScalableVectorType>(ArgI.getCoerceToType ()))) {
3367- ArgVals.push_back (ParamValue::forDirect (AI));
3368- break ;
3369- }
3370-
33713365 llvm::StructType *STy =
33723366 dyn_cast<llvm::StructType>(ArgI.getCoerceToType ());
33733367 Address Alloca =
@@ -3508,6 +3502,25 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
35083502 break ;
35093503 }
35103504
3505+ case ABIArgInfo::TargetSpecific: {
3506+ auto *AI = Fn->getArg (FirstIRArg);
3507+ AI->setName (Arg->getName () + " .target_coerce" );
3508+ Address Alloca =
3509+ CreateMemTemp (Ty, getContext ().getDeclAlign (Arg), Arg->getName ());
3510+ Address Ptr = emitAddressAtOffset (*this , Alloca, ArgI);
3511+ CGM.getABIInfo ().createCoercedStore (AI, Ptr, ArgI, false , *this );
3512+ if (CodeGenFunction::hasScalarEvaluationKind (Ty)) {
3513+ llvm::Value *V =
3514+ EmitLoadOfScalar (Alloca, false , Ty, Arg->getBeginLoc ());
3515+ if (isPromoted) {
3516+ V = emitArgumentDemotion (*this , Arg, V);
3517+ }
3518+ ArgVals.push_back (ParamValue::forDirect (V));
3519+ } else {
3520+ ArgVals.push_back (ParamValue::forIndirect (Alloca));
3521+ }
3522+ break ;
3523+ }
35113524 case ABIArgInfo::Ignore:
35123525 assert (NumIRArgs == 0 );
35133526 // Initialize the local variable appropriately.
@@ -4136,6 +4149,11 @@ void CodeGenFunction::EmitFunctionEpilog(
41364149 }
41374150 break ;
41384151 }
4152+ case ABIArgInfo::TargetSpecific: {
4153+ Address V = emitAddressAtOffset (*this , ReturnValue, RetAI);
4154+ RV = CGM.getABIInfo ().createCoercedLoad (V, RetAI, *this );
4155+ break ;
4156+ }
41394157 case ABIArgInfo::Expand:
41404158 case ABIArgInfo::IndirectAliased:
41414159 llvm_unreachable (" Invalid ABI kind for return argument" );
@@ -5704,6 +5722,24 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
57045722 assert (IRArgPos == FirstIRArg + NumIRArgs);
57055723 break ;
57065724 }
5725+
5726+ case ABIArgInfo::TargetSpecific: {
5727+ Address Src = Address::invalid ();
5728+ if (!I->isAggregate ()) {
5729+ Src = CreateMemTemp (I->Ty , " target_coerce" );
5730+ I->copyInto (*this , Src);
5731+ } else {
5732+ Src = I->hasLValue () ? I->getKnownLValue ().getAddress ()
5733+ : I->getKnownRValue ().getAggregateAddress ();
5734+ }
5735+
5736+ // If the value is offset in memory, apply the offset now.
5737+ Src = emitAddressAtOffset (*this , Src, ArgInfo);
5738+ llvm::Value *Load =
5739+ CGM.getABIInfo ().createCoercedLoad (Src, ArgInfo, *this );
5740+ IRCallArgs[FirstIRArg] = Load;
5741+ break ;
5742+ }
57075743 }
57085744 }
57095745
@@ -6189,6 +6225,19 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
61896225 return convertTempToRValue (DestPtr, RetTy, SourceLocation ());
61906226 }
61916227
6228+ case ABIArgInfo::TargetSpecific: {
6229+ Address DestPtr = ReturnValue.getValue ();
6230+ Address StorePtr = emitAddressAtOffset (*this , DestPtr, RetAI);
6231+ bool DestIsVolatile = ReturnValue.isVolatile ();
6232+ if (!DestPtr.isValid ()) {
6233+ DestPtr = CreateMemTemp (RetTy, " target_coerce" );
6234+ DestIsVolatile = false ;
6235+ }
6236+ CGM.getABIInfo ().createCoercedStore (CI, StorePtr, RetAI, DestIsVolatile,
6237+ *this );
6238+ return convertTempToRValue (DestPtr, RetTy, SourceLocation ());
6239+ }
6240+
61926241 case ABIArgInfo::Expand:
61936242 case ABIArgInfo::IndirectAliased:
61946243 llvm_unreachable (" Invalid ABI kind for return argument" );
0 commit comments