Skip to content

Commit 60e4512

Browse files
committed
rebase
Created using spr 1.3.5
2 parents 9c2b99e + 6a79d2b commit 60e4512

File tree

6 files changed

+128
-13
lines changed

6 files changed

+128
-13
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ struct MissingFeatures {
230230
static bool shouldInstrumentFunction() { return false; }
231231
static bool xray() { return false; }
232232
static bool buildConstrainedFPCall() { return false; }
233+
static bool emitEmptyRecordCheck() { return false; }
233234

234235
// Inline assembly
235236
static bool asmGoto() { return false; }

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ arrangeFreeFunctionLikeCall(LowerTypes &LT, LowerModule &LM,
4747

4848
cir_cconv_assert(!::cir::MissingFeatures::chainCall() && !chainCall && "NYI");
4949
FnInfoOpts opts = chainCall ? FnInfoOpts::IsChainCall : FnInfoOpts::None;
50-
return LT.arrangeLLVMFunctionInfo(fnType.getReturnType(), opts,
51-
fnType.getInputs(), required);
50+
51+
SmallVector<Type> argTypes;
52+
for (const auto &a : args)
53+
argTypes.push_back(a.getType());
54+
55+
return LT.arrangeLLVMFunctionInfo(fnType.getReturnType(), opts, argTypes,
56+
required);
5257
}
5358

5459
/// Adds the formal parameters in FPT to the given prefix. If any parameter in

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ class RequiredArgs {
4949
if (!prototype.isVarArg())
5050
return All;
5151

52-
cir_cconv_assert_or_abort(!::cir::MissingFeatures::variadicFunctions(),
53-
"NYI");
54-
return All; // FIXME(cir): Temporary workaround for the assertion above.
52+
return RequiredArgs(prototype.getNumInputs() + additional);
5553
}
5654

5755
bool allowsOptionalArgs() const { return NumRequired != ~0U; }
56+
57+
unsigned getNumRequiredArgs() const {
58+
assert(allowsOptionalArgs());
59+
return NumRequired;
60+
}
5861
};
5962

6063
// Implementation detail of LowerFunctionInfo, factored out so it can be
@@ -149,14 +152,9 @@ class LowerFunctionInfo final
149152

150153
unsigned arg_size() const { return NumArgs; }
151154

152-
bool isVariadic() const {
153-
cir_cconv_assert(!::cir::MissingFeatures::variadicFunctions());
154-
return false;
155-
}
155+
bool isVariadic() const { return Required.allowsOptionalArgs(); }
156156
unsigned getNumRequiredArgs() const {
157-
if (isVariadic())
158-
cir_cconv_unreachable("NYI");
159-
return arg_size();
157+
return isVariadic() ? Required.getNumRequiredArgs() : arg_size();
160158
}
161159

162160
Type getReturnType() const { return getArgsBuffer()[0].type; }

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8-
98
#include "clang/CIR/Target/AArch64.h"
109
#include "ABIInfoImpl.h"
1110
#include "LowerFunctionInfo.h"
@@ -105,6 +104,39 @@ ABIArgInfo AArch64ABIInfo::classifyReturnType(Type RetTy,
105104
: ABIArgInfo::getDirect());
106105
}
107106

