Increase constness.
[oota-llvm.git] / lib / Target / SparcV9 / LiveVar / BBLiveVar.cpp
index 81d3b529f32a6c73a726495d5aa8efcfb1db98de..be09e62ae437971b1501aafaec4c328d8c7aca12 100644 (file)
@@ -1,4 +1,11 @@
 //===-- BBLiveVar.cpp - Live Variable Analysis for a BasicBlock -----------===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This is a wrapper class for BasicBlock which is used by live var analysis.
 //
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/Support/CFG.h"
 #include "Support/SetOperations.h"
+#include "../SparcInternals.h"
 
-/// BROKEN: Should not include sparc stuff directly into here
-#include "../../Target/Sparc/SparcInternals.h"  //  Only for PHI defn
-
-using std::cerr;
-
-static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
-
-BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
-                                 unsigned POID) {
-  BBLiveVar *Result = new BBLiveVar(BB, MBB, POID);
-  BB.addAnnotation(Result);
-  return Result;
-}
-
-BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock &BB) {
-  return (BBLiveVar*)BB.getAnnotation(AID);
-}
-
-void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {
-  bool Deleted = BB.deleteAnnotation(AID);
-  assert(Deleted && "BBLiveVar annotation did not exist!");
-}
-
+namespace llvm {
 
-BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
-  : Annotation(AID), BB(bb), MBB(mbb), POID(id) {
+BBLiveVar::BBLiveVar(const BasicBlock &bb,
+                     const MachineBasicBlock &mbb,
+                     unsigned id)
+  : BB(bb), MBB(mbb), POID(id) {
   InSetChanged = OutSetChanged = false;
 
   calcDefUseSets();
@@ -56,20 +44,20 @@ void BBLiveVar::calcDefUseSets() {
     const MachineInstr *MI = *MII;
     
     if (DEBUG_LV >= LV_DEBUG_Verbose) {
-      cerr << " *Iterating over machine instr ";
+      std::cerr << " *Iterating over machine instr ";
       MI->dump();
-      cerr << "\n";
+      std::cerr << "\n";
     }
 
     // iterate over  MI operands to find defs
     for (MachineInstr::const_val_op_iterator OpI = MI->begin(), OpE = MI->end();
          OpI != OpE; ++OpI)
-      if (OpI.isDef())      // add to Defs only if this operand is a def
+      if (OpI.isDef()) // add to Defs if this operand is a def
        addDef(*OpI);
 
     // do for implicit operands as well
     for (unsigned i = 0; i < MI->getNumImplicitRefs(); ++i)
-      if (MI->implicitRefIsDefined(i))
+      if (MI->getImplicitOp(i).isDef())
        addDef(MI->getImplicitRef(i));
     
     // iterate over MI operands to find uses
@@ -80,8 +68,7 @@ void BBLiveVar::calcDefUseSets() {
       if (isa<BasicBlock>(Op))
        continue;             // don't process labels
 
-      if (!OpI.isDef() || OpI.isDefAndUse()) {
-                                // add to Uses only if this operand is a use
+      if (OpI.isUse()) { // add to Uses only if this operand is a use
         //
         // *** WARNING: The following code for handling dummy PHI machine
         //     instructions is untested.  The previous code was broken and I
@@ -98,8 +85,8 @@ void BBLiveVar::calcDefUseSets() {
          PredToEdgeInSetMap[PredBB].insert(ArgVal); 
          
          if (DEBUG_LV >= LV_DEBUG_Verbose)
-           cerr << "   - phi operand " << RAV(ArgVal) << " came from BB "
-                 << RAV(PredBB) << "\n";
+           std::cerr << "   - phi operand " << RAV(ArgVal) << " came from BB "
+                      << RAV(PredBB) << "\n";
        } // if( IsPhi )
         else {
           // It is not a Phi use: add to regular use set and remove later defs.
@@ -116,7 +103,7 @@ void BBLiveVar::calcDefUseSets() {
       if (Op->getType() == Type::LabelTy)             // don't process labels
        continue;
 
-      if (!MI->implicitRefIsDefined(i) || MI->implicitRefIsDefinedAndUsed(i) )
+      if (MI->getImplicitOp(i).isUse())
        addUse(Op);
     }
   } // for all machine instructions
@@ -132,7 +119,7 @@ void BBLiveVar::addDef(const Value *Op) {
   InSet.erase(Op);       // this definition kills any later uses
   InSetChanged = true; 
 
-  if (DEBUG_LV >= LV_DEBUG_Verbose) cerr << "  +Def: " << RAV(Op) << "\n";
+  if (DEBUG_LV >= LV_DEBUG_Verbose) std::cerr << "  +Def: " << RAV(Op) << "\n";
 }
 
 
@@ -144,7 +131,7 @@ void  BBLiveVar::addUse(const Value *Op) {
   DefSet.erase(Op);   // remove if there is a def below this use
   InSetChanged = true; 
 
-  if (DEBUG_LV >= LV_DEBUG_Verbose) cerr << "   Use: " << RAV(Op) << "\n";
+  if (DEBUG_LV >= LV_DEBUG_Verbose) std::cerr << "   Use: " << RAV(Op) << "\n";
 }
 
 
@@ -200,7 +187,8 @@ bool BBLiveVar::setPropagate(ValueSet *OutSet, const ValueSet *InSet,
 // propagates in set to OutSets of PREDECESSORs
 //-----------------------------------------------------------------------------
 
-bool BBLiveVar::applyFlowFunc() {
+bool BBLiveVar::applyFlowFunc(hash_map<const BasicBlock*,
+                                       BBLiveVar*> &BBLiveVarInfo) {
   // IMPORTANT: caller should check whether inset changed 
   //            (else no point in calling)
   
@@ -211,7 +199,7 @@ bool BBLiveVar::applyFlowFunc() {
 
   for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
        PI != PE ; ++PI) {
-    BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI);
+    BBLiveVar *PredLVBB = BBLiveVarInfo[*PI];
 
     // do set union
     if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {  
@@ -231,16 +219,14 @@ bool BBLiveVar::applyFlowFunc() {
 // ----------------- Methods For Debugging (Printing) -----------------
 
 void BBLiveVar::printAllSets() const {
-  cerr << "  Defs: "; printSet(DefSet);  cerr << "\n";
-  cerr << "  In: ";  printSet(InSet);  cerr << "\n";
-  cerr << "  Out: "; printSet(OutSet);  cerr << "\n";
+  std::cerr << "  Defs: "; printSet(DefSet);  std::cerr << "\n";
+  std::cerr << "  In: ";  printSet(InSet);  std::cerr << "\n";
+  std::cerr << "  Out: "; printSet(OutSet);  std::cerr << "\n";
 }
 
 void BBLiveVar::printInOutSets() const {
-  cerr << "  In: ";   printSet(InSet);  cerr << "\n";
-  cerr << "  Out: ";  printSet(OutSet);  cerr << "\n";
+  std::cerr << "  In: ";   printSet(InSet);  std::cerr << "\n";
+  std::cerr << "  Out: ";  printSet(OutSet);  std::cerr << "\n";
 }
 
-
-
-
+} // End llvm namespace