1c3aae25116e66c177579b0b79182b09340b19753Chris Lattner//===-- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ---------*- C++ -*-===//
2ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//                     The LLVM Compiler Infrastructure
46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//
57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source
67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details.
7ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===//
9ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
10c3aae25116e66c177579b0b79182b09340b19753Chris Lattner// This file declares the SelectionDAG class, and transitively defines the
11c3aae25116e66c177579b0b79182b09340b19753Chris Lattner// SDNode class and subclasses.
12ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
13cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner//===----------------------------------------------------------------------===//
14cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
15cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner#ifndef LLVM_CODEGEN_SELECTIONDAG_H
16cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner#define LLVM_CODEGEN_SELECTIONDAG_H
17cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
18c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene#include "llvm/ADT/DenseSet.h"
194b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman#include "llvm/ADT/StringMap.h"
20255f89faee13dc491cb64fbeae3c763e7e2ea4e6Chandler Carruth#include "llvm/ADT/ilist.h"
21444b4bf5c84c80833ff283244de0885124091a13Nadav Rotem#include "llvm/CodeGen/DAGCombine.h"
22583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey#include "llvm/CodeGen/SelectionDAGNodes.h"
23c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman#include "llvm/Support/RecyclingAllocator.h"
2498a366d547772010e94609e4584489b3e5ce0043Bill Wendling#include "llvm/Target/TargetMachine.h"
25acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman#include <cassert>
26322812e603705e1c2037313633e72f689524b163Evan Cheng#include <map>
27eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner#include <string>
28255f89faee13dc491cb64fbeae3c763e7e2ea4e6Chandler Carruth#include <vector>
29d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
30d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
31fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
32fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass AliasAnalysis;
33b4e6a5df5dada0cd919cc6e2717eb3118db9cc45Bill Wendlingclass MachineConstantPoolValue;
34b4e6a5df5dada0cd919cc6e2717eb3118db9cc45Bill Wendlingclass MachineFunction;
3531441b7e95e0840e1ae144e5db6f791d6a36bc60Evan Chengclass MDNode;
36bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesenclass SDDbgValue;
37b4e6a5df5dada0cd919cc6e2717eb3118db9cc45Bill Wendlingclass TargetLowering;
38ff7a562751604a9fe13efc75bd59622244b54d35Dan Gohmanclass TargetSelectionDAGInfo;
39fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
408c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofeiclass SDVTListNode : public FoldingSetNode {
418c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  friend struct FoldingSetTrait<SDVTListNode>;
428c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  /// FastID - A reference to an Interned FoldingSetNodeID for this node.
438c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  /// The Allocator in SelectionDAG holds the data.
448c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  /// SDVTList contains all types which are frequently accessed in SelectionDAG.
458c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  /// The size of this list is not expected big so it won't introduce memory penalty.
468c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  FoldingSetNodeIDRef FastID;
478c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  const EVT *VTs;
488c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  unsigned int NumVTs;
498c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  /// The hash value for SDVTList is fixed so cache it to avoid hash calculation
508c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  unsigned HashValue;
518c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofeipublic:
528c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  SDVTListNode(const FoldingSetNodeIDRef ID, const EVT *VT, unsigned int Num) :
538c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei      FastID(ID), VTs(VT), NumVTs(Num) {
548c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei    HashValue = ID.ComputeHash();
558c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  }
568c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  SDVTList getSDVTList() {
578c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei    SDVTList result = {VTs, NumVTs};
588c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei    return result;
598c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  }
608c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei};
618c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei
628c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei// Specialize FoldingSetTrait for SDVTListNode
638c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei// To avoid computing temp FoldingSetNodeID and hash value.
648c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofeitemplate<> struct FoldingSetTrait<SDVTListNode> : DefaultFoldingSetTrait<SDVTListNode> {
658c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  static void Profile(const SDVTListNode &X, FoldingSetNodeID& ID) {
668c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei    ID = X.FastID;
678c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  }
688c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  static bool Equals(const SDVTListNode &X, const FoldingSetNodeID &ID,
698c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei                     unsigned IDHash, FoldingSetNodeID &TempID) {
708c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei    if (X.HashValue != IDHash)
718c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei      return false;
728c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei    return ID == X.FastID;
738c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  }
748c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  static unsigned ComputeHash(const SDVTListNode &X, FoldingSetNodeID &TempID) {
758c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei    return X.HashValue;
768c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei  }
778c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei};
788c955ea858b0c99c856c7c10a3eee7576d13abd1Wan Xiaofei
798e4018e2de52c534405d7155c7009d0b35afb861Cedric Venettemplate<> struct ilist_traits<SDNode> : public ilist_default_traits<SDNode> {
808e4018e2de52c534405d7155c7009d0b35afb861Cedric Venetprivate:
817309be6735666143bd9835b275dc8501617a2591Gabor Greif  mutable ilist_half_node<SDNode> Sentinel;
82fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanpublic:
83fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  SDNode *createSentinel() const {
84c7f6b8c5d40e17bf43fd3a1549d7d89c9da735e1Gabor Greif    return static_cast<SDNode*>(&Sentinel);
85fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  }
86fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  static void destroySentinel(SDNode *) {}
87fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
88c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  SDNode *provideInitialHead() const { return createSentinel(); }
89c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  SDNode *ensureHead(SDNode*) const { return createSentinel(); }
90f3841fcbd587c31aa9842b3f33bd57de40c9f443Gabor Greif  static void noteHead(SDNode*, SDNode*) {}
91c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif
92fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  static void deleteNode(SDNode *) {
9350bee42b54cd9aec5f49566307df2b0cf23afcf6Craig Topper    llvm_unreachable("ilist_traits<SDNode> shouldn't see a deleteNode call!");
94fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  }
95fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanprivate:
96fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  static void createNode(const SDNode &);
97fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman};
98c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
99bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen/// SDDbgInfo - Keeps track of dbg_value information through SDISel.  We do
100bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen/// not build SDNodes for these so as not to perturb the generated code;
101bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng/// instead the info is kept off to the side in this structure. Each SDNode may
102bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng/// have one or more associated dbg_value entries. This information is kept in
103bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng/// DbgValMap.
104fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen/// Byval parameters are handled separately because they don't use alloca's,
105fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen/// which busts the normal mechanism.  There is good reason for handling all
106fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen/// parameters separately:  they may not have code generated for them, they
107fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen/// should always go at the beginning of the function regardless of other code
108fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen/// motion, and debug info for them is potentially useful even if the parameter
109fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen/// is unused.  Right now only byval parameters are handled separately.
110bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesenclass SDDbgInfo {
111bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng  SmallVector<SDDbgValue*, 32> DbgValues;
112fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen  SmallVector<SDDbgValue*, 32> ByvalParmDbgValues;
113f22fd3f7b557a967b1edc1fa9ae770006a39e97cCraig Topper  typedef DenseMap<const SDNode*, SmallVector<SDDbgValue*, 2> > DbgValMapType;
114f22fd3f7b557a967b1edc1fa9ae770006a39e97cCraig Topper  DbgValMapType DbgValMap;
115bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen
116001d3dc976d7cda8a3dd8c7fd4020b0b96033f4eCraig Topper  void operator=(const SDDbgInfo&) LLVM_DELETED_FUNCTION;
117001d3dc976d7cda8a3dd8c7fd4020b0b96033f4eCraig Topper  SDDbgInfo(const SDDbgInfo&) LLVM_DELETED_FUNCTION;
118bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesenpublic:
119bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen  SDDbgInfo() {}
120bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen
121fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen  void add(SDDbgValue *V, const SDNode *Node, bool isParameter) {
122fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen    if (isParameter) {
123fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen      ByvalParmDbgValues.push_back(V);
124fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen    } else     DbgValues.push_back(V);
125bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng    if (Node)
126d4c6c3a7c3140ce487a805138b6f53f82ff6b783Devang Patel      DbgValMap[Node].push_back(V);
127bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen  }
128bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng
129bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen  void clear() {
130d4c6c3a7c3140ce487a805138b6f53f82ff6b783Devang Patel    DbgValMap.clear();
131bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng    DbgValues.clear();
132fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen    ByvalParmDbgValues.clear();
133bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng  }
134bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng
135bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng  bool empty() const {
136fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen    return DbgValues.empty() && ByvalParmDbgValues.empty();
137bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen  }
138bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng
13922a54c1cd711afccd4558374918d12a939e1cca5Benjamin Kramer  ArrayRef<SDDbgValue*> getSDDbgValues(const SDNode *Node) {
140f22fd3f7b557a967b1edc1fa9ae770006a39e97cCraig Topper    DbgValMapType::iterator I = DbgValMap.find(Node);
14122a54c1cd711afccd4558374918d12a939e1cca5Benjamin Kramer    if (I != DbgValMap.end())
14222a54c1cd711afccd4558374918d12a939e1cca5Benjamin Kramer      return I->second;
14322a54c1cd711afccd4558374918d12a939e1cca5Benjamin Kramer    return ArrayRef<SDDbgValue*>();
144bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen  }
145bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng
146f22fd3f7b557a967b1edc1fa9ae770006a39e97cCraig Topper  typedef SmallVectorImpl<SDDbgValue*>::iterator DbgIterator;
147bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng  DbgIterator DbgBegin() { return DbgValues.begin(); }
148bfcb3051899b7141a946d769fcf6e8a8453bc530Evan Cheng  DbgIterator DbgEnd()   { return DbgValues.end(); }
149fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen  DbgIterator ByvalParmDbgBegin() { return ByvalParmDbgValues.begin(); }
150fdb42fa5fe794cc2c89e2ed7f57a89ed24d9952aDale Johannesen  DbgIterator ByvalParmDbgEnd()   { return ByvalParmDbgValues.end(); }
151bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen};
152bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen
153cf495bc2e505e52ad018da55bed11c7b8bc97db5David Greeneclass SelectionDAG;
154cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesvoid checkForCycles(const SelectionDAG *DAG, bool force = false);
155cf495bc2e505e52ad018da55bed11c7b8bc97db5David Greene
156c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// SelectionDAG class - This is used to represent a portion of an LLVM function
157c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// in a low-level Data Dependence DAG representation suitable for instruction
158c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection.  This DAG is constructed as the first step of instruction
159c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection in order to allow implementation of machine specific optimizations
160c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// and code simplifications.
161c3aae25116e66c177579b0b79182b09340b19753Chris Lattner///
162c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// The representation used by the SelectionDAG is a target-independent
163c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// representation, which has some similarities to the GCC RTL representation,
164c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// but is significantly more simple, powerful, and is a graph form instead of a
165c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// linear form.
166cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner///
167cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerclass SelectionDAG {
16850d2b1ac029d63500ea9b9347561b1454fa6ed6aDan Gohman  const TargetMachine &TM;
169ff7a562751604a9fe13efc75bd59622244b54d35Dan Gohman  const TargetSelectionDAGInfo &TSI;
170ee287ca22abcce9f769618c107ff3f46aa2d0cbaBill Wendling  const TargetLowering *TLI;
1717c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  MachineFunction *MF;
172512063dd0f91a76b9dd904dfff72a52b4d09e89fChris Lattner  LLVMContext *Context;
1730508d047fefef36d4f943ee13c82c18cf3a943abDevang Patel  CodeGenOpt::Level OptLevel;
174cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
175f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// EntryNode - The starting token.
176f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  SDNode EntryNode;
177f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman
178f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// Root - The root of the entire DAG.
179f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  SDValue Root;
180cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
181213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// AllNodes - A linked list of nodes in the current DAG.
182fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  ilist<SDNode> AllNodes;
183fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
184f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// NodeAllocatorType - The AllocatorType for allocating SDNodes. We use
185f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// pool allocation with recycling.
186f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  typedef RecyclingAllocator<BumpPtrAllocator, SDNode, sizeof(LargestSDNode),
187f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman                             AlignOf<MostAlignedSDNode>::Alignment>
188f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman    NodeAllocatorType;
189f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman
190f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// NodeAllocator - Pool allocation for nodes.
191f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  NodeAllocatorType NodeAllocator;
192691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth
193213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// CSEMap - This structure is used to memoize nodes, automatically performing
194d23b33435ae722ff5aa5ab97135a4f31041959e2Bob Wilson  /// CSE with existing nodes when a duplicate is requested.
195583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey  FoldingSet<SDNode> CSEMap;
196213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner
197f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// OperandAllocator - Pool allocation for machine-opcode SDNode operands.
198f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  BumpPtrAllocator OperandAllocator;
199f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman
200e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  /// Allocator - Pool allocation for misc. objects that are created once per
201e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  /// SelectionDAG.
202e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  BumpPtrAllocator Allocator;
203e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman
204bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen  /// DbgInfo - Tracks dbg_value information through SDISel.
205bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen  SDDbgInfo *DbgInfo;
206bfdf7f38523bd38ae0538861a2bfd8bdc46e5c33Dale Johannesen
207bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesenpublic:
208bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  /// DAGUpdateListener - Clients of various APIs that cause global effects on
209bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  /// the DAG can optionally implement this interface.  This allows the clients
210bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  /// to handle the various sorts of updates that happen.
211bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  ///
212bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  /// A DAGUpdateListener automatically registers itself with DAG when it is
213bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  /// constructed, and removes itself when destroyed in RAII fashion.
214bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  struct DAGUpdateListener {
215bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen    DAGUpdateListener *const Next;
216bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen    SelectionDAG &DAG;
217bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen
218bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen    explicit DAGUpdateListener(SelectionDAG &D)
219bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen      : Next(D.UpdateListeners), DAG(D) {
220bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen      DAG.UpdateListeners = this;
221bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen    }
222bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen
223bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen    virtual ~DAGUpdateListener() {
224bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen      assert(DAG.UpdateListeners == this &&
225bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen             "DAGUpdateListeners must be destroyed in LIFO order");
226bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen      DAG.UpdateListeners = Next;
227bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen    }
228bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen
229bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen    /// NodeDeleted - The node N that was deleted and, if E is not null, an
230bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen    /// equivalent node E that replaced it.
231bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen    virtual void NodeDeleted(SDNode *N, SDNode *E);
232bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen
233bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen    /// NodeUpdated - The node N that was updated.
234bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen    virtual void NodeUpdated(SDNode *N);
235bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  };
236bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen
237ea28aafa83fc2b6dd632041278c9a18e5a2b2b41Daniel Sanders  /// NewNodesMustHaveLegalTypes - When true, additional steps are taken to
238ea28aafa83fc2b6dd632041278c9a18e5a2b2b41Daniel Sanders  /// ensure that getConstant() and similar functions return DAG nodes that
239ea28aafa83fc2b6dd632041278c9a18e5a2b2b41Daniel Sanders  /// have legal types. This is important after type legalization since
240ea28aafa83fc2b6dd632041278c9a18e5a2b2b41Daniel Sanders  /// any illegally typed nodes generated after this point will not experience
241ea28aafa83fc2b6dd632041278c9a18e5a2b2b41Daniel Sanders  /// type legalization.
242ea28aafa83fc2b6dd632041278c9a18e5a2b2b41Daniel Sanders  bool NewNodesMustHaveLegalTypes;
243ea28aafa83fc2b6dd632041278c9a18e5a2b2b41Daniel Sanders
244bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesenprivate:
245bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  /// DAGUpdateListener is a friend so it can manipulate the listener stack.
246bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  friend struct DAGUpdateListener;
247bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen
248bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  /// UpdateListeners - Linked list of registered DAGUpdateListener instances.
249bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  /// This stack is maintained by DAGUpdateListener RAII.
250bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen  DAGUpdateListener *UpdateListeners;
251bc7d448f242b1bbc1031fb87cd69c285ff9aaffaJakob Stoklund Olesen
252c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  /// setGraphColorHelper - Implementation of setSubgraphColor.
253c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  /// Return whether we had to truncate the search.
254c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  ///
255c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  bool setSubgraphColorHelper(SDNode *N, const char *Color,
256c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif                              DenseSet<SDNode *> &visited,
257c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene                              int level, bool &printed);
258c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene
259001d3dc976d7cda8a3dd8c7fd4020b0b96033f4eCraig Topper  void operator=(const SelectionDAG&) LLVM_DELETED_FUNCTION;
260001d3dc976d7cda8a3dd8c7fd4020b0b96033f4eCraig Topper  SelectionDAG(const SelectionDAG&) LLVM_DELETED_FUNCTION;
261819309efec6f11ba752bd7cbfe186495745f020bDaniel Dunbar
262cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerpublic:
2630508d047fefef36d4f943ee13c82c18cf3a943abDevang Patel  explicit SelectionDAG(const TargetMachine &TM, llvm::CodeGenOpt::Level);
264cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ~SelectionDAG();
265cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
2667c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  /// init - Prepare this SelectionDAG to process code in the given
2677c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  /// MachineFunction.
2687c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  ///
26936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void init(MachineFunction &mf, const TargetLowering *TLI);
2707c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman
2717c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  /// clear - Clear state and free memory necessary to make this
272f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// SelectionDAG ready to process a new block.
273f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  ///
2747c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  void clear();
275f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman
2767c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  MachineFunction &getMachineFunction() const { return *MF; }
27750d2b1ac029d63500ea9b9347561b1454fa6ed6aDan Gohman  const TargetMachine &getTarget() const { return TM; }
278ee287ca22abcce9f769618c107ff3f46aa2d0cbaBill Wendling  const TargetLowering &getTargetLoweringInfo() const { return *TLI; }
279ff7a562751604a9fe13efc75bd59622244b54d35Dan Gohman  const TargetSelectionDAGInfo &getSelectionDAGInfo() const { return TSI; }
280d1474d09cbe5fdeec8ba0d6c6b52f316f3422532Owen Anderson  LLVMContext *getContext() const {return Context; }
281cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
282ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
2831080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  ///
284462dc7f4960e5074ddf4769ec8b2ef1ba7a4d2c8Dan Gohman  void viewGraph(const std::string &Title);
2850b12aef49087b57d276ed760a83525d1e2602144Dan Gohman  void viewGraph();
286fdc40a0a696c658d550d894ea03772e5f8af2c94Scott Michel
287ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#ifndef NDEBUG
288ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  std::map<const SDNode *, std::string> NodeGraphAttrs;
289ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#endif
2901080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
291ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// clearGraphAttrs - Clear all previously defined node graph attributes.
292ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// Intended to be used from a debugging tool (eg. gdb).
293ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void clearGraphAttrs();
294fdc40a0a696c658d550d894ea03772e5f8af2c94Scott Michel
295ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
296ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  ///
297ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void setGraphAttrs(const SDNode *N, const char *Attrs);
298fdc40a0a696c658d550d894ea03772e5f8af2c94Scott Michel
299ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
300ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// Used from getNodeAttributes.
301ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  const std::string getGraphAttrs(const SDNode *N) const;
302fdc40a0a696c658d550d894ea03772e5f8af2c94Scott Michel
303ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// setGraphColor - Convenience for setting node color attribute.
304ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  ///
305ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void setGraphColor(const SDNode *N, const char *Color);
3061080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
307c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  /// setGraphColor - Convenience for setting subgraph color attribute.
308c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  ///
309c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  void setSubgraphColor(SDNode *N, const char *Color);
310c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene
311fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
312b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
313b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
314fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  typedef ilist<SDNode>::iterator allnodes_iterator;
315b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
316b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_end() { return AllNodes.end(); }
317fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  ilist<SDNode>::size_type allnodes_size() const {
3180e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman    return AllNodes.size();
3190e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman  }
320fdc40a0a696c658d550d894ea03772e5f8af2c94Scott Michel
321c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getRoot - Return the root tag of the SelectionDAG.
322cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
323475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  const SDValue &getRoot() const { return Root; }
324cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
325c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getEntryNode - Return the token chain corresponding to the entry of the
326c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// function.
327f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  SDValue getEntryNode() const {
328f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman    return SDValue(const_cast<SDNode *>(&EntryNode), 0);
329f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  }
330cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
331c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// setRoot - Set the current root tag of the SelectionDAG.
332cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
333475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  const SDValue &setRoot(SDValue N) {
334825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson    assert((!N.getNode() || N.getValueType() == MVT::Other) &&
335acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman           "DAG root value is not a chain!");
336cf495bc2e505e52ad018da55bed11c7b8bc97db5David Greene    if (N.getNode())
337cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines      checkForCycles(N.getNode(), this);
338cf495bc2e505e52ad018da55bed11c7b8bc97db5David Greene    Root = N;
339cf495bc2e505e52ad018da55bed11c7b8bc97db5David Greene    if (N.getNode())
340cf495bc2e505e52ad018da55bed11c7b8bc97db5David Greene      checkForCycles(this);
341cf495bc2e505e52ad018da55bed11c7b8bc97db5David Greene    return Root;
342acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman  }
343cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
3441d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// Combine - This iterates over the nodes in the SelectionDAG, folding
34525cf2275ff7de3de3bc0e508abaf457413d74725Duncan Sands  /// certain types of nodes together, or eliminating superfluous nodes.  The
34625cf2275ff7de3de3bc0e508abaf457413d74725Duncan Sands  /// Level argument controls whether Combine is allowed to produce nodes and
34725cf2275ff7de3de3bc0e508abaf457413d74725Duncan Sands  /// types that are illegal on the target.
34898a366d547772010e94609e4584489b3e5ce0043Bill Wendling  void Combine(CombineLevel Level, AliasAnalysis &AA,
34998a366d547772010e94609e4584489b3e5ce0043Bill Wendling               CodeGenOpt::Level OptLevel);
35025cf2275ff7de3de3bc0e508abaf457413d74725Duncan Sands
35101d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that
35225cf2275ff7de3de3bc0e508abaf457413d74725Duncan Sands  /// only uses types natively supported by the target.  Returns "true" if it
35325cf2275ff7de3de3bc0e508abaf457413d74725Duncan Sands  /// made any changes.
35401d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  ///
35501d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// Note that this is an involved process that may invalidate pointers into
35601d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// the graph.
35725cf2275ff7de3de3bc0e508abaf457413d74725Duncan Sands  bool LegalizeTypes();
35825cf2275ff7de3de3bc0e508abaf457413d74725Duncan Sands
359c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
360c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// compatible with the target instruction selector, as indicated by the
361c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// TargetLowering object.
362cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
363c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Note that this is an involved process that may invalidate pointers into
364c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// the graph.
365975716af1b9a09274df6c2d92683449015bd8564Dan Gohman  void Legalize();
366c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
3675c22c8074404797f1313b1334757254fb5c6487aEli Friedman  /// LegalizeVectors - This transforms the SelectionDAG into a SelectionDAG
3685c22c8074404797f1313b1334757254fb5c6487aEli Friedman  /// that only uses vector math operations supported by the target.  This is
3695c22c8074404797f1313b1334757254fb5c6487aEli Friedman  /// necessary as a separate step from Legalize because unrolling a vector
3705c22c8074404797f1313b1334757254fb5c6487aEli Friedman  /// operation can introduce illegal types, which requires running
3715c22c8074404797f1313b1334757254fb5c6487aEli Friedman  /// LegalizeTypes again.
3725c22c8074404797f1313b1334757254fb5c6487aEli Friedman  ///
3735c22c8074404797f1313b1334757254fb5c6487aEli Friedman  /// This returns true if it made any changes; in that case, LegalizeTypes
3745c22c8074404797f1313b1334757254fb5c6487aEli Friedman  /// is called again before Legalize.
3755c22c8074404797f1313b1334757254fb5c6487aEli Friedman  ///
3765c22c8074404797f1313b1334757254fb5c6487aEli Friedman  /// Note that this is an involved process that may invalidate pointers into
3775c22c8074404797f1313b1334757254fb5c6487aEli Friedman  /// the graph.
3785c22c8074404797f1313b1334757254fb5c6487aEli Friedman  bool LegalizeVectors();
3795c22c8074404797f1313b1334757254fb5c6487aEli Friedman
380d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner  /// RemoveDeadNodes - This method deletes all unreachable nodes in the
381190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  /// SelectionDAG.
382190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  void RemoveDeadNodes();
383130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng
384130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// DeleteNode - Remove the specified node from the system.  This node must
385130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// have no referrers.
386130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  void DeleteNode(SDNode *N);
387130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng
38870046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// getVTList - Return an SDVTList that represents the list of values
38970046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// specified.
390e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDVTList getVTList(EVT VT);
391e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDVTList getVTList(EVT VT1, EVT VT2);
392e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3);
393e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3, EVT VT4);
394dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  SDVTList getVTList(ArrayRef<EVT> VTs);
395fdc40a0a696c658d550d894ea03772e5f8af2c94Scott Michel
3961b1a49714ef26225a42199cf2930529f31868322Chris Lattner  //===--------------------------------------------------------------------===//
39770046e920fa37989a041af663ada2b2b646e258fChris Lattner  // Node creation methods.
39870046e920fa37989a041af663ada2b2b646e258fChris Lattner  //
39936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue getConstant(uint64_t Val, EVT VT, bool isTarget = false,
40036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                      bool isOpaque = false);
40136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue getConstant(const APInt &Val, EVT VT, bool isTarget = false,
40236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                      bool isOpaque = false);
40336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue getConstant(const ConstantInt &Val, EVT VT, bool isTarget = false,
40436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                      bool isOpaque = false);
405475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getIntPtrConstant(uint64_t Val, bool isTarget = false);
40636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue getTargetConstant(uint64_t Val, EVT VT, bool isOpaque = false) {
40736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return getConstant(Val, VT, true, isOpaque);
408cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
40936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue getTargetConstant(const APInt &Val, EVT VT, bool isOpaque = false) {
41036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return getConstant(Val, VT, true, isOpaque);
4116394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman  }
41236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue getTargetConstant(const ConstantInt &Val, EVT VT,
41336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                            bool isOpaque = false) {
41436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return getConstant(Val, VT, true, isOpaque);
4154fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman  }
4160a406ae0d940d92c51ee145b48ff7a483a366849Dale Johannesen  // The forms below that take a double should only be used for simple
4170a406ae0d940d92c51ee145b48ff7a483a366849Dale Johannesen  // constants that can be exactly represented in VT.  No checks are made.
418e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getConstantFP(double Val, EVT VT, bool isTarget = false);
419e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getConstantFP(const APFloat& Val, EVT VT, bool isTarget = false);
420e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getConstantFP(const ConstantFP &CF, EVT VT, bool isTarget = false);
421e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getTargetConstantFP(double Val, EVT VT) {
422c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getConstantFP(Val, VT, true);
423c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
424e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getTargetConstantFP(const APFloat& Val, EVT VT) {
425f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen    return getConstantFP(Val, VT, true);
426f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen  }
427e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getTargetConstantFP(const ConstantFP &Val, EVT VT) {
4284fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman    return getConstantFP(Val, VT, true);
4294fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman  }
430ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getGlobalAddress(const GlobalValue *GV, SDLoc DL, EVT VT,
4312a4ed82ce2ba4a02f2a02eb4ed8ce5186f3f93daChris Lattner                           int64_t offset = 0, bool isTargetGA = false,
4322a4ed82ce2ba4a02f2a02eb4ed8ce5186f3f93daChris Lattner                           unsigned char TargetFlags = 0);
433ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getTargetGlobalAddress(const GlobalValue *GV, SDLoc DL, EVT VT,
4342a4ed82ce2ba4a02f2a02eb4ed8ce5186f3f93daChris Lattner                                 int64_t offset = 0,
4352a4ed82ce2ba4a02f2a02eb4ed8ce5186f3f93daChris Lattner                                 unsigned char TargetFlags = 0) {
4360d881dabc1a4e1aefad6dd38de166d8358285638Devang Patel    return getGlobalAddress(GV, DL, VT, offset, true, TargetFlags);
437cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
438e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getFrameIndex(int FI, EVT VT, bool isTarget = false);
439e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getTargetFrameIndex(int FI, EVT VT) {
440c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getFrameIndex(FI, VT, true);
441c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
442e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getJumpTable(int JTI, EVT VT, bool isTarget = false,
443f5a5546f435a261c93078defb41ed18d9cafd7d3Chris Lattner                       unsigned char TargetFlags = 0);
444e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getTargetJumpTable(int JTI, EVT VT, unsigned char TargetFlags = 0) {
445f5a5546f435a261c93078defb41ed18d9cafd7d3Chris Lattner    return getJumpTable(JTI, VT, true, TargetFlags);
446c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
44746510a73e977273ec67747eb34cbdb43f815e451Dan Gohman  SDValue getConstantPool(const Constant *C, EVT VT,
448f5a5546f435a261c93078defb41ed18d9cafd7d3Chris Lattner                          unsigned Align = 0, int Offs = 0, bool isT=false,
449f5a5546f435a261c93078defb41ed18d9cafd7d3Chris Lattner                          unsigned char TargetFlags = 0);
45046510a73e977273ec67747eb34cbdb43f815e451Dan Gohman  SDValue getTargetConstantPool(const Constant *C, EVT VT,
451f5a5546f435a261c93078defb41ed18d9cafd7d3Chris Lattner                                unsigned Align = 0, int Offset = 0,
452f5a5546f435a261c93078defb41ed18d9cafd7d3Chris Lattner                                unsigned char TargetFlags = 0) {
453f5a5546f435a261c93078defb41ed18d9cafd7d3Chris Lattner    return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
454c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
455e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getConstantPool(MachineConstantPoolValue *C, EVT VT,
456f5a5546f435a261c93078defb41ed18d9cafd7d3Chris Lattner                          unsigned Align = 0, int Offs = 0, bool isT=false,
457f5a5546f435a261c93078defb41ed18d9cafd7d3Chris Lattner                          unsigned char TargetFlags = 0);
458475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getTargetConstantPool(MachineConstantPoolValue *C,
459e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson                                  EVT VT, unsigned Align = 0,
460f5a5546f435a261c93078defb41ed18d9cafd7d3Chris Lattner                                  int Offset = 0, unsigned char TargetFlags=0) {
461f5a5546f435a261c93078defb41ed18d9cafd7d3Chris Lattner    return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
462d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
46374500bdba3eae36a1a8a17d8bad0b971b9c212ecJakob Stoklund Olesen  SDValue getTargetIndex(int Index, EVT VT, int64_t Offset = 0,
46474500bdba3eae36a1a8a17d8bad0b971b9c212ecJakob Stoklund Olesen                         unsigned char TargetFlags = 0);
4658ad9b43e690e8773cf836b30e8da26bc71e18844Dale Johannesen  // When generating a branch to a BB, we don't in general know enough
4668ad9b43e690e8773cf836b30e8da26bc71e18844Dale Johannesen  // to provide debug info for the BB at that time, so keep this one around.
467475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getBasicBlock(MachineBasicBlock *MBB);
468ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getBasicBlock(MachineBasicBlock *MBB, SDLoc dl);
469e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getExternalSymbol(const char *Sym, EVT VT);
470ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getExternalSymbol(const char *Sym, SDLoc dl, EVT VT);
471e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getTargetExternalSymbol(const char *Sym, EVT VT,
4721af2231da64a14d638406d133c7912bfc1c8a9ceChris Lattner                                  unsigned char TargetFlags = 0);
473e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getValueType(EVT);
474e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getRegister(unsigned Reg, EVT VT);
4759cf37e8b48732fccd4c301ed51aafed7074bd84eJakob Stoklund Olesen  SDValue getRegisterMask(const uint32_t *RegMask);
476ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getEHLabel(SDLoc dl, SDValue Root, MCSymbol *Label);
47746510a73e977273ec67747eb34cbdb43f815e451Dan Gohman  SDValue getBlockAddress(const BlockAddress *BA, EVT VT,
4786c7ccaa3fd1d6e96d0bf922554b09d2b17c3b0e3Michael Liao                          int64_t Offset = 0, bool isTarget = false,
4796c7ccaa3fd1d6e96d0bf922554b09d2b17c3b0e3Michael Liao                          unsigned char TargetFlags = 0);
4806c7ccaa3fd1d6e96d0bf922554b09d2b17c3b0e3Michael Liao  SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT,
4816c7ccaa3fd1d6e96d0bf922554b09d2b17c3b0e3Michael Liao                                int64_t Offset = 0,
4826c7ccaa3fd1d6e96d0bf922554b09d2b17c3b0e3Michael Liao                                unsigned char TargetFlags = 0) {
4836c7ccaa3fd1d6e96d0bf922554b09d2b17c3b0e3Michael Liao    return getBlockAddress(BA, VT, Offset, true, TargetFlags);
4846c7ccaa3fd1d6e96d0bf922554b09d2b17c3b0e3Michael Liao  }
485c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
486ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getCopyToReg(SDValue Chain, SDLoc dl, unsigned Reg, SDValue N) {
487825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson    return getNode(ISD::CopyToReg, dl, MVT::Other, Chain,
4880f502f6f44f2756f5cb7b17d8f1d8eae000d51b4Dale Johannesen                   getRegister(Reg, N.getValueType()), N);
4890f502f6f44f2756f5cb7b17d8f1d8eae000d51b4Dale Johannesen  }
490cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
491e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyToReg method takes an extra operand, which
49229d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner  // indicates that there is potentially an incoming glue value (if Glue is not
49329d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner  // null) and that there should be a glue result.
494ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getCopyToReg(SDValue Chain, SDLoc dl, unsigned Reg, SDValue N,
49529d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner                       SDValue Glue) {
496f1b4eafbfec976f939ec0ea3e8acf91cef5363e3Chris Lattner    SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
49729d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner    SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Glue };
498dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return getNode(ISD::CopyToReg, dl, VTs,
499dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                   ArrayRef<SDValue>(Ops, Glue.getNode() ? 4 : 3));
5000f502f6f44f2756f5cb7b17d8f1d8eae000d51b4Dale Johannesen  }
50166a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng
502475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  // Similar to last getCopyToReg() except parameter Reg is a SDValue
503ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getCopyToReg(SDValue Chain, SDLoc dl, SDValue Reg, SDValue N,
50429d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner                         SDValue Glue) {
505f1b4eafbfec976f939ec0ea3e8acf91cef5363e3Chris Lattner    SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
50629d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner    SDValue Ops[] = { Chain, Reg, N, Glue };
507dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return getNode(ISD::CopyToReg, dl, VTs,
508dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                   ArrayRef<SDValue>(Ops, Glue.getNode() ? 4 : 3));
5090f502f6f44f2756f5cb7b17d8f1d8eae000d51b4Dale Johannesen  }
510fdc40a0a696c658d550d894ea03772e5f8af2c94Scott Michel
511ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getCopyFromReg(SDValue Chain, SDLoc dl, unsigned Reg, EVT VT) {
512825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson    SDVTList VTs = getVTList(VT, MVT::Other);
5130f502f6f44f2756f5cb7b17d8f1d8eae000d51b4Dale Johannesen    SDValue Ops[] = { Chain, getRegister(Reg, VT) };
514dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return getNode(ISD::CopyFromReg, dl, VTs, Ops);
5150f502f6f44f2756f5cb7b17d8f1d8eae000d51b4Dale Johannesen  }
516fdc40a0a696c658d550d894ea03772e5f8af2c94Scott Michel
517e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyFromReg method takes an extra operand, which
51829d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner  // indicates that there is potentially an incoming glue value (if Glue is not
51929d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner  // null) and that there should be a glue result.
520ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getCopyFromReg(SDValue Chain, SDLoc dl, unsigned Reg, EVT VT,
52129d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner                           SDValue Glue) {
522f1b4eafbfec976f939ec0ea3e8acf91cef5363e3Chris Lattner    SDVTList VTs = getVTList(VT, MVT::Other, MVT::Glue);
52329d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner    SDValue Ops[] = { Chain, getRegister(Reg, VT), Glue };
524dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return getNode(ISD::CopyFromReg, dl, VTs,
525dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                   ArrayRef<SDValue>(Ops, Glue.getNode() ? 3 : 2));
5260f502f6f44f2756f5cb7b17d8f1d8eae000d51b4Dale Johannesen  }
52718c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner
528475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getCondCode(ISD::CondCode Cond);
529cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
53077cdf30742284a173fe818417eb482224cdee8d4Mon P Wang  /// Returns the ConvertRndSat Note: Avoid using this node because it may
53177cdf30742284a173fe818417eb482224cdee8d4Mon P Wang  /// disappear in the future and most targets don't support it.
532ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getConvertRndSat(EVT VT, SDLoc dl, SDValue Val, SDValue DTy,
5330f502f6f44f2756f5cb7b17d8f1d8eae000d51b4Dale Johannesen                           SDValue STy,
5340f502f6f44f2756f5cb7b17d8f1d8eae000d51b4Dale Johannesen                           SDValue Rnd, SDValue Sat, ISD::CvtCode Code);
5356154f6c9292179fab6346ae8336f2ad790b52028Owen Anderson
5369008ca6b6b4f638cfafccb593cbc5b1d3f5ab877Nate Begeman  /// getVectorShuffle - Return an ISD::VECTOR_SHUFFLE node.  The number of
5379008ca6b6b4f638cfafccb593cbc5b1d3f5ab877Nate Begeman  /// elements in VT, which must be a vector type, must match the number of
5385a5ca1519e04310f585197c20e7ae584b7f2d11fNate Begeman  /// mask elements NumElts.  A integer mask element equal to -1 is treated as
5399008ca6b6b4f638cfafccb593cbc5b1d3f5ab877Nate Begeman  /// undefined.
540ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getVectorShuffle(EVT VT, SDLoc dl, SDValue N1, SDValue N2,
5419008ca6b6b4f638cfafccb593cbc5b1d3f5ab877Nate Begeman                           const int *MaskElts);
542cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  SDValue getVectorShuffle(EVT VT, SDLoc dl, SDValue N1, SDValue N2,
543cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                           ArrayRef<int> MaskElts) {
544cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    assert(VT.getVectorNumElements() == MaskElts.size() &&
545cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines           "Must have the same number of vector elements as mask elements!");
546cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    return getVectorShuffle(VT, dl, N1, N2, MaskElts.data());
547cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  }
54877cdf30742284a173fe818417eb482224cdee8d4Mon P Wang
549a3c42f3d4e5d14c8f4fb9bb123e7759c425d041bNadav Rotem  /// getAnyExtOrTrunc - Convert Op, which must be of integer type, to the
550a3c42f3d4e5d14c8f4fb9bb123e7759c425d041bNadav Rotem  /// integer type VT, by either any-extending or truncating it.
551ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getAnyExtOrTrunc(SDValue Op, SDLoc DL, EVT VT);
552a3c42f3d4e5d14c8f4fb9bb123e7759c425d041bNadav Rotem
5533a66a68b0cc81193abfc074b1d360a4950151d38Duncan Sands  /// getSExtOrTrunc - Convert Op, which must be of integer type, to the
5543a66a68b0cc81193abfc074b1d360a4950151d38Duncan Sands  /// integer type VT, by either sign-extending or truncating it.
555ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getSExtOrTrunc(SDValue Op, SDLoc DL, EVT VT);
5563a66a68b0cc81193abfc074b1d360a4950151d38Duncan Sands
5573a66a68b0cc81193abfc074b1d360a4950151d38Duncan Sands  /// getZExtOrTrunc - Convert Op, which must be of integer type, to the
5583a66a68b0cc81193abfc074b1d360a4950151d38Duncan Sands  /// integer type VT, by either zero-extending or truncating it.
559ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getZExtOrTrunc(SDValue Op, SDLoc DL, EVT VT);
5603a66a68b0cc81193abfc074b1d360a4950151d38Duncan Sands
5611ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// getZeroExtendInReg - Return the expression required to zero extend the Op
5621ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// value assuming it was the smaller SrcTy value.
563ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getZeroExtendInReg(SDValue Op, SDLoc DL, EVT SrcTy);
564fdc40a0a696c658d550d894ea03772e5f8af2c94Scott Michel
565cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// getAnyExtendVectorInReg - Return an operation which will any-extend the
566cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// low lanes of the operand into the specified vector type. For example,
567cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// this can convert a v16i8 into a v4i32 by any-extending the low four
568cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// lanes of the operand from i8 to i32.
569cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  SDValue getAnyExtendVectorInReg(SDValue Op, SDLoc DL, EVT VT);
570cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
571cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// getSignExtendVectorInReg - Return an operation which will sign extend the
572cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// low lanes of the operand into the specified vector type. For example,
573cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// this can convert a v16i8 into a v4i32 by sign extending the low four
574cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// lanes of the operand from i8 to i32.
575cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  SDValue getSignExtendVectorInReg(SDValue Op, SDLoc DL, EVT VT);
576cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
577cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// getZeroExtendVectorInReg - Return an operation which will zero extend the
578cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// low lanes of the operand into the specified vector type. For example,
579cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// this can convert a v16i8 into a v4i32 by zero extending the low four
580cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// lanes of the operand from i8 to i32.
581cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  SDValue getZeroExtendVectorInReg(SDValue Op, SDLoc DL, EVT VT);
582cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines
583dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  /// getBoolExtOrTrunc - Convert Op, which must be of integer type, to the
584dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  /// integer type VT, by using an extension appropriate for the target's
585cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  /// BooleanContent for type OpVT or truncating it.
586cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  SDValue getBoolExtOrTrunc(SDValue Op, SDLoc SL, EVT VT, EVT OpVT);
587dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
5884c2454623841f05c6c665659b34c214950d12d7eBob Wilson  /// getNOT - Create a bitwise NOT operation as (XOR Val, -1).
589ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNOT(SDLoc DL, SDValue Val, EVT VT);
5904c2454623841f05c6c665659b34c214950d12d7eBob Wilson
591dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  /// \brief Create a logical NOT operation as (XOR Val, BooleanOne).
592dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  SDValue getLogicalNOT(SDLoc DL, SDValue Val, EVT VT);
593dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
5946a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have
59529d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner  /// a glue result (to ensure it's not CSE'd).  CALLSEQ_START does not have a
596ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  /// useful SDLoc.
5976e0b2a0cb0d398f175a5294bf0ad5488c714e8c2Andrew Trick  SDValue getCALLSEQ_START(SDValue Chain, SDValue Op, SDLoc DL) {
598f1b4eafbfec976f939ec0ea3e8acf91cef5363e3Chris Lattner    SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
599475871a144eb604ddaf37503397ba0941442e5fbDan Gohman    SDValue Ops[] = { Chain,  Op };
600dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return getNode(ISD::CALLSEQ_START, DL, VTs, Ops);
6016a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  }
6021ccae666f596d5aeca5c9942995763600b622062Chris Lattner
6030f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  /// getCALLSEQ_END - Return a new CALLSEQ_END node, which always must have a
60429d8f0cae425f1bba583565227eaebf58f26ce73Chris Lattner  /// glue result (to ensure it's not CSE'd).  CALLSEQ_END does not have
605ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  /// a useful SDLoc.
606475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2,
6076e0b2a0cb0d398f175a5294bf0ad5488c714e8c2Andrew Trick                           SDValue InGlue, SDLoc DL) {
608f1b4eafbfec976f939ec0ea3e8acf91cef5363e3Chris Lattner    SDVTList NodeTys = getVTList(MVT::Other, MVT::Glue);
609475871a144eb604ddaf37503397ba0941442e5fbDan Gohman    SmallVector<SDValue, 4> Ops;
6100f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Chain);
6110f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Op1);
6120f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Op2);
613dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    if (InGlue.getNode())
614dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines      Ops.push_back(InGlue);
615dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    return getNode(ISD::CALLSEQ_END, DL, NodeTys, Ops);
6160f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  }
6170f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling
618ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  /// getUNDEF - Return an UNDEF node.  UNDEF does not have a useful SDLoc.
619e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getUNDEF(EVT VT) {
620ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick    return getNode(ISD::UNDEF, SDLoc(), VT);
621e8d7230f480654cdb8ff1c3d0a38e1e9ab0bd55fDale Johannesen  }
622e8d7230f480654cdb8ff1c3d0a38e1e9ab0bd55fDale Johannesen
623b300d2aa3ef08b5074449e2c05804717f488f4e4Dale Johannesen  /// getGLOBAL_OFFSET_TABLE - Return a GLOBAL_OFFSET_TABLE node.  This does
624ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  /// not have a useful SDLoc.
625e50ed30282bb5b4a9ed952580523f2dda16215acOwen Anderson  SDValue getGLOBAL_OFFSET_TABLE(EVT VT) {
626ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick    return getNode(ISD::GLOBAL_OFFSET_TABLE, SDLoc(), VT);
627b300d2aa3ef08b5074449e2c05804717f488f4e4Dale Johannesen  }
628b300d2aa3ef08b5074449e2c05804717f488f4e4Dale Johannesen
629c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getNode - Gets or creates the specified node.
630cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
631ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT);
632ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT, SDValue N);
633cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT, SDValue N1, SDValue N2,
634cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                  bool nuw = false, bool nsw = false, bool exact = false);
635cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT, SDValue N1, SDValue N2,
636cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                  SDValue N3);
637cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT, SDValue N1, SDValue N2,
638cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                  SDValue N3, SDValue N4);
639cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT, SDValue N1, SDValue N2,
640cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines                  SDValue N3, SDValue N4, SDValue N5);
641dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT, ArrayRef<SDUse> Ops);
642ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT,
643dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                  ArrayRef<SDValue> Ops);
644ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNode(unsigned Opcode, SDLoc DL,
6453853f74aba301ef08b699bac2fa8e53230714a58Benjamin Kramer                  ArrayRef<EVT> ResultTys,
646dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                  ArrayRef<SDValue> Ops);
647ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNode(unsigned Opcode, SDLoc DL, SDVTList VTs,
648dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                  ArrayRef<SDValue> Ops);
649ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNode(unsigned Opcode, SDLoc DL, SDVTList VTs);
650ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNode(unsigned Opcode, SDLoc DL, SDVTList VTs, SDValue N);
651ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNode(unsigned Opcode, SDLoc DL, SDVTList VTs,
6527ade28cd62f5188951387e1056a46001388a21f9Bill Wendling                  SDValue N1, SDValue N2);
653ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNode(unsigned Opcode, SDLoc DL, SDVTList VTs,
6547ade28cd62f5188951387e1056a46001388a21f9Bill Wendling                  SDValue N1, SDValue N2, SDValue N3);
655ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNode(unsigned Opcode, SDLoc DL, SDVTList VTs,
6567ade28cd62f5188951387e1056a46001388a21f9Bill Wendling                  SDValue N1, SDValue N2, SDValue N3, SDValue N4);
657ac6d9bec671252dd1e596fa71180ff6b39d06b5dAndrew Trick  SDValue getNode(unsigned Opcode, SDLoc DL, SDVTList VTs,
6587ade28cd62f5188951387e1056a46001388a21f9Bill Wendling                  SDValue N1, SDValue N2, SDValue N3, SDValue N4,
6597ade28cd62f5188951387e1056a46001388a21f9Bill Wendling                  SDValue N5);
660475871a144eb604ddaf37503397ba0941442e5fbDan Gohman
66198ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman  /// getStackArgumentTokenFactor - Compute a TokenFactor to force all
66298ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman  /// the incoming stack arguments to be loaded from the stack. This is
663