~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/include/llvm/CodeGen/SelectionDAGNodes.h

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
ImportĀ upstreamĀ versionĀ 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/Constants.h"
23
 
#include "llvm/ADT/FoldingSet.h"
24
 
#include "llvm/ADT/GraphTraits.h"
25
 
#include "llvm/ADT/ilist_node.h"
26
 
#include "llvm/ADT/SmallVector.h"
27
 
#include "llvm/ADT/STLExtras.h"
28
 
#include "llvm/CodeGen/ISDOpcodes.h"
29
 
#include "llvm/CodeGen/ValueTypes.h"
30
 
#include "llvm/CodeGen/MachineMemOperand.h"
31
 
#include "llvm/Support/MathExtras.h"
32
 
#include "llvm/System/DataTypes.h"
33
 
#include "llvm/Support/DebugLoc.h"
34
 
#include <cassert>
35
 
 
36
 
namespace llvm {
37
 
 
38
 
class SelectionDAG;
39
 
class GlobalValue;
40
 
class MachineBasicBlock;
41
 
class MachineConstantPoolValue;
42
 
class SDNode;
43
 
class Value;
44
 
class MCSymbol;
45
 
template <typename T> struct DenseMapInfo;
46
 
template <typename T> struct simplify_type;
47
 
template <typename T> struct ilist_traits;
48
 
 
49
 
void checkForCycles(const SDNode *N);
50
 
  
51
 
/// SDVTList - This represents a list of ValueType's that has been intern'd by
52
 
/// a SelectionDAG.  Instances of this simple value class are returned by
53
 
/// SelectionDAG::getVTList(...).
54
 
///
55
 
struct SDVTList {
56
 
  const EVT *VTs;
57
 
  unsigned int NumVTs;
58
 
};
59
 
 
60
 
namespace ISD {
61
 
  /// Node predicates
62
 
 
63
 
  /// isBuildVectorAllOnes - Return true if the specified node is a
64
 
  /// BUILD_VECTOR where all of the elements are ~0 or undef.
65
 
  bool isBuildVectorAllOnes(const SDNode *N);
66
 
 
67
 
  /// isBuildVectorAllZeros - Return true if the specified node is a
68
 
  /// BUILD_VECTOR where all of the elements are 0 or undef.
69
 
  bool isBuildVectorAllZeros(const SDNode *N);
70
 
 
71
 
  /// isScalarToVector - Return true if the specified node is a
72
 
  /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
73
 
  /// element is not an undef.
74
 
  bool isScalarToVector(const SDNode *N);
75
 
}  // end llvm:ISD namespace
76
 
 
77
 
//===----------------------------------------------------------------------===//
78
 
/// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
79
 
/// values as the result of a computation.  Many nodes return multiple values,
80
 
/// from loads (which define a token and a return value) to ADDC (which returns
81
 
/// a result and a carry value), to calls (which may return an arbitrary number
82
 
/// of values).
83
 
///
84
 
/// As such, each use of a SelectionDAG computation must indicate the node that
85
 
/// computes it as well as which return value to use from that node.  This pair
86
 
/// of information is represented with the SDValue value type.
87
 
///
88
 
class SDValue {
89
 
  SDNode *Node;       // The node defining the value we are using.
90
 
  unsigned ResNo;     // Which return value of the node we are using.
91
 
public:
92
 
  SDValue() : Node(0), ResNo(0) {}
93
 
  SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
94
 
 
95
 
  /// get the index which selects a specific result in the SDNode
96
 
  unsigned getResNo() const { return ResNo; }
97
 
 
98
 
  /// get the SDNode which holds the desired result
99
 
  SDNode *getNode() const { return Node; }
100
 
 
101
 
  /// set the SDNode
102
 
  void setNode(SDNode *N) { Node = N; }
103
 
 
104
 
  inline SDNode *operator->() const { return Node; }
105
 
  
106
 
  bool operator==(const SDValue &O) const {
107
 
    return Node == O.Node && ResNo == O.ResNo;
108
 
  }
109
 
  bool operator!=(const SDValue &O) const {
110
 
    return !operator==(O);
111
 
  }
112
 
  bool operator<(const SDValue &O) const {
113
 
    return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
114
 
  }
115
 
 
116
 
  SDValue getValue(unsigned R) const {
117
 
    return SDValue(Node, R);
118
 
  }
119
 
 
120
 
  // isOperandOf - Return true if this node is an operand of N.
121
 
  bool isOperandOf(SDNode *N) const;
122
 
 
123
 
  /// getValueType - Return the ValueType of the referenced return value.
124
 
  ///
125
 
  inline EVT getValueType() const;
126
 
 
127
 
  /// getValueSizeInBits - Returns the size of the value in bits.
128
 
  ///
129
 
  unsigned getValueSizeInBits() const {
130
 
    return getValueType().getSizeInBits();
131
 
  }
132
 
 
133
 
  // Forwarding methods - These forward to the corresponding methods in SDNode.
134
 
  inline unsigned getOpcode() const;
135
 
  inline unsigned getNumOperands() const;
136
 
  inline const SDValue &getOperand(unsigned i) const;
137
 
  inline uint64_t getConstantOperandVal(unsigned i) const;
138
 
  inline bool isTargetMemoryOpcode() const;
139
 
  inline bool isTargetOpcode() const;
140
 
  inline bool isMachineOpcode() const;
141
 
  inline unsigned getMachineOpcode() const;
142
 
  inline const DebugLoc getDebugLoc() const;
143
 
 
144
 
 
145
 
  /// reachesChainWithoutSideEffects - Return true if this operand (which must
146
 
  /// be a chain) reaches the specified operand without crossing any
147
 
  /// side-effecting instructions.  In practice, this looks through token
148
 
  /// factors and non-volatile loads.  In order to remain efficient, this only
149
 
  /// looks a couple of nodes in, it does not do an exhaustive search.
150
 
  bool reachesChainWithoutSideEffects(SDValue Dest,
151
 
                                      unsigned Depth = 2) const;
152
 
 
153
 
  /// use_empty - Return true if there are no nodes using value ResNo
154
 
  /// of Node.
155
 
  ///
156
 
  inline bool use_empty() const;
157
 
 
158
 
  /// hasOneUse - Return true if there is exactly one node using value
159
 
  /// ResNo of Node.
160
 
  ///
161
 
  inline bool hasOneUse() const;
162
 
};
163
 
 
164
 
 
165
 
template<> struct DenseMapInfo<SDValue> {
166
 
  static inline SDValue getEmptyKey() {
167
 
    return SDValue((SDNode*)-1, -1U);
168
 
  }
169
 
  static inline SDValue getTombstoneKey() {
170
 
    return SDValue((SDNode*)-1, 0);
171
 
  }
172
 
  static unsigned getHashValue(const SDValue &Val) {
173
 
    return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
174
 
            (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
175
 
  }
176
 
  static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
177
 
    return LHS == RHS;
178
 
  }
179
 
};
180
 
template <> struct isPodLike<SDValue> { static const bool value = true; };
181
 
 
182
 
 
183
 
/// simplify_type specializations - Allow casting operators to work directly on
184
 
/// SDValues as if they were SDNode*'s.
185
 
template<> struct simplify_type<SDValue> {
186
 
  typedef SDNode* SimpleType;
187
 
  static SimpleType getSimplifiedValue(const SDValue &Val) {
188
 
    return static_cast<SimpleType>(Val.getNode());
189
 
  }
190
 
};
191
 
template<> struct simplify_type<const SDValue> {
192
 
  typedef SDNode* SimpleType;
193
 
  static SimpleType getSimplifiedValue(const SDValue &Val) {
194
 
    return static_cast<SimpleType>(Val.getNode());
195
 
  }
196
 
};
197
 
 
198
 
/// SDUse - Represents a use of a SDNode. This class holds an SDValue,
199
 
/// which records the SDNode being used and the result number, a
200
 
/// pointer to the SDNode using the value, and Next and Prev pointers,
201
 
/// which link together all the uses of an SDNode.
202
 
///
203
 
class SDUse {
204
 
  /// Val - The value being used.
205
 
  SDValue Val;
206
 
  /// User - The user of this value.
207
 
  SDNode *User;
208
 
  /// Prev, Next - Pointers to the uses list of the SDNode referred by
209
 
  /// this operand.
210
 
  SDUse **Prev, *Next;
211
 
 
212
 
  SDUse(const SDUse &U);          // Do not implement
213
 
  void operator=(const SDUse &U); // Do not implement
214
 
 
215
 
public:
216
 
  SDUse() : Val(), User(NULL), Prev(NULL), Next(NULL) {}
217
 
 
218
 
  /// Normally SDUse will just implicitly convert to an SDValue that it holds.
219
 
  operator const SDValue&() const { return Val; }
220
 
 
221
 
  /// If implicit conversion to SDValue doesn't work, the get() method returns
222
 
  /// the SDValue.
223
 
  const SDValue &get() const { return Val; }
224
 
 
225
 
  /// getUser - This returns the SDNode that contains this Use.
226
 
  SDNode *getUser() { return User; }
227
 
 
228
 
  /// getNext - Get the next SDUse in the use list.
229
 
  SDUse *getNext() const { return Next; }
230
 
 
231
 
  /// getNode - Convenience function for get().getNode().
232
 
  SDNode *getNode() const { return Val.getNode(); }
233
 
  /// getResNo - Convenience function for get().getResNo().
234
 
  unsigned getResNo() const { return Val.getResNo(); }
235
 
  /// getValueType - Convenience function for get().getValueType().
236
 
  EVT getValueType() const { return Val.getValueType(); }
237
 
 
238
 
