Print "circular" warning message only in debug mode.
[oota-llvm.git] / lib / Target / SparcV9 / InstrSelection / InstrForest.cpp
index 0934e7bbd566d97be277bf276dc9c9e0c1f13f36..c33faec9a04a6774f09bb2977f14aff52748a544 100644 (file)
@@ -1,12 +1,5 @@
-// $Id$
-//---------------------------------------------------------------------------
-// File:
-//     InstrForest.cpp
-// 
-// Purpose:
-//     Convert SSA graph to instruction trees for instruction selection.
-// 
-// Strategy:
+//===-- InstrForest.cpp - Build instruction forest for inst selection -----===//
+//
 //  The key goal is to group instructions into a single
 //  tree if one or more of them might be potentially combined into a single
 //  complex instruction in the target machine.
 //  and (2) O and I are part of the same basic block,
 //  and (3) O has only a single use, viz., I.
 // 
-//---------------------------------------------------------------------------
+//===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/InstrForest.h"
 #include "llvm/CodeGen/MachineCodeForInstruction.h"
 #include "llvm/Function.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iMemory.h"
-#include "llvm/ConstantVals.h"
-#include "llvm/BasicBlock.h"
+#include "llvm/Constant.h"
+#include "llvm/Type.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "Support/STLExtras.h"
-#include <iostream>
+#include <alloca.h>
 using std::cerr;
 using std::vector;
 
@@ -75,16 +68,20 @@ InstructionNode::InstructionNode(Instruction* I)
     {
       opLabel = AllocaN;                // Alloca(ptr, N) operation
     }
-  else if ((opLabel == Instruction::Load ||
-           opLabel == Instruction::GetElementPtr) &&
-          cast<MemAccessInst>(I)->hasIndices())
+  else if (opLabel == Instruction::GetElementPtr &&
+          cast<GetElementPtrInst>(I)->hasIndices())
     {
-      opLabel = opLabel + 100;          // load/getElem with index vector
+      opLabel = opLabel + 100;          // getElem with index vector
+    }
+  else if (opLabel == Instruction::Xor &&
+           BinaryOperator::isNot(I))
+    {
+      opLabel = (I->getType() == Type::BoolTy)?  NotOp  // boolean Not operator
+                                              : BNotOp; // bitwise Not operator
     }
   else if (opLabel == Instruction::And ||
            opLabel == Instruction::Or ||
-           opLabel == Instruction::Xor ||
-           opLabel == Instruction::Not)
+           opLabel == Instruction::Xor)
     {
       // Distinguish bitwise operators from logical operators!
       if (I->getType() != Type::BoolTy)
@@ -121,21 +118,8 @@ InstructionNode::dumpNode(int indent) const
 {
   for (int i=0; i < indent; i++)
     cerr << "    ";
-  
-  cerr << getInstruction()->getOpcodeName();
-  const MachineCodeForInstruction &mvec =
-    MachineCodeForInstruction::get(getInstruction());
-
-  if (mvec.size() > 0)
-    cerr << "\tMachine Instructions:  ";
-
-  for (unsigned int i=0; i < mvec.size(); ++i) {
-    mvec[i]->dump(0);
-    if (i < mvec.size() - 1)
-      cerr << ";  ";
-  }
-  
-  cerr << "\n";
+  cerr << getInstruction()->getOpcodeName()
+       << " [label " << getOpLabel() << "]" << "\n";
 }
 
 
@@ -186,10 +170,9 @@ LabelNode::dumpNode(int indent) const
 
 InstrForest::InstrForest(Function *F)
 {
-  for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) {
-    BasicBlock *BB = *FI;
-    for_each(BB->begin(), BB->end(),
-             bind_obj(this, &InstrForest::buildTreeForInstruction));
+  for (Function::iterator BB = F->begin(), FE = F->end(); BB != FE; ++BB) {
+    for(BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+      buildTreeForInstruction(I);
   }
 }
 
@@ -218,7 +201,6 @@ inline void
 InstrForest::noteTreeNodeForInstr(Instruction *instr,
                                  InstructionNode *treeNode)
 {
-  assert(treeNode->getNodeType() == InstrTreeNode::NTInstructionNode);
   (*this)[instr] = treeNode;
   treeRoots.push_back(treeNode);       // mark node as root of a new tree
 }
@@ -229,8 +211,8 @@ InstrForest::setLeftChild(InstrTreeNode *parent, InstrTreeNode *child)
 {
   parent->LeftChild = child;
   child->Parent = parent;
-  if (child->getNodeType() == InstrTreeNode::NTInstructionNode)
-    eraseRoot((InstructionNode*) child); // no longer a tree root
+  if (InstructionNode* instrNode = dyn_cast<InstructionNode>(child))
+    eraseRoot(instrNode); // no longer a tree root
 }
 
 inline void
@@ -238,8 +220,8 @@ InstrForest::setRightChild(InstrTreeNode *parent, InstrTreeNode *child)
 {
   parent->RightChild = child;
   child->Parent = parent;
-  if (child->getNodeType() == InstrTreeNode::NTInstructionNode)
-    eraseRoot((InstructionNode*) child); // no longer a tree root
+  if (InstructionNode* instrNode = dyn_cast<InstructionNode>(child))
+    eraseRoot(instrNode); // no longer a tree root
 }
 
 
@@ -297,7 +279,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
        && !instr->isTerminator();
     
       if (includeAddressOperand || isa<Instruction>(operand) ||
-         isa<Constant>(operand) || isa<FunctionArgument>(operand) ||
+         isa<Constant>(operand) || isa<Argument>(operand) ||
          isa<GlobalVariable>(operand))
        {
          // This operand is a data value