~ubuntu-branches/ubuntu/wily/clamav/wily-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Sebastian Andrzej Siewior, Andreas Cadhalpun, Scott Kitterman, Javier Fernández-Sanguino
  • Date: 2015-01-28 00:25:13 UTC
  • mfrom: (0.48.14 sid)
  • Revision ID: package-import@ubuntu.com-20150128002513-lil2oi74cooy4lzr
Tags: 0.98.6+dfsg-1
[ Sebastian Andrzej Siewior ]
* update "fix-ssize_t-size_t-off_t-printf-modifier", include of misc.h was
  missing but was pulled in via the systemd patch.
* Don't leak return codes from libmspack to clamav API. (Closes: #774686).

[ Andreas Cadhalpun ]
* Add patch to avoid emitting incremental progress messages when not
  outputting to a terminal. (Closes: #767350)
* Update lintian-overrides for unused-file-paragraph-in-dep5-copyright.
* clamav-base.postinst: always chown /var/log/clamav and /var/lib/clamav
  to clamav:clamav, not only on fresh installations. (Closes: #775400)
* Adapt the clamav-daemon and clamav-freshclam logrotate scripts,
  so that they correctly work under systemd.
* Move the PidFile variable from the clamd/freshclam configuration files
  to the init scripts. This makes the init scripts more robust against
  misconfiguration and avoids error messages with systemd. (Closes: #767353)
* debian/copyright: drop files from Files-Excluded only present in github
  tarballs
* Drop Workaround-a-bug-in-libc-on-Hurd.patch, because hurd got fixed.
  (see #752237)
* debian/rules: Remove useless --with-system-tommath --without-included-ltdl
  configure options.

[ Scott Kitterman ]
* Stop stripping llvm when repacking the tarball as the system llvm on some
  releases is too old to use
* New upstream bugfix release
  - Library shared object revisions.
  - Includes a patch from Sebastian Andrzej Siewior making ClamAV pid files
    compatible with systemd.
  - Fix a heap out of bounds condition with crafted Yoda's crypter files.
    This issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted mew packer files. This
    issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted upx packer files. This
    issue was discovered by Kevin Szkudlapski of Quarkslab.
  - Fix a heap out of bounds condition with crafted upack packer files. This
    issue was discovered by Sebastian Andrzej Siewior. CVE-2014-9328.
  - Compensate a crash due to incorrect compiler optimization when handling
    crafted petite packer files. This issue was discovered by Sebastian
    Andrzej Siewior.
* Update lintian override for embedded zlib to match new so version

[ Javier Fernández-Sanguino ]
* Updated Spanish Debconf template translation (Closes: #773563)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===-- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ---------*- 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 SelectionDAG class, and transitively defines the
 
11
// SDNode class and subclasses.
 
12
//
 
13
//===----------------------------------------------------------------------===//
 
14
 
 
15
#ifndef LLVM_CODEGEN_SELECTIONDAG_H
 
16
#define LLVM_CODEGEN_SELECTIONDAG_H
 
17
 
 
18
#include "llvm/ADT/ilist.h"
 
19
#include "llvm/ADT/DenseSet.h"
 
20
#include "llvm/ADT/StringMap.h"
 
21
#include "llvm/CodeGen/SelectionDAGNodes.h"
 
22
#include "llvm/Support/RecyclingAllocator.h"
 
23
#include "llvm/Target/TargetMachine.h"
 
24
#include <cassert>
 
25
#include <vector>
 
26
#include <map>
 
27
#include <string>
 
28
 
 
29
namespace llvm {
 
30
 
 
31
class AliasAnalysis;
 
32
class MachineConstantPoolValue;
 
33
class MachineFunction;
 
34
class MDNode;
 
35
class SDNodeOrdering;
 
36
class SDDbgValue;
 
37
class TargetLowering;
 
38
class TargetSelectionDAGInfo;
 
39
 
 
40
template<> struct ilist_traits<SDNode> : public ilist_default_traits<SDNode> {
 
41
private:
 
42
  mutable ilist_half_node<SDNode> Sentinel;
 
43
public:
 
44
  SDNode *createSentinel() const {
 
45
    return static_cast<SDNode*>(&Sentinel);
 
46
  }
 
47
  static void destroySentinel(SDNode *) {}
 
48
 
 
49
  SDNode *provideInitialHead() const { return createSentinel(); }
 
50
  SDNode *ensureHead(SDNode*) const { return createSentinel(); }
 
51
  static void noteHead(SDNode*, SDNode*) {}
 
52
 
 
53
  static void deleteNode(SDNode *) {
 
54
    assert(0 && "ilist_traits<SDNode> shouldn't see a deleteNode call!");
 
55
  }
 
56
private:
 
57
  static void createNode(const SDNode &);
 
58
};
 
59
 
 
60
/// SDDbgInfo - Keeps track of dbg_value information through SDISel.  We do
 
61
/// not build SDNodes for these so as not to perturb the generated code;
 
62
/// instead the info is kept off to the side in this structure. Each SDNode may
 
63
/// have one or more associated dbg_value entries. This information is kept in
 
64
/// DbgValMap.
 
65
/// Byval parameters are handled separately because they don't use alloca's,
 
66
/// which busts the normal mechanism.  There is good reason for handling all
 
67
/// parameters separately:  they may not have code generated for them, they
 
68
/// should always go at the beginning of the function regardless of other code
 
69
/// motion, and debug info for them is potentially useful even if the parameter
 
70
/// is unused.  Right now only byval parameters are handled separately.
 
71
class SDDbgInfo {
 
72
  SmallVector<SDDbgValue*, 32> DbgValues;
 
73
  SmallVector<SDDbgValue*, 32> ByvalParmDbgValues;
 
74
  DenseMap<const SDNode*, SmallVector<SDDbgValue*, 2> > DbgValMap;
 
75
 
 
76
  void operator=(const SDDbgInfo&);   // Do not implement.
 
77
  SDDbgInfo(const SDDbgInfo&);   // Do not implement.
 
78
public:
 
79
  SDDbgInfo() {}
 
80
 
 
81
  void add(SDDbgValue *V, const SDNode *Node, bool isParameter) {
 
82
    if (isParameter) {
 
83
      ByvalParmDbgValues.push_back(V);
 
84
    } else     DbgValues.push_back(V);
 
85
    if (Node)
 
86
      DbgValMap[Node].push_back(V);
 
87
  }
 
88
 
 
89
  void clear() {
 
90
    DbgValMap.clear();
 
91
    DbgValues.clear();
 
92
    ByvalParmDbgValues.clear();
 
93
  }
 
94
 
 
95
  bool empty() const {
 
96
    return DbgValues.empty() && ByvalParmDbgValues.empty();
 
97
  }
 
98
 
 
99
  SmallVector<SDDbgValue*,2> &getSDDbgValues(const SDNode *Node) {
 
100
    return DbgValMap[Node];
 
101
  }
 
102
 
 
103
  typedef SmallVector<SDDbgValue*,32>::iterator DbgIterator;
 
104
  DbgIterator DbgBegin() { return DbgValues.begin(); }
 
105
  DbgIterator DbgEnd()   { return DbgValues.end(); }
 
106
  DbgIterator ByvalParmDbgBegin() { return ByvalParmDbgValues.begin(); }
 
107
  DbgIterator ByvalParmDbgEnd()   { return ByvalParmDbgValues.end(); }
 
108
};
 
109
 
 
110
enum CombineLevel {
 
111
  Unrestricted,   // Combine may create illegal operations and illegal types.
 
112
  NoIllegalTypes, // Combine may create illegal operations but no illegal types.
 
113
  NoIllegalOperations // Combine may only create legal operations and types.
 
114
};
 
115
 
 
116
class SelectionDAG;
 
117
void checkForCycles(const SDNode *N);
 
118
void checkForCycles(const SelectionDAG *DAG);
 
119
 
 
120
/// SelectionDAG class - This is used to represent a portion of an LLVM function
 
121
/// in a low-level Data Dependence DAG representation suitable for instruction
 
122
/// selection.  This DAG is constructed as the first step of instruction
 
123
/// selection in order to allow implementation of machine specific optimizations
 
124
/// and code simplifications.
 
125
///
 
126
/// The representation used by the SelectionDAG is a target-independent
 
127
/// representation, which has some similarities to the GCC RTL representation,
 
128
/// but is significantly more simple, powerful, and is a graph form instead of a
 
129
/// linear form.
 
130
///
 
131
class SelectionDAG {
 
132
  const TargetMachine &TM;
 
133
  const TargetLowering &TLI;
 
134
  const TargetSelectionDAGInfo &TSI;
 
135
  MachineFunction *MF;
 
136
  LLVMContext *Context;
 
137
 
 
138
  /// EntryNode - The starting token.
 
139
  SDNode EntryNode;
 
140
 
 
141
  /// Root - The root of the entire DAG.
 
142
  SDValue Root;
 
143
 
 
144
  /// AllNodes - A linked list of nodes in the current DAG.
 
145
  ilist<SDNode> AllNodes;
 
146
 
 
147
  /// NodeAllocatorType - The AllocatorType for allocating SDNodes. We use
 
148
  /// pool allocation with recycling.
 
149
  typedef RecyclingAllocator<BumpPtrAllocator, SDNode, sizeof(LargestSDNode),
 
150
                             AlignOf<MostAlignedSDNode>::Alignment>
 
151
    NodeAllocatorType;
 
152
 
 
153
  /// NodeAllocator - Pool allocation for nodes.
 
154
  NodeAllocatorType NodeAllocator;
 
155
 
 
156
  /// CSEMap - This structure is used to memoize nodes, automatically performing
 
157
  /// CSE with existing nodes when a duplicate is requested.
 
158
  FoldingSet<SDNode> CSEMap;
 
159
 
 
160
  /// OperandAllocator - Pool allocation for machine-opcode SDNode operands.
 
161
  BumpPtrAllocator OperandAllocator;
 
162
 
 
163
  /// Allocator - Pool allocation for misc. objects that are created once per
 
164
  /// SelectionDAG.
 
165
  BumpPtrAllocator Allocator;
 
166
 
 
167
  /// SDNodeOrdering - The ordering of the SDNodes. It roughly corresponds to
 
168
  /// the ordering of the original LLVM instructions.
 
169
  SDNodeOrdering *Ordering;
 
170
 
 
171
  /// DbgInfo - Tracks dbg_value information through SDISel.
 
172
  SDDbgInfo *DbgInfo;
 
173
 
 
174
  /// setGraphColorHelper - Implementation of setSubgraphColor.
 
175
  /// Return whether we had to truncate the search.
 
176
  ///
 
177
  bool setSubgraphColorHelper(SDNode *N, const char *Color,
 
178
                              DenseSet<SDNode *> &visited,
 
179
                              int level, bool &printed);
 
180
 
 
181
  void operator=(const SelectionDAG&); // Do not implement.
 
182
  SelectionDAG(const SelectionDAG&);   // Do not implement.
 
183
 
 
184
public:
 
185
  explicit SelectionDAG(const TargetMachine &TM);
 
186
  ~SelectionDAG();
 
187
 
 
188
  /// init - Prepare this SelectionDAG to process code in the given
 
189
  /// MachineFunction.
 
190
  ///
 
191
  void init(MachineFunction &mf);
 
192
 
 
193
  /// clear - Clear state and free memory necessary to make this
 
194
  /// SelectionDAG ready to process a new block.
 
195
  ///
 
196
  void clear();
 
197
 
 
198
  MachineFunction &getMachineFunction() const { return *MF; }
 
199
  const TargetMachine &getTarget() const { return TM; }
 
200
  const TargetLowering &getTargetLoweringInfo() const { return TLI; }
 
201
  const TargetSelectionDAGInfo &getSelectionDAGInfo() const { return TSI; }
 
202
  LLVMContext *getContext() const {return Context; }
 
203
 
 
204
  /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
 
205
  ///
 
206
  void viewGraph(const std::string &Title);
 
207
  void viewGraph();
 
208
 
 
209
#ifndef NDEBUG
 
210
  std::map<const SDNode *, std::string> NodeGraphAttrs;
 
211
#endif
 
212
 
 
213
  /// clearGraphAttrs - Clear all previously defined node graph attributes.
 
214
  /// Intended to be used from a debugging tool (eg. gdb).
 
215
  void clearGraphAttrs();
 
216
 
 
217
  /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
 
218
  ///
 
219
  void setGraphAttrs(const SDNode *N, const char *Attrs);
 
220
 
 
221
  /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
 
222
  /// Used from getNodeAttributes.
 
223
  const std::string getGraphAttrs(const SDNode *N) const;
 
224
 
 
225
  /// setGraphColor - Convenience for setting node color attribute.
 
226
  ///
 
227
  void setGraphColor(const SDNode *N, const char *Color);
 
228
 
 
229
  /// setGraphColor - Convenience for setting subgraph color attribute.
 
230
  ///
 
231
  void setSubgraphColor(SDNode *N, const char *Color);
 
232
 
 
233
  typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
 
234
  allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
 
235
  allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
 
236
  typedef ilist<SDNode>::iterator allnodes_iterator;
 
237
  allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
 
238
  allnodes_iterator allnodes_end() { return AllNodes.end(); }
 
239
  ilist<SDNode>::size_type allnodes_size() const {
 
240
    return AllNodes.size();
 
241
  }
 
242
 
 
243
  /// getRoot - Return the root tag of the SelectionDAG.
 
244
  ///
 
245
  const SDValue &getRoot() const { return Root; }
 
246
 
 
247
  /// getEntryNode - Return the token chain corresponding to the entry of the
 
248
  /// function.
 
249
  SDValue getEntryNode() const {
 
250
    return SDValue(const_cast<SDNode *>(&EntryNode), 0);
 
251
  }
 
252
 
 
253
  /// setRoot - Set the current root tag of the SelectionDAG.
 
254
  ///
 
255
  const SDValue &setRoot(SDValue N) {
 
256
    assert((!N.getNode() || N.getValueType() == MVT::Other) &&
 
257
           "DAG root value is not a chain!");
 
258
    if (N.getNode())
 
259
      checkForCycles(N.getNode());
 
260
    Root = N;
 
261
    if (N.getNode())
 
262
      checkForCycles(this);
 
263
    return Root;
 
264
  }
 
265
 
 
266
  /// Combine - This iterates over the nodes in the SelectionDAG, folding
 
267
  /// certain types of nodes together, or eliminating superfluous nodes.  The
 
268
  /// Level argument controls whether Combine is allowed to produce nodes and
 
269
  /// types that are illegal on the target.
 
270
  void Combine(CombineLevel Level, AliasAnalysis &AA,
 
271
               CodeGenOpt::Level OptLevel);
 
272
 
 
273
  /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that
 
274
  /// only uses types natively supported by the target.  Returns "true" if it
 
275
  /// made any changes.
 
276
  ///
 
277
  /// Note that this is an involved process that may invalidate pointers into
 
278
  /// the graph.
 
279
  bool LegalizeTypes();
 
280
 
 
281
  /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
 
282
  /// compatible with the target instruction selector, as indicated by the
 
283
  /// TargetLowering object.
 
284
  ///
 
285
  /// Note that this is an involved process that may invalidate pointers into
 
286
  /// the graph.
 
287
  void Legalize(CodeGenOpt::Level OptLevel);
 
288
 
 
289
  /// LegalizeVectors - This transforms the SelectionDAG into a SelectionDAG
 
290
  /// that only uses vector math operations supported by the target.  This is
 
291
  /// necessary as a separate step from Legalize because unrolling a vector
 
292
  /// operation can introduce illegal types, which requires running
 
293
  /// LegalizeTypes again.
 
294
  ///
 
295
  /// This returns true if it made any changes; in that case, LegalizeTypes
 
296
  /// is called again before Legalize.
 
297
  ///
 
298
  /// Note that this is an involved process that may invalidate pointers into
 
299
  /// the graph.
 
300
  bool LegalizeVectors();
 
301
 
 
302
  /// RemoveDeadNodes - This method deletes all unreachable nodes in the
 
303
  /// SelectionDAG.
 
304
  void RemoveDeadNodes();
 
305
 
 
306
  /// DeleteNode - Remove the specified node from the system.  This node must
 
307
  /// have no referrers.
 
308
  void DeleteNode(SDNode *N);
 
309
 
 
310
  /// getVTList - Return an SDVTList that represents the list of values
 
311
  /// specified.
 
312
  SDVTList getVTList(EVT VT);
 
313
  SDVTList getVTList(EVT VT1, EVT VT2);
 
314
  SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3);
 
315
  SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3, EVT VT4);
 
316
  SDVTList getVTList(const EVT *VTs, unsigned NumVTs);
 
317
 
 
318
  //===--------------------------------------------------------------------===//
 
319
  // Node creation methods.
 
320
  //
 
321
  SDValue getConstant(uint64_t Val, EVT VT, bool isTarget = false);
 
322
  SDValue getConstant(const APInt &Val, EVT VT, bool isTarget = false);
 
323
  SDValue getConstant(const ConstantInt &Val, EVT VT, bool isTarget = false);
 
324
  SDValue getIntPtrConstant(uint64_t Val, bool isTarget = false);
 
325
  SDValue getTargetConstant(uint64_t Val, EVT VT) {
 
326
    return getConstant(Val, VT, true);
 
327
  }
 
328
  SDValue getTargetConstant(const APInt &Val, EVT VT) {
 
329
    return getConstant(Val, VT, true);
 
330
  }
 
331
  SDValue getTargetConstant(const ConstantInt &Val, EVT VT) {
 
332
    return getConstant(Val, VT, true);
 
333
  }
 
334
  // The forms below that take a double should only be used for simple
 
335
  // constants that can be exactly represented in VT.  No checks are made.
 
336
  SDValue getConstantFP(double Val, EVT VT, bool isTarget = false);
 
337
  SDValue getConstantFP(const APFloat& Val, EVT VT, bool isTarget = false);
 
338
  SDValue getConstantFP(const ConstantFP &CF, EVT VT, bool isTarget = false);
 
339
  SDValue getTargetConstantFP(double Val, EVT VT) {
 
340
    return getConstantFP(Val, VT, true);
 
341
  }
 
342
  SDValue getTargetConstantFP(const APFloat& Val, EVT VT) {
 
343
    return getConstantFP(Val, VT, true);
 
344
  }
 
345
  SDValue getTargetConstantFP(const ConstantFP &Val, EVT VT) {
 
346
    return getConstantFP(Val, VT, true);
 
347
  }
 
348
  SDValue getGlobalAddress(const GlobalValue *GV, DebugLoc DL, EVT VT,
 
349
                           int64_t offset = 0, bool isTargetGA = false,
 
350
                           unsigned char TargetFlags = 0);
 
351
  SDValue getTargetGlobalAddress(const GlobalValue *GV, DebugLoc DL, EVT VT,
 
352
                                 int64_t offset = 0,
 
353
                                 unsigned char TargetFlags = 0) {
 
354
    return getGlobalAddress(GV, DL, VT, offset, true, TargetFlags);
 
355
  }
 
356
  SDValue getFrameIndex(int FI, EVT VT, bool isTarget = false);
 
357
  SDValue getTargetFrameIndex(int FI, EVT VT) {
 
358
    return getFrameIndex(FI, VT, true);
 
359
  }
 
360
  SDValue getJumpTable(int JTI, EVT VT, bool isTarget = false,
 
361
                       unsigned char TargetFlags = 0);
 
362
  SDValue getTargetJumpTable(int JTI, EVT VT, unsigned char TargetFlags = 0) {
 
363
    return getJumpTable(JTI, VT, true, TargetFlags);
 
364
  }
 
365
  SDValue getConstantPool(const Constant *C, EVT VT,
 
366
                          unsigned Align = 0, int Offs = 0, bool isT=false,
 
367
                          unsigned char TargetFlags = 0);
 
368
  SDValue getTargetConstantPool(const Constant *C, EVT VT,
 
369
                                unsigned Align = 0, int Offset = 0,
 
370
                                unsigned char TargetFlags = 0) {
 
371
    return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
 
372
  }
 
373
  SDValue getConstantPool(MachineConstantPoolValue *C, EVT VT,
 
374
                          unsigned Align = 0, int Offs = 0, bool isT=false,
 
375
                          unsigned char TargetFlags = 0);
 
376
  SDValue getTargetConstantPool(MachineConstantPoolValue *C,
 
377
                                  EVT VT, unsigned Align = 0,
 
378
                                  int Offset = 0, unsigned char TargetFlags=0) {
 
379
    return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
 
380
  }
 
381
  // When generating a branch to a BB, we don't in general know enough
 
382
  // to provide debug info for the BB at that time, so keep this one around.
 
383
  SDValue getBasicBlock(MachineBasicBlock *MBB);
 
384
  SDValue getBasicBlock(MachineBasicBlock *MBB, DebugLoc dl);
 
385
  SDValue getExternalSymbol(const char *Sym, EVT VT);
 
386
  SDValue getExternalSymbol(const char *Sym, DebugLoc dl, EVT VT);
 
387
  SDValue getTargetExternalSymbol(const char *Sym, EVT VT,
 
388
                                  unsigned char TargetFlags = 0);
 
389
  SDValue getValueType(EVT);
 
390
  SDValue getRegister(unsigned Reg, EVT VT);
 
391
  SDValue getEHLabel(DebugLoc dl, SDValue Root, MCSymbol *Label);
 
392
  SDValue getBlockAddress(const BlockAddress *BA, EVT VT,
 
393
                          bool isTarget = false, unsigned char TargetFlags = 0);
 
394
 
 
395
  SDValue getCopyToReg(SDValue Chain, DebugLoc dl, unsigned Reg, SDValue N) {
 
396
    return getNode(ISD::CopyToReg, dl, MVT::Other, Chain,
 
397
                   getRegister(Reg, N.getValueType()), N);
 
398
  }
 
399
 
 
400
  // This version of the getCopyToReg method takes an extra operand, which
 
401
  // indicates that there is potentially an incoming flag value (if Flag is not
 
402
  // null) and that there should be a flag result.
 
403
  SDValue getCopyToReg(SDValue Chain, DebugLoc dl, unsigned Reg, SDValue N,
 
404
                       SDValue Flag) {
 
405
    SDVTList VTs = getVTList(MVT::Other, MVT::Flag);
 
406
    SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag };
 
407
    return getNode(ISD::CopyToReg, dl, VTs, Ops, Flag.getNode() ? 4 : 3);
 
408
  }
 
409
 
 
410
  // Similar to last getCopyToReg() except parameter Reg is a SDValue
 
411
  SDValue getCopyToReg(SDValue Chain, DebugLoc dl, SDValue Reg, SDValue N,
 
412
                         SDValue Flag) {
 
413
    SDVTList VTs = getVTList(MVT::Other, MVT::Flag);
 
414
    SDValue Ops[] = { Chain, Reg, N, Flag };
 
415
    return getNode(ISD::CopyToReg, dl, VTs, Ops, Flag.getNode() ? 4 : 3);
 
416
  }
 
417
 
 
418
  SDValue getCopyFromReg(SDValue Chain, DebugLoc dl, unsigned Reg, EVT VT) {
 
419
    SDVTList VTs = getVTList(VT, MVT::Other);
 
420
    SDValue Ops[] = { Chain, getRegister(Reg, VT) };
 
421
    return getNode(ISD::CopyFromReg, dl, VTs, Ops, 2);
 
422
  }
 
423
 
 
424
  // This version of the getCopyFromReg method takes an extra operand, which
 
425
  // indicates that there is potentially an incoming flag value (if Flag is not
 
426
  // null) and that there should be a flag result.
 
427
  SDValue getCopyFromReg(SDValue Chain, DebugLoc dl, unsigned Reg, EVT VT,
 
428
                           SDValue Flag) {
 
429
    SDVTList VTs = getVTList(VT, MVT::Other, MVT::Flag);
 
430
    SDValue Ops[] = { Chain, getRegister(Reg, VT), Flag };
 
431
    return getNode(ISD::CopyFromReg, dl, VTs, Ops, Flag.getNode() ? 3 : 2);
 
432
  }
 
433
 
 
434
  SDValue getCondCode(ISD::CondCode Cond);
 
435
 
 
436
  /// Returns the ConvertRndSat Note: Avoid using this node because it may
 
437
  /// disappear in the future and most targets don't support it.
 
438
  SDValue getConvertRndSat(EVT VT, DebugLoc dl, SDValue Val, SDValue DTy,
 
439
                           SDValue STy,
 
440
                           SDValue Rnd, SDValue Sat, ISD::CvtCode Code);
 
441
  
 
442
  /// getVectorShuffle - Return an ISD::VECTOR_SHUFFLE node.  The number of
 
443
  /// elements in VT, which must be a vector type, must match the number of
 
444
  /// mask elements NumElts.  A integer mask element equal to -1 is treated as
 
445
  /// undefined.
 
446
  SDValue getVectorShuffle(EVT VT, DebugLoc dl, SDValue N1, SDValue N2, 
 
447
                           const int *MaskElts);
 
448
 
 
449
  /// getSExtOrTrunc - Convert Op, which must be of integer type, to the
 
450
  /// integer type VT, by either sign-extending or truncating it.
 
451
  SDValue getSExtOrTrunc(SDValue Op, DebugLoc DL, EVT VT);
 
452
 
 
453
  /// getZExtOrTrunc - Convert Op, which must be of integer type, to the
 
454
  /// integer type VT, by either zero-extending or truncating it.
 
455
  SDValue getZExtOrTrunc(SDValue Op, DebugLoc DL, EVT VT);
 
456
 
 
457
  /// getZeroExtendInReg - Return the expression required to zero extend the Op
 
458
  /// value assuming it was the smaller SrcTy value.
 
459
  SDValue getZeroExtendInReg(SDValue Op, DebugLoc DL, EVT SrcTy);
 
460
 
 
461
  /// getNOT - Create a bitwise NOT operation as (XOR Val, -1).
 
462
  SDValue getNOT(DebugLoc DL, SDValue Val, EVT VT);
 
463
 
 
464
  /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have
 
465
  /// a flag result (to ensure it's not CSE'd).  CALLSEQ_START does not have a
 
466
  /// useful DebugLoc.
 
467
  SDValue getCALLSEQ_START(SDValue Chain, SDValue Op) {
 
468
    SDVTList VTs = getVTList(MVT::Other, MVT::Flag);
 
469
    SDValue Ops[] = { Chain,  Op };
 
470
    return getNode(ISD::CALLSEQ_START, DebugLoc(), VTs, Ops, 2);
 
471
  }
 
472
 
 
473
  /// getCALLSEQ_END - Return a new CALLSEQ_END node, which always must have a
 
474
  /// flag result (to ensure it's not CSE'd).  CALLSEQ_END does not have
 
475
  /// a useful DebugLoc.
 
476
  SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2,
 
477
                           SDValue InFlag) {
 
478
    SDVTList NodeTys = getVTList(MVT::Other, MVT::Flag);
 
479
    SmallVector<SDValue, 4> Ops;
 
480
    Ops.push_back(Chain);
 
481
    Ops.push_back(Op1);
 
482
    Ops.push_back(Op2);
 
483
    Ops.push_back(InFlag);
 
484
    return getNode(ISD::CALLSEQ_END, DebugLoc(), NodeTys, &Ops[0],
 
485
                   (unsigned)Ops.size() - (InFlag.getNode() == 0 ? 1 : 0));
 
486
  }
 
487
 
 
488
  /// getUNDEF - Return an UNDEF node.  UNDEF does not have a useful DebugLoc.
 
489
  SDValue getUNDEF(EVT VT) {
 
490
    return getNode(ISD::UNDEF, DebugLoc(), VT);
 
491
  }
 
492
 
 
493
  /// getGLOBAL_OFFSET_TABLE - Return a GLOBAL_OFFSET_TABLE node.  This does
 
494
  /// not have a useful DebugLoc.
 
495
  SDValue getGLOBAL_OFFSET_TABLE(EVT VT) {
 
496
    return getNode(ISD::GLOBAL_OFFSET_TABLE, DebugLoc(), VT);
 
497
  }
 
498
 
 
499
  /// getNode - Gets or creates the specified node.
 
500
  ///
 
501
  SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT);
 
502
  SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT, SDValue N);
 
503
  SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT, SDValue N1, SDValue N2);
 
