LLVM  13.0.0git
LegalizeTypes.h
Go to the documentation of this file.
1 //===-- LegalizeTypes.h - DAG Type Legalizer class definition ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the DAGTypeLegalizer class. This is a private interface
10 // shared between the code that implements the SelectionDAG::LegalizeTypes
11 // method.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_LEGALIZETYPES_H
16 #define LLVM_LIB_CODEGEN_SELECTIONDAG_LEGALIZETYPES_H
17 
18 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/Support/Compiler.h"
22 #include "llvm/Support/Debug.h"
23 
24 namespace llvm {
25 
26 //===----------------------------------------------------------------------===//
27 /// This takes an arbitrary SelectionDAG as input and hacks on it until only
28 /// value types the target machine can handle are left. This involves promoting
29 /// small sizes to large sizes or splitting up large values into small values.
30 ///
32  const TargetLowering &TLI;
33  SelectionDAG &DAG;
34 public:
35  /// This pass uses the NodeId on the SDNodes to hold information about the
36  /// state of the node. The enum has all the values.
37  enum NodeIdFlags {
38  /// All operands have been processed, so this node is ready to be handled.
39  ReadyToProcess = 0,
40 
41  /// This is a new node, not before seen, that was created in the process of
42  /// legalizing some other node.
43  NewNode = -1,
44 
45  /// This node's ID needs to be set to the number of its unprocessed
46  /// operands.
47  Unanalyzed = -2,
48 
49  /// This is a node that has already been processed.
50  Processed = -3
51 
52  // 1+ - This is a node which has this many unprocessed operands.
53  };
54 private:
55 
56  /// This is a bitvector that contains two bits for each simple value type,
57  /// where the two bits correspond to the LegalizeAction enum from
58  /// TargetLowering. This can be queried with "getTypeAction(VT)".
59  TargetLowering::ValueTypeActionImpl ValueTypeActions;
60 
61  /// Return how we should legalize values of this type.
62  TargetLowering::LegalizeTypeAction getTypeAction(EVT VT) const {
63  return TLI.getTypeAction(*DAG.getContext(), VT);
64  }
65 
66  /// Return true if this type is legal on this target.
67  bool isTypeLegal(EVT VT) const {
68  return TLI.getTypeAction(*DAG.getContext(), VT) == TargetLowering::TypeLegal;
69  }
70 
71  /// Return true if this is a simple legal type.
72  bool isSimpleLegalType(EVT VT) const {
73  return VT.isSimple() && TLI.isTypeLegal(VT);
74  }
75 
76  EVT getSetCCResultType(EVT VT) const {
77  return TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
78  }
79 
80  /// Pretend all of this node's results are legal.
81  bool IgnoreNodeResults(SDNode *N) const {
82  return N->getOpcode() == ISD::TargetConstant ||
83  N->getOpcode() == ISD::Register;
84  }
85 
86  // Bijection from SDValue to unique id. As each created node gets a
87  // new id we do not need to worry about reuse expunging. Should we
88  // run out of ids, we can do a one time expensive compactifcation.
89  typedef unsigned TableId;
90 
91  TableId NextValueId = 1;
92 
93  SmallDenseMap<SDValue, TableId, 8> ValueToIdMap;
94  SmallDenseMap<TableId, SDValue, 8> IdToValueMap;
95 
96  /// For integer nodes that are below legal width, this map indicates what
97  /// promoted value to use.
98  SmallDenseMap<TableId, TableId, 8> PromotedIntegers;
99 
100  /// For integer nodes that need to be expanded this map indicates which
101  /// operands are the expanded version of the input.
102  SmallDenseMap<TableId, std::pair<TableId, TableId>, 8> ExpandedIntegers;
103 
104  /// For floating-point nodes converted to integers of the same size, this map
105  /// indicates the converted value to use.
106  SmallDenseMap<TableId, TableId, 8> SoftenedFloats;
107 
108  /// For floating-point nodes that have a smaller precision than the smallest
109  /// supported precision, this map indicates what promoted value to use.
110  SmallDenseMap<TableId, TableId, 8> PromotedFloats;
111 
112  /// For floating-point nodes that have a smaller precision than the smallest
113  /// supported precision, this map indicates the converted value to use.
114  SmallDenseMap<TableId, TableId, 8> SoftPromotedHalfs;
115 
116  /// For float nodes that need to be expanded this map indicates which operands
117  /// are the expanded version of the input.
118  SmallDenseMap<TableId, std::pair<TableId, TableId>, 8> ExpandedFloats;
119 
120  /// For nodes that are <1 x ty>, this map indicates the scalar value of type
121  /// 'ty' to use.
122  SmallDenseMap<TableId, TableId, 8> ScalarizedVectors;
123 
124  /// For nodes that need to be split this map indicates which operands are the
125  /// expanded version of the input.
126  SmallDenseMap<TableId, std::pair<TableId, TableId>, 8> SplitVectors;
127 
128  /// For vector nodes that need to be widened, indicates the widened value to
129  /// use.
130  SmallDenseMap<TableId, TableId, 8> WidenedVectors;
131 
132  /// For values that have been replaced with another, indicates the replacement
133  /// value to use.
134  SmallDenseMap<TableId, TableId, 8> ReplacedValues;
135 
136  /// This defines a worklist of nodes to process. In order to be pushed onto
137  /// this worklist, all operands of a node must have already been processed.
138  SmallVector<SDNode*, 128> Worklist;
139 
140  TableId getTableId(SDValue V) {
141  assert(V.getNode() && "Getting TableId on SDValue()");
142 
143  auto I = ValueToIdMap.find(V);
144  if (I != ValueToIdMap.end()) {
145  // replace if there's been a shift.
146  RemapId(I->second);
147  assert(I->second && "All Ids should be nonzero");
148  return I->second;
149  }
150  // Add if it's not there.
151  ValueToIdMap.insert(std::make_pair(V, NextValueId));
152  IdToValueMap.insert(std::make_pair(NextValueId, V));
153  ++NextValueId;
154  assert(NextValueId != 0 &&
155  "Ran out of Ids. Increase id type size or add compactification");
156  return NextValueId - 1;
157  }
158 
159  const SDValue &getSDValue(TableId &Id) {
160  RemapId(Id);
161  assert(Id && "TableId should be non-zero");
162  auto I = IdToValueMap.find(Id);
163  assert(I != IdToValueMap.end() && "cannot find Id in map");
164  return I->second;
165  }
166 
167 public:
169  : TLI(dag.getTargetLoweringInfo()), DAG(dag),
170  ValueTypeActions(TLI.getValueTypeActions()) {
172  "Too many value types for ValueTypeActions to hold!");
173  }
174 
175  /// This is the main entry point for the type legalizer. This does a
176  /// top-down traversal of the dag, legalizing types as it goes. Returns
177  /// "true" if it made any changes.
178  bool run();
179 
180  void NoteDeletion(SDNode *Old, SDNode *New) {
181  assert(Old != New && "node replaced with self");
182  for (unsigned i = 0, e = Old->getNumValues(); i != e; ++i) {
183  TableId NewId = getTableId(SDValue(New, i));
184  TableId OldId = getTableId(SDValue(Old, i));
185 
186  if (OldId != NewId) {
187  ReplacedValues[OldId] = NewId;
188 
189  // Delete Node from tables. We cannot do this when OldId == NewId,
190  // because NewId can still have table references to it in
191  // ReplacedValues.
192  IdToValueMap.erase(OldId);
193  PromotedIntegers.erase(OldId);
194  ExpandedIntegers.erase(OldId);
195  SoftenedFloats.erase(OldId);
196  PromotedFloats.erase(OldId);
197  SoftPromotedHalfs.erase(OldId);
198  ExpandedFloats.erase(OldId);
199  ScalarizedVectors.erase(OldId);
200  SplitVectors.erase(OldId);
201  WidenedVectors.erase(OldId);
202  }
203 
204  ValueToIdMap.erase(SDValue(Old, i));
205  }
206  }
207 
208  SelectionDAG &getDAG() const { return DAG; }
209 
210 private:
211  SDNode *AnalyzeNewNode(SDNode *N);
212  void AnalyzeNewValue(SDValue &Val);
213  void PerformExpensiveChecks();
214  void RemapId(TableId &Id);
215  void RemapValue(SDValue &V);
216 
217  // Common routines.
218  SDValue BitConvertToInteger(SDValue Op);
219  SDValue BitConvertVectorToIntegerVector(SDValue Op);
220  SDValue CreateStackStoreLoad(SDValue Op, EVT DestVT);
221  bool CustomLowerNode(SDNode *N, EVT VT, bool LegalizeResult);
222  bool CustomWidenLowerNode(SDNode *N, EVT VT);
223 
224  /// Replace each result of the given MERGE_VALUES node with the corresponding
225  /// input operand, except for the result 'ResNo', for which the corresponding
226  /// input operand is returned.
227  SDValue DisintegrateMERGE_VALUES(SDNode *N, unsigned ResNo);
228 
229  SDValue JoinIntegers(SDValue Lo, SDValue Hi);
230 
231  std::pair<SDValue, SDValue> ExpandAtomic(SDNode *Node);
232 
233  SDValue PromoteTargetBoolean(SDValue Bool, EVT ValVT);
234 
235  void ReplaceValueWith(SDValue From, SDValue To);
236  void SplitInteger(SDValue Op, SDValue &Lo, SDValue &Hi);
237  void SplitInteger(SDValue Op, EVT LoVT, EVT HiVT,
238  SDValue &Lo, SDValue &Hi);
239 
240  //===--------------------------------------------------------------------===//
241  // Integer Promotion Support: LegalizeIntegerTypes.cpp
242  //===--------------------------------------------------------------------===//
243 
244  /// Given a processed operand Op which was promoted to a larger integer type,
245  /// this returns the promoted value. The low bits of the promoted value
246  /// corresponding to the original type are exactly equal to Op.
247  /// The extra bits contain rubbish, so the promoted value may need to be zero-
248  /// or sign-extended from the original type before it is usable (the helpers
249  /// SExtPromotedInteger and ZExtPromotedInteger can do this for you).
250  /// For example, if Op is an i16 and was promoted to an i32, then this method
251  /// returns an i32, the lower 16 bits of which coincide with Op, and the upper
252  /// 16 bits of which contain rubbish.
253  SDValue GetPromotedInteger(SDValue Op) {
254  TableId &PromotedId = PromotedIntegers[getTableId(Op)];
255  SDValue PromotedOp = getSDValue(PromotedId);
256  assert(PromotedOp.getNode() && "Operand wasn't promoted?");
257  return PromotedOp;
258  }
259  void SetPromotedInteger(SDValue Op, SDValue Result);
260 
261  /// Get a promoted operand and sign extend it to the final size.
262  SDValue SExtPromotedInteger(SDValue Op) {
263  EVT OldVT = Op.getValueType();
264  SDLoc dl(Op);
265  Op = GetPromotedInteger(Op);
266  return DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, Op.getValueType(), Op,
267  DAG.getValueType(OldVT));
268  }
269 
270  /// Get a promoted operand and zero extend it to the final size.
271  SDValue ZExtPromotedInteger(SDValue Op) {
272  EVT OldVT = Op.getValueType();
273  SDLoc dl(Op);
274  Op = GetPromotedInteger(Op);
275  return DAG.getZeroExtendInReg(Op, dl, OldVT);
276  }
277 
278  // Get a promoted operand and sign or zero extend it to the final size
279  // (depending on TargetLoweringInfo::isSExtCheaperThanZExt). For a given
280  // subtarget and type, the choice of sign or zero-extension will be
281  // consistent.
282  SDValue SExtOrZExtPromotedInteger(SDValue Op) {
283  EVT OldVT = Op.getValueType();
284  SDLoc DL(Op);
285  Op = GetPromotedInteger(Op);
286  if (TLI.isSExtCheaperThanZExt(OldVT, Op.getValueType()))
287  return DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, Op.getValueType(), Op,
288  DAG.getValueType(OldVT));
289  return DAG.getZeroExtendInReg(Op, DL, OldVT);
290  }
291 
292  // Integer Result Promotion.
293  void PromoteIntegerResult(SDNode *N, unsigned ResNo);
294  SDValue PromoteIntRes_MERGE_VALUES(SDNode *N, unsigned ResNo);
295  SDValue PromoteIntRes_AssertSext(SDNode *N);
296  SDValue PromoteIntRes_AssertZext(SDNode *N);
297  SDValue PromoteIntRes_Atomic0(AtomicSDNode *N);
298  SDValue PromoteIntRes_Atomic1(AtomicSDNode *N);
299  SDValue PromoteIntRes_AtomicCmpSwap(AtomicSDNode *N, unsigned ResNo);
300  SDValue PromoteIntRes_EXTRACT_SUBVECTOR(SDNode *N);
301  SDValue PromoteIntRes_VECTOR_REVERSE(SDNode *N);
302  SDValue PromoteIntRes_VECTOR_SHUFFLE(SDNode *N);
303  SDValue PromoteIntRes_VECTOR_SPLICE(SDNode *N);
304  SDValue PromoteIntRes_BUILD_VECTOR(SDNode *N);
305  SDValue PromoteIntRes_SCALAR_TO_VECTOR(SDNode *N);
306  SDValue PromoteIntRes_SPLAT_VECTOR(SDNode *N);
307  SDValue PromoteIntRes_STEP_VECTOR(SDNode *N);
308  SDValue PromoteIntRes_EXTEND_VECTOR_INREG(SDNode *N);
309  SDValue PromoteIntRes_INSERT_VECTOR_ELT(SDNode *N);
310  SDValue PromoteIntRes_CONCAT_VECTORS(SDNode *N);
311  SDValue PromoteIntRes_BITCAST(SDNode *N);
312  SDValue PromoteIntRes_BSWAP(SDNode *N);
313  SDValue PromoteIntRes_BITREVERSE(SDNode *N);
314  SDValue PromoteIntRes_BUILD_PAIR(SDNode *N);
315  SDValue PromoteIntRes_Constant(SDNode *N);
316  SDValue PromoteIntRes_CTLZ(SDNode *N);
317  SDValue PromoteIntRes_CTPOP_PARITY(SDNode *N);
318  SDValue PromoteIntRes_CTTZ(SDNode *N);
319  SDValue PromoteIntRes_EXTRACT_VECTOR_ELT(SDNode *N);
320  SDValue PromoteIntRes_FP_TO_XINT(SDNode *N);
321  SDValue PromoteIntRes_FP_TO_XINT_SAT(SDNode *N);
322  SDValue PromoteIntRes_FP_TO_FP16(SDNode *N);
323  SDValue PromoteIntRes_FREEZE(SDNode *N);
324  SDValue PromoteIntRes_INT_EXTEND(SDNode *N);
325  SDValue PromoteIntRes_LOAD(LoadSDNode *N);
326  SDValue PromoteIntRes_MLOAD(MaskedLoadSDNode *N);
327  SDValue PromoteIntRes_MGATHER(MaskedGatherSDNode *N);
328  SDValue PromoteIntRes_Overflow(SDNode *N);
329  SDValue PromoteIntRes_SADDSUBO(SDNode *N, unsigned ResNo);
330  SDValue PromoteIntRes_SELECT(SDNode *N);
331  SDValue PromoteIntRes_VSELECT(SDNode *N);
332  SDValue PromoteIntRes_SELECT_CC(SDNode *N);
333  SDValue PromoteIntRes_SETCC(SDNode *N);
334  SDValue PromoteIntRes_SHL(SDNode *N);
335  SDValue PromoteIntRes_SimpleIntBinOp(SDNode *N);
336  SDValue PromoteIntRes_ZExtIntBinOp(SDNode *N);
337  SDValue PromoteIntRes_SExtIntBinOp(SDNode *N);
338  SDValue PromoteIntRes_UMINUMAX(SDNode *N);
339  SDValue PromoteIntRes_SIGN_EXTEND_INREG(SDNode *N);
340  SDValue PromoteIntRes_SRA(SDNode *N);
341  SDValue PromoteIntRes_SRL(SDNode *N);
342  SDValue PromoteIntRes_TRUNCATE(SDNode *N);
343  SDValue PromoteIntRes_UADDSUBO(SDNode *N, unsigned ResNo);
344  SDValue PromoteIntRes_ADDSUBCARRY(SDNode *N, unsigned ResNo);
345  SDValue PromoteIntRes_SADDSUBO_CARRY(SDNode *N, unsigned ResNo);
346  SDValue PromoteIntRes_UNDEF(SDNode *N);
347  SDValue PromoteIntRes_VAARG(SDNode *N);
348  SDValue PromoteIntRes_VSCALE(SDNode *N);
349  SDValue PromoteIntRes_XMULO(SDNode *N, unsigned ResNo);
350  SDValue PromoteIntRes_ADDSUBSHLSAT(SDNode *N);
351  SDValue PromoteIntRes_MULFIX(SDNode *N);
352  SDValue PromoteIntRes_DIVFIX(SDNode *N);
353  SDValue PromoteIntRes_FLT_ROUNDS(SDNode *N);
354  SDValue PromoteIntRes_VECREDUCE(SDNode *N);
355  SDValue PromoteIntRes_ABS(SDNode *N);
356  SDValue PromoteIntRes_Rotate(SDNode *N);
357  SDValue PromoteIntRes_FunnelShift(SDNode *N);
358 
359  // Integer Operand Promotion.
360  bool PromoteIntegerOperand(SDNode *N, unsigned OpNo);
361  SDValue PromoteIntOp_ANY_EXTEND(SDNode *N);
362  SDValue PromoteIntOp_ATOMIC_STORE(AtomicSDNode *N);
363  SDValue PromoteIntOp_BITCAST(SDNode *N);
364  SDValue PromoteIntOp_BUILD_PAIR(SDNode *N);
365  SDValue PromoteIntOp_BR_CC(SDNode *N, unsigned OpNo);
366  SDValue PromoteIntOp_BRCOND(SDNode *N, unsigned OpNo);
367  SDValue PromoteIntOp_BUILD_VECTOR(SDNode *N);
368  SDValue PromoteIntOp_INSERT_VECTOR_ELT(SDNode *N, unsigned OpNo);
369  SDValue PromoteIntOp_EXTRACT_VECTOR_ELT(SDNode *N);
370  SDValue PromoteIntOp_EXTRACT_SUBVECTOR(SDNode *N);
371  SDValue PromoteIntOp_CONCAT_VECTORS(SDNode *N);
372  SDValue PromoteIntOp_SCALAR_TO_VECTOR(SDNode *N);
373  SDValue PromoteIntOp_SPLAT_VECTOR(SDNode *N);
374  SDValue PromoteIntOp_SELECT(SDNode *N, unsigned OpNo);
375  SDValue PromoteIntOp_SELECT_CC(SDNode *N, unsigned OpNo);
376  SDValue PromoteIntOp_SETCC(SDNode *N, unsigned OpNo);
377  SDValue PromoteIntOp_Shift(SDNode *N);
378  SDValue PromoteIntOp_SIGN_EXTEND(SDNode *N);
379  SDValue PromoteIntOp_SINT_TO_FP(SDNode *N);
380  SDValue PromoteIntOp_STRICT_SINT_TO_FP(SDNode *N);
381  SDValue PromoteIntOp_STORE(StoreSDNode *N, unsigned OpNo);
382  SDValue PromoteIntOp_TRUNCATE(SDNode *N);
383  SDValue PromoteIntOp_UINT_TO_FP(SDNode *N);
384  SDValue PromoteIntOp_STRICT_UINT_TO_FP(SDNode *N);
385  SDValue PromoteIntOp_ZERO_EXTEND(SDNode *N);
386  SDValue PromoteIntOp_MSTORE(MaskedStoreSDNode *N, unsigned OpNo);
387  SDValue PromoteIntOp_MLOAD(MaskedLoadSDNode *N, unsigned OpNo);
388  SDValue PromoteIntOp_MSCATTER(MaskedScatterSDNode *N, unsigned OpNo);
389  SDValue PromoteIntOp_MGATHER(MaskedGatherSDNode *N, unsigned OpNo);
390  SDValue PromoteIntOp_ADDSUBCARRY(SDNode *N, unsigned OpNo);
391  SDValue PromoteIntOp_FRAMERETURNADDR(SDNode *N);
392  SDValue PromoteIntOp_PREFETCH(SDNode *N, unsigned OpNo);
393  SDValue PromoteIntOp_FIX(SDNode *N);
394  SDValue PromoteIntOp_FPOWI(SDNode *N);
395  SDValue PromoteIntOp_VECREDUCE(SDNode *N);
396  SDValue PromoteIntOp_SET_ROUNDING(SDNode *N);
397 
398  void PromoteSetCCOperands(SDValue &LHS,SDValue &RHS, ISD::CondCode Code);
399 
400  //===--------------------------------------------------------------------===//
401  // Integer Expansion Support: LegalizeIntegerTypes.cpp
402  //===--------------------------------------------------------------------===//
403 
404  /// Given a processed operand Op which was expanded into two integers of half
405  /// the size, this returns the two halves. The low bits of Op are exactly
406  /// equal to the bits of Lo; the high bits exactly equal Hi.
407  /// For example, if Op is an i64 which was expanded into two i32's, then this
408  /// method returns the two i32's, with Lo being equal to the lower 32 bits of
409  /// Op, and Hi being equal to the upper 32 bits.
410  void GetExpandedInteger(SDValue Op, SDValue &Lo, SDValue &Hi);
411  void SetExpandedInteger(SDValue Op, SDValue Lo, SDValue Hi);
412 
413  // Integer Result Expansion.
414  void ExpandIntegerResult(SDNode *N, unsigned ResNo);
415  void ExpandIntRes_ANY_EXTEND (SDNode *N, SDValue &Lo, SDValue &Hi);
416  void ExpandIntRes_AssertSext (SDNode *N, SDValue &Lo, SDValue &Hi);
417  void ExpandIntRes_AssertZext (SDNode *N, SDValue &Lo, SDValue &Hi);
418  void ExpandIntRes_Constant (SDNode *N, SDValue &Lo, SDValue &Hi);
419  void ExpandIntRes_ABS (SDNode *N, SDValue &Lo, SDValue &Hi);
420  void ExpandIntRes_CTLZ (SDNode *N, SDValue &Lo, SDValue &Hi);
421  void ExpandIntRes_CTPOP (SDNode *N, SDValue &Lo, SDValue &Hi);
422  void ExpandIntRes_CTTZ (SDNode *N, SDValue &Lo, SDValue &Hi);
423  void ExpandIntRes_LOAD (LoadSDNode *N, SDValue &Lo, SDValue &Hi);
424  void ExpandIntRes_READCYCLECOUNTER (SDNode *N, SDValue &Lo, SDValue &Hi);
425  void ExpandIntRes_SIGN_EXTEND (SDNode *N, SDValue &Lo, SDValue &Hi);
426  void ExpandIntRes_SIGN_EXTEND_INREG (SDNode *N, SDValue &Lo, SDValue &Hi);
427  void ExpandIntRes_TRUNCATE (SDNode *N, SDValue &Lo, SDValue &Hi);
428  void ExpandIntRes_ZERO_EXTEND (SDNode *N, SDValue &Lo, SDValue &Hi);
429  void ExpandIntRes_FLT_ROUNDS (SDNode *N, SDValue &Lo, SDValue &Hi);
430  void ExpandIntRes_FP_TO_SINT (SDNode *N, SDValue &Lo, SDValue &Hi);
431  void ExpandIntRes_FP_TO_UINT (SDNode *N, SDValue &Lo, SDValue &Hi);
432  void ExpandIntRes_FP_TO_XINT_SAT (SDNode *N, SDValue &Lo, SDValue &Hi);
433  void ExpandIntRes_LLROUND_LLRINT (SDNode *N, SDValue &Lo, SDValue &Hi);
434 
435  void ExpandIntRes_Logical (SDNode *N, SDValue &Lo, SDValue &Hi);
436  void ExpandIntRes_ADDSUB (SDNode *N, SDValue &Lo, SDValue &Hi);
437  void ExpandIntRes_ADDSUBC (SDNode *N, SDValue &Lo, SDValue &Hi);
438  void ExpandIntRes_ADDSUBE (SDNode *N, SDValue &Lo, SDValue &Hi);
439  void ExpandIntRes_ADDSUBCARRY (SDNode *N, SDValue &Lo, SDValue &Hi);
440  void ExpandIntRes_SADDSUBO_CARRY (SDNode *N, SDValue &Lo, SDValue &Hi);
441  void ExpandIntRes_BITREVERSE (SDNode *N, SDValue &Lo, SDValue &Hi);
442  void ExpandIntRes_BSWAP (SDNode *N, SDValue &Lo, SDValue &Hi);
443  void ExpandIntRes_PARITY (SDNode *N, SDValue &Lo, SDValue &Hi);
444  void ExpandIntRes_MUL (SDNode *N, SDValue &Lo, SDValue &Hi);
445  void ExpandIntRes_SDIV (SDNode *N, SDValue &Lo, SDValue &Hi);
446  void ExpandIntRes_SREM (SDNode *N, SDValue &Lo, SDValue &Hi);
447  void ExpandIntRes_UDIV (SDNode *N, SDValue &Lo, SDValue &Hi);
448  void ExpandIntRes_UREM (SDNode *N, SDValue &Lo, SDValue &Hi);
449  void ExpandIntRes_Shift (SDNode *N, SDValue &Lo, SDValue &Hi);
450 
451  void ExpandIntRes_MINMAX (SDNode *N, SDValue &Lo, SDValue &Hi);
452 
453  void ExpandIntRes_SADDSUBO (SDNode *N, SDValue &Lo, SDValue &Hi);
454  void ExpandIntRes_UADDSUBO (SDNode *N, SDValue &Lo, SDValue &Hi);
455  void ExpandIntRes_XMULO (SDNode *N, SDValue &Lo, SDValue &Hi);
456  void ExpandIntRes_ADDSUBSAT (SDNode *N, SDValue &Lo, SDValue &Hi);
457  void ExpandIntRes_SHLSAT (SDNode *N, SDValue &Lo, SDValue &Hi);
458  void ExpandIntRes_MULFIX (SDNode *N, SDValue &Lo, SDValue &Hi);
459  void ExpandIntRes_DIVFIX (SDNode *N, SDValue &Lo, SDValue &Hi);
460 
461  void ExpandIntRes_ATOMIC_LOAD (SDNode *N, SDValue &Lo, SDValue &Hi);
462  void ExpandIntRes_VECREDUCE (SDNode *N, SDValue &Lo, SDValue &Hi);
463 
464  void ExpandIntRes_Rotate (SDNode *N, SDValue &Lo, SDValue &Hi);
465  void ExpandIntRes_FunnelShift (SDNode *N, SDValue &Lo, SDValue &Hi);
466 
467  void ExpandShiftByConstant(SDNode *N, const APInt &Amt,
468  SDValue &Lo, SDValue &Hi);
469  bool ExpandShiftWithKnownAmountBit(SDNode *N, SDValue &Lo, SDValue &Hi);
470  bool ExpandShiftWithUnknownAmountBit(SDNode *N, SDValue &Lo, SDValue &Hi);
471 
472  // Integer Operand Expansion.
473  bool ExpandIntegerOperand(SDNode *N, unsigned OpNo);
474  SDValue ExpandIntOp_BR_CC(SDNode *N);
475  SDValue ExpandIntOp_SELECT_CC(SDNode *N);
476  SDValue ExpandIntOp_SETCC(SDNode *N);
477  SDValue ExpandIntOp_SETCCCARRY(SDNode *N);
478  SDValue ExpandIntOp_Shift(SDNode *N);
479  SDValue ExpandIntOp_SINT_TO_FP(SDNode *N);
480  SDValue ExpandIntOp_STORE(StoreSDNode *N, unsigned OpNo);
481  SDValue ExpandIntOp_TRUNCATE(SDNode *N);
482  SDValue ExpandIntOp_UINT_TO_FP(SDNode *N);
483  SDValue ExpandIntOp_RETURNADDR(SDNode *N);
484  SDValue ExpandIntOp_ATOMIC_STORE(SDNode *N);
485  SDValue ExpandIntOp_SPLAT_VECTOR(SDNode *N);
486 
487  void IntegerExpandSetCCOperands(SDValue &NewLHS, SDValue &NewRHS,
488  ISD::CondCode &CCCode, const SDLoc &dl);
489 
490  //===--------------------------------------------------------------------===//
491  // Float to Integer Conversion Support: LegalizeFloatTypes.cpp
492  //===--------------------------------------------------------------------===//
493 
494  /// GetSoftenedFloat - Given a processed operand Op which was converted to an
495  /// integer of the same size, this returns the integer. The integer contains
496  /// exactly the same bits as Op - only the type changed. For example, if Op
497  /// is an f32 which was softened to an i32, then this method returns an i32,
498  /// the bits of which coincide with those of Op
499  SDValue GetSoftenedFloat(SDValue Op) {
500  TableId Id = getTableId(Op);
501  auto Iter = SoftenedFloats.find(Id);
502  if (Iter == SoftenedFloats.end()) {
503  assert(isSimpleLegalType(Op.getValueType()) &&
504  "Operand wasn't converted to integer?");
505  return Op;
506  }
507  SDValue SoftenedOp = getSDValue(Iter->second);
508  assert(SoftenedOp.getNode() && "Unconverted op in SoftenedFloats?");
509  return SoftenedOp;
510  }
511  void SetSoftenedFloat(SDValue Op, SDValue Result);
512 
513  // Convert Float Results to Integer.
514  void SoftenFloatResult(SDNode *N, unsigned ResNo);
515  SDValue SoftenFloatRes_Unary(SDNode *N, RTLIB::Libcall LC);
516  SDValue SoftenFloatRes_Binary(SDNode *N, RTLIB::Libcall LC);
517  SDValue SoftenFloatRes_MERGE_VALUES(SDNode *N, unsigned ResNo);
518  SDValue SoftenFloatRes_BITCAST(SDNode *N);
519  SDValue SoftenFloatRes_BUILD_PAIR(SDNode *N);
520  SDValue SoftenFloatRes_ConstantFP(SDNode *N);
521  SDValue SoftenFloatRes_EXTRACT_VECTOR_ELT(SDNode *N, unsigned ResNo);
522  SDValue SoftenFloatRes_FABS(SDNode *N);
523  SDValue SoftenFloatRes_FMINNUM(SDNode *N);
524  SDValue SoftenFloatRes_FMAXNUM(SDNode *N);
525  SDValue SoftenFloatRes_FADD(SDNode *N);
526  SDValue SoftenFloatRes_FCBRT(SDNode *N);
527  SDValue SoftenFloatRes_FCEIL(SDNode *N);
528  SDValue SoftenFloatRes_FCOPYSIGN(SDNode *N);
529  SDValue SoftenFloatRes_FCOS(SDNode *N);
530  SDValue SoftenFloatRes_FDIV(SDNode *N);
531  SDValue SoftenFloatRes_FEXP(SDNode *N);
532  SDValue SoftenFloatRes_FEXP2(SDNode *N);
533  SDValue SoftenFloatRes_FFLOOR(SDNode *N);
534  SDValue SoftenFloatRes_FLOG(SDNode *N);
535  SDValue SoftenFloatRes_FLOG2(SDNode *N);
536  SDValue SoftenFloatRes_FLOG10(SDNode *N);
537  SDValue SoftenFloatRes_FMA(SDNode *N);
538  SDValue SoftenFloatRes_FMUL(SDNode *N);
539  SDValue SoftenFloatRes_FNEARBYINT(SDNode *N);
540  SDValue SoftenFloatRes_FNEG(SDNode *N);
541  SDValue SoftenFloatRes_FP_EXTEND(SDNode *N);
542  SDValue SoftenFloatRes_FP16_TO_FP(SDNode *N);
543  SDValue SoftenFloatRes_FP_ROUND(SDNode *N);
544  SDValue SoftenFloatRes_FPOW(SDNode *N);
545  SDValue SoftenFloatRes_FPOWI(SDNode *N);
546  SDValue SoftenFloatRes_FREEZE(SDNode *N);
547  SDValue SoftenFloatRes_FREM(SDNode *N);
548  SDValue SoftenFloatRes_FRINT(SDNode *N);
549  SDValue SoftenFloatRes_FROUND(SDNode *N);
550  SDValue SoftenFloatRes_FROUNDEVEN(SDNode *N);
551  SDValue SoftenFloatRes_FSIN(SDNode *N);
552  SDValue SoftenFloatRes_FSQRT(SDNode *N);
553  SDValue SoftenFloatRes_FSUB(SDNode *N);
554  SDValue SoftenFloatRes_FTRUNC(SDNode *N);
555  SDValue SoftenFloatRes_LOAD(SDNode *N);
556  SDValue SoftenFloatRes_SELECT(SDNode *N);
557  SDValue SoftenFloatRes_SELECT_CC(SDNode *N);
558  SDValue SoftenFloatRes_UNDEF(SDNode *N);
559  SDValue SoftenFloatRes_VAARG(SDNode *N);
560  SDValue SoftenFloatRes_XINT_TO_FP(SDNode *N);
561  SDValue SoftenFloatRes_VECREDUCE(SDNode *N);
562  SDValue SoftenFloatRes_VECREDUCE_SEQ(SDNode *N);
563 
564  // Convert Float Operand to Integer.
565  bool SoftenFloatOperand(SDNode *N, unsigned OpNo);
566  SDValue SoftenFloatOp_Unary(SDNode *N, RTLIB::Libcall LC);
567  SDValue SoftenFloatOp_BITCAST(SDNode *N);
568  SDValue SoftenFloatOp_BR_CC(SDNode *N);
569  SDValue SoftenFloatOp_FP_ROUND(SDNode *N);
570  SDValue SoftenFloatOp_FP_TO_XINT(SDNode *N);
571  SDValue SoftenFloatOp_FP_TO_XINT_SAT(SDNode *N);
572  SDValue SoftenFloatOp_LROUND(SDNode *N);
573  SDValue SoftenFloatOp_LLROUND(SDNode *N);
574  SDValue SoftenFloatOp_LRINT(SDNode *N);
575  SDValue SoftenFloatOp_LLRINT(SDNode *N);
576  SDValue SoftenFloatOp_SELECT_CC(SDNode *N);
577  SDValue SoftenFloatOp_SETCC(SDNode *N);
578  SDValue SoftenFloatOp_STORE(SDNode *N, unsigned OpNo);
579  SDValue SoftenFloatOp_FCOPYSIGN(SDNode *N);
580 
581  //===--------------------------------------------------------------------===//
582  // Float Expansion Support: LegalizeFloatTypes.cpp
583  //===--------------------------------------------------------------------===//
584 
585  /// Given a processed operand Op which was expanded into two floating-point
586  /// values of half the size, this returns the two halves.
587  /// The low bits of Op are exactly equal to the bits of Lo; the high bits
588  /// exactly equal Hi. For example, if Op is a ppcf128 which was expanded
589  /// into two f64's, then this method returns the two f64's, with Lo being
590  /// equal to the lower 64 bits of Op, and Hi to the upper 64 bits.
591  void GetExpandedFloat(SDValue Op, SDValue &Lo, SDValue &Hi);
592  void SetExpandedFloat(SDValue Op, SDValue Lo, SDValue Hi);
593 
594  // Float Result Expansion.
595  void ExpandFloatResult(SDNode *N, unsigned ResNo);
596  void ExpandFloatRes_ConstantFP(SDNode *N, SDValue &Lo, SDValue &Hi);
597  void ExpandFloatRes_Unary(SDNode *N, RTLIB::Libcall LC,
598  SDValue &Lo, SDValue &Hi);
599  void ExpandFloatRes_Binary(SDNode *N, RTLIB::Libcall LC,
600  SDValue &Lo, SDValue &Hi);
601  void ExpandFloatRes_FABS (SDNode *N, SDValue &Lo, SDValue &Hi);
602  void ExpandFloatRes_FMINNUM (SDNode *N, SDValue &Lo, SDValue &Hi);
603  void ExpandFloatRes_FMAXNUM (SDNode *N, SDValue &Lo, SDValue &Hi);
604  void ExpandFloatRes_FADD (SDNode *N, SDValue &Lo, SDValue &Hi);
605  void ExpandFloatRes_FCBRT (SDNode *N, SDValue &Lo, SDValue &Hi);
606  void ExpandFloatRes_FCEIL (SDNode *N, SDValue &Lo, SDValue &Hi);
607  void ExpandFloatRes_FCOPYSIGN (SDNode *N, SDValue &Lo, SDValue &Hi);
608  void ExpandFloatRes_FCOS (SDNode *N, SDValue &Lo, SDValue &Hi);
609  void ExpandFloatRes_FDIV (SDNode *N, SDValue &Lo, SDValue &Hi);
610  void ExpandFloatRes_FEXP (SDNode *N, SDValue &Lo, SDValue &Hi);
611  void ExpandFloatRes_FEXP2 (SDNode *N, SDValue &Lo, SDValue &Hi);
612  void ExpandFloatRes_FFLOOR (SDNode *N, SDValue &Lo, SDValue &Hi);
613  void ExpandFloatRes_FLOG (SDNode *N, SDValue &Lo, SDValue &Hi);
614  void ExpandFloatRes_FLOG2 (SDNode *N, SDValue &Lo, SDValue &Hi);
615  void ExpandFloatRes_FLOG10 (SDNode *N, SDValue &Lo, SDValue &Hi);
616  void ExpandFloatRes_FMA (SDNode *N, SDValue &Lo, SDValue &Hi);
617  void ExpandFloatRes_FMUL (SDNode *N, SDValue &Lo, SDValue &Hi);
618  void ExpandFloatRes_FNEARBYINT(SDNode *N, SDValue &Lo, SDValue &Hi);
619  void ExpandFloatRes_FNEG (SDNode *N, SDValue &Lo, SDValue &Hi);
620  void ExpandFloatRes_FP_EXTEND (SDNode *N, SDValue &Lo, SDValue &Hi);
621  void ExpandFloatRes_FPOW (SDNode *N, SDValue &Lo, SDValue &Hi);
622  void ExpandFloatRes_FPOWI (SDNode *N, SDValue &Lo, SDValue &Hi);
623  void ExpandFloatRes_FREEZE (SDNode *N, SDValue &Lo, SDValue &Hi);
624  void ExpandFloatRes_FREM (SDNode *N, SDValue &Lo, SDValue &Hi);
625  void ExpandFloatRes_FRINT (SDNode *N, SDValue &Lo, SDValue &Hi);
626  void ExpandFloatRes_FROUND (SDNode *N, SDValue &Lo, SDValue &Hi);
627  void ExpandFloatRes_FROUNDEVEN(SDNode *N, SDValue &Lo, SDValue &Hi);
628  void ExpandFloatRes_FSIN (SDNode *N, SDValue &Lo, SDValue &Hi);
629  void ExpandFloatRes_FSQRT (SDNode *N, SDValue &Lo, SDValue &Hi);
630  void ExpandFloatRes_FSUB (SDNode *N, SDValue &Lo, SDValue &Hi);
631  void ExpandFloatRes_FTRUNC (SDNode *N, SDValue &Lo, SDValue &Hi);
632  void ExpandFloatRes_LOAD (SDNode *N, SDValue &Lo, SDValue &Hi);
633  void ExpandFloatRes_XINT_TO_FP(SDNode *N, SDValue &Lo, SDValue &Hi);
634 
635  // Float Operand Expansion.
636  bool ExpandFloatOperand(SDNode *N, unsigned OpNo);
637  SDValue ExpandFloatOp_BR_CC(SDNode *N);
638  SDValue ExpandFloatOp_FCOPYSIGN(SDNode *N);
639  SDValue ExpandFloatOp_FP_ROUND(SDNode *N);
640  SDValue ExpandFloatOp_FP_TO_XINT(SDNode *N);
641  SDValue ExpandFloatOp_LROUND(SDNode *N);
642  SDValue ExpandFloatOp_LLROUND(SDNode *N);
643  SDValue ExpandFloatOp_LRINT(SDNode *N);
644  SDValue ExpandFloatOp_LLRINT(SDNode *N);
645  SDValue ExpandFloatOp_SELECT_CC(SDNode *N);
646  SDValue ExpandFloatOp_SETCC(SDNode *N);
647  SDValue ExpandFloatOp_STORE(SDNode *N, unsigned OpNo);
648 
649  void FloatExpandSetCCOperands(SDValue &NewLHS, SDValue &NewRHS,
650  ISD::CondCode &CCCode, const SDLoc &dl,
651  SDValue &Chain, bool IsSignaling = false);
652 
653  //===--------------------------------------------------------------------===//
654  // Float promotion support: LegalizeFloatTypes.cpp
655  //===--------------------------------------------------------------------===//
656 
657  SDValue GetPromotedFloat(SDValue Op) {
658  TableId &PromotedId = PromotedFloats[getTableId(Op)];
659  SDValue PromotedOp = getSDValue(PromotedId);
660  assert(PromotedOp.getNode() && "Operand wasn't promoted?");
661  return PromotedOp;
662  }
663  void SetPromotedFloat(SDValue Op, SDValue Result);
664 
665  void PromoteFloatResult(SDNode *N, unsigned ResNo);
666  SDValue PromoteFloatRes_BITCAST(SDNode *N);
667  SDValue PromoteFloatRes_BinOp(SDNode *N);
668  SDValue PromoteFloatRes_ConstantFP(SDNode *N);
669  SDValue PromoteFloatRes_EXTRACT_VECTOR_ELT(SDNode *N);
670  SDValue PromoteFloatRes_FCOPYSIGN(SDNode *N);
671  SDValue PromoteFloatRes_FMAD(SDNode *N);
672  SDValue PromoteFloatRes_FPOWI(SDNode *N);
673  SDValue PromoteFloatRes_FP_ROUND(SDNode *N);
674  SDValue PromoteFloatRes_LOAD(SDNode *N);
675  SDValue PromoteFloatRes_SELECT(SDNode *N);
676  SDValue PromoteFloatRes_SELECT_CC(SDNode *N);
677  SDValue PromoteFloatRes_UnaryOp(SDNode *N);
678  SDValue PromoteFloatRes_UNDEF(SDNode *N);
679  SDValue BitcastToInt_ATOMIC_SWAP(SDNode *N);
680  SDValue PromoteFloatRes_XINT_TO_FP(SDNode *N);
681  SDValue PromoteFloatRes_VECREDUCE(SDNode *N);
682  SDValue PromoteFloatRes_VECREDUCE_SEQ(SDNode *N);
683 
684  bool PromoteFloatOperand(SDNode *N, unsigned OpNo);
685  SDValue PromoteFloatOp_BITCAST(SDNode *N, unsigned OpNo);
686  SDValue PromoteFloatOp_FCOPYSIGN(SDNode *N, unsigned OpNo);
687  SDValue PromoteFloatOp_FP_EXTEND(SDNode *N, unsigned OpNo);
688  SDValue PromoteFloatOp_FP_TO_XINT(SDNode *N, unsigned OpNo);
689  SDValue PromoteFloatOp_FP_TO_XINT_SAT(SDNode *N, unsigned OpNo);
690  SDValue PromoteFloatOp_STORE(SDNode *N, unsigned OpNo);
691  SDValue PromoteFloatOp_SELECT_CC(SDNode *N, unsigned OpNo);
692  SDValue PromoteFloatOp_SETCC(SDNode *N, unsigned OpNo);
693 
694  //===--------------------------------------------------------------------===//
695  // Half soft promotion support: LegalizeFloatTypes.cpp
696  //===--------------------------------------------------------------------===//
697 
698  SDValue GetSoftPromotedHalf(SDValue Op) {
699  TableId &PromotedId = SoftPromotedHalfs[getTableId(Op)];
700  SDValue PromotedOp = getSDValue(PromotedId);
701  assert(PromotedOp.getNode() && "Operand wasn't promoted?");
702  return PromotedOp;
703  }
704  void SetSoftPromotedHalf(SDValue Op, SDValue Result);
705 
706  void SoftPromoteHalfResult(SDNode *N, unsigned ResNo);
707  SDValue SoftPromoteHalfRes_BinOp(SDNode *N);
708  SDValue SoftPromoteHalfRes_BITCAST(SDNode *N);
709  SDValue SoftPromoteHalfRes_ConstantFP(SDNode *N);
710  SDValue SoftPromoteHalfRes_EXTRACT_VECTOR_ELT(SDNode *N);
711  SDValue SoftPromoteHalfRes_FCOPYSIGN(SDNode *N);
712  SDValue SoftPromoteHalfRes_FMAD(SDNode *N);
713  SDValue SoftPromoteHalfRes_FPOWI(SDNode *N);
714  SDValue SoftPromoteHalfRes_FP_ROUND(SDNode *N);
715  SDValue SoftPromoteHalfRes_LOAD(SDNode *N);
716  SDValue SoftPromoteHalfRes_SELECT(SDNode *N);
717  SDValue SoftPromoteHalfRes_SELECT_CC(SDNode *N);
718  SDValue SoftPromoteHalfRes_UnaryOp(SDNode *N);
719  SDValue SoftPromoteHalfRes_XINT_TO_FP(SDNode *N);
720  SDValue SoftPromoteHalfRes_UNDEF(SDNode *N);
721  SDValue SoftPromoteHalfRes_VECREDUCE(SDNode *N);
722  SDValue SoftPromoteHalfRes_VECREDUCE_SEQ(SDNode *N);
723 
724  bool SoftPromoteHalfOperand(SDNode *N, unsigned OpNo);
725  SDValue SoftPromoteHalfOp_BITCAST(SDNode *N);
726  SDValue SoftPromoteHalfOp_FCOPYSIGN(SDNode *N, unsigned OpNo);
727  SDValue SoftPromoteHalfOp_FP_EXTEND(SDNode *N);
728  SDValue SoftPromoteHalfOp_FP_TO_XINT(SDNode *N);
729  SDValue SoftPromoteHalfOp_FP_TO_XINT_SAT(SDNode *N);
730  SDValue SoftPromoteHalfOp_SETCC(SDNode *N);
731  SDValue SoftPromoteHalfOp_SELECT_CC(SDNode *N, unsigned OpNo);
732  SDValue SoftPromoteHalfOp_STORE(SDNode *N, unsigned OpNo);
733 
734  //===--------------------------------------------------------------------===//
735  // Scalarization Support: LegalizeVectorTypes.cpp
736  //===--------------------------------------------------------------------===//
737 
738  /// Given a processed one-element vector Op which was scalarized to its
739  /// element type, this returns the element. For example, if Op is a v1i32,
740  /// Op = < i32 val >, this method returns val, an i32.
741  SDValue GetScalarizedVector(SDValue Op) {
742  TableId &ScalarizedId = ScalarizedVectors[getTableId(Op)];
743  SDValue ScalarizedOp = getSDValue(ScalarizedId);
744  assert(ScalarizedOp.getNode() && "Operand wasn't scalarized?");
745  return ScalarizedOp;
746  }
747  void SetScalarizedVector(SDValue Op, SDValue Result);
748 
749  // Vector Result Scalarization: <1 x ty> -> ty.
750  void ScalarizeVectorResult(SDNode *N, unsigned ResNo);
751  SDValue ScalarizeVecRes_MERGE_VALUES(SDNode *N, unsigned ResNo);
752  SDValue ScalarizeVecRes_BinOp(SDNode *N);
753  SDValue ScalarizeVecRes_TernaryOp(SDNode *N);
754  SDValue ScalarizeVecRes_UnaryOp(SDNode *N);
755  SDValue ScalarizeVecRes_StrictFPOp(SDNode *N);
756  SDValue ScalarizeVecRes_OverflowOp(SDNode *N, unsigned ResNo);
757  SDValue ScalarizeVecRes_InregOp(SDNode *N);
758  SDValue ScalarizeVecRes_VecInregOp(SDNode *N);
759 
760  SDValue ScalarizeVecRes_BITCAST(SDNode *N);
761  SDValue ScalarizeVecRes_BUILD_VECTOR(SDNode *N);
762  SDValue ScalarizeVecRes_EXTRACT_SUBVECTOR(SDNode *N);
763  SDValue ScalarizeVecRes_FP_ROUND(SDNode *N);
764  SDValue ScalarizeVecRes_FPOWI(SDNode *N);
765  SDValue ScalarizeVecRes_INSERT_VECTOR_ELT(SDNode *N);
766  SDValue ScalarizeVecRes_LOAD(LoadSDNode *N);
767  SDValue ScalarizeVecRes_SCALAR_TO_VECTOR(SDNode *N);
768  SDValue ScalarizeVecRes_VSELECT(SDNode *N);
769  SDValue ScalarizeVecRes_SELECT(SDNode *N);
770  SDValue ScalarizeVecRes_SELECT_CC(SDNode *N);
771  SDValue ScalarizeVecRes_SETCC(SDNode *N);
772  SDValue ScalarizeVecRes_UNDEF(SDNode *N);
773  SDValue ScalarizeVecRes_VECTOR_SHUFFLE(SDNode *N);
774  SDValue ScalarizeVecRes_FP_TO_XINT_SAT(SDNode *N);
775 
776  SDValue ScalarizeVecRes_FIX(SDNode *N);
777 
778  // Vector Operand Scalarization: <1 x ty> -> ty.
779  bool ScalarizeVectorOperand(SDNode *N, unsigned OpNo);
780  SDValue ScalarizeVecOp_BITCAST(SDNode *N);
781  SDValue ScalarizeVecOp_UnaryOp(SDNode *N);
782  SDValue ScalarizeVecOp_UnaryOp_StrictFP(SDNode *N);
783  SDValue ScalarizeVecOp_CONCAT_VECTORS(SDNode *N);
784  SDValue ScalarizeVecOp_EXTRACT_VECTOR_ELT(SDNode *N);
785  SDValue ScalarizeVecOp_VSELECT(SDNode *N);
786  SDValue ScalarizeVecOp_VSETCC(SDNode *N);
787  SDValue ScalarizeVecOp_STORE(StoreSDNode *N, unsigned OpNo);
788  SDValue ScalarizeVecOp_FP_ROUND(SDNode *N, unsigned OpNo);
789  SDValue ScalarizeVecOp_STRICT_FP_ROUND(SDNode *N, unsigned OpNo);
790  SDValue ScalarizeVecOp_FP_EXTEND(SDNode *N);
791  SDValue ScalarizeVecOp_STRICT_FP_EXTEND(SDNode *N);
792  SDValue ScalarizeVecOp_VECREDUCE(SDNode *N);
793  SDValue ScalarizeVecOp_VECREDUCE_SEQ(SDNode *N);
794 
795  //===--------------------------------------------------------------------===//
796  // Vector Splitting Support: LegalizeVectorTypes.cpp
797  //===--------------------------------------------------------------------===//
798 
799  /// Given a processed vector Op which was split into vectors of half the size,
800  /// this method returns the halves. The first elements of Op coincide with the
801  /// elements of Lo; the remaining elements of Op coincide with the elements of
802  /// Hi: Op is what you would get by concatenating Lo and Hi.
803  /// For example, if Op is a v8i32 that was split into two v4i32's, then this
804  /// method returns the two v4i32's, with Lo corresponding to the first 4
805  /// elements of Op, and Hi to the last 4 elements.
806  void GetSplitVector(SDValue Op, SDValue &Lo, SDValue &Hi);
807  void SetSplitVector(SDValue Op, SDValue Lo, SDValue Hi);
808 
809  // Helper function for incrementing the pointer when splitting
810  // memory operations
811  void IncrementPointer(MemSDNode *N, EVT MemVT, MachinePointerInfo &MPI,
812  SDValue &Ptr, uint64_t *ScaledOffset = nullptr);
813 
814  // Vector Result Splitting: <128 x ty> -> 2 x <64 x ty>.
815  void SplitVectorResult(SDNode *N, unsigned ResNo);
816  void SplitVecRes_BinOp(SDNode *N, SDValue &Lo, SDValue &Hi);
817  void SplitVecRes_TernaryOp(SDNode *N, SDValue &Lo, SDValue &Hi);
818  void SplitVecRes_UnaryOp(SDNode *N, SDValue &Lo, SDValue &Hi);
819  void SplitVecRes_ExtendOp(SDNode *N, SDValue &Lo, SDValue &Hi);
820  void SplitVecRes_InregOp(SDNode *N, SDValue &Lo, SDValue &Hi);
821  void SplitVecRes_ExtVecInRegOp(SDNode *N, SDValue &Lo, SDValue &Hi);
822  void SplitVecRes_StrictFPOp(SDNode *N, SDValue &Lo, SDValue &Hi);
823  void SplitVecRes_OverflowOp(SDNode *N, unsigned ResNo,
824  SDValue &Lo, SDValue &Hi);
825 
826  void SplitVecRes_FIX(SDNode *N, SDValue &Lo, SDValue &Hi);
827 
828  void SplitVecRes_BITCAST(SDNode *N, SDValue &Lo, SDValue &Hi);
829  void SplitVecRes_BUILD_VECTOR(SDNode *N, SDValue &Lo, SDValue &Hi);
830  void SplitVecRes_CONCAT_VECTORS(SDNode *N, SDValue &Lo, SDValue &Hi);
831  void SplitVecRes_EXTRACT_SUBVECTOR(SDNode *N, SDValue &Lo, SDValue &Hi);
832  void SplitVecRes_INSERT_SUBVECTOR(SDNode *N, SDValue &Lo, SDValue &Hi);
833  void SplitVecRes_FPOWI(SDNode *N, SDValue &Lo, SDValue &Hi);
834  void SplitVecRes_FCOPYSIGN(SDNode *N, SDValue &Lo, SDValue &Hi);
835  void SplitVecRes_INSERT_VECTOR_ELT(SDNode *N, SDValue &Lo, SDValue &Hi);
836  void SplitVecRes_LOAD(LoadSDNode *LD, SDValue &Lo, SDValue &Hi);
837  void SplitVecRes_MLOAD(MaskedLoadSDNode *MLD, SDValue &Lo, SDValue &Hi);
838  void SplitVecRes_MGATHER(MaskedGatherSDNode *MGT, SDValue &Lo, SDValue &Hi);
839  void SplitVecRes_ScalarOp(SDNode *N, SDValue &Lo, SDValue &Hi);
840  void SplitVecRes_STEP_VECTOR(SDNode *N, SDValue &Lo, SDValue &Hi);
841  void SplitVecRes_SETCC(SDNode *N, SDValue &Lo, SDValue &Hi);
842  void SplitVecRes_VECTOR_REVERSE(SDNode *N, SDValue &Lo, SDValue &Hi);
843  void SplitVecRes_VECTOR_SHUFFLE(ShuffleVectorSDNode *N, SDValue &Lo,
844  SDValue &Hi);
845  void SplitVecRes_VECTOR_SPLICE(SDNode *N, SDValue &Lo, SDValue &Hi);
846  void SplitVecRes_VAARG(SDNode *N, SDValue &Lo, SDValue &Hi);
847  void SplitVecRes_FP_TO_XINT_SAT(SDNode *N, SDValue &Lo, SDValue &Hi);
848 
849  // Vector Operand Splitting: <128 x ty> -> 2 x <64 x ty>.
850  bool SplitVectorOperand(SDNode *N, unsigned OpNo);
851  SDValue SplitVecOp_VSELECT(SDNode *N, unsigned OpNo);
852  SDValue SplitVecOp_VECREDUCE(SDNode *N, unsigned OpNo);
853  SDValue SplitVecOp_VECREDUCE_SEQ(SDNode *N);
854  SDValue SplitVecOp_UnaryOp(SDNode *N);
855  SDValue SplitVecOp_TruncateHelper(SDNode *N);
856 
857  SDValue SplitVecOp_BITCAST(SDNode *N);
858  SDValue SplitVecOp_INSERT_SUBVECTOR(SDNode *N, unsigned OpNo);
859  SDValue SplitVecOp_EXTRACT_SUBVECTOR(SDNode *N);
860  SDValue SplitVecOp_EXTRACT_VECTOR_ELT(SDNode *N);
861  SDValue SplitVecOp_ExtVecInRegOp(SDNode *N);
862  SDValue SplitVecOp_STORE(StoreSDNode *N, unsigned OpNo);
863  SDValue SplitVecOp_MSTORE(MaskedStoreSDNode *N, unsigned OpNo);
864  SDValue SplitVecOp_MSCATTER(MaskedScatterSDNode *N, unsigned OpNo);
865  SDValue SplitVecOp_MGATHER(MaskedGatherSDNode *MGT, unsigned OpNo);
866  SDValue SplitVecOp_CONCAT_VECTORS(SDNode *N);
867  SDValue SplitVecOp_VSETCC(SDNode *N);
868  SDValue SplitVecOp_FP_ROUND(SDNode *N);
869  SDValue SplitVecOp_FCOPYSIGN(SDNode *N);
870  SDValue SplitVecOp_FP_TO_XINT_SAT(SDNode *N);
871 
872  //===--------------------------------------------------------------------===//
873  // Vector Widening Support: LegalizeVectorTypes.cpp
874  //===--------------------------------------------------------------------===//
875 
876  /// Given a processed vector Op which was widened into a larger vector, this
877  /// method returns the larger vector. The elements of the returned vector
878  /// consist of the elements of Op followed by elements containing rubbish.
879  /// For example, if Op is a v2i32 that was widened to a v4i32, then this
880  /// method returns a v4i32 for which the first two elements are the same as
881  /// those of Op, while the last two elements contain rubbish.
882  SDValue GetWidenedVector(SDValue Op) {
883  TableId &WidenedId = WidenedVectors[getTableId(Op)];
884  SDValue WidenedOp = getSDValue(WidenedId);
885  assert(WidenedOp.getNode() && "Operand wasn't widened?");
886  return WidenedOp;
887  }
888  void SetWidenedVector(SDValue Op, SDValue Result);
889 
890  // Widen Vector Result Promotion.
891  void WidenVectorResult(SDNode *N, unsigned ResNo);
892  SDValue WidenVecRes_MERGE_VALUES(SDNode* N, unsigned ResNo);
893  SDValue WidenVecRes_BITCAST(SDNode* N);
894  SDValue WidenVecRes_BUILD_VECTOR(SDNode* N);
895  SDValue WidenVecRes_CONCAT_VECTORS(SDNode* N);
896  SDValue WidenVecRes_EXTEND_VECTOR_INREG(SDNode* N);
897  SDValue WidenVecRes_EXTRACT_SUBVECTOR(SDNode* N);
898  SDValue WidenVecRes_INSERT_VECTOR_ELT(SDNode* N);
899  SDValue WidenVecRes_LOAD(SDNode* N);
900  SDValue WidenVecRes_MLOAD(MaskedLoadSDNode* N);
901  SDValue WidenVecRes_MGATHER(MaskedGatherSDNode* N);
902  SDValue WidenVecRes_ScalarOp(SDNode* N);
903  SDValue WidenVecRes_SELECT(SDNode* N);
904  SDValue WidenVSELECTMask(SDNode *N);
905  SDValue WidenVecRes_SELECT_CC(SDNode* N);
906  SDValue WidenVecRes_SETCC(SDNode* N);
907  SDValue WidenVecRes_STRICT_FSETCC(SDNode* N);
908  SDValue WidenVecRes_UNDEF(SDNode *N);
909  SDValue WidenVecRes_VECTOR_SHUFFLE(ShuffleVectorSDNode *N);
910 
911  SDValue WidenVecRes_Ternary(SDNode *N);
912  SDValue WidenVecRes_Binary(SDNode *N);
913  SDValue WidenVecRes_BinaryCanTrap(SDNode *N);
914  SDValue WidenVecRes_BinaryWithExtraScalarOp(SDNode *N);
915  SDValue WidenVecRes_StrictFP(SDNode *N);
916  SDValue WidenVecRes_OverflowOp(SDNode *N, unsigned ResNo);
917  SDValue WidenVecRes_Convert(SDNode *N);
918  SDValue WidenVecRes_Convert_StrictFP(SDNode *N);
919  SDValue WidenVecRes_FP_TO_XINT_SAT(SDNode *N);
920  SDValue WidenVecRes_FCOPYSIGN(SDNode *N);
921  SDValue WidenVecRes_POWI(SDNode *N);
922  SDValue WidenVecRes_Unary(SDNode *N);
923  SDValue WidenVecRes_InregOp(SDNode *N);
924 
925  // Widen Vector Operand.
926  bool WidenVectorOperand(SDNode *N, unsigned OpNo);
927  SDValue WidenVecOp_BITCAST(SDNode *N);
928  SDValue WidenVecOp_CONCAT_VECTORS(SDNode *N);
929  SDValue WidenVecOp_EXTEND(SDNode *N);
930  SDValue WidenVecOp_EXTRACT_VECTOR_ELT(SDNode *N);
931  SDValue WidenVecOp_INSERT_SUBVECTOR(SDNode *N);
932  SDValue WidenVecOp_EXTRACT_SUBVECTOR(SDNode *N);
933  SDValue WidenVecOp_STORE(SDNode* N);
934  SDValue WidenVecOp_MSTORE(SDNode* N, unsigned OpNo);
935  SDValue WidenVecOp_MGATHER(SDNode* N, unsigned OpNo);
936  SDValue WidenVecOp_MSCATTER(SDNode* N, unsigned OpNo);
937  SDValue WidenVecOp_SETCC(SDNode* N);
938  SDValue WidenVecOp_STRICT_FSETCC(SDNode* N);
939  SDValue WidenVecOp_VSELECT(SDNode *N);
940 
941  SDValue WidenVecOp_Convert(SDNode *N);
942  SDValue WidenVecOp_FP_TO_XINT_SAT(SDNode *N);
943  SDValue WidenVecOp_FCOPYSIGN(SDNode *N);
944  SDValue WidenVecOp_VECREDUCE(SDNode *N);
945  SDValue WidenVecOp_VECREDUCE_SEQ(SDNode *N);
946 
947  /// Helper function to generate a set of operations to perform
948  /// a vector operation for a wider type.
949  ///
950  SDValue UnrollVectorOp_StrictFP(SDNode *N, unsigned ResNE);
951 
952  //===--------------------------------------------------------------------===//
953  // Vector Widening Utilities Support: LegalizeVectorTypes.cpp
954  //===--------------------------------------------------------------------===//
955 
956  /// Helper function to generate a set of loads to load a vector with a
957  /// resulting wider type. It takes:
958  /// LdChain: list of chains for the load to be generated.
959  /// Ld: load to widen
960  SDValue GenWidenVectorLoads(SmallVectorImpl<SDValue> &LdChain,
961  LoadSDNode *LD);
962 
963  /// Helper function to generate a set of extension loads to load a vector with
964  /// a resulting wider type. It takes:
965  /// LdChain: list of chains for the load to be generated.
966  /// Ld: load to widen
967  /// ExtType: extension element type
968  SDValue GenWidenVectorExtLoads(SmallVectorImpl<SDValue> &LdChain,
969  LoadSDNode *LD, ISD::LoadExtType ExtType);
970 
971  /// Helper function to generate a set of stores to store a widen vector into
972  /// non-widen memory.
973  /// StChain: list of chains for the stores we have generated
974  /// ST: store of a widen value
975  void GenWidenVectorStores(SmallVectorImpl<SDValue> &StChain, StoreSDNode *ST);
976 
977  /// Modifies a vector input (widen or narrows) to a vector of NVT. The
978  /// input vector must have the same element type as NVT.
979  /// When FillWithZeroes is "on" the vector will be widened with zeroes.
980  /// By default, the vector will be widened with undefined values.
981  SDValue ModifyToType(SDValue InOp, EVT NVT, bool FillWithZeroes = false);
982 
983  /// Return a mask of vector type MaskVT to replace InMask. Also adjust
984  /// MaskVT to ToMaskVT if needed with vector extension or truncation.
985  SDValue convertMask(SDValue InMask, EVT MaskVT, EVT ToMaskVT);
986 
987  //===--------------------------------------------------------------------===//
988  // Generic Splitting: LegalizeTypesGeneric.cpp
989  //===--------------------------------------------------------------------===//
990 
991  // Legalization methods which only use that the illegal type is split into two
992  // not necessarily identical types. As such they can be used for splitting
993  // vectors and expanding integers and floats.
994 
995  void GetSplitOp(SDValue Op, SDValue &Lo, SDValue &Hi) {
996  if (Op.getValueType().isVector())
997  GetSplitVector(Op, Lo, Hi);
998  else if (Op.getValueType().isInteger())
999  GetExpandedInteger(Op, Lo, Hi);
1000  else
1001  GetExpandedFloat(Op, Lo, Hi);
1002  }
1003 
1004  /// Use ISD::EXTRACT_ELEMENT nodes to extract the low and high parts of the
1005  /// given value.
1006  void GetPairElements(SDValue Pair, SDValue &Lo, SDValue &Hi);
1007 
1008  // Generic Result Splitting.
1009  void SplitRes_MERGE_VALUES(SDNode *N, unsigned ResNo,
1010  SDValue &Lo, SDValue &Hi);
1011  void SplitRes_SELECT (SDNode *N, SDValue &Lo, SDValue &Hi);
1012  void SplitRes_SELECT_CC (SDNode *N, SDValue &Lo, SDValue &Hi);
1013  void SplitRes_UNDEF (SDNode *N, SDValue &Lo, SDValue &Hi);
1014  void SplitRes_FREEZE (SDNode *N, SDValue &Lo, SDValue &Hi);
1015 
1016  //===--------------------------------------------------------------------===//
1017  // Generic Expansion: LegalizeTypesGeneric.cpp
1018  //===--------------------------------------------------------------------===//
1019 
1020  // Legalization methods which only use that the illegal type is split into two
1021  // identical types of half the size, and that the Lo/Hi part is stored first
1022  // in memory on little/big-endian machines, followed by the Hi/Lo part. As
1023  // such they can be used for expanding integers and floats.
1024 
1025  void GetExpandedOp(SDValue Op, SDValue &Lo, SDValue &Hi) {
1026  if (Op.getValueType().isInteger())
1027  GetExpandedInteger(Op, Lo, Hi);
1028  else
1029  GetExpandedFloat(Op, Lo, Hi);
1030  }
1031 
1032 
1033  /// This function will split the integer \p Op into \p NumElements
1034  /// operations of type \p EltVT and store them in \p Ops.
1035  void IntegerToVector(SDValue Op, unsigned NumElements,
1036  SmallVectorImpl<SDValue> &Ops, EVT EltVT);
1037 
1038  // Generic Result Expansion.
1039  void ExpandRes_MERGE_VALUES (SDNode *N, unsigned ResNo,
1040  SDValue &Lo, SDValue &Hi);
1041  void ExpandRes_BITCAST (SDNode *N, SDValue &Lo, SDValue &Hi);
1042  void ExpandRes_BUILD_PAIR (SDNode *N, SDValue &Lo, SDValue &Hi);
1043  void ExpandRes_EXTRACT_ELEMENT (SDNode *N, SDValue &Lo, SDValue &Hi);
1044  void ExpandRes_EXTRACT_VECTOR_ELT(SDNode *N, SDValue &Lo, SDValue &Hi);
1045  void ExpandRes_NormalLoad (SDNode *N, SDValue &Lo, SDValue &Hi);
1046  void ExpandRes_VAARG (SDNode *N, SDValue &Lo, SDValue &Hi);
1047 
1048  // Generic Operand Expansion.
1049  SDValue ExpandOp_BITCAST (SDNode *N);
1050  SDValue ExpandOp_BUILD_VECTOR (SDNode *N);
1051  SDValue ExpandOp_EXTRACT_ELEMENT (SDNode *N);
1052  SDValue ExpandOp_INSERT_VECTOR_ELT(SDNode *N);
1053  SDValue ExpandOp_SCALAR_TO_VECTOR (SDNode *N);
1054  SDValue ExpandOp_NormalStore (SDNode *N, unsigned OpNo);
1055 };
1056 
1057 } // end namespace llvm.
1058 
1059 #endif
i
i
Definition: README.txt:29
llvm
Definition: AllocatorList.h:23
llvm::SDValue::getNode
SDNode * getNode() const
get the SDNode which holds the desired result
Definition: SelectionDAGNodes.h:152
llvm::SelectionDAG::getValueType
SDValue getValueType(EVT)
Definition: SelectionDAG.cpp:1697
llvm::ARM_MB::LD
@ LD
Definition: ARMBaseInfo.h:72
llvm::MipsISD::Lo
@ Lo
Definition: MipsISelLowering.h:79
llvm::SDNode
Represents one node in the SelectionDAG.
Definition: SelectionDAGNodes.h:455
llvm::RTLIB::Libcall
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit.
Definition: RuntimeLibcalls.h:30
DenseMap.h
llvm::SelectionDAG::getZeroExtendInReg
SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT)
Return the expression required to zero extend the Op value assuming it was the smaller SrcTy value.
Definition: SelectionDAG.cpp:1289
llvm::DAGTypeLegalizer::NodeIdFlags
NodeIdFlags
This pass uses the NodeId on the SDNodes to hold information about the state of the node.
Definition: LegalizeTypes.h:37
SelectionDAG.h
llvm::DAGTypeLegalizer::getDAG
SelectionDAG & getDAG() const
Definition: LegalizeTypes.h:208
llvm::SelectionDAG::getContext
LLVMContext * getContext() const
Definition: SelectionDAG.h:447
llvm::MipsISD::Hi
@ Hi
Definition: MipsISelLowering.h:75
llvm::DAGTypeLegalizer
This takes an arbitrary SelectionDAG as input and hacks on it until only value types the target machi...
Definition: LegalizeTypes.h:31
llvm::ISD::LoadExtType
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
Definition: ISDOpcodes.h:1321
TargetLowering.h
llvm::SelectionDAG
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:216
llvm::ISD::SIGN_EXTEND_INREG
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:737
llvm::EVT
Extended Value Type.
Definition: ValueTypes.h:35
llvm::DAGTypeLegalizer::NoteDeletion
void NoteDeletion(SDNode *Old, SDNode *New)
Definition: LegalizeTypes.h:180
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition: TargetLowering.h:3158
llvm::TargetLoweringBase::ValueTypeActionImpl
Definition: TargetLowering.h:901
llvm::ISD::Register
@ Register
Definition: ISDOpcodes.h:67
llvm::TargetLoweringBase::ValueTypeActionImpl::getTypeAction
LegalizeTypeAction getTypeAction(MVT VT) const
Definition: TargetLowering.h:912
llvm::MVT::MAX_ALLOWED_VALUETYPE
@ MAX_ALLOWED_VALUETYPE
Definition: MachineValueType.h:268
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::SelectionDAG::getNode
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
Definition: SelectionDAG.cpp:7845
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ISD::CondCode
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition: ISDOpcodes.h:1341
Compiler.h
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
LLVM_LIBRARY_VISIBILITY
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library,...
Definition: Compiler.h:131
Node
Definition: ItaniumDemangle.h:114
llvm::TargetLoweringBase::TypeLegal
@ TypeLegal
Definition: TargetLowering.h:206
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
llvm::SelectionDAG::getDataLayout
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:440
llvm::TargetLoweringBase::LegalizeTypeAction
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
Definition: TargetLowering.h:205
llvm::SDValue
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
Definition: SelectionDAGNodes.h:138
llvm::ISD::TargetConstant
@ TargetConstant
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification,...
Definition: ISDOpcodes.h:151
llvm::SDNode::getNumValues
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
Definition: SelectionDAGNodes.h:955
N
#define N
llvm::MVT::LAST_VALUETYPE
@ LAST_VALUETYPE
Definition: MachineValueType.h:262
llvm::DAGTypeLegalizer::DAGTypeLegalizer
DAGTypeLegalizer(SelectionDAG &dag)
Definition: LegalizeTypes.h:168
From
BlockVerifier::State From
Definition: BlockVerifier.cpp:55
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:221
Debug.h