LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

SelectionDAG.cpp

Go to the documentation of this file.
00001 //===-- SelectionDAG.cpp - Implement the SelectionDAG* classes ------------===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the SelectionDAG* classes, which are used to perform
00011 // DAG-based instruction selection in a target-specific manner.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #include "llvm/CodeGen/SelectionDAG.h"
00016 #include "llvm/Type.h"
00017 #include <iostream>
00018 
00019 using namespace llvm;
00020 
00021 SelectionDAG::~SelectionDAG() {
00022   for (unsigned i = 0, e = AllNodes.size(); i != e; ++i)
00023     delete AllNodes[i];
00024 }
00025 
00026 
00027 /// dump - Print out the current Selection DAG...
00028 void SelectionDAG::dump() const {
00029   Root->dump();  // Print from the root...
00030 }
00031 
00032 /// getValueType - Return the ValueType for the specified LLVM type.  This
00033 /// method works on all scalar LLVM types.
00034 ///
00035 MVT::ValueType SelectionDAG::getValueType(const Type *Ty) const {
00036   switch (Ty->getTypeID()) {
00037   case Type::VoidTyID: assert(0 && "Void type object in getValueType!");
00038   default: assert(0 && "Unknown type in DAGBuilder!\n");
00039   case Type::BoolTyID:    return MVT::i1;
00040   case Type::SByteTyID:
00041   case Type::UByteTyID:   return MVT::i8;
00042   case Type::ShortTyID:
00043   case Type::UShortTyID:  return MVT::i16;
00044   case Type::IntTyID:
00045   case Type::UIntTyID:    return MVT::i32;
00046   case Type::LongTyID:
00047   case Type::ULongTyID:   return MVT::i64;
00048   case Type::FloatTyID:   return MVT::f32;
00049   case Type::DoubleTyID:  return MVT::f64;
00050   case Type::LabelTyID:
00051   case Type::PointerTyID: return PointerType;
00052   }
00053 }
00054 
00055 void SelectionDAGNode::dump() const {
00056   // Print out the DAG in post-order
00057   std::map<const SelectionDAGNode*, unsigned> NodeIDs;
00058   unsigned ID = 0;
00059   printit(0, ID, NodeIDs);
00060 }
00061 
00062 void SelectionDAGNode::printit(unsigned Offset, unsigned &LastID,
00063                                std::map<const SelectionDAGNode*,
00064                                         unsigned> &NodeIDs) const {
00065   if (!NodeIDs.count(this)) {
00066     // Emit all of the uses first...
00067     for (unsigned i = 0, e = Uses.size(); i != e; ++i)
00068       Uses[i]->printit(Offset+1, LastID, NodeIDs);
00069 
00070     NodeIDs[this] = LastID++;
00071 
00072     std::cerr << std::string(Offset, ' ') << "#" << LastID-1 << " ";
00073   } else {
00074     // Node has already been emitted...
00075     std::cerr << std::string(Offset, ' ') << "#" << NodeIDs[this] << " ";
00076   }
00077 
00078   switch (ValueType) {
00079   case MVT::isVoid: std::cerr << "V:"; break;
00080   case MVT::i1:   std::cerr << "i1:"; break;
00081   case MVT::i8:   std::cerr << "i8:"; break;
00082   case MVT::i16:  std::cerr << "i16:"; break;
00083   case MVT::i32:  std::cerr << "i32:"; break;
00084   case MVT::i64:  std::cerr << "i64:"; break;
00085   case MVT::f32:  std::cerr << "f32:"; break;
00086   case MVT::f64:  std::cerr << "f64:"; break;
00087   default: assert(0 && "Invalid node ValueType!");
00088   }
00089   switch (NodeType) {
00090   case ISD::ChainNode:      std::cerr << "ChainNode"; break;
00091   case ISD::BlockChainNode: std::cerr << "BlockChainNode"; break;
00092   case ISD::ProtoNode:      std::cerr << "ProtoNode"; break;
00093 
00094   case ISD::Constant:       std::cerr << "Constant"; break;
00095   case ISD::FrameIndex:     std::cerr << "FrameIndex"; break;
00096   case ISD::BasicBlock:     std::cerr << "BasicBlock"; break;
00097 
00098   case ISD::Plus:           std::cerr << "Plus"; break;
00099   case ISD::Minus:          std::cerr << "Minus"; break;
00100   case ISD::Times:          std::cerr << "Times"; break;
00101   case ISD::SDiv:           std::cerr << "SDiv"; break;
00102   case ISD::UDiv:           std::cerr << "UDiv"; break;
00103   case ISD::SRem:           std::cerr << "SRem"; break;
00104   case ISD::URem:           std::cerr << "URem"; break;
00105   case ISD::And:            std::cerr << "And"; break;
00106   case ISD::Or:             std::cerr << "Or"; break;
00107   case ISD::Xor:            std::cerr << "Xor"; break;
00108 
00109   case ISD::SetEQ:          std::cerr << "SetEQ"; break;
00110   case ISD::SetNE:          std::cerr << "SetNE"; break;
00111   case ISD::SetLT:          std::cerr << "SetLT"; break;
00112   case ISD::SetLE:          std::cerr << "SetLE"; break;
00113   case ISD::SetGT:          std::cerr << "SetGT"; break;
00114   case ISD::SetGE:          std::cerr << "SetGE"; break;
00115 
00116   case ISD::Br:             std::cerr << "Br"; break;
00117   case ISD::BrCond:         std::cerr << "BrCond"; break;
00118   case ISD::Switch:         std::cerr << "Switch"; break;
00119   case ISD::Ret:            std::cerr << "Ret"; break;
00120   case ISD::RetVoid:        std::cerr << "RetVoid"; break;
00121   case ISD::Load:           std::cerr << "Load"; break;
00122   case ISD::Store:          std::cerr << "Store"; break;
00123   case ISD::PHI:            std::cerr << "PHI"; break;
00124   case ISD::Call:           std::cerr << "Call"; break;
00125 
00126   case ISD::Unspec1:        std::cerr << "Unspec1"; break;
00127   case ISD::Unspec2:        std::cerr << "Unspec2"; break;
00128   }
00129 
00130   std::cerr << "\n";
00131 }