504
  SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT,
 
505
                  SDValue N1, SDValue N2, SDValue N3);
 
506
  SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT,
 
507
                  SDValue N1, SDValue N2, SDValue N3, SDValue N4);
 
508
  SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT,
 
509
                  SDValue N1, SDValue N2, SDValue N3, SDValue N4,
 
510
                  SDValue N5);
 
511
  SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT,
 
512
                  const SDUse *Ops, unsigned NumOps);
 
513
  SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT,
 
514
                  const SDValue *Ops, unsigned NumOps);
 
515
  SDValue getNode(unsigned Opcode, DebugLoc DL,
 
516
                  const std::vector<EVT> &ResultTys,
 
517
                  const SDValue *Ops, unsigned NumOps);
 
518
  SDValue getNode(unsigned Opcode, DebugLoc DL, const EVT *VTs, unsigned NumVTs,
 
519
                  const SDValue *Ops, unsigned NumOps);
 
520
  SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
 
521
                  const SDValue *Ops, unsigned NumOps);
 
522
  SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs);
 
523
  SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs, SDValue N);
 
524
  SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
 
525
                  SDValue N1, SDValue N2);
 
526
  SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
 
527
                  SDValue N1, SDValue N2, SDValue N3);
 
528
  SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
 
529
                  SDValue N1, SDValue N2, SDValue N3, SDValue N4);
 
