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 | |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 15 | #include "Hexagon.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 16 | #include "HexagonISelLowering.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 17 | #include "HexagonMachineFunctionInfo.h" |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 18 | #include "HexagonRegisterInfo.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 19 | #include "HexagonSubtarget.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "HexagonTargetMachine.h" |
| 21 | #include "HexagonTargetObjectFile.h" |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/APInt.h" |
| 23 | #include "llvm/ADT/ArrayRef.h" |
| 24 | #include "llvm/ADT/SmallVector.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/CallingConvLower.h" |
| 26 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 27 | #include "llvm/CodeGen/MachineFunction.h" |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineMemOperand.h" |
| 29 | #include "llvm/CodeGen/RuntimeLibcalls.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/SelectionDAG.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/ValueTypes.h" |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 33 | #include "llvm/IR/BasicBlock.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 34 | #include "llvm/IR/CallingConv.h" |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 35 | #include "llvm/IR/DataLayout.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 36 | #include "llvm/IR/DerivedTypes.h" |
| 37 | #include "llvm/IR/Function.h" |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 38 | #include "llvm/IR/GlobalValue.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 39 | #include "llvm/IR/InlineAsm.h" |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 40 | #include "llvm/IR/Instructions.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 41 | #include "llvm/IR/Intrinsics.h" |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 42 | #include "llvm/IR/Module.h" |
| 43 | #include "llvm/IR/Type.h" |
| 44 | #include "llvm/IR/Value.h" |
| 45 | #include "llvm/MC/MCRegisterInfo.h" |
| 46 | #include "llvm/Support/Casting.h" |
| 47 | #include "llvm/Support/CodeGen.h" |
NAKAMURA Takumi | 54eed76 | 2012-04-21 15:31:36 +0000 | [diff] [blame] | 48 | #include "llvm/Support/CommandLine.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 49 | #include "llvm/Support/Debug.h" |
| 50 | #include "llvm/Support/ErrorHandling.h" |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 51 | #include "llvm/Support/MathExtras.h" |
NAKAMURA Takumi | e30303f | 2012-04-21 15:31:45 +0000 | [diff] [blame] | 52 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 53 | #include "llvm/Target/TargetCallingConv.h" |
| 54 | #include "llvm/Target/TargetMachine.h" |
| 55 | #include <algorithm> |
| 56 | #include <cassert> |
| 57 | #include <cstddef> |
| 58 | #include <cstdint> |
| 59 | #include <limits> |
| 60 | #include <utility> |
NAKAMURA Takumi | 54eed76 | 2012-04-21 15:31:36 +0000 | [diff] [blame] | 61 | |
Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 62 | using namespace llvm; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 63 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 64 | #define DEBUG_TYPE "hexagon-lowering" |
| 65 | |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 66 | static cl::opt<bool> EmitJumpTables("hexagon-emit-jump-tables", |
| 67 | cl::init(true), cl::Hidden, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 68 | cl::desc("Control jump table emission on Hexagon target")); |
| 69 | |
| 70 | static cl::opt<bool> EnableHexSDNodeSched("enable-hexagon-sdnode-sched", |
| 71 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 72 | cl::desc("Enable Hexagon SDNode scheduling")); |
| 73 | |
| 74 | static cl::opt<bool> EnableFastMath("ffast-math", |
| 75 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 76 | cl::desc("Enable Fast Math processing")); |
| 77 | |
| 78 | static cl::opt<int> MinimumJumpTables("minimum-jump-tables", |
| 79 | cl::Hidden, cl::ZeroOrMore, cl::init(5), |
| 80 | cl::desc("Set minimum jump tables")); |
| 81 | |
| 82 | static cl::opt<int> MaxStoresPerMemcpyCL("max-store-memcpy", |
| 83 | cl::Hidden, cl::ZeroOrMore, cl::init(6), |
| 84 | cl::desc("Max #stores to inline memcpy")); |
| 85 | |
| 86 | static cl::opt<int> MaxStoresPerMemcpyOptSizeCL("max-store-memcpy-Os", |
| 87 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 88 | cl::desc("Max #stores to inline memcpy")); |
| 89 | |
| 90 | static cl::opt<int> MaxStoresPerMemmoveCL("max-store-memmove", |
| 91 | cl::Hidden, cl::ZeroOrMore, cl::init(6), |
| 92 | cl::desc("Max #stores to inline memmove")); |
| 93 | |
| 94 | static cl::opt<int> MaxStoresPerMemmoveOptSizeCL("max-store-memmove-Os", |
| 95 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 96 | cl::desc("Max #stores to inline memmove")); |
| 97 | |
| 98 | static cl::opt<int> MaxStoresPerMemsetCL("max-store-memset", |
| 99 | cl::Hidden, cl::ZeroOrMore, cl::init(8), |
| 100 | cl::desc("Max #stores to inline memset")); |
| 101 | |
| 102 | static cl::opt<int> MaxStoresPerMemsetOptSizeCL("max-store-memset-Os", |
| 103 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 104 | cl::desc("Max #stores to inline memset")); |
| 105 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 106 | |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 107 | namespace { |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 108 | |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 109 | class HexagonCCState : public CCState { |
| 110 | unsigned NumNamedVarArgParams; |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 111 | |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 112 | public: |
| 113 | HexagonCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, |
| 114 | SmallVectorImpl<CCValAssign> &locs, LLVMContext &C, |
| 115 | int NumNamedVarArgParams) |
| 116 | : CCState(CC, isVarArg, MF, locs, C), |
| 117 | NumNamedVarArgParams(NumNamedVarArgParams) {} |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 118 | |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 119 | unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; } |
| 120 | }; |
| 121 | |
| 122 | enum StridedLoadKind { |
| 123 | Even = 0, |
| 124 | Odd, |
| 125 | NoPattern |
| 126 | }; |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 127 | |
| 128 | } // end anonymous namespace |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 129 | |
| 130 | // Implement calling convention for Hexagon. |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 131 | |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 132 | static bool isHvxVectorType(MVT ty); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 133 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 134 | static bool |
| 135 | CC_Hexagon(unsigned ValNo, MVT ValVT, |
| 136 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 137 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 138 | |
| 139 | static bool |
| 140 | CC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 141 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 142 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 143 | |
| 144 | static bool |
| 145 | CC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 146 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 147 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 148 | |
| 149 | static bool |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 150 | CC_HexagonVector(unsigned ValNo, MVT ValVT, |
| 151 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 152 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 153 | |
| 154 | static bool |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 155 | RetCC_Hexagon(unsigned ValNo, MVT ValVT, |
| 156 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 157 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 158 | |
| 159 | static bool |
| 160 | RetCC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 161 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 162 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 163 | |
| 164 | static bool |
| 165 | RetCC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 166 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 167 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 168 | |
| 169 | static bool |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 170 | RetCC_HexagonVector(unsigned ValNo, MVT ValVT, |
| 171 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 172 | ISD::ArgFlagsTy ArgFlags, CCState &State); |
| 173 | |
| 174 | static bool |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 175 | CC_Hexagon_VarArg (unsigned ValNo, MVT ValVT, |
| 176 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 177 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 178 | HexagonCCState &HState = static_cast<HexagonCCState &>(State); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 179 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 180 | if (ValNo < HState.getNumNamedVarArgParams()) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 181 | // Deal with named arguments. |
| 182 | return CC_Hexagon(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State); |
| 183 | } |
| 184 | |
| 185 | // Deal with un-named arguments. |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 186 | unsigned Offset; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 187 | if (ArgFlags.isByVal()) { |
| 188 | // If pass-by-value, the size allocated on stack is decided |
| 189 | // by ArgFlags.getByValSize(), not by the size of LocVT. |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 190 | Offset = State.AllocateStack(ArgFlags.getByValSize(), |
| 191 | ArgFlags.getByValAlign()); |
| 192 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 193 | return false; |
| 194 | } |
Jyotsna Verma | c7dcc2f | 2013-03-07 20:28:34 +0000 | [diff] [blame] | 195 | if (LocVT == MVT::i1 || LocVT == MVT::i8 || LocVT == MVT::i16) { |
| 196 | LocVT = MVT::i32; |
| 197 | ValVT = MVT::i32; |
| 198 | if (ArgFlags.isSExt()) |
| 199 | LocInfo = CCValAssign::SExt; |
| 200 | else if (ArgFlags.isZExt()) |
| 201 | LocInfo = CCValAssign::ZExt; |
| 202 | else |
| 203 | LocInfo = CCValAssign::AExt; |
| 204 | } |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 205 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 206 | Offset = State.AllocateStack(4, 4); |
| 207 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 208 | return false; |
| 209 | } |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 210 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 211 | Offset = State.AllocateStack(8, 8); |
| 212 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 213 | return false; |
| 214 | } |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 215 | if (LocVT == MVT::v2i64 || LocVT == MVT::v4i32 || LocVT == MVT::v8i16 || |
| 216 | LocVT == MVT::v16i8) { |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 217 | Offset = State.AllocateStack(16, 16); |
| 218 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 219 | return false; |
| 220 | } |
| 221 | if (LocVT == MVT::v4i64 || LocVT == MVT::v8i32 || LocVT == MVT::v16i16 || |
| 222 | LocVT == MVT::v32i8) { |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 223 | Offset = State.AllocateStack(32, 32); |
| 224 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 225 | return false; |
| 226 | } |
| 227 | if (LocVT == MVT::v8i64 || LocVT == MVT::v16i32 || LocVT == MVT::v32i16 || |
| 228 | LocVT == MVT::v64i8 || LocVT == MVT::v512i1) { |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 229 | Offset = State.AllocateStack(64, 64); |
| 230 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 231 | return false; |
| 232 | } |
| 233 | if (LocVT == MVT::v16i64 || LocVT == MVT::v32i32 || LocVT == MVT::v64i16 || |
| 234 | LocVT == MVT::v128i8 || LocVT == MVT::v1024i1) { |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 235 | Offset = State.AllocateStack(128, 128); |
| 236 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 237 | return false; |
| 238 | } |
| 239 | if (LocVT == MVT::v32i64 || LocVT == MVT::v64i32 || LocVT == MVT::v128i16 || |
| 240 | LocVT == MVT::v256i8) { |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 241 | Offset = State.AllocateStack(256, 256); |
| 242 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 243 | return false; |
| 244 | } |
| 245 | |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 246 | llvm_unreachable(nullptr); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 249 | static bool CC_Hexagon (unsigned ValNo, MVT ValVT, MVT LocVT, |
| 250 | CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 251 | if (ArgFlags.isByVal()) { |
| 252 | // Passed on stack. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 253 | unsigned Offset = State.AllocateStack(ArgFlags.getByValSize(), |
| 254 | ArgFlags.getByValAlign()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 255 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 256 | return false; |
| 257 | } |
| 258 | |
| 259 | if (LocVT == MVT::i1 || LocVT == MVT::i8 || LocVT == MVT::i16) { |
| 260 | LocVT = MVT::i32; |
| 261 | ValVT = MVT::i32; |
| 262 | if (ArgFlags.isSExt()) |
| 263 | LocInfo = CCValAssign::SExt; |
| 264 | else if (ArgFlags.isZExt()) |
| 265 | LocInfo = CCValAssign::ZExt; |
| 266 | else |
| 267 | LocInfo = CCValAssign::AExt; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 268 | } else if (LocVT == MVT::v4i8 || LocVT == MVT::v2i16) { |
| 269 | LocVT = MVT::i32; |
| 270 | LocInfo = CCValAssign::BCvt; |
| 271 | } else if (LocVT == MVT::v8i8 || LocVT == MVT::v4i16 || LocVT == MVT::v2i32) { |
| 272 | LocVT = MVT::i64; |
| 273 | LocInfo = CCValAssign::BCvt; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 276 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 277 | if (!CC_Hexagon32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
| 278 | return false; |
| 279 | } |
| 280 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 281 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 282 | if (!CC_Hexagon64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
| 283 | return false; |
| 284 | } |
| 285 | |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 286 | if (LocVT == MVT::v8i32 || LocVT == MVT::v16i16 || LocVT == MVT::v32i8) { |
| 287 | unsigned Offset = State.AllocateStack(ArgFlags.getByValSize(), 32); |
| 288 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 289 | return false; |
| 290 | } |
| 291 | |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 292 | if (isHvxVectorType(LocVT)) { |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 293 | if (!CC_HexagonVector(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
| 294 | return false; |
| 295 | } |
| 296 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 297 | return true; // CC didn't match. |
| 298 | } |
| 299 | |
| 300 | |
| 301 | static bool CC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 302 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 303 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 304 | static const MCPhysReg RegList[] = { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 305 | Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4, |
| 306 | Hexagon::R5 |
| 307 | }; |
Tim Northover | 3b6b7ca | 2015-02-21 02:11:17 +0000 | [diff] [blame] | 308 | if (unsigned Reg = State.AllocateReg(RegList)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 309 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 310 | return false; |
| 311 | } |
| 312 | |
| 313 | unsigned Offset = State.AllocateStack(4, 4); |
| 314 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | static bool CC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 319 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 320 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 321 | if (unsigned Reg = State.AllocateReg(Hexagon::D0)) { |
| 322 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 323 | return false; |
| 324 | } |
| 325 | |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 326 | static const MCPhysReg RegList1[] = { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 327 | Hexagon::D1, Hexagon::D2 |
| 328 | }; |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 329 | static const MCPhysReg RegList2[] = { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 330 | Hexagon::R1, Hexagon::R3 |
| 331 | }; |
Tim Northover | 3b6b7ca | 2015-02-21 02:11:17 +0000 | [diff] [blame] | 332 | if (unsigned Reg = State.AllocateReg(RegList1, RegList2)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 333 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 334 | return false; |
| 335 | } |
| 336 | |
| 337 | unsigned Offset = State.AllocateStack(8, 8, Hexagon::D2); |
| 338 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 339 | return false; |
| 340 | } |
| 341 | |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 342 | static bool CC_HexagonVector(unsigned ValNo, MVT ValVT, |
| 343 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 344 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 345 | static const MCPhysReg VecLstS[] = { |
| 346 | Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4, |
| 347 | Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9, |
| 348 | Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14, |
| 349 | Hexagon::V15 |
| 350 | }; |
| 351 | static const MCPhysReg VecLstD[] = { |
| 352 | Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3, Hexagon::W4, |
| 353 | Hexagon::W5, Hexagon::W6, Hexagon::W7 |
| 354 | }; |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 355 | auto &MF = State.getMachineFunction(); |
| 356 | auto &HST = MF.getSubtarget<HexagonSubtarget>(); |
| 357 | bool UseHVX = HST.useHVXOps(); |
| 358 | bool UseHVXDbl = HST.useHVXDblOps(); |
| 359 | |
| 360 | if ((UseHVX && !UseHVXDbl) && |
| 361 | (LocVT == MVT::v8i64 || LocVT == MVT::v16i32 || LocVT == MVT::v32i16 || |
| 362 | LocVT == MVT::v64i8 || LocVT == MVT::v512i1)) { |
| 363 | if (unsigned Reg = State.AllocateReg(VecLstS)) { |
| 364 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 365 | return false; |
| 366 | } |
| 367 | unsigned Offset = State.AllocateStack(64, 64); |
| 368 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 369 | return false; |
| 370 | } |
| 371 | if ((UseHVX && !UseHVXDbl) && |
| 372 | (LocVT == MVT::v16i64 || LocVT == MVT::v32i32 || LocVT == MVT::v64i16 || |
| 373 | LocVT == MVT::v128i8)) { |
| 374 | if (unsigned Reg = State.AllocateReg(VecLstD)) { |
| 375 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 376 | return false; |
| 377 | } |
| 378 | unsigned Offset = State.AllocateStack(128, 128); |
| 379 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 380 | return false; |
| 381 | } |
| 382 | // 128B Mode |
| 383 | if ((UseHVX && UseHVXDbl) && |
| 384 | (LocVT == MVT::v32i64 || LocVT == MVT::v64i32 || LocVT == MVT::v128i16 || |
| 385 | LocVT == MVT::v256i8)) { |
| 386 | if (unsigned Reg = State.AllocateReg(VecLstD)) { |
| 387 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 388 | return false; |
| 389 | } |
| 390 | unsigned Offset = State.AllocateStack(256, 256); |
| 391 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 392 | return false; |
| 393 | } |
| 394 | if ((UseHVX && UseHVXDbl) && |
| 395 | (LocVT == MVT::v16i64 || LocVT == MVT::v32i32 || LocVT == MVT::v64i16 || |
| 396 | LocVT == MVT::v128i8 || LocVT == MVT::v1024i1)) { |
| 397 | if (unsigned Reg = State.AllocateReg(VecLstS)) { |
| 398 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 399 | return false; |
| 400 | } |
| 401 | unsigned Offset = State.AllocateStack(128, 128); |
| 402 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 403 | return false; |
| 404 | } |
| 405 | return true; |
| 406 | } |
| 407 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 408 | static bool RetCC_Hexagon(unsigned ValNo, MVT ValVT, |
| 409 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 410 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 411 | auto &MF = State.getMachineFunction(); |
| 412 | auto &HST = MF.getSubtarget<HexagonSubtarget>(); |
| 413 | bool UseHVX = HST.useHVXOps(); |
| 414 | bool UseHVXDbl = HST.useHVXDblOps(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 415 | |
Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 416 | if (LocVT == MVT::i1) { |
| 417 | // Return values of type MVT::i1 still need to be assigned to R0, but |
| 418 | // the value type needs to remain i1. LowerCallResult will deal with it, |
| 419 | // but it needs to recognize i1 as the value type. |
| 420 | LocVT = MVT::i32; |
| 421 | } else if (LocVT == MVT::i8 || LocVT == MVT::i16) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 422 | LocVT = MVT::i32; |
| 423 | ValVT = MVT::i32; |
| 424 | if (ArgFlags.isSExt()) |
| 425 | LocInfo = CCValAssign::SExt; |
| 426 | else if (ArgFlags.isZExt()) |
| 427 | LocInfo = CCValAssign::ZExt; |
| 428 | else |
| 429 | LocInfo = CCValAssign::AExt; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 430 | } else if (LocVT == MVT::v4i8 || LocVT == MVT::v2i16) { |
| 431 | LocVT = MVT::i32; |
| 432 | LocInfo = CCValAssign::BCvt; |
| 433 | } else if (LocVT == MVT::v8i8 || LocVT == MVT::v4i16 || LocVT == MVT::v2i32) { |
| 434 | LocVT = MVT::i64; |
| 435 | LocInfo = CCValAssign::BCvt; |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 436 | } else if (LocVT == MVT::v64i8 || LocVT == MVT::v32i16 || |
| 437 | LocVT == MVT::v16i32 || LocVT == MVT::v8i64 || |
| 438 | LocVT == MVT::v512i1) { |
| 439 | LocVT = MVT::v16i32; |
| 440 | ValVT = MVT::v16i32; |
| 441 | LocInfo = CCValAssign::Full; |
| 442 | } else if (LocVT == MVT::v128i8 || LocVT == MVT::v64i16 || |
| 443 | LocVT == MVT::v32i32 || LocVT == MVT::v16i64 || |
| 444 | (LocVT == MVT::v1024i1 && UseHVX && UseHVXDbl)) { |
| 445 | LocVT = MVT::v32i32; |
| 446 | ValVT = MVT::v32i32; |
| 447 | LocInfo = CCValAssign::Full; |
| 448 | } else if (LocVT == MVT::v256i8 || LocVT == MVT::v128i16 || |
| 449 | LocVT == MVT::v64i32 || LocVT == MVT::v32i64) { |
| 450 | LocVT = MVT::v64i32; |
| 451 | ValVT = MVT::v64i32; |
| 452 | LocInfo = CCValAssign::Full; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 453 | } |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 454 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 455 | if (!RetCC_Hexagon32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 456 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 459 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 460 | if (!RetCC_Hexagon64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 461 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 462 | } |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 463 | if (LocVT == MVT::v16i32 || LocVT == MVT::v32i32 || LocVT == MVT::v64i32) { |
| 464 | if (!RetCC_HexagonVector(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State)) |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 465 | return false; |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 466 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 467 | return true; // CC didn't match. |
| 468 | } |
| 469 | |
| 470 | static bool RetCC_Hexagon32(unsigned ValNo, MVT ValVT, |
| 471 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 472 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 473 | if (LocVT == MVT::i32 || LocVT == MVT::f32) { |
Krzysztof Parzyszek | 14412ef | 2016-07-18 17:36:46 +0000 | [diff] [blame] | 474 | // Note that use of registers beyond R1 is not ABI compliant. However there |
| 475 | // are (experimental) IR passes which generate internal functions that |
| 476 | // return structs using these additional registers. |
| 477 | static const uint16_t RegList[] = { Hexagon::R0, Hexagon::R1, |
| 478 | Hexagon::R2, Hexagon::R3, |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 479 | Hexagon::R4, Hexagon::R5 }; |
Krzysztof Parzyszek | 14412ef | 2016-07-18 17:36:46 +0000 | [diff] [blame] | 480 | if (unsigned Reg = State.AllocateReg(RegList)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 481 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 482 | return false; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | unsigned Offset = State.AllocateStack(4, 4); |
| 487 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 488 | return false; |
| 489 | } |
| 490 | |
| 491 | static bool RetCC_Hexagon64(unsigned ValNo, MVT ValVT, |
| 492 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 493 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 494 | if (LocVT == MVT::i64 || LocVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 495 | if (unsigned Reg = State.AllocateReg(Hexagon::D0)) { |
| 496 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 497 | return false; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | unsigned Offset = State.AllocateStack(8, 8); |
| 502 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 503 | return false; |
| 504 | } |
| 505 | |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 506 | static bool RetCC_HexagonVector(unsigned ValNo, MVT ValVT, |
| 507 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 508 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 509 | auto &MF = State.getMachineFunction(); |
| 510 | auto &HST = MF.getSubtarget<HexagonSubtarget>(); |
| 511 | bool UseHVX = HST.useHVXOps(); |
| 512 | bool UseHVXDbl = HST.useHVXDblOps(); |
| 513 | |
| 514 | unsigned OffSiz = 64; |
| 515 | if (LocVT == MVT::v16i32) { |
| 516 | if (unsigned Reg = State.AllocateReg(Hexagon::V0)) { |
| 517 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 518 | return false; |
| 519 | } |
| 520 | } else if (LocVT == MVT::v32i32) { |
| 521 | unsigned Req = (UseHVX && UseHVXDbl) ? Hexagon::V0 : Hexagon::W0; |
| 522 | if (unsigned Reg = State.AllocateReg(Req)) { |
| 523 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 524 | return false; |
| 525 | } |
| 526 | OffSiz = 128; |
| 527 | } else if (LocVT == MVT::v64i32) { |
| 528 | if (unsigned Reg = State.AllocateReg(Hexagon::W0)) { |
| 529 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 530 | return false; |
| 531 | } |
| 532 | OffSiz = 256; |
| 533 | } |
| 534 | |
| 535 | unsigned Offset = State.AllocateStack(OffSiz, OffSiz); |
| 536 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 537 | return false; |
| 538 | } |
| 539 | |
Craig Topper | 18e69f4 | 2016-04-15 06:20:21 +0000 | [diff] [blame] | 540 | void HexagonTargetLowering::promoteLdStType(MVT VT, MVT PromotedLdStVT) { |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 541 | if (VT != PromotedLdStVT) { |
Craig Topper | 18e69f4 | 2016-04-15 06:20:21 +0000 | [diff] [blame] | 542 | setOperationAction(ISD::LOAD, VT, Promote); |
| 543 | AddPromotedToType(ISD::LOAD, VT, PromotedLdStVT); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 544 | |
Craig Topper | 18e69f4 | 2016-04-15 06:20:21 +0000 | [diff] [blame] | 545 | setOperationAction(ISD::STORE, VT, Promote); |
| 546 | AddPromotedToType(ISD::STORE, VT, PromotedLdStVT); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 550 | SDValue |
| 551 | HexagonTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 552 | const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 553 | return SDValue(); |
| 554 | } |
| 555 | |
| 556 | /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified |
| 557 | /// by "Src" to address "Dst" of size "Size". Alignment information is |
| 558 | /// specified by the specific parameter attribute. The copy will be passed as |
| 559 | /// a byval function parameter. Sometimes what we are copying is the end of a |
| 560 | /// larger object, the part that does not fit in registers. |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 561 | static SDValue CreateCopyOfByValArgument(SDValue Src, SDValue Dst, |
| 562 | SDValue Chain, ISD::ArgFlagsTy Flags, |
| 563 | SelectionDAG &DAG, const SDLoc &dl) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 564 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), dl, MVT::i32); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 565 | return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(), |
| 566 | /*isVolatile=*/false, /*AlwaysInline=*/false, |
Krzysztof Parzyszek | a46c36b | 2015-04-13 17:16:45 +0000 | [diff] [blame] | 567 | /*isTailCall=*/false, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 568 | MachinePointerInfo(), MachinePointerInfo()); |
| 569 | } |
| 570 | |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 571 | static bool isHvxVectorType(MVT Ty) { |
| 572 | switch (Ty.SimpleTy) { |
| 573 | case MVT::v8i64: |
| 574 | case MVT::v16i32: |
| 575 | case MVT::v32i16: |
| 576 | case MVT::v64i8: |
| 577 | case MVT::v16i64: |
| 578 | case MVT::v32i32: |
| 579 | case MVT::v64i16: |
| 580 | case MVT::v128i8: |
| 581 | case MVT::v32i64: |
| 582 | case MVT::v64i32: |
| 583 | case MVT::v128i16: |
| 584 | case MVT::v256i8: |
| 585 | case MVT::v512i1: |
| 586 | case MVT::v1024i1: |
| 587 | return true; |
| 588 | default: |
| 589 | return false; |
| 590 | } |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 591 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 592 | |
| 593 | // LowerReturn - Lower ISD::RET. If a struct is larger than 8 bytes and is |
| 594 | // passed by value, the function prototype is modified to return void and |
| 595 | // the value is stored in memory pointed by a pointer passed by caller. |
| 596 | SDValue |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 597 | HexagonTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv, |
| 598 | bool isVarArg, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 599 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 600 | const SmallVectorImpl<SDValue> &OutVals, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 601 | const SDLoc &dl, SelectionDAG &DAG) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 602 | // CCValAssign - represent the assignment of the return value to locations. |
| 603 | SmallVector<CCValAssign, 16> RVLocs; |
| 604 | |
| 605 | // CCState - Info about the registers and stack slot. |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 606 | CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, |
| 607 | *DAG.getContext()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 608 | |
| 609 | // Analyze return values of ISD::RET |
| 610 | CCInfo.AnalyzeReturn(Outs, RetCC_Hexagon); |
| 611 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 612 | SDValue Flag; |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 613 | SmallVector<SDValue, 4> RetOps(1, Chain); |
| 614 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 615 | // Copy the result values into the output registers. |
| 616 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 617 | CCValAssign &VA = RVLocs[i]; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 618 | |
| 619 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), OutVals[i], Flag); |
| 620 | |
| 621 | // Guarantee that all emitted copies are stuck together with flags. |
| 622 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 623 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 626 | RetOps[0] = Chain; // Update chain. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 627 | |
Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 628 | // Add the flag if we have it. |
| 629 | if (Flag.getNode()) |
| 630 | RetOps.push_back(Flag); |
| 631 | |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 632 | return DAG.getNode(HexagonISD::RET_FLAG, dl, MVT::Other, RetOps); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 635 | bool HexagonTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
| 636 | // 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] | 637 | auto Attr = |
| 638 | CI->getParent()->getParent()->getFnAttribute("disable-tail-calls"); |
| 639 | if (!CI->isTailCall() || Attr.getValueAsString() == "true") |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 640 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 641 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 642 | return true; |
| 643 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 644 | |
| 645 | /// LowerCallResult - Lower the result values of an ISD::CALL into the |
| 646 | /// appropriate copies out of appropriate physical registers. This assumes that |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 647 | /// Chain/Glue are the input chain/glue to use, and that TheCall is the call |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 648 | /// being lowered. Returns a SDNode with the same number of values as the |
| 649 | /// ISD::CALL. |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 650 | SDValue HexagonTargetLowering::LowerCallResult( |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 651 | SDValue Chain, SDValue Glue, CallingConv::ID CallConv, bool isVarArg, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 652 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, |
| 653 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals, |
| 654 | const SmallVectorImpl<SDValue> &OutVals, SDValue Callee) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 655 | // Assign locations to each value returned by this call. |
| 656 | SmallVector<CCValAssign, 16> RVLocs; |
| 657 | |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 658 | CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, |
| 659 | *DAG.getContext()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 660 | |
| 661 | CCInfo.AnalyzeCallResult(Ins, RetCC_Hexagon); |
| 662 | |
| 663 | // Copy all of the result registers out of their specified physreg. |
| 664 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 665 | SDValue RetVal; |
| 666 | if (RVLocs[i].getValVT() == MVT::i1) { |
| 667 | // Return values of type MVT::i1 require special handling. The reason |
| 668 | // is that MVT::i1 is associated with the PredRegs register class, but |
| 669 | // values of that type are still returned in R0. Generate an explicit |
| 670 | // copy into a predicate register from R0, and treat the value of the |
| 671 | // predicate register as the call result. |
| 672 | auto &MRI = DAG.getMachineFunction().getRegInfo(); |
| 673 | SDValue FR0 = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(), |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 674 | MVT::i32, Glue); |
Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 675 | // FR0 = (Value, Chain, Glue) |
| 676 | unsigned PredR = MRI.createVirtualRegister(&Hexagon::PredRegsRegClass); |
| 677 | SDValue TPR = DAG.getCopyToReg(FR0.getValue(1), dl, PredR, |
| 678 | FR0.getValue(0), FR0.getValue(2)); |
| 679 | // TPR = (Chain, Glue) |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 680 | // Don't glue this CopyFromReg, because it copies from a virtual |
| 681 | // register. If it is glued to the call, InstrEmitter will add it |
| 682 | // as an implicit def to the call (EmitMachineNode). |
| 683 | RetVal = DAG.getCopyFromReg(TPR.getValue(0), dl, PredR, MVT::i1); |
| 684 | Glue = TPR.getValue(1); |
Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 685 | } else { |
| 686 | RetVal = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(), |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 687 | RVLocs[i].getValVT(), Glue); |
| 688 | Glue = RetVal.getValue(2); |
Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 689 | } |
| 690 | InVals.push_back(RetVal.getValue(0)); |
| 691 | Chain = RetVal.getValue(1); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | return Chain; |
| 695 | } |
| 696 | |
| 697 | /// LowerCall - Functions arguments are copied from virtual regs to |
| 698 | /// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted. |
| 699 | SDValue |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 700 | HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 701 | SmallVectorImpl<SDValue> &InVals) const { |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 702 | SelectionDAG &DAG = CLI.DAG; |
Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 703 | SDLoc &dl = CLI.DL; |
| 704 | SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs; |
| 705 | SmallVectorImpl<SDValue> &OutVals = CLI.OutVals; |
| 706 | SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins; |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 707 | SDValue Chain = CLI.Chain; |
| 708 | SDValue Callee = CLI.Callee; |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 709 | bool &IsTailCall = CLI.IsTailCall; |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 710 | CallingConv::ID CallConv = CLI.CallConv; |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 711 | bool IsVarArg = CLI.IsVarArg; |
| 712 | bool DoesNotReturn = CLI.DoesNotReturn; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 713 | |
| 714 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 715 | MachineFunction &MF = DAG.getMachineFunction(); |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 716 | auto PtrVT = getPointerTy(MF.getDataLayout()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 717 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 718 | // Check for varargs. |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 719 | unsigned NumNamedVarArgParams = -1U; |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 720 | if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| 721 | const GlobalValue *GV = GAN->getGlobal(); |
| 722 | Callee = DAG.getTargetGlobalAddress(GV, dl, MVT::i32); |
| 723 | if (const Function* F = dyn_cast<Function>(GV)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 724 | // If a function has zero args and is a vararg function, that's |
| 725 | // disallowed so it must be an undeclared function. Do not assume |
| 726 | // varargs if the callee is undefined. |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 727 | if (F->isVarArg() && F->getFunctionType()->getNumParams() != 0) |
| 728 | NumNamedVarArgParams = F->getFunctionType()->getNumParams(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 729 | } |
| 730 | } |
| 731 | |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 732 | // Analyze operands of the call, assigning locations to each operand. |
| 733 | SmallVector<CCValAssign, 16> ArgLocs; |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 734 | HexagonCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs, |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 735 | *DAG.getContext(), NumNamedVarArgParams); |
Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 736 | |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 737 | if (IsVarArg) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 738 | CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_VarArg); |
| 739 | else |
| 740 | CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon); |
| 741 | |
Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 742 | auto Attr = MF.getFunction()->getFnAttribute("disable-tail-calls"); |
| 743 | if (Attr.getValueAsString() == "true") |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 744 | IsTailCall = false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 745 | |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 746 | if (IsTailCall) { |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 747 | bool StructAttrFlag = MF.getFunction()->hasStructRetAttr(); |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 748 | IsTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 749 | IsVarArg, IsStructRet, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 750 | StructAttrFlag, |
| 751 | Outs, OutVals, Ins, DAG); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 752 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 753 | CCValAssign &VA = ArgLocs[i]; |
| 754 | if (VA.isMemLoc()) { |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 755 | IsTailCall = false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 756 | break; |
| 757 | } |
| 758 | } |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 759 | DEBUG(dbgs() << (IsTailCall ? "Eligible for Tail Call\n" |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 760 | : "Argument must be passed on stack. " |
| 761 | "Not eligible for Tail Call\n")); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 762 | } |
| 763 | // Get a count of how many bytes are to be pushed on the stack. |
| 764 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
| 765 | SmallVector<std::pair<unsigned, SDValue>, 16> RegsToPass; |
| 766 | SmallVector<SDValue, 8> MemOpChains; |
| 767 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 768 | auto &HRI = *Subtarget.getRegisterInfo(); |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 769 | SDValue StackPtr = |
| 770 | DAG.getCopyFromReg(Chain, dl, HRI.getStackRegister(), PtrVT); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 771 | |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 772 | bool NeedsArgAlign = false; |
| 773 | unsigned LargestAlignSeen = 0; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 774 | // Walk the register/memloc assignments, inserting copies/loads. |
| 775 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 776 | CCValAssign &VA = ArgLocs[i]; |
| 777 | SDValue Arg = OutVals[i]; |
| 778 | ISD::ArgFlagsTy Flags = Outs[i].Flags; |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 779 | // Record if we need > 8 byte alignment on an argument. |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 780 | bool ArgAlign = isHvxVectorType(VA.getValVT()); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 781 | NeedsArgAlign |= ArgAlign; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 782 | |
| 783 | // Promote the value if needed. |
| 784 | switch (VA.getLocInfo()) { |
| 785 | default: |
| 786 | // Loc info must be one of Full, SExt, ZExt, or AExt. |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 787 | llvm_unreachable("Unknown loc info!"); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 788 | case CCValAssign::BCvt: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 789 | case CCValAssign::Full: |
| 790 | break; |
| 791 | case CCValAssign::SExt: |
| 792 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 793 | break; |
| 794 | case CCValAssign::ZExt: |
| 795 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 796 | break; |
| 797 | case CCValAssign::AExt: |
| 798 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 799 | break; |
| 800 | } |
| 801 | |
| 802 | if (VA.isMemLoc()) { |
| 803 | unsigned LocMemOffset = VA.getLocMemOffset(); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 804 | SDValue MemAddr = DAG.getConstant(LocMemOffset, dl, |
| 805 | StackPtr.getValueType()); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 806 | MemAddr = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, MemAddr); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 807 | if (ArgAlign) |
| 808 | LargestAlignSeen = std::max(LargestAlignSeen, |
| 809 | VA.getLocVT().getStoreSizeInBits() >> 3); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 810 | if (Flags.isByVal()) { |
| 811 | // The argument is a struct passed by value. According to LLVM, "Arg" |
| 812 | // is is pointer. |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 813 | MemOpChains.push_back(CreateCopyOfByValArgument(Arg, MemAddr, Chain, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 814 | Flags, DAG, dl)); |
| 815 | } else { |
Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 816 | MachinePointerInfo LocPI = MachinePointerInfo::getStack( |
| 817 | DAG.getMachineFunction(), LocMemOffset); |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 818 | SDValue S = DAG.getStore(Chain, dl, Arg, MemAddr, LocPI); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 819 | MemOpChains.push_back(S); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 820 | } |
| 821 | continue; |
| 822 | } |
| 823 | |
| 824 | // Arguments that can be passed on register must be kept at RegsToPass |
| 825 | // vector. |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 826 | if (VA.isRegLoc()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 827 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 830 | if (NeedsArgAlign && Subtarget.hasV60TOps()) { |
| 831 | DEBUG(dbgs() << "Function needs byte stack align due to call args\n"); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 832 | MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 833 | // V6 vectors passed by value have 64 or 128 byte alignment depending |
| 834 | // on whether we are 64 byte vector mode or 128 byte. |
| 835 | bool UseHVXDbl = Subtarget.useHVXDblOps(); |
| 836 | assert(Subtarget.useHVXOps()); |
| 837 | const unsigned ObjAlign = UseHVXDbl ? 128 : 64; |
| 838 | LargestAlignSeen = std::max(LargestAlignSeen, ObjAlign); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 839 | MFI.ensureMaxAlignment(LargestAlignSeen); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 840 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 841 | // Transform all store nodes into one single node because all store |
| 842 | // nodes are independent of each other. |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 843 | if (!MemOpChains.empty()) |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 844 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 845 | |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 846 | SDValue Glue; |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 847 | if (!IsTailCall) { |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 848 | SDValue C = DAG.getConstant(NumBytes, dl, PtrVT, true); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 849 | Chain = DAG.getCALLSEQ_START(Chain, C, dl); |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 850 | Glue = Chain.getValue(1); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 851 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 852 | |
| 853 | // Build a sequence of copy-to-reg nodes chained together with token |
| 854 | // chain and flag operands which copy the outgoing args into registers. |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 855 | // The Glue is necessary since all emitted instructions must be |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 856 | // stuck together. |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 857 | if (!IsTailCall) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 858 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 859 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 860 | RegsToPass[i].second, Glue); |
| 861 | Glue = Chain.getValue(1); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 862 | } |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 863 | } else { |
| 864 | // For tail calls lower the arguments to the 'real' stack slot. |
| 865 | // |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 866 | // Force all the incoming stack arguments to be loaded from the stack |
| 867 | // before any new outgoing arguments are stored to the stack, because the |
| 868 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 869 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 870 | // than necessary, because it means that each store effectively depends |
| 871 | // on every argument instead of just those arguments it would clobber. |
| 872 | // |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 873 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 874 | Glue = SDValue(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 875 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 876 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 877 | RegsToPass[i].second, Glue); |
| 878 | Glue = Chain.getValue(1); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 879 | } |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 880 | Glue = SDValue(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 881 | } |
| 882 | |
Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 883 | bool LongCalls = MF.getSubtarget<HexagonSubtarget>().useLongCalls(); |
| 884 | unsigned Flags = LongCalls ? HexagonII::HMOTF_ConstExtended : 0; |
| 885 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 886 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 887 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 888 | // node so that legalize doesn't hack it. |
Tobias Edler von Koch | b51460c | 2015-12-16 17:29:37 +0000 | [diff] [blame] | 889 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 890 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, PtrVT, 0, Flags); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 891 | } else if (ExternalSymbolSDNode *S = |
| 892 | dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 893 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), PtrVT, Flags); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | // Returns a chain & a flag for retval copy to use. |
| 897 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| 898 | SmallVector<SDValue, 8> Ops; |
| 899 | Ops.push_back(Chain); |
| 900 | Ops.push_back(Callee); |
| 901 | |
| 902 | // Add argument registers to the end of the list so that they are |
| 903 | // known live into the call. |
| 904 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 905 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 906 | RegsToPass[i].second.getValueType())); |
| 907 | } |
| 908 | |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 909 | const uint32_t *Mask = HRI.getCallPreservedMask(MF, CallConv); |
| 910 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 911 | Ops.push_back(DAG.getRegisterMask(Mask)); |
| 912 | |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 913 | if (Glue.getNode()) |
| 914 | Ops.push_back(Glue); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 915 | |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 916 | if (IsTailCall) { |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 917 | MF.getFrameInfo().setHasTailCall(); |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 918 | return DAG.getNode(HexagonISD::TC_RETURN, dl, NodeTys, Ops); |
Arnold Schwaighofer | f54b73d | 2015-05-08 23:52:00 +0000 | [diff] [blame] | 919 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 920 | |
Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 921 | unsigned OpCode = DoesNotReturn ? HexagonISD::CALLnr : HexagonISD::CALL; |
Colin LeMahieu | 2e3a26d | 2015-01-16 17:05:27 +0000 | [diff] [blame] | 922 | Chain = DAG.getNode(OpCode, dl, NodeTys, Ops); |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 923 | Glue = Chain.getValue(1); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 924 | |
| 925 | // Create the CALLSEQ_END node. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 926 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, dl, true), |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 927 | DAG.getIntPtrConstant(0, dl, true), Glue, dl); |
| 928 | Glue = Chain.getValue(1); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 929 | |
| 930 | // Handle result values, copying them out of physregs into vregs that we |
| 931 | // return. |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 932 | return LowerCallResult(Chain, Glue, CallConv, IsVarArg, Ins, dl, DAG, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 933 | InVals, OutVals, Callee); |
| 934 | } |
| 935 | |
| 936 | static bool getIndexedAddressParts(SDNode *Ptr, EVT VT, |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 937 | SDValue &Base, SDValue &Offset, |
| 938 | bool &IsInc, SelectionDAG &DAG) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 939 | if (Ptr->getOpcode() != ISD::ADD) |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 940 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 941 | |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 942 | auto &HST = static_cast<const HexagonSubtarget&>(DAG.getSubtarget()); |
| 943 | bool UseHVX = HST.useHVXOps(); |
| 944 | bool UseHVXDbl = HST.useHVXDblOps(); |
| 945 | |
| 946 | bool ValidHVXDblType = |
| 947 | (UseHVX && UseHVXDbl) && (VT == MVT::v32i32 || VT == MVT::v16i64 || |
| 948 | VT == MVT::v64i16 || VT == MVT::v128i8); |
| 949 | bool ValidHVXType = |
| 950 | UseHVX && !UseHVXDbl && (VT == MVT::v16i32 || VT == MVT::v8i64 || |
| 951 | VT == MVT::v32i16 || VT == MVT::v64i8); |
| 952 | |
| 953 | if (ValidHVXDblType || ValidHVXType || |
| 954 | VT == MVT::i64 || VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8) { |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 955 | IsInc = (Ptr->getOpcode() == ISD::ADD); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 956 | Base = Ptr->getOperand(0); |
| 957 | Offset = Ptr->getOperand(1); |
| 958 | // Ensure that Offset is a constant. |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 959 | return isa<ConstantSDNode>(Offset); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | return false; |
| 963 | } |
| 964 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 965 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 966 | /// offset pointer and addressing mode by reference if this node can be |
| 967 | /// combined with a load / store to form a post-indexed load / store. |
| 968 | bool HexagonTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
| 969 | SDValue &Base, |
| 970 | SDValue &Offset, |
| 971 | ISD::MemIndexedMode &AM, |
| 972 | SelectionDAG &DAG) const |
| 973 | { |
| 974 | EVT VT; |
| 975 | SDValue Ptr; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 976 | |
| 977 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 978 | VT = LD->getMemoryVT(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 979 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 980 | VT = ST->getMemoryVT(); |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 981 | if (ST->getValue().getValueType() == MVT::i64 && ST->isTruncatingStore()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 982 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 983 | } else { |
| 984 | return false; |
| 985 | } |
| 986 | |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 987 | bool IsInc = false; |
| 988 | bool isLegal = getIndexedAddressParts(Op, VT, Base, Offset, IsInc, DAG); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 989 | if (isLegal) { |
| 990 | auto &HII = *Subtarget.getInstrInfo(); |
| 991 | int32_t OffsetVal = cast<ConstantSDNode>(Offset.getNode())->getSExtValue(); |
| 992 | if (HII.isValidAutoIncImm(VT, OffsetVal)) { |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 993 | AM = IsInc ? ISD::POST_INC : ISD::POST_DEC; |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 994 | return true; |
| 995 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | return false; |
| 999 | } |
| 1000 | |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1001 | SDValue |
| 1002 | HexagonTargetLowering::LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1003 | SDNode *Node = Op.getNode(); |
| 1004 | MachineFunction &MF = DAG.getMachineFunction(); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1005 | auto &FuncInfo = *MF.getInfo<HexagonMachineFunctionInfo>(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1006 | switch (Node->getOpcode()) { |
| 1007 | case ISD::INLINEASM: { |
| 1008 | unsigned NumOps = Node->getNumOperands(); |
| 1009 | if (Node->getOperand(NumOps-1).getValueType() == MVT::Glue) |
| 1010 | --NumOps; // Ignore the flag operand. |
| 1011 | |
| 1012 | for (unsigned i = InlineAsm::Op_FirstOperand; i != NumOps;) { |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1013 | if (FuncInfo.hasClobberLR()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1014 | break; |
| 1015 | unsigned Flags = |
| 1016 | cast<ConstantSDNode>(Node->getOperand(i))->getZExtValue(); |
| 1017 | unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags); |
| 1018 | ++i; // Skip the ID value. |
| 1019 | |
| 1020 | switch (InlineAsm::getKind(Flags)) { |
| 1021 | default: llvm_unreachable("Bad flags!"); |
| 1022 | case InlineAsm::Kind_RegDef: |
| 1023 | case InlineAsm::Kind_RegUse: |
| 1024 | case InlineAsm::Kind_Imm: |
| 1025 | case InlineAsm::Kind_Clobber: |
| 1026 | case InlineAsm::Kind_Mem: { |
| 1027 | for (; NumVals; --NumVals, ++i) {} |
| 1028 | break; |
| 1029 | } |
| 1030 | case InlineAsm::Kind_RegDefEarlyClobber: { |
| 1031 | for (; NumVals; --NumVals, ++i) { |
| 1032 | unsigned Reg = |
| 1033 | cast<RegisterSDNode>(Node->getOperand(i))->getReg(); |
| 1034 | |
| 1035 | // Check it to be lr |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1036 | const HexagonRegisterInfo *QRI = Subtarget.getRegisterInfo(); |
Eric Christopher | dbe1cb0 | 2014-06-27 00:13:52 +0000 | [diff] [blame] | 1037 | if (Reg == QRI->getRARegister()) { |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1038 | FuncInfo.setHasClobberLR(true); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1039 | break; |
| 1040 | } |
| 1041 | } |
| 1042 | break; |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | } |
| 1047 | } // Node->getOpcode |
| 1048 | return Op; |
| 1049 | } |
| 1050 | |
Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 1051 | // Need to transform ISD::PREFETCH into something that doesn't inherit |
| 1052 | // all of the properties of ISD::PREFETCH, specifically SDNPMayLoad and |
| 1053 | // SDNPMayStore. |
| 1054 | SDValue HexagonTargetLowering::LowerPREFETCH(SDValue Op, |
| 1055 | SelectionDAG &DAG) const { |
| 1056 | SDValue Chain = Op.getOperand(0); |
| 1057 | SDValue Addr = Op.getOperand(1); |
| 1058 | // Lower it to DCFETCH($reg, #0). A "pat" will try to merge the offset in, |
| 1059 | // if the "reg" is fed by an "add". |
| 1060 | SDLoc DL(Op); |
| 1061 | SDValue Zero = DAG.getConstant(0, DL, MVT::i32); |
| 1062 | return DAG.getNode(HexagonISD::DCFETCH, DL, MVT::Other, Chain, Addr, Zero); |
| 1063 | } |
| 1064 | |
| 1065 | SDValue HexagonTargetLowering::LowerINTRINSIC_VOID(SDValue Op, |
| 1066 | SelectionDAG &DAG) const { |
| 1067 | SDValue Chain = Op.getOperand(0); |
| 1068 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 1069 | // Lower the hexagon_prefetch builtin to DCFETCH, as above. |
| 1070 | if (IntNo == Intrinsic::hexagon_prefetch) { |
| 1071 | SDValue Addr = Op.getOperand(2); |
| 1072 | SDLoc DL(Op); |
| 1073 | SDValue Zero = DAG.getConstant(0, DL, MVT::i32); |
| 1074 | return DAG.getNode(HexagonISD::DCFETCH, DL, MVT::Other, Chain, Addr, Zero); |
| 1075 | } |
| 1076 | return SDValue(); |
| 1077 | } |
| 1078 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1079 | SDValue |
| 1080 | HexagonTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, |
| 1081 | SelectionDAG &DAG) const { |
| 1082 | SDValue Chain = Op.getOperand(0); |
| 1083 | SDValue Size = Op.getOperand(1); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1084 | SDValue Align = Op.getOperand(2); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1085 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1086 | |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1087 | ConstantSDNode *AlignConst = dyn_cast<ConstantSDNode>(Align); |
| 1088 | assert(AlignConst && "Non-constant Align in LowerDYNAMIC_STACKALLOC"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1089 | |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1090 | unsigned A = AlignConst->getSExtValue(); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1091 | auto &HFI = *Subtarget.getFrameLowering(); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1092 | // "Zero" means natural stack alignment. |
| 1093 | if (A == 0) |
| 1094 | A = HFI.getStackAlignment(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1095 | |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1096 | DEBUG({ |
Reid Kleckner | 40d7230 | 2016-10-20 00:22:23 +0000 | [diff] [blame] | 1097 | dbgs () << __func__ << " Align: " << A << " Size: "; |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1098 | Size.getNode()->dump(&DAG); |
| 1099 | dbgs() << "\n"; |
| 1100 | }); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1101 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1102 | SDValue AC = DAG.getConstant(A, dl, MVT::i32); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1103 | SDVTList VTs = DAG.getVTList(MVT::i32, MVT::Other); |
Krzysztof Parzyszek | 23920ec | 2015-10-19 18:30:27 +0000 | [diff] [blame] | 1104 | SDValue AA = DAG.getNode(HexagonISD::ALLOCA, dl, VTs, Chain, Size, AC); |
Nirav Dave | bfdb483 | 2016-06-23 17:52:57 +0000 | [diff] [blame] | 1105 | |
| 1106 | DAG.ReplaceAllUsesOfValueWith(Op, AA); |
Krzysztof Parzyszek | 23920ec | 2015-10-19 18:30:27 +0000 | [diff] [blame] | 1107 | return AA; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 1110 | SDValue HexagonTargetLowering::LowerFormalArguments( |
| 1111 | SDValue Chain, CallingConv::ID CallConv, bool isVarArg, |
| 1112 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, |
| 1113 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1114 | MachineFunction &MF = DAG.getMachineFunction(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1115 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1116 | MachineRegisterInfo &RegInfo = MF.getRegInfo(); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1117 | auto &FuncInfo = *MF.getInfo<HexagonMachineFunctionInfo>(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1118 | |
| 1119 | // Assign locations to all of the incoming arguments. |
| 1120 | SmallVector<CCValAssign, 16> ArgLocs; |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 1121 | CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs, |
| 1122 | *DAG.getContext()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1123 | |
| 1124 | CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon); |
| 1125 | |
| 1126 | // For LLVM, in the case when returning a struct by value (>8byte), |
| 1127 | // the first argument is a pointer that points to the location on caller's |
| 1128 | // stack where the return value will be stored. For Hexagon, the location on |
| 1129 | // caller's stack is passed only when the struct size is smaller than (and |
| 1130 | // equal to) 8 bytes. If not, no address will be passed into callee and |
| 1131 | // callee return the result direclty through R0/R1. |
| 1132 | |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1133 | SmallVector<SDValue, 8> MemOps; |
| 1134 | bool UseHVX = Subtarget.useHVXOps(), UseHVXDbl = Subtarget.useHVXDblOps(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1135 | |
| 1136 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1137 | CCValAssign &VA = ArgLocs[i]; |
| 1138 | ISD::ArgFlagsTy Flags = Ins[i].Flags; |
| 1139 | unsigned ObjSize; |
| 1140 | unsigned StackLocation; |
| 1141 | int FI; |
| 1142 | |
| 1143 | if ( (VA.isRegLoc() && !Flags.isByVal()) |
| 1144 | || (VA.isRegLoc() && Flags.isByVal() && Flags.getByValSize() > 8)) { |
| 1145 | // Arguments passed in registers |
| 1146 | // 1. int, long long, ptr args that get allocated in register. |
| 1147 | // 2. Large struct that gets an register to put its address in. |
| 1148 | EVT RegVT = VA.getLocVT(); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1149 | if (RegVT == MVT::i8 || RegVT == MVT::i16 || |
| 1150 | RegVT == MVT::i32 || RegVT == MVT::f32) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1151 | unsigned VReg = |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1152 | RegInfo.createVirtualRegister(&Hexagon::IntRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1153 | RegInfo.addLiveIn(VA.getLocReg(), VReg); |
| 1154 | InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT)); |
Colin LeMahieu | 4379d10 | 2015-01-28 22:08:16 +0000 | [diff] [blame] | 1155 | } else if (RegVT == MVT::i64 || RegVT == MVT::f64) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1156 | unsigned VReg = |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1157 | RegInfo.createVirtualRegister(&Hexagon::DoubleRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1158 | RegInfo.addLiveIn(VA.getLocReg(), VReg); |
| 1159 | InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT)); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1160 | |
| 1161 | // Single Vector |
| 1162 | } else if ((RegVT == MVT::v8i64 || RegVT == MVT::v16i32 || |
| 1163 | RegVT == MVT::v32i16 || RegVT == MVT::v64i8)) { |
| 1164 | unsigned VReg = |
| 1165 | RegInfo.createVirtualRegister(&Hexagon::VectorRegsRegClass); |
| 1166 | RegInfo.addLiveIn(VA.getLocReg(), VReg); |
| 1167 | InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT)); |
| 1168 | } else if (UseHVX && UseHVXDbl && |
| 1169 | ((RegVT == MVT::v16i64 || RegVT == MVT::v32i32 || |
| 1170 | RegVT == MVT::v64i16 || RegVT == MVT::v128i8))) { |
| 1171 | unsigned VReg = |
| 1172 | RegInfo.createVirtualRegister(&Hexagon::VectorRegs128BRegClass); |
| 1173 | RegInfo.addLiveIn(VA.getLocReg(), VReg); |
| 1174 | InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT)); |
| 1175 | |
| 1176 | // Double Vector |
| 1177 | } else if ((RegVT == MVT::v16i64 || RegVT == MVT::v32i32 || |
| 1178 | RegVT == MVT::v64i16 || RegVT == MVT::v128i8)) { |
| 1179 | unsigned VReg = |
| 1180 | RegInfo.createVirtualRegister(&Hexagon::VecDblRegsRegClass); |
| 1181 | RegInfo.addLiveIn(VA.getLocReg(), VReg); |
| 1182 | InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT)); |
| 1183 | } else if (UseHVX && UseHVXDbl && |
| 1184 | ((RegVT == MVT::v32i64 || RegVT == MVT::v64i32 || |
| 1185 | RegVT == MVT::v128i16 || RegVT == MVT::v256i8))) { |
| 1186 | unsigned VReg = |
| 1187 | RegInfo.createVirtualRegister(&Hexagon::VecDblRegs128BRegClass); |
| 1188 | RegInfo.addLiveIn(VA.getLocReg(), VReg); |
| 1189 | InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT)); |
| 1190 | } else if (RegVT == MVT::v512i1 || RegVT == MVT::v1024i1) { |
| 1191 | assert(0 && "need to support VecPred regs"); |
| 1192 | unsigned VReg = |
| 1193 | RegInfo.createVirtualRegister(&Hexagon::VecPredRegsRegClass); |
| 1194 | RegInfo.addLiveIn(VA.getLocReg(), VReg); |
| 1195 | InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1196 | } else { |
| 1197 | assert (0); |
| 1198 | } |
| 1199 | } else if (VA.isRegLoc() && Flags.isByVal() && Flags.getByValSize() <= 8) { |
| 1200 | assert (0 && "ByValSize must be bigger than 8 bytes"); |
| 1201 | } else { |
| 1202 | // Sanity check. |
| 1203 | assert(VA.isMemLoc()); |
| 1204 | |
| 1205 | if (Flags.isByVal()) { |
| 1206 | // If it's a byval parameter, then we need to compute the |
| 1207 | // "real" size, not the size of the pointer. |
| 1208 | ObjSize = Flags.getByValSize(); |
| 1209 | } else { |
| 1210 | ObjSize = VA.getLocVT().getStoreSizeInBits() >> 3; |
| 1211 | } |
| 1212 | |
| 1213 | StackLocation = HEXAGON_LRFP_SIZE + VA.getLocMemOffset(); |
| 1214 | // Create the frame index object for this incoming parameter... |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1215 | FI = MFI.CreateFixedObject(ObjSize, StackLocation, true); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1216 | |
| 1217 | // Create the SelectionDAG nodes cordl, responding to a load |
| 1218 | // from this parameter. |
| 1219 | SDValue FIN = DAG.getFrameIndex(FI, MVT::i32); |
| 1220 | |
| 1221 | if (Flags.isByVal()) { |
| 1222 | // If it's a pass-by-value aggregate, then do not dereference the stack |
| 1223 | // location. Instead, we should generate a reference to the stack |
| 1224 | // location. |
| 1225 | InVals.push_back(FIN); |
| 1226 | } else { |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1227 | InVals.push_back( |
| 1228 | DAG.getLoad(VA.getLocVT(), dl, Chain, FIN, MachinePointerInfo())); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1229 | } |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | if (!MemOps.empty()) |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1234 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOps); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1235 | |
| 1236 | if (isVarArg) { |
| 1237 | // This will point to the next argument passed via stack. |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1238 | int FrameIndex = MFI.CreateFixedObject(Hexagon_PointerSize, |
| 1239 | HEXAGON_LRFP_SIZE + |
| 1240 | CCInfo.getNextStackOffset(), |
| 1241 | true); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1242 | FuncInfo.setVarArgsFrameIndex(FrameIndex); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | return Chain; |
| 1246 | } |
| 1247 | |
| 1248 | SDValue |
| 1249 | HexagonTargetLowering::LowerVASTART(SDValue Op, SelectionDAG &DAG) const { |
| 1250 | // VASTART stores the address of the VarArgsFrameIndex slot into the |
| 1251 | // memory location argument. |
| 1252 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1253 | HexagonMachineFunctionInfo *QFI = MF.getInfo<HexagonMachineFunctionInfo>(); |
| 1254 | SDValue Addr = DAG.getFrameIndex(QFI->getVarArgsFrameIndex(), MVT::i32); |
| 1255 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1256 | return DAG.getStore(Op.getOperand(0), SDLoc(Op), Addr, Op.getOperand(1), |
| 1257 | MachinePointerInfo(SV)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1260 | // Creates a SPLAT instruction for a constant value VAL. |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 1261 | static SDValue createSplat(SelectionDAG &DAG, const SDLoc &dl, EVT VT, |
| 1262 | SDValue Val) { |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1263 | if (VT.getSimpleVT() == MVT::v4i8) |
| 1264 | return DAG.getNode(HexagonISD::VSPLATB, dl, VT, Val); |
| 1265 | |
| 1266 | if (VT.getSimpleVT() == MVT::v4i16) |
| 1267 | return DAG.getNode(HexagonISD::VSPLATH, dl, VT, Val); |
| 1268 | |
| 1269 | return SDValue(); |
| 1270 | } |
| 1271 | |
| 1272 | static bool isSExtFree(SDValue N) { |
| 1273 | // A sign-extend of a truncate of a sign-extend is free. |
| 1274 | if (N.getOpcode() == ISD::TRUNCATE && |
| 1275 | N.getOperand(0).getOpcode() == ISD::AssertSext) |
| 1276 | return true; |
| 1277 | // We have sign-extended loads. |
| 1278 | if (N.getOpcode() == ISD::LOAD) |
| 1279 | return true; |
| 1280 | return false; |
| 1281 | } |
| 1282 | |
| 1283 | SDValue HexagonTargetLowering::LowerCTPOP(SDValue Op, SelectionDAG &DAG) const { |
| 1284 | SDLoc dl(Op); |
| 1285 | SDValue InpVal = Op.getOperand(0); |
| 1286 | if (isa<ConstantSDNode>(InpVal)) { |
| 1287 | uint64_t V = cast<ConstantSDNode>(InpVal)->getZExtValue(); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1288 | return DAG.getTargetConstant(countPopulation(V), dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1289 | } |
| 1290 | SDValue PopOut = DAG.getNode(HexagonISD::POPCOUNT, dl, MVT::i32, InpVal); |
| 1291 | return DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i64, PopOut); |
| 1292 | } |
| 1293 | |
| 1294 | SDValue HexagonTargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) const { |
| 1295 | SDLoc dl(Op); |
| 1296 | |
| 1297 | SDValue LHS = Op.getOperand(0); |
| 1298 | SDValue RHS = Op.getOperand(1); |
| 1299 | SDValue Cmp = Op.getOperand(2); |
| 1300 | ISD::CondCode CC = cast<CondCodeSDNode>(Cmp)->get(); |
| 1301 | |
| 1302 | EVT VT = Op.getValueType(); |
| 1303 | EVT LHSVT = LHS.getValueType(); |
| 1304 | EVT RHSVT = RHS.getValueType(); |
| 1305 | |
| 1306 | if (LHSVT == MVT::v2i16) { |
| 1307 | assert(ISD::isSignedIntSetCC(CC) || ISD::isUnsignedIntSetCC(CC)); |
| 1308 | unsigned ExtOpc = ISD::isSignedIntSetCC(CC) ? ISD::SIGN_EXTEND |
| 1309 | : ISD::ZERO_EXTEND; |
| 1310 | SDValue LX = DAG.getNode(ExtOpc, dl, MVT::v2i32, LHS); |
| 1311 | SDValue RX = DAG.getNode(ExtOpc, dl, MVT::v2i32, RHS); |
| 1312 | SDValue SC = DAG.getNode(ISD::SETCC, dl, MVT::v2i1, LX, RX, Cmp); |
| 1313 | return SC; |
| 1314 | } |
| 1315 | |
| 1316 | // Treat all other vector types as legal. |
| 1317 | if (VT.isVector()) |
| 1318 | return Op; |
| 1319 | |
| 1320 | // Equals and not equals should use sign-extend, not zero-extend, since |
| 1321 | // we can represent small negative values in the compare instructions. |
| 1322 | // The LLVM default is to use zero-extend arbitrarily in these cases. |
| 1323 | if ((CC == ISD::SETEQ || CC == ISD::SETNE) && |
| 1324 | (RHSVT == MVT::i8 || RHSVT == MVT::i16) && |
| 1325 | (LHSVT == MVT::i8 || LHSVT == MVT::i16)) { |
| 1326 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHS); |
| 1327 | if (C && C->getAPIntValue().isNegative()) { |
| 1328 | LHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, LHS); |
| 1329 | RHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, RHS); |
| 1330 | return DAG.getNode(ISD::SETCC, dl, Op.getValueType(), |
| 1331 | LHS, RHS, Op.getOperand(2)); |
| 1332 | } |
| 1333 | if (isSExtFree(LHS) || isSExtFree(RHS)) { |
| 1334 | LHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, LHS); |
| 1335 | RHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, RHS); |
| 1336 | return DAG.getNode(ISD::SETCC, dl, Op.getValueType(), |
| 1337 | LHS, RHS, Op.getOperand(2)); |
| 1338 | } |
| 1339 | } |
| 1340 | return SDValue(); |
| 1341 | } |
| 1342 | |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1343 | SDValue |
| 1344 | HexagonTargetLowering::LowerVSELECT(SDValue Op, SelectionDAG &DAG) const { |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1345 | SDValue PredOp = Op.getOperand(0); |
| 1346 | SDValue Op1 = Op.getOperand(1), Op2 = Op.getOperand(2); |
| 1347 | EVT OpVT = Op1.getValueType(); |
| 1348 | SDLoc DL(Op); |
| 1349 | |
| 1350 | if (OpVT == MVT::v2i16) { |
| 1351 | SDValue X1 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v2i32, Op1); |
| 1352 | SDValue X2 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v2i32, Op2); |
| 1353 | SDValue SL = DAG.getNode(ISD::VSELECT, DL, MVT::v2i32, PredOp, X1, X2); |
| 1354 | SDValue TR = DAG.getNode(ISD::TRUNCATE, DL, MVT::v2i16, SL); |
| 1355 | return TR; |
| 1356 | } |
| 1357 | |
| 1358 | return SDValue(); |
| 1359 | } |
| 1360 | |
| 1361 | // Handle only specific vector loads. |
| 1362 | SDValue HexagonTargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const { |
| 1363 | EVT VT = Op.getValueType(); |
| 1364 | SDLoc DL(Op); |
| 1365 | LoadSDNode *LoadNode = cast<LoadSDNode>(Op); |
| 1366 | SDValue Chain = LoadNode->getChain(); |
| 1367 | SDValue Ptr = Op.getOperand(1); |
| 1368 | SDValue LoweredLoad; |
| 1369 | SDValue Result; |
| 1370 | SDValue Base = LoadNode->getBasePtr(); |
| 1371 | ISD::LoadExtType Ext = LoadNode->getExtensionType(); |
| 1372 | unsigned Alignment = LoadNode->getAlignment(); |
| 1373 | SDValue LoadChain; |
| 1374 | |
| 1375 | if(Ext == ISD::NON_EXTLOAD) |
| 1376 | Ext = ISD::ZEXTLOAD; |
| 1377 | |
| 1378 | if (VT == MVT::v4i16) { |
| 1379 | if (Alignment == 2) { |
| 1380 | SDValue Loads[4]; |
| 1381 | // Base load. |
| 1382 | Loads[0] = DAG.getExtLoad(Ext, DL, MVT::i32, Chain, Base, |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1383 | LoadNode->getPointerInfo(), MVT::i16, Alignment, |
| 1384 | LoadNode->getMemOperand()->getFlags()); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1385 | // Base+2 load. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1386 | SDValue Increment = DAG.getConstant(2, DL, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1387 | Ptr = DAG.getNode(ISD::ADD, DL, Base.getValueType(), Base, Increment); |
| 1388 | Loads[1] = DAG.getExtLoad(Ext, DL, MVT::i32, Chain, Ptr, |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1389 | LoadNode->getPointerInfo(), MVT::i16, Alignment, |
| 1390 | LoadNode->getMemOperand()->getFlags()); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1391 | // SHL 16, then OR base and base+2. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1392 | SDValue ShiftAmount = DAG.getConstant(16, DL, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1393 | SDValue Tmp1 = DAG.getNode(ISD::SHL, DL, MVT::i32, Loads[1], ShiftAmount); |
| 1394 | SDValue Tmp2 = DAG.getNode(ISD::OR, DL, MVT::i32, Tmp1, Loads[0]); |
| 1395 | // Base + 4. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1396 | Increment = DAG.getConstant(4, DL, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1397 | Ptr = DAG.getNode(ISD::ADD, DL, Base.getValueType(), Base, Increment); |
| 1398 | Loads[2] = DAG.getExtLoad(Ext, DL, MVT::i32, Chain, Ptr, |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1399 | LoadNode->getPointerInfo(), MVT::i16, Alignment, |
| 1400 | LoadNode->getMemOperand()->getFlags()); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1401 | // Base + 6. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1402 | Increment = DAG.getConstant(6, DL, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1403 | Ptr = DAG.getNode(ISD::ADD, DL, Base.getValueType(), Base, Increment); |
| 1404 | Loads[3] = DAG.getExtLoad(Ext, DL, MVT::i32, Chain, Ptr, |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1405 | LoadNode->getPointerInfo(), MVT::i16, Alignment, |
| 1406 | LoadNode->getMemOperand()->getFlags()); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1407 | // SHL 16, then OR base+4 and base+6. |
| 1408 | Tmp1 = DAG.getNode(ISD::SHL, DL, MVT::i32, Loads[3], ShiftAmount); |
| 1409 | SDValue Tmp4 = DAG.getNode(ISD::OR, DL, MVT::i32, Tmp1, Loads[2]); |
| 1410 | // Combine to i64. This could be optimised out later if we can |
| 1411 | // affect reg allocation of this code. |
| 1412 | Result = DAG.getNode(HexagonISD::COMBINE, DL, MVT::i64, Tmp4, Tmp2); |
| 1413 | LoadChain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, |
| 1414 | Loads[0].getValue(1), Loads[1].getValue(1), |
| 1415 | Loads[2].getValue(1), Loads[3].getValue(1)); |
| 1416 | } else { |
| 1417 | // Perform default type expansion. |
| 1418 | Result = DAG.getLoad(MVT::i64, DL, Chain, Ptr, LoadNode->getPointerInfo(), |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1419 | LoadNode->getAlignment(), |
| 1420 | LoadNode->getMemOperand()->getFlags()); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1421 | LoadChain = Result.getValue(1); |
| 1422 | } |
| 1423 | } else |
| 1424 | llvm_unreachable("Custom lowering unsupported load"); |
| 1425 | |
| 1426 | Result = DAG.getNode(ISD::BITCAST, DL, VT, Result); |
| 1427 | // Since we pretend to lower a load, we need the original chain |
| 1428 | // info attached to the result. |
| 1429 | SDValue Ops[] = { Result, LoadChain }; |
| 1430 | |
| 1431 | return DAG.getMergeValues(Ops, DL); |
| 1432 | } |
| 1433 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1434 | SDValue |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1435 | HexagonTargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) const { |
| 1436 | EVT ValTy = Op.getValueType(); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1437 | ConstantPoolSDNode *CPN = cast<ConstantPoolSDNode>(Op); |
| 1438 | unsigned Align = CPN->getAlignment(); |
Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 1439 | bool IsPositionIndependent = isPositionIndependent(); |
| 1440 | unsigned char TF = IsPositionIndependent ? HexagonII::MO_PCREL : 0; |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1441 | |
Ron Lieberman | 822ee88 | 2016-08-13 23:41:11 +0000 | [diff] [blame] | 1442 | unsigned Offset = 0; |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1443 | SDValue T; |
| 1444 | if (CPN->isMachineConstantPoolEntry()) |
Ron Lieberman | 822ee88 | 2016-08-13 23:41:11 +0000 | [diff] [blame] | 1445 | T = DAG.getTargetConstantPool(CPN->getMachineCPVal(), ValTy, Align, Offset, |
| 1446 | TF); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1447 | else |
Ron Lieberman | 822ee88 | 2016-08-13 23:41:11 +0000 | [diff] [blame] | 1448 | T = DAG.getTargetConstantPool(CPN->getConstVal(), ValTy, Align, Offset, |
| 1449 | TF); |
| 1450 | |
| 1451 | assert(cast<ConstantPoolSDNode>(T)->getTargetFlags() == TF && |
| 1452 | "Inconsistent target flag encountered"); |
| 1453 | |
Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 1454 | if (IsPositionIndependent) |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1455 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), ValTy, T); |
| 1456 | return DAG.getNode(HexagonISD::CP, SDLoc(Op), ValTy, T); |
| 1457 | } |
| 1458 | |
| 1459 | SDValue |
| 1460 | HexagonTargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) const { |
| 1461 | EVT VT = Op.getValueType(); |
| 1462 | int Idx = cast<JumpTableSDNode>(Op)->getIndex(); |
Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 1463 | if (isPositionIndependent()) { |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1464 | SDValue T = DAG.getTargetJumpTable(Idx, VT, HexagonII::MO_PCREL); |
| 1465 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), VT, T); |
| 1466 | } |
| 1467 | |
| 1468 | SDValue T = DAG.getTargetJumpTable(Idx, VT); |
| 1469 | return DAG.getNode(HexagonISD::JT, SDLoc(Op), VT, T); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | SDValue |
| 1473 | HexagonTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1474 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1475 | MachineFunction &MF = DAG.getMachineFunction(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1476 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1477 | MFI.setReturnAddressIsTaken(true); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1478 | |
Bill Wendling | 908bf81 | 2014-01-06 00:43:20 +0000 | [diff] [blame] | 1479 | if (verifyReturnAddressArgumentIsConstant(Op, DAG)) |
Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 1480 | return SDValue(); |
Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 1481 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1482 | EVT VT = Op.getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1483 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1484 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 1485 | if (Depth) { |
| 1486 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1487 | SDValue Offset = DAG.getConstant(4, dl, MVT::i32); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1488 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 1489 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1490 | MachinePointerInfo()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | // 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] | 1494 | unsigned Reg = MF.addLiveIn(HRI.getRARegister(), getRegClassFor(MVT::i32)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1495 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 1496 | } |
| 1497 | |
| 1498 | SDValue |
| 1499 | HexagonTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1500 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1501 | MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1502 | MFI.setFrameAddressIsTaken(true); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1503 | |
| 1504 | EVT VT = Op.getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1505 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1506 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 1507 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1508 | HRI.getFrameRegister(), VT); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1509 | while (Depth--) |
| 1510 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1511 | MachinePointerInfo()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1512 | return FrameAddr; |
| 1513 | } |
| 1514 | |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1515 | SDValue |
| 1516 | HexagonTargetLowering::LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const { |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1517 | SDLoc dl(Op); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1518 | return DAG.getNode(HexagonISD::BARRIER, dl, MVT::Other, Op.getOperand(0)); |
| 1519 | } |
| 1520 | |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1521 | SDValue |
| 1522 | HexagonTargetLowering::LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const { |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1523 | SDLoc dl(Op); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1524 | auto *GAN = cast<GlobalAddressSDNode>(Op); |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1525 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1526 | auto *GV = GAN->getGlobal(); |
| 1527 | int64_t Offset = GAN->getOffset(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1528 | |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1529 | auto &HLOF = *HTM.getObjFileLowering(); |
| 1530 | Reloc::Model RM = HTM.getRelocationModel(); |
| 1531 | |
| 1532 | if (RM == Reloc::Static) { |
| 1533 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset); |
Peter Collingbourne | 6733564 | 2016-10-24 19:23:39 +0000 | [diff] [blame] | 1534 | const GlobalObject *GO = GV->getBaseObject(); |
| 1535 | if (GO && HLOF.isGlobalInSmallSection(GO, HTM)) |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1536 | return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, GA); |
| 1537 | return DAG.getNode(HexagonISD::CONST32, dl, PtrVT, GA); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Rafael Espindola | 3beef8d | 2016-06-27 23:15:57 +0000 | [diff] [blame] | 1540 | bool UsePCRel = getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1541 | if (UsePCRel) { |
| 1542 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset, |
| 1543 | HexagonII::MO_PCREL); |
| 1544 | return DAG.getNode(HexagonISD::AT_PCREL, dl, PtrVT, GA); |
| 1545 | } |
| 1546 | |
| 1547 | // Use GOT index. |
| 1548 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
| 1549 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, HexagonII::MO_GOT); |
| 1550 | SDValue Off = DAG.getConstant(Offset, dl, MVT::i32); |
| 1551 | return DAG.getNode(HexagonISD::AT_GOT, dl, PtrVT, GOT, GA, Off); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1554 | // Specifies that for loads and stores VT can be promoted to PromotedLdStVT. |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1555 | SDValue |
| 1556 | HexagonTargetLowering::LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const { |
| 1557 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1558 | SDLoc dl(Op); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1559 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1560 | |
| 1561 | Reloc::Model RM = HTM.getRelocationModel(); |
| 1562 | if (RM == Reloc::Static) { |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1563 | SDValue A = DAG.getTargetBlockAddress(BA, PtrVT); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1564 | return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, A); |
| 1565 | } |
| 1566 | |
| 1567 | SDValue A = DAG.getTargetBlockAddress(BA, PtrVT, 0, HexagonII::MO_PCREL); |
| 1568 | return DAG.getNode(HexagonISD::AT_PCREL, dl, PtrVT, A); |
| 1569 | } |
| 1570 | |
| 1571 | SDValue |
| 1572 | HexagonTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG) |
| 1573 | const { |
| 1574 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1575 | SDValue GOTSym = DAG.getTargetExternalSymbol(HEXAGON_GOT_SYM_NAME, PtrVT, |
| 1576 | HexagonII::MO_PCREL); |
| 1577 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), PtrVT, GOTSym); |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1580 | SDValue |
| 1581 | HexagonTargetLowering::GetDynamicTLSAddr(SelectionDAG &DAG, SDValue Chain, |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 1582 | GlobalAddressSDNode *GA, SDValue Glue, EVT PtrVT, unsigned ReturnReg, |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1583 | unsigned char OperandFlags) const { |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 1584 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1585 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1586 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| 1587 | SDLoc dl(GA); |
| 1588 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, |
| 1589 | GA->getValueType(0), |
| 1590 | GA->getOffset(), |
| 1591 | OperandFlags); |
| 1592 | // Create Operands for the call.The Operands should have the following: |
| 1593 | // 1. Chain SDValue |
| 1594 | // 2. Callee which in this case is the Global address value. |
| 1595 | // 3. Registers live into the call.In this case its R0, as we |
| 1596 | // have just one argument to be passed. |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 1597 | // 4. Glue. |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1598 | // Note: The order is important. |
| 1599 | |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 1600 | const auto &HRI = *Subtarget.getRegisterInfo(); |
| 1601 | const uint32_t *Mask = HRI.getCallPreservedMask(MF, CallingConv::C); |
| 1602 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 1603 | SDValue Ops[] = { Chain, TGA, DAG.getRegister(Hexagon::R0, PtrVT), |
| 1604 | DAG.getRegisterMask(Mask), Glue }; |
| 1605 | Chain = DAG.getNode(HexagonISD::CALL, dl, NodeTys, Ops); |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1606 | |
| 1607 | // Inform MFI that function has calls. |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1608 | MFI.setAdjustsStack(true); |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1609 | |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 1610 | Glue = Chain.getValue(1); |
| 1611 | return DAG.getCopyFromReg(Chain, dl, ReturnReg, PtrVT, Glue); |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | // |
| 1615 | // Lower using the intial executable model for TLS addresses |
| 1616 | // |
| 1617 | SDValue |
| 1618 | HexagonTargetLowering::LowerToTLSInitialExecModel(GlobalAddressSDNode *GA, |
| 1619 | SelectionDAG &DAG) const { |
| 1620 | SDLoc dl(GA); |
| 1621 | int64_t Offset = GA->getOffset(); |
| 1622 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1623 | |
| 1624 | // Get the thread pointer. |
| 1625 | SDValue TP = DAG.getCopyFromReg(DAG.getEntryNode(), dl, Hexagon::UGP, PtrVT); |
| 1626 | |
Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 1627 | bool IsPositionIndependent = isPositionIndependent(); |
| 1628 | unsigned char TF = |
| 1629 | IsPositionIndependent ? HexagonII::MO_IEGOT : HexagonII::MO_IE; |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1630 | |
| 1631 | // First generate the TLS symbol address |
| 1632 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, |
| 1633 | Offset, TF); |
| 1634 | |
| 1635 | SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA); |
| 1636 | |
Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 1637 | if (IsPositionIndependent) { |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1638 | // Generate the GOT pointer in case of position independent code |
| 1639 | SDValue GOT = LowerGLOBAL_OFFSET_TABLE(Sym, DAG); |
| 1640 | |
| 1641 | // Add the TLS Symbol address to GOT pointer.This gives |
| 1642 | // GOT relative relocation for the symbol. |
| 1643 | Sym = DAG.getNode(ISD::ADD, dl, PtrVT, GOT, Sym); |
| 1644 | } |
| 1645 | |
| 1646 | // Load the offset value for TLS symbol.This offset is relative to |
| 1647 | // thread pointer. |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1648 | SDValue LoadOffset = |
| 1649 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Sym, MachinePointerInfo()); |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1650 | |
| 1651 | // Address of the thread local variable is the add of thread |
| 1652 | // pointer and the offset of the variable. |
| 1653 | return DAG.getNode(ISD::ADD, dl, PtrVT, TP, LoadOffset); |
| 1654 | } |
| 1655 | |
| 1656 | // |
| 1657 | // Lower using the local executable model for TLS addresses |
| 1658 | // |
| 1659 | SDValue |
| 1660 | HexagonTargetLowering::LowerToTLSLocalExecModel(GlobalAddressSDNode *GA, |
| 1661 | SelectionDAG &DAG) const { |
| 1662 | SDLoc dl(GA); |
| 1663 | int64_t Offset = GA->getOffset(); |
| 1664 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1665 | |
| 1666 | // Get the thread pointer. |
| 1667 | SDValue TP = DAG.getCopyFromReg(DAG.getEntryNode(), dl, Hexagon::UGP, PtrVT); |
| 1668 | // Generate the TLS symbol address |
| 1669 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, Offset, |
| 1670 | HexagonII::MO_TPREL); |
| 1671 | SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA); |
| 1672 | |
| 1673 | // Address of the thread local variable is the add of thread |
| 1674 | // pointer and the offset of the variable. |
| 1675 | return DAG.getNode(ISD::ADD, dl, PtrVT, TP, Sym); |
| 1676 | } |
| 1677 | |
| 1678 | // |
| 1679 | // Lower using the general dynamic model for TLS addresses |
| 1680 | // |
| 1681 | SDValue |
| 1682 | HexagonTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
| 1683 | SelectionDAG &DAG) const { |
| 1684 | SDLoc dl(GA); |
| 1685 | int64_t Offset = GA->getOffset(); |
| 1686 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1687 | |
| 1688 | // First generate the TLS symbol address |
| 1689 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, Offset, |
| 1690 | HexagonII::MO_GDGOT); |
| 1691 | |
| 1692 | // Then, generate the GOT pointer |
| 1693 | SDValue GOT = LowerGLOBAL_OFFSET_TABLE(TGA, DAG); |
| 1694 | |
| 1695 | // Add the TLS symbol and the GOT pointer |
| 1696 | SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA); |
| 1697 | SDValue Chain = DAG.getNode(ISD::ADD, dl, PtrVT, GOT, Sym); |
| 1698 | |
| 1699 | // Copy over the argument to R0 |
| 1700 | SDValue InFlag; |
| 1701 | Chain = DAG.getCopyToReg(DAG.getEntryNode(), dl, Hexagon::R0, Chain, InFlag); |
| 1702 | InFlag = Chain.getValue(1); |
| 1703 | |
Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame^] | 1704 | return GetDynamicTLSAddr(DAG, Chain, GA, InFlag, PtrVT, |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1705 | Hexagon::R0, HexagonII::MO_GDPLT); |
| 1706 | } |
| 1707 | |
| 1708 | // |
| 1709 | // Lower TLS addresses. |
| 1710 | // |
| 1711 | // For now for dynamic models, we only support the general dynamic model. |
| 1712 | // |
| 1713 | SDValue |
| 1714 | HexagonTargetLowering::LowerGlobalTLSAddress(SDValue Op, |
| 1715 | SelectionDAG &DAG) const { |
| 1716 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 1717 | |
| 1718 | switch (HTM.getTLSModel(GA->getGlobal())) { |
| 1719 | case TLSModel::GeneralDynamic: |
| 1720 | case TLSModel::LocalDynamic: |
| 1721 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 1722 | case TLSModel::InitialExec: |
| 1723 | return LowerToTLSInitialExecModel(GA, DAG); |
| 1724 | case TLSModel::LocalExec: |
| 1725 | return LowerToTLSLocalExecModel(GA, DAG); |
| 1726 | } |
| 1727 | llvm_unreachable("Bogus TLS model"); |
| 1728 | } |
| 1729 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1730 | //===----------------------------------------------------------------------===// |
| 1731 | // TargetLowering Implementation |
| 1732 | //===----------------------------------------------------------------------===// |
| 1733 | |
Eric Christopher | d737b76 | 2015-02-02 22:11:36 +0000 | [diff] [blame] | 1734 | HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM, |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1735 | const HexagonSubtarget &ST) |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1736 | : TargetLowering(TM), HTM(static_cast<const HexagonTargetMachine&>(TM)), |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1737 | Subtarget(ST) { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1738 | bool IsV4 = !Subtarget.hasV5TOps(); |
| 1739 | auto &HRI = *Subtarget.getRegisterInfo(); |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 1740 | bool UseHVX = Subtarget.useHVXOps(); |
| 1741 | bool UseHVXSgl = Subtarget.useHVXSglOps(); |
| 1742 | bool UseHVXDbl = Subtarget.useHVXDblOps(); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1743 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1744 | setPrefLoopAlignment(4); |
| 1745 | setPrefFunctionAlignment(4); |
| 1746 | setMinFunctionAlignment(2); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1747 | setStackPointerRegisterToSaveRestore(HRI.getStackRegister()); |
| 1748 | |
Krzysztof Parzyszek | f228c95 | 2016-06-22 16:07:10 +0000 | [diff] [blame] | 1749 | setMaxAtomicSizeInBitsSupported(64); |
| 1750 | setMinCmpXchgSizeInBits(32); |
| 1751 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1752 | if (EnableHexSDNodeSched) |
| 1753 | setSchedulingPreference(Sched::VLIW); |
| 1754 | else |
| 1755 | setSchedulingPreference(Sched::Source); |
| 1756 | |
| 1757 | // Limits for inline expansion of memcpy/memmove |
| 1758 | MaxStoresPerMemcpy = MaxStoresPerMemcpyCL; |
| 1759 | MaxStoresPerMemcpyOptSize = MaxStoresPerMemcpyOptSizeCL; |
| 1760 | MaxStoresPerMemmove = MaxStoresPerMemmoveCL; |
| 1761 | MaxStoresPerMemmoveOptSize = MaxStoresPerMemmoveOptSizeCL; |
| 1762 | MaxStoresPerMemset = MaxStoresPerMemsetCL; |
| 1763 | MaxStoresPerMemsetOptSize = MaxStoresPerMemsetOptSizeCL; |
| 1764 | |
| 1765 | // |
| 1766 | // Set up register classes. |
| 1767 | // |
| 1768 | |
| 1769 | addRegisterClass(MVT::i1, &Hexagon::PredRegsRegClass); |
| 1770 | addRegisterClass(MVT::v2i1, &Hexagon::PredRegsRegClass); // bbbbaaaa |
| 1771 | addRegisterClass(MVT::v4i1, &Hexagon::PredRegsRegClass); // ddccbbaa |
| 1772 | addRegisterClass(MVT::v8i1, &Hexagon::PredRegsRegClass); // hgfedcba |
| 1773 | addRegisterClass(MVT::i32, &Hexagon::IntRegsRegClass); |
| 1774 | addRegisterClass(MVT::v4i8, &Hexagon::IntRegsRegClass); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1775 | addRegisterClass(MVT::v2i16, &Hexagon::IntRegsRegClass); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1776 | addRegisterClass(MVT::i64, &Hexagon::DoubleRegsRegClass); |
| 1777 | addRegisterClass(MVT::v8i8, &Hexagon::DoubleRegsRegClass); |
| 1778 | addRegisterClass(MVT::v4i16, &Hexagon::DoubleRegsRegClass); |
| 1779 | addRegisterClass(MVT::v2i32, &Hexagon::DoubleRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1780 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1781 | if (Subtarget.hasV5TOps()) { |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1782 | addRegisterClass(MVT::f32, &Hexagon::IntRegsRegClass); |
| 1783 | addRegisterClass(MVT::f64, &Hexagon::DoubleRegsRegClass); |
| 1784 | } |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1785 | |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1786 | if (Subtarget.hasV60TOps()) { |
| 1787 | if (Subtarget.useHVXSglOps()) { |
| 1788 | addRegisterClass(MVT::v64i8, &Hexagon::VectorRegsRegClass); |
| 1789 | addRegisterClass(MVT::v32i16, &Hexagon::VectorRegsRegClass); |
| 1790 | addRegisterClass(MVT::v16i32, &Hexagon::VectorRegsRegClass); |
| 1791 | addRegisterClass(MVT::v8i64, &Hexagon::VectorRegsRegClass); |
| 1792 | addRegisterClass(MVT::v128i8, &Hexagon::VecDblRegsRegClass); |
| 1793 | addRegisterClass(MVT::v64i16, &Hexagon::VecDblRegsRegClass); |
| 1794 | addRegisterClass(MVT::v32i32, &Hexagon::VecDblRegsRegClass); |
| 1795 | addRegisterClass(MVT::v16i64, &Hexagon::VecDblRegsRegClass); |
| 1796 | addRegisterClass(MVT::v512i1, &Hexagon::VecPredRegsRegClass); |
| 1797 | } else if (Subtarget.useHVXDblOps()) { |
| 1798 | addRegisterClass(MVT::v128i8, &Hexagon::VectorRegs128BRegClass); |
| 1799 | addRegisterClass(MVT::v64i16, &Hexagon::VectorRegs128BRegClass); |
| 1800 | addRegisterClass(MVT::v32i32, &Hexagon::VectorRegs128BRegClass); |
| 1801 | addRegisterClass(MVT::v16i64, &Hexagon::VectorRegs128BRegClass); |
| 1802 | addRegisterClass(MVT::v256i8, &Hexagon::VecDblRegs128BRegClass); |
| 1803 | addRegisterClass(MVT::v128i16, &Hexagon::VecDblRegs128BRegClass); |
| 1804 | addRegisterClass(MVT::v64i32, &Hexagon::VecDblRegs128BRegClass); |
| 1805 | addRegisterClass(MVT::v32i64, &Hexagon::VecDblRegs128BRegClass); |
| 1806 | addRegisterClass(MVT::v1024i1, &Hexagon::VecPredRegs128BRegClass); |
| 1807 | } |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1810 | // |
| 1811 | // Handling of scalar operations. |
| 1812 | // |
| 1813 | // All operations default to "legal", except: |
| 1814 | // - indexed loads and stores (pre-/post-incremented), |
| 1815 | // - ANY_EXTEND_VECTOR_INREG, ATOMIC_CMP_SWAP_WITH_SUCCESS, CONCAT_VECTORS, |
| 1816 | // ConstantFP, DEBUGTRAP, FCEIL, FCOPYSIGN, FEXP, FEXP2, FFLOOR, FGETSIGN, |
| 1817 | // FLOG, FLOG2, FLOG10, FMAXNUM, FMINNUM, FNEARBYINT, FRINT, FROUND, TRAP, |
| 1818 | // FTRUNC, PREFETCH, SIGN_EXTEND_VECTOR_INREG, ZERO_EXTEND_VECTOR_INREG, |
| 1819 | // which default to "expand" for at least one type. |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1820 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1821 | // Misc operations. |
| 1822 | setOperationAction(ISD::ConstantFP, MVT::f32, Legal); // Default: expand |
| 1823 | setOperationAction(ISD::ConstantFP, MVT::f64, Legal); // Default: expand |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1824 | |
| 1825 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1826 | setOperationAction(ISD::JumpTable, MVT::i32, Custom); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1827 | setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1828 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
| 1829 | setOperationAction(ISD::INLINEASM, MVT::Other, Custom); |
Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 1830 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
| 1831 | setOperationAction(ISD::INTRINSIC_VOID, MVT::Other, Custom); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1832 | setOperationAction(ISD::EH_RETURN, MVT::Other, Custom); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1833 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1834 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1835 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1836 | |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1837 | // Custom legalize GlobalAddress nodes into CONST32. |
| 1838 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1839 | setOperationAction(ISD::GlobalAddress, MVT::i8, Custom); |
| 1840 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1841 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1842 | // Hexagon needs to optimize cases with negative constants. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1843 | setOperationAction(ISD::SETCC, MVT::i8, Custom); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1844 | setOperationAction(ISD::SETCC, MVT::i16, Custom); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1845 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1846 | // VASTART needs to be custom lowered to use the VarArgsFrameIndex. |
| 1847 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 1848 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 1849 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 1850 | |
| 1851 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 1852 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
| 1853 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom); |
| 1854 | |
| 1855 | if (EmitJumpTables) |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1856 | setMinimumJumpTableEntries(MinimumJumpTables); |
Krzysztof Parzyszek | a61f7da | 2016-01-13 21:43:13 +0000 | [diff] [blame] | 1857 | else |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 1858 | setMinimumJumpTableEntries(std::numeric_limits<int>::max()); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1859 | setOperationAction(ISD::BR_JT, MVT::Other, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1860 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1861 | // Hexagon has instructions for add/sub with carry. The problem with |
| 1862 | // modeling these instructions is that they produce 2 results: Rdd and Px. |
| 1863 | // To model the update of Px, we will have to use Defs[p0..p3] which will |
| 1864 | // cause any predicate live range to spill. So, we pretend we dont't have |
| 1865 | // these instructions. |
| 1866 | setOperationAction(ISD::ADDE, MVT::i8, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1867 | setOperationAction(ISD::ADDE, MVT::i16, Expand); |
| 1868 | setOperationAction(ISD::ADDE, MVT::i32, Expand); |
| 1869 | setOperationAction(ISD::ADDE, MVT::i64, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1870 | setOperationAction(ISD::SUBE, MVT::i8, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1871 | setOperationAction(ISD::SUBE, MVT::i16, Expand); |
| 1872 | setOperationAction(ISD::SUBE, MVT::i32, Expand); |
| 1873 | setOperationAction(ISD::SUBE, MVT::i64, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1874 | setOperationAction(ISD::ADDC, MVT::i8, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1875 | setOperationAction(ISD::ADDC, MVT::i16, Expand); |
| 1876 | setOperationAction(ISD::ADDC, MVT::i32, Expand); |
| 1877 | setOperationAction(ISD::ADDC, MVT::i64, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1878 | setOperationAction(ISD::SUBC, MVT::i8, Expand); |
Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1879 | setOperationAction(ISD::SUBC, MVT::i16, Expand); |
| 1880 | setOperationAction(ISD::SUBC, MVT::i32, Expand); |
| 1881 | setOperationAction(ISD::SUBC, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1882 | |
Krzysztof Parzyszek | 2c4487d | 2015-04-13 20:37:01 +0000 | [diff] [blame] | 1883 | // Only add and sub that detect overflow are the saturating ones. |
| 1884 | for (MVT VT : MVT::integer_valuetypes()) { |
| 1885 | setOperationAction(ISD::UADDO, VT, Expand); |
| 1886 | setOperationAction(ISD::SADDO, VT, Expand); |
| 1887 | setOperationAction(ISD::USUBO, VT, Expand); |
| 1888 | setOperationAction(ISD::SSUBO, VT, Expand); |
| 1889 | } |
| 1890 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1891 | setOperationAction(ISD::CTLZ, MVT::i8, Promote); |
| 1892 | setOperationAction(ISD::CTLZ, MVT::i16, Promote); |
| 1893 | setOperationAction(ISD::CTTZ, MVT::i8, Promote); |
| 1894 | setOperationAction(ISD::CTTZ, MVT::i16, Promote); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1895 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1896 | // In V5, popcount can count # of 1s in i64 but returns i32. |
| 1897 | // On V4 it will be expanded (set later). |
| 1898 | setOperationAction(ISD::CTPOP, MVT::i8, Promote); |
| 1899 | setOperationAction(ISD::CTPOP, MVT::i16, Promote); |
| 1900 | setOperationAction(ISD::CTPOP, MVT::i32, Promote); |
| 1901 | setOperationAction(ISD::CTPOP, MVT::i64, Custom); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1902 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1903 | // We custom lower i64 to i64 mul, so that it is not considered as a legal |
| 1904 | // operation. There is a pattern that will match i64 mul and transform it |
| 1905 | // to a series of instructions. |
| 1906 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1907 | |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1908 | for (unsigned IntExpOp : |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1909 | { ISD::SDIV, ISD::UDIV, ISD::SREM, ISD::UREM, |
| 1910 | ISD::SDIVREM, ISD::UDIVREM, ISD::ROTL, ISD::ROTR, |
| 1911 | ISD::BSWAP, ISD::SHL_PARTS, ISD::SRA_PARTS, ISD::SRL_PARTS, |
| 1912 | ISD::SMUL_LOHI, ISD::UMUL_LOHI }) { |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1913 | setOperationAction(IntExpOp, MVT::i32, Expand); |
| 1914 | setOperationAction(IntExpOp, MVT::i64, Expand); |
| 1915 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1916 | |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1917 | for (unsigned FPExpOp : |
| 1918 | {ISD::FDIV, ISD::FREM, ISD::FSQRT, ISD::FSIN, ISD::FCOS, ISD::FSINCOS, |
| 1919 | ISD::FPOW, ISD::FCOPYSIGN}) { |
| 1920 | setOperationAction(FPExpOp, MVT::f32, Expand); |
| 1921 | setOperationAction(FPExpOp, MVT::f64, Expand); |
| 1922 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1923 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1924 | // No extending loads from i32. |
| 1925 | for (MVT VT : MVT::integer_valuetypes()) { |
| 1926 | setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i32, Expand); |
| 1927 | setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i32, Expand); |
| 1928 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::i32, Expand); |
| 1929 | } |
| 1930 | // Turn FP truncstore into trunc + store. |
| 1931 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Michael Kuperstein | 2bc3d4d | 2016-08-18 20:08:15 +0000 | [diff] [blame] | 1932 | // Turn FP extload into load/fpextend. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1933 | for (MVT VT : MVT::fp_valuetypes()) |
| 1934 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1935 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1936 | // Expand BR_CC and SELECT_CC for all integer and fp types. |
| 1937 | for (MVT VT : MVT::integer_valuetypes()) { |
| 1938 | setOperationAction(ISD::BR_CC, VT, Expand); |
| 1939 | setOperationAction(ISD::SELECT_CC, VT, Expand); |
| 1940 | } |
| 1941 | for (MVT VT : MVT::fp_valuetypes()) { |
| 1942 | setOperationAction(ISD::BR_CC, VT, Expand); |
| 1943 | setOperationAction(ISD::SELECT_CC, VT, Expand); |
| 1944 | } |
| 1945 | setOperationAction(ISD::BR_CC, MVT::Other, Expand); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1946 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1947 | // |
| 1948 | // Handling of vector operations. |
| 1949 | // |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1950 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1951 | // Custom lower v4i16 load only. Let v4i16 store to be |
| 1952 | // promoted for now. |
| 1953 | promoteLdStType(MVT::v4i8, MVT::i32); |
| 1954 | promoteLdStType(MVT::v2i16, MVT::i32); |
| 1955 | promoteLdStType(MVT::v8i8, MVT::i64); |
| 1956 | promoteLdStType(MVT::v2i32, MVT::i64); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1957 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1958 | setOperationAction(ISD::LOAD, MVT::v4i16, Custom); |
| 1959 | setOperationAction(ISD::STORE, MVT::v4i16, Promote); |
| 1960 | AddPromotedToType(ISD::LOAD, MVT::v4i16, MVT::i64); |
| 1961 | AddPromotedToType(ISD::STORE, MVT::v4i16, MVT::i64); |
| 1962 | |
| 1963 | // Set the action for vector operations to "expand", then override it with |
| 1964 | // either "custom" or "legal" for specific cases. |
Craig Topper | 2626094 | 2015-10-18 05:15:34 +0000 | [diff] [blame] | 1965 | static const unsigned VectExpOps[] = { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1966 | // Integer arithmetic: |
| 1967 | ISD::ADD, ISD::SUB, ISD::MUL, ISD::SDIV, ISD::UDIV, |
| 1968 | ISD::SREM, ISD::UREM, ISD::SDIVREM, ISD::UDIVREM, ISD::ADDC, |
| 1969 | ISD::SUBC, ISD::SADDO, ISD::UADDO, ISD::SSUBO, ISD::USUBO, |
| 1970 | ISD::SMUL_LOHI, ISD::UMUL_LOHI, |
| 1971 | // Logical/bit: |
| 1972 | ISD::AND, ISD::OR, ISD::XOR, ISD::ROTL, ISD::ROTR, |
Craig Topper | 33772c5 | 2016-04-28 03:34:31 +0000 | [diff] [blame] | 1973 | ISD::CTPOP, ISD::CTLZ, ISD::CTTZ, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1974 | // Floating point arithmetic/math functions: |
| 1975 | ISD::FADD, ISD::FSUB, ISD::FMUL, ISD::FMA, ISD::FDIV, |
| 1976 | ISD::FREM, ISD::FNEG, ISD::FABS, ISD::FSQRT, ISD::FSIN, |
| 1977 | ISD::FCOS, ISD::FPOWI, ISD::FPOW, ISD::FLOG, ISD::FLOG2, |
| 1978 | ISD::FLOG10, ISD::FEXP, ISD::FEXP2, ISD::FCEIL, ISD::FTRUNC, |
| 1979 | ISD::FRINT, ISD::FNEARBYINT, ISD::FROUND, ISD::FFLOOR, |
| 1980 | ISD::FMINNUM, ISD::FMAXNUM, ISD::FSINCOS, |
| 1981 | // Misc: |
Krzysztof Parzyszek | 046da74 | 2016-10-27 14:30:16 +0000 | [diff] [blame] | 1982 | ISD::BR_CC, ISD::SELECT_CC, ISD::ConstantPool, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1983 | // Vector: |
| 1984 | ISD::BUILD_VECTOR, ISD::SCALAR_TO_VECTOR, |
| 1985 | ISD::EXTRACT_VECTOR_ELT, ISD::INSERT_VECTOR_ELT, |
| 1986 | ISD::EXTRACT_SUBVECTOR, ISD::INSERT_SUBVECTOR, |
| 1987 | ISD::CONCAT_VECTORS, ISD::VECTOR_SHUFFLE |
| 1988 | }; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1989 | |
| 1990 | for (MVT VT : MVT::vector_valuetypes()) { |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1991 | for (unsigned VectExpOp : VectExpOps) |
| 1992 | setOperationAction(VectExpOp, VT, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1993 | |
Krzysztof Parzyszek | a696b1b | 2016-09-08 17:42:14 +0000 | [diff] [blame] | 1994 | // Expand all extending loads and truncating stores: |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1995 | for (MVT TargetVT : MVT::vector_valuetypes()) { |
Krzysztof Parzyszek | a696b1b | 2016-09-08 17:42:14 +0000 | [diff] [blame] | 1996 | if (TargetVT == VT) |
| 1997 | continue; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1998 | setLoadExtAction(ISD::EXTLOAD, TargetVT, VT, Expand); |
Krzysztof Parzyszek | a696b1b | 2016-09-08 17:42:14 +0000 | [diff] [blame] | 1999 | setLoadExtAction(ISD::ZEXTLOAD, TargetVT, VT, Expand); |
| 2000 | setLoadExtAction(ISD::SEXTLOAD, TargetVT, VT, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2001 | setTruncStoreAction(VT, TargetVT, Expand); |
| 2002 | } |
| 2003 | |
Krzysztof Parzyszek | 046da74 | 2016-10-27 14:30:16 +0000 | [diff] [blame] | 2004 | // Normalize all inputs to SELECT to be vectors of i32. |
| 2005 | if (VT.getVectorElementType() != MVT::i32) { |
| 2006 | MVT VT32 = MVT::getVectorVT(MVT::i32, VT.getSizeInBits()/32); |
| 2007 | setOperationAction(ISD::SELECT, VT, Promote); |
| 2008 | AddPromotedToType(ISD::SELECT, VT, VT32); |
| 2009 | } |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2010 | setOperationAction(ISD::SRA, VT, Custom); |
| 2011 | setOperationAction(ISD::SHL, VT, Custom); |
| 2012 | setOperationAction(ISD::SRL, VT, Custom); |
| 2013 | } |
| 2014 | |
| 2015 | // Types natively supported: |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 2016 | for (MVT NativeVT : {MVT::v2i1, MVT::v4i1, MVT::v8i1, MVT::v32i1, MVT::v64i1, |
| 2017 | MVT::v4i8, MVT::v8i8, MVT::v2i16, MVT::v4i16, MVT::v1i32, |
| 2018 | MVT::v2i32, MVT::v1i64}) { |
| 2019 | setOperationAction(ISD::BUILD_VECTOR, NativeVT, Custom); |
| 2020 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, NativeVT, Custom); |
| 2021 | setOperationAction(ISD::INSERT_VECTOR_ELT, NativeVT, Custom); |
| 2022 | setOperationAction(ISD::EXTRACT_SUBVECTOR, NativeVT, Custom); |
| 2023 | setOperationAction(ISD::INSERT_SUBVECTOR, NativeVT, Custom); |
| 2024 | setOperationAction(ISD::CONCAT_VECTORS, NativeVT, Custom); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2025 | |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 2026 | setOperationAction(ISD::ADD, NativeVT, Legal); |
| 2027 | setOperationAction(ISD::SUB, NativeVT, Legal); |
| 2028 | setOperationAction(ISD::MUL, NativeVT, Legal); |
| 2029 | setOperationAction(ISD::AND, NativeVT, Legal); |
| 2030 | setOperationAction(ISD::OR, NativeVT, Legal); |
| 2031 | setOperationAction(ISD::XOR, NativeVT, Legal); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | setOperationAction(ISD::SETCC, MVT::v2i16, Custom); |
| 2035 | setOperationAction(ISD::VSELECT, MVT::v2i16, Custom); |
| 2036 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v4i16, Custom); |
| 2037 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v8i8, Custom); |
Krzysztof Parzyszek | d19d050 | 2016-09-13 21:16:07 +0000 | [diff] [blame] | 2038 | |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2039 | if (UseHVX) { |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2040 | if (UseHVXSgl) { |
| 2041 | setOperationAction(ISD::CONCAT_VECTORS, MVT::v128i8, Custom); |
| 2042 | setOperationAction(ISD::CONCAT_VECTORS, MVT::v64i16, Custom); |
| 2043 | setOperationAction(ISD::CONCAT_VECTORS, MVT::v32i32, Custom); |
| 2044 | setOperationAction(ISD::CONCAT_VECTORS, MVT::v16i64, Custom); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2045 | // We try to generate the vpack{e/o} instructions. If we fail |
| 2046 | // we fall back upon ExpandOp. |
| 2047 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v64i8, Custom); |
| 2048 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v32i16, Custom); |
| 2049 | setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v64i8, Custom); |
| 2050 | setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v32i16, Custom); |
| 2051 | setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v16i32, Custom); |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2052 | } else if (UseHVXDbl) { |
| 2053 | setOperationAction(ISD::CONCAT_VECTORS, MVT::v256i8, Custom); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2054 | setOperationAction(ISD::CONCAT_VECTORS, MVT::v128i16, Custom); |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2055 | setOperationAction(ISD::CONCAT_VECTORS, MVT::v64i32, Custom); |
| 2056 | setOperationAction(ISD::CONCAT_VECTORS, MVT::v32i64, Custom); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2057 | // We try to generate the vpack{e/o} instructions. If we fail |
| 2058 | // we fall back upon ExpandOp. |
| 2059 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v128i8, Custom); |
| 2060 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v64i16, Custom); |
| 2061 | setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v4i32, Custom); |
| 2062 | setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v128i8, Custom); |
| 2063 | setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v64i16, Custom); |
| 2064 | setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v32i32, Custom); |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2065 | } else { |
| 2066 | llvm_unreachable("Unrecognized HVX mode"); |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2067 | } |
| 2068 | } |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2069 | // Subtarget-specific operation actions. |
| 2070 | // |
| 2071 | if (Subtarget.hasV5TOps()) { |
| 2072 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 2073 | setOperationAction(ISD::FADD, MVT::f64, Expand); |
| 2074 | setOperationAction(ISD::FSUB, MVT::f64, Expand); |
| 2075 | setOperationAction(ISD::FMUL, MVT::f64, Expand); |
| 2076 | |
Krzysztof Parzyszek | bd8ef4b | 2016-08-19 13:34:31 +0000 | [diff] [blame] | 2077 | setOperationAction(ISD::FMINNUM, MVT::f32, Legal); |
| 2078 | setOperationAction(ISD::FMAXNUM, MVT::f32, Legal); |
| 2079 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2080 | setOperationAction(ISD::FP_TO_UINT, MVT::i1, Promote); |
| 2081 | setOperationAction(ISD::FP_TO_UINT, MVT::i8, Promote); |
| 2082 | setOperationAction(ISD::FP_TO_UINT, MVT::i16, Promote); |
| 2083 | setOperationAction(ISD::FP_TO_SINT, MVT::i1, Promote); |
| 2084 | setOperationAction(ISD::FP_TO_SINT, MVT::i8, Promote); |
| 2085 | setOperationAction(ISD::FP_TO_SINT, MVT::i16, Promote); |
| 2086 | setOperationAction(ISD::UINT_TO_FP, MVT::i1, Promote); |
| 2087 | setOperationAction(ISD::UINT_TO_FP, MVT::i8, Promote); |
| 2088 | setOperationAction(ISD::UINT_TO_FP, MVT::i16, Promote); |
| 2089 | setOperationAction(ISD::SINT_TO_FP, MVT::i1, Promote); |
| 2090 | setOperationAction(ISD::SINT_TO_FP, MVT::i8, Promote); |
| 2091 | setOperationAction(ISD::SINT_TO_FP, MVT::i16, Promote); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2092 | } else { // V4 |
| 2093 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Expand); |
| 2094 | setOperationAction(ISD::SINT_TO_FP, MVT::i64, Expand); |
| 2095 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand); |
| 2096 | setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand); |
| 2097 | setOperationAction(ISD::FP_TO_SINT, MVT::f64, Expand); |
| 2098 | setOperationAction(ISD::FP_TO_SINT, MVT::f32, Expand); |
| 2099 | setOperationAction(ISD::FP_EXTEND, MVT::f32, Expand); |
| 2100 | setOperationAction(ISD::FP_ROUND, MVT::f64, Expand); |
| 2101 | setCondCodeAction(ISD::SETUNE, MVT::f64, Expand); |
| 2102 | |
| 2103 | setOperationAction(ISD::CTPOP, MVT::i8, Expand); |
| 2104 | setOperationAction(ISD::CTPOP, MVT::i16, Expand); |
| 2105 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
| 2106 | setOperationAction(ISD::CTPOP, MVT::i64, Expand); |
| 2107 | |
| 2108 | // Expand these operations for both f32 and f64: |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 2109 | for (unsigned FPExpOpV4 : |
| 2110 | {ISD::FADD, ISD::FSUB, ISD::FMUL, ISD::FABS, ISD::FNEG, ISD::FMA}) { |
| 2111 | setOperationAction(FPExpOpV4, MVT::f32, Expand); |
| 2112 | setOperationAction(FPExpOpV4, MVT::f64, Expand); |
| 2113 | } |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2114 | |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 2115 | for (ISD::CondCode FPExpCCV4 : |
| 2116 | {ISD::SETOEQ, ISD::SETOGT, ISD::SETOLT, ISD::SETOGE, ISD::SETOLE, |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2117 | ISD::SETUO, ISD::SETO}) { |
Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 2118 | setCondCodeAction(FPExpCCV4, MVT::f32, Expand); |
| 2119 | setCondCodeAction(FPExpCCV4, MVT::f64, Expand); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2120 | } |
| 2121 | } |
| 2122 | |
| 2123 | // Handling of indexed loads/stores: default is "expand". |
| 2124 | // |
Krzysztof Parzyszek | 2a48059 | 2016-07-26 20:30:30 +0000 | [diff] [blame] | 2125 | for (MVT VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i64}) { |
| 2126 | setIndexedLoadAction(ISD::POST_INC, VT, Legal); |
| 2127 | setIndexedStoreAction(ISD::POST_INC, VT, Legal); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2128 | } |
| 2129 | |
Krzysztof Parzyszek | 2a48059 | 2016-07-26 20:30:30 +0000 | [diff] [blame] | 2130 | if (UseHVXSgl) { |
| 2131 | for (MVT VT : {MVT::v64i8, MVT::v32i16, MVT::v16i32, MVT::v8i64, |
| 2132 | MVT::v128i8, MVT::v64i16, MVT::v32i32, MVT::v16i64}) { |
| 2133 | setIndexedLoadAction(ISD::POST_INC, VT, Legal); |
| 2134 | setIndexedStoreAction(ISD::POST_INC, VT, Legal); |
| 2135 | } |
| 2136 | } else if (UseHVXDbl) { |
| 2137 | for (MVT VT : {MVT::v128i8, MVT::v64i16, MVT::v32i32, MVT::v16i64, |
| 2138 | MVT::v256i8, MVT::v128i16, MVT::v64i32, MVT::v32i64}) { |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2139 | setIndexedLoadAction(ISD::POST_INC, VT, Legal); |
| 2140 | setIndexedStoreAction(ISD::POST_INC, VT, Legal); |
| 2141 | } |
| 2142 | } |
| 2143 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2144 | computeRegisterProperties(&HRI); |
| 2145 | |
| 2146 | // |
| 2147 | // Library calls for unsupported operations |
| 2148 | // |
| 2149 | bool FastMath = EnableFastMath; |
| 2150 | |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 2151 | setLibcallName(RTLIB::SDIV_I32, "__hexagon_divsi3"); |
| 2152 | setLibcallName(RTLIB::SDIV_I64, "__hexagon_divdi3"); |
| 2153 | setLibcallName(RTLIB::UDIV_I32, "__hexagon_udivsi3"); |
| 2154 | setLibcallName(RTLIB::UDIV_I64, "__hexagon_udivdi3"); |
| 2155 | setLibcallName(RTLIB::SREM_I32, "__hexagon_modsi3"); |
| 2156 | setLibcallName(RTLIB::SREM_I64, "__hexagon_moddi3"); |
| 2157 | setLibcallName(RTLIB::UREM_I32, "__hexagon_umodsi3"); |
| 2158 | setLibcallName(RTLIB::UREM_I64, "__hexagon_umoddi3"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2159 | |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 2160 | setLibcallName(RTLIB::SINTTOFP_I128_F64, "__hexagon_floattidf"); |
| 2161 | setLibcallName(RTLIB::SINTTOFP_I128_F32, "__hexagon_floattisf"); |
| 2162 | setLibcallName(RTLIB::FPTOUINT_F32_I128, "__hexagon_fixunssfti"); |
| 2163 | setLibcallName(RTLIB::FPTOUINT_F64_I128, "__hexagon_fixunsdfti"); |
| 2164 | setLibcallName(RTLIB::FPTOSINT_F32_I128, "__hexagon_fixsfti"); |
| 2165 | setLibcallName(RTLIB::FPTOSINT_F64_I128, "__hexagon_fixdfti"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2166 | |
| 2167 | if (IsV4) { |
| 2168 | // Handle single-precision floating point operations on V4. |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 2169 | if (FastMath) { |
| 2170 | setLibcallName(RTLIB::ADD_F32, "__hexagon_fast_addsf3"); |
| 2171 | setLibcallName(RTLIB::SUB_F32, "__hexagon_fast_subsf3"); |
| 2172 | setLibcallName(RTLIB::MUL_F32, "__hexagon_fast_mulsf3"); |
| 2173 | setLibcallName(RTLIB::OGT_F32, "__hexagon_fast_gtsf2"); |
| 2174 | setLibcallName(RTLIB::OLT_F32, "__hexagon_fast_ltsf2"); |
| 2175 | // Double-precision compares. |
| 2176 | setLibcallName(RTLIB::OGT_F64, "__hexagon_fast_gtdf2"); |
| 2177 | setLibcallName(RTLIB::OLT_F64, "__hexagon_fast_ltdf2"); |
| 2178 | } else { |
| 2179 | setLibcallName(RTLIB::ADD_F32, "__hexagon_addsf3"); |
| 2180 | setLibcallName(RTLIB::SUB_F32, "__hexagon_subsf3"); |
| 2181 | setLibcallName(RTLIB::MUL_F32, "__hexagon_mulsf3"); |
| 2182 | setLibcallName(RTLIB::OGT_F32, "__hexagon_gtsf2"); |
| 2183 | setLibcallName(RTLIB::OLT_F32, "__hexagon_ltsf2"); |
| 2184 | // Double-precision compares. |
| 2185 | setLibcallName(RTLIB::OGT_F64, "__hexagon_gtdf2"); |
| 2186 | setLibcallName(RTLIB::OLT_F64, "__hexagon_ltdf2"); |
| 2187 | } |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | // This is the only fast library function for sqrtd. |
| 2191 | if (FastMath) |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 2192 | setLibcallName(RTLIB::SQRT_F64, "__hexagon_fast2_sqrtdf2"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2193 | |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 2194 | // Prefix is: nothing for "slow-math", |
| 2195 | // "fast2_" for V4 fast-math and V5+ fast-math double-precision |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2196 | // (actually, keep fast-math and fast-math2 separate for now) |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 2197 | if (FastMath) { |
| 2198 | setLibcallName(RTLIB::ADD_F64, "__hexagon_fast_adddf3"); |
| 2199 | setLibcallName(RTLIB::SUB_F64, "__hexagon_fast_subdf3"); |
| 2200 | setLibcallName(RTLIB::MUL_F64, "__hexagon_fast_muldf3"); |
| 2201 | setLibcallName(RTLIB::DIV_F64, "__hexagon_fast_divdf3"); |
| 2202 | // Calling __hexagon_fast2_divsf3 with fast-math on V5 (ok). |
| 2203 | setLibcallName(RTLIB::DIV_F32, "__hexagon_fast_divsf3"); |
| 2204 | } else { |
| 2205 | setLibcallName(RTLIB::ADD_F64, "__hexagon_adddf3"); |
| 2206 | setLibcallName(RTLIB::SUB_F64, "__hexagon_subdf3"); |
| 2207 | setLibcallName(RTLIB::MUL_F64, "__hexagon_muldf3"); |
| 2208 | setLibcallName(RTLIB::DIV_F64, "__hexagon_divdf3"); |
| 2209 | setLibcallName(RTLIB::DIV_F32, "__hexagon_divsf3"); |
| 2210 | } |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2211 | |
| 2212 | if (Subtarget.hasV5TOps()) { |
| 2213 | if (FastMath) |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 2214 | setLibcallName(RTLIB::SQRT_F32, "__hexagon_fast2_sqrtf"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2215 | else |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 2216 | setLibcallName(RTLIB::SQRT_F32, "__hexagon_sqrtf"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2217 | } else { |
| 2218 | // V4 |
Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 2219 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__hexagon_floatsisf"); |
| 2220 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__hexagon_floatsidf"); |
| 2221 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__hexagon_floatdisf"); |
| 2222 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__hexagon_floatdidf"); |
| 2223 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__hexagon_floatunsisf"); |
| 2224 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__hexagon_floatunsidf"); |
| 2225 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__hexagon_floatundisf"); |
| 2226 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__hexagon_floatundidf"); |
| 2227 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__hexagon_fixunssfsi"); |
| 2228 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__hexagon_fixunssfdi"); |
| 2229 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__hexagon_fixunsdfsi"); |
| 2230 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__hexagon_fixunsdfdi"); |
| 2231 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__hexagon_fixsfsi"); |
| 2232 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__hexagon_fixsfdi"); |
| 2233 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__hexagon_fixdfsi"); |
| 2234 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__hexagon_fixdfdi"); |
| 2235 | setLibcallName(RTLIB::FPEXT_F32_F64, "__hexagon_extendsfdf2"); |
| 2236 | setLibcallName(RTLIB::FPROUND_F64_F32, "__hexagon_truncdfsf2"); |
| 2237 | setLibcallName(RTLIB::OEQ_F32, "__hexagon_eqsf2"); |
| 2238 | setLibcallName(RTLIB::OEQ_F64, "__hexagon_eqdf2"); |
| 2239 | setLibcallName(RTLIB::OGE_F32, "__hexagon_gesf2"); |
| 2240 | setLibcallName(RTLIB::OGE_F64, "__hexagon_gedf2"); |
| 2241 | setLibcallName(RTLIB::OLE_F32, "__hexagon_lesf2"); |
| 2242 | setLibcallName(RTLIB::OLE_F64, "__hexagon_ledf2"); |
| 2243 | setLibcallName(RTLIB::UNE_F32, "__hexagon_nesf2"); |
| 2244 | setLibcallName(RTLIB::UNE_F64, "__hexagon_nedf2"); |
| 2245 | setLibcallName(RTLIB::UO_F32, "__hexagon_unordsf2"); |
| 2246 | setLibcallName(RTLIB::UO_F64, "__hexagon_unorddf2"); |
| 2247 | setLibcallName(RTLIB::O_F32, "__hexagon_unordsf2"); |
| 2248 | setLibcallName(RTLIB::O_F64, "__hexagon_unorddf2"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | // These cause problems when the shift amount is non-constant. |
| 2252 | setLibcallName(RTLIB::SHL_I128, nullptr); |
| 2253 | setLibcallName(RTLIB::SRL_I128, nullptr); |
| 2254 | setLibcallName(RTLIB::SRA_I128, nullptr); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2257 | const char* HexagonTargetLowering::getTargetNodeName(unsigned Opcode) const { |
Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 2258 | switch ((HexagonISD::NodeType)Opcode) { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2259 | case HexagonISD::ALLOCA: return "HexagonISD::ALLOCA"; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2260 | case HexagonISD::AT_GOT: return "HexagonISD::AT_GOT"; |
| 2261 | case HexagonISD::AT_PCREL: return "HexagonISD::AT_PCREL"; |
| 2262 | case HexagonISD::BARRIER: return "HexagonISD::BARRIER"; |
Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 2263 | case HexagonISD::CALL: return "HexagonISD::CALL"; |
| 2264 | case HexagonISD::CALLnr: return "HexagonISD::CALLnr"; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2265 | case HexagonISD::CALLR: return "HexagonISD::CALLR"; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2266 | case HexagonISD::COMBINE: return "HexagonISD::COMBINE"; |
| 2267 | case HexagonISD::CONST32_GP: return "HexagonISD::CONST32_GP"; |
| 2268 | case HexagonISD::CONST32: return "HexagonISD::CONST32"; |
| 2269 | case HexagonISD::CP: return "HexagonISD::CP"; |
| 2270 | case HexagonISD::DCFETCH: return "HexagonISD::DCFETCH"; |
| 2271 | case HexagonISD::EH_RETURN: return "HexagonISD::EH_RETURN"; |
| 2272 | case HexagonISD::EXTRACTU: return "HexagonISD::EXTRACTU"; |
| 2273 | case HexagonISD::EXTRACTURP: return "HexagonISD::EXTRACTURP"; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2274 | case HexagonISD::INSERT: return "HexagonISD::INSERT"; |
| 2275 | case HexagonISD::INSERTRP: return "HexagonISD::INSERTRP"; |
| 2276 | case HexagonISD::JT: return "HexagonISD::JT"; |
| 2277 | case HexagonISD::PACKHL: return "HexagonISD::PACKHL"; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2278 | case HexagonISD::POPCOUNT: return "HexagonISD::POPCOUNT"; |
| 2279 | case HexagonISD::RET_FLAG: return "HexagonISD::RET_FLAG"; |
| 2280 | case HexagonISD::SHUFFEB: return "HexagonISD::SHUFFEB"; |
| 2281 | case HexagonISD::SHUFFEH: return "HexagonISD::SHUFFEH"; |
| 2282 | case HexagonISD::SHUFFOB: return "HexagonISD::SHUFFOB"; |
| 2283 | case HexagonISD::SHUFFOH: return "HexagonISD::SHUFFOH"; |
| 2284 | case HexagonISD::TC_RETURN: return "HexagonISD::TC_RETURN"; |
| 2285 | case HexagonISD::VCMPBEQ: return "HexagonISD::VCMPBEQ"; |
| 2286 | case HexagonISD::VCMPBGT: return "HexagonISD::VCMPBGT"; |
| 2287 | case HexagonISD::VCMPBGTU: return "HexagonISD::VCMPBGTU"; |
| 2288 | case HexagonISD::VCMPHEQ: return "HexagonISD::VCMPHEQ"; |
| 2289 | case HexagonISD::VCMPHGT: return "HexagonISD::VCMPHGT"; |
| 2290 | case HexagonISD::VCMPHGTU: return "HexagonISD::VCMPHGTU"; |
| 2291 | case HexagonISD::VCMPWEQ: return "HexagonISD::VCMPWEQ"; |
| 2292 | case HexagonISD::VCMPWGT: return "HexagonISD::VCMPWGT"; |
| 2293 | case HexagonISD::VCMPWGTU: return "HexagonISD::VCMPWGTU"; |
Krzysztof Parzyszek | c168c01 | 2015-12-03 16:47:20 +0000 | [diff] [blame] | 2294 | case HexagonISD::VCOMBINE: return "HexagonISD::VCOMBINE"; |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2295 | case HexagonISD::VPACK: return "HexagonISD::VPACK"; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2296 | case HexagonISD::VSHLH: return "HexagonISD::VSHLH"; |
| 2297 | case HexagonISD::VSHLW: return "HexagonISD::VSHLW"; |
| 2298 | case HexagonISD::VSPLATB: return "HexagonISD::VSPLTB"; |
| 2299 | case HexagonISD::VSPLATH: return "HexagonISD::VSPLATH"; |
| 2300 | case HexagonISD::VSRAH: return "HexagonISD::VSRAH"; |
| 2301 | case HexagonISD::VSRAW: return "HexagonISD::VSRAW"; |
| 2302 | case HexagonISD::VSRLH: return "HexagonISD::VSRLH"; |
| 2303 | case HexagonISD::VSRLW: return "HexagonISD::VSRLW"; |
| 2304 | case HexagonISD::VSXTBH: return "HexagonISD::VSXTBH"; |
| 2305 | case HexagonISD::VSXTBW: return "HexagonISD::VSXTBW"; |
Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 2306 | case HexagonISD::OP_END: break; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2307 | } |
Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 2308 | return nullptr; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2311 | bool HexagonTargetLowering::isTruncateFree(Type *Ty1, Type *Ty2) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2312 | EVT MTy1 = EVT::getEVT(Ty1); |
| 2313 | EVT MTy2 = EVT::getEVT(Ty2); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2314 | if (!MTy1.isSimple() || !MTy2.isSimple()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2315 | return false; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2316 | return (MTy1.getSimpleVT() == MVT::i64) && (MTy2.getSimpleVT() == MVT::i32); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | bool HexagonTargetLowering::isTruncateFree(EVT VT1, EVT VT2) const { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2320 | if (!VT1.isSimple() || !VT2.isSimple()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2321 | return false; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2322 | return (VT1.getSimpleVT() == MVT::i64) && (VT2.getSimpleVT() == MVT::i32); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
Krzysztof Parzyszek | bd8ef4b | 2016-08-19 13:34:31 +0000 | [diff] [blame] | 2325 | bool HexagonTargetLowering::isFMAFasterThanFMulAndFAdd(EVT VT) const { |
| 2326 | return isOperationLegalOrCustom(ISD::FMA, VT); |
| 2327 | } |
| 2328 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2329 | // Should we expand the build vector with shuffles? |
Krzysztof Parzyszek | d19d050 | 2016-09-13 21:16:07 +0000 | [diff] [blame] | 2330 | bool HexagonTargetLowering::shouldExpandBuildVectorWithShuffles(EVT VT, |
| 2331 | unsigned DefinedValues) const { |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2332 | // Hexagon vector shuffle operates on element sizes of bytes or halfwords |
| 2333 | EVT EltVT = VT.getVectorElementType(); |
| 2334 | int EltBits = EltVT.getSizeInBits(); |
| 2335 | if ((EltBits != 8) && (EltBits != 16)) |
| 2336 | return false; |
| 2337 | |
| 2338 | return TargetLowering::shouldExpandBuildVectorWithShuffles(VT, DefinedValues); |
| 2339 | } |
| 2340 | |
Krzysztof Parzyszek | d19d050 | 2016-09-13 21:16:07 +0000 | [diff] [blame] | 2341 | static StridedLoadKind isStridedLoad(const ArrayRef<int> &Mask) { |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2342 | int even_start = -2; |
| 2343 | int odd_start = -1; |
| 2344 | size_t mask_len = Mask.size(); |
| 2345 | for (auto idx : Mask) { |
| 2346 | if ((idx - even_start) == 2) |
| 2347 | even_start = idx; |
| 2348 | else |
| 2349 | break; |
| 2350 | } |
| 2351 | if (even_start == (int)(mask_len * 2) - 2) |
| 2352 | return StridedLoadKind::Even; |
| 2353 | for (auto idx : Mask) { |
| 2354 | if ((idx - odd_start) == 2) |
| 2355 | odd_start = idx; |
| 2356 | else |
| 2357 | break; |
| 2358 | } |
| 2359 | if (odd_start == (int)(mask_len * 2) - 1) |
| 2360 | return StridedLoadKind::Odd; |
| 2361 | |
| 2362 | return StridedLoadKind::NoPattern; |
| 2363 | } |
| 2364 | |
Krzysztof Parzyszek | d19d050 | 2016-09-13 21:16:07 +0000 | [diff] [blame] | 2365 | bool HexagonTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &Mask, |
| 2366 | EVT VT) const { |
| 2367 | if (Subtarget.useHVXOps()) |
| 2368 | return isStridedLoad(Mask) != StridedLoadKind::NoPattern; |
| 2369 | return true; |
| 2370 | } |
| 2371 | |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2372 | // Lower a vector shuffle (V1, V2, V3). V1 and V2 are the two vectors |
| 2373 | // to select data from, V3 is the permutation. |
| 2374 | SDValue |
| 2375 | HexagonTargetLowering::LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) |
| 2376 | const { |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2377 | const ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op); |
| 2378 | SDValue V1 = Op.getOperand(0); |
| 2379 | SDValue V2 = Op.getOperand(1); |
| 2380 | SDLoc dl(Op); |
| 2381 | EVT VT = Op.getValueType(); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2382 | bool UseHVX = Subtarget.useHVXOps(); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2383 | |
Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 2384 | if (V2.isUndef()) |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2385 | V2 = V1; |
| 2386 | |
| 2387 | if (SVN->isSplat()) { |
| 2388 | int Lane = SVN->getSplatIndex(); |
| 2389 | if (Lane == -1) Lane = 0; |
| 2390 | |
| 2391 | // Test if V1 is a SCALAR_TO_VECTOR. |
| 2392 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) |
| 2393 | return createSplat(DAG, dl, VT, V1.getOperand(0)); |
| 2394 | |
| 2395 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
| 2396 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization |
| 2397 | // reaches it). |
| 2398 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && |
| 2399 | !isa<ConstantSDNode>(V1.getOperand(0))) { |
| 2400 | bool IsScalarToVector = true; |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 2401 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) { |
Sanjay Patel | 7506852 | 2016-03-14 18:09:43 +0000 | [diff] [blame] | 2402 | if (!V1.getOperand(i).isUndef()) { |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2403 | IsScalarToVector = false; |
| 2404 | break; |
| 2405 | } |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 2406 | } |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2407 | if (IsScalarToVector) |
| 2408 | return createSplat(DAG, dl, VT, V1.getOperand(0)); |
| 2409 | } |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2410 | return createSplat(DAG, dl, VT, DAG.getConstant(Lane, dl, MVT::i32)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2411 | } |
| 2412 | |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2413 | if (UseHVX) { |
| 2414 | ArrayRef<int> Mask = SVN->getMask(); |
| 2415 | size_t MaskLen = Mask.size(); |
Sanjay Patel | 1ed771f | 2016-09-14 16:37:15 +0000 | [diff] [blame] | 2416 | int ElemSizeInBits = VT.getScalarSizeInBits(); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2417 | if ((Subtarget.useHVXSglOps() && (ElemSizeInBits * MaskLen) == 64 * 8) || |
| 2418 | (Subtarget.useHVXDblOps() && (ElemSizeInBits * MaskLen) == 128 * 8)) { |
| 2419 | // Return 1 for odd and 2 of even |
| 2420 | StridedLoadKind Pattern = isStridedLoad(Mask); |
| 2421 | |
| 2422 | if (Pattern == StridedLoadKind::NoPattern) |
| 2423 | return SDValue(); |
| 2424 | |
| 2425 | SDValue Vec0 = Op.getOperand(0); |
| 2426 | SDValue Vec1 = Op.getOperand(1); |
| 2427 | SDValue StridePattern = DAG.getConstant(Pattern, dl, MVT::i32); |
| 2428 | SDValue Ops[] = { Vec1, Vec0, StridePattern }; |
| 2429 | return DAG.getNode(HexagonISD::VPACK, dl, VT, Ops); |
| 2430 | } |
| 2431 | // We used to assert in the "else" part here, but that is bad for Halide |
| 2432 | // Halide creates intermediate double registers by interleaving two |
| 2433 | // concatenated vector registers. The interleaving requires vector_shuffle |
| 2434 | // nodes and we shouldn't barf on a double register result of a |
| 2435 | // vector_shuffle because it is most likely an intermediate result. |
| 2436 | } |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2437 | // FIXME: We need to support more general vector shuffles. See |
| 2438 | // below the comment from the ARM backend that deals in the general |
| 2439 | // case with the vector shuffles. For now, let expand handle these. |
| 2440 | return SDValue(); |
| 2441 | |
| 2442 | // If the shuffle is not directly supported and it has 4 elements, use |
| 2443 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
| 2444 | } |
| 2445 | |
| 2446 | // If BUILD_VECTOR has same base element repeated several times, |
| 2447 | // report true. |
| 2448 | static bool isCommonSplatElement(BuildVectorSDNode *BVN) { |
| 2449 | unsigned NElts = BVN->getNumOperands(); |
| 2450 | SDValue V0 = BVN->getOperand(0); |
| 2451 | |
| 2452 | for (unsigned i = 1, e = NElts; i != e; ++i) { |
| 2453 | if (BVN->getOperand(i) != V0) |
| 2454 | return false; |
| 2455 | } |
| 2456 | return true; |
| 2457 | } |
| 2458 | |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2459 | // Lower a vector shift. Try to convert |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2460 | // <VT> = SHL/SRA/SRL <VT> by <VT> to Hexagon specific |
| 2461 | // <VT> = SHL/SRA/SRL <VT> by <IT/i32>. |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2462 | SDValue |
| 2463 | HexagonTargetLowering::LowerVECTOR_SHIFT(SDValue Op, SelectionDAG &DAG) const { |
Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 2464 | BuildVectorSDNode *BVN = nullptr; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2465 | SDValue V1 = Op.getOperand(0); |
| 2466 | SDValue V2 = Op.getOperand(1); |
| 2467 | SDValue V3; |
| 2468 | SDLoc dl(Op); |
| 2469 | EVT VT = Op.getValueType(); |
| 2470 | |
| 2471 | if ((BVN = dyn_cast<BuildVectorSDNode>(V1.getNode())) && |
| 2472 | isCommonSplatElement(BVN)) |
| 2473 | V3 = V2; |
| 2474 | else if ((BVN = dyn_cast<BuildVectorSDNode>(V2.getNode())) && |
| 2475 | isCommonSplatElement(BVN)) |
| 2476 | V3 = V1; |
| 2477 | else |
| 2478 | return SDValue(); |
| 2479 | |
| 2480 | SDValue CommonSplat = BVN->getOperand(0); |
| 2481 | SDValue Result; |
| 2482 | |
| 2483 | if (VT.getSimpleVT() == MVT::v4i16) { |
| 2484 | switch (Op.getOpcode()) { |
| 2485 | case ISD::SRA: |
| 2486 | Result = DAG.getNode(HexagonISD::VSRAH, dl, VT, V3, CommonSplat); |
| 2487 | break; |
| 2488 | case ISD::SHL: |
| 2489 | Result = DAG.getNode(HexagonISD::VSHLH, dl, VT, V3, CommonSplat); |
| 2490 | break; |
| 2491 | case ISD::SRL: |
| 2492 | Result = DAG.getNode(HexagonISD::VSRLH, dl, VT, V3, CommonSplat); |
| 2493 | break; |
| 2494 | default: |
| 2495 | return SDValue(); |
| 2496 | } |
| 2497 | } else if (VT.getSimpleVT() == MVT::v2i32) { |
| 2498 | switch (Op.getOpcode()) { |
| 2499 | case ISD::SRA: |
| 2500 | Result = DAG.getNode(HexagonISD::VSRAW, dl, VT, V3, CommonSplat); |
| 2501 | break; |
| 2502 | case ISD::SHL: |
| 2503 | Result = DAG.getNode(HexagonISD::VSHLW, dl, VT, V3, CommonSplat); |
| 2504 | break; |
| 2505 | case ISD::SRL: |
| 2506 | Result = DAG.getNode(HexagonISD::VSRLW, dl, VT, V3, CommonSplat); |
| 2507 | break; |
| 2508 | default: |
| 2509 | return SDValue(); |
| 2510 | } |
| 2511 | } else { |
| 2512 | return SDValue(); |
| 2513 | } |
| 2514 | |
| 2515 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 2516 | } |
| 2517 | |
| 2518 | SDValue |
| 2519 | HexagonTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const { |
| 2520 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
| 2521 | SDLoc dl(Op); |
| 2522 | EVT VT = Op.getValueType(); |
| 2523 | |
| 2524 | unsigned Size = VT.getSizeInBits(); |
| 2525 | |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2526 | // Only handle vectors of 64 bits or shorter. |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2527 | if (Size > 64) |
| 2528 | return SDValue(); |
| 2529 | |
| 2530 | APInt APSplatBits, APSplatUndef; |
| 2531 | unsigned SplatBitSize; |
| 2532 | bool HasAnyUndefs; |
| 2533 | unsigned NElts = BVN->getNumOperands(); |
| 2534 | |
| 2535 | // Try to generate a SPLAT instruction. |
| 2536 | if ((VT.getSimpleVT() == MVT::v4i8 || VT.getSimpleVT() == MVT::v4i16) && |
| 2537 | (BVN->isConstantSplat(APSplatBits, APSplatUndef, SplatBitSize, |
| 2538 | HasAnyUndefs, 0, true) && SplatBitSize <= 16)) { |
| 2539 | unsigned SplatBits = APSplatBits.getZExtValue(); |
| 2540 | int32_t SextVal = ((int32_t) (SplatBits << (32 - SplatBitSize)) >> |
| 2541 | (32 - SplatBitSize)); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2542 | return createSplat(DAG, dl, VT, DAG.getConstant(SextVal, dl, MVT::i32)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | // Try to generate COMBINE to build v2i32 vectors. |
| 2546 | if (VT.getSimpleVT() == MVT::v2i32) { |
| 2547 | SDValue V0 = BVN->getOperand(0); |
| 2548 | SDValue V1 = BVN->getOperand(1); |
| 2549 | |
Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 2550 | if (V0.isUndef()) |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2551 | V0 = DAG.getConstant(0, dl, MVT::i32); |
Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 2552 | if (V1.isUndef()) |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2553 | V1 = DAG.getConstant(0, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2554 | |
| 2555 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(V0); |
| 2556 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(V1); |
| 2557 | // If the element isn't a constant, it is in a register: |
| 2558 | // generate a COMBINE Register Register instruction. |
| 2559 | if (!C0 || !C1) |
| 2560 | return DAG.getNode(HexagonISD::COMBINE, dl, VT, V1, V0); |
| 2561 | |
| 2562 | // If one of the operands is an 8 bit integer constant, generate |
| 2563 | // a COMBINE Immediate Immediate instruction. |
| 2564 | if (isInt<8>(C0->getSExtValue()) || |
| 2565 | isInt<8>(C1->getSExtValue())) |
| 2566 | return DAG.getNode(HexagonISD::COMBINE, dl, VT, V1, V0); |
| 2567 | } |
| 2568 | |
| 2569 | // Try to generate a S2_packhl to build v2i16 vectors. |
| 2570 | if (VT.getSimpleVT() == MVT::v2i16) { |
| 2571 | for (unsigned i = 0, e = NElts; i != e; ++i) { |
Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 2572 | if (BVN->getOperand(i).isUndef()) |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2573 | continue; |
| 2574 | ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(BVN->getOperand(i)); |
| 2575 | // If the element isn't a constant, it is in a register: |
| 2576 | // generate a S2_packhl instruction. |
| 2577 | if (!Cst) { |
| 2578 | SDValue pack = DAG.getNode(HexagonISD::PACKHL, dl, MVT::v4i16, |
| 2579 | BVN->getOperand(1), BVN->getOperand(0)); |
| 2580 | |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 2581 | return DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::v2i16, |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2582 | pack); |
| 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | // In the general case, generate a CONST32 or a CONST64 for constant vectors, |
| 2588 | // and insert_vector_elt for all the other cases. |
| 2589 | uint64_t Res = 0; |
| 2590 | unsigned EltSize = Size / NElts; |
| 2591 | SDValue ConstVal; |
| 2592 | uint64_t Mask = ~uint64_t(0ULL) >> (64 - EltSize); |
| 2593 | bool HasNonConstantElements = false; |
| 2594 | |
| 2595 | for (unsigned i = 0, e = NElts; i != e; ++i) { |
| 2596 | // LLVM's BUILD_VECTOR operands are in Little Endian mode, whereas Hexagon's |
| 2597 | // combine, const64, etc. are Big Endian. |
| 2598 | unsigned OpIdx = NElts - i - 1; |
| 2599 | SDValue Operand = BVN->getOperand(OpIdx); |
Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 2600 | if (Operand.isUndef()) |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2601 | continue; |
| 2602 | |
| 2603 | int64_t Val = 0; |
| 2604 | if (ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(Operand)) |
| 2605 | Val = Cst->getSExtValue(); |
| 2606 | else |
| 2607 | HasNonConstantElements = true; |
| 2608 | |
| 2609 | Val &= Mask; |
| 2610 | Res = (Res << EltSize) | Val; |
| 2611 | } |
| 2612 | |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2613 | if (Size > 64) |
| 2614 | return SDValue(); |
| 2615 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2616 | if (Size == 64) |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2617 | ConstVal = DAG.getConstant(Res, dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2618 | else |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2619 | ConstVal = DAG.getConstant(Res, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2620 | |
| 2621 | // When there are non constant operands, add them with INSERT_VECTOR_ELT to |
| 2622 | // ConstVal, the constant part of the vector. |
| 2623 | if (HasNonConstantElements) { |
| 2624 | EVT EltVT = VT.getVectorElementType(); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2625 | SDValue Width = DAG.getConstant(EltVT.getSizeInBits(), dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2626 | SDValue Shifted = DAG.getNode(ISD::SHL, dl, MVT::i64, Width, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2627 | DAG.getConstant(32, dl, MVT::i64)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2628 | |
| 2629 | for (unsigned i = 0, e = NElts; i != e; ++i) { |
| 2630 | // LLVM's BUILD_VECTOR operands are in Little Endian mode, whereas Hexagon |
| 2631 | // is Big Endian. |
| 2632 | unsigned OpIdx = NElts - i - 1; |
| 2633 | SDValue Operand = BVN->getOperand(OpIdx); |
Benjamin Kramer | 619c4e5 | 2015-04-10 11:24:51 +0000 | [diff] [blame] | 2634 | if (isa<ConstantSDNode>(Operand)) |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2635 | // This operand is already in ConstVal. |
| 2636 | continue; |
| 2637 | |
| 2638 | if (VT.getSizeInBits() == 64 && |
Sanjay Patel | b1f0a0f | 2016-09-14 16:05:51 +0000 | [diff] [blame] | 2639 | Operand.getValueSizeInBits() == 32) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2640 | SDValue C = DAG.getConstant(0, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2641 | Operand = DAG.getNode(HexagonISD::COMBINE, dl, VT, C, Operand); |
| 2642 | } |
| 2643 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2644 | SDValue Idx = DAG.getConstant(OpIdx, dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2645 | SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i64, Idx, Width); |
| 2646 | SDValue Combined = DAG.getNode(ISD::OR, dl, MVT::i64, Shifted, Offset); |
| 2647 | const SDValue Ops[] = {ConstVal, Operand, Combined}; |
| 2648 | |
| 2649 | if (VT.getSizeInBits() == 32) |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2650 | ConstVal = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i32, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2651 | else |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2652 | ConstVal = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i64, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2653 | } |
| 2654 | } |
| 2655 | |
| 2656 | return DAG.getNode(ISD::BITCAST, dl, VT, ConstVal); |
| 2657 | } |
| 2658 | |
| 2659 | SDValue |
| 2660 | HexagonTargetLowering::LowerCONCAT_VECTORS(SDValue Op, |
| 2661 | SelectionDAG &DAG) const { |
| 2662 | SDLoc dl(Op); |
Krzysztof Parzyszek | c168c01 | 2015-12-03 16:47:20 +0000 | [diff] [blame] | 2663 | bool UseHVX = Subtarget.useHVXOps(); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2664 | EVT VT = Op.getValueType(); |
| 2665 | unsigned NElts = Op.getNumOperands(); |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2666 | SDValue Vec0 = Op.getOperand(0); |
| 2667 | EVT VecVT = Vec0.getValueType(); |
| 2668 | unsigned Width = VecVT.getSizeInBits(); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2669 | |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2670 | if (NElts == 2) { |
| 2671 | MVT ST = VecVT.getSimpleVT(); |
| 2672 | // We are trying to concat two v2i16 to a single v4i16, or two v4i8 |
| 2673 | // into a single v8i8. |
| 2674 | if (ST == MVT::v2i16 || ST == MVT::v4i8) |
| 2675 | return DAG.getNode(HexagonISD::COMBINE, dl, VT, Op.getOperand(1), Vec0); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2676 | |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2677 | if (UseHVX) { |
| 2678 | assert((Width == 64*8 && Subtarget.useHVXSglOps()) || |
| 2679 | (Width == 128*8 && Subtarget.useHVXDblOps())); |
| 2680 | SDValue Vec1 = Op.getOperand(1); |
| 2681 | MVT OpTy = Subtarget.useHVXSglOps() ? MVT::v16i32 : MVT::v32i32; |
| 2682 | MVT ReTy = Subtarget.useHVXSglOps() ? MVT::v32i32 : MVT::v64i32; |
| 2683 | SDValue B0 = DAG.getNode(ISD::BITCAST, dl, OpTy, Vec0); |
| 2684 | SDValue B1 = DAG.getNode(ISD::BITCAST, dl, OpTy, Vec1); |
| 2685 | SDValue VC = DAG.getNode(HexagonISD::VCOMBINE, dl, ReTy, B1, B0); |
| 2686 | return DAG.getNode(ISD::BITCAST, dl, VT, VC); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2687 | } |
| 2688 | } |
| 2689 | |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2690 | if (VT.getSizeInBits() != 32 && VT.getSizeInBits() != 64) |
| 2691 | return SDValue(); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2692 | |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2693 | SDValue C0 = DAG.getConstant(0, dl, MVT::i64); |
| 2694 | SDValue C32 = DAG.getConstant(32, dl, MVT::i64); |
| 2695 | SDValue W = DAG.getConstant(Width, dl, MVT::i64); |
| 2696 | // Create the "width" part of the argument to insert_rp/insertp_rp. |
| 2697 | SDValue S = DAG.getNode(ISD::SHL, dl, MVT::i64, W, C32); |
| 2698 | SDValue V = C0; |
| 2699 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2700 | for (unsigned i = 0, e = NElts; i != e; ++i) { |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2701 | unsigned N = NElts-i-1; |
| 2702 | SDValue OpN = Op.getOperand(N); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2703 | |
Sanjay Patel | b1f0a0f | 2016-09-14 16:05:51 +0000 | [diff] [blame] | 2704 | if (VT.getSizeInBits() == 64 && OpN.getValueSizeInBits() == 32) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2705 | SDValue C = DAG.getConstant(0, dl, MVT::i32); |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2706 | OpN = DAG.getNode(HexagonISD::COMBINE, dl, VT, C, OpN); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2707 | } |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2708 | SDValue Idx = DAG.getConstant(N, dl, MVT::i64); |
| 2709 | SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i64, Idx, W); |
| 2710 | SDValue Or = DAG.getNode(ISD::OR, dl, MVT::i64, S, Offset); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2711 | if (VT.getSizeInBits() == 32) |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2712 | V = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i32, {V, OpN, Or}); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2713 | else if (VT.getSizeInBits() == 64) |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2714 | V = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i64, {V, OpN, Or}); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2715 | else |
| 2716 | return SDValue(); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2717 | } |
| 2718 | |
Krzysztof Parzyszek | f1b3e5e | 2015-12-04 16:18:15 +0000 | [diff] [blame] | 2719 | return DAG.getNode(ISD::BITCAST, dl, VT, V); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | SDValue |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2723 | HexagonTargetLowering::LowerEXTRACT_SUBVECTOR_HVX(SDValue Op, |
| 2724 | SelectionDAG &DAG) const { |
| 2725 | EVT VT = Op.getOperand(0).getValueType(); |
| 2726 | SDLoc dl(Op); |
| 2727 | bool UseHVX = Subtarget.useHVXOps(); |
| 2728 | bool UseHVXSgl = Subtarget.useHVXSglOps(); |
| 2729 | // Just in case... |
| 2730 | |
| 2731 | if (!VT.isVector() || !UseHVX) |
| 2732 | return SDValue(); |
| 2733 | |
| 2734 | EVT ResVT = Op.getValueType(); |
| 2735 | unsigned ResSize = ResVT.getSizeInBits(); |
| 2736 | unsigned VectorSizeInBits = UseHVXSgl ? (64 * 8) : (128 * 8); |
| 2737 | unsigned OpSize = VT.getSizeInBits(); |
| 2738 | |
| 2739 | // We deal only with cases where the result is the vector size |
| 2740 | // and the vector operand is a double register. |
| 2741 | if (!(ResVT.isByteSized() && ResSize == VectorSizeInBits) || |
| 2742 | !(VT.isByteSized() && OpSize == 2 * VectorSizeInBits)) |
| 2743 | return SDValue(); |
| 2744 | |
| 2745 | ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(Op.getOperand(1)); |
| 2746 | if (!Cst) |
| 2747 | return SDValue(); |
| 2748 | unsigned Val = Cst->getZExtValue(); |
| 2749 | |
| 2750 | // These two will get lowered to an appropriate EXTRACT_SUBREG in ISel. |
| 2751 | if (Val == 0) { |
| 2752 | SDValue Vec = Op.getOperand(0); |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 2753 | return DAG.getTargetExtractSubreg(Hexagon::vsub_lo, dl, ResVT, Vec); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | if (ResVT.getVectorNumElements() == Val) { |
| 2757 | SDValue Vec = Op.getOperand(0); |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 2758 | return DAG.getTargetExtractSubreg(Hexagon::vsub_hi, dl, ResVT, Vec); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | return SDValue(); |
| 2762 | } |
| 2763 | |
| 2764 | SDValue |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2765 | HexagonTargetLowering::LowerEXTRACT_VECTOR(SDValue Op, |
| 2766 | SelectionDAG &DAG) const { |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2767 | // If we are dealing with EXTRACT_SUBVECTOR on a HVX type, we may |
| 2768 | // be able to simplify it to an EXTRACT_SUBREG. |
| 2769 | if (Op.getOpcode() == ISD::EXTRACT_SUBVECTOR && Subtarget.useHVXOps() && |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 2770 | isHvxVectorType(Op.getValueType().getSimpleVT())) |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2771 | return LowerEXTRACT_SUBVECTOR_HVX(Op, DAG); |
| 2772 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2773 | EVT VT = Op.getValueType(); |
| 2774 | int VTN = VT.isVector() ? VT.getVectorNumElements() : 1; |
| 2775 | SDLoc dl(Op); |
| 2776 | SDValue Idx = Op.getOperand(1); |
| 2777 | SDValue Vec = Op.getOperand(0); |
| 2778 | EVT VecVT = Vec.getValueType(); |
| 2779 | EVT EltVT = VecVT.getVectorElementType(); |
| 2780 | int EltSize = EltVT.getSizeInBits(); |
| 2781 | SDValue Width = DAG.getConstant(Op.getOpcode() == ISD::EXTRACT_VECTOR_ELT ? |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2782 | EltSize : VTN * EltSize, dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2783 | |
| 2784 | // Constant element number. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2785 | if (ConstantSDNode *CI = dyn_cast<ConstantSDNode>(Idx)) { |
| 2786 | uint64_t X = CI->getZExtValue(); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2787 | SDValue Offset = DAG.getConstant(X * EltSize, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2788 | const SDValue Ops[] = {Vec, Width, Offset}; |
| 2789 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2790 | ConstantSDNode *CW = dyn_cast<ConstantSDNode>(Width); |
| 2791 | assert(CW && "Non constant width in LowerEXTRACT_VECTOR"); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2792 | |
| 2793 | SDValue N; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2794 | MVT SVT = VecVT.getSimpleVT(); |
| 2795 | uint64_t W = CW->getZExtValue(); |
| 2796 | |
| 2797 | if (W == 32) { |
| 2798 | // Translate this node into EXTRACT_SUBREG. |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 2799 | unsigned Subreg = (X == 0) ? Hexagon::isub_lo : 0; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2800 | |
| 2801 | if (X == 0) |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 2802 | Subreg = Hexagon::isub_lo; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2803 | else if (SVT == MVT::v2i32 && X == 1) |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 2804 | Subreg = Hexagon::isub_hi; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2805 | else if (SVT == MVT::v4i16 && X == 2) |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 2806 | Subreg = Hexagon::isub_hi; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2807 | else if (SVT == MVT::v8i8 && X == 4) |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 2808 | Subreg = Hexagon::isub_hi; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2809 | else |
| 2810 | llvm_unreachable("Bad offset"); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2811 | N = DAG.getTargetExtractSubreg(Subreg, dl, MVT::i32, Vec); |
| 2812 | |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2813 | } else if (SVT.getSizeInBits() == 32) { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2814 | N = DAG.getNode(HexagonISD::EXTRACTU, dl, MVT::i32, Ops); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2815 | } else if (SVT.getSizeInBits() == 64) { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2816 | N = DAG.getNode(HexagonISD::EXTRACTU, dl, MVT::i64, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2817 | if (VT.getSizeInBits() == 32) |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 2818 | N = DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::i32, N); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2819 | } else |
| 2820 | return SDValue(); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2821 | |
| 2822 | return DAG.getNode(ISD::BITCAST, dl, VT, N); |
| 2823 | } |
| 2824 | |
| 2825 | // Variable element number. |
| 2826 | SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i32, Idx, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2827 | DAG.getConstant(EltSize, dl, MVT::i32)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2828 | SDValue Shifted = DAG.getNode(ISD::SHL, dl, MVT::i64, Width, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2829 | DAG.getConstant(32, dl, MVT::i64)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2830 | SDValue Combined = DAG.getNode(ISD::OR, dl, MVT::i64, Shifted, Offset); |
| 2831 | |
| 2832 | const SDValue Ops[] = {Vec, Combined}; |
| 2833 | |
| 2834 | SDValue N; |
| 2835 | if (VecVT.getSizeInBits() == 32) { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2836 | N = DAG.getNode(HexagonISD::EXTRACTURP, dl, MVT::i32, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2837 | } else { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2838 | N = DAG.getNode(HexagonISD::EXTRACTURP, dl, MVT::i64, Ops); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2839 | if (VT.getSizeInBits() == 32) |
Krzysztof Parzyszek | a540997 | 2016-11-09 16:19:08 +0000 | [diff] [blame] | 2840 | N = DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::i32, N); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2841 | } |
| 2842 | return DAG.getNode(ISD::BITCAST, dl, VT, N); |
| 2843 | } |
| 2844 | |
| 2845 | SDValue |
| 2846 | HexagonTargetLowering::LowerINSERT_VECTOR(SDValue Op, |
| 2847 | SelectionDAG &DAG) const { |
| 2848 | EVT VT = Op.getValueType(); |
| 2849 | int VTN = VT.isVector() ? VT.getVectorNumElements() : 1; |
| 2850 | SDLoc dl(Op); |
| 2851 | SDValue Vec = Op.getOperand(0); |
| 2852 | SDValue Val = Op.getOperand(1); |
| 2853 | SDValue Idx = Op.getOperand(2); |
| 2854 | EVT VecVT = Vec.getValueType(); |
| 2855 | EVT EltVT = VecVT.getVectorElementType(); |
| 2856 | int EltSize = EltVT.getSizeInBits(); |
| 2857 | SDValue Width = DAG.getConstant(Op.getOpcode() == ISD::INSERT_VECTOR_ELT ? |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2858 | EltSize : VTN * EltSize, dl, MVT::i64); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2859 | |
| 2860 | if (ConstantSDNode *C = cast<ConstantSDNode>(Idx)) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2861 | SDValue Offset = DAG.getConstant(C->getSExtValue() * EltSize, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2862 | const SDValue Ops[] = {Vec, Val, Width, Offset}; |
| 2863 | |
| 2864 | SDValue N; |
| 2865 | if (VT.getSizeInBits() == 32) |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2866 | N = DAG.getNode(HexagonISD::INSERT, dl, MVT::i32, Ops); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2867 | else if (VT.getSizeInBits() == 64) |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2868 | N = DAG.getNode(HexagonISD::INSERT, dl, MVT::i64, Ops); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2869 | else |
| 2870 | return SDValue(); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2871 | |
| 2872 | return DAG.getNode(ISD::BITCAST, dl, VT, N); |
| 2873 | } |
| 2874 | |
| 2875 | // Variable element number. |
| 2876 | SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i32, Idx, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2877 | DAG.getConstant(EltSize, dl, MVT::i32)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2878 | SDValue Shifted = DAG.getNode(ISD::SHL, dl, MVT::i64, Width, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2879 | DAG.getConstant(32, dl, MVT::i64)); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2880 | SDValue Combined = DAG.getNode(ISD::OR, dl, MVT::i64, Shifted, Offset); |
| 2881 | |
Sanjay Patel | b1f0a0f | 2016-09-14 16:05:51 +0000 | [diff] [blame] | 2882 | if (VT.getSizeInBits() == 64 && Val.getValueSizeInBits() == 32) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2883 | SDValue C = DAG.getConstant(0, dl, MVT::i32); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2884 | Val = DAG.getNode(HexagonISD::COMBINE, dl, VT, C, Val); |
| 2885 | } |
| 2886 | |
| 2887 | const SDValue Ops[] = {Vec, Val, Combined}; |
| 2888 | |
| 2889 | SDValue N; |
| 2890 | if (VT.getSizeInBits() == 32) |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2891 | N = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i32, Ops); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2892 | else if (VT.getSizeInBits() == 64) |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2893 | N = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i64, Ops); |
Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2894 | else |
| 2895 | return SDValue(); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2896 | |
| 2897 | return DAG.getNode(ISD::BITCAST, dl, VT, N); |
| 2898 | } |
| 2899 | |
Tim Northover | a441585 | 2013-08-06 09:12:35 +0000 | [diff] [blame] | 2900 | bool |
| 2901 | HexagonTargetLowering::allowTruncateForTailCall(Type *Ty1, Type *Ty2) const { |
| 2902 | // Assuming the caller does not have either a signext or zeroext modifier, and |
| 2903 | // only one value is accepted, any reasonable truncation is allowed. |
| 2904 | if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy()) |
| 2905 | return false; |
| 2906 | |
| 2907 | // FIXME: in principle up to 64-bit could be made safe, but it would be very |
| 2908 | // fragile at the moment: any support for multiple value returns would be |
| 2909 | // liable to disallow tail calls involving i64 -> iN truncation in many cases. |
| 2910 | return Ty1->getPrimitiveSizeInBits() <= 32; |
| 2911 | } |
| 2912 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2913 | SDValue |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2914 | HexagonTargetLowering::LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const { |
| 2915 | SDValue Chain = Op.getOperand(0); |
| 2916 | SDValue Offset = Op.getOperand(1); |
| 2917 | SDValue Handler = Op.getOperand(2); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2918 | SDLoc dl(Op); |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2919 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2920 | |
| 2921 | // Mark function as containing a call to EH_RETURN. |
| 2922 | HexagonMachineFunctionInfo *FuncInfo = |
| 2923 | DAG.getMachineFunction().getInfo<HexagonMachineFunctionInfo>(); |
| 2924 | FuncInfo->setHasEHReturn(); |
| 2925 | |
| 2926 | unsigned OffsetReg = Hexagon::R28; |
| 2927 | |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2928 | SDValue StoreAddr = |
| 2929 | DAG.getNode(ISD::ADD, dl, PtrVT, DAG.getRegister(Hexagon::R30, PtrVT), |
| 2930 | DAG.getIntPtrConstant(4, dl)); |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2931 | Chain = DAG.getStore(Chain, dl, Handler, StoreAddr, MachinePointerInfo()); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2932 | Chain = DAG.getCopyToReg(Chain, dl, OffsetReg, Offset); |
| 2933 | |
| 2934 | // Not needed we already use it as explict input to EH_RETURN. |
| 2935 | // MF.getRegInfo().addLiveOut(OffsetReg); |
| 2936 | |
| 2937 | return DAG.getNode(HexagonISD::EH_RETURN, dl, MVT::Other, Chain); |
| 2938 | } |
| 2939 | |
| 2940 | SDValue |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2941 | HexagonTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2942 | unsigned Opc = Op.getOpcode(); |
| 2943 | switch (Opc) { |
| 2944 | default: |
| 2945 | #ifndef NDEBUG |
| 2946 | Op.getNode()->dumpr(&DAG); |
| 2947 | if (Opc > HexagonISD::OP_BEGIN && Opc < HexagonISD::OP_END) |
| 2948 | errs() << "Check for a non-legal type in this operation\n"; |
| 2949 | #endif |
| 2950 | llvm_unreachable("Should not custom lower this!"); |
| 2951 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
| 2952 | case ISD::INSERT_SUBVECTOR: return LowerINSERT_VECTOR(Op, DAG); |
| 2953 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR(Op, DAG); |
| 2954 | case ISD::EXTRACT_SUBVECTOR: return LowerEXTRACT_VECTOR(Op, DAG); |
| 2955 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR(Op, DAG); |
| 2956 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG); |
| 2957 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2958 | case ISD::SRA: |
| 2959 | case ISD::SHL: |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2960 | case ISD::SRL: return LowerVECTOR_SHIFT(Op, DAG); |
| 2961 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 2962 | case ISD::JumpTable: return LowerJumpTable(Op, DAG); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2963 | case ISD::EH_RETURN: return LowerEH_RETURN(Op, DAG); |
| 2964 | // Frame & Return address. Currently unimplemented. |
| 2965 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
| 2966 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 2967 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2968 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG); |
| 2969 | case ISD::GlobalAddress: return LowerGLOBALADDRESS(Op, DAG); |
| 2970 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 2971 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2972 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2973 | // Custom lower some vector loads. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2974 | case ISD::LOAD: return LowerLOAD(Op, DAG); |
| 2975 | case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); |
| 2976 | case ISD::SETCC: return LowerSETCC(Op, DAG); |
| 2977 | case ISD::VSELECT: return LowerVSELECT(Op, DAG); |
| 2978 | case ISD::CTPOP: return LowerCTPOP(Op, DAG); |
| 2979 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG); |
Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 2980 | case ISD::INTRINSIC_VOID: return LowerINTRINSIC_VOID(Op, DAG); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2981 | case ISD::INLINEASM: return LowerINLINEASM(Op, DAG); |
Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 2982 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2983 | } |
| 2984 | } |
| 2985 | |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 2986 | /// Returns relocation base for the given PIC jumptable. |
| 2987 | SDValue |
| 2988 | HexagonTargetLowering::getPICJumpTableRelocBase(SDValue Table, |
| 2989 | SelectionDAG &DAG) const { |
| 2990 | int Idx = cast<JumpTableSDNode>(Table)->getIndex(); |
| 2991 | EVT VT = Table.getValueType(); |
| 2992 | SDValue T = DAG.getTargetJumpTable(Idx, VT, HexagonII::MO_PCREL); |
| 2993 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Table), VT, T); |
| 2994 | } |
| 2995 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2996 | //===----------------------------------------------------------------------===// |
| 2997 | // Inline Assembly Support |
| 2998 | //===----------------------------------------------------------------------===// |
| 2999 | |
Krzysztof Parzyszek | ca3b532 | 2016-05-18 14:34:51 +0000 | [diff] [blame] | 3000 | TargetLowering::ConstraintType |
| 3001 | HexagonTargetLowering::getConstraintType(StringRef Constraint) const { |
| 3002 | if (Constraint.size() == 1) { |
| 3003 | switch (Constraint[0]) { |
| 3004 | case 'q': |
| 3005 | case 'v': |
| 3006 | if (Subtarget.useHVXOps()) |
| 3007 | return C_Register; |
| 3008 | break; |
| 3009 | } |
| 3010 | } |
| 3011 | return TargetLowering::getConstraintType(Constraint); |
| 3012 | } |
| 3013 | |
Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 3014 | std::pair<unsigned, const TargetRegisterClass*> |
Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 3015 | HexagonTargetLowering::getRegForInlineAsmConstraint( |
Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 3016 | const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const { |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 3017 | bool UseHVX = Subtarget.useHVXOps(), UseHVXDbl = Subtarget.useHVXDblOps(); |
| 3018 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3019 | if (Constraint.size() == 1) { |
| 3020 | switch (Constraint[0]) { |
| 3021 | case 'r': // R0-R31 |
Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 3022 | switch (VT.SimpleTy) { |
| 3023 | default: |
| 3024 | llvm_unreachable("getRegForInlineAsmConstraint Unhandled data type"); |
| 3025 | case MVT::i1: |
| 3026 | case MVT::i8: |
| 3027 | case MVT::i16: |
| 3028 | case MVT::i32: |
| 3029 | case MVT::f32: |
| 3030 | return std::make_pair(0U, &Hexagon::IntRegsRegClass); |
| 3031 | case MVT::i64: |
| 3032 | case MVT::f64: |
| 3033 | return std::make_pair(0U, &Hexagon::DoubleRegsRegClass); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3034 | } |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 3035 | case 'q': // q0-q3 |
Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 3036 | switch (VT.SimpleTy) { |
| 3037 | default: |
| 3038 | llvm_unreachable("getRegForInlineAsmConstraint Unhandled data type"); |
| 3039 | case MVT::v1024i1: |
| 3040 | case MVT::v512i1: |
| 3041 | case MVT::v32i16: |
| 3042 | case MVT::v16i32: |
| 3043 | case MVT::v64i8: |
| 3044 | case MVT::v8i64: |
| 3045 | return std::make_pair(0U, &Hexagon::VecPredRegsRegClass); |
| 3046 | } |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 3047 | case 'v': // V0-V31 |
Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 3048 | switch (VT.SimpleTy) { |
| 3049 | default: |
| 3050 | llvm_unreachable("getRegForInlineAsmConstraint Unhandled data type"); |
| 3051 | case MVT::v16i32: |
| 3052 | case MVT::v32i16: |
| 3053 | case MVT::v64i8: |
| 3054 | case MVT::v8i64: |
| 3055 | return std::make_pair(0U, &Hexagon::VectorRegsRegClass); |
| 3056 | case MVT::v32i32: |
| 3057 | case MVT::v64i16: |
| 3058 | case MVT::v16i64: |
| 3059 | case MVT::v128i8: |
| 3060 | if (Subtarget.hasV60TOps() && UseHVX && UseHVXDbl) |
| 3061 | return std::make_pair(0U, &Hexagon::VectorRegs128BRegClass); |
| 3062 | return std::make_pair(0U, &Hexagon::VecDblRegsRegClass); |
| 3063 | case MVT::v256i8: |
| 3064 | case MVT::v128i16: |
| 3065 | case MVT::v64i32: |
| 3066 | case MVT::v32i64: |
| 3067 | return std::make_pair(0U, &Hexagon::VecDblRegs128BRegClass); |
| 3068 | } |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 3069 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3070 | default: |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3071 | llvm_unreachable("Unknown asm register class"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3072 | } |
| 3073 | } |
| 3074 | |
Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 3075 | return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 3078 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 3079 | /// specified FP immediate natively. If false, the legalizer will |
| 3080 | /// materialize the FP immediate as a load from a constant pool. |
| 3081 | bool HexagonTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 3082 | return Subtarget.hasV5TOps(); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 3083 | } |
| 3084 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3085 | /// isLegalAddressingMode - Return true if the addressing mode represented by |
| 3086 | /// 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] | 3087 | bool HexagonTargetLowering::isLegalAddressingMode(const DataLayout &DL, |
| 3088 | const AddrMode &AM, Type *Ty, |
Matt Arsenault | bd7d80a | 2015-06-01 05:31:59 +0000 | [diff] [blame] | 3089 | unsigned AS) const { |
Krzysztof Parzyszek | ed4e782 | 2016-08-03 15:06:18 +0000 | [diff] [blame] | 3090 | if (Ty->isSized()) { |
| 3091 | // When LSR detects uses of the same base address to access different |
| 3092 | // types (e.g. unions), it will assume a conservative type for these |
| 3093 | // uses: |
| 3094 | // LSR Use: Kind=Address of void in addrspace(4294967295), ... |
| 3095 | // The type Ty passed here would then be "void". Skip the alignment |
| 3096 | // checks, but do not return false right away, since that confuses |
| 3097 | // LSR into crashing. |
| 3098 | unsigned A = DL.getABITypeAlignment(Ty); |
| 3099 | // The base offset must be a multiple of the alignment. |
| 3100 | if ((AM.BaseOffs % A) != 0) |
| 3101 | return false; |
| 3102 | // The shifted offset must fit in 11 bits. |
| 3103 | if (!isInt<11>(AM.BaseOffs >> Log2_32(A))) |
| 3104 | return false; |
| 3105 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3106 | |
| 3107 | // No global is ever allowed as a base. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 3108 | if (AM.BaseGV) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3109 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3110 | |
| 3111 | int Scale = AM.Scale; |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 3112 | if (Scale < 0) |
| 3113 | Scale = -Scale; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3114 | switch (Scale) { |
| 3115 | case 0: // No scale reg, "r+i", "r", or just "i". |
| 3116 | break; |
| 3117 | default: // No scaled addressing mode. |
| 3118 | return false; |
| 3119 | } |
| 3120 | return true; |
| 3121 | } |
| 3122 | |
Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 3123 | /// Return true if folding a constant offset with the given GlobalAddress is |
| 3124 | /// legal. It is frequently not legal in PIC relocation models. |
| 3125 | bool HexagonTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) |
| 3126 | const { |
| 3127 | return HTM.getRelocationModel() == Reloc::Static; |
| 3128 | } |
| 3129 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3130 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 3131 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 3132 | /// a register against the immediate without having to materialize the |
| 3133 | /// immediate into a register. |
| 3134 | bool HexagonTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
| 3135 | return Imm >= -512 && Imm <= 511; |
| 3136 | } |
| 3137 | |
| 3138 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 3139 | /// for tail call optimization. Targets which want to do tail call |
| 3140 | /// optimization should implement this function. |
| 3141 | bool HexagonTargetLowering::IsEligibleForTailCallOptimization( |
| 3142 | SDValue Callee, |
| 3143 | CallingConv::ID CalleeCC, |
| 3144 | bool isVarArg, |
| 3145 | bool isCalleeStructRet, |
| 3146 | bool isCallerStructRet, |
| 3147 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 3148 | const SmallVectorImpl<SDValue> &OutVals, |
| 3149 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 3150 | SelectionDAG& DAG) const { |
| 3151 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 3152 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 3153 | bool CCMatch = CallerCC == CalleeCC; |
| 3154 | |
| 3155 | // *************************************************************************** |
| 3156 | // Look for obvious safe cases to perform tail call optimization that do not |
| 3157 | // require ABI changes. |
| 3158 | // *************************************************************************** |
| 3159 | |
| 3160 | // If this is a tail call via a function pointer, then don't do it! |
Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 3161 | if (!isa<GlobalAddressSDNode>(Callee) && |
| 3162 | !isa<ExternalSymbolSDNode>(Callee)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3163 | return false; |
| 3164 | } |
| 3165 | |
Krzysztof Parzyszek | 0ba9754 | 2016-08-19 15:02:18 +0000 | [diff] [blame] | 3166 | // Do not optimize if the calling conventions do not match and the conventions |
| 3167 | // used are not C or Fast. |
| 3168 | if (!CCMatch) { |
| 3169 | bool R = (CallerCC == CallingConv::C || CallerCC == CallingConv::Fast); |
| 3170 | bool E = (CalleeCC == CallingConv::C || CalleeCC == CallingConv::Fast); |
| 3171 | // If R & E, then ok. |
| 3172 | if (!R || !E) |
| 3173 | return false; |
| 3174 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3175 | |
| 3176 | // Do not tail call optimize vararg calls. |
| 3177 | if (isVarArg) |
| 3178 | return false; |
| 3179 | |
| 3180 | // Also avoid tail call optimization if either caller or callee uses struct |
| 3181 | // return semantics. |
| 3182 | if (isCalleeStructRet || isCallerStructRet) |
| 3183 | return false; |
| 3184 | |
| 3185 | // In addition to the cases above, we also disable Tail Call Optimization if |
| 3186 | // the calling convention code that at least one outgoing argument needs to |
| 3187 | // go on the stack. We cannot check that here because at this point that |
| 3188 | // information is not available. |
| 3189 | return true; |
| 3190 | } |
Colin LeMahieu | 025f860 | 2014-12-08 21:19:18 +0000 | [diff] [blame] | 3191 | |
Krzysztof Parzyszek | 3e409e1 | 2016-08-02 18:34:31 +0000 | [diff] [blame] | 3192 | /// Returns the target specific optimal type for load and store operations as |
| 3193 | /// a result of memset, memcpy, and memmove lowering. |
| 3194 | /// |
| 3195 | /// If DstAlign is zero that means it's safe to destination alignment can |
| 3196 | /// satisfy any constraint. Similarly if SrcAlign is zero it means there isn't |
| 3197 | /// a need to check it against alignment requirement, probably because the |
| 3198 | /// source does not need to be loaded. If 'IsMemset' is true, that means it's |
| 3199 | /// expanding a memset. If 'ZeroMemset' is true, that means it's a memset of |
| 3200 | /// zero. 'MemcpyStrSrc' indicates whether the memcpy source is constant so it |
| 3201 | /// does not need to be loaded. It returns EVT::Other if the type should be |
| 3202 | /// determined using generic target-independent logic. |
| 3203 | EVT HexagonTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 3204 | unsigned DstAlign, unsigned SrcAlign, bool IsMemset, bool ZeroMemset, |
| 3205 | bool MemcpyStrSrc, MachineFunction &MF) const { |
| 3206 | |
| 3207 | auto Aligned = [](unsigned GivenA, unsigned MinA) -> bool { |
| 3208 | return (GivenA % MinA) == 0; |
| 3209 | }; |
| 3210 | |
| 3211 | if (Size >= 8 && Aligned(DstAlign, 8) && (IsMemset || Aligned(SrcAlign, 8))) |
| 3212 | return MVT::i64; |
| 3213 | if (Size >= 4 && Aligned(DstAlign, 4) && (IsMemset || Aligned(SrcAlign, 4))) |
| 3214 | return MVT::i32; |
| 3215 | if (Size >= 2 && Aligned(DstAlign, 2) && (IsMemset || Aligned(SrcAlign, 2))) |
| 3216 | return MVT::i16; |
| 3217 | |
| 3218 | return MVT::Other; |
| 3219 | } |
| 3220 | |
Krzysztof Parzyszek | 2d65ea7 | 2016-03-28 15:43:03 +0000 | [diff] [blame] | 3221 | bool HexagonTargetLowering::allowsMisalignedMemoryAccesses(EVT VT, |
| 3222 | unsigned AS, unsigned Align, bool *Fast) const { |
| 3223 | if (Fast) |
| 3224 | *Fast = false; |
| 3225 | |
| 3226 | switch (VT.getSimpleVT().SimpleTy) { |
| 3227 | default: |
| 3228 | return false; |
| 3229 | case MVT::v64i8: |
| 3230 | case MVT::v128i8: |
| 3231 | case MVT::v256i8: |
| 3232 | case MVT::v32i16: |
| 3233 | case MVT::v64i16: |
| 3234 | case MVT::v128i16: |
| 3235 | case MVT::v16i32: |
| 3236 | case MVT::v32i32: |
| 3237 | case MVT::v64i32: |
| 3238 | case MVT::v8i64: |
| 3239 | case MVT::v16i64: |
| 3240 | case MVT::v32i64: |
| 3241 | return true; |
| 3242 | } |
| 3243 | return false; |
| 3244 | } |
| 3245 | |
Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 3246 | std::pair<const TargetRegisterClass*, uint8_t> |
| 3247 | HexagonTargetLowering::findRepresentativeClass(const TargetRegisterInfo *TRI, |
| 3248 | MVT VT) const { |
| 3249 | const TargetRegisterClass *RRC = nullptr; |
| 3250 | |
| 3251 | uint8_t Cost = 1; |
| 3252 | switch (VT.SimpleTy) { |
| 3253 | default: |
| 3254 | return TargetLowering::findRepresentativeClass(TRI, VT); |
| 3255 | case MVT::v64i8: |
| 3256 | case MVT::v32i16: |
| 3257 | case MVT::v16i32: |
| 3258 | case MVT::v8i64: |
| 3259 | RRC = &Hexagon::VectorRegsRegClass; |
| 3260 | break; |
| 3261 | case MVT::v128i8: |
| 3262 | case MVT::v64i16: |
| 3263 | case MVT::v32i32: |
| 3264 | case MVT::v16i64: |
| 3265 | if (Subtarget.hasV60TOps() && Subtarget.useHVXOps() && |
| 3266 | Subtarget.useHVXDblOps()) |
| 3267 | RRC = &Hexagon::VectorRegs128BRegClass; |
| 3268 | else |
| 3269 | RRC = &Hexagon::VecDblRegsRegClass; |
| 3270 | break; |
| 3271 | case MVT::v256i8: |
| 3272 | case MVT::v128i16: |
| 3273 | case MVT::v64i32: |
| 3274 | case MVT::v32i64: |
| 3275 | RRC = &Hexagon::VecDblRegs128BRegClass; |
| 3276 | break; |
| 3277 | } |
| 3278 | return std::make_pair(RRC, Cost); |
| 3279 | } |
| 3280 | |
Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 3281 | Value *HexagonTargetLowering::emitLoadLinked(IRBuilder<> &Builder, Value *Addr, |
| 3282 | AtomicOrdering Ord) const { |
| 3283 | BasicBlock *BB = Builder.GetInsertBlock(); |
| 3284 | Module *M = BB->getParent()->getParent(); |
| 3285 | Type *Ty = cast<PointerType>(Addr->getType())->getElementType(); |
| 3286 | unsigned SZ = Ty->getPrimitiveSizeInBits(); |
| 3287 | assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic loads supported"); |
| 3288 | Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_L2_loadw_locked |
| 3289 | : Intrinsic::hexagon_L4_loadd_locked; |
| 3290 | Value *Fn = Intrinsic::getDeclaration(M, IntID); |
| 3291 | return Builder.CreateCall(Fn, Addr, "larx"); |
| 3292 | } |
| 3293 | |
| 3294 | /// Perform a store-conditional operation to Addr. Return the status of the |
| 3295 | /// store. This should be 0 if the store succeeded, non-zero otherwise. |
| 3296 | Value *HexagonTargetLowering::emitStoreConditional(IRBuilder<> &Builder, |
| 3297 | Value *Val, Value *Addr, AtomicOrdering Ord) const { |
| 3298 | BasicBlock *BB = Builder.GetInsertBlock(); |
| 3299 | Module *M = BB->getParent()->getParent(); |
| 3300 | Type *Ty = Val->getType(); |
| 3301 | unsigned SZ = Ty->getPrimitiveSizeInBits(); |
| 3302 | assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic stores supported"); |
| 3303 | Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_S2_storew_locked |
| 3304 | : Intrinsic::hexagon_S4_stored_locked; |
| 3305 | Value *Fn = Intrinsic::getDeclaration(M, IntID); |
| 3306 | Value *Call = Builder.CreateCall(Fn, {Addr, Val}, "stcx"); |
| 3307 | Value *Cmp = Builder.CreateICmpEQ(Call, Builder.getInt32(0), ""); |
| 3308 | Value *Ext = Builder.CreateZExt(Cmp, Type::getInt32Ty(M->getContext())); |
| 3309 | return Ext; |
| 3310 | } |
| 3311 | |
Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 3312 | TargetLowering::AtomicExpansionKind |
| 3313 | HexagonTargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const { |
Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 3314 | // Do not expand loads and stores that don't exceed 64 bits. |
Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 3315 | return LI->getType()->getPrimitiveSizeInBits() > 64 |
Tim Northover | f520eff | 2015-12-02 18:12:57 +0000 | [diff] [blame] | 3316 | ? AtomicExpansionKind::LLOnly |
Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 3317 | : AtomicExpansionKind::None; |
Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | bool HexagonTargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const { |
| 3321 | // Do not expand loads and stores that don't exceed 64 bits. |
| 3322 | return SI->getValueOperand()->getType()->getPrimitiveSizeInBits() > 64; |
| 3323 | } |
Krzysztof Parzyszek | f228c95 | 2016-06-22 16:07:10 +0000 | [diff] [blame] | 3324 | |
| 3325 | bool HexagonTargetLowering::shouldExpandAtomicCmpXchgInIR( |
| 3326 | AtomicCmpXchgInst *AI) const { |
| 3327 | const DataLayout &DL = AI->getModule()->getDataLayout(); |
| 3328 | unsigned Size = DL.getTypeStoreSize(AI->getCompareOperand()->getType()); |
| 3329 | return Size >= 4 && Size <= 8; |
| 3330 | } |