  /// operator== - Convenience function for get().operator==
239
 
  bool operator==(const SDValue &V) const {
240
 
    return Val == V;
241
 
  }
242
 
 
243
 
  /// operator!= - Convenience function for get().operator!=
244
 
  bool operator!=(const SDValue &V) const {
245
 
    return Val != V;
246
 
  }
247
 
 
248
 
  /// operator< - Convenience function for get().operator<
249
 
  bool operator<(const SDValue &V) const {
250
 
    return Val < V;
251
 
  }
252
 
 
253
 
private:
254
 
  friend class SelectionDAG;
255
 
  friend class SDNode;
256
 
 
257
 
  void setUser(SDNode *p) { User = p; }
258
 
 
259
 
  /// set - Remove this use from its existing use list, assign it the
260
 
  /// given value, and add it to the new value's node's use list.
261
 
  inline void set(const SDValue &V);
262
 
  /// setInitial - like set, but only supports initializing a newly-allocated
263
 
  /// SDUse with a non-null value.
264
 
  inline void setInitial(const SDValue &V);
265
 
  /// setNode - like set, but only sets the Node portion of the value,
266
 
  /// leaving the ResNo portion unmodified.
267
 
  inline void setNode(SDNode *N);
268
 
 
269
 
  void addToList(SDUse **List) {
270
 
    Next = *List;
271
 
    if (Next) Next->Prev = &Next;
272
 
    Prev = List;
273
 
    *List = this;
274
 
  }
275
 
 
276
 
  void removeFromList() {
277
 
    *Prev = Next;
278
 
    if (Next) Next->Prev = Prev;
279
 
  }
280
 
};
281
 
 
282
 
/// simplify_type specializations - Allow casting operators to work directly on
283
 
/// SDValues as if they were SDNode*'s.
284
 
template<> struct simplify_type<SDUse> {
285
 
  typedef SDNode* SimpleType;
286
 
  static SimpleType getSimplifiedValue(const SDUse &Val) {
287
 
    return static_cast<SimpleType>(Val.getNode());
288
 
  }
289
 
};
290
 
template<> struct simplify_type<const SDUse> {
291
 
  typedef SDNode* SimpleType;
292
 
  static SimpleType getSimplifiedValue(const SDUse &Val) {
293
 
    return static_cast<SimpleType>(Val.getNode());
294
 
  }
295
 
};
296
 
 
297
 
 
298
 
/// SDNode - Represents one node in the SelectionDAG.
299
 
///
300
 
class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
301
 
private:
302
 
  /// NodeType - The operation that this node performs.
303
 
  ///
304
 
  int16_t NodeType;
305
 
 
306
 
  /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
307
 
  /// then they will be delete[]'d when the node is destroyed.
308
 
  uint16_t OperandsNeedDelete : 1;
309
 
 
310
 
  /// HasDebugValue - This tracks whether this node has one or more dbg_value
311
 
  /// nodes corresponding to it.
312
 
  uint16_t HasDebugValue : 1;
313
 
 
314
 
protected:
315
 
  /// SubclassData - This member is defined by this class, but is not used for
316
 
  /// anything.  Subclasses can use it to hold whatever state they find useful.
317
 
  /// This field is initialized to zero by the ctor.
318
 
  uint16_t SubclassData : 14;
319
 
 
320
 
private:
321
 
  /// NodeId - Unique id per SDNode in the DAG.
322
 
  int NodeId;
323
 
 
324
 
  /// OperandList - The values that are used by this operation.
325
 
  ///
326
 
  SDUse *OperandList;
327
 
 
328
 
  /// ValueList - The types of the values this node defines.  SDNode's may
329
 
  /// define multiple values simultaneously.
330
 
  const EVT *ValueList;
331
 
 
332
 
  /// UseList - List of uses for this SDNode.
333
 
  SDUse *UseList;
334
 
 
335
 
  /// NumOperands/NumValues - The number of entries in the Operand/Value list.
336
 
  unsigned short NumOperands, NumValues;
337
 
 
338
 
  /// debugLoc - source line information.
339
 
  DebugLoc debugLoc;
340
 
 
341
 
  /// getValueTypeList - Return a pointer to the specified value type.
342
 
  static const EVT *getValueTypeList(EVT VT);
343
 
 
344
 
  friend class SelectionDAG;
345
 
  friend struct ilist_traits<SDNode>;
346
 
 
347
 
public:
348
 
  //===--------------------------------------------------------------------===//
349
 
  //  Accessors
350
 
  //
351
 
 
352
 
  /// getOpcode - Return the SelectionDAG opcode value for this node. For
353
 
  /// pre-isel nodes (those for which isMachineOpcode returns false), these
354
 
  /// are the opcode values in the ISD and <target>ISD namespaces. For
355
 
  /// post-isel opcodes, see getMachineOpcode.
356
 
  unsigned getOpcode()  const { return (unsigned short)NodeType; }
357
 
 
358
 
  /// isTargetOpcode - Test if this node has a target-specific opcode (in the
359
 
  /// \<target\>ISD namespace).
360
 
  bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
361
 
 
362
 
  /// isTargetMemoryOpcode - Test if this node has a target-specific 
363
 
  /// memory-referencing opcode (in the \<target\>ISD namespace and
364
 
  /// greater than FIRST_TARGET_MEMORY_OPCODE).
365
 
  bool isTargetMemoryOpcode() const {
366
 
    return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
367
 
  }
368
 
 
369
 
  /// isMachineOpcode - Test if this node has a post-isel opcode, directly
370
 
  /// corresponding to a MachineInstr opcode.
371
 
  bool isMachineOpcode() const { return NodeType < 0; }
372
 
 
373
 
  /// getMachineOpcode - This may only be called if isMachineOpcode returns
374
 
  /// true. It returns the MachineInstr opcode value that the node's opcode
375
 
  /// corresponds to.
376
 
  unsigned getMachineOpcode() const {
377
 
    assert(isMachineOpcode() && "Not a MachineInstr opcode!");
378
 
    return ~NodeType;
379
 
  }
380
 
 
381
 
  /// getHasDebugValue - get this bit.
382
 
  bool getHasDebugValue() const { return HasDebugValue; }
383
 
 
384
 
  /// setHasDebugValue - set this bit.
385
 
  void setHasDebugValue(bool b) { HasDebugValue = b; }
386
 
 
387
 
  /// use_empty - Return true if there are no uses of this node.
388
 
  ///
389
 
  bool use_empty() const { return UseList == NULL; }
390
 
 
391
 
  /// hasOneUse - Return true if there is exactly one use of this node.
392
 
  ///
393
 
  bool hasOneUse() const {
394
 
    return !use_empty() && llvm::next(use_begin()) == use_end();
395
 
  }
396
 
 
397
 
  /// use_size - Return the number of uses of this node. This method takes
398
 
  /// time proportional to the number of uses.
399
 
  ///
400
 
  size_t use_size() const { return std::distance(use_begin(), use_end()); }
401
 
 
402
 
  /// getNodeId - Return the unique node id.
403
 
  ///
404
 
  int getNodeId() const { return NodeId; }
405
 
 
406
 
  /// setNodeId - Set unique node id.
407
 
  void setNodeId(int Id) { NodeId = Id; }
408
 
 
409
 
  /// getDebugLoc - Return the source location info.
410
 
  const DebugLoc getDebugLoc() const { return debugLoc; }
411
 
 
412
 
  /// setDebugLoc - Set source location info.  Try to avoid this, putting
413
 
  /// it in the constructor is preferable.
414
 
  void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
415
 
 
416
 
  /// use_iterator - This class provides iterator support for SDUse
417
 
  /// operands that use a specific SDNode.
418
 
  class use_iterator
419
 
    : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
420
 
    SDUse *Op;
421
 
    explicit use_iterator(SDUse *op) : Op(op) {
422
 
    }
423
 
    friend class SDNode;
424
 
  public:
425
 
    typedef std::iterator<std::forward_iterator_tag,
426
 
                          SDUse, ptrdiff_t>::reference reference;
427
 
    typedef std::iterator<std::forward_iterator_tag,
428
 
                          SDUse, ptrdiff_t>::pointer pointer;
429
 
 
430
 
    use_iterator(const use_iterator &I) : Op(I.Op) {}
431
 
    use_iterator() : Op(0) {}
432
 
 
433
 
    bool operator==(const use_iterator &x) const {
434
 
      return Op == x.Op;
435
 
    }
436
 
    bool operator!=(const use_iterator &x) const {
437
 
      return !operator==(x);
438
 
    }
439
 
 
440
 
    /// atEnd - return true if this iterator is at the end of uses list.
441
 
    bool atEnd() const { return Op == 0; }
442
 
 
443
 
    // Iterator traversal: forward iteration only.
444
 
    use_iterator &operator++() {          // Preincrement
445
 
      assert(Op && "Cannot increment end iterator!");
446
 
      Op = Op->getNext();
447
 
      return *this;
448
 
    }
449
 
 
450
 
    use_iterator operator++(int) {        // Postincrement
451
 
      use_iterator tmp = *this; ++*this; return tmp;
452
 
    }
453
 
 
454
 
    /// Retrieve a pointer to the current user node.
455
 
    SDNode *operator*() const {
456
 
      assert(Op && "Cannot dereference end iterator!");
457
 
      return Op->getUser();
458
 
    }
459
 
 
460
 
    SDNode *operator->() const { return operator*(); }
461
 
 
462
 
    SDUse &getUse() const { return *Op; }
463
 
 
464
 
    /// getOperandNo - Retrieve the operand # of this use in its user.
465
 
    ///
466
 
