Tweak argument
[oota-llvm.git] / include / llvm / Analysis / InstForest.h
index f48466b5de78ea4cc6e899733b0bfaa11928df39..e41bf8c3a9325d5c013a57100a096b4a35a9aa54 100644 (file)
@@ -1,4 +1,11 @@
-//===- llvm/Analysis/InstForest.h - Partition Func into forest ---*- C++ -*--=//
+//===- llvm/Analysis/InstForest.h - Partition Func into forest --*- C++ -*-===//
+// 
+//                     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 interface is used to partition a method into a forest of instruction
 // trees, where the following invariants hold:
 #ifndef LLVM_ANALYSIS_INSTFOREST_H
 #define LLVM_ANALYSIS_INSTFOREST_H
 
-#include "llvm/Instruction.h"
-#include "llvm/BasicBlock.h"
 #include "llvm/Function.h"
 #include "Support/Tree.h"
 #include <map>
 
+namespace llvm {
+
 template<class Payload> class InstTreeNode;
 template<class Payload> class InstForest;
 
@@ -50,10 +57,10 @@ class InstTreeNode :
   };
 
   // Helper functions to make accessing our data nicer...
-  const Value *getValue() const { return getTreeData().first.first; }
-        Value *getValue()       { return getTreeData().first.first; }
+  const Value *getValue() const { return this->getTreeData().first.first; }
+        Value *getValue()       { return this->getTreeData().first.first; }
   enum NodeTypeTy getNodeType() const {
-    return (enum NodeTypeTy)getTreeData().first.second;
+    return (enum NodeTypeTy)this->getTreeData().first.second;
   }
 
   InstTreeNode(const InstTreeNode &);     // Do not implement
@@ -64,8 +71,8 @@ class InstTreeNode :
   bool CanMergeInstIntoTree(Instruction *Inst);
 public:
   // Accessor functions...
-  inline       Payload &getData()       { return getTreeData().second; }
-  inline const Payload &getData() const { return getTreeData().second; }
+  inline       Payload &getData()       { return this->getTreeData().second; }
+  inline const Payload &getData() const { return this->getTreeData().second; }
 
   // Type checking functions...
   inline bool isConstant()    const { return getNodeType() == ConstNode; }
@@ -78,13 +85,13 @@ public:
     return cast<Constant>(getValue());
   }
   inline const Constant *getConstant() const {
-    return cast<const Constant>(getValue());
+    return cast<Constant>(getValue());
   }
   inline BasicBlock *getBasicBlock() {
     return cast<BasicBlock>(getValue());
   }
   inline const BasicBlock *getBasicBlock() const {
-    return cast<const BasicBlock>(getValue());
+    return cast<BasicBlock>(getValue());
   }
   inline Instruction *getInstruction() {
     assert(isInstruction() && "getInstruction() on non instruction node!");
@@ -119,8 +126,8 @@ public:
     o << getValue();
     if (!isa<Instruction>(getValue())) o << "\n";
 
-    for (unsigned i = 0; i < getNumChildren(); ++i)
-      getChild(i)->print(o, Indent+1);
+    for (unsigned i = 0; i < this->getNumChildren(); ++i)
+      this->getChild(i)->print(o, Indent+1);
   }
 };
 
