LLVM  5.0.0
HexagonISelLowering.cpp
Go to the documentation of this file.
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"
16 #include "Hexagon.h"
18 #include "HexagonRegisterInfo.h"
19 #include "HexagonSubtarget.h"
20 #include "HexagonTargetMachine.h"
22 #include "llvm/ADT/APInt.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/IR/BasicBlock.h"
34 #include "llvm/IR/CallingConv.h"
35 #include "llvm/IR/DataLayout.h"
36 #include "llvm/IR/DerivedTypes.h"
37 #include "llvm/IR/Function.h"
38 #include "llvm/IR/GlobalValue.h"
39 #include "llvm/IR/InlineAsm.h"
40 #include "llvm/IR/Instructions.h"
41 #include "llvm/IR/Intrinsics.h"
42 #include "llvm/IR/Module.h"
43 #include "llvm/IR/Type.h"
44 #include "llvm/IR/Value.h"
45 #include "llvm/MC/MCRegisterInfo.h"
46 #include "llvm/Support/Casting.h"
47 #include "llvm/Support/CodeGen.h"
49 #include "llvm/Support/Debug.h"
55 #include <algorithm>
56 #include <cassert>
57 #include <cstddef>
58 #include <cstdint>
59 #include <limits>
60 #include <utility>
61 
62 using namespace llvm;
63 
64 #define DEBUG_TYPE "hexagon-lowering"
65 
66 static cl::opt<bool> EmitJumpTables("hexagon-emit-jump-tables",
67  cl::init(true), cl::Hidden,
68  cl::desc("Control jump table emission on Hexagon target"));
69 
70 static cl::opt<bool> EnableHexSDNodeSched("enable-hexagon-sdnode-sched",
72  cl::desc("Enable Hexagon SDNode scheduling"));
73 
74 static cl::opt<bool> EnableFastMath("ffast-math",
76  cl::desc("Enable Fast Math processing"));
77 
78 static cl::opt<int> MinimumJumpTables("minimum-jump-tables",
80  cl::desc("Set minimum jump tables"));
81 
82 static cl::opt<int> MaxStoresPerMemcpyCL("max-store-memcpy",
84  cl::desc("Max #stores to inline memcpy"));
85 
86 static cl::opt<int> MaxStoresPerMemcpyOptSizeCL("max-store-memcpy-Os",
88  cl::desc("Max #stores to inline memcpy"));
89 
90 static cl::opt<int> MaxStoresPerMemmoveCL("max-store-memmove",
92  cl::desc("Max #stores to inline memmove"));
93 
94 static cl::opt<int> MaxStoresPerMemmoveOptSizeCL("max-store-memmove-Os",
96  cl::desc("Max #stores to inline memmove"));
97 
98 static cl::opt<int> MaxStoresPerMemsetCL("max-store-memset",
100  cl::desc("Max #stores to inline memset"));
101 
102 static cl::opt<int> MaxStoresPerMemsetOptSizeCL("max-store-memset-Os",
104  cl::desc("Max #stores to inline memset"));
105 
106 
107 namespace {
108 
109  class HexagonCCState : public CCState {
110  unsigned NumNamedVarArgParams;
111 
112  public:
113  HexagonCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF,
115  int NumNamedVarArgParams)
116  : CCState(CC, isVarArg, MF, locs, C),
117  NumNamedVarArgParams(NumNamedVarArgParams) {}
118 
119  unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; }
120  };
121 
123  Even = 0,
124  Odd,
125  NoPattern
126  };
127 
128 } // end anonymous namespace
129 
130 // Implement calling convention for Hexagon.
131 
132 static bool isHvxVectorType(MVT ty);
133 
134 static bool
135 CC_Hexagon(unsigned ValNo, MVT ValVT,
136  MVT LocVT, CCValAssign::LocInfo LocInfo,
137  ISD::ArgFlagsTy ArgFlags, CCState &State);
138 
139 static bool
140 CC_Hexagon32(unsigned ValNo, MVT ValVT,
141  MVT LocVT, CCValAssign::LocInfo LocInfo,
142  ISD::ArgFlagsTy ArgFlags, CCState &State);
143 
144 static bool
145 CC_Hexagon64(unsigned ValNo, MVT ValVT,
146  MVT LocVT, CCValAssign::LocInfo LocInfo,
147  ISD::ArgFlagsTy ArgFlags, CCState &State);
148 
149 static bool
150 CC_HexagonVector(unsigned ValNo, MVT ValVT,
151  MVT LocVT, CCValAssign::LocInfo LocInfo,
152  ISD::ArgFlagsTy ArgFlags, CCState &State);
153 
154 static bool
155 RetCC_Hexagon(unsigned ValNo, MVT ValVT,
156  MVT LocVT, CCValAssign::LocInfo LocInfo,
157  ISD::ArgFlagsTy ArgFlags, CCState &State);
158 
159 static bool
160 RetCC_Hexagon32(unsigned ValNo, MVT ValVT,
161  MVT LocVT, CCValAssign::LocInfo LocInfo,
162  ISD::ArgFlagsTy ArgFlags, CCState &State);
163 
164 static bool
165 RetCC_Hexagon64(unsigned ValNo, MVT ValVT,
166  MVT LocVT, CCValAssign::LocInfo LocInfo,
167  ISD::ArgFlagsTy ArgFlags, CCState &State);
168 
169 static bool
170 RetCC_HexagonVector(unsigned ValNo, MVT ValVT,
171  MVT LocVT, CCValAssign::LocInfo LocInfo,
172  ISD::ArgFlagsTy ArgFlags, CCState &State);
173 
174 static bool
175 CC_Hexagon_VarArg (unsigned ValNo, MVT ValVT,
176  MVT LocVT, CCValAssign::LocInfo LocInfo,
177  ISD::ArgFlagsTy ArgFlags, CCState &State) {
178  HexagonCCState &HState = static_cast<HexagonCCState &>(State);
179 
180  if (ValNo < HState.getNumNamedVarArgParams()) {
181  // Deal with named arguments.
182  return CC_Hexagon(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State);
183  }
184 
185  // Deal with un-named arguments.
186  unsigned Offset;
187  if (ArgFlags.isByVal()) {
188  // If pass-by-value, the size allocated on stack is decided
189  // by ArgFlags.getByValSize(), not by the size of LocVT.
190  Offset = State.AllocateStack(ArgFlags.getByValSize(),
191  ArgFlags.getByValAlign());
192  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
193  return false;
194  }
195  if (LocVT == MVT::i1 || LocVT == MVT::i8 || LocVT == MVT::i16) {
196  LocVT = MVT::i32;
197  ValVT = MVT::i32;
198  if (ArgFlags.isSExt())
199  LocInfo = CCValAssign::SExt;
200  else if (ArgFlags.isZExt())
201  LocInfo = CCValAssign::ZExt;
202  else
203  LocInfo = CCValAssign::AExt;
204  }
205  if (LocVT == MVT::i32 || LocVT == MVT::f32) {
206  Offset = State.AllocateStack(4, 4);
207  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
208  return false;
209  }
210  if (LocVT == MVT::i64 || LocVT == MVT::f64) {
211  Offset = State.AllocateStack(8, 8);
212  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
213  return false;
214  }
215  if (LocVT == MVT::v2i64 || LocVT == MVT::v4i32 || LocVT == MVT::v8i16 ||
216  LocVT == MVT::v16i8) {
217  Offset = State.AllocateStack(16, 16);
218  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
219  return false;
220  }
221  if (LocVT == MVT::v4i64 || LocVT == MVT::v8i32 || LocVT == MVT::v16i16 ||
222  LocVT == MVT::v32i8) {
223  Offset = State.AllocateStack(32, 32);
224  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
225  return false;
226  }
227  if (LocVT == MVT::v8i64 || LocVT == MVT::v16i32 || LocVT == MVT::v32i16 ||
228  LocVT == MVT::v64i8 || LocVT == MVT::v512i1) {
229  Offset = State.AllocateStack(64, 64);
230  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
231  return false;
232  }
233  if (LocVT == MVT::v16i64 || LocVT == MVT::v32i32 || LocVT == MVT::v64i16 ||
234  LocVT == MVT::v128i8 || LocVT == MVT::v1024i1) {
235  Offset = State.AllocateStack(128, 128);
236  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
237  return false;
238  }
239  if (LocVT == MVT::v32i64 || LocVT == MVT::v64i32 || LocVT == MVT::v128i16 ||
240  LocVT == MVT::v256i8) {
241  Offset = State.AllocateStack(256, 256);
242  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
243  return false;
244  }
245 
246  llvm_unreachable(nullptr);
247 }
248 
249 static bool CC_Hexagon (unsigned ValNo, MVT ValVT, MVT LocVT,
250  CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State) {
251  if (ArgFlags.isByVal()) {
252  // Passed on stack.
253  unsigned Offset = State.AllocateStack(ArgFlags.getByValSize(),
254  ArgFlags.getByValAlign());
255  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
256  return false;
257  }
258 
259  if (LocVT == MVT::i1) {
260  LocVT = MVT::i32;
261  } else if (LocVT == MVT::i8 || LocVT == MVT::i16) {
262  LocVT = MVT::i32;
263  ValVT = MVT::i32;
264  if (ArgFlags.isSExt())
265  LocInfo = CCValAssign::SExt;
266  else if (ArgFlags.isZExt())
267  LocInfo = CCValAssign::ZExt;
268  else
269  LocInfo = CCValAssign::AExt;
270  } else if (LocVT == MVT::v4i8 || LocVT == MVT::v2i16) {
271  LocVT = MVT::i32;
272  LocInfo = CCValAssign::BCvt;
273  } else if (LocVT == MVT::v8i8 || LocVT == MVT::v4i16 || LocVT == MVT::v2i32) {
274  LocVT = MVT::i64;
275  LocInfo = CCValAssign::BCvt;
276  }
277 
278  if (LocVT == MVT::i32 || LocVT == MVT::f32) {
279  if (!CC_Hexagon32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
280  return false;
281  }
282 
283  if (LocVT == MVT::i64 || LocVT == MVT::f64) {
284  if (!CC_Hexagon64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
285  return false;
286  }
287 
288  if (LocVT == MVT::v8i32 || LocVT == MVT::v16i16 || LocVT == MVT::v32i8) {
289  unsigned Offset = State.AllocateStack(ArgFlags.getByValSize(), 32);
290  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
291  return false;
292  }
293 
294  if (isHvxVectorType(LocVT)) {
295  if (!CC_HexagonVector(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
296  return false;
297  }
298 
299  return true; // CC didn't match.
300 }
301 
302 
303 static bool CC_Hexagon32(unsigned ValNo, MVT ValVT,
304  MVT LocVT, CCValAssign::LocInfo LocInfo,
305  ISD::ArgFlagsTy ArgFlags, CCState &State) {
306  static const MCPhysReg RegList[] = {
307  Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4,
308  Hexagon::R5
309  };
310  if (unsigned Reg = State.AllocateReg(RegList)) {
311  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
312  return false;
313  }
314 
315  unsigned Offset = State.AllocateStack(4, 4);
316  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
317  return false;
318 }
319 
320 static bool CC_Hexagon64(unsigned ValNo, MVT ValVT,
321  MVT LocVT, CCValAssign::LocInfo LocInfo,
322  ISD::ArgFlagsTy ArgFlags, CCState &State) {
323  if (unsigned Reg = State.AllocateReg(Hexagon::D0)) {
324  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
325  return false;
326  }
327 
328  static const MCPhysReg RegList1[] = {
329  Hexagon::D1, Hexagon::D2
330  };
331  static const MCPhysReg RegList2[] = {
332  Hexagon::R1, Hexagon::R3
333  };
334  if (unsigned Reg = State.AllocateReg(RegList1, RegList2)) {
335  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
336  return false;
337  }
338 
339  unsigned Offset = State.AllocateStack(8, 8, Hexagon::D2);
340  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
341  return false;
342 }
343 
344 static bool CC_HexagonVector(unsigned ValNo, MVT ValVT,
345  MVT LocVT, CCValAssign::LocInfo LocInfo,
346  ISD::ArgFlagsTy ArgFlags, CCState &State) {
347  static const MCPhysReg VecLstS[] = {
348  Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4,
349  Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9,
350  Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14,
351  Hexagon::V15
352  };
353  static const MCPhysReg VecLstD[] = {
354  Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3, Hexagon::W4,
355  Hexagon::W5, Hexagon::W6, Hexagon::W7
356  };
357  auto &MF = State.getMachineFunction();
358  auto &HST = MF.getSubtarget<HexagonSubtarget>();
359  bool UseHVX = HST.useHVXOps();
360  bool UseHVXDbl = HST.useHVXDblOps();
361 
362  if ((UseHVX && !UseHVXDbl) &&
363  (LocVT == MVT::v8i64 || LocVT == MVT::v16i32 || LocVT == MVT::v32i16 ||
364  LocVT == MVT::v64i8 || LocVT == MVT::v512i1)) {
365  if (unsigned Reg = State.AllocateReg(VecLstS)) {
366  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
367  return false;
368  }
369  unsigned Offset = State.AllocateStack(64, 64);
370  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
371  return false;
372  }
373  if ((UseHVX && !UseHVXDbl) &&
374  (LocVT == MVT::v16i64 || LocVT == MVT::v32i32 || LocVT == MVT::v64i16 ||
375  LocVT == MVT::v128i8)) {
376  if (unsigned Reg = State.AllocateReg(VecLstD)) {
377  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
378  return false;
379  }
380  unsigned Offset = State.AllocateStack(128, 128);
381  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
382  return false;
383  }
384  // 128B Mode
385  if ((UseHVX && UseHVXDbl) &&
386  (LocVT == MVT::v32i64 || LocVT == MVT::v64i32 || LocVT == MVT::v128i16 ||
387  LocVT == MVT::v256i8)) {
388  if (unsigned Reg = State.AllocateReg(VecLstD)) {
389  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
390  return false;
391  }
392  unsigned Offset = State.AllocateStack(256, 256);
393  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
394  return false;
395  }
396  if ((UseHVX && UseHVXDbl) &&
397  (LocVT == MVT::v16i64 || LocVT == MVT::v32i32 || LocVT == MVT::v64i16 ||
398  LocVT == MVT::v128i8 || LocVT == MVT::v1024i1)) {
399  if (unsigned Reg = State.AllocateReg(VecLstS)) {
400  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
401  return false;
402  }
403  unsigned Offset = State.AllocateStack(128, 128);
404  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
405  return false;
406  }
407  return true;
408 }
409 
410 static bool RetCC_Hexagon(unsigned ValNo, MVT ValVT,
411  MVT LocVT, CCValAssign::LocInfo LocInfo,
412  ISD::ArgFlagsTy ArgFlags, CCState &State) {
413  auto &MF = State.getMachineFunction();
414  auto &HST = MF.getSubtarget<HexagonSubtarget>();
415  bool UseHVX = HST.useHVXOps();
416  bool UseHVXDbl = HST.useHVXDblOps();
417 
418  if (LocVT == MVT::i1) {
419  // Return values of type MVT::i1 still need to be assigned to R0, but
420  // the value type needs to remain i1. LowerCallResult will deal with it,
421  // but it needs to recognize i1 as the value type.
422  LocVT = MVT::i32;
423  } else if (LocVT == MVT::i8 || LocVT == MVT::i16) {
424  LocVT = MVT::i32;
425  ValVT = MVT::i32;
426  if (ArgFlags.isSExt())
427  LocInfo = CCValAssign::SExt;
428  else if (ArgFlags.isZExt())
429  LocInfo = CCValAssign::ZExt;
430  else
431  LocInfo = CCValAssign::AExt;
432  } else if (LocVT == MVT::v4i8 || LocVT == MVT::v2i16) {
433  LocVT = MVT::i32;
434  LocInfo = CCValAssign::BCvt;
435  } else if (LocVT == MVT::v8i8 || LocVT == MVT::v4i16 || LocVT == MVT::v2i32) {
436  LocVT = MVT::i64;
437  LocInfo = CCValAssign::BCvt;
438  } else if (LocVT == MVT::v64i8 || LocVT == MVT::v32i16 ||
439  LocVT == MVT::v16i32 || LocVT == MVT::v8i64 ||
440  LocVT == MVT::v512i1) {
441  LocVT = MVT::v16i32;
442  ValVT = MVT::v16i32;
443  LocInfo = CCValAssign::Full;
444  } else if (LocVT == MVT::v128i8 || LocVT == MVT::v64i16 ||
445  LocVT == MVT::v32i32 || LocVT == MVT::v16i64 ||
446  (LocVT == MVT::v1024i1 && UseHVX && UseHVXDbl)) {
447  LocVT = MVT::v32i32;
448  ValVT = MVT::v32i32;
449  LocInfo = CCValAssign::Full;
450  } else if (LocVT == MVT::v256i8 || LocVT == MVT::v128i16 ||
451  LocVT == MVT::v64i32 || LocVT == MVT::v32i64) {
452  LocVT = MVT::v64i32;
453  ValVT = MVT::v64i32;
454  LocInfo = CCValAssign::Full;
455  }
456  if (LocVT == MVT::i32 || LocVT == MVT::f32) {
457  if (!RetCC_Hexagon32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
458  return false;
459  }
460 
461  if (LocVT == MVT::i64 || LocVT == MVT::f64) {
462  if (!RetCC_Hexagon64(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
463  return false;
464  }
465  if (LocVT == MVT::v16i32 || LocVT == MVT::v32i32 || LocVT == MVT::v64i32) {
466  if (!RetCC_HexagonVector(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))
467  return false;
468  }
469  return true; // CC didn't match.
470 }
471 
472 static bool RetCC_Hexagon32(unsigned ValNo, MVT ValVT,
473  MVT LocVT, CCValAssign::LocInfo LocInfo,
474  ISD::ArgFlagsTy ArgFlags, CCState &State) {
475  if (LocVT == MVT::i32 || LocVT == MVT::f32) {
476  // Note that use of registers beyond R1 is not ABI compliant. However there
477  // are (experimental) IR passes which generate internal functions that
478  // return structs using these additional registers.
479  static const uint16_t RegList[] = { Hexagon::R0, Hexagon::R1,
480  Hexagon::R2, Hexagon::R3,
481  Hexagon::R4, Hexagon::R5 };
482  if (unsigned Reg = State.AllocateReg(RegList)) {
483  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
484  return false;
485  }
486  }
487 
488  return true;
489 }
490 
491 static bool RetCC_Hexagon64(unsigned ValNo, MVT ValVT,
492  MVT LocVT, CCValAssign::LocInfo LocInfo,
493  ISD::ArgFlagsTy ArgFlags, CCState &State) {
494  if (LocVT == MVT::i64 || LocVT == MVT::f64) {
495  if (unsigned Reg = State.AllocateReg(Hexagon::D0)) {
496  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
497  return false;
498  }
499  }
500 
501  return true;
502 }
503 
504 static bool RetCC_HexagonVector(unsigned ValNo, MVT ValVT,
505  MVT LocVT, CCValAssign::LocInfo LocInfo,
506  ISD::ArgFlagsTy ArgFlags, CCState &State) {
507  auto &MF = State.getMachineFunction();
508  auto &HST = MF.getSubtarget<HexagonSubtarget>();
509  bool UseHVX = HST.useHVXOps();
510  bool UseHVXDbl = HST.useHVXDblOps();
511 
512  if (LocVT == MVT::v16i32) {
513  if (unsigned Reg = State.AllocateReg(Hexagon::V0)) {
514  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
515  return false;
516  }
517  } else if (LocVT == MVT::v32i32) {
518  unsigned Req = (UseHVX && UseHVXDbl) ? Hexagon::V0 : Hexagon::W0;
519  if (unsigned Reg = State.AllocateReg(Req)) {
520  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
521  return false;
522  }
523  } else if (LocVT == MVT::v64i32) {
524  if (unsigned Reg = State.AllocateReg(Hexagon::W0)) {
525  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
526  return false;
527  }
528  }
529 
530  return true;
531 }
532 
533 void HexagonTargetLowering::promoteLdStType(MVT VT, MVT PromotedLdStVT) {
534  if (VT != PromotedLdStVT) {
536  AddPromotedToType(ISD::LOAD, VT, PromotedLdStVT);
537 
539  AddPromotedToType(ISD::STORE, VT, PromotedLdStVT);
540  }
541 }
542 
543 SDValue
545  const {
546  return SDValue();
547 }
548 
549 /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified
550 /// by "Src" to address "Dst" of size "Size". Alignment information is
551 /// specified by the specific parameter attribute. The copy will be passed as
552 /// a byval function parameter. Sometimes what we are copying is the end of a
553 /// larger object, the part that does not fit in registers.
556  SelectionDAG &DAG, const SDLoc &dl) {
557  SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), dl, MVT::i32);
558  return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(),
559  /*isVolatile=*/false, /*AlwaysInline=*/false,
560  /*isTailCall=*/false,
562 }
563 
564 static bool isHvxVectorType(MVT Ty) {
565  switch (Ty.SimpleTy) {
566  case MVT::v8i64:
567  case MVT::v16i32:
568  case MVT::v32i16:
569  case MVT::v64i8:
570  case MVT::v16i64:
571  case MVT::v32i32:
572  case MVT::v64i16:
573  case MVT::v128i8:
574  case MVT::v32i64:
575  case MVT::v64i32:
576  case MVT::v128i16:
577  case MVT::v256i8:
578  case MVT::v512i1:
579  case MVT::v1024i1:
580  return true;
581  default:
582  return false;
583  }
584 }
585 
586 bool
588  CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg,
590  LLVMContext &Context) const {
592  CCState CCInfo(CallConv, isVarArg, MF, RVLocs, Context);
593  return CCInfo.CheckReturn(Outs, RetCC_Hexagon);
594 }
595 
596 // LowerReturn - Lower ISD::RET. If a struct is larger than 8 bytes and is
597 // passed by value, the function prototype is modified to return void and
598 // the value is stored in memory pointed by a pointer passed by caller.
599 SDValue
601  bool isVarArg,
603  const SmallVectorImpl<SDValue> &OutVals,
604  const SDLoc &dl, SelectionDAG &DAG) const {
605  // CCValAssign - represent the assignment of the return value to locations.
607 
608  // CCState - Info about the registers and stack slot.
609  CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
610  *DAG.getContext());
611 
612  // Analyze return values of ISD::RET
613  CCInfo.AnalyzeReturn(Outs, RetCC_Hexagon);
614 
615  SDValue Flag;
616  SmallVector<SDValue, 4> RetOps(1, Chain);
617 
618  // Copy the result values into the output registers.
619  for (unsigned i = 0; i != RVLocs.size(); ++i) {
620  CCValAssign &VA = RVLocs[i];
621 
622  Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), OutVals[i], Flag);
623 
624  // Guarantee that all emitted copies are stuck together with flags.
625  Flag = Chain.getValue(1);
626  RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
627  }
628 
629  RetOps[0] = Chain; // Update chain.
630 
631  // Add the flag if we have it.
632  if (Flag.getNode())
633  RetOps.push_back(Flag);
634 
635  return DAG.getNode(HexagonISD::RET_FLAG, dl, MVT::Other, RetOps);
636 }
637 
639  // If either no tail call or told not to tail call at all, don't.
640  auto Attr =
641  CI->getParent()->getParent()->getFnAttribute("disable-tail-calls");
642  if (!CI->isTailCall() || Attr.getValueAsString() == "true")
643  return false;
644 
645  return true;
646 }
647 
648 /// LowerCallResult - Lower the result values of an ISD::CALL into the
649 /// appropriate copies out of appropriate physical registers. This assumes that
650 /// Chain/Glue are the input chain/glue to use, and that TheCall is the call
651 /// being lowered. Returns a SDNode with the same number of values as the
652 /// ISD::CALL.
654  SDValue Chain, SDValue Glue, CallingConv::ID CallConv, bool isVarArg,
655  const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
657  const SmallVectorImpl<SDValue> &OutVals, SDValue Callee) const {
658  // Assign locations to each value returned by this call.
660 
661  CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
662  *DAG.getContext());
663 
664  CCInfo.AnalyzeCallResult(Ins, RetCC_Hexagon);
665 
666  // Copy all of the result registers out of their specified physreg.
667  for (unsigned i = 0; i != RVLocs.size(); ++i) {
668  SDValue RetVal;
669  if (RVLocs[i].getValVT() == MVT::i1) {
670  // Return values of type MVT::i1 require special handling. The reason
671  // is that MVT::i1 is associated with the PredRegs register class, but
672  // values of that type are still returned in R0. Generate an explicit
673  // copy into a predicate register from R0, and treat the value of the
674  // predicate register as the call result.
675  auto &MRI = DAG.getMachineFunction().getRegInfo();
676  SDValue FR0 = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(),
677  MVT::i32, Glue);
678  // FR0 = (Value, Chain, Glue)
679  unsigned PredR = MRI.createVirtualRegister(&Hexagon::PredRegsRegClass);
680  SDValue TPR = DAG.getCopyToReg(FR0.getValue(1), dl, PredR,
681  FR0.getValue(0), FR0.getValue(2));
682  // TPR = (Chain, Glue)
683  // Don't glue this CopyFromReg, because it copies from a virtual
684  // register. If it is glued to the call, InstrEmitter will add it
685  // as an implicit def to the call (EmitMachineNode).
686  RetVal = DAG.getCopyFromReg(TPR.getValue(0), dl, PredR, MVT::i1);
687  Glue = TPR.getValue(1);
688  } else {
689  RetVal = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(),
690  RVLocs[i].getValVT(), Glue);
691  Glue = RetVal.getValue(2);
692  }
693  InVals.push_back(RetVal.getValue(0));
694  Chain = RetVal.getValue(1);
695  }
696 
697  return Chain;
698 }
699 
700 /// LowerCall - Functions arguments are copied from virtual regs to
701 /// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted.
702 SDValue
704  SmallVectorImpl<SDValue> &InVals) const {
705  SelectionDAG &DAG = CLI.DAG;
706  SDLoc &dl = CLI.DL;
708  SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
710  SDValue Chain = CLI.Chain;
711  SDValue Callee = CLI.Callee;
712  bool &IsTailCall = CLI.IsTailCall;
713  CallingConv::ID CallConv = CLI.CallConv;
714  bool IsVarArg = CLI.IsVarArg;
715  bool DoesNotReturn = CLI.DoesNotReturn;
716 
717  bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet();
719  MachineFrameInfo &MFI = MF.getFrameInfo();
720  auto PtrVT = getPointerTy(MF.getDataLayout());
721 
722  // Check for varargs.
723  unsigned NumNamedVarArgParams = -1U;
724  if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(Callee)) {
725  const GlobalValue *GV = GAN->getGlobal();
726  Callee = DAG.getTargetGlobalAddress(GV, dl, MVT::i32);
727  if (const Function* F = dyn_cast<Function>(GV)) {
728  // If a function has zero args and is a vararg function, that's
729  // disallowed so it must be an undeclared function. Do not assume
730  // varargs if the callee is undefined.
731  if (F->isVarArg() && F->getFunctionType()->getNumParams() != 0)
732  NumNamedVarArgParams = F->getFunctionType()->getNumParams();
733  }
734  }
735 
736  // Analyze operands of the call, assigning locations to each operand.
738  HexagonCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
739  *DAG.getContext(), NumNamedVarArgParams);
740 
741  if (IsVarArg)
742  CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_VarArg);
743  else
744  CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon);
745 
746  auto Attr = MF.getFunction()->getFnAttribute("disable-tail-calls");
747  if (Attr.getValueAsString() == "true")
748  IsTailCall = false;
749 
750  if (IsTailCall) {
751  bool StructAttrFlag = MF.getFunction()->hasStructRetAttr();
752  IsTailCall = IsEligibleForTailCallOptimization(Callee, CallConv,
753  IsVarArg, IsStructRet,
754  StructAttrFlag,
755  Outs, OutVals, Ins, DAG);
756  for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
757  CCValAssign &VA = ArgLocs[i];
758  if (VA.isMemLoc()) {
759  IsTailCall = false;
760  break;
761  }
762  }
763  DEBUG(dbgs() << (IsTailCall ? "Eligible for Tail Call\n"
764  : "Argument must be passed on stack. "
765  "Not eligible for Tail Call\n"));
766  }
767  // Get a count of how many bytes are to be pushed on the stack.
768  unsigned NumBytes = CCInfo.getNextStackOffset();
770  SmallVector<SDValue, 8> MemOpChains;
771 
772  auto &HRI = *Subtarget.getRegisterInfo();
773  SDValue StackPtr =
774  DAG.getCopyFromReg(Chain, dl, HRI.getStackRegister(), PtrVT);
775 
776  bool NeedsArgAlign = false;
777  unsigned LargestAlignSeen = 0;
778  // Walk the register/memloc assignments, inserting copies/loads.
779  for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
780  CCValAssign &VA = ArgLocs[i];
781  SDValue Arg = OutVals[i];
782  ISD::ArgFlagsTy Flags = Outs[i].Flags;
783  // Record if we need > 8 byte alignment on an argument.
784  bool ArgAlign = isHvxVectorType(VA.getValVT());
785  NeedsArgAlign |= ArgAlign;
786 
787  // Promote the value if needed.
788  switch (VA.getLocInfo()) {
789  default:
790  // Loc info must be one of Full, SExt, ZExt, or AExt.
791  llvm_unreachable("Unknown loc info!");
792  case CCValAssign::BCvt:
793  case CCValAssign::Full:
794  break;
795  case CCValAssign::SExt:
796  Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
797  break;
798  case CCValAssign::ZExt:
799  Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
800  break;
801  case CCValAssign::AExt:
802  Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
803  break;
804  }
805 
806  if (VA.isMemLoc()) {
807  unsigned LocMemOffset = VA.getLocMemOffset();
808  SDValue MemAddr = DAG.getConstant(LocMemOffset, dl,
809  StackPtr.getValueType());
810  MemAddr = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, MemAddr);
811  if (ArgAlign)
812  LargestAlignSeen = std::max(LargestAlignSeen,
813  VA.getLocVT().getStoreSizeInBits() >> 3);
814  if (Flags.isByVal()) {
815  // The argument is a struct passed by value. According to LLVM, "Arg"
816  // is is pointer.
817  MemOpChains.push_back(CreateCopyOfByValArgument(Arg, MemAddr, Chain,
818  Flags, DAG, dl));
819  } else {
821  DAG.getMachineFunction(), LocMemOffset);
822  SDValue S = DAG.getStore(Chain, dl, Arg, MemAddr, LocPI);
823  MemOpChains.push_back(S);
824  }
825  continue;
826  }
827 
828  // Arguments that can be passed on register must be kept at RegsToPass
829  // vector.
830  if (VA.isRegLoc())
831  RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
832  }
833 
834  if (NeedsArgAlign && Subtarget.hasV60TOps()) {
835  DEBUG(dbgs() << "Function needs byte stack align due to call args\n");
836  // V6 vectors passed by value have 64 or 128 byte alignment depending
837  // on whether we are 64 byte vector mode or 128 byte.
838  bool UseHVXDbl = Subtarget.useHVXDblOps();
839  assert(Subtarget.useHVXOps());
840  const unsigned ObjAlign = UseHVXDbl ? 128 : 64;
841  LargestAlignSeen = std::max(LargestAlignSeen, ObjAlign);
842  MFI.ensureMaxAlignment(LargestAlignSeen);
843  }
844  // Transform all store nodes into one single node because all store
845  // nodes are independent of each other.
846  if (!MemOpChains.empty())
847  Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains);
848 
849  SDValue Glue;
850  if (!IsTailCall) {
851  Chain = DAG.getCALLSEQ_START(Chain, NumBytes, 0, dl);
852  Glue = Chain.getValue(1);
853  }
854 
855  // Build a sequence of copy-to-reg nodes chained together with token
856  // chain and flag operands which copy the outgoing args into registers.
857  // The Glue is necessary since all emitted instructions must be
858  // stuck together.
859  if (!IsTailCall) {
860  for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
861  Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
862  RegsToPass[i].second, Glue);
863  Glue = Chain.getValue(1);
864  }
865  } else {
866  // For tail calls lower the arguments to the 'real' stack slot.
867  //
868  // Force all the incoming stack arguments to be loaded from the stack
869  // before any new outgoing arguments are stored to the stack, because the
870  // outgoing stack slots may alias the incoming argument stack slots, and
871  // the alias isn't otherwise explicit. This is slightly more conservative
872  // than necessary, because it means that each store effectively depends
873  // on every argument instead of just those arguments it would clobber.
874  //
875  // Do not flag preceding copytoreg stuff together with the following stuff.
876  Glue = SDValue();
877  for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
878  Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
879  RegsToPass[i].second, Glue);
880  Glue = Chain.getValue(1);
881  }
882  Glue = SDValue();
883  }
884 
885  bool LongCalls = MF.getSubtarget<HexagonSubtarget>().useLongCalls();
886  unsigned Flags = LongCalls ? HexagonII::HMOTF_ConstExtended : 0;
887 
888  // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
889  // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
890  // node so that legalize doesn't hack it.
891  if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
892  Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, PtrVT, 0, Flags);
893  } else if (ExternalSymbolSDNode *S =
894  dyn_cast<ExternalSymbolSDNode>(Callee)) {
895  Callee = DAG.getTargetExternalSymbol(S->getSymbol(), PtrVT, Flags);
896  }
897 
898  // Returns a chain & a flag for retval copy to use.
899  SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
901  Ops.push_back(Chain);
902  Ops.push_back(Callee);
903 
904  // Add argument registers to the end of the list so that they are
905  // known live into the call.
906  for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
907  Ops.push_back(DAG.getRegister(RegsToPass[i].first,
908  RegsToPass[i].second.getValueType()));
909  }
910 
911  const uint32_t *Mask = HRI.getCallPreservedMask(MF, CallConv);
912  assert(Mask && "Missing call preserved mask for calling convention");
913  Ops.push_back(DAG.getRegisterMask(Mask));
914 
915  if (Glue.getNode())
916  Ops.push_back(Glue);
917 
918  if (IsTailCall) {
919  MFI.setHasTailCall();
920  return DAG.getNode(HexagonISD::TC_RETURN, dl, NodeTys, Ops);
921  }
922 
923  // Set this here because we need to know this for "hasFP" in frame lowering.
924  // The target-independent code calls getFrameRegister before setting it, and
925  // getFrameRegister uses hasFP to determine whether the function has FP.
926  MFI.setHasCalls(true);
927 
928  unsigned OpCode = DoesNotReturn ? HexagonISD::CALLnr : HexagonISD::CALL;
929  Chain = DAG.getNode(OpCode, dl, NodeTys, Ops);
930  Glue = Chain.getValue(1);
931 
932  // Create the CALLSEQ_END node.
933  Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, dl, true),
934  DAG.getIntPtrConstant(0, dl, true), Glue, dl);
935  Glue = Chain.getValue(1);
936 
937  // Handle result values, copying them out of physregs into vregs that we
938  // return.
939  return LowerCallResult(Chain, Glue, CallConv, IsVarArg, Ins, dl, DAG,
940  InVals, OutVals, Callee);
941 }
942 
945  bool &IsInc, SelectionDAG &DAG) {
946  if (Ptr->getOpcode() != ISD::ADD)
947  return false;
948 
949  auto &HST = static_cast<const HexagonSubtarget&>(DAG.getSubtarget());
950  bool UseHVX = HST.useHVXOps();
951  bool UseHVXDbl = HST.useHVXDblOps();
952 
953  bool ValidHVXDblType =
954  (UseHVX && UseHVXDbl) && (VT == MVT::v32i32 || VT == MVT::v16i64 ||
955  VT == MVT::v64i16 || VT == MVT::v128i8);
956  bool ValidHVXType =
957  UseHVX && !UseHVXDbl && (VT == MVT::v16i32 || VT == MVT::v8i64 ||
958  VT == MVT::v32i16 || VT == MVT::v64i8);
959 
960  if (ValidHVXDblType || ValidHVXType ||
961  VT == MVT::i64 || VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8) {
962  IsInc = (Ptr->getOpcode() == ISD::ADD);
963  Base = Ptr->getOperand(0);
964  Offset = Ptr->getOperand(1);
965  // Ensure that Offset is a constant.
966  return isa<ConstantSDNode>(Offset);
967  }
968 
969  return false;
970 }
971 
972 /// getPostIndexedAddressParts - returns true by value, base pointer and
973 /// offset pointer and addressing mode by reference if this node can be
974 /// combined with a load / store to form a post-indexed load / store.
976  SDValue &Base,
977  SDValue &Offset,
979  SelectionDAG &DAG) const
980 {
981  EVT VT;
982  SDValue Ptr;
983 
984  if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
985  VT = LD->getMemoryVT();
986  } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
987  VT = ST->getMemoryVT();
988  if (ST->getValue().getValueType() == MVT::i64 && ST->isTruncatingStore())
989  return false;
990  } else {
991  return false;
992  }
993 
994  bool IsInc = false;
995  bool isLegal = getIndexedAddressParts(Op, VT, Base, Offset, IsInc, DAG);
996  if (isLegal) {
997  auto &HII = *Subtarget.getInstrInfo();
998  int32_t OffsetVal = cast<ConstantSDNode>(Offset.getNode())->getSExtValue();
999  if (HII.isValidAutoIncImm(VT, OffsetVal)) {
1000  AM = IsInc ? ISD::POST_INC : ISD::POST_DEC;
1001  return true;
1002  }
1003  }
1004 
1005  return false;
1006 }
1007 
1008 SDValue
1010  MachineFunction &MF = DAG.getMachineFunction();
1011  auto &HMFI = *MF.getInfo<HexagonMachineFunctionInfo>();
1012  const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
1013  unsigned LR = HRI.getRARegister();
1014 
1015  if (Op.getOpcode() != ISD::INLINEASM || HMFI.hasClobberLR())
1016  return Op;
1017 
1018  unsigned NumOps = Op.getNumOperands();
1019  if (Op.getOperand(NumOps-1).getValueType() == MVT::Glue)
1020  --NumOps; // Ignore the flag operand.
1021 
1022  for (unsigned i = InlineAsm::Op_FirstOperand; i != NumOps;) {
1023  unsigned Flags = cast<ConstantSDNode>(Op.getOperand(i))->getZExtValue();
1024  unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
1025  ++i; // Skip the ID value.
1026 
1027  switch (InlineAsm::getKind(Flags)) {
1028  default:
1029  llvm_unreachable("Bad flags!");
1031  case InlineAsm::Kind_Imm:
1032  case InlineAsm::Kind_Mem:
1033  i += NumVals;
1034  break;
1038  for (; NumVals; --NumVals, ++i) {
1039  unsigned Reg = cast<RegisterSDNode>(Op.getOperand(i))->getReg();
1040  if (Reg != LR)
1041  continue;
1042  HMFI.setHasClobberLR(true);
1043  return Op;
1044  }
1045  break;
1046  }
1047  }
1048  }
1049 
1050  return Op;
1051 }
1052 
1053 // Need to transform ISD::PREFETCH into something that doesn't inherit
1054 // all of the properties of ISD::PREFETCH, specifically SDNPMayLoad and
1055 // SDNPMayStore.
1057  SelectionDAG &DAG) const {
1058  SDValue Chain = Op.getOperand(0);
1059  SDValue Addr = Op.getOperand(1);
1060  // Lower it to DCFETCH($reg, #0). A "pat" will try to merge the offset in,
1061  // if the "reg" is fed by an "add".
1062  SDLoc DL(Op);
1063  SDValue Zero = DAG.getConstant(0, DL, MVT::i32);
1064  return DAG.getNode(HexagonISD::DCFETCH, DL, MVT::Other, Chain, Addr, Zero);
1065 }
1066 
1067 // Custom-handle ISD::READCYCLECOUNTER because the target-independent SDNode
1068 // is marked as having side-effects, while the register read on Hexagon does
1069 // not have any. TableGen refuses to accept the direct pattern from that node
1070 // to the A4_tfrcpp.
1072  SelectionDAG &DAG) const {
1073  SDValue Chain = Op.getOperand(0);
1074  SDLoc dl(Op);
1075  SDVTList VTs = DAG.getVTList(MVT::i32, MVT::Other);
1076  return DAG.getNode(HexagonISD::READCYCLE, dl, VTs, Chain);
1077 }
1078 
1080  SelectionDAG &DAG) const {
1081  SDValue Chain = Op.getOperand(0);
1082  unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue();
1083  // Lower the hexagon_prefetch builtin to DCFETCH, as above.
1084  if (IntNo == Intrinsic::hexagon_prefetch) {
1085  SDValue Addr = Op.getOperand(2);
1086  SDLoc DL(Op);
1087  SDValue Zero = DAG.getConstant(0, DL, MVT::i32);
1088  return DAG.getNode(HexagonISD::DCFETCH, DL, MVT::Other, Chain, Addr, Zero);
1089  }
1090  return SDValue();
1091 }
1092 
1093 SDValue
1095  SelectionDAG &DAG) const {
1096  SDValue Chain = Op.getOperand(0);
1097  SDValue Size = Op.getOperand(1);
1098  SDValue Align = Op.getOperand(2);
1099  SDLoc dl(Op);
1100 
1101  ConstantSDNode *AlignConst = dyn_cast<ConstantSDNode>(Align);
1102  assert(AlignConst && "Non-constant Align in LowerDYNAMIC_STACKALLOC");
1103 
1104  unsigned A = AlignConst->getSExtValue();
1105  auto &HFI = *Subtarget.getFrameLowering();
1106  // "Zero" means natural stack alignment.
1107  if (A == 0)
1108  A = HFI.getStackAlignment();
1109 
1110  DEBUG({
1111  dbgs () << __func__ << " Align: " << A << " Size: ";
1112  Size.getNode()->dump(&DAG);
1113  dbgs() << "\n";
1114  });
1115 
1116  SDValue AC = DAG.getConstant(A, dl, MVT::i32);
1117  SDVTList VTs = DAG.getVTList(MVT::i32, MVT::Other);
1118  SDValue AA = DAG.getNode(HexagonISD::ALLOCA, dl, VTs, Chain, Size, AC);
1119 
1120  DAG.ReplaceAllUsesOfValueWith(Op, AA);
1121  return AA;
1122 }
1123 
1125  SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
1126  const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
1127  SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
1128  MachineFunction &MF = DAG.getMachineFunction();
1129  MachineFrameInfo &MFI = MF.getFrameInfo();
1130  MachineRegisterInfo &RegInfo = MF.getRegInfo();
1131  auto &FuncInfo = *MF.getInfo<HexagonMachineFunctionInfo>();
1132 
1133  // Assign locations to all of the incoming arguments.
1135  CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
1136  *DAG.getContext());
1137 
1138  CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon);
1139 
1140  // For LLVM, in the case when returning a struct by value (>8byte),
1141  // the first argument is a pointer that points to the location on caller's
1142  // stack where the return value will be stored. For Hexagon, the location on
1143  // caller's stack is passed only when the struct size is smaller than (and
1144  // equal to) 8 bytes. If not, no address will be passed into callee and
1145  // callee return the result direclty through R0/R1.
1146 
1147  SmallVector<SDValue, 8> MemOps;
1148  bool UseHVX = Subtarget.useHVXOps(), UseHVXDbl = Subtarget.useHVXDblOps();
1149 
1150  for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1151  CCValAssign &VA = ArgLocs[i];
1152  ISD::ArgFlagsTy Flags = Ins[i].Flags;
1153  unsigned ObjSize;
1154  unsigned StackLocation;
1155  int FI;
1156 
1157  if ( (VA.isRegLoc() && !Flags.isByVal())
1158  || (VA.isRegLoc() && Flags.isByVal() && Flags.getByValSize() > 8)) {
1159  // Arguments passed in registers
1160  // 1. int, long long, ptr args that get allocated in register.
1161  // 2. Large struct that gets an register to put its address in.
1162  EVT RegVT = VA.getLocVT();
1163  if (RegVT == MVT::i8 || RegVT == MVT::i16 ||
1164  RegVT == MVT::i32 || RegVT == MVT::f32) {
1165  unsigned VReg =
1166  RegInfo.createVirtualRegister(&Hexagon::IntRegsRegClass);
1167  RegInfo.addLiveIn(VA.getLocReg(), VReg);
1168  SDValue Copy = DAG.getCopyFromReg(Chain, dl, VReg, RegVT);
1169  // Treat values of type MVT::i1 specially: they are passed in
1170  // registers of type i32, but they need to remain as values of
1171  // type i1 for consistency of the argument lowering.
1172  if (VA.getValVT() == MVT::i1) {
1173  // Generate a copy into a predicate register and use the value
1174  // of the register as the "InVal".
1175  unsigned PReg =
1176  RegInfo.createVirtualRegister(&Hexagon::PredRegsRegClass);
1177  SDNode *T = DAG.getMachineNode(Hexagon::C2_tfrrp, dl, MVT::i1,
1178  Copy.getValue(0));
1179  Copy = DAG.getCopyToReg(Copy.getValue(1), dl, PReg, SDValue(T, 0));
1180  Copy = DAG.getCopyFromReg(Copy, dl, PReg, MVT::i1);
1181  }
1182  InVals.push_back(Copy);
1183  Chain = Copy.getValue(1);
1184  } else if (RegVT == MVT::i64 || RegVT == MVT::f64) {
1185  unsigned VReg =
1186  RegInfo.createVirtualRegister(&Hexagon::DoubleRegsRegClass);
1187  RegInfo.addLiveIn(VA.getLocReg(), VReg);
1188  InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT));
1189 
1190  // Single Vector
1191  } else if ((RegVT == MVT::v8i64 || RegVT == MVT::v16i32 ||
1192  RegVT == MVT::v32i16 || RegVT == MVT::v64i8)) {
1193  unsigned VReg =
1194  RegInfo.createVirtualRegister(&Hexagon::VectorRegsRegClass);
1195  RegInfo.addLiveIn(VA.getLocReg(), VReg);
1196  InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT));
1197  } else if (UseHVX && UseHVXDbl &&
1198  ((RegVT == MVT::v16i64 || RegVT == MVT::v32i32 ||
1199  RegVT == MVT::v64i16 || RegVT == MVT::v128i8))) {
1200  unsigned VReg =
1201  RegInfo.createVirtualRegister(&Hexagon::VectorRegs128BRegClass);
1202  RegInfo.addLiveIn(VA.getLocReg(), VReg);
1203  InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT));
1204 
1205  // Double Vector
1206  } else if ((RegVT == MVT::v16i64 || RegVT == MVT::v32i32 ||
1207  RegVT == MVT::v64i16 || RegVT == MVT::v128i8)) {
1208  unsigned VReg =
1209  RegInfo.createVirtualRegister(&Hexagon::VecDblRegsRegClass);
1210  RegInfo.addLiveIn(VA.getLocReg(), VReg);
1211  InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT));
1212  } else if (UseHVX && UseHVXDbl &&
1213  ((RegVT == MVT::v32i64 || RegVT == MVT::v64i32 ||
1214  RegVT == MVT::v128i16 || RegVT == MVT::v256i8))) {
1215  unsigned VReg =
1216  RegInfo.createVirtualRegister(&Hexagon::VecDblRegs128BRegClass);
1217  RegInfo.addLiveIn(VA.getLocReg(), VReg);
1218  InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT));
1219  } else if (RegVT == MVT::v512i1 || RegVT == MVT::v1024i1) {
1220  assert(0 && "need to support VecPred regs");
1221  unsigned VReg =
1222  RegInfo.createVirtualRegister(&Hexagon::VecPredRegsRegClass);
1223  RegInfo.addLiveIn(VA.getLocReg(), VReg);
1224  InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT));
1225  } else {
1226  assert (0);
1227  }
1228  } else if (VA.isRegLoc() && Flags.isByVal() && Flags.getByValSize() <= 8) {
1229  assert (0 && "ByValSize must be bigger than 8 bytes");
1230  } else {
1231  // Sanity check.
1232  assert(VA.isMemLoc());
1233 
1234  if (Flags.isByVal()) {
1235  // If it's a byval parameter, then we need to compute the
1236  // "real" size, not the size of the pointer.
1237  ObjSize = Flags.getByValSize();
1238  } else {
1239  ObjSize = VA.getLocVT().getStoreSizeInBits() >> 3;
1240  }
1241 
1242  StackLocation = HEXAGON_LRFP_SIZE + VA.getLocMemOffset();
1243  // Create the frame index object for this incoming parameter...
1244  FI = MFI.CreateFixedObject(ObjSize, StackLocation, true);
1245 
1246  // Create the SelectionDAG nodes cordl, responding to a load
1247  // from this parameter.
1248  SDValue FIN = DAG.getFrameIndex(FI, MVT::i32);
1249 
1250  if (Flags.isByVal()) {
1251  // If it's a pass-by-value aggregate, then do not dereference the stack
1252  // location. Instead, we should generate a reference to the stack
1253  // location.
1254  InVals.push_back(FIN);
1255  } else {
1256  InVals.push_back(
1257  DAG.getLoad(VA.getValVT(), dl, Chain, FIN, MachinePointerInfo()));
1258  }
1259  }
1260  }
1261 
1262  if (!MemOps.empty())
1263  Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOps);
1264 
1265  if (isVarArg) {
1266  // This will point to the next argument passed via stack.
1269  CCInfo.getNextStackOffset(),
1270  true);
1271  FuncInfo.setVarArgsFrameIndex(FrameIndex);
1272  }
1273 
1274  return Chain;
1275 }
1276 
1277 SDValue
1279  // VASTART stores the address of the VarArgsFrameIndex slot into the
1280  // memory location argument.
1281  MachineFunction &MF = DAG.getMachineFunction();
1283  SDValue Addr = DAG.getFrameIndex(QFI->getVarArgsFrameIndex(), MVT::i32);
1284  const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
1285  return DAG.getStore(Op.getOperand(0), SDLoc(Op), Addr, Op.getOperand(1),
1286  MachinePointerInfo(SV));
1287 }
1288 
1289 static bool isSExtFree(SDValue N) {
1290  // A sign-extend of a truncate of a sign-extend is free.
1291  if (N.getOpcode() == ISD::TRUNCATE &&
1293  return true;
1294  // We have sign-extended loads.
1295  if (N.getOpcode() == ISD::LOAD)
1296  return true;
1297  return false;
1298 }
1299 
1301  SDLoc dl(Op);
1302 
1303  SDValue LHS = Op.getOperand(0);
1304  SDValue RHS = Op.getOperand(1);
1305  SDValue Cmp = Op.getOperand(2);
1306  ISD::CondCode CC = cast<CondCodeSDNode>(Cmp)->get();
1307 
1308  EVT VT = Op.getValueType();
1309  EVT LHSVT = LHS.getValueType();
1310  EVT RHSVT = RHS.getValueType();
1311 
1312  if (LHSVT == MVT::v2i16) {
1314  unsigned ExtOpc = ISD::isSignedIntSetCC(CC) ? ISD::SIGN_EXTEND
1315  : ISD::ZERO_EXTEND;
1316  SDValue LX = DAG.getNode(ExtOpc, dl, MVT::v2i32, LHS);
1317  SDValue RX = DAG.getNode(ExtOpc, dl, MVT::v2i32, RHS);
1318  SDValue SC = DAG.getNode(ISD::SETCC, dl, MVT::v2i1, LX, RX, Cmp);
1319  return SC;
1320  }
1321 
1322  // Treat all other vector types as legal.
1323  if (VT.isVector())
1324  return Op;
1325 
1326  // Equals and not equals should use sign-extend, not zero-extend, since
1327  // we can represent small negative values in the compare instructions.
1328  // The LLVM default is to use zero-extend arbitrarily in these cases.
1329  if ((CC == ISD::SETEQ || CC == ISD::SETNE) &&
1330  (RHSVT == MVT::i8 || RHSVT == MVT::i16) &&
1331  (LHSVT == MVT::i8 || LHSVT == MVT::i16)) {
1333  if (C && C->getAPIntValue().isNegative()) {
1334  LHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, LHS);
1335  RHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, RHS);
1336  return DAG.getNode(ISD::SETCC, dl, Op.getValueType(),
1337  LHS, RHS, Op.getOperand(2));
1338  }
1339  if (isSExtFree(LHS) || isSExtFree(RHS)) {
1340  LHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, LHS);
1341  RHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, RHS);
1342  return DAG.getNode(ISD::SETCC, dl, Op.getValueType(),
1343  LHS, RHS, Op.getOperand(2));
1344  }
1345  }
1346  return SDValue();
1347 }
1348 
1349 SDValue
1351  SDValue PredOp = Op.getOperand(0);
1352  SDValue Op1 = Op.getOperand(1), Op2 = Op.getOperand(2);
1353  EVT OpVT = Op1.getValueType();
1354  SDLoc DL(Op);
1355 
1356  if (OpVT == MVT::v2i16) {
1357  SDValue X1 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v2i32, Op1);
1358  SDValue X2 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v2i32, Op2);
1359  SDValue SL = DAG.getNode(ISD::VSELECT, DL, MVT::v2i32, PredOp, X1, X2);
1360  SDValue TR = DAG.getNode(ISD::TRUNCATE, DL, MVT::v2i16, SL);
1361  return TR;
1362  }
1363 
1364  return SDValue();
1365 }
1366 
1367 SDValue
1369  EVT ValTy = Op.getValueType();
1370  ConstantPoolSDNode *CPN = cast<ConstantPoolSDNode>(Op);
1371  unsigned Align = CPN->getAlignment();
1372  bool IsPositionIndependent = isPositionIndependent();
1373  unsigned char TF = IsPositionIndependent ? HexagonII::MO_PCREL : 0;
1374 
1375  unsigned Offset = 0;
1376  SDValue T;
1377  if (CPN->isMachineConstantPoolEntry())
1378  T = DAG.getTargetConstantPool(CPN->getMachineCPVal(), ValTy, Align, Offset,
1379  TF);
1380  else
1381  T = DAG.getTargetConstantPool(CPN->getConstVal(), ValTy, Align, Offset,
1382  TF);
1383 
1384  assert(cast<ConstantPoolSDNode>(T)->getTargetFlags() == TF &&
1385  "Inconsistent target flag encountered");
1386 
1387  if (IsPositionIndependent)
1388  return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), ValTy, T);
1389  return DAG.getNode(HexagonISD::CP, SDLoc(Op), ValTy, T);
1390 }
1391 
1392 SDValue
1394  EVT VT = Op.getValueType();
1395  int Idx = cast<JumpTableSDNode>(Op)->getIndex();
1396  if (isPositionIndependent()) {
1398  return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), VT, T);
1399  }
1400 
1401  SDValue T = DAG.getTargetJumpTable(Idx, VT);
1402  return DAG.getNode(HexagonISD::JT, SDLoc(Op), VT, T);
1403 }
1404 
1405 SDValue
1407  const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
1408  MachineFunction &MF = DAG.getMachineFunction();
1409  MachineFrameInfo &MFI = MF.getFrameInfo();
1410  MFI.setReturnAddressIsTaken(true);
1411 
1413  return SDValue();
1414 
1415  EVT VT = Op.getValueType();
1416  SDLoc dl(Op);
1417  unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
1418  if (Depth) {
1419  SDValue FrameAddr = LowerFRAMEADDR(Op, DAG);
1420  SDValue Offset = DAG.getConstant(4, dl, MVT::i32);
1421  return DAG.getLoad(VT, dl, DAG.getEntryNode(),
1422  DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset),
1423  MachinePointerInfo());
1424  }
1425 
1426  // Return LR, which contains the return address. Mark it an implicit live-in.
1427  unsigned Reg = MF.addLiveIn(HRI.getRARegister(), getRegClassFor(MVT::i32));
1428  return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT);
1429 }
1430 
1431 SDValue
1433  const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
1435  MFI.setFrameAddressIsTaken(true);
1436 
1437  EVT VT = Op.getValueType();
1438  SDLoc dl(Op);
1439  unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
1440  SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl,
1441  HRI.getFrameRegister(), VT);
1442  while (Depth--)
1443  FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr,
1444  MachinePointerInfo());
1445  return FrameAddr;
1446 }
1447 
1448 SDValue
1450  SDLoc dl(Op);
1451  return DAG.getNode(HexagonISD::BARRIER, dl, MVT::Other, Op.getOperand(0));
1452 }
1453 
1454 SDValue
1456  SDLoc dl(Op);
1457  auto *GAN = cast<GlobalAddressSDNode>(Op);
1458  auto PtrVT = getPointerTy(DAG.getDataLayout());
1459  auto *GV = GAN->getGlobal();
1460  int64_t Offset = GAN->getOffset();
1461 
1462  auto &HLOF = *HTM.getObjFileLowering();
1464 
1465  if (RM == Reloc::Static) {
1466  SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset);
1467  const GlobalObject *GO = GV->getBaseObject();
1468  if (GO && HLOF.isGlobalInSmallSection(GO, HTM))
1469  return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, GA);
1470  return DAG.getNode(HexagonISD::CONST32, dl, PtrVT, GA);
1471  }
1472 
1473  bool UsePCRel = getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV);
1474  if (UsePCRel) {
1475  SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset,
1477  return DAG.getNode(HexagonISD::AT_PCREL, dl, PtrVT, GA);
1478  }
1479 
1480  // Use GOT index.
1481  SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT);
1482  SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, HexagonII::MO_GOT);
1483  SDValue Off = DAG.getConstant(Offset, dl, MVT::i32);
1484  return DAG.getNode(HexagonISD::AT_GOT, dl, PtrVT, GOT, GA, Off);
1485 }
1486 
1487 // Specifies that for loads and stores VT can be promoted to PromotedLdStVT.
1488 SDValue
1490  const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress();
1491  SDLoc dl(Op);
1492  EVT PtrVT = getPointerTy(DAG.getDataLayout());
1493 
1495  if (RM == Reloc::Static) {
1496  SDValue A = DAG.getTargetBlockAddress(BA, PtrVT);
1497  return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, A);
1498  }
1499 
1500  SDValue A = DAG.getTargetBlockAddress(BA, PtrVT, 0, HexagonII::MO_PCREL);
1501  return DAG.getNode(HexagonISD::AT_PCREL, dl, PtrVT, A);
1502 }
1503 
1504 SDValue
1506  const {
1507  EVT PtrVT = getPointerTy(DAG.getDataLayout());
1510  return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), PtrVT, GOTSym);
1511 }
1512 
1513 SDValue
1515  GlobalAddressSDNode *GA, SDValue Glue, EVT PtrVT, unsigned ReturnReg,
1516  unsigned char OperandFlags) const {
1517  MachineFunction &MF = DAG.getMachineFunction();
1518  MachineFrameInfo &MFI = MF.getFrameInfo();
1519  SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
1520  SDLoc dl(GA);
1521  SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl,
1522  GA->getValueType(0),
1523  GA->getOffset(),
1524  OperandFlags);
1525  // Create Operands for the call.The Operands should have the following:
1526  // 1. Chain SDValue
1527  // 2. Callee which in this case is the Global address value.
1528  // 3. Registers live into the call.In this case its R0, as we
1529  // have just one argument to be passed.
1530  // 4. Glue.
1531  // Note: The order is important.
1532 
1533  const auto &HRI = *Subtarget.getRegisterInfo();
1534  const uint32_t *Mask = HRI.getCallPreservedMask(MF, CallingConv::C);
1535  assert(Mask && "Missing call preserved mask for calling convention");
1536  SDValue Ops[] = { Chain, TGA, DAG.getRegister(Hexagon::R0, PtrVT),
1537  DAG.getRegisterMask(Mask), Glue };
1538  Chain = DAG.getNode(HexagonISD::CALL, dl, NodeTys, Ops);
1539 
1540  // Inform MFI that function has calls.
1541  MFI.setAdjustsStack(true);
1542 
1543  Glue = Chain.getValue(1);
1544  return DAG.getCopyFromReg(Chain, dl, ReturnReg, PtrVT, Glue);
1545 }
1546 
1547 //
1548 // Lower using the intial executable model for TLS addresses
1549 //
1550 SDValue
1552  SelectionDAG &DAG) const {
1553  SDLoc dl(GA);
1554  int64_t Offset = GA->getOffset();
1555  auto PtrVT = getPointerTy(DAG.getDataLayout());
1556 
1557  // Get the thread pointer.
1558  SDValue TP = DAG.getCopyFromReg(DAG.getEntryNode(), dl, Hexagon::UGP, PtrVT);
1559 
1560  bool IsPositionIndependent = isPositionIndependent();
1561  unsigned char TF =
1562  IsPositionIndependent ? HexagonII::MO_IEGOT : HexagonII::MO_IE;
1563 
1564  // First generate the TLS symbol address
1565  SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT,
1566  Offset, TF);
1567 
1568  SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA);
1569 
1570  if (IsPositionIndependent) {
1571  // Generate the GOT pointer in case of position independent code
1572  SDValue GOT = LowerGLOBAL_OFFSET_TABLE(Sym, DAG);
1573 
1574  // Add the TLS Symbol address to GOT pointer.This gives
1575  // GOT relative relocation for the symbol.
1576  Sym = DAG.getNode(ISD::ADD, dl, PtrVT, GOT, Sym);
1577  }
1578 
1579  // Load the offset value for TLS symbol.This offset is relative to
1580  // thread pointer.
1581  SDValue LoadOffset =
1582  DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Sym, MachinePointerInfo());
1583 
1584  // Address of the thread local variable is the add of thread
1585  // pointer and the offset of the variable.
1586  return DAG.getNode(ISD::ADD, dl, PtrVT, TP, LoadOffset);
1587 }
1588 
1589 //
1590 // Lower using the local executable model for TLS addresses
1591 //
1592 SDValue
1594  SelectionDAG &DAG) const {
1595  SDLoc dl(GA);
1596  int64_t Offset = GA->getOffset();
1597  auto PtrVT = getPointerTy(DAG.getDataLayout());
1598 
1599  // Get the thread pointer.
1600  SDValue TP = DAG.getCopyFromReg(DAG.getEntryNode(), dl, Hexagon::UGP, PtrVT);
1601  // Generate the TLS symbol address
1602  SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, Offset,
1604  SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA);
1605 
1606  // Address of the thread local variable is the add of thread
1607  // pointer and the offset of the variable.
1608  return DAG.getNode(ISD::ADD, dl, PtrVT, TP, Sym);
1609 }
1610 
1611 //
1612 // Lower using the general dynamic model for TLS addresses
1613 //
1614 SDValue
1616  SelectionDAG &DAG) const {
1617  SDLoc dl(GA);
1618  int64_t Offset = GA->getOffset();
1619  auto PtrVT = getPointerTy(DAG.getDataLayout());
1620 
1621  // First generate the TLS symbol address
1622  SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, Offset,
1624 
1625  // Then, generate the GOT pointer
1626  SDValue GOT = LowerGLOBAL_OFFSET_TABLE(TGA, DAG);
1627 
1628  // Add the TLS symbol and the GOT pointer
1629  SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA);
1630  SDValue Chain = DAG.getNode(ISD::ADD, dl, PtrVT, GOT, Sym);
1631 
1632  // Copy over the argument to R0
1633  SDValue InFlag;
1634  Chain = DAG.getCopyToReg(DAG.getEntryNode(), dl, Hexagon::R0, Chain, InFlag);
1635  InFlag = Chain.getValue(1);
1636 
1637  unsigned Flags =
1638  static_cast<const HexagonSubtarget &>(DAG.getSubtarget()).useLongCalls()
1641 
1642  return GetDynamicTLSAddr(DAG, Chain, GA, InFlag, PtrVT,
1643  Hexagon::R0, Flags);
1644 }
1645 
1646 //
1647 // Lower TLS addresses.
1648 //
1649 // For now for dynamic models, we only support the general dynamic model.
1650 //
1651 SDValue
1653  SelectionDAG &DAG) const {
1654  GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op);
1655 
1656  switch (HTM.getTLSModel(GA->getGlobal())) {
1659  return LowerToTLSGeneralDynamicModel(GA, DAG);
1660  case TLSModel::InitialExec:
1661  return LowerToTLSInitialExecModel(GA, DAG);
1662  case TLSModel::LocalExec:
1663  return LowerToTLSLocalExecModel(GA, DAG);
1664  }
1665  llvm_unreachable("Bogus TLS model");
1666 }
1667 
1668 //===----------------------------------------------------------------------===//
1669 // TargetLowering Implementation
1670 //===----------------------------------------------------------------------===//
1671 
1673  const HexagonSubtarget &ST)
1674  : TargetLowering(TM), HTM(static_cast<const HexagonTargetMachine&>(TM)),
1675  Subtarget(ST) {
1676  bool IsV4 = !Subtarget.hasV5TOps();
1677  auto &HRI = *Subtarget.getRegisterInfo();
1678  bool UseHVX = Subtarget.useHVXOps();
1679  bool UseHVXSgl = Subtarget.useHVXSglOps();
1680  bool UseHVXDbl = Subtarget.useHVXDblOps();
1681 
1685  setStackPointerRegisterToSaveRestore(HRI.getStackRegister());
1686 
1689 
1692  else
1694 
1695  // Limits for inline expansion of memcpy/memmove
1702 
1703  //
1704  // Set up register classes.
1705  //
1706 
1707  addRegisterClass(MVT::i1, &Hexagon::PredRegsRegClass);
1708  addRegisterClass(MVT::v2i1, &Hexagon::PredRegsRegClass); // bbbbaaaa
1709  addRegisterClass(MVT::v4i1, &Hexagon::PredRegsRegClass); // ddccbbaa
1710  addRegisterClass(MVT::v8i1, &Hexagon::PredRegsRegClass); // hgfedcba
1711  addRegisterClass(MVT::i32, &Hexagon::IntRegsRegClass);
1712  addRegisterClass(MVT::v4i8, &Hexagon::IntRegsRegClass);
1713  addRegisterClass(MVT::v2i16, &Hexagon::IntRegsRegClass);
1714  addRegisterClass(MVT::i64, &Hexagon::DoubleRegsRegClass);
1715  addRegisterClass(MVT::v8i8, &Hexagon::DoubleRegsRegClass);
1716  addRegisterClass(MVT::v4i16, &Hexagon::DoubleRegsRegClass);
1717  addRegisterClass(MVT::v2i32, &Hexagon::DoubleRegsRegClass);
1718 
1719  if (Subtarget.hasV5TOps()) {
1720  addRegisterClass(MVT::f32, &Hexagon::IntRegsRegClass);
1721  addRegisterClass(MVT::f64, &Hexagon::DoubleRegsRegClass);
1722  }
1723 
1724  if (Subtarget.hasV60TOps()) {
1725  if (Subtarget.useHVXSglOps()) {
1726  addRegisterClass(MVT::v64i8, &Hexagon::VectorRegsRegClass);
1727  addRegisterClass(MVT::v32i16, &Hexagon::VectorRegsRegClass);
1728  addRegisterClass(MVT::v16i32, &Hexagon::VectorRegsRegClass);
1729  addRegisterClass(MVT::v8i64, &Hexagon::VectorRegsRegClass);
1730  addRegisterClass(MVT::v128i8, &Hexagon::VecDblRegsRegClass);
1731  addRegisterClass(MVT::v64i16, &Hexagon::VecDblRegsRegClass);
1732  addRegisterClass(MVT::v32i32, &Hexagon::VecDblRegsRegClass);
1733  addRegisterClass(MVT::v16i64, &Hexagon::VecDblRegsRegClass);
1734  addRegisterClass(MVT::v512i1, &Hexagon::VecPredRegsRegClass);
1735  } else if (Subtarget.useHVXDblOps()) {
1736  addRegisterClass(MVT::v128i8, &Hexagon::VectorRegs128BRegClass);
1737  addRegisterClass(MVT::v64i16, &Hexagon::VectorRegs128BRegClass);
1738  addRegisterClass(MVT::v32i32, &Hexagon::VectorRegs128BRegClass);
1739  addRegisterClass(MVT::v16i64, &Hexagon::VectorRegs128BRegClass);
1740  addRegisterClass(MVT::v256i8, &Hexagon::VecDblRegs128BRegClass);
1741  addRegisterClass(MVT::v128i16, &Hexagon::VecDblRegs128BRegClass);
1742  addRegisterClass(MVT::v64i32, &Hexagon::VecDblRegs128BRegClass);
1743  addRegisterClass(MVT::v32i64, &Hexagon::VecDblRegs128BRegClass);
1744  addRegisterClass(MVT::v1024i1, &Hexagon::VecPredRegs128BRegClass);
1745  }
1746  }
1747 
1748  //
1749  // Handling of scalar operations.
1750  //
1751  // All operations default to "legal", except:
1752  // - indexed loads and stores (pre-/post-incremented),
1753  // - ANY_EXTEND_VECTOR_INREG, ATOMIC_CMP_SWAP_WITH_SUCCESS, CONCAT_VECTORS,
1754  // ConstantFP, DEBUGTRAP, FCEIL, FCOPYSIGN, FEXP, FEXP2, FFLOOR, FGETSIGN,
1755  // FLOG, FLOG2, FLOG10, FMAXNUM, FMINNUM, FNEARBYINT, FRINT, FROUND, TRAP,
1756  // FTRUNC, PREFETCH, SIGN_EXTEND_VECTOR_INREG, ZERO_EXTEND_VECTOR_INREG,
1757  // which default to "expand" for at least one type.
1758 
1759  // Misc operations.
1760  setOperationAction(ISD::ConstantFP, MVT::f32, Legal); // Default: expand
1761  setOperationAction(ISD::ConstantFP, MVT::f64, Legal); // Default: expand
1762 
1775 
1776  // Custom legalize GlobalAddress nodes into CONST32.
1780 
1781  // Hexagon needs to optimize cases with negative constants.
1784 
1785  // VASTART needs to be custom lowered to use the VarArgsFrameIndex.
1789 
1793 
1794  if (EmitJumpTables)
1796  else
1799 
1800  // Hexagon has instructions for add/sub with carry. The problem with
1801  // modeling these instructions is that they produce 2 results: Rdd and Px.
1802  // To model the update of Px, we will have to use Defs[p0..p3] which will
1803  // cause any predicate live range to spill. So, we pretend we dont't have
1804  // these instructions.
1821 
1822  // Only add and sub that detect overflow are the saturating ones.
1823  for (MVT VT : MVT::integer_valuetypes()) {
1828  }
1829 
1834 
1835  // In V5, popcount can count # of 1s in i64 but returns i32.
1836  // On V4 it will be expanded (set later).
1841 
1847 
1848  for (unsigned IntExpOp :
1853  setOperationAction(IntExpOp, MVT::i32, Expand);
1854  setOperationAction(IntExpOp, MVT::i64, Expand);
1855  }
1856 
1857  for (unsigned FPExpOp :
1860  setOperationAction(FPExpOp, MVT::f32, Expand);
1861  setOperationAction(FPExpOp, MVT::f64, Expand);
1862  }
1863 
1864  // No extending loads from i32.
1865  for (MVT VT : MVT::integer_valuetypes()) {
1869  }
1870  // Turn FP truncstore into trunc + store.
1872  // Turn FP extload into load/fpextend.
1873  for (MVT VT : MVT::fp_valuetypes())
1875 
1876  // Expand BR_CC and SELECT_CC for all integer and fp types.
1877  for (MVT VT : MVT::integer_valuetypes()) {
1880  }
1881  for (MVT VT : MVT::fp_valuetypes()) {
1884  }
1886 
1887  //
1888  // Handling of vector operations.
1889  //
1890 
1891  promoteLdStType(MVT::v4i8, MVT::i32);
1892  promoteLdStType(MVT::v2i16, MVT::i32);
1893  promoteLdStType(MVT::v8i8, MVT::i64);
1894  promoteLdStType(MVT::v4i16, MVT::i64);
1895  promoteLdStType(MVT::v2i32, MVT::i64);
1896 
1897  // Set the action for vector operations to "expand", then override it with
1898  // either "custom" or "legal" for specific cases.
1899  static const unsigned VectExpOps[] = {
1900  // Integer arithmetic:
1905  // Logical/bit:
1908  // Floating point arithmetic/math functions:
1915  // Misc:
1917  // Vector:
1922  };
1923 
1924  for (MVT VT : MVT::vector_valuetypes()) {
1925  for (unsigned VectExpOp : VectExpOps)
1926  setOperationAction(VectExpOp, VT, Expand);
1927 
1928  // Expand all extending loads and truncating stores:
1929  for (MVT TargetVT : MVT::vector_valuetypes()) {
1930  if (TargetVT == VT)
1931  continue;
1932  setLoadExtAction(ISD::EXTLOAD, TargetVT, VT, Expand);
1933  setLoadExtAction(ISD::ZEXTLOAD, TargetVT, VT, Expand);
1934  setLoadExtAction(ISD::SEXTLOAD, TargetVT, VT, Expand);
1935  setTruncStoreAction(VT, TargetVT, Expand);
1936  }
1937 
1938  // Normalize all inputs to SELECT to be vectors of i32.
1939  if (VT.getVectorElementType() != MVT::i32) {
1940  MVT VT32 = MVT::getVectorVT(MVT::i32, VT.getSizeInBits()/32);
1942  AddPromotedToType(ISD::SELECT, VT, VT32);
1943  }
1947  }
1948 
1949  // Types natively supported:
1950  for (MVT NativeVT : {MVT::v2i1, MVT::v4i1, MVT::v8i1, MVT::v32i1, MVT::v64i1,
1952  MVT::v2i32, MVT::v1i64}) {
1959 
1960  setOperationAction(ISD::ADD, NativeVT, Legal);
1961  setOperationAction(ISD::SUB, NativeVT, Legal);
1962  setOperationAction(ISD::MUL, NativeVT, Legal);
1963  setOperationAction(ISD::AND, NativeVT, Legal);
1964  setOperationAction(ISD::OR, NativeVT, Legal);
1965  setOperationAction(ISD::XOR, NativeVT, Legal);
1966  }
1967 
1972 
1973  if (UseHVX) {
1974  if (UseHVXSgl) {
1979  // We try to generate the vpack{e/o} instructions. If we fail
1980  // we fall back upon ExpandOp.
1986  } else if (UseHVXDbl) {
1991  // We try to generate the vpack{e/o} instructions. If we fail
1992  // we fall back upon ExpandOp.
1999  } else {
2000  llvm_unreachable("Unrecognized HVX mode");
2001  }
2002  }
2003  // Subtarget-specific operation actions.
2004  //
2005  if (Subtarget.hasV5TOps()) {
2010 
2013 
2026  } else { // V4
2036 
2041 
2042  // Expand these operations for both f32 and f64:
2043  for (unsigned FPExpOpV4 :
2045  setOperationAction(FPExpOpV4, MVT::f32, Expand);
2046  setOperationAction(FPExpOpV4, MVT::f64, Expand);
2047  }
2048 
2049  for (ISD::CondCode FPExpCCV4 :
2051  ISD::SETUO, ISD::SETO}) {
2052  setCondCodeAction(FPExpCCV4, MVT::f32, Expand);
2053  setCondCodeAction(FPExpCCV4, MVT::f64, Expand);
2054  }
2055  }
2056 
2057  // Handling of indexed loads/stores: default is "expand".
2058  //
2059  for (MVT VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i64}) {
2062  }
2063 
2064  if (UseHVXSgl) {
2069  }
2070  } else if (UseHVXDbl) {
2075  }
2076  }
2077 
2079 
2080  //
2081  // Library calls for unsupported operations
2082  //
2083  bool FastMath = EnableFastMath;
2084 
2085  setLibcallName(RTLIB::SDIV_I32, "__hexagon_divsi3");
2086  setLibcallName(RTLIB::SDIV_I64, "__hexagon_divdi3");
2087  setLibcallName(RTLIB::UDIV_I32, "__hexagon_udivsi3");
2088  setLibcallName(RTLIB::UDIV_I64, "__hexagon_udivdi3");
2089  setLibcallName(RTLIB::SREM_I32, "__hexagon_modsi3");
2090  setLibcallName(RTLIB::SREM_I64, "__hexagon_moddi3");
2091  setLibcallName(RTLIB::UREM_I32, "__hexagon_umodsi3");
2092  setLibcallName(RTLIB::UREM_I64, "__hexagon_umoddi3");
2093 
2094  setLibcallName(RTLIB::SINTTOFP_I128_F64, "__hexagon_floattidf");
2095  setLibcallName(RTLIB::SINTTOFP_I128_F32, "__hexagon_floattisf");
2096  setLibcallName(RTLIB::FPTOUINT_F32_I128, "__hexagon_fixunssfti");
2097  setLibcallName(RTLIB::FPTOUINT_F64_I128, "__hexagon_fixunsdfti");
2098  setLibcallName(RTLIB::FPTOSINT_F32_I128, "__hexagon_fixsfti");
2099  setLibcallName(RTLIB::FPTOSINT_F64_I128, "__hexagon_fixdfti");
2100 
2101  if (IsV4) {
2102  // Handle single-precision floating point operations on V4.
2103  if (FastMath) {
2104  setLibcallName(RTLIB::ADD_F32, "__hexagon_fast_addsf3");
2105  setLibcallName(RTLIB::SUB_F32, "__hexagon_fast_subsf3");
2106  setLibcallName(RTLIB::MUL_F32, "__hexagon_fast_mulsf3");
2107  setLibcallName(RTLIB::OGT_F32, "__hexagon_fast_gtsf2");
2108  setLibcallName(RTLIB::OLT_F32, "__hexagon_fast_ltsf2");
2109  // Double-precision compares.
2110  setLibcallName(RTLIB::OGT_F64, "__hexagon_fast_gtdf2");
2111  setLibcallName(RTLIB::OLT_F64, "__hexagon_fast_ltdf2");
2112  } else {
2113  setLibcallName(RTLIB::ADD_F32, "__hexagon_addsf3");
2114  setLibcallName(RTLIB::SUB_F32, "__hexagon_subsf3");
2115  setLibcallName(RTLIB::MUL_F32, "__hexagon_mulsf3");
2116  setLibcallName(RTLIB::OGT_F32, "__hexagon_gtsf2");
2117  setLibcallName(RTLIB::OLT_F32, "__hexagon_ltsf2");
2118  // Double-precision compares.
2119  setLibcallName(RTLIB::OGT_F64, "__hexagon_gtdf2");
2120  setLibcallName(RTLIB::OLT_F64, "__hexagon_ltdf2");
2121  }
2122  }
2123 
2124  // This is the only fast library function for sqrtd.
2125  if (FastMath)
2126  setLibcallName(RTLIB::SQRT_F64, "__hexagon_fast2_sqrtdf2");
2127 
2128  // Prefix is: nothing for "slow-math",
2129  // "fast2_" for V4 fast-math and V5+ fast-math double-precision
2130  // (actually, keep fast-math and fast-math2 separate for now)
2131  if (FastMath) {
2132  setLibcallName(RTLIB::ADD_F64, "__hexagon_fast_adddf3");
2133  setLibcallName(RTLIB::SUB_F64, "__hexagon_fast_subdf3");
2134  setLibcallName(RTLIB::MUL_F64, "__hexagon_fast_muldf3");
2135  setLibcallName(RTLIB::DIV_F64, "__hexagon_fast_divdf3");
2136  // Calling __hexagon_fast2_divsf3 with fast-math on V5 (ok).
2137  setLibcallName(RTLIB::DIV_F32, "__hexagon_fast_divsf3");
2138  } else {
2139  setLibcallName(RTLIB::ADD_F64, "__hexagon_adddf3");
2140  setLibcallName(RTLIB::SUB_F64, "__hexagon_subdf3");
2141  setLibcallName(RTLIB::MUL_F64, "__hexagon_muldf3");
2142  setLibcallName(RTLIB::DIV_F64, "__hexagon_divdf3");
2143  setLibcallName(RTLIB::DIV_F32, "__hexagon_divsf3");
2144  }
2145 
2146  if (Subtarget.hasV5TOps()) {
2147  if (FastMath)
2148  setLibcallName(RTLIB::SQRT_F32, "__hexagon_fast2_sqrtf");
2149  else
2150  setLibcallName(RTLIB::SQRT_F32, "__hexagon_sqrtf");
2151  } else {
2152  // V4
2153  setLibcallName(RTLIB::SINTTOFP_I32_F32, "__hexagon_floatsisf");
2154  setLibcallName(RTLIB::SINTTOFP_I32_F64, "__hexagon_floatsidf");
2155  setLibcallName(RTLIB::SINTTOFP_I64_F32, "__hexagon_floatdisf");
2156  setLibcallName(RTLIB::SINTTOFP_I64_F64, "__hexagon_floatdidf");
2157  setLibcallName(RTLIB::UINTTOFP_I32_F32, "__hexagon_floatunsisf");
2158  setLibcallName(RTLIB::UINTTOFP_I32_F64, "__hexagon_floatunsidf");
2159  setLibcallName(RTLIB::UINTTOFP_I64_F32, "__hexagon_floatundisf");
2160  setLibcallName(RTLIB::UINTTOFP_I64_F64, "__hexagon_floatundidf");
2161  setLibcallName(RTLIB::FPTOUINT_F32_I32, "__hexagon_fixunssfsi");
2162  setLibcallName(RTLIB::FPTOUINT_F32_I64, "__hexagon_fixunssfdi");
2163  setLibcallName(RTLIB::FPTOUINT_F64_I32, "__hexagon_fixunsdfsi");
2164  setLibcallName(RTLIB::FPTOUINT_F64_I64, "__hexagon_fixunsdfdi");
2165  setLibcallName(RTLIB::FPTOSINT_F32_I32, "__hexagon_fixsfsi");
2166  setLibcallName(RTLIB::FPTOSINT_F32_I64, "__hexagon_fixsfdi");
2167  setLibcallName(RTLIB::FPTOSINT_F64_I32, "__hexagon_fixdfsi");
2168  setLibcallName(RTLIB::FPTOSINT_F64_I64, "__hexagon_fixdfdi");
2169  setLibcallName(RTLIB::FPEXT_F32_F64, "__hexagon_extendsfdf2");
2170  setLibcallName(RTLIB::FPROUND_F64_F32, "__hexagon_truncdfsf2");
2171  setLibcallName(RTLIB::OEQ_F32, "__hexagon_eqsf2");
2172  setLibcallName(RTLIB::OEQ_F64, "__hexagon_eqdf2");
2173  setLibcallName(RTLIB::OGE_F32, "__hexagon_gesf2");
2174  setLibcallName(RTLIB::OGE_F64, "__hexagon_gedf2");
2175  setLibcallName(RTLIB::OLE_F32, "__hexagon_lesf2");
2176  setLibcallName(RTLIB::OLE_F64, "__hexagon_ledf2");
2177  setLibcallName(RTLIB::UNE_F32, "__hexagon_nesf2");
2178  setLibcallName(RTLIB::UNE_F64, "__hexagon_nedf2");
2179  setLibcallName(RTLIB::UO_F32, "__hexagon_unordsf2");
2180  setLibcallName(RTLIB::UO_F64, "__hexagon_unorddf2");
2181  setLibcallName(RTLIB::O_F32, "__hexagon_unordsf2");
2182  setLibcallName(RTLIB::O_F64, "__hexagon_unorddf2");
2183  }
2184 
2185  // These cause problems when the shift amount is non-constant.
2186  setLibcallName(RTLIB::SHL_I128, nullptr);
2187  setLibcallName(RTLIB::SRL_I128, nullptr);
2188  setLibcallName(RTLIB::SRA_I128, nullptr);
2189 }
2190 
2191 const char* HexagonTargetLowering::getTargetNodeName(unsigned Opcode) const {
2192  switch ((HexagonISD::NodeType)Opcode) {
2193  case HexagonISD::ALLOCA: return "HexagonISD::ALLOCA";
2194  case HexagonISD::AT_GOT: return "HexagonISD::AT_GOT";
2195  case HexagonISD::AT_PCREL: return "HexagonISD::AT_PCREL";
2196  case HexagonISD::BARRIER: return "HexagonISD::BARRIER";
2197  case HexagonISD::CALL: return "HexagonISD::CALL";
2198  case HexagonISD::CALLnr: return "HexagonISD::CALLnr";
2199  case HexagonISD::CALLR: return "HexagonISD::CALLR";
2200  case HexagonISD::COMBINE: return "HexagonISD::COMBINE";
2201  case HexagonISD::CONST32_GP: return "HexagonISD::CONST32_GP";
2202  case HexagonISD::CONST32: return "HexagonISD::CONST32";
2203  case HexagonISD::CP: return "HexagonISD::CP";
2204  case HexagonISD::DCFETCH: return "HexagonISD::DCFETCH";
2205  case HexagonISD::EH_RETURN: return "HexagonISD::EH_RETURN";
2206  case HexagonISD::EXTRACTU: return "HexagonISD::EXTRACTU";
2207  case HexagonISD::EXTRACTURP: return "HexagonISD::EXTRACTURP";
2208  case HexagonISD::INSERT: return "HexagonISD::INSERT";
2209  case HexagonISD::INSERTRP: return "HexagonISD::INSERTRP";
2210  case HexagonISD::JT: return "HexagonISD::JT";
2211  case HexagonISD::PACKHL: return "HexagonISD::PACKHL";
2212  case HexagonISD::RET_FLAG: return "HexagonISD::RET_FLAG";
2213  case HexagonISD::TC_RETURN: return "HexagonISD::TC_RETURN";
2214  case HexagonISD::VCOMBINE: return "HexagonISD::VCOMBINE";
2215  case HexagonISD::VPACKE: return "HexagonISD::VPACKE";
2216  case HexagonISD::VPACKO: return "HexagonISD::VPACKO";
2217  case HexagonISD::VASL: return "HexagonISD::VASL";
2218  case HexagonISD::VASR: return "HexagonISD::VASR";
2219  case HexagonISD::VLSR: return "HexagonISD::VLSR";
2220  case HexagonISD::VSPLAT: return "HexagonISD::VSPLAT";
2221  case HexagonISD::READCYCLE: return "HexagonISD::READCYCLE";
2222  case HexagonISD::OP_END: break;
2223  }
2224  return nullptr;
2225 }
2226 
2228  EVT MTy1 = EVT::getEVT(Ty1);
2229  EVT MTy2 = EVT::getEVT(Ty2);
2230  if (!MTy1.isSimple() || !MTy2.isSimple())
2231  return false;
2232  return (MTy1.getSimpleVT() == MVT::i64) && (MTy2.getSimpleVT() == MVT::i32);
2233 }
2234 
2236  if (!VT1.isSimple() || !VT2.isSimple())
2237  return false;
2238  return (VT1.getSimpleVT() == MVT::i64) && (VT2.getSimpleVT() == MVT::i32);
2239 }
2240 
2242  return isOperationLegalOrCustom(ISD::FMA, VT);
2243 }
2244 
2245 // Should we expand the build vector with shuffles?
2247  unsigned DefinedValues) const {
2248  // Hexagon vector shuffle operates on element sizes of bytes or halfwords
2249  EVT EltVT = VT.getVectorElementType();
2250  int EltBits = EltVT.getSizeInBits();
2251  if ((EltBits != 8) && (EltBits != 16))
2252  return false;
2253 
2254  return TargetLowering::shouldExpandBuildVectorWithShuffles(VT, DefinedValues);
2255 }
2256 
2258  int even_start = -2;
2259  int odd_start = -1;
2260  size_t mask_len = Mask.size();
2261  for (auto idx : Mask) {
2262  if ((idx - even_start) == 2)
2263  even_start = idx;
2264  else
2265  break;
2266  }
2267  if (even_start == (int)(mask_len * 2) - 2)
2268  return StridedLoadKind::Even;
2269  for (auto idx : Mask) {
2270  if ((idx - odd_start) == 2)
2271  odd_start = idx;
2272  else
2273  break;
2274  }
2275  if (odd_start == (int)(mask_len * 2) - 1)
2276  return StridedLoadKind::Odd;
2277 
2278  return StridedLoadKind::NoPattern;
2279 }
2280 
2282  EVT VT) const {
2283  if (Subtarget.useHVXOps())
2284  return isStridedLoad(Mask) != StridedLoadKind::NoPattern;
2285  return true;
2286 }
2287 
2288 // Lower a vector shuffle (V1, V2, V3). V1 and V2 are the two vectors
2289 // to select data from, V3 is the permutation.
2290 SDValue
2292  const {
2293  const ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op);
2294  SDValue V1 = Op.getOperand(0);
2295  SDValue V2 = Op.getOperand(1);
2296  SDLoc dl(Op);
2297  EVT VT = Op.getValueType();
2298  bool UseHVX = Subtarget.useHVXOps();
2299 
2300  if (V2.isUndef())
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)
2309  return DAG.getNode(HexagonISD::VSPLAT, dl, VT, V1.getOperand(0));
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;
2317  for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) {
2318  if (!V1.getOperand(i).isUndef()) {
2319  IsScalarToVector = false;
2320  break;
2321  }
2322  }
2323  if (IsScalarToVector)
2324  return DAG.getNode(HexagonISD::VSPLAT, dl, VT, V1.getOperand(0));
2325  }
2326  return DAG.getNode(HexagonISD::VSPLAT, dl, VT,
2327  DAG.getConstant(Lane, dl, MVT::i32));
2328  }
2329 
2330  if (UseHVX) {
2331  ArrayRef<int> Mask = SVN->getMask();
2332  size_t MaskLen = Mask.size();
2333  unsigned SizeInBits = VT.getScalarSizeInBits() * MaskLen;
2334 
2335  if ((Subtarget.useHVXSglOps() && SizeInBits == 64 * 8) ||
2336  (Subtarget.useHVXDblOps() && SizeInBits == 128 * 8)) {
2337  StridedLoadKind Pattern = isStridedLoad(Mask);
2338  if (Pattern == StridedLoadKind::NoPattern)
2339  return SDValue();
2340 
2341  unsigned Opc = Pattern == StridedLoadKind::Even ? HexagonISD::VPACKE
2343  return DAG.getNode(Opc, dl, VT, {Op.getOperand(1), Op.getOperand(0)});
2344  }
2345  // We used to assert in the "else" part here, but that is bad for Halide
2346  // Halide creates intermediate double registers by interleaving two
2347  // concatenated vector registers. The interleaving requires vector_shuffle
2348  // nodes and we shouldn't barf on a double register result of a
2349  // vector_shuffle because it is most likely an intermediate result.
2350  }
2351  // FIXME: We need to support more general vector shuffles. See
2352  // below the comment from the ARM backend that deals in the general
2353  // case with the vector shuffles. For now, let expand handle these.
2354  return SDValue();
2355 
2356  // If the shuffle is not directly supported and it has 4 elements, use
2357  // the PerfectShuffle-generated table to synthesize it from other shuffles.
2358 }
2359 
2360 // If BUILD_VECTOR has same base element repeated several times,
2361 // report true.
2363  unsigned NElts = BVN->getNumOperands();
2364  SDValue V0 = BVN->getOperand(0);
2365 
2366  for (unsigned i = 1, e = NElts; i != e; ++i) {
2367  if (BVN->getOperand(i) != V0)
2368  return false;
2369  }
2370  return true;
2371 }
2372 
2373 // Lower a vector shift. Try to convert
2374 // <VT> = SHL/SRA/SRL <VT> by <VT> to Hexagon specific
2375 // <VT> = SHL/SRA/SRL <VT> by <IT/i32>.
2376 SDValue
2378  BuildVectorSDNode *BVN = nullptr;
2379  SDValue V1 = Op.getOperand(0);
2380  SDValue V2 = Op.getOperand(1);
2381  SDValue V3;
2382  SDLoc dl(Op);
2383  EVT VT = Op.getValueType();
2384 
2385  if ((BVN = dyn_cast<BuildVectorSDNode>(V1.getNode())) &&
2386  isCommonSplatElement(BVN))
2387  V3 = V2;
2388  else if ((BVN = dyn_cast<BuildVectorSDNode>(V2.getNode())) &&
2389  isCommonSplatElement(BVN))
2390  V3 = V1;
2391  else
2392  return SDValue();
2393 
2394  SDValue CommonSplat = BVN->getOperand(0);
2395  SDValue Result;
2396 
2397  if (VT.getSimpleVT() == MVT::v4i16) {
2398  switch (Op.getOpcode()) {
2399  case ISD::SRA:
2400  Result = DAG.getNode(HexagonISD::VASR, dl, VT, V3, CommonSplat);
2401  break;
2402  case ISD::SHL:
2403  Result = DAG.getNode(HexagonISD::VASL, dl, VT, V3, CommonSplat);
2404  break;
2405  case ISD::SRL:
2406  Result = DAG.getNode(HexagonISD::VLSR, dl, VT, V3, CommonSplat);
2407  break;
2408  default:
2409  return SDValue();
2410  }
2411  } else if (VT.getSimpleVT() == MVT::v2i32) {
2412  switch (Op.getOpcode()) {
2413  case ISD::SRA:
2414  Result = DAG.getNode(HexagonISD::VASR, dl, VT, V3, CommonSplat);
2415  break;
2416  case ISD::SHL:
2417  Result = DAG.getNode(HexagonISD::VASL, dl, VT, V3, CommonSplat);
2418  break;
2419  case ISD::SRL:
2420  Result = DAG.getNode(HexagonISD::VLSR, dl, VT, V3, CommonSplat);
2421  break;
2422  default:
2423  return SDValue();
2424  }
2425  } else {
2426  return SDValue();
2427  }
2428 
2429  return DAG.getNode(ISD::BITCAST, dl, VT, Result);
2430 }
2431 
2432 SDValue
2434  BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode());
2435  SDLoc dl(Op);
2436  EVT VT = Op.getValueType();
2437 
2438  unsigned Size = VT.getSizeInBits();
2439 
2440  // Only handle vectors of 64 bits or shorter.
2441  if (Size > 64)
2442  return SDValue();
2443 
2444  unsigned NElts = BVN->getNumOperands();
2445 
2446  // Try to generate a SPLAT instruction.
2447  if (VT == MVT::v4i8 || VT == MVT::v4i16 || VT == MVT::v2i32) {
2448  APInt APSplatBits, APSplatUndef;
2449  unsigned SplatBitSize;
2450  bool HasAnyUndefs;
2451  if (BVN->isConstantSplat(APSplatBits, APSplatUndef, SplatBitSize,
2452  HasAnyUndefs, 0, false)) {
2453  if (SplatBitSize == VT.getVectorElementType().getSizeInBits()) {
2454  unsigned ZV = APSplatBits.getZExtValue();
2455  assert(SplatBitSize <= 32 && "Can only handle up to i32");
2456  // Sign-extend the splat value from SplatBitSize to 32.
2457  int32_t SV = SplatBitSize < 32
2458  ? int32_t(ZV << (32-SplatBitSize)) >> (32-SplatBitSize)
2459  : int32_t(ZV);
2460  return DAG.getNode(HexagonISD::VSPLAT, dl, VT,
2461  DAG.getConstant(SV, dl, MVT::i32));
2462  }
2463  }
2464  }
2465 
2466  // Try to generate COMBINE to build v2i32 vectors.
2467  if (VT.getSimpleVT() == MVT::v2i32) {
2468  SDValue V0 = BVN->getOperand(0);
2469  SDValue V1 = BVN->getOperand(1);
2470 
2471  if (V0.isUndef())
2472  V0 = DAG.getConstant(0, dl, MVT::i32);
2473  if (V1.isUndef())
2474  V1 = DAG.getConstant(0, dl, MVT::i32);
2475 
2478  // If the element isn't a constant, it is in a register:
2479  // generate a COMBINE Register Register instruction.
2480  if (!C0 || !C1)
2481  return DAG.getNode(HexagonISD::COMBINE, dl, VT, V1, V0);
2482 
2483  // If one of the operands is an 8 bit integer constant, generate
2484  // a COMBINE Immediate Immediate instruction.
2485  if (isInt<8>(C0->getSExtValue()) ||
2486  isInt<8>(C1->getSExtValue()))
2487  return DAG.getNode(HexagonISD::COMBINE, dl, VT, V1, V0);
2488  }
2489 
2490  // Try to generate a S2_packhl to build v2i16 vectors.
2491  if (VT.getSimpleVT() == MVT::v2i16) {
2492  for (unsigned i = 0, e = NElts; i != e; ++i) {
2493  if (BVN->getOperand(i).isUndef())
2494  continue;
2496  // If the element isn't a constant, it is in a register:
2497  // generate a S2_packhl instruction.
2498  if (!Cst) {
2499  SDValue pack = DAG.getNode(HexagonISD::PACKHL, dl, MVT::v4i16,
2500  BVN->getOperand(1), BVN->getOperand(0));
2501 
2502  return DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::v2i16,
2503  pack);
2504  }
2505  }
2506  }
2507 
2508  // In the general case, generate a CONST32 or a CONST64 for constant vectors,
2509  // and insert_vector_elt for all the other cases.
2510  uint64_t Res = 0;
2511  unsigned EltSize = Size / NElts;
2512  SDValue ConstVal;
2513  uint64_t Mask = ~uint64_t(0ULL) >> (64 - EltSize);
2514  bool HasNonConstantElements = false;
2515 
2516  for (unsigned i = 0, e = NElts; i != e; ++i) {
2517  // LLVM's BUILD_VECTOR operands are in Little Endian mode, whereas Hexagon's
2518  // combine, const64, etc. are Big Endian.
2519  unsigned OpIdx = NElts - i - 1;
2520  SDValue Operand = BVN->getOperand(OpIdx);
2521  if (Operand.isUndef())
2522  continue;
2523 
2524  int64_t Val = 0;
2525  if (ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(Operand))
2526  Val = Cst->getSExtValue();
2527  else
2528  HasNonConstantElements = true;
2529 
2530  Val &= Mask;
2531  Res = (Res << EltSize) | Val;
2532  }
2533 
2534  if (Size > 64)
2535  return SDValue();
2536 
2537  if (Size == 64)
2538  ConstVal = DAG.getConstant(Res, dl, MVT::i64);
2539  else
2540  ConstVal = DAG.getConstant(Res, dl, MVT::i32);
2541 
2542  // When there are non constant operands, add them with INSERT_VECTOR_ELT to
2543  // ConstVal, the constant part of the vector.
2544  if (HasNonConstantElements) {
2545  EVT EltVT = VT.getVectorElementType();
2546  SDValue Width = DAG.getConstant(EltVT.getSizeInBits(), dl, MVT::i64);
2547  SDValue Shifted = DAG.getNode(ISD::SHL, dl, MVT::i64, Width,
2548  DAG.getConstant(32, dl, MVT::i64));
2549 
2550  for (unsigned i = 0, e = NElts; i != e; ++i) {
2551  // LLVM's BUILD_VECTOR operands are in Little Endian mode, whereas Hexagon
2552  // is Big Endian.
2553  unsigned OpIdx = NElts - i - 1;
2554  SDValue Operand = BVN->getOperand(OpIdx);
2555  if (isa<ConstantSDNode>(Operand))
2556  // This operand is already in ConstVal.
2557  continue;
2558 
2559  if (VT.getSizeInBits() == 64 &&
2560  Operand.getValueSizeInBits() == 32) {
2561  SDValue C = DAG.getConstant(0, dl, MVT::i32);
2562  Operand = DAG.getNode(HexagonISD::COMBINE, dl, VT, C, Operand);
2563  }
2564 
2565  SDValue Idx = DAG.getConstant(OpIdx, dl, MVT::i64);
2566  SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i64, Idx, Width);
2567  SDValue Combined = DAG.getNode(ISD::OR, dl, MVT::i64, Shifted, Offset);
2568  const SDValue Ops[] = {ConstVal, Operand, Combined};
2569 
2570  if (VT.getSizeInBits() == 32)
2571  ConstVal = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i32, Ops);
2572  else
2573  ConstVal = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i64, Ops);
2574  }
2575  }
2576 
2577  return DAG.getNode(ISD::BITCAST, dl, VT, ConstVal);
2578 }
2579 
2580 SDValue
2582  SelectionDAG &DAG) const {
2583  SDLoc dl(Op);
2584  bool UseHVX = Subtarget.useHVXOps();
2585  EVT VT = Op.getValueType();
2586  unsigned NElts = Op.getNumOperands();
2587  SDValue Vec0 = Op.getOperand(0);
2588  EVT VecVT = Vec0.getValueType();
2589  unsigned Width = VecVT.getSizeInBits();
2590 
2591  if (NElts == 2) {
2592  MVT ST = VecVT.getSimpleVT();
2593  // We are trying to concat two v2i16 to a single v4i16, or two v4i8
2594  // into a single v8i8.
2595  if (ST == MVT::v2i16 || ST == MVT::v4i8)
2596  return DAG.getNode(HexagonISD::COMBINE, dl, VT, Op.getOperand(1), Vec0);
2597 
2598  if (UseHVX) {
2599  assert((Width == 64*8 && Subtarget.useHVXSglOps()) ||
2600  (Width == 128*8 && Subtarget.useHVXDblOps()));
2601  SDValue Vec1 = Op.getOperand(1);
2602  MVT OpTy = Subtarget.useHVXSglOps() ? MVT::v16i32 : MVT::v32i32;
2603  MVT ReTy = Subtarget.useHVXSglOps() ? MVT::v32i32 : MVT::v64i32;
2604  SDValue B0 = DAG.getNode(ISD::BITCAST, dl, OpTy, Vec0);
2605  SDValue B1 = DAG.getNode(ISD::BITCAST, dl, OpTy, Vec1);
2606  SDValue VC = DAG.getNode(HexagonISD::VCOMBINE, dl, ReTy, B1, B0);
2607  return DAG.getNode(ISD::BITCAST, dl, VT, VC);
2608  }
2609  }
2610 
2611  if (VT.getSizeInBits() != 32 && VT.getSizeInBits() != 64)
2612  return SDValue();
2613 
2614  SDValue C0 = DAG.getConstant(0, dl, MVT::i64);
2615  SDValue C32 = DAG.getConstant(32, dl, MVT::i64);
2616  SDValue W = DAG.getConstant(Width, dl, MVT::i64);
2617  // Create the "width" part of the argument to insert_rp/insertp_rp.
2618  SDValue S = DAG.getNode(ISD::SHL, dl, MVT::i64, W, C32);
2619  SDValue V = C0;
2620 
2621  for (unsigned i = 0, e = NElts; i != e; ++i) {
2622  unsigned N = NElts-i-1;
2623  SDValue OpN = Op.getOperand(N);
2624 
2625  if (VT.getSizeInBits() == 64 && OpN.getValueSizeInBits() == 32) {
2626  SDValue C = DAG.getConstant(0, dl, MVT::i32);
2627  OpN = DAG.getNode(HexagonISD::COMBINE, dl, VT, C, OpN);
2628  }
2629  SDValue Idx = DAG.getConstant(N, dl, MVT::i64);
2630  SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i64, Idx, W);
2631  SDValue Or = DAG.getNode(ISD::OR, dl, MVT::i64, S, Offset);
2632  if (VT.getSizeInBits() == 32)
2633  V = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i32, {V, OpN, Or});
2634  else if (VT.getSizeInBits() == 64)
2635  V = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i64, {V, OpN, Or});
2636  else
2637  return SDValue();
2638  }
2639 
2640  return DAG.getNode(ISD::BITCAST, dl, VT, V);
2641 }
2642 
2643 SDValue
2644 HexagonTargetLowering::LowerEXTRACT_SUBVECTOR_HVX(SDValue Op,
2645  SelectionDAG &DAG) const {
2646  EVT VT = Op.getOperand(0).getValueType();
2647  SDLoc dl(Op);
2648  bool UseHVX = Subtarget.useHVXOps();
2649  bool UseHVXSgl = Subtarget.useHVXSglOps();
2650  // Just in case...
2651 
2652  if (!VT.isVector() || !UseHVX)
2653  return SDValue();
2654 
2655  EVT ResVT = Op.getValueType();
2656  unsigned ResSize = ResVT.getSizeInBits();
2657  unsigned VectorSizeInBits = UseHVXSgl ? (64 * 8) : (128 * 8);
2658  unsigned OpSize = VT.getSizeInBits();
2659 
2660  // We deal only with cases where the result is the vector size
2661  // and the vector operand is a double register.
2662  if (!(ResVT.isByteSized() && ResSize == VectorSizeInBits) ||
2663  !(VT.isByteSized() && OpSize == 2 * VectorSizeInBits))
2664  return SDValue();
2665 
2667  if (!Cst)
2668  return SDValue();
2669  unsigned Val = Cst->getZExtValue();
2670 
2671  // These two will get lowered to an appropriate EXTRACT_SUBREG in ISel.
2672  if (Val == 0) {
2673  SDValue Vec = Op.getOperand(0);
2674  return DAG.getTargetExtractSubreg(Hexagon::vsub_lo, dl, ResVT, Vec);
2675  }
2676 
2677  if (ResVT.getVectorNumElements() == Val) {
2678  SDValue Vec = Op.getOperand(0);
2679  return DAG.getTargetExtractSubreg(Hexagon::vsub_hi, dl, ResVT, Vec);
2680  }
2681 
2682  return SDValue();
2683 }
2684 
2685 SDValue
2687  SelectionDAG &DAG) const {
2688  // If we are dealing with EXTRACT_SUBVECTOR on a HVX type, we may
2689  // be able to simplify it to an EXTRACT_SUBREG.
2690  if (Op.getOpcode() == ISD::EXTRACT_SUBVECTOR && Subtarget.useHVXOps() &&
2692  return LowerEXTRACT_SUBVECTOR_HVX(Op, DAG);
2693 
2694  EVT VT = Op.getValueType();
2695  int VTN = VT.isVector() ? VT.getVectorNumElements() : 1;
2696  SDLoc dl(Op);
2697  SDValue Idx = Op.getOperand(1);
2698  SDValue Vec = Op.getOperand(0);
2699  EVT VecVT = Vec.getValueType();
2700  EVT EltVT = VecVT.getVectorElementType();
2701  int EltSize = EltVT.getSizeInBits();
2703  EltSize : VTN * EltSize, dl, MVT::i64);
2704 
2705  // Constant element number.
2706  if (ConstantSDNode *CI = dyn_cast<ConstantSDNode>(Idx)) {
2707  uint64_t X = CI->getZExtValue();
2708  SDValue Offset = DAG.getConstant(X * EltSize, dl, MVT::i32);
2709  const SDValue Ops[] = {Vec, Width, Offset};
2710 
2711  ConstantSDNode *CW = dyn_cast<ConstantSDNode>(Width);
2712  assert(CW && "Non constant width in LowerEXTRACT_VECTOR");
2713 
2714  SDValue N;
2715  MVT SVT = VecVT.getSimpleVT();
2716  uint64_t W = CW->getZExtValue();
2717 
2718  if (W == 32) {
2719  // Translate this node into EXTRACT_SUBREG.
2720  unsigned Subreg = (X == 0) ? Hexagon::isub_lo : 0;
2721 
2722  if (X == 0)
2723  Subreg = Hexagon::isub_lo;
2724  else if (SVT == MVT::v2i32 && X == 1)
2725  Subreg = Hexagon::isub_hi;
2726  else if (SVT == MVT::v4i16 && X == 2)
2727  Subreg = Hexagon::isub_hi;
2728  else if (SVT == MVT::v8i8 && X == 4)
2729  Subreg = Hexagon::isub_hi;
2730  else
2731  llvm_unreachable("Bad offset");
2732  N = DAG.getTargetExtractSubreg(Subreg, dl, MVT::i32, Vec);
2733 
2734  } else if (SVT.getSizeInBits() == 32) {
2735  N = DAG.getNode(HexagonISD::EXTRACTU, dl, MVT::i32, Ops);
2736  } else if (SVT.getSizeInBits() == 64) {
2737  N = DAG.getNode(HexagonISD::EXTRACTU, dl, MVT::i64, Ops);
2738  if (VT.getSizeInBits() == 32)
2739  N = DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::i32, N);
2740  } else
2741  return SDValue();
2742 
2743  return DAG.getNode(ISD::BITCAST, dl, VT, N);
2744  }
2745 
2746  // Variable element number.
2747  SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i32, Idx,
2748  DAG.getConstant(EltSize, dl, MVT::i32));
2749  SDValue Shifted = DAG.getNode(ISD::SHL, dl, MVT::i64, Width,
2750  DAG.getConstant(32, dl, MVT::i64));
2751  SDValue Combined = DAG.getNode(ISD::OR, dl, MVT::i64, Shifted, Offset);
2752 
2753  const SDValue Ops[] = {Vec, Combined};
2754 
2755  SDValue N;
2756  if (VecVT.getSizeInBits() == 32) {
2757  N = DAG.getNode(HexagonISD::EXTRACTURP, dl, MVT::i32, Ops);
2758  } else {
2759  N = DAG.getNode(HexagonISD::EXTRACTURP, dl, MVT::i64, Ops);
2760  if (VT.getSizeInBits() == 32)
2761  N = DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::i32, N);
2762  }
2763  return DAG.getNode(ISD::BITCAST, dl, VT, N);
2764 }
2765 
2766 SDValue
2768  SelectionDAG &DAG) const {
2769  EVT VT = Op.getValueType();
2770  int VTN = VT.isVector() ? VT.getVectorNumElements() : 1;
2771  SDLoc dl(Op);
2772  SDValue Vec = Op.getOperand(0);
2773  SDValue Val = Op.getOperand(1);
2774  SDValue Idx = Op.getOperand(2);
2775  EVT VecVT = Vec.getValueType();
2776  EVT EltVT = VecVT.getVectorElementType();
2777  int EltSize = EltVT.getSizeInBits();
2778  SDValue Width = DAG.getConstant(Op.getOpcode() == ISD::INSERT_VECTOR_ELT ?
2779  EltSize : VTN * EltSize, dl, MVT::i64);
2780 
2781  if (ConstantSDNode *C = cast<ConstantSDNode>(Idx)) {
2782  SDValue Offset = DAG.getConstant(C->getSExtValue() * EltSize, dl, MVT::i32);
2783  const SDValue Ops[] = {Vec, Val, Width, Offset};
2784 
2785  SDValue N;
2786  if (VT.getSizeInBits() == 32)
2787  N = DAG.getNode(HexagonISD::INSERT, dl, MVT::i32, Ops);
2788  else if (VT.getSizeInBits() == 64)
2789  N = DAG.getNode(HexagonISD::INSERT, dl, MVT::i64, Ops);
2790  else
2791  return SDValue();
2792 
2793  return DAG.getNode(ISD::BITCAST, dl, VT, N);
2794  }
2795 
2796  // Variable element number.
2797  SDValue Offset = DAG.getNode(ISD::MUL, dl, MVT::i32, Idx,
2798  DAG.getConstant(EltSize, dl, MVT::i32));
2799  SDValue Shifted = DAG.getNode(ISD::SHL, dl, MVT::i64, Width,
2800  DAG.getConstant(32, dl, MVT::i64));
2801  SDValue Combined = DAG.getNode(ISD::OR, dl, MVT::i64, Shifted, Offset);
2802 
2803  if (VT.getSizeInBits() == 64 && Val.getValueSizeInBits() == 32) {
2804  SDValue C = DAG.getConstant(0, dl, MVT::i32);
2805  Val = DAG.getNode(HexagonISD::COMBINE, dl, VT, C, Val);
2806  }
2807 
2808  const SDValue Ops[] = {Vec, Val, Combined};
2809 
2810  SDValue N;
2811  if (VT.getSizeInBits() == 32)
2812  N = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i32, Ops);
2813  else if (VT.getSizeInBits() == 64)
2814  N = DAG.getNode(HexagonISD::INSERTRP, dl, MVT::i64, Ops);
2815  else
2816  return SDValue();
2817 
2818  return DAG.getNode(ISD::BITCAST, dl, VT, N);
2819 }
2820 
2821 bool
2823  // Assuming the caller does not have either a signext or zeroext modifier, and
2824  // only one value is accepted, any reasonable truncation is allowed.
2825  if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy())
2826  return false;
2827 
2828  // FIXME: in principle up to 64-bit could be made safe, but it would be very
2829  // fragile at the moment: any support for multiple value returns would be
2830  // liable to disallow tail calls involving i64 -> iN truncation in many cases.
2831  return Ty1->getPrimitiveSizeInBits() <= 32;
2832 }
2833 
2834 SDValue
2836  SDValue Chain = Op.getOperand(0);
2837  SDValue Offset = Op.getOperand(1);
2838  SDValue Handler = Op.getOperand(2);
2839  SDLoc dl(Op);
2840  auto PtrVT = getPointerTy(DAG.getDataLayout());
2841 
2842  // Mark function as containing a call to EH_RETURN.
2843  HexagonMachineFunctionInfo *FuncInfo =
2845  FuncInfo->setHasEHReturn();
2846 
2847  unsigned OffsetReg = Hexagon::R28;
2848 
2849  SDValue StoreAddr =
2850  DAG.getNode(ISD::ADD, dl, PtrVT, DAG.getRegister(Hexagon::R30, PtrVT),
2851  DAG.getIntPtrConstant(4, dl));
2852  Chain = DAG.getStore(Chain, dl, Handler, StoreAddr, MachinePointerInfo());
2853  Chain = DAG.getCopyToReg(Chain, dl, OffsetReg, Offset);
2854 
2855  // Not needed we already use it as explict input to EH_RETURN.
2856  // MF.getRegInfo().addLiveOut(OffsetReg);
2857 
2858  return DAG.getNode(HexagonISD::EH_RETURN, dl, MVT::Other, Chain);
2859 }
2860 
2861 SDValue
2863  unsigned Opc = Op.getOpcode();
2864  switch (Opc) {
2865  default:
2866 #ifndef NDEBUG
2867  Op.getNode()->dumpr(&DAG);
2868  if (Opc > HexagonISD::OP_BEGIN && Opc < HexagonISD::OP_END)
2869  errs() << "Check for a non-legal type in this operation\n";
2870 #endif
2871  llvm_unreachable("Should not custom lower this!");
2872  case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG);
2873  case ISD::INSERT_SUBVECTOR: return LowerINSERT_VECTOR(Op, DAG);
2874  case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR(Op, DAG);
2875  case ISD::EXTRACT_SUBVECTOR: return LowerEXTRACT_VECTOR(Op, DAG);
2876  case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR(Op, DAG);
2877  case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG);
2878  case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG);
2879  case ISD::SRA:
2880  case ISD::SHL:
2881  case ISD::SRL: return LowerVECTOR_SHIFT(Op, DAG);
2882  case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
2883  case ISD::JumpTable: return LowerJumpTable(Op, DAG);
2884  case ISD::EH_RETURN: return LowerEH_RETURN(Op, DAG);
2885  // Frame & Return address. Currently unimplemented.
2886  case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG);
2887  case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG);
2888  case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG);
2889  case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG);
2890  case ISD::GlobalAddress: return LowerGLOBALADDRESS(Op, DAG);
2891  case ISD::BlockAddress: return LowerBlockAddress(Op, DAG);
2892  case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG);
2893  case ISD::VASTART: return LowerVASTART(Op, DAG);
2894  case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG);
2895  case ISD::SETCC: return LowerSETCC(Op, DAG);
2896  case ISD::VSELECT: return LowerVSELECT(Op, DAG);
2897  case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG);
2898  case ISD::INTRINSIC_VOID: return LowerINTRINSIC_VOID(Op, DAG);
2899  case ISD::INLINEASM: return LowerINLINEASM(Op, DAG);
2900  case ISD::PREFETCH: return LowerPREFETCH(Op, DAG);
2901  case ISD::READCYCLECOUNTER: return LowerREADCYCLECOUNTER(Op, DAG);
2902  }
2903 }
2904 
2905 /// Returns relocation base for the given PIC jumptable.
2906 SDValue
2908  SelectionDAG &DAG) const {
2909  int Idx = cast<JumpTableSDNode>(Table)->getIndex();
2910  EVT VT = Table.getValueType();
2912  return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Table), VT, T);
2913 }
2914 
2915 //===----------------------------------------------------------------------===//
2916 // Inline Assembly Support
2917 //===----------------------------------------------------------------------===//
2918 
2921  if (Constraint.size() == 1) {
2922  switch (Constraint[0]) {
2923  case 'q':
2924  case 'v':
2925  if (Subtarget.useHVXOps())
2926  return C_Register;
2927  break;
2928  }
2929  }
2930  return TargetLowering::getConstraintType(Constraint);
2931 }
2932 
2933 std::pair<unsigned, const TargetRegisterClass*>
2935  const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const {
2936  bool UseHVX = Subtarget.useHVXOps(), UseHVXDbl = Subtarget.useHVXDblOps();
2937 
2938  if (Constraint.size() == 1) {
2939  switch (Constraint[0]) {
2940  case 'r': // R0-R31
2941  switch (VT.SimpleTy) {
2942  default:
2943  llvm_unreachable("getRegForInlineAsmConstraint Unhandled data type");
2944  case MVT::i1:
2945  case MVT::i8:
2946  case MVT::i16:
2947  case MVT::i32:
2948  case MVT::f32:
2949  return std::make_pair(0U, &Hexagon::IntRegsRegClass);
2950  case MVT::i64:
2951  case MVT::f64:
2952  return std::make_pair(0U, &Hexagon::DoubleRegsRegClass);
2953  }
2954  case 'q': // q0-q3
2955  switch (VT.getSizeInBits()) {
2956  default:
2957  llvm_unreachable("getRegForInlineAsmConstraint Unhandled vector size");
2958  case 512:
2959  return std::make_pair(0U, &Hexagon::VecPredRegsRegClass);
2960  case 1024:
2961  return std::make_pair(0U, &Hexagon::VecPredRegs128BRegClass);
2962  }
2963  case 'v': // V0-V31
2964  switch (VT.getSizeInBits()) {
2965  default:
2966  llvm_unreachable("getRegForInlineAsmConstraint Unhandled vector size");
2967  case 512:
2968  return std::make_pair(0U, &Hexagon::VectorRegsRegClass);
2969  case 1024:
2970  if (Subtarget.hasV60TOps() && UseHVX && UseHVXDbl)
2971  return std::make_pair(0U, &Hexagon::VectorRegs128BRegClass);
2972  return std::make_pair(0U, &Hexagon::VecDblRegsRegClass);
2973  case 2048:
2974  return std::make_pair(0U, &Hexagon::VecDblRegs128BRegClass);
2975  }
2976 
2977  default:
2978  llvm_unreachable("Unknown asm register class");
2979  }
2980  }
2981 
2982  return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT);
2983 }
2984 
2985 /// isFPImmLegal - Returns true if the target can instruction select the
2986 /// specified FP immediate natively. If false, the legalizer will
2987 /// materialize the FP immediate as a load from a constant pool.
2989  return Subtarget.hasV5TOps();
2990 }
2991 
2992 /// isLegalAddressingMode - Return true if the addressing mode represented by
2993 /// AM is legal for this target, for a load/store of the specified type.
2995  const AddrMode &AM, Type *Ty,
2996  unsigned AS) const {
2997  if (Ty->isSized()) {
2998  // When LSR detects uses of the same base address to access different
2999  // types (e.g. unions), it will assume a conservative type for these
3000  // uses:
3001  // LSR Use: Kind=Address of void in addrspace(4294967295), ...
3002  // The type Ty passed here would then be "void". Skip the alignment
3003  // checks, but do not return false right away, since that confuses
3004  // LSR into crashing.
3005  unsigned A = DL.getABITypeAlignment(Ty);
3006  // The base offset must be a multiple of the alignment.
3007  if ((AM.BaseOffs % A) != 0)
3008  return false;
3009  // The shifted offset must fit in 11 bits.
3010  if (!isInt<11>(AM.BaseOffs >> Log2_32(A)))
3011  return false;
3012  }
3013 
3014  // No global is ever allowed as a base.
3015  if (AM.BaseGV)
3016  return false;
3017 
3018  int Scale = AM.Scale;
3019  if (Scale < 0)
3020  Scale = -Scale;
3021  switch (Scale) {
3022  case 0: // No scale reg, "r+i", "r", or just "i".
3023  break;
3024  default: // No scaled addressing mode.
3025  return false;
3026  }
3027  return true;
3028 }
3029 
3030 /// Return true if folding a constant offset with the given GlobalAddress is
3031 /// legal. It is frequently not legal in PIC relocation models.
3033  const {
3034  return HTM.getRelocationModel() == Reloc::Static;
3035 }
3036 
3037 /// isLegalICmpImmediate - Return true if the specified immediate is legal
3038 /// icmp immediate, that is the target has icmp instructions which can compare
3039 /// a register against the immediate without having to materialize the
3040 /// immediate into a register.
3042  return Imm >= -512 && Imm <= 511;
3043 }
3044 
3045 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
3046 /// for tail call optimization. Targets which want to do tail call
3047 /// optimization should implement this function.
3049  SDValue Callee,
3050  CallingConv::ID CalleeCC,
3051  bool isVarArg,
3052  bool isCalleeStructRet,
3053  bool isCallerStructRet,
3054  const SmallVectorImpl<ISD::OutputArg> &Outs,
3055  const SmallVectorImpl<SDValue> &OutVals,
3057  SelectionDAG& DAG) const {
3058  const Function *CallerF = DAG.getMachineFunction().getFunction();
3059  CallingConv::ID CallerCC = CallerF->getCallingConv();
3060  bool CCMatch = CallerCC == CalleeCC;
3061 
3062  // ***************************************************************************
3063  // Look for obvious safe cases to perform tail call optimization that do not
3064  // require ABI changes.
3065  // ***************************************************************************
3066 
3067  // If this is a tail call via a function pointer, then don't do it!
3068  if (!isa<GlobalAddressSDNode>(Callee) &&
3069  !isa<ExternalSymbolSDNode>(Callee)) {
3070  return false;
3071  }
3072 
3073  // Do not optimize if the calling conventions do not match and the conventions
3074  // used are not C or Fast.
3075  if (!CCMatch) {
3076  bool R = (CallerCC == CallingConv::C || CallerCC == CallingConv::Fast);
3077  bool E = (CalleeCC == CallingConv::C || CalleeCC == CallingConv::Fast);
3078  // If R & E, then ok.
3079  if (!R || !E)
3080  return false;
3081  }
3082 
3083  // Do not tail call optimize vararg calls.
3084  if (isVarArg)
3085  return false;
3086 
3087  // Also avoid tail call optimization if either caller or callee uses struct
3088  // return semantics.
3089  if (isCalleeStructRet || isCallerStructRet)
3090  return false;
3091 
3092  // In addition to the cases above, we also disable Tail Call Optimization if
3093  // the calling convention code that at least one outgoing argument needs to
3094  // go on the stack. We cannot check that here because at this point that
3095  // information is not available.
3096  return true;
3097 }
3098 
3099 /// Returns the target specific optimal type for load and store operations as
3100 /// a result of memset, memcpy, and memmove lowering.
3101 ///
3102 /// If DstAlign is zero that means it's safe to destination alignment can
3103 /// satisfy any constraint. Similarly if SrcAlign is zero it means there isn't
3104 /// a need to check it against alignment requirement, probably because the
3105 /// source does not need to be loaded. If 'IsMemset' is true, that means it's
3106 /// expanding a memset. If 'ZeroMemset' is true, that means it's a memset of
3107 /// zero. 'MemcpyStrSrc' indicates whether the memcpy source is constant so it
3108 /// does not need to be loaded. It returns EVT::Other if the type should be
3109 /// determined using generic target-independent logic.
3111  unsigned DstAlign, unsigned SrcAlign, bool IsMemset, bool ZeroMemset,
3112  bool MemcpyStrSrc, MachineFunction &MF) const {
3113 
3114  auto Aligned = [](unsigned GivenA, unsigned MinA) -> bool {
3115  return (GivenA % MinA) == 0;
3116  };
3117 
3118  if (Size >= 8 && Aligned(DstAlign, 8) && (IsMemset || Aligned(SrcAlign, 8)))
3119  return MVT::i64;
3120  if (Size >= 4 && Aligned(DstAlign, 4) && (IsMemset || Aligned(SrcAlign, 4)))
3121  return MVT::i32;
3122  if (Size >= 2 && Aligned(DstAlign, 2) && (IsMemset || Aligned(SrcAlign, 2)))
3123  return MVT::i16;
3124 
3125  return MVT::Other;
3126 }
3127 
3129  unsigned AS, unsigned Align, bool *Fast) const {
3130  if (Fast)
3131  *Fast = false;
3132 
3133  switch (VT.getSimpleVT().SimpleTy) {
3134  default:
3135  return false;
3136  case MVT::v64i8:
3137  case MVT::v128i8:
3138  case MVT::v256i8:
3139  case MVT::v32i16:
3140  case MVT::v64i16:
3141  case MVT::v128i16:
3142  case MVT::v16i32:
3143  case MVT::v32i32:
3144  case MVT::v64i32:
3145  case MVT::v8i64:
3146  case MVT::v16i64:
3147  case MVT::v32i64:
3148  return true;
3149  }
3150  return false;
3151 }
3152 
3153 std::pair<const TargetRegisterClass*, uint8_t>
3155  MVT VT) const {
3156  const TargetRegisterClass *RRC = nullptr;
3157 
3158  uint8_t Cost = 1;
3159  switch (VT.SimpleTy) {
3160  default:
3162  case MVT::v64i8:
3163  case MVT::v32i16:
3164  case MVT::v16i32:
3165  case MVT::v8i64:
3166  RRC = &Hexagon::VectorRegsRegClass;
3167  break;
3168  case MVT::v128i8:
3169  case MVT::v64i16:
3170  case MVT::v32i32:
3171  case MVT::v16i64:
3172  if (Subtarget.hasV60TOps() && Subtarget.useHVXOps() &&
3173  Subtarget.useHVXDblOps())
3174  RRC = &Hexagon::VectorRegs128BRegClass;
3175  else
3176  RRC = &Hexagon::VecDblRegsRegClass;
3177  break;
3178  case MVT::v256i8:
3179  case MVT::v128i16:
3180  case MVT::v64i32:
3181  case MVT::v32i64:
3182  RRC = &Hexagon::VecDblRegs128BRegClass;
3183  break;
3184  }
3185  return std::make_pair(RRC, Cost);
3186 }
3187 
3189  AtomicOrdering Ord) const {
3190  BasicBlock *BB = Builder.GetInsertBlock();
3191  Module *M = BB->getParent()->getParent();
3192  Type *Ty = cast<PointerType>(Addr->getType())->getElementType();
3193  unsigned SZ = Ty->getPrimitiveSizeInBits();
3194  assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic loads supported");
3195  Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_L2_loadw_locked
3196  : Intrinsic::hexagon_L4_loadd_locked;
3197  Value *Fn = Intrinsic::getDeclaration(M, IntID);
3198  return Builder.CreateCall(Fn, Addr, "larx");
3199 }
3200 
3201 /// Perform a store-conditional operation to Addr. Return the status of the
3202 /// store. This should be 0 if the store succeeded, non-zero otherwise.
3204  Value *Val, Value *Addr, AtomicOrdering Ord) const {
3205  BasicBlock *BB = Builder.GetInsertBlock();
3206  Module *M = BB->getParent()->getParent();
3207  Type *Ty = Val->getType();
3208  unsigned SZ = Ty->getPrimitiveSizeInBits();
3209  assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic stores supported");
3210  Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_S2_storew_locked
3211  : Intrinsic::hexagon_S4_stored_locked;
3212  Value *Fn = Intrinsic::getDeclaration(M, IntID);
3213  Value *Call = Builder.CreateCall(Fn, {Addr, Val}, "stcx");
3214  Value *Cmp = Builder.CreateICmpEQ(Call, Builder.getInt32(0), "");
3215  Value *Ext = Builder.CreateZExt(Cmp, Type::getInt32Ty(M->getContext()));
3216  return Ext;
3217 }
3218 
3221  // Do not expand loads and stores that don't exceed 64 bits.
3222  return LI->getType()->getPrimitiveSizeInBits() > 64
3225 }
3226 
3228  // Do not expand loads and stores that don't exceed 64 bits.
3229  return SI->getValueOperand()->getType()->getPrimitiveSizeInBits() > 64;
3230 }
3231 
3233  AtomicCmpXchgInst *AI) const {
3234  const DataLayout &DL = AI->getModule()->getDataLayout();
3235  unsigned Size = DL.getTypeStoreSize(AI->getCompareOperand()->getType());
3236  return Size >= 4 && Size <= 8;
3237 }
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
void setFrameAddressIsTaken(bool T)
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:544
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:511
bool isFPImmLegal(const APFloat &Imm, EVT VT) const override
isFPImmLegal - Returns true if the target can instruction select the specified FP immediate natively...
Value * getValueOperand()
Definition: Instructions.h:395
void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeCallResult - Analyze the return values of a call, incorporating info about the passed values i...
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Definition: ISDOpcodes.h:568
SDValue getValue(unsigned R) const
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg If BaseGV is null...
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified load with extension does not work with the specified type and indicate wh...
MVT getValVT() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
SDValue LowerToTLSInitialExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG) const
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
#define R4(n)
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LLVMContext * getContext() const
Definition: SelectionDAG.h:381
LLVMContext & Context
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1542
void setMinimumJumpTableEntries(unsigned Val)
Indicate the minimum number of blocks to generate jump tables.
SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, SDValue InGlue, const SDLoc &DL)
Return a new CALLSEQ_END node, which always must have a glue result (to ensure it's not CSE'd)...
Definition: SelectionDAG.h:800
unsigned getFrameRegister(const MachineFunction &MF) const override
bool isLegalICmpImmediate(int64_t Imm) const override
isLegalICmpImmediate - Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructions which can compare a register against the immediate without having to materialize the immediate into a register.
ConstraintType getConstraintType(StringRef Constraint) const override
Given a constraint, return the type of constraint it is for this target.
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an vector value) starting with the ...
Definition: ISDOpcodes.h:332
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
BR_CC - Conditional branch.
Definition: ISDOpcodes.h:616
LocInfo getLocInfo() const
static MVT getVectorVT(MVT VT, unsigned NumElements)
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition: ISDOpcodes.h:341
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
const TargetMachine & getTargetMachine() const
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
Definition: Instructions.h:514
HexagonTargetObjectFile * getObjFileLowering() const override
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, SDValue &Base, SDValue &Offset, ISD::MemIndexedMode &AM, SelectionDAG &DAG) const override
getPostIndexedAddressParts - returns true by value, base pointer and offset pointer and addressing mo...
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
std::pair< const TargetRegisterClass *, uint8_t > findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT) const override
Return the largest legal super-reg register class of the register class for the specified type and it...
Carry-setting nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:222
static cl::opt< bool > EmitJumpTables("hexagon-emit-jump-tables", cl::init(true), cl::Hidden, cl::desc("Control jump table emission on Hexagon target"))
bool isFMAFasterThanFMulAndFAdd(EVT) const override
Return true if an FMA operation is faster than a pair of mul and add instructions.
unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
void AnalyzeFormalArguments(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeFormalArguments - Analyze an array of argument values, incorporating info about the formals in...
DataLayout DL
Y = RRC X, rotate right via carry.
const TargetSubtargetInfo & getSubtarget() const
Definition: SelectionDAG.h:378
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain...
Definition: ISDOpcodes.h:659
This class represents a function call, abstracting a target machine's calling convention.
SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG) const
const GlobalValue * getGlobal() const
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition: ISDOpcodes.h:250
SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
bool verifyReturnAddressArgumentIsConstant(SDValue Op, SelectionDAG &DAG) const
constexpr bool isInt< 8 >(int64_t x)
Definition: MathExtras.h:295
unsigned getSizeInBits() const
unsigned getByValSize() const
static bool RetCC_Hexagon64(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
Hexagon target-specific information for each MachineFunction.
unsigned second
unsigned getNumOperands() const
Return the number of values used by this operation.
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:108
unsigned getNumOperands() const
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
const SDValue & getOperand(unsigned Num) const
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:262
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
An instruction for reading from memory.
Definition: Instructions.h:164
const HexagonFrameLowering * getFrameLowering() const override
virtual bool shouldExpandBuildVectorWithShuffles(EVT, unsigned DefinedValues) const
#define R2(n)
SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned char TargetFlags=0)
SDValue LowerEXTRACT_VECTOR(SDValue Op, SelectionDAG &DAG) const
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
bool CheckReturn(const SmallVectorImpl< ISD::OutputArg > &ArgsFlags, CCAssignFn Fn)
CheckReturn - Analyze the return values of a function, returning true if the return can be performed ...
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
Same for subtraction.
Definition: ISDOpcodes.h:253
SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1 at the ...
Definition: ISDOpcodes.h:327
The address of the GOT.
Definition: ISDOpcodes.h:66
OUTCHAIN = ATOMIC_FENCE(INCHAIN, ordering, scope) This corresponds to the fence instruction.
Definition: ISDOpcodes.h:741
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:403
bool isUnsignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs an unsigned comparison when used with intege...
Definition: ISDOpcodes.h:948
bool isRegLoc() const
This SDNode is used to implement the code generator support for the llvm IR shufflevector instruction...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:186
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
SDValue LowerEXTRACT_SUBVECTOR_HVX(SDValue Op, SelectionDAG &DAG) const
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:209
bool isNegative() const
Determine sign of this APInt.
Definition: APInt.h:357
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations...
Definition: ISDOpcodes.h:432
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:151
bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AS) const override
isLegalAddressingMode - Return true if the addressing mode represented by AM is legal for this target...
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
The address of a basic block.
Definition: Constants.h:813
void setMaxAtomicSizeInBitsSupported(unsigned SizeInBits)
Set the maximum atomic operation size supported by the backend.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Value * emitStoreConditional(IRBuilder<> &Builder, Value *Val, Value *Addr, AtomicOrdering Ord) const override
Perform a store-conditional operation to Addr.
Shift and rotation operations.
Definition: ISDOpcodes.h:378
bool shouldExpandBuildVectorWithShuffles(EVT VT, unsigned DefinedValues) const override
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand)
A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s), MachineInstr opcode, and operands.
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:375
const HexagonRegisterInfo * getRegisterInfo() const override
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
Definition: ISDOpcodes.h:190
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
void addLoc(const CCValAssign &V)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:664
Reg
All possible values of the reg field in the ModR/M byte.
void setCondCodeAction(ISD::CondCode CC, MVT VT, LegalizeAction Action)
Indicate that the specified condition code is or isn't supported on the target and indicate what to d...
SimpleValueType SimpleTy
#define Hexagon_PointerSize
Definition: Hexagon.h:20
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
const GlobalObject * getBaseObject() const
Definition: Globals.cpp:255
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
bool isPositionIndependent() const
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG...
Definition: ISDOpcodes.h:73
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
This file implements a class to represent arbitrary precision integral constant values and operations...
SDValue LowerToTLSLocalExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG) const
INLINEASM - Represents an inline asm block.
Definition: ISDOpcodes.h:633
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
SmallVector< ISD::InputArg, 32 > Ins
AtomicOrdering
Atomic ordering for LLVM's memory model.
STACKSAVE - STACKSAVE has one operand, an input chain.
Definition: ISDOpcodes.h:655
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:265
MachineFunction & getMachineFunction() const
bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef, unsigned &SplatBitSize, bool &HasAnyUndefs, unsigned MinSplatBits=0, bool isBigEndian=false) const
Check if this is a constant splat, and if so, find the smallest element size that splats the vector...
unsigned getLocReg() const
#define F(x, y, z)
Definition: MD5.cpp:55
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose...
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:454
SDValue getRegisterMask(const uint32_t *RegMask)
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
Definition: Function.h:503
#define T
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition: ISDOpcodes.h:397
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:200
static bool CC_Hexagon32(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
SmallVector< ISD::OutputArg, 32 > Outs
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:975
MachineConstantPoolValue * getMachineCPVal() const
An instruction for storing to memory.
Definition: Instructions.h:306
bool mayBeEmittedAsTailCall(const CallInst *CI) const override
Return true if the target may be able emit the call instruction as a tail call.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
Definition: ISDOpcodes.h:909
const APInt & getAPIntValue() const
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1383
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
Definition: ISDOpcodes.h:707
SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
void setMinCmpXchgSizeInBits(unsigned SizeInBits)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override
Return true if a truncation from FromTy to ToTy is permitted when deciding whether a call is in tail ...
bool isSignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs a signed comparison when used with integer o...
Definition: ISDOpcodes.h:942
static cl::opt< int > MinimumJumpTables("minimum-jump-tables", cl::Hidden, cl::ZeroOrMore, cl::init(5), cl::desc("Set minimum jump tables"))
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Definition: ISDOpcodes.h:151
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:376
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset)
Stack pointer relative access.
SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const
This class is used to represent ISD::STORE nodes.
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:497
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
static CCValAssign getReg(unsigned ValNo, MVT ValVT, unsigned RegNo, MVT LocVT, LocInfo HTP)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:121
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
Definition: ISDOpcodes.h:301
SDValue LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG) const
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:262
SDNode * getNode() const
get the SDNode which holds the desired result
unsigned getScalarSizeInBits() const
Definition: ValueTypes.h:298
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:401
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
Definition: ISDOpcodes.h:166
SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const
unsigned const MachineRegisterInfo * MRI
bool isMachineConstantPoolEntry() const
Machine Value Type.
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
const SDValue & getOperand(unsigned i) const
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type...
SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const
Simple binary floating point operators.
Definition: ISDOpcodes.h:259
SDValue GetDynamicTLSAddr(SelectionDAG &DAG, SDValue Chain, GlobalAddressSDNode *GA, SDValue InFlag, EVT PtrVT, unsigned ReturnReg, unsigned char OperandFlags) const
static bool getIndexedAddressParts(SDNode *Ptr, EVT VT, SDValue &Base, SDValue &Offset, bool &IsInc, SelectionDAG &DAG)
bool isOperationLegalOrCustom(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
MVT getLocVT() const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE...
Definition: ISDOpcodes.h:688
static bool CC_Hexagon(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
static cl::opt< int > MaxStoresPerMemmoveOptSizeCL("max-store-memmove-Os", cl::Hidden, cl::ZeroOrMore, cl::init(4), cl::desc("Max #stores to inline memmove"))
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL...
Definition: ISDOpcodes.h:306
const Constant * getConstVal() const
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:231
bool shouldExpandAtomicStoreInIR(StoreInst *SI) const override
Returns true if the given (atomic) store should be expanded by the IR-level AtomicExpand pass into an...
OperandFlags
These are flags set on operands, but should be considered private, all access should go through the M...
Definition: MCInstrDesc.h:41
#define A
Definition: LargeTest.cpp:12
SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize, const SDLoc &DL)
Return a new CALLSEQ_START node, that starts new call frame, in which InSize bytes are set up inside ...
Definition: SelectionDAG.h:788
SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const
bool isTruncateFree(Type *Ty1, Type *Ty2) const override
Return true if it's free to truncate a value of type FromTy to type ToTy.
SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const
static mvt_range fp_valuetypes()
static unsigned getNumOperandRegisters(unsigned Flag)
getNumOperandRegisters - Extract the number of registers field from the inline asm operand flag...
Definition: InlineAsm.h:336
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
unsigned getOpcode() const
static unsigned getKind(unsigned Flags)
Definition: InlineAsm.h:325
SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, SelectionDAG &DAG) const
void setPrefFunctionAlignment(unsigned Align)
Set the target's preferred function alignment.
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition: ISDOpcodes.h:57
static mvt_range vector_valuetypes()
SDValue LowerCallResult(SDValue Chain, SDValue InFlag, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals, const SmallVectorImpl< SDValue > &OutVals, SDValue Callee) const
LowerCallResult - Lower the result values of an ISD::CALL into the appropriate copies out of appropri...
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1546
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
Definition: ISDOpcodes.h:679
SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const
void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
If Opc/OrigVT is specified as being promoted, the promotion code defaults to trying a larger integer/...
unsigned MaxStoresPerMemmove
Specify maximum bytes of store instructions per memmove call.
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:529
SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG) const
Extended Value Type.
Definition: ValueTypes.h:34
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const
This structure contains all information that is necessary for lowering calls.
bool shouldAssumeDSOLocal(const Module &M, const GlobalValue *GV) const
static SDValue CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, ISD::ArgFlagsTy Flags, SelectionDAG &DAG, const SDLoc &dl)
CreateCopyOfByValArgument - Make a copy of an aggregate at address specified by "Src" to address "Dst...
static bool isSExtFree(SDValue N)
This class contains a discriminated union of information about pointers in memory operands...
SDValue getPICJumpTableRelocBase(SDValue Table, SelectionDAG &DAG) const override
Returns relocation base for the given PIC jumptable.
static bool CC_HexagonVector(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands...
unsigned first
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &dl, SelectionDAG &DAG) const override
This hook must be implemented to lower outgoing return values, described by the Outs array...
unsigned getByValAlign() const
bool isShuffleMaskLegal(const SmallVectorImpl< int > &Mask, EVT VT) const override
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations, those with specific masks.
ArrayRef< int > getMask() const
SDValue getTargetConstantPool(const Constant *C, EVT VT, unsigned Align=0, int Offset=0, unsigned char TargetFlags=0)
Definition: SelectionDAG.h:605
SDValue getTargetJumpTable(int JTI, EVT VT, unsigned char TargetFlags=0)
Definition: SelectionDAG.h:599
TokenFactor - This node takes multiple tokens as input and produces a single token result...
Definition: ISDOpcodes.h:50
const char * getTargetNodeName(unsigned Opcode) const override
This method returns the name of a target specific DAG node.
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:680
#define HEXAGON_LRFP_SIZE
Definition: Hexagon.h:27
CCState - This class holds information needed while lowering arguments and return values...
#define E
Definition: LargeTest.cpp:27
void dump() const
Dump this node, for debugging.
SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:313
#define HEXAGON_GOT_SYM_NAME
Definition: Hexagon.h:43
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:209
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:57
static bool isHvxVectorType(MVT ty)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
CCValAssign - Represent assignment of one arg/retval to a location.
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower the incoming (formal) arguments, described by the Ins array...
SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, unsigned Align, bool isVol, bool AlwaysInline, bool isTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo)
const DataFlowGraph & G
Definition: RDFGraph.cpp:206
Byte Swap and Counting operators.
Definition: ISDOpcodes.h:381
MO_PCREL - On a symbol operand, indicates a PC-relative relocation Used for computing a global addres...
const size_t N
bool shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *AI) const override
Returns true if the given atomic cmpxchg should be expanded by the IR-level AtomicExpand pass into a ...
CHAIN = SC CHAIN, Imm128 - System call.
SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:308
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:122
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N)
Definition: SelectionDAG.h:643
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
static mvt_range integer_valuetypes()
C - The default llvm calling convention, compatible with C.
Definition: CallingConv.h:35
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:531
SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const
void setIndexedLoadAction(unsigned IdxMode, MVT VT, LegalizeAction Action)
Indicate that the specified indexed load does or does not work with the specified type and indicate w...
Class for arbitrary precision integers.
Definition: APInt.h:69
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
A "pseudo-class" with methods for operating on BUILD_VECTORs.
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:388
void setMinFunctionAlignment(unsigned Align)
Set the target's minimum function alignment (in log2(bytes))
int64_t getSExtValue() const
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
static StridedLoadKind isStridedLoad(const ArrayRef< int > &Mask)
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
Return the register class that should be used for the specified value type.
void setPrefLoopAlignment(unsigned Align)
Set the target's preferred loop alignment.
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:444
bool isMemLoc() const
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:447
AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const override
Returns how the given (atomic) load should be expanded by the IR-level AtomicExpand pass...
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition: ISDOpcodes.h:286
SDValue LowerVECTOR_SHIFT(SDValue Op, SelectionDAG &DAG) const
static cl::opt< int > MaxStoresPerMemsetCL("max-store-memset", cl::Hidden, cl::ZeroOrMore, cl::init(8), cl::desc("Max #stores to inline memset"))
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
BR_JT - Jumptable branch.
Definition: ISDOpcodes.h:604
static std::vector< std::string > Flags
Definition: FlagsTest.cpp:8
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:361
SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset=0, unsigned char TargetFlags=0)
Definition: SelectionDAG.h:637
SmallVector< SDValue, 32 > OutVals
static cl::opt< bool > EnableHexSDNodeSched("enable-hexagon-sdnode-sched", cl::Hidden, cl::ZeroOrMore, cl::init(false), cl::desc("Enable Hexagon SDNode scheduling"))
void ensureMaxAlignment(unsigned Align)
Make sure the function is at least Align bytes aligned.
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:361
MO_GOT - Indicates a GOT-relative relocation.
bool IsEligibleForTailCallOptimization(SDValue Callee, CallingConv::ID CalleeCC, bool isVarArg, bool isCalleeStructRet, bool isCallerStructRet, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SmallVectorImpl< ISD::InputArg > &Ins, SelectionDAG &DAG) const
IsEligibleForTailCallOptimization - Check whether the call is eligible for tail call optimization...
SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const
bool isUndef() const
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT)
Definition: SelectionDAG.h:669
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:176
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition: ISDOpcodes.h:205
unsigned getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:462
#define C
Definition: LargeTest.cpp:25
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:580
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const
SDValue LowerREADCYCLECOUNTER(SDValue Op, SelectionDAG &DAG) const
static bool RetCC_Hexagon(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:292
virtual std::pair< const TargetRegisterClass *, uint8_t > findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT) const
Return the largest legal super-reg register class of the register class for the specified type and it...
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace, unsigned Align, bool *Fast) const override
Determine if the target supports unaligned memory accesses.
void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeReturn - Analyze the returned values of a return, incorporating info about the result values i...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
static cl::opt< int > MaxStoresPerMemcpyOptSizeCL("max-store-memcpy-Os", cl::Hidden, cl::ZeroOrMore, cl::init(4), cl::desc("Max #stores to inline memcpy"))
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1659
unsigned MaxStoresPerMemmoveOptSize
Maximum number of store instructions that may be substituted for a call to memmove, used for functions with OptSize attribute.
Value * emitLoadLinked(IRBuilder<> &Builder, Value *Addr, AtomicOrdering Ord) const override
Perform a load-linked operation on Addr, returning a "Value *" with the corresponding pointee type...
unsigned MaxStoresPerMemcpyOptSize
Maximum number of store operations that may be substituted for a call to memcpy, used for functions w...
void setStackPointerRegisterToSaveRestore(unsigned R)
If set to a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save and restore.
bool isTailCall() const
static bool CC_Hexagon_VarArg(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:43
static bool CC_Hexagon64(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
void setLibcallName(RTLIB::Libcall Call, const char *Name)
Rename the default libcall routine name for the specified libcall.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
static CCValAssign getMem(unsigned ValNo, MVT ValVT, unsigned Offset, MVT LocVT, LocInfo HTP)
static volatile int Zero
FSINCOS - Compute both fsin and fcos as a single operation.
Definition: ISDOpcodes.h:574
unsigned MaxStoresPerMemcpy
Specify maximum bytes of store instructions per memcpy call.
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override
Return true if folding a constant offset with the given GlobalAddress is legal.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:388
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
Definition: ValueTypes.cpp:311
SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const
EVT getValueType() const
Return the ValueType of the referenced return value.
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 'eh_return' gcc dwarf builtin...
Definition: ISDOpcodes.h:102
TLSModel::Model getTLSModel(const GlobalValue *GV) const
Returns the TLS model which should be used for the given global variable.
SDValue getGLOBAL_OFFSET_TABLE(EVT VT)
Return a GLOBAL_OFFSET_TABLE node. This does not have a useful SDLoc.
Definition: SelectionDAG.h:821
bool isByteSized() const
Return true if the bit size is a multiple of 8.
Definition: ValueTypes.h:212
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
Definition: ISDOpcodes.h:319
static bool RetCC_HexagonVector(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
void setReturnAddressIsTaken(bool s)
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition: ValueTypes.h:126
unsigned getAlignment() const
static cl::opt< int > MaxStoresPerMemcpyCL("max-store-memcpy", cl::Hidden, cl::ZeroOrMore, cl::init(6), cl::desc("Max #stores to inline memcpy"))
MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
void setSchedulingPreference(Sched::Preference Pref)
Specify the target scheduling preference.
aarch64 promote const
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:115
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:545
LLVM Value Representation.
Definition: Value.h:73
FMA - Perform a * b + c with no intermediate rounding step.
Definition: ISDOpcodes.h:276
SDValue getRegister(unsigned Reg, EVT VT)
const HexagonInstrInfo * getInstrInfo() const override
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:81
PREFETCH - This corresponds to a prefetch intrinsic.
Definition: ISDOpcodes.h:736
static bool RetCC_Hexagon32(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.Val alone...
#define DEBUG(X)
Definition: Debug.h:118
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
static bool isCommonSplatElement(BuildVectorSDNode *BVN)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
LowerCall - Functions arguments are copied from virtual regs to (physical regs)/(stack frame)...
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:411
void dumpr() const
Dump (recursively) this node and its use-def subgraph.
unsigned MaxStoresPerMemset
Specify maximum number of store instructions per memset call.
unsigned MaxStoresPerMemsetOptSize
Maximum number of stores operations that may be substituted for the call to memset, used for functions with OptSize attribute.
SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const
bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, LLVMContext &Context) const override
This hook should be implemented to check whether the return values described by the Outs array can fi...
unsigned getLocMemOffset() const
MVT getVectorElementType() const
Conversion operators.
Definition: ISDOpcodes.h:441
SDValue LowerINSERT_VECTOR(SDValue Op, SelectionDAG &DAG) const
int * Ptr
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:434
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:450
static cl::opt< int > MaxStoresPerMemmoveCL("max-store-memmove", cl::Hidden, cl::ZeroOrMore, cl::init(6), cl::desc("Max #stores to inline memmove"))
SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const
static cl::opt< int > MaxStoresPerMemsetOptSizeCL("max-store-memset-Os", cl::Hidden, cl::ZeroOrMore, cl::init(4), cl::desc("Max #stores to inline memset"))
unsigned AllocateReg(unsigned Reg)
AllocateReg - Attempt to allocate one register.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, FLOG, FLOG2, FLOG10, FEXP, FEXP2, FCEIL, FTRUNC, FRINT, FNEARBYINT, FROUND, FFLOOR - Perform various unary floating point operations.
Definition: ISDOpcodes.h:560
static cl::opt< bool > EnableFastMath("ffast-math", cl::Hidden, cl::ZeroOrMore, cl::init(false), cl::desc("Enable Fast Math processing"))
EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign, bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc, MachineFunction &MF) const override
Returns the target specific optimal type for load and store operations as a result of memset...
unsigned AllocateStack(unsigned Size, unsigned Align)
AllocateStack - Allocate a chunk of stack space with the specified size and alignment.
const BasicBlock * getParent() const
Definition: Instruction.h:66
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
Definition: ISDOpcodes.h:349
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:253
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:237
HexagonTargetLowering(const TargetMachine &TM, const HexagonSubtarget &ST)
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned char TargetFlags=0)
Definition: SelectionDAG.h:588
void setIndexedStoreAction(unsigned IdxMode, MVT VT, LegalizeAction Action)
Indicate that the specified indexed store does or does not work with the specified type and indicate ...
uint64_t getZExtValue() const
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
Definition: ISDOpcodes.h:864
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:273
This class is used to represent ISD::LOAD nodes.
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary...
Definition: ISDOpcodes.h:589