530
  SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
 
531
                  SDValue N1, SDValue N2, SDValue N3, SDValue N4,
 
532
                  SDValue N5);
 
533
 
 
534
  /// getStackArgumentTokenFactor - Compute a TokenFactor to force all
 
535
  /// the incoming stack arguments to be loaded from the stack. This is
 
536
  /// used in tail call lowering to protect stack arguments from being
 
537
  /// clobbered.
 
538
  SDValue getStackArgumentTokenFactor(SDValue Chain);
 
539
 
 
540
  SDValue getMemcpy(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
 
541
                    SDValue Size, unsigned Align, bool isVol, bool AlwaysInline,
 
542
                    const Value *DstSV, uint64_t DstSVOff,
 
543
                    const Value *SrcSV, uint64_t SrcSVOff);
 
544
 
 
545
  SDValue getMemmove(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
 
546
                     SDValue Size, unsigned Align, bool isVol,
 
547
                     const Value *DstSV, uint64_t DstOSVff,
 
548
                     const Value *SrcSV, uint64_t SrcSVOff);
 
549
 
 
550
  SDValue getMemset(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
 
551
                    SDValue Size, unsigned Align, bool isVol,
 
552
                    const Value *DstSV, uint64_t DstSVOff);
 
553
 
 
554
  /// getSetCC - Helper function to make it easier to build SetCC's if you just
 
