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