Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ----*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file declares the SDNode class and derived classes, which are used to
11
// represent the nodes and operations present in a SelectionDAG.  These nodes
12
// and operations are machine code level operations, with some similarities to
13
// the GCC RTL representation.
14
//
15
// Clients should include the SelectionDAG.h file instead of this file directly.
16
//
17
//===----------------------------------------------------------------------===//
18
19
#ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20
#define LLVM_CODEGEN_SELECTIONDAGNODES_H
21
22
#include "llvm/ADT/APFloat.h"
23
#include "llvm/ADT/ArrayRef.h"
24
#include "llvm/ADT/BitVector.h"
25
#include "llvm/ADT/FoldingSet.h"
26
#include "llvm/ADT/GraphTraits.h"
27
#include "llvm/ADT/SmallPtrSet.h"
28
#include "llvm/ADT/SmallVector.h"
29
#include "llvm/ADT/ilist_node.h"
30
#include "llvm/ADT/iterator.h"
31
#include "llvm/ADT/iterator_range.h"
32
#include "llvm/CodeGen/ISDOpcodes.h"
33
#include "llvm/CodeGen/MachineMemOperand.h"
34
#include "llvm/CodeGen/ValueTypes.h"
35
#include "llvm/IR/Constants.h"
36
#include "llvm/IR/DebugLoc.h"
37
#include "llvm/IR/Instruction.h"
38
#include "llvm/IR/Instructions.h"
39
#include "llvm/IR/Metadata.h"
40
#include "llvm/IR/Operator.h"
41
#include "llvm/Support/AlignOf.h"
42
#include "llvm/Support/AtomicOrdering.h"
43
#include "llvm/Support/Casting.h"
44
#include "llvm/Support/ErrorHandling.h"
45
#include "llvm/Support/MachineValueType.h"
46
#include <algorithm>
47
#include <cassert>
48
#include <climits>
49
#include <cstddef>
50
#include <cstdint>
51
#include <cstring>
52
#include <iterator>
53
#include <string>
54
#include <tuple>
55
56
namespace llvm {
57
58
class APInt;
59
class Constant;
60
template <typename T> struct DenseMapInfo;
61
class GlobalValue;
62
class MachineBasicBlock;
63
class MachineConstantPoolValue;
64
class MCSymbol;
65
class raw_ostream;
66
class SDNode;
67
class SelectionDAG;
68
class Type;
69
class Value;
70
71
void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
72
                    bool force = false);
73
74
/// This represents a list of ValueType's that has been intern'd by
75
/// a SelectionDAG.  Instances of this simple value class are returned by
76
/// SelectionDAG::getVTList(...).
77
///
78
struct SDVTList {
79
  const EVT *VTs;
80
  unsigned int NumVTs;
81
};
82
83
namespace ISD {
84
85
  /// Node predicates
86
87
  /// If N is a BUILD_VECTOR node whose elements are all the same constant or
88
  /// undefined, return true and return the constant value in \p SplatValue.
89
  bool isConstantSplatVector(const SDNode *N, APInt &SplatValue);
90
91
  /// Return true if the specified node is a BUILD_VECTOR where all of the
92
  /// elements are ~0 or undef.
93
  bool isBuildVectorAllOnes(const SDNode *N);
94
95
  /// Return true if the specified node is a BUILD_VECTOR where all of the
96
  /// elements are 0 or undef.
97
  bool isBuildVectorAllZeros(const SDNode *N);
98
99
  /// Return true if the specified node is a BUILD_VECTOR node of all
100
  /// ConstantSDNode or undef.
101
  bool isBuildVectorOfConstantSDNodes(const SDNode *N);
102
103
  /// Return true if the specified node is a BUILD_VECTOR node of all
104
  /// ConstantFPSDNode or undef.
105
  bool isBuildVectorOfConstantFPSDNodes(const SDNode *N);
106
107
  /// Return true if the node has at least one operand and all operands of the
108
  /// specified node are ISD::UNDEF.
109
  bool allOperandsUndef(const SDNode *N);
110
111
} // end namespace ISD
112
113
//===----------------------------------------------------------------------===//
114
/// Unlike LLVM values, Selection DAG nodes may return multiple
115
/// values as the result of a computation.  Many nodes return multiple values,
116
/// from loads (which define a token and a return value) to ADDC (which returns
117
/// a result and a carry value), to calls (which may return an arbitrary number
118
/// of values).
119
///
120
/// As such, each use of a SelectionDAG computation must indicate the node that
121
/// computes it as well as which return value to use from that node.  This pair
122
/// of information is represented with the SDValue value type.
123
///
124
0
class SDValue {
125
  friend struct DenseMapInfo<SDValue>;
126
127
  SDNode *Node = nullptr; // The node defining the value we are using.
128
  unsigned ResNo = 0;     // Which return value of the node we are using.
129
130
public:
131
769M
  SDValue() = default;
132
  SDValue(SDNode *node, unsigned resno);
133
134
  /// get the index which selects a specific result in the SDNode
135
419M
  unsigned getResNo() const { return ResNo; }
136
137
  /// get the SDNode which holds the desired result
138
3.46G
  SDNode *getNode() const { return Node; }
139
140
  /// set the SDNode
141
17.3M
  void setNode(SDNode *N) { Node = N; }
142
143
252M
  inline SDNode *operator->() const { return Node; }
144
145
680M
  bool operator==(const SDValue &O) const {
146
680M
    return Node == O.Node && 
ResNo == O.ResNo430M
;
147
680M
  }
148
40.6M
  bool operator!=(const SDValue &O) const {
149
40.6M
    return !operator==(O);
150
40.6M
  }
151
373k
  bool operator<(const SDValue &O) const {
152
373k
    return std::tie(Node, ResNo) < std::tie(O.Node, O.ResNo);
153
373k
  }
154
120M
  explicit operator bool() const {
155
120M
    return Node != nullptr;
156
120M
  }
157
158
30.5M
  SDValue getValue(unsigned R) const {
159
30.5M
    return SDValue(Node, R);
160
30.5M
  }
161
162
  /// Return true if this node is an operand of N.
163
  bool isOperandOf(const SDNode *N) const;
164
165
  /// Return the ValueType of the referenced return value.
166
  inline EVT getValueType() const;
167
168
  /// Return the simple ValueType of the referenced return value.
169
19.1M
  MVT getSimpleValueType() const {
170
19.1M
    return getValueType().getSimpleVT();
171
19.1M
  }
172
173
  /// Returns the size of the value in bits.
174
6.27M
  unsigned getValueSizeInBits() const {
175
6.27M
    return getValueType().getSizeInBits();
176
6.27M
  }
177
178
88.2M
  unsigned getScalarValueSizeInBits() const {
179
88.2M
    return getValueType().getScalarType().getSizeInBits();
180
88.2M
  }
181
182
  // Forwarding methods - These forward to the corresponding methods in SDNode.
183
  inline unsigned getOpcode() const;
184
  inline unsigned getNumOperands() const;
185
  inline const SDValue &getOperand(unsigned i) const;
186
  inline uint64_t getConstantOperandVal(unsigned i) const;
187
  inline bool isTargetMemoryOpcode() const;
188
  inline bool isTargetOpcode() const;
189
  inline bool isMachineOpcode() const;
190
  inline bool isUndef() const;
191
  inline unsigned getMachineOpcode() const;
192
  inline const DebugLoc &getDebugLoc() const;
193
  inline void dump() const;
194
  inline void dump(const SelectionDAG *G) const;
195
  inline void dumpr() const;
196
  inline void dumpr(const SelectionDAG *G) const;
197
198
  /// Return true if this operand (which must be a chain) reaches the
199
  /// specified operand without crossing any side-effecting instructions.
200
  /// In practice, this looks through token factors and non-volatile loads.
201
  /// In order to remain efficient, this only
202
  /// looks a couple of nodes in, it does not do an exhaustive search.
203
  bool reachesChainWithoutSideEffects(SDValue Dest,
204
                                      unsigned Depth = 2) const;
205
206
  /// Return true if there are no nodes using value ResNo of Node.
207
  inline bool use_empty() const;
208
209
  /// Return true if there is exactly one node using value ResNo of Node.
210
  inline bool hasOneUse() const;
211
};
212
213
template<> struct DenseMapInfo<SDValue> {
214
109M
  static inline SDValue getEmptyKey() {
215
109M
    SDValue V;
216
109M
    V.ResNo = -1U;
217
109M
    return V;
218
109M
  }
219
220
80.2M
  static inline SDValue getTombstoneKey() {
221
80.2M
    SDValue V;
222
80.2M
    V.ResNo = -2U;
223
80.2M
    return V;
224
80.2M
  }
225
226
73.7M
  static unsigned getHashValue(const SDValue &Val) {
227
73.7M
    return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
228
73.7M
            (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
229
73.7M
  }
230
231
545M
  static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
232
545M
    return LHS == RHS;
233
545M
  }
234
};
235
template <> struct isPodLike<SDValue> { static const bool value = true; };
236
237
/// Allow casting operators to work directly on
238
/// SDValues as if they were SDNode*'s.
239
template<> struct simplify_type<SDValue> {
240
  using SimpleType = SDNode *;
241
242
133M
  static SimpleType getSimplifiedValue(SDValue &Val) {
243
133M
    return Val.getNode();
244
133M
  }
245
};
246
template<> struct simplify_type<const SDValue> {
247
  using SimpleType = /*const*/ SDNode *;
248
249
704M
  static SimpleType getSimplifiedValue(const SDValue &Val) {
250
704M
    return Val.getNode();
251
704M
  }
252
};
253
254
/// Represents a use of a SDNode. This class holds an SDValue,
255
/// which records the SDNode being used and the result number, a
256
/// pointer to the SDNode using the value, and Next and Prev pointers,
257
/// which link together all the uses of an SDNode.
258
///
259
class SDUse {
260
  /// Val - The value being used.
261
  SDValue Val;
262
  /// User - The user of this value.
263
  SDNode *User = nullptr;
264
  /// Prev, Next - Pointers to the uses list of the SDNode referred by
265
  /// this operand.
266
  SDUse **Prev = nullptr;
267
  SDUse *Next = nullptr;
268
269
public:
270
17.4M
  SDUse() = default;
271
  SDUse(const SDUse &U) = delete;
272
  SDUse &operator=(const SDUse &) = delete;
273
274
  /// Normally SDUse will just implicitly convert to an SDValue that it holds.
275
1.13G
  operator const SDValue&() const { return Val; }
276
277
  /// If implicit conversion to SDValue doesn't work, the get() method returns
278
  /// the SDValue.
279
343M
  const SDValue &get() const { return Val; }
280
281
  /// This returns the SDNode that contains this Use.
282
299M
  SDNode *getUser() { return User; }
283
284
  /// Get the next SDUse in the use list.
285
364M
  SDUse *getNext() const { return Next; }
286
287
  /// Convenience function for get().getNode().
288
252M
  SDNode *getNode() const { return Val.getNode(); }
289
  /// Convenience function for get().getResNo().
290
191M
  unsigned getResNo() const { return Val.getResNo(); }
291
  /// Convenience function for get().getValueType().
292
  EVT getValueType() const { return Val.getValueType(); }
293
294
  /// Convenience function for get().operator==
295
1.23k
  bool operator==(const SDValue &V) const {
296
1.23k
    return Val == V;
297
1.23k
  }
298
299
  /// Convenience function for get().operator!=
300
3.13M
  bool operator!=(const SDValue &V) const {
301
3.13M
    return Val != V;
302
3.13M
  }
303
304
  /// Convenience function for get().operator<
305
  bool operator<(const SDValue &V) const {
306
    return Val < V;
307
  }
308
309
private:
310
  friend class SelectionDAG;
311
  friend class SDNode;
312
  // TODO: unfriend HandleSDNode once we fix its operand handling.
313
  friend class HandleSDNode;
314
315
152M
  void setUser(SDNode *p) { User = p; }
316
317
  /// Remove this use from its existing use list, assign it the
318
  /// given value, and add it to the new value's node's use list.
319
  inline void set(const SDValue &V);
320
  /// Like set, but only supports initializing a newly-allocated
321
  /// SDUse with a non-null value.
322
  inline void setInitial(const SDValue &V);
323
  /// Like set, but only sets the Node portion of the value,
324
  /// leaving the ResNo portion unmodified.
325
  inline void setNode(SDNode *N);
326
327
167M
  void addToList(SDUse **List) {
328
167M
    Next = *List;
329
167M
    if (Next) 
Next->Prev = &Next83.3M
;
330
167M
    Prev = List;
331
167M
    *List = this;
332
167M
  }
333
334
104M
  void removeFromList() {
335
104M
    *Prev = Next;
336
104M
    if (Next) 
Next->Prev = Prev30.3M
;
337
104M
  }
338
};
339
340
/// simplify_type specializations - Allow casting operators to work directly on
341
/// SDValues as if they were SDNode*'s.
342
template<> struct simplify_type<SDUse> {
343
  using SimpleType = SDNode *;
344
345
  static SimpleType getSimplifiedValue(SDUse &Val) {
346
    return Val.getNode();
347
  }
348
};
349
350
/// These are IR-level optimization flags that may be propagated to SDNodes.
351
/// TODO: This data structure should be shared by the IR optimizer and the
352
/// the backend.
353
0
struct SDNodeFlags {
354
private:
355
  // This bit is used to determine if the flags are in a defined state.
356
  // Flag bits can only be masked out during intersection if the masking flags
357
  // are defined.
358
  bool AnyDefined : 1;
359
360
  bool NoUnsignedWrap : 1;
361
  bool NoSignedWrap : 1;
362
  bool Exact : 1;
363
  bool NoNaNs : 1;
364
  bool NoInfs : 1;
365
  bool NoSignedZeros : 1;
366
  bool AllowReciprocal : 1;
367
  bool VectorReduction : 1;
368
  bool AllowContract : 1;
369
  bool ApproximateFuncs : 1;
370
  bool AllowReassociation : 1;
371
372
public:
373
  /// Default constructor turns off all optimization flags.
374
  SDNodeFlags()
375
      : AnyDefined(false), NoUnsignedWrap(false), NoSignedWrap(false),
376
        Exact(false), NoNaNs(false), NoInfs(false),
377
        NoSignedZeros(false), AllowReciprocal(false), VectorReduction(false),
378
        AllowContract(false), ApproximateFuncs(false),
379
123M
        AllowReassociation(false) {}
380
381
  /// Propagate the fast-math-flags from an IR FPMathOperator.
382
391k
  void copyFMF(const FPMathOperator &FPMO) {
383
391k
    setNoNaNs(FPMO.hasNoNaNs());
384
391k
    setNoInfs(FPMO.hasNoInfs());
385
391k
    setNoSignedZeros(FPMO.hasNoSignedZeros());
386
391k
    setAllowReciprocal(FPMO.hasAllowReciprocal());
387
391k
    setAllowContract(FPMO.hasAllowContract());
388
391k
    setApproximateFuncs(FPMO.hasApproxFunc());
389
391k
    setAllowReassociation(FPMO.hasAllowReassoc());
390
391k
  }
391
392
  /// Sets the state of the flags to the defined state.
393
7.38M
  void setDefined() { AnyDefined = true; }
394
  /// Returns true if the flags are in a defined state.
395
1.64M
  bool isDefined() const { return AnyDefined; }
396
397
  // These are mutators for each flag.
398
3.78M
  void setNoUnsignedWrap(bool b) {
399
3.78M
    setDefined();
400
3.78M
    NoUnsignedWrap = b;
401
3.78M
  }
402
679k
  void setNoSignedWrap(bool b) {
403
679k
    setDefined();
404
679k
    NoSignedWrap = b;
405
679k
  }
406
180k
  void setExact(bool b) {
407
180k
    setDefined();
408
180k
    Exact = b;
409
180k
  }
410
391k
  void setNoNaNs(bool b) {
411
391k
    setDefined();
412
391k
    NoNaNs = b;
413
391k
  }
414
391k
  void setNoInfs(bool b) {
415
391k
    setDefined();
416
391k
    NoInfs = b;
417
391k
  }
418
391k
  void setNoSignedZeros(bool b) {
419
391k
    setDefined();
420
391k
    NoSignedZeros = b;
421
391k
  }
422
391k
  void setAllowReciprocal(bool b) {
423
391k
    setDefined();
424
391k
    AllowReciprocal = b;
425
391k
  }
426
1.12k
  void setVectorReduction(bool b) {
427
1.12k
    setDefined();
428
1.12k
    VectorReduction = b;
429
1.12k
  }
430
391k
  void setAllowContract(bool b) {
431
391k
    setDefined();
432
391k
    AllowContract = b;
433
391k
  }
434
391k
  void setApproximateFuncs(bool b) {
435
391k
    setDefined();
436
391k
    ApproximateFuncs = b;
437
391k
  }
438
391k
  void setAllowReassociation(bool b) {
439
391k
    setDefined();
440
391k
    AllowReassociation = b;
441
391k
  }
442
443
  // These are accessors for each flag.
444
7.35M
  bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
445
7.33M
  bool hasNoSignedWrap() const { return NoSignedWrap; }
446
7.96M
  bool hasExact() const { return Exact; }
447
7.72M
  bool hasNoNaNs() const { return NoNaNs; }
448
7.30M
  bool hasNoInfs() const { return NoInfs; }
449
7.39M
  bool hasNoSignedZeros() const { return NoSignedZeros; }
450
7.50M
  bool hasAllowReciprocal() const { return AllowReciprocal; }
451
9.27M
  bool hasVectorReduction() const { return VectorReduction; }
452
7.59M
  bool hasAllowContract() const { return AllowContract; }
453
7.30M
  bool hasApproximateFuncs() const { return ApproximateFuncs; }
454
7.90M
  bool hasAllowReassociation() const { return AllowReassociation; }
455
456
  bool isFast() const {
457
    return NoSignedZeros && AllowReciprocal && NoNaNs && NoInfs &&
458
           AllowContract && ApproximateFuncs && AllowReassociation;
459
  }
460
461
  /// Clear any flags in this flag set that aren't also set in Flags.
462
  /// If the given Flags are undefined then don't do anything.
463
1.25M
  void intersectWith(const SDNodeFlags Flags) {
464
1.25M
    if (!Flags.isDefined())
465
1.02M
      return;
466
223k
    NoUnsignedWrap &= Flags.NoUnsignedWrap;
467
223k
    NoSignedWrap &= Flags.NoSignedWrap;
468
223k
    Exact &= Flags.Exact;
469
223k
    NoNaNs &= Flags.NoNaNs;
470
223k
    NoInfs &= Flags.NoInfs;
471
223k
    NoSignedZeros &= Flags.NoSignedZeros;
472
223k
    AllowReciprocal &= Flags.AllowReciprocal;
473
223k
    VectorReduction &= Flags.VectorReduction;
474
223k
    AllowContract &= Flags.AllowContract;
475
223k
    ApproximateFuncs &= Flags.ApproximateFuncs;
476
223k
    AllowReassociation &= Flags.AllowReassociation;
477
223k
  }
478
};
479
480
/// Represents one node in the SelectionDAG.
481
///
482
class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
483
private:
484
  /// The operation that this node performs.