555
  /// have an ISD::CondCode instead of an SDValue.
 
556
  ///
 
557
  SDValue getSetCC(DebugLoc DL, EVT VT, SDValue LHS, SDValue RHS,
 
558
                   ISD::CondCode Cond) {
 
559
    return getNode(ISD::SETCC, DL, VT, LHS, RHS, getCondCode(Cond));
 
560
  }
 
561
 
 
562
  /// getVSetCC - Helper function to make it easier to build VSetCC's nodes
 
563
  /// if you just have an ISD::CondCode instead of an SDValue.
 
564
  ///
 
565
  SDValue getVSetCC(DebugLoc DL, EVT VT, SDValue LHS, SDValue RHS,
 
566
                    ISD::CondCode Cond) {
 
567
    return getNode(ISD::VSETCC, DL, VT, LHS, RHS, getCondCode(Cond));
 
568
  }
 
569
 
 
570
  /// getSelectCC - Helper function to make it easier to build SelectCC's if you
 
571
  /// just have an ISD::CondCode instead of an SDValue.
 
572
  ///
 
573
  SDValue getSelectCC(DebugLoc DL, SDValue LHS, SDValue RHS,
 
574
                      SDValue True, SDValue False, ISD::CondCode Cond) {
 
575
    return getNode(ISD::SELECT_CC, DL, True.getValueType(),
 
576
                   LHS, RHS, True, False, getCondCode(Cond));
 
577
  }
 
