Change treeRoots data structure to make enumeration deterministic.
authorVikram S. Adve <vadve@cs.uiuc.edu>
Sun, 24 Mar 2002 03:24:00 +0000 (03:24 +0000)
committerVikram S. Adve <vadve@cs.uiuc.edu>
Sun, 24 Mar 2002 03:24:00 +0000 (03:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1962 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/InstrSelection/InstrForest.cpp
lib/Target/SparcV9/InstrSelection/InstrForest.cpp

index b11d71e1f6b1cd78817475e10553b57b0856bf92..660f3112d72a68f396c4151065d1a3cc15b338e0 100644 (file)
@@ -56,7 +56,8 @@ InstrTreeNode::dump(int dumpChildren, int indent) const
 
 
 InstructionNode::InstructionNode(Instruction* I)
-  : InstrTreeNode(NTInstructionNode, I)
+  : InstrTreeNode(NTInstructionNode, I),
+    codeIsFoldedIntoParent(false)
 {
   opLabel = I->getOpcode();
 
@@ -198,7 +199,7 @@ InstrForest::InstrForest(Method *M)
 
 InstrForest::~InstrForest()
 {
-  for (std::hash_map<const Instruction*,InstructionNode*>::iterator I = begin();
+  for (std::hash_map<const Instruction*,InstructionNode*>::iterator I=begin();
        I != end(); ++I)
       delete I->second;
 }
@@ -206,37 +207,45 @@ InstrForest::~InstrForest()
 void
 InstrForest::dump() const
 {
-  for (std::hash_set<InstructionNode*>::const_iterator I = treeRoots.begin();
-       I != treeRoots.end(); ++I)
+  for (const_root_iterator I = roots_begin(); I != roots_end(); ++I)
     (*I)->dump(/*dumpChildren*/ 1, /*indent*/ 0);
 }
 
+inline void
+InstrForest::eraseRoot(InstructionNode* node)
+{
+  for (RootSet::reverse_iterator RI=treeRoots.rbegin(), RE=treeRoots.rend();
+       RI != RE; ++RI)
+    if (*RI == node)
+      treeRoots.erase(RI.base()-1);
+}
+
 inline void
 InstrForest::noteTreeNodeForInstr(Instruction *instr,
                                  InstructionNode *treeNode)
 {
   assert(treeNode->getNodeType() == InstrTreeNode::NTInstructionNode);
   (*this)[instr] = treeNode;
-  treeRoots.insert(treeNode);          // mark node as root of a new tree
+  treeRoots.push_back(treeNode);       // mark node as root of a new tree
 }
 
 
 inline void
-InstrForest::setLeftChild(InstrTreeNode *Par, InstrTreeNode *Chld)
+InstrForest::setLeftChild(InstrTreeNode *parent, InstrTreeNode *child)
 {
-  Par->LeftChild = Chld;
-  Chld->Parent = Par;
-  if (Chld->getNodeType() == InstrTreeNode::NTInstructionNode)
-    treeRoots.erase((InstructionNode*)Chld); // no longer a tree root
+  parent->LeftChild = child;
+  child->Parent = parent;
+  if (child->getNodeType() == InstrTreeNode::NTInstructionNode)
+    eraseRoot((InstructionNode*) child); // no longer a tree root
 }
 
 inline void
-InstrForest::setRightChild(InstrTreeNode *Par, InstrTreeNode *Chld)
+InstrForest::setRightChild(InstrTreeNode *parent, InstrTreeNode *child)
 {
-  Par->RightChild = Chld;
-  Chld->Parent = Par;
-  if (Chld->getNodeType() == InstrTreeNode::NTInstructionNode)
-    treeRoots.erase((InstructionNode*)Chld); // no longer a tree root
+  parent->RightChild = child;
+  child->Parent = parent;
+  if (child->getNodeType() == InstrTreeNode::NTInstructionNode)
+    eraseRoot((InstructionNode*) child); // no longer a tree root
 }
 
 
index b11d71e1f6b1cd78817475e10553b57b0856bf92..660f3112d72a68f396c4151065d1a3cc15b338e0 100644 (file)
@@ -56,7 +56,8 @@ InstrTreeNode::dump(int dumpChildren, int indent) const
 
 
 InstructionNode::InstructionNode(Instruction* I)
-  : InstrTreeNode(NTInstructionNode, I)
+  : InstrTreeNode(NTInstructionNode, I),
+    codeIsFoldedIntoParent(false)
 {
   opLabel = I->getOpcode();
 
@@ -198,7 +199,7 @@ InstrForest::InstrForest(Method *M)
 
 InstrForest::~InstrForest()
 {
-  for (std::hash_map<const Instruction*,InstructionNode*>::iterator I = begin();
+  for (std::hash_map<const Instruction*,InstructionNode*>::iterator I=begin();
        I != end(); ++I)
       delete I->second;
 }
@@ -206,37 +207,45 @@ InstrForest::~InstrForest()
 void
 InstrForest::dump() const
 {
-  for (std::hash_set<InstructionNode*>::const_iterator I = treeRoots.begin();
-       I != treeRoots.end(); ++I)
+  for (const_root_iterator I = roots_begin(); I != roots_end(); ++I)
     (*I)->dump(/*dumpChildren*/ 1, /*indent*/ 0);
 }
 
+inline void
+InstrForest::eraseRoot(InstructionNode* node)
+{
+  for (RootSet::reverse_iterator RI=treeRoots.rbegin(), RE=treeRoots.rend();
+       RI != RE; ++RI)
+    if (*RI == node)
+      treeRoots.erase(RI.base()-1);
+}
+
 inline void
 InstrForest::noteTreeNodeForInstr(Instruction *instr,
                                  InstructionNode *treeNode)
 {
   assert(treeNode->getNodeType() == InstrTreeNode::NTInstructionNode);
   (*this)[instr] = treeNode;
-  treeRoots.insert(treeNode);          // mark node as root of a new tree
+  treeRoots.push_back(treeNode);       // mark node as root of a new tree
 }
 
 
 inline void
-InstrForest::setLeftChild(InstrTreeNode *Par, InstrTreeNode *Chld)
+InstrForest::setLeftChild(InstrTreeNode *parent, InstrTreeNode *child)
 {
-  Par->LeftChild = Chld;
-  Chld->Parent = Par;
-  if (Chld->getNodeType() == InstrTreeNode::NTInstructionNode)
-    treeRoots.erase((InstructionNode*)Chld); // no longer a tree root
+  parent->LeftChild = child;
+  child->Parent = parent;
+  if (child->getNodeType() == InstrTreeNode::NTInstructionNode)
+    eraseRoot((InstructionNode*) child); // no longer a tree root
 }
 
 inline void
-InstrForest::setRightChild(InstrTreeNode *Par, InstrTreeNode *Chld)
+InstrForest::setRightChild(InstrTreeNode *parent, InstrTreeNode *child)
 {
-  Par->RightChild = Chld;
-  Chld->Parent = Par;
-  if (Chld->getNodeType() == InstrTreeNode::NTInstructionNode)
-    treeRoots.erase((InstructionNode*)Chld); // no longer a tree root
+  parent->RightChild = child;
+  child->Parent = parent;
+  if (child->getNodeType() == InstrTreeNode::NTInstructionNode)
+    eraseRoot((InstructionNode*) child); // no longer a tree root
 }