    unsigned getOperandNo() const {
467
 
      assert(Op && "Cannot dereference end iterator!");
468
 
      return (unsigned)(Op - Op->getUser()->OperandList);
469
 
    }
470
 
  };
471
 
 
472
 
  /// use_begin/use_end - Provide iteration support to walk over all uses
473
 
  /// of an SDNode.
474
 
 
475
 
  use_iterator use_begin() const {
476
 
    return use_iterator(UseList);
477
 
  }
478
 
 
479
 
  static use_iterator use_end() { return use_iterator(0); }
480
 
 
481
 
 
482
 
  /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
483
 
  /// indicated value.  This method ignores uses of other values defined by this
484
 
  /// operation.
485
 
  bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
486
 
 
487
 
  /// hasAnyUseOfValue - Return true if there are any use of the indicated
488
 
  /// value. This method ignores uses of other values defined by this operation.
489
 
  bool hasAnyUseOfValue(unsigned Value) const;
490
 
 
491
 
  /// isOnlyUserOf - Return true if this node is the only use of N.
492
 
  ///
493
 
  bool isOnlyUserOf(SDNode *N) const;
494
 
 
495
 
  /// isOperandOf - Return true if this node is an operand of N.
496
 
  ///
497
 
  bool isOperandOf(SDNode *N) const;
498
 
 
499
 
  /// isPredecessorOf - Return true if this node is a predecessor of N. This
500
 
  /// node is either an operand of N or it can be reached by recursively
501
 
  /// traversing up the operands.
502
 
  /// NOTE: this is an expensive method. Use it carefully.
503
 
  bool isPredecessorOf(SDNode *N) const;
504
 
 
505
 
  /// getNumOperands - Return the number of values used by this operation.
506
 
  ///
507
 
  unsigned getNumOperands() const { return NumOperands; }
508
 
 
509
 
  /// getConstantOperandVal - Helper method returns the integer value of a
510
 
  /// ConstantSDNode operand.
511
 
  uint64_t getConstantOperandVal(unsigned Num) const;
512
 
 
513
 
  const SDValue &getOperand(unsigned Num) const {
514
 
    assert(Num < NumOperands && "Invalid child # of SDNode!");
515
 
    return OperandList[Num];
516
 
  }
517
 
 
518
 
  typedef SDUse* op_iterator;
519
 
  op_iterator op_begin() const { return OperandList; }
520
 
  op_iterator op_end() const { return OperandList+NumOperands; }
521
 
 
522
 
  SDVTList getVTList() const {
523
 
    SDVTList X = { ValueList, NumValues };
524
 
    return X;
525
 
  }
526
 
 
527
 
  /// getFlaggedNode - If this node has a flag operand, return the node
528
 
  /// to which the flag operand points. Otherwise return NULL.
529
 
  SDNode *getFlaggedNode() const {
530
 
    if (getNumOperands() != 0 &&
531
 
      getOperand(getNumOperands()-1).getValueType().getSimpleVT() == MVT::Flag)
532
 
      return getOperand(getNumOperands()-1).getNode();
533
 
    return 0;
534
 
  }
535
 
 
536
 
  // If this is a pseudo op, like copyfromreg, look to see if there is a
537
 
  // real target node flagged to it.  If so, return the target node.
538
 
  const SDNode *getFlaggedMachineNode() const {
539
 
    const SDNode *FoundNode = this;
540
 
 
541
 
    // Climb up flag edges until a machine-opcode node is found, or the
542
 
    // end of the chain is reached.
543
 
    while (!FoundNode->isMachineOpcode()) {
544
 
      const SDNode *N = FoundNode->getFlaggedNode();
545
 
      if (!N) break;
546
 
      FoundNode = N;
547
 
    }
548
 
 
549
 
    return FoundNode;
550
 
  }
551
 
 
552
 
  /// getFlaggedUser - If this node has a flag value with a user, return
553
 
  /// the user (there is at most one). Otherwise return NULL.
554
 
  SDNode *getFlaggedUser() const {
555
 
    for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
556
 
      if (UI.getUse().get().getValueType() == MVT::Flag)
557
 
        return *UI;
558
 
    return 0;
559
 
  }
560
 
 
561
 
  /// getNumValues - Return the number of values defined/returned by this
562
 
  /// operator.
563
 
  ///
564
 
  unsigned getNumValues() const { return NumValues; }
565
 
 
566
 
  /// getValueType - Return the type of a specified result.
567
 
  ///
568
 
  EVT getValueType(unsigned ResNo) const {
569
 
    assert(ResNo < NumValues && "Illegal result number!");
570
 
    return ValueList[ResNo];
571
 
  }
572
 
 
573
 
  /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
574
 
  ///
575
 
  unsigned getValueSizeInBits(unsigned ResNo) const {
576
 
    return getValueType(ResNo).getSizeInBits();
577
 
  }
578
 
 
579
 
  typedef const EVT* value_iterator;
580
 
  value_iterator value_begin() const { return ValueList; }
581
 
  value_iterator value_end() const { return ValueList+NumValues; }
582
 
 
583
 
  /// getOperationName - Return the opcode of this operation for printing.
584
 
  ///
585
 
  std::string getOperationName(const SelectionDAG *G = 0) const;
586
 
  static const char* getIndexedModeName(ISD::MemIndexedMode AM);
587
 
  void print_types(raw_ostream &OS, const SelectionDAG *G) const;
588
 
  void print_details(raw_ostream &OS, const SelectionDAG *G) const;
589
 
  void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
590
 
  void printr(raw_ostream &OS, const SelectionDAG *G = 0) const;
591
 
 
592
 
  /// printrFull - Print a SelectionDAG node and all children down to
593
 
  /// the leaves.  The given SelectionDAG allows target-specific nodes
594
 
  /// to be printed in human-readable form.  Unlike printr, this will
595
 
  /// print the whole DAG, including children that appear multiple
596
 
  /// times.
597
 
  ///
598
 
  void printrFull(raw_ostream &O, const SelectionDAG *G = 0) const;
599
 
 
600
 
  /// printrWithDepth - Print a SelectionDAG node and children up to
601
 
  /// depth "depth."  The given SelectionDAG allows target-specific
602
 
  /// nodes to be printed in human-readable form.  Unlike printr, this
603
 
  /// will print children that appear multiple times wherever they are
604
 
  /// used.
605
 
  ///
606
 
  void printrWithDepth(raw_ostream &O, const SelectionDAG *G = 0,
607
 
                       unsigned depth = 100) const;
608
 
 
609
 
 
610
 
  /// dump - Dump this node, for debugging.
611
 
  void dump() const;
612
 
 
613
 
  /// dumpr - Dump (recursively) this node and its use-def subgraph.
614
 
  void dumpr() const;
615
 
 
616
 
  /// dump - Dump this node, for debugging.
617
 
  /// The given SelectionDAG allows target-specific nodes to be printed
618
 
  /// in human-readable form.
619
 
  void dump(const SelectionDAG *G) const;
620
 
 
621
 
  /// dumpr - Dump (recursively) this node and its use-def subgraph.
622
 
  /// The given SelectionDAG allows target-specific nodes to be printed
623
 
  /// in human-readable form.
624
 
  void dumpr(const SelectionDAG *G) const;
625
 
 
626
 
  /// dumprFull - printrFull to dbgs().  The given SelectionDAG allows
627
 
  /// target-specific nodes to be printed in human-readable form.
628
 
  /// Unlike dumpr, this will print the whole DAG, including children
629
 
  /// that appear multiple times.
630
 
  ///
631
 
  void dumprFull(const SelectionDAG *G = 0) const;
632
 
 
633
 
  /// dumprWithDepth - printrWithDepth to dbgs().  The given
634
 
  /// SelectionDAG allows target-specific nodes to be printed in
635
 
  /// human-readable form.  Unlike dumpr, this will print children
636
 
  /// that appear multiple times wherever they are used.
637
 
  ///
638
 
  void dumprWithDepth(const SelectionDAG *G = 0, unsigned depth = 100) const;
639
 
 
640
 
 
641
 
  static bool classof(const SDNode *) { return true; }
642
 
 
643
 
  /// Profile - Gather unique data for the node.
644
 
  ///
645
 
  void Profile(FoldingSetNodeID &ID) const;
646
 
 
647
 
  /// addUse - This method should only be used by the SDUse class.
648
 
  ///
649
 
  void addUse(SDUse &U) { U.addToList(&UseList); }
650
 
 
651
 
protected:
652
 
  static SDVTList getSDVTList(EVT VT) {
653
 
    SDVTList Ret = { getValueTypeList(VT), 1 };
654
 
    return Ret;
655
 
  }
656
 
 
657
 
  SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops,
658
 
         unsigned NumOps)
659
 
    : NodeType(Opc), OperandsNeedDelete(true), HasDebugValue(false),
660
 
      SubclassData(0), NodeId(-1),
661
 
      OperandList(NumOps ? new SDUse[NumOps] : 0),
662
 
      ValueList(VTs.VTs), UseList(NULL),
663
 
      NumOperands(NumOps), NumValues(VTs.NumVTs),
664
 
      debugLoc(dl) {
665
 
    for (unsigned i = 0; i != NumOps; ++i) {
666
 
      OperandList[i].setUser(this);
667
 
      OperandList[i].setInitial(Ops[i]);
668
 
    }
669
 
    checkForCycles(this);
670
 
  }
671
 
 
672
 
  /// This constructor adds no operands itself; operands can be
673
 
  /// set later with InitOperands.
674
 
  SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs)
675
 
    : NodeType(Opc), OperandsNeedDelete(false), HasDebugValue(false),