485
  int16_t NodeType;
486
487
protected:
488
  // We define a set of mini-helper classes to help us interpret the bits in our
489
  // SubclassData.  These are designed to fit within a uint16_t so they pack
490
  // with NodeType.
491
492
  class SDNodeBitfields {
493
    friend class SDNode;
494
    friend class MemIntrinsicSDNode;
495
    friend class MemSDNode;
496
    friend class SelectionDAG;
497
498
    uint16_t HasDebugValue : 1;
499
    uint16_t IsMemIntrinsic : 1;
500
    uint16_t IsDivergent : 1;
501
  };
502
  enum { NumSDNodeBits = 3 };
503
504
  class ConstantSDNodeBitfields {
505
    friend class ConstantSDNode;
506
507
    uint16_t : NumSDNodeBits;
508
509
    uint16_t IsOpaque : 1;
510
  };
511
512
  class MemSDNodeBitfields {
513
    friend class MemSDNode;
514
    friend class MemIntrinsicSDNode;
515
    friend class AtomicSDNode;
516
517
    uint16_t : NumSDNodeBits;
518
519
    uint16_t IsVolatile : 1;
520
    uint16_t IsNonTemporal : 1;
521
    uint16_t IsDereferenceable : 1;
522
    uint16_t IsInvariant : 1;
523
  };
524
  enum { NumMemSDNodeBits = NumSDNodeBits + 4 };
525
526
  class LSBaseSDNodeBitfields {
527
    friend class LSBaseSDNode;
528
529
    uint16_t : NumMemSDNodeBits;
530
531
    uint16_t AddressingMode : 3; // enum ISD::MemIndexedMode
532
  };
533
  enum { NumLSBaseSDNodeBits = NumMemSDNodeBits + 3 };
534
535
  class LoadSDNodeBitfields {
536
    friend class LoadSDNode;
537
    friend class MaskedLoadSDNode;
538
539
    uint16_t : NumLSBaseSDNodeBits;
540
541
    uint16_t ExtTy : 2; // enum ISD::LoadExtType
542
    uint16_t IsExpanding : 1;
543
  };
544
545
  class StoreSDNodeBitfields {
546
    friend class StoreSDNode;
547
    friend class MaskedStoreSDNode;
548
549
    uint16_t : NumLSBaseSDNodeBits;
550
551
    uint16_t IsTruncating : 1;
552
    uint16_t IsCompressing : 1;
553
  };
554
555
  union {
556
    char RawSDNodeBits[sizeof(uint16_t)];
557
    SDNodeBitfields SDNodeBits;
558
    ConstantSDNodeBitfields ConstantSDNodeBits;
559
    MemSDNodeBitfields MemSDNodeBits;
560
    LSBaseSDNodeBitfields LSBaseSDNodeBits;
561
    LoadSDNodeBitfields LoadSDNodeBits;
562
    StoreSDNodeBitfields StoreSDNodeBits;
563
  };
564
565
  // RawSDNodeBits must cover the entirety of the union.  This means that all of
566
  // the union's members must have size <= RawSDNodeBits.  We write the RHS as
567
  // "2" instead of sizeof(RawSDNodeBits) because MSVC can't handle the latter.
568
  static_assert(sizeof(SDNodeBitfields) <= 2, "field too wide");
569
  static_assert(sizeof(ConstantSDNodeBitfields) <= 2, "field too wide");
570
  static_assert(sizeof(MemSDNodeBitfields) <= 2, "field too wide");
571
  static_assert(sizeof(LSBaseSDNodeBitfields) <= 2, "field too wide");
572
  static_assert(sizeof(LoadSDNodeBitfields) <= 2, "field too wide");
573
  static_assert(sizeof(StoreSDNodeBitfields) <= 2, "field too wide");
574
575
private:
576
  friend class SelectionDAG;
577
  // TODO: unfriend HandleSDNode once we fix its operand handling.
578
  friend class HandleSDNode;
579
580
  /// Unique id per SDNode in the DAG.
581
  int NodeId = -1;
582
583
  /// The values that are used by this operation.
584
  SDUse *OperandList = nullptr;
585
586
  /// The types of the values this node defines.  SDNode's may
587
  /// define multiple values simultaneously.
588
  const EVT *ValueList;
589
590
  /// List of uses for this SDNode.
591
  SDUse *UseList = nullptr;
592
593
  /// The number of entries in the Operand/Value list.
594
  unsigned short NumOperands = 0;
595
  unsigned short NumValues;
596
597
  // The ordering of the SDNodes. It roughly corresponds to the ordering of the
598
  // original LLVM instructions.
599
  // This is used for turning off scheduling, because we'll forgo
600
  // the normal scheduling algorithms and output the instructions according to
601
  // this ordering.
602
  unsigned IROrder;
603
604
  /// Source line information.
605
  DebugLoc debugLoc;
606
607
  /// Return a pointer to the specified value type.
608
  static const EVT *getValueTypeList(EVT VT);
609
610
  SDNodeFlags Flags;
611
612
public:
613
  /// Unique and persistent id per SDNode in the DAG.
614
  /// Used for debug printing.
615
  uint16_t PersistentId;
616
617
  //===--------------------------------------------------------------------===//
618
  //  Accessors
619
  //
620
621
  /// Return the SelectionDAG opcode value for this node. For
622
  /// pre-isel nodes (those for which isMachineOpcode returns false), these
623
  /// are the opcode values in the ISD and <target>ISD namespaces. For
624
  /// post-isel opcodes, see getMachineOpcode.
625
5.84G
  unsigned getOpcode()  const { return (unsigned short)NodeType; }
626
627
  /// Test if this node has a target-specific opcode (in the
628
  /// \<target\>ISD namespace).
629
622k
  bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
630
631
  /// Test if this node has a target-specific
632
  /// memory-referencing opcode (in the \<target\>ISD namespace and
633
  /// greater than FIRST_TARGET_MEMORY_OPCODE).
634
74.5M
  bool isTargetMemoryOpcode() const {
635
74.5M
    return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
636
74.5M
  }
637
638
  /// Return true if the type of the node type undefined.
639
74.8M
  bool isUndef() const { return NodeType == ISD::UNDEF; }
640
641
  /// Test if this node is a memory intrinsic (with valid pointer information).
642
  /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
643
  /// non-memory intrinsics (with chains) that are not really instances of
644
  /// MemSDNode. For such nodes, we need some extra state to determine the
645
  /// proper classof relationship.
