[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
Fri Apr 5 12:18:33 PDT 2024
================
@@ -396,12 +405,80 @@ 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.
+
+ // Choice of using llvm::Type::getInt64Ty(getVMContext()) for complex
+ // single-precision floats is based on the ABI ATR-PASS-COMPLEX-IN-GPRS
+ // specification. According to the specification:
+ // - For complex single-precision floats: If the register (gr) is even, it's
+ // incremented by one, and the lower-addressed word of the argument is loaded
+ // into gr, while the higher-addressed word is loaded into gr + 1. Then, gr is
+ // incremented by 2.
+ // - For complex double-precision floats: The words of the argument are loaded
+ // in memory-address order into gr, gr + 1, gr + 2, and gr + 3, with gr being
+ // incremented by 4. Thus, to maintain even alignment and adhere to the ABI
+ // specification, llvm::Type::getInt64Ty(getVMContext()) is used when TypeSize
+ // is 64. Powerpc backend handles this alignment requirement. Specifically,
+ // you can refer to the CC_PPC32_SVR4_Custom_AlignArgRegs method from
+ // PPCCallingconvention.cpp. For more context, refer to the previous
+ // discussion: https://reviews.llvm.org/D146942 and the related LLVM pull
+ // request: #77732
+
+ if (TypeSize == 64) {
+ ElemTy = llvm::Type::getInt64Ty(getVMContext());
+ RegsNeeded = 1;
+ } else {
+ ElemTy = llvm::Type::getInt32Ty(getVMContext());
+ RegsNeeded = TypeSize >> 5;
+ }
+ return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+ int &ArgGPRsLeft) const {
+ Ty = useFirstFieldIfTransparentUnion(Ty);
+
+ if (!(getCodeGenOpts().getComplexInRegABI() == CodeGenOptions::CMPLX_InGPR) ||
+ !ArgGPRsLeft)
----------------
diggerlin wrote:
` if (!(getCodeGenOpts().getComplexInRegABI() == CodeGenOptions::CMPLX_InGPR) || !ArgGPRsLeft)`
-->
` if (getCodeGenOpts().getComplexInRegABI() != CodeGenOptions::CMPLX_InGPR || !ArgGPRsLeft)`
https://github.com/llvm/llvm-project/pull/77732
More information about the cfe-commits
mailing list