676
 
      SubclassData(0), NodeId(-1), OperandList(0), ValueList(VTs.VTs),
677
 
      UseList(NULL), NumOperands(0), NumValues(VTs.NumVTs),
678
 
      debugLoc(dl) {}
679
 
 
680
 
  /// InitOperands - Initialize the operands list of this with 1 operand.
681
 
  void InitOperands(SDUse *Ops, const SDValue &Op0) {
682
 
    Ops[0].setUser(this);
683
 
    Ops[0].setInitial(Op0);
684
 
    NumOperands = 1;
685
 
    OperandList = Ops;
686
 
    checkForCycles(this);
687
 
  }
688
 
 
689
 
  /// InitOperands - Initialize the operands list of this with 2 operands.
690
 
  void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
691
 
    Ops[0].setUser(this);
692
 
    Ops[0].setInitial(Op0);
693
 
    Ops[1].setUser(this);
694
 
    Ops[1].setInitial(Op1);
695
 
    NumOperands = 2;
696
 
    OperandList = Ops;
697
 
    checkForCycles(this);
698
 
  }
699
 
 
700
 
  /// InitOperands - Initialize the operands list of this with 3 operands.
701
 
  void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
702
 
                    const SDValue &Op2) {
703
 
    Ops[0].setUser(this);
704
 
    Ops[0].setInitial(Op0);
705
 
    Ops[1].setUser(this);
706
 
    Ops[1].setInitial(Op1);
707
 
    Ops[2].setUser(this);
708
 
    Ops[2].setInitial(Op2);
709
 
    NumOperands = 3;
710
 
    OperandList = Ops;
711
 
    checkForCycles(this);
712
 
  }
713
 
 
714
 
  /// InitOperands - Initialize the operands list of this with 4 operands.
715
 
  void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
716
 
                    const SDValue &Op2, const SDValue &Op3) {
717
 
    Ops[0].setUser(this);
718
 
    Ops[0].setInitial(Op0);
719
 
    Ops[1].setUser(this);
720
 
    Ops[1].setInitial(Op1);
721
 
    Ops[2].setUser(this);
722
 
    Ops[2].setInitial(Op2);
723
 
    Ops[3].setUser(this);
724
 
    Ops[3].setInitial(Op3);
725
 
    NumOperands = 4;
726
 
    OperandList = Ops;
727
 
    checkForCycles(this);
728
 
  }
729
 
 
730
 
  /// InitOperands - Initialize the operands list of this with N operands.
731
 
  void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
732
 
    for (unsigned i = 0; i != N; ++i) {
733
 
      Ops[i].setUser(this);
734
 
      Ops[i].setInitial(Vals[i]);
735
 
    }
736
 
    NumOperands = N;
737
 
    OperandList = Ops;
738
 
    checkForCycles(this);
739
 
  }
740
 
 
741
 
  /// DropOperands - Release the operands and set this node to have
742
 
  /// zero operands.
743
 
  void DropOperands();
744
 
};
745
 
 
746
 
 
747
 
// Define inline functions from the SDValue class.
748
 
 
749
 
inline unsigned SDValue::getOpcode() const {
750
 
  return Node->getOpcode();
751
 
}
752
 
inline EVT SDValue::getValueType() const {
753
 
  return Node->getValueType(ResNo);
754
 
}
755
 
inline unsigned SDValue::getNumOperands() const {
756
 
  return Node->getNumOperands();
757
 
}
758
 
inline const SDValue &SDValue::getOperand(unsigned i) const {
759
 
  return Node->getOperand(i);
760
 
}
761
 
inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
762
 
  return Node->getConstantOperandVal(i);
763
 
}
764
 
inline bool SDValue::isTargetOpcode() const {
765
 
  return Node->isTargetOpcode();
766
 
}
767
 
inline bool SDValue::isTargetMemoryOpcode() const {
768
 
  return Node->isTargetMemoryOpcode();
769
 
}
770
 
inline bool SDValue::isMachineOpcode() const {
771
 
  return Node->isMachineOpcode();
772
 
}
773
 
inline unsigned SDValue::getMachineOpcode() const {
774
 
  return Node->getMachineOpcode();
775
 
}
776
 
inline bool SDValue::use_empty() const {
777
 
  return !Node->hasAnyUseOfValue(ResNo);
778
 
}
779
 
inline bool SDValue::hasOneUse() const {
780
 
  return Node->hasNUsesOfValue(1, ResNo);
781
 
}
782
 
inline const DebugLoc SDValue::getDebugLoc() const {
783
 
  return Node->getDebugLoc();
784
 
}
785
 
 
786
 
// Define inline functions from the SDUse class.
787
 
 
788
 
inline void SDUse::set(const SDValue &V) {
789
 
  if (Val.getNode()) removeFromList();
790
 
  Val = V;
791
 
  if (V.getNode()) V.getNode()->addUse(*this);
792
 
}
793
 
 
794
 
inline void SDUse::setInitial(const SDValue &V) {
795
 
  Val = V;
796
 
  V.getNode()->addUse(*this);
797
 
}
798
 
 
799
 
inline void SDUse::setNode(SDNode *N) {
800
 
  if (Val.getNode()) removeFromList();
801
 
  Val.setNode(N);
802
 
  if (N) N->addUse(*this);
803
 
}
804
 
 
805
 
/// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
806
 
/// to allow co-allocation of node operands with the node itself.
807
 
class UnarySDNode : public SDNode {
808
 
  SDUse Op;
809
 
public:
810
 
  UnarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X)
811
 
    : SDNode(Opc, dl, VTs) {
812
 
    InitOperands(&Op, X);
813
 
  }
814
 
};
815
 
 
816
 
/// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
817
 
/// to allow co-allocation of node operands with the node itself.
818
 
class BinarySDNode : public SDNode {
819
 
  SDUse Ops[2];
820
 
public:
821
 
  BinarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y)
822
 
    : SDNode(Opc, dl, VTs) {
823
 
    InitOperands(Ops, X, Y);
824
 
  }
825
 
};
826
 
 
827
 
/// TernarySDNode - This class is used for three-operand SDNodes. This is solely
828
 
/// to allow co-allocation of node operands with the node itself.
829
 
class TernarySDNode : public SDNode {
830
 
  SDUse Ops[3];
831
 
public:
832
 
  TernarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y,
833
 
                SDValue Z)
834
 
    : SDNode(Opc, dl, VTs) {
835
 
    InitOperands(Ops, X, Y, Z);
836
 
  }
837
 
};
838
 
 
839
 
 
840
 
/// HandleSDNode - This class is used to form a handle around another node that
841
 
/// is persistant and is updated across invocations of replaceAllUsesWith on its
842
 
/// operand.  This node should be directly created by end-users and not added to
843
 
/// the AllNodes list.
844
 
class HandleSDNode : public SDNode {
845
 
  SDUse Op;
846
 
public:
847
 
  // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
848
 
  // fixed.
849
 
#if __GNUC__==4 && __GNUC_MINOR__==2 && defined(__APPLE__) && !defined(__llvm__)
850
 
  explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
851
 
#else
852
 
  explicit HandleSDNode(SDValue X)
853
 
#endif
854
 
    : SDNode(ISD::HANDLENODE, DebugLoc(), getSDVTList(MVT::Other)) {
855
 
    InitOperands(&Op, X);
856
 
  }
857
 
  ~HandleSDNode();
858
 
  const SDValue &getValue() const { return Op; }
859
 
};
860
 
 
861
 
/// Abstact virtual class for operations for memory operations
862
 
class MemSDNode : public SDNode {
863
 
private:
864
 
  // MemoryVT - VT of in-memory value.
865
 
  EVT MemoryVT;
866
 
 
867
 
protected:
868
 
  /// MMO - Memory reference information.
869
 
  MachineMemOperand *MMO;
870
 
 
871
 
public:
872
 
  MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, EVT MemoryVT,
873
 
            MachineMemOperand *MMO);
874
 
 
875
 
  MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, const SDValue *Ops,
876
 
            unsigned NumOps, EVT MemoryVT, MachineMemOperand *MMO);
877
 
 
878
 
  bool readMem() const { return MMO->isLoad(); }
879
 
  bool writeMem() const { return MMO->isStore(); }
880
 
 
881
 
  /// Returns alignment and volatility of the memory access
882
 
  unsigned getOriginalAlignment() const { 
883
 
    return MMO->getBaseAlignment();
884
 
  }
885
 
  unsigned getAlignment() const {
886
 
    return MMO->getAlignment();
887
 
  }
888
 
 
889
 
  /// getRawSubclassData - Return the SubclassData value, which contains an
890
 
  /// encoding of the volatile flag, as well as bits used by subclasses. This
891
 
  /// function should only be used to compute a FoldingSetNodeID value.
892
 
  unsigned getRawSubclassData() const {
893
 
    return SubclassData;
894
 
  }
895
 
 
896
 
  // We access subclass data here so that we can check consistency
897
 
  // with MachineMemOperand information.
898
 
  bool isVolatile() const { return (SubclassData >> 5) & 1; }
899
 
  bool isNonTemporal() const { return (SubclassData >> 6) & 1; }
900
 
 
901
 
  /// Returns the SrcValue and offset that describes the location of the access
902
 
  const Value *getSrcValue() const { return MMO->getValue(); }
903
 
  int64_t getSrcValueOffset() const { return MMO->getOffset(); }
904
 
 
905
 
  /// getMemoryVT - Return the type of the in-memory value.
906
 
  EVT getMemoryVT() const { return MemoryVT; }
907
 
 
908
 
  /// getMemOperand - Return a MachineMemOperand object describing the memory
