SelectionDAG.cpp revision 78ec311bd5fcdf44ed64841a0f5df1124b3a9b17
1//===-- SelectionDAG.cpp - Implement the SelectionDAG* classes ------------===// 2// 3// This file implements the SelectionDAG* classes, which are used to perform 4// DAG-based instruction selection in a target-specific manner. 5// 6//===----------------------------------------------------------------------===// 7 8#include "llvm/CodeGen/SelectionDAG.h" 9#include "llvm/Type.h" 10 11SelectionDAG::~SelectionDAG() { 12 for (unsigned i = 0, e = AllNodes.size(); i != e; ++i) 13 delete AllNodes[i]; 14} 15 16 17/// dump - Print out the current Selection DAG... 18void SelectionDAG::dump() const { 19 Root->dump(); // Print from the root... 20} 21 22/// getValueType - Return the ValueType for the specified LLVM type. This 23/// method works on all scalar LLVM types. 24/// 25MVT::ValueType SelectionDAG::getValueType(const Type *Ty) const { 26 switch (Ty->getPrimitiveID()) { 27 case Type::VoidTyID: assert(0 && "Void type object in getValueType!"); 28 default: assert(0 && "Unknown type in DAGBuilder!\n"); 29 case Type::BoolTyID: return MVT::i1; 30 case Type::SByteTyID: 31 case Type::UByteTyID: return MVT::i8; 32 case Type::ShortTyID: 33 case Type::UShortTyID: return MVT::i16; 34 case Type::IntTyID: 35 case Type::UIntTyID: return MVT::i32; 36 case Type::LongTyID: 37 case Type::ULongTyID: return MVT::i64; 38 case Type::FloatTyID: return MVT::f32; 39 case Type::DoubleTyID: return MVT::f64; 40 case Type::PointerTyID: return PointerType; 41 } 42} 43 44void SelectionDAGNode::dump() const { 45 // Print out the DAG in post-order 46 std::map<const SelectionDAGNode*, unsigned> NodeIDs; 47 unsigned ID = 0; 48 printit(0, ID, NodeIDs); 49} 50 51void SelectionDAGNode::printit(unsigned Offset, unsigned &LastID, 52 std::map<const SelectionDAGNode*, 53 unsigned> &NodeIDs) const { 54 if (!NodeIDs.count(this)) { 55 // Emit all of the uses first... 56 for (unsigned i = 0, e = Uses.size(); i != e; ++i) 57 Uses[i]->printit(Offset+1, LastID, NodeIDs); 58 59 NodeIDs[this] = LastID++; 60 61 std::cerr << std::string(Offset, ' ') << "#" << LastID-1 << " "; 62 } else { 63 // Node has already been emitted... 64 std::cerr << std::string(Offset, ' ') << "#" << NodeIDs[this] << " "; 65 } 66 67 switch (ValueType) { 68 case MVT::isVoid: std::cerr << "V:"; break; 69 case MVT::i1: std::cerr << "i1:"; break; 70 case MVT::i8: std::cerr << "i8:"; break; 71 case MVT::i16: std::cerr << "i16:"; break; 72 case MVT::i32: std::cerr << "i32:"; break; 73 case MVT::i64: std::cerr << "i64:"; break; 74 case MVT::f32: std::cerr << "f32:"; break; 75 case MVT::f64: std::cerr << "f64:"; break; 76 default: assert(0 && "Invalid node ValueType!"); 77 } 78 switch (NodeType) { 79 case ISD::ChainNode: std::cerr << "ChainNode"; break; 80 case ISD::BlockChainNode: std::cerr << "BlockChainNode"; break; 81 case ISD::ProtoNode: std::cerr << "ProtoNode"; break; 82 case ISD::Constant: std::cerr << "Constant"; break; 83 case ISD::FrameIndex: std::cerr << "FrameIndex"; break; 84 case ISD::Plus: std::cerr << "Plus"; break; 85 case ISD::Minus: std::cerr << "Minus"; break; 86 case ISD::Times: std::cerr << "Times"; break; 87 case ISD::SDiv: std::cerr << "SDiv"; break; 88 case ISD::UDiv: std::cerr << "UDiv"; break; 89 case ISD::SRem: std::cerr << "SRem"; break; 90 case ISD::URem: std::cerr << "URem"; break; 91 case ISD::And: std::cerr << "And"; break; 92 case ISD::Or: std::cerr << "Or"; break; 93 case ISD::Xor: std::cerr << "Xor"; break; 94 case ISD::Br: std::cerr << "Br"; break; 95 case ISD::Switch: std::cerr << "Switch"; break; 96 case ISD::Ret: std::cerr << "Ret"; break; 97 case ISD::RetVoid: std::cerr << "RetVoid"; break; 98 case ISD::Load: std::cerr << "Load"; break; 99 case ISD::Store: std::cerr << "Store"; break; 100 case ISD::PHI: std::cerr << "PHI"; break; 101 case ISD::Call: std::cerr << "Call"; break; 102 } 103 104 std::cerr << "\n"; 105} 106