LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CallingConvLower.cpp
Go to the documentation of this file.
1 //===-- CallingConvLower.cpp - Calling Conventions ------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the CCState class, used for lowering and implementing
11 // calling conventions.
12 //
13 //===----------------------------------------------------------------------===//
14 
17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/Support/Debug.h"
24 using namespace llvm;
25 
28  LLVMContext &C)
29  : CallingConv(CC), IsVarArg(isVarArg), MF(mf), TM(tm),
30  TRI(*TM.getRegisterInfo()), Locs(locs), Context(C),
31  CallOrPrologue(Unknown) {
32  // No stack is used.
33  StackOffset = 0;
34 
36  UsedRegs.resize((TRI.getNumRegs()+31)/32);
37 }
38 
39 // HandleByVal - Allocate space on the stack large enough to pass an argument
40 // by value. The size and alignment information of the argument is encoded in
41 // its parameter attribute.
42 void CCState::HandleByVal(unsigned ValNo, MVT ValVT,
43  MVT LocVT, CCValAssign::LocInfo LocInfo,
44  int MinSize, int MinAlign,
45  ISD::ArgFlagsTy ArgFlags) {
46  unsigned Align = ArgFlags.getByValAlign();
47  unsigned Size = ArgFlags.getByValSize();
48  if (MinSize > (int)Size)
49  Size = MinSize;
50  if (MinAlign > (int)Align)
51  Align = MinAlign;
52  MF.getFrameInfo()->ensureMaxAlignment(Align);
53  TM.getTargetLowering()->HandleByVal(this, Size, Align);
54  unsigned Offset = AllocateStack(Size, Align);
55  addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
56 }
57 
58 /// MarkAllocated - Mark a register and all of its aliases as allocated.
59 void CCState::MarkAllocated(unsigned Reg) {
60  for (MCRegAliasIterator AI(Reg, &TRI, true); AI.isValid(); ++AI)
61  UsedRegs[*AI/32] |= 1 << (*AI&31);
62 }
63 
64 /// AnalyzeFormalArguments - Analyze an array of argument values,
65 /// incorporating info about the formals into this state.
66 void
68  CCAssignFn Fn) {
69  unsigned NumArgs = Ins.size();
70 
71  for (unsigned i = 0; i != NumArgs; ++i) {
72  MVT ArgVT = Ins[i].VT;
73  ISD::ArgFlagsTy ArgFlags = Ins[i].Flags;
74  if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
75 #ifndef NDEBUG
76  dbgs() << "Formal argument #" << i << " has unhandled type "
77  << EVT(ArgVT).getEVTString() << '\n';
78 #endif
80  }
81  }
82 }
83 
84 /// CheckReturn - Analyze the return values of a function, returning true if
85 /// the return can be performed without sret-demotion, and false otherwise.
87  CCAssignFn Fn) {
88  // Determine which register each value should be copied into.
89  for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
90  MVT VT = Outs[i].VT;
91  ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
92  if (Fn(i, VT, VT, CCValAssign::Full, ArgFlags, *this))
93  return false;
94  }
95  return true;
96 }
97 
98 /// AnalyzeReturn - Analyze the returned values of a return,
99 /// incorporating info about the result values into this state.
101  CCAssignFn Fn) {
102  // Determine which register each value should be copied into.
103  for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
104  MVT VT = Outs[i].VT;
105  ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
106  if (Fn(i, VT, VT, CCValAssign::Full, ArgFlags, *this)) {
107 #ifndef NDEBUG
108  dbgs() << "Return operand #" << i << " has unhandled type "
109  << EVT(VT).getEVTString() << '\n';
110 #endif
111  llvm_unreachable(0);
112  }
113  }
114 }
115 
116 /// AnalyzeCallOperands - Analyze the outgoing arguments to a call,
117 /// incorporating info about the passed values into this state.
119  CCAssignFn Fn) {
120  unsigned NumOps = Outs.size();
121  for (unsigned i = 0; i != NumOps; ++i) {
122  MVT ArgVT = Outs[i].VT;
123  ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
124  if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
125 #ifndef NDEBUG
126  dbgs() << "Call operand #" << i << " has unhandled type "
127  << EVT(ArgVT).getEVTString() << '\n';
128 #endif
129  llvm_unreachable(0);
130  }
131  }
132 }
133 
134 /// AnalyzeCallOperands - Same as above except it takes vectors of types
135 /// and argument flags.
138  CCAssignFn Fn) {
139  unsigned NumOps = ArgVTs.size();
140  for (unsigned i = 0; i != NumOps; ++i) {
141  MVT ArgVT = ArgVTs[i];
142  ISD::ArgFlagsTy ArgFlags = Flags[i];
143  if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
144 #ifndef NDEBUG
145  dbgs() << "Call operand #" << i << " has unhandled type "
146  << EVT(ArgVT).getEVTString() << '\n';
147 #endif
148  llvm_unreachable(0);
149  }
150  }
151 }
152 
153 /// AnalyzeCallResult - Analyze the return values of a call,
154 /// incorporating info about the passed values into this state.
156  CCAssignFn Fn) {
157  for (unsigned i = 0, e = Ins.size(); i != e; ++i) {
158  MVT VT = Ins[i].VT;
159  ISD::ArgFlagsTy Flags = Ins[i].Flags;
160  if (Fn(i, VT, VT, CCValAssign::Full, Flags, *this)) {
161 #ifndef NDEBUG
162  dbgs() << "Call result #" << i << " has unhandled type "
163  << EVT(VT).getEVTString() << '\n';
164 #endif
165  llvm_unreachable(0);
166  }
167  }
168 }
169 
170 /// AnalyzeCallResult - Same as above except it's specialized for calls which
171 /// produce a single value.
173  if (Fn(0, VT, VT, CCValAssign::Full, ISD::ArgFlagsTy(), *this)) {
174 #ifndef NDEBUG
175  dbgs() << "Call result has unhandled type "
176  << EVT(VT).getEVTString() << '\n';
177 #endif
178  llvm_unreachable(0);
179  }
180 }
void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
virtual const TargetLowering * getTargetLowering() const
void AnalyzeFormalArguments(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
unsigned getByValSize() const
bool CheckReturn(const SmallVectorImpl< ISD::OutputArg > &ArgsFlags, CCAssignFn Fn)
virtual void HandleByVal(CCState *, unsigned &, unsigned) const
Target-specific cleanup for formal ByVal parameters.
std::string getEVTString() const
getEVTString - This function returns value type as a string, e.g. "i32".
Definition: ValueTypes.cpp:106
#define llvm_unreachable(msg)
void addLoc(const CCValAssign &V)
ID
LLVM Calling Convention Representation.
Definition: CallingConv.h:26
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
CCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, const TargetMachine &TM, SmallVectorImpl< CCValAssign > &locs, LLVMContext &C)
void HandleByVal(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, int MinSize, int MinAlign, ISD::ArgFlagsTy ArgFlags)
unsigned getByValAlign() const
MachineFrameInfo * getFrameInfo()
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
Definition: Debug.cpp:101
void AnalyzeCallOperands(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
uint64_t MinAlign(uint64_t A, uint64_t B)
Definition: MathExtras.h:535
void ensureMaxAlignment(unsigned Align)
void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
void resize(unsigned N)
Definition: SmallVector.h:401
static CCValAssign getMem(unsigned ValNo, MVT ValVT, unsigned Offset, MVT LocVT, LocInfo HTP)
void clearByValRegsInfo()
unsigned AllocateStack(unsigned Size, unsigned Align)