Coverage Report

Created: 2018-09-19 08:35

/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
808M
  SDValue() = default;
132
  SDValue(SDNode *node, unsigned resno);
133
134
  /// get the index which selects a specific result in the SDNode
135
410M
  unsigned getResNo() const { return ResNo; }
136
137
  /// get the SDNode which holds the desired result
138
3.72G
  SDNode *getNode() const { return Node; }
139
140
  /// set the SDNode
141
17.1M
  void setNode(SDNode *N) { Node = N; }
142
143
474M
  inline SDNode *operator->() const { return Node; }
144
145
732M
  bool operator==(const SDValue &O) const {
146
732M
    return Node == O.Node && 
ResNo == O.ResNo467M
;
147
732M
  }
148
41.6M
  bool operator!=(const SDValue &O) const {
149
41.6M
    return !operator==(O);
150
41.6M
  }
151
327k
  bool operator<(const SDValue &O) const {
152
327k
    return std::tie(Node, ResNo) < std::tie(O.Node, O.ResNo);
153
327k
  }
154
120M
  explicit operator bool() const {
155
120M
    return Node != nullptr;
156
120M
  }
157
158
30.2M
  SDValue getValue(unsigned R) const {
159
30.2M
    return SDValue(Node, R);
160
30.2M
  }
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
18.3M
  MVT getSimpleValueType() const {
170
18.3M
    return getValueType().getSimpleVT();
171
18.3M
  }
172
173
  /// Returns the size of the value in bits.
174
5.66M
  unsigned getValueSizeInBits() const {
175
5.66M
    return getValueType().getSizeInBits();
176
5.66M
  }
177
178
87.4M
  unsigned getScalarValueSizeInBits() const {
179
87.4M
    return getValueType().getScalarType().getSizeInBits();
180
87.4M
  }
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
107M
  static inline SDValue getEmptyKey() {
215
107M
    SDValue V;
216
107M
    V.ResNo = -1U;
217
107M
    return V;
218
107M
  }
219
220
78.9M
  static inline SDValue getTombstoneKey() {
221
78.9M
    SDValue V;
222
78.9M
    V.ResNo = -2U;
223
78.9M
    return V;
224
78.9M
  }
225
226
72.5M
  static unsigned getHashValue(const SDValue &Val) {
227
72.5M
    return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
228
72.5M
            (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
229
72.5M
  }
230
231
540M
  static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
232
540M
    return LHS == RHS;
233
540M
  }
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
812M
  static SimpleType getSimplifiedValue(const SDValue &Val) {
250
812M
    return Val.getNode();
251
812M
  }
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.3M
  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.34G
  operator const SDValue&() const { return Val; }
276
277
  /// If implicit conversion to SDValue doesn't work, the get() method returns
278
  /// the SDValue.
279
356M
  const SDValue &get() const { return Val; }
280
281
  /// This returns the SDNode that contains this Use.
282
308M
  SDNode *getUser() { return User; }
283
284
  /// Get the next SDUse in the use list.
285
372M
  SDUse *getNext() const { return Next; }
286
287
  /// Convenience function for get().getNode().
288
246M
  SDNode *getNode() const { return Val.getNode(); }
289
  /// Convenience function for get().getResNo().
290
181M
  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.34k
  bool operator==(const SDValue &V) const {
296
1.34k
    return Val == V;
297
1.34k
  }
298
299
  /// Convenience function for get().operator!=
300
1.96M
  bool operator!=(const SDValue &V) const {
301
1.96M
    return Val != V;
302
1.96M
  }
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
154M
  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
169M
  void addToList(SDUse **List) {
328
169M
    Next = *List;
329
169M
    if (Next) 
Next->Prev = &Next85.9M
;
330
169M
    Prev = List;
331
169M
    *List = this;
332
169M
  }
333
334
107M
  void removeFromList() {
335
107M
    *Prev = Next;
336
107M
    if (Next) 
Next->Prev = Prev30.5M
;
337
107M
  }
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
124M
        AllowReassociation(false) {}
380
381
  /// Propagate the fast-math-flags from an IR FPMathOperator.
382
386k
  void copyFMF(const FPMathOperator &FPMO) {
383
386k
    setNoNaNs(FPMO.hasNoNaNs());
384
386k
    setNoInfs(FPMO.hasNoInfs());
385
386k
    setNoSignedZeros(FPMO.hasNoSignedZeros());
386
386k
    setAllowReciprocal(FPMO.hasAllowReciprocal());
387
386k
    setAllowContract(FPMO.hasAllowContract());
388
386k
    setApproximateFuncs(FPMO.hasApproxFunc());
389
386k
    setAllowReassociation(FPMO.hasAllowReassoc());
390
386k
  }
391
392
  /// Sets the state of the flags to the defined state.
393
7.32M
  void setDefined() { AnyDefined = true; }
394
  /// Returns true if the flags are in a defined state.
395
1.66M
  bool isDefined() const { return AnyDefined; }
396
397
  // These are mutators for each flag.
398
3.76M
  void setNoUnsignedWrap(bool b) {
399
3.76M
    setDefined();
400
3.76M
    NoUnsignedWrap = b;
401
3.76M
  }
402
677k
  void setNoSignedWrap(bool b) {
403
677k
    setDefined();
404
677k
    NoSignedWrap = b;
405
677k
  }
406
178k
  void setExact(bool b) {
407
178k
    setDefined();
408
178k
    Exact = b;
409
178k
  }
410
386k
  void setNoNaNs(bool b) {
411
386k
    setDefined();
412
386k
    NoNaNs = b;
413
386k
  }
414
386k
  void setNoInfs(bool b) {
415
386k
    setDefined();
416
386k
    NoInfs = b;
417
386k
  }
418
386k
  void setNoSignedZeros(bool b) {
419
386k
    setDefined();
420
386k
    NoSignedZeros = b;
421
386k
  }
422
386k
  void setAllowReciprocal(bool b) {
423
386k
    setDefined();
424
386k
    AllowReciprocal = b;
425
386k
  }
426
1.12k
  void setVectorReduction(bool b) {
427
1.12k
    setDefined();
428
1.12k
    VectorReduction = b;
429
1.12k
  }
430
386k
  void setAllowContract(bool b) {
431
386k
    setDefined();
432
386k
    AllowContract = b;
433
386k
  }
434
386k
  void setApproximateFuncs(bool b) {
435
386k
    setDefined();
436
386k
    ApproximateFuncs = b;
437
386k
  }
438
386k
  void setAllowReassociation(bool b) {
439
386k
    setDefined();
440
386k
    AllowReassociation = b;
441
386k
  }
442
443
  // These are accessors for each flag.
444
50.7k
  bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
445
31.6k
  bool hasNoSignedWrap() const { return NoSignedWrap; }
446
643k
  bool hasExact() const { return Exact; }
447
7.64M
  bool hasNoNaNs() const { return NoNaNs; }
448
7.23M
  bool hasNoInfs() const { return NoInfs; }
449
7.32M
  bool hasNoSignedZeros() const { return NoSignedZeros; }
450
7.44M
  bool hasAllowReciprocal() const { return AllowReciprocal; }
451
9.26M
  bool hasVectorReduction() const { return VectorReduction; }
452
7.52M
  bool hasAllowContract() const { return AllowContract; }
453
7.24M
  bool hasApproximateFuncs() const { return ApproximateFuncs; }
454
7.83M
  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.27M
  void intersectWith(const SDNodeFlags Flags) {
464
1.27M
    if (!Flags.isDefined())
465
1.05M
      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
6.21G
  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
613k
  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
76.4M
  bool isTargetMemoryOpcode() const {
635
76.4M
    return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
636
76.4M
  }
637
638
  /// Return true if the type of the node type undefined.
639
70.0M
  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.68M
  bool isMemIntrinsic() const {
647
1.68M
    return (NodeType == ISD::INTRINSIC_W_CHAIN ||
648
1.68M
            
NodeType == ISD::INTRINSIC_VOID1.64M
) &&
649
1.68M
           
SDNodeBits.IsMemIntrinsic85.2k
;
650
1.68M
  }
651
652
  /// Test if this node is a strict floating point pseudo-op.
653
32.2M
  bool isStrictFPOpcode() {
654
32.2M
    switch (NodeType) {
655
32.2M
      default:
656
32.2M
        return false;
657
32.2M
      case ISD::STRICT_FADD:
658
464
      case ISD::STRICT_FSUB:
659
464
      case ISD::STRICT_FMUL:
660
464
      case ISD::STRICT_FDIV:
661
464
      case ISD::STRICT_FREM:
662
464
      case ISD::STRICT_FMA:
663
464
      case ISD::STRICT_FSQRT:
664
464
      case ISD::STRICT_FPOW:
665
464
      case ISD::STRICT_FPOWI:
666
464
      case ISD::STRICT_FSIN:
667
464
      case ISD::STRICT_FCOS:
668
464
      case ISD::STRICT_FEXP:
669
464
      case ISD::STRICT_FEXP2:
670
464
      case ISD::STRICT_FLOG:
671
464
      case ISD::STRICT_FLOG10:
672
464
      case ISD::STRICT_FLOG2:
673
464
      case ISD::STRICT_FRINT:
674
464
      case ISD::STRICT_FNEARBYINT:
675
464
        return true;
676
32.2M
    }
677
32.2M
  }
678
679
  /// Test if this node has a post-isel opcode, directly
680
  /// corresponding to a MachineInstr opcode.
681
268M
  bool isMachineOpcode() const { return NodeType < 0; }
682
683
  /// This may only be called if isMachineOpcode returns
684
  /// true. It returns the MachineInstr opcode value that the node's opcode
685
  /// corresponds to.
686
127M
  unsigned getMachineOpcode() const {
687
127M
    assert(isMachineOpcode() && "Not a MachineInstr opcode!");
688
127M
    return ~NodeType;
689
127M
  }
690
691
17.7M
  bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
692
544
  void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
693
694
124M
  bool isDivergent() const { return SDNodeBits.IsDivergent; }
695
696
  /// Return true if there are no uses of this node.
697
603M
  bool use_empty() const { return UseList == nullptr; }
698
699
  /// Return true if there is exactly one use of this node.
700
42.6M
  bool hasOneUse() const {
701
42.6M
    return !use_empty() && 
std::next(use_begin()) == use_end()42.6M
;
702
42.6M
  }
703
704
  /// Return the number of uses of this node. This method takes
705
  /// time proportional to the number of uses.
706
1.52k
  size_t use_size() const { return std::distance(use_begin(), use_end()); }
707
708
  /// Return the unique node id.
709
315M
  int getNodeId() const { return NodeId; }
710
711
  /// Set unique node id.
712
444M
  void setNodeId(int Id) { NodeId = Id; }
713
714
  /// Return the node ordering.
715
198M
  unsigned getIROrder() const { return IROrder; }
716
717
  /// Set the node ordering.
718
152k
  void setIROrder(unsigned Order) { IROrder = Order; }
719
720
  /// Return the source location info.
721
147M
  const DebugLoc &getDebugLoc() const { return debugLoc; }
722
723
  /// Set source location info.  Try to avoid this, putting
724
  /// it in the constructor is preferable.
725
966k
  void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
726
727
  /// This class provides iterator support for SDUse
728
  /// operands that use a specific SDNode.
729
  class use_iterator
730
    : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
731
    friend class SDNode;
732
733
    SDUse *Op = nullptr;
734
735
555M
    explicit use_iterator(SDUse *op) : Op(op) {}
736
737
  public:
738
    using reference = std::iterator<std::forward_iterator_tag,
739
                                    SDUse, ptrdiff_t>::reference;
740
    using pointer = std::iterator<std::forward_iterator_tag,
741
                                  SDUse, ptrdiff_t>::pointer;
742
743
    use_iterator() = default;
744
252M
    use_iterator(const use_iterator &I) : Op(I.Op) {}
745
746
622M
    bool operator==(const use_iterator &x) const {
747
622M
      return Op == x.Op;
748
622M
    }
749
579M
    bool operator!=(const use_iterator &x) const {
750
579M
      return !operator==(x);
751
579M
    }
752
753
    /// Return true if this iterator is at the end of uses list.
754
    bool atEnd() const { return Op == nullptr; }
755
756
    // Iterator traversal: forward iteration only.
757
372M
    use_iterator &operator++() {          // Preincrement
758
372M
      assert(Op && "Cannot increment end iterator!");
759
372M
      Op = Op->getNext();
760
372M
      return *this;
761
372M
    }
762
763
148
    use_iterator operator++(int) {        // Postincrement
764
148
      use_iterator tmp = *this; ++*this; return tmp;
765
148
    }
766
767
    /// Retrieve a pointer to the current user node.
768
294M
    SDNode *operator*() const {
769
294M
      assert(Op && "Cannot dereference end iterator!");
770
294M
      return Op->getUser();
771
294M
    }
772
773
1.31M
    SDNode *operator->() const { return operator*(); }
774
775
93.2M
    SDUse &getUse() const { return *Op; }
776
777
    /// Retrieve the operand # of this use in its user.
778
13.6M
    unsigned getOperandNo() const {
779
13.6M
      assert(Op && "Cannot dereference end iterator!");
780
13.6M
      return (unsigned)(Op - Op->getUser()->OperandList);
781
13.6M
    }
782
  };
