aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-08-11 14:57:33 +0000
committerChris Lattner <sabre@nondot.org>2003-08-11 14:57:33 +0000
commit78ec311bd5fcdf44ed64841a0f5df1124b3a9b17 (patch)
treeff4cae16293e5c6ae77e355d6aff87847942850e /lib/CodeGen/SelectionDAG/SelectionDAG.cpp
parentcacf462915344c2af25eef1af1f3ee2c7280ff56 (diff)
Initial checkin of SelectionDAG implementation. This is still rough and
unfinished git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7717 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAG.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAG.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
new file mode 100644
index 0000000000..181abea922
--- /dev/null
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -0,0 +1,105 @@
+//===-- SelectionDAG.cpp - Implement the SelectionDAG* classes ------------===//
+//
+// This file implements the SelectionDAG* classes, which are used to perform
+// DAG-based instruction selection in a target-specific manner.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/SelectionDAG.h"
+#include "llvm/Type.h"
+
+SelectionDAG::~SelectionDAG() {
+ for (unsigned i = 0, e = AllNodes.size(); i != e; ++i)
+ delete AllNodes[i];
+}
+
+
+/// dump - Print out the current Selection DAG...
+void SelectionDAG::dump() const {
+ Root->dump(); // Print from the root...
+}
+
+/// getValueType - Return the ValueType for the specified LLVM type. This
+/// method works on all scalar LLVM types.
+///
+MVT::ValueType SelectionDAG::getValueType(const Type *Ty) const {
+ switch (Ty->getPrimitiveID()) {
+ case Type::VoidTyID: assert(0 && "Void type object in getValueType!");
+ default: assert(0 && "Unknown type in DAGBuilder!\n");
+ case Type::BoolTyID: return MVT::i1;
+ case Type::SByteTyID:
+ case Type::UByteTyID: return MVT::i8;
+ case Type::ShortTyID:
+ case Type::UShortTyID: return MVT::i16;
+ case Type::IntTyID:
+ case Type::UIntTyID: return MVT::i32;
+ case Type::LongTyID:
+ case Type::ULongTyID: return MVT::i64;
+ case Type::FloatTyID: return MVT::f32;
+ case Type::DoubleTyID: return MVT::f64;
+ case Type::PointerTyID: return PointerType;
+ }
+}
+
+void SelectionDAGNode::dump() const {
+ // Print out the DAG in post-order
+ std::map<const SelectionDAGNode*, unsigned> NodeIDs;
+ unsigned ID = 0;
+ printit(0, ID, NodeIDs);
+}
+
+void SelectionDAGNode::printit(unsigned Offset, unsigned &LastID,
+ std::map<const SelectionDAGNode*,
+ unsigned> &NodeIDs) const {
+ if (!NodeIDs.count(this)) {
+ // Emit all of the uses first...
+ for (unsigned i = 0, e = Uses.size(); i != e; ++i)
+ Uses[i]->printit(Offset+1, LastID, NodeIDs);
+
+ NodeIDs[this] = LastID++;
+
+ std::cerr << std::string(Offset, ' ') << "#" << LastID-1 << " ";
+ } else {
+ // Node has already been emitted...
+ std::cerr << std::string(Offset, ' ') << "#" << NodeIDs[this] << " ";
+ }
+
+ switch (ValueType) {
+ case MVT::isVoid: std::cerr << "V:"; break;
+ case MVT::i1: std::cerr << "i1:"; break;
+ case MVT::i8: std::cerr << "i8:"; break;
+ case MVT::i16: std::cerr << "i16:"; break;
+ case MVT::i32: std::cerr << "i32:"; break;
+ case MVT::i64: std::cerr << "i64:"; break;
+ case MVT::f32: std::cerr << "f32:"; break;
+ case MVT::f64: std::cerr << "f64:"; break;
+ default: assert(0 && "Invalid node ValueType!");
+ }
+ switch (NodeType) {
+ case ISD::ChainNode: std::cerr << "ChainNode"; break;
+ case ISD::BlockChainNode: std::cerr << "BlockChainNode"; break;
+ case ISD::ProtoNode: std::cerr << "ProtoNode"; break;
+ case ISD::Constant: std::cerr << "Constant"; break;
+ case ISD::FrameIndex: std::cerr << "FrameIndex"; break;
+ case ISD::Plus: std::cerr << "Plus"; break;
+ case ISD::Minus: std::cerr << "Minus"; break;
+ case ISD::Times: std::cerr << "Times"; break;
+ case ISD::SDiv: std::cerr << "SDiv"; break;
+ case ISD::UDiv: std::cerr << "UDiv"; break;
+ case ISD::SRem: std::cerr << "SRem"; break;
+ case ISD::URem: std::cerr << "URem"; break;
+ case ISD::And: std::cerr << "And"; break;
+ case ISD::Or: std::cerr << "Or"; break;
+ case ISD::Xor: std::cerr << "Xor"; break;
+ case ISD::Br: std::cerr << "Br"; break;
+ case ISD::Switch: std::cerr << "Switch"; break;
+ case ISD::Ret: std::cerr << "Ret"; break;
+ case ISD::RetVoid: std::cerr << "RetVoid"; break;
+ case ISD::Load: std::cerr << "Load"; break;
+ case ISD::Store: std::cerr << "Store"; break;
+ case ISD::PHI: std::cerr << "PHI"; break;
+ case ISD::Call: std::cerr << "Call"; break;
+ }
+
+ std::cerr << "\n";
+}