llvm.org GIT mirror llvm / 2f2b0ab
Move CallingConvLower.cpp out of the SelectionDAG directory. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107781 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
5 changed file(s) with 215 addition(s) and 216 deletion(s). Raw diff Collapse all Expand all
2323 class TargetRegisterInfo;
2424 class TargetMachine;
2525 class CCState;
26 class SDNode;
2726
2827 /// CCValAssign - Represent assignment of one arg/retval to a location.
2928 class CCValAssign {
22 Analysis.cpp
33 BranchFolding.cpp
44 CalcSpillWeights.cpp
5 CallingConvLower.cpp
56 CodePlacementOpt.cpp
67 CriticalAntiDepBreaker.cpp
78 DeadMachineInstructionElim.cpp
0 //===-- CallingConvLower.cpp - Calling Conventions ------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the CCState class, used for lowering and implementing
10 // calling conventions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/CodeGen/CallingConvLower.h"
15 #include "llvm/Support/Debug.h"
16 #include "llvm/Support/ErrorHandling.h"
17 #include "llvm/Support/raw_ostream.h"
18 #include "llvm/Target/TargetRegisterInfo.h"
19 #include "llvm/Target/TargetData.h"
20 #include "llvm/Target/TargetMachine.h"
21 using namespace llvm;
22
23 CCState::CCState(CallingConv::ID CC, bool isVarArg, const TargetMachine &tm,
24 SmallVector &locs, LLVMContext &C)
25 : CallingConv(CC), IsVarArg(isVarArg), TM(tm),
26 TRI(*TM.getRegisterInfo()), Locs(locs), Context(C) {
27 // No stack is used.
28 StackOffset = 0;
29
30 UsedRegs.resize((TRI.getNumRegs()+31)/32);
31 }
32
33 // HandleByVal - Allocate a stack slot large enough to pass an argument by
34 // value. The size and alignment information of the argument is encoded in its
35 // parameter attribute.
36 void CCState::HandleByVal(unsigned ValNo, EVT ValVT,
37 EVT LocVT, CCValAssign::LocInfo LocInfo,
38 int MinSize, int MinAlign,
39 ISD::ArgFlagsTy ArgFlags) {
40 unsigned Align = ArgFlags.getByValAlign();
41 unsigned Size = ArgFlags.getByValSize();
42 if (MinSize > (int)Size)
43 Size = MinSize;
44 if (MinAlign > (int)Align)
45 Align = MinAlign;
46 unsigned Offset = AllocateStack(Size, Align);
47
48 addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
49 }
50
51 /// MarkAllocated - Mark a register and all of its aliases as allocated.
52 void CCState::MarkAllocated(unsigned Reg) {
53 UsedRegs[Reg/32] |= 1 << (Reg&31);
54
55 if (const unsigned *RegAliases = TRI.getAliasSet(Reg))
56 for (; (Reg = *RegAliases); ++RegAliases)
57 UsedRegs[Reg/32] |= 1 << (Reg&31);
58 }
59
60 /// AnalyzeFormalArguments - Analyze an array of argument values,
61 /// incorporating info about the formals into this state.
62 void
63 CCState::AnalyzeFormalArguments(const SmallVectorImpl &Ins,
64 CCAssignFn Fn) {
65 unsigned NumArgs = Ins.size();
66
67 for (unsigned i = 0; i != NumArgs; ++i) {
68 EVT ArgVT = Ins[i].VT;
69 ISD::ArgFlagsTy ArgFlags = Ins[i].Flags;
70 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
71 #ifndef NDEBUG
72 dbgs() << "Formal argument #" << i << " has unhandled type "
73 << ArgVT.getEVTString();
74 #endif
75 llvm_unreachable(0);
76 }
77 }
78 }
79
80 /// CheckReturn - Analyze the return values of a function, returning true if
81 /// the return can be performed without sret-demotion, and false otherwise.
82 bool CCState::CheckReturn(const SmallVectorImpl &OutTys,
83 const SmallVectorImpl &ArgsFlags,
84 CCAssignFn Fn) {
85 // Determine which register each value should be copied into.
86 for (unsigned i = 0, e = OutTys.size(); i != e; ++i) {
87 EVT VT = OutTys[i];
88 ISD::ArgFlagsTy ArgFlags = ArgsFlags[i];
89 if (Fn(i, VT, VT, CCValAssign::Full, ArgFlags, *this))
90 return false;
91 }
92 return true;
93 }
94
95 /// AnalyzeReturn - Analyze the returned values of a return,
96 /// incorporating info about the result values into this state.
97 void CCState::AnalyzeReturn(const SmallVectorImpl &Outs,
98 CCAssignFn Fn) {
99 // Determine which register each value should be copied into.
100 for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
101 EVT VT = Outs[i].Val.getValueType();
102 ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
103 if (Fn(i, VT, VT, CCValAssign::Full, ArgFlags, *this)) {
104 #ifndef NDEBUG
105 dbgs() << "Return operand #" << i << " has unhandled type "
106 << VT.getEVTString();
107 #endif
108 llvm_unreachable(0);
109 }
110 }
111 }
112
113 void CCState::AnalyzeReturn(const SmallVectorImpl &Outs,
114 CCAssignFn Fn) {
115 // Determine which register each value should be copied into.
116 for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
117 EVT VT = Outs[i].VT;
118 ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
119 if (Fn(i, VT, VT, CCValAssign::Full, ArgFlags, *this)) {
120 #ifndef NDEBUG
121 dbgs() << "Return operand #" << i << " has unhandled type "
122 << VT.getEVTString();
123 #endif
124 llvm_unreachable(0);
125 }
126 }
127 }
128
129
130 /// AnalyzeCallOperands - Analyze the outgoing arguments to a call,
131 /// incorporating info about the passed values into this state.
132 void CCState::AnalyzeCallOperands(const SmallVectorImpl &Outs,
133 CCAssignFn Fn) {
134 unsigned NumOps = Outs.size();
135 for (unsigned i = 0; i != NumOps; ++i) {
136 EVT ArgVT = Outs[i].Val.getValueType();
137 ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
138 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
139 #ifndef NDEBUG
140 dbgs() << "Call operand #" << i << " has unhandled type "
141 << ArgVT.getEVTString();
142 #endif
143 llvm_unreachable(0);
144 }
145 }
146 }
147
148 /// AnalyzeCallOperands - Analyze the outgoing arguments to a call,
149 /// incorporating info about the passed values into this state.
150 void
151 CCState::AnalyzeCallOperands(const SmallVectorImpl &Outs,
152 CCAssignFn Fn) {
153 unsigned NumOps = Outs.size();
154 for (unsigned i = 0; i != NumOps; ++i) {
155 EVT ArgVT = Outs[i].VT;
156 ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
157 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
158 #ifndef NDEBUG
159 dbgs() << "Call operand #" << i << " has unhandled type "
160 << ArgVT.getEVTString();
161 #endif
162 llvm_unreachable(0);
163 }
164 }
165 }
166
167 /// AnalyzeCallOperands - Same as above except it takes vectors of types
168 /// and argument flags.
169 void CCState::AnalyzeCallOperands(SmallVectorImpl &ArgVTs,
170 SmallVectorImpl &Flags,
171 CCAssignFn Fn) {
172 unsigned NumOps = ArgVTs.size();
173 for (unsigned i = 0; i != NumOps; ++i) {
174 EVT ArgVT = ArgVTs[i];
175 ISD::ArgFlagsTy ArgFlags = Flags[i];
176 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
177 #ifndef NDEBUG
178 dbgs() << "Call operand #" << i << " has unhandled type "
179 << ArgVT.getEVTString();
180 #endif
181 llvm_unreachable(0);
182 }
183 }
184 }
185
186 /// AnalyzeCallResult - Analyze the return values of a call,
187 /// incorporating info about the passed values into this state.
188 void CCState::AnalyzeCallResult(const SmallVectorImpl &Ins,
189 CCAssignFn Fn) {
190 for (unsigned i = 0, e = Ins.size(); i != e; ++i) {
191 EVT VT = Ins[i].VT;
192 ISD::ArgFlagsTy Flags = Ins[i].Flags;
193 if (Fn(i, VT, VT, CCValAssign::Full, Flags, *this)) {
194 #ifndef NDEBUG
195 dbgs() << "Call result #" << i << " has unhandled type "
196 << VT.getEVTString();
197 #endif
198 llvm_unreachable(0);
199 }
200 }
201 }
202
203 /// AnalyzeCallResult - Same as above except it's specialized for calls which
204 /// produce a single value.
205 void CCState::AnalyzeCallResult(EVT VT, CCAssignFn Fn) {
206 if (Fn(0, VT, VT, CCValAssign::Full, ISD::ArgFlagsTy(), *this)) {
207 #ifndef NDEBUG
208 dbgs() << "Call result has unhandled type "
209 << VT.getEVTString();
210 #endif
211 llvm_unreachable(0);
212 }
213 }
0 add_llvm_library(LLVMSelectionDAG
1 CallingConvLower.cpp
21 DAGCombiner.cpp
32 FastISel.cpp
43 FunctionLoweringInfo.cpp
+0
-214
lib/CodeGen/SelectionDAG/CallingConvLower.cpp less more
None //===-- CallingConvLower.cpp - Calling Conventions ------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the CCState class, used for lowering and implementing
10 // calling conventions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/CodeGen/CallingConvLower.h"
15 #include "llvm/Support/Debug.h"
16 #include "llvm/Support/ErrorHandling.h"
17 #include "llvm/Support/raw_ostream.h"
18 #include "llvm/Target/TargetRegisterInfo.h"
19 #include "llvm/Target/TargetData.h"
20 #include "llvm/Target/TargetMachine.h"
21 using namespace llvm;
22
23 CCState::CCState(CallingConv::ID CC, bool isVarArg, const TargetMachine &tm,
24 SmallVector &locs, LLVMContext &C)
25 : CallingConv(CC), IsVarArg(isVarArg), TM(tm),
26 TRI(*TM.getRegisterInfo()), Locs(locs), Context(C) {
27 // No stack is used.
28 StackOffset = 0;
29
30 UsedRegs.resize((TRI.getNumRegs()+31)/32);
31 }
32
33 // HandleByVal - Allocate a stack slot large enough to pass an argument by
34 // value. The size and alignment information of the argument is encoded in its
35 // parameter attribute.
36 void CCState::HandleByVal(unsigned ValNo, EVT ValVT,
37 EVT LocVT, CCValAssign::LocInfo LocInfo,
38 int MinSize, int MinAlign,
39 ISD::ArgFlagsTy ArgFlags) {
40 unsigned Align = ArgFlags.getByValAlign();
41 unsigned Size = ArgFlags.getByValSize();
42 if (MinSize > (int)Size)
43 Size = MinSize;
44 if (MinAlign > (int)Align)
45 Align = MinAlign;
46 unsigned Offset = AllocateStack(Size, Align);
47
48 addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
49 }
50
51 /// MarkAllocated - Mark a register and all of its aliases as allocated.
52 void CCState::MarkAllocated(unsigned Reg) {
53 UsedRegs[Reg/32] |= 1 << (Reg&31);
54
55 if (const unsigned *RegAliases = TRI.getAliasSet(Reg))
56 for (; (Reg = *RegAliases); ++RegAliases)
57 UsedRegs[Reg/32] |= 1 << (Reg&31);
58 }
59
60 /// AnalyzeFormalArguments - Analyze an array of argument values,
61 /// incorporating info about the formals into this state.
62 void
63 CCState::AnalyzeFormalArguments(const SmallVectorImpl &Ins,
64 CCAssignFn Fn) {
65 unsigned NumArgs = Ins.size();
66
67 for (unsigned i = 0; i != NumArgs; ++i) {
68 EVT ArgVT = Ins[i].VT;
69 ISD::ArgFlagsTy ArgFlags = Ins[i].Flags;
70 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
71 #ifndef NDEBUG
72 dbgs() << "Formal argument #" << i << " has unhandled type "
73 << ArgVT.getEVTString();
74 #endif
75 llvm_unreachable(0);
76 }
77 }
78 }
79
80 /// CheckReturn - Analyze the return values of a function, returning true if
81 /// the return can be performed without sret-demotion, and false otherwise.
82 bool CCState::CheckReturn(const SmallVectorImpl &OutTys,
83 const SmallVectorImpl &ArgsFlags,
84 CCAssignFn Fn) {
85 // Determine which register each value should be copied into.
86 for (unsigned i = 0, e = OutTys.size(); i != e; ++i) {
87 EVT VT = OutTys[i];
88 ISD::ArgFlagsTy ArgFlags = ArgsFlags[i];
89 if (Fn(i, VT, VT, CCValAssign::Full, ArgFlags, *this))
90 return false;
91 }
92 return true;
93 }
94
95 /// AnalyzeReturn - Analyze the returned values of a return,
96 /// incorporating info about the result values into this state.
97 void CCState::AnalyzeReturn(const SmallVectorImpl &Outs,
98 CCAssignFn Fn) {
99 // Determine which register each value should be copied into.
100 for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
101 EVT VT = Outs[i].Val.getValueType();
102 ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
103 if (Fn(i, VT, VT, CCValAssign::Full, ArgFlags, *this)) {
104 #ifndef NDEBUG
105 dbgs() << "Return operand #" << i << " has unhandled type "
106 << VT.getEVTString();
107 #endif
108 llvm_unreachable(0);
109 }
110 }
111 }
112
113 void CCState::AnalyzeReturn(const SmallVectorImpl &Outs,
114 CCAssignFn Fn) {
115 // Determine which register each value should be copied into.
116 for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
117 EVT VT = Outs[i].VT;
118 ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
119 if (Fn(i, VT, VT, CCValAssign::Full, ArgFlags, *this)) {
120 #ifndef NDEBUG
121 dbgs() << "Return operand #" << i << " has unhandled type "
122 << VT.getEVTString();
123 #endif
124 llvm_unreachable(0);
125 }
126 }
127 }
128
129
130 /// AnalyzeCallOperands - Analyze the outgoing arguments to a call,
131 /// incorporating info about the passed values into this state.
132 void CCState::AnalyzeCallOperands(const SmallVectorImpl &Outs,
133 CCAssignFn Fn) {
134 unsigned NumOps = Outs.size();
135 for (unsigned i = 0; i != NumOps; ++i) {
136 EVT ArgVT = Outs[i].Val.getValueType();
137 ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
138 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
139 #ifndef NDEBUG
140 dbgs() << "Call operand #" << i << " has unhandled type "
141 << ArgVT.getEVTString();
142 #endif
143 llvm_unreachable(0);
144 }
145 }
146 }
147
148 /// AnalyzeCallOperands - Analyze the outgoing arguments to a call,
149 /// incorporating info about the passed values into this state.
150 void
151 CCState::AnalyzeCallOperands(const SmallVectorImpl &Outs,
152 CCAssignFn Fn) {
153 unsigned NumOps = Outs.size();
154 for (unsigned i = 0; i != NumOps; ++i) {
155 EVT ArgVT = Outs[i].VT;
156 ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
157 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
158 #ifndef NDEBUG
159 dbgs() << "Call operand #" << i << " has unhandled type "
160 << ArgVT.getEVTString();
161 #endif
162 llvm_unreachable(0);
163 }
164 }
165 }
166
167 /// AnalyzeCallOperands - Same as above except it takes vectors of types
168 /// and argument flags.
169 void CCState::AnalyzeCallOperands(SmallVectorImpl &ArgVTs,
170 SmallVectorImpl &Flags,
171 CCAssignFn Fn) {
172 unsigned NumOps = ArgVTs.size();
173 for (unsigned i = 0; i != NumOps; ++i) {
174 EVT ArgVT = ArgVTs[i];
175 ISD::ArgFlagsTy ArgFlags = Flags[i];
176 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
177 #ifndef NDEBUG
178 dbgs() << "Call operand #" << i << " has unhandled type "
179 << ArgVT.getEVTString();
180 #endif
181 llvm_unreachable(0);
182 }
183 }
184 }
185
186 /// AnalyzeCallResult - Analyze the return values of a call,
187 /// incorporating info about the passed values into this state.
188 void CCState::AnalyzeCallResult(const SmallVectorImpl &Ins,
189 CCAssignFn Fn) {
190 for (unsigned i = 0, e = Ins.size(); i != e; ++i) {
191 EVT VT = Ins[i].VT;
192 ISD::ArgFlagsTy Flags = Ins[i].Flags;
193 if (Fn(i, VT, VT, CCValAssign::Full, Flags, *this)) {
194 #ifndef NDEBUG
195 dbgs() << "Call result #" << i << " has unhandled type "
196 << VT.getEVTString();
197 #endif
198 llvm_unreachable(0);
199 }
200 }
201 }
202
203 /// AnalyzeCallResult - Same as above except it's specialized for calls which
204 /// produce a single value.
205 void CCState::AnalyzeCallResult(EVT VT, CCAssignFn Fn) {
206 if (Fn(0, VT, VT, CCValAssign::Full, ISD::ArgFlagsTy(), *this)) {
207 #ifndef NDEBUG
208 dbgs() << "Call result has unhandled type "
209 << VT.getEVTString();
210 #endif
211 llvm_unreachable(0);
212 }
213 }