909
 
  /// reference performed by operation.
910
 
  MachineMemOperand *getMemOperand() const { return MMO; }
911
 
 
912
 
  /// refineAlignment - Update this MemSDNode's MachineMemOperand information
913
 
  /// to reflect the alignment of NewMMO, if it has a greater alignment.
914
 
  /// This must only be used when the new alignment applies to all users of
915
 
  /// this MachineMemOperand.
916
 
  void refineAlignment(const MachineMemOperand *NewMMO) {
917
 
    MMO->refineAlignment(NewMMO);
918
 
  }
919
 
 
920
 
  const SDValue &getChain() const { return getOperand(0); }
921
 
  const SDValue &getBasePtr() const {
922
 
    return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
923
 
  }
924
 
 
925
 
  // Methods to support isa and dyn_cast
926
 
  static bool classof(const MemSDNode *) { return true; }
927
 
  static bool classof(const SDNode *N) {
928
 
    // For some targets, we lower some target intrinsics to a MemIntrinsicNode
929
 
    // with either an intrinsic or a target opcode.
930
 
    return N->getOpcode() == ISD::LOAD                ||
931
 
           N->getOpcode() == ISD::STORE               ||
932
 
           N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
933
 
           N->getOpcode() == ISD::ATOMIC_SWAP         ||
934
 
           N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
935
 
           N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
936
 
           N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
937
 
           N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
938
 
           N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
939
 
           N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
940
 
           N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
941
 
           N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
942
 
           N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
943
 
           N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
944
 
           N->isTargetMemoryOpcode();
945
 
  }
946
 
};
947
 
 
948
 
/// AtomicSDNode - A SDNode reprenting atomic operations.
949
 
///
950
 
class AtomicSDNode : public MemSDNode {
951
 
  SDUse Ops[4];
952
 
 
953
 
public:
954
 
  // Opc:   opcode for atomic
955
 
  // VTL:    value type list
956
 
  // Chain:  memory chain for operaand
957
 
  // Ptr:    address to update as a SDValue
958
 
  // Cmp:    compare value
959
 
  // Swp:    swap value
960
 
  // SrcVal: address to update as a Value (used for MemOperand)
961
 
  // Align:  alignment of memory
962
 
  AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
963
 
               SDValue Chain, SDValue Ptr,
964
 
               SDValue Cmp, SDValue Swp, MachineMemOperand *MMO)
965
 
    : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
966
 
    assert(readMem() && "Atomic MachineMemOperand is not a load!");
967
 
    assert(writeMem() && "Atomic MachineMemOperand is not a store!");
968
 
    InitOperands(Ops, Chain, Ptr, Cmp, Swp);
969
 
  }
970
 
  AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
971
 
               SDValue Chain, SDValue Ptr,
972
 
               SDValue Val, MachineMemOperand *MMO)
973
 
    : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
974
 
    assert(readMem() && "Atomic MachineMemOperand is not a load!");
975
 
    assert(writeMem() && "Atomic MachineMemOperand is not a store!");
976
 
    InitOperands(Ops, Chain, Ptr, Val);
977
 
  }
978
 
 
979
 
  const SDValue &getBasePtr() const { return getOperand(1); }
980
 
  const SDValue &getVal() const { return getOperand(2); }
981
 
 
982
 
  bool isCompareAndSwap() const {
983
 
    unsigned Op = getOpcode();
984
 
    return Op == ISD::ATOMIC_CMP_SWAP;
985
 
  }
986
 
 
987
 
  // Methods to support isa and dyn_cast
988
 
  static bool classof(const AtomicSDNode *) { return true; }
989
 
  static bool classof(const SDNode *N) {
990
 
    return N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
991
 
           N->getOpcode() == ISD::ATOMIC_SWAP         ||
992
 
           N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
993
 
           N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
994
 
           N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
995
 
           N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
996
 
           N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
997
 
           N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
998
 
           N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
999
 
           N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
1000
 
           N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
1001
 
           N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
1002
 
  }
1003
 
};
1004
 
 
1005
 
/// MemIntrinsicSDNode - This SDNode is used for target intrinsics that touch
1006
 
/// memory and need an associated MachineMemOperand. Its opcode may be
1007
 
/// INTRINSIC_VOID, INTRINSIC_W_CHAIN, or a target-specific opcode with a
1008
 
/// value not less than FIRST_TARGET_MEMORY_OPCODE.
1009
 
class MemIntrinsicSDNode : public MemSDNode {
1010
 
public:
1011
 
  MemIntrinsicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs,
1012
 
                     const SDValue *Ops, unsigned NumOps,
1013
 
                     EVT MemoryVT, MachineMemOperand *MMO)
1014
 
    : MemSDNode(Opc, dl, VTs, Ops, NumOps, MemoryVT, MMO) {
1015
 
  }
1016
 
 
1017
 
  // Methods to support isa and dyn_cast
1018
 
  static bool classof(const MemIntrinsicSDNode *) { return true; }
1019
 
  static bool classof(const SDNode *N) {
1020
 
    // We lower some target intrinsics to their target opcode
1021
 
    // early a node with a target opcode can be of this class
1022
 
    return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1023
 
           N->getOpcode() == ISD::INTRINSIC_VOID ||
1024
 
           N->isTargetMemoryOpcode();
1025
 
  }
1026
 
};
1027
 
 
1028
 
/// ShuffleVectorSDNode - This SDNode is used to implement the code generator
1029
 
/// support for the llvm IR shufflevector instruction.  It combines elements
1030
 
/// from two input vectors into a new input vector, with the selection and
1031
 
/// ordering of elements determined by an array of integers, referred to as
1032
 
/// the shuffle mask.  For input vectors of width N, mask indices of 0..N-1
1033
 
/// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1034
 
/// An index of -1 is treated as undef, such that the code generator may put
1035
 
/// any value in the corresponding element of the result.
1036
 
class ShuffleVectorSDNode : public SDNode {
1037
 
  SDUse Ops[2];
1038
 
 
1039
 
  // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1040
 
  // is freed when the SelectionDAG object is destroyed.
1041
 
  const int *Mask;
1042
 
protected:
1043
 
  friend class SelectionDAG;
1044
 
  ShuffleVectorSDNode(EVT VT, DebugLoc dl, SDValue N1, SDValue N2, 
1045
 
                      const int *M)
1046
 
    : SDNode(ISD::VECTOR_SHUFFLE, dl, getSDVTList(VT)), Mask(M) {
1047
 
    InitOperands(Ops, N1, N2);
1048
 
  }
1049
 
public:
1050
 
 
1051
 
  void getMask(SmallVectorImpl<int> &M) const {
1052
 
    EVT VT = getValueType(0);
1053
 
    M.clear();
1054
 
    for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i)
1055
 
      M.push_back(Mask[i]);
1056
 
  }
1057
 
  int getMaskElt(unsigned Idx) const {
1058
 
    assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1059
 
    return Mask[Idx];
1060
 
  }
1061
 
  
1062
 
  bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1063
 
  int  getSplatIndex() const { 
1064
 
    assert(isSplat() && "Cannot get splat index for non-splat!");
1065
 
    EVT VT = getValueType(0);
1066
 
    for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1067
 
      if (Mask[i] != -1)
1068
 
        return Mask[i];
1069
 
    }
1070
 
    return -1;
1071
 
  }
1072
 
  static bool isSplatMask(const int *Mask, EVT VT);
1073
 
 
1074
 
  static bool classof(const ShuffleVectorSDNode *) { return true; }
1075
 
  static bool classof(const SDNode *N) {
1076
 
    return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1077
 
  }
1078
 
};
1079
 
  
1080
 
class ConstantSDNode : public SDNode {
1081
 
  const ConstantInt *Value;
1082
 
  friend class SelectionDAG;
1083
 
  ConstantSDNode(bool isTarget, const ConstantInt *val, EVT VT)
1084
 
    : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
1085
 
             DebugLoc(), getSDVTList(VT)), Value(val) {
1086
 
  }
1087
 
public:
1088
 
 
1089
 
  const ConstantInt *getConstantIntValue() const { return Value; }
1090
 
  const APInt &getAPIntValue() const { return Value->getValue(); }
1091
 
  uint64_t getZExtValue() const { return Value->getZExtValue(); }
1092
 
  int64_t getSExtValue() const { return Value->getSExtValue(); }
1093
 
 
1094
 
  bool isOne() const { return Value->isOne(); }
1095
 
  bool isNullValue() const { return Value->isNullValue(); }
1096
 
  bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1097
 
 
1098
 
  static bool classof(const ConstantSDNode *) { return true; }
1099
 
  static bool classof(const SDNode *N) {
1100
 
    return N->getOpcode() == ISD::Constant ||
1101
 
           N->getOpcode() == ISD::TargetConstant;
1102
 
  }
1103
 
};
1104
 
 
1105
 
class ConstantFPSDNode : public SDNode {
1106
 
  const ConstantFP *Value;
1107
 
  friend class SelectionDAG;
1108
 
  ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1109
 
    : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1110
 
             DebugLoc(), getSDVTList(VT)), Value(val) {
1111
 
  }
1112
 
public:
1113
 
 
1114
 
  const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1115
 
  const ConstantFP *getConstantFPValue() const { return Value; }
1116
 
 
1117
 
  /// isZero - Return true if the value is positive or negative zero.
1118
 
  bool isZero() const { return Value->isZero(); }
1119
 
 
1120
 
  /// isNaN - Return true if the value is a NaN.
1121
 
  bool isNaN() const { return Value->isNaN(); }
1122
 
 
1123
 
  /// isExactlyValue - We don't rely on operator== working on double values, as