107+
uint64_t Size = getContext().getTypeSize(RetTy);
108+
cir_cconv_assert(!::cir::MissingFeatures::emitEmptyRecordCheck());
109+
cir_cconv_assert(
110+
!::cir::MissingFeatures::supportisHomogeneousAggregateQueryForAArch64());
111+
112+
// Aggregates <= 16 bytes are returned directly in registers or on the stack.
113+
if (Size <= 128) {
114+
if (Size <= 64 && !getDataLayout().isBigEndian()) {
115+
// Composite types are returned in lower bits of a 64-bit register for LE,
116+
// and in higher bits for BE. However, integer types are always returned
117+
// in lower bits for both LE and BE, and they are not rounded up to
118+
// 64-bits. We can skip rounding up of composite types for LE, but not for
119+
// BE, otherwise composite types will be indistinguishable from integer
120+
// types.
121+
return ABIArgInfo::getDirect(
122+
mlir::cir::IntType::get(LT.getMLIRContext(), Size, false));
123+
}
124+
125+
unsigned Alignment = getContext().getTypeAlign(RetTy);
126+
Size = llvm::alignTo(Size, 64); // round up to multiple of 8 bytes
127+
128+
// We use a pair of i64 for 16-byte aggregate with 8-byte alignment.
129+
// For aggregates with 16-byte alignment, we use i128.
130+
if (Alignment < 128 && Size == 128) {
131+
mlir::Type baseTy =
132+
mlir::cir::IntType::get(LT.getMLIRContext(), 64, false);
133+
return ABIArgInfo::getDirect(
134+
mlir::cir::ArrayType::get(LT.getMLIRContext(), baseTy, Size / 64));
135+
}
136+
137+
cir_cconv_unreachable("NYI");
138+
}
139+
108140
cir_cconv_unreachable("NYI");
109141
}
110142

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -fclangir -fclangir-call-conv-lowering -emit-cir-flat -mmlir --mlir-print-ir-after=cir-call-conv-lowering %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s
3+
4+
#include <stdint.h>
5+
6+
typedef struct {
7+
short a;
8+
} LT_64;
9+
10+
typedef struct {
11+
int64_t a;
12+
} EQ_64;
13+
14+
typedef struct {
15+
int64_t a;
16+
int b;
17+
} LT_128;
18+
19+
typedef struct {
20+
int64_t a;
21+
int64_t b;
22+
} EQ_128;
23+
24+
// CHECK: cir.func {{.*@ret_lt_64}}() -> !u16i
25+
// CHECK: %[[#V0:]] = cir.alloca !ty_LT_64_, !cir.ptr<!ty_LT_64_>, ["__retval"]
26+
// CHECK: %[[#V1:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr<!ty_LT_64_>), !cir.ptr<!u16i>
27+
// CHECK: %[[#V2:]] = cir.load %[[#V1]] : !cir.ptr<!u16i>, !u16i
28+
// CHECK: cir.return %[[#V2]] : !u16i
29+
LT_64 ret_lt_64() {
30+
LT_64 x;
31+
return x;
32+
}
33+
34+
// CHECK: cir.func {{.*@ret_eq_64}}() -> !u64i
35+
// CHECK: %[[#V0:]] = cir.alloca !ty_EQ_64_, !cir.ptr<!ty_EQ_64_>, ["__retval"]
36+
// CHECK: %[[#V1:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr<!ty_EQ_64_>), !cir.ptr<!u64i>
37+
// CHECK: %[[#V2:]] = cir.load %[[#V1]] : !cir.ptr<!u64i>, !u64i
38+
// CHECK: cir.return %[[#V2]] : !u64i
39+
EQ_64 ret_eq_64() {
40+
EQ_64 x;
41+
return x;
42+
}
43+
44+
// CHECK: cir.func {{.*@ret_lt_128}}() -> !cir.array<!u64i x 2>
45+
// CHECK: %[[#V0:]] = cir.alloca !ty_LT_128_, !cir.ptr<!ty_LT_128_>, ["__retval"]
46+
// CHECK: %[[#V1:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr<!ty_LT_128_>), !cir.ptr<!cir.array<!u64i x 2>>
47+
// CHECK: %[[#V2:]] = cir.load %[[#V1]] : !cir.ptr<!cir.array<!u64i x 2>>, !cir.array<!u64i x 2>
48+
// CHECK: cir.return %[[#V2]] : !cir.array<!u64i x 2>
49+
LT_128 ret_lt_128() {
50+
LT_128 x;
51+
return x;
52+
}
53+
54+
// CHECK: cir.func {{.*@ret_eq_128}}() -> !cir.array<!u64i x 2>
55+
// CHECK: %[[#V0:]] = cir.alloca !ty_EQ_128_, !cir.ptr<!ty_EQ_128_>, ["__retval"]
56+
// CHECK: %[[#V1:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr<!ty_EQ_128_>), !cir.ptr<!cir.array<!u64i x 2>>
57+
// CHECK: %[[#V2:]] = cir.load %[[#V1]] : !cir.ptr<!cir.array<!u64i x 2>>, !cir.array<!u64i x 2>
58+
// CHECK: cir.return %[[#V2]] : !cir.array<!u64i x 2>
59+
EQ_128 ret_eq_128() {
60+
EQ_128 x;
61+
return x;
62+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -fclangir-call-conv-lowering -emit-cir-flat -mmlir --mlir-print-ir-after=cir-call-conv-lowering %s -o %t.cir
2+
3+
int printf(const char *str, ...);
4+
5+
// CHECK: cir.func {{.*@bar}}
6+
// CHECK: %[[#V1:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init]
7+
// CHECK: %[[#V2:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["b", init]
8+
// CHECK: cir.store %arg0, %[[#V0]] : !s32i, !cir.ptr<!s32i>
9+
// CHECK: cir.store %arg1, %[[#V1]] : !s32i, !cir.ptr<!s32i>
10+
// CHECK: %[[#V2:]] = cir.get_global @".str" : !cir.ptr<!cir.array<!s8i x 7>>
11+
// CHECK: %[[#V3:]] = cir.cast(array_to_ptrdecay, %[[#V2]] : !cir.ptr<!cir.array<!s8i x 7>>), !cir.ptr<!s8i>
12+
// CHECK: %[[#V4:]] = cir.load %[[#V1]] : !cir.ptr<!s32i>, !s32i
13+
// CHECK: %[[#V5:]] = cir.load %[[#V2]] : !cir.ptr<!s32i>, !s32i
14+
// CHECK: %[[#V6:]] = cir.call @printf(%[[#V3]], %[[#V4]], %[[#V5]]) : (!cir.ptr<!s8i>, !s32i, !s32i) -> !s32i
15+
void bar(int a, int b) {
16+
printf("%d %d\n", a, b);
17+
}

0 commit comments

Comments
 (0)