578
 
 
579
  /// getVAArg - VAArg produces a result and token chain, and takes a pointer
 
580
  /// and a source value as input.
 
581
  SDValue getVAArg(EVT VT, DebugLoc dl, SDValue Chain, SDValue Ptr,
 
582
                   SDValue SV, unsigned Align);
 
583
 
 
584
  /// getAtomic - Gets a node for an atomic op, produces result and chain and
 
585
  /// takes 3 operands
 
586
  SDValue getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT, SDValue Chain,
 
587
                    SDValue Ptr, SDValue Cmp, SDValue Swp, const Value* PtrVal,
 
588
                    unsigned Alignment=0);
 
589
  SDValue getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT, SDValue Chain,
 
590
                    SDValue Ptr, SDValue Cmp, SDValue Swp,
 
591
                    MachineMemOperand *MMO);
 
592
 
 
593
  /// getAtomic - Gets a node for an atomic op, produces result and chain and
 
594
  /// takes 2 operands.
 
595
  SDValue getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT, SDValue Chain,
 
596
                    SDValue Ptr, SDValue Val, const Value* PtrVal,
 
597
                    unsigned Alignment = 0);
 
598
  SDValue getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT, SDValue Chain,
 
599
                    SDValue Ptr, SDValue Val,
 
600
                    MachineMemOperand *MMO);
 
601
 
 
602
  /// getMemIntrinsicNode - Creates a MemIntrinsicNode that may produce a
 
603
  /// result and takes a list of operands. Opcode may be INTRINSIC_VOID,
 
604
  /// INTRINSIC_W_CHAIN, or a target-specific opcode with a value not
 
605
  /// less than FIRST_TARGET_MEMORY_OPCODE.
 
606
  SDValue getMemIntrinsicNode(unsigned Opcode, DebugLoc dl,
 
607
                              const EVT *VTs, unsigned NumVTs,
 
608
                              const SDValue *Ops, unsigned NumOps,
 
609
                              EVT MemVT, const Value *srcValue, int SVOff,
 
610
                              unsigned Align = 0, bool Vol = false,
 
611
                              bool ReadMem = true, bool WriteMem = true);
 
612
 
 
613
  SDValue getMemIntrinsicNode(unsigned Opcode, DebugLoc dl, SDVTList VTList,
 
614
                              const SDValue *Ops, unsigned NumOps,
 
615
                              EVT MemVT, const Value *srcValue, int SVOff,
 
616
                              unsigned Align = 0, bool Vol = false,
 
617
                              bool ReadMem = true, bool WriteMem = true);
 
618
 
 
619
  SDValue getMemIntrinsicNode(unsigned Opcode, DebugLoc dl, SDVTList VTList,
 
620
                              const SDValue *Ops, unsigned NumOps,
 
621
                              EVT MemVT, MachineMemOperand *MMO);
 
622
 
 
623
  /// getMergeValues - Create a MERGE_VALUES node from the given operands.
 
624
  SDValue getMergeValues(const SDValue *Ops, unsigned NumOps, DebugLoc dl);
 
625
 
 
626
  /// getLoad - Loads are not normal binary operators: their result type is not
 
627
  /// determined by their operands, and they produce a value AND a token chain.
 
628
  ///
 