646
1.69M
  bool isMemIntrinsic() const {
647
1.69M
    return (NodeType == ISD::INTRINSIC_W_CHAIN ||
648
1.69M
            
NodeType == ISD::INTRINSIC_VOID1.65M
) &&
649
1.69M
           
SDNodeBits.IsMemIntrinsic86.3k
;
650
1.69M
  }
651
652
  /// Test if this node is a strict floating point pseudo-op.
653
32.3M
  bool isStrictFPOpcode() {
654
32.3M
    switch (NodeType) {
655
32.3M
      default:
656
32.3M
        return false;
657
32.3M
      case ISD::STRICT_FADD:
658
315
      case ISD::STRICT_FSUB:
659
315
      case ISD::STRICT_FMUL:
660
315
      case ISD::STRICT_FDIV:
661
315
      case ISD::STRICT_FREM:
662
315
      case ISD::STRICT_FMA:
663
315
      case ISD::STRICT_FSQRT:
664
315
      case ISD::STRICT_FPOW:
665
315
      case ISD::STRICT_FPOWI:
666
315
      case ISD::STRICT_FSIN:
667
315
      case ISD::STRICT_FCOS:
668
315
      case ISD::STRICT_FEXP:
669
315
      case ISD::STRICT_FEXP2:
670
315
      case ISD::STRICT_FLOG:
671
315
      case ISD::STRICT_FLOG10:
672
315
      case ISD::STRICT_FLOG2:
673
315
      case ISD::STRICT_FRINT:
674
315
      case ISD::STRICT_FNEARBYINT:
675
315
      case ISD::STRICT_FMAXNUM:
676
315
      case ISD::STRICT_FMINNUM:
677
315
      case ISD::STRICT_FCEIL:
678
315
      case ISD::STRICT_FFLOOR:
679
315
      case ISD::STRICT_FROUND:
680
315
      case ISD::STRICT_FTRUNC:
681
315
        return true;
682
32.3M
    }
683
32.3M
  }
684
685
  /// Test if this node has a post-isel opcode, directly
686
  /// corresponding to a MachineInstr opcode.
687
272M
  bool isMachineOpcode() const { return NodeType < 0; }
688
689
  /// This may only be called if isMachineOpcode returns
690
  /// true. It returns the MachineInstr opcode value that the node's opcode
691
  /// corresponds to.
692
130M
  unsigned getMachineOpcode() const {
693
130M
    assert(isMachineOpcode() && "Not a MachineInstr opcode!");
694
130M
    return ~NodeType;
695
130M
  }
696
697
17.2M
  bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
698
568
  void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
699
700
124M
  bool isDivergent() const { return SDNodeBits.IsDivergent; }
701
702
  /// Return true if there are no uses of this node.
703
602M
  bool use_empty() const { return UseList == nullptr; }
704
705
  /// Return true if there is exactly one use of this node.
706
41.6M
  bool hasOneUse() const {
707
41.6M
    return !use_empty() && 
std::next(use_begin()) == use_end()41.6M
;
708
41.6M
  }
709
710
  /// Return the number of uses of this node. This method takes
711
  /// time proportional to the number of uses.
712
1.67k
  size_t use_size() const { return std::distance(use_begin(), use_end()); }
713
714
  /// Return the unique node id.
715
319M
  int getNodeId() const { return NodeId; }
716
717
  /// Set unique node id.
718
446M
  void setNodeId(int Id) { NodeId = Id; }
719
720
  /// Return the node ordering.
721
205M
  unsigned getIROrder() const { return IROrder; }
722
723
  /// Set the node ordering.
724
154k
  void setIROrder(unsigned Order) { IROrder = Order; }
725
726
  /// Return the source location info.
727
146M
  const DebugLoc &getDebugLoc() const { return debugLoc; }
728
729
  /// Set source location info.  Try to avoid this, putting
730
  /// it in the constructor is preferable.
731
964k
  void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
732
733
  /// This class provides iterator support for SDUse
734
  /// operands that use a specific SDNode.
735
  class use_iterator
736
    : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
737
    friend class SDNode;
738
739
    SDUse *Op = nullptr;
740
741
546M
    explicit use_iterator(SDUse *op) : Op(op) {}
742
743
  public:
744
    using reference = std::iterator<std::forward_iterator_tag,
745
                                    SDUse, ptrdiff_t>::reference;
746
    using pointer = std::iterator<std::forward_iterator_tag,
747
                                  SDUse, ptrdiff_t>::pointer;
748
749
    use_iterator() = default;
750
233M
    use_iterator(const use_iterator &I) : Op(I.Op) {}
751
752
611M
    bool operator==(const use_iterator &x) const {
753
611M
      return Op == x.Op;
754
611M
    }
755
569M
    bool operator!=(const use_iterator &x) const {
756
569M
      return !operator==(x);
757
569M
    }
758
759
    /// Return true if this iterator is at the end of uses list.
760
    bool atEnd() const { return Op == nullptr; }
761
762
    // Iterator traversal: forward iteration only.
763
364M
    use_iterator &operator++() {          // Preincrement
764
364M
      assert(Op && "Cannot increment end iterator!");
765
364M
      Op = Op->getNext();
766
364M
      return *this;
767
364M
    }
768
769
146
    use_iterator operator++(int) {        // Postincrement
770
146
      use_iterator tmp = *this; ++*this; return tmp;
771
146
    }
772
773
    /// Retrieve a pointer to the current user node.
774
287M
    SDNode *operator*() const {
775
287M
      assert(Op && "Cannot dereference end iterator!");
776
287M
      return Op->getUser();
777
287M
    }
778
779
1.34M
    SDNode *operator->() const { return operator*(); }
780
781
92.8M
    SDUse &getUse() const { return *Op; }
782
783
    /// Retrieve the operand # of this use in its user.
784
10.8M
    unsigned getOperandNo() const {
785
10.8M
      assert(Op && "Cannot dereference end iterator!");
786
10.8M
      return (unsigned)(Op - Op->getUser()->OperandList);
787
10.8M
    }
788
  };
789
790
  /// Provide iteration support to walk over all uses of an SDNode.
791
274M
  use_iterator use_begin() const {
792
274M
    return use_iterator(UseList);
793
274M
  }
794
795
272M
  static use_iterator use_end() { return use_iterator(nullptr); }
796
797
30.8M
  inline iterator_range<use_iterator> uses() {
798
30.8M
    return make_range(use_begin(), use_end());
799
30.8M
  }
800
1.13M
  inline iterator_range<use_iterator> uses() const {
801
1.13M
    return make_range(use_begin(), use_end());
802
1.13M
  }
803
804
  /// Return true if there are exactly NUSES uses of the indicated value.
805
  /// This method ignores uses of other values defined by this operation.
806
  bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
807
808
  /// Return true if there are any use of the indicated value.
809
  /// This method ignores uses of other values defined by this operation.
810
  bool hasAnyUseOfValue(unsigned Value) const;
811
812
  /// Return true if this node is the only use of N.
813
  bool isOnlyUserOf(const SDNode *N) const;
814
815
  /// Return true if this node is an operand of N.
816
  bool isOperandOf(const SDNode *N) const;
817
818
  /// Return true if this node is a predecessor of N.
819
  /// NOTE: Implemented on top of hasPredecessor and every bit as
820
  /// expensive. Use carefully.
821
26.2k
  bool isPredecessorOf(const SDNode *N) const {
822
26.2k
    return N->hasPredecessor(this);
823
26.2k
  }
824
825
  /// Return true if N is a predecessor of this node.
826
  /// N is either an operand of this node, or can be reached by recursively
827
  /// traversing up the operands.
828
  /// NOTE: This is an expensive method. Use it carefully.
829
  bool hasPredecessor(const SDNode *N) const;
830
831
  /// Returns true if N is a predecessor of any node in Worklist. This
832
  /// helper keeps Visited and Worklist sets externally to allow unions
833
  /// searches to be performed in parallel, caching of results across
834
  /// queries and incremental addition to Worklist. Stops early if N is
835
  /// found but will resume. Remember to clear Visited and Worklists
836
  /// if DAG changes. MaxSteps gives a maximum number of nodes to visit before
837
  /// giving up. The TopologicalPrune flag signals that positive NodeIds are
838
  /// topologically ordered (Operands have strictly smaller node id) and search
839
  /// can be pruned leveraging this.
840
  static bool hasPredecessorHelper(const SDNode *N,
841
                                   SmallPtrSetImpl<const SDNode *> &Visited,
842
                                   SmallVectorImpl<const SDNode *> &Worklist,
843
                                   unsigned int MaxSteps = 0,
844
479k
                                   bool TopologicalPrune = false) {
845
479k
    SmallVector<const SDNode *, 8> DeferredNodes;
846
479k
    if (Visited.count(N))
847
52.4k
      return true;
848
427k
849
427k
    // Node Id's are assigned in three places: As a topological
850
427k
    // ordering (> 0), during legalization (results in values set to
851
427k
    // 0), new nodes (set to -1). If N has a topolgical id then we
852
427k
    // know that all nodes with ids smaller than it cannot be
853
427k
    // successors and we need not check them. Filter out all node
854
427k
    // that can't be matches. We add them to the worklist before exit
855
427k
    // in case of multiple calls. Note that during selection the topological id
856
427k
    // may be violated if a node's predecessor is selected before it. We mark
857
427k
    // this at selection negating the id of unselected successors and
858
427k
    // restricting topological pruning to positive ids.
859
427k
860
427k
    int NId = N->getNodeId();
861
427k
    // If we Invalidated the Id, reconstruct original NId.
862
427k
    if (NId < -1)
863
20.4k
      NId = -(NId + 1);
864
427k
865
427k
    bool Found = false;
866
5.59M
    while (!Worklist.empty()) {
867
5.21M
      const SDNode *M = Worklist.pop_back_val();
868
5.21M
      int MId = M->getNodeId();
869
5.21M
      if (TopologicalPrune && 
M->getOpcode() != ISD::TokenFactor178k
&&
(NId > 0)175k
&&
870
5.21M
          
(MId > 0)175k
&&
(MId < NId)168k
) {
871
124k
        DeferredNodes.push_back(M);
872
124k
        continue;
873
124k
      }
874
9.40M
      
for (const SDValue &OpV : M->op_values())5.09M
{
875
9.40M
        SDNode *Op = OpV.getNode();
876
9.40M
        if (Visited.insert(Op).second)
877
4.72M
          Worklist.push_back(Op);
878
9.40M
        if (Op == N)
879
51.4k
          Found = true;
880
9.40M
      }
881
5.09M
      if (Found)
882
50.5k
        break;
883
5.04M
      if (MaxSteps != 0 && 
Visited.size() >= MaxSteps671k
)
884
0
        break;
885
5.04M
    }
886
427k
    // Push deferred nodes back on worklist.
887
427k
    Worklist.append(DeferredNodes.begin(), DeferredNodes.end());
888
427k
    // If we bailed early, conservatively return found.
889
427k
    if (MaxSteps != 0 && 
Visited.size() >= MaxSteps126k
)
890
0
      return true;
891
427k
    return Found;
892
427k
  }
893
894
  /// Return true if all the users of N are contained in Nodes.
895
  /// NOTE: Requires at least one match, but doesn't require them all.
896
  static bool areOnlyUsersOf(ArrayRef<const SDNode *> Nodes, const SDNode *N);
897
898
  /// Return the number of values used by this operation.
899
584M
  unsigned getNumOperands() const { return NumOperands; }
900
901
  /// Helper method returns the integer value of a ConstantSDNode operand.
902
  inline uint64_t getConstantOperandVal(unsigned Num) const;
903
904
1.10G
  const SDValue &getOperand(unsigned Num) const {
905
1.10G
    assert(Num < NumOperands && "Invalid child # of SDNode!");
906
1.10G
    return OperandList[Num];
907
1.10G
  }
908
909
  using op_iterator = SDUse *;
910
911
325M
  op_iterator op_begin() const { return OperandList; }
912
318M
  op_iterator op_end() const { return OperandList+NumOperands; }
913
74.7M
  ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
914
915
  /// Iterator for directly iterating over the operand SDValue's.
916
  struct value_op_iterator
917
      : iterator_adaptor_base<value_op_iterator, op_iterator,
918
                              std::random_access_iterator_tag, SDValue,
919
                              ptrdiff_t, value_op_iterator *,
920
                              value_op_iterator *> {
921
    explicit value_op_iterator(SDUse *U = nullptr)
922
374M
      : iterator_adaptor_base(U) {}
923
924
336M
    const SDValue &operator*() const { return I->get(); }
925
  };
926
927
187M
  iterator_range<value_op_iterator> op_values() const {
928
187M
    return make_range(value_op_iterator(op_begin()),
929
187M
                      value_op_iterator(op_end()));
930
187M
  }
931
932
74.6M
  SDVTList getVTList() const {
933
74.6M
    SDVTList X = { ValueList, NumValues };
934
74.6M
    return X;
935
74.6M
  }