783
784
  /// Provide iteration support to walk over all uses of an SDNode.
785
278M
  use_iterator use_begin() const {
786
278M
    return use_iterator(UseList);
787
278M
  }
788
789
276M
  static use_iterator use_end() { return use_iterator(nullptr); }
790
791
33.8M
  inline iterator_range<use_iterator> uses() {
792
33.8M
    return make_range(use_begin(), use_end());
793
33.8M
  }
794
1.13M
  inline iterator_range<use_iterator> uses() const {
795
1.13M
    return make_range(use_begin(), use_end());
796
1.13M
  }
797
798
  /// Return true if there are exactly NUSES uses of the indicated value.
799
  /// This method ignores uses of other values defined by this operation.
800
  bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
801
802
  /// Return true if there are any use of the indicated value.
803
  /// This method ignores uses of other values defined by this operation.
804
  bool hasAnyUseOfValue(unsigned Value) const;
805
806
  /// Return true if this node is the only use of N.
807
  bool isOnlyUserOf(const SDNode *N) const;
808
809
  /// Return true if this node is an operand of N.
810
  bool isOperandOf(const SDNode *N) const;
811
812
  /// Return true if this node is a predecessor of N.
813
  /// NOTE: Implemented on top of hasPredecessor and every bit as
814
  /// expensive. Use carefully.
815
96.8k
  bool isPredecessorOf(const SDNode *N) const {
816
96.8k
    return N->hasPredecessor(this);
817
96.8k
  }
818
819
  /// Return true if N is a predecessor of this node.
820
  /// N is either an operand of this node, or can be reached by recursively
821
  /// traversing up the operands.
822
  /// NOTE: This is an expensive method. Use it carefully.
823
  bool hasPredecessor(const SDNode *N) const;
824
825
  /// Returns true if N is a predecessor of any node in Worklist. This
826
  /// helper keeps Visited and Worklist sets externally to allow unions
827
  /// searches to be performed in parallel, caching of results across
828
  /// queries and incremental addition to Worklist. Stops early if N is
829
  /// found but will resume. Remember to clear Visited and Worklists
830
  /// if DAG changes. MaxSteps gives a maximum number of nodes to visit before
831
  /// giving up. The TopologicalPrune flag signals that positive NodeIds are
832
  /// topologically ordered (Operands have strictly smaller node id) and search
833
  /// can be pruned leveraging this.
834
  static bool hasPredecessorHelper(const SDNode *N,
835
                                   SmallPtrSetImpl<const SDNode *> &Visited,
836
                                   SmallVectorImpl<const SDNode *> &Worklist,
837
                                   unsigned int MaxSteps = 0,
838
484k
                                   bool TopologicalPrune = false) {
839
484k
    SmallVector<const SDNode *, 8> DeferredNodes;
840
484k
    if (Visited.count(N))
841
58.0k
      return true;
842
426k
843
426k
    // Node Id's are assigned in three places: As a topological
844
426k
    // ordering (> 0), during legalization (results in values set to
845
426k
    // 0), new nodes (set to -1). If N has a topolgical id then we
846
426k
    // know that all nodes with ids smaller than it cannot be
847
426k
    // successors and we need not check them. Filter out all node
848
426k
    // that can't be matches. We add them to the worklist before exit
849
426k
    // in case of multiple calls. Note that during selection the topological id
850
426k
    // may be violated if a node's predecessor is selected before it. We mark
851
426k
    // this at selection negating the id of unselected successors and
852
426k
    // restricting topological pruning to positive ids.
853
426k
854
426k
    int NId = N->getNodeId();
855
426k
    // If we Invalidated the Id, reconstruct original NId.
856
426k
    if (NId < -1)
857
20.0k
      NId = -(NId + 1);
858
426k
859
426k
    bool Found = false;
860
5.10M
    while (!Worklist.empty()) {
861
4.73M
      const SDNode *M = Worklist.pop_back_val();
862
4.73M
      int MId = M->getNodeId();
863
4.73M
      if (TopologicalPrune && 
M->getOpcode() != ISD::TokenFactor169k
&&
(NId > 0)165k
&&
864
4.73M
          
(MId > 0)165k
&&
(MId < NId)159k
) {
865
116k
        DeferredNodes.push_back(M);
866
116k
        continue;
867
116k
      }
868
8.93M
      
for (const SDValue &OpV : M->op_values())4.62M
{
869
8.93M
        SDNode *Op = OpV.getNode();
870
8.93M
        if (Visited.insert(Op).second)
871
4.52M
          Worklist.push_back(Op);
872
8.93M
        if (Op == N)
873
56.7k
          Found = true;
874
8.93M
      }
875
4.62M
      if (Found)
876
55.9k
        break;
877
4.56M
      if (MaxSteps != 0 && 
Visited.size() >= MaxSteps105k
)
878
0
        break;
879
4.56M
    }
880
426k
    // Push deferred nodes back on worklist.
881
426k
    Worklist.append(DeferredNodes.begin(), DeferredNodes.end());
882
426k
    // If we bailed early, conservatively return found.
883
426k
    if (MaxSteps != 0 && 
Visited.size() >= MaxSteps120k
)
884
0
      return true;
885
426k
    return Found;
886
426k
  }
887
888
  /// Return true if all the users of N are contained in Nodes.
889
  /// NOTE: Requires at least one match, but doesn't require them all.
890
  static bool areOnlyUsersOf(ArrayRef<const SDNode *> Nodes, const SDNode *N);
891
892
  /// Return the number of values used by this operation.
893
584M
  unsigned getNumOperands() const { return NumOperands; }
894
895
  /// Helper method returns the integer value of a ConstantSDNode operand.
896
  inline uint64_t getConstantOperandVal(unsigned Num) const;
897
898
1.30G
  const SDValue &getOperand(unsigned Num) const {
899
1.30G
    assert(Num < NumOperands && "Invalid child # of SDNode!");
900
1.30G
    return OperandList[Num];
901
1.30G
  }
902
903
  using op_iterator = SDUse *;
904
905
332M
  op_iterator op_begin() const { return OperandList; }
906
325M
  op_iterator op_end() const { return OperandList+NumOperands; }
907
79.9M
  ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
908
909
  /// Iterator for directly iterating over the operand SDValue's.
910
  struct value_op_iterator
911
      : iterator_adaptor_base<value_op_iterator, op_iterator,
912
                              std::random_access_iterator_tag, SDValue,
913
                              ptrdiff_t, value_op_iterator *,
914
                              value_op_iterator *> {
915
    explicit value_op_iterator(SDUse *U = nullptr)
916
378M
      : iterator_adaptor_base(U) {}
917
918
349M
    const SDValue &operator*() const { return I->get(); }
919
  };
920
921
189M
  iterator_range<value_op_iterator> op_values() const {
922
189M
    return make_range(value_op_iterator(op_begin()),
923
189M
                      value_op_iterator(op_end()));
924
189M
  }
925
926
76.6M
  SDVTList getVTList() const {
927
76.6M
    SDVTList X = { ValueList, NumValues };
928
76.6M
    return X;
929
76.6M
  }
930
931
  /// If this node has a glue operand, return the node
932
  /// to which the glue operand points. Otherwise return NULL.
933
85.2M
  SDNode *getGluedNode() const {
934
85.2M
    if (getNumOperands() != 0 &&
935
85.2M
        
getOperand(getNumOperands()-1).getValueType() == MVT::Glue84.7M
)
936
15.8M
      return getOperand(getNumOperands()-1).getNode();
937
69.4M
    return nullptr;
938
69.4M
  }
939
940
  /// If this node has a glue value with a user, return
941
  /// the user (there is at most one). Otherwise return NULL.
