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, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 46 | cl::desc("Control jump table emission on Hexagon target")); |
| 47 | |
| 48 | static cl::opt<bool> EnableHexSDNodeSched("enable-hexagon-sdnode-sched", |
| 49 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 50 | cl::desc("Enable Hexagon SDNode scheduling")); |
| 51 | |
| 52 | static cl::opt<bool> EnableFastMath("ffast-math", |
| 53 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 54 | cl::desc("Enable Fast Math processing")); |
| 55 | |
| 56 | static cl::opt<int> MinimumJumpTables("minimum-jump-tables", |
| 57 | cl::Hidden, cl::ZeroOrMore, cl::init(5), |
| 58 | cl::desc("Set minimum jump tables")); |
| 59 | |
| 60 | static cl::opt<int> MaxStoresPerMemcpyCL("max-store-memcpy", |
| 61 | cl::Hidden, cl::ZeroOrMore, cl::init(6), |
| 62 | cl::desc("Max #stores to inline memcpy")); |
| 63 | |
| 64 | static cl::opt<int> MaxStoresPerMemcpyOptSizeCL("max-store-memcpy-Os", |
| 65 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 66 | cl::desc("Max #stores to inline memcpy")); |
| 67 | |
| 68 | static cl::opt<int> MaxStoresPerMemmoveCL("max-store-memmove", |
| 69 | cl::Hidden, cl::ZeroOrMore, cl::init(6), |
| 70 | cl::desc("Max #stores to inline memmove")); |
| 71 | |
| 72 | static cl::opt<int> MaxStoresPerMemmoveOptSizeCL("max-store-memmove-Os", |
| 73 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 74 | cl::desc("Max #stores to inline memmove")); |
| 75 | |
| 76 | static cl::opt<int> MaxStoresPerMemsetCL("max-store-memset", |
| 77 | cl::Hidden, cl::ZeroOrMore, cl::init(8), |
| 78 | cl::desc("Max #stores to inline memset")); |
| 79 | |
| 80 | static cl::opt<int> MaxStoresPerMemsetOptSizeCL("max-store-memset-Os", |
| 81 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 82 | cl::desc("Max #stores to inline memset")); |
| 83 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 84 | |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 85 | namespace { |
| 86 | class HexagonCCState : public CCState { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 87 | unsigned NumNamedVarArgParams; |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 88 | |
| 89 | public: |
| 90 | HexagonCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 91 | SmallVectorImpl<CCValAssign> &locs, LLVMContext &C, |
| 92 | int NumNamedVarArgParams) |
| 93 | : CCState(CC, isVarArg, MF, locs, C), |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 94 | NumNamedVarArgParams(NumNamedVarArgParams) {} |
| 95 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 96 | unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; } |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 97 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 98 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 99 | |
| 100 | // Implement calling convention for Hexagon. |
| 101 | static bool |
| 102 | CC_Hexagon(unsigned ValNo, MVT ValVT, |
| 103 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 104 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 105 | |
| 106 | static bool |
| 107 | CC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 108 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 109 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 110 | |
| 111 | static bool |
| 112 | CC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 113 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 114 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 115 | |
| 116 | static bool |
| 117 | RetCC_Hexagon(unsigned ValNo, MVT ValVT, |
| 118 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 119 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 120 | |
| 121 | static bool |
| 122 | RetCC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 123 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 124 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 125 | |
| 126 | static bool |
| 127 | RetCC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 128 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 129 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 130 | |
| 131 | static bool |
| 132 | CC_Hexagon_VarArg (unsigned ValNo, MVT ValVT, |
| 133 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 134 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 135 | HexagonCCState &HState = static_cast<HexagonCCState &>(State); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 136 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 137 | if (ValNo < HState.getNumNamedVarArgParams()) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 138 | // Deal with named arguments. |
| 139 | return CC_Hexagon(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State); |
| 140 | } |
| 141 | |
| 142 | // Deal with un-named arguments. |
| 143 | unsigned ofst; |
| 144 | if (ArgFlags.isByVal()) { |
| 145 | // If pass-by-value, the size allocated on stack is decided |
| 146 | // by ArgFlags.getByValSize(), not by the size of LocVT. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 147 | ofst = State.AllocateStack(ArgFlags.getByValSize(), |
| 148 | ArgFlags.getByValAlign()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 149 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, ofst, LocVT, LocInfo)); |
| 150 | return false; |
| 151 | } |
Jyotsna Verma | c7dcc2f | 2013-03-07 20:28:34 +0000 | [diff] [blame] | 152 | if (LocVT == MVT::i1 || LocVT == MVT::i8 || LocVT == MVT::i16) { |
| 153 | LocVT = MVT::i32; |
| 154 | ValVT = MVT::i32; |
| 155 | if (ArgFlags.isSExt()) |
| 156 | LocInfo = CCValAssign::SExt; |
| 157 | else if (ArgFlags.isZExt()) |
| 158 | LocInfo = CCValAssign::ZExt; |
| 159 | else |
| 160 | LocInfo = CCValAssign::AExt; |
| 161 | } |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 162 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 163 | ofst = State.AllocateStack(4, 4); |
| 164 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, ofst, LocVT, LocInfo)); |
| 165 | return false; |
| 166 | } |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 167 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 168 | ofst = State.AllocateStack(8, 8); |
| 169 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, ofst, LocVT, LocInfo)); |
| 170 | return false; |
| 171 | } |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 172 | llvm_unreachable(nullptr); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | |
| 176 | static bool |
| 177 | CC_Hexagon (unsigned ValNo, MVT ValVT, |
| 178 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 179 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 180 | |
| 181 | if (ArgFlags.isByVal()) { |
| 182 | // Passed on stack. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 183 | unsigned Offset = State.AllocateStack(ArgFlags.getByValSize(), |
| 184 | ArgFlags.getByValAlign()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 185 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | if (LocVT == MVT::i1 || LocVT == MVT::i8 || LocVT == MVT::i16) { |
| 190 | LocVT = MVT::i32; |
| 191 | ValVT = MVT::i32; |
| 192 | if (ArgFlags.isSExt()) |
| 193 | LocInfo = CCValAssign::SExt; |
| 194 | else if (ArgFlags.isZExt()) |
| 195 | LocInfo = CCValAssign::ZExt; |
| 196 | else |
| 197 | LocInfo = CCValAssign::AExt; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 198 | } else if (LocVT == MVT::v4i8 || LocVT == MVT::v2i16) { |
| 199 | LocVT = MVT::i32; |
| 200 | LocInfo = CCValAssign::BCvt; |
| 201 | } else if (LocVT == MVT::v8i8 || LocVT == MVT::v4i16 || LocVT == MVT::v2i32) { |
| 202 | LocVT = MVT::i64; |
| 203 | LocInfo = CCValAssign::BCvt; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 206 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 207 | if (!CC_Hexagon32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
| 208 | return false; |
| 209 | } |
| 210 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 211 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 212 | if (!CC_Hexagon64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
| 213 | return false; |
| 214 | } |
| 215 | |
| 216 | return true; // CC didn't match. |
| 217 | } |
| 218 | |
| 219 | |
| 220 | static bool CC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 221 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 222 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 223 | |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 224 | static const MCPhysReg RegList[] = { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 225 | Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4, |
| 226 | Hexagon::R5 |
| 227 | }; |
Tim Northover | 3b6b7ca | 2015-02-21 02:11:17 +0000 | [diff] [blame] | 228 | if (unsigned Reg = State.AllocateReg(RegList)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 229 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 230 | return false; |
| 231 | } |
| 232 | |
| 233 | unsigned Offset = State.AllocateStack(4, 4); |
| 234 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | static bool CC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 239 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 240 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 241 | |
| 242 | if (unsigned Reg = State.AllocateReg(Hexagon::D0)) { |
| 243 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 244 | return false; |
| 245 | } |
| 246 | |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 247 | static const MCPhysReg RegList1[] = { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 248 | Hexagon::D1, Hexagon::D2 |
| 249 | }; |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 250 | static const MCPhysReg RegList2[] = { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 251 | Hexagon::R1, Hexagon::R3 |
| 252 | }; |
Tim Northover | 3b6b7ca | 2015-02-21 02:11:17 +0000 | [diff] [blame] | 253 | if (unsigned Reg = State.AllocateReg(RegList1, RegList2)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 254 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | unsigned Offset = State.AllocateStack(8, 8, Hexagon::D2); |
| 259 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | static bool RetCC_Hexagon(unsigned ValNo, MVT ValVT, |
| 264 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 265 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 266 | |
| 267 | |
| 268 | if (LocVT == MVT::i1 || |
| 269 | LocVT == MVT::i8 || |
| 270 | LocVT == MVT::i16) { |
| 271 | LocVT = MVT::i32; |
| 272 | ValVT = MVT::i32; |
| 273 | if (ArgFlags.isSExt()) |
| 274 | LocInfo = CCValAssign::SExt; |
| 275 | else if (ArgFlags.isZExt()) |
| 276 | LocInfo = CCValAssign::ZExt; |
| 277 | else |
| 278 | LocInfo = CCValAssign::AExt; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 279 | } else if (LocVT == MVT::v4i8 || LocVT == MVT::v2i16) { |
| 280 | LocVT = MVT::i32; |
| 281 | LocInfo = CCValAssign::BCvt; |
| 282 | } else if (LocVT == MVT::v8i8 || LocVT == MVT::v4i16 || LocVT == MVT::v2i32) { |
| 283 | LocVT = MVT::i64; |
| 284 | LocInfo = CCValAssign::BCvt; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 287 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 288 | if (!RetCC_Hexagon32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
| 289 | return false; |
| 290 | } |
| 291 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 292 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 293 | if (!RetCC_Hexagon64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | return true; // CC didn't match. |
| 298 | } |
| 299 | |
| 300 | static bool RetCC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 301 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 302 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 303 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 304 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 305 | if (unsigned Reg = State.AllocateReg(Hexagon::R0)) { |
| 306 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 307 | return false; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | unsigned Offset = State.AllocateStack(4, 4); |
| 312 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 313 | return false; |
| 314 | } |
| 315 | |
| 316 | static bool RetCC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 317 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 318 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 319 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 320 | if (unsigned Reg = State.AllocateReg(Hexagon::D0)) { |
| 321 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 322 | return false; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | unsigned Offset = State.AllocateStack(8, 8); |
| 327 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 328 | return false; |
| 329 | } |
| 330 | |
| 331 | SDValue |
| 332 | HexagonTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) |
| 333 | const { |
| 334 | return SDValue(); |
| 335 | } |
| 336 | |
| 337 | /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified |
| 338 | /// by "Src" to address "Dst" of size "Size". Alignment information is |
| 339 | /// specified by the specific parameter attribute. The copy will be passed as |
| 340 | /// a byval function parameter. Sometimes what we are copying is the end of a |
| 341 | /// larger object, the part that does not fit in registers. |
| 342 | static SDValue |
| 343 | CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, |
| 344 | ISD::ArgFlagsTy Flags, SelectionDAG &DAG, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 345 | SDLoc dl) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 346 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 347 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), dl, MVT::i32); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 348 | return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(), |
| 349 | /*isVolatile=*/false, /*AlwaysInline=*/false, |
Krzysztof Parzyszek | a46c36b | 2015-04-13 17:16:45 +0000 | [diff] [blame] | 350 | /*isTailCall=*/false, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 351 | MachinePointerInfo(), MachinePointerInfo()); |
| 352 | } |
| 353 | |
| 354 | |
| 355 | // LowerReturn - Lower ISD::RET. If a struct is larger than 8 bytes and is |
| 356 | // passed by value, the function prototype is modified to return void and |
| 357 | // the value is stored in memory pointed by a pointer passed by caller. |
| 358 | SDValue |
| 359 | HexagonTargetLowering::LowerReturn(SDValue Chain, |
| 360 | CallingConv::ID CallConv, bool isVarArg, |
| 361 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 362 | const SmallVectorImpl<SDValue> &OutVals, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 363 | SDLoc dl, SelectionDAG &DAG) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 364 | |
| 365 | // CCValAssign - represent the assignment of the return value to locations. |
| 366 | SmallVector<CCValAssign, 16> RVLocs; |
| 367 | |
| 368 | // CCState - Info about the registers and stack slot. |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 369 | CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, |
| 370 | *DAG.getContext()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 371 | |
| 372 | // Analyze return values of ISD::RET |
| 373 | CCInfo.AnalyzeReturn(Outs, RetCC_Hexagon); |
| 374 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 375 | SDValue Flag; |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 376 | SmallVector<SDValue, 4> RetOps(1, Chain); |
| 377 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 378 | // Copy the result values into the output registers. |
| 379 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 380 | CCValAssign &VA = RVLocs[i]; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 381 | |
| 382 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), OutVals[i], Flag); |
| 383 | |
| 384 | // Guarantee that all emitted copies are stuck together with flags. |
| 385 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 386 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 389 | RetOps[0] = Chain; // Update chain. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 390 | |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 391 | // Add the flag if we have it. |
| 392 | if (Flag.getNode()) |
| 393 | RetOps.push_back(Flag); |
| 394 | |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 395 | return DAG.getNode(HexagonISD::RET_FLAG, dl, MVT::Other, RetOps); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 398 | bool HexagonTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
| 399 | // If either no tail call or told not to tail call at all, don't. |
Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 400 | auto Attr = |
| 401 | CI->getParent()->getParent()->getFnAttribute("disable-tail-calls"); |
| 402 | if (!CI->isTailCall() || Attr.getValueAsString() == "true") |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 403 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 404 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 405 | return true; |
| 406 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 407 | |
| 408 | /// LowerCallResult - Lower the result values of an ISD::CALL into the |
| 409 | /// appropriate copies out of appropriate physical registers. This assumes that |
| 410 | /// Chain/InFlag are the input chain/flag to use, and that TheCall is the call |
| 411 | /// being lowered. Returns a SDNode with the same number of values as the |
| 412 | /// ISD::CALL. |
| 413 | SDValue |
| 414 | HexagonTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
| 415 | CallingConv::ID CallConv, bool isVarArg, |
| 416 | const |
| 417 | SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 418 | SDLoc dl, SelectionDAG &DAG, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 419 | SmallVectorImpl<SDValue> &InVals, |
| 420 | const SmallVectorImpl<SDValue> &OutVals, |
| 421 | SDValue Callee) const { |
| 422 | |
| 423 | // Assign locations to each value returned by this call. |
| 424 | SmallVector<CCValAssign, 16> RVLocs; |
| 425 | |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 426 | CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, |
| 427 | *DAG.getContext()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 428 | |
| 429 | CCInfo.AnalyzeCallResult(Ins, RetCC_Hexagon); |
| 430 | |
| 431 | // Copy all of the result registers out of their specified physreg. |
| 432 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 433 | Chain = DAG.getCopyFromReg(Chain, dl, |
| 434 | RVLocs[i].getLocReg(), |
| 435 | RVLocs[i].getValVT(), InFlag).getValue(1); |
| 436 | InFlag = Chain.getValue(2); |
| 437 | InVals.push_back(Chain.getValue(0)); |
| 438 | } |
| 439 | |
| 440 | return Chain; |
| 441 | } |
| 442 | |
| 443 | /// LowerCall - Functions arguments are copied from virtual regs to |
| 444 | /// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted. |
| 445 | SDValue |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 446 | HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 447 | SmallVectorImpl<SDValue> &InVals) const { |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 448 | SelectionDAG &DAG = CLI.DAG; |
Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 449 | SDLoc &dl = CLI.DL; |
| 450 | SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs; |
| 451 | SmallVectorImpl<SDValue> &OutVals = CLI.OutVals; |
| 452 | SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins; |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 453 | SDValue Chain = CLI.Chain; |
| 454 | SDValue Callee = CLI.Callee; |
| 455 | bool &isTailCall = CLI.IsTailCall; |
| 456 | CallingConv::ID CallConv = CLI.CallConv; |
| 457 | bool isVarArg = CLI.IsVarArg; |
Colin LeMahieu | 2e3a26d | 2015-01-16 17:05:27 +0000 | [diff] [blame] | 458 | bool doesNotReturn = CLI.DoesNotReturn; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 459 | |
| 460 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 461 | MachineFunction &MF = DAG.getMachineFunction(); |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 462 | auto PtrVT = getPointerTy(MF.getDataLayout()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 463 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 464 | // Check for varargs. |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 465 | int NumNamedVarArgParams = -1; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 466 | if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(Callee)) |
| 467 | { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 468 | const Function* CalleeFn = nullptr; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 469 | Callee = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, MVT::i32); |
| 470 | if ((CalleeFn = dyn_cast<Function>(GA->getGlobal()))) |
| 471 | { |
| 472 | // If a function has zero args and is a vararg function, that's |
| 473 | // disallowed so it must be an undeclared function. Do not assume |
| 474 | // varargs if the callee is undefined. |
| 475 | if (CalleeFn->isVarArg() && |
| 476 | CalleeFn->getFunctionType()->getNumParams() != 0) { |
| 477 | NumNamedVarArgParams = CalleeFn->getFunctionType()->getNumParams(); |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 482 | // Analyze operands of the call, assigning locations to each operand. |
| 483 | SmallVector<CCValAssign, 16> ArgLocs; |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 484 | HexagonCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs, |
| 485 | *DAG.getContext(), NumNamedVarArgParams); |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 486 | |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 487 | if (isVarArg) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 488 | CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_VarArg); |
| 489 | else |
| 490 | CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon); |
| 491 | |
Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 492 | auto Attr = MF.getFunction()->getFnAttribute("disable-tail-calls"); |
| 493 | if (Attr.getValueAsString() == "true") |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 494 | isTailCall = false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 495 | |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 496 | if (isTailCall) { |
| 497 | bool StructAttrFlag = MF.getFunction()->hasStructRetAttr(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 498 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 499 | isVarArg, IsStructRet, |
| 500 | StructAttrFlag, |
| 501 | Outs, OutVals, Ins, DAG); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 502 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 503 | CCValAssign &VA = ArgLocs[i]; |
| 504 | if (VA.isMemLoc()) { |
| 505 | isTailCall = false; |
| 506 | break; |
| 507 | } |
| 508 | } |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 509 | DEBUG(dbgs() << (isTailCall ? "Eligible for Tail Call\n" |
| 510 | : "Argument must be passed on stack. " |
| 511 | "Not eligible for Tail Call\n")); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 512 | } |
| 513 | // Get a count of how many bytes are to be pushed on the stack. |
| 514 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
| 515 | SmallVector<std::pair<unsigned, SDValue>, 16> RegsToPass; |
| 516 | SmallVector<SDValue, 8> MemOpChains; |
| 517 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 518 | auto &HRI = *Subtarget.getRegisterInfo(); |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 519 | SDValue StackPtr = |
| 520 | DAG.getCopyFromReg(Chain, dl, HRI.getStackRegister(), PtrVT); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 521 | |
| 522 | // Walk the register/memloc assignments, inserting copies/loads. |
| 523 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 524 | CCValAssign &VA = ArgLocs[i]; |
| 525 | SDValue Arg = OutVals[i]; |
| 526 | ISD::ArgFlagsTy Flags = Outs[i].Flags; |
| 527 | |
| 528 | // Promote the value if needed. |
| 529 | switch (VA.getLocInfo()) { |
| 530 | default: |
| 531 | // Loc info must be one of Full, SExt, ZExt, or AExt. |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 532 | llvm_unreachable("Unknown loc info!"); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 533 | case CCValAssign::BCvt: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 534 | case CCValAssign::Full: |
| 535 | break; |
| 536 | case CCValAssign::SExt: |
| 537 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 538 | break; |
| 539 | case CCValAssign::ZExt: |
| 540 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 541 | break; |
| 542 | case CCValAssign::AExt: |
| 543 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 544 | break; |
| 545 | } |
| 546 | |
| 547 | if (VA.isMemLoc()) { |
| 548 | unsigned LocMemOffset = VA.getLocMemOffset(); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 549 | SDValue MemAddr = DAG.getConstant(LocMemOffset, dl, |
| 550 | StackPtr.getValueType()); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 551 | MemAddr = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, MemAddr); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 552 | if (Flags.isByVal()) { |
| 553 | // The argument is a struct passed by value. According to LLVM, "Arg" |
| 554 | // is is pointer. |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 555 | MemOpChains.push_back(CreateCopyOfByValArgument(Arg, MemAddr, Chain, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 556 | Flags, DAG, dl)); |
| 557 | } else { |
Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 558 | MachinePointerInfo LocPI = MachinePointerInfo::getStack( |
| 559 | DAG.getMachineFunction(), LocMemOffset); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 560 | SDValue S = DAG.getStore(Chain, dl, Arg, MemAddr, LocPI, false, |
| 561 | false, 0); |
| 562 | MemOpChains.push_back(S); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 563 | } |
| 564 | continue; |
| 565 | } |
| 566 | |
| 567 | // Arguments that can be passed on register must be kept at RegsToPass |
| 568 | // vector. |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 569 | if (VA.isRegLoc()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 570 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | // Transform all store nodes into one single node because all store |
| 574 | // nodes are independent of each other. |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 575 | if (!MemOpChains.empty()) |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 576 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 577 | |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 578 | if (!isTailCall) { |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 579 | SDValue C = DAG.getConstant(NumBytes, dl, PtrVT, true); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 580 | Chain = DAG.getCALLSEQ_START(Chain, C, dl); |
| 581 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 582 | |
| 583 | // Build a sequence of copy-to-reg nodes chained together with token |
| 584 | // chain and flag operands which copy the outgoing args into registers. |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 585 | // The InFlag in necessary since all emitted instructions must be |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 586 | // stuck together. |
| 587 | SDValue InFlag; |
| 588 | if (!isTailCall) { |
| 589 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 590 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 591 | RegsToPass[i].second, InFlag); |
| 592 | InFlag = Chain.getValue(1); |
| 593 | } |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 594 | } else { |
| 595 | // For tail calls lower the arguments to the 'real' stack slot. |
| 596 | // |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 597 | // Force all the incoming stack arguments to be loaded from the stack |
| 598 | // before any new outgoing arguments are stored to the stack, because the |
| 599 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 600 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 601 | // than necessary, because it means that each store effectively depends |
| 602 | // on every argument instead of just those arguments it would clobber. |
| 603 | // |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 604 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 605 | InFlag = SDValue(); |
| 606 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 607 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 608 | RegsToPass[i].second, InFlag); |
| 609 | InFlag = Chain.getValue(1); |
| 610 | } |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 611 | InFlag = SDValue(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 615 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 616 | // node so that legalize doesn't hack it. |
| 617 | if (flag_aligned_memcpy) { |
| 618 | const char *MemcpyName = |
| 619 | "__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes"; |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 620 | Callee = DAG.getTargetExternalSymbol(MemcpyName, PtrVT); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 621 | flag_aligned_memcpy = false; |
| 622 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 623 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, PtrVT); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 624 | } else if (ExternalSymbolSDNode *S = |
| 625 | dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 626 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), PtrVT); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | // Returns a chain & a flag for retval copy to use. |
| 630 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| 631 | SmallVector<SDValue, 8> Ops; |
| 632 | Ops.push_back(Chain); |
| 633 | Ops.push_back(Callee); |
| 634 | |
| 635 | // Add argument registers to the end of the list so that they are |
| 636 | // known live into the call. |
| 637 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 638 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 639 | RegsToPass[i].second.getValueType())); |
| 640 | } |
| 641 | |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 642 | if (InFlag.getNode()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 643 | Ops.push_back(InFlag); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 644 | |
Arnold Schwaighofer | f54b73d | 2015-05-08 23:52:00 +0000 | [diff] [blame] | 645 | if (isTailCall) { |
| 646 | MF.getFrameInfo()->setHasTailCall(); |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 647 | return DAG.getNode(HexagonISD::TC_RETURN, dl, NodeTys, Ops); |
Arnold Schwaighofer | f54b73d | 2015-05-08 23:52:00 +0000 | [diff] [blame] | 648 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 649 | |
Colin LeMahieu | 2e3a26d | 2015-01-16 17:05:27 +0000 | [diff] [blame] | 650 | int OpCode = doesNotReturn ? HexagonISD::CALLv3nr : HexagonISD::CALLv3; |
| 651 | Chain = DAG.getNode(OpCode, dl, NodeTys, Ops); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 652 | InFlag = Chain.getValue(1); |
| 653 | |
| 654 | // Create the CALLSEQ_END node. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 655 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, dl, true), |
| 656 | DAG.getIntPtrConstant(0, dl, true), InFlag, dl); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 657 | InFlag = Chain.getValue(1); |
| 658 | |
| 659 | // Handle result values, copying them out of physregs into vregs that we |
| 660 | // return. |
| 661 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, dl, DAG, |
| 662 | InVals, OutVals, Callee); |
| 663 | } |
| 664 | |
| 665 | static bool getIndexedAddressParts(SDNode *Ptr, EVT VT, |
| 666 | bool isSEXTLoad, SDValue &Base, |
| 667 | SDValue &Offset, bool &isInc, |
| 668 | SelectionDAG &DAG) { |
| 669 | if (Ptr->getOpcode() != ISD::ADD) |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 670 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 671 | |
| 672 | if (VT == MVT::i64 || VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8) { |
| 673 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 674 | Base = Ptr->getOperand(0); |
| 675 | Offset = Ptr->getOperand(1); |
| 676 | // Ensure that Offset is a constant. |
| 677 | return (isa<ConstantSDNode>(Offset)); |
| 678 | } |
| 679 | |
| 680 | return false; |
| 681 | } |
| 682 | |
| 683 | // TODO: Put this function along with the other isS* functions in |
| 684 | // HexagonISelDAGToDAG.cpp into a common file. Or better still, use the |
Rafael Espindola | b90c5f1 | 2012-11-21 16:56:33 +0000 | [diff] [blame] | 685 | // functions defined in HexagonOperands.td. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 686 | static bool Is_PostInc_S4_Offset(SDNode * S, int ShiftAmount) { |
| 687 | ConstantSDNode *N = cast<ConstantSDNode>(S); |
| 688 | |
| 689 | // immS4 predicate - True if the immediate fits in a 4-bit sign extended. |
| 690 | // field. |
| 691 | int64_t v = (int64_t)N->getSExtValue(); |
| 692 | int64_t m = 0; |
| 693 | if (ShiftAmount > 0) { |
| 694 | m = v % ShiftAmount; |
| 695 | v = v >> ShiftAmount; |
| 696 | } |
| 697 | return (v <= 7) && (v >= -8) && (m == 0); |
| 698 | } |
| 699 | |
| 700 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 701 | /// offset pointer and addressing mode by reference if this node can be |
| 702 | /// combined with a load / store to form a post-indexed load / store. |
| 703 | bool HexagonTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
| 704 | SDValue &Base, |
| 705 | SDValue &Offset, |
| 706 | ISD::MemIndexedMode &AM, |
| 707 | SelectionDAG &DAG) const |
| 708 | { |
| 709 | EVT VT; |
| 710 | SDValue Ptr; |
| 711 | bool isSEXTLoad = false; |
| 712 | |
| 713 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 714 | VT = LD->getMemoryVT(); |
| 715 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 716 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 717 | VT = ST->getMemoryVT(); |
| 718 | if (ST->getValue().getValueType() == MVT::i64 && ST->isTruncatingStore()) { |
| 719 | return false; |
| 720 | } |
| 721 | } else { |
| 722 | return false; |
| 723 | } |
| 724 | |
Chad Rosier | 64dc8aa | 2012-01-06 20:11:59 +0000 | [diff] [blame] | 725 | bool isInc = false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 726 | bool isLegal = getIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 727 | isInc, DAG); |
| 728 | // ShiftAmount = number of left-shifted bits in the Hexagon instruction. |
| 729 | int ShiftAmount = VT.getSizeInBits() / 16; |
| 730 | if (isLegal && Is_PostInc_S4_Offset(Offset.getNode(), ShiftAmount)) { |
| 731 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 732 | return true; |
| 733 | } |
| 734 | |
| 735 | return false; |
| 736 | } |
| 737 | |
| 738 | SDValue HexagonTargetLowering::LowerINLINEASM(SDValue Op, |
| 739 | SelectionDAG &DAG) const { |
| 740 | SDNode *Node = Op.getNode(); |
| 741 | MachineFunction &MF = DAG.getMachineFunction(); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 742 | auto &FuncInfo = *MF.getInfo<HexagonMachineFunctionInfo>(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 743 | switch (Node->getOpcode()) { |
| 744 | case ISD::INLINEASM: { |
| 745 | unsigned NumOps = Node->getNumOperands(); |
| 746 | if (Node->getOperand(NumOps-1).getValueType() == MVT::Glue) |
| 747 | --NumOps; // Ignore the flag operand. |
| 748 | |
| 749 | for (unsigned i = InlineAsm::Op_FirstOperand; i != NumOps;) { |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 750 | if (FuncInfo.hasClobberLR()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 751 | break; |
| 752 | unsigned Flags = |
| 753 | cast<ConstantSDNode>(Node->getOperand(i))->getZExtValue(); |
| 754 | unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags); |
| 755 | ++i; // Skip the ID value. |
| 756 | |
| 757 | switch (InlineAsm::getKind(Flags)) { |
| 758 | default: llvm_unreachable("Bad flags!"); |
| 759 | case InlineAsm::Kind_RegDef: |
| 760 | case InlineAsm::Kind_RegUse: |
| 761 | case InlineAsm::Kind_Imm: |
| 762 | case InlineAsm::Kind_Clobber: |
| 763 | case InlineAsm::Kind_Mem: { |
| 764 | for (; NumVals; --NumVals, ++i) {} |
| 765 | break; |
| 766 | } |
| 767 | case InlineAsm::Kind_RegDefEarlyClobber: { |
| 768 | for (; NumVals; --NumVals, ++i) { |
| 769 | unsigned Reg = |
| 770 | cast<RegisterSDNode>(Node->getOperand(i))->getReg(); |
| 771 | |
| 772 | // Check it to be lr |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 773 | const HexagonRegisterInfo *QRI = Subtarget.getRegisterInfo(); |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 774 | if (Reg == QRI->getRARegister()) { |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 775 | FuncInfo.setHasClobberLR(true); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 776 | break; |
| 777 | } |
| 778 | } |
| 779 | break; |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | } // Node->getOpcode |
| 785 | return Op; |
| 786 | } |
| 787 | |
| 788 | |
| 789 | // |
| 790 | // Taken from the XCore backend. |
| 791 | // |
| 792 | SDValue HexagonTargetLowering:: |
| 793 | LowerBR_JT(SDValue Op, SelectionDAG &DAG) const |
| 794 | { |
| 795 | SDValue Chain = Op.getOperand(0); |
| 796 | SDValue Table = Op.getOperand(1); |
| 797 | SDValue Index = Op.getOperand(2); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 798 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 799 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 800 | unsigned JTI = JT->getIndex(); |
| 801 | MachineFunction &MF = DAG.getMachineFunction(); |
| 802 | const MachineJumpTableInfo *MJTI = MF.getJumpTableInfo(); |
| 803 | SDValue TargetJT = DAG.getTargetJumpTable(JT->getIndex(), MVT::i32); |
| 804 | |
| 805 | // Mark all jump table targets as address taken. |
| 806 | const std::vector<MachineJumpTableEntry> &JTE = MJTI->getJumpTables(); |
| 807 | const std::vector<MachineBasicBlock*> &JTBBs = JTE[JTI].MBBs; |
| 808 | for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) { |
| 809 | MachineBasicBlock *MBB = JTBBs[i]; |
| 810 | MBB->setHasAddressTaken(); |
| 811 | // This line is needed to set the hasAddressTaken flag on the BasicBlock |
| 812 | // object. |
| 813 | BlockAddress::get(const_cast<BasicBlock *>(MBB->getBasicBlock())); |
| 814 | } |
| 815 | |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 816 | SDValue JumpTableBase = DAG.getNode( |
| 817 | HexagonISD::JT, dl, getPointerTy(DAG.getDataLayout()), TargetJT); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 818 | SDValue ShiftIndex = DAG.getNode(ISD::SHL, dl, MVT::i32, Index, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 819 | DAG.getConstant(2, dl, MVT::i32)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 820 | SDValue JTAddress = DAG.getNode(ISD::ADD, dl, MVT::i32, JumpTableBase, |
| 821 | ShiftIndex); |
| 822 | SDValue LoadTarget = DAG.getLoad(MVT::i32, dl, Chain, JTAddress, |
| 823 | MachinePointerInfo(), false, false, false, |
| 824 | 0); |
| 825 | return DAG.getNode(HexagonISD::BR_JT, dl, MVT::Other, Chain, LoadTarget); |
| 826 | } |
| 827 | |
| 828 | |
| 829 | SDValue |
| 830 | HexagonTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, |
| 831 | SelectionDAG &DAG) const { |
| 832 | SDValue Chain = Op.getOperand(0); |
| 833 | SDValue Size = Op.getOperand(1); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 834 | SDValue Align = Op.getOperand(2); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 835 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 836 | |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 837 | ConstantSDNode *AlignConst = dyn_cast<ConstantSDNode>(Align); |
| 838 | assert(AlignConst && "Non-constant Align in LowerDYNAMIC_STACKALLOC"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 839 | |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 840 | unsigned A = AlignConst->getSExtValue(); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 841 | auto &HFI = *Subtarget.getFrameLowering(); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 842 | // "Zero" means natural stack alignment. |
| 843 | if (A == 0) |
| 844 | A = HFI.getStackAlignment(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 845 | |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 846 | DEBUG({ |
Krzysztof Parzyszek | 9ee04e4 | 2015-04-22 17:19:44 +0000 | [diff] [blame] | 847 | dbgs () << LLVM_FUNCTION_NAME << " Align: " << A << " Size: "; |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 848 | Size.getNode()->dump(&DAG); |
| 849 | dbgs() << "\n"; |
| 850 | }); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 851 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 852 | SDValue AC = DAG.getConstant(A, dl, MVT::i32); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 853 | SDVTList VTs = DAG.getVTList(MVT::i32, MVT::Other); |
Krzysztof Parzyszek | 23920ec | 2015-10-19 18:30:27 +0000 | [diff] [blame] | 854 | SDValue AA = DAG.getNode(HexagonISD::ALLOCA, dl, VTs, Chain, Size, AC); |
| 855 | if (Op.getNode()->getHasDebugValue()) |
| 856 | DAG.TransferDbgValues(Op, AA); |
| 857 | return AA; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | SDValue |
| 861 | HexagonTargetLowering::LowerFormalArguments(SDValue Chain, |
| 862 | CallingConv::ID CallConv, |
| 863 | bool isVarArg, |
| 864 | const |
| 865 | SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 866 | SDLoc dl, SelectionDAG &DAG, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 867 | SmallVectorImpl<SDValue> &InVals) |
| 868 | const { |
| 869 | |
| 870 | MachineFunction &MF = DAG.getMachineFunction(); |
| 871 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 872 | MachineRegisterInfo &RegInfo = MF.getRegInfo(); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 873 | auto &FuncInfo = *MF.getInfo<HexagonMachineFunctionInfo>(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 874 | |
| 875 | // Assign locations to all of the incoming arguments. |
| 876 | SmallVector<CCValAssign, 16> ArgLocs; |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 877 | CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs, |
| 878 | *DAG.getContext()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 879 | |
| 880 | CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon); |
| 881 | |
| 882 | // For LLVM, in the case when returning a struct by value (>8byte), |
| 883 | // the first argument is a pointer that points to the location on caller's |
| 884 | // stack where the return value will be stored. For Hexagon, the location on |
| 885 | // caller's stack is passed only when the struct size is smaller than (and |
| 886 | // equal to) 8 bytes. If not, no address will be passed into callee and |
| 887 | // callee return the result direclty through R0/R1. |
| 888 | |
| 889 | SmallVector<SDValue, 4> MemOps; |
| 890 | |
| 891 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 892 | CCValAssign &VA = ArgLocs[i]; |
| 893 | ISD::ArgFlagsTy Flags = Ins[i].Flags; |
| 894 | unsigned ObjSize; |
| 895 | unsigned StackLocation; |
| 896 | int FI; |
| 897 | |
| 898 | if ( (VA.isRegLoc() && !Flags.isByVal()) |
| 899 | || (VA.isRegLoc() && Flags.isByVal() && Flags.getByValSize() > 8)) { |
| 900 | // Arguments passed in registers |
| 901 | // 1. int, long long, ptr args that get allocated in register. |
| 902 | // 2. Large struct that gets an register to put its address in. |
| 903 | EVT RegVT = VA.getLocVT(); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 904 | if (RegVT == MVT::i8 || RegVT == MVT::i16 || |
| 905 | RegVT == MVT::i32 || RegVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 906 | unsigned VReg = |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 907 | RegInfo.createVirtualRegister(&Hexagon::IntRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 908 | RegInfo.addLiveIn(VA.getLocReg(), VReg); |
| 909 | InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT)); |
Colin LeMahieu | 4379d10 | 2015-01-28 22:08:16 +0000 | [diff] [blame] | 910 | } else if (RegVT == MVT::i64 || RegVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 911 | unsigned VReg = |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 912 | RegInfo.createVirtualRegister(&Hexagon::DoubleRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 913 | RegInfo.addLiveIn(VA.getLocReg(), VReg); |
| 914 | InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT)); |
| 915 | } else { |
| 916 | assert (0); |
| 917 | } |
| 918 | } else if (VA.isRegLoc() && Flags.isByVal() && Flags.getByValSize() <= 8) { |
| 919 | assert (0 && "ByValSize must be bigger than 8 bytes"); |
| 920 | } else { |
| 921 | // Sanity check. |
| 922 | assert(VA.isMemLoc()); |
| 923 | |
| 924 | if (Flags.isByVal()) { |
| 925 | // If it's a byval parameter, then we need to compute the |
| 926 | // "real" size, not the size of the pointer. |
| 927 | ObjSize = Flags.getByValSize(); |
| 928 | } else { |
| 929 | ObjSize = VA.getLocVT().getStoreSizeInBits() >> 3; |
| 930 | } |
| 931 | |
| 932 | StackLocation = HEXAGON_LRFP_SIZE + VA.getLocMemOffset(); |
| 933 | // Create the frame index object for this incoming parameter... |
| 934 | FI = MFI->CreateFixedObject(ObjSize, StackLocation, true); |
| 935 | |
| 936 | // Create the SelectionDAG nodes cordl, responding to a load |
| 937 | // from this parameter. |
| 938 | SDValue FIN = DAG.getFrameIndex(FI, MVT::i32); |
| 939 | |
| 940 | if (Flags.isByVal()) { |
| 941 | // If it's a pass-by-value aggregate, then do not dereference the stack |
| 942 | // location. Instead, we should generate a reference to the stack |
| 943 | // location. |
| 944 | InVals.push_back(FIN); |
| 945 | } else { |
| 946 | InVals.push_back(DAG.getLoad(VA.getLocVT(), dl, Chain, FIN, |
| 947 | MachinePointerInfo(), false, false, |
| 948 | false, 0)); |
| 949 | } |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | if (!MemOps.empty()) |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 954 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOps); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 955 | |
| 956 | if (isVarArg) { |
| 957 | // This will point to the next argument passed via stack. |
| 958 | int FrameIndex = MFI->CreateFixedObject(Hexagon_PointerSize, |
| 959 | HEXAGON_LRFP_SIZE + |
| 960 | CCInfo.getNextStackOffset(), |
| 961 | true); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 962 | FuncInfo.setVarArgsFrameIndex(FrameIndex); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | return Chain; |
| 966 | } |
| 967 | |
| 968 | SDValue |
| 969 | HexagonTargetLowering::LowerVASTART(SDValue Op, SelectionDAG &DAG) const { |
| 970 | // VASTART stores the address of the VarArgsFrameIndex slot into the |
| 971 | // memory location argument. |
| 972 | MachineFunction &MF = DAG.getMachineFunction(); |
| 973 | HexagonMachineFunctionInfo *QFI = MF.getInfo<HexagonMachineFunctionInfo>(); |
| 974 | SDValue Addr = DAG.getFrameIndex(QFI->getVarArgsFrameIndex(), MVT::i32); |
| 975 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 976 | return DAG.getStore(Op.getOperand(0), SDLoc(Op), Addr, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 977 | Op.getOperand(1), MachinePointerInfo(SV), false, |
| 978 | false, 0); |
| 979 | } |
| 980 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 981 | // Creates a SPLAT instruction for a constant value VAL. |
| 982 | static SDValue createSplat(SelectionDAG &DAG, SDLoc dl, EVT VT, SDValue Val) { |
| 983 | if (VT.getSimpleVT() == MVT::v4i8) |
| 984 | return DAG.getNode(HexagonISD::VSPLATB, dl, VT, Val); |
| 985 | |
| 986 | if (VT.getSimpleVT() == MVT::v4i16) |
| 987 | return DAG.getNode(HexagonISD::VSPLATH, dl, VT, Val); |
| 988 | |
| 989 | return SDValue(); |
| 990 | } |
| 991 | |
| 992 | static bool isSExtFree(SDValue N) { |
| 993 | // A sign-extend of a truncate of a sign-extend is free. |
| 994 | if (N.getOpcode() == ISD::TRUNCATE && |
| 995 | N.getOperand(0).getOpcode() == ISD::AssertSext) |
| 996 | return true; |
| 997 | // We have sign-extended loads. |
| 998 | if (N.getOpcode() == ISD::LOAD) |
| 999 | return true; |
| 1000 | return false; |
| 1001 | } |
| 1002 | |
| 1003 | SDValue HexagonTargetLowering::LowerCTPOP(SDValue Op, SelectionDAG &DAG) const { |
| 1004 | SDLoc dl(Op); |
| 1005 | SDValue InpVal = Op.getOperand(0); |
| 1006 | if (isa<ConstantSDNode>(InpVal)) { |
| 1007 | uint64_t V = cast<ConstantSDNode>(InpVal)->getZExtValue(); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1008 | return DAG.getTargetConstant(countPopulation(V), dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1009 | } |
| 1010 | SDValue PopOut = DAG.getNode(HexagonISD::POPCOUNT, dl, MVT::i32, InpVal); |
| 1011 | return DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i64, PopOut); |
| 1012 | } |
| 1013 | |
| 1014 | SDValue HexagonTargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) const { |
| 1015 | SDLoc dl(Op); |
| 1016 | |
| 1017 | SDValue LHS = Op.getOperand(0); |
| 1018 | SDValue RHS = Op.getOperand(1); |
| 1019 | SDValue Cmp = Op.getOperand(2); |
| 1020 | ISD::CondCode CC = cast<CondCodeSDNode>(Cmp)->get(); |
| 1021 | |
| 1022 | EVT VT = Op.getValueType(); |
| 1023 | EVT LHSVT = LHS.getValueType(); |
| 1024 | EVT RHSVT = RHS.getValueType(); |
| 1025 | |
| 1026 | if (LHSVT == MVT::v2i16) { |
| 1027 | assert(ISD::isSignedIntSetCC(CC) || ISD::isUnsignedIntSetCC(CC)); |
| 1028 | unsigned ExtOpc = ISD::isSignedIntSetCC(CC) ? ISD::SIGN_EXTEND |
| 1029 | : ISD::ZERO_EXTEND; |
| 1030 | SDValue LX = DAG.getNode(ExtOpc, dl, MVT::v2i32, LHS); |
| 1031 | SDValue RX = DAG.getNode(ExtOpc, dl, MVT::v2i32, RHS); |
| 1032 | SDValue SC = DAG.getNode(ISD::SETCC, dl, MVT::v2i1, LX, RX, Cmp); |
| 1033 | return SC; |
| 1034 | } |
| 1035 | |
| 1036 | // Treat all other vector types as legal. |
| 1037 | if (VT.isVector()) |
| 1038 | return Op; |
| 1039 | |
| 1040 | // Equals and not equals should use sign-extend, not zero-extend, since |
| 1041 | // we can represent small negative values in the compare instructions. |
| 1042 | // The LLVM default is to use zero-extend arbitrarily in these cases. |
| 1043 | if ((CC == ISD::SETEQ || CC == ISD::SETNE) && |
| 1044 | (RHSVT == MVT::i8 || RHSVT == MVT::i16) && |
| 1045 | (LHSVT == MVT::i8 || LHSVT == MVT::i16)) { |
| 1046 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHS); |
| 1047 | if (C && C->getAPIntValue().isNegative()) { |
| 1048 | LHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, LHS); |
| 1049 | RHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, RHS); |
| 1050 | return DAG.getNode(ISD::SETCC, dl, Op.getValueType(), |
| 1051 | LHS, RHS, Op.getOperand(2)); |
| 1052 | } |
| 1053 | if (isSExtFree(LHS) || isSExtFree(RHS)) { |
| 1054 | LHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, LHS); |
| 1055 | RHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, RHS); |
| 1056 | return DAG.getNode(ISD::SETCC, dl, Op.getValueType(), |
| 1057 | LHS, RHS, Op.getOperand(2)); |
| 1058 | } |
| 1059 | } |
| 1060 | return SDValue(); |
| 1061 | } |
| 1062 | |
| 1063 | SDValue HexagonTargetLowering::LowerVSELECT(SDValue Op, SelectionDAG &DAG) |
| 1064 | const { |
| 1065 | SDValue PredOp = Op.getOperand(0); |
| 1066 | SDValue Op1 = Op.getOperand(1), Op2 = Op.getOperand(2); |
| 1067 | EVT OpVT = Op1.getValueType(); |
| 1068 | SDLoc DL(Op); |
| 1069 | |
| 1070 | if (OpVT == MVT::v2i16) { |
| 1071 | SDValue X1 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v2i32, Op1); |
| 1072 | SDValue X2 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v2i32, Op2); |
| 1073 | SDValue SL = DAG.getNode(ISD::VSELECT, DL, MVT::v2i32, PredOp, X1, X2); |
| 1074 | SDValue TR = DAG.getNode(ISD::TRUNCATE, DL, MVT::v2i16, SL); |
| 1075 | return TR; |
| 1076 | } |
| 1077 | |
| 1078 | return SDValue(); |
| 1079 | } |
| 1080 | |
| 1081 | // Handle only specific vector loads. |
| 1082 | SDValue HexagonTargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const { |
| 1083 | EVT VT = Op.getValueType(); |
| 1084 | SDLoc DL(Op); |
| 1085 | LoadSDNode *LoadNode = cast<LoadSDNode>(Op); |
| 1086 | SDValue Chain = LoadNode->getChain(); |
| 1087 | SDValue Ptr = Op.getOperand(1); |
| 1088 | SDValue LoweredLoad; |
| 1089 | SDValue Result; |
| 1090 | SDValue Base = LoadNode->getBasePtr(); |
| 1091 | ISD::LoadExtType Ext = LoadNode->getExtensionType(); |
| 1092 | unsigned Alignment = LoadNode->getAlignment(); |
| 1093 | SDValue LoadChain; |
| 1094 | |
| 1095 | if(Ext == ISD::NON_EXTLOAD) |
| 1096 | Ext = ISD::ZEXTLOAD; |
| 1097 | |
| 1098 | if (VT == MVT::v4i16) { |
| 1099 | if (Alignment == 2) { |
| 1100 | SDValue Loads[4]; |
| 1101 | // Base load. |
| 1102 | Loads[0] = DAG.getExtLoad(Ext, DL, MVT::i32, Chain, Base, |
| 1103 | LoadNode->getPointerInfo(), MVT::i16, |
| 1104 | LoadNode->isVolatile(), |
| 1105 | LoadNode->isNonTemporal(), |
| 1106 | LoadNode->isInvariant(), |
| 1107 | Alignment); |
| 1108 | // Base+2 load. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1109 | SDValue Increment = DAG.getConstant(2, DL, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1110 | Ptr = DAG.getNode(ISD::ADD, DL, Base.getValueType(), Base, Increment); |
| 1111 | Loads[1] = DAG.getExtLoad(Ext, DL, MVT::i32, Chain, Ptr, |
| 1112 | LoadNode->getPointerInfo(), MVT::i16, |
| 1113 | LoadNode->isVolatile(), |
| 1114 | LoadNode->isNonTemporal(), |
| 1115 | LoadNode->isInvariant(), |
| 1116 | Alignment); |
| 1117 | // SHL 16, then OR base and base+2. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1118 | SDValue ShiftAmount = DAG.getConstant(16, DL, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1119 | SDValue Tmp1 = DAG.getNode(ISD::SHL, DL, MVT::i32, Loads[1], ShiftAmount); |
| 1120 | SDValue Tmp2 = DAG.getNode(ISD::OR, DL, MVT::i32, Tmp1, Loads[0]); |
| 1121 | // Base + 4. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1122 | Increment = DAG.getConstant(4, DL, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1123 | Ptr = DAG.getNode(ISD::ADD, DL, Base.getValueType(), Base, Increment); |
| 1124 | Loads[2] = DAG.getExtLoad(Ext, DL, MVT::i32, Chain, Ptr, |
| 1125 | LoadNode->getPointerInfo(), MVT::i16, |
| 1126 | LoadNode->isVolatile(), |
| 1127 | LoadNode->isNonTemporal(), |
| 1128 | LoadNode->isInvariant(), |
| 1129 | Alignment); |
| 1130 | // Base + 6. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1131 | Increment = DAG.getConstant(6, DL, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1132 | Ptr = DAG.getNode(ISD::ADD, DL, Base.getValueType(), Base, Increment); |
| 1133 | Loads[3] = DAG.getExtLoad(Ext, DL, MVT::i32, Chain, Ptr, |
| 1134 | LoadNode->getPointerInfo(), MVT::i16, |
| 1135 | LoadNode->isVolatile(), |
| 1136 | LoadNode->isNonTemporal(), |
| 1137 | LoadNode->isInvariant(), |
| 1138 | Alignment); |
| 1139 | // SHL 16, then OR base+4 and base+6. |
| 1140 | Tmp1 = DAG.getNode(ISD::SHL, DL, MVT::i32, Loads[3], ShiftAmount); |
| 1141 | SDValue Tmp4 = DAG.getNode(ISD::OR, DL, MVT::i32, Tmp1, Loads[2]); |
| 1142 | // Combine to i64. This could be optimised out later if we can |
| 1143 | // affect reg allocation of this code. |
| 1144 | Result = DAG.getNode(HexagonISD::COMBINE, DL, MVT::i64, Tmp4, Tmp2); |
| 1145 | LoadChain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, |
| 1146 | Loads[0].getValue(1), Loads[1].getValue(1), |
| 1147 | Loads[2].getValue(1), Loads[3].getValue(1)); |
| 1148 | } else { |
| 1149 | // Perform default type expansion. |
| 1150 | Result = DAG.getLoad(MVT::i64, DL, Chain, Ptr, LoadNode->getPointerInfo(), |
| 1151 | LoadNode->isVolatile(), LoadNode->isNonTemporal(), |
| 1152 | LoadNode->isInvariant(), LoadNode->getAlignment()); |
| 1153 | LoadChain = Result.getValue(1); |
| 1154 | } |
| 1155 | } else |
| 1156 | llvm_unreachable("Custom lowering unsupported load"); |
| 1157 | |
| 1158 | Result = DAG.getNode(ISD::BITCAST, DL, VT, Result); |
| 1159 | // Since we pretend to lower a load, we need the original chain |
| 1160 | // info attached to the result. |
| 1161 | SDValue Ops[] = { Result, LoadChain }; |
| 1162 | |
| 1163 | return DAG.getMergeValues(Ops, DL); |
| 1164 | } |
| 1165 | |
| 1166 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1167 | SDValue |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1168 | HexagonTargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) const { |
| 1169 | EVT ValTy = Op.getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1170 | SDLoc dl(Op); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1171 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
| 1172 | SDValue Res; |
| 1173 | if (CP->isMachineConstantPoolEntry()) |
| 1174 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), ValTy, |
| 1175 | CP->getAlignment()); |
| 1176 | else |
| 1177 | Res = DAG.getTargetConstantPool(CP->getConstVal(), ValTy, |
| 1178 | CP->getAlignment()); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1179 | return DAG.getNode(HexagonISD::CP, dl, ValTy, Res); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | SDValue |
| 1183 | HexagonTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1184 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1185 | MachineFunction &MF = DAG.getMachineFunction(); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1186 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
| 1187 | MFI.setReturnAddressIsTaken(true); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1188 | |
Bill Wendling | 908bf81 | 2014-01-06 00:43:20 +0000 | [diff] [blame] | 1189 | if (verifyReturnAddressArgumentIsConstant(Op, DAG)) |
Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 1190 | return SDValue(); |
Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 1191 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1192 | EVT VT = Op.getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1193 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1194 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 1195 | if (Depth) { |
| 1196 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1197 | SDValue Offset = DAG.getConstant(4, dl, MVT::i32); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1198 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 1199 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
| 1200 | MachinePointerInfo(), false, false, false, 0); |
| 1201 | } |
| 1202 | |
| 1203 | // Return LR, which contains the return address. Mark it an implicit live-in. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1204 | unsigned Reg = MF.addLiveIn(HRI.getRARegister(), getRegClassFor(MVT::i32)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1205 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 1206 | } |
| 1207 | |
| 1208 | SDValue |
| 1209 | HexagonTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1210 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
| 1211 | MachineFrameInfo &MFI = *DAG.getMachineFunction().getFrameInfo(); |
| 1212 | MFI.setFrameAddressIsTaken(true); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1213 | |
| 1214 | EVT VT = Op.getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1215 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1216 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 1217 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1218 | HRI.getFrameRegister(), VT); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1219 | while (Depth--) |
| 1220 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 1221 | MachinePointerInfo(), |
| 1222 | false, false, false, 0); |
| 1223 | return FrameAddr; |
| 1224 | } |
| 1225 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1226 | SDValue HexagonTargetLowering::LowerATOMIC_FENCE(SDValue Op, |
| 1227 | SelectionDAG& DAG) const { |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1228 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1229 | return DAG.getNode(HexagonISD::BARRIER, dl, MVT::Other, Op.getOperand(0)); |
| 1230 | } |
| 1231 | |
| 1232 | |
| 1233 | SDValue HexagonTargetLowering::LowerGLOBALADDRESS(SDValue Op, |
| 1234 | SelectionDAG &DAG) const { |
| 1235 | SDValue Result; |
| 1236 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| 1237 | int64_t Offset = cast<GlobalAddressSDNode>(Op)->getOffset(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1238 | SDLoc dl(Op); |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1239 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1240 | Result = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1241 | |
Eric Christopher | 36fe028 | 2015-02-03 07:22:52 +0000 | [diff] [blame] | 1242 | const HexagonTargetObjectFile *TLOF = |
| 1243 | static_cast<const HexagonTargetObjectFile *>( |
| 1244 | getTargetMachine().getObjFileLowering()); |
| 1245 | if (TLOF->IsGlobalInSmallSection(GV, getTargetMachine())) { |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1246 | return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, Result); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1249 | return DAG.getNode(HexagonISD::CONST32, dl, PtrVT, Result); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1252 | // Specifies that for loads and stores VT can be promoted to PromotedLdStVT. |
| 1253 | void HexagonTargetLowering::promoteLdStType(EVT VT, EVT PromotedLdStVT) { |
| 1254 | if (VT != PromotedLdStVT) { |
| 1255 | setOperationAction(ISD::LOAD, VT.getSimpleVT(), Promote); |
| 1256 | AddPromotedToType(ISD::LOAD, VT.getSimpleVT(), |
| 1257 | PromotedLdStVT.getSimpleVT()); |
| 1258 | |
| 1259 | setOperationAction(ISD::STORE, VT.getSimpleVT(), Promote); |
| 1260 | AddPromotedToType(ISD::STORE, VT.getSimpleVT(), |
| 1261 | PromotedLdStVT.getSimpleVT()); |
| 1262 | } |
| 1263 | } |
| 1264 | |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1265 | SDValue |
| 1266 | HexagonTargetLowering::LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const { |
| 1267 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
| 1268 | SDValue BA_SD = DAG.getTargetBlockAddress(BA, MVT::i32); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1269 | SDLoc dl(Op); |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1270 | return DAG.getNode(HexagonISD::CONST32_GP, dl, |
| 1271 | getPointerTy(DAG.getDataLayout()), BA_SD); |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1274 | //===----------------------------------------------------------------------===// |
| 1275 | // TargetLowering Implementation |
| 1276 | //===----------------------------------------------------------------------===// |
| 1277 | |
Eric Christopher | d737b76 | 2015-02-02 22:11:36 +0000 | [diff] [blame] | 1278 | HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM, |
| 1279 | const HexagonSubtarget &STI) |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1280 | : TargetLowering(TM), HTM(static_cast<const HexagonTargetMachine&>(TM)), |
| 1281 | Subtarget(STI) { |
| 1282 | bool IsV4 = !Subtarget.hasV5TOps(); |
| 1283 | auto &HRI = *Subtarget.getRegisterInfo(); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1284 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1285 | setPrefLoopAlignment(4); |
| 1286 | setPrefFunctionAlignment(4); |
| 1287 | setMinFunctionAlignment(2); |
| 1288 | setInsertFencesForAtomic(false); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1289 | setStackPointerRegisterToSaveRestore(HRI.getStackRegister()); |
| 1290 | |
| 1291 | if (EnableHexSDNodeSched) |
| 1292 | setSchedulingPreference(Sched::VLIW); |
| 1293 | else |
| 1294 | setSchedulingPreference(Sched::Source); |
| 1295 | |
| 1296 | // Limits for inline expansion of memcpy/memmove |
| 1297 | MaxStoresPerMemcpy = MaxStoresPerMemcpyCL; |
| 1298 | MaxStoresPerMemcpyOptSize = MaxStoresPerMemcpyOptSizeCL; |
| 1299 | MaxStoresPerMemmove = MaxStoresPerMemmoveCL; |
| 1300 | MaxStoresPerMemmoveOptSize = MaxStoresPerMemmoveOptSizeCL; |
| 1301 | MaxStoresPerMemset = MaxStoresPerMemsetCL; |
| 1302 | MaxStoresPerMemsetOptSize = MaxStoresPerMemsetOptSizeCL; |
| 1303 | |
| 1304 | // |
| 1305 | // Set up register classes. |
| 1306 | // |
| 1307 | |
| 1308 | addRegisterClass(MVT::i1, &Hexagon::PredRegsRegClass); |
| 1309 | addRegisterClass(MVT::v2i1, &Hexagon::PredRegsRegClass); // bbbbaaaa |
| 1310 | addRegisterClass(MVT::v4i1, &Hexagon::PredRegsRegClass); // ddccbbaa |
| 1311 | addRegisterClass(MVT::v8i1, &Hexagon::PredRegsRegClass); // hgfedcba |
| 1312 | addRegisterClass(MVT::i32, &Hexagon::IntRegsRegClass); |
| 1313 | addRegisterClass(MVT::v4i8, &Hexagon::IntRegsRegClass); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1314 | addRegisterClass(MVT::v2i16, &Hexagon::IntRegsRegClass); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1315 | addRegisterClass(MVT::i64, &Hexagon::DoubleRegsRegClass); |
| 1316 | addRegisterClass(MVT::v8i8, &Hexagon::DoubleRegsRegClass); |
| 1317 | addRegisterClass(MVT::v4i16, &Hexagon::DoubleRegsRegClass); |
| 1318 | addRegisterClass(MVT::v2i32, &Hexagon::DoubleRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1319 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1320 | if (Subtarget.hasV5TOps()) { |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1321 | addRegisterClass(MVT::f32, &Hexagon::IntRegsRegClass); |
| 1322 | addRegisterClass(MVT::f64, &Hexagon::DoubleRegsRegClass); |
| 1323 | } |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1324 | |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1325 | if (Subtarget.hasV60TOps()) { |
| 1326 | if (Subtarget.useHVXSglOps()) { |
| 1327 | addRegisterClass(MVT::v64i8, &Hexagon::VectorRegsRegClass); |
| 1328 | addRegisterClass(MVT::v32i16, &Hexagon::VectorRegsRegClass); |
| 1329 | addRegisterClass(MVT::v16i32, &Hexagon::VectorRegsRegClass); |
| 1330 | addRegisterClass(MVT::v8i64, &Hexagon::VectorRegsRegClass); |
| 1331 | addRegisterClass(MVT::v128i8, &Hexagon::VecDblRegsRegClass); |
| 1332 | addRegisterClass(MVT::v64i16, &Hexagon::VecDblRegsRegClass); |
| 1333 | addRegisterClass(MVT::v32i32, &Hexagon::VecDblRegsRegClass); |
| 1334 | addRegisterClass(MVT::v16i64, &Hexagon::VecDblRegsRegClass); |
| 1335 | addRegisterClass(MVT::v512i1, &Hexagon::VecPredRegsRegClass); |
| 1336 | } else if (Subtarget.useHVXDblOps()) { |
| 1337 | addRegisterClass(MVT::v128i8, &Hexagon::VectorRegs128BRegClass); |
| 1338 | addRegisterClass(MVT::v64i16, &Hexagon::VectorRegs128BRegClass); |
| 1339 | addRegisterClass(MVT::v32i32, &Hexagon::VectorRegs128BRegClass); |
| 1340 | addRegisterClass(MVT::v16i64, &Hexagon::VectorRegs128BRegClass); |
| 1341 | addRegisterClass(MVT::v256i8, &Hexagon::VecDblRegs128BRegClass); |
| 1342 | addRegisterClass(MVT::v128i16, &Hexagon::VecDblRegs128BRegClass); |
| 1343 | addRegisterClass(MVT::v64i32, &Hexagon::VecDblRegs128BRegClass); |
| 1344 | addRegisterClass(MVT::v32i64, &Hexagon::VecDblRegs128BRegClass); |
| 1345 | addRegisterClass(MVT::v1024i1, &Hexagon::VecPredRegs128BRegClass); |
| 1346 | } |
| 1347 | |
| 1348 | } |
| 1349 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1350 | // |
| 1351 | // Handling of scalar operations. |
| 1352 | // |
| 1353 | // All operations default to "legal", except: |
| 1354 | // - indexed loads and stores (pre-/post-incremented), |
| 1355 | // - ANY_EXTEND_VECTOR_INREG, ATOMIC_CMP_SWAP_WITH_SUCCESS, CONCAT_VECTORS, |
| 1356 | // ConstantFP, DEBUGTRAP, FCEIL, FCOPYSIGN, FEXP, FEXP2, FFLOOR, FGETSIGN, |
| 1357 | // FLOG, FLOG2, FLOG10, FMAXNUM, FMINNUM, FNEARBYINT, FRINT, FROUND, TRAP, |
| 1358 | // FTRUNC, PREFETCH, SIGN_EXTEND_VECTOR_INREG, ZERO_EXTEND_VECTOR_INREG, |
| 1359 | // which default to "expand" for at least one type. |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1360 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1361 | // Misc operations. |
| 1362 | setOperationAction(ISD::ConstantFP, MVT::f32, Legal); // Default: expand |
| 1363 | setOperationAction(ISD::ConstantFP, MVT::f64, Legal); // Default: expand |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1364 | |
| 1365 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1366 | setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1367 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
| 1368 | setOperationAction(ISD::INLINEASM, MVT::Other, Custom); |
| 1369 | setOperationAction(ISD::EH_RETURN, MVT::Other, Custom); |
| 1370 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1371 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1372 | // Custom legalize GlobalAddress nodes into CONST32. |
| 1373 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1374 | setOperationAction(ISD::GlobalAddress, MVT::i8, Custom); |
| 1375 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1376 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1377 | // Hexagon needs to optimize cases with negative constants. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1378 | setOperationAction(ISD::SETCC, MVT::i8, Custom); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1379 | setOperationAction(ISD::SETCC, MVT::i16, Custom); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1380 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1381 | // VASTART needs to be custom lowered to use the VarArgsFrameIndex. |
| 1382 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 1383 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 1384 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 1385 | |
| 1386 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 1387 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
| 1388 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom); |
| 1389 | |
| 1390 | if (EmitJumpTables) |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1391 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1392 | else |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1393 | setOperationAction(ISD::BR_JT, MVT::Other, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1394 | // Increase jump tables cutover to 5, was 4. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1395 | setMinimumJumpTableEntries(MinimumJumpTables); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1396 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1397 | // Hexagon has instructions for add/sub with carry. The problem with |
| 1398 | // modeling these instructions is that they produce 2 results: Rdd and Px. |
| 1399 | // To model the update of Px, we will have to use Defs[p0..p3] which will |
| 1400 | // cause any predicate live range to spill. So, we pretend we dont't have |
| 1401 | // these instructions. |
| 1402 | setOperationAction(ISD::ADDE, MVT::i8, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1403 | setOperationAction(ISD::ADDE, MVT::i16, Expand); |
| 1404 | setOperationAction(ISD::ADDE, MVT::i32, Expand); |
| 1405 | setOperationAction(ISD::ADDE, MVT::i64, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1406 | setOperationAction(ISD::SUBE, MVT::i8, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1407 | setOperationAction(ISD::SUBE, MVT::i16, Expand); |
| 1408 | setOperationAction(ISD::SUBE, MVT::i32, Expand); |
| 1409 | setOperationAction(ISD::SUBE, MVT::i64, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1410 | setOperationAction(ISD::ADDC, MVT::i8, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1411 | setOperationAction(ISD::ADDC, MVT::i16, Expand); |
| 1412 | setOperationAction(ISD::ADDC, MVT::i32, Expand); |
| 1413 | setOperationAction(ISD::ADDC, MVT::i64, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1414 | setOperationAction(ISD::SUBC, MVT::i8, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1415 | setOperationAction(ISD::SUBC, MVT::i16, Expand); |
| 1416 | setOperationAction(ISD::SUBC, MVT::i32, Expand); |
| 1417 | setOperationAction(ISD::SUBC, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1418 | |
Krzysztof Parzyszek | 2c4487d | 2015-04-13 20:37:01 +0000 | [diff] [blame] | 1419 | // Only add and sub that detect overflow are the saturating ones. |
| 1420 | for (MVT VT : MVT::integer_valuetypes()) { |
| 1421 | setOperationAction(ISD::UADDO, VT, Expand); |
| 1422 | setOperationAction(ISD::SADDO, VT, Expand); |
| 1423 | setOperationAction(ISD::USUBO, VT, Expand); |
| 1424 | setOperationAction(ISD::SSUBO, VT, Expand); |
| 1425 | } |
| 1426 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1427 | setOperationAction(ISD::CTLZ, MVT::i8, Promote); |
| 1428 | setOperationAction(ISD::CTLZ, MVT::i16, Promote); |
| 1429 | setOperationAction(ISD::CTTZ, MVT::i8, Promote); |
| 1430 | setOperationAction(ISD::CTTZ, MVT::i16, Promote); |
| 1431 | setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i8, Promote); |
| 1432 | setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i16, Promote); |
| 1433 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i8, Promote); |
| 1434 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i16, Promote); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1435 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1436 | // In V5, popcount can count # of 1s in i64 but returns i32. |
| 1437 | // On V4 it will be expanded (set later). |
| 1438 | setOperationAction(ISD::CTPOP, MVT::i8, Promote); |
| 1439 | setOperationAction(ISD::CTPOP, MVT::i16, Promote); |
| 1440 | setOperationAction(ISD::CTPOP, MVT::i32, Promote); |
| 1441 | setOperationAction(ISD::CTPOP, MVT::i64, Custom); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1442 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1443 | // We custom lower i64 to i64 mul, so that it is not considered as a legal |
| 1444 | // operation. There is a pattern that will match i64 mul and transform it |
| 1445 | // to a series of instructions. |
| 1446 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
Colin LeMahieu | de68b66 | 2015-02-05 21:13:25 +0000 | [diff] [blame] | 1447 | setOperationAction(ISD::MULHS, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1448 | |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1449 | for (unsigned IntExpOp : |
| 1450 | {ISD::SDIV, ISD::UDIV, ISD::SREM, ISD::UREM, ISD::SDIVREM, ISD::UDIVREM, |
| 1451 | ISD::ROTL, ISD::ROTR, ISD::BSWAP, ISD::SHL_PARTS, ISD::SRA_PARTS, |
| 1452 | ISD::SRL_PARTS, ISD::SMUL_LOHI, ISD::UMUL_LOHI}) { |
| 1453 | setOperationAction(IntExpOp, MVT::i32, Expand); |
| 1454 | setOperationAction(IntExpOp, MVT::i64, Expand); |
| 1455 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1456 | |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1457 | for (unsigned FPExpOp : |
| 1458 | {ISD::FDIV, ISD::FREM, ISD::FSQRT, ISD::FSIN, ISD::FCOS, ISD::FSINCOS, |
| 1459 | ISD::FPOW, ISD::FCOPYSIGN}) { |
| 1460 | setOperationAction(FPExpOp, MVT::f32, Expand); |
| 1461 | setOperationAction(FPExpOp, MVT::f64, Expand); |
| 1462 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1463 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1464 | // No extending loads from i32. |
| 1465 | for (MVT VT : MVT::integer_valuetypes()) { |
| 1466 | setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i32, Expand); |
| 1467 | setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i32, Expand); |
| 1468 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::i32, Expand); |
| 1469 | } |
| 1470 | // Turn FP truncstore into trunc + store. |
| 1471 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
| 1472 | // Turn FP extload into load/fextend. |
| 1473 | for (MVT VT : MVT::fp_valuetypes()) |
| 1474 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1475 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1476 | // Expand BR_CC and SELECT_CC for all integer and fp types. |
| 1477 | for (MVT VT : MVT::integer_valuetypes()) { |
| 1478 | setOperationAction(ISD::BR_CC, VT, Expand); |
| 1479 | setOperationAction(ISD::SELECT_CC, VT, Expand); |
| 1480 | } |
| 1481 | for (MVT VT : MVT::fp_valuetypes()) { |
| 1482 | setOperationAction(ISD::BR_CC, VT, Expand); |
| 1483 | setOperationAction(ISD::SELECT_CC, VT, Expand); |
| 1484 | } |
| 1485 | setOperationAction(ISD::BR_CC, MVT::Other, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1486 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1487 | // |
| 1488 | // Handling of vector operations. |
| 1489 | // |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1490 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1491 | // Custom lower v4i16 load only. Let v4i16 store to be |
| 1492 | // promoted for now. |
| 1493 | promoteLdStType(MVT::v4i8, MVT::i32); |
| 1494 | promoteLdStType(MVT::v2i16, MVT::i32); |
| 1495 | promoteLdStType(MVT::v8i8, MVT::i64); |
| 1496 | promoteLdStType(MVT::v2i32, MVT::i64); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1497 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1498 | setOperationAction(ISD::LOAD, MVT::v4i16, Custom); |
| 1499 | setOperationAction(ISD::STORE, MVT::v4i16, Promote); |
| 1500 | AddPromotedToType(ISD::LOAD, MVT::v4i16, MVT::i64); |
| 1501 | AddPromotedToType(ISD::STORE, MVT::v4i16, MVT::i64); |
| 1502 | |
| 1503 | // Set the action for vector operations to "expand", then override it with |
| 1504 | // either "custom" or "legal" for specific cases. |
Craig Topper | 2626094 | 2015-10-18 05:15:34 +0000 | [diff] [blame] | 1505 | static const unsigned VectExpOps[] = { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1506 | // Integer arithmetic: |
| 1507 | ISD::ADD, ISD::SUB, ISD::MUL, ISD::SDIV, ISD::UDIV, |
| 1508 | ISD::SREM, ISD::UREM, ISD::SDIVREM, ISD::UDIVREM, ISD::ADDC, |
| 1509 | ISD::SUBC, ISD::SADDO, ISD::UADDO, ISD::SSUBO, ISD::USUBO, |
| 1510 | ISD::SMUL_LOHI, ISD::UMUL_LOHI, |
| 1511 | // Logical/bit: |
| 1512 | ISD::AND, ISD::OR, ISD::XOR, ISD::ROTL, ISD::ROTR, |
| 1513 | ISD::CTPOP, ISD::CTLZ, ISD::CTTZ, ISD::CTLZ_ZERO_UNDEF, |
| 1514 | ISD::CTTZ_ZERO_UNDEF, |
| 1515 | // Floating point arithmetic/math functions: |
| 1516 | ISD::FADD, ISD::FSUB, ISD::FMUL, ISD::FMA, ISD::FDIV, |
| 1517 | ISD::FREM, ISD::FNEG, ISD::FABS, ISD::FSQRT, ISD::FSIN, |
| 1518 | ISD::FCOS, ISD::FPOWI, ISD::FPOW, ISD::FLOG, ISD::FLOG2, |
| 1519 | ISD::FLOG10, ISD::FEXP, ISD::FEXP2, ISD::FCEIL, ISD::FTRUNC, |
| 1520 | ISD::FRINT, ISD::FNEARBYINT, ISD::FROUND, ISD::FFLOOR, |
| 1521 | ISD::FMINNUM, ISD::FMAXNUM, ISD::FSINCOS, |
| 1522 | // Misc: |
| 1523 | ISD::SELECT, ISD::ConstantPool, |
| 1524 | // Vector: |
| 1525 | ISD::BUILD_VECTOR, ISD::SCALAR_TO_VECTOR, |
| 1526 | ISD::EXTRACT_VECTOR_ELT, ISD::INSERT_VECTOR_ELT, |
| 1527 | ISD::EXTRACT_SUBVECTOR, ISD::INSERT_SUBVECTOR, |
| 1528 | ISD::CONCAT_VECTORS, ISD::VECTOR_SHUFFLE |
| 1529 | }; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1530 | |
| 1531 | for (MVT VT : MVT::vector_valuetypes()) { |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1532 | for (unsigned VectExpOp : VectExpOps) |
| 1533 | setOperationAction(VectExpOp, VT, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1534 | |
| 1535 | // Expand all extended loads and truncating stores: |
| 1536 | for (MVT TargetVT : MVT::vector_valuetypes()) { |
| 1537 | setLoadExtAction(ISD::EXTLOAD, TargetVT, VT, Expand); |
| 1538 | setTruncStoreAction(VT, TargetVT, Expand); |
| 1539 | } |
| 1540 | |
| 1541 | setOperationAction(ISD::SRA, VT, Custom); |
| 1542 | setOperationAction(ISD::SHL, VT, Custom); |
| 1543 | setOperationAction(ISD::SRL, VT, Custom); |
| 1544 | } |
| 1545 | |
| 1546 | // Types natively supported: |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1547 | for (MVT NativeVT : {MVT::v2i1, MVT::v4i1, MVT::v8i1, MVT::v32i1, MVT::v64i1, |
| 1548 | MVT::v4i8, MVT::v8i8, MVT::v2i16, MVT::v4i16, MVT::v1i32, |
| 1549 | MVT::v2i32, MVT::v1i64}) { |
| 1550 | setOperationAction(ISD::BUILD_VECTOR, NativeVT, Custom); |
| 1551 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, NativeVT, Custom); |
| 1552 | setOperationAction(ISD::INSERT_VECTOR_ELT, NativeVT, Custom); |
| 1553 | setOperationAction(ISD::EXTRACT_SUBVECTOR, NativeVT, Custom); |
| 1554 | setOperationAction(ISD::INSERT_SUBVECTOR, NativeVT, Custom); |
| 1555 | setOperationAction(ISD::CONCAT_VECTORS, NativeVT, Custom); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1556 | |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1557 | setOperationAction(ISD::ADD, NativeVT, Legal); |
| 1558 | setOperationAction(ISD::SUB, NativeVT, Legal); |
| 1559 | setOperationAction(ISD::MUL, NativeVT, Legal); |
| 1560 | setOperationAction(ISD::AND, NativeVT, Legal); |
| 1561 | setOperationAction(ISD::OR, NativeVT, Legal); |
| 1562 | setOperationAction(ISD::XOR, NativeVT, Legal); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | setOperationAction(ISD::SETCC, MVT::v2i16, Custom); |
| 1566 | setOperationAction(ISD::VSELECT, MVT::v2i16, Custom); |
| 1567 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v4i16, Custom); |
| 1568 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v8i8, Custom); |
| 1569 | |
| 1570 | // Subtarget-specific operation actions. |
| 1571 | // |
| 1572 | if (Subtarget.hasV5TOps()) { |
| 1573 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 1574 | setOperationAction(ISD::FADD, MVT::f64, Expand); |
| 1575 | setOperationAction(ISD::FSUB, MVT::f64, Expand); |
| 1576 | setOperationAction(ISD::FMUL, MVT::f64, Expand); |
| 1577 | |
| 1578 | setOperationAction(ISD::FP_TO_UINT, MVT::i1, Promote); |
| 1579 | setOperationAction(ISD::FP_TO_UINT, MVT::i8, Promote); |
| 1580 | setOperationAction(ISD::FP_TO_UINT, MVT::i16, Promote); |
| 1581 | setOperationAction(ISD::FP_TO_SINT, MVT::i1, Promote); |
| 1582 | setOperationAction(ISD::FP_TO_SINT, MVT::i8, Promote); |
| 1583 | setOperationAction(ISD::FP_TO_SINT, MVT::i16, Promote); |
| 1584 | setOperationAction(ISD::UINT_TO_FP, MVT::i1, Promote); |
| 1585 | setOperationAction(ISD::UINT_TO_FP, MVT::i8, Promote); |
| 1586 | setOperationAction(ISD::UINT_TO_FP, MVT::i16, Promote); |
| 1587 | setOperationAction(ISD::SINT_TO_FP, MVT::i1, Promote); |
| 1588 | setOperationAction(ISD::SINT_TO_FP, MVT::i8, Promote); |
| 1589 | setOperationAction(ISD::SINT_TO_FP, MVT::i16, Promote); |
| 1590 | |
| 1591 | } else { // V4 |
| 1592 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Expand); |
| 1593 | setOperationAction(ISD::SINT_TO_FP, MVT::i64, Expand); |
| 1594 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand); |
| 1595 | setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand); |
| 1596 | setOperationAction(ISD::FP_TO_SINT, MVT::f64, Expand); |
| 1597 | setOperationAction(ISD::FP_TO_SINT, MVT::f32, Expand); |
| 1598 | setOperationAction(ISD::FP_EXTEND, MVT::f32, Expand); |
| 1599 | setOperationAction(ISD::FP_ROUND, MVT::f64, Expand); |
| 1600 | setCondCodeAction(ISD::SETUNE, MVT::f64, Expand); |
| 1601 | |
| 1602 | setOperationAction(ISD::CTPOP, MVT::i8, Expand); |
| 1603 | setOperationAction(ISD::CTPOP, MVT::i16, Expand); |
| 1604 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
| 1605 | setOperationAction(ISD::CTPOP, MVT::i64, Expand); |
| 1606 | |
| 1607 | // Expand these operations for both f32 and f64: |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1608 | for (unsigned FPExpOpV4 : |
| 1609 | {ISD::FADD, ISD::FSUB, ISD::FMUL, ISD::FABS, ISD::FNEG, ISD::FMA}) { |
| 1610 | setOperationAction(FPExpOpV4, MVT::f32, Expand); |
| 1611 | setOperationAction(FPExpOpV4, MVT::f64, Expand); |
| 1612 | } |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1613 | |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1614 | for (ISD::CondCode FPExpCCV4 : |
| 1615 | {ISD::SETOEQ, ISD::SETOGT, ISD::SETOLT, ISD::SETOGE, ISD::SETOLE, |
| 1616 | ISD::SETUO, ISD::SETO}) { |
| 1617 | setCondCodeAction(FPExpCCV4, MVT::f32, Expand); |
| 1618 | setCondCodeAction(FPExpCCV4, MVT::f64, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | // Handling of indexed loads/stores: default is "expand". |
| 1623 | // |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1624 | for (MVT LSXTy : {MVT::i8, MVT::i16, MVT::i32, MVT::i64}) { |
| 1625 | setIndexedLoadAction(ISD::POST_INC, LSXTy, Legal); |
| 1626 | setIndexedStoreAction(ISD::POST_INC, LSXTy, Legal); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | computeRegisterProperties(&HRI); |
| 1630 | |
| 1631 | // |
| 1632 | // Library calls for unsupported operations |
| 1633 | // |
| 1634 | bool FastMath = EnableFastMath; |
| 1635 | |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1636 | setLibcallName(RTLIB::SDIV_I32, "__hexagon_divsi3"); |
| 1637 | setLibcallName(RTLIB::SDIV_I64, "__hexagon_divdi3"); |
| 1638 | setLibcallName(RTLIB::UDIV_I32, "__hexagon_udivsi3"); |
| 1639 | setLibcallName(RTLIB::UDIV_I64, "__hexagon_udivdi3"); |
| 1640 | setLibcallName(RTLIB::SREM_I32, "__hexagon_modsi3"); |
| 1641 | setLibcallName(RTLIB::SREM_I64, "__hexagon_moddi3"); |
| 1642 | setLibcallName(RTLIB::UREM_I32, "__hexagon_umodsi3"); |
| 1643 | setLibcallName(RTLIB::UREM_I64, "__hexagon_umoddi3"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1644 | |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1645 | setLibcallName(RTLIB::SINTTOFP_I128_F64, "__hexagon_floattidf"); |
| 1646 | setLibcallName(RTLIB::SINTTOFP_I128_F32, "__hexagon_floattisf"); |
| 1647 | setLibcallName(RTLIB::FPTOUINT_F32_I128, "__hexagon_fixunssfti"); |
| 1648 | setLibcallName(RTLIB::FPTOUINT_F64_I128, "__hexagon_fixunsdfti"); |
| 1649 | setLibcallName(RTLIB::FPTOSINT_F32_I128, "__hexagon_fixsfti"); |
| 1650 | setLibcallName(RTLIB::FPTOSINT_F64_I128, "__hexagon_fixdfti"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1651 | |
| 1652 | if (IsV4) { |
| 1653 | // Handle single-precision floating point operations on V4. |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1654 | if (FastMath) { |
| 1655 | setLibcallName(RTLIB::ADD_F32, "__hexagon_fast_addsf3"); |
| 1656 | setLibcallName(RTLIB::SUB_F32, "__hexagon_fast_subsf3"); |
| 1657 | setLibcallName(RTLIB::MUL_F32, "__hexagon_fast_mulsf3"); |
| 1658 | setLibcallName(RTLIB::OGT_F32, "__hexagon_fast_gtsf2"); |
| 1659 | setLibcallName(RTLIB::OLT_F32, "__hexagon_fast_ltsf2"); |
| 1660 | // Double-precision compares. |
| 1661 | setLibcallName(RTLIB::OGT_F64, "__hexagon_fast_gtdf2"); |
| 1662 | setLibcallName(RTLIB::OLT_F64, "__hexagon_fast_ltdf2"); |
| 1663 | } else { |
| 1664 | setLibcallName(RTLIB::ADD_F32, "__hexagon_addsf3"); |
| 1665 | setLibcallName(RTLIB::SUB_F32, "__hexagon_subsf3"); |
| 1666 | setLibcallName(RTLIB::MUL_F32, "__hexagon_mulsf3"); |
| 1667 | setLibcallName(RTLIB::OGT_F32, "__hexagon_gtsf2"); |
| 1668 | setLibcallName(RTLIB::OLT_F32, "__hexagon_ltsf2"); |
| 1669 | // Double-precision compares. |
| 1670 | setLibcallName(RTLIB::OGT_F64, "__hexagon_gtdf2"); |
| 1671 | setLibcallName(RTLIB::OLT_F64, "__hexagon_ltdf2"); |
| 1672 | } |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | // This is the only fast library function for sqrtd. |
| 1676 | if (FastMath) |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1677 | setLibcallName(RTLIB::SQRT_F64, "__hexagon_fast2_sqrtdf2"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1678 | |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1679 | // Prefix is: nothing for "slow-math", |
| 1680 | // "fast2_" for V4 fast-math and V5+ fast-math double-precision |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1681 | // (actually, keep fast-math and fast-math2 separate for now) |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1682 | if (FastMath) { |
| 1683 | setLibcallName(RTLIB::ADD_F64, "__hexagon_fast_adddf3"); |
| 1684 | setLibcallName(RTLIB::SUB_F64, "__hexagon_fast_subdf3"); |
| 1685 | setLibcallName(RTLIB::MUL_F64, "__hexagon_fast_muldf3"); |
| 1686 | setLibcallName(RTLIB::DIV_F64, "__hexagon_fast_divdf3"); |
| 1687 | // Calling __hexagon_fast2_divsf3 with fast-math on V5 (ok). |
| 1688 | setLibcallName(RTLIB::DIV_F32, "__hexagon_fast_divsf3"); |
| 1689 | } else { |
| 1690 | setLibcallName(RTLIB::ADD_F64, "__hexagon_adddf3"); |
| 1691 | setLibcallName(RTLIB::SUB_F64, "__hexagon_subdf3"); |
| 1692 | setLibcallName(RTLIB::MUL_F64, "__hexagon_muldf3"); |
| 1693 | setLibcallName(RTLIB::DIV_F64, "__hexagon_divdf3"); |
| 1694 | setLibcallName(RTLIB::DIV_F32, "__hexagon_divsf3"); |
| 1695 | } |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1696 | |
| 1697 | if (Subtarget.hasV5TOps()) { |
| 1698 | if (FastMath) |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1699 | setLibcallName(RTLIB::SQRT_F32, "__hexagon_fast2_sqrtf"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1700 | else |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1701 | setLibcallName(RTLIB::SQRT_F32, "__hexagon_sqrtf"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1702 | } else { |
| 1703 | // V4 |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1704 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__hexagon_floatsisf"); |
| 1705 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__hexagon_floatsidf"); |
| 1706 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__hexagon_floatdisf"); |
| 1707 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__hexagon_floatdidf"); |
| 1708 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__hexagon_floatunsisf"); |
| 1709 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__hexagon_floatunsidf"); |
| 1710 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__hexagon_floatundisf"); |
| 1711 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__hexagon_floatundidf"); |
| 1712 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__hexagon_fixunssfsi"); |
| 1713 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__hexagon_fixunssfdi"); |
| 1714 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__hexagon_fixunsdfsi"); |
| 1715 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__hexagon_fixunsdfdi"); |
| 1716 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__hexagon_fixsfsi"); |
| 1717 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__hexagon_fixsfdi"); |
| 1718 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__hexagon_fixdfsi"); |
| 1719 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__hexagon_fixdfdi"); |
| 1720 | setLibcallName(RTLIB::FPEXT_F32_F64, "__hexagon_extendsfdf2"); |
| 1721 | setLibcallName(RTLIB::FPROUND_F64_F32, "__hexagon_truncdfsf2"); |
| 1722 | setLibcallName(RTLIB::OEQ_F32, "__hexagon_eqsf2"); |
| 1723 | setLibcallName(RTLIB::OEQ_F64, "__hexagon_eqdf2"); |
| 1724 | setLibcallName(RTLIB::OGE_F32, "__hexagon_gesf2"); |
| 1725 | setLibcallName(RTLIB::OGE_F64, "__hexagon_gedf2"); |
| 1726 | setLibcallName(RTLIB::OLE_F32, "__hexagon_lesf2"); |
| 1727 | setLibcallName(RTLIB::OLE_F64, "__hexagon_ledf2"); |
| 1728 | setLibcallName(RTLIB::UNE_F32, "__hexagon_nesf2"); |
| 1729 | setLibcallName(RTLIB::UNE_F64, "__hexagon_nedf2"); |
| 1730 | setLibcallName(RTLIB::UO_F32, "__hexagon_unordsf2"); |
| 1731 | setLibcallName(RTLIB::UO_F64, "__hexagon_unorddf2"); |
| 1732 | setLibcallName(RTLIB::O_F32, "__hexagon_unordsf2"); |
| 1733 | setLibcallName(RTLIB::O_F64, "__hexagon_unorddf2"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | // These cause problems when the shift amount is non-constant. |
| 1737 | setLibcallName(RTLIB::SHL_I128, nullptr); |
| 1738 | setLibcallName(RTLIB::SRL_I128, nullptr); |
| 1739 | setLibcallName(RTLIB::SRA_I128, nullptr); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1742 | |
| 1743 | const char* HexagonTargetLowering::getTargetNodeName(unsigned Opcode) const { |
Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1744 | switch ((HexagonISD::NodeType)Opcode) { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1745 | case HexagonISD::ALLOCA: return "HexagonISD::ALLOCA"; |
| 1746 | case HexagonISD::ARGEXTEND: return "HexagonISD::ARGEXTEND"; |
| 1747 | case HexagonISD::AT_GOT: return "HexagonISD::AT_GOT"; |
| 1748 | case HexagonISD::AT_PCREL: return "HexagonISD::AT_PCREL"; |
| 1749 | case HexagonISD::BARRIER: return "HexagonISD::BARRIER"; |
| 1750 | case HexagonISD::BR_JT: return "HexagonISD::BR_JT"; |
| 1751 | case HexagonISD::CALLR: return "HexagonISD::CALLR"; |
| 1752 | case HexagonISD::CALLv3nr: return "HexagonISD::CALLv3nr"; |
| 1753 | case HexagonISD::CALLv3: return "HexagonISD::CALLv3"; |
| 1754 | case HexagonISD::COMBINE: return "HexagonISD::COMBINE"; |
| 1755 | case HexagonISD::CONST32_GP: return "HexagonISD::CONST32_GP"; |
| 1756 | case HexagonISD::CONST32: return "HexagonISD::CONST32"; |
| 1757 | case HexagonISD::CP: return "HexagonISD::CP"; |
| 1758 | case HexagonISD::DCFETCH: return "HexagonISD::DCFETCH"; |
| 1759 | case HexagonISD::EH_RETURN: return "HexagonISD::EH_RETURN"; |
| 1760 | case HexagonISD::EXTRACTU: return "HexagonISD::EXTRACTU"; |
| 1761 | case HexagonISD::EXTRACTURP: return "HexagonISD::EXTRACTURP"; |
| 1762 | case HexagonISD::FCONST32: return "HexagonISD::FCONST32"; |
| 1763 | case HexagonISD::INSERT: return "HexagonISD::INSERT"; |
| 1764 | case HexagonISD::INSERTRP: return "HexagonISD::INSERTRP"; |
| 1765 | case HexagonISD::JT: return "HexagonISD::JT"; |
| 1766 | case HexagonISD::PACKHL: return "HexagonISD::PACKHL"; |
| 1767 | case HexagonISD::PIC_ADD: return "HexagonISD::PIC_ADD"; |
| 1768 | case HexagonISD::POPCOUNT: return "HexagonISD::POPCOUNT"; |
| 1769 | case HexagonISD::RET_FLAG: return "HexagonISD::RET_FLAG"; |
| 1770 | case HexagonISD::SHUFFEB: return "HexagonISD::SHUFFEB"; |
| 1771 | case HexagonISD::SHUFFEH: return "HexagonISD::SHUFFEH"; |
| 1772 | case HexagonISD::SHUFFOB: return "HexagonISD::SHUFFOB"; |
| 1773 | case HexagonISD::SHUFFOH: return "HexagonISD::SHUFFOH"; |
| 1774 | case HexagonISD::TC_RETURN: return "HexagonISD::TC_RETURN"; |
| 1775 | case HexagonISD::VCMPBEQ: return "HexagonISD::VCMPBEQ"; |
| 1776 | case HexagonISD::VCMPBGT: return "HexagonISD::VCMPBGT"; |
| 1777 | case HexagonISD::VCMPBGTU: return "HexagonISD::VCMPBGTU"; |
| 1778 | case HexagonISD::VCMPHEQ: return "HexagonISD::VCMPHEQ"; |
| 1779 | case HexagonISD::VCMPHGT: return "HexagonISD::VCMPHGT"; |
| 1780 | case HexagonISD::VCMPHGTU: return "HexagonISD::VCMPHGTU"; |
| 1781 | case HexagonISD::VCMPWEQ: return "HexagonISD::VCMPWEQ"; |
| 1782 | case HexagonISD::VCMPWGT: return "HexagonISD::VCMPWGT"; |
| 1783 | case HexagonISD::VCMPWGTU: return "HexagonISD::VCMPWGTU"; |
| 1784 | case HexagonISD::VSHLH: return "HexagonISD::VSHLH"; |
| 1785 | case HexagonISD::VSHLW: return "HexagonISD::VSHLW"; |
| 1786 | case HexagonISD::VSPLATB: return "HexagonISD::VSPLTB"; |
| 1787 | case HexagonISD::VSPLATH: return "HexagonISD::VSPLATH"; |
| 1788 | case HexagonISD::VSRAH: return "HexagonISD::VSRAH"; |
| 1789 | case HexagonISD::VSRAW: return "HexagonISD::VSRAW"; |
| 1790 | case HexagonISD::VSRLH: return "HexagonISD::VSRLH"; |
| 1791 | case HexagonISD::VSRLW: return "HexagonISD::VSRLW"; |
| 1792 | case HexagonISD::VSXTBH: return "HexagonISD::VSXTBH"; |
| 1793 | case HexagonISD::VSXTBW: return "HexagonISD::VSXTBW"; |
Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1794 | case HexagonISD::OP_END: break; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1795 | } |
Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1796 | return nullptr; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1799 | bool HexagonTargetLowering::isTruncateFree(Type *Ty1, Type *Ty2) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1800 | EVT MTy1 = EVT::getEVT(Ty1); |
| 1801 | EVT MTy2 = EVT::getEVT(Ty2); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1802 | if (!MTy1.isSimple() || !MTy2.isSimple()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1803 | return false; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1804 | return (MTy1.getSimpleVT() == MVT::i64) && (MTy2.getSimpleVT() == MVT::i32); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | bool HexagonTargetLowering::isTruncateFree(EVT VT1, EVT VT2) const { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1808 | if (!VT1.isSimple() || !VT2.isSimple()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1809 | return false; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1810 | return (VT1.getSimpleVT() == MVT::i64) && (VT2.getSimpleVT() == MVT::i32); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1813 | // shouldExpandBuildVectorWithShuffles |
| 1814 | // Should we expand the build vector with shuffles? |
| 1815 | bool |
| 1816 | HexagonTargetLowering::shouldExpandBuildVectorWithShuffles(EVT VT, |
| 1817 | unsigned DefinedValues) const { |
| 1818 | |
| 1819 | // Hexagon vector shuffle operates on element sizes of bytes or halfwords |
| 1820 | EVT EltVT = VT.getVectorElementType(); |
| 1821 | int EltBits = EltVT.getSizeInBits(); |
| 1822 | if ((EltBits != 8) && (EltBits != 16)) |
| 1823 | return false; |
| 1824 | |
| 1825 | return TargetLowering::shouldExpandBuildVectorWithShuffles(VT, DefinedValues); |
| 1826 | } |
| 1827 | |
| 1828 | // LowerVECTOR_SHUFFLE - Lower a vector shuffle (V1, V2, V3). V1 and |
| 1829 | // V2 are the two vectors to select data from, V3 is the permutation. |
| 1830 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
| 1831 | const ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op); |
| 1832 | SDValue V1 = Op.getOperand(0); |
| 1833 | SDValue V2 = Op.getOperand(1); |
| 1834 | SDLoc dl(Op); |
| 1835 | EVT VT = Op.getValueType(); |
| 1836 | |
| 1837 | if (V2.getOpcode() == ISD::UNDEF) |
| 1838 | V2 = V1; |
| 1839 | |
| 1840 | if (SVN->isSplat()) { |
| 1841 | int Lane = SVN->getSplatIndex(); |
| 1842 | if (Lane == -1) Lane = 0; |
| 1843 | |
| 1844 | // Test if V1 is a SCALAR_TO_VECTOR. |
| 1845 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) |
| 1846 | return createSplat(DAG, dl, VT, V1.getOperand(0)); |
| 1847 | |
| 1848 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
| 1849 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization |
| 1850 | // reaches it). |
| 1851 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && |
| 1852 | !isa<ConstantSDNode>(V1.getOperand(0))) { |
| 1853 | bool IsScalarToVector = true; |
| 1854 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) |
| 1855 | if (V1.getOperand(i).getOpcode() != ISD::UNDEF) { |
| 1856 | IsScalarToVector = false; |
| 1857 | break; |
| 1858 | } |
| 1859 | if (IsScalarToVector) |
| 1860 | return createSplat(DAG, dl, VT, V1.getOperand(0)); |
| 1861 | } |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1862 | return createSplat(DAG, dl, VT, DAG.getConstant(Lane, dl, MVT::i32)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | // FIXME: We need to support more general vector shuffles. See |
| 1866 | // below the comment from the ARM backend that deals in the general |
| 1867 | // case with the vector shuffles. For now, let expand handle these. |
| 1868 | return SDValue(); |
| 1869 | |
| 1870 | // If the shuffle is not directly supported and it has 4 elements, use |
| 1871 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
| 1872 | } |
| 1873 | |
| 1874 | // If BUILD_VECTOR has same base element repeated several times, |
| 1875 | // report true. |
| 1876 | static bool isCommonSplatElement(BuildVectorSDNode *BVN) { |
| 1877 | unsigned NElts = BVN->getNumOperands(); |
| 1878 | SDValue V0 = BVN->getOperand(0); |
| 1879 | |
| 1880 | for (unsigned i = 1, e = NElts; i != e; ++i) { |
| 1881 | if (BVN->getOperand(i) != V0) |
| 1882 | return false; |
| 1883 | } |
| 1884 | return true; |
| 1885 | } |
| 1886 | |
| 1887 | // LowerVECTOR_SHIFT - Lower a vector shift. Try to convert |
| 1888 | // <VT> = SHL/SRA/SRL <VT> by <VT> to Hexagon specific |
| 1889 | // <VT> = SHL/SRA/SRL <VT> by <IT/i32>. |
| 1890 | static SDValue LowerVECTOR_SHIFT(SDValue Op, SelectionDAG &DAG) { |
| 1891 | BuildVectorSDNode *BVN = 0; |
| 1892 | SDValue V1 = Op.getOperand(0); |
| 1893 | SDValue V2 = Op.getOperand(1); |
| 1894 | SDValue V3; |
| 1895 | SDLoc dl(Op); |
| 1896 | EVT VT = Op.getValueType(); |
| 1897 | |
| 1898 | if ((BVN = dyn_cast<BuildVectorSDNode>(V1.getNode())) && |
| 1899 | isCommonSplatElement(BVN)) |
| 1900 | V3 = V2; |
| 1901 | else if ((BVN = dyn_cast<BuildVectorSDNode>(V2.getNode())) && |
| 1902 | isCommonSplatElement(BVN)) |
| 1903 | V3 = V1; |
| 1904 | else |
| 1905 | return SDValue(); |
| 1906 | |
| 1907 | SDValue CommonSplat = BVN->getOperand(0); |
| 1908 | SDValue Result; |
| 1909 | |
| 1910 | if (VT.getSimpleVT() == MVT::v4i16) { |
| 1911 | switch (Op.getOpcode()) { |
| 1912 | case ISD::SRA: |
| 1913 | Result = DAG.getNode(HexagonISD::VSRAH, dl, VT, V3, CommonSplat); |
| 1914 | break; |
| 1915 | case ISD::SHL: |
| 1916 | Result = DAG.getNode(HexagonISD::VSHLH, dl, VT, V3, CommonSplat); |
| 1917 | break; |
| 1918 | case ISD::SRL: |
| 1919 | Result = DAG.getNode(HexagonISD::VSRLH, dl, VT, V3, CommonSplat); |
| 1920 | break; |
| 1921 | default: |
| 1922 | return SDValue(); |
| 1923 | } |
| 1924 | } else if (VT.getSimpleVT() == MVT::v2i32) { |
| 1925 | switch (Op.getOpcode()) { |
| 1926 | case ISD::SRA: |
| 1927 | Result = DAG.getNode(HexagonISD::VSRAW, dl, VT, V3, CommonSplat); |
| 1928 | break; |
| 1929 | case ISD::SHL: |
| 1930 | Result = DAG.getNode(HexagonISD::VSHLW, dl, VT, V3, CommonSplat); |
| 1931 | break; |
| 1932 | case ISD::SRL: |
| 1933 | Result = DAG.getNode(HexagonISD::VSRLW, dl, VT, V3, CommonSplat); |
| 1934 | break; |
| 1935 | default: |
| 1936 | return SDValue(); |
| 1937 | } |
| 1938 | } else { |
| 1939 | return SDValue(); |
| 1940 | } |
| 1941 | |
| 1942 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 1943 | } |
| 1944 | |
| 1945 | SDValue |
| 1946 | HexagonTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const { |
| 1947 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
| 1948 | SDLoc dl(Op); |
| 1949 | EVT VT = Op.getValueType(); |
| 1950 | |
| 1951 | unsigned Size = VT.getSizeInBits(); |
| 1952 | |
| 1953 | // A vector larger than 64 bits cannot be represented in Hexagon. |
| 1954 | // Expand will split the vector. |
| 1955 | if (Size > 64) |
| 1956 | return SDValue(); |
| 1957 | |
| 1958 | APInt APSplatBits, APSplatUndef; |
| 1959 | unsigned SplatBitSize; |
| 1960 | bool HasAnyUndefs; |
| 1961 | unsigned NElts = BVN->getNumOperands(); |
| 1962 | |
| 1963 | // Try to generate a SPLAT instruction. |
| 1964 | if ((VT.getSimpleVT() == MVT::v4i8 || VT.getSimpleVT() == MVT::v4i16) && |
| 1965 | (BVN->isConstantSplat(APSplatBits, APSplatUndef, SplatBitSize, |
| 1966 | HasAnyUndefs, 0, true) && SplatBitSize <= 16)) { |
| 1967 | unsigned SplatBits = APSplatBits.getZExtValue(); |
| 1968 | int32_t SextVal = ((int32_t) (SplatBits << (32 - SplatBitSize)) >> |
| 1969 | (32 - SplatBitSize)); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1970 | return createSplat(DAG, dl, VT, DAG.getConstant(SextVal, dl, MVT::i32)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | // Try to generate COMBINE to build v2i32 vectors. |
| 1974 | if (VT.getSimpleVT() == MVT::v2i32) { |
| 1975 | SDValue V0 = BVN->getOperand(0); |
| 1976 | SDValue V1 = BVN->getOperand(1); |
| 1977 | |
| 1978 | if (V0.getOpcode() == ISD::UNDEF) |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1979 | V0 = DAG.getConstant(0, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1980 | if (V1.getOpcode() == ISD::UNDEF) |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1981 | V1 = DAG.getConstant(0, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1982 | |
| 1983 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(V0); |
| 1984 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(V1); |
| 1985 | // If the element isn't a constant, it is in a register: |
| 1986 | // generate a COMBINE Register Register instruction. |
| 1987 | if (!C0 || !C1) |
| 1988 | return DAG.getNode(HexagonISD::COMBINE, dl, VT, V1, V0); |
| 1989 | |
| 1990 | // If one of the operands is an 8 bit integer constant, generate |
| 1991 | // a COMBINE Immediate Immediate instruction. |
| 1992 | if (isInt<8>(C0->getSExtValue()) || |
| 1993 | isInt<8>(C1->getSExtValue())) |
| 1994 | return DAG.getNode(HexagonISD::COMBINE, dl, VT, V1, V0); |
| 1995 | } |
| 1996 | |
| 1997 | // Try to generate a S2_packhl to build v2i16 vectors. |
| 1998 | if (VT.getSimpleVT() == MVT::v2i16) { |
| 1999 | for (unsigned i = 0, e = NElts; i != e; ++i) { |
| 2000 | if (BVN->getOperand(i).getOpcode() == ISD::UNDEF) |
| 2001 | continue; |
| 2002 | ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(BVN->getOperand(i)); |
| 2003 | // If the element isn't a constant, it is in a register: |
| 2004 | // generate a S2_packhl instruction. |
| 2005 | if (!Cst) { |
| 2006 | SDValue pack = DAG.getNode(HexagonISD::PACKHL, dl, MVT::v4i16, |
| 2007 | BVN->getOperand(1), BVN->getOperand(0)); |
| 2008 | |
| 2009 | return DAG.getTargetExtractSubreg(Hexagon::subreg_loreg, dl, MVT::v2i16, |
| 2010 | pack); |
| 2011 | } |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | // In the general case, generate a CONST32 or a CONST64 for constant vectors, |
| 2016 | // and insert_vector_elt for all the other cases. |
| 2017 | uint64_t Res = 0; |
| 2018 | unsigned EltSize = Size / NElts; |
| 2019 | SDValue ConstVal; |
| 2020 | uint64_t Mask = ~uint64_t(0ULL) >> (64 - EltSize); |
| 2021 | bool HasNonConstantElements = false; |
| 2022 | |
| 2023 | for (unsigned i = 0, e = NElts; i != e; ++i) { |
| 2024 | // LLVM's BUILD_VECTOR operands are in Little Endian mode, whereas Hexagon's |
| 2025 | // combine, const64, etc. are Big Endian. |
| 2026 | unsigned OpIdx = NElts - i - 1; |
| 2027 | SDValue Operand = BVN->getOperand(OpIdx); |
| 2028 | if (Operand.getOpcode() == ISD::UNDEF) |
| 2029 | continue; |
| 2030 | |
| 2031 | int64_t Val = 0; |
| 2032 | if (ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(Operand)) |
| 2033 | Val = Cst->getSExtValue(); |
| 2034 | else |
| 2035 | HasNonConstantElements = true; |
| 2036 | |
| 2037 | Val &= Mask; |
| 2038 | Res = (Res << EltSize) | Val; |
| 2039 | } |
| 2040 | |
| 2041 | if (Size == 64) |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2042 | ConstVal = DAG.getConstant(Res, dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2043 | else |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2044 | ConstVal = DAG.getConstant(Res, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2045 | |
| 2046 | // When there are non constant operands, add them with INSERT_VECTOR_ELT to |
| 2047 | // ConstVal, the constant part of the vector. |
| 2048 | if (HasNonConstantElements) { |
| 2049 | EVT EltVT = VT.getVectorElementType(); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2050 | SDValue Width = DAG.getConstant(EltVT.getSizeInBits(), dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2051 | SDValue Shifted = DAG.getNode(ISD::SHL, dl, MVT::i64, Width, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2052 | DAG.getConstant(32, dl, MVT::i64)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2053 | |
| 2054 | for (unsigned i = 0, e = NElts; i != e; ++i) { |
| 2055 | // LLVM's BUILD_VECTOR operands are in Little Endian mode, whereas Hexagon |
| 2056 | // is Big Endian. |
| 2057 | unsigned OpIdx = NElts - i - 1; |
| 2058 | SDValue Operand = BVN->getOperand(OpIdx); |
Benjamin Kramer | 619c4e5 | 2015-04-10 11:24:51 +0000 | [diff] [blame] | 2059 | if (isa<ConstantSDNode>(Operand)) |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2060 | // This operand is already in ConstVal. |
| 2061 | continue; |
| 2062 | |
| 2063 | if (VT.getSizeInBits() == 64 && |
| 2064 | Operand.getValueType().getSizeInBits() == 32) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2065 | SDValue C = DAG.getConstant(0, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2066 | Operand = DAG.getNode(HexagonISD::COMBINE, dl, VT, C, Operand); |
| 2067 | } |
| 2068 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2069 | SDValue Idx = DAG.getConstant(OpIdx, dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2070 | SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i64, Idx, Width); |
| 2071 | SDValue Combined = DAG.getNode(ISD::OR, dl, MVT::i64, Shifted, Offset); |
| 2072 | const SDValue Ops[] = {ConstVal, Operand, Combined}; |
| 2073 | |
| 2074 | if (VT.getSizeInBits() == 32) |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2075 | ConstVal = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i32, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2076 | else |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2077 | ConstVal = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i64, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | return DAG.getNode(ISD::BITCAST, dl, VT, ConstVal); |
| 2082 | } |
| 2083 | |
| 2084 | SDValue |
| 2085 | HexagonTargetLowering::LowerCONCAT_VECTORS(SDValue Op, |
| 2086 | SelectionDAG &DAG) const { |
| 2087 | SDLoc dl(Op); |
| 2088 | EVT VT = Op.getValueType(); |
| 2089 | unsigned NElts = Op.getNumOperands(); |
| 2090 | SDValue Vec = Op.getOperand(0); |
| 2091 | EVT VecVT = Vec.getValueType(); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2092 | SDValue Width = DAG.getConstant(VecVT.getSizeInBits(), dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2093 | SDValue Shifted = DAG.getNode(ISD::SHL, dl, MVT::i64, Width, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2094 | DAG.getConstant(32, dl, MVT::i64)); |
| 2095 | SDValue ConstVal = DAG.getConstant(0, dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2096 | |
| 2097 | ConstantSDNode *W = dyn_cast<ConstantSDNode>(Width); |
| 2098 | ConstantSDNode *S = dyn_cast<ConstantSDNode>(Shifted); |
| 2099 | |
| 2100 | if ((VecVT.getSimpleVT() == MVT::v2i16) && (NElts == 2) && W && S) { |
| 2101 | if ((W->getZExtValue() == 32) && ((S->getZExtValue() >> 32) == 32)) { |
| 2102 | // We are trying to concat two v2i16 to a single v4i16. |
| 2103 | SDValue Vec0 = Op.getOperand(1); |
| 2104 | SDValue Combined = DAG.getNode(HexagonISD::COMBINE, dl, VT, Vec0, Vec); |
| 2105 | return DAG.getNode(ISD::BITCAST, dl, VT, Combined); |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | if ((VecVT.getSimpleVT() == MVT::v4i8) && (NElts == 2) && W && S) { |
| 2110 | if ((W->getZExtValue() == 32) && ((S->getZExtValue() >> 32) == 32)) { |
| 2111 | // We are trying to concat two v4i8 to a single v8i8. |
| 2112 | SDValue Vec0 = Op.getOperand(1); |
| 2113 | SDValue Combined = DAG.getNode(HexagonISD::COMBINE, dl, VT, Vec0, Vec); |
| 2114 | return DAG.getNode(ISD::BITCAST, dl, VT, Combined); |
| 2115 | } |
| 2116 | } |
| 2117 | |
| 2118 | for (unsigned i = 0, e = NElts; i != e; ++i) { |
| 2119 | unsigned OpIdx = NElts - i - 1; |
| 2120 | SDValue Operand = Op.getOperand(OpIdx); |
| 2121 | |
| 2122 | if (VT.getSizeInBits() == 64 && |
| 2123 | Operand.getValueType().getSizeInBits() == 32) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2124 | SDValue C = DAG.getConstant(0, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2125 | Operand = DAG.getNode(HexagonISD::COMBINE, dl, VT, C, Operand); |
| 2126 | } |
| 2127 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2128 | SDValue Idx = DAG.getConstant(OpIdx, dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2129 | SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i64, Idx, Width); |
| 2130 | SDValue Combined = DAG.getNode(ISD::OR, dl, MVT::i64, Shifted, Offset); |
| 2131 | const SDValue Ops[] = {ConstVal, Operand, Combined}; |
| 2132 | |
| 2133 | if (VT.getSizeInBits() == 32) |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2134 | ConstVal = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i32, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2135 | else |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2136 | ConstVal = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i64, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | return DAG.getNode(ISD::BITCAST, dl, VT, ConstVal); |
| 2140 | } |
| 2141 | |
| 2142 | SDValue |
| 2143 | HexagonTargetLowering::LowerEXTRACT_VECTOR(SDValue Op, |
| 2144 | SelectionDAG &DAG) const { |
| 2145 | EVT VT = Op.getValueType(); |
| 2146 | int VTN = VT.isVector() ? VT.getVectorNumElements() : 1; |
| 2147 | SDLoc dl(Op); |
| 2148 | SDValue Idx = Op.getOperand(1); |
| 2149 | SDValue Vec = Op.getOperand(0); |
| 2150 | EVT VecVT = Vec.getValueType(); |
| 2151 | EVT EltVT = VecVT.getVectorElementType(); |
| 2152 | int EltSize = EltVT.getSizeInBits(); |
| 2153 | SDValue Width = DAG.getConstant(Op.getOpcode() == ISD::EXTRACT_VECTOR_ELT ? |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2154 | EltSize : VTN * EltSize, dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2155 | |
| 2156 | // Constant element number. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2157 | if (ConstantSDNode *CI = dyn_cast<ConstantSDNode>(Idx)) { |
| 2158 | uint64_t X = CI->getZExtValue(); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2159 | SDValue Offset = DAG.getConstant(X * EltSize, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2160 | const SDValue Ops[] = {Vec, Width, Offset}; |
| 2161 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2162 | ConstantSDNode *CW = dyn_cast<ConstantSDNode>(Width); |
| 2163 | assert(CW && "Non constant width in LowerEXTRACT_VECTOR"); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2164 | |
| 2165 | SDValue N; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2166 | MVT SVT = VecVT.getSimpleVT(); |
| 2167 | uint64_t W = CW->getZExtValue(); |
| 2168 | |
| 2169 | if (W == 32) { |
| 2170 | // Translate this node into EXTRACT_SUBREG. |
| 2171 | unsigned Subreg = (X == 0) ? Hexagon::subreg_loreg : 0; |
| 2172 | |
| 2173 | if (X == 0) |
| 2174 | Subreg = Hexagon::subreg_loreg; |
| 2175 | else if (SVT == MVT::v2i32 && X == 1) |
| 2176 | Subreg = Hexagon::subreg_hireg; |
| 2177 | else if (SVT == MVT::v4i16 && X == 2) |
| 2178 | Subreg = Hexagon::subreg_hireg; |
| 2179 | else if (SVT == MVT::v8i8 && X == 4) |
| 2180 | Subreg = Hexagon::subreg_hireg; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2181 | else |
| 2182 | llvm_unreachable("Bad offset"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2183 | N = DAG.getTargetExtractSubreg(Subreg, dl, MVT::i32, Vec); |
| 2184 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2185 | } else if (VecVT.getSizeInBits() == 32) { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2186 | N = DAG.getNode(HexagonISD::EXTRACTU, dl, MVT::i32, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2187 | } else { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2188 | N = DAG.getNode(HexagonISD::EXTRACTU, dl, MVT::i64, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2189 | if (VT.getSizeInBits() == 32) |
| 2190 | N = DAG.getTargetExtractSubreg(Hexagon::subreg_loreg, dl, MVT::i32, N); |
| 2191 | } |
| 2192 | |
| 2193 | return DAG.getNode(ISD::BITCAST, dl, VT, N); |
| 2194 | } |
| 2195 | |
| 2196 | // Variable element number. |
| 2197 | SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i32, Idx, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2198 | DAG.getConstant(EltSize, dl, MVT::i32)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2199 | SDValue Shifted = DAG.getNode(ISD::SHL, dl, MVT::i64, Width, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2200 | DAG.getConstant(32, dl, MVT::i64)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2201 | SDValue Combined = DAG.getNode(ISD::OR, dl, MVT::i64, Shifted, Offset); |
| 2202 | |
| 2203 | const SDValue Ops[] = {Vec, Combined}; |
| 2204 | |
| 2205 | SDValue N; |
| 2206 | if (VecVT.getSizeInBits() == 32) { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2207 | N = DAG.getNode(HexagonISD::EXTRACTURP, dl, MVT::i32, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2208 | } else { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2209 | N = DAG.getNode(HexagonISD::EXTRACTURP, dl, MVT::i64, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2210 | if (VT.getSizeInBits() == 32) |
| 2211 | N = DAG.getTargetExtractSubreg(Hexagon::subreg_loreg, dl, MVT::i32, N); |
| 2212 | } |
| 2213 | return DAG.getNode(ISD::BITCAST, dl, VT, N); |
| 2214 | } |
| 2215 | |
| 2216 | SDValue |
| 2217 | HexagonTargetLowering::LowerINSERT_VECTOR(SDValue Op, |
| 2218 | SelectionDAG &DAG) const { |
| 2219 | EVT VT = Op.getValueType(); |
| 2220 | int VTN = VT.isVector() ? VT.getVectorNumElements() : 1; |
| 2221 | SDLoc dl(Op); |
| 2222 | SDValue Vec = Op.getOperand(0); |
| 2223 | SDValue Val = Op.getOperand(1); |
| 2224 | SDValue Idx = Op.getOperand(2); |
| 2225 | EVT VecVT = Vec.getValueType(); |
| 2226 | EVT EltVT = VecVT.getVectorElementType(); |
| 2227 | int EltSize = EltVT.getSizeInBits(); |
| 2228 | SDValue Width = DAG.getConstant(Op.getOpcode() == ISD::INSERT_VECTOR_ELT ? |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2229 | EltSize : VTN * EltSize, dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2230 | |
| 2231 | if (ConstantSDNode *C = cast<ConstantSDNode>(Idx)) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2232 | SDValue Offset = DAG.getConstant(C->getSExtValue() * EltSize, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2233 | const SDValue Ops[] = {Vec, Val, Width, Offset}; |
| 2234 | |
| 2235 | SDValue N; |
| 2236 | if (VT.getSizeInBits() == 32) |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2237 | N = DAG.getNode(HexagonISD::INSERT, dl, MVT::i32, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2238 | else |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2239 | N = DAG.getNode(HexagonISD::INSERT, dl, MVT::i64, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2240 | |
| 2241 | return DAG.getNode(ISD::BITCAST, dl, VT, N); |
| 2242 | } |
| 2243 | |
| 2244 | // Variable element number. |
| 2245 | SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i32, Idx, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2246 | DAG.getConstant(EltSize, dl, MVT::i32)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2247 | SDValue Shifted = DAG.getNode(ISD::SHL, dl, MVT::i64, Width, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2248 | DAG.getConstant(32, dl, MVT::i64)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2249 | SDValue Combined = DAG.getNode(ISD::OR, dl, MVT::i64, Shifted, Offset); |
| 2250 | |
| 2251 | if (VT.getSizeInBits() == 64 && |
| 2252 | Val.getValueType().getSizeInBits() == 32) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2253 | SDValue C = DAG.getConstant(0, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2254 | Val = DAG.getNode(HexagonISD::COMBINE, dl, VT, C, Val); |
| 2255 | } |
| 2256 | |
| 2257 | const SDValue Ops[] = {Vec, Val, Combined}; |
| 2258 | |
| 2259 | SDValue N; |
| 2260 | if (VT.getSizeInBits() == 32) |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2261 | N = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i32, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2262 | else |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2263 | N = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i64, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2264 | |
| 2265 | return DAG.getNode(ISD::BITCAST, dl, VT, N); |
| 2266 | } |
| 2267 | |
Tim Northover | a441585 | 2013-08-06 09:12:35 +0000 | [diff] [blame] | 2268 | bool |
| 2269 | HexagonTargetLowering::allowTruncateForTailCall(Type *Ty1, Type *Ty2) const { |
| 2270 | // Assuming the caller does not have either a signext or zeroext modifier, and |
| 2271 | // only one value is accepted, any reasonable truncation is allowed. |
| 2272 | if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy()) |
| 2273 | return false; |
| 2274 | |
| 2275 | // FIXME: in principle up to 64-bit could be made safe, but it would be very |
| 2276 | // fragile at the moment: any support for multiple value returns would be |
| 2277 | // liable to disallow tail calls involving i64 -> iN truncation in many cases. |
| 2278 | return Ty1->getPrimitiveSizeInBits() <= 32; |
| 2279 | } |
| 2280 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2281 | SDValue |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2282 | HexagonTargetLowering::LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const { |
| 2283 | SDValue Chain = Op.getOperand(0); |
| 2284 | SDValue Offset = Op.getOperand(1); |
| 2285 | SDValue Handler = Op.getOperand(2); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2286 | SDLoc dl(Op); |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2287 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2288 | |
| 2289 | // Mark function as containing a call to EH_RETURN. |
| 2290 | HexagonMachineFunctionInfo *FuncInfo = |
| 2291 | DAG.getMachineFunction().getInfo<HexagonMachineFunctionInfo>(); |
| 2292 | FuncInfo->setHasEHReturn(); |
| 2293 | |
| 2294 | unsigned OffsetReg = Hexagon::R28; |
| 2295 | |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2296 | SDValue StoreAddr = |
| 2297 | DAG.getNode(ISD::ADD, dl, PtrVT, DAG.getRegister(Hexagon::R30, PtrVT), |
| 2298 | DAG.getIntPtrConstant(4, dl)); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2299 | Chain = DAG.getStore(Chain, dl, Handler, StoreAddr, MachinePointerInfo(), |
| 2300 | false, false, 0); |
| 2301 | Chain = DAG.getCopyToReg(Chain, dl, OffsetReg, Offset); |
| 2302 | |
| 2303 | // Not needed we already use it as explict input to EH_RETURN. |
| 2304 | // MF.getRegInfo().addLiveOut(OffsetReg); |
| 2305 | |
| 2306 | return DAG.getNode(HexagonISD::EH_RETURN, dl, MVT::Other, Chain); |
| 2307 | } |
| 2308 | |
| 2309 | SDValue |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2310 | HexagonTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2311 | unsigned Opc = Op.getOpcode(); |
| 2312 | switch (Opc) { |
| 2313 | default: |
| 2314 | #ifndef NDEBUG |
| 2315 | Op.getNode()->dumpr(&DAG); |
| 2316 | if (Opc > HexagonISD::OP_BEGIN && Opc < HexagonISD::OP_END) |
| 2317 | errs() << "Check for a non-legal type in this operation\n"; |
| 2318 | #endif |
| 2319 | llvm_unreachable("Should not custom lower this!"); |
| 2320 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
| 2321 | case ISD::INSERT_SUBVECTOR: return LowerINSERT_VECTOR(Op, DAG); |
| 2322 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR(Op, DAG); |
| 2323 | case ISD::EXTRACT_SUBVECTOR: return LowerEXTRACT_VECTOR(Op, DAG); |
| 2324 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR(Op, DAG); |
| 2325 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG); |
| 2326 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2327 | case ISD::SRA: |
| 2328 | case ISD::SHL: |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2329 | case ISD::SRL: return LowerVECTOR_SHIFT(Op, DAG); |
| 2330 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
| 2331 | case ISD::EH_RETURN: return LowerEH_RETURN(Op, DAG); |
| 2332 | // Frame & Return address. Currently unimplemented. |
| 2333 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
| 2334 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
| 2335 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG); |
| 2336 | case ISD::GlobalAddress: return LowerGLOBALADDRESS(Op, DAG); |
| 2337 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
| 2338 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
| 2339 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2340 | // Custom lower some vector loads. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2341 | case ISD::LOAD: return LowerLOAD(Op, DAG); |
| 2342 | case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); |
| 2343 | case ISD::SETCC: return LowerSETCC(Op, DAG); |
| 2344 | case ISD::VSELECT: return LowerVSELECT(Op, DAG); |
| 2345 | case ISD::CTPOP: return LowerCTPOP(Op, DAG); |
| 2346 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG); |
| 2347 | case ISD::INLINEASM: return LowerINLINEASM(Op, DAG); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2348 | } |
| 2349 | } |
| 2350 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2351 | MachineBasicBlock * |
| 2352 | HexagonTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
| 2353 | MachineBasicBlock *BB) |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 2354 | const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2355 | switch (MI->getOpcode()) { |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 2356 | case Hexagon::ALLOCA: { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2357 | MachineFunction *MF = BB->getParent(); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 2358 | auto *FuncInfo = MF->getInfo<HexagonMachineFunctionInfo>(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2359 | FuncInfo->addAllocaAdjustInst(MI); |
| 2360 | return BB; |
| 2361 | } |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 2362 | default: llvm_unreachable("Unexpected instr type to insert"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2363 | } // switch |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | //===----------------------------------------------------------------------===// |
| 2367 | // Inline Assembly Support |
| 2368 | //===----------------------------------------------------------------------===// |
| 2369 | |
Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 2370 | std::pair<unsigned, const TargetRegisterClass *> |
| 2371 | HexagonTargetLowering::getRegForInlineAsmConstraint( |
Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 2372 | const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2373 | if (Constraint.size() == 1) { |
| 2374 | switch (Constraint[0]) { |
| 2375 | case 'r': // R0-R31 |
Chad Rosier | 295bd43 | 2013-06-22 18:37:38 +0000 | [diff] [blame] | 2376 | switch (VT.SimpleTy) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2377 | default: |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 2378 | llvm_unreachable("getRegForInlineAsmConstraint Unhandled data type"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2379 | case MVT::i32: |
| 2380 | case MVT::i16: |
| 2381 | case MVT::i8: |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 2382 | case MVT::f32: |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2383 | return std::make_pair(0U, &Hexagon::IntRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2384 | case MVT::i64: |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 2385 | case MVT::f64: |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2386 | return std::make_pair(0U, &Hexagon::DoubleRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2387 | } |
| 2388 | default: |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 2389 | llvm_unreachable("Unknown asm register class"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2390 | } |
| 2391 | } |
| 2392 | |
Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 2393 | return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2394 | } |
| 2395 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 2396 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 2397 | /// specified FP immediate natively. If false, the legalizer will |
| 2398 | /// materialize the FP immediate as a load from a constant pool. |
| 2399 | bool HexagonTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2400 | return Subtarget.hasV5TOps(); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2403 | /// isLegalAddressingMode - Return true if the addressing mode represented by |
| 2404 | /// AM is legal for this target, for a load/store of the specified type. |
Mehdi Amini | 0cdec1e | 2015-07-09 02:09:40 +0000 | [diff] [blame] | 2405 | bool HexagonTargetLowering::isLegalAddressingMode(const DataLayout &DL, |
| 2406 | const AddrMode &AM, Type *Ty, |
Matt Arsenault | bd7d80a | 2015-06-01 05:31:59 +0000 | [diff] [blame] | 2407 | unsigned AS) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2408 | // Allows a signed-extended 11-bit immediate field. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2409 | if (AM.BaseOffs <= -(1LL << 13) || AM.BaseOffs >= (1LL << 13)-1) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2410 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2411 | |
| 2412 | // No global is ever allowed as a base. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2413 | if (AM.BaseGV) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2414 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2415 | |
| 2416 | int Scale = AM.Scale; |
| 2417 | if (Scale < 0) Scale = -Scale; |
| 2418 | switch (Scale) { |
| 2419 | case 0: // No scale reg, "r+i", "r", or just "i". |
| 2420 | break; |
| 2421 | default: // No scaled addressing mode. |
| 2422 | return false; |
| 2423 | } |
| 2424 | return true; |
| 2425 | } |
| 2426 | |
| 2427 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 2428 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 2429 | /// a register against the immediate without having to materialize the |
| 2430 | /// immediate into a register. |
| 2431 | bool HexagonTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
| 2432 | return Imm >= -512 && Imm <= 511; |
| 2433 | } |
| 2434 | |
| 2435 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 2436 | /// for tail call optimization. Targets which want to do tail call |
| 2437 | /// optimization should implement this function. |
| 2438 | bool HexagonTargetLowering::IsEligibleForTailCallOptimization( |
| 2439 | SDValue Callee, |
| 2440 | CallingConv::ID CalleeCC, |
| 2441 | bool isVarArg, |
| 2442 | bool isCalleeStructRet, |
| 2443 | bool isCallerStructRet, |
| 2444 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 2445 | const SmallVectorImpl<SDValue> &OutVals, |
| 2446 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 2447 | SelectionDAG& DAG) const { |
| 2448 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 2449 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 2450 | bool CCMatch = CallerCC == CalleeCC; |
| 2451 | |
| 2452 | // *************************************************************************** |
| 2453 | // Look for obvious safe cases to perform tail call optimization that do not |
| 2454 | // require ABI changes. |
| 2455 | // *************************************************************************** |
| 2456 | |
| 2457 | // If this is a tail call via a function pointer, then don't do it! |
Craig Topper | 66059c9 | 2015-11-18 07:07:59 +0000 | [diff] [blame] | 2458 | if (!(isa<GlobalAddressSDNode>(Callee)) && |
| 2459 | !(isa<ExternalSymbolSDNode>(Callee))) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2460 | return false; |
| 2461 | } |
| 2462 | |
| 2463 | // Do not optimize if the calling conventions do not match. |
| 2464 | if (!CCMatch) |
| 2465 | return false; |
| 2466 | |
| 2467 | // Do not tail call optimize vararg calls. |
| 2468 | if (isVarArg) |
| 2469 | return false; |
| 2470 | |
| 2471 | // Also avoid tail call optimization if either caller or callee uses struct |
| 2472 | // return semantics. |
| 2473 | if (isCalleeStructRet || isCallerStructRet) |
| 2474 | return false; |
| 2475 | |
| 2476 | // In addition to the cases above, we also disable Tail Call Optimization if |
| 2477 | // the calling convention code that at least one outgoing argument needs to |
| 2478 | // go on the stack. We cannot check that here because at this point that |
| 2479 | // information is not available. |
| 2480 | return true; |
| 2481 | } |
Colin LeMahieu | 025f860 | 2014-12-08 21:19:18 +0000 | [diff] [blame] | 2482 | |
| 2483 | // Return true when the given node fits in a positive half word. |
| 2484 | bool llvm::isPositiveHalfWord(SDNode *N) { |
| 2485 | ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N); |
| 2486 | if (CN && CN->getSExtValue() > 0 && isInt<16>(CN->getSExtValue())) |
| 2487 | return true; |
| 2488 | |
| 2489 | switch (N->getOpcode()) { |
| 2490 | default: |
| 2491 | return false; |
| 2492 | case ISD::SIGN_EXTEND_INREG: |
| 2493 | return true; |
| 2494 | } |
| 2495 | } |
Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 2496 | |
| 2497 | Value *HexagonTargetLowering::emitLoadLinked(IRBuilder<> &Builder, Value *Addr, |
| 2498 | AtomicOrdering Ord) const { |
| 2499 | BasicBlock *BB = Builder.GetInsertBlock(); |
| 2500 | Module *M = BB->getParent()->getParent(); |
| 2501 | Type *Ty = cast<PointerType>(Addr->getType())->getElementType(); |
| 2502 | unsigned SZ = Ty->getPrimitiveSizeInBits(); |
| 2503 | assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic loads supported"); |
| 2504 | Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_L2_loadw_locked |
| 2505 | : Intrinsic::hexagon_L4_loadd_locked; |
| 2506 | Value *Fn = Intrinsic::getDeclaration(M, IntID); |
| 2507 | return Builder.CreateCall(Fn, Addr, "larx"); |
| 2508 | } |
| 2509 | |
| 2510 | /// Perform a store-conditional operation to Addr. Return the status of the |
| 2511 | /// store. This should be 0 if the store succeeded, non-zero otherwise. |
| 2512 | Value *HexagonTargetLowering::emitStoreConditional(IRBuilder<> &Builder, |
| 2513 | Value *Val, Value *Addr, AtomicOrdering Ord) const { |
| 2514 | BasicBlock *BB = Builder.GetInsertBlock(); |
| 2515 | Module *M = BB->getParent()->getParent(); |
| 2516 | Type *Ty = Val->getType(); |
| 2517 | unsigned SZ = Ty->getPrimitiveSizeInBits(); |
| 2518 | assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic stores supported"); |
| 2519 | Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_S2_storew_locked |
| 2520 | : Intrinsic::hexagon_S4_stored_locked; |
| 2521 | Value *Fn = Intrinsic::getDeclaration(M, IntID); |
| 2522 | Value *Call = Builder.CreateCall(Fn, {Addr, Val}, "stcx"); |
| 2523 | Value *Cmp = Builder.CreateICmpEQ(Call, Builder.getInt32(0), ""); |
| 2524 | Value *Ext = Builder.CreateZExt(Cmp, Type::getInt32Ty(M->getContext())); |
| 2525 | return Ext; |
| 2526 | } |
| 2527 | |
Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 2528 | TargetLowering::AtomicExpansionKind |
| 2529 | HexagonTargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const { |
Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 2530 | // Do not expand loads and stores that don't exceed 64 bits. |
Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 2531 | return LI->getType()->getPrimitiveSizeInBits() > 64 |
| 2532 | ? AtomicExpansionKind::LLSC |
| 2533 | : AtomicExpansionKind::None; |
Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | bool HexagonTargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const { |
| 2537 | // Do not expand loads and stores that don't exceed 64 bits. |
| 2538 | return SI->getValueOperand()->getType()->getPrimitiveSizeInBits() > 64; |
| 2539 | } |
| 2540 | |