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

2024-02-26 Thread zhijian lin via cfe-commits


@@ -337,12 +350,77 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(QualType Ty,
+ uint64_t ) const {
+
+  assert(Ty->isAnyComplexType());
+  llvm::Type *ElemTy;
+  unsigned SizeRegs;
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+SizeRegs = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+SizeRegs = (TypeSize + 31) / 32;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, SizeRegs));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int ) const {
+
+  assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  ASTContext  = getContext();
+
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (isComplexInRegABI && Ty->isAnyComplexType() &&
+  TypeSize <= RLen * ArgGPRsLeft) {
+ArgGPRsLeft -= TypeSize / RLen;
+return handleComplex(Ty, TypeSize);
+  }
+
+  if (isAggregateTypeForABI(Ty)) {
+if (ArgGPRsLeft)
+  ArgGPRsLeft -= 1;
+// Records with non-trivial destructors/copy-constructors should not be
+// passed by value.
+if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI())) {
+  return getNaturalAlignIndirect(Ty, RAA == CGCXXABI::RAA_DirectInMemory);
+}
+return getNaturalAlignIndirect(Ty);
+  }
+
+  if (!Ty->isFloatingType()) {
+if (TypeSize > RLen && TypeSize <= 2 * RLen)
+  ArgGPRsLeft -= 2;
+else
+  ArgGPRsLeft--;
+  }
+
+  // Treat an enum type as its underlying type.
+  if (const EnumType *EnumTy = Ty->getAs())
+Ty = EnumTy->getDecl()->getIntegerType();
+
+  if (const auto *EIT = Ty->getAs())
+if (EIT->getNumBits() >
+Context.getTypeSize(Context.getTargetInfo().hasInt128Type()
+? Context.Int128Ty
+: Context.LongLongTy))
+  return getNaturalAlignIndirect(Ty);
+
+  return (isPromotableIntegerTypeForABI(Ty) ? ABIArgInfo::getExtend(Ty)

diggerlin wrote:

since most of the code is same as 
`DefaultABIInfo::classifyArgumentType(QualType Ty)` , I suggest rewrite the 
function `PPC32_SVR4_ABIInfo::classifyArgumentType` as 

```
ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
int ) const { 
   
   special functionality code of the function here
   .
   
DefaultABIInfo::classifyArgumentType(Ty)   
   }
```
duplication code is not a good idea.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits


@@ -372,11 +453,12 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction 
, Address VAList,
   if (getTarget().getTriple().isOSDarwin()) {
 auto TI = getContext().getTypeInfoInChars(Ty);
 TI.Align = getParamTypeAlignment(Ty);
+int ArgGPRs = NumArgGPRs;
 
 CharUnits SlotSize = CharUnits::fromQuantity(4);
 return emitVoidPtrVAArg(CGF, VAList, Ty,
-classifyArgumentType(Ty).isIndirect(), TI, 
SlotSize,
-/*AllowHigherAlign=*/true);
+classifyArgumentType(Ty, ArgGPRs).isIndirect(), TI,

diggerlin wrote:

I am sure purpose the calculation the variable `ArgGPRs`, it be calculated in 
the function  `classifyArgumentType` , but never use it.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits


@@ -337,12 +350,77 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(QualType Ty,
+ uint64_t ) const {
+
+  assert(Ty->isAnyComplexType());

diggerlin wrote:

if use only for the assert, suggest putting assert outside the function,

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits


@@ -271,22 +271,33 @@ namespace {
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
+  bool isComplexInRegABI;
+  // Size of GPR in bits
+  unsigned RLen;
+  static const int NumArgGPRs = 8;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
+  ABIArgInfo handleComplex(QualType Ty, uint64_t ) const;
 
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes , bool SoftFloatABI,
- bool RetSmallStructInRegABI)
+ bool RetSmallStructInRegABI, unsigned RLen,
+ bool ComplexInRegABI)
   : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
-IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+IsRetSmallStructInRegABI(RetSmallStructInRegABI),
+isComplexInRegABI(ComplexInRegABI), RLen(RLen) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType Ty, int ) const;
 
   void computeInfo(CGFunctionInfo ) const override {
+
+int ArgGPRsLeft = NumArgGPRs;
+
 if (!getCXXABI().classifyReturnType(FI))
   FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
 for (auto  : FI.arguments())
-  I.info = classifyArgumentType(I.type);
+  I.info = classifyArgumentType(I.type, ArgGPRsLeft);

diggerlin wrote:

why do you need  introduce a new variable `ArgGPRsLeft` since you do not use 
the new variable after the call .

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-26 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-23 Thread Amy Kwan via cfe-commits


@@ -361,6 +439,9 @@ ABIArgInfo PPC32_SVR4_ABIInfo::classifyReturnType(QualType 
RetTy) const {
   return ABIArgInfo::getDirect(CoerceTy);
 }
   }
+  if (isComplexInRegABI && RetTy->isAnyComplexType()) {

amy-kwan wrote:

Braces not needed here.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-23 Thread Amy Kwan via cfe-commits


@@ -223,6 +223,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code 
coverage criteria.
 
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
+  /// If -fcomplex-ppc-gnu-abi for ppc32

amy-kwan wrote:

```suggestion
  /// If -fcomplex-ppc-gnu-abi is specified on ppc32.
```
This sentence might read a bit better.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-23 Thread Amy Kwan via cfe-commits


@@ -2540,6 +2540,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, store Complex values in GPR instead of stack 
for PowerPC-32">,

amy-kwan wrote:

```suggestion
  DocBrief<"Follow the GNU ABI, pass Complex values in GPRs instead of the 
stack for PowerPC-32">,
```

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-23 Thread Amy Kwan via cfe-commits


@@ -271,22 +271,33 @@ namespace {
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
+  bool isComplexInRegABI;
+  // Size of GPR in bits

amy-kwan wrote:

```suggestion
  bool IsComplexInRegABI;
  // Size of GPR in bits.
```
End sentence with a period, and capitalize the boolean variable for consistency.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-23 Thread Amy Kwan via cfe-commits


@@ -337,12 +350,77 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(QualType Ty,
+ uint64_t ) const {
+
+  assert(Ty->isAnyComplexType());

amy-kwan wrote:

It would also be good if the assert has a message.
Additionally, for people who do not do assert builds, since `Ty` is only used 
for the assert, they may get an unused variable warning.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-23 Thread Amy Kwan via cfe-commits

https://github.com/amy-kwan commented:

I think the braces can also be omitted on the conditions within the `clang/*` 
files.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-23 Thread Amy Kwan via cfe-commits

https://github.com/amy-kwan edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits


@@ -337,12 +350,77 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(QualType Ty,
+ uint64_t ) const {
+
+  assert(Ty->isAnyComplexType());
+  llvm::Type *ElemTy;
+  unsigned SizeRegs;
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+SizeRegs = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+SizeRegs = (TypeSize + 31) / 32;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, SizeRegs));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int ) const {
+
+  assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  ASTContext  = getContext();
+
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (isComplexInRegABI && Ty->isAnyComplexType() &&
+  TypeSize <= RLen * ArgGPRsLeft) {
+ArgGPRsLeft -= TypeSize / RLen;
+return handleComplex(Ty, TypeSize);
+  }
+
+  if (isAggregateTypeForABI(Ty)) {
+if (ArgGPRsLeft)
+  ArgGPRsLeft -= 1;
+// Records with non-trivial destructors/copy-constructors should not be
+// passed by value.
+if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI())) {
+  return getNaturalAlignIndirect(Ty, RAA == CGCXXABI::RAA_DirectInMemory);
+}
+return getNaturalAlignIndirect(Ty);
+  }
+
+  if (!Ty->isFloatingType()) {
+if (TypeSize > RLen && TypeSize <= 2 * RLen)
+  ArgGPRsLeft -= 2;
+else
+  ArgGPRsLeft--;

diggerlin wrote:

There is a bug here, you decrease the ArgGPRsLeft no mater whether ArgGPRsLeft 
>0;

I think you can put after `Ty = useFirstFieldIfTransparentUnion(Ty);`
```
Ty = useFirstFieldIfTransparentUnion(Ty);
if(Ty->isFloatingType()) return;
```
and change the code here as 
```
if(TypeSize <= RLen * ArgGPRsLeft) 
ArgGPRsLeft -= TypeSize / RLen;
```

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits


@@ -337,12 +350,77 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(QualType Ty,
+ uint64_t ) const {
+
+  assert(Ty->isAnyComplexType());
+  llvm::Type *ElemTy;
+  unsigned SizeRegs;

diggerlin wrote:

I can not understand what the SizeRegs stand for ?
can you explain it ? do it indicate how many Registers will be used by the 
parameter which has TypeSize length.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits


@@ -337,12 +350,77 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(QualType Ty,
+ uint64_t ) const {
+
+  assert(Ty->isAnyComplexType());

diggerlin wrote:

it looks the Ty pass in the function is only used for assert ?

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits


@@ -337,12 +350,77 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(QualType Ty,
+ uint64_t ) const {
+
+  assert(Ty->isAnyComplexType());
+  llvm::Type *ElemTy;
+  unsigned SizeRegs;
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+SizeRegs = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());

diggerlin wrote:

I am curiously , why not get ElemTy = llvm::Type::getInt128Ty(getVMContext()); 
instead of ElemTy = llvm::Type::getInt32Ty(getVMContext());

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits

https://github.com/diggerlin edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits


@@ -271,22 +271,33 @@ namespace {
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
+  bool isComplexInRegABI;
+  // Size of GPR in bits
+  unsigned RLen;

diggerlin wrote:

`RLen` is too short to understand what `R` means , suggest to change to 
`RegLen` and `RegisterLen`.  and Do we need to add `RLen` ? since the  class is 
PPC32_SVR4_ABIInfo, Should the Register Len be default to 32 bit ?

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits


@@ -184,11 +184,13 @@ createTargetCodeGenInfo(CodeGenModule ) {
 
 bool IsSoftFloat =
 CodeGenOpts.FloatABI == "soft" || Target.hasFeature("spe");
-return createPPC32TargetCodeGenInfo(CGM, IsSoftFloat);
+unsigned RLen = Target.getPointerWidth(LangAS::Default);

diggerlin wrote:

the variable is used only once , do not need to introduce a new variable.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits


@@ -184,11 +184,13 @@ createTargetCodeGenInfo(CodeGenModule ) {
 
 bool IsSoftFloat =
 CodeGenOpts.FloatABI == "soft" || Target.hasFeature("spe");
-return createPPC32TargetCodeGenInfo(CGM, IsSoftFloat);
+unsigned RLen = Target.getPointerWidth(LangAS::Default);
+return createPPC32TargetCodeGenInfo(CGM, IsSoftFloat, RLen);
   }
   case llvm::Triple::ppcle: {
 bool IsSoftFloat = CodeGenOpts.FloatABI == "soft";
-return createPPC32TargetCodeGenInfo(CGM, IsSoftFloat);
+unsigned RLen = Target.getPointerWidth(LangAS::Default);
+return createPPC32TargetCodeGenInfo(CGM, IsSoftFloat, RLen);

diggerlin wrote:

the variable is used only once , do not need to introduce a new variable.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-22 Thread zhijian lin via cfe-commits


@@ -337,12 +350,77 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(QualType Ty,
+ uint64_t ) const {
+

diggerlin wrote:

it look the TypeSize only has 32bit and 64bit. can you change the `uint64_t 
` to `bool is64BitTypeSize`

and change following code as 

```
llvm::Type *ElemTy =is64BitTypeSize? llvm::Type::getInt64Ty(getVMContext()): 
llvm::Type::getInt32Ty(getVMContext());

unsigned SizeRegs = is64BitTypeSize ? 1:2;
```

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-09 Thread Kishan Parmar via cfe-commits


@@ -486,7 +486,8 @@ std::unique_ptr
 createAIXTargetCodeGenInfo(CodeGenModule , bool Is64Bit);
 
 std::unique_ptr
-createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI);
+createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI,
+ unsigned RLen);

Long5hot wrote:

I was not sure about hardcoding Register Width(RLen) **"32"** for RLen here.. 
https://github.com/llvm/llvm-project/pull/77732/files#diff-05339beb4a6cf7efdfc537984255dd372dcf1edd2d00eabed25831da4d1d0a9fR276

So i used similiar approach like, how RISC-V does to calculate Register Width 
here.
PPC : 
https://github.com/llvm/llvm-project/pull/77732/files#diff-e724febedab9c1a2832bf2056d208ff02ddcb2e6f90b5a653afc9b19ac78a5d7R187
RISCV : 
https://github.com/llvm/llvm-project/pull/77732/files#diff-e724febedab9c1a2832bf2056d208ff02ddcb2e6f90b5a653afc9b19ac78a5d7L226

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-08 Thread Nemanja Ivanovic via cfe-commits

nemanjai wrote:

My review is not complete, I just submitted what I have so far so at least we 
can get started on answering the questions I have so far.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-08 Thread Nemanja Ivanovic via cfe-commits


@@ -486,7 +486,8 @@ std::unique_ptr
 createAIXTargetCodeGenInfo(CodeGenModule , bool Is64Bit);
 
 std::unique_ptr
-createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI);
+createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI,
+ unsigned RLen);

nemanjai wrote:

Please explain this change. It is not clear to me why we're adding this 
parameter. Are we adding support for 32-bit targets with 64-bit pointers? If 
so, please justify. Also, this is something that would belong in a separate 
patch.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-08 Thread Nemanja Ivanovic via cfe-commits


@@ -78,6 +78,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_Default,
+CMPLX_OnStack,
+CMPLX_OnGPR, // if ppc32 -fcomplex-ppc-gnu-abi

nemanjai wrote:

Nit: can we use `In[GF]PR` in the names as "in registers"/"on stack" are in 
common usage.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-08 Thread Nemanja Ivanovic via cfe-commits


@@ -2540,6 +2540,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, store Complex values in GPR instead of stack 
for PowerPC-32">,

nemanjai wrote:

Please use "Pass" instead of "Store" as the latter generally refers to storing 
values in memory and this actually affects parameter passing.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-03 Thread Justin Hibbits via cfe-commits

chmeeedalf wrote:

> ping! @chmeeedalf @nemanjai

I know nothing about the complex ABI, so all I can say is the code looks okay 
from a structural point, can't say anything to the logic.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-25 Thread Kishan Parmar via cfe-commits

Long5hot wrote:

ping! @chmeeedalf @nemanjai 

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-23 Thread Kishan Parmar via cfe-commits

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

>From 6a209fb25b7923228a7f4e2a8e2accbc31988622 Mon Sep 17 00:00:00 2001
From: Kishan Parmar 
Date: Wed, 24 Jan 2024 13:14:03 +0530
Subject: [PATCH] [clang][PowerPC] Add flag to enable compatibility with GNU
 for complex arguments

Fixes : https://github.com/llvm/llvm-project/issues/56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for 
PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   7 +
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   6 +-
 clang/lib/CodeGen/TargetInfo.h|   3 +-
 clang/lib/CodeGen/Targets/PPC.cpp | 110 +--
 clang/lib/Driver/ToolChains/Clang.cpp |   9 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   8 ++
 .../CodeGen/PowerPC/ppc32-complex-gnu-abi.c   | 132 ++
 9 files changed, 266 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 2f2e45d5cf63dfa..5bafcab086bb409 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -223,6 +223,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code 
coverage criteria.
 
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
+  /// If -fcomplex-ppc-gnu-abi for ppc32
+ENUM_CODEGENOPT(ComplexInRegABI, ComplexArgumentConventionKind, 2, 
CMPLX_Default)
 
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 3f8fe385fef3dff..670b009e4138c1d 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -78,6 +78,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_Default,
+CMPLX_OnStack,
+CMPLX_OnGPR, // if ppc32 -fcomplex-ppc-gnu-abi
+CMPLX_OnFPR
+  };
+
   enum ProfileInstrKind {
 ProfileNone,   // Profile instrumentation is turned off.
 ProfileClangInstr, // Clang instrumentation to generate execution counts
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748facaf..38e351e38037249 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2540,6 +2540,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, store Complex values in GPR instead of stack 
for PowerPC-32">,
+  HelpText<"Store Complex values in GPR instead of stack for PowerPC-32">;
+
 defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow",
   CodeGenOpts<"StrictFloatCastOverflow">, DefaultTrue,
   NegFlag
 createAIXTargetCodeGenInfo(CodeGenModule , bool Is64Bit);
 
 std::unique_ptr
-createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI);
+createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI,
+ unsigned RLen);
 
 std::unique_ptr
 createPPC64TargetCodeGenInfo(CodeGenModule );
diff --git a/clang/lib/CodeGen/Targets/PPC.cpp 
b/clang/lib/CodeGen/Targets/PPC.cpp
index 40e508c1772..f514f2e25a48f92 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -271,22 +271,33 @@ namespace {
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
+  bool isComplexInRegABI;
+  // Size of GPR in bits
+  unsigned RLen;
+  static const int NumArgGPRs = 8;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
+  ABIArgInfo handleComplex(QualType Ty, uint64_t ) const;
 
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes , bool SoftFloatABI,
- bool RetSmallStructInRegABI)
+ bool RetSmallStructInRegABI, unsigned RLen,
+ bool ComplexInRegABI)
   : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
-IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+IsRetSmallStructInRegABI(RetSmallStructInRegABI),
+

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

2024-01-16 Thread Kishan Parmar via cfe-commits

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

>From ec05087b89af829247879c2e860f9d93f548c7a1 Mon Sep 17 00:00:00 2001
From: Kishan Parmar 
Date: Wed, 17 Jan 2024 10:29:34 +0530
Subject: [PATCH] [clang][PowerPC] Add flag to enable compatibility with GNU
 for complex arguments

Fixes : https://github.com/llvm/llvm-project/issues/56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for 
PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   7 +
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   6 +-
 clang/lib/CodeGen/TargetInfo.h|   3 +-
 clang/lib/CodeGen/Targets/PPC.cpp | 110 +--
 clang/lib/Driver/ToolChains/Clang.cpp |   9 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   8 ++
 .../CodeGen/PowerPC/ppc32-complex-gnu-abi.c   | 132 ++
 9 files changed, 266 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 2c4fb6745bc172f..beeefae15c63f82 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -213,6 +213,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code 
coverage criteria.
 
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
+  /// If -fcomplex-ppc-gnu-abi for ppc32
+ENUM_CODEGENOPT(ComplexInRegABI, ComplexArgumentConventionKind, 2, 
CMPLX_Default)
 
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 6952b48e898a819..8abca0e3dda3343 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -78,6 +78,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_Default,
+CMPLX_OnStack,
+CMPLX_OnGPR, // if ppc32 -fcomplex-ppc-gnu-abi
+CMPLX_OnFPR
+  };
+
   enum ProfileInstrKind {
 ProfileNone,   // Profile instrumentation is turned off.
 ProfileClangInstr, // Clang instrumentation to generate execution counts
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a4a988c71ec412c..10166757b1352ed 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2540,6 +2540,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, store Complex values in GPR instead of stack 
for PowerPC-32">,
+  HelpText<"Store Complex values in GPR instead of stack for PowerPC-32">;
+
 defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow",
   CodeGenOpts<"StrictFloatCastOverflow">, DefaultTrue,
   NegFlag
 createAIXTargetCodeGenInfo(CodeGenModule , bool Is64Bit);
 
 std::unique_ptr
-createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI);
+createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI,
+ unsigned RLen);
 
 std::unique_ptr
 createPPC64TargetCodeGenInfo(CodeGenModule );