942
3.94M
  SDNode *getGluedUser() const {
943
8.99M
    for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; 
++UI5.04M
)
944
6.72M
      if (UI.getUse().get().getValueType() == MVT::Glue)
945
1.67M
        return *UI;
946
3.94M
    
return nullptr2.27M
;
947
3.94M
  }
948
949
21.8M
  const SDNodeFlags getFlags() const { return Flags; }
950
18.8M
  void setFlags(SDNodeFlags NewFlags) { Flags = NewFlags; }
951
  bool isFast() { return Flags.isFast(); }
952
953
  /// Clear any flags in this node that aren't also set in Flags.
954
  /// If Flags is not in a defined state then this has no effect.
955
  void intersectFlagsWith(const SDNodeFlags Flags);
956
957
  /// Return the number of values defined/returned by this operator.
958
175M
  unsigned getNumValues() const { return NumValues; }
959
960
  /// Return the type of a specified result.
961
1.06G
  EVT getValueType(unsigned ResNo) const {
962
1.06G
    assert(ResNo < NumValues && "Illegal result number!");
963
1.06G
    return ValueList[ResNo];
964
1.06G
  }
965
966
  /// Return the type of a specified result as a simple type.
967
35.1M
  MVT getSimpleValueType(unsigned ResNo) const {
968
35.1M
    return getValueType(ResNo).getSimpleVT();
969
35.1M
  }
970
971
  /// Returns MVT::getSizeInBits(getValueType(ResNo)).
972
976k
  unsigned getValueSizeInBits(unsigned ResNo) const {
973
976k
    return getValueType(ResNo).getSizeInBits();
974
976k
  }
975
976
  using value_iterator = const EVT *;
977
978
39.1M
  value_iterator value_begin() const { return ValueList; }
979
39.1M
  value_iterator value_end() const { return ValueList+NumValues; }
980
981
  /// Return the opcode of this operation for printing.
982
  std::string getOperationName(const SelectionDAG *G = nullptr) const;
983
  static const char* getIndexedModeName(ISD::MemIndexedMode AM);
984
  void print_types(raw_ostream &OS, const SelectionDAG *G) const;
985
  void print_details(raw_ostream &OS, const SelectionDAG *G) const;
986
  void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
987
  void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
988
989
  /// Print a SelectionDAG node and all children down to
990
  /// the leaves.  The given SelectionDAG allows target-specific nodes
991
  /// to be printed in human-readable form.  Unlike printr, this will
992
  /// print the whole DAG, including children that appear multiple
993
  /// times.
994
  ///
995
  void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
996
997
  /// Print a SelectionDAG node and children up to
998
  /// depth "depth."  The given SelectionDAG allows target-specific
999
  /// nodes to be printed in human-readable form.  Unlike printr, this
1000
  /// will print children that appear multiple times wherever they are
1001
  /// used.
1002
  ///
1003
  void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
1004
                       unsigned depth = 100) const;
1005
1006
  /// Dump this node, for debugging.
1007
  void dump() const;
1008
1009
  /// Dump (recursively) this node and its use-def subgraph.
1010
  void dumpr() const;
1011
1012
  /// Dump this node, for debugging.
1013
  /// The given SelectionDAG allows target-specific nodes to be printed
1014
  /// in human-readable form.
1015
  void dump(const SelectionDAG *G) const;
1016
1017
  /// Dump (recursively) this node and its use-def subgraph.
1018
  /// The given SelectionDAG allows target-specific nodes to be printed
1019
  /// in human-readable form.
1020
  void dumpr(const SelectionDAG *G) const;
1021
1022
  /// printrFull to dbgs().  The given SelectionDAG allows
1023
  /// target-specific nodes to be printed in human-readable form.
1024
  /// Unlike dumpr, this will print the whole DAG, including children
1025
  /// that appear multiple times.
1026
  void dumprFull(const SelectionDAG *G = nullptr) const;
1027
1028
  /// printrWithDepth to dbgs().  The given
1029
  /// SelectionDAG allows target-specific nodes to be printed in
1030
  /// human-readable form.  Unlike dumpr, this will print children
1031
  /// that appear multiple times wherever they are used.
1032
  ///
1033
  void dumprWithDepth(const SelectionDAG *G = nullptr,
1034
                      unsigned depth = 100) const;
1035
1036
  /// Gather unique data for the node.
1037
  void Profile(FoldingSetNodeID &ID) const;
1038
1039
  /// This method should only be used by the SDUse class.
1040
169M
  void addUse(SDUse &U) { U.addToList(&UseList); }
1041
1042
protected:
1043
46.8M
  static SDVTList getSDVTList(EVT VT) {
1044
46.8M
    SDVTList Ret = { getValueTypeList(VT), 1 };
1045
46.8M
    return Ret;
1046
46.8M
  }
1047
1048
  /// Create an SDNode.
1049
  ///
1050
  /// SDNodes are created without any operands, and never own the operand
1051
  /// storage. To add operands, see SelectionDAG::createOperands.
1052
  SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
1053
      : NodeType(Opc), ValueList(VTs.VTs), NumValues(VTs.NumVTs),
1054
87.6M
        IROrder(Order), debugLoc(std::move(dl)) {
1055
87.6M
    memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
1056
87.6M
    assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
1057
87.6M
    assert(NumValues == VTs.NumVTs &&
1058
87.6M
           "NumValues wasn't wide enough for its operands!");
1059
87.6M
  }
1060
1061
  /// Release the operands and set this node to have zero operands.
1062
  void DropOperands();
1063
};
1064
1065
/// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
1066
/// into SDNode creation functions.
1067
/// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
1068
/// from the original Instruction, and IROrder is the ordinal position of
1069
/// the instruction.
1070
/// When an SDNode is created after the DAG is being built, both DebugLoc and
1071
/// the IROrder are propagated from the original SDNode.
1072
/// So SDLoc class provides two constructors besides the default one, one to
1073
/// be used by the DAGBuilder, the other to be used by others.
1074
0
class SDLoc {
1075
private:
1076
  DebugLoc DL;
1077
  int IROrder = 0;
1078
1079
public:
1080
7.30M
  SDLoc() = default;
1081
126M
  SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
1082
47.2M
  SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
1083
21.0M
  SDLoc(const Instruction *I, int Order) : IROrder(Order) {
1084
21.0M
    assert(Order >= 0 && "bad IROrder");
1085
21.0M
    if (I)
1086
19.4M
      DL = I->getDebugLoc();
1087
21.0M
  }
1088
1089
66.2M
  unsigned getIROrder() const { return IROrder; }
1090
44.3M
  const DebugLoc &getDebugLoc() const { return DL; }
1091
};
1092
1093
// Define inline functions from the SDValue class.
1094
1095
inline SDValue::SDValue(SDNode *node, unsigned resno)
1096
272M
    : Node(node), ResNo(resno) {
1097
272M
  // Explicitly check for !ResNo to avoid use-after-free, because there are
1098
272M
  // callers that use SDValue(N, 0) with a deleted N to indicate successful
1099
272M
  // combines.
1100
272M
  assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&
1101
272M
         "Invalid result number for the given node!");
1102
272M
  assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
1103
272M
}
1104
1105
599M
inline unsigned SDValue::getOpcode() const {
1106
599M
  return Node->getOpcode();
1107
599M
}
1108
1109
750M
inline EVT SDValue::getValueType() const {
1110
750M
  return Node->getValueType(ResNo);
1111
750M
}
1112
1113
83.9M
inline unsigned SDValue::getNumOperands() const {
1114
83.9M
  return Node->getNumOperands();
1115
83.9M
}
1116
1117
199M
inline const SDValue &SDValue::getOperand(unsigned i) const {
1118
199M
  return Node->getOperand(i);
1119
199M
}
1120
1121
1.54M
inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1122
1.54M
  return Node->getConstantOperandVal(i);
1123
1.54M
}
1124
1125
inline bool SDValue::isTargetOpcode() const {
1126
  return Node->isTargetOpcode();
1127
}
1128
1129
inline bool SDValue::isTargetMemoryOpcode() const {
1130
  return Node->isTargetMemoryOpcode();
1131
}
1132
1133
41.2M
inline bool SDValue::isMachineOpcode() const {
1134
41.2M
  return Node->isMachineOpcode();
1135
41.2M
}
1136
1137
7.98M
inline unsigned SDValue::getMachineOpcode() const {
1138
7.98M
  return Node->getMachineOpcode();
1139
7.98M
}
1140
1141
69.6M
inline bool SDValue::isUndef() const {
1142
69.6M
  return Node->isUndef();
1143
69.6M
}
1144
1145
1.05M
inline bool SDValue::use_empty() const {
1146
1.05M
  return !Node->hasAnyUseOfValue(ResNo);
1147
1.05M
}
1148
1149
23.3M
inline bool SDValue::hasOneUse() const {
1150
23.3M
  return Node->hasNUsesOfValue(1, ResNo);
1151
23.3M
}
1152
1153
124k
inline const DebugLoc &SDValue::getDebugLoc() const {
1154
124k
  return Node->getDebugLoc();
1155
124k
}
1156
1157
inline void SDValue::dump() const {
1158
  return Node->dump();
1159
}
1160
1161
inline void SDValue::dump(const SelectionDAG *G) const {
1162
  return Node->dump(G);
1163
}
1164
1165
inline void SDValue::dumpr() const {
1166
  return Node->dumpr();
1167
}
1168
1169
inline void SDValue::dumpr(const SelectionDAG *G) const {
1170
  return Node->dumpr(G);
1171
}
1172
1173
// Define inline functions from the SDUse class.
1174
1175
103M
inline void SDUse::set(const SDValue &V) {
1176
103M
  if (
Val.getNode()103M
) removeFromList();
1177
103M
  Val = V;
1178
103M
  if (V.getNode()) 
V.getNode()->addUse(*this)11.4M
;
1179
103M
}
1180
1181
154M
inline void SDUse::setInitial(const SDValue &V) {
1182
154M
  Val = V;
1183
154M
  V.getNode()->addUse(*this);
1184
154M
}
1185
1186
3.77M
inline void SDUse::setNode(SDNode *N) {
1187
3.77M
  if (Val.getNode()) removeFromList();
1188
3.77M
  Val.setNode(N);
1189
3.77M
  if (N) N->addUse(*this);
1190
3.77M
}
1191
1192
/// This class is used to form a handle around another node that
1193
/// is persistent and is updated across invocations of replaceAllUsesWith on its
1194
/// operand.  This node should be directly created by end-users and not added to
1195
/// the AllNodes list.
1196
class HandleSDNode : public SDNode {
1197
  SDUse Op;
1198
1199
public:
1200
  explicit HandleSDNode(SDValue X)
1201
17.3M
    : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1202
17.3M
    // HandleSDNodes are never inserted into the DAG, so they won't be
1203
17.3M
    // auto-numbered. Use ID 65535 as a sentinel.
1204
17.3M
    PersistentId = 0xffff;
1205
17.3M
1206
17.3M
    // Manually set up the operand list. This node type is special in that it's
1207
17.3M
    // always stack allocated and SelectionDAG does not manage its operands.
1208
17.3M
    // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1209
17.3M
    // be so special.
1210
17.3M
    Op.setUser(this);
1211
17.3M
    Op.setInitial(X);
1212
17.3M
    NumOperands = 1;
1213
17.3M
    OperandList = &Op;
1214
17.3M
  }
