LegalizeTypes.h revision 360784
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"
19#include "llvm/CodeGen/SelectionDAG.h"
20#include "llvm/CodeGen/TargetLowering.h"
21#include "llvm/Support/Compiler.h"
22#include "llvm/Support/Debug.h"
23
24namespace 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///
31class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
32  const TargetLowering &TLI;
33  SelectionDAG &DAG;
34public:
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  };
54private:
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 float nodes that need to be expanded this map indicates which operands
113  /// are the expanded version of the input.
114  SmallDenseMap<TableId, std::pair<TableId, TableId>, 8> ExpandedFloats;
115
116  /// For nodes that are <1 x ty>, this map indicates the scalar value of type
117  /// 'ty' to use.
118  SmallDenseMap<TableId, TableId, 8> ScalarizedVectors;
119
120  /// For nodes that need to be split this map indicates which operands are the
121  /// expanded version of the input.
122  SmallDenseMap<TableId, std::pair<TableId, TableId>, 8> SplitVectors;
123
124  /// For vector nodes that need to be widened, indicates the widened value to
125  /// use.
126  SmallDenseMap<TableId, TableId, 8> WidenedVectors;
127
128  /// For values that have been replaced with another, indicates the replacement
129  /// value to use.
130  SmallDenseMap<TableId, TableId, 8> ReplacedValues;
131
132  /// This defines a worklist of nodes to process. In order to be pushed onto
133  /// this worklist, all operands of a node must have already been processed.
134  SmallVector<SDNode*, 128> Worklist;
135
136  TableId getTableId(SDValue V) {
137    assert(V.getNode() && "Getting TableId on SDValue()");
138
139    auto I = ValueToIdMap.find(V);
140    if (I != ValueToIdMap.end()) {
141      // replace if there's been a shift.
142      RemapId(I->second);
143      assert(I->second && "All Ids should be nonzero");
144      return I->second;
145    }
146    // Add if it's not there.
147    ValueToIdMap.insert(std::make_pair(V, NextValueId));
148    IdToValueMap.insert(std::make_pair(NextValueId, V));
149    ++NextValueId;
150    assert(NextValueId != 0 &&
151           "Ran out of Ids. Increase id type size or add compactification");
152    return NextValueId - 1;
153  }
154
155  const SDValue &getSDValue(TableId &Id) {
156    RemapId(Id);
157    assert(Id && "TableId should be non-zero");
158    return IdToValueMap[Id];
159  }
160
161public:
162  explicit DAGTypeLegalizer(SelectionDAG &dag)
163    : TLI(dag.getTargetLoweringInfo()), DAG(dag),
164    ValueTypeActions(TLI.getValueTypeActions()) {
165    static_assert(MVT::LAST_VALUETYPE <= MVT::MAX_ALLOWED_VALUETYPE,
166                  "Too many value types for ValueTypeActions to hold!");
167  }
168
169  /// This is the main entry point for the type legalizer.  This does a
170  /// top-down traversal of the dag, legalizing types as it goes.  Returns
171  /// "true" if it made any changes.
172  bool run();
173
174  void NoteDeletion(SDNode *Old, SDNode *New) {
175    for (unsigned i = 0, e = Old->getNumValues(); i != e; ++i) {
176      TableId NewId = getTableId(SDValue(New, i));
177      TableId OldId = getTableId(SDValue(Old, i));
178
179      if (OldId != NewId)
180        ReplacedValues[OldId] = NewId;
181
182      // Delete Node from tables.
183      ValueToIdMap.erase(SDValue(Old, i));
184      IdToValueMap.erase(OldId);
185      PromotedIntegers.erase(OldId);
186      ExpandedIntegers.erase(OldId);
187      SoftenedFloats.erase(OldId);
188      PromotedFloats.erase(OldId);
189      ExpandedFloats.erase(OldId);
190      ScalarizedVectors.erase(OldId);
191      SplitVectors.erase(OldId);
192      WidenedVectors.erase(OldId);
193    }
194  }
195
196  SelectionDAG &getDAG() const { return DAG; }
197
198private:
199  SDNode *AnalyzeNewNode(SDNode *N);
200  void AnalyzeNewValue(SDValue &Val);
201  void PerformExpensiveChecks();
202  void RemapId(TableId &Id);
203  void RemapValue(SDValue &V);
204
205  // Common routines.
206  SDValue BitConvertToInteger(SDValue Op);
207  SDValue BitConvertVectorToIntegerVector(SDValue Op);
208  SDValue CreateStackStoreLoad(SDValue Op, EVT DestVT);
209  bool CustomLowerNode(SDNode *N, EVT VT, bool LegalizeResult);
210  bool CustomWidenLowerNode(SDNode *N, EVT VT);
211
212  /// Replace each result of the given MERGE_VALUES node with the corresponding
213  /// input operand, except for the result 'ResNo', for which the corresponding
214  /// input operand is returned.
215  SDValue DisintegrateMERGE_VALUES(SDNode *N, unsigned ResNo);
216
217  SDValue JoinIntegers(SDValue Lo, SDValue Hi);
218
219  std::pair<SDValue, SDValue> ExpandAtomic(SDNode *Node);
220
221  SDValue PromoteTargetBoolean(SDValue Bool, EVT ValVT);
222
223  void ReplaceValueWith(SDValue From, SDValue To);
224  void SplitInteger(SDValue Op, SDValue &Lo, SDValue &Hi);
225  void SplitInteger(SDValue Op, EVT LoVT, EVT HiVT,
226                    SDValue &Lo, SDValue &Hi);
227
228  //===--------------------------------------------------------------------===//
229  // Integer Promotion Support: LegalizeIntegerTypes.cpp
230  //===--------------------------------------------------------------------===//
231
232  /// Given a processed operand Op which was promoted to a larger integer type,
233  /// this returns the promoted value. The low bits of the promoted value
234  /// corresponding to the original type are exactly equal to Op.
235  /// The extra bits contain rubbish, so the promoted value may need to be zero-
236  /// or sign-extended from the original type before it is usable (the helpers
237  /// SExtPromotedInteger and ZExtPromotedInteger can do this for you).
238  /// For example, if Op is an i16 and was promoted to an i32, then this method
239  /// returns an i32, the lower 16 bits of which coincide with Op, and the upper
240  /// 16 bits of which contain rubbish.
241  SDValue GetPromotedInteger(SDValue Op) {
242    TableId &PromotedId = PromotedIntegers[getTableId(Op)];
243    SDValue PromotedOp = getSDValue(PromotedId);
244    assert(PromotedOp.getNode() && "Operand wasn't promoted?");
245    return PromotedOp;
246  }
247  void SetPromotedInteger(SDValue Op, SDValue Result);
248
249  /// Get a promoted operand and sign extend it to the final size.
250  SDValue SExtPromotedInteger(SDValue Op) {
251    EVT OldVT = Op.getValueType();
252    SDLoc dl(Op);
253    Op = GetPromotedInteger(Op);
254    return DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, Op.getValueType(), Op,
255                       DAG.getValueType(OldVT));
256  }
257
258  /// Get a promoted operand and zero extend it to the final size.
259  SDValue ZExtPromotedInteger(SDValue Op) {
260    EVT OldVT = Op.getValueType();
261    SDLoc dl(Op);
262    Op = GetPromotedInteger(Op);
263    return DAG.getZeroExtendInReg(Op, dl, OldVT.getScalarType());
264  }
265
266  // Get a promoted operand and sign or zero extend it to the final size
267  // (depending on TargetLoweringInfo::isSExtCheaperThanZExt). For a given
268  // subtarget and type, the choice of sign or zero-extension will be
269  // consistent.
270  SDValue SExtOrZExtPromotedInteger(SDValue Op) {
271    EVT OldVT = Op.getValueType();
272    SDLoc DL(Op);
273    Op = GetPromotedInteger(Op);
274    if (TLI.isSExtCheaperThanZExt(OldVT, Op.getValueType()))
275      return DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, Op.getValueType(), Op,
276                         DAG.getValueType(OldVT));
277    return DAG.getZeroExtendInReg(Op, DL, OldVT.getScalarType());
278  }
279
280  // Integer Result Promotion.
281  void PromoteIntegerResult(SDNode *N, unsigned ResNo);
282  SDValue PromoteIntRes_MERGE_VALUES(SDNode *N, unsigned ResNo);
283  SDValue PromoteIntRes_AssertSext(SDNode *N);
284  SDValue PromoteIntRes_AssertZext(SDNode *N);
285  SDValue PromoteIntRes_Atomic0(AtomicSDNode *N);
286  SDValue PromoteIntRes_Atomic1(AtomicSDNode *N);
287  SDValue PromoteIntRes_AtomicCmpSwap(AtomicSDNode *N, unsigned ResNo);
288  SDValue PromoteIntRes_EXTRACT_SUBVECTOR(SDNode *N);
289  SDValue PromoteIntRes_VECTOR_SHUFFLE(SDNode *N);
290  SDValue PromoteIntRes_BUILD_VECTOR(SDNode *N);
291  SDValue PromoteIntRes_SCALAR_TO_VECTOR(SDNode *N);
292  SDValue PromoteIntRes_SPLAT_VECTOR(SDNode *N);
293  SDValue PromoteIntRes_EXTEND_VECTOR_INREG(SDNode *N);
294  SDValue PromoteIntRes_INSERT_VECTOR_ELT(SDNode *N);
295  SDValue PromoteIntRes_CONCAT_VECTORS(SDNode *N);
296  SDValue PromoteIntRes_BITCAST(SDNode *N);
297  SDValue PromoteIntRes_BSWAP(SDNode *N);
298  SDValue PromoteIntRes_BITREVERSE(SDNode *N);
299  SDValue PromoteIntRes_BUILD_PAIR(SDNode *N);
300  SDValue PromoteIntRes_Constant(SDNode *N);
301  SDValue PromoteIntRes_CTLZ(SDNode *N);
302  SDValue PromoteIntRes_CTPOP(SDNode *N);
303  SDValue PromoteIntRes_CTTZ(SDNode *N);
304  SDValue PromoteIntRes_EXTRACT_VECTOR_ELT(SDNode *N);
305  SDValue PromoteIntRes_FP_TO_XINT(SDNode *N);
306  SDValue PromoteIntRes_FP_TO_FP16(SDNode *N);
307  SDValue PromoteIntRes_INT_EXTEND(SDNode *N);
308  SDValue PromoteIntRes_LOAD(LoadSDNode *N);
309  SDValue PromoteIntRes_MLOAD(MaskedLoadSDNode *N);
310  SDValue PromoteIntRes_MGATHER(MaskedGatherSDNode *N);
311  SDValue PromoteIntRes_Overflow(SDNode *N);
312  SDValue PromoteIntRes_SADDSUBO(SDNode *N, unsigned ResNo);
313  SDValue PromoteIntRes_SELECT(SDNode *N);
314  SDValue PromoteIntRes_VSELECT(SDNode *N);
315  SDValue PromoteIntRes_SELECT_CC(SDNode *N);
316  SDValue PromoteIntRes_SETCC(SDNode *N);
317  SDValue PromoteIntRes_SHL(SDNode *N);
318  SDValue PromoteIntRes_SimpleIntBinOp(SDNode *N);
319  SDValue PromoteIntRes_ZExtIntBinOp(SDNode *N);
320  SDValue PromoteIntRes_SExtIntBinOp(SDNode *N);
321  SDValue PromoteIntRes_SIGN_EXTEND_INREG(SDNode *N);
322  SDValue PromoteIntRes_SRA(SDNode *N);
323  SDValue PromoteIntRes_SRL(SDNode *N);
324  SDValue PromoteIntRes_TRUNCATE(SDNode *N);
325  SDValue PromoteIntRes_UADDSUBO(SDNode *N, unsigned ResNo);
326  SDValue PromoteIntRes_ADDSUBCARRY(SDNode *N, unsigned ResNo);
327  SDValue PromoteIntRes_UNDEF(SDNode *N);
328  SDValue PromoteIntRes_VAARG(SDNode *N);
329  SDValue PromoteIntRes_XMULO(SDNode *N, unsigned ResNo);
330  SDValue PromoteIntRes_ADDSUBSAT(SDNode *N);
331  SDValue PromoteIntRes_MULFIX(SDNode *N);
332  SDValue PromoteIntRes_DIVFIX(SDNode *N);
333  SDValue PromoteIntRes_FLT_ROUNDS(SDNode *N);
334  SDValue PromoteIntRes_VECREDUCE(SDNode *N);
335  SDValue PromoteIntRes_ABS(SDNode *N);
336
337  // Integer Operand Promotion.
338  bool PromoteIntegerOperand(SDNode *N, unsigned OpNo);
339  SDValue PromoteIntOp_ANY_EXTEND(SDNode *N);
340  SDValue PromoteIntOp_ATOMIC_STORE(AtomicSDNode *N);
341  SDValue PromoteIntOp_BITCAST(SDNode *N);
342  SDValue PromoteIntOp_BUILD_PAIR(SDNode *N);
343  SDValue PromoteIntOp_BR_CC(SDNode *N, unsigned OpNo);
344  SDValue PromoteIntOp_BRCOND(SDNode *N, unsigned OpNo);
345  SDValue PromoteIntOp_BUILD_VECTOR(SDNode *N);
346  SDValue PromoteIntOp_INSERT_VECTOR_ELT(SDNode *N, unsigned OpNo);
347  SDValue PromoteIntOp_EXTRACT_VECTOR_ELT(SDNode *N);
348  SDValue PromoteIntOp_EXTRACT_SUBVECTOR(SDNode *N);
349  SDValue PromoteIntOp_CONCAT_VECTORS(SDNode *N);
350  SDValue PromoteIntOp_SCALAR_TO_VECTOR(SDNode *N);
351  SDValue PromoteIntOp_SPLAT_VECTOR(SDNode *N);
352  SDValue PromoteIntOp_SELECT(SDNode *N, unsigned OpNo);
353  SDValue PromoteIntOp_SELECT_CC(SDNode *N, unsigned OpNo);
354  SDValue PromoteIntOp_SETCC(SDNode *N, unsigned OpNo);
355  SDValue PromoteIntOp_Shift(SDNode *N);
356  SDValue PromoteIntOp_SIGN_EXTEND(SDNode *N);
357  SDValue PromoteIntOp_SINT_TO_FP(SDNode *N);
358  SDValue PromoteIntOp_STRICT_SINT_TO_FP(SDNode *N);
359  SDValue PromoteIntOp_STORE(StoreSDNode *N, unsigned OpNo);
360  SDValue PromoteIntOp_TRUNCATE(SDNode *N);
361  SDValue PromoteIntOp_UINT_TO_FP(SDNode *N);
362  SDValue PromoteIntOp_STRICT_UINT_TO_FP(SDNode *N);
363  SDValue PromoteIntOp_ZERO_EXTEND(SDNode *N);
364  SDValue PromoteIntOp_MSTORE(MaskedStoreSDNode *N, unsigned OpNo);
365  SDValue PromoteIntOp_MLOAD(MaskedLoadSDNode *N, unsigned OpNo);
366  SDValue PromoteIntOp_MSCATTER(MaskedScatterSDNode *N, unsigned OpNo);
367  SDValue PromoteIntOp_MGATHER(MaskedGatherSDNode *N, unsigned OpNo);
368  SDValue PromoteIntOp_ADDSUBCARRY(SDNode *N, unsigned OpNo);
369  SDValue PromoteIntOp_FRAMERETURNADDR(SDNode *N);
370  SDValue PromoteIntOp_PREFETCH(SDNode *N, unsigned OpNo);
371  SDValue PromoteIntOp_FIX(SDNode *N);
372  SDValue PromoteIntOp_FPOWI(SDNode *N);
373  SDValue PromoteIntOp_VECREDUCE(SDNode *N);
374
375  void PromoteSetCCOperands(SDValue &LHS,SDValue &RHS, ISD::CondCode Code);
376
377  //===--------------------------------------------------------------------===//
378  // Integer Expansion Support: LegalizeIntegerTypes.cpp
379  //===--------------------------------------------------------------------===//
380
381  /// Given a processed operand Op which was expanded into two integers of half
382  /// the size, this returns the two halves. The low bits of Op are exactly
383  /// equal to the bits of Lo; the high bits exactly equal Hi.
384  /// For example, if Op is an i64 which was expanded into two i32's, then this
385  /// method returns the two i32's, with Lo being equal to the lower 32 bits of
386  /// Op, and Hi being equal to the upper 32 bits.
387  void GetExpandedInteger(SDValue Op, SDValue &Lo, SDValue &Hi);
388  void SetExpandedInteger(SDValue Op, SDValue Lo, SDValue Hi);
389
390  // Integer Result Expansion.
391  void ExpandIntegerResult(SDNode *N, unsigned ResNo);
392  void ExpandIntRes_ANY_EXTEND        (SDNode *N, SDValue &Lo, SDValue &Hi);
393  void ExpandIntRes_AssertSext        (SDNode *N, SDValue &Lo, SDValue &Hi);
394  void ExpandIntRes_AssertZext        (SDNode *N, SDValue &Lo, SDValue &Hi);
395  void ExpandIntRes_Constant          (SDNode *N, SDValue &Lo, SDValue &Hi);
396  void ExpandIntRes_ABS               (SDNode *N, SDValue &Lo, SDValue &Hi);
397  void ExpandIntRes_CTLZ              (SDNode *N, SDValue &Lo, SDValue &Hi);
398  void ExpandIntRes_CTPOP             (SDNode *N, SDValue &Lo, SDValue &Hi);
399  void ExpandIntRes_CTTZ              (SDNode *N, SDValue &Lo, SDValue &Hi);
400  void ExpandIntRes_LOAD          (LoadSDNode *N, SDValue &Lo, SDValue &Hi);
401  void ExpandIntRes_READCYCLECOUNTER  (SDNode *N, SDValue &Lo, SDValue &Hi);
402  void ExpandIntRes_SIGN_EXTEND       (SDNode *N, SDValue &Lo, SDValue &Hi);
403  void ExpandIntRes_SIGN_EXTEND_INREG (SDNode *N, SDValue &Lo, SDValue &Hi);
404  void ExpandIntRes_TRUNCATE          (SDNode *N, SDValue &Lo, SDValue &Hi);
405  void ExpandIntRes_ZERO_EXTEND       (SDNode *N, SDValue &Lo, SDValue &Hi);
406  void ExpandIntRes_FLT_ROUNDS        (SDNode *N, SDValue &Lo, SDValue &Hi);
407  void ExpandIntRes_FP_TO_SINT        (SDNode *N, SDValue &Lo, SDValue &Hi);
408  void ExpandIntRes_FP_TO_UINT        (SDNode *N, SDValue &Lo, SDValue &Hi);
409  void ExpandIntRes_LLROUND_LLRINT    (SDNode *N, SDValue &Lo, SDValue &Hi);
410
411  void ExpandIntRes_Logical           (SDNode *N, SDValue &Lo, SDValue &Hi);
412  void ExpandIntRes_ADDSUB            (SDNode *N, SDValue &Lo, SDValue &Hi);
413  void ExpandIntRes_ADDSUBC           (SDNode *N, SDValue &Lo, SDValue &Hi);
414  void ExpandIntRes_ADDSUBE           (SDNode *N, SDValue &Lo, SDValue &Hi);
415  void ExpandIntRes_ADDSUBCARRY       (SDNode *N, SDValue &Lo, SDValue &Hi);
416  void ExpandIntRes_BITREVERSE        (SDNode *N, SDValue &Lo, SDValue &Hi);
417  void ExpandIntRes_BSWAP             (SDNode *N, SDValue &Lo, SDValue &Hi);
418  void ExpandIntRes_MUL               (SDNode *N, SDValue &Lo, SDValue &Hi);
419  void ExpandIntRes_SDIV              (SDNode *N, SDValue &Lo, SDValue &Hi);
420  void ExpandIntRes_SREM              (SDNode *N, SDValue &Lo, SDValue &Hi);
421  void ExpandIntRes_UDIV              (SDNode *N, SDValue &Lo, SDValue &Hi);
422  void ExpandIntRes_UREM              (SDNode *N, SDValue &Lo, SDValue &Hi);
423  void ExpandIntRes_Shift             (SDNode *N, SDValue &Lo, SDValue &Hi);
424
425  void ExpandIntRes_MINMAX            (SDNode *N, SDValue &Lo, SDValue &Hi);
426
427  void ExpandIntRes_SADDSUBO          (SDNode *N, SDValue &Lo, SDValue &Hi);
428  void ExpandIntRes_UADDSUBO          (SDNode *N, SDValue &Lo, SDValue &Hi);
429  void ExpandIntRes_XMULO             (SDNode *N, SDValue &Lo, SDValue &Hi);
430  void ExpandIntRes_ADDSUBSAT         (SDNode *N, SDValue &Lo, SDValue &Hi);
431  void ExpandIntRes_MULFIX            (SDNode *N, SDValue &Lo, SDValue &Hi);
432  void ExpandIntRes_DIVFIX            (SDNode *N, SDValue &Lo, SDValue &Hi);
433
434  void ExpandIntRes_ATOMIC_LOAD       (SDNode *N, SDValue &Lo, SDValue &Hi);
435  void ExpandIntRes_VECREDUCE         (SDNode *N, SDValue &Lo, SDValue &Hi);
436
437  void ExpandShiftByConstant(SDNode *N, const APInt &Amt,
438                             SDValue &Lo, SDValue &Hi);
439  bool ExpandShiftWithKnownAmountBit(SDNode *N, SDValue &Lo, SDValue &Hi);
440  bool ExpandShiftWithUnknownAmountBit(SDNode *N, SDValue &Lo, SDValue &Hi);
441
442  // Integer Operand Expansion.
443  bool ExpandIntegerOperand(SDNode *N, unsigned OpNo);
444  SDValue ExpandIntOp_BR_CC(SDNode *N);
445  SDValue ExpandIntOp_SELECT_CC(SDNode *N);
446  SDValue ExpandIntOp_SETCC(SDNode *N);
447  SDValue ExpandIntOp_SETCCCARRY(SDNode *N);
448  SDValue ExpandIntOp_Shift(SDNode *N);
449  SDValue ExpandIntOp_SINT_TO_FP(SDNode *N);
450  SDValue ExpandIntOp_STORE(StoreSDNode *N, unsigned OpNo);
451  SDValue ExpandIntOp_TRUNCATE(SDNode *N);
452  SDValue ExpandIntOp_UINT_TO_FP(SDNode *N);
453  SDValue ExpandIntOp_RETURNADDR(SDNode *N);
454  SDValue ExpandIntOp_ATOMIC_STORE(SDNode *N);
455
456  void IntegerExpandSetCCOperands(SDValue &NewLHS, SDValue &NewRHS,
457                                  ISD::CondCode &CCCode, const SDLoc &dl);
458
459  //===--------------------------------------------------------------------===//
460  // Float to Integer Conversion Support: LegalizeFloatTypes.cpp
461  //===--------------------------------------------------------------------===//
462
463  /// GetSoftenedFloat - Given a processed operand Op which was converted to an
464  /// integer of the same size, this returns the integer.  The integer contains
465  /// exactly the same bits as Op - only the type changed.  For example, if Op
466  /// is an f32 which was softened to an i32, then this method returns an i32,
467  /// the bits of which coincide with those of Op
468  SDValue GetSoftenedFloat(SDValue Op) {
469    TableId Id = getTableId(Op);
470    auto Iter = SoftenedFloats.find(Id);
471    if (Iter == SoftenedFloats.end()) {
472      assert(isSimpleLegalType(Op.getValueType()) &&
473             "Operand wasn't converted to integer?");
474      return Op;
475    }
476    SDValue SoftenedOp = getSDValue(Iter->second);
477    assert(SoftenedOp.getNode() && "Unconverted op in SoftenedFloats?");
478    return SoftenedOp;
479  }
480  void SetSoftenedFloat(SDValue Op, SDValue Result);
481
482  // Convert Float Results to Integer.
483  void SoftenFloatResult(SDNode *N, unsigned ResNo);
484  SDValue SoftenFloatRes_Unary(SDNode *N, RTLIB::Libcall LC);
485  SDValue SoftenFloatRes_Binary(SDNode *N, RTLIB::Libcall LC);
486  SDValue SoftenFloatRes_MERGE_VALUES(SDNode *N, unsigned ResNo);
487  SDValue SoftenFloatRes_BITCAST(SDNode *N);
488  SDValue SoftenFloatRes_BUILD_PAIR(SDNode *N);
489  SDValue SoftenFloatRes_ConstantFP(SDNode *N);
490  SDValue SoftenFloatRes_EXTRACT_VECTOR_ELT(SDNode *N, unsigned ResNo);
491  SDValue SoftenFloatRes_FABS(SDNode *N);
492  SDValue SoftenFloatRes_FMINNUM(SDNode *N);
493  SDValue SoftenFloatRes_FMAXNUM(SDNode *N);
494  SDValue SoftenFloatRes_FADD(SDNode *N);
495  SDValue SoftenFloatRes_FCBRT(SDNode *N);
496  SDValue SoftenFloatRes_FCEIL(SDNode *N);
497  SDValue SoftenFloatRes_FCOPYSIGN(SDNode *N);
498  SDValue SoftenFloatRes_FCOS(SDNode *N);
499  SDValue SoftenFloatRes_FDIV(SDNode *N);
500  SDValue SoftenFloatRes_FEXP(SDNode *N);
501  SDValue SoftenFloatRes_FEXP2(SDNode *N);
502  SDValue SoftenFloatRes_FFLOOR(SDNode *N);
503  SDValue SoftenFloatRes_FLOG(SDNode *N);
504  SDValue SoftenFloatRes_FLOG2(SDNode *N);
505  SDValue SoftenFloatRes_FLOG10(SDNode *N);
506  SDValue SoftenFloatRes_FMA(SDNode *N);
507  SDValue SoftenFloatRes_FMUL(SDNode *N);
508  SDValue SoftenFloatRes_FNEARBYINT(SDNode *N);
509  SDValue SoftenFloatRes_FNEG(SDNode *N);
510  SDValue SoftenFloatRes_FP_EXTEND(SDNode *N);
511  SDValue SoftenFloatRes_FP16_TO_FP(SDNode *N);
512  SDValue SoftenFloatRes_FP_ROUND(SDNode *N);
513  SDValue SoftenFloatRes_FPOW(SDNode *N);
514  SDValue SoftenFloatRes_FPOWI(SDNode *N);
515  SDValue SoftenFloatRes_FREM(SDNode *N);
516  SDValue SoftenFloatRes_FRINT(SDNode *N);
517  SDValue SoftenFloatRes_FROUND(SDNode *N);
518  SDValue SoftenFloatRes_FSIN(SDNode *N);
519  SDValue SoftenFloatRes_FSQRT(SDNode *N);
520  SDValue SoftenFloatRes_FSUB(SDNode *N);
521  SDValue SoftenFloatRes_FTRUNC(SDNode *N);
522  SDValue SoftenFloatRes_LOAD(SDNode *N);
523  SDValue SoftenFloatRes_SELECT(SDNode *N);
524  SDValue SoftenFloatRes_SELECT_CC(SDNode *N);
525  SDValue SoftenFloatRes_UNDEF(SDNode *N);
526  SDValue SoftenFloatRes_VAARG(SDNode *N);
527  SDValue SoftenFloatRes_XINT_TO_FP(SDNode *N);
528
529  // Convert Float Operand to Integer.
530  bool SoftenFloatOperand(SDNode *N, unsigned OpNo);
531  SDValue SoftenFloatOp_Unary(SDNode *N, RTLIB::Libcall LC);
532  SDValue SoftenFloatOp_BITCAST(SDNode *N);
533  SDValue SoftenFloatOp_BR_CC(SDNode *N);
534  SDValue SoftenFloatOp_FP_ROUND(SDNode *N);
535  SDValue SoftenFloatOp_FP_TO_XINT(SDNode *N);
536  SDValue SoftenFloatOp_LROUND(SDNode *N);
537  SDValue SoftenFloatOp_LLROUND(SDNode *N);
538  SDValue SoftenFloatOp_LRINT(SDNode *N);
539  SDValue SoftenFloatOp_LLRINT(SDNode *N);
540  SDValue SoftenFloatOp_SELECT_CC(SDNode *N);
541  SDValue SoftenFloatOp_SETCC(SDNode *N);
542  SDValue SoftenFloatOp_STORE(SDNode *N, unsigned OpNo);
543  SDValue SoftenFloatOp_FCOPYSIGN(SDNode *N);
544
545  //===--------------------------------------------------------------------===//
546  // Float Expansion Support: LegalizeFloatTypes.cpp
547  //===--------------------------------------------------------------------===//
548
549  /// Given a processed operand Op which was expanded into two floating-point
550  /// values of half the size, this returns the two halves.
551  /// The low bits of Op are exactly equal to the bits of Lo; the high bits
552  /// exactly equal Hi.  For example, if Op is a ppcf128 which was expanded
553  /// into two f64's, then this method returns the two f64's, with Lo being
554  /// equal to the lower 64 bits of Op, and Hi to the upper 64 bits.
555  void GetExpandedFloat(SDValue Op, SDValue &Lo, SDValue &Hi);
556  void SetExpandedFloat(SDValue Op, SDValue Lo, SDValue Hi);
557
558  // Float Result Expansion.
559  void ExpandFloatResult(SDNode *N, unsigned ResNo);
560  void ExpandFloatRes_ConstantFP(SDNode *N, SDValue &Lo, SDValue &Hi);
561  void ExpandFloatRes_Unary(SDNode *N, RTLIB::Libcall LC,
562                            SDValue &Lo, SDValue &Hi);
563  void ExpandFloatRes_Binary(SDNode *N, RTLIB::Libcall LC,
564                             SDValue &Lo, SDValue &Hi);
565  void ExpandFloatRes_FABS      (SDNode *N, SDValue &Lo, SDValue &Hi);
566  void ExpandFloatRes_FMINNUM   (SDNode *N, SDValue &Lo, SDValue &Hi);
567  void ExpandFloatRes_FMAXNUM   (SDNode *N, SDValue &Lo, SDValue &Hi);
568  void ExpandFloatRes_FADD      (SDNode *N, SDValue &Lo, SDValue &Hi);
569  void ExpandFloatRes_FCBRT     (SDNode *N, SDValue &Lo, SDValue &Hi);
570  void ExpandFloatRes_FCEIL     (SDNode *N, SDValue &Lo, SDValue &Hi);
571  void ExpandFloatRes_FCOPYSIGN (SDNode *N, SDValue &Lo, SDValue &Hi);
572  void ExpandFloatRes_FCOS      (SDNode *N, SDValue &Lo, SDValue &Hi);
573  void ExpandFloatRes_FDIV      (SDNode *N, SDValue &Lo, SDValue &Hi);
574  void ExpandFloatRes_FEXP      (SDNode *N, SDValue &Lo, SDValue &Hi);
575  void ExpandFloatRes_FEXP2     (SDNode *N, SDValue &Lo, SDValue &Hi);
576  void ExpandFloatRes_FFLOOR    (SDNode *N, SDValue &Lo, SDValue &Hi);
577  void ExpandFloatRes_FLOG      (SDNode *N, SDValue &Lo, SDValue &Hi);
578  void ExpandFloatRes_FLOG2     (SDNode *N, SDValue &Lo, SDValue &Hi);
579  void ExpandFloatRes_FLOG10    (SDNode *N, SDValue &Lo, SDValue &Hi);
580  void ExpandFloatRes_FMA       (SDNode *N, SDValue &Lo, SDValue &Hi);
581  void ExpandFloatRes_FMUL      (SDNode *N, SDValue &Lo, SDValue &Hi);
582  void ExpandFloatRes_FNEARBYINT(SDNode *N, SDValue &Lo, SDValue &Hi);
583  void ExpandFloatRes_FNEG      (SDNode *N, SDValue &Lo, SDValue &Hi);
584  void ExpandFloatRes_FP_EXTEND (SDNode *N, SDValue &Lo, SDValue &Hi);
585  void ExpandFloatRes_FPOW      (SDNode *N, SDValue &Lo, SDValue &Hi);
586  void ExpandFloatRes_FPOWI     (SDNode *N, SDValue &Lo, SDValue &Hi);
587  void ExpandFloatRes_FREM      (SDNode *N, SDValue &Lo, SDValue &Hi);
588  void ExpandFloatRes_FRINT     (SDNode *N, SDValue &Lo, SDValue &Hi);
589  void ExpandFloatRes_FROUND    (SDNode *N, SDValue &Lo, SDValue &Hi);
590  void ExpandFloatRes_FSIN      (SDNode *N, SDValue &Lo, SDValue &Hi);
591  void ExpandFloatRes_FSQRT     (SDNode *N, SDValue &Lo, SDValue &Hi);
592  void ExpandFloatRes_FSUB      (SDNode *N, SDValue &Lo, SDValue &Hi);
593  void ExpandFloatRes_FTRUNC    (SDNode *N, SDValue &Lo, SDValue &Hi);
594  void ExpandFloatRes_LOAD      (SDNode *N, SDValue &Lo, SDValue &Hi);
595  void ExpandFloatRes_XINT_TO_FP(SDNode *N, SDValue &Lo, SDValue &Hi);
596
597  // Float Operand Expansion.
598  bool ExpandFloatOperand(SDNode *N, unsigned OpNo);
599  SDValue ExpandFloatOp_BR_CC(SDNode *N);
600  SDValue ExpandFloatOp_FCOPYSIGN(SDNode *N);
601  SDValue ExpandFloatOp_FP_ROUND(SDNode *N);
602  SDValue ExpandFloatOp_FP_TO_SINT(SDNode *N);
603  SDValue ExpandFloatOp_FP_TO_UINT(SDNode *N);
604  SDValue ExpandFloatOp_LROUND(SDNode *N);
605  SDValue ExpandFloatOp_LLROUND(SDNode *N);
606  SDValue ExpandFloatOp_LRINT(SDNode *N);
607  SDValue ExpandFloatOp_LLRINT(SDNode *N);
608  SDValue ExpandFloatOp_SELECT_CC(SDNode *N);
609  SDValue ExpandFloatOp_SETCC(SDNode *N);
610  SDValue ExpandFloatOp_STORE(SDNode *N, unsigned OpNo);
611
612  void FloatExpandSetCCOperands(SDValue &NewLHS, SDValue &NewRHS,
613                                ISD::CondCode &CCCode, const SDLoc &dl);
614
615  //===--------------------------------------------------------------------===//
616  // Float promotion support: LegalizeFloatTypes.cpp
617  //===--------------------------------------------------------------------===//
618
619  SDValue GetPromotedFloat(SDValue Op) {
620    TableId &PromotedId = PromotedFloats[getTableId(Op)];
621    SDValue PromotedOp = getSDValue(PromotedId);
622    assert(PromotedOp.getNode() && "Operand wasn't promoted?");
623    return PromotedOp;
624  }
625  void SetPromotedFloat(SDValue Op, SDValue Result);
626
627  void PromoteFloatResult(SDNode *N, unsigned ResNo);
628  SDValue PromoteFloatRes_BITCAST(SDNode *N);
629  SDValue PromoteFloatRes_BinOp(SDNode *N);
630  SDValue PromoteFloatRes_ConstantFP(SDNode *N);
631  SDValue PromoteFloatRes_EXTRACT_VECTOR_ELT(SDNode *N);
632  SDValue PromoteFloatRes_FCOPYSIGN(SDNode *N);
633  SDValue PromoteFloatRes_FMAD(SDNode *N);
634  SDValue PromoteFloatRes_FPOWI(SDNode *N);
635  SDValue PromoteFloatRes_FP_ROUND(SDNode *N);
636  SDValue PromoteFloatRes_LOAD(SDNode *N);
637  SDValue PromoteFloatRes_SELECT(SDNode *N);
638  SDValue PromoteFloatRes_SELECT_CC(SDNode *N);
639  SDValue PromoteFloatRes_UnaryOp(SDNode *N);
640  SDValue PromoteFloatRes_UNDEF(SDNode *N);
641  SDValue BitcastToInt_ATOMIC_SWAP(SDNode *N);
642  SDValue PromoteFloatRes_XINT_TO_FP(SDNode *N);
643
644  bool PromoteFloatOperand(SDNode *N, unsigned OpNo);
645  SDValue PromoteFloatOp_BITCAST(SDNode *N, unsigned OpNo);
646  SDValue PromoteFloatOp_FCOPYSIGN(SDNode *N, unsigned OpNo);
647  SDValue PromoteFloatOp_FP_EXTEND(SDNode *N, unsigned OpNo);
648  SDValue PromoteFloatOp_FP_TO_XINT(SDNode *N, unsigned OpNo);
649  SDValue PromoteFloatOp_STORE(SDNode *N, unsigned OpNo);
650  SDValue PromoteFloatOp_SELECT_CC(SDNode *N, unsigned OpNo);
651  SDValue PromoteFloatOp_SETCC(SDNode *N, unsigned OpNo);
652
653  //===--------------------------------------------------------------------===//
654  // Scalarization Support: LegalizeVectorTypes.cpp
655  //===--------------------------------------------------------------------===//
656
657  /// Given a processed one-element vector Op which was scalarized to its
658  /// element type, this returns the element. For example, if Op is a v1i32,
659  /// Op = < i32 val >, this method returns val, an i32.
660  SDValue GetScalarizedVector(SDValue Op) {
661    TableId &ScalarizedId = ScalarizedVectors[getTableId(Op)];
662    SDValue ScalarizedOp = getSDValue(ScalarizedId);
663    assert(ScalarizedOp.getNode() && "Operand wasn't scalarized?");
664    return ScalarizedOp;
665  }
666  void SetScalarizedVector(SDValue Op, SDValue Result);
667
668  // Vector Result Scalarization: <1 x ty> -> ty.
669  void ScalarizeVectorResult(SDNode *N, unsigned ResNo);
670  SDValue ScalarizeVecRes_MERGE_VALUES(SDNode *N, unsigned ResNo);
671  SDValue ScalarizeVecRes_BinOp(SDNode *N);
672  SDValue ScalarizeVecRes_TernaryOp(SDNode *N);
673  SDValue ScalarizeVecRes_UnaryOp(SDNode *N);
674  SDValue ScalarizeVecRes_StrictFPOp(SDNode *N);
675  SDValue ScalarizeVecRes_OverflowOp(SDNode *N, unsigned ResNo);
676  SDValue ScalarizeVecRes_InregOp(SDNode *N);
677  SDValue ScalarizeVecRes_VecInregOp(SDNode *N);
678
679  SDValue ScalarizeVecRes_BITCAST(SDNode *N);
680  SDValue ScalarizeVecRes_BUILD_VECTOR(SDNode *N);
681  SDValue ScalarizeVecRes_EXTRACT_SUBVECTOR(SDNode *N);
682  SDValue ScalarizeVecRes_FP_ROUND(SDNode *N);
683  SDValue ScalarizeVecRes_FPOWI(SDNode *N);
684  SDValue ScalarizeVecRes_INSERT_VECTOR_ELT(SDNode *N);
685  SDValue ScalarizeVecRes_LOAD(LoadSDNode *N);
686  SDValue ScalarizeVecRes_SCALAR_TO_VECTOR(SDNode *N);
687  SDValue ScalarizeVecRes_VSELECT(SDNode *N);
688  SDValue ScalarizeVecRes_SELECT(SDNode *N);
689  SDValue ScalarizeVecRes_SELECT_CC(SDNode *N);
690  SDValue ScalarizeVecRes_SETCC(SDNode *N);
691  SDValue ScalarizeVecRes_UNDEF(SDNode *N);
692  SDValue ScalarizeVecRes_VECTOR_SHUFFLE(SDNode *N);
693
694  SDValue ScalarizeVecRes_FIX(SDNode *N);
695
696  // Vector Operand Scalarization: <1 x ty> -> ty.
697  bool ScalarizeVectorOperand(SDNode *N, unsigned OpNo);
698  SDValue ScalarizeVecOp_BITCAST(SDNode *N);
699  SDValue ScalarizeVecOp_UnaryOp(SDNode *N);
700  SDValue ScalarizeVecOp_UnaryOp_StrictFP(SDNode *N);
701  SDValue ScalarizeVecOp_CONCAT_VECTORS(SDNode *N);
702  SDValue ScalarizeVecOp_EXTRACT_VECTOR_ELT(SDNode *N);
703  SDValue ScalarizeVecOp_VSELECT(SDNode *N);
704  SDValue ScalarizeVecOp_VSETCC(SDNode *N);
705  SDValue ScalarizeVecOp_STORE(StoreSDNode *N, unsigned OpNo);
706  SDValue ScalarizeVecOp_FP_ROUND(SDNode *N, unsigned OpNo);
707  SDValue ScalarizeVecOp_STRICT_FP_ROUND(SDNode *N, unsigned OpNo);
708  SDValue ScalarizeVecOp_VECREDUCE(SDNode *N);
709
710  //===--------------------------------------------------------------------===//
711  // Vector Splitting Support: LegalizeVectorTypes.cpp
712  //===--------------------------------------------------------------------===//
713
714  /// Given a processed vector Op which was split into vectors of half the size,
715  /// this method returns the halves. The first elements of Op coincide with the
716  /// elements of Lo; the remaining elements of Op coincide with the elements of
717  /// Hi: Op is what you would get by concatenating Lo and Hi.
718  /// For example, if Op is a v8i32 that was split into two v4i32's, then this
719  /// method returns the two v4i32's, with Lo corresponding to the first 4
720  /// elements of Op, and Hi to the last 4 elements.
721  void GetSplitVector(SDValue Op, SDValue &Lo, SDValue &Hi);
722  void SetSplitVector(SDValue Op, SDValue Lo, SDValue Hi);
723
724  // Vector Result Splitting: <128 x ty> -> 2 x <64 x ty>.
725  void SplitVectorResult(SDNode *N, unsigned ResNo);
726  void SplitVecRes_BinOp(SDNode *N, SDValue &Lo, SDValue &Hi);
727  void SplitVecRes_TernaryOp(SDNode *N, SDValue &Lo, SDValue &Hi);
728  void SplitVecRes_UnaryOp(SDNode *N, SDValue &Lo, SDValue &Hi);
729  void SplitVecRes_ExtendOp(SDNode *N, SDValue &Lo, SDValue &Hi);
730  void SplitVecRes_InregOp(SDNode *N, SDValue &Lo, SDValue &Hi);
731  void SplitVecRes_ExtVecInRegOp(SDNode *N, SDValue &Lo, SDValue &Hi);
732  void SplitVecRes_StrictFPOp(SDNode *N, SDValue &Lo, SDValue &Hi);
733  void SplitVecRes_OverflowOp(SDNode *N, unsigned ResNo,
734                              SDValue &Lo, SDValue &Hi);
735
736  void SplitVecRes_FIX(SDNode *N, SDValue &Lo, SDValue &Hi);
737
738  void SplitVecRes_BITCAST(SDNode *N, SDValue &Lo, SDValue &Hi);
739  void SplitVecRes_BUILD_VECTOR(SDNode *N, SDValue &Lo, SDValue &Hi);
740  void SplitVecRes_CONCAT_VECTORS(SDNode *N, SDValue &Lo, SDValue &Hi);
741  void SplitVecRes_EXTRACT_SUBVECTOR(SDNode *N, SDValue &Lo, SDValue &Hi);
742  void SplitVecRes_INSERT_SUBVECTOR(SDNode *N, SDValue &Lo, SDValue &Hi);
743  void SplitVecRes_FPOWI(SDNode *N, SDValue &Lo, SDValue &Hi);
744  void SplitVecRes_FCOPYSIGN(SDNode *N, SDValue &Lo, SDValue &Hi);
745  void SplitVecRes_INSERT_VECTOR_ELT(SDNode *N, SDValue &Lo, SDValue &Hi);
746  void SplitVecRes_LOAD(LoadSDNode *LD, SDValue &Lo, SDValue &Hi);
747  void SplitVecRes_MLOAD(MaskedLoadSDNode *MLD, SDValue &Lo, SDValue &Hi);
748  void SplitVecRes_MGATHER(MaskedGatherSDNode *MGT, SDValue &Lo, SDValue &Hi);
749  void SplitVecRes_SCALAR_TO_VECTOR(SDNode *N, SDValue &Lo, SDValue &Hi);
750  void SplitVecRes_SETCC(SDNode *N, SDValue &Lo, SDValue &Hi);
751  void SplitVecRes_VECTOR_SHUFFLE(ShuffleVectorSDNode *N, SDValue &Lo,
752                                  SDValue &Hi);
753  void SplitVecRes_VAARG(SDNode *N, SDValue &Lo, SDValue &Hi);
754
755  // Vector Operand Splitting: <128 x ty> -> 2 x <64 x ty>.
756  bool SplitVectorOperand(SDNode *N, unsigned OpNo);
757  SDValue SplitVecOp_VSELECT(SDNode *N, unsigned OpNo);
758  SDValue SplitVecOp_VECREDUCE(SDNode *N, unsigned OpNo);
759  SDValue SplitVecOp_UnaryOp(SDNode *N);
760  SDValue SplitVecOp_TruncateHelper(SDNode *N);
761
762  SDValue SplitVecOp_BITCAST(SDNode *N);
763  SDValue SplitVecOp_EXTRACT_SUBVECTOR(SDNode *N);
764  SDValue SplitVecOp_EXTRACT_VECTOR_ELT(SDNode *N);
765  SDValue SplitVecOp_ExtVecInRegOp(SDNode *N);
766  SDValue SplitVecOp_STORE(StoreSDNode *N, unsigned OpNo);
767  SDValue SplitVecOp_MSTORE(MaskedStoreSDNode *N, unsigned OpNo);
768  SDValue SplitVecOp_MSCATTER(MaskedScatterSDNode *N, unsigned OpNo);
769  SDValue SplitVecOp_MGATHER(MaskedGatherSDNode *MGT, unsigned OpNo);
770  SDValue SplitVecOp_CONCAT_VECTORS(SDNode *N);
771  SDValue SplitVecOp_VSETCC(SDNode *N);
772  SDValue SplitVecOp_FP_ROUND(SDNode *N);
773  SDValue SplitVecOp_FCOPYSIGN(SDNode *N);
774
775  //===--------------------------------------------------------------------===//
776  // Vector Widening Support: LegalizeVectorTypes.cpp
777  //===--------------------------------------------------------------------===//
778
779  /// Given a processed vector Op which was widened into a larger vector, this
780  /// method returns the larger vector. The elements of the returned vector
781  /// consist of the elements of Op followed by elements containing rubbish.
782  /// For example, if Op is a v2i32 that was widened to a v4i32, then this
783  /// method returns a v4i32 for which the first two elements are the same as
784  /// those of Op, while the last two elements contain rubbish.
785  SDValue GetWidenedVector(SDValue Op) {
786    TableId &WidenedId = WidenedVectors[getTableId(Op)];
787    SDValue WidenedOp = getSDValue(WidenedId);
788    assert(WidenedOp.getNode() && "Operand wasn't widened?");
789    return WidenedOp;
790  }
791  void SetWidenedVector(SDValue Op, SDValue Result);
792
793  // Widen Vector Result Promotion.
794  void WidenVectorResult(SDNode *N, unsigned ResNo);
795  SDValue WidenVecRes_MERGE_VALUES(SDNode* N, unsigned ResNo);
796  SDValue WidenVecRes_BITCAST(SDNode* N);
797  SDValue WidenVecRes_BUILD_VECTOR(SDNode* N);
798  SDValue WidenVecRes_CONCAT_VECTORS(SDNode* N);
799  SDValue WidenVecRes_EXTEND_VECTOR_INREG(SDNode* N);
800  SDValue WidenVecRes_EXTRACT_SUBVECTOR(SDNode* N);
801  SDValue WidenVecRes_INSERT_VECTOR_ELT(SDNode* N);
802  SDValue WidenVecRes_LOAD(SDNode* N);
803  SDValue WidenVecRes_MLOAD(MaskedLoadSDNode* N);
804  SDValue WidenVecRes_MGATHER(MaskedGatherSDNode* N);
805  SDValue WidenVecRes_SCALAR_TO_VECTOR(SDNode* N);
806  SDValue WidenVecRes_SELECT(SDNode* N);
807  SDValue WidenVSELECTAndMask(SDNode *N);
808  SDValue WidenVecRes_SELECT_CC(SDNode* N);
809  SDValue WidenVecRes_SETCC(SDNode* N);
810  SDValue WidenVecRes_STRICT_FSETCC(SDNode* N);
811  SDValue WidenVecRes_UNDEF(SDNode *N);
812  SDValue WidenVecRes_VECTOR_SHUFFLE(ShuffleVectorSDNode *N);
813
814  SDValue WidenVecRes_Ternary(SDNode *N);
815  SDValue WidenVecRes_Binary(SDNode *N);
816  SDValue WidenVecRes_BinaryCanTrap(SDNode *N);
817  SDValue WidenVecRes_BinaryWithExtraScalarOp(SDNode *N);
818  SDValue WidenVecRes_StrictFP(SDNode *N);
819  SDValue WidenVecRes_OverflowOp(SDNode *N, unsigned ResNo);
820  SDValue WidenVecRes_Convert(SDNode *N);
821  SDValue WidenVecRes_Convert_StrictFP(SDNode *N);
822  SDValue WidenVecRes_FCOPYSIGN(SDNode *N);
823  SDValue WidenVecRes_POWI(SDNode *N);
824  SDValue WidenVecRes_Shift(SDNode *N);
825  SDValue WidenVecRes_Unary(SDNode *N);
826  SDValue WidenVecRes_InregOp(SDNode *N);
827
828  // Widen Vector Operand.
829  bool WidenVectorOperand(SDNode *N, unsigned OpNo);
830  SDValue WidenVecOp_BITCAST(SDNode *N);
831  SDValue WidenVecOp_CONCAT_VECTORS(SDNode *N);
832  SDValue WidenVecOp_EXTEND(SDNode *N);
833  SDValue WidenVecOp_EXTRACT_VECTOR_ELT(SDNode *N);
834  SDValue WidenVecOp_EXTRACT_SUBVECTOR(SDNode *N);
835  SDValue WidenVecOp_STORE(SDNode* N);
836  SDValue WidenVecOp_MSTORE(SDNode* N, unsigned OpNo);
837  SDValue WidenVecOp_MGATHER(SDNode* N, unsigned OpNo);
838  SDValue WidenVecOp_MSCATTER(SDNode* N, unsigned OpNo);
839  SDValue WidenVecOp_SETCC(SDNode* N);
840  SDValue WidenVecOp_STRICT_FSETCC(SDNode* N);
841  SDValue WidenVecOp_VSELECT(SDNode *N);
842
843  SDValue WidenVecOp_Convert(SDNode *N);
844  SDValue WidenVecOp_FCOPYSIGN(SDNode *N);
845  SDValue WidenVecOp_VECREDUCE(SDNode *N);
846
847  /// Helper function to generate a set of operations to perform
848  /// a vector operation for a wider type.
849  ///
850  SDValue UnrollVectorOp_StrictFP(SDNode *N, unsigned ResNE);
851
852  //===--------------------------------------------------------------------===//
853  // Vector Widening Utilities Support: LegalizeVectorTypes.cpp
854  //===--------------------------------------------------------------------===//
855
856  /// Helper function to generate a set of loads to load a vector with a
857  /// resulting wider type. It takes:
858  ///   LdChain: list of chains for the load to be generated.
859  ///   Ld:      load to widen
860  SDValue GenWidenVectorLoads(SmallVectorImpl<SDValue> &LdChain,
861                              LoadSDNode *LD);
862
863  /// Helper function to generate a set of extension loads to load a vector with
864  /// a resulting wider type. It takes:
865  ///   LdChain: list of chains for the load to be generated.
866  ///   Ld:      load to widen
867  ///   ExtType: extension element type
868  SDValue GenWidenVectorExtLoads(SmallVectorImpl<SDValue> &LdChain,
869                                 LoadSDNode *LD, ISD::LoadExtType ExtType);
870
871  /// Helper function to generate a set of stores to store a widen vector into
872  /// non-widen memory.
873  ///   StChain: list of chains for the stores we have generated
874  ///   ST:      store of a widen value
875  void GenWidenVectorStores(SmallVectorImpl<SDValue> &StChain, StoreSDNode *ST);
876
877  /// Helper function to generate a set of stores to store a truncate widen
878  /// vector into non-widen memory.
879  ///   StChain: list of chains for the stores we have generated
880  ///   ST:      store of a widen value
881  void GenWidenVectorTruncStores(SmallVectorImpl<SDValue> &StChain,
882                                 StoreSDNode *ST);
883
884  /// Modifies a vector input (widen or narrows) to a vector of NVT.  The
885  /// input vector must have the same element type as NVT.
886  /// When FillWithZeroes is "on" the vector will be widened with zeroes.
887  /// By default, the vector will be widened with undefined values.
888  SDValue ModifyToType(SDValue InOp, EVT NVT, bool FillWithZeroes = false);
889
890  /// Return a mask of vector type MaskVT to replace InMask. Also adjust
891  /// MaskVT to ToMaskVT if needed with vector extension or truncation.
892  SDValue convertMask(SDValue InMask, EVT MaskVT, EVT ToMaskVT);
893
894  //===--------------------------------------------------------------------===//
895  // Generic Splitting: LegalizeTypesGeneric.cpp
896  //===--------------------------------------------------------------------===//
897
898  // Legalization methods which only use that the illegal type is split into two
899  // not necessarily identical types.  As such they can be used for splitting
900  // vectors and expanding integers and floats.
901
902  void GetSplitOp(SDValue Op, SDValue &Lo, SDValue &Hi) {
903    if (Op.getValueType().isVector())
904      GetSplitVector(Op, Lo, Hi);
905    else if (Op.getValueType().isInteger())
906      GetExpandedInteger(Op, Lo, Hi);
907    else
908      GetExpandedFloat(Op, Lo, Hi);
909  }
910
911  /// Use ISD::EXTRACT_ELEMENT nodes to extract the low and high parts of the
912  /// given value.
913  void GetPairElements(SDValue Pair, SDValue &Lo, SDValue &Hi);
914
915  // Generic Result Splitting.
916  void SplitRes_MERGE_VALUES(SDNode *N, unsigned ResNo,
917                             SDValue &Lo, SDValue &Hi);
918  void SplitRes_SELECT      (SDNode *N, SDValue &Lo, SDValue &Hi);
919  void SplitRes_SELECT_CC   (SDNode *N, SDValue &Lo, SDValue &Hi);
920  void SplitRes_UNDEF       (SDNode *N, SDValue &Lo, SDValue &Hi);
921
922  void SplitVSETCC(const SDNode *N);
923
924  //===--------------------------------------------------------------------===//
925  // Generic Expansion: LegalizeTypesGeneric.cpp
926  //===--------------------------------------------------------------------===//
927
928  // Legalization methods which only use that the illegal type is split into two
929  // identical types of half the size, and that the Lo/Hi part is stored first
930  // in memory on little/big-endian machines, followed by the Hi/Lo part.  As
931  // such they can be used for expanding integers and floats.
932
933  void GetExpandedOp(SDValue Op, SDValue &Lo, SDValue &Hi) {
934    if (Op.getValueType().isInteger())
935      GetExpandedInteger(Op, Lo, Hi);
936    else
937      GetExpandedFloat(Op, Lo, Hi);
938  }
939
940
941  /// This function will split the integer \p Op into \p NumElements
942  /// operations of type \p EltVT and store them in \p Ops.
943  void IntegerToVector(SDValue Op, unsigned NumElements,
944                       SmallVectorImpl<SDValue> &Ops, EVT EltVT);
945
946  // Generic Result Expansion.
947  void ExpandRes_MERGE_VALUES      (SDNode *N, unsigned ResNo,
948                                    SDValue &Lo, SDValue &Hi);
949  void ExpandRes_BITCAST           (SDNode *N, SDValue &Lo, SDValue &Hi);
950  void ExpandRes_BUILD_PAIR        (SDNode *N, SDValue &Lo, SDValue &Hi);
951  void ExpandRes_EXTRACT_ELEMENT   (SDNode *N, SDValue &Lo, SDValue &Hi);
952  void ExpandRes_EXTRACT_VECTOR_ELT(SDNode *N, SDValue &Lo, SDValue &Hi);
953  void ExpandRes_NormalLoad        (SDNode *N, SDValue &Lo, SDValue &Hi);
954  void ExpandRes_VAARG             (SDNode *N, SDValue &Lo, SDValue &Hi);
955
956  // Generic Operand Expansion.
957  SDValue ExpandOp_BITCAST          (SDNode *N);
958  SDValue ExpandOp_BUILD_VECTOR     (SDNode *N);
959  SDValue ExpandOp_EXTRACT_ELEMENT  (SDNode *N);
960  SDValue ExpandOp_INSERT_VECTOR_ELT(SDNode *N);
961  SDValue ExpandOp_SCALAR_TO_VECTOR (SDNode *N);
962  SDValue ExpandOp_NormalStore      (SDNode *N, unsigned OpNo);
963};
964
965} // end namespace llvm.
966
967#endif
968