629
  SDValue getLoad(EVT VT, DebugLoc dl, SDValue Chain, SDValue Ptr,
 
630
                  const Value *SV, int SVOffset, bool isVolatile,
 
631
                  bool isNonTemporal, unsigned Alignment);
 
632
  SDValue getExtLoad(ISD::LoadExtType ExtType, EVT VT, DebugLoc dl,
 
633
                     SDValue Chain, SDValue Ptr, const Value *SV,
 
634
                     int SVOffset, EVT MemVT, bool isVolatile,
 
635
                     bool isNonTemporal, unsigned Alignment);
 
636
  SDValue getIndexedLoad(SDValue OrigLoad, DebugLoc dl, SDValue Base,
 
637
                         SDValue Offset, ISD::MemIndexedMode AM);
 
638
  SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
 
639
                  EVT VT, DebugLoc dl,
 
640
                  SDValue Chain, SDValue Ptr, SDValue Offset,
 
641
                  const Value *SV, int SVOffset, EVT MemVT,
 
642
                  bool isVolatile, bool isNonTemporal, unsigned Alignment);
 
643
  SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
 
644
                  EVT VT, DebugLoc dl,
 
645
                  SDValue Chain, SDValue Ptr, SDValue Offset,
 
646
                  EVT MemVT, MachineMemOperand *MMO);
 
647
 
 
648
  /// getStore - Helper function to build ISD::STORE nodes.
 
649
  ///
 
650
  SDValue getStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr,
 
651
                   const Value *SV, int SVOffset, bool isVolatile,
 
652
                   bool isNonTemporal, unsigned Alignment);
 
653
  SDValue getStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr,
 
654
                   MachineMemOperand *MMO);
 
655
  SDValue getTruncStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr,
 
656
                        const Value *SV, int SVOffset, EVT TVT,
 
657
                        bool isNonTemporal, bool isVolatile,
 
658
                        unsigned Alignment);
 
659
  SDValue getTruncStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr,
 
660
                        EVT TVT, MachineMemOperand *MMO);
 
661
  SDValue getIndexedStore(SDValue OrigStoe, DebugLoc dl, SDValue Base,
 
662
                           SDValue Offset, ISD::MemIndexedMode AM);
 
663
 
 
664
  /// getSrcValue - Construct a node to track a Value* through the backend.
 
665
  SDValue getSrcValue(const Value *v);
 
666
 
 
667
  /// getMDNode - Return an MDNodeSDNode which holds an MDNode.
 
668
  SDValue getMDNode(const MDNode *MD);
 
669
  
 
670
  /// getShiftAmountOperand - Return the specified value casted to
 
671
  /// the target's desired shift amount type.
 
672
  SDValue getShiftAmountOperand(SDValue Op);
 
673
 
 
674
  /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
 
675
  /// specified operands.  If the resultant node already exists in the DAG,
 
676
  /// this does not modify the specified node, instead it returns the node that
 
677
  /// already exists.  If the resultant node does not exist in the DAG, the
 
678
  /// input node is returned.  As a degenerate case, if you specify the same
 
679
  /// input operands as the node already has, the input node is returned.
 
680
  SDNode *UpdateNodeOperands(SDNode *N, SDValue Op);
 
681
  SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2);
 
682
  SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
 
683
                               SDValue Op3);
 
684
  SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
 
685
                               SDValue Op3, SDValue Op4);
 
686
  SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
 
687
                               SDValue Op3, SDValue Op4, SDValue Op5);
 
688
  SDNode *UpdateNodeOperands(SDNode *N,
 
689
                               const SDValue *Ops, unsigned NumOps);
 
690
 
 
691
  /// SelectNodeTo - These are used for target selectors to *mutate* the
 
692
  /// specified node to have the specified return type, Target opcode, and
 
693
  /// operands.  Note that target opcodes are stored as
 
694
  /// ~TargetOpcode in the node opcode field.  The resultant node is returned.
 
695
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT);
 
696
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT, SDValue Op1);
 
697
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
 
698
                       SDValue Op1, SDValue Op2);
 
699
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
 
700
                       SDValue Op1, SDValue Op2, SDValue Op3);
 
701
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
 
702
                       const SDValue *Ops, unsigned NumOps);
 
703
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1, EVT VT2);
 
704
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
 
705
                       EVT VT2, const SDValue *Ops, unsigned NumOps);
 
706
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
 
707
                       EVT VT2, EVT VT3, const SDValue *Ops, unsigned NumOps);
 
708
  SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
 
709
                       EVT VT2, EVT VT3, EVT VT4, const SDValue *Ops,
 
710
                       unsigned NumOps);
 
711
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
 
712
                       EVT VT2, SDValue Op1);
 
713
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
 
714
                       EVT VT2, SDValue Op1, SDValue Op2);
 
715
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
 
716
                       EVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
 
717
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
 
718
                       EVT VT2, EVT VT3, SDValue Op1, SDValue Op2, SDValue Op3);
 
719
  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs,
 
720
                       const SDValue *Ops, unsigned NumOps);
 
721
 
 
722
  /// MorphNodeTo - This *mutates* the specified node to have the specified
 
723
  /// return type, opcode, and operands.
 
724
  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
 
725
                      const SDValue *Ops, unsigned NumOps);
 
726
 
 
727
  /// getMachineNode - These are used for target selectors to create a new node
 
728
  /// with specified return type(s), MachineInstr opcode, and operands.
 
729
  ///
 
730
  /// Note that getMachineNode returns the resultant node.  If there is already
 
731
  /// a node of the specified opcode and operands, it returns that node instead
 
732
  /// of the current one.
 
733
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT);
 
734
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT,
 
735
                                SDValue Op1);
 
736
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT,
 
737
                                SDValue Op1, SDValue Op2);
 
738
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT,
 
739
                         SDValue Op1, SDValue Op2, SDValue Op3);
 
740
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT,
 
741
                         const SDValue *Ops, unsigned NumOps);
 
742
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2);
 
743
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
 
744
                         SDValue Op1);
 
745
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1,
 
746
                         EVT VT2, SDValue Op1, SDValue Op2);
 
747
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1,
 
748
                         EVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
 
749
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
 
750
                         const SDValue *Ops, unsigned NumOps);
 
751
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
 
752
                         EVT VT3, SDValue Op1, SDValue Op2);
 
753
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
 
754
                         EVT VT3, SDValue Op1, SDValue Op2, SDValue Op3);
 
755
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
 
756
                         EVT VT3, const SDValue *Ops, unsigned NumOps);
 
757
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
 
758
                         EVT VT3, EVT VT4, const SDValue *Ops, unsigned NumOps);
 
759
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl,
 
760
                         const std::vector<EVT> &ResultTys, const SDValue *Ops,
 
761
                         unsigned NumOps);
 
762
  MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, SDVTList VTs,
 
763
                         const SDValue *Ops, unsigned NumOps);
 
764
 
 
765
  /// getTargetExtractSubreg - A convenience function for creating
 
766
  /// TargetInstrInfo::EXTRACT_SUBREG nodes.
 
767
  SDValue getTargetExtractSubreg(int SRIdx, DebugLoc DL, EVT VT,
 
768
                                 SDValue Operand);
 
769
 
 
770
  /// getTargetInsertSubreg - A convenience function for creating
 
