Skip to content

Commit 12dfdd3

Browse files
committed
[AVR] Rewrite the function calling convention.
Summary: The previous version relied on the standard calling convention using std::reverse() to try to force the AVR ABI. But this only works for simple cases, it fails for example with aggregate types. This patch rewrites the calling convention with custom C++ code, that implements the ABI defined in https://gcc.gnu.org/wiki/avr-gcc. To do that it adds a few 16-bit pseudo registers for unaligned argument passing, such as R24R23. For example this function: define void @fun({ i8, i16 } %a) will pass %a.0 in R22 and %a.1 in R24R23. There are no instructions that can use these pseudo registers, so a new register class, DREGSMOVW, is defined to make them apart. Also the ArgCC_AVR_BUILTIN_DIV is no longer necessary, as it is identical to the C++ behavior (actually the clobber list is more strict for __div* functions, but that is currently unimplemented). Reviewers: dylanmckay Subscribers: Gaelan, Sh4rK, indirect, jwagen, efriedma, dsprenkels, hiraditya, Jim, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68524 Patch by Rodrigo Rivas Costa.
1 parent 118ac53 commit 12dfdd3

File tree

9 files changed

+436
-211
lines changed

9 files changed

+436
-211
lines changed

llvm/lib/Target/AVR/AVRCallingConv.td

+1-17
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,13 @@
66
//
77
//===----------------------------------------------------------------------===//
88
// This describes the calling conventions for AVR architecture.
9+
// Normal functions use a special calling convention, solved in code.
910
//===----------------------------------------------------------------------===//
1011

1112
//===----------------------------------------------------------------------===//
1213
// AVR Return Value Calling Convention
1314
//===----------------------------------------------------------------------===//
1415

15-
def RetCC_AVR : CallingConv
16-
<[
17-
// i8 is returned in R24.
18-
CCIfType<[i8], CCAssignToReg<[R24]>>,
19-
20-
// i16 are returned in R25:R24, R23:R22, R21:R20 and R19:R18.
21-
CCIfType<[i16], CCAssignToReg<[R25R24, R23R22, R21R20, R19R18]>>
22-
]>;
23-
2416
// Special return value calling convention for runtime functions.
2517
def RetCC_AVR_BUILTIN : CallingConv
2618
<[
@@ -41,14 +33,6 @@ def ArgCC_AVR_Vararg : CallingConv
4133
CCAssignToStack<2, 1>
4234
]>;
4335

44-
// Special argument calling convention for
45-
// division runtime functions.
46-
def ArgCC_AVR_BUILTIN_DIV : CallingConv
47-
<[
48-
CCIfType<[i8], CCAssignToReg<[R24,R22]>>,
49-
CCIfType<[i16], CCAssignToReg<[R25R24, R23R22]>>
50-
]>;
51-
5236
//===----------------------------------------------------------------------===//
5337
// Callee-saved register lists.
5438
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)