1124
 
  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1125
 
  /// As such, this method can be used to do an exact bit-for-bit comparison of
1126
 
  /// two floating point values.
1127
 
 
1128
 
  /// We leave the version with the double argument here because it's just so
1129
 
  /// convenient to write "2.0" and the like.  Without this function we'd
1130
 
  /// have to duplicate its logic everywhere it's called.
1131
 
  bool isExactlyValue(double V) const {
1132
 
    bool ignored;
1133
 
    // convert is not supported on this type
1134
 
    if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
1135
 
      return false;
1136
 
    APFloat Tmp(V);
1137
 
    Tmp.convert(Value->getValueAPF().getSemantics(),
1138
 
                APFloat::rmNearestTiesToEven, &ignored);
1139
 
    return isExactlyValue(Tmp);
1140
 
  }
1141
 
  bool isExactlyValue(const APFloat& V) const;
1142
 
 
1143
 
  static bool isValueValidForType(EVT VT, const APFloat& Val);
1144
 
 
1145
 
  static bool classof(const ConstantFPSDNode *) { return true; }
1146
 
  static bool classof(const SDNode *N) {
1147
 
    return N->getOpcode() == ISD::ConstantFP ||
1148
 
           N->getOpcode() == ISD::TargetConstantFP;
1149
 
  }
1150
 
};
1151
 
 
1152
 
class GlobalAddressSDNode : public SDNode {
1153
 
  const GlobalValue *TheGlobal;
1154
 
  int64_t Offset;
1155
 
  unsigned char TargetFlags;
1156
 
  friend class SelectionDAG;
1157
 
  GlobalAddressSDNode(unsigned Opc, DebugLoc DL, const GlobalValue *GA, EVT VT,
1158
 
                      int64_t o, unsigned char TargetFlags);
1159
 
public:
1160
 
 
1161
 
  const GlobalValue *getGlobal() const { return TheGlobal; }
1162
 
  int64_t getOffset() const { return Offset; }
1163
 
  unsigned char getTargetFlags() const { return TargetFlags; }
1164
 
  // Return the address space this GlobalAddress belongs to.
1165
 
  unsigned getAddressSpace() const;
1166
 
 
1167
 
  static bool classof(const GlobalAddressSDNode *) { return true; }
1168
 
  static bool classof(const SDNode *N) {
1169
 
    return N->getOpcode() == ISD::GlobalAddress ||
1170
 
           N->getOpcode() == ISD::TargetGlobalAddress ||
1171
 
           N->getOpcode() == ISD::GlobalTLSAddress ||
1172
 
           N->getOpcode() == ISD::TargetGlobalTLSAddress;
1173
 
  }
1174
 
};
1175
 
 
1176
 
class FrameIndexSDNode : public SDNode {
1177
 
  int FI;
1178
 
  friend class SelectionDAG;
1179
 
  FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1180
 
    : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1181
 
      DebugLoc(), getSDVTList(VT)), FI(fi) {
1182
 
  }
1183
 
public:
1184
 
 
1185
 
  int getIndex() const { return FI; }
1186
 
 
1187
 
  static bool classof(const FrameIndexSDNode *) { return true; }
1188
 
  static bool classof(const SDNode *N) {
1189
 
    return N->getOpcode() == ISD::FrameIndex ||
1190
 
           N->getOpcode() == ISD::TargetFrameIndex;
1191
 
  }
1192
 
};
1193
 
 
1194
 
class JumpTableSDNode : public SDNode {
1195
 
  int JTI;
1196
 
  unsigned char TargetFlags;
1197
 
  friend class SelectionDAG;
1198
 
  JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1199
 
    : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1200
 
      DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1201
 
  }
1202
 
public:
1203
 
 
1204
 
  int getIndex() const { return JTI; }
1205
 
  unsigned char getTargetFlags() const { return TargetFlags; }
1206
 
 
1207
 
  static bool classof(const JumpTableSDNode *) { return true; }
1208
 
  static bool classof(const SDNode *N) {
1209
 
    return N->getOpcode() == ISD::JumpTable ||
1210
 
           N->getOpcode() == ISD::TargetJumpTable;
1211
 
  }
1212
 
};
1213
 
 
1214
 
class ConstantPoolSDNode : public SDNode {
1215
 
  union {
1216
 
    const Constant *ConstVal;
1217
 
    MachineConstantPoolValue *MachineCPVal;
1218
 
  } Val;
1219
 
  int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1220
 
  unsigned Alignment;  // Minimum alignment requirement of CP (not log2 value).
1221
 
  unsigned char TargetFlags;
1222
 
  friend class SelectionDAG;
1223
 
  ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1224
 
                     unsigned Align, unsigned char TF)
1225
 
    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1226
 
             DebugLoc(),
1227
 
             getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1228
 
    assert((int)Offset >= 0 && "Offset is too large");
1229
 
    Val.ConstVal = c;
1230
 
  }
1231
 
  ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1232
 
                     EVT VT, int o, unsigned Align, unsigned char TF)
1233
 
    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1234
 
             DebugLoc(),
1235
 
             getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1236
 
    assert((int)Offset >= 0 && "Offset is too large");
1237
 
    Val.MachineCPVal = v;
1238
 
    Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1239
 
  }
1240
 
public:
1241
 
  
1242
 
 
1243
 
  bool isMachineConstantPoolEntry() const {
1244
 
    return (int)Offset < 0;
1245
 
  }
1246
 
 
1247
 
  const Constant *getConstVal() const {
1248
 
    assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1249
 
    return Val.ConstVal;
1250
 
  }
1251
 
 
1252
 
  MachineConstantPoolValue *getMachineCPVal() const {
1253
 
    assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1254
 
    return Val.MachineCPVal;
1255
 
  }
1256
 
 
1257
 
  int getOffset() const {
1258
 
    return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1259
 
  }
1260
 
 
1261
 
  // Return the alignment of this constant pool object, which is either 0 (for
1262
 
  // default alignment) or the desired value.
1263
 
  unsigned getAlignment() const { return Alignment; }
1264
 
  unsigned char getTargetFlags() const { return TargetFlags; }
1265
 
 
1266
 
  const Type *getType() const;
1267
 
 
1268
 
  static bool classof(const ConstantPoolSDNode *) { return true; }
1269
 
  static bool classof(const SDNode *N) {
1270
 
    return N->getOpcode() == ISD::ConstantPool ||
1271
 
           N->getOpcode() == ISD::TargetConstantPool;
1272
 
  }
1273
 
};
1274
 
 
1275
 
class BasicBlockSDNode : public SDNode {
1276
 
  MachineBasicBlock *MBB;
1277
 
  friend class SelectionDAG;
1278
 
  /// Debug info is meaningful and potentially useful here, but we create
1279
 
  /// blocks out of order when they're jumped to, which makes it a bit
1280
 
  /// harder.  Let's see if we need it first.
1281
 
  explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1282
 
    : SDNode(ISD::BasicBlock, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb) {
1283
 
  }
1284
 
public:
1285
 
 
1286
 
  MachineBasicBlock *getBasicBlock() const { return MBB; }
1287
 
 
1288
 
  static bool classof(const BasicBlockSDNode *) { return true; }
1289
 
  static bool classof(const SDNode *N) {
1290
 
    return N->getOpcode() == ISD::BasicBlock;
1291
 
  }
1292
 
};
1293
 
 
1294
 
/// BuildVectorSDNode - A "pseudo-class" with methods for operating on
1295
 
/// BUILD_VECTORs.
1296
 
class BuildVectorSDNode : public SDNode {
1297
 
  // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1298
 
  explicit BuildVectorSDNode();        // Do not implement
1299
 
public:
1300
 
  /// isConstantSplat - Check if this is a constant splat, and if so, find the
1301
 
  /// smallest element size that splats the vector.  If MinSplatBits is
1302
 
  /// nonzero, the element size must be at least that large.  Note that the
1303
 
  /// splat element may be the entire vector (i.e., a one element vector).
1304
 
  /// Returns the splat element value in SplatValue.  Any undefined bits in
1305
 
  /// that value are zero, and the corresponding bits in the SplatUndef mask
1306
 
  /// are set.  The SplatBitSize value is set to the splat element size in
1307
 
  /// bits.  HasAnyUndefs is set to true if any bits in the vector are
1308
 
  /// undefined.  isBigEndian describes the endianness of the target.
1309
 
  bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1310
 
                       unsigned &SplatBitSize, bool &HasAnyUndefs,
1311
 
                       unsigned MinSplatBits = 0, bool isBigEndian = false);
1312
 
 
1313
 
  static inline bool classof(const BuildVectorSDNode *) { return true; }
1314
 
  static inline bool classof(const SDNode *N) {
1315
 
    return N->getOpcode() == ISD::BUILD_VECTOR;
1316
 
  }
1317
 
};
1318
 
 
1319
 
/// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1320
 
/// used when the SelectionDAG needs to make a simple reference to something
1321
 
/// in the LLVM IR representation.
1322
 
///
1323
 
class SrcValueSDNode : public SDNode {
1324
 
  const Value *V;
1325
 
  friend class SelectionDAG;
1326
 
  /// Create a SrcValue for a general value.
1327
 
  explicit SrcValueSDNode(const Value *v)
1328
 
    : SDNode(ISD::SRCVALUE, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1329
 
 
1330
 
public:
1331
 
  /// getValue - return the contained Value.
1332
 
  const Value *getValue() const { return V; }
1333
 
 
1334
 
  static bool classof(const SrcValueSDNode *) { return true; }
1335
 
  static bool classof(const SDNode *N) {
1336
 
    return N->getOpcode() == ISD::SRCVALUE;
1337
 
  }
1338
 
};
1339
 
  
1340
 
class MDNodeSDNode : public SDNode {
1341
 