1215
  ~HandleSDNode();
1216
1217
16.0M
  const SDValue &getValue() const { return Op; }
1218
};
1219
1220
class AddrSpaceCastSDNode : public SDNode {
1221
private:
1222
  unsigned SrcAddrSpace;
1223
  unsigned DestAddrSpace;
1224
1225
public:
1226
  AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
1227
                      unsigned SrcAS, unsigned DestAS);
1228
1229
456
  unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1230
379
  unsigned getDestAddressSpace() const { return DestAddrSpace; }
1231
1232
1.27k
  static bool classof(const SDNode *N) {
1233
1.27k
    return N->getOpcode() == ISD::ADDRSPACECAST;
1234
1.27k
  }
1235
};
1236
1237
/// This is an abstract virtual class for memory operations.
1238
class MemSDNode : public SDNode {
1239
private:
1240
  // VT of in-memory value.
1241
  EVT MemoryVT;
1242
1243
protected:
1244
  /// Memory reference information.
1245
  MachineMemOperand *MMO;
1246
1247
public:
1248
  MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1249
            EVT memvt, MachineMemOperand *MMO);
1250
1251
3.72k
  bool readMem() const { return MMO->isLoad(); }
1252
18.3k
  bool writeMem() const { return MMO->isStore(); }
1253
1254
  /// Returns alignment and volatility of the memory access
1255
6.88M
  unsigned getOriginalAlignment() const {
1256
6.88M
    return MMO->getBaseAlignment();
1257
6.88M
  }
1258
16.9M
  unsigned getAlignment() const {
1259
16.9M
    return MMO->getAlignment();
1260
16.9M
  }
1261
1262
  /// Return the SubclassData value, without HasDebugValue. This contains an
1263
  /// encoding of the volatile flag, as well as bits used by subclasses. This
1264
  /// function should only be used to compute a FoldingSetNodeID value.
1265
  /// The HasDebugValue bit is masked out because CSE map needs to match
1266
  /// nodes with debug info with nodes without debug info. Same is about
1267
  /// isDivergent bit.
1268
10.4M
  unsigned getRawSubclassData() const {
1269
10.4M
    uint16_t Data;
1270
10.4M
    union {
1271
10.4M
      char RawSDNodeBits[sizeof(uint16_t)];
1272
10.4M
      SDNodeBitfields SDNodeBits;
1273
10.4M
    };
1274
10.4M
    memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1275
10.4M
    SDNodeBits.HasDebugValue = 0;
1276
10.4M
    SDNodeBits.IsDivergent = false;
1277
10.4M
    memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1278
10.4M
    return Data;
1279
10.4M
  }
1280
1281
65.1M
  bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1282
781k
  bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1283
31.8k
  bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1284
37.1M
  bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1285
1286
  // Returns the offset from the location of the access.
1287
6.93M
  int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1288
1289
  /// Returns the AA info that describes the dereference.
1290
5.74M
  AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1291
1292
  /// Returns the Ranges that describes the dereference.
1293
4.98M
  const MDNode *getRanges() const { return MMO->getRanges(); }
1294
1295
  /// Returns the synchronization scope ID for this memory operation.
1296
0
  SyncScope::ID getSyncScopeID() const { return MMO->getSyncScopeID(); }
1297
1298
  /// Return the atomic ordering requirements for this memory operation. For
1299
  /// cmpxchg atomic operations, return the atomic ordering requirements when
1300
  /// store occurs.
1301
132k
  AtomicOrdering getOrdering() const { return MMO->getOrdering(); }
1302
1303
  /// Return the type of the in-memory value.
1304
82.7M
  EVT getMemoryVT() const { return MemoryVT; }
1305
1306
  /// Return a MachineMemOperand object describing the memory
1307
  /// reference performed by operation.
1308
9.96M
  MachineMemOperand *getMemOperand() const { return MMO; }
1309
1310
16.3M
  const MachinePointerInfo &getPointerInfo() const {
1311
16.3M
    return MMO->getPointerInfo();
1312
16.3M
  }
1313
1314
  /// Return the address space for the associated pointer
1315
9.11M
  unsigned getAddressSpace() const {
1316
9.11M
    return getPointerInfo().getAddrSpace();
1317
9.11M
  }
1318
1319
  /// Update this MemSDNode's MachineMemOperand information
1320
  /// to reflect the alignment of NewMMO, if it has a greater alignment.
1321
  /// This must only be used when the new alignment applies to all users of
1322
  /// this MachineMemOperand.
1323
68.0k
  void refineAlignment(const MachineMemOperand *NewMMO) {
1324
68.0k
    MMO->refineAlignment(NewMMO);
1325
68.0k
  }
1326
1327
65.0M
  const SDValue &getChain() const { return getOperand(0); }
1328
95.5M
  const SDValue &getBasePtr() const {
1329
95.5M
    return getOperand(getOpcode() == ISD::STORE ? 
285.9M
:
19.58M
);
1330
95.5M
  }
1331
1332
  // Methods to support isa and dyn_cast
1333
17.7M
  static bool classof(const SDNode *N) {
1334
17.7M
    // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1335
17.7M
    // with either an intrinsic or a target opcode.
1336
17.7M
    return N->getOpcode() == ISD::LOAD                ||
1337
17.7M
           
N->getOpcode() == ISD::STORE12.9M
||
1338
17.7M
           
N->getOpcode() == ISD::PREFETCH1.71M
||
1339
17.7M
           
N->getOpcode() == ISD::ATOMIC_CMP_SWAP1.71M
||
1340
17.7M
           
N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS1.71M
||
1341
17.7M
           
N->getOpcode() == ISD::ATOMIC_SWAP1.70M
||
1342
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD_ADD1.70M
||
1343
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD_SUB1.70M
||
1344
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD_AND1.70M
||
1345
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD_CLR1.70M
||
1346
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD_OR1.70M
||
1347
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD_XOR1.69M
||
1348
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD_NAND1.69M
||
1349
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD_MIN1.69M
||
1350
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD_MAX1.69M
||
1351
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD_UMIN1.69M
||
1352
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD_UMAX1.69M
||
1353
17.7M
           
N->getOpcode() == ISD::ATOMIC_LOAD1.69M
||
1354
17.7M
           
N->getOpcode() == ISD::ATOMIC_STORE1.69M
||
1355
17.7M
           
N->getOpcode() == ISD::MLOAD1.68M
||
1356
17.7M
           
N->getOpcode() == ISD::MSTORE1.68M
||
1357
17.7M
           
N->getOpcode() == ISD::MGATHER1.68M
||
1358
17.7M
           
N->getOpcode() == ISD::MSCATTER1.68M
||
1359
17.7M
           
N->isMemIntrinsic()1.68M
||
1360
17.7M
           
N->isTargetMemoryOpcode()1.60M
;
1361
17.7M
  }
1362
};
1363
1364
/// This is an SDNode representing atomic operations.
1365
class AtomicSDNode : public MemSDNode {
1366
public:
1367
  AtomicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTL,
1368
               EVT MemVT, MachineMemOperand *MMO)
1369
21.5k
      : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {}
1370
1371
3.64k
  const SDValue &getBasePtr() const { return getOperand(1); }
1372
342
  const SDValue &getVal() const { return getOperand(2); }
1373
1374
  /// Returns true if this SDNode represents cmpxchg atomic operation, false
1375
  /// otherwise.
1376
  bool isCompareAndSwap() const {
1377
    unsigned Op = getOpcode();
1378
    return Op == ISD::ATOMIC_CMP_SWAP ||
1379
           Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1380
  }
1381
1382
  /// For cmpxchg atomic operations, return the atomic ordering requirements
1383
  /// when store does not occur.
1384
  AtomicOrdering getFailureOrdering() const {
1385
    assert(isCompareAndSwap() && "Must be cmpxchg operation");
1386
    return MMO->getFailureOrdering();
1387
  }
1388
1389
  // Methods to support isa and dyn_cast
1390
564k
  static bool classof(const SDNode *N) {
1391
564k
    return N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
1392
564k
           
N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS564k
||
1393
564k
           
N->getOpcode() == ISD::ATOMIC_SWAP564k
||
1394
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD_ADD564k
||
1395
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD_SUB564k
||
1396
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD_AND564k
||
1397
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD_CLR563k
||
1398
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD_OR563k
||
1399
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD_XOR563k
||
1400
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD_NAND563k
||
1401
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD_MIN563k
||
1402
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD_MAX563k
||
1403
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD_UMIN563k
||
1404
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD_UMAX563k
||
1405
564k
           
N->getOpcode() == ISD::ATOMIC_LOAD563k
||
1406
564k
           
N->getOpcode() == ISD::ATOMIC_STORE563k
;
1407
564k
  }
1408
};
1409
1410
/// This SDNode is used for target intrinsics that touch
1411
/// memory and need an associated MachineMemOperand. Its opcode may be
1412
/// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1413
/// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1414
class MemIntrinsicSDNode : public MemSDNode {
1415
public:
1416
  MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1417
                     SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
1418
160k
      : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MMO) {
1419
160k
    SDNodeBits.IsMemIntrinsic = true;
1420
160k
  }
1421
1422
  // Methods to support isa and dyn_cast
1423
186
  static bool classof(const SDNode *N) {
1424
186
    // We lower some target intrinsics to their target opcode
1425
186
    // early a node with a target opcode can be of this class
1426
186
    return N->isMemIntrinsic()             ||
1427
186
           
N->getOpcode() == ISD::PREFETCH0
||
1428
186
           
N->isTargetMemoryOpcode()0
;
1429
186
  }