diff --git a/clang/lib/CodeGen/Targets/PPC.cpp 
b/clang/lib/CodeGen/Targets/PPC.cpp
index 40e508c1772..f514f2e25a48f92 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -271,22 +271,33 @@ namespace {
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
+  bool isComplexInRegABI;
+  // Size of GPR in bits
+  unsigned RLen;
+  static const int NumArgGPRs = 8;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
+  ABIArgInfo handleComplex(QualType Ty, uint64_t ) const;
 
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes , bool SoftFloatABI,
- bool RetSmallStructInRegABI)
+ bool RetSmallStructInRegABI, unsigned RLen,
+ bool ComplexInRegABI)
   : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
-IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+IsRetSmallStructInRegABI(RetSmallStructInRegABI),
+

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

2024-01-10 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-10 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-10 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-10 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-10 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-10 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-10 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-10 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-10 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-10 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 164f85db876e61cf4a3c34493ed11e8f5820f968 
f79b66cb6eb624c6e06c447a7f9d6824dc1628d5 -- 
clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c 
clang/include/clang/Basic/CodeGenOptions.h clang/lib/CodeGen/CodeGenModule.cpp 
clang/lib/CodeGen/TargetInfo.h clang/lib/CodeGen/Targets/PPC.cpp 
clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Frontend/CompilerInvocation.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/Targets/PPC.cpp 
b/clang/lib/CodeGen/Targets/PPC.cpp
index f4885a927a..f514f2e25a 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -439,7 +439,7 @@ ABIArgInfo PPC32_SVR4_ABIInfo::classifyReturnType(QualType 
RetTy) const {
   return ABIArgInfo::getDirect(CoerceTy);
 }
   }