936
937
  /// If this node has a glue operand, return the node
938
  /// to which the glue operand points. Otherwise return NULL.
939
85.7M
  SDNode *getGluedNode() const {
940
85.7M
    if (getNumOperands() != 0 &&
941
85.7M
        
getOperand(getNumOperands()-1).getValueType() == MVT::Glue85.2M
)
942
15.8M
      return getOperand(getNumOperands()-1).getNode();
943
69.8M
    return nullptr;
944
69.8M
  }
945
946
  /// If this node has a glue value with a user, return
947
  /// the user (there is at most one). Otherwise return NULL.
948
3.94M
  SDNode *getGluedUser() const {
949
8.99M
    for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; 
++UI5.04M
)
950
6.72M
      if (UI.getUse().get().getValueType() == MVT::Glue)
951
1.67M
        return *UI;
952
3.94M
    
return nullptr2.27M
;
953
3.94M
  }
954
955
21.9M
  const SDNodeFlags getFlags() const { return Flags; }
956
18.6M
  void setFlags(SDNodeFlags NewFlags) { Flags = NewFlags; }
957
  bool isFast() { return Flags.isFast(); }
958
959
  /// Clear any flags in this node that aren't also set in Flags.
960
  /// If Flags is not in a defined state then this has no effect.
961
  void intersectFlagsWith(const SDNodeFlags Flags);
962
963
  /// Return the number of values defined/returned by this operator.
964
174M
  unsigned getNumValues() const { return NumValues; }
965
966
  /// Return the type of a specified result.
967
1.06G
  EVT getValueType(unsigned ResNo) const {
968
1.06G
    assert(ResNo < NumValues && "Illegal result number!");
969
1.06G
    return ValueList[ResNo];
970
1.06G
  }
971
972
  /// Return the type of a specified result as a simple type.
973
35.6M
  MVT getSimpleValueType(unsigned ResNo) const {
974
35.6M
    return getValueType(ResNo).getSimpleVT();
975
35.6M
  }
976
977
  /// Returns MVT::getSizeInBits(getValueType(ResNo)).
978
988k
  unsigned getValueSizeInBits(unsigned ResNo) const {
979
988k
    return getValueType(ResNo).getSizeInBits();
980
988k
  }
981
982
  using value_iterator = const EVT *;
983
984
39.3M
  value_iterator value_begin() const { return ValueList; }
985
39.3M
  value_iterator value_end() const { return ValueList+NumValues; }
986
987
  /// Return the opcode of this operation for printing.
988
  std::string getOperationName(const SelectionDAG *G = nullptr) const;
989
  static const char* getIndexedModeName(ISD::MemIndexedMode AM);
990
  void print_types(raw_ostream &OS, const SelectionDAG *G) const;
991
  void print_details(raw_ostream &OS, const SelectionDAG *G) const;
992
  void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
993
  void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
994
995
  /// Print a SelectionDAG node and all children down to
996
  /// the leaves.  The given SelectionDAG allows target-specific nodes
997
  /// to be printed in human-readable form.  Unlike printr, this will
998
  /// print the whole DAG, including children that appear multiple
999
  /// times.
1000
  ///
1001
  void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
1002
1003
  /// Print a SelectionDAG node and children up to
1004
  /// depth "depth."  The given SelectionDAG allows target-specific
1005
  /// nodes to be printed in human-readable form.  Unlike printr, this
1006
  /// will print children that appear multiple times wherever they are
1007
  /// used.
1008
  ///
1009
  void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
1010
                       unsigned depth = 100) const;
1011
1012
  /// Dump this node, for debugging.
1013
  void dump() const;
1014
1015
  /// Dump (recursively) this node and its use-def subgraph.
1016
  void dumpr() const;
1017
1018
  /// Dump this node, for debugging.
1019
  /// The given SelectionDAG allows target-specific nodes to be printed
1020
  /// in human-readable form.
1021
  void dump(const SelectionDAG *G) const;
1022
1023
  /// Dump (recursively) this node and its use-def subgraph.
1024
  /// The given SelectionDAG allows target-specific nodes to be printed
1025
  /// in human-readable form.
1026
  void dumpr(const SelectionDAG *G) const;
1027
1028
  /// printrFull to dbgs().  The given SelectionDAG allows
1029
  /// target-specific nodes to be printed in human-readable form.
1030
  /// Unlike dumpr, this will print the whole DAG, including children
1031
  /// that appear multiple times.
1032
  void dumprFull(const SelectionDAG *G = nullptr) const;
1033
1034
  /// printrWithDepth to dbgs().  The given
1035
  /// SelectionDAG allows target-specific nodes to be printed in
1036
  /// human-readable form.  Unlike dumpr, this will print children
1037
  /// that appear multiple times wherever they are used.
1038
  ///
1039
  void dumprWithDepth(const SelectionDAG *G = nullptr,
1040
                      unsigned depth = 100) const;
1041
1042
  /// Gather unique data for the node.
1043
  void Profile(FoldingSetNodeID &ID) const;
1044
1045
  /// This method should only be used by the SDUse class.
1046
167M
  void addUse(SDUse &U) { U.addToList(&UseList); }
1047
1048
protected:
1049
47.1M
  static SDVTList getSDVTList(EVT VT) {
1050
47.1M
    SDVTList Ret = { getValueTypeList(VT), 1 };
1051
47.1M
    return Ret;
1052
47.1M
  }
1053
1054
  /// Create an SDNode.
1055
  ///
1056
  /// SDNodes are created without any operands, and never own the operand
1057
  /// storage. To add operands, see SelectionDAG::createOperands.
1058
  SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
1059
      : NodeType(Opc), ValueList(VTs.VTs), NumValues(VTs.NumVTs),
1060
87.0M
        IROrder(Order), debugLoc(std::move(dl)) {
1061
87.0M
    memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
1062
87.0M
    assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
1063
87.0M
    assert(NumValues == VTs.NumVTs &&
1064
87.0M
           "NumValues wasn't wide enough for its operands!");
1065
87.0M
  }
1066
1067
  /// Release the operands and set this node to have zero operands.
1068
  void DropOperands();
1069
};
1070
1071
/// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
1072
/// into SDNode creation functions.
1073
/// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
1074
/// from the original Instruction, and IROrder is the ordinal position of
1075
/// the instruction.
1076
/// When an SDNode is created after the DAG is being built, both DebugLoc and
1077
/// the IROrder are propagated from the original SDNode.
1078
/// So SDLoc class provides two constructors besides the default one, one to
1079
/// be used by the DAGBuilder, the other to be used by others.
1080
0
class SDLoc {
1081
private:
1082
  DebugLoc DL;
1083
  int IROrder = 0;
1084
1085
public:
1086
7.09M
  SDLoc() = default;
1087
125M
  SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
1088
48.2M
  SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
1089
21.1M
  SDLoc(const Instruction *I, int Order) : IROrder(Order) {
1090
21.1M
    assert(Order >= 0 && "bad IROrder");
1091
21.1M
    if (I)
1092
19.5M
      DL = I->getDebugLoc();
1093
21.1M
  }
1094
1095
65.1M
  unsigned getIROrder() const { return IROrder; }
1096
43.8M
  const DebugLoc &getDebugLoc() const { return DL; }
1097
};
1098
1099
// Define inline functions from the SDValue class.
1100
1101
inline SDValue::SDValue(SDNode *node, unsigned resno)
1102
271M
    : Node(node), ResNo(resno) {
1103
271M
  // Explicitly check for !ResNo to avoid use-after-free, because there are
1104
271M
  // callers that use SDValue(N, 0) with a deleted N to indicate successful
1105
271M
  // combines.
1106
271M
  assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&
1107
271M
         "Invalid result number for the given node!");
1108
271M
  assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
1109
271M
}
1110
1111
572M
inline unsigned SDValue::getOpcode() const {
1112
572M
  return Node->getOpcode();
1113
572M
}
1114
1115
745M
inline EVT SDValue::getValueType() const {
1116
745M
  return Node->getValueType(ResNo);
1117
745M
}
1118
1119
85.6M
inline unsigned SDValue::getNumOperands() const {
1120
85.6M
  return Node->getNumOperands();
1121
85.6M
}
1122
1123
183M
inline const SDValue &SDValue::getOperand(unsigned i) const {
1124
183M
  return Node->getOperand(i);
1125
183M
}
1126
1127
1.44M
inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1128
1.44M
  return Node->getConstantOperandVal(i);
1129
1.44M
}
1130
1131
inline bool SDValue::isTargetOpcode() const {
1132
  return Node->isTargetOpcode();
1133
}
1134
1135
inline bool SDValue::isTargetMemoryOpcode() const {
1136
  return Node->isTargetMemoryOpcode();
1137
}
1138
1139
41.6M
inline bool SDValue::isMachineOpcode() const {
1140
41.6M
  return Node->isMachineOpcode();
1141
41.6M
}
1142
1143
8.07M
inline unsigned SDValue::getMachineOpcode() const {
1144
8.07M
  return Node->getMachineOpcode();
1145
8.07M
}
1146
1147
74.4M
inline bool SDValue::isUndef() const {
1148
74.4M
  return Node->isUndef();
1149
74.4M
}
1150
1151
1.08M
inline bool SDValue::use_empty() const {
1152
1.08M
  return !Node->hasAnyUseOfValue(ResNo);
1153
1.08M
}
1154
1155
23.3M
inline bool SDValue::hasOneUse() const {
1156
23.3M
  return Node->hasNUsesOfValue(1, ResNo);
1157
23.3M
}
1158
1159
126k
inline const DebugLoc &SDValue::getDebugLoc() const {
1160
126k
  return Node->getDebugLoc();
1161
126k
}
1162
1163
inline void SDValue::dump() const {
1164
  return Node->dump();
1165
}
1166
1167
inline void SDValue::dump(const SelectionDAG *G) const {
1168
  return Node->dump(G);
1169
}
1170
1171
inline void SDValue::dumpr() const {
1172
  return Node->dumpr();
1173
}
1174
1175
inline void SDValue::dumpr(const SelectionDAG *G) const {
1176
  return Node->dumpr(G);
1177
}
1178
1179
// Define inline functions from the SDUse class.
1180
1181
101M
inline void SDUse::set(const SDValue &V) {
1182
101M
  if (Val.getNode()) 
removeFromList()101M
;
1183
101M
  Val = V;
1184
101M
  if (V.getNode()) 
V.getNode()->addUse(*this)11.4M
;
1185
101M
}
1186
1187
152M
inline void SDUse::setInitial(const SDValue &V) {
1188
152M
  Val = V;
1189
152M
  V.getNode()->addUse(*this);
1190
152M
}
1191
1192
3.50M
inline void SDUse::setNode(SDNode *N) {
1193
3.50M
  if (Val.getNode()) removeFromList();
1194
3.50M
  Val.setNode(N);
1195
3.50M
  if (N) N->addUse(*this);
1196
3.50M
}
1197
1198
/// This class is used to form a handle around another node that
1199
/// is persistent and is updated across invocations of replaceAllUsesWith on its
1200
/// operand.  This node should be directly created by end-users and not added to
1201
/// the AllNodes list.
1202
class HandleSDNode : public SDNode {
1203
  SDUse Op;
1204
1205
public:
1206
  explicit HandleSDNode(SDValue X)
1207
17.4M
    : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1208
17.4M
    // HandleSDNodes are never inserted into the DAG, so they won't be
1209
17.4M
    // auto-numbered. Use ID 65535 as a sentinel.
1210
17.4M
    PersistentId = 0xffff;
1211
17.4M
1212
17.4M
    // Manually set up the operand list. This node type is special in that it's
1213
17.4M
    // always stack allocated and SelectionDAG does not manage its operands.
1214
17.4M
    // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1215
17.4M
    // be so special.
1216
17.4M
    Op.setUser(this);
1217
17.4M
    Op.setInitial(X);
1218
17.4M
    NumOperands = 1;
1219
17.4M
    OperandList = &Op;
1220
17.4M
  }
1221
  ~HandleSDNode();
1222
1223
16.1M
  const SDValue &getValue() const { return Op; }
1224
};
1225
1226
class AddrSpaceCastSDNode : public SDNode {
1227
private:
1228
  unsigned SrcAddrSpace;
1229
  unsigned DestAddrSpace;
1230
1231
public:
1232
  AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
1233
                      unsigned SrcAS, unsigned DestAS);
1234
1235
458
  unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1236
381
  unsigned getDestAddressSpace() const { return DestAddrSpace; }
1237
1238
1.28k
  static bool classof(const SDNode *N) {
1239
1.28k
    return N->getOpcode() == ISD::ADDRSPACECAST;
1240
1.28k
  }
