Skip to content

Commit f9329ff

Browse files
[NVPTX] Update ABI handling
For PTX, we want the target to handle struct returns directly. llvm-svn: 195268
1 parent 17bdb0f commit f9329ff

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4197,16 +4197,26 @@ class NVPTXTargetCodeGenInfo : public TargetCodeGenInfo {
41974197
ABIArgInfo NVPTXABIInfo::classifyReturnType(QualType RetTy) const {
41984198
if (RetTy->isVoidType())
41994199
return ABIArgInfo::getIgnore();
4200-
if (isAggregateTypeForABI(RetTy))
4201-
return ABIArgInfo::getIndirect(0);
4202-
return ABIArgInfo::getDirect();
4200+
4201+
// note: this is different from default ABI
4202+
if (!RetTy->isScalarType())
4203+
return ABIArgInfo::getDirect();
4204+
4205+
// Treat an enum type as its underlying type.
4206+
if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
4207+
RetTy = EnumTy->getDecl()->getIntegerType();
4208+
4209+
return (RetTy->isPromotableIntegerType() ?
4210+
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
42034211
}
42044212

42054213
ABIArgInfo NVPTXABIInfo::classifyArgumentType(QualType Ty) const {
4206-
if (isAggregateTypeForABI(Ty))
4207-
return ABIArgInfo::getIndirect(0);
4214+
// Treat an enum type as its underlying type.
4215+
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
4216+
Ty = EnumTy->getDecl()->getIntegerType();
42084217

4209-
return ABIArgInfo::getDirect();
4218+
return (Ty->isPromotableIntegerType() ?
4219+
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
42104220
}
42114221

42124222
void NVPTXABIInfo::computeInfo(CGFunctionInfo &FI) const {

clang/test/CodeGen/nvptx-abi.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -triple nvptx-unknown-unknown -S -o - %s -emit-llvm | FileCheck %s
2+
// RUN: %clang_cc1 -triple nvptx64-unknown-unknown -S -o - %s -emit-llvm | FileCheck %s
3+
4+
typedef struct float4_s {
5+
float x, y, z, w;
6+
} float4_t;
7+
8+
float4_t my_function(void);
9+
10+
// CHECK-DAG: declare %struct.float4_s @my_function
11+
12+
float bar(void) {
13+
float4_t ret;
14+
// CHECK-DAG: call %struct.float4_s @my_function
15+
ret = my_function();
16+
return ret.x;
17+
}

0 commit comments

Comments
 (0)