-  if(isComplexInRegABI && RetTy->isAnyComplexType()) {
+  if (isComplexInRegABI && RetTy->isAnyComplexType()) {
 return handleComplex(RetTy, Size);
   }
 

``




https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-10 Thread Kishan Parmar via cfe-commits

Long5hot wrote:

Following up with this patch : https://reviews.llvm.org/D146942

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-10 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Kishan Parmar (Long5hot)


Changes

Fixes : https://github.com/llvm/llvm-project/issues/56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for 
PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of 
complex.

---

Patch is 23.05 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/77732.diff


9 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.def (+2) 
- (modified) clang/include/clang/Basic/CodeGenOptions.h (+7) 
- (modified) clang/include/clang/Driver/Options.td (+4) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+4-2) 
- (modified) clang/lib/CodeGen/TargetInfo.h (+2-1) 
- (modified) clang/lib/CodeGen/Targets/PPC.cpp (+98-12) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+9) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+8) 
- (added) clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c (+132) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 2c4fb6745bc172..beeefae15c63f8 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -213,6 +213,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code 
coverage criteria.
 
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
+  /// If -fcomplex-ppc-gnu-abi for ppc32
+ENUM_CODEGENOPT(ComplexInRegABI, ComplexArgumentConventionKind, 2, 
CMPLX_Default)
 
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 6952b48e898a81..8abca0e3dda334 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -78,6 +78,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_Default,
+CMPLX_OnStack,
+CMPLX_OnGPR, // if ppc32 -fcomplex-ppc-gnu-abi
+CMPLX_OnFPR
+  };
+
   enum ProfileInstrKind {
 ProfileNone,   // Profile instrumentation is turned off.
 ProfileClangInstr, // Clang instrumentation to generate execution counts
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19becba4a5ad83..251bcb8c49782f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2540,6 +2540,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, store Complex values in GPR instead of stack 
for PowerPC-32">,
+  HelpText<"Store Complex values in GPR instead of stack for PowerPC-32">;
+
 defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow",
   CodeGenOpts<"StrictFloatCastOverflow">, DefaultTrue,
   NegFlag
 createAIXTargetCodeGenInfo(CodeGenModule , bool Is64Bit);
 
 std::unique_ptr
-createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI);
+createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI,
+ unsigned RLen);
 
 std::unique_ptr
 createPPC64TargetCodeGenInfo(CodeGenModule );