1241
};
1242
1243
/// This is an abstract virtual class for memory operations.
1244
class MemSDNode : public SDNode {
1245
private:
1246
  // VT of in-memory value.
1247
  EVT MemoryVT;
1248
1249
protected:
1250
  /// Memory reference information.
1251
  MachineMemOperand *MMO;
1252
1253
public:
1254
  MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1255
            EVT memvt, MachineMemOperand *MMO);
1256
1257
3.72k
  bool readMem() const { return MMO->isLoad(); }
1258
18.7k
  bool writeMem() const { return MMO->isStore(); }
1259
1260
  /// Returns alignment and volatility of the memory access
1261
6.05M
  unsigned getOriginalAlignment() const {
1262
6.05M
    return MMO->getBaseAlignment();
1263
6.05M
  }
1264
16.7M
  unsigned getAlignment() const {
1265
16.7M
    return MMO->getAlignment();
1266
16.7M
  }
1267
1268
  /// Return the SubclassData value, without HasDebugValue. This contains an
1269
  /// encoding of the volatile flag, as well as bits used by subclasses. This
1270
  /// function should only be used to compute a FoldingSetNodeID value.
1271
  /// The HasDebugValue bit is masked out because CSE map needs to match
1272
  /// nodes with debug info with nodes without debug info. Same is about
1273
  /// isDivergent bit.
1274
10.0M
  unsigned getRawSubclassData() const {
1275
10.0M
    uint16_t Data;
1276
10.0M
    union {
1277
10.0M
      char RawSDNodeBits[sizeof(uint16_t)];
1278
10.0M
      SDNodeBitfields SDNodeBits;
1279
10.0M
    };
1280
10.0M
    memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1281
10.0M
    SDNodeBits.HasDebugValue = 0;
1282
10.0M
    SDNodeBits.IsDivergent = false;
1283
10.0M
    memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1284
10.0M
    return Data;
1285
10.0M
  }
1286
1287
38.1M
  bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1288
802k
  bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1289
32.4k
  bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1290
10.2M
  bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1291
1292
  // Returns the offset from the location of the access.
1293
6.08M
  int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1294
1295
  /// Returns the AA info that describes the dereference.
1296
5.75M
  AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1297
1298
  /// Returns the Ranges that describes the dereference.
1299
5.02M
  const MDNode *getRanges() const { return MMO->getRanges(); }
1300
1301
  /// Returns the synchronization scope ID for this memory operation.
1302
0
  SyncScope::ID getSyncScopeID() const { return MMO->getSyncScopeID(); }
1303
1304
  /// Return the atomic ordering requirements for this memory operation. For
1305
  /// cmpxchg atomic operations, return the atomic ordering requirements when
1306
  /// store occurs.
1307
133k
  AtomicOrdering getOrdering() const { return MMO->getOrdering(); }
1308
1309
  /// Return the type of the in-memory value.
1310
56.5M
  EVT getMemoryVT() const { return MemoryVT; }
1311
1312
  /// Return a MachineMemOperand object describing the memory
1313
  /// reference performed by operation.
1314
9.67M
  MachineMemOperand *getMemOperand() const { return MMO; }
1315
1316
16.0M
  const MachinePointerInfo &getPointerInfo() const {
1317
16.0M
    return MMO->getPointerInfo();
1318
16.0M
  }
1319
1320
  /// Return the address space for the associated pointer
1321
8.90M
  unsigned getAddressSpace() const {
1322
8.90M
    return getPointerInfo().getAddrSpace();
1323
8.90M
  }
1324
1325
  /// Update this MemSDNode's MachineMemOperand information
1326
  /// to reflect the alignment of NewMMO, if it has a greater alignment.
1327
  /// This must only be used when the new alignment applies to all users of
1328
  /// this MachineMemOperand.
1329
67.8k
  void refineAlignment(const MachineMemOperand *NewMMO) {
1330
67.8k
    MMO->refineAlignment(NewMMO);
1331
67.8k
  }
1332
1333
51.3M
  const SDValue &getChain() const { return getOperand(0); }
1334
37.1M
  const SDValue &getBasePtr() const {
1335
37.1M
    return getOperand(getOpcode() == ISD::STORE ? 
228.9M
:
18.26M
);
1336
37.1M
  }
1337
1338
  // Methods to support isa and dyn_cast
1339
13.3M
  static bool classof(const SDNode *N) {
1340
13.3M
    // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1341
13.3M
    // with either an intrinsic or a target opcode.
1342
13.3M
    return N->getOpcode() == ISD::LOAD                ||
1343
13.3M
           
N->getOpcode() == ISD::STORE8.59M
||
1344
13.3M
           
N->getOpcode() == ISD::PREFETCH1.72M
||
1345
13.3M
           
N->getOpcode() == ISD::ATOMIC_CMP_SWAP1.72M
||
1346
13.3M
           
N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS1.72M
||
1347
13.3M
           
N->getOpcode() == ISD::ATOMIC_SWAP1.71M
||
1348
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD_ADD1.71M
||
1349
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD_SUB1.71M
||
1350
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD_AND1.71M
||
1351
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD_CLR1.71M
||
1352
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD_OR1.71M
||
1353
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD_XOR1.71M
||
1354
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD_NAND1.70M
||
1355
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD_MIN1.70M
||
1356
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD_MAX1.70M
||
1357
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD_UMIN1.70M
||
1358
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD_UMAX1.70M
||
1359
13.3M
           
N->getOpcode() == ISD::ATOMIC_LOAD1.70M
||
1360
13.3M
           
N->getOpcode() == ISD::ATOMIC_STORE1.70M
||
1361
13.3M
           
N->getOpcode() == ISD::MLOAD1.69M
||
1362
13.3M
           
N->getOpcode() == ISD::MSTORE1.69M
||
1363
13.3M
           
N->getOpcode() == ISD::MGATHER1.69M
||
1364
13.3M
           
N->getOpcode() == ISD::MSCATTER1.69M
||
1365
13.3M
           
N->isMemIntrinsic()1.69M
||
1366
13.3M
           
N->isTargetMemoryOpcode()1.61M
;
1367
13.3M
  }
1368
};
1369
1370
/// This is an SDNode representing atomic operations.
1371
class AtomicSDNode : public MemSDNode {
1372
public:
1373
  AtomicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTL,
1374
               EVT MemVT, MachineMemOperand *MMO)
1375
22.2k
      : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {}
1376
1377
3.85k
  const SDValue &getBasePtr() const { return getOperand(1); }
1378
342
  const SDValue &getVal() const { return getOperand(2); }
1379
1380
  /// Returns true if this SDNode represents cmpxchg atomic operation, false
1381
  /// otherwise.
1382
  bool isCompareAndSwap() const {
1383
    unsigned Op = getOpcode();
1384
    return Op == ISD::ATOMIC_CMP_SWAP ||
1385
           Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1386
  }
1387
1388
  /// For cmpxchg atomic operations, return the atomic ordering requirements
1389
  /// when store does not occur.
1390
  AtomicOrdering getFailureOrdering() const {
1391
    assert(isCompareAndSwap() && "Must be cmpxchg operation");
1392
    return MMO->getFailureOrdering();
1393
  }
1394
1395
  // Methods to support isa and dyn_cast
1396
583k
  static bool classof(const SDNode *N) {
1397
583k
    return N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
1398
583k
           
N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS583k
||
1399
583k
           
N->getOpcode() == ISD::ATOMIC_SWAP583k
||
1400
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD_ADD583k
||
1401
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD_SUB583k
||
1402
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD_AND583k
||
1403
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD_CLR583k
||
1404
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD_OR583k
||
1405
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD_XOR583k
||
1406
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD_NAND582k
||
1407
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD_MIN582k
||
1408
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD_MAX582k
||
1409
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD_UMIN582k
||
1410
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD_UMAX582k
||
1411
583k
           
N->getOpcode() == ISD::ATOMIC_LOAD582k
||
1412
583k
           
N->getOpcode() == ISD::ATOMIC_STORE582k
;
1413
583k
  }
1414
};
1415
1416
/// This SDNode is used for target intrinsics that touch
1417
/// memory and need an associated MachineMemOperand. Its opcode may be
1418
/// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1419
/// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1420
class MemIntrinsicSDNode : public MemSDNode {
1421
public:
1422
  MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1423
                     SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
1424
163k
      : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MMO) {
1425
163k
    SDNodeBits.IsMemIntrinsic = true;
1426
163k
  }
1427
1428
  // Methods to support isa and dyn_cast
1429
186
  static bool classof(const SDNode *N) {
1430
186
    // We lower some target intrinsics to their target opcode
1431
186
    // early a node with a target opcode can be of this class
1432
186
    return N->isMemIntrinsic()             ||
1433
186
           
N->getOpcode() == ISD::PREFETCH0
||
1434
186
           
N->isTargetMemoryOpcode()0
;
1435
186
  }
1436
};
1437
1438
/// This SDNode is used to implement the code generator
1439
/// support for the llvm IR shufflevector instruction.  It combines elements
1440
/// from two input vectors into a new input vector, with the selection and
1441
/// ordering of elements determined by an array of integers, referred to as
1442
/// the shuffle mask.  For input vectors of width N, mask indices of 0..N-1
1443
/// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1444
/// An index of -1 is treated as undef, such that the code generator may put
1445
/// any value in the corresponding element of the result.
1446
class ShuffleVectorSDNode : public SDNode {
1447
  // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1448
  // is freed when the SelectionDAG object is destroyed.
1449
  const int *Mask;
1450
1451
protected:
1452
  friend class SelectionDAG;
1453
1454
  ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
1455
130k
      : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {}
1456
1457
public:
1458
500k
  ArrayRef<int> getMask() const {
1459
500k
    EVT VT = getValueType(0);
1460
500k
    return makeArrayRef(Mask, VT.getVectorNumElements());
1461
500k
  }
1462
1463
3.15M
  int getMaskElt(unsigned Idx) const {
1464
3.15M
    assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1465
3.15M
    return Mask[Idx];
1466
3.15M
  }
1467
1468
111k
  bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1469
1470
40.6k
  int  getSplatIndex() const {
1471
40.6k
    assert(isSplat() && "Cannot get splat index for non-splat!");
1472
40.6k
    EVT VT = getValueType(0);
1473
41.7k
    for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; 
++i1.02k
) {
1474
41.7k
      if (Mask[i] >= 0)
1475
40.6k
        return Mask[i];
1476
41.7k
    }
1477
40.6k
    
llvm_unreachable0
("Splat with all undef indices?");
1478
40.6k
  }
1479
1480
  static bool isSplatMask(const int *Mask, EVT VT);
1481
1482
  /// Change values in a shuffle permute mask assuming
1483
  /// the two vector operands have swapped position.
1484
234k
  static void commuteMask(MutableArrayRef<int> Mask) {
1485
234k
    unsigned NumElems = Mask.size();
1486
3.05M
    for (unsigned i = 0; i != NumElems; 
++i2.82M
) {
1487
2.82M
      int idx = Mask[i];
1488
2.82M
      if (idx < 0)
1489
379k
        continue;
1490
2.44M
      else if (idx < (int)NumElems)
1491
1.49M
        Mask[i] = idx + NumElems;
1492
949k
      else
1493
949k
        Mask[i] = idx - NumElems;
1494
2.82M
    }
1495
234k
  }
1496
1497
2.01M
  static bool classof(const SDNode *N) {
1498
2.01M
    return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1499
2.01M
  }
1500
};
1501
1502
class ConstantSDNode : public SDNode {
1503
  friend class SelectionDAG;
1504
1505
  const ConstantInt *Value;
1506
1507
  ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1508
      : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DebugLoc(),
1509
               getSDVTList(VT)),
1510
13.2M
        Value(val) {
1511
13.2M
    ConstantSDNodeBits.IsOpaque = isOpaque;
1512
13.2M
  }
1513
1514
public:
1515
20.8M
  const ConstantInt *getConstantIntValue() const { return Value; }
1516
54.0M
  const APInt &getAPIntValue() const { return Value->getValue(); }
1517
18.1M
  uint64_t getZExtValue() const { return Value->getZExtValue(); }
1518
53.1M
  int64_t getSExtValue() const { return Value->getSExtValue(); }
1519
341
  uint64_t getLimitedValue(uint64_t Limit = UINT64_MAX) {
1520
341
    return Value->getLimitedValue(Limit);
1521
341
  }
1522
1523
7.03M
  bool isOne() const { return Value->isOne(); }
1524
18.7M
  bool isNullValue() const { return Value->isZero(); }
1525
6.57M
  bool isAllOnesValue() const { return Value->isMinusOne(); }
1526
1527
27.9M
  bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1528
1529
432M
  static bool classof(const SDNode *N) {
1530
432M
    return N->getOpcode() == ISD::Constant ||
1531
432M
           
N->getOpcode() == ISD::TargetConstant286M
;
1532
432M
  }