  const MDNode *MD;
1342
 
  friend class SelectionDAG;
1343
 
  explicit MDNodeSDNode(const MDNode *md)
1344
 
  : SDNode(ISD::MDNODE_SDNODE, DebugLoc(), getSDVTList(MVT::Other)), MD(md) {}
1345
 
public:
1346
 
  
1347
 
  const MDNode *getMD() const { return MD; }
1348
 
  
1349
 
  static bool classof(const MDNodeSDNode *) { return true; }
1350
 
  static bool classof(const SDNode *N) {
1351
 
    return N->getOpcode() == ISD::MDNODE_SDNODE;
1352
 
  }
1353
 
};
1354
 
 
1355
 
 
1356
 
class RegisterSDNode : public SDNode {
1357
 
  unsigned Reg;
1358
 
  friend class SelectionDAG;
1359
 
  RegisterSDNode(unsigned reg, EVT VT)
1360
 
    : SDNode(ISD::Register, DebugLoc(), getSDVTList(VT)), Reg(reg) {
1361
 
  }
1362
 
public:
1363
 
 
1364
 
  unsigned getReg() const { return Reg; }
1365
 
 
1366
 
  static bool classof(const RegisterSDNode *) { return true; }
1367
 
  static bool classof(const SDNode *N) {
1368
 
    return N->getOpcode() == ISD::Register;
1369
 
  }
1370
 
};
1371
 
 
1372
 
class BlockAddressSDNode : public SDNode {
1373
 
  const BlockAddress *BA;
1374
 
  unsigned char TargetFlags;
1375
 
  friend class SelectionDAG;
1376
 
  BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1377
 
                     unsigned char Flags)
1378
 
    : SDNode(NodeTy, DebugLoc(), getSDVTList(VT)),
1379
 
             BA(ba), TargetFlags(Flags) {
1380
 
  }
1381
 
public:
1382
 
  const BlockAddress *getBlockAddress() const { return BA; }
1383
 
  unsigned char getTargetFlags() const { return TargetFlags; }
1384
 
 
1385
 
  static bool classof(const BlockAddressSDNode *) { return true; }
1386
 
  static bool classof(const SDNode *N) {
1387
 
    return N->getOpcode() == ISD::BlockAddress ||
1388
 
           N->getOpcode() == ISD::TargetBlockAddress;
1389
 
  }
1390
 
};
1391
 
 
1392
 
class EHLabelSDNode : public SDNode {
1393
 
  SDUse Chain;
1394
 
  MCSymbol *Label;
1395
 
  friend class SelectionDAG;
1396
 
  EHLabelSDNode(DebugLoc dl, SDValue ch, MCSymbol *L)
1397
 
    : SDNode(ISD::EH_LABEL, dl, getSDVTList(MVT::Other)), Label(L) {
1398
 
    InitOperands(&Chain, ch);
1399
 
  }
1400
 
public:
1401
 
  MCSymbol *getLabel() const { return Label; }
1402
 
 
1403
 
  static bool classof(const EHLabelSDNode *) { return true; }
1404
 
  static bool classof(const SDNode *N) {
1405
 
    return N->getOpcode() == ISD::EH_LABEL;
1406
 
  }
1407
 
};
1408
 
 
1409
 
class ExternalSymbolSDNode : public SDNode {
1410
 
  const char *Symbol;
1411
 
  unsigned char TargetFlags;
1412
 
  
1413
 
  friend class SelectionDAG;
1414
 
  ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1415
 
    : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1416
 
             DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
1417
 
  }
1418
 
public:
1419
 
 
1420
 
  const char *getSymbol() const { return Symbol; }
1421
 
  unsigned char getTargetFlags() const { return TargetFlags; }
1422
 
 
1423
 
  static bool classof(const ExternalSymbolSDNode *) { return true; }
1424
 
  static bool classof(const SDNode *N) {
1425
 
    return N->getOpcode() == ISD::ExternalSymbol ||
1426
 
           N->getOpcode() == ISD::TargetExternalSymbol;
1427
 
  }
1428
 
};
1429
 
 
1430
 
class CondCodeSDNode : public SDNode {
1431
 
  ISD::CondCode Condition;
1432
 
  friend class SelectionDAG;
1433
 
  explicit CondCodeSDNode(ISD::CondCode Cond)
1434
 
    : SDNode(ISD::CONDCODE, DebugLoc(), getSDVTList(MVT::Other)),
1435
 
      Condition(Cond) {
1436
 
  }
1437
 
public:
1438
 
 
1439
 
  ISD::CondCode get() const { return Condition; }
1440
 
 
1441
 
  static bool classof(const CondCodeSDNode *) { return true; }
1442
 
  static bool classof(const SDNode *N) {
1443
 
    return N->getOpcode() == ISD::CONDCODE;
1444
 
  }
1445
 
};
1446
 
  
1447
 
/// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
1448
 
/// future and most targets don't support it.
1449
 
class CvtRndSatSDNode : public SDNode {
1450
 
  ISD::CvtCode CvtCode;
1451
 
  friend class SelectionDAG;
1452
 
  explicit CvtRndSatSDNode(EVT VT, DebugLoc dl, const SDValue *Ops,
1453
 
                           unsigned NumOps, ISD::CvtCode Code)
1454
 
    : SDNode(ISD::CONVERT_RNDSAT, dl, getSDVTList(VT), Ops, NumOps),
1455
 
      CvtCode(Code) {
1456
 
    assert(NumOps == 5 && "wrong number of operations");
1457
 
  }
1458
 
public:
1459
 
  ISD::CvtCode getCvtCode() const { return CvtCode; }
1460
 
 
1461
 
  static bool classof(const CvtRndSatSDNode *) { return true; }
1462
 
  static bool classof(const SDNode *N) {
1463
 
    return N->getOpcode() == ISD::CONVERT_RNDSAT;
1464
 
  }
1465
 
};
1466
 
 
1467
 
/// VTSDNode - This class is used to represent EVT's, which are used
1468
 
/// to parameterize some operations.
1469
 
class VTSDNode : public SDNode {
1470
 
  EVT ValueType;
1471
 
  friend class SelectionDAG;
1472
 
  explicit VTSDNode(EVT VT)
1473
 
    : SDNode(ISD::VALUETYPE, DebugLoc(), getSDVTList(MVT::Other)),
1474
 
      ValueType(VT) {
1475
 
  }
1476
 
public:
1477
 
 
1478
 
  EVT getVT() const { return ValueType; }
1479
 
 
1480
 
  static bool classof(const VTSDNode *) { return true; }
1481
 
  static bool classof(const SDNode *N) {
1482
 
    return N->getOpcode() == ISD::VALUETYPE;
1483
 
  }
1484
 
};
1485
 
 
1486
 
/// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1487
 
///
1488
 
class LSBaseSDNode : public MemSDNode {
1489
 
  //! Operand array for load and store
1490
 
  /*!
1491
 
    \note Moving this array to the base class captures more
1492
 
    common functionality shared between LoadSDNode and
1493
 
    StoreSDNode
1494
 
   */
1495
 
  SDUse Ops[4];
1496
 
public:
1497
 
  LSBaseSDNode(ISD::NodeType NodeTy, DebugLoc dl, SDValue *Operands,
1498
 
               unsigned numOperands, SDVTList VTs, ISD::MemIndexedMode AM,
1499
 
               EVT MemVT, MachineMemOperand *MMO)
1500
 
    : MemSDNode(NodeTy, dl, VTs, MemVT, MMO) {
1501
 
    SubclassData |= AM << 2;
1502
 
    assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
1503
 
    InitOperands(Ops, Operands, numOperands);
1504
 
    assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1505
 
           "Only indexed loads and stores have a non-undef offset operand");
1506
 
  }
1507
 
 
1508
 
  const SDValue &getOffset() const {
1509
 
    return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1510
 
  }
1511
 
 
1512
 
  /// getAddressingMode - Return the addressing mode for this load or store:
1513
 
  /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1514
 
  ISD::MemIndexedMode getAddressingMode() const {
1515
 
    return ISD::MemIndexedMode((SubclassData >> 2) & 7);
1516
 
  }
1517
 
 
1518
 
  /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1519
 
  bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1520
 
 
1521
 
  /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1522
 
  bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1523
 
 
1524
 
  static bool classof(const LSBaseSDNode *) { return true; }
1525
 
  static bool classof(const SDNode *N) {
1526
 
    return N->getOpcode() == ISD::LOAD ||
1527
 
           N->getOpcode() == ISD::STORE;
1528
 
  }
1529
 
};
1530
 
 
1531
 
/// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1532
 
///
1533
 
class LoadSDNode : public LSBaseSDNode {
1534
 
  friend class SelectionDAG;
1535
 
  LoadSDNode(SDValue *ChainPtrOff, DebugLoc dl, SDVTList VTs,
1536
 
             ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1537
 
             MachineMemOperand *MMO)
1538
 
    : LSBaseSDNode(ISD::LOAD, dl, ChainPtrOff, 3,
1539
 
                   VTs, AM, MemVT, MMO) {
1540
 
    SubclassData |= (unsigned short)ETy;
1541
 
    assert(getExtensionType() == ETy && "LoadExtType encoding error!");
1542
 
    assert(readMem() && "Load MachineMemOperand is not a load!");
1543
 
    assert(!writeMem() && "Load MachineMemOperand is a store!");
1544
 
  }
1545
 
public:
1546
 
 
1547
 
  /// getExtensionType - Return whether this is a plain node,
1548
 