1430
};
1431
1432
/// This SDNode is used to implement the code generator
1433
/// support for the llvm IR shufflevector instruction.  It combines elements
1434
/// from two input vectors into a new input vector, with the selection and
1435
/// ordering of elements determined by an array of integers, referred to as
1436
/// the shuffle mask.  For input vectors of width N, mask indices of 0..N-1
1437
/// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1438
/// An index of -1 is treated as undef, such that the code generator may put
1439
/// any value in the corresponding element of the result.
1440
class ShuffleVectorSDNode : public SDNode {
1441
  // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1442
  // is freed when the SelectionDAG object is destroyed.
1443
  const int *Mask;
1444
1445
protected:
1446
  friend class SelectionDAG;
1447
1448
  ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
1449
116k
      : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {}
1450
1451
public:
1452
402k
  ArrayRef<int> getMask() const {
1453
402k
    EVT VT = getValueType(0);
1454
402k
    return makeArrayRef(Mask, VT.getVectorNumElements());
1455
402k
  }
1456
1457
2.86M
  int getMaskElt(unsigned Idx) const {
1458
2.86M
    assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1459
2.86M
    return Mask[Idx];
1460
2.86M
  }
1461
1462
101k
  bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1463
1464
40.3k
  int  getSplatIndex() const {
1465
40.3k
    assert(isSplat() && "Cannot get splat index for non-splat!");
1466
40.3k
    EVT VT = getValueType(0);
1467
41.1k
    for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; 
++i837
) {
1468
41.1k
      if (Mask[i] >= 0)
1469
40.3k
        return Mask[i];
1470
41.1k
    }
1471
40.3k
    
llvm_unreachable0
("Splat with all undef indices?");
1472
40.3k
  }
1473
1474
  static bool isSplatMask(const int *Mask, EVT VT);
1475
1476
  /// Change values in a shuffle permute mask assuming
1477
  /// the two vector operands have swapped position.
1478
205k
  static void commuteMask(MutableArrayRef<int> Mask) {
1479
205k
    unsigned NumElems = Mask.size();
1480
2.73M
    for (unsigned i = 0; i != NumElems; 
++i2.52M
) {
1481
2.52M
      int idx = Mask[i];
1482
2.52M
      if (idx < 0)
1483
354k
        continue;
1484
2.17M
      else if (idx < (int)NumElems)
1485
1.36M
        Mask[i] = idx + NumElems;
1486
812k
      else
1487
812k
        Mask[i] = idx - NumElems;
1488
2.52M
    }
1489
205k
  }
1490
1491
1.02M
  static bool classof(const SDNode *N) {
1492
1.02M
    return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1493
1.02M
  }
1494
};
1495
1496
class ConstantSDNode : public SDNode {
1497
  friend class SelectionDAG;
1498
1499
  const ConstantInt *Value;
1500
1501
  ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1502
      : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DebugLoc(),
1503
               getSDVTList(VT)),
1504
13.1M
        Value(val) {
1505
13.1M
    ConstantSDNodeBits.IsOpaque = isOpaque;
1506
13.1M
  }
1507
1508
public:
1509
21.0M
  const ConstantInt *getConstantIntValue() const { return Value; }
1510
52.2M
  const APInt &getAPIntValue() const { return Value->getValue(); }
1511
17.6M
  uint64_t getZExtValue() const { return Value->getZExtValue(); }
1512
104M
  int64_t getSExtValue() const { return Value->getSExtValue(); }
1513
341
  uint64_t getLimitedValue(uint64_t Limit = UINT64_MAX) {
1514
341
    return Value->getLimitedValue(Limit);
1515
341
  }
1516
1517
7.00M
  bool isOne() const { return Value->isOne(); }
1518
18.5M
  bool isNullValue() const { return Value->isZero(); }
1519
6.54M
  bool isAllOnesValue() const { return Value->isMinusOne(); }
1520
1521
27.7M
  bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1522
1523
484M
  static bool classof(const SDNode *N) {
1524
484M
    return N->getOpcode() == ISD::Constant ||
1525
484M
           
N->getOpcode() == ISD::TargetConstant285M
;
1526
484M
  }
1527
};
1528
1529
1.91M
uint64_t SDNode::getConstantOperandVal(unsigned Num) const {
1530
1.91M
  return cast<ConstantSDNode>(getOperand(Num))->getZExtValue();
1531
1.91M
}
1532
1533
class ConstantFPSDNode : public SDNode {
1534
  friend class SelectionDAG;
1535
1536
  const ConstantFP *Value;
1537
1538
  ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1539
      : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0,
1540
               DebugLoc(), getSDVTList(VT)),
1541
114k
        Value(val) {}
1542
1543
public:
1544
363k
  const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1545
177k
  const ConstantFP *getConstantFPValue() const { return Value; }
1546
1547
  /// Return true if the value is positive or negative zero.
1548
141k
  bool isZero() const { return Value->isZero(); }
1549
1550
  /// Return true if the value is a NaN.
1551
7.36k
  bool isNaN() const { return Value->isNaN(); }
1552
1553
  /// Return true if the value is an infinity
1554
2
  bool isInfinity() const { return Value->isInfinity(); }
1555
1556
  /// Return true if the value is negative.
1557
37.5k
  bool isNegative() const { return Value->isNegative(); }
1558
1559
  /// We don't rely on operator== working on double values, as
1560
  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1561
  /// As such, this method can be used to do an exact bit-for-bit comparison of
1562
  /// two floating point values.
1563
1564
  /// We leave the version with the double argument here because it's just so
1565
  /// convenient to write "2.0" and the like.  Without this function we'd
1566
  /// have to duplicate its logic everywhere it's called.
1567
78.7k
  bool isExactlyValue(double V) const {
1568
78.7k
    return Value->getValueAPF().isExactlyValue(V);
1569
78.7k
  }
1570
  bool isExactlyValue(const APFloat& V) const;
1571
1572
  static bool isValueValidForType(EVT VT, const APFloat& Val);
1573
1574
218M
  static bool classof(const SDNode *N) {
1575
218M
    return N->getOpcode() == ISD::ConstantFP ||
1576
218M
           
N->getOpcode() == ISD::TargetConstantFP218M
;
1577
218M
  }
1578
};
1579
1580
/// Returns true if \p V is a constant integer zero.
1581
bool isNullConstant(SDValue V);
1582
1583
/// Returns true if \p V is an FP constant with a value of positive zero.
1584
bool isNullFPConstant(SDValue V);
1585
1586
/// Returns true if \p V is an integer constant with all bits set.
1587
bool isAllOnesConstant(SDValue V);
1588
1589
/// Returns true if \p V is a constant integer one.
1590
bool isOneConstant(SDValue V);
1591
1592
/// Returns true if \p V is a bitwise not operation. Assumes that an all ones
1593
/// constant is canonicalized to be operand 1.
1594
bool isBitwiseNot(SDValue V);
1595
1596
/// Returns the SDNode if it is a constant splat BuildVector or constant int.
1597
ConstantSDNode *isConstOrConstSplat(SDValue N);
1598
1599
/// Returns the SDNode if it is a constant splat BuildVector or constant float.
1600
ConstantFPSDNode *isConstOrConstSplatFP(SDValue N);
1601
1602
class GlobalAddressSDNode : public SDNode {
1603
  friend class SelectionDAG;
1604
1605
  const GlobalValue *TheGlobal;
1606
  int64_t Offset;
1607
  unsigned char TargetFlags;
1608
1609
  GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1610
                      const GlobalValue *GA, EVT VT, int64_t o,
1611
                      unsigned char TF);
1612
1613
public:
1614
7.35M
  const GlobalValue *getGlobal() const { return TheGlobal; }
1615
4.73M
  int64_t getOffset() const { return Offset; }
1616
3.08M
  unsigned char getTargetFlags() const { return TargetFlags; }
1617
  // Return the address space this GlobalAddress belongs to.
1618
  unsigned getAddressSpace() const;
1619
1620
147M
  static bool classof(const SDNode *N) {
1621
147M
    return N->getOpcode() == ISD::GlobalAddress ||
1622
147M
           
N->getOpcode() == ISD::TargetGlobalAddress144M
||
1623
147M
           
N->getOpcode() == ISD::GlobalTLSAddress139M
||
1624
147M
           
N->getOpcode() == ISD::TargetGlobalTLSAddress139M
;
1625
147M
  }
1626
};
1627
1628
class FrameIndexSDNode : public SDNode {
1629
  friend class SelectionDAG;
1630
1631
  int FI;
1632
1633
  FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1634
    : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1635
875k
      0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1636
875k
  }
1637
1638
public:
1639
8.24M
  int getIndex() const { return FI; }
1640
1641
99.6M
  static bool classof(const SDNode *N) {
1642
99.6M
    return N->getOpcode() == ISD::FrameIndex ||
1643
99.6M
           
N->getOpcode() == ISD::TargetFrameIndex90.6M
;
1644
99.6M
  }
1645
};
1646
1647
class JumpTableSDNode : public SDNode {
1648
  friend class SelectionDAG;
1649
1650
  int JTI;
1651
  unsigned char TargetFlags;
1652
1653
  JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1654
    : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1655
7.31k
      0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1656
7.31k
  }
1657
1658
public:
1659
11.5k
  int getIndex() const { return JTI; }
1660
7.02k
  unsigned char getTargetFlags() const { return TargetFlags; }
1661
1662
59.9M
  static bool classof(const SDNode *N) {
1663
59.9M
    return N->getOpcode() == ISD::JumpTable ||
1664
59.9M
           N->getOpcode() == ISD::TargetJumpTable;
1665
59.9M
  }
1666
};
1667
1668
class ConstantPoolSDNode : public SDNode {
1669
  friend class SelectionDAG;
1670
1671
  union {
1672
    const Constant *ConstVal;
1673
    MachineConstantPoolValue *MachineCPVal;
1674
  } Val;
1675
  int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1676
  unsigned Alignment;  // Minimum alignment requirement of CP (not log2 value).
1677
  unsigned char TargetFlags;
1678
1679
  ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1680
                     unsigned Align, unsigned char TF)
1681
    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1682
             DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1683
243k
             TargetFlags(TF) {
1684
243k
    assert(Offset >= 0 && "Offset is too large");
1685
243k
    Val.ConstVal = c;
1686
243k
  }
1687
1688
  ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1689
                     EVT VT, int o, unsigned Align, unsigned char TF)
1690
    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1691
             DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1692
273
             TargetFlags(TF) {
1693
273
    assert(Offset >= 0 && "Offset is too large");
1694
273
    Val.MachineCPVal = v;
1695
273
    Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1696
273
  }