1533
};
1534
1535
1.79M
uint64_t SDNode::getConstantOperandVal(unsigned Num) const {
1536
1.79M
  return cast<ConstantSDNode>(getOperand(Num))->getZExtValue();
1537
1.79M
}
1538
1539
class ConstantFPSDNode : public SDNode {
1540
  friend class SelectionDAG;
1541
1542
  const ConstantFP *Value;
1543
1544
  ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1545
      : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0,
1546
               DebugLoc(), getSDVTList(VT)),
1547
116k
        Value(val) {}
1548
1549
public:
1550
368k
  const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1551
175k
  const ConstantFP *getConstantFPValue() const { return Value; }
1552
1553
  /// Return true if the value is positive or negative zero.
1554
160k
  bool isZero() const { return Value->isZero(); }
1555
1556
  /// Return true if the value is a NaN.
1557
7.32k
  bool isNaN() const { return Value->isNaN(); }
1558
1559
  /// Return true if the value is an infinity
1560
2
  bool isInfinity() const { return Value->isInfinity(); }
1561
1562
  /// Return true if the value is negative.
1563
42.8k
  bool isNegative() const { return Value->isNegative(); }
1564
1565
  /// We don't rely on operator== working on double values, as
1566
  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1567
  /// As such, this method can be used to do an exact bit-for-bit comparison of
1568
  /// two floating point values.
1569
1570
  /// We leave the version with the double argument here because it's just so
1571
  /// convenient to write "2.0" and the like.  Without this function we'd
1572
  /// have to duplicate its logic everywhere it's called.
1573
78.3k
  bool isExactlyValue(double V) const {
1574
78.3k
    return Value->getValueAPF().isExactlyValue(V);
1575
78.3k
  }
1576
  bool isExactlyValue(const APFloat& V) const;
1577
1578
  static bool isValueValidForType(EVT VT, const APFloat& Val);
1579
1580
217M
  static bool classof(const SDNode *N) {
1581
217M
    return N->getOpcode() == ISD::ConstantFP ||
1582
217M
           
N->getOpcode() == ISD::TargetConstantFP216M
;
1583
217M
  }
1584
};
1585
1586
/// Returns true if \p V is a constant integer zero.
1587
bool isNullConstant(SDValue V);
1588
1589
/// Returns true if \p V is an FP constant with a value of positive zero.
1590
bool isNullFPConstant(SDValue V);
1591
1592
/// Returns true if \p V is an integer constant with all bits set.
1593
bool isAllOnesConstant(SDValue V);
1594
1595
/// Returns true if \p V is a constant integer one.
1596
bool isOneConstant(SDValue V);
1597
1598
/// Return the non-bitcasted source operand of \p V if it exists.
1599
/// If \p V is not a bitcasted value, it is returned as-is.
1600
SDValue peekThroughBitcasts(SDValue V);
1601
1602
/// Return the non-bitcasted and one-use source operand of \p V if it exists.
1603
/// If \p V is not a bitcasted one-use value, it is returned as-is.
1604
SDValue peekThroughOneUseBitcasts(SDValue V);
1605
1606
/// Returns true if \p V is a bitwise not operation. Assumes that an all ones
1607
/// constant is canonicalized to be operand 1.
1608
bool isBitwiseNot(SDValue V);
1609
1610
/// Returns the SDNode if it is a constant splat BuildVector or constant int.
1611
ConstantSDNode *isConstOrConstSplat(SDValue N, bool AllowUndefs = false);
1612
1613
/// Returns the SDNode if it is a constant splat BuildVector or constant float.
1614
ConstantFPSDNode *isConstOrConstSplatFP(SDValue N, bool AllowUndefs = false);
1615
1616
class GlobalAddressSDNode : public SDNode {
1617
  friend class SelectionDAG;
1618
1619
  const GlobalValue *TheGlobal;
1620
  int64_t Offset;
1621
  unsigned char TargetFlags;
1622
1623
  GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1624
                      const GlobalValue *GA, EVT VT, int64_t o,
1625
                      unsigned char TF);
1626
1627
public:
1628
7.13M
  const GlobalValue *getGlobal() const { return TheGlobal; }
1629
4.70M
  int64_t getOffset() const { return Offset; }
1630
3.06M
  unsigned char getTargetFlags() const { return TargetFlags; }
1631
  // Return the address space this GlobalAddress belongs to.
1632
  unsigned getAddressSpace() const;
1633
1634
139M
  static bool classof(const SDNode *N) {
1635
139M
    return N->getOpcode() == ISD::GlobalAddress ||
1636
139M
           
N->getOpcode() == ISD::TargetGlobalAddress137M
||
1637
139M
           
N->getOpcode() == ISD::GlobalTLSAddress132M
||
1638
139M
           
N->getOpcode() == ISD::TargetGlobalTLSAddress132M
;
1639
139M
  }
1640
};
1641
1642
class FrameIndexSDNode : public SDNode {
1643
  friend class SelectionDAG;
1644
1645
  int FI;
1646
1647
  FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1648
    : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1649
882k
      0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1650
882k
  }
1651
1652
public:
1653
8.01M
  int getIndex() const { return FI; }
1654
1655
94.7M
  static bool classof(const SDNode *N) {
1656
94.7M
    return N->getOpcode() == ISD::FrameIndex ||
1657
94.7M
           
N->getOpcode() == ISD::TargetFrameIndex86.4M
;
1658
94.7M
  }
1659
};
1660
1661
class JumpTableSDNode : public SDNode {
1662
  friend class SelectionDAG;
1663
1664
  int JTI;
1665
  unsigned char TargetFlags;
1666
1667
  JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1668
    : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1669
9.42k
      0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1670
9.42k
  }
1671
1672
public:
1673
15.1k
  int getIndex() const { return JTI; }
1674
8.52k
  unsigned char getTargetFlags() const { return TargetFlags; }
1675
1676
60.2M
  static bool classof(const SDNode *N) {
1677
60.2M
    return N->getOpcode() == ISD::JumpTable ||
1678
60.2M
           
N->getOpcode() == ISD::TargetJumpTable60.2M
;
1679
60.2M
  }
1680
};
1681
1682
class ConstantPoolSDNode : public SDNode {
1683
  friend class SelectionDAG;
1684
1685
  union {
1686
    const Constant *ConstVal;
1687
    MachineConstantPoolValue *MachineCPVal;
1688
  } Val;
1689
  int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1690
  unsigned Alignment;  // Minimum alignment requirement of CP (not log2 value).
1691
  unsigned char TargetFlags;
1692
1693
  ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1694
                     unsigned Align, unsigned char TF)
1695
    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1696
             DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1697
250k
             TargetFlags(TF) {
1698
250k
    assert(Offset >= 0 && "Offset is too large");
1699
250k
    Val.ConstVal = c;
1700
250k
  }
1701
1702
  ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1703
                     EVT VT, int o, unsigned Align, unsigned char TF)
1704
    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1705
             DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1706
265
             TargetFlags(TF) {
1707
265
    assert(Offset >= 0 && "Offset is too large");
1708
265
    Val.MachineCPVal = v;
1709
265
    Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1710
265
  }
1711
1712
public:
1713
482k
  bool isMachineConstantPoolEntry() const {
1714
482k
    return Offset < 0;
1715
482k
  }
1716
1717
505k
  const Constant *getConstVal() const {
1718
505k
    assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1719
505k
    return Val.ConstVal;
1720
505k
  }
1721
1722
368
  MachineConstantPoolValue *getMachineCPVal() const {
1723
368
    assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1724
368
    return Val.MachineCPVal;
1725
368
  }
1726
1727
499k
  int getOffset() const {
1728
499k
    return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1729
499k
  }
1730
1731
  // Return the alignment of this constant pool object, which is either 0 (for
1732
  // default alignment) or the desired value.
1733
490k
  unsigned getAlignment() const { return Alignment; }
1734
261k
  unsigned char getTargetFlags() const { return TargetFlags; }
1735
1736
  Type *getType() const;
1737
1738
70.3M
  static bool classof(const SDNode *N) {
1739
70.3M
    return N->getOpcode() == ISD::ConstantPool ||
1740
70.3M
           
N->getOpcode() == ISD::TargetConstantPool70.3M
;
1741
70.3M
  }
1742
};
1743
1744
/// Completely target-dependent object reference.
1745
class TargetIndexSDNode : public SDNode {
1746
  friend class SelectionDAG;
1747
1748
  unsigned char TargetFlags;
1749
  int Index;
1750
  int64_t Offset;
1751
1752
public:
1753
  TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1754
    : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1755
0
      TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1756
1757
0
  unsigned char getTargetFlags() const { return TargetFlags; }
1758
0
  int getIndex() const { return Index; }
1759
0
  int64_t getOffset() const { return Offset; }
1760
1761
60.0M
  static bool classof(const SDNode *N) {
1762
60.0M
    return N->getOpcode() == ISD::TargetIndex;
1763
60.0M
  }
1764
};
1765
1766
class BasicBlockSDNode : public SDNode {
1767
  friend class SelectionDAG;
1768
1769
  MachineBasicBlock *MBB;
1770
1771
  /// Debug info is meaningful and potentially useful here, but we create
1772
  /// blocks out of order when they're jumped to, which makes it a bit
1773
  /// harder.  Let's see if we need it first.
1774
  explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1775
    : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1776
1.93M
  {}
1777
1778
public:
1779
2.69M
  MachineBasicBlock *getBasicBlock() const { return MBB; }
1780
1781
68.2M
  static bool classof(const SDNode *N) {
1782
68.2M
    return N->getOpcode() == ISD::BasicBlock;
1783
68.2M
  }
1784
};
1785
1786
/// A "pseudo-class" with methods for operating on BUILD_VECTORs.
1787
class BuildVectorSDNode : public SDNode {
1788
public:
1789
  // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1790
  explicit BuildVectorSDNode() = delete;
1791
1792
  /// Check if this is a constant splat, and if so, find the
1793
  /// smallest element size that splats the vector.  If MinSplatBits is
1794
  /// nonzero, the element size must be at least that large.  Note that the
1795
  /// splat element may be the entire vector (i.e., a one element vector).
1796
  /// Returns the splat element value in SplatValue.  Any undefined bits in
1797
  /// that value are zero, and the corresponding bits in the SplatUndef mask
1798
  /// are set.  The SplatBitSize value is set to the splat element size in
1799
  /// bits.  HasAnyUndefs is set to true if any bits in the vector are
1800
  /// undefined.  isBigEndian describes the endianness of the target.
1801
  bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1802
                       unsigned &SplatBitSize, bool &HasAnyUndefs,
1803
                       unsigned MinSplatBits = 0,
1804
                       bool isBigEndian = false) const;
1805
1806
  /// Returns the splatted value or a null value if this is not a splat.
1807
  ///
1808
  /// If passed a non-null UndefElements bitvector, it will resize it to match
1809
  /// the vector width and set the bits where elements are undef.
1810
  SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1811
1812
  /// Returns the splatted constant or null if this is not a constant
1813
  /// splat.
1814
  ///
1815
  /// If passed a non-null UndefElements bitvector, it will resize it to match
1816
  /// the vector width and set the bits where elements are undef.
1817
  ConstantSDNode *
1818
  getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1819
1820
  /// Returns the splatted constant FP or null if this is not a constant
1821
  /// FP splat.
1822
  ///
1823
  /// If passed a non-null UndefElements bitvector, it will resize it to match
1824
  /// the vector width and set the bits where elements are undef.
1825
  ConstantFPSDNode *
1826
  getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1827
1828
  /// If this is a constant FP splat and the splatted constant FP is an
1829
  /// exact power or 2, return the log base 2 integer value.  Otherwise,
1830
  /// return -1.
1831
  ///
1832
  /// The BitWidth specifies the necessary bit precision.
1833
  int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
1834
                                          uint32_t BitWidth) const;
1835
1836
  bool isConstant() const;
1837
1838
41.4M
  static bool classof(const SDNode *N) {
1839
41.4M
    return N->getOpcode() == ISD::BUILD_VECTOR;
1840
41.4M
  }
