Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1 | //===-- HexagonISelLowering.cpp - Hexagon DAG Lowering Implementation -----===// |
| 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 interfaces that Hexagon uses to lower LLVM code |
| 11 | // into a selection DAG. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "HexagonISelLowering.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 16 | #include "HexagonMachineFunctionInfo.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 17 | #include "HexagonSubtarget.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "HexagonTargetMachine.h" |
| 19 | #include "HexagonTargetObjectFile.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/CallingConvLower.h" |
| 21 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 22 | #include "llvm/CodeGen/MachineFunction.h" |
| 23 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 26 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 27 | #include "llvm/CodeGen/ValueTypes.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 28 | #include "llvm/IR/CallingConv.h" |
| 29 | #include "llvm/IR/DerivedTypes.h" |
| 30 | #include "llvm/IR/Function.h" |
| 31 | #include "llvm/IR/GlobalAlias.h" |
| 32 | #include "llvm/IR/GlobalVariable.h" |
| 33 | #include "llvm/IR/InlineAsm.h" |
| 34 | #include "llvm/IR/Intrinsics.h" |
NAKAMURA Takumi | 54eed76 | 2012-04-21 15:31:36 +0000 | [diff] [blame] | 35 | #include "llvm/Support/CommandLine.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Debug.h" |
| 37 | #include "llvm/Support/ErrorHandling.h" |
NAKAMURA Takumi | e30303f | 2012-04-21 15:31:45 +0000 | [diff] [blame] | 38 | #include "llvm/Support/raw_ostream.h" |
NAKAMURA Takumi | 54eed76 | 2012-04-21 15:31:36 +0000 | [diff] [blame] | 39 | |
Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 40 | using namespace llvm; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 41 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 42 | #define DEBUG_TYPE "hexagon-lowering" |
| 43 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 44 | static cl::opt<bool> |
| 45 | EmitJumpTables("hexagon-emit-jump-tables", cl::init(true), cl::Hidden, |
| 46 | cl::desc("Control jump table emission on Hexagon target")); |
| 47 | |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 48 | namespace { |
| 49 | class HexagonCCState : public CCState { |
| 50 | int NumNamedVarArgParams; |
| 51 | |
| 52 | public: |
| 53 | HexagonCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 54 | SmallVectorImpl<CCValAssign> &locs, LLVMContext &C, |
| 55 | int NumNamedVarArgParams) |
| 56 | : CCState(CC, isVarArg, MF, locs, C), |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 57 | NumNamedVarArgParams(NumNamedVarArgParams) {} |
| 58 | |
| 59 | int getNumNamedVarArgParams() const { return NumNamedVarArgParams; } |
| 60 | }; |
| 61 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 62 | |
| 63 | // Implement calling convention for Hexagon. |
| 64 | static bool |
| 65 | CC_Hexagon(unsigned ValNo, MVT ValVT, |
| 66 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 67 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 68 | |
| 69 | static bool |
| 70 | CC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 71 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 72 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 73 | |
| 74 | static bool |
| 75 | CC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 76 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 77 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 78 | |
| 79 | static bool |
| 80 | RetCC_Hexagon(unsigned ValNo, MVT ValVT, |
| 81 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 82 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 83 | |
| 84 | static bool |
| 85 | RetCC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 86 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 87 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 88 | |
| 89 | static bool |
| 90 | RetCC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 91 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 92 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 93 | |
| 94 | static bool |
| 95 | CC_Hexagon_VarArg (unsigned ValNo, MVT ValVT, |
| 96 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 97 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 98 | HexagonCCState &HState = static_cast<HexagonCCState &>(State); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 99 | |
| 100 | // NumNamedVarArgParams can not be zero for a VarArg function. |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 101 | assert((HState.getNumNamedVarArgParams() > 0) && |
| 102 | "NumNamedVarArgParams is not bigger than zero."); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 103 | |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 104 | if ((int)ValNo < HState.getNumNamedVarArgParams()) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 105 | // Deal with named arguments. |
| 106 | return CC_Hexagon(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State); |
| 107 | } |
| 108 | |
| 109 | // Deal with un-named arguments. |
| 110 | unsigned ofst; |
| 111 | if (ArgFlags.isByVal()) { |
| 112 | // If pass-by-value, the size allocated on stack is decided |
| 113 | // by ArgFlags.getByValSize(), not by the size of LocVT. |
| 114 | assert ((ArgFlags.getByValSize() > 8) && |
| 115 | "ByValSize must be bigger than 8 bytes"); |
| 116 | ofst = State.AllocateStack(ArgFlags.getByValSize(), 4); |
| 117 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, ofst, LocVT, LocInfo)); |
| 118 | return false; |
| 119 | } |
Jyotsna Verma | c7dcc2f | 2013-03-07 20:28:34 +0000 | [diff] [blame] | 120 | if (LocVT == MVT::i1 || LocVT == MVT::i8 || LocVT == MVT::i16) { |
| 121 | LocVT = MVT::i32; |
| 122 | ValVT = MVT::i32; |
| 123 | if (ArgFlags.isSExt()) |
| 124 | LocInfo = CCValAssign::SExt; |
| 125 | else if (ArgFlags.isZExt()) |
| 126 | LocInfo = CCValAssign::ZExt; |
| 127 | else |
| 128 | LocInfo = CCValAssign::AExt; |
| 129 | } |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 130 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 131 | ofst = State.AllocateStack(4, 4); |
| 132 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, ofst, LocVT, LocInfo)); |
| 133 | return false; |
| 134 | } |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 135 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 136 | ofst = State.AllocateStack(8, 8); |
| 137 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, ofst, LocVT, LocInfo)); |
| 138 | return false; |
| 139 | } |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 140 | llvm_unreachable(nullptr); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
| 144 | static bool |
| 145 | CC_Hexagon (unsigned ValNo, MVT ValVT, |
| 146 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 147 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 148 | |
| 149 | if (ArgFlags.isByVal()) { |
| 150 | // Passed on stack. |
| 151 | assert ((ArgFlags.getByValSize() > 8) && |
| 152 | "ByValSize must be bigger than 8 bytes"); |
| 153 | unsigned Offset = State.AllocateStack(ArgFlags.getByValSize(), 4); |
| 154 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | if (LocVT == MVT::i1 || LocVT == MVT::i8 || LocVT == MVT::i16) { |
| 159 | LocVT = MVT::i32; |
| 160 | ValVT = MVT::i32; |
| 161 | if (ArgFlags.isSExt()) |
| 162 | LocInfo = CCValAssign::SExt; |
| 163 | else if (ArgFlags.isZExt()) |
| 164 | LocInfo = CCValAssign::ZExt; |
| 165 | else |
| 166 | LocInfo = CCValAssign::AExt; |
| 167 | } |
| 168 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 169 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 170 | if (!CC_Hexagon32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
| 171 | return false; |
| 172 | } |
| 173 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 174 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 175 | if (!CC_Hexagon64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | return true; // CC didn't match. |
| 180 | } |
| 181 | |
| 182 | |
| 183 | static bool CC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 184 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 185 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 186 | |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 187 | static const MCPhysReg RegList[] = { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 188 | Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4, |
| 189 | Hexagon::R5 |
| 190 | }; |
| 191 | if (unsigned Reg = State.AllocateReg(RegList, 6)) { |
| 192 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 193 | return false; |
| 194 | } |
| 195 | |
| 196 | unsigned Offset = State.AllocateStack(4, 4); |
| 197 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | static bool CC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 202 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 203 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 204 | |
| 205 | if (unsigned Reg = State.AllocateReg(Hexagon::D0)) { |
| 206 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 207 | return false; |
| 208 | } |
| 209 | |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 210 | static const MCPhysReg RegList1[] = { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 211 | Hexagon::D1, Hexagon::D2 |
| 212 | }; |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 213 | static const MCPhysReg RegList2[] = { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 214 | Hexagon::R1, Hexagon::R3 |
| 215 | }; |
| 216 | if (unsigned Reg = State.AllocateReg(RegList1, RegList2, 2)) { |
| 217 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | unsigned Offset = State.AllocateStack(8, 8, Hexagon::D2); |
| 222 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 223 | return false; |
| 224 | } |
| 225 | |
| 226 | static bool RetCC_Hexagon(unsigned ValNo, MVT ValVT, |
| 227 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 228 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 229 | |
| 230 | |
| 231 | if (LocVT == MVT::i1 || |
| 232 | LocVT == MVT::i8 || |
| 233 | LocVT == MVT::i16) { |
| 234 | LocVT = MVT::i32; |
| 235 | ValVT = MVT::i32; |
| 236 | if (ArgFlags.isSExt()) |
| 237 | LocInfo = CCValAssign::SExt; |
| 238 | else if (ArgFlags.isZExt()) |
| 239 | LocInfo = CCValAssign::ZExt; |
| 240 | else |
| 241 | LocInfo = CCValAssign::AExt; |
| 242 | } |
| 243 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 244 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 245 | if (!RetCC_Hexagon32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
| 246 | return false; |
| 247 | } |
| 248 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 249 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 250 | if (!RetCC_Hexagon64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | return true; // CC didn't match. |
| 255 | } |
| 256 | |
| 257 | static bool RetCC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 258 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 259 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 260 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 261 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 262 | if (unsigned Reg = State.AllocateReg(Hexagon::R0)) { |
| 263 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 264 | return false; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | unsigned Offset = State.AllocateStack(4, 4); |
| 269 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 270 | return false; |
| 271 | } |
| 272 | |
| 273 | static bool RetCC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 274 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 275 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 276 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 277 | if (unsigned Reg = State.AllocateReg(Hexagon::D0)) { |
| 278 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 279 | return false; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | unsigned Offset = State.AllocateStack(8, 8); |
| 284 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 285 | return false; |
| 286 | } |
| 287 | |
| 288 | SDValue |
| 289 | HexagonTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) |
| 290 | const { |
| 291 | return SDValue(); |
| 292 | } |
| 293 | |
| 294 | /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified |
| 295 | /// by "Src" to address "Dst" of size "Size". Alignment information is |
| 296 | /// specified by the specific parameter attribute. The copy will be passed as |
| 297 | /// a byval function parameter. Sometimes what we are copying is the end of a |
| 298 | /// larger object, the part that does not fit in registers. |
| 299 | static SDValue |
| 300 | CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, |
| 301 | ISD::ArgFlagsTy Flags, SelectionDAG &DAG, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 302 | SDLoc dl) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 303 | |
| 304 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i32); |
| 305 | return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(), |
| 306 | /*isVolatile=*/false, /*AlwaysInline=*/false, |
| 307 | MachinePointerInfo(), MachinePointerInfo()); |
| 308 | } |
| 309 | |
| 310 | |
| 311 | // LowerReturn - Lower ISD::RET. If a struct is larger than 8 bytes and is |
| 312 | // passed by value, the function prototype is modified to return void and |
| 313 | // the value is stored in memory pointed by a pointer passed by caller. |
| 314 | SDValue |
| 315 | HexagonTargetLowering::LowerReturn(SDValue Chain, |
| 316 | CallingConv::ID CallConv, bool isVarArg, |
| 317 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 318 | const SmallVectorImpl<SDValue> &OutVals, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 319 | SDLoc dl, SelectionDAG &DAG) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 320 | |
| 321 | // CCValAssign - represent the assignment of the return value to locations. |
| 322 | SmallVector<CCValAssign, 16> RVLocs; |
| 323 | |
| 324 | // CCState - Info about the registers and stack slot. |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 325 | CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, |
| 326 | *DAG.getContext()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 327 | |
| 328 | // Analyze return values of ISD::RET |
| 329 | CCInfo.AnalyzeReturn(Outs, RetCC_Hexagon); |
| 330 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 331 | SDValue Flag; |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 332 | SmallVector<SDValue, 4> RetOps(1, Chain); |
| 333 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 334 | // Copy the result values into the output registers. |
| 335 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 336 | CCValAssign &VA = RVLocs[i]; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 337 | |
| 338 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), OutVals[i], Flag); |
| 339 | |
| 340 | // Guarantee that all emitted copies are stuck together with flags. |
| 341 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 342 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 345 | RetOps[0] = Chain; // Update chain. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 346 | |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 347 | // Add the flag if we have it. |
| 348 | if (Flag.getNode()) |
| 349 | RetOps.push_back(Flag); |
| 350 | |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 351 | return DAG.getNode(HexagonISD::RET_FLAG, dl, MVT::Other, RetOps); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | /// LowerCallResult - Lower the result values of an ISD::CALL into the |
| 358 | /// appropriate copies out of appropriate physical registers. This assumes that |
| 359 | /// Chain/InFlag are the input chain/flag to use, and that TheCall is the call |
| 360 | /// being lowered. Returns a SDNode with the same number of values as the |
| 361 | /// ISD::CALL. |
| 362 | SDValue |
| 363 | HexagonTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
| 364 | CallingConv::ID CallConv, bool isVarArg, |
| 365 | const |
| 366 | SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 367 | SDLoc dl, SelectionDAG &DAG, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 368 | SmallVectorImpl<SDValue> &InVals, |
| 369 | const SmallVectorImpl<SDValue> &OutVals, |
| 370 | SDValue Callee) const { |
| 371 | |
| 372 | // Assign locations to each value returned by this call. |
| 373 | SmallVector<CCValAssign, 16> RVLocs; |
| 374 | |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 375 | CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, |
| 376 | *DAG.getContext()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 377 | |
| 378 | CCInfo.AnalyzeCallResult(Ins, RetCC_Hexagon); |
| 379 | |
| 380 | // Copy all of the result registers out of their specified physreg. |
| 381 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 382 | Chain = DAG.getCopyFromReg(Chain, dl, |
| 383 | RVLocs[i].getLocReg(), |
| 384 | RVLocs[i].getValVT(), InFlag).getValue(1); |
| 385 | InFlag = Chain.getValue(2); |
| 386 | InVals.push_back(Chain.getValue(0)); |
| 387 | } |
| 388 | |
| 389 | return Chain; |
| 390 | } |
| 391 | |
| 392 | /// LowerCall - Functions arguments are copied from virtual regs to |
| 393 | /// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted. |
| 394 | SDValue |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 395 | HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 396 | SmallVectorImpl<SDValue> &InVals) const { |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 397 | SelectionDAG &DAG = CLI.DAG; |
Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 398 | SDLoc &dl = CLI.DL; |
| 399 | SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs; |
| 400 | SmallVectorImpl<SDValue> &OutVals = CLI.OutVals; |
| 401 | SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins; |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 402 | SDValue Chain = CLI.Chain; |
| 403 | SDValue Callee = CLI.Callee; |
| 404 | bool &isTailCall = CLI.IsTailCall; |
| 405 | CallingConv::ID CallConv = CLI.CallConv; |
| 406 | bool isVarArg = CLI.IsVarArg; |
Colin LeMahieu | 2e3a26d | 2015-01-16 17:05:27 +0000 | [diff] [blame^] | 407 | bool doesNotReturn = CLI.DoesNotReturn; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 408 | |
| 409 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 410 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 411 | // Check for varargs. |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 412 | int NumNamedVarArgParams = -1; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 413 | if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(Callee)) |
| 414 | { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 415 | const Function* CalleeFn = nullptr; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 416 | Callee = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, MVT::i32); |
| 417 | if ((CalleeFn = dyn_cast<Function>(GA->getGlobal()))) |
| 418 | { |
| 419 | // If a function has zero args and is a vararg function, that's |
| 420 | // disallowed so it must be an undeclared function. Do not assume |
| 421 | // varargs if the callee is undefined. |
| 422 | if (CalleeFn->isVarArg() && |
| 423 | CalleeFn->getFunctionType()->getNumParams() != 0) { |
| 424 | NumNamedVarArgParams = CalleeFn->getFunctionType()->getNumParams(); |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 429 | // Analyze operands of the call, assigning locations to each operand. |
| 430 | SmallVector<CCValAssign, 16> ArgLocs; |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 431 | HexagonCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs, |
| 432 | *DAG.getContext(), NumNamedVarArgParams); |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 433 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 434 | if (NumNamedVarArgParams > 0) |
| 435 | CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_VarArg); |
| 436 | else |
| 437 | CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon); |
| 438 | |
| 439 | |
| 440 | if(isTailCall) { |
| 441 | bool StructAttrFlag = |
| 442 | DAG.getMachineFunction().getFunction()->hasStructRetAttr(); |
| 443 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 444 | isVarArg, IsStructRet, |
| 445 | StructAttrFlag, |
| 446 | Outs, OutVals, Ins, DAG); |
| 447 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i){ |
| 448 | CCValAssign &VA = ArgLocs[i]; |
| 449 | if (VA.isMemLoc()) { |
| 450 | isTailCall = false; |
| 451 | break; |
| 452 | } |
| 453 | } |
| 454 | if (isTailCall) { |
| 455 | DEBUG(dbgs () << "Eligible for Tail Call\n"); |
| 456 | } else { |
| 457 | DEBUG(dbgs () << |
| 458 | "Argument must be passed on stack. Not eligible for Tail Call\n"); |
| 459 | } |
| 460 | } |
| 461 | // Get a count of how many bytes are to be pushed on the stack. |
| 462 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
| 463 | SmallVector<std::pair<unsigned, SDValue>, 16> RegsToPass; |
| 464 | SmallVector<SDValue, 8> MemOpChains; |
| 465 | |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 466 | const HexagonRegisterInfo *QRI = static_cast<const HexagonRegisterInfo *>( |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 467 | DAG.getSubtarget().getRegisterInfo()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 468 | SDValue StackPtr = |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 469 | DAG.getCopyFromReg(Chain, dl, QRI->getStackRegister(), getPointerTy()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 470 | |
| 471 | // Walk the register/memloc assignments, inserting copies/loads. |
| 472 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 473 | CCValAssign &VA = ArgLocs[i]; |
| 474 | SDValue Arg = OutVals[i]; |
| 475 | ISD::ArgFlagsTy Flags = Outs[i].Flags; |
| 476 | |
| 477 | // Promote the value if needed. |
| 478 | switch (VA.getLocInfo()) { |
| 479 | default: |
| 480 | // Loc info must be one of Full, SExt, ZExt, or AExt. |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 481 | llvm_unreachable("Unknown loc info!"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 482 | case CCValAssign::Full: |
| 483 | break; |
| 484 | case CCValAssign::SExt: |
| 485 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 486 | break; |
| 487 | case CCValAssign::ZExt: |
| 488 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 489 | break; |
| 490 | case CCValAssign::AExt: |
| 491 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 492 | break; |
| 493 | } |
| 494 | |
| 495 | if (VA.isMemLoc()) { |
| 496 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 497 | SDValue PtrOff = DAG.getConstant(LocMemOffset, StackPtr.getValueType()); |
| 498 | PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff); |
| 499 | |
| 500 | if (Flags.isByVal()) { |
| 501 | // The argument is a struct passed by value. According to LLVM, "Arg" |
| 502 | // is is pointer. |
| 503 | MemOpChains.push_back(CreateCopyOfByValArgument(Arg, PtrOff, Chain, |
| 504 | Flags, DAG, dl)); |
| 505 | } else { |
| 506 | // The argument is not passed by value. "Arg" is a buildin type. It is |
| 507 | // not a pointer. |
| 508 | MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff, |
| 509 | MachinePointerInfo(),false, false, |
| 510 | 0)); |
| 511 | } |
| 512 | continue; |
| 513 | } |
| 514 | |
| 515 | // Arguments that can be passed on register must be kept at RegsToPass |
| 516 | // vector. |
| 517 | if (VA.isRegLoc()) { |
| 518 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | // Transform all store nodes into one single node because all store |
| 523 | // nodes are independent of each other. |
| 524 | if (!MemOpChains.empty()) { |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 525 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | if (!isTailCall) |
| 529 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getConstant(NumBytes, |
Andrew Trick | ad6d08a | 2013-05-29 22:03:55 +0000 | [diff] [blame] | 530 | getPointerTy(), true), |
| 531 | dl); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 532 | |
| 533 | // Build a sequence of copy-to-reg nodes chained together with token |
| 534 | // chain and flag operands which copy the outgoing args into registers. |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 535 | // The InFlag in necessary since all emitted instructions must be |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 536 | // stuck together. |
| 537 | SDValue InFlag; |
| 538 | if (!isTailCall) { |
| 539 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 540 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 541 | RegsToPass[i].second, InFlag); |
| 542 | InFlag = Chain.getValue(1); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | // For tail calls lower the arguments to the 'real' stack slot. |
| 547 | if (isTailCall) { |
| 548 | // Force all the incoming stack arguments to be loaded from the stack |
| 549 | // before any new outgoing arguments are stored to the stack, because the |
| 550 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 551 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 552 | // than necessary, because it means that each store effectively depends |
| 553 | // on every argument instead of just those arguments it would clobber. |
| 554 | // |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 555 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 556 | InFlag = SDValue(); |
| 557 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 558 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 559 | RegsToPass[i].second, InFlag); |
| 560 | InFlag = Chain.getValue(1); |
| 561 | } |
| 562 | InFlag =SDValue(); |
| 563 | } |
| 564 | |
| 565 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 566 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 567 | // node so that legalize doesn't hack it. |
| 568 | if (flag_aligned_memcpy) { |
| 569 | const char *MemcpyName = |
| 570 | "__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes"; |
| 571 | Callee = |
| 572 | DAG.getTargetExternalSymbol(MemcpyName, getPointerTy()); |
| 573 | flag_aligned_memcpy = false; |
| 574 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| 575 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, getPointerTy()); |
| 576 | } else if (ExternalSymbolSDNode *S = |
| 577 | dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 578 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy()); |
| 579 | } |
| 580 | |
| 581 | // Returns a chain & a flag for retval copy to use. |
| 582 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| 583 | SmallVector<SDValue, 8> Ops; |
| 584 | Ops.push_back(Chain); |
| 585 | Ops.push_back(Callee); |
| 586 | |
| 587 | // Add argument registers to the end of the list so that they are |
| 588 | // known live into the call. |
| 589 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 590 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 591 | RegsToPass[i].second.getValueType())); |
| 592 | } |
| 593 | |
| 594 | if (InFlag.getNode()) { |
| 595 | Ops.push_back(InFlag); |
| 596 | } |
| 597 | |
| 598 | if (isTailCall) |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 599 | return DAG.getNode(HexagonISD::TC_RETURN, dl, NodeTys, Ops); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 600 | |
Colin LeMahieu | 2e3a26d | 2015-01-16 17:05:27 +0000 | [diff] [blame^] | 601 | int OpCode = doesNotReturn ? HexagonISD::CALLv3nr : HexagonISD::CALLv3; |
| 602 | Chain = DAG.getNode(OpCode, dl, NodeTys, Ops); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 603 | InFlag = Chain.getValue(1); |
| 604 | |
| 605 | // Create the CALLSEQ_END node. |
| 606 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
Andrew Trick | ad6d08a | 2013-05-29 22:03:55 +0000 | [diff] [blame] | 607 | DAG.getIntPtrConstant(0, true), InFlag, dl); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 608 | InFlag = Chain.getValue(1); |
| 609 | |
| 610 | // Handle result values, copying them out of physregs into vregs that we |
| 611 | // return. |
| 612 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, dl, DAG, |
| 613 | InVals, OutVals, Callee); |
| 614 | } |
| 615 | |
| 616 | static bool getIndexedAddressParts(SDNode *Ptr, EVT VT, |
| 617 | bool isSEXTLoad, SDValue &Base, |
| 618 | SDValue &Offset, bool &isInc, |
| 619 | SelectionDAG &DAG) { |
| 620 | if (Ptr->getOpcode() != ISD::ADD) |
| 621 | return false; |
| 622 | |
| 623 | if (VT == MVT::i64 || VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8) { |
| 624 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 625 | Base = Ptr->getOperand(0); |
| 626 | Offset = Ptr->getOperand(1); |
| 627 | // Ensure that Offset is a constant. |
| 628 | return (isa<ConstantSDNode>(Offset)); |
| 629 | } |
| 630 | |
| 631 | return false; |
| 632 | } |
| 633 | |
| 634 | // TODO: Put this function along with the other isS* functions in |
| 635 | // HexagonISelDAGToDAG.cpp into a common file. Or better still, use the |
Rafael Espindola | b90c5f1 | 2012-11-21 16:56:33 +0000 | [diff] [blame] | 636 | // functions defined in HexagonOperands.td. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 637 | static bool Is_PostInc_S4_Offset(SDNode * S, int ShiftAmount) { |
| 638 | ConstantSDNode *N = cast<ConstantSDNode>(S); |
| 639 | |
| 640 | // immS4 predicate - True if the immediate fits in a 4-bit sign extended. |
| 641 | // field. |
| 642 | int64_t v = (int64_t)N->getSExtValue(); |
| 643 | int64_t m = 0; |
| 644 | if (ShiftAmount > 0) { |
| 645 | m = v % ShiftAmount; |
| 646 | v = v >> ShiftAmount; |
| 647 | } |
| 648 | return (v <= 7) && (v >= -8) && (m == 0); |
| 649 | } |
| 650 | |
| 651 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 652 | /// offset pointer and addressing mode by reference if this node can be |
| 653 | /// combined with a load / store to form a post-indexed load / store. |
| 654 | bool HexagonTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
| 655 | SDValue &Base, |
| 656 | SDValue &Offset, |
| 657 | ISD::MemIndexedMode &AM, |
| 658 | SelectionDAG &DAG) const |
| 659 | { |
| 660 | EVT VT; |
| 661 | SDValue Ptr; |
| 662 | bool isSEXTLoad = false; |
| 663 | |
| 664 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 665 | VT = LD->getMemoryVT(); |
| 666 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 667 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 668 | VT = ST->getMemoryVT(); |
| 669 | if (ST->getValue().getValueType() == MVT::i64 && ST->isTruncatingStore()) { |
| 670 | return false; |
| 671 | } |
| 672 | } else { |
| 673 | return false; |
| 674 | } |
| 675 | |
Chad Rosier | 64dc8aa | 2012-01-06 20:11:59 +0000 | [diff] [blame] | 676 | bool isInc = false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 677 | bool isLegal = getIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 678 | isInc, DAG); |
| 679 | // ShiftAmount = number of left-shifted bits in the Hexagon instruction. |
| 680 | int ShiftAmount = VT.getSizeInBits() / 16; |
| 681 | if (isLegal && Is_PostInc_S4_Offset(Offset.getNode(), ShiftAmount)) { |
| 682 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 683 | return true; |
| 684 | } |
| 685 | |
| 686 | return false; |
| 687 | } |
| 688 | |
| 689 | SDValue HexagonTargetLowering::LowerINLINEASM(SDValue Op, |
| 690 | SelectionDAG &DAG) const { |
| 691 | SDNode *Node = Op.getNode(); |
| 692 | MachineFunction &MF = DAG.getMachineFunction(); |
| 693 | HexagonMachineFunctionInfo *FuncInfo = |
| 694 | MF.getInfo<HexagonMachineFunctionInfo>(); |
| 695 | switch (Node->getOpcode()) { |
| 696 | case ISD::INLINEASM: { |
| 697 | unsigned NumOps = Node->getNumOperands(); |
| 698 | if (Node->getOperand(NumOps-1).getValueType() == MVT::Glue) |
| 699 | --NumOps; // Ignore the flag operand. |
| 700 | |
| 701 | for (unsigned i = InlineAsm::Op_FirstOperand; i != NumOps;) { |
| 702 | if (FuncInfo->hasClobberLR()) |
| 703 | break; |
| 704 | unsigned Flags = |
| 705 | cast<ConstantSDNode>(Node->getOperand(i))->getZExtValue(); |
| 706 | unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags); |
| 707 | ++i; // Skip the ID value. |
| 708 | |
| 709 | switch (InlineAsm::getKind(Flags)) { |
| 710 | default: llvm_unreachable("Bad flags!"); |
| 711 | case InlineAsm::Kind_RegDef: |
| 712 | case InlineAsm::Kind_RegUse: |
| 713 | case InlineAsm::Kind_Imm: |
| 714 | case InlineAsm::Kind_Clobber: |
| 715 | case InlineAsm::Kind_Mem: { |
| 716 | for (; NumVals; --NumVals, ++i) {} |
| 717 | break; |
| 718 | } |
| 719 | case InlineAsm::Kind_RegDefEarlyClobber: { |
| 720 | for (; NumVals; --NumVals, ++i) { |
| 721 | unsigned Reg = |
| 722 | cast<RegisterSDNode>(Node->getOperand(i))->getReg(); |
| 723 | |
| 724 | // Check it to be lr |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 725 | const HexagonRegisterInfo *QRI = |
| 726 | static_cast<const HexagonRegisterInfo *>( |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 727 | DAG.getSubtarget().getRegisterInfo()); |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 728 | if (Reg == QRI->getRARegister()) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 729 | FuncInfo->setHasClobberLR(true); |
| 730 | break; |
| 731 | } |
| 732 | } |
| 733 | break; |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | } // Node->getOpcode |
| 739 | return Op; |
| 740 | } |
| 741 | |
| 742 | |
| 743 | // |
| 744 | // Taken from the XCore backend. |
| 745 | // |
| 746 | SDValue HexagonTargetLowering:: |
| 747 | LowerBR_JT(SDValue Op, SelectionDAG &DAG) const |
| 748 | { |
| 749 | SDValue Chain = Op.getOperand(0); |
| 750 | SDValue Table = Op.getOperand(1); |
| 751 | SDValue Index = Op.getOperand(2); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 752 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 753 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 754 | unsigned JTI = JT->getIndex(); |
| 755 | MachineFunction &MF = DAG.getMachineFunction(); |
| 756 | const MachineJumpTableInfo *MJTI = MF.getJumpTableInfo(); |
| 757 | SDValue TargetJT = DAG.getTargetJumpTable(JT->getIndex(), MVT::i32); |
| 758 | |
| 759 | // Mark all jump table targets as address taken. |
| 760 | const std::vector<MachineJumpTableEntry> &JTE = MJTI->getJumpTables(); |
| 761 | const std::vector<MachineBasicBlock*> &JTBBs = JTE[JTI].MBBs; |
| 762 | for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) { |
| 763 | MachineBasicBlock *MBB = JTBBs[i]; |
| 764 | MBB->setHasAddressTaken(); |
| 765 | // This line is needed to set the hasAddressTaken flag on the BasicBlock |
| 766 | // object. |
| 767 | BlockAddress::get(const_cast<BasicBlock *>(MBB->getBasicBlock())); |
| 768 | } |
| 769 | |
| 770 | SDValue JumpTableBase = DAG.getNode(HexagonISD::WrapperJT, dl, |
| 771 | getPointerTy(), TargetJT); |
| 772 | SDValue ShiftIndex = DAG.getNode(ISD::SHL, dl, MVT::i32, Index, |
| 773 | DAG.getConstant(2, MVT::i32)); |
| 774 | SDValue JTAddress = DAG.getNode(ISD::ADD, dl, MVT::i32, JumpTableBase, |
| 775 | ShiftIndex); |
| 776 | SDValue LoadTarget = DAG.getLoad(MVT::i32, dl, Chain, JTAddress, |
| 777 | MachinePointerInfo(), false, false, false, |
| 778 | 0); |
| 779 | return DAG.getNode(HexagonISD::BR_JT, dl, MVT::Other, Chain, LoadTarget); |
| 780 | } |
| 781 | |
| 782 | |
| 783 | SDValue |
| 784 | HexagonTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, |
| 785 | SelectionDAG &DAG) const { |
| 786 | SDValue Chain = Op.getOperand(0); |
| 787 | SDValue Size = Op.getOperand(1); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 788 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 789 | |
| 790 | unsigned SPReg = getStackPointerRegisterToSaveRestore(); |
| 791 | |
| 792 | // Get a reference to the stack pointer. |
| 793 | SDValue StackPointer = DAG.getCopyFromReg(Chain, dl, SPReg, MVT::i32); |
| 794 | |
| 795 | // Subtract the dynamic size from the actual stack size to |
| 796 | // obtain the new stack size. |
| 797 | SDValue Sub = DAG.getNode(ISD::SUB, dl, MVT::i32, StackPointer, Size); |
| 798 | |
| 799 | // |
| 800 | // For Hexagon, the outgoing memory arguments area should be on top of the |
| 801 | // alloca area on the stack i.e., the outgoing memory arguments should be |
| 802 | // at a lower address than the alloca area. Move the alloca area down the |
| 803 | // stack by adding back the space reserved for outgoing arguments to SP |
| 804 | // here. |
| 805 | // |
| 806 | // We do not know what the size of the outgoing args is at this point. |
| 807 | // So, we add a pseudo instruction ADJDYNALLOC that will adjust the |
| 808 | // stack pointer. We patch this instruction with the correct, known |
| 809 | // offset in emitPrologue(). |
| 810 | // |
| 811 | // Use a placeholder immediate (zero) for now. This will be patched up |
| 812 | // by emitPrologue(). |
| 813 | SDValue ArgAdjust = DAG.getNode(HexagonISD::ADJDYNALLOC, dl, |
| 814 | MVT::i32, |
| 815 | Sub, |
| 816 | DAG.getConstant(0, MVT::i32)); |
| 817 | |
| 818 | // The Sub result contains the new stack start address, so it |
| 819 | // must be placed in the stack pointer register. |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 820 | const HexagonRegisterInfo *QRI = static_cast<const HexagonRegisterInfo *>( |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 821 | DAG.getSubtarget().getRegisterInfo()); |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 822 | SDValue CopyChain = DAG.getCopyToReg(Chain, dl, QRI->getStackRegister(), Sub); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 823 | |
| 824 | SDValue Ops[2] = { ArgAdjust, CopyChain }; |
Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 825 | return DAG.getMergeValues(Ops, dl); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | SDValue |
| 829 | HexagonTargetLowering::LowerFormalArguments(SDValue Chain, |
| 830 | CallingConv::ID CallConv, |
| 831 | bool isVarArg, |
| 832 | const |
| 833 | SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 834 | SDLoc dl, SelectionDAG &DAG, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 835 | SmallVectorImpl<SDValue> &InVals) |
| 836 | const { |
| 837 | |
| 838 | MachineFunction &MF = DAG.getMachineFunction(); |
| 839 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 840 | MachineRegisterInfo &RegInfo = MF.getRegInfo(); |
| 841 | HexagonMachineFunctionInfo *FuncInfo = |
| 842 | MF.getInfo<HexagonMachineFunctionInfo>(); |
| 843 | |
| 844 | |
| 845 | // Assign locations to all of the incoming arguments. |
| 846 | SmallVector<CCValAssign, 16> ArgLocs; |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 847 | CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs, |
| 848 | *DAG.getContext()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 849 | |
| 850 | CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon); |
| 851 | |
| 852 | // For LLVM, in the case when returning a struct by value (>8byte), |
| 853 | // the first argument is a pointer that points to the location on caller's |
| 854 | // stack where the return value will be stored. For Hexagon, the location on |
| 855 | // caller's stack is passed only when the struct size is smaller than (and |
| 856 | // equal to) 8 bytes. If not, no address will be passed into callee and |
| 857 | // callee return the result direclty through R0/R1. |
| 858 | |
| 859 | SmallVector<SDValue, 4> MemOps; |
| 860 | |
| 861 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 862 | CCValAssign &VA = ArgLocs[i]; |
| 863 | ISD::ArgFlagsTy Flags = Ins[i].Flags; |
| 864 | unsigned ObjSize; |
| 865 | unsigned StackLocation; |
| 866 | int FI; |
| 867 | |
| 868 | if ( (VA.isRegLoc() && !Flags.isByVal()) |
| 869 | || (VA.isRegLoc() && Flags.isByVal() && Flags.getByValSize() > 8)) { |
| 870 | // Arguments passed in registers |
| 871 | // 1. int, long long, ptr args that get allocated in register. |
| 872 | // 2. Large struct that gets an register to put its address in. |
| 873 | EVT RegVT = VA.getLocVT(); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 874 | if (RegVT == MVT::i8 || RegVT == MVT::i16 || |
| 875 | RegVT == MVT::i32 || RegVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 876 | unsigned VReg = |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 877 | RegInfo.createVirtualRegister(&Hexagon::IntRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 878 | RegInfo.addLiveIn(VA.getLocReg(), VReg); |
| 879 | InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT)); |
Chandler Carruth | b415bf98 | 2012-04-18 21:31:19 +0000 | [diff] [blame] | 880 | } else if (RegVT == MVT::i64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 881 | unsigned VReg = |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 882 | RegInfo.createVirtualRegister(&Hexagon::DoubleRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 883 | RegInfo.addLiveIn(VA.getLocReg(), VReg); |
| 884 | InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT)); |
| 885 | } else { |
| 886 | assert (0); |
| 887 | } |
| 888 | } else if (VA.isRegLoc() && Flags.isByVal() && Flags.getByValSize() <= 8) { |
| 889 | assert (0 && "ByValSize must be bigger than 8 bytes"); |
| 890 | } else { |
| 891 | // Sanity check. |
| 892 | assert(VA.isMemLoc()); |
| 893 | |
| 894 | if (Flags.isByVal()) { |
| 895 | // If it's a byval parameter, then we need to compute the |
| 896 | // "real" size, not the size of the pointer. |
| 897 | ObjSize = Flags.getByValSize(); |
| 898 | } else { |
| 899 | ObjSize = VA.getLocVT().getStoreSizeInBits() >> 3; |
| 900 | } |
| 901 | |
| 902 | StackLocation = HEXAGON_LRFP_SIZE + VA.getLocMemOffset(); |
| 903 | // Create the frame index object for this incoming parameter... |
| 904 | FI = MFI->CreateFixedObject(ObjSize, StackLocation, true); |
| 905 | |
| 906 | // Create the SelectionDAG nodes cordl, responding to a load |
| 907 | // from this parameter. |
| 908 | SDValue FIN = DAG.getFrameIndex(FI, MVT::i32); |
| 909 | |
| 910 | if (Flags.isByVal()) { |
| 911 | // If it's a pass-by-value aggregate, then do not dereference the stack |
| 912 | // location. Instead, we should generate a reference to the stack |
| 913 | // location. |
| 914 | InVals.push_back(FIN); |
| 915 | } else { |
| 916 | InVals.push_back(DAG.getLoad(VA.getLocVT(), dl, Chain, FIN, |
| 917 | MachinePointerInfo(), false, false, |
| 918 | false, 0)); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | if (!MemOps.empty()) |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 924 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOps); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 925 | |
| 926 | if (isVarArg) { |
| 927 | // This will point to the next argument passed via stack. |
| 928 | int FrameIndex = MFI->CreateFixedObject(Hexagon_PointerSize, |
| 929 | HEXAGON_LRFP_SIZE + |
| 930 | CCInfo.getNextStackOffset(), |
| 931 | true); |
| 932 | FuncInfo->setVarArgsFrameIndex(FrameIndex); |
| 933 | } |
| 934 | |
| 935 | return Chain; |
| 936 | } |
| 937 | |
| 938 | SDValue |
| 939 | HexagonTargetLowering::LowerVASTART(SDValue Op, SelectionDAG &DAG) const { |
| 940 | // VASTART stores the address of the VarArgsFrameIndex slot into the |
| 941 | // memory location argument. |
| 942 | MachineFunction &MF = DAG.getMachineFunction(); |
| 943 | HexagonMachineFunctionInfo *QFI = MF.getInfo<HexagonMachineFunctionInfo>(); |
| 944 | SDValue Addr = DAG.getFrameIndex(QFI->getVarArgsFrameIndex(), MVT::i32); |
| 945 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 946 | return DAG.getStore(Op.getOperand(0), SDLoc(Op), Addr, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 947 | Op.getOperand(1), MachinePointerInfo(SV), false, |
| 948 | false, 0); |
| 949 | } |
| 950 | |
| 951 | SDValue |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 952 | HexagonTargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) const { |
| 953 | EVT ValTy = Op.getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 954 | SDLoc dl(Op); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 955 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
| 956 | SDValue Res; |
| 957 | if (CP->isMachineConstantPoolEntry()) |
| 958 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), ValTy, |
| 959 | CP->getAlignment()); |
| 960 | else |
| 961 | Res = DAG.getTargetConstantPool(CP->getConstVal(), ValTy, |
| 962 | CP->getAlignment()); |
| 963 | return DAG.getNode(HexagonISD::CONST32, dl, ValTy, Res); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | SDValue |
| 967 | HexagonTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const { |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 968 | const TargetRegisterInfo *TRI = DAG.getSubtarget().getRegisterInfo(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 969 | MachineFunction &MF = DAG.getMachineFunction(); |
| 970 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 971 | MFI->setReturnAddressIsTaken(true); |
| 972 | |
Bill Wendling | 908bf81 | 2014-01-06 00:43:20 +0000 | [diff] [blame] | 973 | if (verifyReturnAddressArgumentIsConstant(Op, DAG)) |
Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 974 | return SDValue(); |
Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 975 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 976 | EVT VT = Op.getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 977 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 978 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 979 | if (Depth) { |
| 980 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 981 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 982 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 983 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
| 984 | MachinePointerInfo(), false, false, false, 0); |
| 985 | } |
| 986 | |
| 987 | // Return LR, which contains the return address. Mark it an implicit live-in. |
| 988 | unsigned Reg = MF.addLiveIn(TRI->getRARegister(), getRegClassFor(MVT::i32)); |
| 989 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 990 | } |
| 991 | |
| 992 | SDValue |
| 993 | HexagonTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 994 | const HexagonRegisterInfo *TRI = static_cast<const HexagonRegisterInfo *>( |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 995 | DAG.getSubtarget().getRegisterInfo()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 996 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 997 | MFI->setFrameAddressIsTaken(true); |
| 998 | |
| 999 | EVT VT = Op.getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1000 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1001 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 1002 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, |
| 1003 | TRI->getFrameRegister(), VT); |
| 1004 | while (Depth--) |
| 1005 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 1006 | MachinePointerInfo(), |
| 1007 | false, false, false, 0); |
| 1008 | return FrameAddr; |
| 1009 | } |
| 1010 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1011 | SDValue HexagonTargetLowering::LowerATOMIC_FENCE(SDValue Op, |
| 1012 | SelectionDAG& DAG) const { |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1013 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1014 | return DAG.getNode(HexagonISD::BARRIER, dl, MVT::Other, Op.getOperand(0)); |
| 1015 | } |
| 1016 | |
| 1017 | |
| 1018 | SDValue HexagonTargetLowering::LowerGLOBALADDRESS(SDValue Op, |
| 1019 | SelectionDAG &DAG) const { |
| 1020 | SDValue Result; |
| 1021 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| 1022 | int64_t Offset = cast<GlobalAddressSDNode>(Op)->getOffset(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1023 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1024 | Result = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), Offset); |
| 1025 | |
Dmitri Gribenko | f24e57f | 2013-01-14 22:18:18 +0000 | [diff] [blame] | 1026 | const HexagonTargetObjectFile &TLOF = |
| 1027 | static_cast<const HexagonTargetObjectFile &>(getObjFileLowering()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1028 | if (TLOF.IsGlobalInSmallSection(GV, getTargetMachine())) { |
| 1029 | return DAG.getNode(HexagonISD::CONST32_GP, dl, getPointerTy(), Result); |
| 1030 | } |
| 1031 | |
| 1032 | return DAG.getNode(HexagonISD::CONST32, dl, getPointerTy(), Result); |
| 1033 | } |
| 1034 | |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1035 | SDValue |
| 1036 | HexagonTargetLowering::LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const { |
| 1037 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
| 1038 | SDValue BA_SD = DAG.getTargetBlockAddress(BA, MVT::i32); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1039 | SDLoc dl(Op); |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1040 | return DAG.getNode(HexagonISD::CONST32_GP, dl, getPointerTy(), BA_SD); |
| 1041 | } |
| 1042 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1043 | //===----------------------------------------------------------------------===// |
| 1044 | // TargetLowering Implementation |
| 1045 | //===----------------------------------------------------------------------===// |
| 1046 | |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 1047 | HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &targetmachine) |
Aditya Nandakumar | 3053155 | 2014-11-13 21:29:21 +0000 | [diff] [blame] | 1048 | : TargetLowering(targetmachine), |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1049 | TM(targetmachine) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1050 | |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 1051 | const HexagonSubtarget &Subtarget = TM.getSubtarget<HexagonSubtarget>(); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1052 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1053 | // Set up the register classes. |
| 1054 | addRegisterClass(MVT::i32, &Hexagon::IntRegsRegClass); |
| 1055 | addRegisterClass(MVT::i64, &Hexagon::DoubleRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1056 | |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 1057 | if (Subtarget.hasV5TOps()) { |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1058 | addRegisterClass(MVT::f32, &Hexagon::IntRegsRegClass); |
| 1059 | addRegisterClass(MVT::f64, &Hexagon::DoubleRegsRegClass); |
| 1060 | } |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1061 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1062 | addRegisterClass(MVT::i1, &Hexagon::PredRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1063 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1064 | computeRegisterProperties(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1065 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1066 | // Align loop entry |
| 1067 | setPrefLoopAlignment(4); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1068 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1069 | // Limits for inline expansion of memcpy/memmove |
| 1070 | MaxStoresPerMemcpy = 6; |
| 1071 | MaxStoresPerMemmove = 6; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1072 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1073 | // |
| 1074 | // Library calls for unsupported operations |
| 1075 | // |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1076 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1077 | setLibcallName(RTLIB::SINTTOFP_I128_F64, "__hexagon_floattidf"); |
| 1078 | setLibcallName(RTLIB::SINTTOFP_I128_F32, "__hexagon_floattisf"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1079 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1080 | setLibcallName(RTLIB::FPTOUINT_F32_I128, "__hexagon_fixunssfti"); |
| 1081 | setLibcallName(RTLIB::FPTOUINT_F64_I128, "__hexagon_fixunsdfti"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1082 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1083 | setLibcallName(RTLIB::FPTOSINT_F32_I128, "__hexagon_fixsfti"); |
| 1084 | setLibcallName(RTLIB::FPTOSINT_F64_I128, "__hexagon_fixdfti"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1085 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1086 | setLibcallName(RTLIB::SDIV_I32, "__hexagon_divsi3"); |
| 1087 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 1088 | setLibcallName(RTLIB::SREM_I32, "__hexagon_umodsi3"); |
| 1089 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1090 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1091 | setLibcallName(RTLIB::SDIV_I64, "__hexagon_divdi3"); |
| 1092 | setOperationAction(ISD::SDIV, MVT::i64, Expand); |
| 1093 | setLibcallName(RTLIB::SREM_I64, "__hexagon_moddi3"); |
| 1094 | setOperationAction(ISD::SREM, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1095 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1096 | setLibcallName(RTLIB::UDIV_I32, "__hexagon_udivsi3"); |
| 1097 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1098 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1099 | setLibcallName(RTLIB::UDIV_I64, "__hexagon_udivdi3"); |
| 1100 | setOperationAction(ISD::UDIV, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1101 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1102 | setLibcallName(RTLIB::UREM_I32, "__hexagon_umodsi3"); |
| 1103 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1104 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1105 | setLibcallName(RTLIB::UREM_I64, "__hexagon_umoddi3"); |
| 1106 | setOperationAction(ISD::UREM, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1107 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1108 | setLibcallName(RTLIB::DIV_F32, "__hexagon_divsf3"); |
| 1109 | setOperationAction(ISD::FDIV, MVT::f32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1110 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1111 | setLibcallName(RTLIB::DIV_F64, "__hexagon_divdf3"); |
| 1112 | setOperationAction(ISD::FDIV, MVT::f64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1113 | |
Colin LeMahieu | 7959cac | 2015-01-15 16:30:07 +0000 | [diff] [blame] | 1114 | setLibcallName(RTLIB::ADD_F64, "__hexagon_adddf3"); |
| 1115 | setLibcallName(RTLIB::SUB_F64, "__hexagon_subdf3"); |
Colin LeMahieu | 2d1c145 | 2015-01-15 17:28:14 +0000 | [diff] [blame] | 1116 | setLibcallName(RTLIB::MUL_F64, "__hexagon_muldf3"); |
Colin LeMahieu | 7959cac | 2015-01-15 16:30:07 +0000 | [diff] [blame] | 1117 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1118 | setOperationAction(ISD::FSQRT, MVT::f32, Expand); |
| 1119 | setOperationAction(ISD::FSQRT, MVT::f64, Expand); |
| 1120 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 1121 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1122 | |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 1123 | if (Subtarget.hasV5TOps()) { |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1124 | // Hexagon V5 Support. |
| 1125 | setOperationAction(ISD::FADD, MVT::f32, Legal); |
Colin LeMahieu | 7959cac | 2015-01-15 16:30:07 +0000 | [diff] [blame] | 1126 | setOperationAction(ISD::FADD, MVT::f64, Expand); |
| 1127 | setOperationAction(ISD::FSUB, MVT::f32, Legal); |
| 1128 | setOperationAction(ISD::FSUB, MVT::f64, Expand); |
Colin LeMahieu | 2d1c145 | 2015-01-15 17:28:14 +0000 | [diff] [blame] | 1129 | setOperationAction(ISD::FMUL, MVT::f64, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1130 | setOperationAction(ISD::FP_EXTEND, MVT::f32, Legal); |
| 1131 | setCondCodeAction(ISD::SETOEQ, MVT::f32, Legal); |
| 1132 | setCondCodeAction(ISD::SETOEQ, MVT::f64, Legal); |
| 1133 | setCondCodeAction(ISD::SETUEQ, MVT::f32, Legal); |
| 1134 | setCondCodeAction(ISD::SETUEQ, MVT::f64, Legal); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1135 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1136 | setCondCodeAction(ISD::SETOGE, MVT::f32, Legal); |
| 1137 | setCondCodeAction(ISD::SETOGE, MVT::f64, Legal); |
| 1138 | setCondCodeAction(ISD::SETUGE, MVT::f32, Legal); |
| 1139 | setCondCodeAction(ISD::SETUGE, MVT::f64, Legal); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1140 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1141 | setCondCodeAction(ISD::SETOGT, MVT::f32, Legal); |
| 1142 | setCondCodeAction(ISD::SETOGT, MVT::f64, Legal); |
| 1143 | setCondCodeAction(ISD::SETUGT, MVT::f32, Legal); |
| 1144 | setCondCodeAction(ISD::SETUGT, MVT::f64, Legal); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1145 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1146 | setCondCodeAction(ISD::SETOLE, MVT::f32, Legal); |
| 1147 | setCondCodeAction(ISD::SETOLE, MVT::f64, Legal); |
| 1148 | setCondCodeAction(ISD::SETOLT, MVT::f32, Legal); |
| 1149 | setCondCodeAction(ISD::SETOLT, MVT::f64, Legal); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1150 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1151 | setOperationAction(ISD::ConstantFP, MVT::f32, Legal); |
| 1152 | setOperationAction(ISD::ConstantFP, MVT::f64, Legal); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1153 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1154 | setOperationAction(ISD::FP_TO_UINT, MVT::i1, Promote); |
| 1155 | setOperationAction(ISD::FP_TO_SINT, MVT::i1, Promote); |
| 1156 | setOperationAction(ISD::UINT_TO_FP, MVT::i1, Promote); |
| 1157 | setOperationAction(ISD::SINT_TO_FP, MVT::i1, Promote); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1158 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1159 | setOperationAction(ISD::FP_TO_UINT, MVT::i8, Promote); |
| 1160 | setOperationAction(ISD::FP_TO_SINT, MVT::i8, Promote); |
| 1161 | setOperationAction(ISD::UINT_TO_FP, MVT::i8, Promote); |
| 1162 | setOperationAction(ISD::SINT_TO_FP, MVT::i8, Promote); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1163 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1164 | setOperationAction(ISD::FP_TO_UINT, MVT::i16, Promote); |
| 1165 | setOperationAction(ISD::FP_TO_SINT, MVT::i16, Promote); |
| 1166 | setOperationAction(ISD::UINT_TO_FP, MVT::i16, Promote); |
| 1167 | setOperationAction(ISD::SINT_TO_FP, MVT::i16, Promote); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1168 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1169 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Legal); |
| 1170 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Legal); |
| 1171 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Legal); |
| 1172 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Legal); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1173 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1174 | setOperationAction(ISD::FP_TO_UINT, MVT::i64, Legal); |
| 1175 | setOperationAction(ISD::FP_TO_SINT, MVT::i64, Legal); |
| 1176 | setOperationAction(ISD::UINT_TO_FP, MVT::i64, Legal); |
| 1177 | setOperationAction(ISD::SINT_TO_FP, MVT::i64, Legal); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1178 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1179 | setOperationAction(ISD::FABS, MVT::f32, Legal); |
| 1180 | setOperationAction(ISD::FABS, MVT::f64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1181 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1182 | setOperationAction(ISD::FNEG, MVT::f32, Legal); |
| 1183 | setOperationAction(ISD::FNEG, MVT::f64, Expand); |
| 1184 | } else { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1185 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1186 | // Expand fp<->uint. |
| 1187 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Expand); |
| 1188 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1189 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1190 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Expand); |
| 1191 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1192 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1193 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__hexagon_floatdisf"); |
| 1194 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__hexagon_floatundisf"); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1195 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1196 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__hexagon_floatunsisf"); |
| 1197 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__hexagon_floatsisf"); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1198 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1199 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__hexagon_floatdidf"); |
| 1200 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__hexagon_floatundidf"); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1201 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1202 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__hexagon_floatunsidf"); |
| 1203 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__hexagon_floatsidf"); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1204 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1205 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__hexagon_fixunssfsi"); |
| 1206 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__hexagon_fixunssfdi"); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1207 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1208 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__hexagon_fixdfdi"); |
| 1209 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__hexagon_fixsfdi"); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1210 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1211 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__hexagon_fixunsdfsi"); |
| 1212 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__hexagon_fixunsdfdi"); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1213 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1214 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1215 | setLibcallName(RTLIB::ADD_F32, "__hexagon_addsf3"); |
| 1216 | setOperationAction(ISD::FADD, MVT::f32, Expand); |
Colin LeMahieu | 7959cac | 2015-01-15 16:30:07 +0000 | [diff] [blame] | 1217 | setOperationAction(ISD::FADD, MVT::f64, Expand); |
| 1218 | |
| 1219 | setLibcallName(RTLIB::SUB_F32, "__hexagon_subsf3"); |
| 1220 | setOperationAction(ISD::FSUB, MVT::f32, Expand); |
| 1221 | setOperationAction(ISD::FSUB, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1222 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1223 | setLibcallName(RTLIB::FPEXT_F32_F64, "__hexagon_extendsfdf2"); |
| 1224 | setOperationAction(ISD::FP_EXTEND, MVT::f32, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1225 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1226 | setLibcallName(RTLIB::OEQ_F32, "__hexagon_eqsf2"); |
| 1227 | setCondCodeAction(ISD::SETOEQ, MVT::f32, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1228 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1229 | setLibcallName(RTLIB::OEQ_F64, "__hexagon_eqdf2"); |
| 1230 | setCondCodeAction(ISD::SETOEQ, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1231 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1232 | setLibcallName(RTLIB::OGE_F32, "__hexagon_gesf2"); |
| 1233 | setCondCodeAction(ISD::SETOGE, MVT::f32, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1234 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1235 | setLibcallName(RTLIB::OGE_F64, "__hexagon_gedf2"); |
| 1236 | setCondCodeAction(ISD::SETOGE, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1237 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1238 | setLibcallName(RTLIB::OGT_F32, "__hexagon_gtsf2"); |
| 1239 | setCondCodeAction(ISD::SETOGT, MVT::f32, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1240 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1241 | setLibcallName(RTLIB::OGT_F64, "__hexagon_gtdf2"); |
| 1242 | setCondCodeAction(ISD::SETOGT, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1243 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1244 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__hexagon_fixdfsi"); |
| 1245 | setOperationAction(ISD::FP_TO_SINT, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1246 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1247 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__hexagon_fixsfsi"); |
| 1248 | setOperationAction(ISD::FP_TO_SINT, MVT::f32, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1249 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1250 | setLibcallName(RTLIB::OLE_F64, "__hexagon_ledf2"); |
| 1251 | setCondCodeAction(ISD::SETOLE, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1252 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1253 | setLibcallName(RTLIB::OLE_F32, "__hexagon_lesf2"); |
| 1254 | setCondCodeAction(ISD::SETOLE, MVT::f32, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1255 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1256 | setLibcallName(RTLIB::OLT_F64, "__hexagon_ltdf2"); |
| 1257 | setCondCodeAction(ISD::SETOLT, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1258 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1259 | setLibcallName(RTLIB::OLT_F32, "__hexagon_ltsf2"); |
| 1260 | setCondCodeAction(ISD::SETOLT, MVT::f32, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1261 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1262 | setOperationAction(ISD::FMUL, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1263 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1264 | setLibcallName(RTLIB::MUL_F32, "__hexagon_mulsf3"); |
| 1265 | setOperationAction(ISD::MUL, MVT::f32, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1266 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1267 | setLibcallName(RTLIB::UNE_F64, "__hexagon_nedf2"); |
| 1268 | setCondCodeAction(ISD::SETUNE, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1269 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1270 | setLibcallName(RTLIB::UNE_F32, "__hexagon_nesf2"); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1271 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1272 | setLibcallName(RTLIB::SUB_F64, "__hexagon_subdf3"); |
| 1273 | setOperationAction(ISD::SUB, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1274 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1275 | setLibcallName(RTLIB::SUB_F32, "__hexagon_subsf3"); |
| 1276 | setOperationAction(ISD::SUB, MVT::f32, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1277 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1278 | setLibcallName(RTLIB::FPROUND_F64_F32, "__hexagon_truncdfsf2"); |
| 1279 | setOperationAction(ISD::FP_ROUND, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1280 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1281 | setLibcallName(RTLIB::UO_F64, "__hexagon_unorddf2"); |
| 1282 | setCondCodeAction(ISD::SETUO, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1283 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1284 | setLibcallName(RTLIB::O_F64, "__hexagon_unorddf2"); |
| 1285 | setCondCodeAction(ISD::SETO, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1286 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1287 | setLibcallName(RTLIB::O_F32, "__hexagon_unordsf2"); |
| 1288 | setCondCodeAction(ISD::SETO, MVT::f32, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1289 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1290 | setLibcallName(RTLIB::UO_F32, "__hexagon_unordsf2"); |
| 1291 | setCondCodeAction(ISD::SETUO, MVT::f32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1292 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1293 | setOperationAction(ISD::FABS, MVT::f32, Expand); |
| 1294 | setOperationAction(ISD::FABS, MVT::f64, Expand); |
| 1295 | setOperationAction(ISD::FNEG, MVT::f32, Expand); |
| 1296 | setOperationAction(ISD::FNEG, MVT::f64, Expand); |
| 1297 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1298 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1299 | setLibcallName(RTLIB::SREM_I32, "__hexagon_modsi3"); |
| 1300 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1301 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1302 | setIndexedLoadAction(ISD::POST_INC, MVT::i8, Legal); |
| 1303 | setIndexedLoadAction(ISD::POST_INC, MVT::i16, Legal); |
| 1304 | setIndexedLoadAction(ISD::POST_INC, MVT::i32, Legal); |
| 1305 | setIndexedLoadAction(ISD::POST_INC, MVT::i64, Legal); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1306 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1307 | setIndexedStoreAction(ISD::POST_INC, MVT::i8, Legal); |
| 1308 | setIndexedStoreAction(ISD::POST_INC, MVT::i16, Legal); |
| 1309 | setIndexedStoreAction(ISD::POST_INC, MVT::i32, Legal); |
| 1310 | setIndexedStoreAction(ISD::POST_INC, MVT::i64, Legal); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1311 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1312 | setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1313 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1314 | // Turn FP extload into load/fextend. |
Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 1315 | for (MVT VT : MVT::fp_valuetypes()) |
| 1316 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1317 | // Hexagon has a i1 sign extending load. |
Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 1318 | for (MVT VT : MVT::integer_valuetypes()) |
| 1319 | setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1320 | // Turn FP truncstore into trunc + store. |
| 1321 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1322 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1323 | // Custom legalize GlobalAddress nodes into CONST32. |
| 1324 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 1325 | setOperationAction(ISD::GlobalAddress, MVT::i8, Custom); |
| 1326 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
| 1327 | // Truncate action? |
| 1328 | setOperationAction(ISD::TRUNCATE, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1329 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1330 | // Hexagon doesn't have sext_inreg, replace them with shl/sra. |
| 1331 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1332 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1333 | // Hexagon has no REM or DIVREM operations. |
| 1334 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 1335 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 1336 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 1337 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
| 1338 | setOperationAction(ISD::SREM, MVT::i64, Expand); |
| 1339 | setOperationAction(ISD::SDIVREM, MVT::i64, Expand); |
| 1340 | setOperationAction(ISD::UDIVREM, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1341 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1342 | setOperationAction(ISD::BSWAP, MVT::i64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1343 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1344 | // Lower SELECT_CC to SETCC and SELECT. |
| 1345 | setOperationAction(ISD::SELECT_CC, MVT::i1, Expand); |
| 1346 | setOperationAction(ISD::SELECT_CC, MVT::i32, Expand); |
| 1347 | setOperationAction(ISD::SELECT_CC, MVT::i64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1348 | |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 1349 | if (Subtarget.hasV5TOps()) { |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1350 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1351 | // We need to make the operation type of SELECT node to be Custom, |
| 1352 | // such that we don't go into the infinite loop of |
| 1353 | // select -> setcc -> select_cc -> select loop. |
| 1354 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 1355 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1356 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1357 | setOperationAction(ISD::SELECT_CC, MVT::f32, Expand); |
| 1358 | setOperationAction(ISD::SELECT_CC, MVT::f64, Expand); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1359 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1360 | } else { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1361 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1362 | // Hexagon has no select or setcc: expand to SELECT_CC. |
| 1363 | setOperationAction(ISD::SELECT, MVT::f32, Expand); |
| 1364 | setOperationAction(ISD::SELECT, MVT::f64, Expand); |
| 1365 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1366 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1367 | if (EmitJumpTables) { |
| 1368 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
| 1369 | } else { |
| 1370 | setOperationAction(ISD::BR_JT, MVT::Other, Expand); |
| 1371 | } |
| 1372 | // Increase jump tables cutover to 5, was 4. |
| 1373 | setMinimumJumpTableEntries(5); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1374 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1375 | setOperationAction(ISD::BR_CC, MVT::f32, Expand); |
| 1376 | setOperationAction(ISD::BR_CC, MVT::f64, Expand); |
| 1377 | setOperationAction(ISD::BR_CC, MVT::i1, Expand); |
| 1378 | setOperationAction(ISD::BR_CC, MVT::i32, Expand); |
| 1379 | setOperationAction(ISD::BR_CC, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1380 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1381 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
Jyotsna Verma | 0eeea14 | 2013-03-05 19:04:47 +0000 | [diff] [blame] | 1382 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1383 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 1384 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 1385 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 1386 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 1387 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 1388 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
| 1389 | setOperationAction(ISD::FSINCOS, MVT::f64, Expand); |
| 1390 | setOperationAction(ISD::FSINCOS, MVT::f32, Expand); |
Jyotsna Verma | 0eeea14 | 2013-03-05 19:04:47 +0000 | [diff] [blame] | 1391 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1392 | // In V4, we have double word add/sub with carry. The problem with |
| 1393 | // modelling this instruction is that it produces 2 results - Rdd and Px. |
| 1394 | // To model update of Px, we will have to use Defs[p0..p3] which will |
| 1395 | // cause any predicate live range to spill. So, we pretend we dont't |
| 1396 | // have these instructions. |
| 1397 | setOperationAction(ISD::ADDE, MVT::i8, Expand); |
| 1398 | setOperationAction(ISD::ADDE, MVT::i16, Expand); |
| 1399 | setOperationAction(ISD::ADDE, MVT::i32, Expand); |
| 1400 | setOperationAction(ISD::ADDE, MVT::i64, Expand); |
| 1401 | setOperationAction(ISD::SUBE, MVT::i8, Expand); |
| 1402 | setOperationAction(ISD::SUBE, MVT::i16, Expand); |
| 1403 | setOperationAction(ISD::SUBE, MVT::i32, Expand); |
| 1404 | setOperationAction(ISD::SUBE, MVT::i64, Expand); |
| 1405 | setOperationAction(ISD::ADDC, MVT::i8, Expand); |
| 1406 | setOperationAction(ISD::ADDC, MVT::i16, Expand); |
| 1407 | setOperationAction(ISD::ADDC, MVT::i32, Expand); |
| 1408 | setOperationAction(ISD::ADDC, MVT::i64, Expand); |
| 1409 | setOperationAction(ISD::SUBC, MVT::i8, Expand); |
| 1410 | setOperationAction(ISD::SUBC, MVT::i16, Expand); |
| 1411 | setOperationAction(ISD::SUBC, MVT::i32, Expand); |
| 1412 | setOperationAction(ISD::SUBC, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1413 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1414 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
| 1415 | setOperationAction(ISD::CTPOP, MVT::i64, Expand); |
| 1416 | setOperationAction(ISD::CTTZ, MVT::i32, Expand); |
| 1417 | setOperationAction(ISD::CTTZ, MVT::i64, Expand); |
| 1418 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i32, Expand); |
| 1419 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i64, Expand); |
| 1420 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
| 1421 | setOperationAction(ISD::CTLZ, MVT::i64, Expand); |
| 1422 | setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Expand); |
| 1423 | setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Expand); |
| 1424 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
| 1425 | setOperationAction(ISD::ROTR, MVT::i32, Expand); |
| 1426 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
| 1427 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); |
| 1428 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand); |
| 1429 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 1430 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1431 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1432 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand); |
| 1433 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand); |
| 1434 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1435 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1436 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 1437 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1438 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1439 | setOperationAction(ISD::SMUL_LOHI, MVT::i64, Expand); |
| 1440 | setOperationAction(ISD::UMUL_LOHI, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1441 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1442 | setOperationAction(ISD::EH_RETURN, MVT::Other, Custom); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1443 | |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 1444 | if (Subtarget.isSubtargetV2()) { |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1445 | setExceptionPointerRegister(Hexagon::R20); |
| 1446 | setExceptionSelectorRegister(Hexagon::R21); |
| 1447 | } else { |
| 1448 | setExceptionPointerRegister(Hexagon::R0); |
| 1449 | setExceptionSelectorRegister(Hexagon::R1); |
| 1450 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1451 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1452 | // VASTART needs to be custom lowered to use the VarArgsFrameIndex. |
| 1453 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1454 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1455 | // Use the default implementation. |
| 1456 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 1457 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 1458 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 1459 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 1460 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1461 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1462 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom); |
| 1463 | setOperationAction(ISD::INLINEASM, MVT::Other, Custom); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1464 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1465 | setMinFunctionAlignment(2); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1466 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1467 | // Needed for DYNAMIC_STACKALLOC expansion. |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 1468 | const HexagonRegisterInfo *QRI = static_cast<const HexagonRegisterInfo *>( |
| 1469 | TM.getSubtargetImpl()->getRegisterInfo()); |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 1470 | setStackPointerRegisterToSaveRestore(QRI->getStackRegister()); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1471 | setSchedulingPreference(Sched::VLIW); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1474 | const char* |
| 1475 | HexagonTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 1476 | switch (Opcode) { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1477 | default: return nullptr; |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1478 | case HexagonISD::CONST32: return "HexagonISD::CONST32"; |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1479 | case HexagonISD::CONST32_GP: return "HexagonISD::CONST32_GP"; |
| 1480 | case HexagonISD::CONST32_Int_Real: return "HexagonISD::CONST32_Int_Real"; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1481 | case HexagonISD::ADJDYNALLOC: return "HexagonISD::ADJDYNALLOC"; |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1482 | case HexagonISD::CMPICC: return "HexagonISD::CMPICC"; |
| 1483 | case HexagonISD::CMPFCC: return "HexagonISD::CMPFCC"; |
| 1484 | case HexagonISD::BRICC: return "HexagonISD::BRICC"; |
| 1485 | case HexagonISD::BRFCC: return "HexagonISD::BRFCC"; |
| 1486 | case HexagonISD::SELECT_ICC: return "HexagonISD::SELECT_ICC"; |
| 1487 | case HexagonISD::SELECT_FCC: return "HexagonISD::SELECT_FCC"; |
| 1488 | case HexagonISD::Hi: return "HexagonISD::Hi"; |
| 1489 | case HexagonISD::Lo: return "HexagonISD::Lo"; |
| 1490 | case HexagonISD::FTOI: return "HexagonISD::FTOI"; |
| 1491 | case HexagonISD::ITOF: return "HexagonISD::ITOF"; |
Colin LeMahieu | 2e3a26d | 2015-01-16 17:05:27 +0000 | [diff] [blame^] | 1492 | case HexagonISD::CALLv3: return "HexagonISD::CALLv3"; |
| 1493 | case HexagonISD::CALLv3nr: return "HexagonISD::CALLv3nr"; |
| 1494 | case HexagonISD::CALLR: return "HexagonISD::CALLR"; |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1495 | case HexagonISD::RET_FLAG: return "HexagonISD::RET_FLAG"; |
| 1496 | case HexagonISD::BR_JT: return "HexagonISD::BR_JT"; |
| 1497 | case HexagonISD::TC_RETURN: return "HexagonISD::TC_RETURN"; |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 1498 | case HexagonISD::EH_RETURN: return "HexagonISD::EH_RETURN"; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | bool |
| 1503 | HexagonTargetLowering::isTruncateFree(Type *Ty1, Type *Ty2) const { |
| 1504 | EVT MTy1 = EVT::getEVT(Ty1); |
| 1505 | EVT MTy2 = EVT::getEVT(Ty2); |
| 1506 | if (!MTy1.isSimple() || !MTy2.isSimple()) { |
| 1507 | return false; |
| 1508 | } |
| 1509 | return ((MTy1.getSimpleVT() == MVT::i64) && (MTy2.getSimpleVT() == MVT::i32)); |
| 1510 | } |
| 1511 | |
| 1512 | bool HexagonTargetLowering::isTruncateFree(EVT VT1, EVT VT2) const { |
| 1513 | if (!VT1.isSimple() || !VT2.isSimple()) { |
| 1514 | return false; |
| 1515 | } |
| 1516 | return ((VT1.getSimpleVT() == MVT::i64) && (VT2.getSimpleVT() == MVT::i32)); |
| 1517 | } |
| 1518 | |
Tim Northover | a441585 | 2013-08-06 09:12:35 +0000 | [diff] [blame] | 1519 | bool |
| 1520 | HexagonTargetLowering::allowTruncateForTailCall(Type *Ty1, Type *Ty2) const { |
| 1521 | // Assuming the caller does not have either a signext or zeroext modifier, and |
| 1522 | // only one value is accepted, any reasonable truncation is allowed. |
| 1523 | if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy()) |
| 1524 | return false; |
| 1525 | |
| 1526 | // FIXME: in principle up to 64-bit could be made safe, but it would be very |
| 1527 | // fragile at the moment: any support for multiple value returns would be |
| 1528 | // liable to disallow tail calls involving i64 -> iN truncation in many cases. |
| 1529 | return Ty1->getPrimitiveSizeInBits() <= 32; |
| 1530 | } |
| 1531 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1532 | SDValue |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 1533 | HexagonTargetLowering::LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const { |
| 1534 | SDValue Chain = Op.getOperand(0); |
| 1535 | SDValue Offset = Op.getOperand(1); |
| 1536 | SDValue Handler = Op.getOperand(2); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1537 | SDLoc dl(Op); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 1538 | |
| 1539 | // Mark function as containing a call to EH_RETURN. |
| 1540 | HexagonMachineFunctionInfo *FuncInfo = |
| 1541 | DAG.getMachineFunction().getInfo<HexagonMachineFunctionInfo>(); |
| 1542 | FuncInfo->setHasEHReturn(); |
| 1543 | |
| 1544 | unsigned OffsetReg = Hexagon::R28; |
| 1545 | |
| 1546 | SDValue StoreAddr = DAG.getNode(ISD::ADD, dl, getPointerTy(), |
| 1547 | DAG.getRegister(Hexagon::R30, getPointerTy()), |
| 1548 | DAG.getIntPtrConstant(4)); |
| 1549 | Chain = DAG.getStore(Chain, dl, Handler, StoreAddr, MachinePointerInfo(), |
| 1550 | false, false, 0); |
| 1551 | Chain = DAG.getCopyToReg(Chain, dl, OffsetReg, Offset); |
| 1552 | |
| 1553 | // Not needed we already use it as explict input to EH_RETURN. |
| 1554 | // MF.getRegInfo().addLiveOut(OffsetReg); |
| 1555 | |
| 1556 | return DAG.getNode(HexagonISD::EH_RETURN, dl, MVT::Other, Chain); |
| 1557 | } |
| 1558 | |
| 1559 | SDValue |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1560 | HexagonTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
| 1561 | switch (Op.getOpcode()) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 1562 | default: llvm_unreachable("Should not custom lower this!"); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1563 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 1564 | case ISD::EH_RETURN: return LowerEH_RETURN(Op, DAG); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1565 | // Frame & Return address. Currently unimplemented. |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1566 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
| 1567 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1568 | case ISD::GlobalTLSAddress: |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 1569 | llvm_unreachable("TLS not implemented for Hexagon."); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1570 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG); |
| 1571 | case ISD::GlobalAddress: return LowerGLOBALADDRESS(Op, DAG); |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1572 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1573 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
| 1574 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
| 1575 | |
| 1576 | case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1577 | case ISD::SELECT: return Op; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1578 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1579 | case ISD::INLINEASM: return LowerINLINEASM(Op, DAG); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1580 | |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | //===----------------------------------------------------------------------===// |
| 1587 | // Hexagon Scheduler Hooks |
| 1588 | //===----------------------------------------------------------------------===// |
| 1589 | MachineBasicBlock * |
| 1590 | HexagonTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
| 1591 | MachineBasicBlock *BB) |
| 1592 | const { |
| 1593 | switch (MI->getOpcode()) { |
| 1594 | case Hexagon::ADJDYNALLOC: { |
| 1595 | MachineFunction *MF = BB->getParent(); |
| 1596 | HexagonMachineFunctionInfo *FuncInfo = |
| 1597 | MF->getInfo<HexagonMachineFunctionInfo>(); |
| 1598 | FuncInfo->addAllocaAdjustInst(MI); |
| 1599 | return BB; |
| 1600 | } |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 1601 | default: llvm_unreachable("Unexpected instr type to insert"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1602 | } // switch |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | //===----------------------------------------------------------------------===// |
| 1606 | // Inline Assembly Support |
| 1607 | //===----------------------------------------------------------------------===// |
| 1608 | |
| 1609 | std::pair<unsigned, const TargetRegisterClass*> |
| 1610 | HexagonTargetLowering::getRegForInlineAsmConstraint(const |
| 1611 | std::string &Constraint, |
Chad Rosier | 295bd43 | 2013-06-22 18:37:38 +0000 | [diff] [blame] | 1612 | MVT VT) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1613 | if (Constraint.size() == 1) { |
| 1614 | switch (Constraint[0]) { |
| 1615 | case 'r': // R0-R31 |
Chad Rosier | 295bd43 | 2013-06-22 18:37:38 +0000 | [diff] [blame] | 1616 | switch (VT.SimpleTy) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1617 | default: |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 1618 | llvm_unreachable("getRegForInlineAsmConstraint Unhandled data type"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1619 | case MVT::i32: |
| 1620 | case MVT::i16: |
| 1621 | case MVT::i8: |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1622 | case MVT::f32: |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1623 | return std::make_pair(0U, &Hexagon::IntRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1624 | case MVT::i64: |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1625 | case MVT::f64: |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1626 | return std::make_pair(0U, &Hexagon::DoubleRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1627 | } |
| 1628 | default: |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 1629 | llvm_unreachable("Unknown asm register class"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 1634 | } |
| 1635 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1636 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 1637 | /// specified FP immediate natively. If false, the legalizer will |
| 1638 | /// materialize the FP immediate as a load from a constant pool. |
| 1639 | bool HexagonTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 1640 | return TM.getSubtarget<HexagonSubtarget>().hasV5TOps(); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1643 | /// isLegalAddressingMode - Return true if the addressing mode represented by |
| 1644 | /// AM is legal for this target, for a load/store of the specified type. |
| 1645 | bool HexagonTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
| 1646 | Type *Ty) const { |
| 1647 | // Allows a signed-extended 11-bit immediate field. |
| 1648 | if (AM.BaseOffs <= -(1LL << 13) || AM.BaseOffs >= (1LL << 13)-1) { |
| 1649 | return false; |
| 1650 | } |
| 1651 | |
| 1652 | // No global is ever allowed as a base. |
| 1653 | if (AM.BaseGV) { |
| 1654 | return false; |
| 1655 | } |
| 1656 | |
| 1657 | int Scale = AM.Scale; |
| 1658 | if (Scale < 0) Scale = -Scale; |
| 1659 | switch (Scale) { |
| 1660 | case 0: // No scale reg, "r+i", "r", or just "i". |
| 1661 | break; |
| 1662 | default: // No scaled addressing mode. |
| 1663 | return false; |
| 1664 | } |
| 1665 | return true; |
| 1666 | } |
| 1667 | |
| 1668 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 1669 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 1670 | /// a register against the immediate without having to materialize the |
| 1671 | /// immediate into a register. |
| 1672 | bool HexagonTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
| 1673 | return Imm >= -512 && Imm <= 511; |
| 1674 | } |
| 1675 | |
| 1676 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1677 | /// for tail call optimization. Targets which want to do tail call |
| 1678 | /// optimization should implement this function. |
| 1679 | bool HexagonTargetLowering::IsEligibleForTailCallOptimization( |
| 1680 | SDValue Callee, |
| 1681 | CallingConv::ID CalleeCC, |
| 1682 | bool isVarArg, |
| 1683 | bool isCalleeStructRet, |
| 1684 | bool isCallerStructRet, |
| 1685 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 1686 | const SmallVectorImpl<SDValue> &OutVals, |
| 1687 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1688 | SelectionDAG& DAG) const { |
| 1689 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1690 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1691 | bool CCMatch = CallerCC == CalleeCC; |
| 1692 | |
| 1693 | // *************************************************************************** |
| 1694 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1695 | // require ABI changes. |
| 1696 | // *************************************************************************** |
| 1697 | |
| 1698 | // If this is a tail call via a function pointer, then don't do it! |
| 1699 | if (!(dyn_cast<GlobalAddressSDNode>(Callee)) |
| 1700 | && !(dyn_cast<ExternalSymbolSDNode>(Callee))) { |
| 1701 | return false; |
| 1702 | } |
| 1703 | |
| 1704 | // Do not optimize if the calling conventions do not match. |
| 1705 | if (!CCMatch) |
| 1706 | return false; |
| 1707 | |
| 1708 | // Do not tail call optimize vararg calls. |
| 1709 | if (isVarArg) |
| 1710 | return false; |
| 1711 | |
| 1712 | // Also avoid tail call optimization if either caller or callee uses struct |
| 1713 | // return semantics. |
| 1714 | if (isCalleeStructRet || isCallerStructRet) |
| 1715 | return false; |
| 1716 | |
| 1717 | // In addition to the cases above, we also disable Tail Call Optimization if |
| 1718 | // the calling convention code that at least one outgoing argument needs to |
| 1719 | // go on the stack. We cannot check that here because at this point that |
| 1720 | // information is not available. |
| 1721 | return true; |
| 1722 | } |
Colin LeMahieu | 025f860 | 2014-12-08 21:19:18 +0000 | [diff] [blame] | 1723 | |
| 1724 | // Return true when the given node fits in a positive half word. |
| 1725 | bool llvm::isPositiveHalfWord(SDNode *N) { |
| 1726 | ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N); |
| 1727 | if (CN && CN->getSExtValue() > 0 && isInt<16>(CN->getSExtValue())) |
| 1728 | return true; |
| 1729 | |
| 1730 | switch (N->getOpcode()) { |
| 1731 | default: |
| 1732 | return false; |
| 1733 | case ISD::SIGN_EXTEND_INREG: |
| 1734 | return true; |
| 1735 | } |
| 1736 | } |