From: Vikram S. Adve Date: Sun, 24 Mar 2002 03:25:17 +0000 (+0000) Subject: Change treeRoots data structure to make enumeration deterministic. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6be4ebe1eb682eb6a9f5ef9fb8b52edd7cfb32bc;p=oota-llvm.git Change treeRoots data structure to make enumeration deterministic. Also, add a flag to marked nodes that do not need code because they have been folded into the user (parent in the BURG tree). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1963 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/InstrForest.h b/include/llvm/CodeGen/InstrForest.h index 834899d22cc..ef5e2f9a06a 100644 --- a/include/llvm/CodeGen/InstrForest.h +++ b/include/llvm/CodeGen/InstrForest.h @@ -27,7 +27,6 @@ #include "llvm/Instruction.h" #include "Support/NonCopyable.h" #include "Support/HashExtras.h" -#include class Constant; class BasicBlock; @@ -170,6 +169,9 @@ protected: class InstructionNode : public InstrTreeNode { +private: + bool codeIsFoldedIntoParent; + public: InstructionNode(Instruction *_instr); @@ -177,6 +179,10 @@ public: assert(treeNodeType == NTInstructionNode); return cast(val); } + + void markFoldedIntoParent() { codeIsFoldedIntoParent = true; } + bool isFoldedIntoParent() { return codeIsFoldedIntoParent; } + protected: virtual void dumpNode(int indent) const; }; @@ -239,8 +245,17 @@ protected: //------------------------------------------------------------------------ class InstrForest : private std::hash_map { +public: + // Use a vector for the root set to get a deterministic iterator + // for stable code generation. Even though we need to erase nodes + // during forest construction, a vector should still be efficient + // because the elements to erase are nearly always near the end. + typedef std::vector RootSet; + typedef RootSet:: iterator root_iterator; + typedef RootSet::const_iterator const_root_iterator; + private: - std::hash_set treeRoots; + RootSet treeRoots; public: /*ctor*/ InstrForest (Function *F); @@ -250,9 +265,10 @@ public: return (*this)[instr]; } - inline const std::hash_set &getRootSet() const { - return treeRoots; - } + const_root_iterator roots_begin() const { return treeRoots.begin(); } + root_iterator roots_begin() { return treeRoots.begin(); } + const_root_iterator roots_end () const { return treeRoots.end(); } + root_iterator roots_end () { return treeRoots.end(); } void dump() const; @@ -260,6 +276,7 @@ private: // // Private methods for buidling the instruction forest // + void eraseRoot (InstructionNode* node); void setLeftChild (InstrTreeNode* parent, InstrTreeNode* child); void setRightChild(InstrTreeNode* parent, InstrTreeNode* child); void setParent (InstrTreeNode* child, InstrTreeNode* parent);