@@ -142,6 +149,8 @@ template<class Payload>
 class InstForest : public std::vector<InstTreeNode<Payload> *> {
   friend class InstTreeNode<Payload>;
 
+  typedef typename std::vector<InstTreeNode<Payload> *>::const_iterator const_iterator;
+
   // InstMap - Map contains entries for ALL instructions in the method and the
   // InstTreeNode that they correspond to.
   //
@@ -152,9 +161,9 @@ class InstForest : public std::vector<InstTreeNode<Payload> *> {
   }
 
   void removeInstFromRootList(Instruction *I) {
-    for (unsigned i = size(); i > 0; --i)
-      if (operator[](i-1)->getValue() == I) {
-       erase(begin()+i-1);
+    for (unsigned i = this->size(); i > 0; --i)
+      if ((*this)[i-1]->getValue() == I) {
+       this->erase(this->begin()+i-1);
        return;
       }
   }
@@ -173,8 +182,8 @@ public:
 
   // dtor - Free the trees...
   ~InstForest() {
-    for (unsigned i = size(); i != 0; --i)
-      delete operator[](i-1);
+    for (unsigned i = this->size(); i != 0; --i)
+      delete (*this)[i-1];
   }
 
   // getInstNode - Return the instruction node that corresponds to the specified
@@ -182,13 +191,13 @@ public:
   // the parent pointer can be used to find the root of the tree.
   //
   inline InstTreeNode<Payload> *getInstNode(Instruction *Inst) {
-    std::map<Instruction*, InstTreeNode<Payload> *>::iterator I =
+    typename std::map<Instruction*, InstTreeNode<Payload> *>::iterator I =
       InstMap.find(Inst);
     if (I != InstMap.end()) return I->second;
     return 0;
   }
   inline const InstTreeNode<Payload> *getInstNode(const Instruction *Inst)const{
-    std::map<Instruction*, InstTreeNode<Payload>*>::const_iterator I = 
+    typename std::map<Instruction*, InstTreeNode<Payload>*>::const_iterator I = 
       InstMap.find(Inst);
     if (I != InstMap.end()) return I->second;
     return 0;
@@ -196,7 +205,7 @@ public:
 
   // print - Called by operator<< below...
   void print(std::ostream &out) const {
-    for (const_iterator I = begin(), E = end(); I != E; ++I)
+    for (const_iterator I = this->begin(), E = this->end(); I != E; ++I)
       out << *I;
   }
 };
@@ -218,7 +227,7 @@ inline std::ostream &operator<<(std::ostream &o, const InstForest<Payload> &IF){
 //
 template <class Payload>
 bool InstTreeNode<Payload>::CanMergeInstIntoTree(Instruction *I) {
-  if (I->use_size() > 1) return false;
+  if (!I->use_empty() && !I->hasOneUse()) return false;
   return I->getParent() == cast<Instruction>(getValue())->getParent();
 }
 
@@ -230,18 +239,18 @@ bool InstTreeNode<Payload>::CanMergeInstIntoTree(Instruction *I) {
 template <class Payload>
 InstTreeNode<Payload>::InstTreeNode(InstForest<Payload> &IF, Value *V,
                                    InstTreeNode *Parent) : super(Parent) {
-  getTreeData().first.first = V;   // Save tree node
+  this->getTreeData().first.first = V;   // Save tree node
  
   if (!isa<Instruction>(V)) {
     assert((isa<Constant>(V) || isa<BasicBlock>(V) ||
            isa<Argument>(V) || isa<GlobalValue>(V)) &&
           "Unrecognized value type for InstForest Partition!");
     if (isa<Constant>(V))
-      getTreeData().first.second = ConstNode;
+      this->getTreeData().first.second = ConstNode;
     else if (isa<BasicBlock>(V))
-      getTreeData().first.second = BasicBlockNode;
+      this->getTreeData().first.second = BasicBlockNode;
     else 
-      getTreeData().first.second = TemporaryNode;
+      this->getTreeData().first.second = TemporaryNode;
       
     return;
   }
@@ -250,7 +259,7 @@ InstTreeNode<Payload>::InstTreeNode(InstForest<Payload> &IF, Value *V,
   Instruction *I = cast<Instruction>(V);
   if (Parent && !Parent->CanMergeInstIntoTree(I)) {
     // Not root node of tree, but mult uses?
-    getTreeData().first.second = TemporaryNode;   // Must be a temporary!
+    this->getTreeData().first.second = TemporaryNode;   // Must be a temporary!
     return;
   }
 
@@ -278,8 +287,10 @@ InstTreeNode<Payload>::InstTreeNode(InstForest<Payload> &IF, Value *V,
   }
 
   setChildren(Children);
-  getTreeData().first.second = InstructionNode;
+  this->getTreeData().first.second = InstructionNode;
 }
 
+} // End llvm namespace
+
 #endif