xref: /freebsd/contrib/llvm-project/llvm/lib/Target/M68k/M68kCallingConv.td (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1//===-- M68kCallingConv.td - Calling Conventions for M68k --*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This describes the calling conventions for the M68k architectures. These
11/// conventions assume Int to be 4 bytes and 4 byte aligned.
12///
13//===----------------------------------------------------------------------===//
14
15// TODO Verify C convention follows SysV M68K ABI
16
17class CCIfSubtarget<string F, CCAction A>
18    : CCIf<!strconcat("static_cast<const M68kSubtarget &>"
19                      "(State.getMachineFunction().getSubtarget()).", F), A>;
20
21//===----------------------------------------------------------------------===//
22// Return Value Calling Conventions
23//===----------------------------------------------------------------------===//
24
25/// Return-value conventions common to all M68k CC's.
26def RetCC_M68kCommon : CallingConv<[
27]>;
28
29/// M68k C return convention.
30/// TODO: Return via address register
31def RetCC_M68k_C : CallingConv<[
32  CCIfType<[i1],   CCPromoteToType<i8>>,
33  CCIfType<[i8],   CCAssignToReg<[BD0, BD1]>>,
34  CCIfType<[i16],  CCAssignToReg<[WD0, WD1]>>,
35  CCIfType<[i32],  CCAssignToReg<[D0, D1]>>,
36  CCDelegateTo<RetCC_M68kCommon>
37]>;
38
39/// M68k fastcc return convention.
40/// This convention allows to return up to 16 bytes in registers which can be
41/// split among 16 1-byte values or used for a single 16-byte value.
42/// TODO: Verify its functionality and write tests
43def RetCC_M68k_Fast : CallingConv<[
44  CCIfType<[i1],   CCPromoteToType<i8>>,
45  CCIfType<[i8],   CCAssignToReg<[BD0, BD1]>>,
46  CCIfType<[i16],  CCAssignToReg<[WD0, WD1, WA0, WA1]>>,
47  CCIfType<[i32],  CCAssignToReg<[D0, D1, A0, A1]>>,
48  CCDelegateTo<RetCC_M68kCommon>
49]>;
50
51/// This is the root return-value convention for the M68k backend.
52def RetCC_M68k : CallingConv<[
53  CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_M68k_Fast>>,
54  CCDelegateTo<RetCC_M68k_C>
55]>;
56
57//===----------------------------------------------------------------------===//
58// M68k C Calling Convention
59//===----------------------------------------------------------------------===//
60
61/// CC_M68k_Common - In all M68k calling conventions, extra integers and FP
62/// values are spilled on the stack.
63def CC_M68k_Common : CallingConv<[
64  /// Handles byval parameters.
65  CCIfByVal<CCPassByVal<4, 4>>,
66
67  /// Integer values get stored in stack slots that are 4 bytes in
68  /// size and 4-byte aligned.
69  CCIfType<[i32],  CCAssignToStack<4, 4>>
70]>;
71
72def CC_M68k_Fast : CallingConv<[
73  /// Promote i1/i8/i16 arguments to i32.
74  CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
75
76  /// The 'nest' parameter, if any, is passed in A1.
77  CCIfNest<CCAssignToReg<[A1]>>, // FIXME verify if this is correct
78
79  /// Since M68k uses %An for pointers and we want them be passed in regs
80  /// too we have to use custom function.
81  CCIfType<[i32], CCCustom<"CC_M68k_Any_AssignToReg">>,
82
83  /// Otherwise, same as everything else.
84  CCDelegateTo<CC_M68k_Common>
85]>;
86
87def CC_M68k_C : CallingConv<[
88  /// Promote i1/i8/i16 arguments to i32.
89  CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
90
91  /// The 'nest' parameter, if any, is passed in A1.
92  CCIfNest<CCAssignToReg<[A1]>>, // FIXME verify if this is correct
93
94  /// Use registers only if 'inreg' used and the call is not vararg
95  CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[D0, D1]>>>>,
96
97  // TODO: Support for 'sret'
98
99  /// Otherwise, same as everything else.
100  CCDelegateTo<CC_M68k_Common>
101]>;
102
103/// This is the root argument convention for the M68k backend.
104def CC_M68k : CallingConv<[
105  CCIfCC<"CallingConv::Fast", CCDelegateTo<CC_M68k_Fast>>,
106  CCDelegateTo<CC_M68k_C>
107]>;
108
109//===----------------------------------------------------------------------===//
110// Callee-saved Registers.
111//===----------------------------------------------------------------------===//
112
113def CSR_NoRegs : CalleeSavedRegs<(add)>;
114
115// A5 - BP
116// A6 - FP
117def CSR_STD : CalleeSavedRegs<(add D2, D3, D4, D5, D6, D7,
118                                   A2, A3, A4, A5, A6)>;
119
120