@@ -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);
@@ -3335,17 +3340,6 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
33353340 }
33363341 }
33373342
3338- // Struct of fixed-length vectors and struct of array of fixed-length
3339- // vector in VLS calling convention are coerced to vector tuple
3340- // type(represented as TargetExtType) and scalable vector type
3341- // respectively, they're no longer handled as struct.
3342- if (ArgI.isDirect () && isa<llvm::StructType>(ConvertType (Ty)) &&
3343- (isa<llvm::TargetExtType>(ArgI.getCoerceToType ()) ||
3344- isa<llvm::ScalableVectorType>(ArgI.getCoerceToType ()))) {
3345- ArgVals.push_back (ParamValue::forDirect (AI));
3346- break ;
3347- }
3348-
33493343 llvm::StructType *STy =
33503344 dyn_cast<llvm::StructType>(ArgI.getCoerceToType ());
33513345 Address Alloca =
@@ -3486,6 +3480,25 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
34863480 break ;
34873481 }
34883482
3483+ case ABIArgInfo::TargetSpecific: {
3484+ auto *AI = Fn->getArg (FirstIRArg);
3485+ AI->setName (Arg->getName () + " .target_coerce" );
3486+ Address Alloca =
3487+ CreateMemTemp (Ty, getContext ().getDeclAlign (Arg), Arg->getName ());
3488+ Address Ptr = emitAddressAtOffset (*this , Alloca, ArgI);
3489+ CGM.getABIInfo ().CreateCoercedStore (AI, Ptr, ArgI, false , *this );
3490+ if (CodeGenFunction::hasScalarEvaluationKind (Ty)) {
3491+ llvm::Value *V =
3492+ EmitLoadOfScalar (Alloca, false , Ty, Arg->getBeginLoc ());
3493+ if (isPromoted) {
3494+ V = emitArgumentDemotion (*this , Arg, V);
3495+ }
3496+ ArgVals.push_back (ParamValue::forDirect (V));
3497+ } else {
3498+ ArgVals.push_back (ParamValue::forIndirect (Alloca));
3499+ }
3500+ break ;
3501+ }
34893502 case ABIArgInfo::Ignore:
34903503 assert (NumIRArgs == 0 );
34913504 // Initialize the local variable appropriately.
@@ -4114,6 +4127,11 @@ void CodeGenFunction::EmitFunctionEpilog(
41144127 }
41154128 break ;
41164129 }
4130+ case ABIArgInfo::TargetSpecific: {
4131+ Address V = emitAddressAtOffset (*this , ReturnValue, RetAI);
4132+ RV = CGM.getABIInfo ().CreateCoercedLoad (V, RetAI, *this );
4133+ break ;
4134+ }
41174135 case ABIArgInfo::Expand:
41184136 case ABIArgInfo::IndirectAliased:
41194137 llvm_unreachable (" Invalid ABI kind for return argument" );
@@ -5691,6 +5709,24 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
56915709 assert (IRArgPos == FirstIRArg + NumIRArgs);
56925710 break ;
56935711 }
5712+
5713+ case ABIArgInfo::TargetSpecific: {
5714+ Address Src = Address::invalid ();
5715+ if (!I->isAggregate ()) {
5716+ Src = CreateMemTemp (I->Ty , " target_coerce" );
5717+ I->copyInto (*this , Src);
5718+ } else {
5719+ Src = I->hasLValue () ? I->getKnownLValue ().getAddress ()
5720+ : I->getKnownRValue ().getAggregateAddress ();
5721+ }
5722+
5723+ // If the value is offset in memory, apply the offset now.
5724+ Src = emitAddressAtOffset (*this , Src, ArgInfo);
5725+ llvm::Value *Load =
5726+ CGM.getABIInfo ().CreateCoercedLoad (Src, ArgInfo, *this );
5727+ IRCallArgs[FirstIRArg] = Load;
5728+ break ;
5729+ }
56945730 }
56955731 }
56965732
@@ -6177,6 +6213,19 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
61776213 return convertTempToRValue (DestPtr, RetTy, SourceLocation ());
61786214 }
61796215
6216+ case ABIArgInfo::TargetSpecific: {
6217+ Address DestPtr = ReturnValue.getValue ();
6218+ Address StorePtr = emitAddressAtOffset (*this , DestPtr, RetAI);
6219+ bool DestIsVolatile = ReturnValue.isVolatile ();
6220+ if (!DestPtr.isValid ()) {
6221+ DestPtr = CreateMemTemp (RetTy, " target_coerce" );
6222+ DestIsVolatile = false ;
6223+ }
6224+ CGM.getABIInfo ().CreateCoercedStore (CI, StorePtr, RetAI, DestIsVolatile,
6225+ *this );
6226+ return convertTempToRValue (DestPtr, RetTy, SourceLocation ());
6227+ }
6228+
61806229 case ABIArgInfo::Expand:
61816230 case ABIArgInfo::IndirectAliased:
61826231 llvm_unreachable (" Invalid ABI kind for return argument" );
0 commit comments