1697
1698
public:
1699
488k
  bool isMachineConstantPoolEntry() const {
1700
488k
    return Offset < 0;
1701
488k
  }
1702
1703
509k
  const Constant *getConstVal() const {
1704
509k
    assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1705
509k
    return Val.ConstVal;
1706
509k
  }
1707
1708
370
  MachineConstantPoolValue *getMachineCPVal() const {
1709
370
    assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1710
370
    return Val.MachineCPVal;
1711
370
  }
1712
1713
394k
  int getOffset() const {
1714
394k
    return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1715
394k
  }
1716
1717
  // Return the alignment of this constant pool object, which is either 0 (for
1718
  // default alignment) or the desired value.
1719
481k
  unsigned getAlignment() const { return Alignment; }
1720
257k
  unsigned char getTargetFlags() const { return TargetFlags; }
1721
1722
  Type *getType() const;
1723
1724
71.3M
  static bool classof(const SDNode *N) {
1725
71.3M
    return N->getOpcode() == ISD::ConstantPool ||
1726
71.3M
           
N->getOpcode() == ISD::TargetConstantPool71.3M
;
1727
71.3M
  }
1728
};
1729
1730
/// Completely target-dependent object reference.
1731
class TargetIndexSDNode : public SDNode {
1732
  friend class SelectionDAG;
1733
1734
  unsigned char TargetFlags;
1735
  int Index;
1736
  int64_t Offset;
1737
1738
public:
1739
  TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1740
    : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1741
0
      TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1742
1743
0
  unsigned char getTargetFlags() const { return TargetFlags; }
1744
0
  int getIndex() const { return Index; }
1745
0
  int64_t getOffset() const { return Offset; }
1746
1747
59.7M
  static bool classof(const SDNode *N) {
1748
59.7M
    return N->getOpcode() == ISD::TargetIndex;
1749
59.7M
  }
1750
};
1751
1752
class BasicBlockSDNode : public SDNode {
1753
  friend class SelectionDAG;
1754
1755
  MachineBasicBlock *MBB;
1756
1757
  /// Debug info is meaningful and potentially useful here, but we create
1758
  /// blocks out of order when they're jumped to, which makes it a bit
1759
  /// harder.  Let's see if we need it first.
1760
  explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1761
    : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1762
1.93M
  {}
1763
1764
public:
1765
2.70M
  MachineBasicBlock *getBasicBlock() const { return MBB; }
1766
1767
67.8M
  static bool classof(const SDNode *N) {
1768
67.8M
    return N->getOpcode() == ISD::BasicBlock;
1769
67.8M
  }
1770
};
1771
1772
/// A "pseudo-class" with methods for operating on BUILD_VECTORs.
1773
class BuildVectorSDNode : public SDNode {
1774
public:
1775
  // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1776
  explicit BuildVectorSDNode() = delete;
1777
1778
  /// Check if this is a constant splat, and if so, find the
1779
  /// smallest element size that splats the vector.  If MinSplatBits is
1780
  /// nonzero, the element size must be at least that large.  Note that the
1781
  /// splat element may be the entire vector (i.e., a one element vector).
1782
  /// Returns the splat element value in SplatValue.  Any undefined bits in
1783
  /// that value are zero, and the corresponding bits in the SplatUndef mask
1784
  /// are set.  The SplatBitSize value is set to the splat element size in
1785
  /// bits.  HasAnyUndefs is set to true if any bits in the vector are
1786
  /// undefined.  isBigEndian describes the endianness of the target.
1787
  bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1788
                       unsigned &SplatBitSize, bool &HasAnyUndefs,
1789
                       unsigned MinSplatBits = 0,
1790
                       bool isBigEndian = false) const;
1791
1792
  /// Returns the splatted value or a null value if this is not a splat.
1793
  ///
1794
  /// If passed a non-null UndefElements bitvector, it will resize it to match
1795
  /// the vector width and set the bits where elements are undef.
1796
  SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1797
1798
  /// Returns the splatted constant or null if this is not a constant
1799
  /// splat.
1800
  ///
1801
  /// If passed a non-null UndefElements bitvector, it will resize it to match
1802
  /// the vector width and set the bits where elements are undef.
1803
  ConstantSDNode *
1804
  getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1805
1806
  /// Returns the splatted constant FP or null if this is not a constant
1807
  /// FP splat.
1808
  ///
1809
  /// If passed a non-null UndefElements bitvector, it will resize it to match
1810
  /// the vector width and set the bits where elements are undef.
1811
  ConstantFPSDNode *
1812
  getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1813
1814
  /// If this is a constant FP splat and the splatted constant FP is an
1815
  /// exact power or 2, return the log base 2 integer value.  Otherwise,
1816
  /// return -1.
1817
  ///
1818
  /// The BitWidth specifies the necessary bit precision.
1819
  int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
1820
                                          uint32_t BitWidth) const;
1821
1822
  bool isConstant() const;
1823
1824
41.4M
  static bool classof(const SDNode *N) {
1825
41.4M
    return N->getOpcode() == ISD::BUILD_VECTOR;
1826
41.4M
  }
1827
};
1828
1829
/// An SDNode that holds an arbitrary LLVM IR Value. This is
1830
/// used when the SelectionDAG needs to make a simple reference to something
1831
/// in the LLVM IR representation.
1832
///
1833
class SrcValueSDNode : public SDNode {
1834
  friend class SelectionDAG;
1835
1836
  const Value *V;
1837
1838
  /// Create a SrcValue for a general value.
1839
  explicit SrcValueSDNode(const Value *v)
1840
1.57k
    : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1841
1842
public:
1843
  /// Return the contained Value.
1844
2.78k
  const Value *getValue() const { return V; }
1845
1846
15
  static bool classof(const SDNode *N) {
1847
15
    return N->getOpcode() == ISD::SRCVALUE;
1848
15
  }
1849
};
1850
1851
class MDNodeSDNode : public SDNode {
1852
  friend class SelectionDAG;
1853
1854
  const MDNode *MD;
1855
1856
  explicit MDNodeSDNode(const MDNode *md)
1857
  : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1858
23.6k
  {}
1859
1860
public:
1861
23.5k
  const MDNode *getMD() const { return MD; }
1862
1863
47.9M
  static bool classof(const SDNode *N) {
1864
47.9M
    return N->getOpcode() == ISD::MDNODE_SDNODE;
1865
47.9M
  }
1866
};
1867
1868
class RegisterSDNode : public SDNode {
1869
  friend class SelectionDAG;
1870
1871
  unsigned Reg;
1872
1873
  RegisterSDNode(unsigned reg, EVT VT)
1874
7.90M
    : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
1875
1876
public:
1877
36.7M
  unsigned getReg() const { return Reg; }
1878
1879
109M
  static bool classof(const SDNode *N) {
1880
109M
    return N->getOpcode() == ISD::Register;
1881
109M
  }
1882
};
1883
1884
class RegisterMaskSDNode : public SDNode {
1885
  friend class SelectionDAG;
1886
1887
  // The memory for RegMask is not owned by the node.
1888
  const uint32_t *RegMask;
1889
1890
  RegisterMaskSDNode(const uint32_t *mask)
1891
    : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1892
557k
      RegMask(mask) {}
1893
1894
public:
1895
1.28M
  const uint32_t *getRegMask() const { return RegMask; }
1896
1897
84.1M
  static bool classof(const SDNode *N) {
1898
84.1M
    return N->getOpcode() == ISD::RegisterMask;
1899
84.1M
  }
1900
};
1901
1902
class BlockAddressSDNode : public SDNode {
1903
  friend class SelectionDAG;
1904
1905
  const BlockAddress *BA;
1906
  int64_t Offset;
1907
  unsigned char TargetFlags;
1908
1909
  BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1910
                     int64_t o, unsigned char Flags)
1911
    : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1912
283
             BA(ba), Offset(o), TargetFlags(Flags) {}
1913
1914
public:
1915
397
  const BlockAddress *getBlockAddress() const { return BA; }
1916
262
  int64_t getOffset() const { return Offset; }
1917
225
  unsigned char getTargetFlags() const { return TargetFlags; }
1918
1919
59.6M
  static bool classof(const SDNode *N) {
1920
59.6M
    return N->getOpcode() == ISD::BlockAddress ||
1921
59.6M
           
N->getOpcode() == ISD::TargetBlockAddress59.6M
;
1922
59.6M
  }
1923
};
1924
1925
class LabelSDNode : public SDNode {
1926
  friend class SelectionDAG;
1927
1928
  MCSymbol *Label;
1929
1930
  LabelSDNode(unsigned Order, const DebugLoc &dl, MCSymbol *L)
1931
48.9k
      : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {}
1932
1933
public:
1934
48.8k
  MCSymbol *getLabel() const { return Label; }
1935
1936
  static bool classof(const SDNode *N) {
1937
    return N->getOpcode() == ISD::EH_LABEL ||
1938
           N->getOpcode() == ISD::ANNOTATION_LABEL;
1939
  }
1940
};
1941
1942
class ExternalSymbolSDNode : public SDNode {
1943
  friend class SelectionDAG;
1944
1945
  const char *Symbol;
1946
  unsigned char TargetFlags;
1947
1948
  ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1949
    : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1950
50.1k
             0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {}
1951
1952
public:
1953
89.3k
  const char *getSymbol() const { return Symbol; }
1954
23.6k
  unsigned char getTargetFlags() const { return TargetFlags; }
1955
1956
59.8M
  static bool classof(const SDNode *N) {
1957
59.8M
    return N->getOpcode() == ISD::ExternalSymbol ||
1958
59.8M
           
N->getOpcode() == ISD::TargetExternalSymbol59.7M
;
1959
59.8M
  }
1960
};
1961
1962
class MCSymbolSDNode : public SDNode {
1963
  friend class SelectionDAG;
1964
1965
  MCSymbol *Symbol;
1966
1967
  MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
1968
53
      : SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
1969
1970
public:
1971
74
  MCSymbol *getMCSymbol() const { return Symbol; }
1972
1973
59.6M
  static bool classof(const SDNode *N) {
1974
59.6M
    return N->getOpcode() == ISD::MCSymbol;
1975
59.6M
  }
1976
};
1977
1978
class CondCodeSDNode : public SDNode {
1979
  friend class SelectionDAG;
1980
1981
  ISD::CondCode Condition;
1982
1983
  explicit CondCodeSDNode(ISD::CondCode Cond)
1984
    : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1985
1.44M
      Condition(Cond) {}
1986
1987
public:
1988
10.3M
  ISD::CondCode get() const { return Condition; }
1989
1990
  static bool classof(const SDNode *N) {
1991
    return N->getOpcode() == ISD::CONDCODE;
1992
  }
1993
};
1994
1995
/// This class is used to represent EVT's, which are used
1996
/// to parameterize some operations.
1997
class VTSDNode : public SDNode {
1998
  friend class SelectionDAG;
1999
2000
  EVT ValueType;
2001
2002
  explicit VTSDNode(EVT VT)
2003
    : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2004
323k
      ValueType(VT) {}
2005
2006
public:
2007
3.45M
  EVT getVT() const { return ValueType; }
2008
2009
21
  static bool classof(const SDNode *N) {
2010
21
    return N->getOpcode() == ISD::VALUETYPE;
2011
21
  }
2012
};
2013
2014
/// Base class for LoadSDNode and StoreSDNode
2015
class LSBaseSDNode : public MemSDNode {
2016
public:
2017
  LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
2018
               SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
2019
               MachineMemOperand *MMO)
