@@ -292,9 +292,6 @@ class X86_32ABIInfo : public ABIInfo {
292
292
293
293
static bool shouldReturnTypeInRegister (QualType Ty, ASTContext &Context);
294
294
295
- static unsigned getIndirectArgumentAlignment (QualType Ty,
296
- ASTContext &Context);
297
-
298
295
// / getIndirectResult - Give a source type \arg Ty, return a suitable result
299
296
// / such that the argument will be passed in memory.
300
297
ABIArgInfo getIndirectResult (QualType Ty, ASTContext &Context,
@@ -496,21 +493,19 @@ ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy,
496
493
}
497
494
}
498
495
499
- unsigned X86_32ABIInfo::getIndirectArgumentAlignment (QualType Ty,
500
- ASTContext &Context) {
501
- unsigned Align = Context.getTypeAlign (Ty);
502
- if (Align < 128 ) return 0 ;
503
- if (const RecordType* RT = Ty->getAs <RecordType>())
504
- if (typeContainsSSEVector (RT->getDecl (), Context))
505
- return 16 ;
506
- return 0 ;
507
- }
508
-
509
496
ABIArgInfo X86_32ABIInfo::getIndirectResult (QualType Ty,
510
497
ASTContext &Context,
511
498
bool ByVal) const {
512
- return ABIArgInfo::getIndirect (getIndirectArgumentAlignment (Ty, Context),
513
- ByVal);
499
+ if (!ByVal)
500
+ return ABIArgInfo::getIndirect (0 , false );
501
+
502
+ // Compute the byval alignment. We trust the back-end to honor the
503
+ // minimum ABI alignment for byval, to make cleaner IR.
504
+ const unsigned MinABIAlign = 4 ;
505
+ unsigned Align = Context.getTypeAlign (Ty) / 8 ;
506
+ if (Align > MinABIAlign)
507
+ return ABIArgInfo::getIndirect (Align);
508
+ return ABIArgInfo::getIndirect (0 );
514
509
}
515
510
516
511
ABIArgInfo X86_32ABIInfo::classifyArgumentType (QualType Ty,
@@ -696,6 +691,10 @@ class X86_64ABIInfo : public ABIInfo {
696
691
const llvm::Type *CoerceTo,
697
692
ASTContext &Context) const ;
698
693
694
+ // / getIndirectResult - Give a source type \arg Ty, return a suitable result
695
+ // / such that the argument will be returned in memory.
696
+ ABIArgInfo getIndirectReturnResult (QualType Ty, ASTContext &Context) const ;
697
+
699
698
// / getIndirectResult - Give a source type \arg Ty, return a suitable result
700
699
// / such that the argument will be passed in memory.
701
700
ABIArgInfo getIndirectResult (QualType Ty, ASTContext &Context) const ;
@@ -1071,6 +1070,22 @@ ABIArgInfo X86_64ABIInfo::getCoerceResult(QualType Ty,
1071
1070
return ABIArgInfo::getCoerce (CoerceTo);
1072
1071
}
1073
1072
1073
+ ABIArgInfo X86_64ABIInfo::getIndirectReturnResult (QualType Ty,
1074
+ ASTContext &Context) const {
1075
+ // If this is a scalar LLVM value then assume LLVM will pass it in the right
1076
+ // place naturally.
1077
+ if (!CodeGenFunction::hasAggregateLLVMType (Ty)) {
1078
+ // Treat an enum type as its underlying type.
1079
+ if (const EnumType *EnumTy = Ty->getAs <EnumType>())
1080
+ Ty = EnumTy->getDecl ()->getIntegerType ();
1081
+
1082
+ return (Ty->isPromotableIntegerType () ?
1083
+ ABIArgInfo::getExtend () : ABIArgInfo::getDirect ());
1084
+ }
1085
+
1086
+ return ABIArgInfo::getIndirect (0 );
1087
+ }
1088
+
1074
1089
ABIArgInfo X86_64ABIInfo::getIndirectResult (QualType Ty,
1075
1090
ASTContext &Context) const {
1076
1091
// If this is a scalar LLVM value then assume LLVM will pass it in the right
@@ -1084,10 +1099,16 @@ ABIArgInfo X86_64ABIInfo::getIndirectResult(QualType Ty,
1084
1099
ABIArgInfo::getExtend () : ABIArgInfo::getDirect ());
1085
1100
}
1086
1101
1087
- bool ByVal = !isRecordWithNonTrivialDestructorOrCopyConstructor (Ty);
1102
+ if (isRecordWithNonTrivialDestructorOrCopyConstructor (Ty))
1103
+ return ABIArgInfo::getIndirect (0 , /* ByVal=*/ false );
1088
1104
1089
- // FIXME: Set alignment correctly.
1090
- return ABIArgInfo::getIndirect (0 , ByVal);
1105
+ // Compute the byval alignment. We trust the back-end to honor the
1106
+ // minimum ABI alignment for byval, to make cleaner IR.
1107
+ const unsigned MinABIAlign = 8 ;
1108
+ unsigned Align = Context.getTypeAlign (Ty) / 8 ;
1109
+ if (Align > MinABIAlign)
1110
+ return ABIArgInfo::getIndirect (Align);
1111
+ return ABIArgInfo::getIndirect (0 );
1091
1112
}
1092
1113
1093
1114
ABIArgInfo X86_64ABIInfo::classifyReturnType (QualType RetTy,
@@ -1115,7 +1136,7 @@ ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy,
1115
1136
// AMD64-ABI 3.2.3p4: Rule 2. Types of class memory are returned via
1116
1137
// hidden argument.
1117
1138
case Memory:
1118
- return getIndirectResult (RetTy, Context);
1139
+ return getIndirectReturnResult (RetTy, Context);
1119
1140
1120
1141
// AMD64-ABI 3.2.3p4: Rule 3. If the class is INTEGER, the next
1121
1142
// available register of the sequence %rax, %rdx is used.
0 commit comments