diff --git a/clang/lib/CodeGen/Targets/PPC.cpp 
b/clang/lib/CodeGen/Targets/PPC.cpp
index 40e508c177..f4885a927ab0ba 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -271,22 +271,33 @@ namespace {
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
+  bool isComplexInRegABI;
+  // Size of GPR in bits
+  unsigned RLen;
+  static const int NumArgGPRs = 8;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
+  ABIArgInfo handleComplex(QualType Ty, uint64_t ) const;
 
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes , bool SoftFloatABI,
- bool RetSmallStructInRegABI)
+ bool RetSmallStructInRegABI, unsigned RLen,
+ bool ComplexInRegABI)
   : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
-IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+IsRetSmallStructInRegABI(RetSmallStructInRegABI),
+isComplexInRegABI(ComplexInRegABI), RLen(RLen) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) 

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

2024-01-10 Thread Kishan Parmar via cfe-commits

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

Fixes : https://github.com/llvm/llvm-project/issues/56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for 
PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of 
complex.

>From e636286c6c817299ed7348fa8c40cc0fbc2e Mon Sep 17 00:00:00 2001
From: Kishan Parmar 
Date: Thu, 11 Jan 2024 11:54:50 +0530
Subject: [PATCH] [clang][PowerPC] Add flag to enable compatibility with GNU
 for complex arguments