771
  /// TargetInstrInfo::INSERT_SUBREG nodes.
 
772
  SDValue getTargetInsertSubreg(int SRIdx, DebugLoc DL, EVT VT,
 
773
                                SDValue Operand, SDValue Subreg);
 
774
 
 
775
  /// getNodeIfExists - Get the specified node if it's already available, or
 
776
  /// else return NULL.
 
777
  SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs,
 
778
                          const SDValue *Ops, unsigned NumOps);
 
779
 
 
780
  /// getDbgValue - Creates a SDDbgValue node.
 
781
  ///
 
782
  SDDbgValue *getDbgValue(MDNode *MDPtr, SDNode *N, unsigned R, uint64_t Off,
 
783
                          DebugLoc DL, unsigned O);
 
784
  SDDbgValue *getDbgValue(MDNode *MDPtr, const Value *C, uint64_t Off,
 
785
                          DebugLoc DL, unsigned O);
 
786
  SDDbgValue *getDbgValue(MDNode *MDPtr, unsigned FI, uint64_t Off,
 
787
                          DebugLoc DL, unsigned O);
 
788
 
 
789
  /// DAGUpdateListener - Clients of various APIs that cause global effects on
 
790
  /// the DAG can optionally implement this interface.  This allows the clients
 
791
  /// to handle the various sorts of updates that happen.
 
792
  class DAGUpdateListener {
 
793
  public:
 
794
    virtual ~DAGUpdateListener();
 
795
 
 
796
    /// NodeDeleted - The node N that was deleted and, if E is not null, an
 
797
    /// equivalent node E that replaced it.
 
798
    virtual void NodeDeleted(SDNode *N, SDNode *E) = 0;
 
799
 
 
800
    /// NodeUpdated - The node N that was updated.
 
801
    virtual void NodeUpdated(SDNode *N) = 0;
 
802
  };
 
803
 
 
804
  /// RemoveDeadNode - Remove the specified node from the system. If any of its
 
805
  /// operands then becomes dead, remove them as well. Inform UpdateListener
 
806
  /// for each node deleted.
 
807
  void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0);
 
808
 
 
809
  /// RemoveDeadNodes - This method deletes the unreachable nodes in the
 
810
  /// given list, and any nodes that become unreachable as a result.
 
811
  void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes,
 
812
                       DAGUpdateListener *UpdateListener = 0);
 
813
 
 
814
  /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
 
815
  /// This can cause recursive merging of nodes in the DAG.  Use the first
 
816
  /// version if 'From' is known to have a single result, use the second
 
817
  /// if you have two nodes with identical results (or if 'To' has a superset
 
818
  /// of the results of 'From'), use the third otherwise.
 
819
  ///
 
820
  /// These methods all take an optional UpdateListener, which (if not null) is
 
821
  /// informed about nodes that are deleted and modified due to recursive
 
822
  /// changes in the dag.
 
823
  ///
 
824
  /// These functions only replace all existing uses. It's possible that as
 
825
  /// these replacements are being performed, CSE may cause the From node
 
826
  /// to be given new uses. These new uses of From are left in place, and
 
827
  /// not automatically transfered to To.
 
828
  ///
 
829
  void ReplaceAllUsesWith(SDValue From, SDValue Op,
 
830
                          DAGUpdateListener *UpdateListener = 0);
 
831
  void ReplaceAllUsesWith(SDNode *From, SDNode *To,
 
832
                          DAGUpdateListener *UpdateListener = 0);
 
833
  void ReplaceAllUsesWith(SDNode *From, const SDValue *To,
 
834
                          DAGUpdateListener *UpdateListener = 0);
 
835
 
 
836
  /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
 
837
  /// uses of other values produced by From.Val alone.
 
838
  void ReplaceAllUsesOfValueWith(SDValue From, SDValue To,
 
839
                                 DAGUpdateListener *UpdateListener = 0);
 
840
 
 
841
  /// ReplaceAllUsesOfValuesWith - Like ReplaceAllUsesOfValueWith, but
 
842
  /// for multiple values at once. This correctly handles the case where
 
843
  /// there is an overlap between the From values and the To values.
 
844
  void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To,
 
845
                                  unsigned Num,
 
846
                                  DAGUpdateListener *UpdateListener = 0);
 
847
 
 
848
  /// AssignTopologicalOrder - Topological-sort the AllNodes list and a
 
849
  /// assign a unique node id for each node in the DAG based on their
 
850
  /// topological order. Returns the number of nodes.
 
851
  unsigned AssignTopologicalOrder();
 
852
 
 
853
  /// RepositionNode - Move node N in the AllNodes list to be immediately
 
854
  /// before the given iterator Position. This may be used to update the
 
855
  /// topological ordering when the list of nodes is modified.
 
856
  void RepositionNode(allnodes_iterator Position, SDNode *N) {
 
857
    AllNodes.insert(Position, AllNodes.remove(N));
 
858
  }
 
859
 
 
860
  /// isCommutativeBinOp - Returns true if the opcode is a commutative binary
 
861
  /// operation.
 
862
  static bool isCommutativeBinOp(unsigned Opcode) {
 
863
    // FIXME: This should get its info from the td file, so that we can include
 
864
    // target info.
 
865
    switch (Opcode) {
 
866
    case ISD::ADD:
 
867
    case ISD::MUL:
 
868
    case ISD::MULHU:
 
869
    case ISD::MULHS:
 
870
    case ISD::SMUL_LOHI:
 
871
    case ISD::UMUL_LOHI:
 
872
    case ISD::FADD:
 
873
    case ISD::FMUL:
 
874
    case ISD::AND:
 
875
    case ISD::OR:
 
876
    case ISD::XOR:
 
877
    case ISD::SADDO:
 
878
    case ISD::UADDO:
 
879
    case ISD::ADDC:
 
880
    case ISD::ADDE: return true;
 
881
    default: return false;
 
882
    }
 
883
  }
 
884
 
 
885
  /// AssignOrdering - Assign an order to the SDNode.
 
886
  void AssignOrdering(const SDNode *SD, unsigned Order);
 
887
 
 
888
  /// GetOrdering - Get the order for the SDNode.
 
889
  unsigned GetOrdering(const SDNode *SD) const;
 
890
 
 
891
  /// AddDbgValue - Add a dbg_value SDNode. If SD is non-null that means the
 
892
  /// value is produced by SD.
 
893
  void AddDbgValue(SDDbgValue *DB, SDNode *SD, bool isParameter);
 
894
 
 
895
  /// GetDbgValues - Get the debug values which reference the given SDNode.
 
896
  SmallVector<SDDbgValue*,2> &GetDbgValues(const SDNode* SD) {
 
897
    return DbgInfo->getSDDbgValues(SD);
 
898
  }
 
899
 
 
900
  /// hasDebugValues - Return true if there are any SDDbgValue nodes associated
 
901
  /// with this SelectionDAG.
 
902
  bool hasDebugValues() const { return !DbgInfo->empty(); }
 
903
 
 
904
  SDDbgInfo::DbgIterator DbgBegin() { return DbgInfo->DbgBegin(); }
 
905
  SDDbgInfo::DbgIterator DbgEnd()   { return DbgInfo->DbgEnd(); }
 
