Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1109 lines
49 KiB

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