1841
};
1842
1843
/// An SDNode that holds an arbitrary LLVM IR Value. This is
1844
/// used when the SelectionDAG needs to make a simple reference to something
1845
/// in the LLVM IR representation.
1846
///
1847
class SrcValueSDNode : public SDNode {
1848
  friend class SelectionDAG;
1849
1850
  const Value *V;
1851
1852
  /// Create a SrcValue for a general value.
1853
  explicit SrcValueSDNode(const Value *v)
1854
1.72k
    : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1855
1856
public:
1857
  /// Return the contained Value.
1858
2.88k
  const Value *getValue() const { return V; }
1859
1860
25
  static bool classof(const SDNode *N) {
1861
25
    return N->getOpcode() == ISD::SRCVALUE;
1862
25
  }
1863
};
1864
1865
class MDNodeSDNode : public SDNode {
1866
  friend class SelectionDAG;
1867
1868
  const MDNode *MD;
1869
1870
  explicit MDNodeSDNode(const MDNode *md)
1871
  : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1872
24.3k
  {}
1873
1874
public:
1875
24.1k
  const MDNode *getMD() const { return MD; }
1876
1877
48.0M
  static bool classof(const SDNode *N) {
1878
48.0M
    return N->getOpcode() == ISD::MDNODE_SDNODE;
1879
48.0M
  }
1880
};
1881
1882
class RegisterSDNode : public SDNode {
1883
  friend class SelectionDAG;
1884
1885
  unsigned Reg;
1886
1887
  RegisterSDNode(unsigned reg, EVT VT)
1888
7.93M
    : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
1889
1890
public:
1891
36.3M
  unsigned getReg() const { return Reg; }
1892
1893
109M
  static bool classof(const SDNode *N) {
1894
109M
    return N->getOpcode() == ISD::Register;
1895
109M
  }
1896
};
1897
1898
class RegisterMaskSDNode : public SDNode {
1899
  friend class SelectionDAG;
1900
1901
  // The memory for RegMask is not owned by the node.
1902
  const uint32_t *RegMask;
1903
1904
  RegisterMaskSDNode(const uint32_t *mask)
1905
    : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1906
556k
      RegMask(mask) {}
1907
1908
public:
1909
1.26M
  const uint32_t *getRegMask() const { return RegMask; }
1910
1911
84.4M
  static bool classof(const SDNode *N) {
1912
84.4M
    return N->getOpcode() == ISD::RegisterMask;
1913
84.4M
  }
1914
};
1915
1916
class BlockAddressSDNode : public SDNode {
1917
  friend class SelectionDAG;
1918
1919
  const BlockAddress *BA;
1920
  int64_t Offset;
1921
  unsigned char TargetFlags;
1922
1923
  BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1924
                     int64_t o, unsigned char Flags)
1925
    : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1926
283
             BA(ba), Offset(o), TargetFlags(Flags) {}
1927
1928
public:
1929
404
  const BlockAddress *getBlockAddress() const { return BA; }
1930
269
  int64_t getOffset() const { return Offset; }
1931
232
  unsigned char getTargetFlags() const { return TargetFlags; }
1932
1933
59.9M
  static bool classof(const SDNode *N) {
1934
59.9M
    return N->getOpcode() == ISD::BlockAddress ||
1935
59.9M
           
N->getOpcode() == ISD::TargetBlockAddress59.9M
;
1936
59.9M
  }
1937
};
1938
1939
class LabelSDNode : public SDNode {
1940
  friend class SelectionDAG;
1941
1942
  MCSymbol *Label;
1943
1944
  LabelSDNode(unsigned Order, const DebugLoc &dl, MCSymbol *L)
1945
48.1k
      : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {}
1946
1947
public:
1948
48.0k
  MCSymbol *getLabel() const { return Label; }
1949
1950
  static bool classof(const SDNode *N) {
1951
    return N->getOpcode() == ISD::EH_LABEL ||
1952
           N->getOpcode() == ISD::ANNOTATION_LABEL;
1953
  }
1954
};
1955
1956
class ExternalSymbolSDNode : public SDNode {
1957
  friend class SelectionDAG;
1958
1959
  const char *Symbol;
1960
  unsigned char TargetFlags;
1961
1962
  ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1963
    : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1964
51.2k
             0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {}
1965
1966
public:
1967
90.9k
  const char *getSymbol() const { return Symbol; }
1968
24.1k
  unsigned char getTargetFlags() const { return TargetFlags; }
1969
1970
60.1M
  static bool classof(const SDNode *N) {
1971
60.1M
    return N->getOpcode() == ISD::ExternalSymbol ||
1972
60.1M
           
N->getOpcode() == ISD::TargetExternalSymbol60.1M
;
1973
60.1M
  }
1974
};
1975
1976
class MCSymbolSDNode : public SDNode {
1977
  friend class SelectionDAG;
1978
1979
  MCSymbol *Symbol;
1980
1981
  MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
1982
66
      : SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
1983
1984
public:
1985
88
  MCSymbol *getMCSymbol() const { return Symbol; }
1986
1987
59.9M
  static bool classof(const SDNode *N) {
1988
59.9M
    return N->getOpcode() == ISD::MCSymbol;
1989
59.9M
  }
1990
};
1991
1992
class CondCodeSDNode : public SDNode {
1993
  friend class SelectionDAG;
1994
1995
  ISD::CondCode Condition;
1996
1997
  explicit CondCodeSDNode(ISD::CondCode Cond)
1998
    : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1999
1.45M
      Condition(Cond) {}
2000
2001
public:
2002
10.4M
  ISD::CondCode get() const { return Condition; }
2003
2004
  static bool classof(const SDNode *N) {
2005
    return N->getOpcode() == ISD::CONDCODE;
2006
  }
2007
};
2008
2009
/// This class is used to represent EVT's, which are used
2010
/// to parameterize some operations.
2011
class VTSDNode : public SDNode {
2012
  friend class SelectionDAG;
2013
2014
  EVT ValueType;
2015
2016
  explicit VTSDNode(EVT VT)
2017
    : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2018
323k
      ValueType(VT) {}
2019
2020
public:
2021
3.46M
  EVT getVT() const { return ValueType; }
2022
2023
31
  static bool classof(const SDNode *N) {
2024
31
    return N->getOpcode() == ISD::VALUETYPE;
2025
31
  }
2026
};
2027
2028
/// Base class for LoadSDNode and StoreSDNode
2029
class LSBaseSDNode : public MemSDNode {
2030
public:
2031
  LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
2032
               SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
2033
               MachineMemOperand *MMO)
2034
7.89M
      : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2035
7.89M
    LSBaseSDNodeBits.AddressingMode = AM;
2036
7.89M
    assert(getAddressingMode() == AM && "Value truncated");
2037
7.89M
  }
2038
2039
18.9k
  const SDValue &getOffset() const {
2040
18.9k
    return getOperand(getOpcode() == ISD::LOAD ? 
29.26k
:
39.64k
);
2041
18.9k
  }
2042
2043
  /// Return the addressing mode for this load or store:
2044
  /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2045
101M
  ISD::MemIndexedMode getAddressingMode() const {
2046
101M
    return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2047
101M
  }
2048
2049
  /// Return true if this is a pre/post inc/dec load/store.
2050
19.0M
  bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2051
2052
  /// Return true if this is NOT a pre/post inc/dec load/store.
2053
17.7M
  bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2054
2055
11.4k
  static bool classof(const SDNode *N) {
2056
11.4k
    return N->getOpcode() == ISD::LOAD ||
2057
11.4k
           
N->getOpcode() == ISD::STORE5.69k
;
2058
11.4k
  }
2059
};
2060
2061
/// This class is used to represent ISD::LOAD nodes.
2062
class LoadSDNode : public LSBaseSDNode {
2063
  friend class SelectionDAG;
2064
2065
  LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2066
             ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
2067
             MachineMemOperand *MMO)
2068
3.93M
      : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
2069
3.93M
    LoadSDNodeBits.ExtTy = ETy;
2070
3.93M
    assert(readMem() && "Load MachineMemOperand is not a load!");
2071
3.93M
    assert(!writeMem() && "Load MachineMemOperand is a store!");
2072
3.93M
  }
2073
2074
public:
2075
  /// Return whether this is a plain node,
2076
  /// or one of the varieties of value-extending loads.
2077
27.4M
  ISD::LoadExtType getExtensionType() const {
2078
27.4M
    return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2079
27.4M
  }
2080
2081
9.89M
  const SDValue &getBasePtr() const { return getOperand(1); }
2082
118k
  const SDValue &getOffset() const { return getOperand(2); }
2083
2084
52.1M
  static bool classof(const SDNode *N) {
2085
52.1M
    return N->getOpcode() == ISD::LOAD;
2086
52.1M
  }
2087
};
2088
2089
/// This class is used to represent ISD::STORE nodes.
2090
class StoreSDNode : public LSBaseSDNode {
2091
  friend class SelectionDAG;
2092
2093
  StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2094
              ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
2095
              MachineMemOperand *MMO)
2096
3.96M
      : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
2097
3.96M
    StoreSDNodeBits.IsTruncating = isTrunc;
2098
3.96M
    assert(!readMem() && "Store MachineMemOperand is a load!");
2099
3.96M
    assert(writeMem() && "Store MachineMemOperand is not a store!");
2100
3.96M
  }
2101
2102
public:
2103
  /// Return true if the op does a truncation before store.
2104
  /// For integers this is the same as doing a TRUNCATE and storing the result.
2105
  /// For floats, it is the same as doing an FP_ROUND and storing the result.
2106
20.7M
  bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2107
213
  void setTruncatingStore(bool Truncating) {
2108
213
    StoreSDNodeBits.IsTruncating = Truncating;
2109
213
  }
2110
2111
45.0M
  const SDValue &getValue() const { return getOperand(1); }
2112
16.2M
  const SDValue &getBasePtr() const { return getOperand(2); }
2113
1.85k
  const SDValue &getOffset() const { return getOperand(3); }
2114
2115
30.5M
  static bool classof(const SDNode *N) {
2116
30.5M
    return N->getOpcode() == ISD::STORE;
2117
30.5M
  }
2118
};
2119
2120
/// This base class is used to represent MLOAD and MSTORE nodes
2121
class MaskedLoadStoreSDNode : public MemSDNode {
2122
public:
2123
  friend class SelectionDAG;
2124
2125
  MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
2126
                        const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2127
                        MachineMemOperand *MMO)
2128
2.04k
      : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2129
2130
  // MaskedLoadSDNode (Chain, ptr, mask, passthru)
2131
  // MaskedStoreSDNode (Chain, data, ptr, mask)
2132
  // Mask is a vector of i1 elements
2133
53
  const SDValue &getBasePtr() const {
2134
53
    return getOperand(getOpcode() == ISD::MLOAD ? 
131
:
222
);
2135
53
  }
2136
1.33k
  const SDValue &getMask() const {
2137
1.33k
    return getOperand(getOpcode() == ISD::MLOAD ? 
2799
:
3532
);
2138
1.33k
  }
2139
2140
  static bool classof(const SDNode *N) {
2141
    return N->getOpcode() == ISD::MLOAD ||
2142
           N->getOpcode() == ISD::MSTORE;
2143
  }
2144
};
2145
2146
/// This class is used to represent an MLOAD node
2147
class MaskedLoadSDNode : public MaskedLoadStoreSDNode {
2148
public:
2149
  friend class SelectionDAG;
2150
2151
  MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2152
                   ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT,
2153
                   MachineMemOperand *MMO)
2154
1.22k
      : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, MemVT, MMO) {
2155
1.22k
    LoadSDNodeBits.ExtTy = ETy;
2156
1.22k
    LoadSDNodeBits.IsExpanding = IsExpanding;
2157
1.22k
  }
2158
2159
2.24k
  ISD::LoadExtType getExtensionType() const {
2160
2.24k
    return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2161
2.24k
  }
2162
2163
96
  const SDValue &getBasePtr() const { return getOperand(1); }
2164
875
  const SDValue &getMask() const    { return getOperand(2); }
2165
171
  const SDValue &getPassThru() const { return getOperand(3); }
2166
2167
569
  static bool classof(const SDNode *N) {
2168
569
    return N->getOpcode() == ISD::MLOAD;
2169
569
  }
2170
2171
2.89k
  bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2172
};
2173
2174
/// This class is used to represent an MSTORE node
2175
class MaskedStoreSDNode : public MaskedLoadStoreSDNode {
2176
public:
2177
  friend class SelectionDAG;
2178
2179
  MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2180
                    bool isTrunc, bool isCompressing, EVT MemVT,
2181
                    MachineMemOperand *MMO)
2182
820
      : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, MemVT, MMO) {
2183
820
    StoreSDNodeBits.IsTruncating = isTrunc;
2184
820
    StoreSDNodeBits.IsCompressing = isCompressing;
2185
820
  }
2186
2187
  /// Return true if the op does a truncation before store.
2188
  /// For integers this is the same as doing a TRUNCATE and storing the result.
2189
  /// For floats, it is the same as doing an FP_ROUND and storing the result.
2190
1.20k
  bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2191
2192
  /// Returns true if the op does a compression to the vector before storing.
2193
  /// The node contiguously stores the active elements (integers or floats)
2194
  /// in src (those with their respective bit set in writemask k) to unaligned
2195
  /// memory at base_addr.
2196
1.54k
  bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2197
2198
1.76k
  const SDValue &getValue() const   { return getOperand(1); }
2199
49
  const SDValue &getBasePtr() const { return getOperand(2); }
2200
962
  const SDValue &getMask() const    { return getOperand(3); }
2201
2202
349
  static bool classof(const SDNode *N) {
2203
349
    return N->getOpcode() == ISD::MSTORE;
2204
349
  }
