blob: 76d7bb99463807f0222de8360e2d35ac21d6062d [file] [log] [blame]
Chris Lattner78ec3112003-08-11 14:57:33 +00001//===-- SelectionDAG.cpp - Implement the SelectionDAG* classes ------------===//
John Criswellb576c942003-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 Lattner78ec3112003-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"
Chris Lattnere25738c2004-06-02 04:28:06 +000017using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000018
Chris Lattner78ec3112003-08-11 14:57:33 +000019SelectionDAG::~SelectionDAG() {
20 for (unsigned i = 0, e = AllNodes.size(); i != e; ++i)
21 delete AllNodes[i];
22}
23
24
25/// dump - Print out the current Selection DAG...
26void SelectionDAG::dump() const {
27 Root->dump(); // Print from the root...
28}
29
30/// getValueType - Return the ValueType for the specified LLVM type. This
31/// method works on all scalar LLVM types.
32///
33MVT::ValueType SelectionDAG::getValueType(const Type *Ty) const {
34 switch (Ty->getPrimitiveID()) {
35 case Type::VoidTyID: assert(0 && "Void type object in getValueType!");
36 default: assert(0 && "Unknown type in DAGBuilder!\n");
37 case Type::BoolTyID: return MVT::i1;
38 case Type::SByteTyID:
39 case Type::UByteTyID: return MVT::i8;
40 case Type::ShortTyID:
41 case Type::UShortTyID: return MVT::i16;
42 case Type::IntTyID:
43 case Type::UIntTyID: return MVT::i32;
44 case Type::LongTyID:
45 case Type::ULongTyID: return MVT::i64;
46 case Type::FloatTyID: return MVT::f32;
47 case Type::DoubleTyID: return MVT::f64;
Chris Lattner7dc97ff2003-08-15 04:53:16 +000048 case Type::LabelTyID:
Chris Lattner78ec3112003-08-11 14:57:33 +000049 case Type::PointerTyID: return PointerType;
50 }
51}
52
53void SelectionDAGNode::dump() const {
54 // Print out the DAG in post-order
55 std::map<const SelectionDAGNode*, unsigned> NodeIDs;
56 unsigned ID = 0;
57 printit(0, ID, NodeIDs);
58}
59
60void SelectionDAGNode::printit(unsigned Offset, unsigned &LastID,
61 std::map<const SelectionDAGNode*,
62 unsigned> &NodeIDs) const {
63 if (!NodeIDs.count(this)) {
64 // Emit all of the uses first...
65 for (unsigned i = 0, e = Uses.size(); i != e; ++i)
66 Uses[i]->printit(Offset+1, LastID, NodeIDs);
67
68 NodeIDs[this] = LastID++;
69
70 std::cerr << std::string(Offset, ' ') << "#" << LastID-1 << " ";
71 } else {
72 // Node has already been emitted...
73 std::cerr << std::string(Offset, ' ') << "#" << NodeIDs[this] << " ";
74 }
75
76 switch (ValueType) {
77 case MVT::isVoid: std::cerr << "V:"; break;
78 case MVT::i1: std::cerr << "i1:"; break;
79 case MVT::i8: std::cerr << "i8:"; break;
80 case MVT::i16: std::cerr << "i16:"; break;
81 case MVT::i32: std::cerr << "i32:"; break;
82 case MVT::i64: std::cerr << "i64:"; break;
83 case MVT::f32: std::cerr << "f32:"; break;
84 case MVT::f64: std::cerr << "f64:"; break;
85 default: assert(0 && "Invalid node ValueType!");
86 }
87 switch (NodeType) {
88 case ISD::ChainNode: std::cerr << "ChainNode"; break;
89 case ISD::BlockChainNode: std::cerr << "BlockChainNode"; break;
90 case ISD::ProtoNode: std::cerr << "ProtoNode"; break;
Chris Lattner7dc97ff2003-08-15 04:53:16 +000091
Chris Lattner78ec3112003-08-11 14:57:33 +000092 case ISD::Constant: std::cerr << "Constant"; break;
93 case ISD::FrameIndex: std::cerr << "FrameIndex"; break;
Chris Lattner7dc97ff2003-08-15 04:53:16 +000094 case ISD::BasicBlock: std::cerr << "BasicBlock"; break;
95
Chris Lattner78ec3112003-08-11 14:57:33 +000096 case ISD::Plus: std::cerr << "Plus"; break;
97 case ISD::Minus: std::cerr << "Minus"; break;
98 case ISD::Times: std::cerr << "Times"; break;
99 case ISD::SDiv: std::cerr << "SDiv"; break;
100 case ISD::UDiv: std::cerr << "UDiv"; break;
101 case ISD::SRem: std::cerr << "SRem"; break;
102 case ISD::URem: std::cerr << "URem"; break;
103 case ISD::And: std::cerr << "And"; break;
104 case ISD::Or: std::cerr << "Or"; break;
105 case ISD::Xor: std::cerr << "Xor"; break;
Chris Lattner7dc97ff2003-08-15 04:53:16 +0000106
107 case ISD::SetEQ: std::cerr << "SetEQ"; break;
108 case ISD::SetNE: std::cerr << "SetNE"; break;
109 case ISD::SetLT: std::cerr << "SetLT"; break;
110 case ISD::SetLE: std::cerr << "SetLE"; break;
111 case ISD::SetGT: std::cerr << "SetGT"; break;
112 case ISD::SetGE: std::cerr << "SetGE"; break;
113
Chris Lattner78ec3112003-08-11 14:57:33 +0000114 case ISD::Br: std::cerr << "Br"; break;
Chris Lattner7dc97ff2003-08-15 04:53:16 +0000115 case ISD::BrCond: std::cerr << "BrCond"; break;
Chris Lattner78ec3112003-08-11 14:57:33 +0000116 case ISD::Switch: std::cerr << "Switch"; break;
117 case ISD::Ret: std::cerr << "Ret"; break;
118 case ISD::RetVoid: std::cerr << "RetVoid"; break;
119 case ISD::Load: std::cerr << "Load"; break;
120 case ISD::Store: std::cerr << "Store"; break;
121 case ISD::PHI: std::cerr << "PHI"; break;
122 case ISD::Call: std::cerr << "Call"; break;
Chris Lattner7dc97ff2003-08-15 04:53:16 +0000123
124 case ISD::Unspec1: std::cerr << "Unspec1"; break;
125 case ISD::Unspec2: std::cerr << "Unspec2"; break;
Chris Lattner78ec3112003-08-11 14:57:33 +0000126 }
127
128 std::cerr << "\n";
129}