  /// or one of the varieties of value-extending loads.
1549
 
  ISD::LoadExtType getExtensionType() const {
1550
 
    return ISD::LoadExtType(SubclassData & 3);
1551
 
  }
1552
 
 
1553
 
  const SDValue &getBasePtr() const { return getOperand(1); }
1554
 
  const SDValue &getOffset() const { return getOperand(2); }
1555
 
 
1556
 
  static bool classof(const LoadSDNode *) { return true; }
1557
 
  static bool classof(const SDNode *N) {
1558
 
    return N->getOpcode() == ISD::LOAD;
1559
 
  }
1560
 
};
1561
 
 
1562
 
/// StoreSDNode - This class is used to represent ISD::STORE nodes.
1563
 
///
1564
 
class StoreSDNode : public LSBaseSDNode {
1565
 
  friend class SelectionDAG;
1566
 
  StoreSDNode(SDValue *ChainValuePtrOff, DebugLoc dl, SDVTList VTs,
1567
 
              ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
1568
 
              MachineMemOperand *MMO)
1569
 
    : LSBaseSDNode(ISD::STORE, dl, ChainValuePtrOff, 4,
1570
 
                   VTs, AM, MemVT, MMO) {
1571
 
    SubclassData |= (unsigned short)isTrunc;
1572
 
    assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
1573
 
    assert(!readMem() && "Store MachineMemOperand is a load!");
1574
 
    assert(writeMem() && "Store MachineMemOperand is not a store!");
1575
 
  }
1576
 
public:
1577
 
 
1578
 
  /// isTruncatingStore - Return true if the op does a truncation before store.
1579
 
  /// For integers this is the same as doing a TRUNCATE and storing the result.
1580
 
  /// For floats, it is the same as doing an FP_ROUND and storing the result.
1581
 
  bool isTruncatingStore() const { return SubclassData & 1; }
1582
 
 
1583
 
  const SDValue &getValue() const { return getOperand(1); }
1584
 
  const SDValue &getBasePtr() const { return getOperand(2); }
1585
 
  const SDValue &getOffset() const { return getOperand(3); }
1586
 
 
1587
 
  static bool classof(const StoreSDNode *) { return true; }
1588
 
  static bool classof(const SDNode *N) {
1589
 
    return N->getOpcode() == ISD::STORE;
1590
 
  }
1591
 
};
1592
 
 
1593
 
/// MachineSDNode - An SDNode that represents everything that will be needed
1594
 
/// to construct a MachineInstr. These nodes are created during the
1595
 
/// instruction selection proper phase.
1596
 
///
1597
 
class MachineSDNode : public SDNode {
1598
 
public:
1599
 
  typedef MachineMemOperand **mmo_iterator;
1600
 
 
1601
 
private:
1602
 
  friend class SelectionDAG;
1603
 
  MachineSDNode(unsigned Opc, const DebugLoc DL, SDVTList VTs)
1604
 
    : SDNode(Opc, DL, VTs), MemRefs(0), MemRefsEnd(0) {}
1605
 
 
1606
 
  /// LocalOperands - Operands for this instruction, if they fit here. If
1607
 
  /// they don't, this field is unused.
1608
 
  SDUse LocalOperands[4];
1609
 
 
1610
 
  /// MemRefs - Memory reference descriptions for this instruction.
1611
 
  mmo_iterator MemRefs;
1612
 
  mmo_iterator MemRefsEnd;
1613
 
 
1614
 
public:
1615
 
  mmo_iterator memoperands_begin() const { return MemRefs; }
1616
 
  mmo_iterator memoperands_end() const { return MemRefsEnd; }
1617
 
  bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
1618
 
 
1619
 
  /// setMemRefs - Assign this MachineSDNodes's memory reference descriptor
1620
 
  /// list. This does not transfer ownership.
1621
 
  void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
1622
 
    MemRefs = NewMemRefs;
1623
 
    MemRefsEnd = NewMemRefsEnd;
1624
 
  }
1625
 
 
1626
 
  static bool classof(const MachineSDNode *) { return true; }
1627
 
  static bool classof(const SDNode *N) {
1628
 
    return N->isMachineOpcode();
1629
 
  }
1630
 
};
1631
 
 
1632
 
class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
1633
 
                                            SDNode, ptrdiff_t> {
1634
 
  SDNode *Node;
1635
 
  unsigned Operand;
1636
 
 
1637
 
  SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1638
 
public:
1639
 
  bool operator==(const SDNodeIterator& x) const {
1640
 
    return Operand == x.Operand;
1641
 
  }
1642
 
  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1643
 
 
1644
 
  const SDNodeIterator &operator=(const SDNodeIterator &I) {
1645
 
    assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1646
 
    Operand = I.Operand;
1647
 
    return *this;
1648
 
  }
1649
 
 
1650
 
  pointer operator*() const {
1651
 
    return Node->getOperand(Operand).getNode();
1652
 
  }
1653
 
  pointer operator->() const { return operator*(); }
1654
 
 
1655
 
  SDNodeIterator& operator++() {                // Preincrement
1656
 
    ++Operand;
1657
 
    return *this;
1658
 
  }
1659
 
  SDNodeIterator operator++(int) { // Postincrement
1660
 
    SDNodeIterator tmp = *this; ++*this; return tmp;
1661
 
  }
1662
 
  size_t operator-(SDNodeIterator Other) const {
1663
 
    assert(Node == Other.Node &&
1664
 
           "Cannot compare iterators of two different nodes!");
1665
 
    return Operand - Other.Operand;
1666
 
  }
1667
 
 
1668
 
  static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1669
 
  static SDNodeIterator end  (SDNode *N) {
1670
 
    return SDNodeIterator(N, N->getNumOperands());
1671
 
  }
1672
 
 
1673
 
  unsigned getOperand() const { return Operand; }
1674
 
  const SDNode *getNode() const { return Node; }
1675
 
};
1676
 
 
1677
 
template <> struct GraphTraits<SDNode*> {
1678
 
  typedef SDNode NodeType;
1679
 
  typedef SDNodeIterator ChildIteratorType;
1680
 
  static inline NodeType *getEntryNode(SDNode *N) { return N; }
1681
 
  static inline ChildIteratorType child_begin(NodeType *N) {
1682
 
    return SDNodeIterator::begin(N);
1683
 
  }
1684
 
  static inline ChildIteratorType child_end(NodeType *N) {
1685
 
    return SDNodeIterator::end(N);
1686
 
  }
1687
 
};
1688
 
 
1689
 
/// LargestSDNode - The largest SDNode class.
1690
 
///
1691
 
typedef LoadSDNode LargestSDNode;
1692
 
 
1693
 
/// MostAlignedSDNode - The SDNode class with the greatest alignment
1694
 
/// requirement.
1695
 
///
1696
 
typedef GlobalAddressSDNode MostAlignedSDNode;
1697
 
 
1698
 
namespace ISD {
1699
 
  /// isNormalLoad - Returns true if the specified node is a non-extending
1700
 
  /// and unindexed load.
1701
 
  inline bool isNormalLoad(const SDNode *N) {
1702
 
    const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
1703
 
    return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
1704
 
      Ld->getAddressingMode() == ISD::UNINDEXED;
1705
 
  }
1706
 
 
1707
 
  /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1708
 
  /// load.
1709
 
  inline bool isNON_EXTLoad(const SDNode *N) {
1710
 
    return isa<LoadSDNode>(N) &&
1711
 
      cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1712
 
  }
1713
 
 
1714
 
  /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1715
 
  ///
1716
 
  inline bool isEXTLoad(const SDNode *N) {
1717
 
    return isa<LoadSDNode>(N) &&
1718
 
      cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1719
 
  }
1720
 
 
1721
 
  /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1722
 
  ///
1723
 
  inline bool isSEXTLoad(const SDNode *N) {
1724
 
    return isa<LoadSDNode>(N) &&
1725
 
      cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1726
 
  }
1727
 
 
1728
 
  /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1729
 
  ///
1730
 
  inline bool isZEXTLoad(const SDNode *N) {
1731
 
    return isa<LoadSDNode>(N) &&
1732
 
      cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1733
 
  }
1734
 
 
1735
 
  /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
1736
 
  ///
1737
 
  inline bool isUNINDEXEDLoad(const SDNode *N) {
1738
 
    return isa<LoadSDNode>(N) &&
1739
 
      cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1740
 
  }
1741
 
 
1742
 
  /// isNormalStore - Returns true if the specified node is a non-truncating
1743
 
  /// and unindexed store.
1744
 
  inline bool isNormalStore(const SDNode *N) {
1745
 
    const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
1746
 
    return St && !St->isTruncatingStore() &&
1747
 
      St->getAddressingMode() == ISD::UNINDEXED;
1748
 
  }
1749
 
 
1750
 
  /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1751
 
  /// store.
1752
 
  inline bool isNON_TRUNCStore(const SDNode *N) {
1753
 
    return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
1754
 
  }
1755
 
 
1756
 
  /// isTRUNCStore - Returns true if the specified node is a truncating
1757
 
  /// store.
1758
 
  inline bool isTRUNCStore(const SDNode *N) {
1759
 
    return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
1760
 
  }
1761
 
 
1762
 
  /// isUNINDEXEDStore - Returns true if the specified node is an
1763
 
  /// unindexed store.
1764
 
  inline bool isUNINDEXEDStore(const SDNode *N) {
1765
 
    return isa<StoreSDNode>(N) &&
1766
 
      cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1767
 
  }
1768
 
}
1769
 
 
1770
 
} // end llvm namespace
1771
 
 
1772
 
#endif