Skip to content

Commit b1aa36e

Browse files
sitio-coutolanza
authored andcommitted
[CIR][ABI] Add AArch64 unsigned int CC lowering (#708)
Adds the necessary bits to lower arguments and return values of type unsigned int for the x86_64 target.
1 parent e7bcf3e commit b1aa36e

File tree

6 files changed

+91
-2
lines changed

6 files changed

+91
-2
lines changed

clang/include/clang/CIR/MissingFeatures.h

+2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ struct MissingFeatures {
209209

210210
static bool fixedWidthIntegers() { return false; }
211211
static bool vectorType() { return false; }
212+
static bool functionMemberPointerType() { return false; }
213+
static bool fixedSizeIntType() { return false; }
212214

213215
//-- Missing LLVM attributes
214216

clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfoImpl.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
#include "ABIInfo.h"
1515
#include "CIRCXXABI.h"
16+
#include "LowerFunction.h"
1617
#include "LowerFunctionInfo.h"
18+
#include "clang/CIR/MissingFeatures.h"
1719
#include "llvm/Support/ErrorHandling.h"
1820

1921
namespace mlir {
@@ -30,6 +32,11 @@ bool classifyReturnType(const CIRCXXABI &CXXABI, LowerFunctionInfo &FI,
3032
return CXXABI.classifyReturnType(FI);
3133
}
3234

35+
bool isAggregateTypeForABI(Type T) {
36+
assert(!::cir::MissingFeatures::functionMemberPointerType());
37+
return !LowerFunction::hasScalarEvaluationKind(T);
38+
}
39+
3340
Type useFirstFieldIfTransparentUnion(Type Ty) {
3441
if (auto RT = dyn_cast<StructType>(Ty)) {
3542
if (RT.isUnion())

clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfoImpl.h

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace cir {
2424
bool classifyReturnType(const CIRCXXABI &CXXABI, LowerFunctionInfo &FI,
2525
const ABIInfo &Info);
2626

27+
bool isAggregateTypeForABI(Type T);
28+
2729
/// Pass transparent unions as if they were the type of the first element. Sema
2830
/// should ensure that all elements of the union have the same "machine type".
2931
Type useFirstFieldIfTransparentUnion(Type Ty);

clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.h

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ class LowerFunction {
8686

8787
/// Return the TypeEvaluationKind of Type \c T.
8888
static ::cir::TypeEvaluationKind getEvaluationKind(Type T);
89+
90+
static bool hasScalarEvaluationKind(Type T) {
91+
return getEvaluationKind(T) == ::cir::TypeEvaluationKind::TEK_Scalar;
92+
}
8993
};
9094

9195
} // namespace cir

clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/AArch64.cpp

+48-2
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@ class AArch64ABIInfo : public ABIInfo {
3939

4040
private:
4141
AArch64ABIKind getABIKind() const { return Kind; }
42+
bool isDarwinPCS() const { return Kind == AArch64ABIKind::DarwinPCS; }
4243

4344
ABIArgInfo classifyReturnType(Type RetTy, bool IsVariadic) const;
45+
ABIArgInfo classifyArgumentType(Type RetTy, bool IsVariadic,
46+
unsigned CallingConvention) const;
4447

4548
void computeInfo(LowerFunctionInfo &FI) const override {
4649
if (!::mlir::cir::classifyReturnType(getCXXABI(), FI, *this))
4750
FI.getReturnInfo() =
4851
classifyReturnType(FI.getReturnType(), FI.isVariadic());
4952

50-
for (auto &_ : FI.arguments())
51-
llvm_unreachable("NYI");
53+
for (auto &it : FI.arguments())
54+
it.info = classifyArgumentType(it.type, FI.isVariadic(),
55+
FI.getCallingConvention());
5256
}
5357
};
5458

@@ -67,6 +71,48 @@ ABIArgInfo AArch64ABIInfo::classifyReturnType(Type RetTy,
6771
if (isa<VoidType>(RetTy))
6872
return ABIArgInfo::getIgnore();
6973

74+
if (const auto _ = dyn_cast<VectorType>(RetTy)) {
75+
llvm_unreachable("NYI");
76+
}
77+
78+
// Large vector types should be returned via memory.
79+
if (isa<VectorType>(RetTy) && getContext().getTypeSize(RetTy) > 128)
80+
llvm_unreachable("NYI");
81+
82+
if (!isAggregateTypeForABI(RetTy)) {
83+
// NOTE(cir): Skip enum handling.
84+
85+
if (MissingFeature::fixedSizeIntType())
86+
llvm_unreachable("NYI");
87+
88+
return (isPromotableIntegerTypeForABI(RetTy) && isDarwinPCS()
89+
? ABIArgInfo::getExtend(RetTy)
90+
: ABIArgInfo::getDirect());
91+
}
92+
93+
llvm_unreachable("NYI");
94+
}
95+
96+
ABIArgInfo
97+
AArch64ABIInfo::classifyArgumentType(Type Ty, bool IsVariadic,
98+
unsigned CallingConvention) const {
99+
Ty = useFirstFieldIfTransparentUnion(Ty);
100+
101+
// TODO(cir): check for illegal vector types.
102+
if (MissingFeature::vectorType())
103+
llvm_unreachable("NYI");
104+
105+
if (!isAggregateTypeForABI(Ty)) {
106+
// NOTE(cir): Enum is IntType in CIR. Skip enum handling here.
107+
108+
if (MissingFeature::fixedSizeIntType())
109+
llvm_unreachable("NYI");
110+
111+
return (isPromotableIntegerTypeForABI(Ty) && isDarwinPCS()
112+
? ABIArgInfo::getExtend(Ty)
113+
: ABIArgInfo::getDirect());
114+
}
115+
70116
llvm_unreachable("NYI");
71117
}
72118

clang/test/CIR/Transforms/Target/aarch64/aarch64-call-conv-lowering-pass.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,31 @@ void Void(void) {
66
// CHECK: cir.call @_Z4Voidv() : () -> ()
77
Void();
88
}
9+
10+
// Test call conv lowering for trivial usinged integer cases.
11+
12+
// CHECK: cir.func @_Z5UCharh(%arg0: !u8i loc({{.+}})) -> !u8i
13+
unsigned char UChar(unsigned char c) {
14+
// CHECK: cir.call @_Z5UCharh(%2) : (!u8i) -> !u8i
15+
return UChar(c);
16+
}
17+
// CHECK: cir.func @_Z6UShortt(%arg0: !u16i loc({{.+}})) -> !u16i
18+
unsigned short UShort(unsigned short s) {
19+
// CHECK: cir.call @_Z6UShortt(%2) : (!u16i) -> !u16i
20+
return UShort(s);
21+
}
22+
// CHECK: cir.func @_Z4UIntj(%arg0: !u32i loc({{.+}})) -> !u32i
23+
unsigned int UInt(unsigned int i) {
24+
// CHECK: cir.call @_Z4UIntj(%2) : (!u32i) -> !u32i
25+
return UInt(i);
26+
}
27+
// CHECK: cir.func @_Z5ULongm(%arg0: !u64i loc({{.+}})) -> !u64i
28+
unsigned long ULong(unsigned long l) {
29+
// CHECK: cir.call @_Z5ULongm(%2) : (!u64i) -> !u64i
30+
return ULong(l);
31+
}
32+
// CHECK: cir.func @_Z9ULongLongy(%arg0: !u64i loc({{.+}})) -> !u64i
33+
unsigned long long ULongLong(unsigned long long l) {
34+
// CHECK: cir.call @_Z9ULongLongy(%2) : (!u64i) -> !u64i
35+
return ULongLong(l);
36+
}

0 commit comments

Comments
 (0)