2020
8.45M
      : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2021
8.45M
    LSBaseSDNodeBits.AddressingMode = AM;
2022
8.45M
    assert(getAddressingMode() == AM && "Value truncated");
2023
8.45M
  }
2024
2025
17.9k
  const SDValue &getOffset() const {
2026
17.9k
    return getOperand(getOpcode() == ISD::LOAD ? 
28.68k
:
39.24k
);
2027
17.9k
  }
2028
2029
  /// Return the addressing mode for this load or store:
2030
  /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2031
183M
  ISD::MemIndexedMode getAddressingMode() const {
2032
183M
    return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2033
183M
  }
2034
2035
  /// Return true if this is a pre/post inc/dec load/store.
2036
31.4M
  bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2037
2038
  /// Return true if this is NOT a pre/post inc/dec load/store.
2039
20.8M
  bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2040
2041
11.3k
  static bool classof(const SDNode *N) {
2042
11.3k
    return N->getOpcode() == ISD::LOAD ||
2043
11.3k
           
N->getOpcode() == ISD::STORE5.70k
;
2044
11.3k
  }
2045
};
2046
2047
/// This class is used to represent ISD::LOAD nodes.
2048
class LoadSDNode : public LSBaseSDNode {
2049
  friend class SelectionDAG;
2050
2051
  LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2052
             ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
2053
             MachineMemOperand *MMO)
2054
3.95M
      : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
2055
3.95M
    LoadSDNodeBits.ExtTy = ETy;
2056
3.95M
    assert(readMem() && "Load MachineMemOperand is not a load!");
2057
3.95M
    assert(!writeMem() && "Load MachineMemOperand is a store!");
2058
3.95M
  }
2059
2060
public:
2061
  /// Return whether this is a plain node,
2062
  /// or one of the varieties of value-extending loads.
2063
30.8M
  ISD::LoadExtType getExtensionType() const {
2064
30.8M
    return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2065
30.8M
  }
2066
2067
9.73M
  const SDValue &getBasePtr() const { return getOperand(1); }
2068
118k
  const SDValue &getOffset() const { return getOperand(2); }
2069
2070
82.4M
  static bool classof(const SDNode *N) {
2071
82.4M
    return N->getOpcode() == ISD::LOAD;
2072
82.4M
  }
2073
};
2074
2075
/// This class is used to represent ISD::STORE nodes.
2076
class StoreSDNode : public LSBaseSDNode {
2077
  friend class SelectionDAG;
2078
2079
  StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2080
              ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
2081
              MachineMemOperand *MMO)
2082
4.50M
      : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
2083
4.50M
    StoreSDNodeBits.IsTruncating = isTrunc;
2084
4.50M
    assert(!readMem() && "Store MachineMemOperand is a load!");
2085
4.50M
    assert(writeMem() && "Store MachineMemOperand is not a store!");
2086
4.50M
  }
2087
2088
public:
2089
  /// Return true if the op does a truncation before store.
2090
  /// For integers this is the same as doing a TRUNCATE and storing the result.
2091
  /// For floats, it is the same as doing an FP_ROUND and storing the result.
2092
26.1M
  bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2093
213
  void setTruncatingStore(bool Truncating) {
2094
213
    StoreSDNodeBits.IsTruncating = Truncating;
2095
213
  }
2096
2097
59.3M
  const SDValue &getValue() const { return getOperand(1); }
2098
20.0M
  const SDValue &getBasePtr() const { return getOperand(2); }
2099
1.85k
  const SDValue &getOffset() const { return getOperand(3); }
2100
2101
39.1M
  static bool classof(const SDNode *N) {
2102
39.1M
    return N->getOpcode() == ISD::STORE;
2103
39.1M
  }
2104
};
2105
2106
/// This base class is used to represent MLOAD and MSTORE nodes
2107
class MaskedLoadStoreSDNode : public MemSDNode {
2108
public:
2109
  friend class SelectionDAG;
2110
2111
  MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
2112
                        const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2113
                        MachineMemOperand *MMO)
2114
2.03k
      : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2115
2116
  // MaskedLoadSDNode (Chain, ptr, mask, passthru)
2117
  // MaskedStoreSDNode (Chain, data, ptr, mask)
2118
  // Mask is a vector of i1 elements
2119
53
  const SDValue &getBasePtr() const {
2120
53
    return getOperand(getOpcode() == ISD::MLOAD ? 
131
:
222
);
2121
53
  }
2122
1.32k
  const SDValue &getMask() const {
2123
1.32k
    return getOperand(getOpcode() == ISD::MLOAD ? 
2799
:
3528
);
2124
1.32k
  }
2125
2126
  static bool classof(const SDNode *N) {
2127
    return N->getOpcode() == ISD::MLOAD ||
2128
           N->getOpcode() == ISD::MSTORE;
2129
  }
2130
};
2131
2132
/// This class is used to represent an MLOAD node
2133
class MaskedLoadSDNode : public MaskedLoadStoreSDNode {
2134
public:
2135
  friend class SelectionDAG;
2136
2137
  MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2138
                   ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT,
2139
                   MachineMemOperand *MMO)
2140
1.22k
      : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, MemVT, MMO) {
2141
1.22k
    LoadSDNodeBits.ExtTy = ETy;
2142
1.22k
    LoadSDNodeBits.IsExpanding = IsExpanding;
2143
1.22k
  }
2144
2145
2.24k
  ISD::LoadExtType getExtensionType() const {
2146
2.24k
    return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2147
2.24k
  }
2148
2149
96
  const SDValue &getBasePtr() const { return getOperand(1); }
2150
875
  const SDValue &getMask() const    { return getOperand(2); }
2151
171
  const SDValue &getPassThru() const { return getOperand(3); }
2152
2153
569
  static bool classof(const SDNode *N) {
2154
569
    return N->getOpcode() == ISD::MLOAD;
2155
569
  }
2156
2157
2.89k
  bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2158
};
2159
2160
/// This class is used to represent an MSTORE node
2161
class MaskedStoreSDNode : public MaskedLoadStoreSDNode {
2162
public:
2163
  friend class SelectionDAG;
2164
2165
  MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2166
                    bool isTrunc, bool isCompressing, EVT MemVT,
2167
                    MachineMemOperand *MMO)
2168
814
      : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, MemVT, MMO) {
2169
814
    StoreSDNodeBits.IsTruncating = isTrunc;
2170
814
    StoreSDNodeBits.IsCompressing = isCompressing;
2171
814
  }
2172
2173
  /// Return true if the op does a truncation before store.
2174
  /// For integers this is the same as doing a TRUNCATE and storing the result.
2175
  /// For floats, it is the same as doing an FP_ROUND and storing the result.
2176
1.19k
  bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2177
2178
  /// Returns true if the op does a compression to the vector before storing.
2179
  /// The node contiguously stores the active elements (integers or floats)
2180
  /// in src (those with their respective bit set in writemask k) to unaligned
2181
  /// memory at base_addr.
2182
1.53k
  bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2183
2184
854
  const SDValue &getValue() const   { return getOperand(1); }
2185
50
  const SDValue &getBasePtr() const { return getOperand(2); }
2186
951
  const SDValue &getMask() const    { return getOperand(3); }
2187
2188
345
  static bool classof(const SDNode *N) {
2189
345
    return N->getOpcode() == ISD::MSTORE;
2190
345
  }
2191
};
2192
2193
/// This is a base class used to represent
2194
/// MGATHER and MSCATTER nodes
2195
///
2196
class MaskedGatherScatterSDNode : public MemSDNode {
2197
public:
2198
  friend class SelectionDAG;
2199
2200
  MaskedGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order,
2201
                            const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2202
                            MachineMemOperand *MMO)
2203
1.27k
      : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2204
2205
  // In the both nodes address is Op1, mask is Op2:
2206
  // MaskedGatherSDNode  (Chain, passthru, mask, base, index, scale)
2207
  // MaskedScatterSDNode (Chain, value, mask, base, index, scale)
2208
  // Mask is a vector of i1 elements
2209
636
  const SDValue &getBasePtr() const { return getOperand(3); }
2210
669
  const SDValue &getIndex()   const { return getOperand(4); }
2211
1.25k
  const SDValue &getMask()    const { return getOperand(2); }
2212
636
  const SDValue &getScale()   const { return getOperand(5); }
2213
2214
  static bool classof(const SDNode *N) {
2215
    return N->getOpcode() == ISD::MGATHER ||
2216
           N->getOpcode() == ISD::MSCATTER;
2217
  }
2218
};
2219
2220
/// This class is used to represent an MGATHER node
2221
///
2222
class MaskedGatherSDNode : public MaskedGatherScatterSDNode {
2223
public:
2224
  friend class SelectionDAG;
2225
2226
  MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2227
                     EVT MemVT, MachineMemOperand *MMO)
2228
936
      : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO) {}
2229
2230
478
  const SDValue &getPassThru() const { return getOperand(1); }
2231
2232
  static bool classof(const SDNode *N) {
2233
    return N->getOpcode() == ISD::MGATHER;
2234
  }
2235
};
2236
2237
/// This class is used to represent an MSCATTER node
2238
///
2239
class MaskedScatterSDNode : public MaskedGatherScatterSDNode {
2240
public:
2241
  friend class SelectionDAG;
2242
2243
  MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2244
                      EVT MemVT, MachineMemOperand *MMO)
2245
336
      : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO) {}
2246
2247
410
  const SDValue &getValue() const { return getOperand(1); }