Fixes : https://github.com/llvm/llvm-project/issues/56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for 
PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   7 +
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   6 +-
 clang/lib/CodeGen/TargetInfo.h|   3 +-
 clang/lib/CodeGen/Targets/PPC.cpp | 110 +--
 clang/lib/Driver/ToolChains/Clang.cpp |   9 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   8 ++
 .../CodeGen/PowerPC/ppc32-complex-gnu-abi.c   | 132 ++
 9 files changed, 266 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 2c4fb6745bc172..beeefae15c63f8 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -213,6 +213,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code 
coverage criteria.
 
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
+  /// If -fcomplex-ppc-gnu-abi for ppc32
+ENUM_CODEGENOPT(ComplexInRegABI, ComplexArgumentConventionKind, 2, 
CMPLX_Default)
 
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 6952b48e898a81..8abca0e3dda334 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -78,6 +78,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_Default,
+CMPLX_OnStack,
+CMPLX_OnGPR, // if ppc32 -fcomplex-ppc-gnu-abi
+CMPLX_OnFPR
+  };
+
   enum ProfileInstrKind {
 ProfileNone,   // Profile instrumentation is turned off.
 ProfileClangInstr, // Clang instrumentation to generate execution counts
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19becba4a5ad83..251bcb8c49782f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2540,6 +2540,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, store Complex values in GPR instead of stack 
for PowerPC-32">,
+  HelpText<"Store Complex values in GPR instead of stack for PowerPC-32">;
+
 defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow",
   CodeGenOpts<"StrictFloatCastOverflow">, DefaultTrue,
   NegFlag
 createAIXTargetCodeGenInfo(CodeGenModule , bool Is64Bit);
 
 std::unique_ptr
-createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI);
+createPPC32TargetCodeGenInfo(CodeGenModule , bool SoftFloatABI,
+ unsigned RLen);
 
 std::unique_ptr
 createPPC64TargetCodeGenInfo(CodeGenModule );
diff --git a/clang/lib/CodeGen/Targets/PPC.cpp 
b/clang/lib/CodeGen/Targets/PPC.cpp
index 40e508c177..f4885a927ab0ba 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -271,22 +271,33 @@ namespace {
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
+  bool isComplexInRegABI;
+  // Size of GPR in bits
+  unsigned RLen;
+  static const int NumArgGPRs = 8;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
+  ABIArgInfo handleComplex(QualType Ty, uint64_t ) const;
 
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes , bool SoftFloatABI,
-

<    1   2