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