SelectionDAG.h revision 002d83418a7be0083752fa910a6187e65124c78e
1//===-- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ---------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file was developed by the LLVM research group and is distributed under 6// the University of Illinois Open Source 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/CodeGen/SelectionDAGNodes.h" 19#include "llvm/ADT/ilist" 20 21#include <map> 22#include <list> 23#include <string> 24 25namespace llvm { 26 class TargetLowering; 27 class TargetMachine; 28 class MachineFunction; 29 30/// SelectionDAG class - This is used to represent a portion of an LLVM function 31/// in a low-level Data Dependence DAG representation suitable for instruction 32/// selection. This DAG is constructed as the first step of instruction 33/// selection in order to allow implementation of machine specific optimizations 34/// and code simplifications. 35/// 36/// The representation used by the SelectionDAG is a target-independent 37/// representation, which has some similarities to the GCC RTL representation, 38/// but is significantly more simple, powerful, and is a graph form instead of a 39/// linear form. 40/// 41class SelectionDAG { 42 TargetLowering &TLI; 43 MachineFunction &MF; 44 45 // Root - The root of the entire DAG. EntryNode - The starting token. 46 SDOperand Root, EntryNode; 47 48 // AllNodes - A linked list of nodes in the current DAG. 49 ilist<SDNode> AllNodes; 50 51 // ValueNodes - track SrcValue nodes 52 std::map<std::pair<const Value*, int>, SDNode*> ValueNodes; 53 54public: 55 SelectionDAG(TargetLowering &tli, MachineFunction &mf) : TLI(tli), MF(mf) { 56 EntryNode = Root = getNode(ISD::EntryToken, MVT::Other); 57 } 58 ~SelectionDAG(); 59 60 MachineFunction &getMachineFunction() const { return MF; } 61 const TargetMachine &getTarget() const; 62 TargetLowering &getTargetLoweringInfo() const { return TLI; } 63 64 /// viewGraph - Pop up a ghostview window with the DAG rendered using 'dot'. 65 /// 66 void viewGraph(); 67 68 69 typedef ilist<SDNode>::const_iterator allnodes_const_iterator; 70 allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); } 71 allnodes_const_iterator allnodes_end() const { return AllNodes.end(); } 72 typedef ilist<SDNode>::iterator allnodes_iterator; 73 allnodes_iterator allnodes_begin() { return AllNodes.begin(); } 74 allnodes_iterator allnodes_end() { return AllNodes.end(); } 75 76 /// getRoot - Return the root tag of the SelectionDAG. 77 /// 78 const SDOperand &getRoot() const { return Root; } 79 80 /// getEntryNode - Return the token chain corresponding to the entry of the 81 /// function. 82 const SDOperand &getEntryNode() const { return EntryNode; } 83 84 /// setRoot - Set the current root tag of the SelectionDAG. 85 /// 86 const SDOperand &setRoot(SDOperand N) { return Root = N; } 87 88 /// Combine - This iterates over the nodes in the SelectionDAG, folding 89 /// certain types of nodes together, or eliminating superfluous nodes. When 90 /// the AfterLegalize argument is set to 'true', Combine takes care not to 91 /// generate any nodes that will be illegal on the target. 92 void Combine(bool AfterLegalize); 93 94 /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is 95 /// compatible with the target instruction selector, as indicated by the 96 /// TargetLowering object. 97 /// 98 /// Note that this is an involved process that may invalidate pointers into 99 /// the graph. 100 void Legalize(); 101 102 /// RemoveDeadNodes - This method deletes all unreachable nodes in the 103 /// SelectionDAG, including nodes (like loads) that have uses of their token 104 /// chain but no other uses and no side effect. If a node is passed in as an 105 /// argument, it is used as the seed for node deletion. 106 void RemoveDeadNodes(SDNode *N = 0); 107 108 SDOperand getString(const std::string &Val); 109 SDOperand getConstant(uint64_t Val, MVT::ValueType VT); 110 SDOperand getTargetConstant(uint64_t Val, MVT::ValueType VT); 111 SDOperand getConstantFP(double Val, MVT::ValueType VT); 112 SDOperand getGlobalAddress(const GlobalValue *GV, MVT::ValueType VT, 113 int offset = 0); 114 SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT::ValueType VT, 115 int offset = 0); 116 SDOperand getFrameIndex(int FI, MVT::ValueType VT); 117 SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT); 118 SDOperand getConstantPool(Constant *C, MVT::ValueType VT); 119 SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT); 120 SDOperand getBasicBlock(MachineBasicBlock *MBB); 121 SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT); 122 SDOperand getTargetExternalSymbol(const char *Sym, MVT::ValueType VT); 123 SDOperand getValueType(MVT::ValueType); 124 SDOperand getRegister(unsigned Reg, MVT::ValueType VT); 125 126 SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N) { 127 return getNode(ISD::CopyToReg, MVT::Other, Chain, 128 getRegister(Reg, N.getValueType()), N); 129 } 130 131 // This version of the getCopyToReg method takes an extra operand, which 132 // indicates that there is potentially an incoming flag value (if Flag is not 133 // null) and that there should be a flag result. 134 SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N, 135 SDOperand Flag) { 136 std::vector<MVT::ValueType> VTs; 137 VTs.push_back(MVT::Other); 138 VTs.push_back(MVT::Flag); 139 std::vector<SDOperand> Ops; 140 Ops.push_back(Chain); 141 Ops.push_back(getRegister(Reg, N.getValueType())); 142 Ops.push_back(N); 143 if (Flag.Val) Ops.push_back(Flag); 144 return getNode(ISD::CopyToReg, VTs, Ops); 145 } 146 147 // Similar to last getCopyToReg() except parameter Reg is a SDOperand 148 SDOperand getCopyToReg(SDOperand Chain, SDOperand Reg, SDOperand N, 149 SDOperand Flag) { 150 std::vector<MVT::ValueType> VTs; 151 VTs.push_back(MVT::Other); 152 VTs.push_back(MVT::Flag); 153 std::vector<SDOperand> Ops; 154 Ops.push_back(Chain); 155 Ops.push_back(Reg); 156 Ops.push_back(N); 157 if (Flag.Val) Ops.push_back(Flag); 158 return getNode(ISD::CopyToReg, VTs, Ops); 159 } 160 161 SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT::ValueType VT) { 162 std::vector<MVT::ValueType> ResultTys; 163 ResultTys.push_back(VT); 164 ResultTys.push_back(MVT::Other); 165 std::vector<SDOperand> Ops; 166 Ops.push_back(Chain); 167 Ops.push_back(getRegister(Reg, VT)); 168 return getNode(ISD::CopyFromReg, ResultTys, Ops); 169 } 170 171 // This version of the getCopyFromReg method takes an extra operand, which 172 // indicates that there is potentially an incoming flag value (if Flag is not 173 // null) and that there should be a flag result. 174 SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT::ValueType VT, 175 SDOperand Flag) { 176 std::vector<MVT::ValueType> ResultTys; 177 ResultTys.push_back(VT); 178 ResultTys.push_back(MVT::Other); 179 ResultTys.push_back(MVT::Flag); 180 std::vector<SDOperand> Ops; 181 Ops.push_back(Chain); 182 Ops.push_back(getRegister(Reg, VT)); 183 if (Flag.Val) Ops.push_back(Flag); 184 return getNode(ISD::CopyFromReg, ResultTys, Ops); 185 } 186 187 /// getCall - Note that this destroys the vector of RetVals passed in. 188 /// 189 SDNode *getCall(std::vector<MVT::ValueType> &RetVals, SDOperand Chain, 190 SDOperand Callee, bool isTailCall = false) { 191 SDNode *NN = new SDNode(isTailCall ? ISD::TAILCALL : ISD::CALL, Chain, 192 Callee); 193 setNodeValueTypes(NN, RetVals); 194 AllNodes.push_back(NN); 195 return NN; 196 } 197 /// getCall - Note that this destroys the vector of RetVals passed in. 198 /// 199 SDNode *getCall(std::vector<MVT::ValueType> &RetVals, SDOperand Chain, 200 SDOperand Callee, SDOperand Flag, bool isTailCall = false) { 201 SDNode *NN = new SDNode(isTailCall ? ISD::TAILCALL : ISD::CALL, Chain, 202 Callee, Flag); 203 setNodeValueTypes(NN, RetVals); 204 AllNodes.push_back(NN); 205 return NN; 206 } 207 208 /// getCall - This is identical to the one above, and should be used for calls 209 /// where arguments are passed in physical registers. This destroys the 210 /// RetVals and ArgsInRegs vectors. 211 SDNode *getCall(std::vector<MVT::ValueType> &RetVals, SDOperand Chain, 212 SDOperand Callee, std::vector<SDOperand> &ArgsInRegs, 213 bool isTailCall = false) { 214 ArgsInRegs.insert(ArgsInRegs.begin(), Callee); 215 ArgsInRegs.insert(ArgsInRegs.begin(), Chain); 216 SDNode *NN = new SDNode(isTailCall ? ISD::TAILCALL : ISD::CALL, ArgsInRegs); 217 setNodeValueTypes(NN, RetVals); 218 AllNodes.push_back(NN); 219 return NN; 220 } 221 222 SDOperand getCondCode(ISD::CondCode Cond); 223 224 /// getZeroExtendInReg - Return the expression required to zero extend the Op 225 /// value assuming it was the smaller SrcTy value. 226 SDOperand getZeroExtendInReg(SDOperand Op, MVT::ValueType SrcTy); 227 228 /// getNode - Gets or creates the specified node. 229 /// 230 SDOperand getNode(unsigned Opcode, MVT::ValueType VT); 231 SDOperand getNode(unsigned Opcode, MVT::ValueType VT, SDOperand N); 232 SDOperand getNode(unsigned Opcode, MVT::ValueType VT, 233 SDOperand N1, SDOperand N2); 234 SDOperand getNode(unsigned Opcode, MVT::ValueType VT, 235 SDOperand N1, SDOperand N2, SDOperand N3); 236 SDOperand getNode(unsigned Opcode, MVT::ValueType VT, 237 SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4); 238 SDOperand getNode(unsigned Opcode, MVT::ValueType VT, 239 SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4, 240 SDOperand N5); 241 SDOperand getNode(unsigned Opcode, MVT::ValueType VT, 242 SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4, 243 SDOperand N5, SDOperand N6); 244 SDOperand getNode(unsigned Opcode, MVT::ValueType VT, 245 std::vector<SDOperand> &Children); 246 SDOperand getNode(unsigned Opcode, std::vector<MVT::ValueType> &ResultTys, 247 std::vector<SDOperand> &Ops); 248 249 /// getSetCC - Helper function to make it easier to build SetCC's if you just 250 /// have an ISD::CondCode instead of an SDOperand. 251 /// 252 SDOperand getSetCC(MVT::ValueType VT, SDOperand LHS, SDOperand RHS, 253 ISD::CondCode Cond) { 254 return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond)); 255 } 256 257 /// getSelectCC - Helper function to make it easier to build SelectCC's if you 258 /// just have an ISD::CondCode instead of an SDOperand. 259 /// 260 SDOperand getSelectCC(SDOperand LHS, SDOperand RHS, 261 SDOperand True, SDOperand False, ISD::CondCode Cond) { 262 MVT::ValueType VT = True.getValueType(); 263 return getNode(ISD::SELECT_CC, VT, LHS, RHS, True, False,getCondCode(Cond)); 264 } 265 266 /// getBR2Way_CC - Helper function to make it easier to build BRTWOWAY_CC 267 /// nodes. 268 /// 269 SDOperand getBR2Way_CC(SDOperand Chain, SDOperand CCNode, SDOperand LHS, 270 SDOperand RHS, SDOperand True, SDOperand False) { 271 std::vector<SDOperand> Ops; 272 Ops.push_back(Chain); 273 Ops.push_back(CCNode); 274 Ops.push_back(LHS); 275 Ops.push_back(RHS); 276 Ops.push_back(True); 277 Ops.push_back(False); 278 return getNode(ISD::BRTWOWAY_CC, MVT::Other, Ops); 279 } 280 281 /// getLoad - Loads are not normal binary operators: their result type is not 282 /// determined by their operands, and they produce a value AND a token chain. 283 /// 284 SDOperand getLoad(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr, 285 SDOperand SV); 286 SDOperand getVecLoad(unsigned Count, MVT::ValueType VT, SDOperand Chain, 287 SDOperand Ptr, SDOperand SV); 288 SDOperand getExtLoad(unsigned Opcode, MVT::ValueType VT, SDOperand Chain, 289 SDOperand Ptr, SDOperand SV, MVT::ValueType EVT); 290 291 // getSrcValue - construct a node to track a Value* through the backend 292 SDOperand getSrcValue(const Value* I, int offset = 0); 293 294 295 /// SelectNodeTo - These are used for target selectors to *mutate* the 296 /// specified node to have the specified return type, Target opcode, and 297 /// operands. Note that target opcodes are stored as 298 /// ISD::BUILTIN_OP_END+TargetOpcode in the node opcode field. The 0th value 299 /// of the resultant node is returned. 300 SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT); 301 SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 302 SDOperand Op1); 303 SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 304 SDOperand Op1, SDOperand Op2); 305 SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 306 SDOperand Op1, SDOperand Op2, SDOperand Op3); 307 SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 308 SDOperand Op1, SDOperand Op2, SDOperand Op3, 309 SDOperand Op4); 310 SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 311 SDOperand Op1, SDOperand Op2, SDOperand Op3, 312 SDOperand Op4, SDOperand Op5); 313 SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 314 SDOperand Op1, SDOperand Op2, SDOperand Op3, 315 SDOperand Op4, SDOperand Op5, SDOperand Op6); 316 SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1, 317 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2); 318 SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1, 319 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, 320 SDOperand Op3); 321 SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1, 322 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, 323 SDOperand Op3, SDOperand Op4); 324 SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1, 325 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, 326 SDOperand Op3, SDOperand Op4, SDOperand Op5); 327 328 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT) { 329 return getNode(ISD::BUILTIN_OP_END+Opcode, VT); 330 } 331 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT, 332 SDOperand Op1) { 333 return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Op1); 334 } 335 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT, 336 SDOperand Op1, SDOperand Op2) { 337 return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Op1, Op2); 338 } 339 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT, 340 SDOperand Op1, SDOperand Op2, SDOperand Op3) { 341 return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Op1, Op2, Op3); 342 } 343 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT, 344 SDOperand Op1, SDOperand Op2, SDOperand Op3, 345 SDOperand Op4) { 346 return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Op1, Op2, Op3, Op4); 347 } 348 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT, 349 SDOperand Op1, SDOperand Op2, SDOperand Op3, 350 SDOperand Op4, SDOperand Op5) { 351 return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Op1, Op2, Op3, Op4, Op5); 352 } 353 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT, 354 SDOperand Op1, SDOperand Op2, SDOperand Op3, 355 SDOperand Op4, SDOperand Op5, SDOperand Op6) { 356 return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Op1, Op2, Op3, Op4, Op5, Op6); 357 } 358 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT, 359 std::vector<SDOperand> &Ops) { 360 return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Ops); 361 } 362 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT1, 363 MVT::ValueType VT2, SDOperand Op1) { 364 std::vector<MVT::ValueType> ResultTys; 365 ResultTys.push_back(VT1); 366 ResultTys.push_back(VT2); 367 std::vector<SDOperand> Ops; 368 Ops.push_back(Op1); 369 return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops); 370 } 371 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT1, 372 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2) { 373 std::vector<MVT::ValueType> ResultTys; 374 ResultTys.push_back(VT1); 375 ResultTys.push_back(VT2); 376 std::vector<SDOperand> Ops; 377 Ops.push_back(Op1); 378 Ops.push_back(Op2); 379 return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops); 380 } 381 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT1, 382 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, 383 SDOperand Op3) { 384 std::vector<MVT::ValueType> ResultTys; 385 ResultTys.push_back(VT1); 386 ResultTys.push_back(VT2); 387 std::vector<SDOperand> Ops; 388 Ops.push_back(Op1); 389 Ops.push_back(Op2); 390 Ops.push_back(Op3); 391 return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops); 392 } 393 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT1, 394 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, 395 SDOperand Op3, SDOperand Op4) { 396 std::vector<MVT::ValueType> ResultTys; 397 ResultTys.push_back(VT1); 398 ResultTys.push_back(VT2); 399 std::vector<SDOperand> Ops; 400 Ops.push_back(Op1); 401 Ops.push_back(Op2); 402 Ops.push_back(Op3); 403 Ops.push_back(Op4); 404 return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops); 405 } 406 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT1, 407 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, 408 SDOperand Op3, SDOperand Op4, SDOperand Op5) { 409 std::vector<MVT::ValueType> ResultTys; 410 ResultTys.push_back(VT1); 411 ResultTys.push_back(VT2); 412 std::vector<SDOperand> Ops; 413 Ops.push_back(Op1); 414 Ops.push_back(Op2); 415 Ops.push_back(Op3); 416 Ops.push_back(Op4); 417 Ops.push_back(Op5); 418 return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops); 419 } 420 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT1, 421 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, 422 SDOperand Op3, SDOperand Op4, SDOperand Op5, 423 SDOperand Op6) { 424 std::vector<MVT::ValueType> ResultTys; 425 ResultTys.push_back(VT1); 426 ResultTys.push_back(VT2); 427 std::vector<SDOperand> Ops; 428 Ops.push_back(Op1); 429 Ops.push_back(Op2); 430 Ops.push_back(Op3); 431 Ops.push_back(Op4); 432 Ops.push_back(Op5); 433 Ops.push_back(Op6); 434 return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops); 435 } 436 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT1, 437 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, 438 SDOperand Op3, SDOperand Op4, SDOperand Op5, 439 SDOperand Op6, SDOperand Op7) { 440 std::vector<MVT::ValueType> ResultTys; 441 ResultTys.push_back(VT1); 442 ResultTys.push_back(VT2); 443 std::vector<SDOperand> Ops; 444 Ops.push_back(Op1); 445 Ops.push_back(Op2); 446 Ops.push_back(Op3); 447 Ops.push_back(Op4); 448 Ops.push_back(Op5); 449 Ops.push_back(Op6); 450 Ops.push_back(Op7); 451 return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops); 452 } 453 SDOperand getTargetNode(unsigned Opcode, MVT::ValueType VT1, 454 MVT::ValueType VT2, std::vector<SDOperand> &Ops) { 455 std::vector<MVT::ValueType> ResultTys; 456 ResultTys.push_back(VT1); 457 ResultTys.push_back(VT2); 458 return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops); 459 } 460 461 /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead. 462 /// This can cause recursive merging of nodes in the DAG. Use the first 463 /// version if 'From' is known to have a single result, use the second 464 /// if you have two nodes with identical results, use the third otherwise. 465 /// 466 /// These methods all take an optional vector, which (if not null) is 467 /// populated with any nodes that are deleted from the SelectionDAG, due to 468 /// new equivalences that are discovered. 469 /// 470 void ReplaceAllUsesWith(SDOperand From, SDOperand Op, 471 std::vector<SDNode*> *Deleted = 0); 472 void ReplaceAllUsesWith(SDNode *From, SDNode *To, 473 std::vector<SDNode*> *Deleted = 0); 474 void ReplaceAllUsesWith(SDNode *From, const std::vector<SDOperand> &To, 475 std::vector<SDNode*> *Deleted = 0); 476 477 478 /// DeleteNode - Remove the specified node from the system. This node must 479 /// have no referrers. 480 void DeleteNode(SDNode *N); 481 482 void dump() const; 483 484private: 485 void RemoveNodeFromCSEMaps(SDNode *N); 486 SDNode *AddNonLeafNodeToCSEMaps(SDNode *N); 487 void DestroyDeadNode(SDNode *N); 488 void DeleteNodeNotInCSEMaps(SDNode *N); 489 void setNodeValueTypes(SDNode *N, std::vector<MVT::ValueType> &RetVals); 490 void setNodeValueTypes(SDNode *N, MVT::ValueType VT1, MVT::ValueType VT2); 491 492 493 /// SimplifySetCC - Try to simplify a setcc built with the specified operands 494 /// and cc. If unable to simplify it, return a null SDOperand. 495 SDOperand SimplifySetCC(MVT::ValueType VT, SDOperand N1, 496 SDOperand N2, ISD::CondCode Cond); 497 498 // List of non-single value types. 499 std::list<std::vector<MVT::ValueType> > VTList; 500 501 // Maps to auto-CSE operations. 502 std::map<std::pair<unsigned, MVT::ValueType>, SDNode *> NullaryOps; 503 std::map<std::pair<unsigned, std::pair<SDOperand, MVT::ValueType> >, 504 SDNode *> UnaryOps; 505 std::map<std::pair<unsigned, std::pair<SDOperand, SDOperand> >, 506 SDNode *> BinaryOps; 507 508 std::map<std::pair<unsigned, MVT::ValueType>, RegisterSDNode*> RegNodes; 509 std::vector<CondCodeSDNode*> CondCodeNodes; 510 511 std::map<std::pair<SDOperand, std::pair<SDOperand, MVT::ValueType> >, 512 SDNode *> Loads; 513 514 std::map<std::pair<const GlobalValue*, int>, SDNode*> GlobalValues; 515 std::map<std::pair<const GlobalValue*, int>, SDNode*> TargetGlobalValues; 516 std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> Constants; 517 std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> TargetConstants; 518 std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> ConstantFPs; 519 std::map<int, SDNode*> FrameIndices, TargetFrameIndices; 520 std::map<Constant *, SDNode*> ConstantPoolIndices; 521 std::map<Constant *, SDNode*> TargetConstantPoolIndices; 522 std::map<MachineBasicBlock *, SDNode*> BBNodes; 523 std::vector<SDNode*> ValueTypeNodes; 524 std::map<std::string, SDNode*> ExternalSymbols; 525 std::map<std::string, SDNode*> TargetExternalSymbols; 526 std::map<std::string, StringSDNode*> StringNodes; 527 std::map<std::pair<unsigned, 528 std::pair<MVT::ValueType, std::vector<SDOperand> > >, 529 SDNode*> OneResultNodes; 530 std::map<std::pair<unsigned, 531 std::pair<std::vector<MVT::ValueType>, 532 std::vector<SDOperand> > >, 533 SDNode*> ArbitraryNodes; 534}; 535 536template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> { 537 typedef SelectionDAG::allnodes_iterator nodes_iterator; 538 static nodes_iterator nodes_begin(SelectionDAG *G) { 539 return G->allnodes_begin(); 540 } 541 static nodes_iterator nodes_end(SelectionDAG *G) { 542 return G->allnodes_end(); 543 } 544}; 545 546} // end namespace llvm 547 548#endif 549