SelectionDAG.h revision 0b12aef49087b57d276ed760a83525d1e2602144
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 Gohman/// NodeAllocatorType - The AllocatorType for allocating SDNodes. We use 40fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman/// pool allocation with recycling. 41fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman/// 42fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmantypedef RecyclingAllocator<BumpPtrAllocator, SDNode, sizeof(LargestSDNode), 43fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman AlignOf<MostAlignedSDNode>::Alignment> 44fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman NodeAllocatorType; 45fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 46fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmantemplate<> class ilist_traits<SDNode> : public ilist_default_traits<SDNode> { 47fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman mutable SDNode Sentinel; 48fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanpublic: 49fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman ilist_traits() : Sentinel(ISD::DELETED_NODE, SDVTList()) {} 50fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 51fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman SDNode *createSentinel() const { 52fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman return &Sentinel; 53fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman } 54fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman static void destroySentinel(SDNode *) {} 55fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 56fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman static void deleteNode(SDNode *) { 57fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman assert(0 && "ilist_traits<SDNode> shouldn't see a deleteNode call!"); 58fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman } 59fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanprivate: 60fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman static void createNode(const SDNode &); 61fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman}; 62c3aae25116e66c177579b0b79182b09340b19753Chris Lattner 63c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// SelectionDAG class - This is used to represent a portion of an LLVM function 64c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// in a low-level Data Dependence DAG representation suitable for instruction 65c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection. This DAG is constructed as the first step of instruction 66c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection in order to allow implementation of machine specific optimizations 67c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// and code simplifications. 68c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// 69c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// The representation used by the SelectionDAG is a target-independent 70c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// representation, which has some similarities to the GCC RTL representation, 71c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// but is significantly more simple, powerful, and is a graph form instead of a 72c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// linear form. 73cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner/// 74cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerclass SelectionDAG { 75063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner TargetLowering &TLI; 76c3aae25116e66c177579b0b79182b09340b19753Chris Lattner MachineFunction &MF; 77ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner FunctionLoweringInfo &FLI; 7844c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey MachineModuleInfo *MMI; 79cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 80213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner /// Root - The root of the entire DAG. EntryNode - The starting token. 81475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Root, EntryNode; 82cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 83213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner /// AllNodes - A linked list of nodes in the current DAG. 84fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman ilist<SDNode> AllNodes; 85fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman 86fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman /// NodeAllocator - Pool allocation for nodes. The allocator isn't 87fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman /// allocated inside this class because we want to reuse a single 88fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman /// recycler across multiple SelectionDAG runs. 89fed90b6d097d50881afb45e4d79f430db66dd741Dan 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 95e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// Allocator - Pool allocation for misc. objects that are created once per 96e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// SelectionDAG. 97e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman BumpPtrAllocator Allocator; 98e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman 99d038e04188047eca4749d025ef1f05f7ae660bcaDuncan Sands /// VerifyNode - Sanity check the given node. Aborts if it is invalid. 100d038e04188047eca4749d025ef1f05f7ae660bcaDuncan Sands void VerifyNode(SDNode *N); 101d038e04188047eca4749d025ef1f05f7ae660bcaDuncan Sands 102cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerpublic: 103ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner SelectionDAG(TargetLowering &tli, MachineFunction &mf, 1040e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman FunctionLoweringInfo &fli, MachineModuleInfo *mmi, 105fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman NodeAllocatorType &nodeallocator) 106fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman : TLI(tli), MF(mf), FLI(fli), MMI(mmi), NodeAllocator(nodeallocator) { 107c3aae25116e66c177579b0b79182b09340b19753Chris Lattner EntryNode = Root = getNode(ISD::EntryToken, MVT::Other); 108c3aae25116e66c177579b0b79182b09340b19753Chris Lattner } 109cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner ~SelectionDAG(); 110cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 111c3aae25116e66c177579b0b79182b09340b19753Chris Lattner MachineFunction &getMachineFunction() const { return MF; } 112063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner const TargetMachine &getTarget() const; 113063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner TargetLowering &getTargetLoweringInfo() const { return TLI; } 114ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner FunctionLoweringInfo &getFunctionLoweringInfo() const { return FLI; } 11544c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey MachineModuleInfo *getMachineModuleInfo() const { return MMI; } 116cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 117ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'. 1181080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner /// 119462dc7f4960e5074ddf4769ec8b2ef1ba7a4d2c8Dan Gohman void viewGraph(const std::string &Title); 1200b12aef49087b57d276ed760a83525d1e2602144Dan Gohman void viewGraph(); 121ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey 122ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#ifndef NDEBUG 123ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey std::map<const SDNode *, std::string> NodeGraphAttrs; 124ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#endif 1251080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner 126ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// clearGraphAttrs - Clear all previously defined node graph attributes. 127ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// Intended to be used from a debugging tool (eg. gdb). 128ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey void clearGraphAttrs(); 129ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey 130ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".) 131ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// 132ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey void setGraphAttrs(const SDNode *N, const char *Attrs); 133ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey 134ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".) 135ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// Used from getNodeAttributes. 136ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey const std::string getGraphAttrs(const SDNode *N) const; 137ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey 138ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// setGraphColor - Convenience for setting node color attribute. 139ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey /// 140ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey void setGraphColor(const SDNode *N, const char *Color); 1411080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner 142fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman typedef ilist<SDNode>::const_iterator allnodes_const_iterator; 143b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); } 144b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner allnodes_const_iterator allnodes_end() const { return AllNodes.end(); } 145fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman typedef ilist<SDNode>::iterator allnodes_iterator; 146b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner allnodes_iterator allnodes_begin() { return AllNodes.begin(); } 147b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner allnodes_iterator allnodes_end() { return AllNodes.end(); } 148fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman ilist<SDNode>::size_type allnodes_size() const { 1490e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman return AllNodes.size(); 1500e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman } 151b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner 152c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// getRoot - Return the root tag of the SelectionDAG. 153cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner /// 154475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue &getRoot() const { return Root; } 155cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 156c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// getEntryNode - Return the token chain corresponding to the entry of the 157c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// function. 158475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue &getEntryNode() const { return EntryNode; } 159cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 160c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// setRoot - Set the current root tag of the SelectionDAG. 161cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner /// 162475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue &setRoot(SDValue N) { 163acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman assert((!N.Val || N.getValueType() == MVT::Other) && 164acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman "DAG root value is not a chain!"); 165acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman return Root = N; 166acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman } 167cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 1681d4d41411190dd9e62764e56713753d4155764ddNate Begeman /// Combine - This iterates over the nodes in the SelectionDAG, folding 1691d4d41411190dd9e62764e56713753d4155764ddNate Begeman /// certain types of nodes together, or eliminating superfluous nodes. When 1701d4d41411190dd9e62764e56713753d4155764ddNate Begeman /// the AfterLegalize argument is set to 'true', Combine takes care not to 1711d4d41411190dd9e62764e56713753d4155764ddNate Begeman /// generate any nodes that will be illegal on the target. 172c7c3f110eda0ff8040e4bd99e38d3112b910810fJim Laskey void Combine(bool AfterLegalize, AliasAnalysis &AA); 1731d4d41411190dd9e62764e56713753d4155764ddNate Begeman 17401d029b82cb08367d81aa10cdc94d05360466649Chris Lattner /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that 17501d029b82cb08367d81aa10cdc94d05360466649Chris Lattner /// only uses types natively supported by the target. 17601d029b82cb08367d81aa10cdc94d05360466649Chris Lattner /// 17701d029b82cb08367d81aa10cdc94d05360466649Chris Lattner /// Note that this is an involved process that may invalidate pointers into 17801d029b82cb08367d81aa10cdc94d05360466649Chris Lattner /// the graph. 17901d029b82cb08367d81aa10cdc94d05360466649Chris Lattner void LegalizeTypes(); 18001d029b82cb08367d81aa10cdc94d05360466649Chris Lattner 181c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is 182c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// compatible with the target instruction selector, as indicated by the 183c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// TargetLowering object. 184cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner /// 185c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// Note that this is an involved process that may invalidate pointers into 186c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// the graph. 187063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner void Legalize(); 188c3aae25116e66c177579b0b79182b09340b19753Chris Lattner 189d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner /// RemoveDeadNodes - This method deletes all unreachable nodes in the 190190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner /// SelectionDAG. 191190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner void RemoveDeadNodes(); 192130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng 193130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng /// DeleteNode - Remove the specified node from the system. This node must 194130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng /// have no referrers. 195130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng void DeleteNode(SDNode *N); 196130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng 19770046e920fa37989a041af663ada2b2b646e258fChris Lattner /// getVTList - Return an SDVTList that represents the list of values 19870046e920fa37989a041af663ada2b2b646e258fChris Lattner /// specified. 19983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDVTList getVTList(MVT VT); 20083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDVTList getVTList(MVT VT1, MVT VT2); 20183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDVTList getVTList(MVT VT1, MVT VT2, MVT VT3); 20283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDVTList getVTList(const MVT *VTs, unsigned NumVTs); 20370046e920fa37989a041af663ada2b2b646e258fChris Lattner 20470046e920fa37989a041af663ada2b2b646e258fChris Lattner /// getNodeValueTypes - These are obsolete, use getVTList instead. 20583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *getNodeValueTypes(MVT VT) { 20670046e920fa37989a041af663ada2b2b646e258fChris Lattner return getVTList(VT).VTs; 20770046e920fa37989a041af663ada2b2b646e258fChris Lattner } 20883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *getNodeValueTypes(MVT VT1, MVT VT2) { 20970046e920fa37989a041af663ada2b2b646e258fChris Lattner return getVTList(VT1, VT2).VTs; 21070046e920fa37989a041af663ada2b2b646e258fChris Lattner } 21183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *getNodeValueTypes(MVT VT1, MVT VT2, MVT VT3) { 21270046e920fa37989a041af663ada2b2b646e258fChris Lattner return getVTList(VT1, VT2, VT3).VTs; 21370046e920fa37989a041af663ada2b2b646e258fChris Lattner } 214f877b735ad4987f26cafcbaf22aa4c2199458b5dDan Gohman const MVT *getNodeValueTypes(const std::vector<MVT> &vtList) { 21513d57320bd212483463d4f8992d5787b29eda5dfBill Wendling return getVTList(&vtList[0], (unsigned)vtList.size()).VTs; 21670046e920fa37989a041af663ada2b2b646e258fChris Lattner } 21770046e920fa37989a041af663ada2b2b646e258fChris Lattner 21870046e920fa37989a041af663ada2b2b646e258fChris Lattner 2191b1a49714ef26225a42199cf2930529f31868322Chris Lattner //===--------------------------------------------------------------------===// 22070046e920fa37989a041af663ada2b2b646e258fChris Lattner // Node creation methods. 22170046e920fa37989a041af663ada2b2b646e258fChris Lattner // 222475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstant(uint64_t Val, MVT VT, bool isTarget = false); 223475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstant(const APInt &Val, MVT VT, bool isTarget = false); 224475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getIntPtrConstant(uint64_t Val, bool isTarget = false); 225475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstant(uint64_t Val, MVT VT) { 226cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner return getConstant(Val, VT, true); 227cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner } 228475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstant(const APInt &Val, MVT VT) { 2296394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman return getConstant(Val, VT, true); 2306394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman } 231475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstantFP(double Val, MVT VT, bool isTarget = false); 232475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstantFP(const APFloat& Val, MVT VT, bool isTarget = false); 233475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstantFP(double Val, MVT VT) { 234c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner return getConstantFP(Val, VT, true); 235c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner } 236475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstantFP(const APFloat& Val, MVT VT) { 237f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen return getConstantFP(Val, VT, true); 238f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen } 239475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getGlobalAddress(const GlobalValue *GV, MVT VT, 240cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner int offset = 0, bool isTargetGA = false); 241475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetGlobalAddress(const GlobalValue *GV, MVT VT, 242cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner int offset = 0) { 243cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner return getGlobalAddress(GV, VT, offset, true); 244cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner } 245475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getFrameIndex(int FI, MVT VT, bool isTarget = false); 246475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetFrameIndex(int FI, MVT VT) { 247c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner return getFrameIndex(FI, VT, true); 248c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner } 249475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getJumpTable(int JTI, MVT VT, bool isTarget = false); 250475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetJumpTable(int JTI, MVT VT) { 251c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner return getJumpTable(JTI, VT, true); 252c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner } 253475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstantPool(Constant *C, MVT VT, 254c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner unsigned Align = 0, int Offs = 0, bool isT=false); 255475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstantPool(Constant *C, MVT VT, 256c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner unsigned Align = 0, int Offset = 0) { 257c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner return getConstantPool(C, VT, Align, Offset, true); 258c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner } 259475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getConstantPool(MachineConstantPoolValue *C, MVT VT, 260d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng unsigned Align = 0, int Offs = 0, bool isT=false); 261475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetConstantPool(MachineConstantPoolValue *C, 26283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands MVT VT, unsigned Align = 0, 263d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng int Offset = 0) { 264d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng return getConstantPool(C, VT, Align, Offset, true); 265d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng } 266475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getBasicBlock(MachineBasicBlock *MBB); 267475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getExternalSymbol(const char *Sym, MVT VT); 268475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTargetExternalSymbol(const char *Sym, MVT VT); 269475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getArgFlags(ISD::ArgFlagsTy Flags); 270475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getValueType(MVT); 271475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getRegister(unsigned Reg, MVT VT); 272475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getDbgStopPoint(SDValue Root, unsigned Line, unsigned Col, 2737f460203b0c5350e9b2c592f438e40f7a7de6e45Dan Gohman const CompileUnitDesc *CU); 274475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getLabel(unsigned Opcode, SDValue Root, unsigned LabelID); 275c3aae25116e66c177579b0b79182b09340b19753Chris Lattner 276475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCopyToReg(SDValue Chain, unsigned Reg, SDValue N) { 277d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner return getNode(ISD::CopyToReg, MVT::Other, Chain, 278d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner getRegister(Reg, N.getValueType()), N); 279cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner } 280cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 281e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // This version of the getCopyToReg method takes an extra operand, which 282e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // indicates that there is potentially an incoming flag value (if Flag is not 283e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // null) and that there should be a flag result. 284475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCopyToReg(SDValue Chain, unsigned Reg, SDValue N, 285475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Flag) { 28683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag); 287475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag }; 2882fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3); 289e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner } 29066a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng 291475871a144eb604ddaf37503397ba0941442e5fbDan Gohman // Similar to last getCopyToReg() except parameter Reg is a SDValue 292475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCopyToReg(SDValue Chain, SDValue Reg, SDValue N, 293475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Flag) { 29483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag); 295475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ops[] = { Chain, Reg, N, Flag }; 2962fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3); 29766a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng } 298e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner 299475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCopyFromReg(SDValue Chain, unsigned Reg, MVT VT) { 30083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *VTs = getNodeValueTypes(VT, MVT::Other); 301475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ops[] = { Chain, getRegister(Reg, VT) }; 3022fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner return getNode(ISD::CopyFromReg, VTs, 2, Ops, 2); 30318c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner } 304e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner 305e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // This version of the getCopyFromReg method takes an extra operand, which 306e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // indicates that there is potentially an incoming flag value (if Flag is not 307e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner // null) and that there should be a flag result. 308475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCopyFromReg(SDValue Chain, unsigned Reg, MVT VT, 309475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Flag) { 31083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *VTs = getNodeValueTypes(VT, MVT::Other, MVT::Flag); 311475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ops[] = { Chain, getRegister(Reg, VT), Flag }; 3122fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.Val ? 3 : 2); 313e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner } 31418c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner 315475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCondCode(ISD::CondCode Cond); 316cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 3171ccae666f596d5aeca5c9942995763600b622062Chris Lattner /// getZeroExtendInReg - Return the expression required to zero extend the Op 3181ccae666f596d5aeca5c9942995763600b622062Chris Lattner /// value assuming it was the smaller SrcTy value. 319475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getZeroExtendInReg(SDValue Op, MVT SrcTy); 3206a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner 3216a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have 3226a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner /// a flag result (to ensure it's not CSE'd). 323475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCALLSEQ_START(SDValue Chain, SDValue Op) { 32483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag); 325475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ops[] = { Chain, Op }; 3262fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner return getNode(ISD::CALLSEQ_START, VTs, 2, Ops, 2); 3276a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner } 3281ccae666f596d5aeca5c9942995763600b622062Chris Lattner 3290f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling /// getCALLSEQ_END - Return a new CALLSEQ_END node, which always must have a 3300f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling /// flag result (to ensure it's not CSE'd). 331475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, 332475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue InFlag) { 3330f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling SDVTList NodeTys = getVTList(MVT::Other, MVT::Flag); 334475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SmallVector<SDValue, 4> Ops; 3350f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling Ops.push_back(Chain); 3360f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling Ops.push_back(Op1); 3370f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling Ops.push_back(Op2); 3380f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling Ops.push_back(InFlag); 3390f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling return getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0], 34034cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng (unsigned)Ops.size() - (InFlag.Val == 0 ? 1 : 0)); 3410f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling } 3420f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling 343c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// getNode - Gets or creates the specified node. 344cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner /// 345475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT); 346475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, SDValue N); 347475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, SDValue N1, SDValue N2); 348475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, 349475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3); 350475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, 351475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3, SDValue N4); 352475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, 353475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3, SDValue N4, 354475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N5); 355475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, 356475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 357475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, MVT VT, 3586d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman const SDUse *Ops, unsigned NumOps); 359475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, const std::vector<MVT> &ResultTys, 360475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 361475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, const MVT *VTs, unsigned NumVTs, 362475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 363475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs); 364475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, SDValue N); 365475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, SDValue N1, SDValue N2); 366475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, 367475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3); 368475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, 369475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3, SDValue N4); 370475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, 371475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N1, SDValue N2, SDValue N3, SDValue N4, 372475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N5); 373475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getNode(unsigned Opcode, SDVTList VTs, 374475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 375475871a144eb604ddaf37503397ba0941442e5fbDan Gohman 376475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMemcpy(SDValue Chain, SDValue Dst, SDValue Src, 377475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Size, unsigned Align, 378707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman bool AlwaysInline, 3791f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman const Value *DstSV, uint64_t DstSVOff, 3801f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman const Value *SrcSV, uint64_t SrcSVOff); 3815c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola 382475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMemmove(SDValue Chain, SDValue Dst, SDValue Src, 383475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Size, unsigned Align, 3841f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman const Value *DstSV, uint64_t DstOSVff, 3851f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman const Value *SrcSV, uint64_t SrcSVOff); 3865c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola 387475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMemset(SDValue Chain, SDValue Dst, SDValue Src, 388475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Size, unsigned Align, 3891f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman const Value *DstSV, uint64_t DstSVOff); 3905c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola 3917cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner /// getSetCC - Helper function to make it easier to build SetCC's if you just 392475871a144eb604ddaf37503397ba0941442e5fbDan Gohman /// have an ISD::CondCode instead of an SDValue. 3937cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner /// 394475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getSetCC(MVT VT, SDValue LHS, SDValue RHS, 3957cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner ISD::CondCode Cond) { 3967cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond)); 397b43e9c196542acc80c9e4643809661065710848fNate Begeman } 398b43e9c196542acc80c9e4643809661065710848fNate Begeman 399b43e9c196542acc80c9e4643809661065710848fNate Begeman /// getVSetCC - Helper function to make it easier to build VSetCC's nodes 400475871a144eb604ddaf37503397ba0941442e5fbDan Gohman /// if you just have an ISD::CondCode instead of an SDValue. 401b43e9c196542acc80c9e4643809661065710848fNate Begeman /// 402475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getVSetCC(MVT VT, SDValue LHS, SDValue RHS, 403b43e9c196542acc80c9e4643809661065710848fNate Begeman ISD::CondCode Cond) { 404b43e9c196542acc80c9e4643809661065710848fNate Begeman return getNode(ISD::VSETCC, VT, LHS, RHS, getCondCode(Cond)); 4057cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner } 4069373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman 4079373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman /// getSelectCC - Helper function to make it easier to build SelectCC's if you 408475871a144eb604ddaf37503397ba0941442e5fbDan Gohman /// just have an ISD::CondCode instead of an SDValue. 4099373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman /// 410475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getSelectCC(SDValue LHS, SDValue RHS, 411475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue True, SDValue False, ISD::CondCode Cond) { 4122fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner return getNode(ISD::SELECT_CC, True.getValueType(), LHS, RHS, True, False, 4132fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner getCondCode(Cond)); 4149373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman } 4157cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner 416acc398c195a697795bff3245943d104eb19192b9Nate Begeman /// getVAArg - VAArg produces a result and token chain, and takes a pointer 417acc398c195a697795bff3245943d104eb19192b9Nate Begeman /// and a source value as input. 418475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getVAArg(MVT VT, SDValue Chain, SDValue Ptr, 419475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue SV); 4207cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman 421ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth /// getAtomic - Gets a node for an atomic op, produces result and chain, takes 42228873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang /// 3 operands 423475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getAtomic(unsigned Opcode, SDValue Chain, SDValue Ptr, 424475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Cmp, SDValue Swp, const Value* PtrVal, 42528873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang unsigned Alignment=0); 426ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth 427ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth /// getAtomic - Gets a node for an atomic op, produces result and chain, takes 42828873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang /// 2 operands 429475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getAtomic(unsigned Opcode, SDValue Chain, SDValue Ptr, 430475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Val, const Value* PtrVal, 43128873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang unsigned Alignment = 0); 432ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth 4334bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands /// getMergeValues - Create a MERGE_VALUES node from the given operands. 4344bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands /// Allowed to return something different (and simpler) if Simplify is true. 435475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMergeValues(const SDValue *Ops, unsigned NumOps, 4364bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands bool Simplify = true); 4374bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands 438f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands /// getMergeValues - Create a MERGE_VALUES node from the given types and ops. 439f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands /// Allowed to return something different (and simpler) if Simplify is true. 4404bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands /// May be faster than the above version if VTs is known and NumOps is large. 441475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMergeValues(SDVTList VTs, const SDValue *Ops, unsigned NumOps, 442f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands bool Simplify = true) { 443f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands if (Simplify && NumOps == 1) 444f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands return Ops[0]; 445f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands return getNode(ISD::MERGE_VALUES, VTs, Ops, NumOps); 446f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands } 447f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands 448c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// getLoad - Loads are not normal binary operators: their result type is not 449c3aae25116e66c177579b0b79182b09340b19753Chris Lattner /// determined by their operands, and they produce a value AND a token chain. 450cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner /// 451475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getLoad(MVT VT, SDValue Chain, SDValue Ptr, 45295c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb const Value *SV, int SVOffset, bool isVolatile=false, 45395c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb unsigned Alignment=0); 454475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getExtLoad(ISD::LoadExtType ExtType, MVT VT, 455475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Chain, SDValue Ptr, const Value *SV, 45683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands int SVOffset, MVT EVT, bool isVolatile=false, 45795c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb unsigned Alignment=0); 458475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getIndexedLoad(SDValue OrigLoad, SDValue Base, 459475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Offset, ISD::MemIndexedMode AM); 460475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, 461475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT, SDValue Chain, 462475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Ptr, SDValue Offset, 46383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const Value *SV, int SVOffset, MVT EVT, 464e10efce22502d1a1855d25baf1458660f4ba6f33Duncan Sands bool isVolatile=false, unsigned Alignment=0); 4652d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth 466ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng /// getStore - Helper function to build ISD::STORE nodes. 467ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng /// 468475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getStore(SDValue Chain, SDValue Val, SDValue Ptr, 46995c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb const Value *SV, int SVOffset, bool isVolatile=false, 47095c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb unsigned Alignment=0); 471475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getTruncStore(SDValue Chain, SDValue Val, SDValue Ptr, 47283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands const Value *SV, int SVOffset, MVT TVT, 47395c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb bool isVolatile=false, unsigned Alignment=0); 474475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getIndexedStore(SDValue OrigStoe, SDValue Base, 475475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Offset, ISD::MemIndexedMode AM); 476ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng 47769de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman // getSrcValue - Construct a node to track a Value* through the backend. 478475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getSrcValue(const Value *v); 47969de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman 48069de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman // getMemOperand - Construct a node to track a memory reference 48169de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman // through the backend. 482475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getMemOperand(const MachineMemOperand &MO); 483cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 484b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// UpdateNodeOperands - *Mutate* the specified node in-place to have the 485b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// specified operands. If the resultant node already exists in the DAG, 486b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// this does not modify the specified node, instead it returns the node that 487b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// already exists. If the resultant node does not exist in the DAG, the 488b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// input node is returned. As a degenerate case, if you specify the same 489b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner /// input operands as the node already has, the input node is returned. 490475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, SDValue Op); 491475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2); 492475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2, 493475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op3); 494475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2, 495475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op3, SDValue Op4); 496475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2, 497475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op3, SDValue Op4, SDValue Op5); 498475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue UpdateNodeOperands(SDValue N, 499475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 5001b95095857b78e12138c22e76c7936611c51355bChris Lattner 5011b95095857b78e12138c22e76c7936611c51355bChris Lattner /// SelectNodeTo - These are used for target selectors to *mutate* the 5021b95095857b78e12138c22e76c7936611c51355bChris Lattner /// specified node to have the specified return type, Target opcode, and 5031b95095857b78e12138c22e76c7936611c51355bChris Lattner /// operands. Note that target opcodes are stored as 504e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// ~TargetOpcode in the node opcode field. The resultant node is returned. 50583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT); 506475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, SDValue Op1); 50783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, 508475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2); 50983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, 510475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2, SDValue Op3); 51183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, 512475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 513cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, MVT VT2); 514cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, 515475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, const SDValue *Ops, unsigned NumOps); 516cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, 517475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, MVT VT3, const SDValue *Ops, unsigned NumOps); 518cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, 519475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1); 52083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, 521475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2); 52283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, 523475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3); 524cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs, 525475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 526694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng 527e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// MorphNodeTo - These *mutate* the specified node to have the specified 528e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// return type, opcode, and operands. 529e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT); 530475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT, SDValue Op1); 531e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT, 532475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2); 533e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT, 534475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2, SDValue Op3); 535e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT, 536475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 537e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, MVT VT2); 538e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, 539475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, const SDValue *Ops, unsigned NumOps); 540e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, 541475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, MVT VT3, const SDValue *Ops, unsigned NumOps); 542e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, 543475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1); 544e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, 545475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2); 546e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, 547475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3); 548e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman SDNode *MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs, 549475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 550753c8f20e45f6e4198c7cf4096ecc8948a029e9cChris Lattner 5516ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// getTargetNode - These are used for target selectors to create a new node 5526ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// with specified return type(s), target opcode, and operands. 5536ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// 5546ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// Note that getTargetNode returns the resultant node. If there is already a 5556ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// node of the specified opcode and operands, it returns that node instead of 5566ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng /// the current one. 55783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT); 558475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *getTargetNode(unsigned Opcode, MVT VT, SDValue Op1); 559475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *getTargetNode(unsigned Opcode, MVT VT, SDValue Op1, SDValue Op2); 56083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT, 561475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2, SDValue Op3); 56283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT, 563475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 56483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2); 565475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, SDValue Op1); 56683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, 567475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2); 56883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, 569475871a144eb604ddaf37503397ba0941442e5fbDan Gohman MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3); 57083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, 571475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 57283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, 573475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2); 57483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, 575475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue Op1, SDValue Op2, SDValue Op3); 57683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, 577475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 57883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, MVT VT4, 579475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 580f877b735ad4987f26cafcbaf22aa4c2199458b5dDan Gohman SDNode *getTargetNode(unsigned Opcode, const std::vector<MVT> &ResultTys, 581475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 58208b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng 58308b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng /// getNodeIfExists - Get the specified node if it's already available, or 58408b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng /// else return NULL. 58508b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs, 586475871a144eb604ddaf37503397ba0941442e5fbDan Gohman const SDValue *Ops, unsigned NumOps); 5876542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner 588f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// DAGUpdateListener - Clients of various APIs that cause global effects on 589f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// the DAG can optionally implement this interface. This allows the clients 590f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// to handle the various sorts of updates that happen. 591f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner class DAGUpdateListener { 592f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner public: 593f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner virtual ~DAGUpdateListener(); 594edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands 595edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands /// NodeDeleted - The node N that was deleted and, if E is not null, an 596edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands /// equivalent node E that replaced it. 597edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands virtual void NodeDeleted(SDNode *N, SDNode *E) = 0; 598edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands 599edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands /// NodeUpdated - The node N that was updated. 600f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner virtual void NodeUpdated(SDNode *N) = 0; 601f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner }; 602f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner 603f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// RemoveDeadNode - Remove the specified node from the system. If any of its 604f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// operands then becomes dead, remove them as well. Inform UpdateListener 605f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// for each node deleted. 606f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0); 607f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner 6080fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman /// RemoveDeadNodes - This method deletes the unreachable nodes in the 6090fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman /// given list, and any nodes that become unreachable as a result. 6100fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes, 6110fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman DAGUpdateListener *UpdateListener = 0); 6120fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman 6136542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead. 61426005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner /// This can cause recursive merging of nodes in the DAG. Use the first 61526005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner /// version if 'From' is known to have a single result, use the second 61626005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner /// if you have two nodes with identical results, use the third otherwise. 6176542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner /// 618f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// These methods all take an optional UpdateListener, which (if not null) is 619f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// informed about nodes that are deleted and modified due to recursive 620f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// changes in the dag. 621fde3f3061d665babeb78443119a09876098fc35eChris Lattner /// 622475871a144eb604ddaf37503397ba0941442e5fbDan Gohman void ReplaceAllUsesWith(SDValue From, SDValue Op, 623f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner DAGUpdateListener *UpdateListener = 0); 624fde3f3061d665babeb78443119a09876098fc35eChris Lattner void ReplaceAllUsesWith(SDNode *From, SDNode *To, 625f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner DAGUpdateListener *UpdateListener = 0); 626475871a144eb604ddaf37503397ba0941442e5fbDan Gohman void ReplaceAllUsesWith(SDNode *From, const SDValue *To, 627f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner DAGUpdateListener *UpdateListener = 0); 628fae9f1cb34d6d2c4dbd007f2d748a70b67776a82Evan Cheng 62980274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving 630f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner /// uses of other values produced by From.Val alone. 631475871a144eb604ddaf37503397ba0941442e5fbDan Gohman void ReplaceAllUsesOfValueWith(SDValue From, SDValue To, 632f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner DAGUpdateListener *UpdateListener = 0); 63380274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner 634e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// ReplaceAllUsesOfValuesWith - Like ReplaceAllUsesOfValueWith, but 635e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// for multiple values at once. This correctly handles the case where 636e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman /// there is an overlap between the From values and the To values. 637475871a144eb604ddaf37503397ba0941442e5fbDan Gohman void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To, 638e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman unsigned Num, 639e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman DAGUpdateListener *UpdateListener = 0); 640e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman 641e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng /// AssignTopologicalOrder - Assign a unique node id for each node in the DAG 64209fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng /// based on their topological order. It returns the maximum id and a vector 64309fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng /// of the SDNodes* in assigned order by reference. 64409fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng unsigned AssignTopologicalOrder(std::vector<SDNode*> &TopOrder); 645e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng 6461efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng /// isCommutativeBinOp - Returns true if the opcode is a commutative binary 6471efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng /// operation. 6481efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng static bool isCommutativeBinOp(unsigned Opcode) { 6494ae9e0c5301126d7f2d4b2975eb86ed21f7b574dChris Lattner // FIXME: This should get its info from the td file, so that we can include 6504ae9e0c5301126d7f2d4b2975eb86ed21f7b574dChris Lattner // target info. 6511efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng switch (Opcode) { 6521efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::ADD: 6531efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::MUL: 6541efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::MULHU: 6551efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::MULHS: 656b6c7437568f0472548ede2710458f52cfad4532eDan Gohman case ISD::SMUL_LOHI: 657b6c7437568f0472548ede2710458f52cfad4532eDan Gohman case ISD::UMUL_LOHI: 6581efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::FADD: 6591efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::FMUL: 6601efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::AND: 6611efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::OR: 6621efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::XOR: 6631efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::ADDC: 6641efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng case ISD::ADDE: return true; 6651efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng default: return false; 6661efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng } 6671efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng } 6681efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng 669cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner void dump() const; 670d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner 67137ce9df0da6cddc3b8bfef9b63d33d058a0f2f15Chris Lattner /// CreateStackTemporary - Create a stack temporary, suitable for holding the 672364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang /// specified value type. If minAlign is specified, the slot size will have 673364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang /// at least that alignment. 674475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue CreateStackTemporary(MVT VT, unsigned minAlign = 1); 675364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang 67651dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner /// FoldSetCC - Constant fold a setcc to true or false. 677475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue FoldSetCC(MVT VT, SDValue N1, 678475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue N2, ISD::CondCode Cond); 67951dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner 6802e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman /// SignBitIsZero - Return true if the sign bit of Op is known to be zero. We 6812e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman /// use this predicate to simplify operations downstream. 682475871a144eb604ddaf37503397ba0941442e5fbDan Gohman bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const; 6832e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman 684ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero. We 685ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// use this predicate to simplify operations downstream. Op and Mask are 686ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// known to be the same type. 687475871a144eb604ddaf37503397ba0941442e5fbDan Gohman bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth = 0) 688ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman const; 689ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman 690ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// ComputeMaskedBits - Determine which of the bits specified in Mask are 691ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// known to be either zero or one and return them in the KnownZero/KnownOne 692ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// bitsets. This code only analyzes bits in Mask, in order to short-circuit 693ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// processing. Targets can implement the computeMaskedBitsForTargetNode 694ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// method in the TargetLowering class to allow target nodes to be understood. 695475871a144eb604ddaf37503397ba0941442e5fbDan Gohman void ComputeMaskedBits(SDValue Op, const APInt &Mask, APInt &KnownZero, 696fd29e0eb060ea8b4d490860329234d2ae5f5952eDan Gohman APInt &KnownOne, unsigned Depth = 0) const; 697fd29e0eb060ea8b4d490860329234d2ae5f5952eDan Gohman 698ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// ComputeNumSignBits - Return the number of times the sign bit of the 699ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// register is replicated into the other bits. We know that at least 1 bit 700ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// is always equal to the sign bit (itself), but other cases can give us 701ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// information. For example, immediately after an "SRA X, 2", we know that 702ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// the top 3 bits are all equal to each other, so we return 3. Targets can 703ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// implement the ComputeNumSignBitsForTarget method in the TargetLowering 704ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman /// class to allow target nodes to be understood. 705475871a144eb604ddaf37503397ba0941442e5fbDan Gohman unsigned ComputeNumSignBits(SDValue Op, unsigned Depth = 0) const; 706a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng 707475871a144eb604ddaf37503397ba0941442e5fbDan Gohman /// isVerifiedDebugInfoDesc - Returns true if the specified SDValue has 708a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng /// been verified as a debug information descriptor. 709475871a144eb604ddaf37503397ba0941442e5fbDan Gohman bool isVerifiedDebugInfoDesc(SDValue Op) const; 71077f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng 71177f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng /// getShuffleScalarElt - Returns the scalar element that will make up the ith 71277f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng /// element of the result of the vector shuffle. 713475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDValue getShuffleScalarElt(const SDNode *N, unsigned Idx); 714ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman 715d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattnerprivate: 7161b95095857b78e12138c22e76c7936611c51355bChris Lattner void RemoveNodeFromCSEMaps(SDNode *N); 7176542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner SDNode *AddNonLeafNodeToCSEMaps(SDNode *N); 718475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos); 719475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2, 720a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner void *&InsertPos); 721475871a144eb604ddaf37503397ba0941442e5fbDan Gohman SDNode *FindModifiedNodeSlot(SDNode *N, const SDValue *Ops, unsigned NumOps, 722a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner void *&InsertPos); 723b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner 724fde3f3061d665babeb78443119a09876098fc35eChris Lattner void DeleteNodeNotInCSEMaps(SDNode *N); 7259c6e70eca9a49c146b26621cbcbb9464ceeac024Dan Gohman 7269c6e70eca9a49c146b26621cbcbb9464ceeac024Dan Gohman unsigned getMVTAlignment(MVT MemoryVT) const; 7277cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner 728109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner // List of non-single value types. 729e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman std::vector<SDVTList> VTList; 730109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner 7311cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner // Maps to auto-CSE operations. 7327cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner std::vector<CondCodeSDNode*> CondCodeNodes; 7331cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner 73415e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner std::vector<SDNode*> ValueTypeNodes; 7358e4eb09b1e3571965f49edcdfb56b1375b1b7551Duncan Sands std::map<MVT, SDNode*, MVT::compareRawBits> ExtendedValueTypeNodes; 7364b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman StringMap<SDNode*> ExternalSymbols; 7374b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman StringMap<SDNode*> TargetExternalSymbols; 738cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner}; 739cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 7401080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattnertemplate <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> { 7411080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner typedef SelectionDAG::allnodes_iterator nodes_iterator; 7421080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner static nodes_iterator nodes_begin(SelectionDAG *G) { 7431080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner return G->allnodes_begin(); 7441080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner } 7451080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner static nodes_iterator nodes_end(SelectionDAG *G) { 7461080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner return G->allnodes_end(); 7471080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner } 7481080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner}; 7491080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner 750b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner} // end namespace llvm 751cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner 752cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner#endif 753