2248
2249
  static bool classof(const SDNode *N) {
2250
    return N->getOpcode() == ISD::MSCATTER;
2251
  }
2252
};
2253
2254
/// An SDNode that represents everything that will be needed
2255
/// to construct a MachineInstr. These nodes are created during the
2256
/// instruction selection proper phase.
2257
///
2258
/// Note that the only supported way to set the `memoperands` is by calling the
2259
/// `SelectionDAG::setNodeMemRefs` function as the memory management happens
2260
/// inside the DAG rather than in the node.
2261
class MachineSDNode : public SDNode {
2262
private:
2263
  friend class SelectionDAG;
2264
2265
  MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
2266
752k
      : SDNode(Opc, Order, DL, VTs) {}
2267
2268
  // We use a pointer union between a single `MachineMemOperand` pointer and
2269
  // a pointer to an array of `MachineMemOperand` pointers. This is null when
2270
  // the number of these is zero, the single pointer variant used when the
2271
  // number is one, and the array is used for larger numbers.
2272
  //
2273
  // The array is allocated via the `SelectionDAG`'s allocator and so will
2274
  // always live until the DAG is cleaned up and doesn't require ownership here.
2275
  //
2276
  // We can't use something simpler like `TinyPtrVector` here because `SDNode`
2277
  // subclasses aren't managed in a conforming C++ manner. See the comments on
2278
  // `SelectionDAG::MorphNodeTo` which details what all goes on, but the
2279
  // constraint here is that these don't manage memory with their constructor or
2280
  // destructor and can be initialized to a good state even if they start off
2281
  // uninitialized.
2282
  PointerUnion<MachineMemOperand *, MachineMemOperand **> MemRefs = {};
2283
2284
  // Note that this could be folded into the above `MemRefs` member if doing so
2285
  // is advantageous at some point. We don't need to store this in most cases.
2286
  // However, at the moment this doesn't appear to make the allocation any
2287
  // smaller and makes the code somewhat simpler to read.
2288
  int NumMemRefs = 0;
2289
2290
public:
2291
  using mmo_iterator = ArrayRef<MachineMemOperand *>::const_iterator;
2292
2293
11.3M
  ArrayRef<MachineMemOperand *> memoperands() const {
2294
11.3M
    // Special case the common cases.
2295
11.3M
    if (NumMemRefs == 0)
2296
8.66M
      return {};
2297
2.70M
    if (NumMemRefs == 1)
2298
2.70M
      return makeArrayRef(MemRefs.getAddrOfPtr1(), 1);
2299
5.20k
2300
5.20k
    // Otherwise we have an actual array.
2301
5.20k
    return makeArrayRef(MemRefs.get<MachineMemOperand **>(), NumMemRefs);
2302
5.20k
  }
2303
173k
  mmo_iterator memoperands_begin() const { return memoperands().begin(); }
2304
62.1k
  mmo_iterator memoperands_end() const { return memoperands().end(); }
2305
298k
  bool memoperands_empty() const { return memoperands().empty(); }
2306
2307
  /// Clear out the memory reference descriptor list.
2308
11.0M
  void clearMemRefs() {
2309
11.0M
    MemRefs = nullptr;
2310
11.0M
    NumMemRefs = 0;
2311
11.0M
  }
2312
2313
12.6M
  static bool classof(const SDNode *N) {
2314
12.6M
    return N->isMachineOpcode();
2315
12.6M
  }
2316
};
2317
2318
class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2319
                                            SDNode, ptrdiff_t> {
2320
  const SDNode *Node;
2321
  unsigned Operand;
2322
2323
19.3k
  SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2324
2325
public:
2326
27.2k
  bool operator==(const SDNodeIterator& x) const {
2327
27.2k
    return Operand == x.Operand;
2328
27.2k
  }
2329
27.2k
  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2330
2331
17.6k
  pointer operator*() const {
2332
17.6k
    return Node->getOperand(Operand).getNode();
2333
17.6k
  }
2334
  pointer operator->() const { return operator*(); }
2335
2336
17.6k
  SDNodeIterator& operator++() {                // Preincrement
2337
17.6k
    ++Operand;
2338
17.6k
    return *this;
2339
17.6k
  }
2340
0
  SDNodeIterator operator++(int) { // Postincrement
2341
0
    SDNodeIterator tmp = *this; ++*this; return tmp;
2342
0
  }
2343
  size_t operator-(SDNodeIterator Other) const {
2344
    assert(Node == Other.Node &&
2345
           "Cannot compare iterators of two different nodes!");
2346
    return Operand - Other.Operand;
2347
  }
2348
2349
9.65k
  static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2350
9.65k
  static SDNodeIterator end  (const SDNode *N) {
2351
9.65k
    return SDNodeIterator(N, N->getNumOperands());
2352
9.65k
  }
2353
2354
  unsigned getOperand() const { return Operand; }
2355
  const SDNode *getNode() const { return Node; }
2356
};
2357
2358
template <> struct GraphTraits<SDNode*> {
2359
  using NodeRef = SDNode *;
2360
  using ChildIteratorType = SDNodeIterator;
2361
2362
  static NodeRef getEntryNode(SDNode *N) { return N; }
2363
2364
  static ChildIteratorType child_begin(NodeRef N) {
2365
    return SDNodeIterator::begin(N);
2366
  }
2367
2368
  static ChildIteratorType child_end(NodeRef N) {
2369
    return SDNodeIterator::end(N);
2370
  }
2371
};
2372
2373
/// A representation of the largest SDNode, for use in sizeof().
2374
///
2375
/// This needs to be a union because the largest node differs on 32 bit systems
2376
/// with 4 and 8 byte pointer alignment, respectively.
2377
using LargestSDNode = AlignedCharArrayUnion<AtomicSDNode, TargetIndexSDNode,
2378
                                            BlockAddressSDNode,
2379
                                            GlobalAddressSDNode>;
2380
2381
/// The SDNode class with the greatest alignment requirement.
2382
using MostAlignedSDNode = GlobalAddressSDNode;
2383
2384
namespace ISD {
2385
2386
  /// Returns true if the specified node is a non-extending and unindexed load.
2387
11.4M
  inline bool isNormalLoad(const SDNode *N) {
2388
11.4M
    const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2389
11.4M
    return Ld && 
Ld->getExtensionType() == ISD::NON_EXTLOAD6.03M
&&
2390
11.4M
      
Ld->getAddressingMode() == ISD::UNINDEXED4.95M
;
2391
11.4M
  }
2392
2393
  /// Returns true if the specified node is a non-extending load.
2394
696k
  inline bool isNON_EXTLoad(const SDNode *N) {
2395
696k
    return isa<LoadSDNode>(N) &&
2396
696k
      
cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD288k
;
2397
696k
  }
2398
2399
  /// Returns true if the specified node is a EXTLOAD.
2400
839k
  inline bool isEXTLoad(const SDNode *N) {
2401
839k
    return isa<LoadSDNode>(N) &&
2402
839k
      
cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD88.3k
;
2403
839k
  }
2404
2405
  /// Returns true if the specified node is a SEXTLOAD.
2406
588k
  inline bool isSEXTLoad(const SDNode *N) {
2407
588k
    return isa<LoadSDNode>(N) &&
2408
588k
      
cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD70.5k
;
2409
588k
  }
2410
2411
  /// Returns true if the specified node is a ZEXTLOAD.
2412
5.74M
  inline bool isZEXTLoad(const SDNode *N) {
2413
5.74M
    return isa<LoadSDNode>(N) &&
2414
5.74M
      
cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD5.51M
;
2415
5.74M
  }
2416
2417
  /// Returns true if the specified node is an unindexed load.
2418
1.82M
  inline bool isUNINDEXEDLoad(const SDNode *N) {
2419
1.82M
    return isa<LoadSDNode>(N) &&
2420
1.82M
      
cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED1.49M
;
2421
1.82M
  }
2422
2423
  /// Returns true if the specified node is a non-truncating
2424
  /// and unindexed store.
2425
6.43M
  inline bool isNormalStore(const SDNode *N) {
2426
6.43M
    const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2427
6.43M
    return St && 
!St->isTruncatingStore()6.43M
&&
2428
6.43M
      
St->getAddressingMode() == ISD::UNINDEXED5.95M
;
2429
6.43M
  }
2430
2431
  /// Returns true if the specified node is a non-truncating store.
2432
2.84M
  inline bool isNON_TRUNCStore(const SDNode *N) {
2433
2.84M
    return isa<StoreSDNode>(N) && 
!cast<StoreSDNode>(N)->isTruncatingStore()288k
;
2434
2.84M
  }
2435
2436
  /// Returns true if the specified node is a truncating store.
2437
  inline bool isTRUNCStore(const SDNode *N) {
2438
    return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2439
  }
2440
2441
  /// Returns true if the specified node is an unindexed store.
2442
  inline bool isUNINDEXEDStore(const SDNode *N) {
2443
    return isa<StoreSDNode>(N) &&
2444
      cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2445
  }
2446
2447
  /// Return true if the node is a math/logic binary operator. This corresponds
2448
  /// to the IR function of the same name.
2449
  inline bool isBinaryOp(const SDNode *N) {
2450
    auto Op = N->getOpcode();
2451
    return (Op == ISD::ADD || Op == ISD::SUB || Op == ISD::MUL ||
2452
            Op == ISD::AND || Op == ISD::OR || Op == ISD::XOR ||
2453
            Op == ISD::SHL || Op == ISD::SRL || Op == ISD::SRA ||
2454
            Op == ISD::SDIV || Op == ISD::UDIV || Op == ISD::SREM ||
2455
            Op == ISD::UREM || Op == ISD::FADD || Op == ISD::FSUB ||
2456
            Op == ISD::FMUL || Op == ISD::FDIV || Op == ISD::FREM);
2457
  }
2458
2459
  /// Attempt to match a unary predicate against a scalar/splat constant or
2460
  /// every element of a constant BUILD_VECTOR.
2461
  bool matchUnaryPredicate(SDValue Op,
2462
                           std::function<bool(ConstantSDNode *)> Match);
2463
2464
  /// Attempt to match a binary predicate against a pair of scalar/splat
2465
  /// constants or every element of a pair of constant BUILD_VECTORs.
2466
  bool matchBinaryPredicate(
2467
      SDValue LHS, SDValue RHS,
2468
      std::function<bool(ConstantSDNode *, ConstantSDNode *)> Match);
2469
2470
} // end namespace ISD
2471
2472
} // end namespace llvm
2473
2474
#endif // LLVM_CODEGEN_SELECTIONDAGNODES_H