906
  SDDbgInfo::DbgIterator ByvalParmDbgBegin() { 
 
907
    return DbgInfo->ByvalParmDbgBegin(); 
 
908
  }
 
909
  SDDbgInfo::DbgIterator ByvalParmDbgEnd()   { 
 
910
    return DbgInfo->ByvalParmDbgEnd(); 
 
911
  }
 
912
 
 
913
  void dump() const;
 
914
 
 
915
  /// CreateStackTemporary - Create a stack temporary, suitable for holding the
 
916
  /// specified value type.  If minAlign is specified, the slot size will have
 
917
  /// at least that alignment.
 
918
  SDValue CreateStackTemporary(EVT VT, unsigned minAlign = 1);
 
919
 
 
920
  /// CreateStackTemporary - Create a stack temporary suitable for holding
 
921
  /// either of the specified value types.
 
922
  SDValue CreateStackTemporary(EVT VT1, EVT VT2);
 
923
 
 
924
  /// FoldConstantArithmetic -
 
925
  SDValue FoldConstantArithmetic(unsigned Opcode,
 
926
                                 EVT VT,
 
927
                                 ConstantSDNode *Cst1,
 
928
                                 ConstantSDNode *Cst2);
 
929
 
 
930
  /// FoldSetCC - Constant fold a setcc to true or false.
 
931
  SDValue FoldSetCC(EVT VT, SDValue N1,
 
932
                    SDValue N2, ISD::CondCode Cond, DebugLoc dl);
 
933
 
 
934
  /// SignBitIsZero - Return true if the sign bit of Op is known to be zero.  We
 
935
  /// use this predicate to simplify operations downstream.
 
936
  bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const;
 
937
 
 
938
  /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero.  We
 
939
  /// use this predicate to simplify operations downstream.  Op and Mask are
 
940
  /// known to be the same type.
 
941
  bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth = 0)
 
942
    const;
 
943
 
 
944
  /// ComputeMaskedBits - Determine which of the bits specified in Mask are
 
945
  /// known to be either zero or one and return them in the KnownZero/KnownOne
 
946
  /// bitsets.  This code only analyzes bits in Mask, in order to short-circuit
 
947
  /// processing.  Targets can implement the computeMaskedBitsForTargetNode
 
948
  /// method in the TargetLowering class to allow target nodes to be understood.
 
949
  void ComputeMaskedBits(SDValue Op, const APInt &Mask, APInt &KnownZero,
 
950
                         APInt &KnownOne, unsigned Depth = 0) const;
 
951
 
 
952
  /// ComputeNumSignBits - Return the number of times the sign bit of the
 
953
  /// register is replicated into the other bits.  We know that at least 1 bit
 
954
  /// is always equal to the sign bit (itself), but other cases can give us
 
955
  /// information.  For example, immediately after an "SRA X, 2", we know that
 
956
  /// the top 3 bits are all equal to each other, so we return 3.  Targets can
 
957
  /// implement the ComputeNumSignBitsForTarget method in the TargetLowering
 
958
  /// class to allow target nodes to be understood.
 
959
  unsigned ComputeNumSignBits(SDValue Op, unsigned Depth = 0) const;
 
960
 
 
961
  /// isKnownNeverNan - Test whether the given SDValue is known to never be NaN.
 
962
  bool isKnownNeverNaN(SDValue Op) const;
 
963
 
 
964
  /// isKnownNeverZero - Test whether the given SDValue is known to never be
 
965
  /// positive or negative Zero.
 
966
  bool isKnownNeverZero(SDValue Op) const;
 
967
 
 
968
  /// isEqualTo - Test whether two SDValues are known to compare equal. This
 
969
  /// is true if they are the same value, or if one is negative zero and the
 
970
  /// other positive zero.
 
971
  bool isEqualTo(SDValue A, SDValue B) const;
 
972
 
 
973
  /// isVerifiedDebugInfoDesc - Returns true if the specified SDValue has
 
974
  /// been verified as a debug information descriptor.
 
975
  bool isVerifiedDebugInfoDesc(SDValue Op) const;
 
976
 
 
977
  /// UnrollVectorOp - Utility function used by legalize and lowering to
 
978
  /// "unroll" a vector operation by splitting out the scalars and operating
 
979
  /// on each element individually.  If the ResNE is 0, fully unroll the vector
 
980
  /// op. If ResNE is less than the width of the vector op, unroll up to ResNE.
 
981
  /// If the  ResNE is greater than the width of the vector op, unroll the
 
982
  /// vector op and fill the end of the resulting vector with UNDEFS.
 
983
  SDValue UnrollVectorOp(SDNode *N, unsigned ResNE = 0);
 
984
 
 
985
  /// isConsecutiveLoad - Return true if LD is loading 'Bytes' bytes from a 
 
986
  /// location that is 'Dist' units away from the location that the 'Base' load 
 
987
  /// is loading from.
 
988
  bool isConsecutiveLoad(LoadSDNode *LD, LoadSDNode *Base,
 
989
                         unsigned Bytes, int Dist) const;
 
990
 
 
991
  /// InferPtrAlignment - Infer alignment of a load / store address. Return 0 if
 
992
  /// it cannot be inferred.
 
993
  unsigned InferPtrAlignment(SDValue Ptr) const;
 
994
 
 
995
private:
 
996
  bool RemoveNodeFromCSEMaps(SDNode *N);
 
997
  void AddModifiedNodeToCSEMaps(SDNode *N, DAGUpdateListener *UpdateListener);
 
998
  SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos);
 
999
  SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
 
1000
                               void *&InsertPos);
 
1001
  SDNode *FindModifiedNodeSlot(SDNode *N, const SDValue *Ops, unsigned NumOps,
 
1002
                               void *&InsertPos);
 
1003
 
 
1004
  void DeleteNodeNotInCSEMaps(SDNode *N);
 
1005
  void DeallocateNode(SDNode *N);
 
1006
 
 
1007
  unsigned getEVTAlignment(EVT MemoryVT) const;
 
1008
 
 
1009
  void allnodes_clear();
 
1010
 
 
1011
  /// VTList - List of non-single value types.
 
1012
  std::vector<SDVTList> VTList;
 
1013
 
 
1014
  /// CondCodeNodes - Maps to auto-CSE operations.
 
1015
  std::vector<CondCodeSDNode*> CondCodeNodes;
 
1016
 
 
1017
  std::vector<SDNode*> ValueTypeNodes;
 
1018
  std::map<EVT, SDNode*, EVT::compareRawBits> ExtendedValueTypeNodes;
 
1019
  StringMap<SDNode*> ExternalSymbols;
 
1020
  
 
1021
  std::map<std::pair<std::string, unsigned char>,SDNode*> TargetExternalSymbols;
 
1022
};
 
1023
 
 
1024
template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
 
1025
  typedef SelectionDAG::allnodes_iterator nodes_iterator;
 
1026
  static nodes_iterator nodes_begin(SelectionDAG *G) {
 
1027
    return G->allnodes_begin();
 
1028
  }
 
1029
  static nodes_iterator nodes_end(SelectionDAG *G) {
 
1030
    return G->allnodes_end();
 
1031
  }
 
1032
};
 
1033
 
 
1034
}  // end namespace llvm
 
1035
 
 
1036
#endif