[clang] [PowerPC] make `_Complex` ABI GCC-compatible (PR #208917)
Matt Turner via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 29 08:49:37 PST 2026
================
@@ -427,9 +441,94 @@ CharUnits PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
return CharUnits::fromQuantity(4);
}
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyComplexType(QualType Ty) const {
+ assert(Ty->isAnyComplexType() && "not a complex type");
+
+ uint64_t Size = getContext().getTypeSize(Ty);
+ llvm::LLVMContext &VMC = getVMContext();
+ llvm::Type *I32 = llvm::Type::getInt32Ty(VMC);
+
+ // Coerce to an integer for _Complex char and _Complex short.
+ if (Size <= GPRBits)
+ return ABIArgInfo::getDirect(llvm::IntegerType::get(VMC, Size));
+
+ // Coerce to a vector <N x i32> for _Complex float and _Complex int.
+ // A vector gives this the correct 8-byte register alignment.
+ if (Size == 2 * GPRBits)
+ return ABIArgInfo::getDirect(llvm::FixedVectorType::get(I32, 2));
+
+ // Coerce to an array [N x i32] for _Complex double and similar.
+ // An array of i32 gives the correct 4-byte register alignment.
+ return ABIArgInfo::getDirect(llvm::ArrayType::get(I32, Size / GPRBits));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+ int &ArgGPRsLeft) const {
+ assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+ Ty = useFirstFieldIfTransparentUnion(Ty);
+
+ bool IsComplex = Ty->isAnyComplexType() && isComplexGnuABI();
+
+ // Use the default implementation when this argument is not relevant for GPR
+ // budget:
+ //
+ // - floating-point types are passed in FPRs
+ // - when GPRs are already exhausted
+ //
+ // Complex types (when GNU compatible) always need custom handling.
+ if (!IsComplex && (!ArgGPRsLeft || (Ty->isFloatingType() && !IsSoftFloatABI)))
+ return DefaultABIInfo::classifyArgumentType(Ty);
+
+ uint64_t TypeSize = getContext().getTypeSize(Ty);
+ uint64_t RegsNeeded = (TypeSize + GPRBits - 1) / GPRBits;
+
+ if (IsComplex || !isAggregateTypeForABI(Ty)) {
----------------
mattst88 wrote:
`isFloatingType()` is false for vectors, so a 128-bit AltiVec argument gets here
and is charged four GPRs. It goes in a VR and uses none:
```c
typedef int v4si __attribute__((vector_size(16)));
void fv(v4si, int, int, int, _Complex double);
void cv(v4si v) { fv(v, 1, 2, 3, 4.0 + 5.0i); }
```
GCC passes the complex in r6-r9. This patch thinks one GPR is left, pads r6,
and the complex goes in r7-r10.
https://github.com/llvm/llvm-project/pull/208917
More information about the cfe-commits
mailing list