LCOV - code coverage report
Current view: top level - include/llvm/CodeGen - SelectionDAG.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 166 177 93.8 %
Date: 2018-02-20 03:34:22 Functions: 87 93 93.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ----------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file declares the SelectionDAG class, and transitively defines the
      11             : // SDNode class and subclasses.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_CODEGEN_SELECTIONDAG_H
      16             : #define LLVM_CODEGEN_SELECTIONDAG_H
      17             : 
      18             : #include "llvm/ADT/APFloat.h"
      19             : #include "llvm/ADT/APInt.h"
      20             : #include "llvm/ADT/ArrayRef.h"
      21             : #include "llvm/ADT/DenseMap.h"
      22             : #include "llvm/ADT/DenseSet.h"
      23             : #include "llvm/ADT/FoldingSet.h"
      24             : #include "llvm/ADT/SetVector.h"
      25             : #include "llvm/ADT/SmallVector.h"
      26             : #include "llvm/ADT/StringMap.h"
      27             : #include "llvm/ADT/ilist.h"
      28             : #include "llvm/ADT/iterator.h"
      29             : #include "llvm/ADT/iterator_range.h"
      30             : #include "llvm/Analysis/AliasAnalysis.h"
      31             : #include "llvm/CodeGen/DAGCombine.h"
      32             : #include "llvm/CodeGen/ISDOpcodes.h"
      33             : #include "llvm/CodeGen/MachineFunction.h"
      34             : #include "llvm/CodeGen/MachineMemOperand.h"
      35             : #include "llvm/CodeGen/MachineValueType.h"
      36             : #include "llvm/CodeGen/SelectionDAGNodes.h"
      37             : #include "llvm/CodeGen/ValueTypes.h"
      38             : #include "llvm/IR/DebugLoc.h"
      39             : #include "llvm/IR/Instructions.h"
      40             : #include "llvm/IR/Metadata.h"
      41             : #include "llvm/Support/Allocator.h"
      42             : #include "llvm/Support/ArrayRecycler.h"
      43             : #include "llvm/Support/AtomicOrdering.h"
      44             : #include "llvm/Support/Casting.h"
      45             : #include "llvm/Support/CodeGen.h"
      46             : #include "llvm/Support/ErrorHandling.h"
      47             : #include "llvm/Support/RecyclingAllocator.h"
      48             : #include <algorithm>
      49             : #include <cassert>
      50             : #include <cstdint>
      51             : #include <functional>
      52             : #include <map>
      53             : #include <string>
      54             : #include <tuple>
      55             : #include <utility>
      56             : #include <vector>
      57             : 
      58             : namespace llvm {
      59             : 
      60             : class BlockAddress;
      61             : class Constant;
      62             : class ConstantFP;
      63             : class ConstantInt;
      64             : class DataLayout;
      65             : struct fltSemantics;
      66             : class GlobalValue;
      67             : struct KnownBits;
      68             : class LLVMContext;
      69             : class MachineBasicBlock;
      70             : class MachineConstantPoolValue;
      71             : class MCSymbol;
      72             : class OptimizationRemarkEmitter;
      73             : class SDDbgValue;
      74             : class SelectionDAG;
      75             : class SelectionDAGTargetInfo;
      76             : class TargetLibraryInfo;
      77             : class TargetLowering;
      78             : class TargetMachine;
      79             : class TargetSubtargetInfo;
      80             : class Value;
      81             : 
      82             : class SDVTListNode : public FoldingSetNode {
      83             :   friend struct FoldingSetTrait<SDVTListNode>;
      84             : 
      85             :   /// A reference to an Interned FoldingSetNodeID for this node.
      86             :   /// The Allocator in SelectionDAG holds the data.
      87             :   /// SDVTList contains all types which are frequently accessed in SelectionDAG.
      88             :   /// The size of this list is not expected to be big so it won't introduce
      89             :   /// a memory penalty.
      90             :   FoldingSetNodeIDRef FastID;
      91             :   const EVT *VTs;
      92             :   unsigned int NumVTs;
      93             :   /// The hash value for SDVTList is fixed, so cache it to avoid
      94             :   /// hash calculation.
      95             :   unsigned HashValue;
      96             : 
      97             : public:
      98      116726 :   SDVTListNode(const FoldingSetNodeIDRef ID, const EVT *VT, unsigned int Num) :
      99      116726 :       FastID(ID), VTs(VT), NumVTs(Num) {
     100      116726 :     HashValue = ID.ComputeHash();
     101             :   }
     102             : 
     103             :   SDVTList getSDVTList() {
     104             :     SDVTList result = {VTs, NumVTs};
     105             :     return result;
     106             :   }
     107             : };
     108             : 
     109             : /// Specialize FoldingSetTrait for SDVTListNode
     110             : /// to avoid computing temp FoldingSetNodeID and hash value.
     111             : template<> struct FoldingSetTrait<SDVTListNode> : DefaultFoldingSetTrait<SDVTListNode> {
     112           0 :   static void Profile(const SDVTListNode &X, FoldingSetNodeID& ID) {
     113           0 :     ID = X.FastID;
     114           0 :   }
     115             : 
     116             :   static bool Equals(const SDVTListNode &X, const FoldingSetNodeID &ID,
     117             :                      unsigned IDHash, FoldingSetNodeID &TempID) {
     118     5776481 :     if (X.HashValue != IDHash)
     119             :       return false;
     120     5225252 :     return ID == X.FastID;
     121             :   }
     122             : 
     123             :   static unsigned ComputeHash(const SDVTListNode &X, FoldingSetNodeID &TempID) {
     124             :     return X.HashValue;
     125             :   }
     126             : };
     127             : 
     128             : template <> struct ilist_alloc_traits<SDNode> {
     129             :   static void deleteNode(SDNode *) {
     130           0 :     llvm_unreachable("ilist_traits<SDNode> shouldn't see a deleteNode call!");
     131             :   }
     132             : };
     133             : 
     134             : /// Keeps track of dbg_value information through SDISel.  We do
     135             : /// not build SDNodes for these so as not to perturb the generated code;
     136             : /// instead the info is kept off to the side in this structure. Each SDNode may
     137             : /// have one or more associated dbg_value entries. This information is kept in
     138             : /// DbgValMap.
     139             : /// Byval parameters are handled separately because they don't use alloca's,
     140             : /// which busts the normal mechanism.  There is good reason for handling all
     141             : /// parameters separately:  they may not have code generated for them, they
     142             : /// should always go at the beginning of the function regardless of other code
     143             : /// motion, and debug info for them is potentially useful even if the parameter
     144             : /// is unused.  Right now only byval parameters are handled separately.
     145       44968 : class SDDbgInfo {
     146             :   BumpPtrAllocator Alloc;
     147             :   SmallVector<SDDbgValue*, 32> DbgValues;
     148             :   SmallVector<SDDbgValue*, 32> ByvalParmDbgValues;
     149             :   using DbgValMapType = DenseMap<const SDNode *, SmallVector<SDDbgValue *, 2>>;
     150             :   DbgValMapType DbgValMap;
     151             : 
     152             : public:
     153       45186 :   SDDbgInfo() = default;
     154             :   SDDbgInfo(const SDDbgInfo &) = delete;
     155             :   SDDbgInfo &operator=(const SDDbgInfo &) = delete;
     156             : 
     157       27914 :   void add(SDDbgValue *V, const SDNode *Node, bool isParameter) {
     158       27914 :     if (isParameter) {
     159           6 :       ByvalParmDbgValues.push_back(V);
     160       27908 :     } else     DbgValues.push_back(V);
     161       27914 :     if (Node)
     162       37610 :       DbgValMap[Node].push_back(V);
     163       27914 :   }
     164             : 
     165             :   /// \brief Invalidate all DbgValues attached to the node and remove
     166             :   /// it from the Node-to-DbgValues map.
     167             :   void erase(const SDNode *Node);
     168             : 
     169             :   void clear() {
     170      332409 :     DbgValMap.clear();
     171             :     DbgValues.clear();
     172             :     ByvalParmDbgValues.clear();
     173      332408 :     Alloc.Reset();
     174             :   }
     175             : 
     176       27914 :   BumpPtrAllocator &getAlloc() { return Alloc; }
     177             : 
     178             :   bool empty() const {
     179      332399 :     return DbgValues.empty() && ByvalParmDbgValues.empty();
     180             :   }
     181             : 
     182        7728 :   ArrayRef<SDDbgValue*> getSDDbgValues(const SDNode *Node) {
     183        7728 :     DbgValMapType::iterator I = DbgValMap.find(Node);
     184        7728 :     if (I != DbgValMap.end())
     185        7728 :       return I->second;
     186           0 :     return ArrayRef<SDDbgValue*>();
     187             :   }
     188             : 
     189             :   using DbgIterator = SmallVectorImpl<SDDbgValue*>::iterator;
     190             : 
     191             :   DbgIterator DbgBegin() { return DbgValues.begin(); }
     192             :   DbgIterator DbgEnd()   { return DbgValues.end(); }
     193             :   DbgIterator ByvalParmDbgBegin() { return ByvalParmDbgValues.begin(); }
     194             :   DbgIterator ByvalParmDbgEnd()   { return ByvalParmDbgValues.end(); }
     195             : };
     196             : 
     197             : void checkForCycles(const SelectionDAG *DAG, bool force = false);
     198             : 
     199             : /// This is used to represent a portion of an LLVM function in a low-level
     200             : /// Data Dependence DAG representation suitable for instruction selection.
     201             : /// This DAG is constructed as the first step of instruction selection in order
     202             : /// to allow implementation of machine specific optimizations
     203             : /// and code simplifications.
     204             : ///
     205             : /// The representation used by the SelectionDAG is a target-independent
     206             : /// representation, which has some similarities to the GCC RTL representation,
     207             : /// but is significantly more simple, powerful, and is a graph form instead of a
     208             : /// linear form.
     209             : ///
     210             : class SelectionDAG {
     211             :   const TargetMachine &TM;
     212             :   const SelectionDAGTargetInfo *TSI = nullptr;
     213             :   const TargetLowering *TLI = nullptr;
     214             :   const TargetLibraryInfo *LibInfo = nullptr;
     215             :   MachineFunction *MF;
     216             :   Pass *SDAGISelPass = nullptr;
     217             :   LLVMContext *Context;
     218             :   CodeGenOpt::Level OptLevel;
     219             : 
     220             :   /// The function-level optimization remark emitter.  Used to emit remarks
     221             :   /// whenever manipulating the DAG.
     222             :   OptimizationRemarkEmitter *ORE;
     223             : 
     224             :   /// The starting token.
     225             :   SDNode EntryNode;
     226             : 
     227             :   /// The root of the entire DAG.
     228             :   SDValue Root;
     229             : 
     230             :   /// A linked list of nodes in the current DAG.
     231             :   ilist<SDNode> AllNodes;
     232             : 
     233             :   /// The AllocatorType for allocating SDNodes. We use
     234             :   /// pool allocation with recycling.
     235             :   using NodeAllocatorType = RecyclingAllocator<BumpPtrAllocator, SDNode,
     236             :                                                sizeof(LargestSDNode),
     237             :                                                alignof(MostAlignedSDNode)>;
     238             : 
     239             :   /// Pool allocation for nodes.
     240             :   NodeAllocatorType NodeAllocator;
     241             : 
     242             :   /// This structure is used to memoize nodes, automatically performing
     243             :   /// CSE with existing nodes when a duplicate is requested.
     244             :   FoldingSet<SDNode> CSEMap;
     245             : 
     246             :   /// Pool allocation for machine-opcode SDNode operands.
     247             :   BumpPtrAllocator OperandAllocator;
     248             :   ArrayRecycler<SDUse> OperandRecycler;
     249             : 
     250             :   /// Pool allocation for misc. objects that are created once per SelectionDAG.
     251             :   BumpPtrAllocator Allocator;
     252             : 
     253             :   /// Tracks dbg_value information through SDISel.
     254             :   SDDbgInfo *DbgInfo;
     255             : 
     256             :   uint16_t NextPersistentId = 0;
     257             : 
     258             : public:
     259             :   /// Clients of various APIs that cause global effects on
     260             :   /// the DAG can optionally implement this interface.  This allows the clients
     261             :   /// to handle the various sorts of updates that happen.
     262             :   ///
     263             :   /// A DAGUpdateListener automatically registers itself with DAG when it is
     264             :   /// constructed, and removes itself when destroyed in RAII fashion.
     265             :   struct DAGUpdateListener {
     266             :     DAGUpdateListener *const Next;
     267             :     SelectionDAG &DAG;
     268             : 
     269             :     explicit DAGUpdateListener(SelectionDAG &D)
     270    40357520 :       : Next(D.UpdateListeners), DAG(D) {
     271    40357520 :       DAG.UpdateListeners = this;
     272             :     }
     273             : 
     274           0 :     virtual ~DAGUpdateListener() {
     275             :       assert(DAG.UpdateListeners == this &&
     276             :              "DAGUpdateListeners must be destroyed in LIFO order");
     277    12778204 :       DAG.UpdateListeners = Next;
     278           0 :     }
     279             : 
     280             :     /// The node N that was deleted and, if E is not null, an
     281             :     /// equivalent node E that replaced it.
     282             :     virtual void NodeDeleted(SDNode *N, SDNode *E);
     283             : 
     284             :     /// The node N that was updated.
     285             :     virtual void NodeUpdated(SDNode *N);
     286             :   };
     287             : 
     288     3544390 :   struct DAGNodeDeletedListener : public DAGUpdateListener {
     289             :     std::function<void(SDNode *, SDNode *)> Callback;
     290             : 
     291             :     DAGNodeDeletedListener(SelectionDAG &DAG,
     292             :                            std::function<void(SDNode *, SDNode *)> Callback)
     293     3211924 :         : DAGUpdateListener(DAG), Callback(std::move(Callback)) {}
     294             : 
     295     3980943 :     void NodeDeleted(SDNode *N, SDNode *E) override { Callback(N, E); }
     296             :   };
     297             : 
     298             :   /// When true, additional steps are taken to
     299             :   /// ensure that getConstant() and similar functions return DAG nodes that
     300             :   /// have legal types. This is important after type legalization since
     301             :   /// any illegally typed nodes generated after this point will not experience
     302             :   /// type legalization.
     303             :   bool NewNodesMustHaveLegalTypes = false;
     304             : 
     305             : private:
     306             :   /// DAGUpdateListener is a friend so it can manipulate the listener stack.
     307             :   friend struct DAGUpdateListener;
     308             : 
     309             :   /// Linked list of registered DAGUpdateListener instances.
     310             :   /// This stack is maintained by DAGUpdateListener RAII.
     311             :   DAGUpdateListener *UpdateListeners = nullptr;
     312             : 
     313             :   /// Implementation of setSubgraphColor.
     314             :   /// Return whether we had to truncate the search.
     315             :   bool setSubgraphColorHelper(SDNode *N, const char *Color,
     316             :                               DenseSet<SDNode *> &visited,
     317             :                               int level, bool &printed);
     318             : 
     319             :   template <typename SDNodeT, typename... ArgTypes>
     320    19729294 :   SDNodeT *newSDNode(ArgTypes &&... Args) {
     321    19729294 :     return new (NodeAllocator.template Allocate<SDNodeT>())
     322    59012936 :         SDNodeT(std::forward<ArgTypes>(Args)...);
     323             :   }
     324             : 
     325             :   /// Build a synthetic SDNodeT with the given args and extract its subclass
     326             :   /// data as an integer (e.g. for use in a folding set).
     327             :   ///
     328             :   /// The args to this function are the same as the args to SDNodeT's
     329             :   /// constructor, except the second arg (assumed to be a const DebugLoc&) is
     330             :   /// omitted.
     331             :   template <typename SDNodeT, typename... ArgTypes>
     332     1946893 :   static uint16_t getSyntheticNodeSubclassData(unsigned IROrder,
     333             :                                                ArgTypes &&... Args) {
     334             :     // The compiler can reduce this expression to a constant iff we pass an
     335             :     // empty DebugLoc.  Thankfully, the debug location doesn't have any bearing
     336             :     // on the subclass data.
     337             :     return SDNodeT(IROrder, DebugLoc(), std::forward<ArgTypes>(Args)...)
     338     5840679 :         .getRawSubclassData();
     339             :   }
     340             : 
     341             :   template <typename SDNodeTy>
     342       14011 :   static uint16_t getSyntheticNodeSubclassData(unsigned Opc, unsigned Order,
     343             :                                                 SDVTList VTs, EVT MemoryVT,
     344             :                                                 MachineMemOperand *MMO) {
     345             :     return SDNodeTy(Opc, Order, DebugLoc(), VTs, MemoryVT, MMO)
     346       42033 :          .getRawSubclassData();
     347             :   }
     348             : 
     349    14818375 :   void createOperands(SDNode *Node, ArrayRef<SDValue> Vals) {
     350             :     assert(!Node->OperandList && "Node already has operands");
     351    14818375 :     SDUse *Ops = OperandRecycler.allocate(
     352    14818375 :         ArrayRecycler<SDUse>::Capacity::get(Vals.size()), OperandAllocator);
     353             : 
     354   107029181 :     for (unsigned I = 0; I != Vals.size(); ++I) {
     355    46105403 :       Ops[I].setUser(Node);
     356    46105403 :       Ops[I].setInitial(Vals[I]);
     357             :     }
     358    14818375 :     Node->NumOperands = Vals.size();
     359    14818375 :     Node->OperandList = Ops;
     360    14818375 :     checkForCycles(Node);
     361    14818375 :   }
     362             : 
     363    22670752 :   void removeOperands(SDNode *Node) {
     364    22670752 :     if (!Node->OperandList)
     365             :       return;
     366    29635870 :     OperandRecycler.deallocate(
     367    14817935 :         ArrayRecycler<SDUse>::Capacity::get(Node->NumOperands),
     368             :         Node->OperandList);
     369    14817935 :     Node->NumOperands = 0;
     370    14817935 :     Node->OperandList = nullptr;
     371             :   }
     372             : 
     373             : public:
     374             :   explicit SelectionDAG(const TargetMachine &TM, CodeGenOpt::Level);
     375             :   SelectionDAG(const SelectionDAG &) = delete;
     376             :   SelectionDAG &operator=(const SelectionDAG &) = delete;
     377             :   ~SelectionDAG();
     378             : 
     379             :   /// Prepare this SelectionDAG to process code in the given MachineFunction.
     380             :   void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE,
     381             :             Pass *PassPtr, const TargetLibraryInfo *LibraryInfo);
     382             : 
     383             :   /// Clear state and free memory necessary to make this
     384             :   /// SelectionDAG ready to process a new block.
     385             :   void clear();
     386             : 
     387             :   MachineFunction &getMachineFunction() const { return *MF; }
     388             :   const Pass *getPass() const { return SDAGISelPass; }
     389             : 
     390    48815876 :   const DataLayout &getDataLayout() const { return MF->getDataLayout(); }
     391             :   const TargetMachine &getTarget() const { return TM; }
     392     2795643 :   const TargetSubtargetInfo &getSubtarget() const { return MF->getSubtarget(); }
     393             :   const TargetLowering &getTargetLoweringInfo() const { return *TLI; }
     394             :   const TargetLibraryInfo &getLibInfo() const { return *LibInfo; }
     395             :   const SelectionDAGTargetInfo &getSelectionDAGInfo() const { return *TSI; }
     396             :   LLVMContext *getContext() const {return Context; }
     397             :   OptimizationRemarkEmitter &getORE() const { return *ORE; }
     398             : 
     399             :   /// Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
     400             :   void viewGraph(const std::string &Title);
     401             :   void viewGraph();
     402             : 
     403             : #ifndef NDEBUG
     404             :   std::map<const SDNode *, std::string> NodeGraphAttrs;
     405             : #endif
     406             : 
     407             :   /// Clear all previously defined node graph attributes.
     408             :   /// Intended to be used from a debugging tool (eg. gdb).
     409             :   void clearGraphAttrs();
     410             : 
     411             :   /// Set graph attributes for a node. (eg. "color=red".)
     412             :   void setGraphAttrs(const SDNode *N, const char *Attrs);
     413             : 
     414             :   /// Get graph attributes for a node. (eg. "color=red".)
     415             :   /// Used from getNodeAttributes.
     416             :   const std::string getGraphAttrs(const SDNode *N) const;
     417             : 
     418             :   /// Convenience for setting node color attribute.
     419             :   void setGraphColor(const SDNode *N, const char *Color);
     420             : 
     421             :   /// Convenience for setting subgraph color attribute.
     422             :   void setSubgraphColor(SDNode *N, const char *Color);
     423             : 
     424             :   using allnodes_const_iterator = ilist<SDNode>::const_iterator;
     425             : 
     426             :   allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
     427             :   allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
     428             : 
     429             :   using allnodes_iterator = ilist<SDNode>::iterator;
     430             : 
     431             :   allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
     432             :   allnodes_iterator allnodes_end() { return AllNodes.end(); }
     433             : 
     434             :   ilist<SDNode>::size_type allnodes_size() const {
     435             :     return AllNodes.size();
     436             :   }
     437             : 
     438             :   iterator_range<allnodes_iterator> allnodes() {
     439             :     return make_range(allnodes_begin(), allnodes_end());
     440             :   }
     441             :   iterator_range<allnodes_const_iterator> allnodes() const {
     442             :     return make_range(allnodes_begin(), allnodes_end());
     443             :   }
     444             : 
     445             :   /// Return the root tag of the SelectionDAG.
     446     3686310 :   const SDValue &getRoot() const { return Root; }
     447             : 
     448             :   /// Return the token chain corresponding to the entry of the function.
     449             :   SDValue getEntryNode() const {
     450     1698297 :     return SDValue(const_cast<SDNode *>(&EntryNode), 0);
     451             :   }
     452             : 
     453             :   /// Set the current root tag of the SelectionDAG.
     454             :   ///
     455     5546437 :   const SDValue &setRoot(SDValue N) {
     456             :     assert((!N.getNode() || N.getValueType() == MVT::Other) &&
     457             :            "DAG root value is not a chain!");
     458     5546437 :     if (N.getNode())
     459     5192059 :       checkForCycles(N.getNode(), this);
     460     5546439 :     Root = N;
     461     5546439 :     if (N.getNode())
     462     5192060 :       checkForCycles(this);
     463     5546439 :     return Root;
     464             :   }
     465             : 
     466             :   /// This iterates over the nodes in the SelectionDAG, folding
     467             :   /// certain types of nodes together, or eliminating superfluous nodes.  The
     468             :   /// Level argument controls whether Combine is allowed to produce nodes and
     469             :   /// types that are illegal on the target.
     470             :   void Combine(CombineLevel Level, AliasAnalysis *AA,
     471             :                CodeGenOpt::Level OptLevel);
     472             : 
     473             :   /// This transforms the SelectionDAG into a SelectionDAG that
     474             :   /// only uses types natively supported by the target.
     475             :   /// Returns "true" if it made any changes.
     476             :   ///
     477             :   /// Note that this is an involved process that may invalidate pointers into
     478             :   /// the graph.
     479             :   bool LegalizeTypes();
     480             : 
     481             :   /// This transforms the SelectionDAG into a SelectionDAG that is
     482             :   /// compatible with the target instruction selector, as indicated by the
     483             :   /// TargetLowering object.
     484             :   ///
     485             :   /// Note that this is an involved process that may invalidate pointers into
     486             :   /// the graph.
     487             :   void Legalize();
     488             : 
     489             :   /// \brief Transforms a SelectionDAG node and any operands to it into a node
     490             :   /// that is compatible with the target instruction selector, as indicated by
     491             :   /// the TargetLowering object.
     492             :   ///
     493             :   /// \returns true if \c N is a valid, legal node after calling this.
     494             :   ///
     495             :   /// This essentially runs a single recursive walk of the \c Legalize process
     496             :   /// over the given node (and its operands). This can be used to incrementally
     497             :   /// legalize the DAG. All of the nodes which are directly replaced,
     498             :   /// potentially including N, are added to the output parameter \c
     499             :   /// UpdatedNodes so that the delta to the DAG can be understood by the
     500             :   /// caller.
     501             :   ///
     502             :   /// When this returns false, N has been legalized in a way that make the
     503             :   /// pointer passed in no longer valid. It may have even been deleted from the
     504             :   /// DAG, and so it shouldn't be used further. When this returns true, the
     505             :   /// N passed in is a legal node, and can be immediately processed as such.
     506             :   /// This may still have done some work on the DAG, and will still populate
     507             :   /// UpdatedNodes with any new nodes replacing those originally in the DAG.
     508             :   bool LegalizeOp(SDNode *N, SmallSetVector<SDNode *, 16> &UpdatedNodes);
     509             : 
     510             :   /// This transforms the SelectionDAG into a SelectionDAG
     511             :   /// that only uses vector math operations supported by the target.  This is
     512             :   /// necessary as a separate step from Legalize because unrolling a vector
     513             :   /// operation can introduce illegal types, which requires running
     514             :   /// LegalizeTypes again.
     515             :   ///
     516             :   /// This returns true if it made any changes; in that case, LegalizeTypes
     517             :   /// is called again before Legalize.
     518             :   ///
     519             :   /// Note that this is an involved process that may invalidate pointers into
     520             :   /// the graph.
     521             :   bool LegalizeVectors();
     522             : 
     523             :   /// This method deletes all unreachable nodes in the SelectionDAG.
     524             :   void RemoveDeadNodes();
     525             : 
     526             :   /// Remove the specified node from the system.  This node must
     527             :   /// have no referrers.
     528             :   void DeleteNode(SDNode *N);
     529             : 
     530             :   /// Return an SDVTList that represents the list of values specified.
     531             :   SDVTList getVTList(EVT VT);
     532             :   SDVTList getVTList(EVT VT1, EVT VT2);
     533             :   SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3);
     534             :   SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3, EVT VT4);
     535             :   SDVTList getVTList(ArrayRef<EVT> VTs);
     536             : 
     537             :   //===--------------------------------------------------------------------===//
     538             :   // Node creation methods.
     539             : 
     540             :   /// \brief Create a ConstantSDNode wrapping a constant value.
     541             :   /// If VT is a vector type, the constant is splatted into a BUILD_VECTOR.
     542             :   ///
     543             :   /// If only legal types can be produced, this does the necessary
     544             :   /// transformations (e.g., if the vector element type is illegal).
     545             :   /// @{
     546             :   SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT,
     547             :                       bool isTarget = false, bool isOpaque = false);
     548             :   SDValue getConstant(const APInt &Val, const SDLoc &DL, EVT VT,
     549             :                       bool isTarget = false, bool isOpaque = false);
     550             : 
     551       13215 :   SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget = false,
     552             :                              bool IsOpaque = false) {
     553       26430 :     return getConstant(APInt::getAllOnesValue(VT.getScalarSizeInBits()), DL,
     554       39645 :                        VT, IsTarget, IsOpaque);
     555             :   }
     556             : 
     557             :   SDValue getConstant(const ConstantInt &Val, const SDLoc &DL, EVT VT,
     558             :                       bool isTarget = false, bool isOpaque = false);
     559             :   SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL,
     560             :                             bool isTarget = false);
     561             :   SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT,
     562             :                             bool isOpaque = false) {
     563     3795013 :     return getConstant(Val, DL, VT, true, isOpaque);
     564             :   }
     565             :   SDValue getTargetConstant(const APInt &Val, const SDLoc &DL, EVT VT,
     566             :                             bool isOpaque = false) {
     567      274898 :     return getConstant(Val, DL, VT, true, isOpaque);
     568             :   }
     569             :   SDValue getTargetConstant(const ConstantInt &Val, const SDLoc &DL, EVT VT,
     570             :                             bool isOpaque = false) {
     571      247730 :     return getConstant(Val, DL, VT, true, isOpaque);
     572             :   }
     573             : 
     574             :   /// \brief Create a true or false constant of type \p VT using the target's
     575             :   /// BooleanContent for type \p OpVT.
     576             :   SDValue getBoolConstant(bool V, const SDLoc &DL, EVT VT, EVT OpVT);
     577             :   /// @}
     578             : 
     579             :   /// \brief Create a ConstantFPSDNode wrapping a constant value.
     580             :   /// If VT is a vector type, the constant is splatted into a BUILD_VECTOR.
     581             :   ///
     582             :   /// If only legal types can be produced, this does the necessary
     583             :   /// transformations (e.g., if the vector element type is illegal).
     584             :   /// The forms that take a double should only be used for simple constants
     585             :   /// that can be exactly represented in VT.  No checks are made.
     586             :   /// @{
     587             :   SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT,
     588             :                         bool isTarget = false);
     589             :   SDValue getConstantFP(const APFloat &Val, const SDLoc &DL, EVT VT,
     590             :                         bool isTarget = false);
     591             :   SDValue getConstantFP(const ConstantFP &CF, const SDLoc &DL, EVT VT,
     592             :                         bool isTarget = false);
     593             :   SDValue getTargetConstantFP(double Val, const SDLoc &DL, EVT VT) {
     594             :     return getConstantFP(Val, DL, VT, true);
     595             :   }
     596             :   SDValue getTargetConstantFP(const APFloat &Val, const SDLoc &DL, EVT VT) {
     597           6 :     return getConstantFP(Val, DL, VT, true);
     598             :   }
     599             :   SDValue getTargetConstantFP(const ConstantFP &Val, const SDLoc &DL, EVT VT) {
     600         828 :     return getConstantFP(Val, DL, VT, true);
     601             :   }
     602             :   /// @}
     603             : 
     604             :   SDValue getGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT,
     605             :                            int64_t offset = 0, bool isTargetGA = false,
     606             :                            unsigned char TargetFlags = 0);
     607             :   SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT,
     608             :                                  int64_t offset = 0,
     609             :                                  unsigned char TargetFlags = 0) {
     610     1201160 :     return getGlobalAddress(GV, DL, VT, offset, true, TargetFlags);
     611             :   }
     612             :   SDValue getFrameIndex(int FI, EVT VT, bool isTarget = false);
     613             :   SDValue getTargetFrameIndex(int FI, EVT VT) {
     614      183309 :     return getFrameIndex(FI, VT, true);
     615             :   }
     616             :   SDValue getJumpTable(int JTI, EVT VT, bool isTarget = false,
     617             :                        unsigned char TargetFlags = 0);
     618             :   SDValue getTargetJumpTable(int JTI, EVT VT, unsigned char TargetFlags = 0) {
     619         351 :     return getJumpTable(JTI, VT, true, TargetFlags);
     620             :   }
     621             :   SDValue getConstantPool(const Constant *C, EVT VT,
     622             :                           unsigned Align = 0, int Offs = 0, bool isT=false,
     623             :                           unsigned char TargetFlags = 0);
     624             :   SDValue getTargetConstantPool(const Constant *C, EVT VT,
     625             :                                 unsigned Align = 0, int Offset = 0,
     626             :                                 unsigned char TargetFlags = 0) {
     627       43608 :     return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
     628             :   }
     629             :   SDValue getConstantPool(MachineConstantPoolValue *C, EVT VT,
     630             :                           unsigned Align = 0, int Offs = 0, bool isT=false,
     631             :                           unsigned char TargetFlags = 0);
     632             :   SDValue getTargetConstantPool(MachineConstantPoolValue *C,
     633             :                                   EVT VT, unsigned Align = 0,
     634             :                                   int Offset = 0, unsigned char TargetFlags=0) {
     635         257 :     return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
     636             :   }
     637             :   SDValue getTargetIndex(int Index, EVT VT, int64_t Offset = 0,
     638             :                          unsigned char TargetFlags = 0);
     639             :   // When generating a branch to a BB, we don't in general know enough
     640             :   // to provide debug info for the BB at that time, so keep this one around.
     641             :   SDValue getBasicBlock(MachineBasicBlock *MBB);
     642             :   SDValue getBasicBlock(MachineBasicBlock *MBB, SDLoc dl);
     643             :   SDValue getExternalSymbol(const char *Sym, EVT VT);
     644             :   SDValue getExternalSymbol(const char *Sym, const SDLoc &dl, EVT VT);
     645             :   SDValue getTargetExternalSymbol(const char *Sym, EVT VT,
     646             :                                   unsigned char TargetFlags = 0);
     647             :   SDValue getMCSymbol(MCSymbol *Sym, EVT VT);
     648             : 
     649             :   SDValue getValueType(EVT);
     650             :   SDValue getRegister(unsigned Reg, EVT VT);
     651             :   SDValue getRegisterMask(const uint32_t *RegMask);
     652             :   SDValue getEHLabel(const SDLoc &dl, SDValue Root, MCSymbol *Label);
     653             :   SDValue getLabelNode(unsigned Opcode, const SDLoc &dl, SDValue Root,
     654             :                        MCSymbol *Label);
     655             :   SDValue getBlockAddress(const BlockAddress *BA, EVT VT,
     656             :                           int64_t Offset = 0, bool isTarget = false,
     657             :                           unsigned char TargetFlags = 0);
     658             :   SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT,
     659             :                                 int64_t Offset = 0,
     660             :                                 unsigned char TargetFlags = 0) {
     661         135 :     return getBlockAddress(BA, VT, Offset, true, TargetFlags);
     662             :   }
     663             : 
     664      143627 :   SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg,
     665             :                        SDValue N) {
     666             :     return getNode(ISD::CopyToReg, dl, MVT::Other, Chain,
     667      430881 :                    getRegister(Reg, N.getValueType()), N);
     668             :   }
     669             : 
     670             :   // This version of the getCopyToReg method takes an extra operand, which
     671             :   // indicates that there is potentially an incoming glue value (if Glue is not
     672             :   // null) and that there should be a glue result.
     673      688401 :   SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N,
     674             :                        SDValue Glue) {
     675      688401 :     SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
     676     1376804 :     SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Glue };
     677             :     return getNode(ISD::CopyToReg, dl, VTs,
     678      688402 :                    makeArrayRef(Ops, Glue.getNode() ? 4 : 3));
     679             :   }
     680             : 
     681             :   // Similar to last getCopyToReg() except parameter Reg is a SDValue
     682        1755 :   SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, SDValue Reg, SDValue N,
     683             :                        SDValue Glue) {
     684        1755 :     SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
     685        1755 :     SDValue Ops[] = { Chain, Reg, N, Glue };
     686             :     return getNode(ISD::CopyToReg, dl, VTs,
     687        1755 :                    makeArrayRef(Ops, Glue.getNode() ? 4 : 3));
     688             :   }
     689             : 
     690      571400 :   SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT) {
     691      571400 :     SDVTList VTs = getVTList(VT, MVT::Other);
     692      571400 :     SDValue Ops[] = { Chain, getRegister(Reg, VT) };
     693      571400 :     return getNode(ISD::CopyFromReg, dl, VTs, Ops);
     694             :   }
     695             : 
     696             :   // This version of the getCopyFromReg method takes an extra operand, which
     697             :   // indicates that there is potentially an incoming glue value (if Glue is not
     698             :   // null) and that there should be a glue result.
     699       54505 :   SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT,
     700             :                          SDValue Glue) {
     701       54505 :     SDVTList VTs = getVTList(VT, MVT::Other, MVT::Glue);
     702       54505 :     SDValue Ops[] = { Chain, getRegister(Reg, VT), Glue };
     703             :     return getNode(ISD::CopyFromReg, dl, VTs,
     704       54505 :                    makeArrayRef(Ops, Glue.getNode() ? 3 : 2));
     705             :   }
     706             : 
     707             :   SDValue getCondCode(ISD::CondCode Cond);
     708             : 
     709             :   /// Return an ISD::VECTOR_SHUFFLE node. The number of elements in VT,
     710             :   /// which must be a vector type, must match the number of mask elements
     711             :   /// NumElts. An integer mask element equal to -1 is treated as undefined.
     712             :   SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2,
     713             :                            ArrayRef<int> Mask);
     714             : 
     715             :   /// Return an ISD::BUILD_VECTOR node. The number of elements in VT,
     716             :   /// which must be a vector type, must match the number of operands in Ops.
     717             :   /// The operands must have the same type as (or, for integers, a type wider
     718             :   /// than) VT's element type.
     719      272538 :   SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef<SDValue> Ops) {
     720             :     // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
     721      272538 :     return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
     722             :   }
     723             : 
     724             :   /// Return an ISD::BUILD_VECTOR node. The number of elements in VT,
     725             :   /// which must be a vector type, must match the number of operands in Ops.
     726             :   /// The operands must have the same type as (or, for integers, a type wider
     727             :   /// than) VT's element type.
     728             :   SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef<SDUse> Ops) {
     729             :     // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
     730        3915 :     return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
     731             :   }
     732             : 
     733             :   /// Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all
     734             :   /// elements. VT must be a vector type. Op's type must be the same as (or,
     735             :   /// for integers, a type wider than) VT's element type.
     736      144229 :   SDValue getSplatBuildVector(EVT VT, const SDLoc &DL, SDValue Op) {
     737             :     // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
     738      288458 :     if (Op.getOpcode() == ISD::UNDEF) {
     739             :       assert((VT.getVectorElementType() == Op.getValueType() ||
     740             :               (VT.isInteger() &&
     741             :                VT.getVectorElementType().bitsLE(Op.getValueType()))) &&
     742             :              "A splatted value must have a width equal or (for integers) "
     743             :              "greater than the vector element type!");
     744           0 :       return getNode(ISD::UNDEF, SDLoc(), VT);
     745             :     }
     746             : 
     747      144229 :     SmallVector<SDValue, 16> Ops(VT.getVectorNumElements(), Op);
     748      144229 :     return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
     749             :   }
     750             : 
     751             :   /// \brief Returns an ISD::VECTOR_SHUFFLE node semantically equivalent to
     752             :   /// the shuffle node in input but with swapped operands.
     753             :   ///
     754             :   /// Example: shuffle A, B, <0,5,2,7> -> shuffle B, A, <4,1,6,3>
     755             :   SDValue getCommutedVectorShuffle(const ShuffleVectorSDNode &SV);
     756             : 
     757             :   /// Convert Op, which must be of float type, to the
     758             :   /// float type VT, by either extending or rounding (by truncation).
     759             :   SDValue getFPExtendOrRound(SDValue Op, const SDLoc &DL, EVT VT);
     760             : 
     761             :   /// Convert Op, which must be of integer type, to the
     762             :   /// integer type VT, by either any-extending or truncating it.
     763             :   SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
     764             : 
     765             :   /// Convert Op, which must be of integer type, to the
     766             :   /// integer type VT, by either sign-extending or truncating it.
     767             :   SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
     768             : 
     769             :   /// Convert Op, which must be of integer type, to the
     770             :   /// integer type VT, by either zero-extending or truncating it.
     771             :   SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
     772             : 
     773             :   /// Return the expression required to zero extend the Op
     774             :   /// value assuming it was the smaller SrcTy value.
     775             :   SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT SrcTy);
     776             : 
     777             :   /// Return an operation which will any-extend the low lanes of the operand
     778             :   /// into the specified vector type. For example,
     779             :   /// this can convert a v16i8 into a v4i32 by any-extending the low four
     780             :   /// lanes of the operand from i8 to i32.
     781             :   SDValue getAnyExtendVectorInReg(SDValue Op, const SDLoc &DL, EVT VT);
     782             : 
     783             :   /// Return an operation which will sign extend the low lanes of the operand
     784             :   /// into the specified vector type. For example,
     785             :   /// this can convert a v16i8 into a v4i32 by sign extending the low four
     786             :   /// lanes of the operand from i8 to i32.
     787             :   SDValue getSignExtendVectorInReg(SDValue Op, const SDLoc &DL, EVT VT);
     788             : 
     789             :   /// Return an operation which will zero extend the low lanes of the operand
     790             :   /// into the specified vector type. For example,
     791             :   /// this can convert a v16i8 into a v4i32 by zero extending the low four
     792             :   /// lanes of the operand from i8 to i32.
     793             :   SDValue getZeroExtendVectorInReg(SDValue Op, const SDLoc &DL, EVT VT);
     794             : 
     795             :   /// Convert Op, which must be of integer type, to the integer type VT,
     796             :   /// by using an extension appropriate for the target's
     797             :   /// BooleanContent for type OpVT or truncating it.
     798             :   SDValue getBoolExtOrTrunc(SDValue Op, const SDLoc &SL, EVT VT, EVT OpVT);
     799             : 
     800             :   /// Create a bitwise NOT operation as (XOR Val, -1).
     801             :   SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT);
     802             : 
     803             :   /// \brief Create a logical NOT operation as (XOR Val, BooleanOne).
     804             :   SDValue getLogicalNOT(const SDLoc &DL, SDValue Val, EVT VT);
     805             : 
     806             :   /// \brief Create an add instruction with appropriate flags when used for
     807             :   /// addressing some offset of an object. i.e. if a load is split into multiple
     808             :   /// components, create an add nuw from the base pointer to the offset.
     809      101988 :   SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Op, int64_t Offset) {
     810      203976 :     EVT VT = Op.getValueType();
     811      101988 :     return getObjectPtrOffset(SL, Op, getConstant(Offset, SL, VT));
     812             :   }
     813             : 
     814      102159 :   SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Op, SDValue Offset) {
     815      204318 :     EVT VT = Op.getValueType();
     816             : 
     817             :     // The object itself can't wrap around the address space, so it shouldn't be
     818             :     // possible for the adds of the offsets to the split parts to overflow.
     819             :     SDNodeFlags Flags;
     820             :     Flags.setNoUnsignedWrap(true);
     821      102159 :     return getNode(ISD::ADD, SL, VT, Op, Offset, Flags);
     822             :   }
     823             : 
     824             :   /// Return a new CALLSEQ_START node, that starts new call frame, in which
     825             :   /// InSize bytes are set up inside CALLSEQ_START..CALLSEQ_END sequence and
     826             :   /// OutSize specifies part of the frame set up prior to the sequence.
     827      215782 :   SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize,
     828             :                            const SDLoc &DL) {
     829      215782 :     SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
     830             :     SDValue Ops[] = { Chain,
     831             :                       getIntPtrConstant(InSize, DL, true),
     832      215782 :                       getIntPtrConstant(OutSize, DL, true) };
     833      215782 :     return getNode(ISD::CALLSEQ_START, DL, VTs, Ops);
     834             :   }
     835             : 
     836             :   /// Return a new CALLSEQ_END node, which always must have a
     837             :   /// glue result (to ensure it's not CSE'd).
     838             :   /// CALLSEQ_END does not have a useful SDLoc.
     839      215732 :   SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2,
     840             :                          SDValue InGlue, const SDLoc &DL) {
     841      215732 :     SDVTList NodeTys = getVTList(MVT::Other, MVT::Glue);
     842             :     SmallVector<SDValue, 4> Ops;
     843      215732 :     Ops.push_back(Chain);
     844      215732 :     Ops.push_back(Op1);
     845      215732 :     Ops.push_back(Op2);
     846      215732 :     if (InGlue.getNode())
     847      215331 :       Ops.push_back(InGlue);
     848      431464 :     return getNode(ISD::CALLSEQ_END, DL, NodeTys, Ops);
     849             :   }
     850             : 
     851             :   /// Return true if the result of this operation is always undefined.
     852             :   bool isUndef(unsigned Opcode, ArrayRef<SDValue> Ops);
     853             : 
     854             :   /// Return an UNDEF node. UNDEF does not have a useful SDLoc.
     855     2302312 :   SDValue getUNDEF(EVT VT) {
     856     4604624 :     return getNode(ISD::UNDEF, SDLoc(), VT);
     857             :   }
     858             : 
     859             :   /// Return a GLOBAL_OFFSET_TABLE node. This does not have a useful SDLoc.
     860          17 :   SDValue getGLOBAL_OFFSET_TABLE(EVT VT) {
     861          34 :     return getNode(ISD::GLOBAL_OFFSET_TABLE, SDLoc(), VT);
     862             :   }
     863             : 
     864             :   /// Gets or creates the specified node.
     865             :   ///
     866             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     867             :                   ArrayRef<SDUse> Ops);
     868             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     869             :                   ArrayRef<SDValue> Ops, const SDNodeFlags Flags = SDNodeFlags());
     870             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, ArrayRef<EVT> ResultTys,
     871             :                   ArrayRef<SDValue> Ops);
     872             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTs,
     873             :                   ArrayRef<SDValue> Ops);
     874             : 
     875             :   // Specialize based on number of operands.
     876             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT);
     877             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N,
     878             :                   const SDNodeFlags Flags = SDNodeFlags());
     879             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
     880             :                   SDValue N2, const SDNodeFlags Flags = SDNodeFlags());
     881             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
     882             :                   SDValue N2, SDValue N3);
     883             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
     884             :                   SDValue N2, SDValue N3, SDValue N4);
     885             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
     886             :                   SDValue N2, SDValue N3, SDValue N4, SDValue N5);
     887             : 
     888             :   // Specialize again based on number of operands for nodes with a VTList
     889             :   // rather than a single VT.
     890             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTs);
     891             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTs, SDValue N);
     892             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTs, SDValue N1,
     893             :                   SDValue N2);
     894             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTs, SDValue N1,
     895             :                   SDValue N2, SDValue N3);
     896             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTs, SDValue N1,
     897             :                   SDValue N2, SDValue N3, SDValue N4);
     898             :   SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTs, SDValue N1,
     899             :                   SDValue N2, SDValue N3, SDValue N4, SDValue N5);
     900             : 
     901             :   /// Compute a TokenFactor to force all the incoming stack arguments to be
     902             :   /// loaded from the stack. This is used in tail call lowering to protect
     903             :   /// stack arguments from being clobbered.
     904             :   SDValue getStackArgumentTokenFactor(SDValue Chain);
     905             : 
     906             :   SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src,
     907             :                     SDValue Size, unsigned Align, bool isVol, bool AlwaysInline,
     908             :                     bool isTailCall, MachinePointerInfo DstPtrInfo,
     909             :                     MachinePointerInfo SrcPtrInfo);
     910             : 
     911             :   SDValue getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src,
     912             :                      SDValue Size, unsigned Align, bool isVol, bool isTailCall,
     913             :                      MachinePointerInfo DstPtrInfo,
     914             :                      MachinePointerInfo SrcPtrInfo);
     915             : 
     916             :   SDValue getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src,
     917             :                     SDValue Size, unsigned Align, bool isVol, bool isTailCall,
     918             :                     MachinePointerInfo DstPtrInfo);
     919             : 
     920             :   /// Helper function to make it easier to build SetCC's if you just
     921             :   /// have an ISD::CondCode instead of an SDValue.
     922             :   ///
     923      138783 :   SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS,
     924             :                    ISD::CondCode Cond) {
     925             :     assert(LHS.getValueType().isVector() == RHS.getValueType().isVector() &&
     926             :       "Cannot compare scalars to vectors");
     927             :     assert(LHS.getValueType().isVector() == VT.isVector() &&
     928             :       "Cannot compare scalars to vectors");
     929             :     assert(Cond != ISD::SETCC_INVALID &&
     930             :         "Cannot create a setCC of an invalid node.");
     931      138783 :     return getNode(ISD::SETCC, DL, VT, LHS, RHS, getCondCode(Cond));
     932             :   }
     933             : 
     934             :   /// Helper function to make it easier to build Select's if you just
     935             :   /// have operands and don't want to check for vector.
     936       36359 :   SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS,
     937             :                     SDValue RHS) {
     938             :     assert(LHS.getValueType() == RHS.getValueType() &&
     939             :            "Cannot use select on differing types");
     940             :     assert(VT.isVector() == LHS.getValueType().isVector() &&
     941             :            "Cannot mix vectors and scalars");
     942      109077 :     return getNode(Cond.getValueType().isVector() ? ISD::VSELECT : ISD::SELECT, DL, VT,
     943       72718 :                    Cond, LHS, RHS);
     944             :   }
     945             : 
     946             :   /// Helper function to make it easier to build SelectCC's if you
     947             :   /// just have an ISD::CondCode instead of an SDValue.
     948             :   ///
     949        5010 :   SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True,
     950             :                       SDValue False, ISD::CondCode Cond) {
     951             :     return getNode(ISD::SELECT_CC, DL, True.getValueType(),
     952       10020 :                    LHS, RHS, True, False, getCondCode(Cond));
     953             :   }
     954             : 
     955             :   /// VAArg produces a result and token chain, and takes a pointer
     956             :   /// and a source value as input.
     957             :   SDValue getVAArg(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
     958             :                    SDValue SV, unsigned Align);
     959             : 
     960             :   /// Gets a node for an atomic cmpxchg op. There are two
     961             :   /// valid Opcodes. ISD::ATOMIC_CMO_SWAP produces the value loaded and a
     962             :   /// chain result. ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS produces the value loaded,
     963             :   /// a success flag (initially i1), and a chain.
     964             :   SDValue getAtomicCmpSwap(unsigned Opcode, const SDLoc &dl, EVT MemVT,
     965             :                            SDVTList VTs, SDValue Chain, SDValue Ptr,
     966             :                            SDValue Cmp, SDValue Swp, MachinePointerInfo PtrInfo,
     967             :                            unsigned Alignment, AtomicOrdering SuccessOrdering,
     968             :                            AtomicOrdering FailureOrdering,
     969             :                            SyncScope::ID SSID);
     970             :   SDValue getAtomicCmpSwap(unsigned Opcode, const SDLoc &dl, EVT MemVT,
     971             :                            SDVTList VTs, SDValue Chain, SDValue Ptr,
     972             :                            SDValue Cmp, SDValue Swp, MachineMemOperand *MMO);
     973             : 
     974             :   /// Gets a node for an atomic op, produces result (if relevant)
     975             :   /// and chain and takes 2 operands.
     976             :   SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDValue Chain,
     977             :                     SDValue Ptr, SDValue Val, const Value *PtrVal,
     978             :                     unsigned Alignment, AtomicOrdering Ordering,
     979             :                     SyncScope::ID SSID);
     980             :   SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDValue Chain,
     981             :                     SDValue Ptr, SDValue Val, MachineMemOperand *MMO);
     982             : 
     983             :   /// Gets a node for an atomic op, produces result and chain and
     984             :   /// takes 1 operand.
     985             :   SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, EVT VT,
     986             :                     SDValue Chain, SDValue Ptr, MachineMemOperand *MMO);
     987             : 
     988             :   /// Gets a node for an atomic op, produces result and chain and takes N
     989             :   /// operands.
     990             :   SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT,
     991             :                     SDVTList VTList, ArrayRef<SDValue> Ops,
     992             :                     MachineMemOperand *MMO);
     993             : 
     994             :   /// Creates a MemIntrinsicNode that may produce a
     995             :   /// result and takes a list of operands. Opcode may be INTRINSIC_VOID,
     996             :   /// INTRINSIC_W_CHAIN, or a target-specific opcode with a value not
     997             :   /// less than FIRST_TARGET_MEMORY_OPCODE.
     998             :   SDValue getMemIntrinsicNode(
     999             :     unsigned Opcode, const SDLoc &dl, SDVTList VTList,
    1000             :     ArrayRef<SDValue> Ops, EVT MemVT,
    1001             :     MachinePointerInfo PtrInfo,
    1002             :     unsigned Align = 0,
    1003             :     MachineMemOperand::Flags Flags
    1004             :     = MachineMemOperand::MOLoad | MachineMemOperand::MOStore,
    1005             :     unsigned Size = 0);
    1006             : 
    1007             :   SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList,
    1008             :                               ArrayRef<SDValue> Ops, EVT MemVT,
    1009             :                               MachineMemOperand *MMO);
    1010             : 
    1011             :   /// Create a MERGE_VALUES node from the given operands.
    1012             :   SDValue getMergeValues(ArrayRef<SDValue> Ops, const SDLoc &dl);
    1013             : 
    1014             :   /// Loads are not normal binary operators: their result type is not
    1015             :   /// determined by their operands, and they produce a value AND a token chain.
    1016             :   ///
    1017             :   /// This function will set the MOLoad flag on MMOFlags, but you can set it if
    1018             :   /// you want.  The MOStore flag must not be set.
    1019             :   SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
    1020             :                   MachinePointerInfo PtrInfo, unsigned Alignment = 0,
    1021             :                   MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
    1022             :                   const AAMDNodes &AAInfo = AAMDNodes(),
    1023             :                   const MDNode *Ranges = nullptr);
    1024             :   SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
    1025             :                   MachineMemOperand *MMO);
    1026             :   SDValue
    1027             :   getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain,
    1028             :              SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT,
    1029             :              unsigned Alignment = 0,
    1030             :              MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
    1031             :              const AAMDNodes &AAInfo = AAMDNodes());
    1032             :   SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT,
    1033             :                      SDValue Chain, SDValue Ptr, EVT MemVT,
    1034             :                      MachineMemOperand *MMO);
    1035             :   SDValue getIndexedLoad(SDValue OrigLoad, const SDLoc &dl, SDValue Base,
    1036             :                          SDValue Offset, ISD::MemIndexedMode AM);
    1037             :   SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT,
    1038             :                   const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset,
    1039             :                   MachinePointerInfo PtrInfo, EVT MemVT, unsigned Alignment = 0,
    1040             :                   MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
    1041             :                   const AAMDNodes &AAInfo = AAMDNodes(),
    1042             :                   const MDNode *Ranges = nullptr);
    1043             :   SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT,
    1044             :                   const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset,
    1045             :                   EVT MemVT, MachineMemOperand *MMO);
    1046             : 
    1047             :   /// Helper function to build ISD::STORE nodes.
    1048             :   ///
    1049             :   /// This function will set the MOStore flag on MMOFlags, but you can set it if
    1050             :   /// you want.  The MOLoad and MOInvariant flags must not be set.
    1051             :   SDValue
    1052             :   getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr,
    1053             :            MachinePointerInfo PtrInfo, unsigned Alignment = 0,
    1054             :            MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
    1055             :            const AAMDNodes &AAInfo = AAMDNodes());
    1056             :   SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr,
    1057             :                    MachineMemOperand *MMO);
    1058             :   SDValue
    1059             :   getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr,
    1060             :                 MachinePointerInfo PtrInfo, EVT TVT, unsigned Alignment = 0,
    1061             :                 MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
    1062             :                 const AAMDNodes &AAInfo = AAMDNodes());
    1063             :   SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val,
    1064             :                         SDValue Ptr, EVT TVT, MachineMemOperand *MMO);
    1065             :   SDValue getIndexedStore(SDValue OrigStoe, const SDLoc &dl, SDValue Base,
    1066             :                           SDValue Offset, ISD::MemIndexedMode AM);
    1067             : 
    1068             :   /// Returns sum of the base pointer and offset.
    1069             :   SDValue getMemBasePlusOffset(SDValue Base, unsigned Offset, const SDLoc &DL);
    1070             : 
    1071             :   SDValue getMaskedLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
    1072             :                         SDValue Mask, SDValue Src0, EVT MemVT,
    1073             :                         MachineMemOperand *MMO, ISD::LoadExtType,
    1074             :                         bool IsExpanding = false);
    1075             :   SDValue getMaskedStore(SDValue Chain, const SDLoc &dl, SDValue Val,
    1076             :                          SDValue Ptr, SDValue Mask, EVT MemVT,
    1077             :                          MachineMemOperand *MMO, bool IsTruncating = false,
    1078             :                          bool IsCompressing = false);
    1079             :   SDValue getMaskedGather(SDVTList VTs, EVT VT, const SDLoc &dl,
    1080             :                           ArrayRef<SDValue> Ops, MachineMemOperand *MMO);
    1081             :   SDValue getMaskedScatter(SDVTList VTs, EVT VT, const SDLoc &dl,
    1082             :                            ArrayRef<SDValue> Ops, MachineMemOperand *MMO);
    1083             : 
    1084             :   /// Return (create a new or find existing) a target-specific node.
    1085             :   /// TargetMemSDNode should be derived class from MemSDNode.
    1086             :   template <class TargetMemSDNode>
    1087             :   SDValue getTargetMemSDNode(SDVTList VTs, ArrayRef<SDValue> Ops,
    1088             :                              const SDLoc &dl, EVT MemVT,
    1089             :                              MachineMemOperand *MMO);
    1090             : 
    1091             :   /// Construct a node to track a Value* through the backend.
    1092             :   SDValue getSrcValue(const Value *v);
    1093             : 
    1094             :   /// Return an MDNodeSDNode which holds an MDNode.
    1095             :   SDValue getMDNode(const MDNode *MD);
    1096             : 
    1097             :   /// Return a bitcast using the SDLoc of the value operand, and casting to the
    1098             :   /// provided type. Use getNode to set a custom SDLoc.
    1099             :   SDValue getBitcast(EVT VT, SDValue V);
    1100             : 
    1101             :   /// Return an AddrSpaceCastSDNode.
    1102             :   SDValue getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr, unsigned SrcAS,
    1103             :                            unsigned DestAS);
    1104             : 
    1105             :   /// Return the specified value casted to
    1106             :   /// the target's desired shift amount type.
    1107             :   SDValue getShiftAmountOperand(EVT LHSTy, SDValue Op);
    1108             : 
    1109             :   /// Expand the specified \c ISD::VAARG node as the Legalize pass would.
    1110             :   SDValue expandVAArg(SDNode *Node);
    1111             : 
    1112             :   /// Expand the specified \c ISD::VACOPY node as the Legalize pass would.
    1113             :   SDValue expandVACopy(SDNode *Node);
    1114             : 
    1115             :   /// *Mutate* the specified node in-place to have the
    1116             :   /// specified operands.  If the resultant node already exists in the DAG,
    1117             :   /// this does not modify the specified node, instead it returns the node that
    1118             :   /// already exists.  If the resultant node does not exist in the DAG, the
    1119             :   /// input node is returned.  As a degenerate case, if you specify the same
    1120             :   /// input operands as the node already has, the input node is returned.
    1121             :   SDNode *UpdateNodeOperands(SDNode *N, SDValue Op);
    1122             :   SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2);
    1123             :   SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
    1124             :                                SDValue Op3);
    1125             :   SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
    1126             :                                SDValue Op3, SDValue Op4);
    1127             :   SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
    1128             :                                SDValue Op3, SDValue Op4, SDValue Op5);
    1129             :   SDNode *UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops);
    1130             : 
    1131             :   /// These are used for target selectors to *mutate* the
    1132             :   /// specified node to have the specified return type, Target opcode, and
    1133             :   /// operands.  Note that target opcodes are stored as
    1134             :   /// ~TargetOpcode in the node opcode field.  The resultant node is returned.
    1135             :   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT);
    1136             :   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT, SDValue Op1);
    1137             :   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
    1138             :                        SDValue Op1, SDValue Op2);
    1139             :   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
    1140             :                        SDValue Op1, SDValue Op2, SDValue Op3);
    1141             :   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
    1142             :                        ArrayRef<SDValue> Ops);
    1143             :   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1, EVT VT2);
    1144             :   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
    1145             :                        EVT VT2, ArrayRef<SDValue> Ops);
    1146             :   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
    1147             :                        EVT VT2, EVT VT3, ArrayRef<SDValue> Ops);
    1148             :   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
    1149             :                        EVT VT2, SDValue Op1);
    1150             :   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
    1151             :                        EVT VT2, SDValue Op1, SDValue Op2);
    1152             :   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs,
    1153             :                        ArrayRef<SDValue> Ops);
    1154             : 
    1155             :   /// This *mutates* the specified node to have the specified
    1156             :   /// return type, opcode, and operands.
    1157             :   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
    1158             :                       ArrayRef<SDValue> Ops);
    1159             : 
    1160             :   /// Mutate the specified strict FP node to its non-strict equivalent,
    1161             :   /// unlinking the node from its chain and dropping the metadata arguments.
    1162             :   /// The node must be a strict FP node.
    1163             :   SDNode *mutateStrictFPToFP(SDNode *Node);
    1164             : 
    1165             :   /// These are used for target selectors to create a new node
    1166             :   /// with specified return type(s), MachineInstr opcode, and operands.
    1167             :   ///
    1168             :   /// Note that getMachineNode returns the resultant node.  If there is already
    1169             :   /// a node of the specified opcode and operands, it returns that node instead
    1170             :   /// of the current one.
    1171             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT);
    1172             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
    1173             :                                 SDValue Op1);
    1174             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
    1175             :                                 SDValue Op1, SDValue Op2);
    1176             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
    1177             :                                 SDValue Op1, SDValue Op2, SDValue Op3);
    1178             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
    1179             :                                 ArrayRef<SDValue> Ops);
    1180             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
    1181             :                                 EVT VT2, SDValue Op1, SDValue Op2);
    1182             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
    1183             :                                 EVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
    1184             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
    1185             :                                 EVT VT2, ArrayRef<SDValue> Ops);
    1186             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
    1187             :                                 EVT VT2, EVT VT3, SDValue Op1, SDValue Op2);
    1188             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
    1189             :                                 EVT VT2, EVT VT3, SDValue Op1, SDValue Op2,
    1190             :                                 SDValue Op3);
    1191             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
    1192             :                                 EVT VT2, EVT VT3, ArrayRef<SDValue> Ops);
    1193             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl,
    1194             :                                 ArrayRef<EVT> ResultTys, ArrayRef<SDValue> Ops);
    1195             :   MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, SDVTList VTs,
    1196             :                                 ArrayRef<SDValue> Ops);
    1197             : 
    1198             :   /// A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
    1199             :   SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT,
    1200             :                                  SDValue Operand);
    1201             : 
    1202             :   /// A convenience function for creating TargetInstrInfo::INSERT_SUBREG nodes.
    1203             :   SDValue getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT,
    1204             :                                 SDValue Operand, SDValue Subreg);
    1205             : 
    1206             :   /// Get the specified node if it's already available, or else return NULL.
    1207             :   SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs, ArrayRef<SDValue> Ops,
    1208             :                           const SDNodeFlags Flags = SDNodeFlags());
    1209             : 
    1210             :   /// Creates a SDDbgValue node.
    1211             :   SDDbgValue *getDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N,
    1212             :                           unsigned R, bool IsIndirect, const DebugLoc &DL,
    1213             :                           unsigned O);
    1214             : 
    1215             :   /// Creates a constant SDDbgValue node.
    1216             :   SDDbgValue *getConstantDbgValue(DIVariable *Var, DIExpression *Expr,
    1217             :                                   const Value *C, const DebugLoc &DL,
    1218             :                                   unsigned O);
    1219             : 
    1220             :   /// Creates a FrameIndex SDDbgValue node.
    1221             :   SDDbgValue *getFrameIndexDbgValue(DIVariable *Var, DIExpression *Expr,
    1222             :                                     unsigned FI, const DebugLoc &DL,
    1223             :                                     unsigned O);
    1224             : 
    1225             :   /// Transfer debug values from one node to another, while optionally
    1226             :   /// generating fragment expressions for split-up values. If \p InvalidateDbg
    1227             :   /// is set, debug values are invalidated after they are transferred.
    1228             :   void transferDbgValues(SDValue From, SDValue To, unsigned OffsetInBits = 0,
    1229             :                          unsigned SizeInBits = 0, bool InvalidateDbg = true);
    1230             : 
    1231             :   /// Remove the specified node from the system. If any of its
    1232             :   /// operands then becomes dead, remove them as well. Inform UpdateListener
    1233             :   /// for each node deleted.
    1234             :   void RemoveDeadNode(SDNode *N);
    1235             : 
    1236             :   /// This method deletes the unreachable nodes in the
    1237             :   /// given list, and any nodes that become unreachable as a result.
    1238             :   void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes);
    1239             : 
    1240             :   /// Modify anything using 'From' to use 'To' instead.
    1241             :   /// This can cause recursive merging of nodes in the DAG.  Use the first
    1242             :   /// version if 'From' is known to have a single result, use the second
    1243             :   /// if you have two nodes with identical results (or if 'To' has a superset
    1244             :   /// of the results of 'From'), use the third otherwise.
    1245             :   ///
    1246             :   /// These methods all take an optional UpdateListener, which (if not null) is
    1247             :   /// informed about nodes that are deleted and modified due to recursive
    1248             :   /// changes in the dag.
    1249             :   ///
    1250             :   /// These functions only replace all existing uses. It's possible that as
    1251             :   /// these replacements are being performed, CSE may cause the From node
    1252             :   /// to be given new uses. These new uses of From are left in place, and
    1253             :   /// not automatically transferred to To.
    1254             :   ///
    1255             :   void ReplaceAllUsesWith(SDValue From, SDValue Op);
    1256             :   void ReplaceAllUsesWith(SDNode *From, SDNode *To);
    1257             :   void ReplaceAllUsesWith(SDNode *From, const SDValue *To);
    1258             : 
    1259             :   /// Replace any uses of From with To, leaving
    1260             :   /// uses of other values produced by From.getNode() alone.
    1261             :   void ReplaceAllUsesOfValueWith(SDValue From, SDValue To);
    1262             : 
    1263             :   /// Like ReplaceAllUsesOfValueWith, but for multiple values at once.
    1264             :   /// This correctly handles the case where
    1265             :   /// there is an overlap between the From values and the To values.
    1266             :   void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To,
    1267             :                                   unsigned Num);
    1268             : 
    1269             :   /// If an existing load has uses of its chain, create a token factor node with
    1270             :   /// that chain and the new memory node's chain and update users of the old
    1271             :   /// chain to the token factor. This ensures that the new memory node will have
    1272             :   /// the same relative memory dependency position as the old load. Returns the
    1273             :   /// new merged load chain.
    1274             :   SDValue makeEquivalentMemoryOrdering(LoadSDNode *Old, SDValue New);
    1275             : 
    1276             :   /// Topological-sort the AllNodes list and a
    1277             :   /// assign a unique node id for each node in the DAG based on their
    1278             :   /// topological order. Returns the number of nodes.
    1279             :   unsigned AssignTopologicalOrder();
    1280             : 
    1281             :   /// Move node N in the AllNodes list to be immediately
    1282             :   /// before the given iterator Position. This may be used to update the
    1283             :   /// topological ordering when the list of nodes is modified.
    1284             :   void RepositionNode(allnodes_iterator Position, SDNode *N) {
    1285             :     AllNodes.insert(Position, AllNodes.remove(N));
    1286             :   }
    1287             : 
    1288             :   /// Returns an APFloat semantics tag appropriate for the given type. If VT is
    1289             :   /// a vector type, the element semantics are returned.
    1290        5180 :   static const fltSemantics &EVTToAPFloatSemantics(EVT VT) {
    1291        5180 :     switch (VT.getScalarType().getSimpleVT().SimpleTy) {
    1292           0 :     default: llvm_unreachable("Unknown FP format");
    1293         177 :     case MVT::f16:     return APFloat::IEEEhalf();
    1294        2183 :     case MVT::f32:     return APFloat::IEEEsingle();
    1295        2677 :     case MVT::f64:     return APFloat::IEEEdouble();
    1296         111 :     case MVT::f80:     return APFloat::x87DoubleExtended();
    1297          30 :     case MVT::f128:    return APFloat::IEEEquad();
    1298           2 :     case MVT::ppcf128: return APFloat::PPCDoubleDouble();
    1299             :     }
    1300             :   }
    1301             : 
    1302             :   /// Add a dbg_value SDNode. If SD is non-null that means the
    1303             :   /// value is produced by SD.
    1304             :   void AddDbgValue(SDDbgValue *DB, SDNode *SD, bool isParameter);
    1305             : 
    1306             :   /// Get the debug values which reference the given SDNode.
    1307             :   ArrayRef<SDDbgValue*> GetDbgValues(const SDNode* SD) {
    1308        7728 :     return DbgInfo->getSDDbgValues(SD);
    1309             :   }
    1310             : 
    1311             : public:
    1312             :   /// Return true if there are any SDDbgValue nodes associated
    1313             :   /// with this SelectionDAG.
    1314      332399 :   bool hasDebugValues() const { return !DbgInfo->empty(); }
    1315             : 
    1316             :   SDDbgInfo::DbgIterator DbgBegin() { return DbgInfo->DbgBegin(); }
    1317             :   SDDbgInfo::DbgIterator DbgEnd()   { return DbgInfo->DbgEnd(); }
    1318             : 
    1319             :   SDDbgInfo::DbgIterator ByvalParmDbgBegin() {
    1320             :     return DbgInfo->ByvalParmDbgBegin();
    1321             :   }
    1322             : 
    1323             :   SDDbgInfo::DbgIterator ByvalParmDbgEnd()   {
    1324             :     return DbgInfo->ByvalParmDbgEnd();
    1325             :   }
    1326             : 
    1327             :   /// To be invoked on an SDNode that is slated to be erased. This
    1328             :   /// function mirrors \c llvm::salvageDebugInfo.
    1329             :   void salvageDebugInfo(SDNode &N);
    1330             : 
    1331             :   void dump() const;
    1332             : 
    1333             :   /// Create a stack temporary, suitable for holding the specified value type.
    1334             :   /// If minAlign is specified, the slot size will have at least that alignment.
    1335             :   SDValue CreateStackTemporary(EVT VT, unsigned minAlign = 1);
    1336             : 
    1337             :   /// Create a stack temporary suitable for holding either of the specified
    1338             :   /// value types.
    1339             :   SDValue CreateStackTemporary(EVT VT1, EVT VT2);
    1340             : 
    1341             :   SDValue FoldSymbolOffset(unsigned Opcode, EVT VT,
    1342             :                            const GlobalAddressSDNode *GA,
    1343             :                            const SDNode *N2);
    1344             : 
    1345             :   SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
    1346             :                                  SDNode *Cst1, SDNode *Cst2);
    1347             : 
    1348             :   SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
    1349             :                                  const ConstantSDNode *Cst1,
    1350             :                                  const ConstantSDNode *Cst2);
    1351             : 
    1352             :   SDValue FoldConstantVectorArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
    1353             :                                        ArrayRef<SDValue> Ops,
    1354             :                                        const SDNodeFlags Flags = SDNodeFlags());
    1355             : 
    1356             :   /// Constant fold a setcc to true or false.
    1357             :   SDValue FoldSetCC(EVT VT, SDValue N1, SDValue N2, ISD::CondCode Cond,
    1358             :                     const SDLoc &dl);
    1359             : 
    1360             :   /// See if the specified operand can be simplified with the knowledge that only
    1361             :   /// the bits specified by Mask are used.  If so, return the simpler operand,
    1362             :   /// otherwise return a null SDValue.
    1363             :   ///
    1364             :   /// (This exists alongside SimplifyDemandedBits because GetDemandedBits can
    1365             :   /// simplify nodes with multiple uses more aggressively.)
    1366             :   SDValue GetDemandedBits(SDValue V, const APInt &Mask);
    1367             : 
    1368             :   /// Return true if the sign bit of Op is known to be zero.
    1369             :   /// We use this predicate to simplify operations downstream.
    1370             :   bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const;
    1371             : 
    1372             :   /// Return true if 'Op & Mask' is known to be zero.  We
    1373             :   /// use this predicate to simplify operations downstream.  Op and Mask are
    1374             :   /// known to be the same type.
    1375             :   bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth = 0)
    1376             :     const;
    1377             : 
    1378             :   /// Determine which bits of Op are known to be either zero or one and return
    1379             :   /// them in Known. For vectors, the known bits are those that are shared by
    1380             :   /// every vector element.
    1381             :   /// Targets can implement the computeKnownBitsForTargetNode method in the
    1382             :   /// TargetLowering class to allow target nodes to be understood.
    1383             :   void computeKnownBits(SDValue Op, KnownBits &Known, unsigned Depth = 0) const;
    1384             : 
    1385             :   /// Determine which bits of Op are known to be either zero or one and return
    1386             :   /// them in Known. The DemandedElts argument allows us to only collect the
    1387             :   /// known bits that are shared by the requested vector elements.
    1388             :   /// Targets can implement the computeKnownBitsForTargetNode method in the
    1389             :   /// TargetLowering class to allow target nodes to be understood.
    1390             :   void computeKnownBits(SDValue Op, KnownBits &Known, const APInt &DemandedElts,
    1391             :                         unsigned Depth = 0) const;
    1392             : 
    1393             :   /// Used to represent the possible overflow behavior of an operation.
    1394             :   /// Never: the operation cannot overflow.
    1395             :   /// Always: the operation will always overflow.
    1396             :   /// Sometime: the operation may or may not overflow.
    1397             :   enum OverflowKind {
    1398             :     OFK_Never,
    1399             :     OFK_Sometime,
    1400             :     OFK_Always,
    1401             :   };
    1402             : 
    1403             :   /// Determine if the result of the addition of 2 node can overflow.
    1404             :   OverflowKind computeOverflowKind(SDValue N0, SDValue N1) const;
    1405             : 
    1406             :   /// Test if the given value is known to have exactly one bit set. This differs
    1407             :   /// from computeKnownBits in that it doesn't necessarily determine which bit
    1408             :   /// is set.
    1409             :   bool isKnownToBeAPowerOfTwo(SDValue Val) const;
    1410             : 
    1411             :   /// Return the number of times the sign bit of the register is replicated into
    1412             :   /// the other bits. We know that at least 1 bit is always equal to the sign
    1413             :   /// bit (itself), but other cases can give us information. For example,
    1414             :   /// immediately after an "SRA X, 2", we know that the top 3 bits are all equal
    1415             :   /// to each other, so we return 3. Targets can implement the
    1416             :   /// ComputeNumSignBitsForTarget method in the TargetLowering class to allow
    1417             :   /// target nodes to be understood.
    1418             :   unsigned ComputeNumSignBits(SDValue Op, unsigned Depth = 0) const;
    1419             : 
    1420             :   /// Return the number of times the sign bit of the register is replicated into
    1421             :   /// the other bits. We know that at least 1 bit is always equal to the sign
    1422             :   /// bit (itself), but other cases can give us information. For example,
    1423             :   /// immediately after an "SRA X, 2", we know that the top 3 bits are all equal
    1424             :   /// to each other, so we return 3. The DemandedElts argument allows
    1425             :   /// us to only collect the minimum sign bits of the requested vector elements.
    1426             :   /// Targets can implement the ComputeNumSignBitsForTarget method in the
    1427             :   /// TargetLowering class to allow target nodes to be understood.
    1428             :   unsigned ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
    1429             :                               unsigned Depth = 0) const;
    1430             : 
    1431             :   /// Return true if the specified operand is an ISD::ADD with a ConstantSDNode
    1432             :   /// on the right-hand side, or if it is an ISD::OR with a ConstantSDNode that
    1433             :   /// is guaranteed to have the same semantics as an ADD. This handles the
    1434             :   /// equivalence:
    1435             :   ///     X|Cst == X+Cst iff X&Cst = 0.
    1436             :   bool isBaseWithConstantOffset(SDValue Op) const;
    1437             : 
    1438             :   /// Test whether the given SDValue is known to never be NaN.
    1439             :   bool isKnownNeverNaN(SDValue Op) const;
    1440             : 
    1441             :   /// Test whether the given SDValue is known to never be positive or negative
    1442             :   /// zero.
    1443             :   bool isKnownNeverZero(SDValue Op) const;
    1444             : 
    1445             :   /// Test whether two SDValues are known to compare equal. This
    1446             :   /// is true if they are the same value, or if one is negative zero and the
    1447             :   /// other positive zero.
    1448             :   bool isEqualTo(SDValue A, SDValue B) const;
    1449             : 
    1450             :   /// Return true if A and B have no common bits set. As an example, this can
    1451             :   /// allow an 'add' to be transformed into an 'or'.
    1452             :   bool haveNoCommonBitsSet(SDValue A, SDValue B) const;
    1453             : 
    1454             :   /// Utility function used by legalize and lowering to
    1455             :   /// "unroll" a vector operation by splitting out the scalars and operating
    1456             :   /// on each element individually.  If the ResNE is 0, fully unroll the vector
    1457             :   /// op. If ResNE is less than the width of the vector op, unroll up to ResNE.
    1458             :   /// If the  ResNE is greater than the width of the vector op, unroll the
    1459             :   /// vector op and fill the end of the resulting vector with UNDEFS.
    1460             :   SDValue UnrollVectorOp(SDNode *N, unsigned ResNE = 0);
    1461             : 
    1462             :   /// Return true if loads are next to each other and can be
    1463             :   /// merged. Check that both are nonvolatile and if LD is loading
    1464             :   /// 'Bytes' bytes from a location that is 'Dist' units away from the
    1465             :   /// location that the 'Base' load is loading from.
    1466             :   bool areNonVolatileConsecutiveLoads(LoadSDNode *LD, LoadSDNode *Base,
    1467             :                                       unsigned Bytes, int Dist) const;
    1468             : 
    1469             :   /// Infer alignment of a load / store address. Return 0 if
    1470             :   /// it cannot be inferred.
    1471             :   unsigned InferPtrAlignment(SDValue Ptr) const;
    1472             : 
    1473             :   /// Compute the VTs needed for the low/hi parts of a type
    1474             :   /// which is split (or expanded) into two not necessarily identical pieces.
    1475             :   std::pair<EVT, EVT> GetSplitDestVTs(const EVT &VT) const;
    1476             : 
    1477             :   /// Split the vector with EXTRACT_SUBVECTOR using the provides
    1478             :   /// VTs and return the low/high part.
    1479             :   std::pair<SDValue, SDValue> SplitVector(const SDValue &N, const SDLoc &DL,
    1480             :                                           const EVT &LoVT, const EVT &HiVT);
    1481             : 
    1482             :   /// Split the vector with EXTRACT_SUBVECTOR and return the low/high part.
    1483        4758 :   std::pair<SDValue, SDValue> SplitVector(const SDValue &N, const SDLoc &DL) {
    1484        4758 :     EVT LoVT, HiVT;
    1485       14274 :     std::tie(LoVT, HiVT) = GetSplitDestVTs(N.getValueType());
    1486        4758 :     return SplitVector(N, DL, LoVT, HiVT);
    1487             :   }
    1488             : 
    1489             :   /// Split the node's operand with EXTRACT_SUBVECTOR and
    1490             :   /// return the low/high part.
    1491        4053 :   std::pair<SDValue, SDValue> SplitVectorOperand(const SDNode *N, unsigned OpNo)
    1492             :   {
    1493       12159 :     return SplitVector(N->getOperand(OpNo), SDLoc(N));
    1494             :   }
    1495             : 
    1496             :   /// Append the extracted elements from Start to Count out of the vector Op
    1497             :   /// in Args. If Count is 0, all of the elements will be extracted.
    1498             :   void ExtractVectorElements(SDValue Op, SmallVectorImpl<SDValue> &Args,
    1499             :                              unsigned Start = 0, unsigned Count = 0);
    1500             : 
    1501             :   /// Compute the default alignment value for the given type.
    1502             :   unsigned getEVTAlignment(EVT MemoryVT) const;
    1503             : 
    1504             :   /// Test whether the given value is a constant int or similar node.
    1505             :   SDNode *isConstantIntBuildVectorOrConstantInt(SDValue N);
    1506             : 
    1507             :   /// Test whether the given value is a constant FP or similar node.
    1508             :   SDNode *isConstantFPBuildVectorOrConstantFP(SDValue N);
    1509             : 
    1510             :   /// \returns true if \p N is any kind of constant or build_vector of
    1511             :   /// constants, int or float. If a vector, it may not necessarily be a splat.
    1512        8245 :   inline bool isConstantValueOfAnyType(SDValue N) {
    1513       13997 :     return isConstantIntBuildVectorOrConstantInt(N) ||
    1514       13997 :            isConstantFPBuildVectorOrConstantFP(N);
    1515             :   }
    1516             : 
    1517             : private:
    1518             :   void InsertNode(SDNode *N);
    1519             :   bool RemoveNodeFromCSEMaps(SDNode *N);
    1520             :   void AddModifiedNodeToCSEMaps(SDNode *N);
    1521             :   SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos);
    1522             :   SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
    1523             :                                void *&InsertPos);
    1524             :   SDNode *FindModifiedNodeSlot(SDNode *N, ArrayRef<SDValue> Ops,
    1525             :                                void *&InsertPos);
    1526             :   SDNode *UpdateSDLocOnMergeSDNode(SDNode *N, const SDLoc &loc);
    1527             : 
    1528             :   void DeleteNodeNotInCSEMaps(SDNode *N);
    1529             :   void DeallocateNode(SDNode *N);
    1530             : 
    1531             :   void allnodes_clear();
    1532             : 
    1533             :   /// Look up the node specified by ID in CSEMap.  If it exists, return it.  If
    1534             :   /// not, return the insertion token that will make insertion faster.  This
    1535             :   /// overload is for nodes other than Constant or ConstantFP, use the other one
    1536             :   /// for those.
    1537             :   SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos);
    1538             : 
    1539             :   /// Look up the node specified by ID in CSEMap.  If it exists, return it.  If
    1540             :   /// not, return the insertion token that will make insertion faster.  Performs
    1541             :   /// additional processing for constant nodes.
    1542             :   SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, const SDLoc &DL,
    1543             :                               void *&InsertPos);
    1544             : 
    1545             :   /// List of non-single value types.
    1546             :   FoldingSet<SDVTListNode> VTListMap;
    1547             : 
    1548             :   /// Maps to auto-CSE operations.
    1549             :   std::vector<CondCodeSDNode*> CondCodeNodes;
    1550             : 
    1551             :   std::vector<SDNode*> ValueTypeNodes;
    1552             :   std::map<EVT, SDNode*, EVT::compareRawBits> ExtendedValueTypeNodes;
    1553             :   StringMap<SDNode*> ExternalSymbols;
    1554             : 
    1555             :   std::map<std::pair<std::string, unsigned char>,SDNode*> TargetExternalSymbols;
    1556             :   DenseMap<MCSymbol *, SDNode *> MCSymbols;
    1557             : };
    1558             : 
    1559             : template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
    1560             :   using nodes_iterator = pointer_iterator<SelectionDAG::allnodes_iterator>;
    1561             : 
    1562             :   static nodes_iterator nodes_begin(SelectionDAG *G) {
    1563             :     return nodes_iterator(G->allnodes_begin());
    1564             :   }
    1565             : 
    1566             :   static nodes_iterator nodes_end(SelectionDAG *G) {
    1567             :     return nodes_iterator(G->allnodes_end());
    1568             :   }
    1569             : };
    1570             : 
    1571             : template <class TargetMemSDNode>
    1572         533 : SDValue SelectionDAG::getTargetMemSDNode(SDVTList VTs,
    1573             :                                          ArrayRef<SDValue> Ops,
    1574             :                                          const SDLoc &dl, EVT MemVT,
    1575             :                                          MachineMemOperand *MMO) {
    1576             :   /// Compose node ID and try to find an existing node.
    1577             :   FoldingSetNodeID ID;
    1578        2132 :   unsigned Opcode =
    1579             :     TargetMemSDNode(dl.getIROrder(), DebugLoc(), VTs, MemVT, MMO).getOpcode();
    1580         533 :   ID.AddInteger(Opcode);
    1581         533 :   ID.AddPointer(VTs.VTs);
    1582        6561 :   for (auto& Op : Ops) {
    1583        3014 :     ID.AddPointer(Op.getNode());
    1584        3014 :     ID.AddInteger(Op.getResNo());
    1585             :   }
    1586         533 :   ID.AddInteger(MemVT.getRawBits());
    1587         533 :   ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
    1588        1066 :   ID.AddInteger(getSyntheticNodeSubclassData<TargetMemSDNode>(
    1589             :     dl.getIROrder(), VTs, MemVT, MMO));
    1590             : 
    1591         533 :   void *IP = nullptr;
    1592         533 :   if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
    1593           0 :     cast<TargetMemSDNode>(E)->refineAlignment(MMO);
    1594           0 :     return SDValue(E, 0);
    1595             :   }
    1596             : 
    1597             :   /// Existing node was not found. Create a new one.
    1598        1066 :   auto *N = newSDNode<TargetMemSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
    1599             :                                        MemVT, MMO);
    1600         533 :   createOperands(N, Ops);
    1601         533 :   CSEMap.InsertNode(N, IP);
    1602         533 :   InsertNode(N);
    1603         533 :   return SDValue(N, 0);
    1604             : }
    1605             : 
    1606             : } // end namespace llvm
    1607             : 
    1608             : #endif // LLVM_CODEGEN_SELECTIONDAG_H

Generated by: LCOV version 1.13