2205
};
2206
2207
/// This is a base class used to represent
2208
/// MGATHER and MSCATTER nodes
2209
///
2210
class MaskedGatherScatterSDNode : public MemSDNode {
2211
public:
2212
  friend class SelectionDAG;
2213
2214
  MaskedGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order,
2215
                            const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2216
                            MachineMemOperand *MMO)
2217
1.27k
      : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2218
2219
  // In the both nodes address is Op1, mask is Op2:
2220
  // MaskedGatherSDNode  (Chain, passthru, mask, base, index, scale)
2221
  // MaskedScatterSDNode (Chain, value, mask, base, index, scale)
2222
  // Mask is a vector of i1 elements
2223
636
  const SDValue &getBasePtr() const { return getOperand(3); }
2224
669
  const SDValue &getIndex()   const { return getOperand(4); }
2225
1.25k
  const SDValue &getMask()    const { return getOperand(2); }
2226
636
  const SDValue &getScale()   const { return getOperand(5); }
2227
2228
  static bool classof(const SDNode *N) {
2229
    return N->getOpcode() == ISD::MGATHER ||
2230
           N->getOpcode() == ISD::MSCATTER;
2231
  }
2232
};
2233
2234
/// This class is used to represent an MGATHER node
2235
///
2236
class MaskedGatherSDNode : public MaskedGatherScatterSDNode {
2237
public:
2238
  friend class SelectionDAG;
2239
2240
  MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2241
                     EVT MemVT, MachineMemOperand *MMO)
2242
936
      : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO) {}
2243
2244
478
  const SDValue &getPassThru() const { return getOperand(1); }
2245
2246
  static bool classof(const SDNode *N) {
2247
    return N->getOpcode() == ISD::MGATHER;
2248
  }
2249
};
2250
2251
/// This class is used to represent an MSCATTER node
2252
///
2253
class MaskedScatterSDNode : public MaskedGatherScatterSDNode {
2254
public:
2255
  friend class SelectionDAG;
2256
2257
  MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2258
                      EVT MemVT, MachineMemOperand *MMO)
2259
336
      : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO) {}
2260
2261
410
  const SDValue &getValue() const { return getOperand(1); }
2262
2263
  static bool classof(const SDNode *N) {
2264
    return N->getOpcode() == ISD::MSCATTER;
2265
  }
2266
};
2267
2268
/// An SDNode that represents everything that will be needed
2269
/// to construct a MachineInstr. These nodes are created during the
2270
/// instruction selection proper phase.
2271
///
2272
/// Note that the only supported way to set the `memoperands` is by calling the
2273
/// `SelectionDAG::setNodeMemRefs` function as the memory management happens
2274
/// inside the DAG rather than in the node.
2275
class MachineSDNode : public SDNode {
2276
private:
2277
  friend class SelectionDAG;
2278
2279
  MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
2280
766k
      : SDNode(Opc, Order, DL, VTs) {}
2281
2282
  // We use a pointer union between a single `MachineMemOperand` pointer and
2283
  // a pointer to an array of `MachineMemOperand` pointers. This is null when
2284
  // the number of these is zero, the single pointer variant used when the
2285
  // number is one, and the array is used for larger numbers.
2286
  //
2287
  // The array is allocated via the `SelectionDAG`'s allocator and so will
2288
  // always live until the DAG is cleaned up and doesn't require ownership here.
2289
  //
2290
  // We can't use something simpler like `TinyPtrVector` here because `SDNode`
2291
  // subclasses aren't managed in a conforming C++ manner. See the comments on
2292
  // `SelectionDAG::MorphNodeTo` which details what all goes on, but the
2293
  // constraint here is that these don't manage memory with their constructor or
2294
  // destructor and can be initialized to a good state even if they start off
2295
  // uninitialized.
2296
  PointerUnion<MachineMemOperand *, MachineMemOperand **> MemRefs = {};
2297
2298
  // Note that this could be folded into the above `MemRefs` member if doing so
2299
  // is advantageous at some point. We don't need to store this in most cases.
2300
  // However, at the moment this doesn't appear to make the allocation any
2301
  // smaller and makes the code somewhat simpler to read.
2302
  int NumMemRefs = 0;
2303
2304
public:
2305
  using mmo_iterator = ArrayRef<MachineMemOperand *>::const_iterator;
2306
2307
11.4M
  ArrayRef<MachineMemOperand *> memoperands() const {
2308
11.4M
    // Special case the common cases.
2309
11.4M
    if (NumMemRefs == 0)
2310
8.73M
      return {};
2311
2.73M
    if (NumMemRefs == 1)
2312
2.72M
      return makeArrayRef(MemRefs.getAddrOfPtr1(), 1);
2313
5.27k
2314
5.27k
    // Otherwise we have an actual array.
2315
5.27k
    return makeArrayRef(MemRefs.get<MachineMemOperand **>(), NumMemRefs);
2316
5.27k
  }
2317
176k
  mmo_iterator memoperands_begin() const { return memoperands().begin(); }
2318
65.1k
  mmo_iterator memoperands_end() const { return memoperands().end(); }
2319
299k
  bool memoperands_empty() const { return memoperands().empty(); }
2320
2321
  /// Clear out the memory reference descriptor list.
2322
11.1M
  void clearMemRefs() {
2323
11.1M
    MemRefs = nullptr;
2324
11.1M
    NumMemRefs = 0;
2325
11.1M
  }
2326
2327
12.8M
  static bool classof(const SDNode *N) {
2328
12.8M
    return N->isMachineOpcode();
2329
12.8M
  }
2330
};
2331
2332
class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2333
                                            SDNode, ptrdiff_t> {
2334
  const SDNode *Node;
2335
  unsigned Operand;
2336
2337
20.5k
  SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2338
2339
public:
2340
28.3k
  bool operator==(const SDNodeIterator& x) const {
2341
28.3k
    return Operand == x.Operand;
2342
28.3k
  }
2343
28.3k
  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2344
2345
18.4k
  pointer operator*() const {
2346
18.4k
    return Node->getOperand(Operand).getNode();
2347
18.4k
  }
2348
  pointer operator->() const { return operator*(); }
2349
2350
18.0k
  SDNodeIterator& operator++() {                // Preincrement
2351
18.0k
    ++Operand;
2352
18.0k
    return *this;
2353
18.0k
  }
2354
0
  SDNodeIterator operator++(int) { // Postincrement
2355
0
    SDNodeIterator tmp = *this; ++*this; return tmp;
2356
0
  }
2357
  size_t operator-(SDNodeIterator Other) const {
2358
    assert(Node == Other.Node &&
2359
           "Cannot compare iterators of two different nodes!");
2360
    return Operand - Other.Operand;
2361
  }
2362
2363
10.2k
  static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2364
10.2k
  static SDNodeIterator end  (const SDNode *N) {
2365
10.2k
    return SDNodeIterator(N, N->getNumOperands());
2366
10.2k
  }
2367
2368
  unsigned getOperand() const { return Operand; }
2369
  const SDNode *getNode() const { return Node; }
2370
};
2371
2372
template <> struct GraphTraits<SDNode*> {
2373
  using NodeRef = SDNode *;
2374
  using ChildIteratorType = SDNodeIterator;
2375
2376
  static NodeRef getEntryNode(SDNode *N) { return N; }
2377
2378
  static ChildIteratorType child_begin(NodeRef N) {
2379
    return SDNodeIterator::begin(N);
2380
  }
2381
2382
  static ChildIteratorType child_end(NodeRef N) {
2383
    return SDNodeIterator::end(N);
2384
  }
2385
};
2386
2387
/// A representation of the largest SDNode, for use in sizeof().
2388
///
2389
/// This needs to be a union because the largest node differs on 32 bit systems
2390
/// with 4 and 8 byte pointer alignment, respectively.
2391
using LargestSDNode = AlignedCharArrayUnion<AtomicSDNode, TargetIndexSDNode,
2392
                                            BlockAddressSDNode,
2393
                                            GlobalAddressSDNode>;
2394
2395
/// The SDNode class with the greatest alignment requirement.
2396
using MostAlignedSDNode = GlobalAddressSDNode;
2397
2398
namespace ISD {
2399
2400
  /// Returns true if the specified node is a non-extending and unindexed load.
2401
6.23M
  inline bool isNormalLoad(const SDNode *N) {
2402
6.23M
    const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2403
6.23M
    return Ld && 
Ld->getExtensionType() == ISD::NON_EXTLOAD2.34M
&&
2404
6.23M
      
Ld->getAddressingMode() == ISD::UNINDEXED2.03M
;
2405
6.23M
  }
2406
2407
  /// Returns true if the specified node is a non-extending load.
2408
714k
  inline bool isNON_EXTLoad(const SDNode *N) {
2409
714k
    return isa<LoadSDNode>(N) &&
2410
714k
      
cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD292k
;
2411
714k
  }
2412
2413
  /// Returns true if the specified node is a EXTLOAD.
2414
852k
  inline bool isEXTLoad(const SDNode *N) {
2415
852k
    return isa<LoadSDNode>(N) &&
2416
852k
      
cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD88.6k
;
2417
852k
  }
2418
2419
  /// Returns true if the specified node is a SEXTLOAD.
2420
592k
  inline bool isSEXTLoad(const SDNode *N) {
2421
592k
    return isa<LoadSDNode>(N) &&
2422
592k
      
cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD70.6k
;
2423
592k
  }
2424
2425
  /// Returns true if the specified node is a ZEXTLOAD.
2426
5.81M
  inline bool isZEXTLoad(const SDNode *N) {
2427
5.81M
    return isa<LoadSDNode>(N) &&
2428
5.81M
      
cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD5.56M
;
2429
5.81M
  }
2430
2431
  /// Returns true if the specified node is an unindexed load.
2432
1.85M
  inline bool isUNINDEXEDLoad(const SDNode *N) {
2433
1.85M
    return isa<LoadSDNode>(N) &&
2434
1.85M
      
cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED1.51M
;
2435
1.85M
  }
2436
2437
  /// Returns true if the specified node is a non-truncating
2438
  /// and unindexed store.
2439
4.82M
  inline bool isNormalStore(const SDNode *N) {
2440
4.82M
    const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2441
4.82M
    return St && 
!St->isTruncatingStore()4.82M
&&
2442
4.82M
      
St->getAddressingMode() == ISD::UNINDEXED4.34M
;
2443
4.82M
  }
2444
2445
  /// Returns true if the specified node is a non-truncating store.
2446
  inline bool isNON_TRUNCStore(const SDNode *N) {
2447
    return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2448
  }
2449
2450
  /// Returns true if the specified node is a truncating store.
2451
  inline bool isTRUNCStore(const SDNode *N) {
2452
    return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2453
  }
2454
2455
  /// Returns true if the specified node is an unindexed store.
2456
  inline bool isUNINDEXEDStore(const SDNode *N) {
2457
    return isa<StoreSDNode>(N) &&
2458
      cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2459
  }
2460
2461
  /// Return true if the node is a math/logic binary operator. This corresponds
2462
  /// to the IR function of the same name.
2463
117k
  inline bool isBinaryOp(const SDNode *N) {
2464
117k
    auto Op = N->getOpcode();
2465
117k
    return (Op == ISD::ADD || 
Op == ISD::SUB107k
||
Op == ISD::MUL105k
||
2466
117k
            
Op == ISD::AND103k
||
Op == ISD::OR102k
||
Op == ISD::XOR101k
||
2467
117k
            
Op == ISD::SHL100k
||
Op == ISD::SRL100k
||
Op == ISD::SRA99.7k
||
2468
117k
            
Op == ISD::SDIV99.4k
||
Op == ISD::UDIV99.3k
||
Op == ISD::SREM99.3k
||
2469
117k
            
Op == ISD::UREM99.3k
||
Op == ISD::FADD99.3k
||
Op == ISD::FSUB98.5k
||
2470
117k
            
Op == ISD::FMUL98.3k
||
Op == ISD::FDIV97.6k
||
Op == ISD::FREM97.3k
);
2471
117k
  }
2472
2473
  /// Attempt to match a unary predicate against a scalar/splat constant or
2474
  /// every element of a constant BUILD_VECTOR.
2475
  bool matchUnaryPredicate(SDValue Op,
2476
                           std::function<bool(ConstantSDNode *)> Match);
2477
2478
  /// Attempt to match a binary predicate against a pair of scalar/splat
2479
  /// constants or every element of a pair of constant BUILD_VECTORs.
2480
  bool matchBinaryPredicate(
2481
      SDValue LHS, SDValue RHS,
2482
      std::function<bool(ConstantSDNode *, ConstantSDNode *)> Match);
2483
2484
} // end namespace ISD
2485
2486
} // end namespace llvm
2487
2488
#endif // LLVM_CODEGEN_SELECTIONDAGNODES_H