blob: 11ed4f5b808059a6871bb8119311d02c77ec366f [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- TargetCallingConv.td - Target Calling Conventions ---*- tablegen -*-===//
Andrew Scullcdfcccc2018-10-05 20:58:37 +01002//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scullcdfcccc2018-10-05 20:58:37 +01006//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01007//===----------------------------------------------------------------------===//
8//
9// This file defines the target-independent interfaces with which targets
10// describe their calling conventions.
11//
12//===----------------------------------------------------------------------===//
13
14class CCAction;
15class CallingConv;
16
17/// CCCustom - Calls a custom arg handling function.
18class CCCustom<string fn> : CCAction {
19 string FuncName = fn;
20}
21
22/// CCPredicateAction - Instances of this class check some predicate, then
23/// delegate to another action if the predicate is true.
24class CCPredicateAction<CCAction A> : CCAction {
25 CCAction SubAction = A;
26}
27
28/// CCIfType - If the current argument is one of the specified types, apply
29/// Action A.
30class CCIfType<list<ValueType> vts, CCAction A> : CCPredicateAction<A> {
31 list<ValueType> VTs = vts;
32}
33
34/// CCIf - If the predicate matches, apply A.
35class CCIf<string predicate, CCAction A> : CCPredicateAction<A> {
36 string Predicate = predicate;
37}
38
39/// CCIfByVal - If the current argument has ByVal parameter attribute, apply
40/// Action A.
41class CCIfByVal<CCAction A> : CCIf<"ArgFlags.isByVal()", A> {
42}
43
44/// CCIfSwiftSelf - If the current argument has swiftself parameter attribute,
45/// apply Action A.
46class CCIfSwiftSelf<CCAction A> : CCIf<"ArgFlags.isSwiftSelf()", A> {
47}
48
49/// CCIfSwiftError - If the current argument has swifterror parameter attribute,
50/// apply Action A.
51class CCIfSwiftError<CCAction A> : CCIf<"ArgFlags.isSwiftError()", A> {
52}
53
54/// CCIfConsecutiveRegs - If the current argument has InConsecutiveRegs
55/// parameter attribute, apply Action A.
56class CCIfConsecutiveRegs<CCAction A> : CCIf<"ArgFlags.isInConsecutiveRegs()", A> {
57}
58
59/// CCIfCC - Match if the current calling convention is 'CC'.
60class CCIfCC<string CC, CCAction A>
61 : CCIf<!strconcat("State.getCallingConv() == ", CC), A> {}
62
63/// CCIfInReg - If this argument is marked with the 'inreg' attribute, apply
64/// the specified action.
65class CCIfInReg<CCAction A> : CCIf<"ArgFlags.isInReg()", A> {}
66
67/// CCIfNest - If this argument is marked with the 'nest' attribute, apply
68/// the specified action.
69class CCIfNest<CCAction A> : CCIf<"ArgFlags.isNest()", A> {}
70
71/// CCIfSplit - If this argument is marked with the 'split' attribute, apply
72/// the specified action.
73class CCIfSplit<CCAction A> : CCIf<"ArgFlags.isSplit()", A> {}
74
75/// CCIfSRet - If this argument is marked with the 'sret' attribute, apply
76/// the specified action.
77class CCIfSRet<CCAction A> : CCIf<"ArgFlags.isSRet()", A> {}
78
79/// CCIfVarArg - If the current function is vararg - apply the action
80class CCIfVarArg<CCAction A> : CCIf<"State.isVarArg()", A> {}
81
82/// CCIfNotVarArg - If the current function is not vararg - apply the action
83class CCIfNotVarArg<CCAction A> : CCIf<"!State.isVarArg()", A> {}
84
85/// CCAssignToReg - This action matches if there is a register in the specified
86/// list that is still available. If so, it assigns the value to the first
87/// available register and succeeds.
88class CCAssignToReg<list<Register> regList> : CCAction {
89 list<Register> RegList = regList;
90}
91
92/// CCAssignToRegWithShadow - Same as CCAssignToReg, but with list of registers
93/// which became shadowed, when some register is used.
94class CCAssignToRegWithShadow<list<Register> regList,
95 list<Register> shadowList> : CCAction {
96 list<Register> RegList = regList;
97 list<Register> ShadowRegList = shadowList;
98}
99
100/// CCAssignToStack - This action always matches: it assigns the value to a
101/// stack slot of the specified size and alignment on the stack. If size is
102/// zero then the ABI size is used; if align is zero then the ABI alignment
103/// is used - these may depend on the target or subtarget.
104class CCAssignToStack<int size, int align> : CCAction {
105 int Size = size;
106 int Align = align;
107}
108
109/// CCAssignToStackWithShadow - Same as CCAssignToStack, but with a list of
110/// registers to be shadowed. Note that, unlike CCAssignToRegWithShadow, this
111/// shadows ALL of the registers in shadowList.
112class CCAssignToStackWithShadow<int size,
113 int align,
114 list<Register> shadowList> : CCAction {
115 int Size = size;
116 int Align = align;
117 list<Register> ShadowRegList = shadowList;
118}
119
120/// CCPassByVal - This action always matches: it assigns the value to a stack
121/// slot to implement ByVal aggregate parameter passing. Size and alignment
122/// specify the minimum size and alignment for the stack slot.
123class CCPassByVal<int size, int align> : CCAction {
124 int Size = size;
125 int Align = align;
126}
127
128/// CCPromoteToType - If applied, this promotes the specified current value to
129/// the specified type.
130class CCPromoteToType<ValueType destTy> : CCAction {
131 ValueType DestTy = destTy;
132}
133
134/// CCPromoteToUpperBitsInType - If applied, this promotes the specified current
135/// value to the specified type and shifts the value into the upper bits.
136class CCPromoteToUpperBitsInType<ValueType destTy> : CCAction {
137 ValueType DestTy = destTy;
138}
139
140/// CCBitConvertToType - If applied, this bitconverts the specified current
141/// value to the specified type.
142class CCBitConvertToType<ValueType destTy> : CCAction {
143 ValueType DestTy = destTy;
144}
145
146/// CCPassIndirect - If applied, this stores the value to stack and passes the pointer
147/// as normal argument.
148class CCPassIndirect<ValueType destTy> : CCAction {
149 ValueType DestTy = destTy;
150}
151
152/// CCDelegateTo - This action invokes the specified sub-calling-convention. It
153/// is successful if the specified CC matches.
154class CCDelegateTo<CallingConv cc> : CCAction {
155 CallingConv CC = cc;
156}
157
158/// CallingConv - An instance of this is used to define each calling convention
159/// that the target supports.
160class CallingConv<list<CCAction> actions> {
161 list<CCAction> Actions = actions;
Andrew Walbran16937d02019-10-22 13:54:20 +0100162
163 /// If true, this calling convention will be emitted as externally visible in
164 /// the llvm namespaces instead of as a static function.
165 bit Entry = 0;
166
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100167 bit Custom = 0;
168}
169
170/// CustomCallingConv - An instance of this is used to declare calling
171/// conventions that are implemented using a custom function of the same name.
172class CustomCallingConv : CallingConv<[]> {
173 let Custom = 1;
174}
175
176/// CalleeSavedRegs - A list of callee saved registers for a given calling
177/// convention. The order of registers is used by PrologEpilogInsertion when
178/// allocation stack slots for saved registers.
179///
180/// For each CalleeSavedRegs def, TableGen will emit a FOO_SaveList array for
181/// returning from getCalleeSavedRegs(), and a FOO_RegMask bit mask suitable for
182/// returning from getCallPreservedMask().
183class CalleeSavedRegs<dag saves> {
184 dag SaveList = saves;
185
186 // Registers that are also preserved across function calls, but should not be
187 // included in the generated FOO_SaveList array. These registers will be
188 // included in the FOO_RegMask bit mask. This can be used for registers that
189 // are saved automatically, like the SPARC register windows.
190 dag OtherPreserved;
191}