LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HexagonCallingConvLower.cpp
Go to the documentation of this file.
1 //===-- llvm/CallingConvLower.cpp - Calling Convention lowering -----------===//
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 Hexagon_CCState class, used for lowering and
11 // implementing calling conventions. Adapted from the machine independent
12 // version of the class (CCState) but this handles calls to varargs functions
13 //
14 //===----------------------------------------------------------------------===//
15 
17 #include "Hexagon.h"
18 #include "llvm/IR/DataLayout.h"
19 #include "llvm/Support/Debug.h"
24 using namespace llvm;
25 
27  const TargetMachine &tm,
29  LLVMContext &c)
30  : CallingConv(CC), IsVarArg(isVarArg), TM(tm), Locs(locs), Context(c) {
31  // No stack is used.
32  StackOffset = 0;
33 
34  UsedRegs.resize((TM.getRegisterInfo()->getNumRegs()+31)/32);
35 }
36 
37 // HandleByVal - Allocate a stack slot large enough to pass an argument by
38 // value. The size and alignment information of the argument is encoded in its
39 // parameter attribute.
40 void Hexagon_CCState::HandleByVal(unsigned ValNo, EVT ValVT,
41  EVT LocVT, CCValAssign::LocInfo LocInfo,
42  int MinSize, int MinAlign,
43  ISD::ArgFlagsTy ArgFlags) {
44  unsigned Align = ArgFlags.getByValAlign();
45  unsigned Size = ArgFlags.getByValSize();
46  if (MinSize > (int)Size)
47  Size = MinSize;
48  if (MinAlign > (int)Align)
49  Align = MinAlign;
50  unsigned Offset = AllocateStack(Size, Align);
51 
52  addLoc(CCValAssign::getMem(ValNo, ValVT.getSimpleVT(), Offset,
53  LocVT.getSimpleVT(), LocInfo));
54 }
55 
56 /// MarkAllocated - Mark a register and all of its aliases as allocated.
57 void Hexagon_CCState::MarkAllocated(unsigned Reg) {
58  const TargetRegisterInfo &TRI = *TM.getRegisterInfo();
59  for (MCRegAliasIterator AI(Reg, &TRI, true); AI.isValid(); ++AI)
60  UsedRegs[*AI/32] |= 1 << (*AI&31);
61 }
62 
63 /// AnalyzeFormalArguments - Analyze an ISD::FORMAL_ARGUMENTS node,
64 /// incorporating info about the formals into this state.
65 void
67  &Ins,
69  unsigned SretValueInRegs) {
70  unsigned NumArgs = Ins.size();
71  unsigned i = 0;
72 
73  // If the function returns a small struct in registers, skip
74  // over the first (dummy) argument.
75  if (SretValueInRegs != 0) {
76  ++i;
77  }
78 
79 
80  for (; i != NumArgs; ++i) {
81  EVT ArgVT = Ins[i].VT;
82  ISD::ArgFlagsTy ArgFlags = Ins[i].Flags;
83  if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this, 0, 0, false)) {
84  dbgs() << "Formal argument #" << i << " has unhandled type "
85  << ArgVT.getEVTString() << "\n";
86  abort();
87  }
88  }
89 }
90 
91 /// AnalyzeReturn - Analyze the returned values of an ISD::RET node,
92 /// incorporating info about the result values into this state.
93 void
96  unsigned SretValueInRegs) {
97 
98  // For Hexagon, Return small structures in registers.
99  if (SretValueInRegs != 0) {
100  if (SretValueInRegs <= 32) {
101  unsigned Reg = Hexagon::R0;
104  return;
105  }
106  if (SretValueInRegs <= 64) {
107  unsigned Reg = Hexagon::D0;
110  return;
111  }
112  }
113 
114 
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, -1, -1, false)){
120  dbgs() << "Return operand #" << i << " has unhandled type "
121  << VT.getEVTString() << "\n";
122  abort();
123  }
124  }
125 }
126 
127 
128 /// AnalyzeCallOperands - Analyze an ISD::CALL node, incorporating info
129 /// about the passed values into this state.
130 void
132  &Outs,
134  int NonVarArgsParams,
135  unsigned SretValueSize) {
136  unsigned NumOps = Outs.size();
137 
138  unsigned i = 0;
139  // If the called function returns a small struct in registers, skip
140  // the first actual parameter. We do not want to pass a pointer to
141  // the stack location.
142  if (SretValueSize != 0) {
143  ++i;
144  }
145 
146  for (; i != NumOps; ++i) {
147  EVT ArgVT = Outs[i].VT;
148  ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
149  if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this,
150  NonVarArgsParams, i+1, false)) {
151  dbgs() << "Call operand #" << i << " has unhandled type "
152  << ArgVT.getEVTString() << "\n";
153  abort();
154  }
155  }
156 }
157 
158 /// AnalyzeCallOperands - Same as above except it takes vectors of types
159 /// and argument flags.
160 void
163  Hexagon_CCAssignFn Fn) {
164  unsigned NumOps = ArgVTs.size();
165  for (unsigned i = 0; i != NumOps; ++i) {
166  EVT ArgVT = ArgVTs[i];
167  ISD::ArgFlagsTy ArgFlags = Flags[i];
168  if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this, -1, -1,
169  false)) {
170  dbgs() << "Call operand #" << i << " has unhandled type "
171  << ArgVT.getEVTString() << "\n";
172  abort();
173  }
174  }
175 }
176 
177 /// AnalyzeCallResult - Analyze the return values of an ISD::CALL node,
178 /// incorporating info about the passed values into this state.
179 void
182  unsigned SretValueInRegs) {
183 
184  for (unsigned i = 0, e = Ins.size(); i != e; ++i) {
185  EVT VT = Ins[i].VT;
187  if (Fn(i, VT, VT, CCValAssign::Full, Flags, *this, -1, -1, false)) {
188  dbgs() << "Call result #" << i << " has unhandled type "
189  << VT.getEVTString() << "\n";
190  abort();
191  }
192  }
193 }
194 
195 /// AnalyzeCallResult - Same as above except it's specialized for calls which
196 /// produce a single value.
198  if (Fn(0, VT, VT, CCValAssign::Full, ISD::ArgFlagsTy(), *this, -1, -1,
199  false)) {
200  dbgs() << "Call result has unhandled type "
201  << VT.getEVTString() << "\n";
202  abort();
203  }
204 }
void AnalyzeFormalArguments(const SmallVectorImpl< ISD::InputArg > &Ins, Hexagon_CCAssignFn Fn, unsigned SretValueInRegs)
bool Hexagon_CCAssignFn(unsigned ValNo, EVT ValVT, EVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Hexagon_CCState &State, int NonVarArgsParams, int CurrentParam, bool ForceMem)
void addLoc(const CCValAssign &V)
unsigned getByValSize() const
void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, Hexagon_CCAssignFn Fn, unsigned SretValueInRegs)
std::string getEVTString() const
getEVTString - This function returns value type as a string, e.g. "i32".
Definition: ValueTypes.cpp:106
void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, Hexagon_CCAssignFn Fn, unsigned SretValueInRegs)
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...
unsigned AllocateStack(unsigned Size, unsigned Align)
static CCValAssign getReg(unsigned ValNo, MVT ValVT, unsigned RegNo, MVT LocVT, LocInfo HTP)
void HandleByVal(unsigned ValNo, EVT ValVT, EVT LocVT, CCValAssign::LocInfo LocInfo, int MinSize, int MinAlign, ISD::ArgFlagsTy ArgFlags)
Hexagon_CCState(CallingConv::ID CC, bool isVarArg, const TargetMachine &TM, SmallVectorImpl< CCValAssign > &locs, LLVMContext &c)
unsigned getByValAlign() const
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
Definition: Debug.cpp:101
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 AnalyzeCallOperands(const SmallVectorImpl< ISD::OutputArg > &Outs, Hexagon_CCAssignFn Fn, int NonVarArgsParams, unsigned SretValueSize)
void resize(unsigned N)
Definition: SmallVector.h:401
static CCValAssign getMem(unsigned ValNo, MVT ValVT, unsigned Offset, MVT LocVT, LocInfo HTP)
virtual const TargetRegisterInfo * getRegisterInfo() const
MVT getSimpleVT() const
Definition: ValueTypes.h:749