blob: 58a9639c92b249cd8bb66cc6124fbcdc7a91ebdf [file] [log] [blame]
Chris Lattner600d3082003-08-11 14:57:33 +00001//===-- SelectionDAG.cpp - Implement the SelectionDAG* classes ------------===//
John Criswell482202a2003-10-20 19:43:21 +00002//
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//===----------------------------------------------------------------------===//
Chris Lattner600d3082003-08-11 14:57:33 +00009//
10// This file implements the SelectionDAG* classes, which are used to perform
11// DAG-based instruction selection in a target-specific manner.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/CodeGen/SelectionDAG.h"
16#include "llvm/Type.h"
17
18SelectionDAG::~SelectionDAG() {
19 for (unsigned i = 0, e = AllNodes.size(); i != e; ++i)
20 delete AllNodes[i];
21}
22
23
24/// dump - Print out the current Selection DAG...
25void SelectionDAG::dump() const {
26 Root->dump(); // Print from the root...
27}
28
29/// getValueType - Return the ValueType for the specified LLVM type. This
30/// method works on all scalar LLVM types.
31///
32MVT::ValueType SelectionDAG::getValueType(const Type *Ty) const {
33 switch (Ty->getPrimitiveID()) {
34 case Type::VoidTyID: assert(0 && "Void type object in getValueType!");
35 default: assert(0 && "Unknown type in DAGBuilder!\n");
36 case Type::BoolTyID: return MVT::i1;
37 case Type::SByteTyID:
38 case Type::UByteTyID: return MVT::i8;
39 case Type::ShortTyID:
40 case Type::UShortTyID: return MVT::i16;
41 case Type::IntTyID:
42 case Type::UIntTyID: return MVT::i32;
43 case Type::LongTyID:
44 case Type::ULongTyID: return MVT::i64;
45 case Type::FloatTyID: return MVT::f32;
46 case Type::DoubleTyID: return MVT::f64;
Chris Lattnere81de412003-08-15 04:53:16 +000047 case Type::LabelTyID:
Chris Lattner600d3082003-08-11 14:57:33 +000048 case Type::PointerTyID: return PointerType;
49 }
50}
51
52void SelectionDAGNode::dump() const {
53 // Print out the DAG in post-order
54 std::map<const SelectionDAGNode*, unsigned> NodeIDs;
55 unsigned ID = 0;
56 printit(0, ID, NodeIDs);
57}
58
59void SelectionDAGNode::printit(unsigned Offset, unsigned &LastID,
60 std::map<const SelectionDAGNode*,
61 unsigned> &NodeIDs) const {
62 if (!NodeIDs.count(this)) {
63 // Emit all of the uses first...
64 for (unsigned i = 0, e = Uses.size(); i != e; ++i)
65 Uses[i]->printit(Offset+1, LastID, NodeIDs);
66
67 NodeIDs[this] = LastID++;
68
69 std::cerr << std::string(Offset, ' ') << "#" << LastID-1 << " ";
70 } else {
71 // Node has already been emitted...
72 std::cerr << std::string(Offset, ' ') << "#" << NodeIDs[this] << " ";
73 }
74
75 switch (ValueType) {
76 case MVT::isVoid: std::cerr << "V:"; break;
77 case MVT::i1: std::cerr << "i1:"; break;
78 case MVT::i8: std::cerr << "i8:"; break;
79 case MVT::i16: std::cerr << "i16:"; break;
80 case MVT::i32: std::cerr << "i32:"; break;
81 case MVT::i64: std::cerr << "i64:"; break;
82 case MVT::f32: std::cerr << "f32:"; break;
83 case MVT::f64: std::cerr << "f64:"; break;
84 default: assert(0 && "Invalid node ValueType!");
85 }
86 switch (NodeType) {
87 case ISD::ChainNode: std::cerr << "ChainNode"; break;
88 case ISD::BlockChainNode: std::cerr << "BlockChainNode"; break;
89 case ISD::ProtoNode: std::cerr << "ProtoNode"; break;
Chris Lattnere81de412003-08-15 04:53:16 +000090
Chris Lattner600d3082003-08-11 14:57:33 +000091 case ISD::Constant: std::cerr << "Constant"; break;
92 case ISD::FrameIndex: std::cerr << "FrameIndex"; break;
Chris Lattnere81de412003-08-15 04:53:16 +000093 case ISD::BasicBlock: std::cerr << "BasicBlock"; break;
94
Chris Lattner600d3082003-08-11 14:57:33 +000095 case ISD::Plus: std::cerr << "Plus"; break;
96 case ISD::Minus: std::cerr << "Minus"; break;
97 case ISD::Times: std::cerr << "Times"; break;
98 case ISD::SDiv: std::cerr << "SDiv"; break;
99 case ISD::UDiv: std::cerr << "UDiv"; break;
100 case ISD::SRem: std::cerr << "SRem"; break;
101 case ISD::URem: std::cerr << "URem"; break;
102 case ISD::And: std::cerr << "And"; break;
103 case ISD::Or: std::cerr << "Or"; break;
104 case ISD::Xor: std::cerr << "Xor"; break;
Chris Lattnere81de412003-08-15 04:53:16 +0000105
106 case ISD::SetEQ: std::cerr << "SetEQ"; break;
107 case ISD::SetNE: std::cerr << "SetNE"; break;
108 case ISD::SetLT: std::cerr << "SetLT"; break;
109 case ISD::SetLE: std::cerr << "SetLE"; break;
110 case ISD::SetGT: std::cerr << "SetGT"; break;
111 case ISD::SetGE: std::cerr << "SetGE"; break;
112
Chris Lattner600d3082003-08-11 14:57:33 +0000113 case ISD::Br: std::cerr << "Br"; break;
Chris Lattnere81de412003-08-15 04:53:16 +0000114 case ISD::BrCond: std::cerr << "BrCond"; break;
Chris Lattner600d3082003-08-11 14:57:33 +0000115 case ISD::Switch: std::cerr << "Switch"; break;
116 case ISD::Ret: std::cerr << "Ret"; break;
117 case ISD::RetVoid: std::cerr << "RetVoid"; break;
118 case ISD::Load: std::cerr << "Load"; break;
119 case ISD::Store: std::cerr << "Store"; break;
120 case ISD::PHI: std::cerr << "PHI"; break;
121 case ISD::Call: std::cerr << "Call"; break;
Chris Lattnere81de412003-08-15 04:53:16 +0000122
123 case ISD::Unspec1: std::cerr << "Unspec1"; break;
124 case ISD::Unspec2: std::cerr << "Unspec2"; break;
Chris Lattner600d3082003-08-11 14:57:33 +0000125 }
126
127 std::cerr << "\n";
128}