SelectionDAG.h revision 4fbd796a1251a27e6590765a0a34876f436a0af9
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 18fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman#include "llvm/ADT/ilist.h" 19583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey#include "llvm/ADT/FoldingSet.h" 204b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman#include "llvm/ADT/StringMap.h" 21583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey#include "llvm/CodeGen/SelectionDAGNodes.h" 22b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner 23acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman#include <cassert> 24109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner#include <list> 255892d47a625638a90afeb31dd4f6f80a2f9bacdeChris Lattner#include <vector> 26322812e603705e1c2037313633e72f689524b163Evan Cheng#include <map> 27eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner#include <string> 28d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 29d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 30fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 31fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass AliasAnalysis; 32fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass TargetLowering; 33fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass TargetMachine; 34fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass MachineModuleInfo; 35fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass MachineFunction; 36fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass MachineConstantPoolValue; 37fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass FunctionLoweringInfo; 38fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 39fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmantemplate<> class ilist_traits<SDNode> : public ilist_default_traits<SDNode> { 40fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman mutable SDNode Sentinel; 41fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanpublic: 42fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman ilist_traits() : Sentinel(ISD::DELETED_NODE, SDVTList()) {} 43fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 44fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman SDNode *createSentinel() const { 45fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman return &Sentinel; 46fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman } 47fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman static void destroySentinel(SDNode *) {} 48fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 49fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman static void deleteNode(SDNode *) { 50fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman assert(0 && "ilist_traits<SDNode> shouldn't see a deleteNode call!"); 51fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman } 52fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanprivate: 53fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman static void createNode(const SDNode &); 54fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman}; 55c3aae25116e66c177579b0b79182b09340b19753Chris Lattner 56c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// SelectionDAG class - This is used to represent a portion of an LLVM function 57c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// in a low-level Data Dependence DAG representation suitable for instruction 58c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection. This DAG is constructed as the first step of instruction 59c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection in order to allow implementation of machine specific optimizations 60c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// and code simplifications. 61c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// 62c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// The representation used by the SelectionDAG is a target-independent 63c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// representation, which has some similarities to the GCC RTL representation, 64c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// but is significantly more simple, powerful, and is a graph form instead of a 65c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// linear form. 66cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner/// 67cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerclass SelectionDAG { 68063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner TargetLowering &TLI; 697c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman MachineFunction *MF; 70ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner FunctionLoweringInfo &FLI; 7144c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey MachineModuleInfo *MMI; 72cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 73f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman /// EntryNode - The starting token. 74f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman SDNode EntryNode; 75f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman 76f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman /// Root - The root of the entire DAG. 77f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman SDValue Root; 78cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 79213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner /// AllNodes - A linked list of nodes in the current DAG. 80fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman ilist<SDNode> AllNodes; 81fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 82f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman /// NodeAllocatorType - The AllocatorType for allocating SDNodes. We use 83f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman /// pool allocation with recycling. 84f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman typedef RecyclingAllocator<BumpPtrAllocator, SDNode, sizeof(LargestSDNode), 85f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman AlignOf<MostAlignedSDNode>::Alignment> 86f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman NodeAllocatorType; 87f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman 88f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman /// NodeAllocator - Pool allocation for nodes. 89f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman NodeAllocatorType NodeAllocator; 90691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth 91213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner /// CSEMap - This structure is used to memoize nodes, automatically performing 92213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner /// CSE with existing nodes with a duplicate is requested. 93583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey FoldingSet<SDNode> CSEMap; 94213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner 95f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman /// OperandAllocator - Pool allocation for machine-opcode SDNode operands. 96f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman BumpPtrAllocator OperandAllocator; 97f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman 98e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// Allocator - Pool allocation for misc. objects that are created once per 99e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// SelectionDAG. 100e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman BumpPtrAllocator Allocator; 101e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman 102d038e04188047eca4749d025ef1f05f7ae660bcaDuncan Sands /// VerifyNode - Sanity check the given node. Aborts if it is invalid. 103d038e04188047eca4749d025ef1f05f7ae660bcaDuncan Sands void VerifyNode(SDNode *N); 104d038e04188047eca4749d025ef1f05f7ae660bcaDuncan Sands 105cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerpublic: 1067c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman SelectionDAG(TargetLowering &tli, FunctionLoweringInfo &fli); 107cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner ~SelectionDAG(); 108cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 1097c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman /// init - Prepare this SelectionDAG to process code in the given 1107c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman /// MachineFunction. 1117c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman /// 1127c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman void init(MachineFunction &mf, MachineModuleInfo *mmi); 1137c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman 1147c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman /// clear - Clear state and free memory necessary to make this 115f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman /// SelectionDAG ready to process a new block. 116f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman /// 1177c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman void clear(); 118f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman 1197c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman MachineFunction &getMachineFunction() const { return *MF; } 120063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner const TargetMachine &getTarget() const; 121063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner TargetLowering &getTargetLoweringInfo() const { return TLI; } 122ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner FunctionLoweringInfo &getFunctionLoweringInfo() const { return FLI; } 12344c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey MachineModuleInfo *getMachineModuleInfo() const { return MMI; } 124cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 125ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'. 1261080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner /// 127462dc7f4960e5074ddf4769ec8b2ef1ba7a4d2c8Dan Gohman void viewGraph(const std::string &Title); 1280b12aef49087b57d276ed760a83525d1e2602144Dan Gohman void viewGraph(); 129ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey 130ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#ifndef NDEBUG 131ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey std::map<const SDNode *, std::string> NodeGraphAttrs; 132ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#endif 1331080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner 134ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// clearGraphAttrs - Clear all previously defined node graph attributes. 135ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// Intended to be used from a debugging tool (eg. gdb). 136ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey void clearGraphAttrs(); 137ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey 138ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".) 139ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// 140ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey void setGraphAttrs(const SDNode *N, const char *Attrs); 141ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey 142ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".) 143ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// Used from getNodeAttributes. 144ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey const std::string getGraphAttrs(const SDNode *N) const; 145ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey 146ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// setGraphColor - Convenience for setting node color attribute. 147ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// 148ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey void setGraphColor(const SDNode *N, const char *Color); 1491080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner 150fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman typedef ilist<SDNode>::const_iterator allnodes_const_iterator; 151b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); } 152b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner allnodes_const_iterator allnodes_end() const { return AllNodes.end(); } 153fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman typedef ilist<SDNode>::iterator allnodes_iterator; 154b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner allnodes_iterator allnodes_begin() { return AllNodes.begin(); } 155b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner allnodes_iterator allnodes_end() { return AllNodes.end(); } 156fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman ilist<SDNode>::size_type allnodes_size() const { 1570e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman return AllNodes.size(); 1580e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman } 159b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner 160c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// getRoot - Return the root tag of the SelectionDAG. 161cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner /// 162475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue &getRoot() const { return Root; } 163cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 164c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// getEntryNode - Return the token chain corresponding to the entry of the 165c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// function. 166f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman SDValue getEntryNode() const { 167f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman return SDValue(const_cast<SDNode *>(&EntryNode), 0); 168f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman } 169cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 170c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// setRoot - Set the current root tag of the SelectionDAG. 171cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner /// 172475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue &setRoot(SDValue N) { 173ba36cb5242eb02b12b277f82b9efe497f7da4d7fGabor Greif assert((!N.getNode() || N.getValueType() == MVT::Other) && 174acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman "DAG root value is not a chain!"); 175acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman return Root = N; 176acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman } 177cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 1781d4d41411190dd9e62764e56713753d4155764ddNate Begeman /// Combine - This iterates over the nodes in the SelectionDAG, folding 1791d4d41411190dd9e62764e56713753d4155764ddNate Begeman /// certain types of nodes together, or eliminating superfluous nodes. When 1801d4d41411190dd9e62764e56713753d4155764ddNate Begeman /// the AfterLegalize argument is set to 'true', Combine takes care not to 1811d4d41411190dd9e62764e56713753d4155764ddNate Begeman /// generate any nodes that will be illegal on the target. 182a267651b7ec4f96e01b31f541d446758bf8da8a9Dan Gohman void Combine(bool AfterLegalize, AliasAnalysis &AA, bool Fast); 1831d4d41411190dd9e62764e56713753d4155764ddNate Begeman 18401d029b82cb08367d81aa10cdc94d05360466649Chris Lattner /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that 18501d029b82cb08367d81aa10cdc94d05360466649Chris Lattner /// only uses types natively supported by the target. 18601d029b82cb08367d81aa10cdc94d05360466649Chris Lattner /// 18701d029b82cb08367d81aa10cdc94d05360466649Chris Lattner /// Note that this is an involved process that may invalidate pointers into 18801d029b82cb08367d81aa10cdc94d05360466649Chris Lattner /// the graph. 18901d029b82cb08367d81aa10cdc94d05360466649Chris Lattner void LegalizeTypes(); 19001d029b82cb08367d81aa10cdc94d05360466649Chris Lattner 191c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is 192c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// compatible with the target instruction selector, as indicated by the 193c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// TargetLowering object. 194cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner /// 195c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// Note that this is an involved process that may invalidate pointers into 196c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// the graph. 197063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner void Legalize(); 198c3aae25116e66c177579b0b79182b09340b19753Chris Lattner 199d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner /// RemoveDeadNodes - This method deletes all unreachable nodes in the 200190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner /// SelectionDAG. 201190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner void RemoveDeadNodes(); 202130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng 203130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng /// DeleteNode - Remove the specified node from the system. This node must 204130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng /// have no referrers. 205130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng void DeleteNode(SDNode *N); 206130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng 20770046e920fa37989a041af663ada2b2b646e258fChris Lattner /// getVTList - Return an SDVTList that represents the list of values 20870046e920fa37989a041af663ada2b2b646e258fChris Lattner /// specified. 20983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDVTList getVTList(MVT VT); 21083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDVTList getVTList(MVT VT1, MVT VT2); 21183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDVTList getVTList(MVT VT1, MVT VT2, MVT VT3); 21283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDVTList getVTList(const MVT *VTs, unsigned NumVTs); 21370046e920fa37989a041af663ada2b2b646e258fChris Lattner 21470046e920fa37989a041af663ada2b2b646e258fChris Lattner /// getNodeValueTypes - These are obsolete, use getVTList instead. 21583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *getNodeValueTypes(MVT VT) { 21670046e920fa37989a041af663ada2b2b646e258fChris Lattner return getVTList(VT).VTs; 21770046e920fa37989a041af663ada2b2b646e258fChris Lattner } 21883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *getNodeValueTypes(MVT VT1, MVT VT2) { 21970046e920fa37989a041af663ada2b2b646e258fChris Lattner return getVTList(VT1, VT2).VTs; 22070046e920fa37989a041af663ada2b2b646e258fChris Lattner } 22183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *getNodeValueTypes(MVT VT1, MVT VT2, MVT VT3) { 22270046e920fa37989a041af663ada2b2b646e258fChris Lattner return getVTList(VT1, VT2, VT3).VTs; 22370046e920fa37989a041af663ada2b2b646e258fChris Lattner } 224f877b735ad4987f26cafcbaf22aa4c2199458b5dDan Gohman const MVT *getNodeValueTypes(const std::vector<MVT> &vtList) { 22513d57320bd212483463d4f8992d5787b29eda5dfBill Wendling return getVTList(&vtList[0], (unsigned)vtList.size()).VTs; 22670046e920fa37989a041af663ada2b2b646e258fChris Lattner } 22770046e920fa37989a041af663ada2b2b646e258fChris Lattner 22870046e920fa37989a041af663ada2b2b646e258fChris Lattner 2291b1a49714ef26225a42199cf2930529f31868322Chris Lattner //===--------------------------------------------------------------------===// 23070046e920fa37989a041af663ada2b2b646e258fChris Lattner // Node creation methods. 23170046e920fa37989a041af663ada2b2b646e258fChris Lattner // 232475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstant(uint64_t Val, MVT VT, bool isTarget = false); 233475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstant(const APInt &Val, MVT VT, bool isTarget = false); 2344fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman SDValue getConstant(const ConstantInt &Val, MVT VT, bool isTarget = false); 235475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getIntPtrConstant(uint64_t Val, bool isTarget = false); 236475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstant(uint64_t Val, MVT VT) { 237cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner return getConstant(Val, VT, true); 238cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner } 239475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstant(const APInt &Val, MVT VT) { 2406394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman return getConstant(Val, VT, true); 2416394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman } 2424fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman SDValue getTargetConstant(const ConstantInt &Val, MVT VT) { 2434fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman return getConstant(Val, VT, true); 2444fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman } 245475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstantFP(double Val, MVT VT, bool isTarget = false); 246475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstantFP(const APFloat& Val, MVT VT, bool isTarget = false); 2474fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman SDValue getConstantFP(const ConstantFP &CF, MVT VT, bool isTarget = false); 248475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstantFP(double Val, MVT VT) { 249c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner return getConstantFP(Val, VT, true); 250c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner } 251475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstantFP(const APFloat& Val, MVT VT) { 252f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen return getConstantFP(Val, VT, true); 253f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen } 2544fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman SDValue getTargetConstantFP(const ConstantFP &Val, MVT VT) { 2554fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman return getConstantFP(Val, VT, true); 2564fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman } 257475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getGlobalAddress(const GlobalValue *GV, MVT VT, 258cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner int offset = 0, bool isTargetGA = false); 259475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetGlobalAddress(const GlobalValue *GV, MVT VT, 260cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner int offset = 0) { 261cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner return getGlobalAddress(GV, VT, offset, true); 262cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner } 263475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getFrameIndex(int FI, MVT VT, bool isTarget = false); 264475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetFrameIndex(int FI, MVT VT) { 265c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner return getFrameIndex(FI, VT, true); 266c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner } 267475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getJumpTable(int JTI, MVT VT, bool isTarget = false); 268475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetJumpTable(int JTI, MVT VT) { 269c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner return getJumpTable(JTI, VT, true); 270c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner } 271475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstantPool(Constant *C, MVT VT, 272c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner unsigned Align = 0, int Offs = 0, bool isT=false); 273475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstantPool(Constant *C, MVT VT, 274c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner unsigned Align = 0, int Offset = 0) { 275c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner return getConstantPool(C, VT, Align, Offset, true); 276c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner } 277475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstantPool(MachineConstantPoolValue *C, MVT VT, 278d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng unsigned Align = 0, int Offs = 0, bool isT=false); 279475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstantPool(MachineConstantPoolValue *C, 28083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands MVT VT, unsigned Align = 0, 281d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng int Offset = 0) { 282d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng return getConstantPool(C, VT, Align, Offset, true); 283d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng } 284475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getBasicBlock(MachineBasicBlock *MBB); 285475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getExternalSymbol(const char *Sym, MVT VT); 286475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetExternalSymbol(const char *Sym, MVT VT); 287475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getArgFlags(ISD::ArgFlagsTy Flags); 288475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getValueType(MVT); 289475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getRegister(unsigned Reg, MVT VT); 290475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getDbgStopPoint(SDValue Root, unsigned Line, unsigned Col, 2917f460203b0c5350e9b2c592f438e40f7a7de6e45Dan Gohman const CompileUnitDesc *CU); 292475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getLabel(unsigned Opcode, SDValue Root, unsigned LabelID); 293c3aae25116e66c177579b0b79182b09340b19753Chris Lattner 294475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCopyToReg(SDValue Chain, unsigned Reg, SDValue N) { 295d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner return getNode(ISD::CopyToReg, MVT::Other, Chain, 296d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner getRegister(Reg, N.getValueType()), N); 297cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner } 298cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 299e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // This version of the getCopyToReg method takes an extra operand, which 300e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // indicates that there is potentially an incoming flag value (if Flag is not 301e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // null) and that there should be a flag result. 302475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCopyToReg(SDValue Chain, unsigned Reg, SDValue N, 303475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Flag) { 30483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag); 305475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag }; 306ba36cb5242eb02b12b277f82b9efe497f7da4d7fGabor Greif return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.getNode() ? 4 : 3); 307e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner } 30866a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng 309475871a144eb604ddaf37503397ba0941442e5fbDan Gohman // Similar to last getCopyToReg() except parameter Reg is a SDValue 310475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCopyToReg(SDValue Chain, SDValue Reg, SDValue N, 311475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Flag) { 31283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag); 313475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ops[] = { Chain, Reg, N, Flag }; 314ba36cb5242eb02b12b277f82b9efe497f7da4d7fGabor Greif return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.getNode() ? 4 : 3); 31566a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng } 316e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner 317475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCopyFromReg(SDValue Chain, unsigned Reg, MVT VT) { 31883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *VTs = getNodeValueTypes(VT, MVT::Other); 319475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ops[] = { Chain, getRegister(Reg, VT) }; 3202fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner return getNode(ISD::CopyFromReg, VTs, 2, Ops, 2); 32118c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner } 322e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner 323e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // This version of the getCopyFromReg method takes an extra operand, which 324e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // indicates that there is potentially an incoming flag value (if Flag is not 325e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // null) and that there should be a flag result. 326475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCopyFromReg(SDValue Chain, unsigned Reg, MVT VT, 327475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Flag) { 32883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *VTs = getNodeValueTypes(VT, MVT::Other, MVT::Flag); 329475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ops[] = { Chain, getRegister(Reg, VT), Flag }; 330ba36cb5242eb02b12b277f82b9efe497f7da4d7fGabor Greif return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.getNode() ? 3 : 2); 331e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner } 33218c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner 333475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCondCode(ISD::CondCode Cond); 334cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 3351ccae666f596d5aeca5c9942995763600b622062Chris Lattner /// getZeroExtendInReg - Return the expression required to zero extend the Op 3361ccae666f596d5aeca5c9942995763600b622062Chris Lattner /// value assuming it was the smaller SrcTy value. 337475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getZeroExtendInReg(SDValue Op, MVT SrcTy); 3386a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner 3396a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have 3406a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner /// a flag result (to ensure it's not CSE'd). 341475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCALLSEQ_START(SDValue Chain, SDValue Op) { 34283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag); 343475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ops[] = { Chain, Op }; 3442fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner return getNode(ISD::CALLSEQ_START, VTs, 2, Ops, 2); 3456a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner } 3461ccae666f596d5aeca5c9942995763600b622062Chris Lattner 3470f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling /// getCALLSEQ_END - Return a new CALLSEQ_END node, which always must have a 3480f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling /// flag result (to ensure it's not CSE'd). 349475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, 350475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue InFlag) { 3510f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling SDVTList NodeTys = getVTList(MVT::Other, MVT::Flag); 352475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SmallVector<SDValue, 4> Ops; 3530f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling Ops.push_back(Chain); 3540f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling Ops.push_back(Op1); 3550f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling Ops.push_back(Op2); 3560f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling Ops.push_back(InFlag); 3570f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling return getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0], 358ba36cb5242eb02b12b277f82b9efe497f7da4d7fGabor Greif (unsigned)Ops.size() - (InFlag.getNode() == 0 ? 1 : 0)); 3590f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling } 3600f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling 361c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// getNode - Gets or creates the specified node. 362cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner /// 363475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT); 364475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, SDValue N); 365475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, SDValue N1, SDValue N2); 366475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, 367475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3); 368475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, 369475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3, SDValue N4); 370475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, 371475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3, SDValue N4, 372475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N5); 373475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, 374475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 375475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, 3766d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman const SDUse *Ops, unsigned NumOps); 377475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, const std::vector<MVT> &ResultTys, 378475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 379475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, const MVT *VTs, unsigned NumVTs, 380475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 381475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs); 382475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, SDValue N); 383475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, SDValue N1, SDValue N2); 384475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, 385475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3); 386475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, 387475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3, SDValue N4); 388475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, 389475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3, SDValue N4, 390475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N5); 391475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, 392475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 393475871a144eb604ddaf37503397ba0941442e5fbDan Gohman 394475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMemcpy(SDValue Chain, SDValue Dst, SDValue Src, 395475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Size, unsigned Align, 396707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman bool AlwaysInline, 3971f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman const Value *DstSV, uint64_t DstSVOff, 3981f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman const Value *SrcSV, uint64_t SrcSVOff); 3995c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola 400475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMemmove(SDValue Chain, SDValue Dst, SDValue Src, 401475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Size, unsigned Align, 4021f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman const Value *DstSV, uint64_t DstOSVff, 4031f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman const Value *SrcSV, uint64_t SrcSVOff); 4045c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola 405475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMemset(SDValue Chain, SDValue Dst, SDValue Src, 406475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Size, unsigned Align, 4071f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman const Value *DstSV, uint64_t DstSVOff); 4085c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola 4097cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner /// getSetCC - Helper function to make it easier to build SetCC's if you just 410475871a144eb604ddaf37503397ba0941442e5fbDan Gohman /// have an ISD::CondCode instead of an SDValue. 4117cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner /// 412475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getSetCC(MVT VT, SDValue LHS, SDValue RHS, 4137cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner ISD::CondCode Cond) { 4147cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond)); 415b43e9c196542acc80c9e4643809661065710848fNate Begeman } 416b43e9c196542acc80c9e4643809661065710848fNate Begeman 417b43e9c196542acc80c9e4643809661065710848fNate Begeman /// getVSetCC - Helper function to make it easier to build VSetCC's nodes 418475871a144eb604ddaf37503397ba0941442e5fbDan Gohman /// if you just have an ISD::CondCode instead of an SDValue. 419b43e9c196542acc80c9e4643809661065710848fNate Begeman /// 420475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getVSetCC(MVT VT, SDValue LHS, SDValue RHS, 421b43e9c196542acc80c9e4643809661065710848fNate Begeman ISD::CondCode Cond) { 422b43e9c196542acc80c9e4643809661065710848fNate Begeman return getNode(ISD::VSETCC, VT, LHS, RHS, getCondCode(Cond)); 4237cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner } 4249373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman 4259373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman /// getSelectCC - Helper function to make it easier to build SelectCC's if you 426475871a144eb604ddaf37503397ba0941442e5fbDan Gohman /// just have an ISD::CondCode instead of an SDValue. 4279373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman /// 428475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getSelectCC(SDValue LHS, SDValue RHS, 429475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue True, SDValue False, ISD::CondCode Cond) { 4302fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner return getNode(ISD::SELECT_CC, True.getValueType(), LHS, RHS, True, False, 4312fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner getCondCode(Cond)); 4329373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman } 4337cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner 434acc398c195a697795bff3245943d104eb19192b9Nate Begeman /// getVAArg - VAArg produces a result and token chain, and takes a pointer 435acc398c195a697795bff3245943d104eb19192b9Nate Begeman /// and a source value as input. 436475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getVAArg(MVT VT, SDValue Chain, SDValue Ptr, 437475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue SV); 4387cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman 439ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth /// getAtomic - Gets a node for an atomic op, produces result and chain, takes 44028873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang /// 3 operands 441475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getAtomic(unsigned Opcode, SDValue Chain, SDValue Ptr, 442475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Cmp, SDValue Swp, const Value* PtrVal, 44328873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang unsigned Alignment=0); 444ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth 445ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth /// getAtomic - Gets a node for an atomic op, produces result and chain, takes 44628873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang /// 2 operands 447475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getAtomic(unsigned Opcode, SDValue Chain, SDValue Ptr, 448475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Val, const Value* PtrVal, 44928873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang unsigned Alignment = 0); 450ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth 4514bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands /// getMergeValues - Create a MERGE_VALUES node from the given operands. 4524bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands /// Allowed to return something different (and simpler) if Simplify is true. 453475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMergeValues(const SDValue *Ops, unsigned NumOps, 4544bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands bool Simplify = true); 4554bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands 456f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands /// getMergeValues - Create a MERGE_VALUES node from the given types and ops. 457f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands /// Allowed to return something different (and simpler) if Simplify is true. 4584bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands /// May be faster than the above version if VTs is known and NumOps is large. 459475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMergeValues(SDVTList VTs, const SDValue *Ops, unsigned NumOps, 460f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands bool Simplify = true) { 461f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands if (Simplify && NumOps == 1) 462f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands return Ops[0]; 463f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands return getNode(ISD::MERGE_VALUES, VTs, Ops, NumOps); 464f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands } 465f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands 466c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// getLoad - Loads are not normal binary operators: their result type is not 467c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// determined by their operands, and they produce a value AND a token chain. 468cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner /// 469475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getLoad(MVT VT, SDValue Chain, SDValue Ptr, 47095c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb const Value *SV, int SVOffset, bool isVolatile=false, 47195c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb unsigned Alignment=0); 472475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getExtLoad(ISD::LoadExtType ExtType, MVT VT, 473475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Chain, SDValue Ptr, const Value *SV, 47483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands int SVOffset, MVT EVT, bool isVolatile=false, 47595c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb unsigned Alignment=0); 476475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getIndexedLoad(SDValue OrigLoad, SDValue Base, 477475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Offset, ISD::MemIndexedMode AM); 478475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, 479475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT, SDValue Chain, 480475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ptr, SDValue Offset, 48183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const Value *SV, int SVOffset, MVT EVT, 482e10efce22502d1a1855d25baf1458660f4ba6f33Duncan Sands bool isVolatile=false, unsigned Alignment=0); 4832d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth 484ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng /// getStore - Helper function to build ISD::STORE nodes. 485ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng /// 486475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getStore(SDValue Chain, SDValue Val, SDValue Ptr, 48795c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb const Value *SV, int SVOffset, bool isVolatile=false, 48895c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb unsigned Alignment=0); 489475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTruncStore(SDValue Chain, SDValue Val, SDValue Ptr, 49083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const Value *SV, int SVOffset, MVT TVT, 49195c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb bool isVolatile=false, unsigned Alignment=0); 492475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getIndexedStore(SDValue OrigStoe, SDValue Base, 493475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Offset, ISD::MemIndexedMode AM); 494ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng 49569de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman // getSrcValue - Construct a node to track a Value* through the backend. 496475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getSrcValue(const Value *v); 49769de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman 49869de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman // getMemOperand - Construct a node to track a memory reference 49969de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman // through the backend. 500475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMemOperand(const MachineMemOperand &MO); 501cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 502b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// UpdateNodeOperands - *Mutate* the specified node in-place to have the 503b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// specified operands. If the resultant node already exists in the DAG, 504b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// this does not modify the specified node, instead it returns the node that 505b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// already exists. If the resultant node does not exist in the DAG, the 506b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// input node is returned. As a degenerate case, if you specify the same 507b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// input operands as the node already has, the input node is returned. 508475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, SDValue Op); 509475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2); 510475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2, 511475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op3); 512475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2, 513475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op3, SDValue Op4); 514475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2, 515475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op3, SDValue Op4, SDValue Op5); 516475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, 517475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 5181b95095857b78e12138c22e76c7936611c51355bChris Lattner 5191b95095857b78e12138c22e76c7936611c51355bChris Lattner /// SelectNodeTo - These are used for target selectors to *mutate* the 5201b95095857b78e12138c22e76c7936611c51355bChris Lattner /// specified node to have the specified return type, Target opcode, and 5211b95095857b78e12138c22e76c7936611c51355bChris Lattner /// operands. Note that target opcodes are stored as 522e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// ~TargetOpcode in the node opcode field. The resultant node is returned. 52383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT); 524475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, SDValue Op1); 52583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, 526475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2); 52783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, 528475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2, SDValue Op3); 52983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, 530475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 531cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, MVT VT2); 532cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, 533475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, const SDValue *Ops, unsigned NumOps); 534cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, 535475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, MVT VT3, const SDValue *Ops, unsigned NumOps); 536cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, 537475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1); 53883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, 539475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2); 54083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, 541475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3); 542cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs, 543475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 544694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng 545e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// MorphNodeTo - These *mutate* the specified node to have the specified 546e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// return type, opcode, and operands. 547e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT); 548475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT, SDValue Op1); 549e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT, 550475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2); 551e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT, 552475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2, SDValue Op3); 553e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT, 554475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 555e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, MVT VT2); 556e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, 557475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, const SDValue *Ops, unsigned NumOps); 558e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, 559475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, MVT VT3, const SDValue *Ops, unsigned NumOps); 560e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, 561475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1); 562e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, 563475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2); 564e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, 565475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3); 566e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs, 567475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 568753c8f20e45f6e4198c7cf4096ecc8948a029e9cChris Lattner 5696ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// getTargetNode - These are used for target selectors to create a new node 5706ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// with specified return type(s), target opcode, and operands. 5716ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// 5726ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// Note that getTargetNode returns the resultant node. If there is already a 5736ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// node of the specified opcode and operands, it returns that node instead of 5746ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// the current one. 57583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT); 576475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *getTargetNode(unsigned Opcode, MVT VT, SDValue Op1); 577475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *getTargetNode(unsigned Opcode, MVT VT, SDValue Op1, SDValue Op2); 57883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT, 579475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2, SDValue Op3); 58083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT, 581475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 58283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2); 583475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, SDValue Op1); 58483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, 585475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2); 58683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, 587475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3); 58883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, 589475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 59083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, 591475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2); 59283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, 593475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2, SDValue Op3); 59483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, 595475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 59683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, MVT VT4, 597475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 598f877b735ad4987f26cafcbaf22aa4c2199458b5dDan Gohman SDNode *getTargetNode(unsigned Opcode, const std::vector<MVT> &ResultTys, 599475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 60008b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng 60108b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng /// getNodeIfExists - Get the specified node if it's already available, or 60208b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng /// else return NULL. 60308b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs, 604475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 6056542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner 606f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// DAGUpdateListener - Clients of various APIs that cause global effects on 607f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// the DAG can optionally implement this interface. This allows the clients 608f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// to handle the various sorts of updates that happen. 609f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner class DAGUpdateListener { 610f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner public: 611f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner virtual ~DAGUpdateListener(); 612edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands 613edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands /// NodeDeleted - The node N that was deleted and, if E is not null, an 614edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands /// equivalent node E that replaced it. 615edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands virtual void NodeDeleted(SDNode *N, SDNode *E) = 0; 616edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands 617edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands /// NodeUpdated - The node N that was updated. 618f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner virtual void NodeUpdated(SDNode *N) = 0; 619f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner }; 620f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner 621f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// RemoveDeadNode - Remove the specified node from the system. If any of its 622f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// operands then becomes dead, remove them as well. Inform UpdateListener 623f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// for each node deleted. 624f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0); 625f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner 6260fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman /// RemoveDeadNodes - This method deletes the unreachable nodes in the 6270fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman /// given list, and any nodes that become unreachable as a result. 6280fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes, 6290fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman DAGUpdateListener *UpdateListener = 0); 6300fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman 6316542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead. 63226005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner /// This can cause recursive merging of nodes in the DAG. Use the first 63326005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner /// version if 'From' is known to have a single result, use the second 63426005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner /// if you have two nodes with identical results, use the third otherwise. 6356542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner /// 636f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// These methods all take an optional UpdateListener, which (if not null) is 637f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// informed about nodes that are deleted and modified due to recursive 638f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// changes in the dag. 639fde3f3061d665babeb78443119a09876098fc35eChris Lattner /// 640475871a144eb604ddaf37503397ba0941442e5fbDan Gohman void ReplaceAllUsesWith(SDValue From, SDValue Op, 641f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner DAGUpdateListener *UpdateListener = 0); 642fde3f3061d665babeb78443119a09876098fc35eChris Lattner void ReplaceAllUsesWith(SDNode *From, SDNode *To, 643f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner DAGUpdateListener *UpdateListener = 0); 644475871a144eb604ddaf37503397ba0941442e5fbDan Gohman void ReplaceAllUsesWith(SDNode *From, const SDValue *To, 645f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner DAGUpdateListener *UpdateListener = 0); 646fae9f1cb34d6d2c4dbd007f2d748a70b67776a82Evan Cheng 64780274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving 648f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// uses of other values produced by From.Val alone. 649475871a144eb604ddaf37503397ba0941442e5fbDan Gohman void ReplaceAllUsesOfValueWith(SDValue From, SDValue To, 650f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner DAGUpdateListener *UpdateListener = 0); 65180274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner 652e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// ReplaceAllUsesOfValuesWith - Like ReplaceAllUsesOfValueWith, but 653e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// for multiple values at once. This correctly handles the case where 654e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// there is an overlap between the From values and the To values. 655475871a144eb604ddaf37503397ba0941442e5fbDan Gohman void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To, 656e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman unsigned Num, 657e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman DAGUpdateListener *UpdateListener = 0); 658e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman 659e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng /// AssignTopologicalOrder - Assign a unique node id for each node in the DAG 66009fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng /// based on their topological order. It returns the maximum id and a vector 66109fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng /// of the SDNodes* in assigned order by reference. 66209fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng unsigned AssignTopologicalOrder(std::vector<SDNode*> &TopOrder); 663e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng 6641efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng /// isCommutativeBinOp - Returns true if the opcode is a commutative binary 6651efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng /// operation. 6661efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng static bool isCommutativeBinOp(unsigned Opcode) { 6674ae9e0c5301126d7f2d4b2975eb86ed21f7b574dChris Lattner // FIXME: This should get its info from the td file, so that we can include 6684ae9e0c5301126d7f2d4b2975eb86ed21f7b574dChris Lattner // target info. 6691efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng switch (Opcode) { 6701efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::ADD: 6711efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::MUL: 6721efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::MULHU: 6731efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::MULHS: 674b6c7437568f0472548ede2710458f52cfad4532eDan Gohman case ISD::SMUL_LOHI: 675b6c7437568f0472548ede2710458f52cfad4532eDan Gohman case ISD::UMUL_LOHI: 6761efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::FADD: 6771efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::FMUL: 6781efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::AND: 6791efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::OR: 6801efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::XOR: 6811efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::ADDC: 6821efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::ADDE: return true; 6831efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng default: return false; 6841efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng } 6851efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng } 6861efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng 687cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner void dump() const; 688d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner 68937ce9df0da6cddc3b8bfef9b63d33d058a0f2f15Chris Lattner /// CreateStackTemporary - Create a stack temporary, suitable for holding the 690364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang /// specified value type. If minAlign is specified, the slot size will have 691364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang /// at least that alignment. 692475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue CreateStackTemporary(MVT VT, unsigned minAlign = 1); 693364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang 69451dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner /// FoldSetCC - Constant fold a setcc to true or false. 695475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue FoldSetCC(MVT VT, SDValue N1, 696475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N2, ISD::CondCode Cond); 69751dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner 6982e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman /// SignBitIsZero - Return true if the sign bit of Op is known to be zero. We 6992e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman /// use this predicate to simplify operations downstream. 700475871a144eb604ddaf37503397ba0941442e5fbDan Gohman bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const; 7012e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman 702ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero. We 703ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// use this predicate to simplify operations downstream. Op and Mask are 704ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// known to be the same type. 705475871a144eb604ddaf37503397ba0941442e5fbDan Gohman bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth = 0) 706ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman const; 707ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman 708ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// ComputeMaskedBits - Determine which of the bits specified in Mask are 709ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// known to be either zero or one and return them in the KnownZero/KnownOne 710ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// bitsets. This code only analyzes bits in Mask, in order to short-circuit 711ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// processing. Targets can implement the computeMaskedBitsForTargetNode 712ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// method in the TargetLowering class to allow target nodes to be understood. 713475871a144eb604ddaf37503397ba0941442e5fbDan Gohman void ComputeMaskedBits(SDValue Op, const APInt &Mask, APInt &KnownZero, 714fd29e0eb060ea8b4d490860329234d2ae5f5952eDan Gohman APInt &KnownOne, unsigned Depth = 0) const; 715fd29e0eb060ea8b4d490860329234d2ae5f5952eDan Gohman 716ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// ComputeNumSignBits - Return the number of times the sign bit of the 717ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// register is replicated into the other bits. We know that at least 1 bit 718ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// is always equal to the sign bit (itself), but other cases can give us 719ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// information. For example, immediately after an "SRA X, 2", we know that 720ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// the top 3 bits are all equal to each other, so we return 3. Targets can 721ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// implement the ComputeNumSignBitsForTarget method in the TargetLowering 722ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// class to allow target nodes to be understood. 723475871a144eb604ddaf37503397ba0941442e5fbDan Gohman unsigned ComputeNumSignBits(SDValue Op, unsigned Depth = 0) const; 724a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng 725475871a144eb604ddaf37503397ba0941442e5fbDan Gohman /// isVerifiedDebugInfoDesc - Returns true if the specified SDValue has 726a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng /// been verified as a debug information descriptor. 727475871a144eb604ddaf37503397ba0941442e5fbDan Gohman bool isVerifiedDebugInfoDesc(SDValue Op) const; 72877f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng 72977f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng /// getShuffleScalarElt - Returns the scalar element that will make up the ith 73077f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng /// element of the result of the vector shuffle. 731475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getShuffleScalarElt(const SDNode *N, unsigned Idx); 732ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman 733d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattnerprivate: 7341b95095857b78e12138c22e76c7936611c51355bChris Lattner void RemoveNodeFromCSEMaps(SDNode *N); 7356542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner SDNode *AddNonLeafNodeToCSEMaps(SDNode *N); 736475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos); 737475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2, 738a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner void *&InsertPos); 739475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *FindModifiedNodeSlot(SDNode *N, const SDValue *Ops, unsigned NumOps, 740a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner void *&InsertPos); 741b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner 742fde3f3061d665babeb78443119a09876098fc35eChris Lattner void DeleteNodeNotInCSEMaps(SDNode *N); 7439c6e70eca9a49c146b26621cbcbb9464ceeac024Dan Gohman 7449c6e70eca9a49c146b26621cbcbb9464ceeac024Dan Gohman unsigned getMVTAlignment(MVT MemoryVT) const; 745f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman 746f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman void allnodes_clear(); 7477cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner 748109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner // List of non-single value types. 749e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman std::vector<SDVTList> VTList; 750109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner 7511cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner // Maps to auto-CSE operations. 7527cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner std::vector<CondCodeSDNode*> CondCodeNodes; 7531cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner 75415e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner std::vector<SDNode*> ValueTypeNodes; 7558e4eb09b1e3571965f49edcdfb56b1375b1b7551Duncan Sands std::map<MVT, SDNode*, MVT::compareRawBits> ExtendedValueTypeNodes; 7564b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman StringMap<SDNode*> ExternalSymbols; 7574b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman StringMap<SDNode*> TargetExternalSymbols; 758cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner}; 759cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 7601080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattnertemplate <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> { 7611080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner typedef SelectionDAG::allnodes_iterator nodes_iterator; 7621080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner static nodes_iterator nodes_begin(SelectionDAG *G) { 7631080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner return G->allnodes_begin(); 7641080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner } 7651080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner static nodes_iterator nodes_end(SelectionDAG *G) { 7661080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner return G->allnodes_end(); 7671080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner } 7681080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner}; 7691080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner 770b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner} // end namespace llvm 771cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 772cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner#endif 773