[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

zhijian lin via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 12 06:31:37 PDT 2024


================
@@ -337,12 +347,58 @@ CharUnits PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(uint64_t &TypeSize) const {
+  llvm::Type *ElemTy;
+  unsigned RegsNeeded; // Registers Needed for Complex.
+
+  if (TypeSize == 64) {
+    ElemTy = llvm::Type::getInt64Ty(getVMContext());
+    RegsNeeded = 1;
+  } else {
+    ElemTy = llvm::Type::getInt32Ty(getVMContext());
+    RegsNeeded = (TypeSize + 31) / 32;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+                                                    int &ArgGPRsLeft) const {
+  assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  ASTContext &Context = getContext();
+
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (IsComplexInRegABI && Ty->isAnyComplexType() &&
+      TypeSize <= RegLen * ArgGPRsLeft) {
+    assert(Ty->isAnyComplexType() && "Ty must be Complex type.");
+    ArgGPRsLeft -= TypeSize / RegLen;
+    return handleComplex(TypeSize);
+  }
+
+  if (ArgGPRsLeft) {
+    // Records with non-trivial destructors/copy-constructors should not be
+    // passed by value.
+    if (isAggregateTypeForABI(Ty))
+      ArgGPRsLeft -= 1;
+    else if (!Ty->isFloatingType()) {
+      // For other premitive types.
+      if (TypeSize > RegLen && TypeSize <= 2 * RegLen)
+        ArgGPRsLeft -= TypeSize / RegLen;
----------------
diggerlin wrote:

and If I understand correct, the single precision floating point complex . and 64 bit integer (long long unsigned)  also need a  even alignment .

`If gr > 9, go to OTHER. If gr is even, set gr = gr + 1. Load the lower-addressed word of the
argument into gr and the higher-addressed word into gr + 1, set gr = gr + 2,` 

it looks  the logic not express in your code when you calculate the `ArgGPRsLeft` ?


https://github.com/llvm/llvm-project/pull/77732


More information about the cfe-commits mailing list