Skip to content

Commit 0d123d9

Browse files
committed
fixup! [clang][RISCV] Enable struct of homogeneous scalable vector as function argument
1 parent 195c500 commit 0d123d9

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,8 +1531,7 @@ void ClangToLLVMArgMapping::construct(const ASTContext &Context,
15311531
case ABIArgInfo::Direct: {
15321532
// FIXME: handle sseregparm someday...
15331533
llvm::StructType *STy = dyn_cast<llvm::StructType>(AI.getCoerceToType());
1534-
if (AI.isDirect() && AI.getCanBeFlattened() && STy &&
1535-
!STy->containsHomogeneousScalableVectorTypes()) {
1534+
if (AI.isDirect() && AI.getCanBeFlattened() && STy) {
15361535
IRArgs.NumberOfArgs = STy->getNumElements();
15371536
} else {
15381537
IRArgs.NumberOfArgs = 1;
@@ -1714,8 +1713,7 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) {
17141713
// FCAs, so we flatten them if this is safe to do for this argument.
17151714
llvm::Type *argType = ArgInfo.getCoerceToType();
17161715
llvm::StructType *st = dyn_cast<llvm::StructType>(argType);
1717-
if (st && ArgInfo.isDirect() && ArgInfo.getCanBeFlattened() &&
1718-
!st->containsHomogeneousScalableVectorTypes()) {
1716+
if (st && ArgInfo.isDirect() && ArgInfo.getCanBeFlattened()) {
17191717
assert(NumIRArgs == st->getNumElements());
17201718
for (unsigned i = 0, e = st->getNumElements(); i != e; ++i)
17211719
ArgTypes[FirstIRArg + i] = st->getElementType(i);
@@ -3212,7 +3210,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
32123210
dyn_cast<llvm::StructType>(ArgI.getCoerceToType());
32133211
llvm::TypeSize StructSize;
32143212
llvm::TypeSize PtrElementSize;
3215-
if (ArgI.isDirect() && ArgI.getCanBeFlattened() && STy &&
3213+
if (ArgI.isDirect() && !ArgI.getCanBeFlattened() && STy &&
32163214
STy->getNumElements() > 1) {
32173215
StructSize = CGM.getDataLayout().getTypeAllocSize(STy);
32183216
PtrElementSize =
@@ -5279,7 +5277,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
52795277
llvm::Type *SrcTy = ConvertTypeForMem(I->Ty);
52805278
llvm::TypeSize SrcTypeSize;
52815279
llvm::TypeSize DstTypeSize;
5282-
if (STy && ArgInfo.isDirect() && ArgInfo.getCanBeFlattened()) {
5280+
if (STy && ArgInfo.isDirect() && !ArgInfo.getCanBeFlattened()) {
52835281
SrcTypeSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
52845282
DstTypeSize = CGM.getDataLayout().getTypeAllocSize(STy);
52855283
if (STy->containsHomogeneousScalableVectorTypes()) {

clang/lib/CodeGen/Targets/RISCV.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,13 @@ ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType Ty, bool IsFixed,
433433
return getNaturalAlignIndirect(Ty, /*ByVal=*/false);
434434
}
435435

436-
return ABIArgInfo::getDirect();
436+
ABIArgInfo Info = ABIArgInfo::getDirect();
437+
438+
// If it is tuple type, it can't be flattened.
439+
if (llvm::StructType *STy = dyn_cast<llvm::StructType>(CGT.ConvertType(Ty)))
440+
Info.setCanBeFlattened(!STy->containsHomogeneousScalableVectorTypes());
441+
442+
return Info;
437443
}
438444

439445
if (const VectorType *VT = Ty->getAs<VectorType>())

0 commit comments

Comments
 (0)