From: Chris Lattner Date: Sun, 20 Jan 2002 22:54:45 +0000 (+0000) Subject: Changes to build successfully with GCC 3.02 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=697954c15da58bd8b186dbafdedd8b06db770201;p=oota-llvm.git Changes to build successfully with GCC 3.02 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1503 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Makefile.common b/Makefile.common index 95f3aa9f098..72d9a32ed7e 100644 --- a/Makefile.common +++ b/Makefile.common @@ -52,7 +52,7 @@ RunBurg = $(BURG) $(BURG_OPTS) #Prof = -pg # TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti -CompileCommonOpts = $(Prof) -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include +CompileCommonOpts = $(Prof) -Wall -W -Wwrite-strings -Wno-unused-parameter -Wno-missing-braces -I$(LEVEL)/include # Compile a file, don't link... Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts) diff --git a/Makefile.rules b/Makefile.rules index 95f3aa9f098..72d9a32ed7e 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -52,7 +52,7 @@ RunBurg = $(BURG) $(BURG_OPTS) #Prof = -pg # TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti -CompileCommonOpts = $(Prof) -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include +CompileCommonOpts = $(Prof) -Wall -W -Wwrite-strings -Wno-unused-parameter -Wno-missing-braces -I$(LEVEL)/include # Compile a file, don't link... Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts) diff --git a/include/Support/Annotation.h b/include/Support/Annotation.h index 99197326928..c0642e1d23d 100644 --- a/include/Support/Annotation.h +++ b/include/Support/Annotation.h @@ -166,12 +166,13 @@ struct AnnotationManager { //===--------------------------------------------------------------------===// // Basic ID <-> Name map functionality - static AnnotationID getID (const string &Name); // Name -> ID - static const string &getName(AnnotationID ID); // ID -> Name + static AnnotationID getID(const std::string &Name); // Name -> ID + static const std::string &getName(AnnotationID ID); // ID -> Name // getID - Name -> ID + registration of a factory function for demand driven // annotation support. - static AnnotationID getID (const string &Name, Factory Fact, void *Data=0); + static AnnotationID getID(const std::string &Name, Factory Fact, + void *Data = 0); //===--------------------------------------------------------------------===// // Annotation creation on demand support... diff --git a/include/Support/CommandLine.h b/include/Support/CommandLine.h index 84a3bc9b59d..3c0ac1ac693 100644 --- a/include/Support/CommandLine.h +++ b/include/Support/CommandLine.h @@ -100,7 +100,7 @@ class Option { // an argument. Should return true if there was an error processing the // argument and the program should exit. // - virtual bool handleOccurance(const char *ArgName, const string &Arg) = 0; + virtual bool handleOccurance(const char *ArgName, const std::string &Arg) = 0; virtual enum NumOccurances getNumOccurancesFlagDefault() const { return Optional; @@ -146,10 +146,10 @@ public: // addOccurance - Wrapper around handleOccurance that enforces Flags // - bool addOccurance(const char *ArgName, const string &Value); + bool addOccurance(const char *ArgName, const std::string &Value); // Prints option name followed by message. Always returns true. - bool error(string Message, const char *ArgName = 0); + bool error(std::string Message, const char *ArgName = 0); public: inline int getNumOccurances() const { return NumOccurances; } @@ -162,7 +162,7 @@ public: // class Alias : public Option { Option &AliasFor; - virtual bool handleOccurance(const char *ArgName, const string &Arg) { + virtual bool handleOccurance(const char *ArgName, const std::string &Arg) { return AliasFor.handleOccurance(AliasFor.ArgStr, Arg); } virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;} @@ -177,7 +177,7 @@ public: // class Flag : public Option { bool Value; - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); public: inline Flag(const char *ArgStr, const char *Message, int Flags = 0, bool DefaultVal = 0) : Option(ArgStr, Message, Flags), @@ -193,7 +193,7 @@ public: // class Int : public Option { int Value; - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); virtual enum ValueExpected getValueExpectedFlagDefault() const { return ValueRequired; } @@ -209,18 +209,18 @@ public: //===----------------------------------------------------------------------===// // String valued command line option // -class String : public Option, public string { - virtual bool handleOccurance(const char *ArgName, const string &Arg); +class String : public Option, public std::string { + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); virtual enum ValueExpected getValueExpectedFlagDefault() const { return ValueRequired; } public: inline String(const char *ArgStr, const char *Help, int Flags = 0, const char *DefaultVal = "") - : Option(ArgStr, Help, Flags), string(DefaultVal) {} + : Option(ArgStr, Help, Flags), std::string(DefaultVal) {} - inline const string &operator=(const string &Val) { - return string::operator=(Val); + inline const std::string &operator=(const std::string &Val) { + return std::string::operator=(Val); } }; @@ -228,7 +228,7 @@ public: //===----------------------------------------------------------------------===// // String list command line option // -class StringList : public Option, public vector { +class StringList : public Option, public std::vector { virtual enum NumOccurances getNumOccurancesFlagDefault() const { return ZeroOrMore; @@ -236,7 +236,7 @@ class StringList : public Option, public vector { virtual enum ValueExpected getValueExpectedFlagDefault() const { return ValueRequired; } - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); public: inline StringList(const char *ArgStr, const char *Help, int Flags = 0) @@ -256,7 +256,7 @@ protected: // Use a vector instead of a map, because the lists should be short, // the overhead is less, and most importantly, it keeps them in the order // inserted so we can print our option out nicely. - vector > > ValueMap; + std::vector > > ValueMap; inline EnumBase(const char *ArgStr, const char *Help, int Flags) : Option(ArgStr, Help, Flags) {} @@ -284,7 +284,7 @@ protected: inline EnumValueBase(int Flags) : EnumBase(Flags) {} // handleOccurance - Set Value to the enum value specified by Arg - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); // Return the width of the option tag for printing... virtual unsigned getOptionWidth() const; @@ -323,7 +323,7 @@ class EnumFlagsBase : public EnumValueBase { return ValueDisallowed; } protected: - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); inline EnumFlagsBase(int Flags) : EnumValueBase(Flags) {} // Return the width of the option tag for printing... @@ -363,11 +363,11 @@ class EnumListBase : public EnumBase { return ValueDisallowed; } protected: - vector Values; // The options specified so far. + std::vector Values; // The options specified so far. inline EnumListBase(int Flags) : EnumBase(Flags) {} - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); // Return the width of the option tag for printing... virtual unsigned getOptionWidth() const; diff --git a/include/Support/DepthFirstIterator.h b/include/Support/DepthFirstIterator.h index a2d5a9df68c..2961497adc3 100644 --- a/include/Support/DepthFirstIterator.h +++ b/include/Support/DepthFirstIterator.h @@ -20,21 +20,21 @@ class df_iterator : public std::forward_iterator Visited; // All of the blocks visited so far... + std::set Visited; // All of the blocks visited so far... // VisitStack - Used to maintain the ordering. Top = current block // First element is node pointer, second is the 'next child' to visit - stack > VisitStack; + std::stack > VisitStack; const bool Reverse; // Iterate over children before self? private: void reverseEnterNode() { - pair &Top = VisitStack.top(); + std::pair &Top = VisitStack.top(); NodeType *Node = Top.first; ChildItTy &It = Top.second; for (; It != GT::child_end(Node); ++It) { NodeType *Child = *It; if (!Visited.count(Child)) { Visited.insert(Child); - VisitStack.push(make_pair(Child, GT::child_begin(Child))); + VisitStack.push(std::make_pair(Child, GT::child_begin(Child))); reverseEnterNode(); return; } @@ -43,7 +43,7 @@ private: inline df_iterator(NodeType *Node, bool reverse) : Reverse(reverse) { Visited.insert(Node); - VisitStack.push(make_pair(Node, GT::child_begin(Node))); + VisitStack.push(std::make_pair(Node, GT::child_begin(Node))); if (Reverse) reverseEnterNode(); } inline df_iterator() { /* End is when stack is empty */ } @@ -81,7 +81,7 @@ public: reverseEnterNode(); } else { // Normal Depth First Iterator do { - pair &Top = VisitStack.top(); + std::pair &Top = VisitStack.top(); NodeType *Node = Top.first; ChildItTy &It = Top.second; @@ -90,7 +90,7 @@ public: if (!Visited.count(Next)) { // Has our next sibling been visited? // No, do it now. Visited.insert(Next); - VisitStack.push(make_pair(Next, GT::child_begin(Next))); + VisitStack.push(std::make_pair(Next, GT::child_begin(Next))); return *this; } } diff --git a/include/Support/HashExtras.h b/include/Support/HashExtras.h index 6ea831e78f0..d7e48a3b625 100644 --- a/include/Support/HashExtras.h +++ b/include/Support/HashExtras.h @@ -11,7 +11,10 @@ #define LLVM_SUPPORT_HASHEXTRAS_H #include -#include +#include + +// Cannot specialize hash template from outside of the std namespace. +namespace std { template <> struct hash { size_t operator()(string const &str) const { @@ -24,4 +27,6 @@ template struct hash { inline size_t operator()(const T *Val) const { return (size_t)Val; } }; +} // End namespace std + #endif diff --git a/include/Support/PostOrderIterator.h b/include/Support/PostOrderIterator.h index 89a9b4db869..85b3bf649c0 100644 --- a/include/Support/PostOrderIterator.h +++ b/include/Support/PostOrderIterator.h @@ -20,10 +20,10 @@ class po_iterator : public std::forward_iterator Visited; // All of the blocks visited so far... + std::set Visited; // All of the blocks visited so far... // VisitStack - Used to maintain the ordering. Top = current block // First element is basic block pointer, second is the 'next child' to visit - stack > VisitStack; + std::stack > VisitStack; void traverseChild() { while (VisitStack.top().second != GT::child_end(VisitStack.top().first)) { @@ -122,10 +122,10 @@ ipo_iterator ipo_end(T G){ // } // -typedef reverse_iterator::iterator> rpo_iterator; +typedef std::vector::reverse_iterator rpo_iterator; // TODO: FIXME: ReversePostOrderTraversal is not generic! class ReversePostOrderTraversal { - vector Blocks; // Block list in normal PO order + std::vector Blocks; // Block list in normal PO order inline void Initialize(BasicBlock *BB) { copy(po_begin(BB), po_end(BB), back_inserter(Blocks)); } diff --git a/include/Support/STLExtras.h b/include/Support/STLExtras.h index 44d789dcf22..0168bf26244 100644 --- a/include/Support/STLExtras.h +++ b/include/Support/STLExtras.h @@ -36,7 +36,7 @@ // arguments to get a boolean result. // template -struct bitwise_or : public binary_function { +struct bitwise_or : public std::binary_function { bool operator()(const Ty& left, const Ty& right) const { return left | right; } @@ -70,9 +70,9 @@ class mapped_iterator { RootIt current; UnaryFunc Fn; public: - typedef typename iterator_traits::iterator_category + typedef typename std::iterator_traits::iterator_category iterator_category; - typedef typename iterator_traits::difference_type + typedef typename std::iterator_traits::difference_type difference_type; typedef typename UnaryFunc::result_type value_type; typedef typename UnaryFunc::result_type *pointer; @@ -102,6 +102,7 @@ public: _Self& operator-= (difference_type n) { current -= n; return *this; } reference operator[](difference_type n) const { return *(*this + n); } + inline bool operator!=(const _Self &X) const { return !operator==(X); } inline bool operator==(const _Self &X) const { return current == X.current; } inline bool operator< (const _Self &X) const { return current < X.current; } diff --git a/include/Support/StringExtras.h b/include/Support/StringExtras.h index e67e25ced51..46e2c5aaf0b 100644 --- a/include/Support/StringExtras.h +++ b/include/Support/StringExtras.h @@ -11,7 +11,7 @@ #include #include -static inline string utostr(uint64_t X, bool isNeg = false) { +static inline std::string utostr(uint64_t X, bool isNeg = false) { char Buffer[40]; char *BufPtr = Buffer+39; @@ -25,10 +25,10 @@ static inline string utostr(uint64_t X, bool isNeg = false) { if (isNeg) *--BufPtr = '-'; // Add negative sign... - return string(BufPtr); + return std::string(BufPtr); } -static inline string itostr(int64_t X) { +static inline std::string itostr(int64_t X) { if (X < 0) return utostr((uint64_t)-X, true); else @@ -36,7 +36,7 @@ static inline string itostr(int64_t X) { } -static inline string utostr(unsigned X, bool isNeg = false) { +static inline std::string utostr(unsigned X, bool isNeg = false) { char Buffer[20]; char *BufPtr = Buffer+19; @@ -50,17 +50,17 @@ static inline string utostr(unsigned X, bool isNeg = false) { if (isNeg) *--BufPtr = '-'; // Add negative sign... - return string(BufPtr); + return std::string(BufPtr); } -static inline string itostr(int X) { +static inline std::string itostr(int X) { if (X < 0) return utostr((unsigned)-X, true); else return utostr((unsigned)X); } -static inline string ftostr(double V) { +static inline std::string ftostr(double V) { char Buffer[200]; snprintf(Buffer, 200, "%e", V); return Buffer; diff --git a/include/Support/Tree.h b/include/Support/Tree.h index 33b0bb7b039..9e8d5ae7efa 100644 --- a/include/Support/Tree.h +++ b/include/Support/Tree.h @@ -12,21 +12,21 @@ template class Tree { - vector Children; // This nodes children, if any - ConcreteTreeNode *Parent; // Parent of this node... - Payload Data; // Data held in this node... + std::vector Children; // This nodes children, if any + ConcreteTreeNode *Parent; // Parent of this node... + Payload Data; // Data held in this node... protected: - void setChildren(const vector &children) { + void setChildren(const std::vector &children) { Children = children; } public: inline Tree(ConcreteTreeNode *parent) : Parent(parent) {} - inline Tree(const vector &children, ConcreteTreeNode *par) - : Children(children), Parent(par) {} + inline Tree(const std::vector &children, + ConcreteTreeNode *par) : Children(children), Parent(par) {} - inline Tree(const vector &children, ConcreteTreeNode *par, - const Payload &data) + inline Tree(const std::vector &children, + ConcreteTreeNode *par, const Payload &data) : Children(children), Parent(parent), Data(data) {} // Tree dtor - Free all children diff --git a/include/llvm/ADT/DepthFirstIterator.h b/include/llvm/ADT/DepthFirstIterator.h index a2d5a9df68c..2961497adc3 100644 --- a/include/llvm/ADT/DepthFirstIterator.h +++ b/include/llvm/ADT/DepthFirstIterator.h @@ -20,21 +20,21 @@ class df_iterator : public std::forward_iterator Visited; // All of the blocks visited so far... + std::set Visited; // All of the blocks visited so far... // VisitStack - Used to maintain the ordering. Top = current block // First element is node pointer, second is the 'next child' to visit - stack > VisitStack; + std::stack > VisitStack; const bool Reverse; // Iterate over children before self? private: void reverseEnterNode() { - pair &Top = VisitStack.top(); + std::pair &Top = VisitStack.top(); NodeType *Node = Top.first; ChildItTy &It = Top.second; for (; It != GT::child_end(Node); ++It) { NodeType *Child = *It; if (!Visited.count(Child)) { Visited.insert(Child); - VisitStack.push(make_pair(Child, GT::child_begin(Child))); + VisitStack.push(std::make_pair(Child, GT::child_begin(Child))); reverseEnterNode(); return; } @@ -43,7 +43,7 @@ private: inline df_iterator(NodeType *Node, bool reverse) : Reverse(reverse) { Visited.insert(Node); - VisitStack.push(make_pair(Node, GT::child_begin(Node))); + VisitStack.push(std::make_pair(Node, GT::child_begin(Node))); if (Reverse) reverseEnterNode(); } inline df_iterator() { /* End is when stack is empty */ } @@ -81,7 +81,7 @@ public: reverseEnterNode(); } else { // Normal Depth First Iterator do { - pair &Top = VisitStack.top(); + std::pair &Top = VisitStack.top(); NodeType *Node = Top.first; ChildItTy &It = Top.second; @@ -90,7 +90,7 @@ public: if (!Visited.count(Next)) { // Has our next sibling been visited? // No, do it now. Visited.insert(Next); - VisitStack.push(make_pair(Next, GT::child_begin(Next))); + VisitStack.push(std::make_pair(Next, GT::child_begin(Next))); return *this; } } diff --git a/include/llvm/ADT/HashExtras.h b/include/llvm/ADT/HashExtras.h index 6ea831e78f0..d7e48a3b625 100644 --- a/include/llvm/ADT/HashExtras.h +++ b/include/llvm/ADT/HashExtras.h @@ -11,7 +11,10 @@ #define LLVM_SUPPORT_HASHEXTRAS_H #include -#include +#include + +// Cannot specialize hash template from outside of the std namespace. +namespace std { template <> struct hash { size_t operator()(string const &str) const { @@ -24,4 +27,6 @@ template struct hash { inline size_t operator()(const T *Val) const { return (size_t)Val; } }; +} // End namespace std + #endif diff --git a/include/llvm/ADT/PostOrderIterator.h b/include/llvm/ADT/PostOrderIterator.h index 89a9b4db869..85b3bf649c0 100644 --- a/include/llvm/ADT/PostOrderIterator.h +++ b/include/llvm/ADT/PostOrderIterator.h @@ -20,10 +20,10 @@ class po_iterator : public std::forward_iterator Visited; // All of the blocks visited so far... + std::set Visited; // All of the blocks visited so far... // VisitStack - Used to maintain the ordering. Top = current block // First element is basic block pointer, second is the 'next child' to visit - stack > VisitStack; + std::stack > VisitStack; void traverseChild() { while (VisitStack.top().second != GT::child_end(VisitStack.top().first)) { @@ -122,10 +122,10 @@ ipo_iterator ipo_end(T G){ // } // -typedef reverse_iterator::iterator> rpo_iterator; +typedef std::vector::reverse_iterator rpo_iterator; // TODO: FIXME: ReversePostOrderTraversal is not generic! class ReversePostOrderTraversal { - vector Blocks; // Block list in normal PO order + std::vector Blocks; // Block list in normal PO order inline void Initialize(BasicBlock *BB) { copy(po_begin(BB), po_end(BB), back_inserter(Blocks)); } diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h index 44d789dcf22..0168bf26244 100644 --- a/include/llvm/ADT/STLExtras.h +++ b/include/llvm/ADT/STLExtras.h @@ -36,7 +36,7 @@ // arguments to get a boolean result. // template -struct bitwise_or : public binary_function { +struct bitwise_or : public std::binary_function { bool operator()(const Ty& left, const Ty& right) const { return left | right; } @@ -70,9 +70,9 @@ class mapped_iterator { RootIt current; UnaryFunc Fn; public: - typedef typename iterator_traits::iterator_category + typedef typename std::iterator_traits::iterator_category iterator_category; - typedef typename iterator_traits::difference_type + typedef typename std::iterator_traits::difference_type difference_type; typedef typename UnaryFunc::result_type value_type; typedef typename UnaryFunc::result_type *pointer; @@ -102,6 +102,7 @@ public: _Self& operator-= (difference_type n) { current -= n; return *this; } reference operator[](difference_type n) const { return *(*this + n); } + inline bool operator!=(const _Self &X) const { return !operator==(X); } inline bool operator==(const _Self &X) const { return current == X.current; } inline bool operator< (const _Self &X) const { return current < X.current; } diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h index e67e25ced51..46e2c5aaf0b 100644 --- a/include/llvm/ADT/StringExtras.h +++ b/include/llvm/ADT/StringExtras.h @@ -11,7 +11,7 @@ #include #include -static inline string utostr(uint64_t X, bool isNeg = false) { +static inline std::string utostr(uint64_t X, bool isNeg = false) { char Buffer[40]; char *BufPtr = Buffer+39; @@ -25,10 +25,10 @@ static inline string utostr(uint64_t X, bool isNeg = false) { if (isNeg) *--BufPtr = '-'; // Add negative sign... - return string(BufPtr); + return std::string(BufPtr); } -static inline string itostr(int64_t X) { +static inline std::string itostr(int64_t X) { if (X < 0) return utostr((uint64_t)-X, true); else @@ -36,7 +36,7 @@ static inline string itostr(int64_t X) { } -static inline string utostr(unsigned X, bool isNeg = false) { +static inline std::string utostr(unsigned X, bool isNeg = false) { char Buffer[20]; char *BufPtr = Buffer+19; @@ -50,17 +50,17 @@ static inline string utostr(unsigned X, bool isNeg = false) { if (isNeg) *--BufPtr = '-'; // Add negative sign... - return string(BufPtr); + return std::string(BufPtr); } -static inline string itostr(int X) { +static inline std::string itostr(int X) { if (X < 0) return utostr((unsigned)-X, true); else return utostr((unsigned)X); } -static inline string ftostr(double V) { +static inline std::string ftostr(double V) { char Buffer[200]; snprintf(Buffer, 200, "%e", V); return Buffer; diff --git a/include/llvm/ADT/Tree.h b/include/llvm/ADT/Tree.h index 33b0bb7b039..9e8d5ae7efa 100644 --- a/include/llvm/ADT/Tree.h +++ b/include/llvm/ADT/Tree.h @@ -12,21 +12,21 @@ template class Tree { - vector Children; // This nodes children, if any - ConcreteTreeNode *Parent; // Parent of this node... - Payload Data; // Data held in this node... + std::vector Children; // This nodes children, if any + ConcreteTreeNode *Parent; // Parent of this node... + Payload Data; // Data held in this node... protected: - void setChildren(const vector &children) { + void setChildren(const std::vector &children) { Children = children; } public: inline Tree(ConcreteTreeNode *parent) : Parent(parent) {} - inline Tree(const vector &children, ConcreteTreeNode *par) - : Children(children), Parent(par) {} + inline Tree(const std::vector &children, + ConcreteTreeNode *par) : Children(children), Parent(par) {} - inline Tree(const vector &children, ConcreteTreeNode *par, - const Payload &data) + inline Tree(const std::vector &children, + ConcreteTreeNode *par, const Payload &data) : Children(children), Parent(parent), Data(data) {} // Tree dtor - Free all children diff --git a/include/llvm/Analysis/CallGraph.h b/include/llvm/Analysis/CallGraph.h index 8365a4f397c..f5b020269cc 100644 --- a/include/llvm/Analysis/CallGraph.h +++ b/include/llvm/Analysis/CallGraph.h @@ -27,12 +27,12 @@ namespace cfg { class CallGraph; class CallGraphNode { Method *Meth; - vector CalledMethods; + std::vector CalledMethods; CallGraphNode(const CallGraphNode &); // Do not implement public: - typedef vector::iterator iterator; - typedef vector::const_iterator const_iterator; + typedef std::vector::iterator iterator; + typedef std::vector::const_iterator const_iterator; // getMethod - Return the method that this call graph node represents... Method *getMethod() const { return Meth; } @@ -65,7 +65,7 @@ private: // Stuff to construct the node, used by CallGraph class CallGraph { Module *Mod; // The module this call graph represents - typedef map MethodMapTy; + typedef std::map MethodMapTy; MethodMapTy MethodMap; // Map from a method to its node CallGraphNode *Root; diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h index 6639b64a055..c018eafe2ce 100644 --- a/include/llvm/Analysis/Dominators.h +++ b/include/llvm/Analysis/Dominators.h @@ -47,8 +47,9 @@ public: // class DominatorSet : public DominatorBase { public: - typedef set DomSetType; // Dom set for a bb - typedef map DomSetMapType; // Map of dom sets + typedef std::set DomSetType; // Dom set for a bb + // Map of dom sets + typedef std::map DomSetMapType; private: DomSetMapType Doms; @@ -91,7 +92,7 @@ public: // method. // class ImmediateDominators : public DominatorBase { - map IDoms; + std::map IDoms; void calcIDoms(const DominatorSet &DS); public: @@ -104,7 +105,7 @@ public: } // Accessor interface: - typedef map IDomMapType; + typedef std::map IDomMapType; typedef IDomMapType::const_iterator const_iterator; inline const_iterator begin() const { return IDoms.begin(); } inline const_iterator end() const { return IDoms.end(); } @@ -114,7 +115,7 @@ public: // node returns null, because it does not have an immediate dominator. // inline const BasicBlock *operator[](const BasicBlock *BB) const { - map::const_iterator I = + std::map::const_iterator I = IDoms.find(BB); return I != IDoms.end() ? I->second : 0; } @@ -130,18 +131,18 @@ class DominatorTree : public DominatorBase { public: typedef Node2 Node; private: - map Nodes; + std::map Nodes; void calculate(const DominatorSet &DS); - typedef map NodeMapType; + typedef std::map NodeMapType; public: - class Node2 : public vector { + class Node2 : public std::vector { friend class DominatorTree; const BasicBlock *TheNode; Node2 * const IDom; public: inline const BasicBlock *getNode() const { return TheNode; } inline Node2 *getIDom() const { return IDom; } - inline const vector &getChildren() const { return *this; } + inline const std::vector &getChildren() const { return *this; } // dominates - Returns true iff this dominates N. Note that this is not a // constant time operation! @@ -181,8 +182,8 @@ public: // class DominanceFrontier : public DominatorBase { public: - typedef set DomSetType; // Dom set for a bb - typedef map DomSetMapType; // Map of dom sets + typedef std::set DomSetType; // Dom set for a bb + typedef std::map DomSetMapType; // Dom set map private: DomSetMapType Frontiers; const DomSetType &calcDomFrontier(const DominatorTree &DT, diff --git a/include/llvm/Analysis/FindUnsafePointerTypes.h b/include/llvm/Analysis/FindUnsafePointerTypes.h index 3f66f3308b4..c52ca2fbbb5 100644 --- a/include/llvm/Analysis/FindUnsafePointerTypes.h +++ b/include/llvm/Analysis/FindUnsafePointerTypes.h @@ -24,11 +24,11 @@ class PointerType; struct FindUnsafePointerTypes : public Pass { // UnsafeTypes - Set of types that are not safe to transform. - set UnsafeTypes; + std::set UnsafeTypes; public: // Accessor for underlying type set... - inline const set &getUnsafeTypes() const { + inline const std::set &getUnsafeTypes() const { return UnsafeTypes; } @@ -41,7 +41,7 @@ public: // printResults - Loop over the results of the analysis, printing out unsafe // types. // - void printResults(const Module *Mod, ostream &o); + void printResults(const Module *Mod, std::ostream &o); }; #endif diff --git a/include/llvm/Analysis/FindUsedTypes.h b/include/llvm/Analysis/FindUsedTypes.h index aa00e5f8a83..956901dfaa2 100644 --- a/include/llvm/Analysis/FindUsedTypes.h +++ b/include/llvm/Analysis/FindUsedTypes.h @@ -12,7 +12,7 @@ class SymbolTable; class FindUsedTypes : public Pass { - set UsedTypes; + std::set UsedTypes; bool IncludeSymbolTables; public: @@ -25,13 +25,13 @@ public: // getTypes - After the pass has been run, return the set containing all of // the types used in the module. // - inline const set &getTypes() const { return UsedTypes; } + inline const std::set &getTypes() const { return UsedTypes; } // Print the types found in the module. If the optional Module parameter is // passed in, then the types are printed symbolically if possible, using the // symbol table from the module. // - void printTypes(ostream &o, const Module *M = 0) const; + void printTypes(std::ostream &o, const Module *M = 0) const; private: // IncorporateType - Incorporate one type and all of its subtypes into the diff --git a/include/llvm/Analysis/InstForest.h b/include/llvm/Analysis/InstForest.h index e8ab0aae08a..13eb54fa52c 100644 --- a/include/llvm/Analysis/InstForest.h +++ b/include/llvm/Analysis/InstForest.h @@ -35,10 +35,12 @@ template class InstForest; // template class InstTreeNode : - public Tree, pair, Payload> > { + public Tree, + std::pair, Payload> > { friend class InstForest; - typedef Tree, pair, Payload> > super; + typedef Tree, + std::pair, Payload> > super; // Constants used for the node type value enum NodeTypeTy { @@ -104,15 +106,15 @@ public: public: // print - Called by operator<< below... - void print(ostream &o, unsigned Indent) const { - o << string(Indent*2, ' '); + void print(std::ostream &o, unsigned Indent) const { + o << std::string(Indent*2, ' '); switch (getNodeType()) { case ConstNode : o << "Constant : "; break; - case BasicBlockNode : o << "BasicBlock : " << getValue()->getName() << endl; + case BasicBlockNode : o << "BasicBlock : " << getValue()->getName() << "\n"; return; case InstructionNode: o << "Instruction: "; break; case TemporaryNode : o << "Temporary : "; break; - default: o << "UNKNOWN NODE TYPE: " << getNodeType() << endl; abort(); + default: o << "UNKNOWN NODE TYPE: " << getNodeType() << "\n"; abort(); } o << getValue(); @@ -124,7 +126,8 @@ public: }; template -inline ostream &operator<<(ostream &o, const InstTreeNode *N) { +inline std::ostream &operator<<(std::ostream &o, + const InstTreeNode *N) { N->print(o, 0); return o; } @@ -137,16 +140,16 @@ inline ostream &operator<<(ostream &o, const InstTreeNode *N) { // guaranteed to be an instruction node. The constructor builds the forest. // template -class InstForest : public vector *> { +class InstForest : public std::vector *> { friend class InstTreeNode; // InstMap - Map contains entries for ALL instructions in the method and the // InstTreeNode that they correspond to. // - map *> InstMap; + std::map *> InstMap; void addInstMapping(Instruction *I, InstTreeNode *IN) { - InstMap.insert(make_pair(I, IN)); + InstMap.insert(std::make_pair(I, IN)); } void removeInstFromRootList(Instruction *I) { @@ -180,26 +183,27 @@ public: // the parent pointer can be used to find the root of the tree. // inline InstTreeNode *getInstNode(Instruction *Inst) { - map *>::iterator I = InstMap.find(Inst); + std::map *>::iterator I = + InstMap.find(Inst); if (I != InstMap.end()) return I->second; return 0; } inline const InstTreeNode *getInstNode(const Instruction *Inst)const{ - map*>::const_iterator I = + std::map*>::const_iterator I = InstMap.find(Inst); if (I != InstMap.end()) return I->second; return 0; } // print - Called by operator<< below... - void print(ostream &out) const { + void print(std::ostream &out) const { for (const_iterator I = begin(), E = end(); I != E; ++I) out << *I; } }; template -inline ostream &operator<<(ostream &o, const InstForest &IF) { +inline std::ostream &operator<<(std::ostream &o, const InstForest &IF){ IF.print(o); return o; } @@ -254,7 +258,7 @@ InstTreeNode::InstTreeNode(InstForest &IF, Value *V, // Otherwise, we are an internal instruction node. We must process our // uses and add them as children of this node. // - vector Children; + std::vector Children; // Make sure that the forest knows about us! IF.addInstMapping(I, this); diff --git a/include/llvm/Analysis/Interval.h b/include/llvm/Analysis/Interval.h index db9d67c15ab..18f3a88c7e9 100644 --- a/include/llvm/Analysis/Interval.h +++ b/include/llvm/Analysis/Interval.h @@ -31,9 +31,9 @@ class Interval { // BasicBlock *HeaderNode; public: - typedef vector::iterator succ_iterator; - typedef vector::iterator pred_iterator; - typedef vector::iterator node_iterator; + typedef std::vector::iterator succ_iterator; + typedef std::vector::iterator pred_iterator; + typedef std::vector::iterator node_iterator; inline Interval(BasicBlock *Header) : HeaderNode(Header) { Nodes.push_back(Header); @@ -46,18 +46,18 @@ public: // Nodes - The basic blocks in this interval. // - vector Nodes; + std::vector Nodes; // Successors - List of BasicBlocks that are reachable directly from nodes in // this interval, but are not in the interval themselves. // These nodes neccesarily must be header nodes for other intervals. // - vector Successors; + std::vector Successors; // Predecessors - List of BasicBlocks that have this Interval's header block // as one of their successors. // - vector Predecessors; + std::vector Predecessors; // contains - Find out if a basic block is in this interval inline bool contains(BasicBlock *BB) const { diff --git a/include/llvm/Analysis/IntervalIterator.h b/include/llvm/Analysis/IntervalIterator.h index 454c0ca07e3..52d2cc807d9 100644 --- a/include/llvm/Analysis/IntervalIterator.h +++ b/include/llvm/Analysis/IntervalIterator.h @@ -79,8 +79,8 @@ inline void addNodeToInterval(Interval *Int, Interval *I) { template class IntervalIterator { - stack > IntStack; - set Visited; + std::stack > IntStack; + std::set Visited; OrigContainer_t *OrigContainer; bool IOwnMem; // If True, delete intervals when done with them // See file header for conditions of use @@ -88,7 +88,7 @@ public: typedef BasicBlock* _BB; typedef IntervalIterator _Self; - typedef forward_iterator_tag iterator_category; + typedef std::forward_iterator_tag iterator_category; IntervalIterator() {} // End iterator, empty stack IntervalIterator(Method *M, bool OwnMemory) : IOwnMem(OwnMemory) { diff --git a/include/llvm/Analysis/IntervalPartition.h b/include/llvm/Analysis/IntervalPartition.h index 494ccd20976..f05408b0221 100644 --- a/include/llvm/Analysis/IntervalPartition.h +++ b/include/llvm/Analysis/IntervalPartition.h @@ -31,11 +31,11 @@ namespace cfg { // BasicBlock is a (possibly nonexistent) loop with a "tail" of non looping // nodes following it. // -class IntervalPartition : public vector { - typedef map IntervalMapTy; +class IntervalPartition : public std::vector { + typedef std::map IntervalMapTy; IntervalMapTy IntervalMap; - typedef vector IntervalListTy; + typedef std::vector IntervalListTy; Interval *RootInterval; public: diff --git a/include/llvm/Analysis/LiveVar/LiveVarMap.h b/include/llvm/Analysis/LiveVar/LiveVarMap.h index bc00d4f2815..44b3bbb7a41 100644 --- a/include/llvm/Analysis/LiveVar/LiveVarMap.h +++ b/include/llvm/Analysis/LiveVar/LiveVarMap.h @@ -12,7 +12,7 @@ #ifndef LIVE_VAR_MAP_H #define LIVE_VAR_MAP_H -#include +#include class BasicBlock; class BBLiveVar; @@ -34,11 +34,11 @@ struct hashFuncBB { // sturcture containing the hash function for BB -typedef hash_map BBToBBLiveVarMapType; +typedef std::hash_map BBToBBLiveVarMapType; -typedef hash_map MInstToLiveVarSetMapType; +typedef std::hash_map MInstToLiveVarSetMapType; #endif diff --git a/include/llvm/Analysis/LiveVar/LiveVarSet.h b/include/llvm/Analysis/LiveVar/LiveVarSet.h index 17524fccd32..d7761cfc205 100644 --- a/include/llvm/Analysis/LiveVar/LiveVarSet.h +++ b/include/llvm/Analysis/LiveVar/LiveVarSet.h @@ -8,7 +8,7 @@ #ifndef LIVE_VAR_SET_H #define LIVE_VAR_SET_H -#include "ValueSet.h" +#include "llvm/Analysis/LiveVar/ValueSet.h" #include "llvm/Instruction.h" #include "llvm/Type.h" diff --git a/include/llvm/Analysis/LiveVar/ValueSet.h b/include/llvm/Analysis/LiveVar/ValueSet.h index ee6aa15aaba..d17e0229a12 100644 --- a/include/llvm/Analysis/LiveVar/ValueSet.h +++ b/include/llvm/Analysis/LiveVar/ValueSet.h @@ -1,4 +1,4 @@ -/* Title: ValueSet.h +/* Title: ValueSet.h -*- C++ -*- Author: Ruchira Sasanka Date: Jun 30, 01 Purpose: Contains a mathematical set of Values. LiveVarSet is derived from @@ -8,24 +8,9 @@ #ifndef VALUE_SET_H #define VALUE_SET_H -#include - -#include -#include -//#include -#include - -#include "llvm/Value.h" - - -//------------------------ Support functions --------------------------------- - -struct hashFuncValue { // sturcture containing the hash func - inline size_t operator () (const Value *const val) const - { return (size_t) val; } -}; - - +class Value; +#include "Support/HashExtras.h" +#include //------------------- Class Definition for ValueSet -------------------------- @@ -33,12 +18,8 @@ void printValue( const Value *const v); // func to print a Value -class ValueSet : public hash_set -{ - +class ValueSet : public std::hash_set { public: - ValueSet(); // constructor - inline void add(const Value *const val) { assert( val ); insert(val);} // for adding a live variable to set diff --git a/include/llvm/Analysis/LoopDepth.h b/include/llvm/Analysis/LoopDepth.h index 76a590c31f2..89068d6bb79 100644 --- a/include/llvm/Analysis/LoopDepth.h +++ b/include/llvm/Analysis/LoopDepth.h @@ -14,14 +14,14 @@ class Method; namespace cfg {class Interval; } class LoopDepthCalculator { - map LoopDepth; + std::map LoopDepth; inline void AddBB(const BasicBlock *BB); // Increment count for this block inline void ProcessInterval(cfg::Interval *I); public: LoopDepthCalculator(Method *M); inline unsigned getLoopDepth(const BasicBlock *BB) const { - map::const_iterator I = LoopDepth.find(BB); + std::map::const_iterator I = LoopDepth.find(BB); return I != LoopDepth.end() ? I->second : 0; } }; diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 3a202265203..10fcfe9f300 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -25,8 +25,8 @@ namespace cfg { // class Loop { Loop *ParentLoop; - vector Blocks; // First entry is the header node - vector SubLoops; // Loops contained entirely within this one + std::vector Blocks; // First entry is the header node + std::vector SubLoops; // Loops contained entirely within this one unsigned LoopDepth; // Nesting depth of this loop Loop(const Loop &); // DO NOT IMPLEMENT @@ -40,8 +40,10 @@ public: bool contains(const BasicBlock *BB) const; // getSubLoops - Return the loops contained entirely within this loop - inline const vector &getSubLoops() const { return SubLoops; } - inline const vector &getBlocks() const { return Blocks; } + inline const std::vector &getSubLoops() const { return SubLoops; } + inline const std::vector &getBlocks() const { + return Blocks; + } private: friend class LoopInfo; @@ -62,19 +64,19 @@ private: // class LoopInfo { // BBMap - Mapping of basic blocks to the inner most loop they occur in - map BBMap; - vector TopLevelLoops; + std::map BBMap; + std::vector TopLevelLoops; public: // LoopInfo ctor - Calculate the natural loop information for a CFG LoopInfo(const DominatorSet &DS); - const vector &getTopLevelLoops() const { return TopLevelLoops; } + const std::vector &getTopLevelLoops() const { return TopLevelLoops; } // getLoopFor - Return the inner most loop that BB lives in. If a basic block // is in no loop (for example the entry node), null is returned. // const Loop *getLoopFor(const BasicBlock *BB) const { - map::const_iterator I = BBMap.find(BB); + std::map::const_iterator I = BBMap.find(BB); return I != BBMap.end() ? I->second : 0; } inline const Loop *operator[](const BasicBlock *BB) const { diff --git a/include/llvm/Analysis/ModuleAnalyzer.h b/include/llvm/Analysis/ModuleAnalyzer.h index a0baa8a7dde..8493becc640 100644 --- a/include/llvm/Analysis/ModuleAnalyzer.h +++ b/include/llvm/Analysis/ModuleAnalyzer.h @@ -78,7 +78,7 @@ protected: virtual bool processInstruction(const Instruction *I) { return false; } private: - bool handleType(set &TypeSet, const Type *T); + bool handleType(std::set &TypeSet, const Type *T); }; #endif diff --git a/include/llvm/Analysis/SlotCalculator.h b/include/llvm/Analysis/SlotCalculator.h index c7b3149054c..95282447a5f 100644 --- a/include/llvm/Analysis/SlotCalculator.h +++ b/include/llvm/Analysis/SlotCalculator.h @@ -23,14 +23,14 @@ class SlotCalculator { const Module *TheModule; bool IgnoreNamedNodes; // Shall we not count named nodes? - typedef vector TypePlane; - vector Table; - map NodeMap; + typedef std::vector TypePlane; + std::vector Table; + std::map NodeMap; // ModuleLevel - Used to keep track of which values belong to the module, // and which values belong to the currently incorporated method. // - vector ModuleLevel; + std::vector ModuleLevel; public: SlotCalculator(const Module *M, bool IgnoreNamed); diff --git a/include/llvm/Analysis/Verifier.h b/include/llvm/Analysis/Verifier.h index 2feadca7798..eb125396c5b 100644 --- a/include/llvm/Analysis/Verifier.h +++ b/include/llvm/Analysis/Verifier.h @@ -22,7 +22,7 @@ class Method; // error messages corresponding to the problem are added to the errorMsgs // vectors, and a value of true is returned. // -bool verify(const Module *M, vector &ErrorMsgs); -bool verify(const Method *M, vector &ErrorMsgs); +bool verify(const Module *M, std::vector &ErrorMsgs); +bool verify(const Method *M, std::vector &ErrorMsgs); #endif diff --git a/include/llvm/Analysis/Writer.h b/include/llvm/Analysis/Writer.h index 2b432318722..daaf65729e4 100644 --- a/include/llvm/Analysis/Writer.h +++ b/include/llvm/Analysis/Writer.h @@ -16,13 +16,14 @@ namespace cfg { class Interval; class IntervalPartition; - void WriteToOutput(const Interval *I, ostream &o); - inline ostream &operator <<(ostream &o, const Interval *I) { + void WriteToOutput(const Interval *I, std::ostream &o); + inline std::ostream &operator <<(std::ostream &o, const Interval *I) { WriteToOutput(I, o); return o; } - void WriteToOutput(const IntervalPartition &IP, ostream &o); - inline ostream &operator <<(ostream &o, const IntervalPartition &IP) { + void WriteToOutput(const IntervalPartition &IP, std::ostream &o); + inline std::ostream &operator <<(std::ostream &o, + const IntervalPartition &IP) { WriteToOutput(IP, o); return o; } @@ -32,23 +33,25 @@ namespace cfg { class DominatorTree; class DominanceFrontier; - void WriteToOutput(const DominatorSet &, ostream &o); - inline ostream &operator <<(ostream &o, const DominatorSet &DS) { + void WriteToOutput(const DominatorSet &, std::ostream &o); + inline std::ostream &operator <<(std::ostream &o, const DominatorSet &DS) { WriteToOutput(DS, o); return o; } - void WriteToOutput(const ImmediateDominators &, ostream &o); - inline ostream &operator <<(ostream &o, const ImmediateDominators &ID) { + void WriteToOutput(const ImmediateDominators &, std::ostream &o); + inline std::ostream &operator <<(std::ostream &o, + const ImmediateDominators &ID) { WriteToOutput(ID, o); return o; } - void WriteToOutput(const DominatorTree &, ostream &o); - inline ostream &operator <<(ostream &o, const DominatorTree &DT) { + void WriteToOutput(const DominatorTree &, std::ostream &o); + inline std::ostream &operator <<(std::ostream &o, const DominatorTree &DT) { WriteToOutput(DT, o); return o; } - void WriteToOutput(const DominanceFrontier &, ostream &o); - inline ostream &operator <<(ostream &o, const DominanceFrontier &DF) { + void WriteToOutput(const DominanceFrontier &, std::ostream &o); + inline std::ostream &operator <<(std::ostream &o, + const DominanceFrontier &DF) { WriteToOutput(DF, o); return o; } @@ -56,13 +59,13 @@ namespace cfg { class CallGraph; class CallGraphNode; - void WriteToOutput(const CallGraph &, ostream &o); - inline ostream &operator <<(ostream &o, const CallGraph &CG) { + void WriteToOutput(const CallGraph &, std::ostream &o); + inline std::ostream &operator <<(std::ostream &o, const CallGraph &CG) { WriteToOutput(CG, o); return o; } - void WriteToOutput(const CallGraphNode *, ostream &o); - inline ostream &operator <<(ostream &o, const CallGraphNode *CGN) { + void WriteToOutput(const CallGraphNode *, std::ostream &o); + inline std::ostream &operator <<(std::ostream &o, const CallGraphNode *CGN) { WriteToOutput(CGN, o); return o; } @@ -70,21 +73,21 @@ namespace cfg { class Loop; class LoopInfo; - void WriteToOutput(const LoopInfo &, ostream &o); - inline ostream &operator <<(ostream &o, const LoopInfo &LI) { + void WriteToOutput(const LoopInfo &, std::ostream &o); + inline std::ostream &operator <<(std::ostream &o, const LoopInfo &LI) { WriteToOutput(LI, o); return o; } - void WriteToOutput(const Loop *, ostream &o); - inline ostream &operator <<(ostream &o, const Loop *L) { + void WriteToOutput(const Loop *, std::ostream &o); + inline std::ostream &operator <<(std::ostream &o, const Loop *L) { WriteToOutput(L, o); return o; } } // End namespace CFG class InductionVariable; -void WriteToOutput(const InductionVariable &, ostream &o); -inline ostream &operator <<(ostream &o, const InductionVariable &IV) { +void WriteToOutput(const InductionVariable &, std::ostream &o); +inline std::ostream &operator <<(std::ostream &o, const InductionVariable &IV) { WriteToOutput(IV, o); return o; } diff --git a/include/llvm/Annotation.h b/include/llvm/Annotation.h index 99197326928..c0642e1d23d 100644 --- a/include/llvm/Annotation.h +++ b/include/llvm/Annotation.h @@ -166,12 +166,13 @@ struct AnnotationManager { //===--------------------------------------------------------------------===// // Basic ID <-> Name map functionality - static AnnotationID getID (const string &Name); // Name -> ID - static const string &getName(AnnotationID ID); // ID -> Name + static AnnotationID getID(const std::string &Name); // Name -> ID + static const std::string &getName(AnnotationID ID); // ID -> Name // getID - Name -> ID + registration of a factory function for demand driven // annotation support. - static AnnotationID getID (const string &Name, Factory Fact, void *Data=0); + static AnnotationID getID(const std::string &Name, Factory Fact, + void *Data = 0); //===--------------------------------------------------------------------===// // Annotation creation on demand support... diff --git a/include/llvm/Assembly/CachedWriter.h b/include/llvm/Assembly/CachedWriter.h index b5171b40976..cccf0377a4c 100644 --- a/include/llvm/Assembly/CachedWriter.h +++ b/include/llvm/Assembly/CachedWriter.h @@ -11,6 +11,7 @@ #define LLVM_ASSEMBLY_CACHED_WRITER_H #include "llvm/Assembly/Writer.h" +#include class AssemblyWriter; // Internal private class class SlotCalculator; @@ -19,10 +20,11 @@ class CachedWriter { AssemblyWriter *AW; SlotCalculator *SC; public: - ostream &Out; + std::ostream &Out; public: - CachedWriter(ostream &O = cout) : AW(0), SC(0), Out(O) { } - CachedWriter(const Module *M, ostream &O = cout) : AW(0), SC(0), Out(O) { + CachedWriter(std::ostream &O = std::cout) : AW(0), SC(0), Out(O) { } + CachedWriter(const Module *M, std::ostream &O = std::cout) + : AW(0), SC(0), Out(O) { setModule(M); } ~CachedWriter(); @@ -63,7 +65,7 @@ public: return *this << (const Value*)X; } - inline CachedWriter &operator<<(ostream &(&Manip)(ostream &)) { + inline CachedWriter &operator<<(std::ostream &(&Manip)(std::ostream &)) { Out << Manip; return *this; } diff --git a/include/llvm/Assembly/Parser.h b/include/llvm/Assembly/Parser.h index 011594d1322..02e5d4fbb68 100644 --- a/include/llvm/Assembly/Parser.h +++ b/include/llvm/Assembly/Parser.h @@ -16,7 +16,7 @@ class ParseException; // The useful interface defined by this file... Parse an ascii file, and return // the internal representation in a nice slice'n'dice'able representation. // -Module *ParseAssemblyFile(const string &Filename);// throw (ParseException); +Module *ParseAssemblyFile(const std::string &Filename);// throw (ParseException) //===------------------------------------------------------------------------=== // Helper Classes @@ -27,7 +27,7 @@ Module *ParseAssemblyFile(const string &Filename);// throw (ParseException); // class ParseException { public: - ParseException(const string &filename, const string &message, + ParseException(const std::string &filename, const std::string &message, int LineNo = -1, int ColNo = -1); ParseException(const ParseException &E); @@ -35,13 +35,13 @@ public: // getMessage - Return the message passed in at construction time plus extra // information extracted from the options used to parse with... // - const string getMessage() const; + const std::string getMessage() const; - inline const string getRawMessage() const { // Just the raw message... + inline const std::string &getRawMessage() const { // Just the raw message... return Message; } - inline const string &getFilename() const { + inline const std::string &getFilename() const { return Filename; } @@ -55,8 +55,8 @@ public: } private : - string Filename; - string Message; + std::string Filename; + std::string Message; int LineNo, ColumnNo; // -1 if not relevant ParseException &operator=(const ParseException &E); // objects by reference diff --git a/include/llvm/Assembly/PrintModulePass.h b/include/llvm/Assembly/PrintModulePass.h index a03b3492e62..72d8fabde04 100644 --- a/include/llvm/Assembly/PrintModulePass.h +++ b/include/llvm/Assembly/PrintModulePass.h @@ -10,14 +10,15 @@ #include "llvm/Pass.h" #include "llvm/Assembly/Writer.h" +#include class PrintModulePass : public Pass { - string Banner; // String to print before each method - ostream *Out; // ostream to print on + std::string Banner; // String to print before each method + std::ostream *Out; // ostream to print on bool DeleteStream; // Delete the ostream in our dtor? bool PrintPerMethod; // Print one method at a time rather than the whole? public: - inline PrintModulePass(const string &B, ostream *o = &cout, + inline PrintModulePass(const std::string &B, std::ostream *o = &std::cout, bool DS = false, bool printPerMethod = true) : Banner(B), Out(o), DeleteStream(DS), PrintPerMethod(printPerMethod) { diff --git a/include/llvm/Assembly/Writer.h b/include/llvm/Assembly/Writer.h index 02c9fd0cc1d..6ef33ad1b60 100644 --- a/include/llvm/Assembly/Writer.h +++ b/include/llvm/Assembly/Writer.h @@ -30,26 +30,26 @@ class SlotCalculator; // representation of an object into an ascii bytestream that the parser can // understand later... (the parser only understands whole classes though) // -void WriteToAssembly(const Module *Module, ostream &o); -void WriteToAssembly(const GlobalVariable *G, ostream &o); -void WriteToAssembly(const Method *Method, ostream &o); -void WriteToAssembly(const BasicBlock *BB, ostream &o); -void WriteToAssembly(const Instruction *In, ostream &o); -void WriteToAssembly(const Constant *V, ostream &o); +void WriteToAssembly(const Module *Module, std::ostream &o); +void WriteToAssembly(const GlobalVariable *G, std::ostream &o); +void WriteToAssembly(const Method *Method, std::ostream &o); +void WriteToAssembly(const BasicBlock *BB, std::ostream &o); +void WriteToAssembly(const Instruction *In, std::ostream &o); +void WriteToAssembly(const Constant *V, std::ostream &o); // WriteTypeSymbolic - This attempts to write the specified type as a symbolic // type, iff there is an entry in the modules symbol table for the specified // type or one of it's component types. This is slower than a simple x << Type; // -ostream &WriteTypeSymbolic(ostream &o, const Type *Ty, const Module *Module); +std::ostream &WriteTypeSymbolic(std::ostream &, const Type *, const Module *M); // WriteAsOperand - Write the name of the specified value out to the specified // ostream. This can be useful when you just want to print int %reg126, not the // whole instruction that generated it. // -ostream &WriteAsOperand(ostream &o, const Value *V, bool PrintType = true, - bool PrintName = true, SlotCalculator *Table = 0); +std::ostream &WriteAsOperand(std::ostream &, const Value *, bool PrintTy = true, + bool PrintName = true, SlotCalculator *Table = 0); // WriteToVCG - Dump the specified structure to a VCG file. If method is @@ -57,8 +57,8 @@ ostream &WriteAsOperand(ostream &o, const Value *V, bool PrintType = true, // family of files with a common base name is created, with a method name // suffix. // -void WriteToVCG(const Module *Module, const string &Filename); -void WriteToVCG(const Method *Method, const string &Filename); +void WriteToVCG(const Module *Module, const std::string &Filename); +void WriteToVCG(const Method *Method, const std::string &Filename); @@ -66,37 +66,37 @@ void WriteToVCG(const Method *Method, const string &Filename); // Define operator<< to work on the various classes that we can send to an // ostream... // -inline ostream &operator<<(ostream &o, const Module *C) { +inline std::ostream &operator<<(std::ostream &o, const Module *C) { WriteToAssembly(C, o); return o; } -inline ostream &operator<<(ostream &o, const GlobalVariable *G) { +inline std::ostream &operator<<(std::ostream &o, const GlobalVariable *G) { WriteToAssembly(G, o); return o; } -inline ostream &operator<<(ostream &o, const Method *M) { +inline std::ostream &operator<<(std::ostream &o, const Method *M) { WriteToAssembly(M, o); return o; } -inline ostream &operator<<(ostream &o, const BasicBlock *B) { +inline std::ostream &operator<<(std::ostream &o, const BasicBlock *B) { WriteToAssembly(B, o); return o; } -inline ostream &operator<<(ostream &o, const Instruction *I) { +inline std::ostream &operator<<(std::ostream &o, const Instruction *I) { WriteToAssembly(I, o); return o; } -inline ostream &operator<<(ostream &o, const Constant *I) { +inline std::ostream &operator<<(std::ostream &o, const Constant *I) { WriteToAssembly(I, o); return o; } -inline ostream &operator<<(ostream &o, const Type *T) { +inline std::ostream &operator<<(std::ostream &o, const Type *T) { if (!T) return o << ""; return o << T->getDescription(); } -inline ostream &operator<<(ostream &o, const Value *I) { +inline std::ostream &operator<<(std::ostream &o, const Value *I) { switch (I->getValueType()) { case Value::TypeVal: return o << cast(I); case Value::ConstantVal: WriteToAssembly(cast(I) , o); break; diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index 50de364f3ef..6770aa38aef 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -49,8 +49,8 @@ public: // Instruction iterators... typedef InstListType::iterator iterator; typedef InstListType::const_iterator const_iterator; - typedef reverse_iterator const_reverse_iterator; - typedef reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + typedef std::reverse_iterator reverse_iterator; // Predecessor and successor iterators... typedef PredIterator pred_iterator; @@ -61,11 +61,11 @@ public: const BasicBlock> succ_const_iterator; // Ctor, dtor - BasicBlock(const string &Name = "", Method *Parent = 0); + BasicBlock(const std::string &Name = "", Method *Parent = 0); ~BasicBlock(); // Specialize setName to take care of symbol table majik - virtual void setName(const string &name, SymbolTable *ST = 0); + virtual void setName(const std::string &name, SymbolTable *ST = 0); // getParent - Return the enclosing method, or null if none const Method *getParent() const { return InstList.getParent(); } diff --git a/include/llvm/Bytecode/Primitives.h b/include/llvm/Bytecode/Primitives.h index e0c25a15ca7..4058bd21ade 100644 --- a/include/llvm/Bytecode/Primitives.h +++ b/include/llvm/Bytecode/Primitives.h @@ -116,12 +116,12 @@ static inline bool align32(const unsigned char *&Buf, } static inline bool read(const unsigned char *&Buf, const unsigned char *EndBuf, - string &Result, bool Aligned = true) { + std::string &Result, bool Aligned = true) { unsigned Size; if (read_vbr(Buf, EndBuf, Size)) return true; // Failure reading size? if (Buf+Size > EndBuf) return true; // Size invalid? - Result = string((char*)Buf, Size); + Result = std::string((char*)Buf, Size); Buf += Size; if (Aligned) // If we should stay aligned do so... @@ -157,7 +157,8 @@ static inline bool input_data(const unsigned char *&Buf, // string... note that this should be inlined always so only the relevant IF // body should be included... // -static inline void output(unsigned i, deque &Out, int pos = -1){ +static inline void output(unsigned i, std::deque &Out, + int pos = -1) { #ifdef LITTLE_ENDIAN if (pos == -1) Out.insert(Out.end(), (unsigned char*)&i, (unsigned char*)&i+4); @@ -178,7 +179,7 @@ static inline void output(unsigned i, deque &Out, int pos = -1){ #endif } -static inline void output(int i, deque &Out) { +static inline void output(int i, std::deque &Out) { output((unsigned)i, Out); } @@ -191,7 +192,7 @@ static inline void output(int i, deque &Out) { // // Note that using this may cause the output buffer to become unaligned... // -static inline void output_vbr(uint64_t i, deque &out) { +static inline void output_vbr(uint64_t i, std::deque &out) { while (1) { if (i < 0x80) { // done? out.push_back((unsigned char)i); // We know the high bit is clear... @@ -205,7 +206,7 @@ static inline void output_vbr(uint64_t i, deque &out) { } } -static inline void output_vbr(unsigned i, deque &out) { +static inline void output_vbr(unsigned i, std::deque &out) { while (1) { if (i < 0x80) { // done? out.push_back((unsigned char)i); // We know the high bit is clear... @@ -219,7 +220,7 @@ static inline void output_vbr(unsigned i, deque &out) { } } -static inline void output_vbr(int64_t i, deque &out) { +static inline void output_vbr(int64_t i, std::deque &out) { if (i < 0) output_vbr(((uint64_t)(-i) << 1) | 1, out); // Set low order sign bit... else @@ -227,7 +228,7 @@ static inline void output_vbr(int64_t i, deque &out) { } -static inline void output_vbr(int i, deque &out) { +static inline void output_vbr(int i, std::deque &out) { if (i < 0) output_vbr(((unsigned)(-i) << 1) | 1, out); // Set low order sign bit... else @@ -237,12 +238,12 @@ static inline void output_vbr(int i, deque &out) { // align32 - emit the minimal number of bytes that will bring us to 32 bit // alignment... // -static inline void align32(deque &Out) { +static inline void align32(std::deque &Out) { int NumPads = (4-(Out.size() & 3)) & 3; // Bytes to get padding to 32 bits while (NumPads--) Out.push_back((unsigned char)0xAB); } -static inline void output(const string &s, deque &Out, +static inline void output(const std::string &s, std::deque &Out, bool Aligned = true) { unsigned Len = s.length(); output_vbr(Len, Out); // Strings may have an arbitrary length... @@ -253,7 +254,8 @@ static inline void output(const string &s, deque &Out, } static inline void output_data(void *Ptr, void *End, - deque &Out, bool Align = false) { + std::deque &Out, + bool Align = false) { #ifdef LITTLE_ENDIAN Out.insert(Out.end(), (unsigned char*)Ptr, (unsigned char*)End); #else diff --git a/include/llvm/Bytecode/Reader.h b/include/llvm/Bytecode/Reader.h index 2ef2532d4d5..7cd2365c98b 100644 --- a/include/llvm/Bytecode/Reader.h +++ b/include/llvm/Bytecode/Reader.h @@ -18,8 +18,9 @@ class Module; // Parse and return a class... // -Module *ParseBytecodeFile(const string &Filename, string *ErrorStr = 0); +Module *ParseBytecodeFile(const std::string &Filename, + std::string *ErrorStr = 0); Module *ParseBytecodeBuffer(const char *Buffer, unsigned BufferSize, - string *ErrorStr = 0); + std::string *ErrorStr = 0); #endif diff --git a/include/llvm/CodeGen/InstrForest.h b/include/llvm/CodeGen/InstrForest.h index aa101f934d8..0f614a6a9ff 100644 --- a/include/llvm/CodeGen/InstrForest.h +++ b/include/llvm/CodeGen/InstrForest.h @@ -27,8 +27,7 @@ #include "llvm/Instruction.h" #include "Support/NonCopyable.h" #include "Support/HashExtras.h" -#include -#include +#include class Constant; class BasicBlock; @@ -239,9 +238,9 @@ protected: // //------------------------------------------------------------------------ -class InstrForest : private hash_map { +class InstrForest : private std::hash_map { private: - hash_set treeRoots; + std::hash_set treeRoots; public: /*ctor*/ InstrForest (Method *M); @@ -251,7 +250,7 @@ public: return (*this)[instr]; } - inline const hash_set &getRootSet() const { + inline const std::hash_set &getRootSet() const { return treeRoots; } diff --git a/include/llvm/CodeGen/InstrSelection.h b/include/llvm/CodeGen/InstrSelection.h index 27e3ebe5531..287992a47cd 100644 --- a/include/llvm/CodeGen/InstrSelection.h +++ b/include/llvm/CodeGen/InstrSelection.h @@ -84,7 +84,8 @@ class TmpInstruction : public Instruction { public: // Constructor that uses the type of S1 as the type of the temporary. // s1 must be a valid value. s2 may be NULL. - TmpInstruction(OtherOps opcode, Value *s1, Value* s2, const string &name="") + TmpInstruction(OtherOps opcode, Value *s1, Value* s2, + const std::string &name = "") : Instruction(s1->getType(), opcode, name) { assert(s1 != NULL && "Use different constructor if both operands are 0"); @@ -94,7 +95,7 @@ public: // Constructor that allows the type of the temporary to be specified. // Both S1 and S2 may be NULL. TmpInstruction(OtherOps opcode, const Type* tmpType, - Value *s1, Value* s2, const string &name = "") + Value *s1, Value* s2, const std::string &name = "") : Instruction(tmpType, opcode, name) { Initialize(opcode, s1, s2); diff --git a/include/llvm/CodeGen/InstrSelectionSupport.h b/include/llvm/CodeGen/InstrSelectionSupport.h index 2cce1dc7542..33af635d8e8 100644 --- a/include/llvm/CodeGen/InstrSelectionSupport.h +++ b/include/llvm/CodeGen/InstrSelectionSupport.h @@ -24,8 +24,6 @@ class TmpInstruction; class Constant; class TargetMachine; -//************************ Exported Functions ******************************/ - //--------------------------------------------------------------------------- // Function GetConstantValueAsSignedInt @@ -54,7 +52,7 @@ int64_t GetConstantValueAsSignedInt (const Value *V, //--------------------------------------------------------------------------- Value* FoldGetElemChain (const InstructionNode* getElemInstrNode, - vector& chainIdxVec); + std::vector& chainIdxVec); //------------------------------------------------------------------------ @@ -130,11 +128,8 @@ MachineOperand::MachineOperandType // fall under case 3; these must be inserted before `minstr'. //--------------------------------------------------------------------------- -vector FixConstantOperandsForInstr (Instruction* vmInstr, - MachineInstr* minstr, - TargetMachine& target); - - -//**************************************************************************/ +std::vector FixConstantOperandsForInstr (Instruction* vmInstr, + MachineInstr* minstr, + TargetMachine& target); #endif diff --git a/include/llvm/CodeGen/InterferenceGraph.h b/include/llvm/CodeGen/InterferenceGraph.h index 99dea8fbe0a..408bee4558a 100644 --- a/include/llvm/CodeGen/InterferenceGraph.h +++ b/include/llvm/CodeGen/InterferenceGraph.h @@ -1,4 +1,4 @@ -/* Title: InterferenceGraph.h +/* Title: InterferenceGraph.h -*- C++ -*- Author: Ruchira Sasanka Date: July 20, 01 Purpose: Interference Graph used for register coloring. @@ -24,7 +24,7 @@ #include "llvm/CodeGen/IGNode.h" -typedef vector IGNodeListType; +typedef std::vector IGNodeListType; class InterferenceGraph @@ -47,6 +47,8 @@ class InterferenceGraph // to create it after adding all IGNodes to the IGNodeList InterferenceGraph(RegClass *const RC); + ~InterferenceGraph(); + void createGraph(); void addLRToIG(LiveRange *const LR); @@ -65,12 +67,6 @@ class InterferenceGraph void printIG() const; void printIGNodeList() const; - - ~InterferenceGraph(); - - }; - #endif - diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index d6b8ef71540..4c5dd1056c3 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -22,8 +22,6 @@ #include "llvm/Annotation.h" #include "llvm/Method.h" #include -#include -#include #include template class ValOpIterator; @@ -131,7 +129,7 @@ public: } public: - friend ostream& operator<<(ostream& os, const MachineOperand& mop); + friend std::ostream& operator<<(std::ostream& os, const MachineOperand& mop); private: @@ -262,9 +260,9 @@ class MachineInstr : public NonCopyable { private: MachineOpCode opCode; OpCodeMask opCodeMask; // extra bits for variants of an opcode - vector operands; - vector implicitRefs; // values implicitly referenced by this - vector implicitIsDef; // machine instruction (eg, call args) + std::vector operands; + std::vector implicitRefs; // values implicitly referenced by this + std::vector implicitIsDef; // machine instruction (eg, call args) public: typedef ValOpIterator val_const_op_iterator; @@ -306,9 +304,9 @@ public: public: - friend ostream& operator<<(ostream& os, const MachineInstr& minstr); - friend val_const_op_iterator; - friend val_op_iterator; + friend std::ostream& operator<<(std::ostream& os, const MachineInstr& minstr); + friend class val_const_op_iterator; + friend class val_op_iterator; public: // Access to set the operands when building the machine instruction @@ -449,17 +447,17 @@ public: // //--------------------------------------------------------------------------- -class MachineCodeForVMInstr: public vector +class MachineCodeForVMInstr: public std::vector { private: - vector tempVec; // used by m/c instr but not VM instr + std::vector tempVec; // used by m/c instr but not VM instr public: /*ctor*/ MachineCodeForVMInstr () {} /*ctor*/ ~MachineCodeForVMInstr (); - const vector& getTempValues () const { return tempVec; } - vector& getTempValues () { return tempVec; } + const std::vector& getTempValues () const { return tempVec; } + std::vector& getTempValues () { return tempVec; } void addTempValue (Value* val) { tempVec.push_back(val); } @@ -499,10 +497,10 @@ MachineCodeForVMInstr::~MachineCodeForVMInstr() //--------------------------------------------------------------------------- -class MachineCodeForBasicBlock: public vector { +class MachineCodeForBasicBlock: public std::vector { public: - typedef vector::iterator iterator; - typedef vector::const_iterator const_iterator; + typedef std::vector::iterator iterator; + typedef std::vector::const_iterator const_iterator; }; @@ -529,8 +527,8 @@ private: unsigned currentOptionalArgsSize; unsigned maxOptionalArgsSize; unsigned currentTmpValuesSize; - hash_set constantsForConstPool; - hash_map offsets; + std::hash_set constantsForConstPool; + std::hash_map offsets; // hash_map offsetsFromSP; public: @@ -572,7 +570,7 @@ public: inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;} inline unsigned getCurrentOptionalArgsSize() const { return currentOptionalArgsSize;} - inline const hash_set& + inline const std::hash_set& getConstantPoolValues() const {return constantsForConstPool;} // @@ -628,10 +626,10 @@ private: //--------------------------------------------------------------------------- -ostream& operator<< (ostream& os, const MachineInstr& minstr); +std::ostream& operator<< (std::ostream& os, const MachineInstr& minstr); -ostream& operator<< (ostream& os, const MachineOperand& mop); +std::ostream& operator<< (std::ostream& os, const MachineOperand& mop); void PrintMachineInstructions(const Method *method); diff --git a/include/llvm/CodeGen/RegClass.h b/include/llvm/CodeGen/RegClass.h index d6cbaf892bb..fe25986f408 100644 --- a/include/llvm/CodeGen/RegClass.h +++ b/include/llvm/CodeGen/RegClass.h @@ -13,8 +13,9 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/MachineRegInfo.h" #include +#include -typedef vector ReservedColorListType; +typedef std::vector ReservedColorListType; //----------------------------------------------------------------------------- @@ -46,7 +47,7 @@ class RegClass InterferenceGraph IG; // Interference graph - constructed by // buildInterferenceGraph - stack IGNodeStack; // the stack used for coloring + std::stack IGNodeStack; // the stack used for coloring const ReservedColorListType *const ReservedColorList; // @@ -117,21 +118,14 @@ class RegClass inline void printIGNodeList() const { - cerr << "IG Nodes for Register Class " << RegClassID << ":" << endl; + std::cerr << "IG Nodes for Register Class " << RegClassID << ":" << "\n"; IG.printIGNodeList(); } inline void printIG() { - cerr << "IG for Register Class " << RegClassID << ":" << endl; + std::cerr << "IG for Register Class " << RegClassID << ":" << "\n"; IG.printIG(); } - }; - - - - - - #endif diff --git a/include/llvm/CodeGen/ValueSet.h b/include/llvm/CodeGen/ValueSet.h index ee6aa15aaba..d17e0229a12 100644 --- a/include/llvm/CodeGen/ValueSet.h +++ b/include/llvm/CodeGen/ValueSet.h @@ -1,4 +1,4 @@ -/* Title: ValueSet.h +/* Title: ValueSet.h -*- C++ -*- Author: Ruchira Sasanka Date: Jun 30, 01 Purpose: Contains a mathematical set of Values. LiveVarSet is derived from @@ -8,24 +8,9 @@ #ifndef VALUE_SET_H #define VALUE_SET_H -#include - -#include -#include -//#include -#include - -#include "llvm/Value.h" - - -//------------------------ Support functions --------------------------------- - -struct hashFuncValue { // sturcture containing the hash func - inline size_t operator () (const Value *const val) const - { return (size_t) val; } -}; - - +class Value; +#include "Support/HashExtras.h" +#include //------------------- Class Definition for ValueSet -------------------------- @@ -33,12 +18,8 @@ void printValue( const Value *const v); // func to print a Value -class ValueSet : public hash_set -{ - +class ValueSet : public std::hash_set { public: - ValueSet(); // constructor - inline void add(const Value *const val) { assert( val ); insert(val);} // for adding a live variable to set diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 7ce2feced7b..1a4ebda6ec2 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -36,9 +36,9 @@ protected: void destroyConstantImpl(); public: // Specialize setName to handle symbol table majik... - virtual void setName(const string &name, SymbolTable *ST = 0); + virtual void setName(const std::string &name, SymbolTable *ST = 0); - virtual string getStrValue() const = 0; + virtual std::string getStrValue() const = 0; // Static constructor to get a '0' constant of arbitrary type... static Constant *getNullConstant(const Type *Ty); @@ -78,7 +78,7 @@ public: // inverted - Return the opposite value of the current value. inline ConstantBool *inverted() const { return (this==True) ? False : True; } - virtual string getStrValue() const; + virtual std::string getStrValue() const; inline bool getValue() const { return Val; } // isNullValue - Return true if this is the value that would be returned by @@ -149,7 +149,7 @@ protected: public: static ConstantSInt *get(const Type *Ty, int64_t V); - virtual string getStrValue() const; + virtual std::string getStrValue() const; static bool isValueValidForType(const Type *Ty, int64_t V); inline int64_t getValue() const { return Val.Signed; } @@ -173,7 +173,7 @@ protected: public: static ConstantUInt *get(const Type *Ty, uint64_t V); - virtual string getStrValue() const; + virtual std::string getStrValue() const; static bool isValueValidForType(const Type *Ty, uint64_t V); inline uint64_t getValue() const { return Val.Unsigned; } @@ -199,7 +199,7 @@ protected: public: static ConstantFP *get(const Type *Ty, double V); - virtual string getStrValue() const; + virtual std::string getStrValue() const; static bool isValueValidForType(const Type *Ty, double V); inline double getValue() const { return Val; } @@ -223,20 +223,20 @@ public: class ConstantArray : public Constant { ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT protected: - ConstantArray(const ArrayType *T, const vector &Val); + ConstantArray(const ArrayType *T, const std::vector &Val); ~ConstantArray() {} virtual void destroyConstant(); public: - static ConstantArray *get(const ArrayType *T, const vector &); - static ConstantArray *get(const string &Initializer); + static ConstantArray *get(const ArrayType *T, const std::vector &); + static ConstantArray *get(const std::string &Initializer); - virtual string getStrValue() const; + virtual std::string getStrValue() const; inline const ArrayType *getType() const { return (ArrayType*)Value::getType(); } - inline const vector &getValues() const { return Operands; } + inline const std::vector &getValues() const { return Operands; } // isNullValue - Return true if this is the value that would be returned by // getNullConstant. @@ -257,20 +257,20 @@ public: class ConstantStruct : public Constant { ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT protected: - ConstantStruct(const StructType *T, const vector &Val); + ConstantStruct(const StructType *T, const std::vector &Val); ~ConstantStruct() {} virtual void destroyConstant(); public: static ConstantStruct *get(const StructType *T, - const vector &V); + const std::vector &V); - virtual string getStrValue() const; + virtual std::string getStrValue() const; inline const StructType *getType() const { return (StructType*)Value::getType(); } - inline const vector &getValues() const { return Operands; } + inline const std::vector &getValues() const { return Operands; } // isNullValue - Return true if this is the value that would be returned by // getNullConstant. @@ -297,7 +297,7 @@ protected: inline ConstantPointer(const PointerType *T) : Constant((const Type*)T){} ~ConstantPointer() {} public: - virtual string getStrValue() const = 0; + virtual std::string getStrValue() const = 0; inline const PointerType *getType() const { return (PointerType*)Value::getType(); } @@ -322,7 +322,7 @@ protected: inline ConstantPointerNull(const PointerType *T) : ConstantPointer(T) {} inline ~ConstantPointerNull() {} public: - virtual string getStrValue() const; + virtual std::string getStrValue() const; static ConstantPointerNull *get(const PointerType *T); @@ -359,7 +359,7 @@ protected: public: static ConstantPointerRef *get(GlobalValue *GV); - virtual string getStrValue() const; + virtual std::string getStrValue() const; const GlobalValue *getValue() const { return cast(Operands[0].get()); diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h index 4e69a8c0678..10ff57bd422 100644 --- a/include/llvm/DerivedTypes.h +++ b/include/llvm/DerivedTypes.h @@ -18,7 +18,7 @@ class DerivedType : public Type { // if I am a type, and I get resolved into a more concrete type. // ///// FIXME: kill mutable nonsense when Type's are not const - mutable vector AbstractTypeUsers; + mutable std::vector AbstractTypeUsers; char isRefining; // Used for recursive types @@ -94,7 +94,7 @@ public: class MethodType : public DerivedType { public: - typedef vector > ParamTypes; + typedef std::vector > ParamTypes; private: PATypeHandle ResultType; ParamTypes ParamTys; @@ -108,7 +108,7 @@ protected: // defines private constructors and has no friends // Private ctor - Only can be created by a static member... - MethodType(const Type *Result, const vector &Params, + MethodType(const Type *Result, const std::vector &Params, bool IsVarArgs); public: @@ -130,7 +130,8 @@ public: // virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy); - static MethodType *get(const Type *Result, const vector &Params, + static MethodType *get(const Type *Result, + const std::vector &Params, bool isVarArg); @@ -180,7 +181,7 @@ public: class StructType : public CompositeType { public: - typedef vector > ElementTypes; + typedef std::vector > ElementTypes; private: ElementTypes ETypes; // Element types of struct @@ -194,7 +195,7 @@ protected: // defines private constructors and has no friends // Private ctor - Only can be created by a static member... - StructType(const vector &Types); + StructType(const std::vector &Types); public: inline const ElementTypes &getElementTypes() const { return ETypes; } @@ -221,7 +222,7 @@ public: // virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy); - static StructType *get(const vector &Params); + static StructType *get(const std::vector &Params); // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const StructType *T) { return true; } diff --git a/include/llvm/Function.h b/include/llvm/Function.h index 9c026cc9a3d..93b9dc6d7ab 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -29,8 +29,8 @@ public: // BasicBlock iterators... typedef BasicBlocksType::iterator iterator; typedef BasicBlocksType::const_iterator const_iterator; - typedef reverse_iterator const_reverse_iterator; - typedef reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + typedef std::reverse_iterator reverse_iterator; private: @@ -42,11 +42,11 @@ private: void setParent(Module *parent); public: - Method(const MethodType *Ty, bool isInternal, const string &Name = ""); + Method(const MethodType *Ty, bool isInternal, const std::string &Name = ""); ~Method(); // Specialize setName to handle symbol table majik... - virtual void setName(const string &name, SymbolTable *ST = 0); + virtual void setName(const std::string &name, SymbolTable *ST = 0); const Type *getReturnType() const; // Return the return type of method const MethodType *getMethodType() const; // Return the MethodType for me @@ -129,11 +129,11 @@ public: _BB_i_t BB; // BasicBlocksType::iterator _BI_t BI; // BasicBlock::iterator public: - typedef bidirectional_iterator_tag iterator_category; - typedef IIty value_type; - typedef unsigned difference_type; - typedef BIty pointer; - typedef IIty reference; + typedef std::bidirectional_iterator_tag iterator_category; + typedef IIty value_type; + typedef unsigned difference_type; + typedef BIty pointer; + typedef IIty reference; template InstIterator(M &m) : BBs(m.getBasicBlocks()), BB(BBs.begin()) { // begin ctor diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h index d6a977bd372..1527940d796 100644 --- a/include/llvm/GlobalValue.h +++ b/include/llvm/GlobalValue.h @@ -17,7 +17,7 @@ class GlobalValue : public User { GlobalValue(const GlobalValue &); // do not implement protected: GlobalValue(const Type *Ty, ValueTy vty, bool hasInternalLinkage, - const string &name = "") + const std::string &name = "") : User(Ty, vty, name), HasInternalLinkage(hasInternalLinkage), Parent(0) {} bool HasInternalLinkage; // Is this value accessable externally? diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h index f46fa359cb6..9f10f719ef2 100644 --- a/include/llvm/GlobalVariable.h +++ b/include/llvm/GlobalVariable.h @@ -25,11 +25,11 @@ class GlobalVariable : public GlobalValue { bool isConstantGlobal; // Is this a global constant? public: GlobalVariable(const Type *Ty, bool isConstant, bool isInternal, - Constant *Initializer = 0, const string &Name = ""); + Constant *Initializer = 0, const std::string &Name = ""); ~GlobalVariable() {} // Specialize setName to handle symbol table majik... - virtual void setName(const string &name, SymbolTable *ST = 0); + virtual void setName(const std::string &name, SymbolTable *ST = 0); // The initializer for the global variable/constant is held by Operands[0] if // an initializer is specified. diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index 3d834e97a08..4aa612af70e 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -25,7 +25,7 @@ class TerminatorInst : public Instruction { public: TerminatorInst(Instruction::TermOps iType); TerminatorInst(const Type *Ty, Instruction::TermOps iType, - const string &Name = ""); + const std::string &Name = ""); inline ~TerminatorInst() {} // Terminators must implement the methods required by Instruction... @@ -66,7 +66,7 @@ public: // static UnaryOperator *create(UnaryOps Op, Value *Source); - UnaryOperator(Value *S, UnaryOps iType, const string &Name = "") + UnaryOperator(Value *S, UnaryOps iType, const std::string &Name = "") : Instruction(S->getType(), iType, Name) { Operands.reserve(1); Operands.push_back(Use(S, this)); @@ -105,10 +105,10 @@ public: // and the two operands. // static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2, - const string &Name = ""); + const std::string &Name = ""); BinaryOperator(BinaryOps iType, Value *S1, Value *S2, - const string &Name = "") + const std::string &Name = "") : Instruction(S1->getType(), iType, Name) { Operands.reserve(2); Operands.push_back(Use(S1, this)); diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index a7407ab3c82..efcecc93039 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -25,11 +25,11 @@ class Instruction : public User { protected: unsigned iType; // InstructionType public: - Instruction(const Type *Ty, unsigned iType, const string &Name = ""); + Instruction(const Type *Ty, unsigned iType, const std::string &Name = ""); virtual ~Instruction(); // Virtual dtor == good. // Specialize setName to handle symbol table majik... - virtual void setName(const string &name, SymbolTable *ST = 0); + virtual void setName(const std::string &name, SymbolTable *ST = 0); // clone() - Create a copy of 'this' instruction that is identical in all ways // except the following: diff --git a/include/llvm/Linker.h b/include/llvm/Linker.h index 3650ccbadfb..e74c5d40fae 100644 --- a/include/llvm/Linker.h +++ b/include/llvm/Linker.h @@ -16,7 +16,7 @@ class Module; // error occurs, true is returned and ErrorMsg (if not null) is set to indicate // the problem. // -bool LinkModules(Module *Dest, const Module *Src, string *ErrorMsg = 0); +bool LinkModules(Module *Dest, const Module *Src, std::string *ErrorMsg = 0); #endif diff --git a/include/llvm/Module.h b/include/llvm/Module.h index 92f137eb952..617840c809e 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -26,16 +26,16 @@ public: typedef ValueHolder MethodListType; // Global Variable iterators... - typedef GlobalListType::iterator giterator; - typedef GlobalListType::const_iterator const_giterator; - typedef reverse_iterator reverse_giterator; - typedef reverse_iterator const_reverse_giterator; + typedef GlobalListType::iterator giterator; + typedef GlobalListType::const_iterator const_giterator; + typedef std::reverse_iterator reverse_giterator; + typedef std::reverse_iterator const_reverse_giterator; // Method iterators... - typedef MethodListType::iterator iterator; - typedef MethodListType::const_iterator const_iterator; - typedef reverse_iterator const_reverse_iterator; - typedef reverse_iterator reverse_iterator; + typedef MethodListType::iterator iterator; + typedef MethodListType::const_iterator const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; private: GlobalListType GlobalList; // The Global Variables diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h index e357df0037a..c00092786e2 100644 --- a/include/llvm/Pass.h +++ b/include/llvm/Pass.h @@ -45,7 +45,7 @@ struct Pass { // // runAllPasses - Run a bunch of passes on the specified module, efficiently. - static bool runAllPasses(Module *M, vector &Passes) { + static bool runAllPasses(Module *M, std::vector &Passes) { bool MadeChanges = false; // Run all of the pass initializers for (unsigned i = 0; i < Passes.size(); ++i) @@ -65,7 +65,7 @@ struct Pass { // runAllPassesAndFree - Run a bunch of passes on the specified module, // efficiently. When done, delete all of the passes. // - static bool runAllPassesAndFree(Module *M, vector &Passes) { + static bool runAllPassesAndFree(Module *M, std::vector &Passes) { // First run all of the passes bool MadeChanges = runAllPasses(M, Passes); diff --git a/include/llvm/SlotCalculator.h b/include/llvm/SlotCalculator.h index c7b3149054c..95282447a5f 100644 --- a/include/llvm/SlotCalculator.h +++ b/include/llvm/SlotCalculator.h @@ -23,14 +23,14 @@ class SlotCalculator { const Module *TheModule; bool IgnoreNamedNodes; // Shall we not count named nodes? - typedef vector TypePlane; - vector Table; - map NodeMap; + typedef std::vector TypePlane; + std::vector Table; + std::map NodeMap; // ModuleLevel - Used to keep track of which values belong to the module, // and which values belong to the currently incorporated method. // - vector ModuleLevel; + std::vector ModuleLevel; public: SlotCalculator(const Module *M, bool IgnoreNamed); diff --git a/include/llvm/Support/Annotation.h b/include/llvm/Support/Annotation.h index 99197326928..c0642e1d23d 100644 --- a/include/llvm/Support/Annotation.h +++ b/include/llvm/Support/Annotation.h @@ -166,12 +166,13 @@ struct AnnotationManager { //===--------------------------------------------------------------------===// // Basic ID <-> Name map functionality - static AnnotationID getID (const string &Name); // Name -> ID - static const string &getName(AnnotationID ID); // ID -> Name + static AnnotationID getID(const std::string &Name); // Name -> ID + static const std::string &getName(AnnotationID ID); // ID -> Name // getID - Name -> ID + registration of a factory function for demand driven // annotation support. - static AnnotationID getID (const string &Name, Factory Fact, void *Data=0); + static AnnotationID getID(const std::string &Name, Factory Fact, + void *Data = 0); //===--------------------------------------------------------------------===// // Annotation creation on demand support... diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h index 84a3bc9b59d..3c0ac1ac693 100644 --- a/include/llvm/Support/CommandLine.h +++ b/include/llvm/Support/CommandLine.h @@ -100,7 +100,7 @@ class Option { // an argument. Should return true if there was an error processing the // argument and the program should exit. // - virtual bool handleOccurance(const char *ArgName, const string &Arg) = 0; + virtual bool handleOccurance(const char *ArgName, const std::string &Arg) = 0; virtual enum NumOccurances getNumOccurancesFlagDefault() const { return Optional; @@ -146,10 +146,10 @@ public: // addOccurance - Wrapper around handleOccurance that enforces Flags // - bool addOccurance(const char *ArgName, const string &Value); + bool addOccurance(const char *ArgName, const std::string &Value); // Prints option name followed by message. Always returns true. - bool error(string Message, const char *ArgName = 0); + bool error(std::string Message, const char *ArgName = 0); public: inline int getNumOccurances() const { return NumOccurances; } @@ -162,7 +162,7 @@ public: // class Alias : public Option { Option &AliasFor; - virtual bool handleOccurance(const char *ArgName, const string &Arg) { + virtual bool handleOccurance(const char *ArgName, const std::string &Arg) { return AliasFor.handleOccurance(AliasFor.ArgStr, Arg); } virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;} @@ -177,7 +177,7 @@ public: // class Flag : public Option { bool Value; - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); public: inline Flag(const char *ArgStr, const char *Message, int Flags = 0, bool DefaultVal = 0) : Option(ArgStr, Message, Flags), @@ -193,7 +193,7 @@ public: // class Int : public Option { int Value; - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); virtual enum ValueExpected getValueExpectedFlagDefault() const { return ValueRequired; } @@ -209,18 +209,18 @@ public: //===----------------------------------------------------------------------===// // String valued command line option // -class String : public Option, public string { - virtual bool handleOccurance(const char *ArgName, const string &Arg); +class String : public Option, public std::string { + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); virtual enum ValueExpected getValueExpectedFlagDefault() const { return ValueRequired; } public: inline String(const char *ArgStr, const char *Help, int Flags = 0, const char *DefaultVal = "") - : Option(ArgStr, Help, Flags), string(DefaultVal) {} + : Option(ArgStr, Help, Flags), std::string(DefaultVal) {} - inline const string &operator=(const string &Val) { - return string::operator=(Val); + inline const std::string &operator=(const std::string &Val) { + return std::string::operator=(Val); } }; @@ -228,7 +228,7 @@ public: //===----------------------------------------------------------------------===// // String list command line option // -class StringList : public Option, public vector { +class StringList : public Option, public std::vector { virtual enum NumOccurances getNumOccurancesFlagDefault() const { return ZeroOrMore; @@ -236,7 +236,7 @@ class StringList : public Option, public vector { virtual enum ValueExpected getValueExpectedFlagDefault() const { return ValueRequired; } - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); public: inline StringList(const char *ArgStr, const char *Help, int Flags = 0) @@ -256,7 +256,7 @@ protected: // Use a vector instead of a map, because the lists should be short, // the overhead is less, and most importantly, it keeps them in the order // inserted so we can print our option out nicely. - vector > > ValueMap; + std::vector > > ValueMap; inline EnumBase(const char *ArgStr, const char *Help, int Flags) : Option(ArgStr, Help, Flags) {} @@ -284,7 +284,7 @@ protected: inline EnumValueBase(int Flags) : EnumBase(Flags) {} // handleOccurance - Set Value to the enum value specified by Arg - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); // Return the width of the option tag for printing... virtual unsigned getOptionWidth() const; @@ -323,7 +323,7 @@ class EnumFlagsBase : public EnumValueBase { return ValueDisallowed; } protected: - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); inline EnumFlagsBase(int Flags) : EnumValueBase(Flags) {} // Return the width of the option tag for printing... @@ -363,11 +363,11 @@ class EnumListBase : public EnumBase { return ValueDisallowed; } protected: - vector Values; // The options specified so far. + std::vector Values; // The options specified so far. inline EnumListBase(int Flags) : EnumBase(Flags) {} - virtual bool handleOccurance(const char *ArgName, const string &Arg); + virtual bool handleOccurance(const char *ArgName, const std::string &Arg); // Return the width of the option tag for printing... virtual unsigned getOptionWidth() const; diff --git a/include/llvm/Support/Linker.h b/include/llvm/Support/Linker.h index 3650ccbadfb..e74c5d40fae 100644 --- a/include/llvm/Support/Linker.h +++ b/include/llvm/Support/Linker.h @@ -16,7 +16,7 @@ class Module; // error occurs, true is returned and ErrorMsg (if not null) is set to indicate // the problem. // -bool LinkModules(Module *Dest, const Module *Src, string *ErrorMsg = 0); +bool LinkModules(Module *Dest, const Module *Src, std::string *ErrorMsg = 0); #endif diff --git a/include/llvm/Support/NameMangling.h b/include/llvm/Support/NameMangling.h index 67e68c77380..8d33dcc4355 100644 --- a/include/llvm/Support/NameMangling.h +++ b/include/llvm/Support/NameMangling.h @@ -14,14 +14,14 @@ class Value; // MangleTypeName - Implement a consistent name-mangling scheme for // a given type. // -string MangleTypeName(const Type *type); +std::string MangleTypeName(const Type *type); // MangleName - implement a consistent name-mangling scheme for all // externally visible (i.e., global) objects. // // privateName should be unique within the module. // -string MangleName(const string &privateName, const Value *V); +std::string MangleName(const std::string &privateName, const Value *V); #endif diff --git a/include/llvm/SymbolTable.h b/include/llvm/SymbolTable.h index 243631161c4..e425e88d0d2 100644 --- a/include/llvm/SymbolTable.h +++ b/include/llvm/SymbolTable.h @@ -27,10 +27,11 @@ class Type; class SymbolTable : public AbstractTypeUser, - public map > { + public std::map > { public: - typedef map VarMap; - typedef map super; + typedef std::map VarMap; + typedef std::map super; private: SymbolTable *ParentSymTab; @@ -51,7 +52,7 @@ public: SymbolTable *getParentSymTab() { return ParentSymTab; } // lookup - Returns null on failure... - Value *lookup(const Type *Ty, const string &name); + Value *lookup(const Type *Ty, const std::string &name); // insert - Add named definition to the symbol table... inline void insert(Value *N) { @@ -63,7 +64,7 @@ public: // name... There can be a many to one mapping between names and // (constant/type)s. // - inline void insert(const string &Name, Value *V) { + inline void insert(const std::string &Name, Value *V) { assert((isa(V) || isa(V)) && "Can only insert types and constants here!"); insertEntry(Name, V->getType(), V); @@ -78,7 +79,7 @@ public: // it (or derived from it) that does not already occur in the symbol table for // the specified type. // - string getUniqueName(const Type *Ty, const string &BaseName); + std::string getUniqueName(const Type *Ty, const std::string &BaseName); inline unsigned type_size(const Type *TypeID) const { return find(TypeID)->second.size(); @@ -121,7 +122,7 @@ private: // insertEntry - Insert a value into the symbol table with the specified // name... // - void insertEntry(const string &Name, const Type *Ty, Value *V); + void insertEntry(const std::string &Name, const Type *Ty, Value *V); // removeEntry - Remove a value from the symbol table... // diff --git a/include/llvm/Target/MachineInstrInfo.h b/include/llvm/Target/MachineInstrInfo.h index 6b1804fd146..e2489f40450 100644 --- a/include/llvm/Target/MachineInstrInfo.h +++ b/include/llvm/Target/MachineInstrInfo.h @@ -59,11 +59,11 @@ const unsigned int M_PSEUDO_FLAG = 1 << 14; struct MachineInstrDescriptor { - string opCodeString; // Assembly language mnemonic for the opcode. - int numOperands; // Number of args; -1 if variable #args - int resultPos; // Position of the result; -1 if no result + std::string opCodeString; // Assembly language mnemonic for the opcode. + int numOperands; // Number of args; -1 if variable #args + int resultPos; // Position of the result; -1 if no result unsigned int maxImmedConst; // Largest +ve constant in IMMMED field or 0. - bool immedIsSignExtended; // Is IMMED field sign-extended? If so, + bool immedIsSignExtended; // Is IMMED field sign-extended? If so, // smallest -ve value is -(maxImmedConst+1). unsigned int numDelaySlots; // Number of delay slots after instruction unsigned int latency; // Latency in machine cycles @@ -246,8 +246,8 @@ public: // virtual void CreateCodeToLoadConst(Value* val, Instruction* dest, - vector& minstrVec, - vector& temps) const =0; + std::vector& minstrVec, + std::vector &) const = 0; // Create an instruction sequence to copy an integer value `val' // to a floating point value `dest' by copying to memory and back. @@ -258,8 +258,8 @@ public: virtual void CreateCodeToCopyIntToFloat(Method* method, Value* val, Instruction* dest, - vector& minstrVec, - vector& tempVec, + std::vector& minstVec, + std::vector& tmpVec, TargetMachine& target) const = 0; // Similarly, create an instruction sequence to copy an FP value @@ -269,8 +269,8 @@ public: virtual void CreateCodeToCopyFloatToInt(Method* method, Value* val, Instruction* dest, - vector& minstrVec, - vector& tempVec, + std::vector& minstVec, + std::vector& tmpVec, TargetMachine& target) const = 0; @@ -279,10 +279,7 @@ public: CreateCopyInstructionsByType(const TargetMachine& target, Value* src, Instruction* dest, - vector& minstrVec) const = 0; - - - + std::vector& minstrVec) const = 0; }; #endif diff --git a/include/llvm/Target/TargetCacheInfo.h b/include/llvm/Target/TargetCacheInfo.h index 21436d09fce..34194ec9970 100644 --- a/include/llvm/Target/TargetCacheInfo.h +++ b/include/llvm/Target/TargetCacheInfo.h @@ -28,9 +28,9 @@ public: protected: unsigned int numLevels; - vector cacheLineSizes; - vector cacheSizes; - vector cacheAssoc; + std::vector cacheLineSizes; + std::vector cacheSizes; + std::vector cacheAssoc; public: /*ctor*/ MachineCacheInfo (const TargetMachine& tgt); diff --git a/include/llvm/Target/TargetData.h b/include/llvm/Target/TargetData.h index edd6b26540f..2bce5f40b97 100644 --- a/include/llvm/Target/TargetData.h +++ b/include/llvm/Target/TargetData.h @@ -31,7 +31,7 @@ class TargetData { static Annotation *TypeAnFactory(AnnotationID, const Annotable *, void *); public: - TargetData(const string &TargetName, unsigned char PtrSize = 8, + TargetData(const std::string &TargetName, unsigned char PtrSize = 8, unsigned char PtrAl = 8, unsigned char DoubleAl = 8, unsigned char FloatAl = 4, unsigned char LongAl = 8, unsigned char IntAl = 4, unsigned char ShortAl = 2, @@ -61,7 +61,7 @@ public: // stores that include the implicit form of getelementptr. // unsigned getIndexedOffset(const Type *Ty, - const vector &Indices) const; + const std::vector &Indices) const; inline const StructLayout *getStructLayout(const StructType *Ty) const { return (const StructLayout*)((const Type*)Ty)->getOrCreateAnnotation(AID); @@ -73,7 +73,7 @@ public: // TargetData structure. // struct StructLayout : public Annotation { - vector MemberOffsets; + std::vector MemberOffsets; unsigned StructSize; unsigned StructAlignment; private: diff --git a/include/llvm/Target/TargetInstrInfo.h b/include/llvm/Target/TargetInstrInfo.h index 6b1804fd146..e2489f40450 100644 --- a/include/llvm/Target/TargetInstrInfo.h +++ b/include/llvm/Target/TargetInstrInfo.h @@ -59,11 +59,11 @@ const unsigned int M_PSEUDO_FLAG = 1 << 14; struct MachineInstrDescriptor { - string opCodeString; // Assembly language mnemonic for the opcode. - int numOperands; // Number of args; -1 if variable #args - int resultPos; // Position of the result; -1 if no result + std::string opCodeString; // Assembly language mnemonic for the opcode. + int numOperands; // Number of args; -1 if variable #args + int resultPos; // Position of the result; -1 if no result unsigned int maxImmedConst; // Largest +ve constant in IMMMED field or 0. - bool immedIsSignExtended; // Is IMMED field sign-extended? If so, + bool immedIsSignExtended; // Is IMMED field sign-extended? If so, // smallest -ve value is -(maxImmedConst+1). unsigned int numDelaySlots; // Number of delay slots after instruction unsigned int latency; // Latency in machine cycles @@ -246,8 +246,8 @@ public: // virtual void CreateCodeToLoadConst(Value* val, Instruction* dest, - vector& minstrVec, - vector& temps) const =0; + std::vector& minstrVec, + std::vector &) const = 0; // Create an instruction sequence to copy an integer value `val' // to a floating point value `dest' by copying to memory and back. @@ -258,8 +258,8 @@ public: virtual void CreateCodeToCopyIntToFloat(Method* method, Value* val, Instruction* dest, - vector& minstrVec, - vector& tempVec, + std::vector& minstVec, + std::vector& tmpVec, TargetMachine& target) const = 0; // Similarly, create an instruction sequence to copy an FP value @@ -269,8 +269,8 @@ public: virtual void CreateCodeToCopyFloatToInt(Method* method, Value* val, Instruction* dest, - vector& minstrVec, - vector& tempVec, + std::vector& minstVec, + std::vector& tmpVec, TargetMachine& target) const = 0; @@ -279,10 +279,7 @@ public: CreateCopyInstructionsByType(const TargetMachine& target, Value* src, Instruction* dest, - vector& minstrVec) const = 0; - - - + std::vector& minstrVec) const = 0; }; #endif diff --git a/include/llvm/Target/TargetMachine.h b/include/llvm/Target/TargetMachine.h index ad1f1059581..6effeedef58 100644 --- a/include/llvm/Target/TargetMachine.h +++ b/include/llvm/Target/TargetMachine.h @@ -38,14 +38,14 @@ typedef int OpCodeMask; class TargetMachine : public NonCopyableV { public: - const string TargetName; + const std::string TargetName; const TargetData DataLayout; // Calculates type size & alignment int optSizeForSubWordData; int minMemOpWordSize; int maxAtomicMemOpWordSize; protected: - TargetMachine(const string &targetname, // Can only create subclasses... + TargetMachine(const std::string &targetname, // Can only create subclasses... unsigned char PtrSize = 8, unsigned char PtrAl = 8, unsigned char DoubleAl = 8, unsigned char FloatAl = 4, unsigned char LongAl = 8, unsigned char IntAl = 4, @@ -86,7 +86,7 @@ public: // method. The specified method must have been compiled before this may be // used. // - virtual void emitAssembly(const Module *M, ostream &OutStr) const = 0; + virtual void emitAssembly(const Module *M, std::ostream &OutStr) const = 0; }; #endif diff --git a/include/llvm/Target/TargetRegInfo.h b/include/llvm/Target/TargetRegInfo.h index ae083c9b13f..b2fa0484922 100644 --- a/include/llvm/Target/TargetRegInfo.h +++ b/include/llvm/Target/TargetRegInfo.h @@ -9,7 +9,7 @@ #define LLVM_TARGET_MACHINEREGINFO_H #include "Support/NonCopyable.h" -#include +#include #include class TargetMachine; @@ -76,11 +76,11 @@ public: -typedef hash_map AddedInstrMapType; +typedef std::hash_map AddedInstrMapType; // A vector of all machine register classes // -typedef vector MachineRegClassArrayType; +typedef std::vector MachineRegClassArrayType; class MachineRegInfo : public NonCopyableV { @@ -128,7 +128,7 @@ public: LiveRangeInfo & LRI) const = 0; virtual void suggestRegs4CallArgs(const MachineInstr *const CallI, - LiveRangeInfo& LRI, vector RCL) const = 0; + LiveRangeInfo& LRI, std::vector RCL) const = 0; virtual void suggestReg4RetValue(const MachineInstr *const RetI, LiveRangeInfo& LRI) const = 0; @@ -186,7 +186,7 @@ public: // virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0; - virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0; + virtual const std::string getUnifiedRegName(int UnifiedRegNum) const = 0; // Gives the type of a register based on the type of the LR diff --git a/include/llvm/Target/TargetSchedInfo.h b/include/llvm/Target/TargetSchedInfo.h index 356c7851b03..e8908c532a4 100644 --- a/include/llvm/Target/TargetSchedInfo.h +++ b/include/llvm/Target/TargetSchedInfo.h @@ -8,10 +8,10 @@ #define LLVM_TARGET_MACHINESCHEDINFO_H #include "llvm/Target/MachineInstrInfo.h" -#include +#include typedef long long cycles_t; -const cycles_t HUGE_LATENCY = ~((unsigned long long) 1 << sizeof(cycles_t)-1); +const cycles_t HUGE_LATENCY = ~((unsigned long long) 1 << sizeof(cycles_t)-2); const cycles_t INVALID_LATENCY = -HUGE_LATENCY; static const unsigned MAX_OPCODE_SIZE = 16; @@ -28,13 +28,13 @@ private: OpCodePair(); // disable for now }; - +namespace std { template <> struct hash { size_t operator()(const OpCodePair& pair) const { return hash()(pair.val); } }; - +} //--------------------------------------------------------------------------- // class MachineResource @@ -50,10 +50,10 @@ typedef unsigned int resourceId_t; class MachineResource { public: - const string rname; + const std::string rname; resourceId_t rid; - /*ctor*/ MachineResource(const string& resourceName) + /*ctor*/ MachineResource(const std::string& resourceName) : rname(resourceName), rid(nextId++) {} private: @@ -66,7 +66,7 @@ class CPUResource : public MachineResource { public: int maxNumUsers; // MAXINT if no restriction - /*ctor*/ CPUResource(const string& rname, int maxUsers) + /*ctor*/ CPUResource(const std::string& rname, int maxUsers) : MachineResource(rname), maxNumUsers(maxUsers) {} }; @@ -147,11 +147,11 @@ struct InstrRUsage { cycles_t numBubbles; // Feasible slots to use for this instruction. - vector feasibleSlots; + std::vector feasibleSlots; // Resource usages for this instruction, with one resource vector per cycle. cycles_t numCycles; - vector > resourcesByCycle; + std::vector > resourcesByCycle; private: // Conveniences for initializing this structure @@ -243,7 +243,7 @@ InstrRUsage::addUsageDelta(const InstrRUsageDelta& delta) // resize the resources vector if more cycles are specified unsigned maxCycles = this->numCycles; - maxCycles = max(maxCycles, delta.startCycle + abs(NC) - 1); + maxCycles = std::max(maxCycles, delta.startCycle + abs(NC) - 1); if (maxCycles > this->numCycles) { this->resourcesByCycle.resize(maxCycles); @@ -259,7 +259,7 @@ InstrRUsage::addUsageDelta(const InstrRUsageDelta& delta) { // Look for the resource backwards so we remove the last entry // for that resource in each cycle. - vector& rvec = this->resourcesByCycle[c]; + std::vector& rvec = this->resourcesByCycle[c]; int r; for (r = (int) rvec.size(); r >= 0; r--) if (rvec[r] == delta.resourceId) @@ -349,14 +349,14 @@ public: inline int getMinIssueGap (MachineOpCode fromOp, MachineOpCode toOp) const { - hash_map::const_iterator + std::hash_map::const_iterator I = issueGaps.find(OpCodePair(fromOp, toOp)); return (I == issueGaps.end())? 0 : (*I).second; } - inline const vector* + inline const std::vector* getConflictList(MachineOpCode opCode) const { - hash_map >::const_iterator + std::hash_map >::const_iterator I = conflictLists.find(opCode); return (I == conflictLists.end())? NULL : & (*I).second; } @@ -377,22 +377,22 @@ protected: virtual void initializeResources (); private: - void computeInstrResources(const vector& instrRUForClasses); - void computeIssueGaps(const vector& instrRUForClasses); + void computeInstrResources(const std::vector& instrRUForClasses); + void computeIssueGaps(const std::vector& instrRUForClasses); protected: int numSchedClasses; const MachineInstrInfo* mii; - const InstrClassRUsage* classRUsages; // raw array by sclass - const InstrRUsageDelta* usageDeltas; // raw array [1:numUsageDeltas] - const InstrIssueDelta* issueDeltas; // raw array [1:numIssueDeltas] + const InstrClassRUsage* classRUsages; // raw array by sclass + const InstrRUsageDelta* usageDeltas; // raw array [1:numUsageDeltas] + const InstrIssueDelta* issueDeltas; // raw array [1:numIssueDeltas] unsigned int numUsageDeltas; unsigned int numIssueDeltas; - vector instrRUsages; // indexed by opcode - hash_map issueGaps; // indexed by opcode pair - hash_map > - conflictLists; // indexed by opcode + std::vector instrRUsages; // indexed by opcode + std::hash_map issueGaps; // indexed by opcode pair + std::hash_map > + conflictLists; // indexed by opcode }; #endif diff --git a/include/llvm/Transforms/IPO/ConstantMerge.h b/include/llvm/Transforms/IPO/ConstantMerge.h index 6eed7712880..37d830ccf85 100644 --- a/include/llvm/Transforms/IPO/ConstantMerge.h +++ b/include/llvm/Transforms/IPO/ConstantMerge.h @@ -24,7 +24,7 @@ class GlobalVariable; class ConstantMerge : public Pass { protected: - map Constants; + std::map Constants; unsigned LastConstantSeen; public: inline ConstantMerge() : LastConstantSeen(0) {} diff --git a/include/llvm/Transforms/MutateStructTypes.h b/include/llvm/Transforms/MutateStructTypes.h index b2d4b30c272..23bf71c3b19 100644 --- a/include/llvm/Transforms/MutateStructTypes.h +++ b/include/llvm/Transforms/MutateStructTypes.h @@ -28,19 +28,19 @@ class MutateStructTypes : public Pass { // incoming slot [or negative if the specified incoming slot should be // removed]. // - typedef pair > TransformType; + typedef std::pair > TransformType; // Transforms to do for each structure type... - map Transforms; + std::map Transforms; // Mapping of old type to new types... - map > TypeMap; + std::map > TypeMap; // Mapping from global value of old type, to a global value of the new type... - map GlobalMap; + std::map GlobalMap; // Mapping from intra method value to intra method value - map LocalValueMap; + std::map LocalValueMap; public: // Ctor - Take a map that specifies what transformation to do for each field @@ -49,7 +49,7 @@ public: // the destination structure the field should end up in. A negative value // indicates that the field should be deleted entirely. // - typedef map > TransformsType; + typedef std::map > TransformsType; MutateStructTypes(const TransformsType &Transforms); @@ -83,7 +83,7 @@ private: // AdjustIndices - Convert the indexes specifed by Idx to the new changed form // using the specified OldTy as the base type being indexed into. // - void AdjustIndices(const CompositeType *OldTy, vector &Idx, + void AdjustIndices(const CompositeType *OldTy, std::vector &Idx, unsigned idx = 0); }; diff --git a/include/llvm/Transforms/Utils/Linker.h b/include/llvm/Transforms/Utils/Linker.h index 3650ccbadfb..e74c5d40fae 100644 --- a/include/llvm/Transforms/Utils/Linker.h +++ b/include/llvm/Transforms/Utils/Linker.h @@ -16,7 +16,7 @@ class Module; // error occurs, true is returned and ErrorMsg (if not null) is set to indicate // the problem. // -bool LinkModules(Module *Dest, const Module *Src, string *ErrorMsg = 0); +bool LinkModules(Module *Dest, const Module *Src, std::string *ErrorMsg = 0); #endif diff --git a/include/llvm/Type.h b/include/llvm/Type.h index 3617aaed9e1..1bbe02337be 100644 --- a/include/llvm/Type.h +++ b/include/llvm/Type.h @@ -71,23 +71,23 @@ public: private: PrimitiveID ID; // The current base type of this type... unsigned UID; // The unique ID number for this class - string Desc; // The printed name of the string... + std::string Desc; // The printed name of the string... bool Abstract; // True if type contains an OpaqueType bool Recursive; // True if the type is recursive protected: // ctor is protected, so only subclasses can create Type objects... - Type(const string &Name, PrimitiveID id); + Type(const std::string &Name, PrimitiveID id); virtual ~Type() {} // When types are refined, they update their description to be more concrete. // - inline void setDescription(const string &D) { Desc = D; } + inline void setDescription(const std::string &D) { Desc = D; } // setName - Associate the name with this type in the symbol table, but don't // set the local name to be equal specified name. // - virtual void setName(const string &Name, SymbolTable *ST = 0); + virtual void setName(const std::string &Name, SymbolTable *ST = 0); // Types can become nonabstract later, if they are refined. // @@ -116,7 +116,7 @@ public: inline unsigned getUniqueID() const { return UID; } // getDescription - Return the string representation of the type... - inline const string &getDescription() const { return Desc; } + inline const std::string &getDescription() const { return Desc; } // isSigned - Return whether a numeric type is signed. virtual bool isSigned() const { return 0; } diff --git a/include/llvm/User.h b/include/llvm/User.h index 2ea3a43fd0d..007db5f74c8 100644 --- a/include/llvm/User.h +++ b/include/llvm/User.h @@ -17,9 +17,9 @@ class User : public Value { User(const User &); // Do not implement protected: - vector Operands; + std::vector Operands; public: - User(const Type *Ty, ValueTy vty, const string &name = ""); + User(const Type *Ty, ValueTy vty, const std::string &name = ""); virtual ~User() { dropAllReferences(); } inline Value *getOperand(unsigned i) { @@ -39,8 +39,8 @@ public: // --------------------------------------------------------------------------- // Operand Iterator interface... // - typedef vector::iterator op_iterator; - typedef vector::const_iterator const_op_iterator; + typedef std::vector::iterator op_iterator; + typedef std::vector::const_iterator const_op_iterator; inline op_iterator op_begin() { return Operands.begin(); } inline const_op_iterator op_begin() const { return Operands.begin(); } diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 8a0014c85a9..19839706f2d 100644 --- a/include/llvm/Value.h +++ b/include/llvm/Value.h @@ -49,8 +49,8 @@ public: }; private: - vector Uses; - string Name; + std::vector Uses; + std::string Name; PATypeHandle Ty; ValueTy VTy; @@ -58,7 +58,7 @@ private: protected: inline void setType(const Type *ty) { Ty = ty; } public: - Value(const Type *Ty, ValueTy vty, const string &name = ""); + Value(const Type *Ty, ValueTy vty, const std::string &name = ""); virtual ~Value(); // Support for debugging @@ -68,10 +68,10 @@ public: inline const Type *getType() const { return Ty; } // All values can potentially be named... - inline bool hasName() const { return Name != ""; } - inline const string &getName() const { return Name; } + inline bool hasName() const { return Name != ""; } + inline const std::string &getName() const { return Name; } - virtual void setName(const string &name, SymbolTable * = 0) { + virtual void setName(const std::string &name, SymbolTable * = 0) { Name = name; } @@ -101,8 +101,8 @@ public: //---------------------------------------------------------------------- // Methods for handling the vector of uses of this Value. // - typedef vector::iterator use_iterator; - typedef vector::const_iterator use_const_iterator; + typedef std::vector::iterator use_iterator; + typedef std::vector::const_iterator use_const_iterator; inline unsigned use_size() const { return Uses.size(); } inline bool use_empty() const { return Uses.empty(); } diff --git a/include/llvm/ValueHolder.h b/include/llvm/ValueHolder.h index ef4ed1949f8..b75d243a3d4 100644 --- a/include/llvm/ValueHolder.h +++ b/include/llvm/ValueHolder.h @@ -25,7 +25,7 @@ // template class ValueHolder { - vector ValueList; + std::vector ValueList; ItemParentType *ItemParent; SymTabType *Parent; @@ -66,10 +66,10 @@ public: // sub-Definition iterator code //===--------------------------------------------------------------------===// // - typedef vector::iterator iterator; - typedef vector::const_iterator const_iterator; - typedef reverse_iterator const_reverse_iterator; - typedef reverse_iterator reverse_iterator; + typedef std::vector::iterator iterator; + typedef std::vector::const_iterator const_iterator; + typedef std::reverse_iterator const_reverse_iterator; + typedef std::reverse_iterator reverse_iterator; inline iterator begin() { return ValueList.begin(); } inline const_iterator begin() const { return ValueList.begin(); } diff --git a/include/llvm/iMemory.h b/include/llvm/iMemory.h index bf384a61699..13b1400d3a3 100644 --- a/include/llvm/iMemory.h +++ b/include/llvm/iMemory.h @@ -21,7 +21,7 @@ class AllocationInst : public Instruction { public: AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, - const string &Name = "") + const std::string &Name = "") : Instruction(Ty, iTy, Name) { assert(Ty->isPointerType() && "Can't allocate a non pointer type!"); @@ -67,7 +67,7 @@ public: class MallocInst : public AllocationInst { public: - MallocInst(const Type *Ty, Value *ArraySize = 0, const string &Name = "") + MallocInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "") : AllocationInst(Ty, ArraySize, Malloc, Name) {} virtual Instruction *clone() const { @@ -94,7 +94,7 @@ public: class AllocaInst : public AllocationInst { public: - AllocaInst(const Type *Ty, Value *ArraySize = 0, const string &Name = "") + AllocaInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "") : AllocationInst(Ty, ArraySize, Alloca, Name) {} virtual Instruction *clone() const { @@ -154,7 +154,7 @@ public: class MemAccessInst : public Instruction { protected: inline MemAccessInst(const Type *Ty, unsigned Opcode, - const string &Nam = "") + const std::string &Nam = "") : Instruction(Ty, Opcode, Nam) {} public: // getIndexedType - Returns the type of the element that would be loaded with @@ -164,7 +164,7 @@ public: // pointer type. // static const Type *getIndexedType(const Type *Ptr, - const vector &Indices, + const std::vector &Indices, bool AllowStructLeaf = false); inline op_iterator idx_begin() { @@ -177,8 +177,8 @@ public: inline const_op_iterator idx_end() const { return op_end(); } - vector copyIndices() const { - return vector(idx_begin(), idx_end()); + std::vector copyIndices() const { + return std::vector(idx_begin(), idx_end()); } Value *getPointerOperand() { @@ -217,8 +217,8 @@ class LoadInst : public MemAccessInst { Operands.push_back(Use(LI.Operands[i], this)); } public: - LoadInst(Value *Ptr, const vector &Idx, const string &Name = ""); - LoadInst(Value *Ptr, const string &Name = ""); + LoadInst(Value *Ptr, const std::vector &Ix, const std::string & = ""); + LoadInst(Value *Ptr, const std::string &Name = ""); virtual Instruction *clone() const { return new LoadInst(*this); } virtual const char *getOpcodeName() const { return "load"; } @@ -247,9 +247,9 @@ class StoreInst : public MemAccessInst { Operands.push_back(Use(SI.Operands[i], this)); } public: - StoreInst(Value *Val, Value *Ptr, const vector &Idx, - const string &Name = ""); - StoreInst(Value *Val, Value *Ptr, const string &Name = ""); + StoreInst(Value *Val, Value *Ptr, const std::vector &Idx, + const std::string &Name = ""); + StoreInst(Value *Val, Value *Ptr, const std::string &Name = ""); virtual Instruction *clone() const { return new StoreInst(*this); } virtual const char *getOpcodeName() const { return "store"; } @@ -280,8 +280,8 @@ class GetElementPtrInst : public MemAccessInst { Operands.push_back(Use(EPI.Operands[i], this)); } public: - GetElementPtrInst(Value *Ptr, const vector &Idx, - const string &Name = ""); + GetElementPtrInst(Value *Ptr, const std::vector &Idx, + const std::string &Name = ""); virtual Instruction *clone() const { return new GetElementPtrInst(*this); } virtual const char *getOpcodeName() const { return "getelementptr"; } virtual unsigned getFirstIndexOperandNumber() const { return 1; } diff --git a/include/llvm/iOperators.h b/include/llvm/iOperators.h index 7cbaecf64a0..f9cba9f68ca 100644 --- a/include/llvm/iOperators.h +++ b/include/llvm/iOperators.h @@ -15,7 +15,7 @@ // class GenericUnaryInst : public UnaryOperator { public: - GenericUnaryInst(UnaryOps Opcode, Value *S1, const string &Name = "") + GenericUnaryInst(UnaryOps Opcode, Value *S1, const std::string &Name = "") : UnaryOperator(S1, Opcode, Name) { } @@ -32,7 +32,7 @@ public: class GenericBinaryInst : public BinaryOperator { public: GenericBinaryInst(BinaryOps Opcode, Value *S1, Value *S2, - const string &Name = "") + const std::string &Name = "") : BinaryOperator(Opcode, S1, S2, Name) { } @@ -43,7 +43,7 @@ class SetCondInst : public BinaryOperator { BinaryOps OpType; public: SetCondInst(BinaryOps opType, Value *S1, Value *S2, - const string &Name = ""); + const std::string &Name = ""); virtual const char *getOpcodeName() const; }; diff --git a/include/llvm/iOther.h b/include/llvm/iOther.h index de1532d5903..85698da7617 100644 --- a/include/llvm/iOther.h +++ b/include/llvm/iOther.h @@ -24,7 +24,7 @@ class CastInst : public Instruction { Operands.push_back(Use(CI.Operands[0], this)); } public: - CastInst(Value *S, const Type *Ty, const string &Name = "") + CastInst(Value *S, const Type *Ty, const std::string &Name = "") : Instruction(Ty, Cast, Name) { Operands.reserve(1); Operands.push_back(Use(S, this)); @@ -55,13 +55,13 @@ class MethodArgument : public Value { // Defined in the InstrType.cpp file inline void setParent(Method *parent) { Parent = parent; } public: - MethodArgument(const Type *Ty, const string &Name = "") + MethodArgument(const Type *Ty, const std::string &Name = "") : Value(Ty, Value::MethodArgumentVal, Name) { Parent = 0; } // Specialize setName to handle symbol table majik... - virtual void setName(const string &name, SymbolTable *ST = 0); + virtual void setName(const std::string &name, SymbolTable *ST = 0); inline const Method *getParent() const { return Parent; } inline Method *getParent() { return Parent; } @@ -81,7 +81,7 @@ public: class CallInst : public Instruction { CallInst(const CallInst &CI); public: - CallInst(Value *Meth, const vector ¶ms, const string &Name = ""); + CallInst(Value *M, const std::vector &Par, const std::string & = ""); virtual const char *getOpcodeName() const { return "call"; } @@ -123,7 +123,7 @@ class ShiftInst : public Instruction { Operands.push_back(Use(SI.Operands[1], this)); } public: - ShiftInst(OtherOps Opcode, Value *S, Value *SA, const string &Name = "") + ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "") : Instruction(S->getType(), Opcode, Name) { assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!"); Operands.reserve(2); diff --git a/include/llvm/iPHINode.h b/include/llvm/iPHINode.h index 66afac62c08..0ac0d44c669 100644 --- a/include/llvm/iPHINode.h +++ b/include/llvm/iPHINode.h @@ -21,7 +21,7 @@ class BasicBlock; class PHINode : public Instruction { PHINode(const PHINode &PN); public: - PHINode(const Type *Ty, const string &Name = ""); + PHINode(const Type *Ty, const std::string &Name = ""); virtual Instruction *clone() const { return new PHINode(*this); } virtual const char *getOpcodeName() const { return "phi"; } diff --git a/include/llvm/iTerminators.h b/include/llvm/iTerminators.h index ebd8b873dd4..6ed75fa687c 100644 --- a/include/llvm/iTerminators.h +++ b/include/llvm/iTerminators.h @@ -198,7 +198,7 @@ class InvokeInst : public TerminatorInst { InvokeInst(const InvokeInst &BI); public: InvokeInst(Value *Meth, BasicBlock *IfNormal, BasicBlock *IfException, - const vector &Params, const string &Name = ""); + const std::vector &Params, const std::string &Name = ""); virtual Instruction *clone() const { return new InvokeInst(*this); } diff --git a/lib/Analysis/Expressions.cpp b/lib/Analysis/Expressions.cpp index a35e37a9630..e94c7960596 100644 --- a/lib/Analysis/Expressions.cpp +++ b/lib/Analysis/Expressions.cpp @@ -11,6 +11,7 @@ #include "llvm/Optimizations/ConstantHandling.h" #include "llvm/Method.h" #include "llvm/BasicBlock.h" +#include using namespace opt; // Get all the constant handling stuff using namespace analysis; @@ -178,7 +179,7 @@ inline const ConstantInt *operator*(const DefZero &L, const DefOne &R) { static ExprType handleAddition(ExprType Left, ExprType Right, Value *V) { const Type *Ty = V->getType(); if (Left.ExprTy > Right.ExprTy) - swap(Left, Right); // Make left be simpler than right + std::swap(Left, Right); // Make left be simpler than right switch (Left.ExprTy) { case ExprType::Constant: @@ -229,7 +230,7 @@ ExprType analysis::ClassifyExpression(Value *Expr) { case Value::TypeVal: case Value::BasicBlockVal: case Value::MethodVal: case Value::ModuleVal: default: //assert(0 && "Unexpected expression type to classify!"); - cerr << "Bizarre thing to expr classify: " << Expr << endl; + std::cerr << "Bizarre thing to expr classify: " << Expr << "\n"; return Expr; case Value::GlobalVariableVal: // Global Variable & Method argument: case Value::MethodArgumentVal: // nothing known, return variable itself @@ -280,7 +281,7 @@ ExprType analysis::ClassifyExpression(Value *Expr) { ExprType Left (ClassifyExpression(I->getOperand(0))); ExprType Right(ClassifyExpression(I->getOperand(1))); if (Left.ExprTy > Right.ExprTy) - swap(Left, Right); // Make left be simpler than right + std::swap(Left, Right); // Make left be simpler than right if (Left.ExprTy != ExprType::Constant) // RHS must be > constant return I; // Quadratic eqn! :( diff --git a/lib/Analysis/IPA/CallGraph.cpp b/lib/Analysis/IPA/CallGraph.cpp index d77064cf35f..e48cf7fa386 100644 --- a/lib/Analysis/IPA/CallGraph.cpp +++ b/lib/Analysis/IPA/CallGraph.cpp @@ -29,7 +29,7 @@ cfg::CallGraphNode *cfg::CallGraph::getNodeFor(Method *M) { assert(M->getParent() == Mod && "Method not in current module!"); CallGraphNode *New = new CallGraphNode(M); - MethodMap.insert(pair(M, New)); + MethodMap.insert(std::make_pair(M, New)); return New; } @@ -71,7 +71,7 @@ cfg::CallGraph::~CallGraph() { } -void cfg::WriteToOutput(const CallGraphNode *CGN, ostream &o) { +void cfg::WriteToOutput(const CallGraphNode *CGN, std::ostream &o) { if (CGN->getMethod()) o << "Call graph node for method: '" << CGN->getMethod()->getName() <<"'\n"; else @@ -79,10 +79,10 @@ void cfg::WriteToOutput(const CallGraphNode *CGN, ostream &o) { for (unsigned i = 0; i < CGN->size(); ++i) o << " Calls method '" << (*CGN)[i]->getMethod()->getName() << "'\n"; - o << endl; + o << "\n"; } -void cfg::WriteToOutput(const CallGraph &CG, ostream &o) { +void cfg::WriteToOutput(const CallGraph &CG, std::ostream &o) { WriteToOutput(CG.getRoot(), o); for (CallGraph::const_iterator I = CG.begin(), E = CG.end(); I != E; ++I) o << I->second; diff --git a/lib/Analysis/IPA/FindUnsafePointerTypes.cpp b/lib/Analysis/IPA/FindUnsafePointerTypes.cpp index 50fb8ea7b63..1058e6ed39b 100644 --- a/lib/Analysis/IPA/FindUnsafePointerTypes.cpp +++ b/lib/Analysis/IPA/FindUnsafePointerTypes.cpp @@ -60,7 +60,7 @@ bool FindUnsafePointerTypes::doPerMethodWork(Method *Meth) { UnsafeTypes.insert((PointerType*)ITy); if (PrintFailures) { - CachedWriter CW(M->getParent(), cerr); + CachedWriter CW(M->getParent(), std::cerr); CW << "FindUnsafePointerTypes: Type '" << ITy << "' marked unsafe in '" << Meth->getName() << "' by:\n" << Inst; } @@ -74,7 +74,7 @@ bool FindUnsafePointerTypes::doPerMethodWork(Method *Meth) { // printResults - Loop over the results of the analysis, printing out unsafe // types. // -void FindUnsafePointerTypes::printResults(const Module *M, ostream &o) { +void FindUnsafePointerTypes::printResults(const Module *M, std::ostream &o) { if (UnsafeTypes.empty()) { o << "SafePointerAccess Analysis: No unsafe types found!\n"; return; @@ -84,9 +84,9 @@ void FindUnsafePointerTypes::printResults(const Module *M, ostream &o) { CW << "SafePointerAccess Analysis: Found these unsafe types:\n"; unsigned Counter = 1; - for (set::const_iterator I = getUnsafeTypes().begin(), + for (std::set::const_iterator I = getUnsafeTypes().begin(), E = getUnsafeTypes().end(); I != E; ++I, ++Counter) { - CW << " #" << Counter << ". " << (Value*)*I << endl; + CW << " #" << Counter << ". " << (Value*)*I << "\n"; } } diff --git a/lib/Analysis/IPA/FindUsedTypes.cpp b/lib/Analysis/IPA/FindUsedTypes.cpp index 6f8049abad1..1d98983115c 100644 --- a/lib/Analysis/IPA/FindUsedTypes.cpp +++ b/lib/Analysis/IPA/FindUsedTypes.cpp @@ -78,15 +78,15 @@ bool FindUsedTypes::doPerMethodWork(Method *m) { // passed in, then the types are printed symbolically if possible, using the // symbol table from the module. // -void FindUsedTypes::printTypes(ostream &o, const Module *M = 0) const { +void FindUsedTypes::printTypes(std::ostream &o, const Module *M = 0) const { o << "Types in use by this module:\n"; if (M) { CachedWriter CW(M, o); - for (set::const_iterator I = UsedTypes.begin(), + for (std::set::const_iterator I = UsedTypes.begin(), E = UsedTypes.end(); I != E; ++I) - CW << " " << *I << endl; + CW << " " << *I << "\n"; } else - for (set::const_iterator I = UsedTypes.begin(), + for (std::set::const_iterator I = UsedTypes.begin(), E = UsedTypes.end(); I != E; ++I) - o << " " << *I << endl; + o << " " << *I << "\n"; } diff --git a/lib/Analysis/InductionVariable.cpp b/lib/Analysis/InductionVariable.cpp index d88c9cfc683..045c9323328 100644 --- a/lib/Analysis/InductionVariable.cpp +++ b/lib/Analysis/InductionVariable.cpp @@ -88,7 +88,7 @@ InductionVariable::InductionVariable(PHINode *P, cfg::LoopInfo *LoopInfo) { ExprType E2 = analysis::ClassifyExpression(V2); if (E1.ExprTy > E2.ExprTy) // Make E1 be the simpler expression - swap(E1, E2); + std::swap(E1, E2); // E1 must be a constant incoming value, and E2 must be a linear expression // with respect to the PHI node. @@ -109,7 +109,7 @@ InductionVariable::InductionVariable(PHINode *P, cfg::LoopInfo *LoopInfo) { // Make sure that V1 is the incoming value, and V2 is from the backedge of // the loop. if (L->contains(Phi->getIncomingBlock(0))) // Wrong order. Swap now. - swap(V1, V2); + std::swap(V1, V2); Start = V1; // We know that Start has to be loop invariant... Step = 0; diff --git a/lib/Analysis/IntervalPartition.cpp b/lib/Analysis/IntervalPartition.cpp index 8616cb721ce..fff8d224e21 100644 --- a/lib/Analysis/IntervalPartition.cpp +++ b/lib/Analysis/IntervalPartition.cpp @@ -9,6 +9,7 @@ #include "Support/STLExtras.h" using namespace cfg; +using std::make_pair; //===----------------------------------------------------------------------===// // IntervalPartition Implementation diff --git a/lib/Analysis/LiveVar/BBLiveVar.cpp b/lib/Analysis/LiveVar/BBLiveVar.cpp index d7e036b2563..0ecf96cf13c 100644 --- a/lib/Analysis/LiveVar/BBLiveVar.cpp +++ b/lib/Analysis/LiveVar/BBLiveVar.cpp @@ -1,8 +1,13 @@ #include "llvm/Analysis/LiveVar/BBLiveVar.h" #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" #include "llvm/CodeGen/MachineInstr.h" + +/// BROKEN: Should not include sparc stuff directly into here #include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn +using std::cerr; +using std::endl; +using std::pair; //----------------------------------------------------------------------------- // Constructor @@ -39,7 +44,7 @@ void BBLiveVar::calcDefUseSets() if( DEBUG_LV > 1) { // debug msg cerr << " *Iterating over machine instr "; MInst->dump(); - cerr << endl; + cerr << "\n"; } // iterate over MI operands to find defs @@ -85,9 +90,9 @@ void BBLiveVar::calcDefUseSets() if( DEBUG_LV > 1) { // debug msg of level 2 cerr << " - phi operand "; printValue( ArgVal ); - cerr << " came from BB "; + cerr << " came from BB "; printValue( PhiArgMap[ ArgVal ]); - cerr< 1) { - cerr << " +Def: "; printValue( Op ); cerr << endl; + cerr << " +Def: "; printValue( Op ); cerr << "\n"; } } diff --git a/lib/Analysis/LiveVar/BBLiveVar.h b/lib/Analysis/LiveVar/BBLiveVar.h index 6d7d4eb5334..9ce56a88f63 100644 --- a/lib/Analysis/LiveVar/BBLiveVar.h +++ b/lib/Analysis/LiveVar/BBLiveVar.h @@ -28,7 +28,7 @@ class BBLiveVar // map that contains phi args->BB they came // set by calcDefUseSets & used by setPropagate - hash_map PhiArgMap; + std::hash_map PhiArgMap; // method to propogate an InSet to OutSet of a predecessor bool setPropagate( LiveVarSet *const OutSetOfPred, diff --git a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp index 636359d1d08..5de35ff1be5 100644 --- a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp +++ b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp @@ -12,15 +12,15 @@ #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" #include "llvm/CodeGen/MachineInstr.h" #include "Support/PostOrderIterator.h" - +#include +using std::cout; +using std::endl; //************************** Constructor/Destructor *************************** -MethodLiveVarInfo::MethodLiveVarInfo(const Method *const M) : Meth(M), - BB2BBLVMap() -{ - assert(! M->isExternal() ); // cannot be a prototype decleration +MethodLiveVarInfo::MethodLiveVarInfo(const Method *const M) : Meth(M) { + assert(!M->isExternal() && "Cannot be a prototype declaration"); HasAnalyzed = false; // still we haven't called analyze() } @@ -55,8 +55,6 @@ MethodLiveVarInfo:: ~MethodLiveVarInfo() if( (*MI).first ) // delete all LiveVarSets in MInst2LVSetBI delete (*MI).second; } - - } diff --git a/lib/Analysis/LiveVar/ValueSet.cpp b/lib/Analysis/LiveVar/ValueSet.cpp index 6806d1c5638..d176d9e53cf 100644 --- a/lib/Analysis/LiveVar/ValueSet.cpp +++ b/lib/Analysis/LiveVar/ValueSet.cpp @@ -1,11 +1,14 @@ #include "llvm/Analysis/LiveVar/ValueSet.h" #include "llvm/ConstantVals.h" - +#include +using std::cerr; +using std::endl; +using std::pair; +using std::hash_set; void printValue( const Value *const v) // func to print a Value { - if (v->hasName()) cerr << v << "(" << ((*v).getName()) << ") "; else if (Constant *C = dyn_cast(v)) @@ -16,17 +19,13 @@ void printValue( const Value *const v) // func to print a Value //---------------- Method implementations -------------------------- - - -ValueSet:: ValueSet() : hash_set () { } - // for performing two set unions bool ValueSet::setUnion( const ValueSet *const set1) { const_iterator set1it; pair result; bool changed = false; - for( set1it = set1->begin() ; set1it != set1->end(); set1it++) { + for( set1it = set1->begin() ; set1it != set1->end(); ++set1it) { // for all all elements in set1 result = insert( *set1it ); // insert to this set if( result.second == true) changed = true; @@ -41,7 +40,7 @@ void ValueSet::setDifference( const ValueSet *const set1, const ValueSet *const set2) { const_iterator set1it, set2it; - for( set1it = set1->begin() ; set1it != set1->end(); set1it++) { + for( set1it = set1->begin() ; set1it != set1->end(); ++set1it) { // for all elements in set1 iterator set2it = set2->find( *set1it ); // find wether the elem is in set2 if( set2it == set2->end() ) // if the element is not in set2 @@ -53,7 +52,7 @@ void ValueSet::setDifference( const ValueSet *const set1, // for performing set subtraction void ValueSet::setSubtract( const ValueSet *const set1) { const_iterator set1it; - for( set1it = set1->begin() ; set1it != set1->end(); set1it++) + for( set1it = set1->begin() ; set1it != set1->end(); ++set1it) // for all elements in set1 erase( *set1it ); // erase that element from this set } @@ -62,7 +61,5 @@ void ValueSet::setSubtract( const ValueSet *const set1) { void ValueSet::printSet() const { // for printing a live variable set - const_iterator it; - for( it = begin() ; it != end(); it++) - printValue( *it ); + for_each(begin(), end(), printValue); } diff --git a/lib/Analysis/LoopDepth.cpp b/lib/Analysis/LoopDepth.cpp index ed96bd4f577..994b7cd3c98 100644 --- a/lib/Analysis/LoopDepth.cpp +++ b/lib/Analysis/LoopDepth.cpp @@ -22,8 +22,6 @@ inline void LoopDepthCalculator::ProcessInterval(cfg::Interval *I) { } LoopDepthCalculator::LoopDepthCalculator(Method *M) { - //map LoopDepth; - cfg::IntervalPartition *IP = new cfg::IntervalPartition(M); while (!IP->isDegeneratePartition()) { for_each(IP->begin(), IP->end(), @@ -34,7 +32,7 @@ LoopDepthCalculator::LoopDepthCalculator(Method *M) { // cfg::IntervalPartition *NewIP = new cfg::IntervalPartition(*IP, true); if (NewIP->size() == IP->size()) { - cerr << "IRREDUCIBLE GRAPH FOUND!!!\n"; + assert(0 && "IRREDUCIBLE GRAPH FOUND!!!\n"); // TODO: fix irreducible graph return; } diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp index 40a195b042f..ed91ca8bd5f 100644 --- a/lib/Analysis/LoopInfo.cpp +++ b/lib/Analysis/LoopInfo.cpp @@ -33,7 +33,7 @@ cfg::Loop *cfg::LoopInfo::ConsiderForLoop(const BasicBlock *BB, const DominatorSet &DS) { if (BBMap.find(BB) != BBMap.end()) return 0; // Havn't processed this node? - vector TodoStack; + std::vector TodoStack; // Scan the predecessors of BB, checking to see if BB dominates any of // them. @@ -64,7 +64,7 @@ cfg::Loop *cfg::LoopInfo::ConsiderForLoop(const BasicBlock *BB, // loop can be found for them. Also check subsidary basic blocks to see if // they start subloops of their own. // - for (vector::reverse_iterator I = L->Blocks.rbegin(), + for (std::vector::reverse_iterator I = L->Blocks.rbegin(), E = L->Blocks.rend(); I != E; ++I) { // Check to see if this block starts a new loop @@ -74,7 +74,7 @@ cfg::Loop *cfg::LoopInfo::ConsiderForLoop(const BasicBlock *BB, } if (BBMap.find(*I) == BBMap.end()) - BBMap.insert(make_pair(*I, L)); + BBMap.insert(std::make_pair(*I, L)); } return L; diff --git a/lib/Analysis/ModuleAnalyzer.cpp b/lib/Analysis/ModuleAnalyzer.cpp index 129fb3b8621..dc07512cb57 100644 --- a/lib/Analysis/ModuleAnalyzer.cpp +++ b/lib/Analysis/ModuleAnalyzer.cpp @@ -13,6 +13,8 @@ #include "llvm/DerivedTypes.h" #include "Support/STLExtras.h" #include +#include +using std::set; // processModule - Driver function to call all of my subclasses virtual methods. // @@ -59,8 +61,8 @@ inline bool ModuleAnalyzer::handleType(set &TypeSet, break; default: - cerr << "ModuleAnalyzer::handleType, type unknown: '" - << T->getName() << "'\n"; + std::cerr << "ModuleAnalyzer::handleType, type unknown: '" + << T->getName() << "'\n"; break; } diff --git a/lib/Analysis/PostDominators.cpp b/lib/Analysis/PostDominators.cpp index 2ed02dbed26..2e4f6e4df1f 100644 --- a/lib/Analysis/PostDominators.cpp +++ b/lib/Analysis/PostDominators.cpp @@ -10,6 +10,8 @@ #include "Support/DepthFirstIterator.h" #include "Support/STLExtras.h" #include +using std::set; + //===----------------------------------------------------------------------===// // Helper Template diff --git a/lib/Analysis/Writer.cpp b/lib/Analysis/Writer.cpp index 3d9134f0dc4..1e873bfa526 100644 --- a/lib/Analysis/Writer.cpp +++ b/lib/Analysis/Writer.cpp @@ -12,6 +12,10 @@ #include "llvm/Analysis/InductionVariable.h" #include #include +using std::ostream; +using std::set; +using std::vector; +using std::string; //===----------------------------------------------------------------------===// // Interval Printing Routines @@ -23,19 +27,19 @@ void cfg::WriteToOutput(const Interval *I, ostream &o) { // Print out all of the basic blocks in the interval... copy(I->Nodes.begin(), I->Nodes.end(), - ostream_iterator(o, "\n")); + std::ostream_iterator(o, "\n")); o << "Interval Predecessors:\n"; copy(I->Predecessors.begin(), I->Predecessors.end(), - ostream_iterator(o, "\n")); + std::ostream_iterator(o, "\n")); o << "Interval Successors:\n"; copy(I->Successors.begin(), I->Successors.end(), - ostream_iterator(o, "\n")); + std::ostream_iterator(o, "\n")); } void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) { - copy(IP.begin(), IP.end(), ostream_iterator(o, "\n")); + copy(IP.begin(), IP.end(), std::ostream_iterator(o, "\n")); } @@ -45,7 +49,7 @@ void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) { //===----------------------------------------------------------------------===// ostream &operator<<(ostream &o, const set &BBs) { - copy(BBs.begin(), BBs.end(), ostream_iterator(o, "\n")); + copy(BBs.begin(),BBs.end(), std::ostream_iterator(o,"\n")); return o; } @@ -53,7 +57,7 @@ void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) { for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) { o << "=============================--------------------------------\n" << "\nDominator Set For Basic Block\n" << I->first - << "-------------------------------\n" << I->second << endl; + << "-------------------------------\n" << I->second << "\n"; } } @@ -63,7 +67,7 @@ void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) { I != E; ++I) { o << "=============================--------------------------------\n" << "\nImmediate Dominator For Basic Block\n" << I->first - << "is: \n" << I->second << endl; + << "is: \n" << I->second << "\n"; } } @@ -93,7 +97,7 @@ void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) { I != E; ++I) { o << "=============================--------------------------------\n" << "\nDominance Frontier For Basic Block\n" << I->first - << "is: \n" << I->second << endl; + << "is: \n" << I->second << "\n"; } } @@ -109,15 +113,15 @@ void cfg::WriteToOutput(const Loop *L, ostream &o) { if (i) o << ","; WriteAsOperand(o, (const Value*)L->getBlocks()[i]); } - o << endl; + o << "\n"; copy(L->getSubLoops().begin(), L->getSubLoops().end(), - ostream_iterator(o, "\n")); + std::ostream_iterator(o, "\n")); } void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) { copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(), - ostream_iterator(o, "\n")); + std::ostream_iterator(o, "\n")); } @@ -138,11 +142,11 @@ void WriteToOutput(const InductionVariable &IV, ostream &o) { WriteAsOperand(o, (const Value*)IV.Phi); o << ":\n" << (const Value*)IV.Phi; } else { - o << endl; + o << "\n"; } if (IV.InductionType == InductionVariable::Unknown) return; o << " Start ="; WriteAsOperand(o, IV.Start); o << " Step =" ; WriteAsOperand(o, IV.Step); - o << endl; + o << "\n"; } diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp index b487042bcb9..4b280efd7d0 100644 --- a/lib/AsmParser/Parser.cpp +++ b/lib/AsmParser/Parser.cpp @@ -8,6 +8,7 @@ #include "llvm/Module.h" #include "ParserInternals.h" #include // for sprintf +using std::string; // The useful interface defined by this file... Parse an ascii file, and return // the internal representation in a nice slice'n'dice'able representation. @@ -30,7 +31,7 @@ Module *ParseAssemblyFile(const string &Filename) { // throw (ParseException) fclose(F); if (Result) { // Check to see that it is valid... - vector Errors; + std::vector Errors; if (verify(Result, Errors)) { delete Result; Result = 0; string Message; diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h index 750833fae83..e1e2c4954c0 100644 --- a/lib/AsmParser/ParserInternals.h +++ b/lib/AsmParser/ParserInternals.h @@ -23,12 +23,12 @@ class Module; // Global variables exported from the lexer... -extern FILE *llvmAsmin; +extern std::FILE *llvmAsmin; extern int llvmAsmlineno; // Globals exported by the parser... -extern string CurFilename; -Module *RunVMAsmParser(const string &Filename, FILE *F); +extern std::string CurFilename; +Module *RunVMAsmParser(const std::string &Filename, FILE *F); // UnEscapeLexed - Run through the specified buffer and change \xx codes to the @@ -47,7 +47,7 @@ char *UnEscapeLexed(char *Buffer, bool AllowNull = false); // This also helps me because I keep typing 'throw new ParseException' instead // of just 'throw ParseException'... sigh... // -static inline void ThrowException(const string &message, +static inline void ThrowException(const std::string &message, int LineNo = -1) { if (LineNo == -1) LineNo = llvmAsmlineno; // TODO: column number in exception @@ -116,18 +116,19 @@ struct ValID { return Result; } - inline string getName() const { + inline std::string getName() const { switch (Type) { - case NumberVal : return string("#") + itostr(Num); + case NumberVal : return std::string("#") + itostr(Num); case NameVal : return Name; - case ConstStringVal: return string("\"") + Name + string("\""); + case ConstStringVal: return std::string("\"") + Name + std::string("\""); case ConstFPVal : return ftostr(ConstPoolFP); case ConstNullVal : return "null"; case ConstUIntVal : - case ConstSIntVal : return string("%") + itostr(ConstPool64); + case ConstSIntVal : return std::string("%") + itostr(ConstPool64); default: assert(0 && "Unknown value!"); abort(); + return ""; } } @@ -163,7 +164,7 @@ public: struct InstPlaceHolderHelper : public Instruction { InstPlaceHolderHelper(const Type *Ty) : Instruction(Ty, UserOp1, "") {} - virtual Instruction *clone() const { abort(); } + virtual Instruction *clone() const { abort(); return 0; } virtual const char *getOpcodeName() const { return "placeholder"; } }; diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 285e78acefb..aab868abb97 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -22,6 +22,15 @@ #include // Get definition of pair class #include #include // This embarasment is due to our flex lexer... +#include +using std::list; +using std::vector; +using std::pair; +using std::map; +using std::pair; +using std::make_pair; +using std::cerr; +using std::string; int yyerror(const char *ErrorMsg); // Forward declarations to prevent "implicit int yylex(); // declaration" of xxx warnings. @@ -46,7 +55,6 @@ string CurFilename; typedef vector ValueList; // Numbered defs static void ResolveDefinitions(vector &LateResolvers, vector *FutureLateResolvers = 0); -static void ResolveTypes (vector > &LateResolveTypes); static struct PerModuleInfo { Module *CurrentModule; @@ -425,22 +433,6 @@ static void ResolveDefinitions(vector &LateResolvers, LateResolvers.clear(); } -// ResolveType - Take a specified unresolved type and resolve it. If there is -// nothing to resolve it to yet, return true. Otherwise resolve it and return -// false. -// -static bool ResolveType(PATypeHolder &T) { - const Type *Ty = T; - ValID &DID = getValIDFromPlaceHolder(Ty); - - const Type *TheRealType = getTypeVal(DID, true); - if (TheRealType == 0 || TheRealType == Ty) return true; - - // Refine the opaque type we had to the new type we are getting. - cast(Ty)->refineAbstractTypeTo(TheRealType); - return false; -} - // ResolveTypeTo - A brand new type was just declared. This means that (if // name is not null) things referencing Name can be resolved. Otherwise, things // refering to the number can be resolved. Do this now. @@ -641,12 +633,13 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) { PATypeHolder *TypeVal; Value *ValueVal; - list *MethodArgList; - vector *ValueList; - list > *TypeList; - list > *PHIList; // Represent the RHS of PHI node - list > *JumpTable; - vector *ConstVector; + std::list *MethodArgList; + std::vector *ValueList; + std::list > *TypeList; + std::list > *PHIList; // Represent the RHS of PHI node + std::list > *JumpTable; + std::vector *ConstVector; int64_t SInt64Val; uint64_t UInt64Val; @@ -812,8 +805,8 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference } | UpRTypesV '(' ArgTypeListI ')' { // Method derived type? vector Params; - mapto($3->begin(), $3->end(), back_inserter(Params), - mem_fun_ref(&PATypeHandle::get)); + mapto($3->begin(), $3->end(), std::back_inserter(Params), + std::mem_fun_ref(&PATypeHandle::get)); bool isVarArg = Params.size() && Params.back() == Type::VoidTy; if (isVarArg) Params.pop_back(); @@ -827,8 +820,8 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference } | '{' TypeListI '}' { // Structure type? vector Elements; - mapto($2->begin(), $2->end(), back_inserter(Elements), - mem_fun_ref(&PATypeHandle::get)); + mapto($2->begin(), $2->end(), std::back_inserter(Elements), + std::mem_fun_ref(&PATypeHandle::get)); $$ = newTH(HandleUpRefs(StructType::get(Elements))); delete $2; diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index 78da567f012..d5833dbeed5 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/lib/Bytecode/Reader/ConstantReader.cpp @@ -14,8 +14,9 @@ #include "llvm/ConstantVals.h" #include "llvm/GlobalVariable.h" #include - - +#include +using std::make_pair; +using std::cerr; const Type *BytecodeParser::parseTypeConstant(const uchar *&Buf, const uchar *EndBuf) { @@ -36,7 +37,7 @@ const Type *BytecodeParser::parseTypeConstant(const uchar *&Buf, unsigned NumParams; if (read_vbr(Buf, EndBuf, NumParams)) return failure(Val); - vector Params; + std::vector Params; while (NumParams--) { if (read_vbr(Buf, EndBuf, Typ)) return failure(Val); const Type *Ty = getType(Typ); @@ -59,12 +60,12 @@ const Type *BytecodeParser::parseTypeConstant(const uchar *&Buf, if (read_vbr(Buf, EndBuf, NumElements)) return failure(Val); BCR_TRACE(5, "Array Type Constant #" << ElTyp << " size=" - << NumElements << endl); + << NumElements << "\n"); return ArrayType::get(ElementType, NumElements); } case Type::StructTyID: { unsigned Typ; - vector Elements; + std::vector Elements; if (read_vbr(Buf, EndBuf, Typ)) return failure(Val); while (Typ) { // List is terminated by void/0 typeid @@ -80,7 +81,7 @@ const Type *BytecodeParser::parseTypeConstant(const uchar *&Buf, case Type::PointerTyID: { unsigned ElTyp; if (read_vbr(Buf, EndBuf, ElTyp)) return failure(Val); - BCR_TRACE(5, "Pointer Type Constant #" << (ElTyp-14) << endl); + BCR_TRACE(5, "Pointer Type Constant #" << (ElTyp-14) << "\n"); const Type *ElementType = getType(ElTyp); if (ElementType == 0) return failure(Val); return PointerType::get(ElementType); @@ -241,7 +242,7 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf, const ArrayType *AT = cast(Ty); unsigned NumElements = AT->getNumElements(); - vector Elements; + std::vector Elements; while (NumElements--) { // Read all of the elements of the constant. unsigned Slot; if (read_vbr(Buf, EndBuf, Slot)) return failure(true); @@ -257,7 +258,7 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf, const StructType *ST = cast(Ty); const StructType::ElementTypes &ET = ST->getElementTypes(); - vector Elements; + std::vector Elements; for (unsigned i = 0; i < ET.size(); ++i) { unsigned Slot; if (read_vbr(Buf, EndBuf, Slot)) return failure(true); diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp index b498ac90c1a..8402db5e827 100644 --- a/lib/Bytecode/Reader/InstructionReader.cpp +++ b/lib/Bytecode/Reader/InstructionReader.cpp @@ -16,6 +16,9 @@ #include "llvm/iMemory.h" #include "llvm/iPHINode.h" #include "llvm/iOther.h" +#include +using std::vector; +using std::cerr; bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf, RawInst &Result) { @@ -107,7 +110,7 @@ bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf, #if 0 cerr << "NO: " << Result.NumOperands << " opcode: " << Result.Opcode << " Ty: " << Result.Ty->getDescription() << " arg1: " << Result.Arg1 - << " arg2: " << Result.Arg2 << " arg3: " << Result.Arg3 << endl; + << " arg2: " << Result.Arg2 << " arg3: " << Result.Arg3 << "\n"; #endif return false; } @@ -441,6 +444,6 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf, } // end switch(Raw.Opcode) cerr << "Unrecognized instruction! " << Raw.Opcode - << " ADDR = 0x" << (void*)Buf << endl; + << " ADDR = 0x" << (void*)Buf << "\n"; return failure(true); } diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index c8be36845a2..d0c4d7a5ae3 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -20,11 +20,15 @@ #include "llvm/iPHINode.h" #include "llvm/iOther.h" #include -#include +typedef int blksize_t; #include +#include #include #include #include +#include +using std::cerr; +using std::make_pair; bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) { if (Ty->isPrimitiveType()) { @@ -42,7 +46,7 @@ bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) { Slot = FirstDerivedTyID + (&*I - &ModuleTypeValues[0]); } } - //cerr << "getTypeSlot '" << Ty->getName() << "' = " << Slot << endl; + //cerr << "getTypeSlot '" << Ty->getName() << "' = " << Slot << "\n"; return false; } @@ -50,7 +54,7 @@ const Type *BytecodeParser::getType(unsigned ID) { const Type *T = Type::getPrimitiveType((Type::PrimitiveID)ID); if (T) return T; - //cerr << "Looking up Type ID: " << ID << endl; + //cerr << "Looking up Type ID: " << ID << "\n"; const Value *D = getValue(Type::TypeTy, ID, false); if (D == 0) return failure(0); @@ -58,7 +62,7 @@ const Type *BytecodeParser::getType(unsigned ID) { return cast(D); } -int BytecodeParser::insertValue(Value *Val, vector &ValueTab) { +int BytecodeParser::insertValue(Value *Val, std::vector &ValueTab) { unsigned type; if (getTypeSlot(Val->getType(), type)) return failure(-1); assert(type != Type::TypeTyID && "Types should never be insertValue'd!"); @@ -67,7 +71,7 @@ int BytecodeParser::insertValue(Value *Val, vector &ValueTab) { ValueTab.resize(type+1, ValueList()); //cerr << "insertValue Values[" << type << "][" << ValueTab[type].size() - // << "] = " << Val << endl; + // << "] = " << Val << "\n"; ValueTab[type].push_back(Val); return ValueTab[type].size()-1; @@ -115,7 +119,7 @@ Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) { case Type::LabelTyID: d = new BBPHolder(Ty, oNum); break; case Type::MethodTyID: cerr << "Creating method pholder! : " << type << ":" << oNum << " " - << Ty->getName() << endl; + << Ty->getName() << "\n"; d = new MethPHolder(Ty, oNum); if (insertValue(d, LateResolveModuleValues) ==-1) return failure(0); return d; @@ -196,17 +200,17 @@ bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf, // Symtab entry: [def slot #][name] unsigned slot; if (read_vbr(Buf, EndBuf, slot)) return failure(true); - string Name; + std::string Name; if (read(Buf, EndBuf, Name, false)) // Not aligned... return failure(true); Value *D = getValue(Ty, slot, false); // Find mapping... if (D == 0) { - BCR_TRACE(3, "FAILED LOOKUP: Slot #" << slot << endl); + BCR_TRACE(3, "FAILED LOOKUP: Slot #" << slot << "\n"); return failure(true); } BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << D; - if (!isa(D)) cerr << endl); + if (!isa(D)) cerr << "\n"); D->setName(Name, ST); } @@ -272,7 +276,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, MethodSignatureList.pop_front(); Method *M = new Method(MTy, isInternal != 0); - BCR_TRACE(2, "METHOD TYPE: " << MTy << endl); + BCR_TRACE(2, "METHOD TYPE: " << MTy << "\n"); const MethodType::ParamTypes &Params = MTy->getParamTypes(); for (MethodType::ParamTypes::const_iterator It = Params.begin(); @@ -418,7 +422,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, DeclareNewGlobalValue(GV, unsigned(DestSlot)); BCR_TRACE(2, "Global Variable of type: " << PTy->getDescription() - << " into slot #" << DestSlot << endl); + << " into slot #" << DestSlot << "\n"); if (read_vbr(Buf, End, VarType)) return failure(true); } @@ -459,7 +463,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, MethodSignatureList.push_back( make_pair(cast(Val->getType()), SlotNo)); if (read_vbr(Buf, End, MethSignature)) return failure(true); - BCR_TRACE(2, "Method of type: " << Ty << endl); + BCR_TRACE(2, "Method of type: " << Ty << "\n"); } if (align32(Buf, End)) return failure(true); @@ -566,11 +570,11 @@ Module *ParseBytecodeBuffer(const uchar *Buffer, unsigned Length) { // Parse and return a class file... // -Module *ParseBytecodeFile(const string &Filename, string *ErrorStr) { +Module *ParseBytecodeFile(const std::string &Filename, std::string *ErrorStr) { struct stat StatBuf; Module *Result = 0; - if (Filename != string("-")) { // Read from a file... + if (Filename != std::string("-")) { // Read from a file... int FD = open(Filename.c_str(), O_RDONLY); if (FD == -1) { if (ErrorStr) *ErrorStr = "Error opening file!"; diff --git a/lib/Bytecode/Reader/ReaderInternals.h b/lib/Bytecode/Reader/ReaderInternals.h index 6abaa2e56ba..8a7297a8b3d 100644 --- a/lib/Bytecode/Reader/ReaderInternals.h +++ b/lib/Bytecode/Reader/ReaderInternals.h @@ -21,7 +21,7 @@ #if TRACE_LEVEL // ByteCodeReading_TRACEer #include "llvm/Assembly/Writer.h" -#define BCR_TRACE(n, X) if (n < TRACE_LEVEL) cerr << string(n*2, ' ') << X +#define BCR_TRACE(n, X) if (n < TRACE_LEVEL) cerr << std::string(n*2, ' ') << X #else #define BCR_TRACE(n, X) #endif @@ -41,12 +41,12 @@ struct RawInst { // The raw fields out of the bytecode stream... unsigned Arg1, Arg2; union { unsigned Arg3; - vector *VarArgs; // Contains arg #3,4,5... if NumOperands > 3 + std::vector *VarArgs; // Contains arg #3,4,5... if NumOperands > 3 }; }; class BytecodeParser : public AbstractTypeUser { - string Error; // Error message string goes here... + std::string Error; // Error message string goes here... public: BytecodeParser() { // Define this in case we don't see a ModuleGlobalInfo block. @@ -55,13 +55,13 @@ public: Module *ParseBytecode(const uchar *Buf, const uchar *EndBuf); - string getError() const { return Error; } + std::string getError() const { return Error; } private: // All of this data is transient across calls to ParseBytecode Module *TheModule; // Current Module being read into... - typedef vector ValueList; - typedef vector ValueTable; + typedef std::vector ValueList; + typedef std::vector ValueTable; ValueTable Values, LateResolveValues; ValueTable ModuleValues, LateResolveModuleValues; @@ -70,14 +70,14 @@ private: // All of this data is transient across calls to ParseBytecode // are defined, and if so, the temporary object that they represent is held // here. // - typedef map, GlobalVariable*> - GlobalRefsType; + typedef std::map, + GlobalVariable*> GlobalRefsType; GlobalRefsType GlobalRefs; // TypesLoaded - This vector mirrors the Values[TypeTyID] plane. It is used // to deal with forward references to types. // - typedef vector > TypeValuesListTy; + typedef std::vector > TypeValuesListTy; TypeValuesListTy ModuleTypeValues; TypeValuesListTy MethodTypeValues; @@ -89,11 +89,11 @@ private: // All of this data is transient across calls to ParseBytecode // into its slot to reserve it. When the method is loaded, this placeholder // is replaced. // - list > MethodSignatureList; + std::list > MethodSignatureList; private: - bool ParseModule (const uchar * Buf, const uchar *End, Module *&); - bool ParseModuleGlobalInfo (const uchar *&Buf, const uchar *End, Module *); + bool ParseModule (const uchar * Buf, const uchar *End, Module *&); + bool ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, Module *); bool ParseSymbolTable (const uchar *&Buf, const uchar *End, SymbolTable *); bool ParseMethod (const uchar *&Buf, const uchar *End, Module *); bool ParseBasicBlock (const uchar *&Buf, const uchar *End, BasicBlock *&); @@ -111,7 +111,7 @@ private: Value *getValue(const Type *Ty, unsigned num, bool Create = true); const Type *getType(unsigned ID); - int insertValue(Value *D, vector &D); // -1 = Failure + int insertValue(Value *D, std::vector &D); // -1 = Failure bool postResolveValues(ValueTable &ValTab); bool getTypeSlot(const Type *Ty, unsigned &Slot); diff --git a/lib/Bytecode/Writer/ConstantWriter.cpp b/lib/Bytecode/Writer/ConstantWriter.cpp index bcfa9765731..73130f3ee87 100644 --- a/lib/Bytecode/Writer/ConstantWriter.cpp +++ b/lib/Bytecode/Writer/ConstantWriter.cpp @@ -13,6 +13,8 @@ #include "llvm/ConstantVals.h" #include "llvm/SymbolTable.h" #include "llvm/DerivedTypes.h" +#include +using std::cerr; void BytecodeWriter::outputType(const Type *T) { output_vbr((unsigned)T->getPrimitiveID(), Out); @@ -134,7 +136,7 @@ bool BytecodeWriter::outputConstant(const Constant *CPV) { case Type::StructTyID: { const ConstantStruct *CPS = cast(CPV); - const vector &Vals = CPS->getValues(); + const std::vector &Vals = CPS->getValues(); for (unsigned i = 0; i < Vals.size(); ++i) { int Slot = Table.getValSlot(Vals[i]); diff --git a/lib/Bytecode/Writer/InstructionWriter.cpp b/lib/Bytecode/Writer/InstructionWriter.cpp index 825fde6a16b..f047ab5e1c5 100644 --- a/lib/Bytecode/Writer/InstructionWriter.cpp +++ b/lib/Bytecode/Writer/InstructionWriter.cpp @@ -28,7 +28,7 @@ typedef unsigned char uchar; // static void outputInstructionFormat0(const Instruction *I, const SlotCalculator &Table, - unsigned Type, deque &Out) { + unsigned Type, std::deque &Out) { // Opcode must have top two bits clear... output_vbr(I->getOpcode() << 2, Out); // Instruction Opcode ID output_vbr(Type, Out); // Result type @@ -63,7 +63,7 @@ static void outputInstructionFormat0(const Instruction *I, // static void outputInstrVarArgsCall(const Instruction *I, const SlotCalculator &Table, unsigned Type, - deque &Out) { + std::deque &Out) { assert(isa(I) || isa(I)); // Opcode must have top two bits clear... output_vbr(I->getOpcode() << 2, Out); // Instruction Opcode ID @@ -106,7 +106,7 @@ static void outputInstrVarArgsCall(const Instruction *I, // static void outputInstructionFormat1(const Instruction *I, const SlotCalculator &Table, int *Slots, - unsigned Type, deque &Out) { + unsigned Type, std::deque &Out) { unsigned Opcode = I->getOpcode(); // Instruction Opcode ID // bits Instruction format: @@ -127,7 +127,7 @@ static void outputInstructionFormat1(const Instruction *I, // static void outputInstructionFormat2(const Instruction *I, const SlotCalculator &Table, int *Slots, - unsigned Type, deque &Out) { + unsigned Type, std::deque &Out) { unsigned Opcode = I->getOpcode(); // Instruction Opcode ID // bits Instruction format: @@ -151,7 +151,7 @@ static void outputInstructionFormat2(const Instruction *I, // static void outputInstructionFormat3(const Instruction *I, const SlotCalculator &Table, int *Slots, - unsigned Type, deque &Out) { + unsigned Type, std::deque &Out) { unsigned Opcode = I->getOpcode(); // Instruction Opcode ID // bits Instruction format: diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp index ede822846d3..4738f712a16 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/SlotCalculator.cpp @@ -196,7 +196,8 @@ void SlotCalculator::purgeMethod() { while (CurPlane.size() != ModuleSize) { //SC_DEBUG(" Removing [" << i << "] Value=" << CurPlane.back() << "\n"); - map::iterator NI = NodeMap.find(CurPlane.back()); + std::map::iterator NI = + NodeMap.find(CurPlane.back()); assert(NI != NodeMap.end() && "Node not in nodemap?"); NodeMap.erase(NI); // Erase from nodemap CurPlane.pop_back(); // Shrink plane @@ -223,7 +224,7 @@ void SlotCalculator::purgeMethod() { } int SlotCalculator::getValSlot(const Value *D) const { - map::const_iterator I = NodeMap.find(D); + std::map::const_iterator I = NodeMap.find(D); if (I == NodeMap.end()) return -1; return (int)I->second; diff --git a/lib/Bytecode/Writer/SlotCalculator.h b/lib/Bytecode/Writer/SlotCalculator.h index c7b3149054c..95282447a5f 100644 --- a/lib/Bytecode/Writer/SlotCalculator.h +++ b/lib/Bytecode/Writer/SlotCalculator.h @@ -23,14 +23,14 @@ class SlotCalculator { const Module *TheModule; bool IgnoreNamedNodes; // Shall we not count named nodes? - typedef vector TypePlane; - vector Table; - map NodeMap; + typedef std::vector TypePlane; + std::vector Table; + std::map NodeMap; // ModuleLevel - Used to keep track of which values belong to the module, // and which values belong to the currently incorporated method. // - vector ModuleLevel; + std::vector ModuleLevel; public: SlotCalculator(const Module *M, bool IgnoreNamed); diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index 3091384722b..9ea5d37451d 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -34,7 +34,7 @@ #include #include -BytecodeWriter::BytecodeWriter(deque &o, const Module *M) +BytecodeWriter::BytecodeWriter(std::deque &o, const Module *M) : Out(o), Table(M, false) { outputSignature(); @@ -66,7 +66,7 @@ void BytecodeWriter::outputConstants(bool isMethod) { unsigned NumPlanes = Table.getNumPlanes(); for (unsigned pno = 0; pno < NumPlanes; pno++) { - const vector &Plane = Table.getPlane(pno); + const std::vector &Plane = Table.getPlane(pno); if (Plane.empty()) continue; // Skip empty type planes... unsigned ValNo = 0; @@ -95,8 +95,8 @@ void BytecodeWriter::outputConstants(bool isMethod) { assert (Slot != -1 && "Type in constant pool but not in method!!"); output_vbr((unsigned)Slot, Out); - //cout << "Emitting " << NC << " constants of type '" - // << Plane.front()->getType()->getName() << "' = Slot #" << Slot << endl; + //cerr << "Emitting " << NC << " constants of type '" + // << Plane.front()->getType()->getName() << "' = Slot #" << Slot << "\n"; for (unsigned i = ValNo; i < ValNo+NC; ++i) { const Value *V = Plane[i]; @@ -211,7 +211,7 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) { void WriteBytecodeToFile(const Module *C, ostream &Out) { assert(C && "You can't write a null module!!"); - deque Buffer; + std::deque Buffer; // This object populates buffer for us... BytecodeWriter BCW(Buffer, C); @@ -220,7 +220,7 @@ void WriteBytecodeToFile(const Module *C, ostream &Out) { // sequential in memory, however, so write out as much as possible in big // chunks, until we're done. // - deque::const_iterator I = Buffer.begin(), E = Buffer.end(); + std::deque::const_iterator I = Buffer.begin(),E = Buffer.end(); while (I != E) { // Loop until it's all written // Scan to see how big this chunk is... const unsigned char *ChunkPtr = &*I; @@ -235,7 +235,7 @@ void WriteBytecodeToFile(const Module *C, ostream &Out) { } // Write out the chunk... - Out.write(ChunkPtr, LastPtr-ChunkPtr); + Out.write((char*)ChunkPtr, LastPtr-ChunkPtr); } Out.flush(); diff --git a/lib/Bytecode/Writer/WriterInternals.h b/lib/Bytecode/Writer/WriterInternals.h index 8a929870f40..10170305b34 100644 --- a/lib/Bytecode/Writer/WriterInternals.h +++ b/lib/Bytecode/Writer/WriterInternals.h @@ -20,10 +20,10 @@ #include class BytecodeWriter { - deque &Out; + std::deque &Out; SlotCalculator Table; public: - BytecodeWriter(deque &o, const Module *M); + BytecodeWriter(std::deque &o, const Module *M); protected: void outputConstants(bool isMethod); @@ -51,12 +51,12 @@ private : // class BytecodeBlock { unsigned Loc; - deque &Out; + std::deque &Out; BytecodeBlock(const BytecodeBlock &); // do not implement void operator=(const BytecodeBlock &); // do not implement public: - inline BytecodeBlock(unsigned ID, deque &o) : Out(o) { + inline BytecodeBlock(unsigned ID, std::deque &o) : Out(o) { output(ID, Out); output((unsigned)0, Out); // Reserve the space for the block size... Loc = Out.size(); diff --git a/lib/CodeGen/InstrSched/InstrScheduling.cpp b/lib/CodeGen/InstrSched/InstrScheduling.cpp index 528e5abdd34..ea41b6f8222 100644 --- a/lib/CodeGen/InstrSched/InstrScheduling.cpp +++ b/lib/CodeGen/InstrSched/InstrScheduling.cpp @@ -18,10 +18,12 @@ #include "llvm/Instruction.h" #include "Support/CommandLine.h" #include "SchedPriorities.h" -#include #include #include - +#include +#include +using std::cerr; +using std::vector; //************************* External Data Types *****************************/ @@ -353,11 +355,11 @@ private: unsigned int totalInstrCount; cycles_t curTime; cycles_t nextEarliestIssueTime; // next cycle we can issue - vector > choicesForSlot; // indexed by slot# + vector > choicesForSlot; // indexed by slot# vector choiceVec; // indexed by node ptr vector numInClass; // indexed by sched class vector nextEarliestStartTime; // indexed by opCode - hash_map delaySlotInfoForBranches; + std::hash_map delaySlotInfoForBranches; // indexed by branch node ptr public: @@ -419,7 +421,7 @@ public: return choiceVec[i]; } - inline hash_set& getChoicesForSlot(unsigned slotNum) { + inline std::hash_set& getChoicesForSlot(unsigned slotNum) { assert(slotNum < nslots); return choicesForSlot[slotNum]; } @@ -495,7 +497,7 @@ public: bool createIfMissing=false) { DelaySlotInfo* dinfo; - hash_map::const_iterator + std::hash_map::const_iterator I = delaySlotInfoForBranches.find(bn); if (I == delaySlotInfoForBranches.end()) { @@ -552,7 +554,7 @@ SchedulingManager::updateEarliestStartTimes(const SchedGraphNode* node, { if (schedInfo.numBubblesAfter(node->getOpCode()) > 0) { // Update next earliest time before which *nothing* can issue. - nextEarliestIssueTime = max(nextEarliestIssueTime, + nextEarliestIssueTime = std::max(nextEarliestIssueTime, curTime + 1 + schedInfo.numBubblesAfter(node->getOpCode())); } @@ -603,7 +605,7 @@ AssignInstructionsToSlots(class SchedulingManager& S, unsigned maxIssue) unsigned numIssued; for (numIssued = 0; numIssued < maxIssue; numIssued++) { - int chosenSlot = -1, chosenNodeIndex = -1; + int chosenSlot = -1; for (unsigned s=startSlot; s < S.nslots; s++) if ((*igroup)[s] == NULL && S.getChoicesForSlot(s).size() == 1) { @@ -877,7 +879,7 @@ FindSlotChoices(SchedulingManager& S, assert(s < S.nslots && "No feasible slot for instruction?"); - highestSlotUsed = max(highestSlotUsed, (int) s); + highestSlotUsed = std::max(highestSlotUsed, (int) s); } assert(highestSlotUsed <= (int) S.nslots-1 && "Invalid slot used?"); @@ -961,7 +963,6 @@ FindSlotChoices(SchedulingManager& S, // Otherwise, just ignore the instruction. for (unsigned i=indexForBreakingNode+1; i < S.getNumChoices(); i++) { - bool foundLowerSlot = false; MachineOpCode opCode = S.getChoice(i)->getOpCode(); for (unsigned int s=startSlot; s < nslotsToUse; s++) if (S.schedInfo.instrCanUseSlot(opCode, s)) @@ -1001,15 +1002,15 @@ ChooseOneGroup(SchedulingManager& S) { for (cycles_t c = firstCycle; c <= S.getTime(); c++) { - cout << " Cycle " << c << " : Scheduled instructions:\n"; + cerr << " Cycle " << (long)c << " : Scheduled instructions:\n"; const InstrGroup* igroup = S.isched.getIGroup(c); for (unsigned int s=0; s < S.nslots; s++) { - cout << " "; + cerr << " "; if ((*igroup)[s] != NULL) - cout << * ((*igroup)[s])->getMachineInstr() << endl; + cerr << * ((*igroup)[s])->getMachineInstr() << "\n"; else - cout << "" << endl; + cerr << "\n"; } } } @@ -1056,9 +1057,9 @@ ForwardListSchedule(SchedulingManager& S) // an instruction can be issued, or the next earliest in which // one will be ready, or to the next cycle, whichever is latest. // - S.updateTime(max(S.getTime() + 1, - max(S.getEarliestIssueTime(), - S.schedPrio.getEarliestReadyTime()))); + S.updateTime(std::max(S.getTime() + 1, + std::max(S.getEarliestIssueTime(), + S.schedPrio.getEarliestReadyTime()))); } } @@ -1499,8 +1500,7 @@ ScheduleInstructionsWithSSA(Method* method, if (SchedDebugLevel >= Sched_PrintSchedGraphs) { - cout << endl << "*** SCHEDULING GRAPHS FOR INSTRUCTION SCHEDULING" - << endl; + cerr << "\n*** SCHEDULING GRAPHS FOR INSTRUCTION SCHEDULING\n"; graphSet.dump(); } @@ -1513,7 +1513,7 @@ ScheduleInstructionsWithSSA(Method* method, const BasicBlock* bb = bbvec[0]; if (SchedDebugLevel >= Sched_PrintSchedTrace) - cout << endl << "*** TRACE OF INSTRUCTION SCHEDULING OPERATIONS\n\n"; + cerr << "\n*** TRACE OF INSTRUCTION SCHEDULING OPERATIONS\n\n"; SchedPriorities schedPrio(method, graph); // expensive! SchedulingManager S(target, graph, schedPrio); @@ -1527,8 +1527,7 @@ ScheduleInstructionsWithSSA(Method* method, if (SchedDebugLevel >= Sched_PrintMachineCode) { - cout << endl - << "*** Machine instructions after INSTRUCTION SCHEDULING" << endl; + cerr << "\n*** Machine instructions after INSTRUCTION SCHEDULING\n"; MachineCodeForMethod::get(method).dump(); } diff --git a/lib/CodeGen/InstrSched/SchedGraph.cpp b/lib/CodeGen/InstrSched/SchedGraph.cpp index 9e9af5b80d8..7c83e1a58c8 100644 --- a/lib/CodeGen/InstrSched/SchedGraph.cpp +++ b/lib/CodeGen/InstrSched/SchedGraph.cpp @@ -23,10 +23,16 @@ #include "llvm/Target/MachineRegInfo.h" #include "llvm/iOther.h" #include "Support/StringExtras.h" +#include "Support/STLExtras.h" #include -#include #include +#include +#include +using std::vector; +using std::pair; +using std::hash_map; +using std::cerr; //*********************** Internal Data Structures *************************/ @@ -132,7 +138,7 @@ SchedGraphEdge::~SchedGraphEdge() } void SchedGraphEdge::dump(int indent=0) const { - cout << string(indent*2, ' ') << *this; + cerr << std::string(indent*2, ' ') << *this; } @@ -168,7 +174,7 @@ SchedGraphNode::~SchedGraphNode() } void SchedGraphNode::dump(int indent=0) const { - cout << string(indent*2, ' ') << *this; + cerr << std::string(indent*2, ' ') << *this; } @@ -222,21 +228,20 @@ SchedGraph::SchedGraph(const BasicBlock* bb, const TargetMachine& target) { bbVec.push_back(bb); - this->buildGraph(target); + buildGraph(target); } /*dtor*/ SchedGraph::~SchedGraph() { - for (iterator I=begin(); I != end(); ++I) + for (const_iterator I = begin(); I != end(); ++I) { - SchedGraphNode* node = (*I).second; + SchedGraphNode *node = I->second; // for each node, delete its out-edges - for (SchedGraphNode::iterator I = node->beginOutEdges(); - I != node->endOutEdges(); ++I) - delete *I; + std::for_each(node->beginOutEdges(), node->endOutEdges(), + deleter); // then delete the node itself. delete node; @@ -247,24 +252,24 @@ SchedGraph::~SchedGraph() void SchedGraph::dump() const { - cout << " Sched Graph for Basic Blocks: "; + cerr << " Sched Graph for Basic Blocks: "; for (unsigned i=0, N=bbVec.size(); i < N; i++) { - cout << (bbVec[i]->hasName()? bbVec[i]->getName() : "block") + cerr << (bbVec[i]->hasName()? bbVec[i]->getName() : "block") << " (" << bbVec[i] << ")" << ((i == N-1)? "" : ", "); } - cout << endl << endl << " Actual Root nodes : "; + cerr << "\n\n Actual Root nodes : "; for (unsigned i=0, N=graphRoot->outEdges.size(); i < N; i++) - cout << graphRoot->outEdges[i]->getSink()->getNodeId() + cerr << graphRoot->outEdges[i]->getSink()->getNodeId() << ((i == N-1)? "" : ", "); - cout << endl << " Graph Nodes:" << endl; + cerr << "\n Graph Nodes:\n"; for (const_iterator I=begin(); I != end(); ++I) - cout << endl << * (*I).second; + cerr << "\n" << *I->second; - cout << endl; + cerr << "\n"; } @@ -690,7 +695,7 @@ SchedGraph::addNonSSAEdgesForValue(const Instruction* instr, // this operand is a definition or use of value `instr' SchedGraphNode* node = this->getGraphNodeForInstr(mvec[i]); assert(node && "No node for machine instruction in this BB?"); - refVec.push_back(make_pair(node, o)); + refVec.push_back(std::make_pair(node, o)); } } @@ -747,8 +752,8 @@ SchedGraph::findDefUseInfoAtInstr(const TargetMachine& target, { int regNum = mop.getMachineRegNum(); if (regNum != target.getRegInfo().getZeroRegNum()) - regToRefVecMap[mop.getMachineRegNum()].push_back(make_pair(node, - i)); + regToRefVecMap[mop.getMachineRegNum()].push_back( + std::make_pair(node, i)); continue; // nothing more to do } @@ -762,7 +767,7 @@ SchedGraph::findDefUseInfoAtInstr(const TargetMachine& target, && "Do not expect any other kind of operand to be defined!"); const Instruction* defInstr = cast(mop.getVRegValue()); - valueToDefVecMap[defInstr].push_back(make_pair(node, i)); + valueToDefVecMap[defInstr].push_back(std::make_pair(node, i)); } // @@ -774,7 +779,7 @@ SchedGraph::findDefUseInfoAtInstr(const TargetMachine& target, if (const Instruction* defInstr = dyn_cast_or_null(minstr.getImplicitRef(i))) { - valueToDefVecMap[defInstr].push_back(make_pair(node, -i)); + valueToDefVecMap[defInstr].push_back(std::make_pair(node, -i)); } } @@ -860,7 +865,6 @@ SchedGraph::buildNodesforBB(const TargetMachine& target, void SchedGraph::buildGraph(const TargetMachine& target) { - const MachineInstrInfo& mii = target.getInstrInfo(); const BasicBlock* bb = bbVec[0]; assert(bbVec.size() == 1 && "Only handling a single basic block here"); @@ -966,24 +970,22 @@ SchedGraphSet::SchedGraphSet(const Method* _method, SchedGraphSet::~SchedGraphSet() { // delete all the graphs - for (iterator I=begin(); I != end(); ++I) - delete (*I).second; + for (const_iterator I = begin(); I != end(); ++I) + delete I->second; } void SchedGraphSet::dump() const { - cout << "======== Sched graphs for method `" - << (method->hasName()? method->getName() : "???") - << "' ========" << endl << endl; + cerr << "======== Sched graphs for method `" << method->getName() + << "' ========\n\n"; for (const_iterator I=begin(); I != end(); ++I) - (*I).second->dump(); + I->second->dump(); - cout << endl << "====== End graphs for method `" - << (method->hasName()? method->getName() : "") - << "' ========" << endl << endl; + cerr << "\n====== End graphs for method `" << method->getName() + << "' ========\n\n"; } @@ -1000,8 +1002,7 @@ SchedGraphSet::buildGraphsForMethod(const Method *method, -ostream& -operator<<(ostream& os, const SchedGraphEdge& edge) +std::ostream &operator<<(std::ostream &os, const SchedGraphEdge& edge) { os << "edge [" << edge.src->getNodeId() << "] -> [" << edge.sink->getNodeId() << "] : "; @@ -1015,33 +1016,30 @@ operator<<(ostream& os, const SchedGraphEdge& edge) default: assert(0); break; } - os << " : delay = " << edge.minDelay << endl; + os << " : delay = " << edge.minDelay << "\n"; return os; } -ostream& -operator<<(ostream& os, const SchedGraphNode& node) +std::ostream &operator<<(std::ostream &os, const SchedGraphNode& node) { - os << string(8, ' ') + os << std::string(8, ' ') << "Node " << node.nodeId << " : " - << "latency = " << node.latency << endl << string(12, ' '); + << "latency = " << node.latency << "\n" << std::string(12, ' '); if (node.getMachineInstr() == NULL) - os << "(Dummy node)" << endl; + os << "(Dummy node)\n"; else { - os << *node.getMachineInstr() << endl << string(12, ' '); - os << node.inEdges.size() << " Incoming Edges:" << endl; + os << *node.getMachineInstr() << "\n" << std::string(12, ' '); + os << node.inEdges.size() << " Incoming Edges:\n"; for (unsigned i=0, N=node.inEdges.size(); i < N; i++) - os << string(16, ' ') << *node.inEdges[i]; + os << std::string(16, ' ') << *node.inEdges[i]; - os << string(12, ' ') << node.outEdges.size() - << " Outgoing Edges:" << endl; + os << std::string(12, ' ') << node.outEdges.size() + << " Outgoing Edges:\n"; for (unsigned i=0, N=node.outEdges.size(); i < N; i++) - { - os << string(16, ' ') << * node.outEdges[i]; - } + os << std::string(16, ' ') << *node.outEdges[i]; } return os; diff --git a/lib/CodeGen/InstrSched/SchedGraph.h b/lib/CodeGen/InstrSched/SchedGraph.h index a4567a5198f..2890241d59d 100644 --- a/lib/CodeGen/InstrSched/SchedGraph.h +++ b/lib/CodeGen/InstrSched/SchedGraph.h @@ -24,7 +24,7 @@ #include "Support/NonCopyable.h" #include "Support/HashExtras.h" #include "Support/GraphTraits.h" -#include +#include class Value; class Instruction; @@ -128,7 +128,7 @@ public: // // Debugging support // - friend ostream& operator<<(ostream& os, const SchedGraphEdge& edge); + friend std::ostream& operator<<(std::ostream& os, const SchedGraphEdge& edge); void dump (int indent=0) const; @@ -144,16 +144,16 @@ private: unsigned int nodeId; const BasicBlock* bb; const MachineInstr* minstr; - vector inEdges; - vector outEdges; + std::vector inEdges; + std::vector outEdges; int origIndexInBB; // original position of machine instr in BB int latency; public: - typedef vector:: iterator iterator; - typedef vector::const_iterator const_iterator; - typedef vector:: reverse_iterator reverse_iterator; - typedef vector::const_reverse_iterator const_reverse_iterator; + typedef std::vector:: iterator iterator; + typedef std::vector::const_iterator const_iterator; + typedef std::vector:: reverse_iterator reverse_iterator; + typedef std::vector::const_reverse_iterator const_reverse_iterator; public: // @@ -186,7 +186,7 @@ public: // // Debugging support // - friend ostream& operator<<(ostream& os, const SchedGraphNode& node); + friend std::ostream& operator<<(std::ostream& os, const SchedGraphNode& node); void dump (int indent=0) const; @@ -214,22 +214,23 @@ private: class SchedGraph : public NonCopyable, - private hash_map + private std::hash_map { private: - vector bbVec; // basic blocks included in the graph + std::vector bbVec; // basic blocks included in the graph SchedGraphNode* graphRoot; // the root and leaf are not inserted SchedGraphNode* graphLeaf; // in the hash_map (see getNumNodes()) + typedef std::hash_map map_base; public: - typedef hash_map::iterator iterator; - typedef hash_map::const_iterator const_iterator; + using map_base::iterator; + using map_base::const_iterator; public: // // Accessor methods // - const vector& getBasicBlocks() const { return bbVec; } + const std::vector& getBasicBlocks() const { return bbVec; } const unsigned int getNumNodes() const { return size()+2; } SchedGraphNode* getRoot() const { return graphRoot; } SchedGraphNode* getLeaf() const { return graphLeaf; } @@ -257,19 +258,9 @@ public: // Unordered iterators. // Return values is pair. // - iterator begin() { - return hash_map::begin(); - } - iterator end() { - return hash_map::end(); - } - const_iterator begin() const { - return hash_map::begin(); - } - const_iterator end() const { - return hash_map::end(); - } - + using map_base::begin; + using map_base::end; + // // Ordered iterators. // Return values is pair. @@ -308,13 +299,13 @@ private: void buildNodesforBB (const TargetMachine& target, const BasicBlock* bb, - vector& memNodeVec, + std::vector& memNod, RegToRefVecMap& regToRefVecMap, ValueToDefVecMap& valueToDefVecMap); void findDefUseInfoAtInstr (const TargetMachine& target, SchedGraphNode* node, - vector& memNodeVec, + std::vector& memNode, RegToRefVecMap& regToRefVecMap, ValueToDefVecMap& valueToDefVecMap); @@ -325,10 +316,10 @@ private: void addCDEdges (const TerminatorInst* term, const TargetMachine& target); - void addMemEdges (const vector& memNodeVec, + void addMemEdges (const std::vector& memNod, const TargetMachine& target); - void addCallCCEdges (const vector& memNodeVec, + void addCallCCEdges (const std::vector& memNod, MachineCodeForBasicBlock& bbMvec, const TargetMachine& target); @@ -347,14 +338,15 @@ private: class SchedGraphSet : public NonCopyable, - private hash_map + private std::hash_map { private: const Method* method; public: - typedef hash_map::iterator iterator; - typedef hash_map::const_iterator const_iterator; + typedef std::hash_map map_base; + using map_base::iterator; + using map_base::const_iterator; public: /*ctor*/ SchedGraphSet (const Method* _method, @@ -372,18 +364,8 @@ public: // // Iterators // - iterator begin() { - return hash_map::begin(); - } - iterator end() { - return hash_map::end(); - } - const_iterator begin() const { - return hash_map::begin(); - } - const_iterator end() const { - return hash_map::end(); - } + using map_base::begin; + using map_base::end; // // Debugging support @@ -544,14 +526,7 @@ template <> struct GraphTraits { }; -//************************ External Functions *****************************/ - - -ostream& operator<<(ostream& os, const SchedGraphEdge& edge); - -ostream& operator<<(ostream& os, const SchedGraphNode& node); - - -/***************************************************************************/ +std::ostream &operator<<(std::ostream& os, const SchedGraphEdge& edge); +std::ostream &operator<<(std::ostream &os, const SchedGraphNode& node); #endif diff --git a/lib/CodeGen/InstrSched/SchedPriorities.cpp b/lib/CodeGen/InstrSched/SchedPriorities.cpp index 17697072381..8cde2521151 100644 --- a/lib/CodeGen/InstrSched/SchedPriorities.cpp +++ b/lib/CodeGen/InstrSched/SchedPriorities.cpp @@ -20,20 +20,17 @@ #include "SchedPriorities.h" #include "Support/PostOrderIterator.h" - +#include +using std::cerr; SchedPriorities::SchedPriorities(const Method* method, const SchedGraph* _graph) : curTime(0), graph(_graph), - methodLiveVarInfo(method), // expensive! - lastUseMap(), - nodeDelayVec(_graph->getNumNodes(),INVALID_LATENCY), //make errors obvious + methodLiveVarInfo(method), // expensive! + nodeDelayVec(_graph->getNumNodes(), INVALID_LATENCY), // make errors obvious earliestForNode(_graph->getNumNodes(), 0), earliestReadyTime(0), - candsAsHeap(), - candsAsSet(), - mcands(), nextToTry(candsAsHeap.begin()) { methodLiveVarInfo.analyze(); @@ -66,7 +63,7 @@ SchedPriorities::computeDelays(const SchedGraph* graph) E != node->endOutEdges(); ++E) { cycles_t sinkDelay = getNodeDelayRef((*E)->getSink()); - nodeDelay = max(nodeDelay, sinkDelay + (*E)->getMinDelay()); + nodeDelay = std::max(nodeDelay, sinkDelay + (*E)->getMinDelay()); } } getNodeDelayRef(node) = nodeDelay; @@ -87,20 +84,37 @@ SchedPriorities::initializeReadyHeap(const SchedGraph* graph) #undef TEST_HEAP_CONVERSION #ifdef TEST_HEAP_CONVERSION - cout << "Before heap conversion:" << endl; + cerr << "Before heap conversion:\n"; copy(candsAsHeap.begin(), candsAsHeap.end(), - ostream_iterator(cout,"\n")); + ostream_iterator(cerr,"\n")); #endif candsAsHeap.makeHeap(); #ifdef TEST_HEAP_CONVERSION - cout << "After heap conversion:" << endl; + cerr << "After heap conversion:\n"; copy(candsAsHeap.begin(), candsAsHeap.end(), - ostream_iterator(cout,"\n")); + ostream_iterator(cerr,"\n")); #endif } +void +SchedPriorities::insertReady(const SchedGraphNode* node) +{ + candsAsHeap.insert(node, nodeDelayVec[node->getNodeId()]); + candsAsSet.insert(node); + mcands.clear(); // ensure reset choices is called before any more choices + earliestReadyTime = std::min(earliestReadyTime, + earliestForNode[node->getNodeId()]); + + if (SchedDebugLevel >= Sched_PrintSchedTrace) + { + cerr << " Cycle " << (long)getTime() << ": " + << " Node " << node->getNodeId() << " is ready; " + << " Delay = " << (long)getNodeDelayRef(node) << "; Instruction: \n"; + cerr << " " << *node->getMachineInstr() << "\n"; + } +} void SchedPriorities::issuedReadyNodeAt(cycles_t curTime, @@ -116,7 +130,7 @@ SchedPriorities::issuedReadyNodeAt(cycles_t curTime, for (NodeHeap::const_iterator I=candsAsHeap.begin(); I != candsAsHeap.end(); ++I) if (candsAsHeap.getNode(I)) - earliestReadyTime = min(earliestReadyTime, + earliestReadyTime = std::min(earliestReadyTime, getEarliestForNodeRef(candsAsHeap.getNode(I))); } @@ -125,7 +139,7 @@ SchedPriorities::issuedReadyNodeAt(cycles_t curTime, E != node->endOutEdges(); ++E) { cycles_t& etime = getEarliestForNodeRef((*E)->getSink()); - etime = max(etime, curTime + (*E)->getMinDelay()); + etime = std::max(etime, curTime + (*E)->getMinDelay()); } } @@ -140,14 +154,14 @@ SchedPriorities::issuedReadyNodeAt(cycles_t curTime, //---------------------------------------------------------------------- inline int -SchedPriorities::chooseByRule1(vector& mcands) +SchedPriorities::chooseByRule1(std::vector& mcands) { return (mcands.size() == 1)? 0 // only one choice exists so take it : -1; // -1 indicates multiple choices } inline int -SchedPriorities::chooseByRule2(vector& mcands) +SchedPriorities::chooseByRule2(std::vector& mcands) { assert(mcands.size() >= 1 && "Should have at least one candidate here."); for (unsigned i=0, N = mcands.size(); i < N; i++) @@ -158,7 +172,7 @@ SchedPriorities::chooseByRule2(vector& mcands) } inline int -SchedPriorities::chooseByRule3(vector& mcands) +SchedPriorities::chooseByRule3(std::vector& mcands) { assert(mcands.size() >= 1 && "Should have at least one candidate here."); int maxUses = candsAsHeap.getNode(mcands[0])->getNumOutEdges(); @@ -224,7 +238,7 @@ SchedPriorities::getNextHighest(const SchedulingManager& S, void -SchedPriorities::findSetWithMaxDelay(vector& mcands, +SchedPriorities::findSetWithMaxDelay(std::vector& mcands, const SchedulingManager& S) { if (mcands.size() == 0 && nextToTry != candsAsHeap.end()) @@ -240,12 +254,12 @@ SchedPriorities::findSetWithMaxDelay(vector& mcands, if (SchedDebugLevel >= Sched_PrintSchedTrace) { - cout << " Cycle " << this->getTime() << ": " - << "Next highest delay = " << maxDelay << " : " + cerr << " Cycle " << (long)getTime() << ": " + << "Next highest delay = " << (long)maxDelay << " : " << mcands.size() << " Nodes with this delay: "; for (unsigned i=0; i < mcands.size(); i++) - cout << candsAsHeap.getNode(mcands[i])->getNodeId() << ", "; - cout << endl; + cerr << candsAsHeap.getNode(mcands[i])->getNodeId() << ", "; + cerr << "\n"; } } } @@ -257,10 +271,10 @@ SchedPriorities::instructionHasLastUse(MethodLiveVarInfo& methodLiveVarInfo, { const MachineInstr* minstr = graphNode->getMachineInstr(); - hash_map::const_iterator + std::hash_map::const_iterator ui = lastUseMap.find(minstr); if (ui != lastUseMap.end()) - return (*ui).second; + return ui->second; // else check if instruction is a last use and save it in the hash_map bool hasLastUse = false; diff --git a/lib/CodeGen/InstrSched/SchedPriorities.h b/lib/CodeGen/InstrSched/SchedPriorities.h index 81a2e6a0534..a8b3e233976 100644 --- a/lib/CodeGen/InstrSched/SchedPriorities.h +++ b/lib/CodeGen/InstrSched/SchedPriorities.h @@ -26,6 +26,7 @@ #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" #include "llvm/Target/MachineSchedInfo.h" #include +#include class Method; class MachineInstr; @@ -36,22 +37,22 @@ struct NodeDelayPair { const SchedGraphNode* node; cycles_t delay; NodeDelayPair(const SchedGraphNode* n, cycles_t d) : node(n), delay(d) {} - inline bool operator< (const NodeDelayPair& np) { return delay < np.delay; } + inline bool operator<(const NodeDelayPair& np) { return delay < np.delay; } }; inline bool NDPLessThan(const NodeDelayPair* np1, const NodeDelayPair* np2) { - return (np1->delay < np2->delay); + return np1->delay < np2->delay; } -class NodeHeap: public list, public NonCopyable { +class NodeHeap: public std::list, public NonCopyable { public: - typedef list::iterator iterator; - typedef list::const_iterator const_iterator; + typedef std::list::iterator iterator; + typedef std::list::const_iterator const_iterator; public: - /*ctor*/ NodeHeap () : list(), _size(0) {} + /*ctor*/ NodeHeap () : std::list(), _size(0) {} /*dtor*/ ~NodeHeap () {} inline unsigned int size () const { return _size; } @@ -89,7 +90,7 @@ public: iterator I=begin(); for ( ; I != end() && getDelay(I) >= delay; ++I) ; - list::insert(I, ndp); + std::list::insert(I, ndp); } _size++; } @@ -131,22 +132,22 @@ private: cycles_t curTime; const SchedGraph* graph; MethodLiveVarInfo methodLiveVarInfo; - hash_map lastUseMap; - vector nodeDelayVec; - vector earliestForNode; + std::hash_map lastUseMap; + std::vector nodeDelayVec; + std::vector earliestForNode; cycles_t earliestReadyTime; NodeHeap candsAsHeap; // candidate nodes, ready to go - hash_set candsAsSet; // same entries as candsAsHeap, + std::hash_set candsAsSet;//same entries as candsAsHeap, // but as set for fast lookup - vector mcands; // holds pointers into cands + std::vector mcands; // holds pointers into cands candIndex nextToTry; // next cand after the last // one tried in this cycle - int chooseByRule1 (vector& mcands); - int chooseByRule2 (vector& mcands); - int chooseByRule3 (vector& mcands); + int chooseByRule1 (std::vector& mcands); + int chooseByRule2 (std::vector& mcands); + int chooseByRule3 (std::vector& mcands); - void findSetWithMaxDelay (vector& mcands, + void findSetWithMaxDelay (std::vector& mcands, const SchedulingManager& S); void computeDelays (const SchedGraph* graph); @@ -169,36 +170,15 @@ private: }; -inline void -SchedPriorities::insertReady(const SchedGraphNode* node) -{ - candsAsHeap.insert(node, nodeDelayVec[node->getNodeId()]); - candsAsSet.insert(node); - mcands.clear(); // ensure reset choices is called before any more choices - earliestReadyTime = min(earliestReadyTime, - earliestForNode[node->getNodeId()]); - - if (SchedDebugLevel >= Sched_PrintSchedTrace) - { - cout << " Cycle " << this->getTime() << ": " - << " Node " << node->getNodeId() << " is ready; " - << " Delay = " << this->getNodeDelayRef(node) << "; Instruction: " - << endl; - cout << " " << *node->getMachineInstr() << endl; - } -} - inline void SchedPriorities::updateTime(cycles_t c) { curTime = c; nextToTry = candsAsHeap.begin(); mcands.clear(); } -inline ostream& operator<< (ostream& os, const NodeDelayPair* nd) { +inline std::ostream &operator<<(std::ostream &os, const NodeDelayPair* nd) { return os << "Delay for node " << nd->node->getNodeId() - << " = " << nd->delay << endl; + << " = " << (long)nd->delay << "\n"; } -/***************************************************************************/ - #endif diff --git a/lib/CodeGen/InstrSelection/InstrForest.cpp b/lib/CodeGen/InstrSelection/InstrForest.cpp index ce3e2c3a3f7..20cbe8d71bf 100644 --- a/lib/CodeGen/InstrSelection/InstrForest.cpp +++ b/lib/CodeGen/InstrSelection/InstrForest.cpp @@ -31,6 +31,9 @@ #include "llvm/BasicBlock.h" #include "llvm/CodeGen/MachineInstr.h" #include "Support/STLExtras.h" +#include +using std::cerr; +using std::vector; //------------------------------------------------------------------------ // class InstrTreeNode @@ -119,21 +122,21 @@ void InstructionNode::dumpNode(int indent) const { for (int i=0; i < indent; i++) - cout << " "; + cerr << " "; - cout << getInstruction()->getOpcodeName(); + cerr << getInstruction()->getOpcodeName(); const vector &mvec = getInstruction()->getMachineInstrVec(); if (mvec.size() > 0) - cout << "\tMachine Instructions: "; + cerr << "\tMachine Instructions: "; for (unsigned int i=0; i < mvec.size(); i++) { mvec[i]->dump(0); if (i < mvec.size() - 1) - cout << "; "; + cerr << "; "; } - cout << endl; + cerr << "\n"; } @@ -141,9 +144,9 @@ void VRegListNode::dumpNode(int indent) const { for (int i=0; i < indent; i++) - cout << " "; + cerr << " "; - cout << "List" << endl; + cerr << "List" << "\n"; } @@ -151,29 +154,29 @@ void VRegNode::dumpNode(int indent) const { for (int i=0; i < indent; i++) - cout << " "; + cerr << " "; - cout << "VReg " << getValue() << "\t(type " - << (int) getValue()->getValueType() << ")" << endl; + cerr << "VReg " << getValue() << "\t(type " + << (int) getValue()->getValueType() << ")" << "\n"; } void ConstantNode::dumpNode(int indent) const { for (int i=0; i < indent; i++) - cout << " "; + cerr << " "; - cout << "Constant " << getValue() << "\t(type " - << (int) getValue()->getValueType() << ")" << endl; + cerr << "Constant " << getValue() << "\t(type " + << (int) getValue()->getValueType() << ")" << "\n"; } void LabelNode::dumpNode(int indent) const { for (int i=0; i < indent; i++) - cout << " "; + cerr << " "; - cout << "Label " << getValue() << endl; + cerr << "Label " << getValue() << "\n"; } //------------------------------------------------------------------------ @@ -190,7 +193,7 @@ InstrForest::InstrForest(Method *M) InstrForest::~InstrForest() { - for (hash_map:: iterator I = begin(); + for (std::hash_map::iterator I = begin(); I != end(); ++I) delete (*I).second; } @@ -198,7 +201,7 @@ InstrForest::~InstrForest() void InstrForest::dump() const { - for (hash_set::const_iterator I = treeRoots.begin(); + for (std::hash_set::const_iterator I = treeRoots.begin(); I != treeRoots.end(); ++I) (*I)->dump(/*dumpChildren*/ 1, /*indent*/ 0); } diff --git a/lib/CodeGen/InstrSelection/InstrSelection.cpp b/lib/CodeGen/InstrSelection/InstrSelection.cpp index b959c90ca30..ab489c507e8 100644 --- a/lib/CodeGen/InstrSelection/InstrSelection.cpp +++ b/lib/CodeGen/InstrSelection/InstrSelection.cpp @@ -23,8 +23,8 @@ #include "llvm/iPHINode.h" #include "llvm/Target/MachineRegInfo.h" #include "Support/CommandLine.h" -#include - +#include +using std::cerr; //******************** Internal Data Declarations ************************/ @@ -84,17 +84,17 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target) if (SelectDebugLevel >= Select_DebugInstTrees) { - cout << "\n\n*** Instruction trees for method " + cerr << "\n\n*** Instruction trees for method " << (method->hasName()? method->getName() : "") - << endl << endl; + << "\n\n"; instrForest.dump(); } // // Invoke BURG instruction selection for each tree // - const hash_set &treeRoots = instrForest.getRootSet(); - for (hash_set::const_iterator + const std::hash_set &treeRoots = instrForest.getRootSet(); + for (std::hash_set::const_iterator treeRootIter = treeRoots.begin(); treeRootIter != treeRoots.end(); ++treeRootIter) { @@ -138,8 +138,7 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target) if (SelectDebugLevel >= Select_PrintMachineCode) { - cout << endl - << "*** Machine instructions after INSTRUCTION SELECTION" << endl; + cerr << "\n*** Machine instructions after INSTRUCTION SELECTION\n"; MachineCodeForMethod::get(method).dump(); } @@ -210,7 +209,7 @@ void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) { // insert the copy instruction to the predecessor BB - vector CopyInstVec; + std::vector CopyInstVec; MachineInstr *CpMI = target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PN); @@ -250,25 +249,18 @@ void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) { PHINode *PN = (PHINode *) (*IIt); - Value *PhiCpRes = new Value(PN->getType(), PN->getValueType()); - - string *Name = new string("PhiCp:"); - (*Name) += (int) PhiCpRes; - PhiCpRes->setName( *Name ); - + Value *PhiCpRes = new Value(PN->getType(), PN->getValueType(),"PhiCp:"); // for each incoming value of the phi, insert phi elimination // for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) { // insert the copy instruction to the predecessor BB - MachineInstr *CpMI = target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PhiCpRes); InsertPhiElimInst(PN->getIncomingBlock(i), CpMI); - } @@ -279,8 +271,6 @@ void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) { MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec(); bbMvec.insert( bbMvec.begin(), CpMI2); - - } else break; // since PHI nodes can only be at the top @@ -338,7 +328,7 @@ PostprocessMachineCodeForTree(InstructionNode* instrNode, MachineCodeForVMInstr& mvec = vmInstr->getMachineInstrVec(); for (int i = (int) mvec.size()-1; i >= 0; i--) { - vector loadConstVec = + std::vector loadConstVec = FixConstantOperandsForInstr(vmInstr, mvec[i], target); if (loadConstVec.size() > 0) @@ -372,7 +362,7 @@ SelectInstructionsForTree(InstrTreeNode* treeRoot, int goalnt, if (ruleForNode == 0) { - cerr << "Could not match instruction tree for instr selection" << endl; + cerr << "Could not match instruction tree for instr selection\n"; assert(0); return true; } diff --git a/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp b/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp index 30d9c7eb78a..34dd83b49e0 100644 --- a/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp +++ b/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp @@ -22,7 +22,7 @@ #include "llvm/Instruction.h" #include "llvm/Type.h" #include "llvm/iMemory.h" - +using std::vector; //*************************** Local Functions ******************************/ diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 5832b8ed18b..ccb52c2c981 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -20,6 +20,8 @@ #include "llvm/Method.h" #include "llvm/iOther.h" #include "llvm/Instruction.h" +#include +using std::cerr; AnnotationID MachineCodeForMethod::AID( AnnotationManager::getID("MachineCodeForMethodAnnotation")); @@ -83,13 +85,12 @@ void MachineInstr::dump(unsigned int indent) const { for (unsigned i=0; i < indent; i++) - cout << " "; + cerr << " "; - cout << *this; + cerr << *this; } -ostream& -operator<< (ostream& os, const MachineInstr& minstr) +std::ostream &operator<<(std::ostream& os, const MachineInstr& minstr) { os << TargetInstrDescriptors[minstr.opCode].opCodeString; @@ -101,7 +102,7 @@ operator<< (ostream& os, const MachineInstr& minstr) #undef DEBUG_VAL_OP_ITERATOR #ifdef DEBUG_VAL_OP_ITERATOR - os << endl << "\tValue operands are: "; + os << "\n\tValue operands are: "; for (MachineInstr::val_const_op_iterator vo(&minstr); ! vo.done(); ++vo) { const Value* val = *vo; @@ -127,15 +128,11 @@ operator<< (ostream& os, const MachineInstr& minstr) } #endif - - - os << endl; - - return os; + return os << "\n"; } -static inline ostream& -OutputOperand(ostream &os, const MachineOperand &mop) +static inline std::ostream &OutputOperand(std::ostream &os, + const MachineOperand &mop) { Value* val; switch (mop.getOperandType()) @@ -145,7 +142,7 @@ OutputOperand(ostream &os, const MachineOperand &mop) val = mop.getVRegValue(); os << "(val "; if (val && val->hasName()) - os << val->getName().c_str(); + os << val->getName(); else os << val; return os << ")"; @@ -158,8 +155,7 @@ OutputOperand(ostream &os, const MachineOperand &mop) } -ostream& -operator<<(ostream &os, const MachineOperand &mop) +std::ostream &operator<<(std::ostream &os, const MachineOperand &mop) { switch(mop.opType) { @@ -171,16 +167,16 @@ operator<<(ostream &os, const MachineOperand &mop) os << "%ccreg"; return OutputOperand(os, mop); case MachineOperand::MO_SignExtendedImmed: - return os << mop.immedVal; + return os << (long)mop.immedVal; case MachineOperand::MO_UnextendedImmed: - return os << mop.immedVal; + return os << (long)mop.immedVal; case MachineOperand::MO_PCRelativeDisp: { const Value* opVal = mop.getVRegValue(); bool isLabel = isa(opVal) || isa(opVal); os << "%disp(" << (isLabel? "label " : "addr-of-val "); if (opVal->hasName()) - os << opVal->getName().c_str(); + os << opVal->getName(); else os << opVal; return os << ")"; @@ -403,8 +399,7 @@ MachineCodeForMethod::pushTempValue(const TargetMachine& target, size += align - mod; } - offset = growUp? firstTmpOffset + offset - : firstTmpOffset - offset; + offset = growUp ? firstTmpOffset + offset : firstTmpOffset - offset; currentTmpValuesSize += size; return offset; @@ -419,28 +414,26 @@ MachineCodeForMethod::popAllTempValues(const TargetMachine& target) int MachineCodeForMethod::getOffset(const Value* val) const { - hash_map::const_iterator pair = offsets.find(val); - return (pair == offsets.end())? INVALID_FRAME_OFFSET : (*pair).second; + std::hash_map::const_iterator pair = offsets.find(val); + return (pair == offsets.end())? INVALID_FRAME_OFFSET : pair->second; } void MachineCodeForMethod::dump() const { - cout << "\n" << method->getReturnType() - << " \"" << method->getName() << "\"" << endl; + cerr << "\n" << method->getReturnType() + << " \"" << method->getName() << "\"\n"; for (Method::const_iterator BI = method->begin(); BI != method->end(); ++BI) { BasicBlock* bb = *BI; - cout << "\n" + cerr << "\n" << (bb->hasName()? bb->getName() : "Label") - << " (" << bb << ")" << ":" - << endl; + << " (" << bb << ")" << ":\n"; MachineCodeForBasicBlock& mvec = bb->getMachineInstrVec(); for (unsigned i=0; i < mvec.size(); i++) - cout << "\t" << *mvec[i]; + cerr << "\t" << *mvec[i]; } - cout << endl << "End method \"" << method->getName() << "\"" - << endl << endl; + cerr << "\nEnd method \"" << method->getName() << "\"\n\n"; } diff --git a/lib/CodeGen/RegAlloc/IGNode.cpp b/lib/CodeGen/RegAlloc/IGNode.cpp index 4e66d9a762c..a2257420529 100644 --- a/lib/CodeGen/RegAlloc/IGNode.cpp +++ b/lib/CodeGen/RegAlloc/IGNode.cpp @@ -1,12 +1,13 @@ #include "llvm/CodeGen/IGNode.h" - +#include +#include +using std::cerr; //----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- -IGNode::IGNode(LiveRange *const PLR, unsigned int Ind): Index(Ind), - AdjList(), - ParentLR(PLR) +IGNode::IGNode(LiveRange *const PLR, unsigned int Ind) : Index(Ind), + ParentLR(PLR) { OnStack = false; CurDegree = -1 ; @@ -23,11 +24,12 @@ void IGNode::pushOnStack() int neighs = AdjList.size(); if( neighs < 0) { - cout << "\nAdj List size = " << neighs; + cerr << "\nAdj List size = " << neighs; assert(0 && "Invalid adj list size"); } - for(int i=0; i < neighs; i++) (AdjList[i])->decCurDegree(); + for(int i=0; i < neighs; i++) + AdjList[i]->decCurDegree(); } //----------------------------------------------------------------------------- @@ -35,11 +37,9 @@ void IGNode::pushOnStack() // two IGNodes together. //----------------------------------------------------------------------------- void IGNode::delAdjIGNode(const IGNode *const Node) { - vector ::iterator It = AdjList.begin(); - - // find Node - for( ; It != AdjList.end() && (*It != Node); It++ ) ; + std::vector::iterator It = + find(AdjList.begin(), AdjList.end(), Node); assert( It != AdjList.end() ); // the node must be there - - AdjList.erase( It ); + + AdjList.erase(It); } diff --git a/lib/CodeGen/RegAlloc/IGNode.h b/lib/CodeGen/RegAlloc/IGNode.h index 0f4cf9c82a1..b89aea32b1d 100644 --- a/lib/CodeGen/RegAlloc/IGNode.h +++ b/lib/CodeGen/RegAlloc/IGNode.h @@ -29,8 +29,6 @@ #include "llvm/CodeGen/RegAllocCommon.h" #include "llvm/CodeGen/LiveRange.h" - - //---------------------------------------------------------------------------- // Class IGNode // @@ -39,13 +37,11 @@ class IGNode { - private: - const int Index; // index within IGNodeList bool OnStack; // this has been pushed on to stack for coloring - vector AdjList; // adjacency list for this live range + std::vector AdjList; // adjacency list for this live range int CurDegree; // @@ -54,7 +50,6 @@ class IGNode // Decremented when a neighbor is pushed on to the stack. // After that, never incremented/set again nor used. - LiveRange *const ParentLR; // parent LR (cannot be a const) @@ -152,10 +147,4 @@ class IGNode }; - - - - - - #endif diff --git a/lib/CodeGen/RegAlloc/InterferenceGraph.cpp b/lib/CodeGen/RegAlloc/InterferenceGraph.cpp index e18c9a7a348..0de7275acf7 100644 --- a/lib/CodeGen/RegAlloc/InterferenceGraph.cpp +++ b/lib/CodeGen/RegAlloc/InterferenceGraph.cpp @@ -1,4 +1,7 @@ #include "llvm/CodeGen/InterferenceGraph.h" +#include "Support/STLExtras.h" +#include +using std::cerr; //----------------------------------------------------------------------------- // Constructor: Records the RegClass and initalizes IGNodeList. @@ -11,7 +14,7 @@ InterferenceGraph::InterferenceGraph(RegClass *const RC) : RegCl(RC), IG = NULL; Size = 0; if( DEBUG_RA) { - cout << "Interference graph created!" << endl; + cerr << "Interference graph created!\n"; } } @@ -22,19 +25,12 @@ InterferenceGraph::InterferenceGraph(RegClass *const RC) : RegCl(RC), InterferenceGraph:: ~InterferenceGraph() { // delete the matrix - // - if( IG ) - delete []IG; + for(unsigned int r=0; r < IGNodeList.size(); ++r) + delete[] IG[r]; + delete[] IG; // delete all IGNodes in the IGNodeList - // - vector::const_iterator IGIt = IGNodeList.begin(); - for(unsigned i=0; i < IGNodeList.size() ; ++i) { - - const IGNode *const Node = IGNodeList[i]; - if( Node ) delete Node; - } - + for_each(IGNodeList.begin(), IGNodeList.end(), deleter); } @@ -46,13 +42,13 @@ InterferenceGraph:: ~InterferenceGraph() { void InterferenceGraph::createGraph() { Size = IGNodeList.size(); - IG = (char **) new char *[Size]; + IG = new char*[Size]; for( unsigned int r=0; r < Size; ++r) IG[r] = new char[Size]; // init IG matrix for(unsigned int i=0; i < Size; i++) - for( unsigned int j=0; j < Size ; j++) + for(unsigned int j=0; j < Size; j++) IG[i][j] = 0; } @@ -61,9 +57,7 @@ void InterferenceGraph::createGraph() //----------------------------------------------------------------------------- void InterferenceGraph::addLRToIG(LiveRange *const LR) { - IGNode *Node = new IGNode(LR, IGNodeList.size() ); - IGNodeList.push_back( Node ); - + IGNodeList.push_back(new IGNode(LR, IGNodeList.size())); } @@ -92,12 +86,11 @@ void InterferenceGraph::setInterference(const LiveRange *const LR1, char *val; if( DEBUG_RA > 1) - cout << "setting intf for: [" << row << "][" << col << "]" << endl; + cerr << "setting intf for: [" << row << "][" << col << "]\n"; ( row > col) ? val = &IG[row][col]: val = &IG[col][row]; if( ! (*val) ) { // if this interf is not previously set - *val = 1; // add edges between nodes IGNode1->addAdjIGNode( IGNode2 ); IGNode2->addAdjIGNode( IGNode1 ); @@ -123,7 +116,10 @@ unsigned InterferenceGraph::getInterference(const LiveRange *const LR1, const unsigned int col = LR2->getUserIGNode()->getIndex(); char ret; - ( row > col) ? (ret = IG[row][col]) : (ret = IG[col][row]) ; + if (row > col) + ret = IG[row][col]; + else + ret = IG[col][row]; return ret; } @@ -148,9 +144,9 @@ void InterferenceGraph::mergeIGNodesOfLRs(const LiveRange *const LR1, assertIGNode( SrcNode ); if( DEBUG_RA > 1) { - cout << "Merging LRs: \""; LR1->printSet(); - cout << "\" and \""; LR2->printSet(); - cout << "\"" << endl; + cerr << "Merging LRs: \""; LR1->printSet(); + cerr << "\" and \""; LR2->printSet(); + cerr << "\"\n"; } unsigned SrcDegree = SrcNode->getNumOfNeighbors(); @@ -217,17 +213,16 @@ void InterferenceGraph::printIG() const for(unsigned int i=0; i < Size; i++) { const IGNode *const Node = IGNodeList[i]; - if( ! Node ) - continue; // skip empty rows - - cout << " [" << i << "] "; + if(Node) { + cerr << " [" << i << "] "; - for( unsigned int j=0; j < Size; j++) { - if( j >= i) break; - if( IG[i][j] ) cout << "(" << i << "," << j << ") "; + for( unsigned int j=0; j < i; j++) { + if(IG[i][j]) + cerr << "(" << i << "," << j << ") "; } - cout << endl; + cerr << "\n"; } + } } //---------------------------------------------------------------------------- @@ -235,21 +230,14 @@ void InterferenceGraph::printIG() const //---------------------------------------------------------------------------- void InterferenceGraph::printIGNodeList() const { - vector::const_iterator IGIt = IGNodeList.begin(); // hash map iter - for(unsigned i=0; i < IGNodeList.size() ; ++i) { - const IGNode *const Node = IGNodeList[i]; - if( ! Node ) - continue; - - cout << " [" << Node->getIndex() << "] "; - (Node->getParentLR())->printSet(); - //int Deg = Node->getCurDegree(); - cout << "\t <# of Neighs: " << Node->getNumOfNeighbors() << ">" << endl; - + if (Node) { + cerr << " [" << Node->getIndex() << "] "; + Node->getParentLR()->printSet(); + //int Deg = Node->getCurDegree(); + cerr << "\t <# of Neighs: " << Node->getNumOfNeighbors() << ">\n"; + } } } - - diff --git a/lib/CodeGen/RegAlloc/InterferenceGraph.h b/lib/CodeGen/RegAlloc/InterferenceGraph.h index 99dea8fbe0a..408bee4558a 100644 --- a/lib/CodeGen/RegAlloc/InterferenceGraph.h +++ b/lib/CodeGen/RegAlloc/InterferenceGraph.h @@ -1,4 +1,4 @@ -/* Title: InterferenceGraph.h +/* Title: InterferenceGraph.h -*- C++ -*- Author: Ruchira Sasanka Date: July 20, 01 Purpose: Interference Graph used for register coloring. @@ -24,7 +24,7 @@ #include "llvm/CodeGen/IGNode.h" -typedef vector IGNodeListType; +typedef std::vector IGNodeListType; class InterferenceGraph @@ -47,6 +47,8 @@ class InterferenceGraph // to create it after adding all IGNodes to the IGNodeList InterferenceGraph(RegClass *const RC); + ~InterferenceGraph(); + void createGraph(); void addLRToIG(LiveRange *const LR); @@ -65,12 +67,6 @@ class InterferenceGraph void printIG() const; void printIGNodeList() const; - - ~InterferenceGraph(); - - }; - #endif - diff --git a/lib/CodeGen/RegAlloc/LiveRange.h b/lib/CodeGen/RegAlloc/LiveRange.h index 778e070046e..8034751da99 100644 --- a/lib/CodeGen/RegAlloc/LiveRange.h +++ b/lib/CodeGen/RegAlloc/LiveRange.h @@ -1,4 +1,4 @@ -/* Title: LiveRange.h +/* Title: LiveRange.h -*- C++ -*- Author: Ruchira Sasanka Date: July 25, 01 Purpose: To keep info about a live range. @@ -13,6 +13,7 @@ #include "llvm/Analysis/LiveVar/ValueSet.h" #include "llvm/Type.h" +#include class RegClass; class IGNode; @@ -176,7 +177,7 @@ class LiveRange : public ValueSet if(SuggestedColor == -1 ) SuggestedColor = Col; else if (DEBUG_RA) - cerr << "Already has a suggested color " << Col << endl; + std::cerr << "Already has a suggested color " << Col << "\n"; } inline unsigned getSuggestedColor() const { diff --git a/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp b/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp index 7fb688f55ef..b66e6ef308b 100644 --- a/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp +++ b/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp @@ -1,15 +1,15 @@ #include "llvm/CodeGen/LiveRangeInfo.h" +#include +using std::cerr; //--------------------------------------------------------------------------- // Constructor //--------------------------------------------------------------------------- LiveRangeInfo::LiveRangeInfo(const Method *const M, const TargetMachine& tm, - vector &RCL) - : Meth(M), LiveRangeMap(), - TM(tm), RegClassList(RCL), - MRI( tm.getRegInfo()), - CallRetInstrList() + std::vector &RCL) + : Meth(M), LiveRangeMap(), TM(tm), + RegClassList(RCL), MRI(tm.getRegInfo()) { } @@ -17,33 +17,25 @@ LiveRangeInfo::LiveRangeInfo(const Method *const M, // Destructor: Deletes all LiveRanges in the LiveRangeMap //--------------------------------------------------------------------------- LiveRangeInfo::~LiveRangeInfo() { - LiveRangeMapType::iterator MI = LiveRangeMap.begin(); for( ; MI != LiveRangeMap.end() ; ++MI) { - if( (*MI).first ) { - - LiveRange *LR = (*MI).second; - - if( LR ) { - - // we need to be careful in deleting LiveRanges in LiveRangeMap - // since two/more Values in the live range map can point to the same - // live range. We have to make the other entries NULL when we delete - // a live range. - - LiveRange::iterator LI = LR->begin(); - - for( ; LI != LR->end() ; ++LI) { - LiveRangeMap[*LI] = NULL; - } + if (MI->first && MI->second) { + LiveRange *LR = MI->second; - delete LR; + // we need to be careful in deleting LiveRanges in LiveRangeMap + // since two/more Values in the live range map can point to the same + // live range. We have to make the other entries NULL when we delete + // a live range. - } + LiveRange::iterator LI = LR->begin(); + + for( ; LI != LR->end() ; ++LI) + LiveRangeMap[*LI] = 0; + + delete LR; } } - } @@ -82,7 +74,7 @@ void LiveRangeInfo::unionAndUpdateLRs(LiveRange *const L1, LiveRange *L2) L1->addSpillCost( L2->getSpillCost() ); // add the spill costs - delete ( L2 ); // delete L2 as it is no longer needed + delete L2; // delete L2 as it is no longer needed } @@ -96,7 +88,7 @@ void LiveRangeInfo::constructLiveRanges() { if( DEBUG_RA) - cout << "Consturcting Live Ranges ..." << endl; + cerr << "Consturcting Live Ranges ...\n"; // first find the live ranges for all incoming args of the method since // those LRs start from the start of the method @@ -108,14 +100,13 @@ void LiveRangeInfo::constructLiveRanges() for( ; ArgIt != ArgList.end() ; ++ArgIt) { // for each argument - LiveRange * ArgRange = new LiveRange(); // creates a new LR and const Value *const Val = (const Value *) *ArgIt; assert( Val); - ArgRange->add( Val ); // add the arg (def) to it - LiveRangeMap[ Val ] = ArgRange; + ArgRange->add(Val); // add the arg (def) to it + LiveRangeMap[Val] = ArgRange; // create a temp machine op to find the register class of value //const MachineOperand Op(MachineOperand::MO_VirtualRegister); @@ -125,8 +116,8 @@ void LiveRangeInfo::constructLiveRanges() if( DEBUG_RA > 1) { - cout << " adding LiveRange for argument "; - printValue( (const Value *) *ArgIt); cout << endl; + cerr << " adding LiveRange for argument "; + printValue((const Value *) *ArgIt); cerr << "\n"; } } @@ -140,7 +131,6 @@ void LiveRangeInfo::constructLiveRanges() Method::const_iterator BBI = Meth->begin(); // random iterator for BBs - for( ; BBI != Meth->end(); ++BBI) { // go thru BBs in random order // Now find all LRs for machine the instructions. A new LR will be created @@ -150,8 +140,7 @@ void LiveRangeInfo::constructLiveRanges() // get the iterator for machine instructions const MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec(); - MachineCodeForBasicBlock::const_iterator - MInstIterator = MIVec.begin(); + MachineCodeForBasicBlock::const_iterator MInstIterator = MIVec.begin(); // iterate over all the machine instructions in BB for( ; MInstIterator != MIVec.end(); MInstIterator++) { @@ -161,53 +150,46 @@ void LiveRangeInfo::constructLiveRanges() // Now if the machine instruction is a call/return instruction, // add it to CallRetInstrList for processing its implicit operands - if( (TM.getInstrInfo()).isReturn( MInst->getOpCode()) || - (TM.getInstrInfo()).isCall( MInst->getOpCode()) ) + if(TM.getInstrInfo().isReturn(MInst->getOpCode()) || + TM.getInstrInfo().isCall(MInst->getOpCode())) CallRetInstrList.push_back( MInst ); // iterate over MI operands to find defs - for( MachineInstr::val_const_op_iterator OpI(MInst);!OpI.done(); ++OpI) { - - if( DEBUG_RA) { + for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done(); ++OpI) { + if(DEBUG_RA) { MachineOperand::MachineOperandType OpTyp = OpI.getMachineOperand().getOperandType(); - if ( OpTyp == MachineOperand::MO_CCRegister) { - cout << "\n**CC reg found. Is Def=" << OpI.isDef() << " Val:"; + if (OpTyp == MachineOperand::MO_CCRegister) { + cerr << "\n**CC reg found. Is Def=" << OpI.isDef() << " Val:"; printValue( OpI.getMachineOperand().getVRegValue() ); - cout << endl; + cerr << "\n"; } } // create a new LR iff this operand is a def if( OpI.isDef() ) { - const Value *const Def = *OpI; - // Only instruction values are accepted for live ranges here - if( Def->getValueType() != Value::InstructionVal ) { - cout << "\n**%%Error: Def is not an instruction val. Def="; - printValue( Def ); cout << endl; + cerr << "\n**%%Error: Def is not an instruction val. Def="; + printValue( Def ); cerr << "\n"; continue; } - LiveRange *DefRange = LiveRangeMap[Def]; // see LR already there (because of multiple defs) - if( !DefRange) { // if it is not in LiveRangeMap - DefRange = new LiveRange(); // creates a new live range and DefRange->add( Def ); // add the instruction (def) to it LiveRangeMap[ Def ] = DefRange; // update the map if( DEBUG_RA > 1) { - cout << " creating a LR for def: "; - printValue(Def); cout << endl; + cerr << " creating a LR for def: "; + printValue(Def); cerr << "\n"; } // set the register class of the new live range @@ -221,7 +203,7 @@ void LiveRangeInfo::constructLiveRanges() if(isCC && DEBUG_RA) { - cout << "\a**created a LR for a CC reg:"; + cerr << "\a**created a LR for a CC reg:"; printValue( OpI.getMachineOperand().getVRegValue() ); } @@ -235,8 +217,8 @@ void LiveRangeInfo::constructLiveRanges() LiveRangeMap[ Def ] = DefRange; if( DEBUG_RA > 1) { - cout << " added to an existing LR for def: "; - printValue( Def ); cout << endl; + cerr << " added to an existing LR for def: "; + printValue( Def ); cerr << "\n"; } } @@ -256,7 +238,7 @@ void LiveRangeInfo::constructLiveRanges() suggestRegs4CallRets(); if( DEBUG_RA) - cout << "Initial Live Ranges constructed!" << endl; + cerr << "Initial Live Ranges constructed!\n"; } @@ -312,11 +294,8 @@ void LiveRangeInfo::suggestRegs4CallRets() //--------------------------------------------------------------------------- void LiveRangeInfo::coalesceLRs() { - - - if( DEBUG_RA) - cout << endl << "Coalscing LRs ..." << endl; + cerr << "\nCoalscing LRs ...\n"; Method::const_iterator BBI = Meth->begin(); // random iterator for BBs @@ -324,8 +303,7 @@ void LiveRangeInfo::coalesceLRs() // get the iterator for machine instructions const MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec(); - MachineCodeForBasicBlock::const_iterator - MInstIterator = MIVec.begin(); + MachineCodeForBasicBlock::const_iterator MInstIterator = MIVec.begin(); // iterate over all the machine instructions in BB for( ; MInstIterator != MIVec.end(); ++MInstIterator) { @@ -333,9 +311,9 @@ void LiveRangeInfo::coalesceLRs() const MachineInstr * MInst = *MInstIterator; if( DEBUG_RA > 1) { - cout << " *Iterating over machine instr "; + cerr << " *Iterating over machine instr "; MInst->dump(); - cout << endl; + cerr << "\n"; } @@ -357,8 +335,8 @@ void LiveRangeInfo::coalesceLRs() //don't warn about labels if (!((*UseI)->getType())->isLabelType() && DEBUG_RA) { - cout<<" !! Warning: No LR for use "; printValue(*UseI); - cout << endl; + cerr<<" !! Warning: No LR for use "; printValue(*UseI); + cerr << "\n"; } continue; // ignore and continue } @@ -407,7 +385,7 @@ void LiveRangeInfo::coalesceLRs() } // for all BBs if( DEBUG_RA) - cout << endl << "Coalscing Done!" << endl; + cerr << "\nCoalscing Done!\n"; } @@ -421,11 +399,11 @@ void LiveRangeInfo::coalesceLRs() void LiveRangeInfo::printLiveRanges() { LiveRangeMapType::iterator HMI = LiveRangeMap.begin(); // hash map iterator - cout << endl << "Printing Live Ranges from Hash Map:" << endl; - for( ; HMI != LiveRangeMap.end() ; HMI ++ ) { - if( (*HMI).first && (*HMI).second ) { - cout <<" "; printValue((*HMI).first); cout << "\t: "; - ((*HMI).second)->printSet(); cout << endl; + cerr << "\nPrinting Live Ranges from Hash Map:\n"; + for( ; HMI != LiveRangeMap.end() ; ++HMI) { + if( HMI->first && HMI->second ) { + cerr <<" "; printValue((*HMI).first); cerr << "\t: "; + HMI->second->printSet(); cerr << "\n"; } } } diff --git a/lib/CodeGen/RegAlloc/LiveRangeInfo.h b/lib/CodeGen/RegAlloc/LiveRangeInfo.h index 1eee1aea5e3..9e7ef06fe28 100644 --- a/lib/CodeGen/RegAlloc/LiveRangeInfo.h +++ b/lib/CodeGen/RegAlloc/LiveRangeInfo.h @@ -1,4 +1,4 @@ -/* Title: LiveRangeInfo.h +/* Title: LiveRangeInfo.h -*- C++ -*- Author: Ruchira Sasanka Date: Jun 30, 01 Purpose: @@ -34,8 +34,8 @@ #include "llvm/CodeGen/RegClass.h" -typedef hash_map LiveRangeMapType; -typedef vector CallRetInstrListType; +typedef std::hash_map LiveRangeMapType; +typedef std::vector CallRetInstrListType; @@ -59,7 +59,7 @@ private: const TargetMachine& TM; // target machine description - vector & RegClassList;// a vector containing register classess + std::vector & RegClassList;// vector containing register classess const MachineRegInfo& MRI; // machine reg info @@ -82,7 +82,7 @@ public: LiveRangeInfo(const Method *const M, const TargetMachine& tm, - vector & RCList); + std::vector & RCList); // Destructor to destroy all LiveRanges in the LiveRange Map diff --git a/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp b/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp index 7d6fbb7cc98..e2d455bad9d 100644 --- a/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp +++ b/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp @@ -14,7 +14,9 @@ #include "llvm/CodeGen/MachineInstr.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/MachineFrameInfo.h" +#include #include +using std::cerr; // ***TODO: There are several places we add instructions. Validate the order @@ -35,18 +37,16 @@ cl::Enum DEBUG_RA("dregalloc", cl::NoFlags, PhyRegAlloc::PhyRegAlloc(Method *M, const TargetMachine& tm, MethodLiveVarInfo *const Lvi) - : RegClassList(), - TM(tm), - Meth(M), + : TM(tm), Meth(M), mcInfo(MachineCodeForMethod::get(M)), LVI(Lvi), LRI(M, tm, RegClassList), MRI( tm.getRegInfo() ), NumOfRegClasses(MRI.getNumOfRegClasses()), - AddedInstrMap(), LoopDepthCalc(M), ResColList() { + LoopDepthCalc(M) { // create each RegisterClass and put in RegClassList // - for( unsigned int rc=0; rc < NumOfRegClasses; rc++) + for(unsigned int rc=0; rc < NumOfRegClasses; rc++) RegClassList.push_back( new RegClass(M, MRI.getMachineRegClass(rc), &ResColList) ); } @@ -69,7 +69,7 @@ PhyRegAlloc::~PhyRegAlloc() { //---------------------------------------------------------------------------- void PhyRegAlloc::createIGNodeListsAndIGs() { - if(DEBUG_RA ) cout << "Creating LR lists ..." << endl; + if(DEBUG_RA ) cerr << "Creating LR lists ...\n"; // hash map iterator LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin(); @@ -85,8 +85,8 @@ void PhyRegAlloc::createIGNodeListsAndIGs() if( !L) { if( DEBUG_RA) { - cout << "\n*?!?Warning: Null liver range found for: "; - printValue( (*HMI).first) ; cout << endl; + cerr << "\n*?!?Warning: Null liver range found for: "; + printValue(HMI->first); cerr << "\n"; } continue; } @@ -108,7 +108,7 @@ void PhyRegAlloc::createIGNodeListsAndIGs() RegClassList[ rc ]->createInterferenceGraph(); if( DEBUG_RA) - cout << "LRLists Created!" << endl; + cerr << "LRLists Created!\n"; } @@ -140,8 +140,8 @@ void PhyRegAlloc::addInterference(const Value *const Def, for( ; LIt != LVSet->end(); ++LIt) { if( DEBUG_RA > 1) { - cout << "< Def="; printValue(Def); - cout << ", Lvar="; printValue( *LIt); cout << "> "; + cerr << "< Def="; printValue(Def); + cerr << ", Lvar="; printValue( *LIt); cerr << "> "; } // get the live range corresponding to live var @@ -166,8 +166,8 @@ void PhyRegAlloc::addInterference(const Value *const Def, else if(DEBUG_RA > 1) { // we will not have LRs for values not explicitly allocated in the // instruction stream (e.g., constants) - cout << " warning: no live range for " ; - printValue( *LIt); cout << endl; } + cerr << " warning: no live range for " ; + printValue(*LIt); cerr << "\n"; } } @@ -203,7 +203,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, } if( DEBUG_RA) - cout << "\n For call inst: " << *MInst; + cerr << "\n For call inst: " << *MInst; LiveVarSet::const_iterator LIt = LVSetAft->begin(); @@ -216,7 +216,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, LiveRange *const LR = LRI.getLiveRangeForValue(*LIt ); if( LR && DEBUG_RA) { - cout << "\n\tLR Aft Call: "; + cerr << "\n\tLR Aft Call: "; LR->printSet(); } @@ -227,7 +227,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, if( LR && (LR != RetValLR) ) { LR->setCallInterference(); if( DEBUG_RA) { - cout << "\n ++Added call interf for LR: " ; + cerr << "\n ++Added call interf for LR: " ; LR->printSet(); } } @@ -247,7 +247,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, void PhyRegAlloc::buildInterferenceGraphs() { - if(DEBUG_RA) cout << "Creating interference graphs ..." << endl; + if(DEBUG_RA) cerr << "Creating interference graphs ...\n"; unsigned BBLoopDepthCost; Method::const_iterator BBI = Meth->begin(); // random iterator for BBs @@ -333,7 +333,7 @@ void PhyRegAlloc::buildInterferenceGraphs() addInterferencesForArgs(); if( DEBUG_RA) - cout << "Interference graphs calculted!" << endl; + cerr << "Interference graphs calculted!\n"; } @@ -411,8 +411,8 @@ void PhyRegAlloc::addInterferencesForArgs() addInterference( *ArgIt, InSet, false ); // add interferences between // args and LVars at start if( DEBUG_RA > 1) { - cout << " - %% adding interference for argument "; - printValue( (const Value *) *ArgIt); cout << endl; + cerr << " - %% adding interference for argument "; + printValue((const Value *)*ArgIt); cerr << "\n"; } } } @@ -510,7 +510,7 @@ void PhyRegAlloc::updateMachineCode() // delete this condition checking later (must assert if Val is null) if( !Val) { if (DEBUG_RA) - cout << "Warning: NULL Value found for operand" << endl; + cerr << "Warning: NULL Value found for operand\n"; continue; } assert( Val && "Value is NULL"); @@ -522,9 +522,9 @@ void PhyRegAlloc::updateMachineCode() // nothing to worry if it's a const or a label if (DEBUG_RA) { - cout << "*NO LR for operand : " << Op ; - cout << " [reg:" << Op.getAllocatedRegNum() << "]"; - cout << " in inst:\t" << *MInst << endl; + cerr << "*NO LR for operand : " << Op ; + cerr << " [reg:" << Op.getAllocatedRegNum() << "]"; + cerr << " in inst:\t" << *MInst << "\n"; } // if register is not allocated, mark register as invalid @@ -563,18 +563,16 @@ void PhyRegAlloc::updateMachineCode() // instruction, add them now. // if( AddedInstrMap[ MInst ] ) { - - deque &IBef = (AddedInstrMap[MInst])->InstrnsBefore; + std::deque &IBef = AddedInstrMap[MInst]->InstrnsBefore; if( ! IBef.empty() ) { - - deque::iterator AdIt; + std::deque::iterator AdIt; for( AdIt = IBef.begin(); AdIt != IBef.end() ; ++AdIt ) { if( DEBUG_RA) { cerr << "For inst " << *MInst; - cerr << " PREPENDed instr: " << **AdIt << endl; + cerr << " PREPENDed instr: " << **AdIt << "\n"; } MInstIterator = MIVec.insert( MInstIterator, *AdIt ); @@ -600,7 +598,7 @@ void PhyRegAlloc::updateMachineCode() if((delay=TM.getInstrInfo().getNumDelaySlots(MInst->getOpCode())) >0){ move2DelayedInstr(MInst, *(MInstIterator+delay) ); - if(DEBUG_RA) cout<< "\nMoved an added instr after the delay slot"; + if(DEBUG_RA) cerr<< "\nMoved an added instr after the delay slot"; } else { @@ -609,11 +607,11 @@ void PhyRegAlloc::updateMachineCode() // Here we can add the "instructions after" to the current // instruction since there are no delay slots for this instruction - deque &IAft = (AddedInstrMap[MInst])->InstrnsAfter; + std::deque &IAft = AddedInstrMap[MInst]->InstrnsAfter; if( ! IAft.empty() ) { - deque::iterator AdIt; + std::deque::iterator AdIt; ++MInstIterator; // advance to the next instruction @@ -621,7 +619,7 @@ void PhyRegAlloc::updateMachineCode() if(DEBUG_RA) { cerr << "For inst " << *MInst; - cerr << " APPENDed instr: " << **AdIt << endl; + cerr << " APPENDed instr: " << **AdIt << "\n"; } MInstIterator = MIVec.insert( MInstIterator, *AdIt ); @@ -669,9 +667,7 @@ void PhyRegAlloc::insertCode4SpilledLR(const LiveRange *LR, RegClass *RC = LR->getRegClass(); const LiveVarSet *LVSetBef = LVI->getLiveVarSetBeforeMInst(MInst, BB); - - int TmpOff = - mcInfo.pushTempValue(TM, MRI.getSpilledRegSize(RegType) ); + mcInfo.pushTempValue(TM, MRI.getSpilledRegSize(RegType) ); MachineInstr *MIBef=NULL, *AdIMid=NULL, *MIAft=NULL; @@ -854,13 +850,10 @@ int PhyRegAlloc::getUniRegNotUsedByThisInst(RegClass *RC, return MRI.getUnifiedRegNum(RC->getID(), c); else assert( 0 && "FATAL: No free register could be found in reg class!!"); - + return 0; } - - - //---------------------------------------------------------------------------- // This method modifies the IsColorUsedArr of the register class passed to it. // It sets the bits corresponding to the registers used by this machine @@ -909,14 +902,10 @@ void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC, LiveRange *const LRofImpRef = LRI.getLiveRangeForValue( MInst->getImplicitRef(z) ); - - if( LRofImpRef ) - if( LRofImpRef->hasColor() ) - IsColorUsedArr[ LRofImpRef->getColor() ] = true; + + if(LRofImpRef && LRofImpRef->hasColor()) + IsColorUsedArr[LRofImpRef->getColor()] = true; } - - - } @@ -936,9 +925,8 @@ void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC, void PhyRegAlloc:: move2DelayedInstr(const MachineInstr *OrigMI, const MachineInstr *DelayedMI) { - // "added after" instructions of the original instr - deque &OrigAft = (AddedInstrMap[OrigMI])->InstrnsAfter; + std::deque &OrigAft = AddedInstrMap[OrigMI]->InstrnsAfter; // "added instructions" of the delayed instr AddedInstrns *DelayAdI = AddedInstrMap[DelayedMI]; @@ -949,21 +937,15 @@ void PhyRegAlloc:: move2DelayedInstr(const MachineInstr *OrigMI, } // "added after" instructions of the delayed instr - deque &DelayedAft = DelayAdI->InstrnsAfter; + std::deque &DelayedAft = DelayAdI->InstrnsAfter; // go thru all the "added after instructions" of the original instruction // and append them to the "addded after instructions" of the delayed // instructions - - deque::iterator OrigAdIt; - - for( OrigAdIt = OrigAft.begin(); OrigAdIt != OrigAft.end() ; ++OrigAdIt ) { - DelayedAft.push_back( *OrigAdIt ); - } + DelayedAft.insert(DelayedAft.end(), OrigAft.begin(), OrigAft.end()); // empty the "added after instructions" of the original instruction OrigAft.clear(); - } //---------------------------------------------------------------------------- @@ -973,14 +955,14 @@ void PhyRegAlloc:: move2DelayedInstr(const MachineInstr *OrigMI, void PhyRegAlloc::printMachineCode() { - cout << endl << ";************** Method "; - cout << Meth->getName() << " *****************" << endl; + cerr << "\n;************** Method " << Meth->getName() + << " *****************\n"; Method::const_iterator BBI = Meth->begin(); // random iterator for BBs for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order - cout << endl ; printLabel( *BBI); cout << ": "; + cerr << "\n"; printLabel( *BBI); cerr << ": "; // get the iterator for machine instructions MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec(); @@ -992,8 +974,8 @@ void PhyRegAlloc::printMachineCode() MachineInstr *const MInst = *MInstIterator; - cout << endl << "\t"; - cout << TargetInstrDescriptors[MInst->getOpCode()].opCodeString; + cerr << "\n\t"; + cerr << TargetInstrDescriptors[MInst->getOpCode()].opCodeString; //for(MachineInstr::val_const_op_iterator OpI(MInst);!OpI.done();++OpI) { @@ -1009,41 +991,39 @@ void PhyRegAlloc::printMachineCode() const Value *const Val = Op.getVRegValue () ; // ****this code is temporary till NULL Values are fixed if( ! Val ) { - cout << "\t<*NULL*>"; + cerr << "\t<*NULL*>"; continue; } // if a label or a constant - if( (Val->getValueType() == Value::BasicBlockVal) ) { - - cout << "\t"; printLabel( Op.getVRegValue () ); - } - else { + if(isa(Val) { + cerr << "\t"; printLabel( Op.getVRegValue () ); + } else { // else it must be a register value const int RegNum = Op.getAllocatedRegNum(); - cout << "\t" << "%" << MRI.getUnifiedRegName( RegNum ); + cerr << "\t" << "%" << MRI.getUnifiedRegName( RegNum ); if (Val->hasName() ) - cout << "(" << Val->getName() << ")"; + cerr << "(" << Val->getName() << ")"; else - cout << "(" << Val << ")"; + cerr << "(" << Val << ")"; if( Op.opIsDef() ) - cout << "*"; + cerr << "*"; const LiveRange *LROfVal = LRI.getLiveRangeForValue(Val); if( LROfVal ) if( LROfVal->hasSpillOffset() ) - cout << "$"; + cerr << "$"; } } else if(Op.getOperandType() == MachineOperand::MO_MachineRegister) { - cout << "\t" << "%" << MRI.getUnifiedRegName(Op.getMachineRegNum()); + cerr << "\t" << "%" << MRI.getUnifiedRegName(Op.getMachineRegNum()); } else - cout << "\t" << Op; // use dump field + cerr << "\t" << Op; // use dump field } @@ -1051,23 +1031,22 @@ void PhyRegAlloc::printMachineCode() unsigned NumOfImpRefs = MInst->getNumImplicitRefs(); if( NumOfImpRefs > 0 ) { - cout << "\tImplicit:"; + cerr << "\tImplicit:"; for(unsigned z=0; z < NumOfImpRefs; z++) { printValue( MInst->getImplicitRef(z) ); - cout << "\t"; + cerr << "\t"; } } } // for all machine instructions - - cout << endl; + cerr << "\n"; } // for all BBs - cout << endl; + cerr << "\n"; } @@ -1125,9 +1104,9 @@ void PhyRegAlloc::colorIncomingArgs() assert( FirstMI && "No machine instruction in entry BB"); AddedInstrns *AI = AddedInstrMap[ FirstMI ]; - if ( !AI ) { + if (!AI) { AI = new AddedInstrns(); - AddedInstrMap[ FirstMI ] = AI; + AddedInstrMap[FirstMI] = AI; } MRI.colorMethodArgs(Meth, LRI, AI ); @@ -1137,12 +1116,11 @@ void PhyRegAlloc::colorIncomingArgs() //---------------------------------------------------------------------------- // Used to generate a label for a basic block //---------------------------------------------------------------------------- -void PhyRegAlloc::printLabel(const Value *const Val) -{ - if( Val->hasName() ) - cout << Val->getName(); +void PhyRegAlloc::printLabel(const Value *const Val) { + if (Val->hasName()) + cerr << Val->getName(); else - cout << "Label" << Val; + cerr << "Label" << Val; } @@ -1155,7 +1133,7 @@ void PhyRegAlloc::printLabel(const Value *const Val) void PhyRegAlloc::markUnusableSugColors() { - if(DEBUG_RA ) cout << "\nmarking unusable suggested colors ..." << endl; + if(DEBUG_RA ) cerr << "\nmarking unusable suggested colors ...\n"; // hash map iterator LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin(); @@ -1193,22 +1171,18 @@ void PhyRegAlloc::markUnusableSugColors() void PhyRegAlloc::allocateStackSpace4SpilledLRs() { - if(DEBUG_RA ) cout << "\nsetting LR stack offsets ..." << endl; + if(DEBUG_RA ) cerr << "\nsetting LR stack offsets ...\n"; // hash map iterator LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin(); LiveRangeMapType::const_iterator HMIEnd = (LRI.getLiveRangeMap())->end(); for( ; HMI != HMIEnd ; ++HMI ) { - if( (*HMI).first ) { - LiveRange *L = (*HMI).second; // get the LiveRange - if(L) - if( ! L->hasColor() ) - - // NOTE: ** allocating the size of long Type ** - L->setSpillOffFromFP(mcInfo.allocateSpilledValue(TM, - Type::LongTy)); - + if(HMI->first && HMI->second) { + LiveRange *L = HMI->second; // get the LiveRange + if( ! L->hasColor() ) + // NOTE: ** allocating the size of long Type ** + L->setSpillOffFromFP(mcInfo.allocateSpilledValue(TM, Type::LongTy)); } } // for all LR's in hash map } diff --git a/lib/CodeGen/RegAlloc/PhyRegAlloc.h b/lib/CodeGen/RegAlloc/PhyRegAlloc.h index 9d34557b01e..6871b2d28ad 100644 --- a/lib/CodeGen/RegAlloc/PhyRegAlloc.h +++ b/lib/CodeGen/RegAlloc/PhyRegAlloc.h @@ -1,4 +1,4 @@ -/* Title: PhyRegAlloc.h +/* Title: PhyRegAlloc.h -*- C++ -*- Author: Ruchira Sasanka Date: Aug 20, 01 Purpose: This is the main entry point for register allocation. @@ -54,13 +54,11 @@ class AddedInstrns { public: - deque InstrnsBefore; // Added insts BEFORE an existing inst - deque InstrnsAfter; // Added insts AFTER an existing inst - - AddedInstrns() : InstrnsBefore(), InstrnsAfter() { } + std::deque InstrnsBefore;// Added insts BEFORE an existing inst + std::deque InstrnsAfter; // Added insts AFTER an existing inst }; -typedef hash_map AddedInstrMapType; +typedef std::hash_map AddedInstrMapType; @@ -74,7 +72,7 @@ typedef hash_map AddedInstrMapType; class PhyRegAlloc: public NonCopyable { - vector RegClassList ; // vector of register classes + std::vector RegClassList; // vector of register classes const TargetMachine &TM; // target machine const Method* Meth; // name of the method we work on MachineCodeForMethod& mcInfo; // descriptor for method's native code @@ -115,8 +113,7 @@ class PhyRegAlloc: public NonCopyable const BasicBlock *BB, const unsigned OpNum); - inline void constructLiveRanges() - { LRI.constructLiveRanges(); } + inline void constructLiveRanges() { LRI.constructLiveRanges(); } void colorIncomingArgs(); void colorCallRetArgs(); @@ -141,12 +138,9 @@ class PhyRegAlloc: public NonCopyable void addInterf4PseudoInstr(const MachineInstr *MInst); - public: - PhyRegAlloc(Method *const M, const TargetMachine& TM, MethodLiveVarInfo *const Lvi); - ~PhyRegAlloc(); // main method called for allocating registers diff --git a/lib/CodeGen/RegAlloc/RegClass.cpp b/lib/CodeGen/RegAlloc/RegClass.cpp index 3918871d69f..8ba6a15ad11 100644 --- a/lib/CodeGen/RegAlloc/RegClass.cpp +++ b/lib/CodeGen/RegAlloc/RegClass.cpp @@ -1,5 +1,6 @@ #include "llvm/CodeGen/RegClass.h" - +#include +using std::cerr; //---------------------------------------------------------------------------- // This constructor inits IG. The actual matrix is created by a call to @@ -11,7 +12,7 @@ RegClass::RegClass(const Method *const M, : Meth(M), MRC(Mrc), RegClassID( Mrc->getRegClassID() ), IG(this), IGNodeStack(), ReservedColorList(RCL) { if( DEBUG_RA) - cout << "Created Reg Class: " << RegClassID << endl; + cerr << "Created Reg Class: " << RegClassID << "\n"; IsColorUsedArr = new bool[ Mrc->getNumOfAllRegs() ]; } @@ -23,7 +24,7 @@ RegClass::RegClass(const Method *const M, //---------------------------------------------------------------------------- void RegClass::colorAllRegs() { - if(DEBUG_RA) cout << "Coloring IG of reg class " << RegClassID << " ...\n"; + if(DEBUG_RA) cerr << "Coloring IG of reg class " << RegClassID << " ...\n"; // pre-color IGNodes pushAllIGNodes(); // push all IG Nodes @@ -57,9 +58,9 @@ void RegClass::pushAllIGNodes() bool PushedAll = pushUnconstrainedIGNodes(); if( DEBUG_RA) { - cout << " Puhsed all-unconstrained IGNodes. "; - if( PushedAll ) cout << " No constrained nodes left."; - cout << endl; + cerr << " Puhsed all-unconstrained IGNodes. "; + if( PushedAll ) cerr << " No constrained nodes left."; + cerr << "\n"; } if( PushedAll ) // if NO constrained nodes left @@ -129,8 +130,8 @@ bool RegClass::pushUnconstrainedIGNodes() IGNode->pushOnStack(); // set OnStack and dec deg of neighs if (DEBUG_RA > 1) { - cout << " pushed un-constrained IGNode " << IGNode->getIndex() ; - cout << " on to stack" << endl; + cerr << " pushed un-constrained IGNode " << IGNode->getIndex() ; + cerr << " on to stack\n"; } } else pushedall = false; // we didn't push all live ranges @@ -215,16 +216,16 @@ void RegClass::colorIGNode(IGNode *const Node) } else { if( DEBUG_RA ) { - cout << " Node " << Node->getIndex(); - cout << " already colored with color " << Node->getColor() << endl; + cerr << " Node " << Node->getIndex(); + cerr << " already colored with color " << Node->getColor() << "\n"; } } if( !Node->hasColor() ) { if( DEBUG_RA ) { - cout << " Node " << Node->getIndex(); - cout << " - could not find a color (needs spilling)" << endl; + cerr << " Node " << Node->getIndex(); + cerr << " - could not find a color (needs spilling)\n"; } } diff --git a/lib/CodeGen/RegAlloc/RegClass.h b/lib/CodeGen/RegAlloc/RegClass.h index d6cbaf892bb..fe25986f408 100644 --- a/lib/CodeGen/RegAlloc/RegClass.h +++ b/lib/CodeGen/RegAlloc/RegClass.h @@ -13,8 +13,9 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/MachineRegInfo.h" #include +#include -typedef vector ReservedColorListType; +typedef std::vector ReservedColorListType; //----------------------------------------------------------------------------- @@ -46,7 +47,7 @@ class RegClass InterferenceGraph IG; // Interference graph - constructed by // buildInterferenceGraph - stack IGNodeStack; // the stack used for coloring + std::stack IGNodeStack; // the stack used for coloring const ReservedColorListType *const ReservedColorList; // @@ -117,21 +118,14 @@ class RegClass inline void printIGNodeList() const { - cerr << "IG Nodes for Register Class " << RegClassID << ":" << endl; + std::cerr << "IG Nodes for Register Class " << RegClassID << ":" << "\n"; IG.printIGNodeList(); } inline void printIG() { - cerr << "IG for Register Class " << RegClassID << ":" << endl; + std::cerr << "IG for Register Class " << RegClassID << ":" << "\n"; IG.printIG(); } - }; - - - - - - #endif diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index c48ec92b3e9..d92764e49a6 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -19,6 +19,10 @@ #include // For fmod #include #include +#include +using std::vector; +using std::cout; +using std::cerr; cl::Flag QuietMode ("quiet" , "Do not emit any non-program output"); cl::Alias QuietModeA("q" , "Alias for -quiet", cl::NoFlags, QuietMode); @@ -35,7 +39,7 @@ CachedWriter CW; // Object to accelerate printing of LLVM static cl::Flag ProfileStructureFields("profilestructfields", "Profile Structure Field Accesses"); #include -static map > FieldAccessCounts; +static std::map > FieldAccessCounts; #endif sigjmp_buf SignalRecoverBuffer; @@ -91,14 +95,14 @@ static GenericValue getOperandValue(Value *V, ExecutionContext &SF) { case Type::PointerTyID: if (isa(CPV)) { Result.PointerVal = 0; - } else if (ConstantPointerRef *CPR =dyn_cast(CPV)) { + } else if (isa(CPV)) { assert(0 && "Not implemented!"); } else { assert(0 && "Unknown constant pointer type!"); } break; default: - cout << "ERROR: Constant unimp for type: " << CPV->getType() << endl; + cout << "ERROR: Constant unimp for type: " << CPV->getType() << "\n"; } return Result; } else if (GlobalValue *GV = dyn_cast(V)) { @@ -134,7 +138,7 @@ static void printOperandInfo(Value *V, ExecutionContext &SF) { cout << ( Cur >= 160? char((Cur>>4)+'A'-10) : char((Cur>>4) + '0')) << ((Cur&15) >= 10? char((Cur&15)+'A'-10) : char((Cur&15) + '0')); } - cout << endl; + cout << "\n"; } } @@ -143,7 +147,7 @@ static void printOperandInfo(Value *V, ExecutionContext &SF) { static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) { unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value - //cout << "Setting value: " << &SF.Values[TyP][getOperandSlot(V)] << endl; + //cout << "Setting value: " << &SF.Values[TyP][getOperandSlot(V)] << "\n"; SF.Values[TyP][getOperandSlot(V)] = Val; } @@ -217,7 +221,7 @@ static void InitializeMemory(Constant *Init, char *Addr) { return; default: - CW << "Bad Type: " << Init->getType() << endl; + CW << "Bad Type: " << Init->getType() << "\n"; assert(0 && "Unknown constant type to initialize memory with!"); } } @@ -277,7 +281,7 @@ static GenericValue executeAddInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_BINARY_OPERATOR(+, Double); IMPLEMENT_BINARY_OPERATOR(+, Pointer); default: - cout << "Unhandled type for Add instruction: " << Ty << endl; + cout << "Unhandled type for Add instruction: " << Ty << "\n"; } return Dest; } @@ -298,7 +302,7 @@ static GenericValue executeSubInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_BINARY_OPERATOR(-, Double); IMPLEMENT_BINARY_OPERATOR(-, Pointer); default: - cout << "Unhandled type for Sub instruction: " << Ty << endl; + cout << "Unhandled type for Sub instruction: " << Ty << "\n"; } return Dest; } @@ -319,7 +323,7 @@ static GenericValue executeMulInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_BINARY_OPERATOR(*, Double); IMPLEMENT_BINARY_OPERATOR(*, Pointer); default: - cout << "Unhandled type for Mul instruction: " << Ty << endl; + cout << "Unhandled type for Mul instruction: " << Ty << "\n"; } return Dest; } @@ -340,7 +344,7 @@ static GenericValue executeDivInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_BINARY_OPERATOR(/, Double); IMPLEMENT_BINARY_OPERATOR(/, Pointer); default: - cout << "Unhandled type for Div instruction: " << Ty << endl; + cout << "Unhandled type for Div instruction: " << Ty << "\n"; } return Dest; } @@ -365,7 +369,7 @@ static GenericValue executeRemInst(GenericValue Src1, GenericValue Src2, Dest.DoubleVal = fmod(Src1.DoubleVal, Src2.DoubleVal); break; default: - cout << "Unhandled type for Rem instruction: " << Ty << endl; + cout << "Unhandled type for Rem instruction: " << Ty << "\n"; } return Dest; } @@ -384,7 +388,7 @@ static GenericValue executeAndInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_BINARY_OPERATOR(&, Long); IMPLEMENT_BINARY_OPERATOR(&, Pointer); default: - cout << "Unhandled type for And instruction: " << Ty << endl; + cout << "Unhandled type for And instruction: " << Ty << "\n"; } return Dest; } @@ -404,7 +408,7 @@ static GenericValue executeOrInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_BINARY_OPERATOR(|, Long); IMPLEMENT_BINARY_OPERATOR(|, Pointer); default: - cout << "Unhandled type for Or instruction: " << Ty << endl; + cout << "Unhandled type for Or instruction: " << Ty << "\n"; } return Dest; } @@ -424,7 +428,7 @@ static GenericValue executeXorInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_BINARY_OPERATOR(^, Long); IMPLEMENT_BINARY_OPERATOR(^, Pointer); default: - cout << "Unhandled type for Xor instruction: " << Ty << endl; + cout << "Unhandled type for Xor instruction: " << Ty << "\n"; } return Dest; } @@ -449,7 +453,7 @@ static GenericValue executeSetEQInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_SETCC(==, Double); IMPLEMENT_SETCC(==, Pointer); default: - cout << "Unhandled type for SetEQ instruction: " << Ty << endl; + cout << "Unhandled type for SetEQ instruction: " << Ty << "\n"; } return Dest; } @@ -471,7 +475,7 @@ static GenericValue executeSetNEInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_SETCC(!=, Pointer); default: - cout << "Unhandled type for SetNE instruction: " << Ty << endl; + cout << "Unhandled type for SetNE instruction: " << Ty << "\n"; } return Dest; } @@ -492,7 +496,7 @@ static GenericValue executeSetLEInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_SETCC(<=, Double); IMPLEMENT_SETCC(<=, Pointer); default: - cout << "Unhandled type for SetLE instruction: " << Ty << endl; + cout << "Unhandled type for SetLE instruction: " << Ty << "\n"; } return Dest; } @@ -513,7 +517,7 @@ static GenericValue executeSetGEInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_SETCC(>=, Double); IMPLEMENT_SETCC(>=, Pointer); default: - cout << "Unhandled type for SetGE instruction: " << Ty << endl; + cout << "Unhandled type for SetGE instruction: " << Ty << "\n"; } return Dest; } @@ -534,7 +538,7 @@ static GenericValue executeSetLTInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_SETCC(<, Double); IMPLEMENT_SETCC(<, Pointer); default: - cout << "Unhandled type for SetLT instruction: " << Ty << endl; + cout << "Unhandled type for SetLT instruction: " << Ty << "\n"; } return Dest; } @@ -555,7 +559,7 @@ static GenericValue executeSetGTInst(GenericValue Src1, GenericValue Src2, IMPLEMENT_SETCC(>, Double); IMPLEMENT_SETCC(>, Pointer); default: - cout << "Unhandled type for SetGT instruction: " << Ty << endl; + cout << "Unhandled type for SetGT instruction: " << Ty << "\n"; } return Dest; } @@ -598,7 +602,7 @@ static void PerformExitStuff() { // Print out structure field accounting information... if (!FieldAccessCounts.empty()) { CW << "Profile Field Access Counts:\n"; - map >::iterator + std::map >::iterator I = FieldAccessCounts.begin(), E = FieldAccessCounts.end(); for (; I != E; ++I) { vector &OfC = I->second; @@ -613,9 +617,9 @@ static void PerformExitStuff() { if (i) CW << ", "; CW << OfC[i]; } - CW << endl; + CW << "\n"; } - CW << endl; + CW << "\n"; CW << "Profile Field Access Percentages:\n"; cout.precision(3); @@ -630,9 +634,9 @@ static void PerformExitStuff() { if (i) CW << ", "; CW << double(OfC[i])/Sum; } - CW << endl; + CW << "\n"; } - CW << endl; + CW << "\n"; FieldAccessCounts.clear(); } @@ -673,7 +677,7 @@ void Interpreter::executeRetInst(ReturnInst *I, ExecutionContext &SF) { CW << "Method " << M->getType() << " \"" << M->getName() << "\" returned "; print(RetTy, Result); - cout << endl; + cout << "\n"; } if (RetTy->isIntegral()) @@ -701,7 +705,7 @@ void Interpreter::executeRetInst(ReturnInst *I, ExecutionContext &SF) { CW << "Method " << M->getType() << " \"" << M->getName() << "\" returned "; print(RetTy, Result); - cout << endl; + cout << "\n"; } } @@ -930,7 +934,7 @@ static void executeShlInst(ShiftInst *I, ExecutionContext &SF) { IMPLEMENT_SHIFT(<<, ULong); IMPLEMENT_SHIFT(<<, Long); default: - cout << "Unhandled type for Shl instruction: " << Ty << endl; + cout << "Unhandled type for Shl instruction: " << Ty << "\n"; } SetValue(I, Dest, SF); } @@ -951,7 +955,7 @@ static void executeShrInst(ShiftInst *I, ExecutionContext &SF) { IMPLEMENT_SHIFT(>>, ULong); IMPLEMENT_SHIFT(>>, Long); default: - cout << "Unhandled type for Shr instruction: " << Ty << endl; + cout << "Unhandled type for Shr instruction: " << Ty << "\n"; } SetValue(I, Dest, SF); } @@ -977,7 +981,7 @@ static void executeShrInst(ShiftInst *I, ExecutionContext &SF) { IMPLEMENT_CAST(DESTTY, DESTCTY, Double) #define IMPLEMENT_CAST_CASE_END() \ - default: cout << "Unhandled cast: " << SrcTy << " to " << Ty << endl; \ + default: cout << "Unhandled cast: " << SrcTy << " to " << Ty << "\n"; \ break; \ } \ break @@ -1006,7 +1010,7 @@ static void executeCastInst(CastInst *I, ExecutionContext &SF) { IMPLEMENT_CAST_CASE(Float , (float)); IMPLEMENT_CAST_CASE(Double , (double)); default: - cout << "Unhandled dest type for cast instruction: " << Ty << endl; + cout << "Unhandled dest type for cast instruction: " << Ty << "\n"; } SetValue(I, Dest, SF); } @@ -1060,7 +1064,6 @@ void Interpreter::callMethod(Method *M, const vector &ArgVals) { if (RetTy != Type::VoidTy) { if (!ECStack.empty() && ECStack.back().Caller) { ExecutionContext &SF = ECStack.back(); - CallInst *Caller = SF.Caller; SetValue(SF.Caller, Result, SF); SF.Caller = 0; // We returned from the call... @@ -1069,7 +1072,7 @@ void Interpreter::callMethod(Method *M, const vector &ArgVals) { CW << "Method " << M->getType() << " \"" << M->getName() << "\" returned "; print(RetTy, Result); - cout << endl; + cout << "\n"; if (RetTy->isIntegral()) ExitCode = Result.SByteVal; // Capture the exit code of the program @@ -1290,8 +1293,8 @@ void Interpreter::printValue(const Type *Ty, GenericValue V) { case Type::UShortTyID: cout << V.UShortVal; break; case Type::IntTyID: cout << V.IntVal; break; case Type::UIntTyID: cout << V.UIntVal; break; - case Type::LongTyID: cout << V.LongVal; break; - case Type::ULongTyID: cout << V.ULongVal; break; + case Type::LongTyID: cout << (long)V.LongVal; break; + case Type::ULongTyID: cout << (unsigned long)V.ULongVal; break; case Type::FloatTyID: cout << V.FloatVal; break; case Type::DoubleTyID: cout << V.DoubleVal; break; case Type::PointerTyID:cout << (void*)V.PointerVal; break; @@ -1306,31 +1309,31 @@ void Interpreter::print(const Type *Ty, GenericValue V) { printValue(Ty, V); } -void Interpreter::print(const string &Name) { +void Interpreter::print(const std::string &Name) { Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name)); if (!PickedVal) return; if (const Method *M = dyn_cast(PickedVal)) { CW << M; // Print the method } else if (const Type *Ty = dyn_cast(PickedVal)) { - CW << "type %" << Name << " = " << Ty->getDescription() << endl; + CW << "type %" << Name << " = " << Ty->getDescription() << "\n"; } else if (const BasicBlock *BB = dyn_cast(PickedVal)) { CW << BB; // Print the basic block } else { // Otherwise there should be an annotation for the slot# print(PickedVal->getType(), getOperandValue(PickedVal, ECStack[CurFrame])); - cout << endl; + cout << "\n"; } } -void Interpreter::infoValue(const string &Name) { +void Interpreter::infoValue(const std::string &Name) { Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name)); if (!PickedVal) return; cout << "Value: "; print(PickedVal->getType(), getOperandValue(PickedVal, ECStack[CurFrame])); - cout << endl; + cout << "\n"; printOperandInfo(PickedVal, ECStack[CurFrame]); } @@ -1353,7 +1356,7 @@ void Interpreter::printStackFrame(int FrameNo = -1) { printValue(Args[i]->getType(), getOperandValue(Args[i], ECStack[FrameNo])); } - cout << ")" << endl; + cout << ")\n"; CW << *(ECStack[FrameNo].CurInst-(FrameNo != int(ECStack.size()-1))); } diff --git a/lib/ExecutionEngine/Interpreter/ExecutionAnnotations.h b/lib/ExecutionEngine/Interpreter/ExecutionAnnotations.h index f6a27265f04..12717ec48e0 100644 --- a/lib/ExecutionEngine/Interpreter/ExecutionAnnotations.h +++ b/lib/ExecutionEngine/Interpreter/ExecutionAnnotations.h @@ -23,7 +23,7 @@ static AnnotationID MethodInfoAID( struct MethodInfo : public Annotation { MethodInfo(Method *M); - vector NumPlaneElements; + std::vector NumPlaneElements; // Create - Factory function to allow MethodInfo annotations to be diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index a54a6f1ced0..bcff5e57954 100644 --- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -13,26 +13,29 @@ #include "llvm/DerivedTypes.h" #include #include +#include #include #include #include +using std::vector; +using std::cout; typedef GenericValue (*ExFunc)(MethodType *, const vector &); -static map Functions; -static map FuncNames; +static std::map Functions; +static std::map FuncNames; static Interpreter *TheInterpreter; // getCurrentExecutablePath() - Return the directory that the lli executable // lives in. // -string Interpreter::getCurrentExecutablePath() const { +std::string Interpreter::getCurrentExecutablePath() const { Dl_info Info; if (dladdr(&TheInterpreter, &Info) == 0) return ""; - string LinkAddr(Info.dli_fname); + std::string LinkAddr(Info.dli_fname); unsigned SlashPos = LinkAddr.rfind('/'); - if (SlashPos != string::npos) + if (SlashPos != std::string::npos) LinkAddr.resize(SlashPos); // Trim the executable name off... return LinkAddr; @@ -65,7 +68,7 @@ static char getTypeID(const Type *Ty) { static ExFunc lookupMethod(const Method *M) { // Function not found, look it up... start by figuring out what the // composite function name should be. - string ExtName = "lle_"; + std::string ExtName = "lle_"; const MethodType *MT = M->getMethodType(); for (unsigned i = 0; const Type *Ty = MT->getContainedType(i); ++i) ExtName += getTypeID(Ty); @@ -80,7 +83,7 @@ static ExFunc lookupMethod(const Method *M) { if (FnPtr == 0) // Try calling a generic function... if it exists... FnPtr = (ExFunc)dlsym(RTLD_DEFAULT, ("lle_X_"+M->getName()).c_str()); if (FnPtr != 0) - Functions.insert(make_pair(M, FnPtr)); // Cache for later + Functions.insert(std::make_pair(M, FnPtr)); // Cache for later return FnPtr; } @@ -90,11 +93,11 @@ GenericValue Interpreter::callExternalMethod(Method *M, // Do a lookup to see if the method is in our cache... this should just be a // defered annotation! - map::iterator FI = Functions.find(M); + std::map::iterator FI = Functions.find(M); ExFunc Fn = (FI == Functions.end()) ? lookupMethod(M) : FI->second; if (Fn == 0) { cout << "Tried to execute an unknown external method: " - << M->getType()->getDescription() << " " << M->getName() << endl; + << M->getType()->getDescription() << " " << M->getName() << "\n"; return GenericValue(); } @@ -177,13 +180,13 @@ GenericValue lle_Vb_putchar(MethodType *M, const vector &Args) { // int "putchar"(int) GenericValue lle_ii_putchar(MethodType *M, const vector &Args) { - cout << ((char)Args[0].IntVal) << flush; + cout << ((char)Args[0].IntVal) << std::flush; return Args[0]; } // void "putchar"(ubyte) GenericValue lle_VB_putchar(MethodType *M, const vector &Args) { - cout << Args[0].SByteVal << flush; + cout << Args[0].SByteVal << std::flush; return Args[0]; } diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.h b/lib/ExecutionEngine/Interpreter/Interpreter.h index 44b382bd9f0..ffe10015978 100644 --- a/lib/ExecutionEngine/Interpreter/Interpreter.h +++ b/lib/ExecutionEngine/Interpreter/Interpreter.h @@ -41,7 +41,7 @@ union GenericValue { PointerTy PointerVal; }; -typedef vector ValuePlaneTy; +typedef std::vector ValuePlaneTy; // ExecutionContext struct - This struct represents one stack frame currently // executing. @@ -51,7 +51,7 @@ struct ExecutionContext { BasicBlock *CurBB; // The currently executing BB BasicBlock::iterator CurInst; // The next instruction to execute MethodInfo *MethInfo; // The MethInfo annotation for the method - vector Values; // ValuePlanes for each type + std::vector Values;// ValuePlanes for each type BasicBlock *PrevBB; // The previous BB or null if in first BB CallInst *Caller; // Holds the call that called subframes. @@ -69,7 +69,7 @@ class Interpreter { // The runtime stack of executing code. The top of the stack is the current // method record. - vector ECStack; + std::vector ECStack; public: Interpreter(); @@ -86,24 +86,24 @@ public: void handleUserInput(); // User Interation Methods... - void loadModule(const string &Filename); + void loadModule(const std::string &Filename); bool flushModule(); - bool callMethod(const string &Name); // return true on failure - void setBreakpoint(const string &Name); - void infoValue(const string &Name); - void print(const string &Name); + bool callMethod(const std::string &Name); // return true on failure + void setBreakpoint(const std::string &Name); + void infoValue(const std::string &Name); + void print(const std::string &Name); static void print(const Type *Ty, GenericValue V); static void printValue(const Type *Ty, GenericValue V); // Hack until we can parse command line args... - bool callMainMethod(const string &MainName, - const vector &InputFilename); + bool callMainMethod(const std::string &MainName, + const std::vector &InputFilename); void list(); // Do the 'list' command void printStackTrace(); // Do the 'backtrace' command // Code execution methods... - void callMethod (Method *Meth, const vector &ArgVals); + void callMethod(Method *Meth, const std::vector &ArgVals); bool executeInstruction(); // Execute one instruction... void stepInstruction(); // Do the 'step' command @@ -117,7 +117,7 @@ public: void executeBrInst(BranchInst *I, ExecutionContext &SF); void executeAllocInst(AllocationInst *I, ExecutionContext &SF); GenericValue callExternalMethod(Method *Meth, - const vector &ArgVals); + const std::vector &ArgVals); void exitCalled(GenericValue GV); // getCurrentMethod - Return the currently executing method @@ -134,7 +134,7 @@ private: // Helper functions // getCurrentExecutablePath() - Return the directory that the lli executable // lives in. // - string getCurrentExecutablePath() const; + std::string getCurrentExecutablePath() const; // printCurrentInstruction - Print out the instruction that the virtual PC is // at, or fail silently if no program is running. @@ -151,13 +151,14 @@ private: // Helper functions // matches to that name. This is obviously slow, and should only be used for // user interaction. // - vector LookupMatchingNames(const string &Name); + std::vector LookupMatchingNames(const std::string &Name); // ChooseOneOption - Prompt the user to choose among the specified options to // pick one value. If no options are provided, emit an error. If a single // option is provided, just return that option. // - Value *ChooseOneOption(const string &Name, const vector &Opts); + Value *ChooseOneOption(const std::string &Name, + const std::vector &Opts); void initializeExecutionEngine(); diff --git a/lib/ExecutionEngine/Interpreter/Support.cpp b/lib/ExecutionEngine/Interpreter/Support.cpp index a619304c62b..ca89ae33332 100644 --- a/lib/ExecutionEngine/Interpreter/Support.cpp +++ b/lib/ExecutionEngine/Interpreter/Support.cpp @@ -7,13 +7,15 @@ #include "Interpreter.h" #include "llvm/SymbolTable.h" #include "llvm/Assembly/Writer.h" +#include +using std::cout; //===----------------------------------------------------------------------===// // // LookupMatchingNames helper - Search a symbol table for values matching Name. // -static inline void LookupMatchingNames(const string &Name, SymTabValue &STV, - vector &Results) { +static inline void LookupMatchingNames(const std::string &Name,SymTabValue &STV, + std::vector &Results) { SymbolTable *SymTab = STV.getSymbolTable(); if (SymTab == 0) return; // No symbolic values :( @@ -34,8 +36,8 @@ static inline void LookupMatchingNames(const string &Name, SymTabValue &STV, // matches to that name. This is obviously slow, and should only be used for // user interaction. // -vector Interpreter::LookupMatchingNames(const string &Name) { - vector Results; +std::vector Interpreter::LookupMatchingNames(const std::string &Name) { + std::vector Results; Method *CurMeth = getCurrentMethod(); if (CurMeth) ::LookupMatchingNames(Name, *CurMeth, Results); @@ -47,8 +49,8 @@ vector Interpreter::LookupMatchingNames(const string &Name) { // pick one value. If no options are provided, emit an error. If a single // option is provided, just return that option. // -Value *Interpreter::ChooseOneOption(const string &Name, - const vector &Opts) { +Value *Interpreter::ChooseOneOption(const std::string &Name, + const std::vector &Opts) { switch (Opts.size()) { case 1: return Opts[0]; case 0: @@ -61,16 +63,16 @@ Value *Interpreter::ChooseOneOption(const string &Name, cout << " 0. Cancel operation\n"; for (unsigned i = 0; i < Opts.size(); ++i) { cout << " " << (i+1) << "."; - WriteAsOperand(cout, Opts[i]) << endl; + WriteAsOperand(cout, Opts[i]) << "\n"; } unsigned Option; do { - cout << "lli> " << flush; - cin >> Option; + cout << "lli> " << std::flush; + std::cin >> Option; if (Option > Opts.size()) cout << "Invalid selection: Please choose from 0 to " << Opts.size() - << endl; + << "\n"; } while (Option > Opts.size()); if (Option == 0) return 0; diff --git a/lib/ExecutionEngine/Interpreter/UserInput.cpp b/lib/ExecutionEngine/Interpreter/UserInput.cpp index 179b97d277f..1cd8b08c1fd 100644 --- a/lib/ExecutionEngine/Interpreter/UserInput.cpp +++ b/lib/ExecutionEngine/Interpreter/UserInput.cpp @@ -10,6 +10,9 @@ #include "llvm/DerivedTypes.h" #include "llvm/Transforms/Linker.h" #include +using std::string; +using std::cout; +using std::cin; enum CommandID { Quit, Help, // Basics @@ -69,14 +72,14 @@ void Interpreter::handleUserInput() { bool UserQuit = false; // Sort the table... - sort(CommandTable, CommandTableEnd); + std::sort(CommandTable, CommandTableEnd); // Print the instruction that we are stopped at... printCurrentInstruction(); do { string Command; - cout << "lli> " << flush; + cout << "lli> " << std::flush; cin >> Command; CommandTableElement *E = find(CommandTable, CommandTableEnd, Command); @@ -164,11 +167,11 @@ void Interpreter::loadModule(const string &Filename) { if (Module *SupportLib = ParseBytecodeFile(RuntimeLib, &ErrorMsg)) { if (LinkModules(CurMod, SupportLib, &ErrorMsg)) - cerr << "Error Linking runtime library into current module: " - << ErrorMsg << endl; + std::cerr << "Error Linking runtime library into current module: " + << ErrorMsg << "\n"; } else { - cerr << "Error loading runtime library '"+RuntimeLib+"': " - << ErrorMsg << "\n"; + std::cerr << "Error loading runtime library '"+RuntimeLib+"': " + << ErrorMsg << "\n"; } } @@ -208,7 +211,7 @@ void Interpreter::setBreakpoint(const string &Name) { // callMethod - Enter the specified method... // bool Interpreter::callMethod(const string &Name) { - vector Options = LookupMatchingNames(Name); + std::vector Options = LookupMatchingNames(Name); for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches... if (!isa(Options[i])) { @@ -223,7 +226,7 @@ bool Interpreter::callMethod(const string &Name) { Method *M = cast(PickedMeth); - vector Args; + std::vector Args; // TODO, get args from user... callMethod(M, Args); // Start executing it... @@ -234,7 +237,7 @@ bool Interpreter::callMethod(const string &Name) { return false; } -static void *CreateArgv(const vector &InputArgv) { +static void *CreateArgv(const std::vector &InputArgv) { // Pointers are 64 bits... uint64_t *Result = new PointerTy[InputArgv.size()+1]; @@ -255,8 +258,8 @@ static void *CreateArgv(const vector &InputArgv) { // callMethod can parse command line options and stuff for us. // bool Interpreter::callMainMethod(const string &Name, - const vector &InputArgv) { - vector Options = LookupMatchingNames(Name); + const std::vector &InputArgv) { + std::vector Options = LookupMatchingNames(Name); for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches... if (!isa(Options[i])) { @@ -272,7 +275,7 @@ bool Interpreter::callMainMethod(const string &Name, Method *M = cast(PickedMeth); const MethodType *MT = M->getMethodType(); - vector Args; + std::vector Args; switch (MT->getParamTypes().size()) { default: cout << "Unknown number of arguments to synthesize for '" << Name << "'!\n"; diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index f04c8a46a31..e1622529c26 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -17,6 +17,10 @@ #include "llvm/DerivedTypes.h" #include "llvm/iOther.h" #include "llvm/ConstantVals.h" +#include +using std::cerr; +using std::string; +using std::map; // Error - Simple wrapper function to conditionally assign to E and return true. // This just makes error return conditions a little bit simpler... @@ -70,7 +74,7 @@ static void PrintMap(const map &M) { for (map::const_iterator I = M.begin(), E = M.end(); I != E; ++I) { cerr << " Fr: " << (void*)I->first << " " << I->first - << " To: " << (void*)I->second << " " << I->second << endl; + << " To: " << (void*)I->second << " " << I->second << "\n"; } } @@ -97,15 +101,15 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Constant *Result = 0; if (ConstantArray *CPA = dyn_cast(CPV)) { - const vector &Ops = CPA->getValues(); - vector Operands(Ops.size()); + const std::vector &Ops = CPA->getValues(); + std::vector Operands(Ops.size()); for (unsigned i = 0; i < Ops.size(); ++i) Operands[i] = cast(RemapOperand(Ops[i], LocalMap, GlobalMap)); Result = ConstantArray::get(cast(CPA->getType()), Operands); } else if (ConstantStruct *CPS = dyn_cast(CPV)) { - const vector &Ops = CPS->getValues(); - vector Operands(Ops.size()); + const std::vector &Ops = CPS->getValues(); + std::vector Operands(Ops.size()); for (unsigned i = 0; i < Ops.size(); ++i) Operands[i] = cast(RemapOperand(Ops[i], LocalMap, GlobalMap)); @@ -120,7 +124,7 @@ static Value *RemapOperand(const Value *In, map &LocalMap, } // Cache the mapping in our local map structure... - LocalMap.insert(make_pair(In, CPV)); + LocalMap.insert(std::make_pair(In, CPV)); return Result; } @@ -132,7 +136,7 @@ static Value *RemapOperand(const Value *In, map &LocalMap, PrintMap(*GlobalMap); } - cerr << "Couldn't remap value: " << (void*)In << " " << In << endl; + cerr << "Couldn't remap value: " << (void*)In << " " << In << "\n"; assert(0 && "Couldn't remap value!"); return 0; } @@ -172,7 +176,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src, " - Global variables differ in const'ness"); // Okay, everything is cool, remember the mapping... - ValueMap.insert(make_pair(SGV, DGV)); + ValueMap.insert(std::make_pair(SGV, DGV)); } else { // No linking to be performed, simply create an identical version of the // symbol over in the dest module... the initializer will be filled in @@ -186,7 +190,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src, Dest->getGlobalList().push_back(DGV); // Make sure to remember this mapping... - ValueMap.insert(make_pair(SGV, DGV)); + ValueMap.insert(std::make_pair(SGV, DGV)); } } return false; @@ -262,7 +266,7 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src, SM->getName() + "\" - Method is already defined!"); // Otherwise, just remember this mapping... - ValueMap.insert(make_pair(SM, DM)); + ValueMap.insert(std::make_pair(SM, DM)); } else { // Method does not already exist, simply insert an external method // signature identical to SM into the dest module... @@ -273,7 +277,7 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src, Dest->getMethodList().push_back(DM); // ... and remember this mapping... - ValueMap.insert(make_pair(SM, DM)); + ValueMap.insert(std::make_pair(SM, DM)); } } return false; @@ -300,7 +304,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src, Dest->getArgumentList().push_back(DMA); // Add a mapping to our local map - LocalMap.insert(make_pair(SMA, DMA)); + LocalMap.insert(std::make_pair(SMA, DMA)); } // Loop over all of the basic blocks, copying the instructions over... @@ -310,7 +314,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src, // Create new basic block and add to mapping and the Dest method... BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest); - LocalMap.insert(make_pair(SBB, DBB)); + LocalMap.insert(std::make_pair(SBB, DBB)); // Loop over all of the instructions in the src basic block, copying them // over. Note that this is broken in a strict sense because the cloned @@ -324,7 +328,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src, Instruction *DI = SI->clone(); DI->setName(SI->getName()); DBB->getInstList().push_back(DI); - LocalMap.insert(make_pair(SI, DI)); + LocalMap.insert(std::make_pair(SI, DI)); } } diff --git a/lib/Support/Annotation.cpp b/lib/Support/Annotation.cpp index 65a049d42dc..d0d13cda866 100644 --- a/lib/Support/Annotation.cpp +++ b/lib/Support/Annotation.cpp @@ -6,6 +6,10 @@ #include #include "llvm/Annotation.h" +using std::string; +using std::map; +using std::pair; +using std::make_pair; typedef map IDMapType; static unsigned IDCounter = 0; // Unique ID counter diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index f6938169dab..549f42c4e3b 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -15,7 +15,13 @@ #include #include #include +#include using namespace cl; +using std::map; +using std::pair; +using std::vector; +using std::string; +using std::cerr; // Return the global command line option vector. Making it a function scoped // static ensures that it will be initialized correctly before its first use. @@ -31,7 +37,7 @@ static void AddArgument(const string &ArgName, Option *Opt) { << "' specified more than once!\n"; } else { // Add argument to the argument map! - getOpts().insert(make_pair(ArgName, Opt)); + getOpts().insert(std::make_pair(ArgName, Opt)); } } @@ -59,7 +65,7 @@ static inline bool ProvideOption(Option *Handler, const char *ArgName, break; case ValueOptional: break; default: cerr << "Bad ValueMask flag! CommandLine usage error:" - << Handler->getValueExpectedFlag() << endl; abort(); + << Handler->getValueExpectedFlag() << "\n"; abort(); } // Run the handler now! @@ -210,7 +216,7 @@ Option::Option(const char *argStr, const char *helpStr, int flags) bool Option::error(string Message, const char *ArgName = 0) { if (ArgName == 0) ArgName = ArgStr; - cerr << "-" << ArgName << " option" << Message << endl; + cerr << "-" << ArgName << " option" << Message << "\n"; return true; } @@ -244,7 +250,7 @@ void Option::printOptionInfo(unsigned GlobalWidth) const { unsigned L = std::strlen(ArgStr); if (L == 0) return; // Don't print the empty arg like this! cerr << " -" << ArgStr << string(GlobalWidth-L-6, ' ') << " - " - << HelpStr << endl; + << HelpStr << "\n"; } @@ -301,8 +307,8 @@ void EnumBase::processValues(va_list Vals) { while (const char *EnumName = va_arg(Vals, const char *)) { int EnumVal = va_arg(Vals, int); const char *EnumDesc = va_arg(Vals, const char *); - ValueMap.push_back(make_pair(EnumName, // Add value to value map - make_pair(EnumVal, EnumDesc))); + ValueMap.push_back(std::make_pair(EnumName, // Add value to value map + std::make_pair(EnumVal, EnumDesc))); } } @@ -339,7 +345,7 @@ bool EnumValueBase::handleOccurance(const char *ArgName, const string &Arg) { unsigned EnumValueBase::getOptionWidth() const { unsigned BaseSize = Option::getOptionWidth(); for (unsigned i = 0; i < ValueMap.size(); ++i) - BaseSize = max(BaseSize, std::strlen(ValueMap[i].first)+8); + BaseSize = std::max(BaseSize, std::strlen(ValueMap[i].first)+8); return BaseSize; } @@ -354,7 +360,7 @@ void EnumValueBase::printOptionInfo(unsigned GlobalWidth) const { << ValueMap[i].second.second; if (i == 0) cerr << " (default)"; - cerr << endl; + cerr << "\n"; } } @@ -369,7 +375,7 @@ bool EnumFlagsBase::handleOccurance(const char *ArgName, const string &Arg) { unsigned EnumFlagsBase::getOptionWidth() const { unsigned BaseSize = 0; for (unsigned i = 0; i < ValueMap.size(); ++i) - BaseSize = max(BaseSize, std::strlen(ValueMap[i].first)+6); + BaseSize = std::max(BaseSize, std::strlen(ValueMap[i].first)+6); return BaseSize; } @@ -379,7 +385,7 @@ void EnumFlagsBase::printOptionInfo(unsigned GlobalWidth) const { cerr << " -" << ValueMap[i].first << string(GlobalWidth-L-6, ' ') << " - " << ValueMap[i].second.second; if (i == 0) cerr << " (default)"; - cerr << endl; + cerr << "\n"; } } @@ -402,7 +408,7 @@ bool EnumListBase::handleOccurance(const char *ArgName, const string &Arg) { unsigned EnumListBase::getOptionWidth() const { unsigned BaseSize = 0; for (unsigned i = 0; i < ValueMap.size(); ++i) - BaseSize = max(BaseSize, std::strlen(ValueMap[i].first)+6); + BaseSize = std::max(BaseSize, std::strlen(ValueMap[i].first)+6); return BaseSize; } @@ -414,7 +420,7 @@ void EnumListBase::printOptionInfo(unsigned GlobalWidth) const { for (unsigned i = 0; i < ValueMap.size(); ++i) { unsigned L = std::strlen(ValueMap[i].first); cerr << " -" << ValueMap[i].first << string(GlobalWidth-L-6, ' ') << " - " - << ValueMap[i].second.second << endl; + << ValueMap[i].second.second << "\n"; } } @@ -440,15 +446,15 @@ class Help : public Option { virtual bool handleOccurance(const char *ArgName, const string &Arg) { // Copy Options into a vector so we can sort them as we like... vector > Options; - copy(getOpts().begin(), getOpts().end(), back_inserter(Options)); + copy(getOpts().begin(), getOpts().end(), std::back_inserter(Options)); // Eliminate Hidden or ReallyHidden arguments, depending on ShowHidden Options.erase(remove_if(Options.begin(), Options.end(), - ptr_fun(ShowHidden ? isReallyHidden : isHidden)), + std::ptr_fun(ShowHidden ? isReallyHidden : isHidden)), Options.end()); // Eliminate duplicate entries in table (from enum flags options, f.e.) - set OptionSet; + std::set OptionSet; for (unsigned i = 0; i < Options.size(); ) if (OptionSet.count(Options[i].second) == 0) OptionSet.insert(Options[i++].second); // Add to set @@ -457,7 +463,7 @@ class Help : public Option { if (ProgramOverview) - cerr << "OVERVIEW:" << ProgramOverview << endl; + cerr << "OVERVIEW:" << ProgramOverview << "\n"; // TODO: Sort options by some criteria cerr << "USAGE: " << ProgramName << " [options]\n\n"; @@ -478,7 +484,7 @@ class Help : public Option { void getMaxArgLen(pair OptPair) { const Option *Opt = OptPair.second; if (Opt->ArgStr[0] == 0) EmptyArg = Opt; // Capture the empty arg if exists - MaxArgLen = max(MaxArgLen, Opt->getOptionWidth()); + MaxArgLen = std::max(MaxArgLen, Opt->getOptionWidth()); } void printOption(pair OptPair) { diff --git a/lib/Target/SparcV9/InstrSched/InstrScheduling.cpp b/lib/Target/SparcV9/InstrSched/InstrScheduling.cpp index 528e5abdd34..ea41b6f8222 100644 --- a/lib/Target/SparcV9/InstrSched/InstrScheduling.cpp +++ b/lib/Target/SparcV9/InstrSched/InstrScheduling.cpp @@ -18,10 +18,12 @@ #include "llvm/Instruction.h" #include "Support/CommandLine.h" #include "SchedPriorities.h" -#include #include #include - +#include +#include +using std::cerr; +using std::vector; //************************* External Data Types *****************************/ @@ -353,11 +355,11 @@ private: unsigned int totalInstrCount; cycles_t curTime; cycles_t nextEarliestIssueTime; // next cycle we can issue - vector > choicesForSlot; // indexed by slot# + vector > choicesForSlot; // indexed by slot# vector choiceVec; // indexed by node ptr vector numInClass; // indexed by sched class vector nextEarliestStartTime; // indexed by opCode - hash_map delaySlotInfoForBranches; + std::hash_map delaySlotInfoForBranches; // indexed by branch node ptr public: @@ -419,7 +421,7 @@ public: return choiceVec[i]; } - inline hash_set& getChoicesForSlot(unsigned slotNum) { + inline std::hash_set& getChoicesForSlot(unsigned slotNum) { assert(slotNum < nslots); return choicesForSlot[slotNum]; } @@ -495,7 +497,7 @@ public: bool createIfMissing=false) { DelaySlotInfo* dinfo; - hash_map::const_iterator + std::hash_map::const_iterator I = delaySlotInfoForBranches.find(bn); if (I == delaySlotInfoForBranches.end()) { @@ -552,7 +554,7 @@ SchedulingManager::updateEarliestStartTimes(const SchedGraphNode* node, { if (schedInfo.numBubblesAfter(node->getOpCode()) > 0) { // Update next earliest time before which *nothing* can issue. - nextEarliestIssueTime = max(nextEarliestIssueTime, + nextEarliestIssueTime = std::max(nextEarliestIssueTime, curTime + 1 + schedInfo.numBubblesAfter(node->getOpCode())); } @@ -603,7 +605,7 @@ AssignInstructionsToSlots(class SchedulingManager& S, unsigned maxIssue) unsigned numIssued; for (numIssued = 0; numIssued < maxIssue; numIssued++) { - int chosenSlot = -1, chosenNodeIndex = -1; + int chosenSlot = -1; for (unsigned s=startSlot; s < S.nslots; s++) if ((*igroup)[s] == NULL && S.getChoicesForSlot(s).size() == 1) { @@ -877,7 +879,7 @@ FindSlotChoices(SchedulingManager& S, assert(s < S.nslots && "No feasible slot for instruction?"); - highestSlotUsed = max(highestSlotUsed, (int) s); + highestSlotUsed = std::max(highestSlotUsed, (int) s); } assert(highestSlotUsed <= (int) S.nslots-1 && "Invalid slot used?"); @@ -961,7 +963,6 @@ FindSlotChoices(SchedulingManager& S, // Otherwise, just ignore the instruction. for (unsigned i=indexForBreakingNode+1; i < S.getNumChoices(); i++) { - bool foundLowerSlot = false; MachineOpCode opCode = S.getChoice(i)->getOpCode(); for (unsigned int s=startSlot; s < nslotsToUse; s++) if (S.schedInfo.instrCanUseSlot(opCode, s)) @@ -1001,15 +1002,15 @@ ChooseOneGroup(SchedulingManager& S) { for (cycles_t c = firstCycle; c <= S.getTime(); c++) { - cout << " Cycle " << c << " : Scheduled instructions:\n"; + cerr << " Cycle " << (long)c << " : Scheduled instructions:\n"; const InstrGroup* igroup = S.isched.getIGroup(c); for (unsigned int s=0; s < S.nslots; s++) { - cout << " "; + cerr << " "; if ((*igroup)[s] != NULL) - cout << * ((*igroup)[s])->getMachineInstr() << endl; + cerr << * ((*igroup)[s])->getMachineInstr() << "\n"; else - cout << "" << endl; + cerr << "\n"; } } } @@ -1056,9 +1057,9 @@ ForwardListSchedule(SchedulingManager& S) // an instruction can be issued, or the next earliest in which // one will be ready, or to the next cycle, whichever is latest. // - S.updateTime(max(S.getTime() + 1, - max(S.getEarliestIssueTime(), - S.schedPrio.getEarliestReadyTime()))); + S.updateTime(std::max(S.getTime() + 1, + std::max(S.getEarliestIssueTime(), + S.schedPrio.getEarliestReadyTime()))); } } @@ -1499,8 +1500,7 @@ ScheduleInstructionsWithSSA(Method* method, if (SchedDebugLevel >= Sched_PrintSchedGraphs) { - cout << endl << "*** SCHEDULING GRAPHS FOR INSTRUCTION SCHEDULING" - << endl; + cerr << "\n*** SCHEDULING GRAPHS FOR INSTRUCTION SCHEDULING\n"; graphSet.dump(); } @@ -1513,7 +1513,7 @@ ScheduleInstructionsWithSSA(Method* method, const BasicBlock* bb = bbvec[0]; if (SchedDebugLevel >= Sched_PrintSchedTrace) - cout << endl << "*** TRACE OF INSTRUCTION SCHEDULING OPERATIONS\n\n"; + cerr << "\n*** TRACE OF INSTRUCTION SCHEDULING OPERATIONS\n\n"; SchedPriorities schedPrio(method, graph); // expensive! SchedulingManager S(target, graph, schedPrio); @@ -1527,8 +1527,7 @@ ScheduleInstructionsWithSSA(Method* method, if (SchedDebugLevel >= Sched_PrintMachineCode) { - cout << endl - << "*** Machine instructions after INSTRUCTION SCHEDULING" << endl; + cerr << "\n*** Machine instructions after INSTRUCTION SCHEDULING\n"; MachineCodeForMethod::get(method).dump(); } diff --git a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp index 9e9af5b80d8..7c83e1a58c8 100644 --- a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp +++ b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp @@ -23,10 +23,16 @@ #include "llvm/Target/MachineRegInfo.h" #include "llvm/iOther.h" #include "Support/StringExtras.h" +#include "Support/STLExtras.h" #include -#include #include +#include +#include +using std::vector; +using std::pair; +using std::hash_map; +using std::cerr; //*********************** Internal Data Structures *************************/ @@ -132,7 +138,7 @@ SchedGraphEdge::~SchedGraphEdge() } void SchedGraphEdge::dump(int indent=0) const { - cout << string(indent*2, ' ') << *this; + cerr << std::string(indent*2, ' ') << *this; } @@ -168,7 +174,7 @@ SchedGraphNode::~SchedGraphNode() } void SchedGraphNode::dump(int indent=0) const { - cout << string(indent*2, ' ') << *this; + cerr << std::string(indent*2, ' ') << *this; } @@ -222,21 +228,20 @@ SchedGraph::SchedGraph(const BasicBlock* bb, const TargetMachine& target) { bbVec.push_back(bb); - this->buildGraph(target); + buildGraph(target); } /*dtor*/ SchedGraph::~SchedGraph() { - for (iterator I=begin(); I != end(); ++I) + for (const_iterator I = begin(); I != end(); ++I) { - SchedGraphNode* node = (*I).second; + SchedGraphNode *node = I->second; // for each node, delete its out-edges - for (SchedGraphNode::iterator I = node->beginOutEdges(); - I != node->endOutEdges(); ++I) - delete *I; + std::for_each(node->beginOutEdges(), node->endOutEdges(), + deleter); // then delete the node itself. delete node; @@ -247,24 +252,24 @@ SchedGraph::~SchedGraph() void SchedGraph::dump() const { - cout << " Sched Graph for Basic Blocks: "; + cerr << " Sched Graph for Basic Blocks: "; for (unsigned i=0, N=bbVec.size(); i < N; i++) { - cout << (bbVec[i]->hasName()? bbVec[i]->getName() : "block") + cerr << (bbVec[i]->hasName()? bbVec[i]->getName() : "block") << " (" << bbVec[i] << ")" << ((i == N-1)? "" : ", "); } - cout << endl << endl << " Actual Root nodes : "; + cerr << "\n\n Actual Root nodes : "; for (unsigned i=0, N=graphRoot->outEdges.size(); i < N; i++) - cout << graphRoot->outEdges[i]->getSink()->getNodeId() + cerr << graphRoot->outEdges[i]->getSink()->getNodeId() << ((i == N-1)? "" : ", "); - cout << endl << " Graph Nodes:" << endl; + cerr << "\n Graph Nodes:\n"; for (const_iterator I=begin(); I != end(); ++I) - cout << endl << * (*I).second; + cerr << "\n" << *I->second; - cout << endl; + cerr << "\n"; } @@ -690,7 +695,7 @@ SchedGraph::addNonSSAEdgesForValue(const Instruction* instr, // this operand is a definition or use of value `instr' SchedGraphNode* node = this->getGraphNodeForInstr(mvec[i]); assert(node && "No node for machine instruction in this BB?"); - refVec.push_back(make_pair(node, o)); + refVec.push_back(std::make_pair(node, o)); } } @@ -747,8 +752,8 @@ SchedGraph::findDefUseInfoAtInstr(const TargetMachine& target, { int regNum = mop.getMachineRegNum(); if (regNum != target.getRegInfo().getZeroRegNum()) - regToRefVecMap[mop.getMachineRegNum()].push_back(make_pair(node, - i)); + regToRefVecMap[mop.getMachineRegNum()].push_back( + std::make_pair(node, i)); continue; // nothing more to do } @@ -762,7 +767,7 @@ SchedGraph::findDefUseInfoAtInstr(const TargetMachine& target, && "Do not expect any other kind of operand to be defined!"); const Instruction* defInstr = cast(mop.getVRegValue()); - valueToDefVecMap[defInstr].push_back(make_pair(node, i)); + valueToDefVecMap[defInstr].push_back(std::make_pair(node, i)); } // @@ -774,7 +779,7 @@ SchedGraph::findDefUseInfoAtInstr(const TargetMachine& target, if (const Instruction* defInstr = dyn_cast_or_null(minstr.getImplicitRef(i))) { - valueToDefVecMap[defInstr].push_back(make_pair(node, -i)); + valueToDefVecMap[defInstr].push_back(std::make_pair(node, -i)); } } @@ -860,7 +865,6 @@ SchedGraph::buildNodesforBB(const TargetMachine& target, void SchedGraph::buildGraph(const TargetMachine& target) { - const MachineInstrInfo& mii = target.getInstrInfo(); const BasicBlock* bb = bbVec[0]; assert(bbVec.size() == 1 && "Only handling a single basic block here"); @@ -966,24 +970,22 @@ SchedGraphSet::SchedGraphSet(const Method* _method, SchedGraphSet::~SchedGraphSet() { // delete all the graphs - for (iterator I=begin(); I != end(); ++I) - delete (*I).second; + for (const_iterator I = begin(); I != end(); ++I) + delete I->second; } void SchedGraphSet::dump() const { - cout << "======== Sched graphs for method `" - << (method->hasName()? method->getName() : "???") - << "' ========" << endl << endl; + cerr << "======== Sched graphs for method `" << method->getName() + << "' ========\n\n"; for (const_iterator I=begin(); I != end(); ++I) - (*I).second->dump(); + I->second->dump(); - cout << endl << "====== End graphs for method `" - << (method->hasName()? method->getName() : "") - << "' ========" << endl << endl; + cerr << "\n====== End graphs for method `" << method->getName() + << "' ========\n\n"; } @@ -1000,8 +1002,7 @@ SchedGraphSet::buildGraphsForMethod(const Method *method, -ostream& -operator<<(ostream& os, const SchedGraphEdge& edge) +std::ostream &operator<<(std::ostream &os, const SchedGraphEdge& edge) { os << "edge [" << edge.src->getNodeId() << "] -> [" << edge.sink->getNodeId() << "] : "; @@ -1015,33 +1016,30 @@ operator<<(ostream& os, const SchedGraphEdge& edge) default: assert(0); break; } - os << " : delay = " << edge.minDelay << endl; + os << " : delay = " << edge.minDelay << "\n"; return os; } -ostream& -operator<<(ostream& os, const SchedGraphNode& node) +std::ostream &operator<<(std::ostream &os, const SchedGraphNode& node) { - os << string(8, ' ') + os << std::string(8, ' ') << "Node " << node.nodeId << " : " - << "latency = " << node.latency << endl << string(12, ' '); + << "latency = " << node.latency << "\n" << std::string(12, ' '); if (node.getMachineInstr() == NULL) - os << "(Dummy node)" << endl; + os << "(Dummy node)\n"; else { - os << *node.getMachineInstr() << endl << string(12, ' '); - os << node.inEdges.size() << " Incoming Edges:" << endl; + os << *node.getMachineInstr() << "\n" << std::string(12, ' '); + os << node.inEdges.size() << " Incoming Edges:\n"; for (unsigned i=0, N=node.inEdges.size(); i < N; i++) - os << string(16, ' ') << *node.inEdges[i]; + os << std::string(16, ' ') << *node.inEdges[i]; - os << string(12, ' ') << node.outEdges.size() - << " Outgoing Edges:" << endl; + os << std::string(12, ' ') << node.outEdges.size() + << " Outgoing Edges:\n"; for (unsigned i=0, N=node.outEdges.size(); i < N; i++) - { - os << string(16, ' ') << * node.outEdges[i]; - } + os << std::string(16, ' ') << *node.outEdges[i]; } return os; diff --git a/lib/Target/SparcV9/InstrSched/SchedGraph.h b/lib/Target/SparcV9/InstrSched/SchedGraph.h index a4567a5198f..2890241d59d 100644 --- a/lib/Target/SparcV9/InstrSched/SchedGraph.h +++ b/lib/Target/SparcV9/InstrSched/SchedGraph.h @@ -24,7 +24,7 @@ #include "Support/NonCopyable.h" #include "Support/HashExtras.h" #include "Support/GraphTraits.h" -#include +#include class Value; class Instruction; @@ -128,7 +128,7 @@ public: // // Debugging support // - friend ostream& operator<<(ostream& os, const SchedGraphEdge& edge); + friend std::ostream& operator<<(std::ostream& os, const SchedGraphEdge& edge); void dump (int indent=0) const; @@ -144,16 +144,16 @@ private: unsigned int nodeId; const BasicBlock* bb; const MachineInstr* minstr; - vector inEdges; - vector outEdges; + std::vector inEdges; + std::vector outEdges; int origIndexInBB; // original position of machine instr in BB int latency; public: - typedef vector:: iterator iterator; - typedef vector::const_iterator const_iterator; - typedef vector:: reverse_iterator reverse_iterator; - typedef vector::const_reverse_iterator const_reverse_iterator; + typedef std::vector:: iterator iterator; + typedef std::vector::const_iterator const_iterator; + typedef std::vector:: reverse_iterator reverse_iterator; + typedef std::vector::const_reverse_iterator const_reverse_iterator; public: // @@ -186,7 +186,7 @@ public: // // Debugging support // - friend ostream& operator<<(ostream& os, const SchedGraphNode& node); + friend std::ostream& operator<<(std::ostream& os, const SchedGraphNode& node); void dump (int indent=0) const; @@ -214,22 +214,23 @@ private: class SchedGraph : public NonCopyable, - private hash_map + private std::hash_map { private: - vector bbVec; // basic blocks included in the graph + std::vector bbVec; // basic blocks included in the graph SchedGraphNode* graphRoot; // the root and leaf are not inserted SchedGraphNode* graphLeaf; // in the hash_map (see getNumNodes()) + typedef std::hash_map map_base; public: - typedef hash_map::iterator iterator; - typedef hash_map::const_iterator const_iterator; + using map_base::iterator; + using map_base::const_iterator; public: // // Accessor methods // - const vector& getBasicBlocks() const { return bbVec; } + const std::vector& getBasicBlocks() const { return bbVec; } const unsigned int getNumNodes() const { return size()+2; } SchedGraphNode* getRoot() const { return graphRoot; } SchedGraphNode* getLeaf() const { return graphLeaf; } @@ -257,19 +258,9 @@ public: // Unordered iterators. // Return values is pair. // - iterator begin() { - return hash_map::begin(); - } - iterator end() { - return hash_map::end(); - } - const_iterator begin() const { - return hash_map::begin(); - } - const_iterator end() const { - return hash_map::end(); - } - + using map_base::begin; + using map_base::end; + // // Ordered iterators. // Return values is pair. @@ -308,13 +299,13 @@ private: void buildNodesforBB (const TargetMachine& target, const BasicBlock* bb, - vector& memNodeVec, + std::vector& memNod, RegToRefVecMap& regToRefVecMap, ValueToDefVecMap& valueToDefVecMap); void findDefUseInfoAtInstr (const TargetMachine& target, SchedGraphNode* node, - vector& memNodeVec, + std::vector& memNode, RegToRefVecMap& regToRefVecMap, ValueToDefVecMap& valueToDefVecMap); @@ -325,10 +316,10 @@ private: void addCDEdges (const TerminatorInst* term, const TargetMachine& target); - void addMemEdges (const vector& memNodeVec, + void addMemEdges (const std::vector& memNod, const TargetMachine& target); - void addCallCCEdges (const vector& memNodeVec, + void addCallCCEdges (const std::vector& memNod, MachineCodeForBasicBlock& bbMvec, const TargetMachine& target); @@ -347,14 +338,15 @@ private: class SchedGraphSet : public NonCopyable, - private hash_map + private std::hash_map { private: const Method* method; public: - typedef hash_map::iterator iterator; - typedef hash_map::const_iterator const_iterator; + typedef std::hash_map map_base; + using map_base::iterator; + using map_base::const_iterator; public: /*ctor*/ SchedGraphSet (const Method* _method, @@ -372,18 +364,8 @@ public: // // Iterators // - iterator begin() { - return hash_map::begin(); - } - iterator end() { - return hash_map::end(); - } - const_iterator begin() const { - return hash_map::begin(); - } - const_iterator end() const { - return hash_map::end(); - } + using map_base::begin; + using map_base::end; // // Debugging support @@ -544,14 +526,7 @@ template <> struct GraphTraits { }; -//************************ External Functions *****************************/ - - -ostream& operator<<(ostream& os, const SchedGraphEdge& edge); - -ostream& operator<<(ostream& os, const SchedGraphNode& node); - - -/***************************************************************************/ +std::ostream &operator<<(std::ostream& os, const SchedGraphEdge& edge); +std::ostream &operator<<(std::ostream &os, const SchedGraphNode& node); #endif diff --git a/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp b/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp index 17697072381..8cde2521151 100644 --- a/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp +++ b/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp @@ -20,20 +20,17 @@ #include "SchedPriorities.h" #include "Support/PostOrderIterator.h" - +#include +using std::cerr; SchedPriorities::SchedPriorities(const Method* method, const SchedGraph* _graph) : curTime(0), graph(_graph), - methodLiveVarInfo(method), // expensive! - lastUseMap(), - nodeDelayVec(_graph->getNumNodes(),INVALID_LATENCY), //make errors obvious + methodLiveVarInfo(method), // expensive! + nodeDelayVec(_graph->getNumNodes(), INVALID_LATENCY), // make errors obvious earliestForNode(_graph->getNumNodes(), 0), earliestReadyTime(0), - candsAsHeap(), - candsAsSet(), - mcands(), nextToTry(candsAsHeap.begin()) { methodLiveVarInfo.analyze(); @@ -66,7 +63,7 @@ SchedPriorities::computeDelays(const SchedGraph* graph) E != node->endOutEdges(); ++E) { cycles_t sinkDelay = getNodeDelayRef((*E)->getSink()); - nodeDelay = max(nodeDelay, sinkDelay + (*E)->getMinDelay()); + nodeDelay = std::max(nodeDelay, sinkDelay + (*E)->getMinDelay()); } } getNodeDelayRef(node) = nodeDelay; @@ -87,20 +84,37 @@ SchedPriorities::initializeReadyHeap(const SchedGraph* graph) #undef TEST_HEAP_CONVERSION #ifdef TEST_HEAP_CONVERSION - cout << "Before heap conversion:" << endl; + cerr << "Before heap conversion:\n"; copy(candsAsHeap.begin(), candsAsHeap.end(), - ostream_iterator(cout,"\n")); + ostream_iterator(cerr,"\n")); #endif candsAsHeap.makeHeap(); #ifdef TEST_HEAP_CONVERSION - cout << "After heap conversion:" << endl; + cerr << "After heap conversion:\n"; copy(candsAsHeap.begin(), candsAsHeap.end(), - ostream_iterator(cout,"\n")); + ostream_iterator(cerr,"\n")); #endif } +void +SchedPriorities::insertReady(const SchedGraphNode* node) +{ + candsAsHeap.insert(node, nodeDelayVec[node->getNodeId()]); + candsAsSet.insert(node); + mcands.clear(); // ensure reset choices is called before any more choices + earliestReadyTime = std::min(earliestReadyTime, + earliestForNode[node->getNodeId()]); + + if (SchedDebugLevel >= Sched_PrintSchedTrace) + { + cerr << " Cycle " << (long)getTime() << ": " + << " Node " << node->getNodeId() << " is ready; " + << " Delay = " << (long)getNodeDelayRef(node) << "; Instruction: \n"; + cerr << " " << *node->getMachineInstr() << "\n"; + } +} void SchedPriorities::issuedReadyNodeAt(cycles_t curTime, @@ -116,7 +130,7 @@ SchedPriorities::issuedReadyNodeAt(cycles_t curTime, for (NodeHeap::const_iterator I=candsAsHeap.begin(); I != candsAsHeap.end(); ++I) if (candsAsHeap.getNode(I)) - earliestReadyTime = min(earliestReadyTime, + earliestReadyTime = std::min(earliestReadyTime, getEarliestForNodeRef(candsAsHeap.getNode(I))); } @@ -125,7 +139,7 @@ SchedPriorities::issuedReadyNodeAt(cycles_t curTime, E != node->endOutEdges(); ++E) { cycles_t& etime = getEarliestForNodeRef((*E)->getSink()); - etime = max(etime, curTime + (*E)->getMinDelay()); + etime = std::max(etime, curTime + (*E)->getMinDelay()); } } @@ -140,14 +154,14 @@ SchedPriorities::issuedReadyNodeAt(cycles_t curTime, //---------------------------------------------------------------------- inline int -SchedPriorities::chooseByRule1(vector& mcands) +SchedPriorities::chooseByRule1(std::vector& mcands) { return (mcands.size() == 1)? 0 // only one choice exists so take it : -1; // -1 indicates multiple choices } inline int -SchedPriorities::chooseByRule2(vector& mcands) +SchedPriorities::chooseByRule2(std::vector& mcands) { assert(mcands.size() >= 1 && "Should have at least one candidate here."); for (unsigned i=0, N = mcands.size(); i < N; i++) @@ -158,7 +172,7 @@ SchedPriorities::chooseByRule2(vector& mcands) } inline int -SchedPriorities::chooseByRule3(vector& mcands) +SchedPriorities::chooseByRule3(std::vector& mcands) { assert(mcands.size() >= 1 && "Should have at least one candidate here."); int maxUses = candsAsHeap.getNode(mcands[0])->getNumOutEdges(); @@ -224,7 +238,7 @@ SchedPriorities::getNextHighest(const SchedulingManager& S, void -SchedPriorities::findSetWithMaxDelay(vector& mcands, +SchedPriorities::findSetWithMaxDelay(std::vector& mcands, const SchedulingManager& S) { if (mcands.size() == 0 && nextToTry != candsAsHeap.end()) @@ -240,12 +254,12 @@ SchedPriorities::findSetWithMaxDelay(vector& mcands, if (SchedDebugLevel >= Sched_PrintSchedTrace) { - cout << " Cycle " << this->getTime() << ": " - << "Next highest delay = " << maxDelay << " : " + cerr << " Cycle " << (long)getTime() << ": " + << "Next highest delay = " << (long)maxDelay << " : " << mcands.size() << " Nodes with this delay: "; for (unsigned i=0; i < mcands.size(); i++) - cout << candsAsHeap.getNode(mcands[i])->getNodeId() << ", "; - cout << endl; + cerr << candsAsHeap.getNode(mcands[i])->getNodeId() << ", "; + cerr << "\n"; } } } @@ -257,10 +271,10 @@ SchedPriorities::instructionHasLastUse(MethodLiveVarInfo& methodLiveVarInfo, { const MachineInstr* minstr = graphNode->getMachineInstr(); - hash_map::const_iterator + std::hash_map::const_iterator ui = lastUseMap.find(minstr); if (ui != lastUseMap.end()) - return (*ui).second; + return ui->second; // else check if instruction is a last use and save it in the hash_map bool hasLastUse = false; diff --git a/lib/Target/SparcV9/InstrSched/SchedPriorities.h b/lib/Target/SparcV9/InstrSched/SchedPriorities.h index 81a2e6a0534..a8b3e233976 100644 --- a/lib/Target/SparcV9/InstrSched/SchedPriorities.h +++ b/lib/Target/SparcV9/InstrSched/SchedPriorities.h @@ -26,6 +26,7 @@ #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" #include "llvm/Target/MachineSchedInfo.h" #include +#include class Method; class MachineInstr; @@ -36,22 +37,22 @@ struct NodeDelayPair { const SchedGraphNode* node; cycles_t delay; NodeDelayPair(const SchedGraphNode* n, cycles_t d) : node(n), delay(d) {} - inline bool operator< (const NodeDelayPair& np) { return delay < np.delay; } + inline bool operator<(const NodeDelayPair& np) { return delay < np.delay; } }; inline bool NDPLessThan(const NodeDelayPair* np1, const NodeDelayPair* np2) { - return (np1->delay < np2->delay); + return np1->delay < np2->delay; } -class NodeHeap: public list, public NonCopyable { +class NodeHeap: public std::list, public NonCopyable { public: - typedef list::iterator iterator; - typedef list::const_iterator const_iterator; + typedef std::list::iterator iterator; + typedef std::list::const_iterator const_iterator; public: - /*ctor*/ NodeHeap () : list(), _size(0) {} + /*ctor*/ NodeHeap () : std::list(), _size(0) {} /*dtor*/ ~NodeHeap () {} inline unsigned int size () const { return _size; } @@ -89,7 +90,7 @@ public: iterator I=begin(); for ( ; I != end() && getDelay(I) >= delay; ++I) ; - list::insert(I, ndp); + std::list::insert(I, ndp); } _size++; } @@ -131,22 +132,22 @@ private: cycles_t curTime; const SchedGraph* graph; MethodLiveVarInfo methodLiveVarInfo; - hash_map lastUseMap; - vector nodeDelayVec; - vector earliestForNode; + std::hash_map lastUseMap; + std::vector nodeDelayVec; + std::vector earliestForNode; cycles_t earliestReadyTime; NodeHeap candsAsHeap; // candidate nodes, ready to go - hash_set candsAsSet; // same entries as candsAsHeap, + std::hash_set candsAsSet;//same entries as candsAsHeap, // but as set for fast lookup - vector mcands; // holds pointers into cands + std::vector mcands; // holds pointers into cands candIndex nextToTry; // next cand after the last // one tried in this cycle - int chooseByRule1 (vector& mcands); - int chooseByRule2 (vector& mcands); - int chooseByRule3 (vector& mcands); + int chooseByRule1 (std::vector& mcands); + int chooseByRule2 (std::vector& mcands); + int chooseByRule3 (std::vector& mcands); - void findSetWithMaxDelay (vector& mcands, + void findSetWithMaxDelay (std::vector& mcands, const SchedulingManager& S); void computeDelays (const SchedGraph* graph); @@ -169,36 +170,15 @@ private: }; -inline void -SchedPriorities::insertReady(const SchedGraphNode* node) -{ - candsAsHeap.insert(node, nodeDelayVec[node->getNodeId()]); - candsAsSet.insert(node); - mcands.clear(); // ensure reset choices is called before any more choices - earliestReadyTime = min(earliestReadyTime, - earliestForNode[node->getNodeId()]); - - if (SchedDebugLevel >= Sched_PrintSchedTrace) - { - cout << " Cycle " << this->getTime() << ": " - << " Node " << node->getNodeId() << " is ready; " - << " Delay = " << this->getNodeDelayRef(node) << "; Instruction: " - << endl; - cout << " " << *node->getMachineInstr() << endl; - } -} - inline void SchedPriorities::updateTime(cycles_t c) { curTime = c; nextToTry = candsAsHeap.begin(); mcands.clear(); } -inline ostream& operator<< (ostream& os, const NodeDelayPair* nd) { +inline std::ostream &operator<<(std::ostream &os, const NodeDelayPair* nd) { return os << "Delay for node " << nd->node->getNodeId() - << " = " << nd->delay << endl; + << " = " << (long)nd->delay << "\n"; } -/***************************************************************************/ - #endif diff --git a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp index ce3e2c3a3f7..20cbe8d71bf 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp @@ -31,6 +31,9 @@ #include "llvm/BasicBlock.h" #include "llvm/CodeGen/MachineInstr.h" #include "Support/STLExtras.h" +#include +using std::cerr; +using std::vector; //------------------------------------------------------------------------ // class InstrTreeNode @@ -119,21 +122,21 @@ void InstructionNode::dumpNode(int indent) const { for (int i=0; i < indent; i++) - cout << " "; + cerr << " "; - cout << getInstruction()->getOpcodeName(); + cerr << getInstruction()->getOpcodeName(); const vector &mvec = getInstruction()->getMachineInstrVec(); if (mvec.size() > 0) - cout << "\tMachine Instructions: "; + cerr << "\tMachine Instructions: "; for (unsigned int i=0; i < mvec.size(); i++) { mvec[i]->dump(0); if (i < mvec.size() - 1) - cout << "; "; + cerr << "; "; } - cout << endl; + cerr << "\n"; } @@ -141,9 +144,9 @@ void VRegListNode::dumpNode(int indent) const { for (int i=0; i < indent; i++) - cout << " "; + cerr << " "; - cout << "List" << endl; + cerr << "List" << "\n"; } @@ -151,29 +154,29 @@ void VRegNode::dumpNode(int indent) const { for (int i=0; i < indent; i++) - cout << " "; + cerr << " "; - cout << "VReg " << getValue() << "\t(type " - << (int) getValue()->getValueType() << ")" << endl; + cerr << "VReg " << getValue() << "\t(type " + << (int) getValue()->getValueType() << ")" << "\n"; } void ConstantNode::dumpNode(int indent) const { for (int i=0; i < indent; i++) - cout << " "; + cerr << " "; - cout << "Constant " << getValue() << "\t(type " - << (int) getValue()->getValueType() << ")" << endl; + cerr << "Constant " << getValue() << "\t(type " + << (int) getValue()->getValueType() << ")" << "\n"; } void LabelNode::dumpNode(int indent) const { for (int i=0; i < indent; i++) - cout << " "; + cerr << " "; - cout << "Label " << getValue() << endl; + cerr << "Label " << getValue() << "\n"; } //------------------------------------------------------------------------ @@ -190,7 +193,7 @@ InstrForest::InstrForest(Method *M) InstrForest::~InstrForest() { - for (hash_map:: iterator I = begin(); + for (std::hash_map::iterator I = begin(); I != end(); ++I) delete (*I).second; } @@ -198,7 +201,7 @@ InstrForest::~InstrForest() void InstrForest::dump() const { - for (hash_set::const_iterator I = treeRoots.begin(); + for (std::hash_set::const_iterator I = treeRoots.begin(); I != treeRoots.end(); ++I) (*I)->dump(/*dumpChildren*/ 1, /*indent*/ 0); } diff --git a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp index b959c90ca30..ab489c507e8 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp @@ -23,8 +23,8 @@ #include "llvm/iPHINode.h" #include "llvm/Target/MachineRegInfo.h" #include "Support/CommandLine.h" -#include - +#include +using std::cerr; //******************** Internal Data Declarations ************************/ @@ -84,17 +84,17 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target) if (SelectDebugLevel >= Select_DebugInstTrees) { - cout << "\n\n*** Instruction trees for method " + cerr << "\n\n*** Instruction trees for method " << (method->hasName()? method->getName() : "") - << endl << endl; + << "\n\n"; instrForest.dump(); } // // Invoke BURG instruction selection for each tree // - const hash_set &treeRoots = instrForest.getRootSet(); - for (hash_set::const_iterator + const std::hash_set &treeRoots = instrForest.getRootSet(); + for (std::hash_set::const_iterator treeRootIter = treeRoots.begin(); treeRootIter != treeRoots.end(); ++treeRootIter) { @@ -138,8 +138,7 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target) if (SelectDebugLevel >= Select_PrintMachineCode) { - cout << endl - << "*** Machine instructions after INSTRUCTION SELECTION" << endl; + cerr << "\n*** Machine instructions after INSTRUCTION SELECTION\n"; MachineCodeForMethod::get(method).dump(); } @@ -210,7 +209,7 @@ void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) { // insert the copy instruction to the predecessor BB - vector CopyInstVec; + std::vector CopyInstVec; MachineInstr *CpMI = target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PN); @@ -250,25 +249,18 @@ void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) { PHINode *PN = (PHINode *) (*IIt); - Value *PhiCpRes = new Value(PN->getType(), PN->getValueType()); - - string *Name = new string("PhiCp:"); - (*Name) += (int) PhiCpRes; - PhiCpRes->setName( *Name ); - + Value *PhiCpRes = new Value(PN->getType(), PN->getValueType(),"PhiCp:"); // for each incoming value of the phi, insert phi elimination // for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) { // insert the copy instruction to the predecessor BB - MachineInstr *CpMI = target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PhiCpRes); InsertPhiElimInst(PN->getIncomingBlock(i), CpMI); - } @@ -279,8 +271,6 @@ void InsertCode4AllPhisInMeth(Method *method, TargetMachine &target) { MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec(); bbMvec.insert( bbMvec.begin(), CpMI2); - - } else break; // since PHI nodes can only be at the top @@ -338,7 +328,7 @@ PostprocessMachineCodeForTree(InstructionNode* instrNode, MachineCodeForVMInstr& mvec = vmInstr->getMachineInstrVec(); for (int i = (int) mvec.size()-1; i >= 0; i--) { - vector loadConstVec = + std::vector loadConstVec = FixConstantOperandsForInstr(vmInstr, mvec[i], target); if (loadConstVec.size() > 0) @@ -372,7 +362,7 @@ SelectInstructionsForTree(InstrTreeNode* treeRoot, int goalnt, if (ruleForNode == 0) { - cerr << "Could not match instruction tree for instr selection" << endl; + cerr << "Could not match instruction tree for instr selection\n"; assert(0); return true; } diff --git a/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp b/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp index 30d9c7eb78a..34dd83b49e0 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp @@ -22,7 +22,7 @@ #include "llvm/Instruction.h" #include "llvm/Type.h" #include "llvm/iMemory.h" - +using std::vector; //*************************** Local Functions ******************************/ diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp index d7e036b2563..0ecf96cf13c 100644 --- a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp +++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp @@ -1,8 +1,13 @@ #include "llvm/Analysis/LiveVar/BBLiveVar.h" #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" #include "llvm/CodeGen/MachineInstr.h" + +/// BROKEN: Should not include sparc stuff directly into here #include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn +using std::cerr; +using std::endl; +using std::pair; //----------------------------------------------------------------------------- // Constructor @@ -39,7 +44,7 @@ void BBLiveVar::calcDefUseSets() if( DEBUG_LV > 1) { // debug msg cerr << " *Iterating over machine instr "; MInst->dump(); - cerr << endl; + cerr << "\n"; } // iterate over MI operands to find defs @@ -85,9 +90,9 @@ void BBLiveVar::calcDefUseSets() if( DEBUG_LV > 1) { // debug msg of level 2 cerr << " - phi operand "; printValue( ArgVal ); - cerr << " came from BB "; + cerr << " came from BB "; printValue( PhiArgMap[ ArgVal ]); - cerr< 1) { - cerr << " +Def: "; printValue( Op ); cerr << endl; + cerr << " +Def: "; printValue( Op ); cerr << "\n"; } } diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.h b/lib/Target/SparcV9/LiveVar/BBLiveVar.h index 6d7d4eb5334..9ce56a88f63 100644 --- a/lib/Target/SparcV9/LiveVar/BBLiveVar.h +++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.h @@ -28,7 +28,7 @@ class BBLiveVar // map that contains phi args->BB they came // set by calcDefUseSets & used by setPropagate - hash_map PhiArgMap; + std::hash_map PhiArgMap; // method to propogate an InSet to OutSet of a predecessor bool setPropagate( LiveVarSet *const OutSetOfPred, diff --git a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp index 636359d1d08..5de35ff1be5 100644 --- a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp +++ b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp @@ -12,15 +12,15 @@ #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" #include "llvm/CodeGen/MachineInstr.h" #include "Support/PostOrderIterator.h" - +#include +using std::cout; +using std::endl; //************************** Constructor/Destructor *************************** -MethodLiveVarInfo::MethodLiveVarInfo(const Method *const M) : Meth(M), - BB2BBLVMap() -{ - assert(! M->isExternal() ); // cannot be a prototype decleration +MethodLiveVarInfo::MethodLiveVarInfo(const Method *const M) : Meth(M) { + assert(!M->isExternal() && "Cannot be a prototype declaration"); HasAnalyzed = false; // still we haven't called analyze() } @@ -55,8 +55,6 @@ MethodLiveVarInfo:: ~MethodLiveVarInfo() if( (*MI).first ) // delete all LiveVarSets in MInst2LVSetBI delete (*MI).second; } - - } diff --git a/lib/Target/SparcV9/LiveVar/ValueSet.cpp b/lib/Target/SparcV9/LiveVar/ValueSet.cpp index 6806d1c5638..d176d9e53cf 100644 --- a/lib/Target/SparcV9/LiveVar/ValueSet.cpp +++ b/lib/Target/SparcV9/LiveVar/ValueSet.cpp @@ -1,11 +1,14 @@ #include "llvm/Analysis/LiveVar/ValueSet.h" #include "llvm/ConstantVals.h" - +#include +using std::cerr; +using std::endl; +using std::pair; +using std::hash_set; void printValue( const Value *const v) // func to print a Value { - if (v->hasName()) cerr << v << "(" << ((*v).getName()) << ") "; else if (Constant *C = dyn_cast(v)) @@ -16,17 +19,13 @@ void printValue( const Value *const v) // func to print a Value //---------------- Method implementations -------------------------- - - -ValueSet:: ValueSet() : hash_set () { } - // for performing two set unions bool ValueSet::setUnion( const ValueSet *const set1) { const_iterator set1it; pair result; bool changed = false; - for( set1it = set1->begin() ; set1it != set1->end(); set1it++) { + for( set1it = set1->begin() ; set1it != set1->end(); ++set1it) { // for all all elements in set1 result = insert( *set1it ); // insert to this set if( result.second == true) changed = true; @@ -41,7 +40,7 @@ void ValueSet::setDifference( const ValueSet *const set1, const ValueSet *const set2) { const_iterator set1it, set2it; - for( set1it = set1->begin() ; set1it != set1->end(); set1it++) { + for( set1it = set1->begin() ; set1it != set1->end(); ++set1it) { // for all elements in set1 iterator set2it = set2->find( *set1it ); // find wether the elem is in set2 if( set2it == set2->end() ) // if the element is not in set2 @@ -53,7 +52,7 @@ void ValueSet::setDifference( const ValueSet *const set1, // for performing set subtraction void ValueSet::setSubtract( const ValueSet *const set1) { const_iterator set1it; - for( set1it = set1->begin() ; set1it != set1->end(); set1it++) + for( set1it = set1->begin() ; set1it != set1->end(); ++set1it) // for all elements in set1 erase( *set1it ); // erase that element from this set } @@ -62,7 +61,5 @@ void ValueSet::setSubtract( const ValueSet *const set1) { void ValueSet::printSet() const { // for printing a live variable set - const_iterator it; - for( it = begin() ; it != end(); it++) - printValue( *it ); + for_each(begin(), end(), printValue); } diff --git a/lib/Target/SparcV9/RegAlloc/IGNode.cpp b/lib/Target/SparcV9/RegAlloc/IGNode.cpp index 4e66d9a762c..a2257420529 100644 --- a/lib/Target/SparcV9/RegAlloc/IGNode.cpp +++ b/lib/Target/SparcV9/RegAlloc/IGNode.cpp @@ -1,12 +1,13 @@ #include "llvm/CodeGen/IGNode.h" - +#include +#include +using std::cerr; //----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- -IGNode::IGNode(LiveRange *const PLR, unsigned int Ind): Index(Ind), - AdjList(), - ParentLR(PLR) +IGNode::IGNode(LiveRange *const PLR, unsigned int Ind) : Index(Ind), + ParentLR(PLR) { OnStack = false; CurDegree = -1 ; @@ -23,11 +24,12 @@ void IGNode::pushOnStack() int neighs = AdjList.size(); if( neighs < 0) { - cout << "\nAdj List size = " << neighs; + cerr << "\nAdj List size = " << neighs; assert(0 && "Invalid adj list size"); } - for(int i=0; i < neighs; i++) (AdjList[i])->decCurDegree(); + for(int i=0; i < neighs; i++) + AdjList[i]->decCurDegree(); } //----------------------------------------------------------------------------- @@ -35,11 +37,9 @@ void IGNode::pushOnStack() // two IGNodes together. //----------------------------------------------------------------------------- void IGNode::delAdjIGNode(const IGNode *const Node) { - vector ::iterator It = AdjList.begin(); - - // find Node - for( ; It != AdjList.end() && (*It != Node); It++ ) ; + std::vector::iterator It = + find(AdjList.begin(), AdjList.end(), Node); assert( It != AdjList.end() ); // the node must be there - - AdjList.erase( It ); + + AdjList.erase(It); } diff --git a/lib/Target/SparcV9/RegAlloc/IGNode.h b/lib/Target/SparcV9/RegAlloc/IGNode.h index 0f4cf9c82a1..b89aea32b1d 100644 --- a/lib/Target/SparcV9/RegAlloc/IGNode.h +++ b/lib/Target/SparcV9/RegAlloc/IGNode.h @@ -29,8 +29,6 @@ #include "llvm/CodeGen/RegAllocCommon.h" #include "llvm/CodeGen/LiveRange.h" - - //---------------------------------------------------------------------------- // Class IGNode // @@ -39,13 +37,11 @@ class IGNode { - private: - const int Index; // index within IGNodeList bool OnStack; // this has been pushed on to stack for coloring - vector AdjList; // adjacency list for this live range + std::vector AdjList; // adjacency list for this live range int CurDegree; // @@ -54,7 +50,6 @@ class IGNode // Decremented when a neighbor is pushed on to the stack. // After that, never incremented/set again nor used. - LiveRange *const ParentLR; // parent LR (cannot be a const) @@ -152,10 +147,4 @@ class IGNode }; - - - - - - #endif diff --git a/lib/Target/SparcV9/RegAlloc/InterferenceGraph.cpp b/lib/Target/SparcV9/RegAlloc/InterferenceGraph.cpp index e18c9a7a348..0de7275acf7 100644 --- a/lib/Target/SparcV9/RegAlloc/InterferenceGraph.cpp +++ b/lib/Target/SparcV9/RegAlloc/InterferenceGraph.cpp @@ -1,4 +1,7 @@ #include "llvm/CodeGen/InterferenceGraph.h" +#include "Support/STLExtras.h" +#include +using std::cerr; //----------------------------------------------------------------------------- // Constructor: Records the RegClass and initalizes IGNodeList. @@ -11,7 +14,7 @@ InterferenceGraph::InterferenceGraph(RegClass *const RC) : RegCl(RC), IG = NULL; Size = 0; if( DEBUG_RA) { - cout << "Interference graph created!" << endl; + cerr << "Interference graph created!\n"; } } @@ -22,19 +25,12 @@ InterferenceGraph::InterferenceGraph(RegClass *const RC) : RegCl(RC), InterferenceGraph:: ~InterferenceGraph() { // delete the matrix - // - if( IG ) - delete []IG; + for(unsigned int r=0; r < IGNodeList.size(); ++r) + delete[] IG[r]; + delete[] IG; // delete all IGNodes in the IGNodeList - // - vector::const_iterator IGIt = IGNodeList.begin(); - for(unsigned i=0; i < IGNodeList.size() ; ++i) { - - const IGNode *const Node = IGNodeList[i]; - if( Node ) delete Node; - } - + for_each(IGNodeList.begin(), IGNodeList.end(), deleter); } @@ -46,13 +42,13 @@ InterferenceGraph:: ~InterferenceGraph() { void InterferenceGraph::createGraph() { Size = IGNodeList.size(); - IG = (char **) new char *[Size]; + IG = new char*[Size]; for( unsigned int r=0; r < Size; ++r) IG[r] = new char[Size]; // init IG matrix for(unsigned int i=0; i < Size; i++) - for( unsigned int j=0; j < Size ; j++) + for(unsigned int j=0; j < Size; j++) IG[i][j] = 0; } @@ -61,9 +57,7 @@ void InterferenceGraph::createGraph() //----------------------------------------------------------------------------- void InterferenceGraph::addLRToIG(LiveRange *const LR) { - IGNode *Node = new IGNode(LR, IGNodeList.size() ); - IGNodeList.push_back( Node ); - + IGNodeList.push_back(new IGNode(LR, IGNodeList.size())); } @@ -92,12 +86,11 @@ void InterferenceGraph::setInterference(const LiveRange *const LR1, char *val; if( DEBUG_RA > 1) - cout << "setting intf for: [" << row << "][" << col << "]" << endl; + cerr << "setting intf for: [" << row << "][" << col << "]\n"; ( row > col) ? val = &IG[row][col]: val = &IG[col][row]; if( ! (*val) ) { // if this interf is not previously set - *val = 1; // add edges between nodes IGNode1->addAdjIGNode( IGNode2 ); IGNode2->addAdjIGNode( IGNode1 ); @@ -123,7 +116,10 @@ unsigned InterferenceGraph::getInterference(const LiveRange *const LR1, const unsigned int col = LR2->getUserIGNode()->getIndex(); char ret; - ( row > col) ? (ret = IG[row][col]) : (ret = IG[col][row]) ; + if (row > col) + ret = IG[row][col]; + else + ret = IG[col][row]; return ret; } @@ -148,9 +144,9 @@ void InterferenceGraph::mergeIGNodesOfLRs(const LiveRange *const LR1, assertIGNode( SrcNode ); if( DEBUG_RA > 1) { - cout << "Merging LRs: \""; LR1->printSet(); - cout << "\" and \""; LR2->printSet(); - cout << "\"" << endl; + cerr << "Merging LRs: \""; LR1->printSet(); + cerr << "\" and \""; LR2->printSet(); + cerr << "\"\n"; } unsigned SrcDegree = SrcNode->getNumOfNeighbors(); @@ -217,17 +213,16 @@ void InterferenceGraph::printIG() const for(unsigned int i=0; i < Size; i++) { const IGNode *const Node = IGNodeList[i]; - if( ! Node ) - continue; // skip empty rows - - cout << " [" << i << "] "; + if(Node) { + cerr << " [" << i << "] "; - for( unsigned int j=0; j < Size; j++) { - if( j >= i) break; - if( IG[i][j] ) cout << "(" << i << "," << j << ") "; + for( unsigned int j=0; j < i; j++) { + if(IG[i][j]) + cerr << "(" << i << "," << j << ") "; } - cout << endl; + cerr << "\n"; } + } } //---------------------------------------------------------------------------- @@ -235,21 +230,14 @@ void InterferenceGraph::printIG() const //---------------------------------------------------------------------------- void InterferenceGraph::printIGNodeList() const { - vector::const_iterator IGIt = IGNodeList.begin(); // hash map iter - for(unsigned i=0; i < IGNodeList.size() ; ++i) { - const IGNode *const Node = IGNodeList[i]; - if( ! Node ) - continue; - - cout << " [" << Node->getIndex() << "] "; - (Node->getParentLR())->printSet(); - //int Deg = Node->getCurDegree(); - cout << "\t <# of Neighs: " << Node->getNumOfNeighbors() << ">" << endl; - + if (Node) { + cerr << " [" << Node->getIndex() << "] "; + Node->getParentLR()->printSet(); + //int Deg = Node->getCurDegree(); + cerr << "\t <# of Neighs: " << Node->getNumOfNeighbors() << ">\n"; + } } } - - diff --git a/lib/Target/SparcV9/RegAlloc/InterferenceGraph.h b/lib/Target/SparcV9/RegAlloc/InterferenceGraph.h index 99dea8fbe0a..408bee4558a 100644 --- a/lib/Target/SparcV9/RegAlloc/InterferenceGraph.h +++ b/lib/Target/SparcV9/RegAlloc/InterferenceGraph.h @@ -1,4 +1,4 @@ -/* Title: InterferenceGraph.h +/* Title: InterferenceGraph.h -*- C++ -*- Author: Ruchira Sasanka Date: July 20, 01 Purpose: Interference Graph used for register coloring. @@ -24,7 +24,7 @@ #include "llvm/CodeGen/IGNode.h" -typedef vector IGNodeListType; +typedef std::vector IGNodeListType; class InterferenceGraph @@ -47,6 +47,8 @@ class InterferenceGraph // to create it after adding all IGNodes to the IGNodeList InterferenceGraph(RegClass *const RC); + ~InterferenceGraph(); + void createGraph(); void addLRToIG(LiveRange *const LR); @@ -65,12 +67,6 @@ class InterferenceGraph void printIG() const; void printIGNodeList() const; - - ~InterferenceGraph(); - - }; - #endif - diff --git a/lib/Target/SparcV9/RegAlloc/LiveRange.h b/lib/Target/SparcV9/RegAlloc/LiveRange.h index 778e070046e..8034751da99 100644 --- a/lib/Target/SparcV9/RegAlloc/LiveRange.h +++ b/lib/Target/SparcV9/RegAlloc/LiveRange.h @@ -1,4 +1,4 @@ -/* Title: LiveRange.h +/* Title: LiveRange.h -*- C++ -*- Author: Ruchira Sasanka Date: July 25, 01 Purpose: To keep info about a live range. @@ -13,6 +13,7 @@ #include "llvm/Analysis/LiveVar/ValueSet.h" #include "llvm/Type.h" +#include class RegClass; class IGNode; @@ -176,7 +177,7 @@ class LiveRange : public ValueSet if(SuggestedColor == -1 ) SuggestedColor = Col; else if (DEBUG_RA) - cerr << "Already has a suggested color " << Col << endl; + std::cerr << "Already has a suggested color " << Col << "\n"; } inline unsigned getSuggestedColor() const { diff --git a/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.cpp b/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.cpp index 7fb688f55ef..b66e6ef308b 100644 --- a/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.cpp +++ b/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.cpp @@ -1,15 +1,15 @@ #include "llvm/CodeGen/LiveRangeInfo.h" +#include +using std::cerr; //--------------------------------------------------------------------------- // Constructor //--------------------------------------------------------------------------- LiveRangeInfo::LiveRangeInfo(const Method *const M, const TargetMachine& tm, - vector &RCL) - : Meth(M), LiveRangeMap(), - TM(tm), RegClassList(RCL), - MRI( tm.getRegInfo()), - CallRetInstrList() + std::vector &RCL) + : Meth(M), LiveRangeMap(), TM(tm), + RegClassList(RCL), MRI(tm.getRegInfo()) { } @@ -17,33 +17,25 @@ LiveRangeInfo::LiveRangeInfo(const Method *const M, // Destructor: Deletes all LiveRanges in the LiveRangeMap //--------------------------------------------------------------------------- LiveRangeInfo::~LiveRangeInfo() { - LiveRangeMapType::iterator MI = LiveRangeMap.begin(); for( ; MI != LiveRangeMap.end() ; ++MI) { - if( (*MI).first ) { - - LiveRange *LR = (*MI).second; - - if( LR ) { - - // we need to be careful in deleting LiveRanges in LiveRangeMap - // since two/more Values in the live range map can point to the same - // live range. We have to make the other entries NULL when we delete - // a live range. - - LiveRange::iterator LI = LR->begin(); - - for( ; LI != LR->end() ; ++LI) { - LiveRangeMap[*LI] = NULL; - } + if (MI->first && MI->second) { + LiveRange *LR = MI->second; - delete LR; + // we need to be careful in deleting LiveRanges in LiveRangeMap + // since two/more Values in the live range map can point to the same + // live range. We have to make the other entries NULL when we delete + // a live range. - } + LiveRange::iterator LI = LR->begin(); + + for( ; LI != LR->end() ; ++LI) + LiveRangeMap[*LI] = 0; + + delete LR; } } - } @@ -82,7 +74,7 @@ void LiveRangeInfo::unionAndUpdateLRs(LiveRange *const L1, LiveRange *L2) L1->addSpillCost( L2->getSpillCost() ); // add the spill costs - delete ( L2 ); // delete L2 as it is no longer needed + delete L2; // delete L2 as it is no longer needed } @@ -96,7 +88,7 @@ void LiveRangeInfo::constructLiveRanges() { if( DEBUG_RA) - cout << "Consturcting Live Ranges ..." << endl; + cerr << "Consturcting Live Ranges ...\n"; // first find the live ranges for all incoming args of the method since // those LRs start from the start of the method @@ -108,14 +100,13 @@ void LiveRangeInfo::constructLiveRanges() for( ; ArgIt != ArgList.end() ; ++ArgIt) { // for each argument - LiveRange * ArgRange = new LiveRange(); // creates a new LR and const Value *const Val = (const Value *) *ArgIt; assert( Val); - ArgRange->add( Val ); // add the arg (def) to it - LiveRangeMap[ Val ] = ArgRange; + ArgRange->add(Val); // add the arg (def) to it + LiveRangeMap[Val] = ArgRange; // create a temp machine op to find the register class of value //const MachineOperand Op(MachineOperand::MO_VirtualRegister); @@ -125,8 +116,8 @@ void LiveRangeInfo::constructLiveRanges() if( DEBUG_RA > 1) { - cout << " adding LiveRange for argument "; - printValue( (const Value *) *ArgIt); cout << endl; + cerr << " adding LiveRange for argument "; + printValue((const Value *) *ArgIt); cerr << "\n"; } } @@ -140,7 +131,6 @@ void LiveRangeInfo::constructLiveRanges() Method::const_iterator BBI = Meth->begin(); // random iterator for BBs - for( ; BBI != Meth->end(); ++BBI) { // go thru BBs in random order // Now find all LRs for machine the instructions. A new LR will be created @@ -150,8 +140,7 @@ void LiveRangeInfo::constructLiveRanges() // get the iterator for machine instructions const MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec(); - MachineCodeForBasicBlock::const_iterator - MInstIterator = MIVec.begin(); + MachineCodeForBasicBlock::const_iterator MInstIterator = MIVec.begin(); // iterate over all the machine instructions in BB for( ; MInstIterator != MIVec.end(); MInstIterator++) { @@ -161,53 +150,46 @@ void LiveRangeInfo::constructLiveRanges() // Now if the machine instruction is a call/return instruction, // add it to CallRetInstrList for processing its implicit operands - if( (TM.getInstrInfo()).isReturn( MInst->getOpCode()) || - (TM.getInstrInfo()).isCall( MInst->getOpCode()) ) + if(TM.getInstrInfo().isReturn(MInst->getOpCode()) || + TM.getInstrInfo().isCall(MInst->getOpCode())) CallRetInstrList.push_back( MInst ); // iterate over MI operands to find defs - for( MachineInstr::val_const_op_iterator OpI(MInst);!OpI.done(); ++OpI) { - - if( DEBUG_RA) { + for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done(); ++OpI) { + if(DEBUG_RA) { MachineOperand::MachineOperandType OpTyp = OpI.getMachineOperand().getOperandType(); - if ( OpTyp == MachineOperand::MO_CCRegister) { - cout << "\n**CC reg found. Is Def=" << OpI.isDef() << " Val:"; + if (OpTyp == MachineOperand::MO_CCRegister) { + cerr << "\n**CC reg found. Is Def=" << OpI.isDef() << " Val:"; printValue( OpI.getMachineOperand().getVRegValue() ); - cout << endl; + cerr << "\n"; } } // create a new LR iff this operand is a def if( OpI.isDef() ) { - const Value *const Def = *OpI; - // Only instruction values are accepted for live ranges here - if( Def->getValueType() != Value::InstructionVal ) { - cout << "\n**%%Error: Def is not an instruction val. Def="; - printValue( Def ); cout << endl; + cerr << "\n**%%Error: Def is not an instruction val. Def="; + printValue( Def ); cerr << "\n"; continue; } - LiveRange *DefRange = LiveRangeMap[Def]; // see LR already there (because of multiple defs) - if( !DefRange) { // if it is not in LiveRangeMap - DefRange = new LiveRange(); // creates a new live range and DefRange->add( Def ); // add the instruction (def) to it LiveRangeMap[ Def ] = DefRange; // update the map if( DEBUG_RA > 1) { - cout << " creating a LR for def: "; - printValue(Def); cout << endl; + cerr << " creating a LR for def: "; + printValue(Def); cerr << "\n"; } // set the register class of the new live range @@ -221,7 +203,7 @@ void LiveRangeInfo::constructLiveRanges() if(isCC && DEBUG_RA) { - cout << "\a**created a LR for a CC reg:"; + cerr << "\a**created a LR for a CC reg:"; printValue( OpI.getMachineOperand().getVRegValue() ); } @@ -235,8 +217,8 @@ void LiveRangeInfo::constructLiveRanges() LiveRangeMap[ Def ] = DefRange; if( DEBUG_RA > 1) { - cout << " added to an existing LR for def: "; - printValue( Def ); cout << endl; + cerr << " added to an existing LR for def: "; + printValue( Def ); cerr << "\n"; } } @@ -256,7 +238,7 @@ void LiveRangeInfo::constructLiveRanges() suggestRegs4CallRets(); if( DEBUG_RA) - cout << "Initial Live Ranges constructed!" << endl; + cerr << "Initial Live Ranges constructed!\n"; } @@ -312,11 +294,8 @@ void LiveRangeInfo::suggestRegs4CallRets() //--------------------------------------------------------------------------- void LiveRangeInfo::coalesceLRs() { - - - if( DEBUG_RA) - cout << endl << "Coalscing LRs ..." << endl; + cerr << "\nCoalscing LRs ...\n"; Method::const_iterator BBI = Meth->begin(); // random iterator for BBs @@ -324,8 +303,7 @@ void LiveRangeInfo::coalesceLRs() // get the iterator for machine instructions const MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec(); - MachineCodeForBasicBlock::const_iterator - MInstIterator = MIVec.begin(); + MachineCodeForBasicBlock::const_iterator MInstIterator = MIVec.begin(); // iterate over all the machine instructions in BB for( ; MInstIterator != MIVec.end(); ++MInstIterator) { @@ -333,9 +311,9 @@ void LiveRangeInfo::coalesceLRs() const MachineInstr * MInst = *MInstIterator; if( DEBUG_RA > 1) { - cout << " *Iterating over machine instr "; + cerr << " *Iterating over machine instr "; MInst->dump(); - cout << endl; + cerr << "\n"; } @@ -357,8 +335,8 @@ void LiveRangeInfo::coalesceLRs() //don't warn about labels if (!((*UseI)->getType())->isLabelType() && DEBUG_RA) { - cout<<" !! Warning: No LR for use "; printValue(*UseI); - cout << endl; + cerr<<" !! Warning: No LR for use "; printValue(*UseI); + cerr << "\n"; } continue; // ignore and continue } @@ -407,7 +385,7 @@ void LiveRangeInfo::coalesceLRs() } // for all BBs if( DEBUG_RA) - cout << endl << "Coalscing Done!" << endl; + cerr << "\nCoalscing Done!\n"; } @@ -421,11 +399,11 @@ void LiveRangeInfo::coalesceLRs() void LiveRangeInfo::printLiveRanges() { LiveRangeMapType::iterator HMI = LiveRangeMap.begin(); // hash map iterator - cout << endl << "Printing Live Ranges from Hash Map:" << endl; - for( ; HMI != LiveRangeMap.end() ; HMI ++ ) { - if( (*HMI).first && (*HMI).second ) { - cout <<" "; printValue((*HMI).first); cout << "\t: "; - ((*HMI).second)->printSet(); cout << endl; + cerr << "\nPrinting Live Ranges from Hash Map:\n"; + for( ; HMI != LiveRangeMap.end() ; ++HMI) { + if( HMI->first && HMI->second ) { + cerr <<" "; printValue((*HMI).first); cerr << "\t: "; + HMI->second->printSet(); cerr << "\n"; } } } diff --git a/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.h b/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.h index 1eee1aea5e3..9e7ef06fe28 100644 --- a/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.h +++ b/lib/Target/SparcV9/RegAlloc/LiveRangeInfo.h @@ -1,4 +1,4 @@ -/* Title: LiveRangeInfo.h +/* Title: LiveRangeInfo.h -*- C++ -*- Author: Ruchira Sasanka Date: Jun 30, 01 Purpose: @@ -34,8 +34,8 @@ #include "llvm/CodeGen/RegClass.h" -typedef hash_map LiveRangeMapType; -typedef vector CallRetInstrListType; +typedef std::hash_map LiveRangeMapType; +typedef std::vector CallRetInstrListType; @@ -59,7 +59,7 @@ private: const TargetMachine& TM; // target machine description - vector & RegClassList;// a vector containing register classess + std::vector & RegClassList;// vector containing register classess const MachineRegInfo& MRI; // machine reg info @@ -82,7 +82,7 @@ public: LiveRangeInfo(const Method *const M, const TargetMachine& tm, - vector & RCList); + std::vector & RCList); // Destructor to destroy all LiveRanges in the LiveRange Map diff --git a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp index 7d6fbb7cc98..e2d455bad9d 100644 --- a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp +++ b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp @@ -14,7 +14,9 @@ #include "llvm/CodeGen/MachineInstr.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/MachineFrameInfo.h" +#include #include +using std::cerr; // ***TODO: There are several places we add instructions. Validate the order @@ -35,18 +37,16 @@ cl::Enum DEBUG_RA("dregalloc", cl::NoFlags, PhyRegAlloc::PhyRegAlloc(Method *M, const TargetMachine& tm, MethodLiveVarInfo *const Lvi) - : RegClassList(), - TM(tm), - Meth(M), + : TM(tm), Meth(M), mcInfo(MachineCodeForMethod::get(M)), LVI(Lvi), LRI(M, tm, RegClassList), MRI( tm.getRegInfo() ), NumOfRegClasses(MRI.getNumOfRegClasses()), - AddedInstrMap(), LoopDepthCalc(M), ResColList() { + LoopDepthCalc(M) { // create each RegisterClass and put in RegClassList // - for( unsigned int rc=0; rc < NumOfRegClasses; rc++) + for(unsigned int rc=0; rc < NumOfRegClasses; rc++) RegClassList.push_back( new RegClass(M, MRI.getMachineRegClass(rc), &ResColList) ); } @@ -69,7 +69,7 @@ PhyRegAlloc::~PhyRegAlloc() { //---------------------------------------------------------------------------- void PhyRegAlloc::createIGNodeListsAndIGs() { - if(DEBUG_RA ) cout << "Creating LR lists ..." << endl; + if(DEBUG_RA ) cerr << "Creating LR lists ...\n"; // hash map iterator LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin(); @@ -85,8 +85,8 @@ void PhyRegAlloc::createIGNodeListsAndIGs() if( !L) { if( DEBUG_RA) { - cout << "\n*?!?Warning: Null liver range found for: "; - printValue( (*HMI).first) ; cout << endl; + cerr << "\n*?!?Warning: Null liver range found for: "; + printValue(HMI->first); cerr << "\n"; } continue; } @@ -108,7 +108,7 @@ void PhyRegAlloc::createIGNodeListsAndIGs() RegClassList[ rc ]->createInterferenceGraph(); if( DEBUG_RA) - cout << "LRLists Created!" << endl; + cerr << "LRLists Created!\n"; } @@ -140,8 +140,8 @@ void PhyRegAlloc::addInterference(const Value *const Def, for( ; LIt != LVSet->end(); ++LIt) { if( DEBUG_RA > 1) { - cout << "< Def="; printValue(Def); - cout << ", Lvar="; printValue( *LIt); cout << "> "; + cerr << "< Def="; printValue(Def); + cerr << ", Lvar="; printValue( *LIt); cerr << "> "; } // get the live range corresponding to live var @@ -166,8 +166,8 @@ void PhyRegAlloc::addInterference(const Value *const Def, else if(DEBUG_RA > 1) { // we will not have LRs for values not explicitly allocated in the // instruction stream (e.g., constants) - cout << " warning: no live range for " ; - printValue( *LIt); cout << endl; } + cerr << " warning: no live range for " ; + printValue(*LIt); cerr << "\n"; } } @@ -203,7 +203,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, } if( DEBUG_RA) - cout << "\n For call inst: " << *MInst; + cerr << "\n For call inst: " << *MInst; LiveVarSet::const_iterator LIt = LVSetAft->begin(); @@ -216,7 +216,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, LiveRange *const LR = LRI.getLiveRangeForValue(*LIt ); if( LR && DEBUG_RA) { - cout << "\n\tLR Aft Call: "; + cerr << "\n\tLR Aft Call: "; LR->printSet(); } @@ -227,7 +227,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, if( LR && (LR != RetValLR) ) { LR->setCallInterference(); if( DEBUG_RA) { - cout << "\n ++Added call interf for LR: " ; + cerr << "\n ++Added call interf for LR: " ; LR->printSet(); } } @@ -247,7 +247,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, void PhyRegAlloc::buildInterferenceGraphs() { - if(DEBUG_RA) cout << "Creating interference graphs ..." << endl; + if(DEBUG_RA) cerr << "Creating interference graphs ...\n"; unsigned BBLoopDepthCost; Method::const_iterator BBI = Meth->begin(); // random iterator for BBs @@ -333,7 +333,7 @@ void PhyRegAlloc::buildInterferenceGraphs() addInterferencesForArgs(); if( DEBUG_RA) - cout << "Interference graphs calculted!" << endl; + cerr << "Interference graphs calculted!\n"; } @@ -411,8 +411,8 @@ void PhyRegAlloc::addInterferencesForArgs() addInterference( *ArgIt, InSet, false ); // add interferences between // args and LVars at start if( DEBUG_RA > 1) { - cout << " - %% adding interference for argument "; - printValue( (const Value *) *ArgIt); cout << endl; + cerr << " - %% adding interference for argument "; + printValue((const Value *)*ArgIt); cerr << "\n"; } } } @@ -510,7 +510,7 @@ void PhyRegAlloc::updateMachineCode() // delete this condition checking later (must assert if Val is null) if( !Val) { if (DEBUG_RA) - cout << "Warning: NULL Value found for operand" << endl; + cerr << "Warning: NULL Value found for operand\n"; continue; } assert( Val && "Value is NULL"); @@ -522,9 +522,9 @@ void PhyRegAlloc::updateMachineCode() // nothing to worry if it's a const or a label if (DEBUG_RA) { - cout << "*NO LR for operand : " << Op ; - cout << " [reg:" << Op.getAllocatedRegNum() << "]"; - cout << " in inst:\t" << *MInst << endl; + cerr << "*NO LR for operand : " << Op ; + cerr << " [reg:" << Op.getAllocatedRegNum() << "]"; + cerr << " in inst:\t" << *MInst << "\n"; } // if register is not allocated, mark register as invalid @@ -563,18 +563,16 @@ void PhyRegAlloc::updateMachineCode() // instruction, add them now. // if( AddedInstrMap[ MInst ] ) { - - deque &IBef = (AddedInstrMap[MInst])->InstrnsBefore; + std::deque &IBef = AddedInstrMap[MInst]->InstrnsBefore; if( ! IBef.empty() ) { - - deque::iterator AdIt; + std::deque::iterator AdIt; for( AdIt = IBef.begin(); AdIt != IBef.end() ; ++AdIt ) { if( DEBUG_RA) { cerr << "For inst " << *MInst; - cerr << " PREPENDed instr: " << **AdIt << endl; + cerr << " PREPENDed instr: " << **AdIt << "\n"; } MInstIterator = MIVec.insert( MInstIterator, *AdIt ); @@ -600,7 +598,7 @@ void PhyRegAlloc::updateMachineCode() if((delay=TM.getInstrInfo().getNumDelaySlots(MInst->getOpCode())) >0){ move2DelayedInstr(MInst, *(MInstIterator+delay) ); - if(DEBUG_RA) cout<< "\nMoved an added instr after the delay slot"; + if(DEBUG_RA) cerr<< "\nMoved an added instr after the delay slot"; } else { @@ -609,11 +607,11 @@ void PhyRegAlloc::updateMachineCode() // Here we can add the "instructions after" to the current // instruction since there are no delay slots for this instruction - deque &IAft = (AddedInstrMap[MInst])->InstrnsAfter; + std::deque &IAft = AddedInstrMap[MInst]->InstrnsAfter; if( ! IAft.empty() ) { - deque::iterator AdIt; + std::deque::iterator AdIt; ++MInstIterator; // advance to the next instruction @@ -621,7 +619,7 @@ void PhyRegAlloc::updateMachineCode() if(DEBUG_RA) { cerr << "For inst " << *MInst; - cerr << " APPENDed instr: " << **AdIt << endl; + cerr << " APPENDed instr: " << **AdIt << "\n"; } MInstIterator = MIVec.insert( MInstIterator, *AdIt ); @@ -669,9 +667,7 @@ void PhyRegAlloc::insertCode4SpilledLR(const LiveRange *LR, RegClass *RC = LR->getRegClass(); const LiveVarSet *LVSetBef = LVI->getLiveVarSetBeforeMInst(MInst, BB); - - int TmpOff = - mcInfo.pushTempValue(TM, MRI.getSpilledRegSize(RegType) ); + mcInfo.pushTempValue(TM, MRI.getSpilledRegSize(RegType) ); MachineInstr *MIBef=NULL, *AdIMid=NULL, *MIAft=NULL; @@ -854,13 +850,10 @@ int PhyRegAlloc::getUniRegNotUsedByThisInst(RegClass *RC, return MRI.getUnifiedRegNum(RC->getID(), c); else assert( 0 && "FATAL: No free register could be found in reg class!!"); - + return 0; } - - - //---------------------------------------------------------------------------- // This method modifies the IsColorUsedArr of the register class passed to it. // It sets the bits corresponding to the registers used by this machine @@ -909,14 +902,10 @@ void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC, LiveRange *const LRofImpRef = LRI.getLiveRangeForValue( MInst->getImplicitRef(z) ); - - if( LRofImpRef ) - if( LRofImpRef->hasColor() ) - IsColorUsedArr[ LRofImpRef->getColor() ] = true; + + if(LRofImpRef && LRofImpRef->hasColor()) + IsColorUsedArr[LRofImpRef->getColor()] = true; } - - - } @@ -936,9 +925,8 @@ void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC, void PhyRegAlloc:: move2DelayedInstr(const MachineInstr *OrigMI, const MachineInstr *DelayedMI) { - // "added after" instructions of the original instr - deque &OrigAft = (AddedInstrMap[OrigMI])->InstrnsAfter; + std::deque &OrigAft = AddedInstrMap[OrigMI]->InstrnsAfter; // "added instructions" of the delayed instr AddedInstrns *DelayAdI = AddedInstrMap[DelayedMI]; @@ -949,21 +937,15 @@ void PhyRegAlloc:: move2DelayedInstr(const MachineInstr *OrigMI, } // "added after" instructions of the delayed instr - deque &DelayedAft = DelayAdI->InstrnsAfter; + std::deque &DelayedAft = DelayAdI->InstrnsAfter; // go thru all the "added after instructions" of the original instruction // and append them to the "addded after instructions" of the delayed // instructions - - deque::iterator OrigAdIt; - - for( OrigAdIt = OrigAft.begin(); OrigAdIt != OrigAft.end() ; ++OrigAdIt ) { - DelayedAft.push_back( *OrigAdIt ); - } + DelayedAft.insert(DelayedAft.end(), OrigAft.begin(), OrigAft.end()); // empty the "added after instructions" of the original instruction OrigAft.clear(); - } //---------------------------------------------------------------------------- @@ -973,14 +955,14 @@ void PhyRegAlloc:: move2DelayedInstr(const MachineInstr *OrigMI, void PhyRegAlloc::printMachineCode() { - cout << endl << ";************** Method "; - cout << Meth->getName() << " *****************" << endl; + cerr << "\n;************** Method " << Meth->getName() + << " *****************\n"; Method::const_iterator BBI = Meth->begin(); // random iterator for BBs for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order - cout << endl ; printLabel( *BBI); cout << ": "; + cerr << "\n"; printLabel( *BBI); cerr << ": "; // get the iterator for machine instructions MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec(); @@ -992,8 +974,8 @@ void PhyRegAlloc::printMachineCode() MachineInstr *const MInst = *MInstIterator; - cout << endl << "\t"; - cout << TargetInstrDescriptors[MInst->getOpCode()].opCodeString; + cerr << "\n\t"; + cerr << TargetInstrDescriptors[MInst->getOpCode()].opCodeString; //for(MachineInstr::val_const_op_iterator OpI(MInst);!OpI.done();++OpI) { @@ -1009,41 +991,39 @@ void PhyRegAlloc::printMachineCode() const Value *const Val = Op.getVRegValue () ; // ****this code is temporary till NULL Values are fixed if( ! Val ) { - cout << "\t<*NULL*>"; + cerr << "\t<*NULL*>"; continue; } // if a label or a constant - if( (Val->getValueType() == Value::BasicBlockVal) ) { - - cout << "\t"; printLabel( Op.getVRegValue () ); - } - else { + if(isa(Val) { + cerr << "\t"; printLabel( Op.getVRegValue () ); + } else { // else it must be a register value const int RegNum = Op.getAllocatedRegNum(); - cout << "\t" << "%" << MRI.getUnifiedRegName( RegNum ); + cerr << "\t" << "%" << MRI.getUnifiedRegName( RegNum ); if (Val->hasName() ) - cout << "(" << Val->getName() << ")"; + cerr << "(" << Val->getName() << ")"; else - cout << "(" << Val << ")"; + cerr << "(" << Val << ")"; if( Op.opIsDef() ) - cout << "*"; + cerr << "*"; const LiveRange *LROfVal = LRI.getLiveRangeForValue(Val); if( LROfVal ) if( LROfVal->hasSpillOffset() ) - cout << "$"; + cerr << "$"; } } else if(Op.getOperandType() == MachineOperand::MO_MachineRegister) { - cout << "\t" << "%" << MRI.getUnifiedRegName(Op.getMachineRegNum()); + cerr << "\t" << "%" << MRI.getUnifiedRegName(Op.getMachineRegNum()); } else - cout << "\t" << Op; // use dump field + cerr << "\t" << Op; // use dump field } @@ -1051,23 +1031,22 @@ void PhyRegAlloc::printMachineCode() unsigned NumOfImpRefs = MInst->getNumImplicitRefs(); if( NumOfImpRefs > 0 ) { - cout << "\tImplicit:"; + cerr << "\tImplicit:"; for(unsigned z=0; z < NumOfImpRefs; z++) { printValue( MInst->getImplicitRef(z) ); - cout << "\t"; + cerr << "\t"; } } } // for all machine instructions - - cout << endl; + cerr << "\n"; } // for all BBs - cout << endl; + cerr << "\n"; } @@ -1125,9 +1104,9 @@ void PhyRegAlloc::colorIncomingArgs() assert( FirstMI && "No machine instruction in entry BB"); AddedInstrns *AI = AddedInstrMap[ FirstMI ]; - if ( !AI ) { + if (!AI) { AI = new AddedInstrns(); - AddedInstrMap[ FirstMI ] = AI; + AddedInstrMap[FirstMI] = AI; } MRI.colorMethodArgs(Meth, LRI, AI ); @@ -1137,12 +1116,11 @@ void PhyRegAlloc::colorIncomingArgs() //---------------------------------------------------------------------------- // Used to generate a label for a basic block //---------------------------------------------------------------------------- -void PhyRegAlloc::printLabel(const Value *const Val) -{ - if( Val->hasName() ) - cout << Val->getName(); +void PhyRegAlloc::printLabel(const Value *const Val) { + if (Val->hasName()) + cerr << Val->getName(); else - cout << "Label" << Val; + cerr << "Label" << Val; } @@ -1155,7 +1133,7 @@ void PhyRegAlloc::printLabel(const Value *const Val) void PhyRegAlloc::markUnusableSugColors() { - if(DEBUG_RA ) cout << "\nmarking unusable suggested colors ..." << endl; + if(DEBUG_RA ) cerr << "\nmarking unusable suggested colors ...\n"; // hash map iterator LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin(); @@ -1193,22 +1171,18 @@ void PhyRegAlloc::markUnusableSugColors() void PhyRegAlloc::allocateStackSpace4SpilledLRs() { - if(DEBUG_RA ) cout << "\nsetting LR stack offsets ..." << endl; + if(DEBUG_RA ) cerr << "\nsetting LR stack offsets ...\n"; // hash map iterator LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin(); LiveRangeMapType::const_iterator HMIEnd = (LRI.getLiveRangeMap())->end(); for( ; HMI != HMIEnd ; ++HMI ) { - if( (*HMI).first ) { - LiveRange *L = (*HMI).second; // get the LiveRange - if(L) - if( ! L->hasColor() ) - - // NOTE: ** allocating the size of long Type ** - L->setSpillOffFromFP(mcInfo.allocateSpilledValue(TM, - Type::LongTy)); - + if(HMI->first && HMI->second) { + LiveRange *L = HMI->second; // get the LiveRange + if( ! L->hasColor() ) + // NOTE: ** allocating the size of long Type ** + L->setSpillOffFromFP(mcInfo.allocateSpilledValue(TM, Type::LongTy)); } } // for all LR's in hash map } diff --git a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h index 9d34557b01e..6871b2d28ad 100644 --- a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h +++ b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h @@ -1,4 +1,4 @@ -/* Title: PhyRegAlloc.h +/* Title: PhyRegAlloc.h -*- C++ -*- Author: Ruchira Sasanka Date: Aug 20, 01 Purpose: This is the main entry point for register allocation. @@ -54,13 +54,11 @@ class AddedInstrns { public: - deque InstrnsBefore; // Added insts BEFORE an existing inst - deque InstrnsAfter; // Added insts AFTER an existing inst - - AddedInstrns() : InstrnsBefore(), InstrnsAfter() { } + std::deque InstrnsBefore;// Added insts BEFORE an existing inst + std::deque InstrnsAfter; // Added insts AFTER an existing inst }; -typedef hash_map AddedInstrMapType; +typedef std::hash_map AddedInstrMapType; @@ -74,7 +72,7 @@ typedef hash_map AddedInstrMapType; class PhyRegAlloc: public NonCopyable { - vector RegClassList ; // vector of register classes + std::vector RegClassList; // vector of register classes const TargetMachine &TM; // target machine const Method* Meth; // name of the method we work on MachineCodeForMethod& mcInfo; // descriptor for method's native code @@ -115,8 +113,7 @@ class PhyRegAlloc: public NonCopyable const BasicBlock *BB, const unsigned OpNum); - inline void constructLiveRanges() - { LRI.constructLiveRanges(); } + inline void constructLiveRanges() { LRI.constructLiveRanges(); } void colorIncomingArgs(); void colorCallRetArgs(); @@ -141,12 +138,9 @@ class PhyRegAlloc: public NonCopyable void addInterf4PseudoInstr(const MachineInstr *MInst); - public: - PhyRegAlloc(Method *const M, const TargetMachine& TM, MethodLiveVarInfo *const Lvi); - ~PhyRegAlloc(); // main method called for allocating registers diff --git a/lib/Target/SparcV9/RegAlloc/RegClass.cpp b/lib/Target/SparcV9/RegAlloc/RegClass.cpp index 3918871d69f..8ba6a15ad11 100644 --- a/lib/Target/SparcV9/RegAlloc/RegClass.cpp +++ b/lib/Target/SparcV9/RegAlloc/RegClass.cpp @@ -1,5 +1,6 @@ #include "llvm/CodeGen/RegClass.h" - +#include +using std::cerr; //---------------------------------------------------------------------------- // This constructor inits IG. The actual matrix is created by a call to @@ -11,7 +12,7 @@ RegClass::RegClass(const Method *const M, : Meth(M), MRC(Mrc), RegClassID( Mrc->getRegClassID() ), IG(this), IGNodeStack(), ReservedColorList(RCL) { if( DEBUG_RA) - cout << "Created Reg Class: " << RegClassID << endl; + cerr << "Created Reg Class: " << RegClassID << "\n"; IsColorUsedArr = new bool[ Mrc->getNumOfAllRegs() ]; } @@ -23,7 +24,7 @@ RegClass::RegClass(const Method *const M, //---------------------------------------------------------------------------- void RegClass::colorAllRegs() { - if(DEBUG_RA) cout << "Coloring IG of reg class " << RegClassID << " ...\n"; + if(DEBUG_RA) cerr << "Coloring IG of reg class " << RegClassID << " ...\n"; // pre-color IGNodes pushAllIGNodes(); // push all IG Nodes @@ -57,9 +58,9 @@ void RegClass::pushAllIGNodes() bool PushedAll = pushUnconstrainedIGNodes(); if( DEBUG_RA) { - cout << " Puhsed all-unconstrained IGNodes. "; - if( PushedAll ) cout << " No constrained nodes left."; - cout << endl; + cerr << " Puhsed all-unconstrained IGNodes. "; + if( PushedAll ) cerr << " No constrained nodes left."; + cerr << "\n"; } if( PushedAll ) // if NO constrained nodes left @@ -129,8 +130,8 @@ bool RegClass::pushUnconstrainedIGNodes() IGNode->pushOnStack(); // set OnStack and dec deg of neighs if (DEBUG_RA > 1) { - cout << " pushed un-constrained IGNode " << IGNode->getIndex() ; - cout << " on to stack" << endl; + cerr << " pushed un-constrained IGNode " << IGNode->getIndex() ; + cerr << " on to stack\n"; } } else pushedall = false; // we didn't push all live ranges @@ -215,16 +216,16 @@ void RegClass::colorIGNode(IGNode *const Node) } else { if( DEBUG_RA ) { - cout << " Node " << Node->getIndex(); - cout << " already colored with color " << Node->getColor() << endl; + cerr << " Node " << Node->getIndex(); + cerr << " already colored with color " << Node->getColor() << "\n"; } } if( !Node->hasColor() ) { if( DEBUG_RA ) { - cout << " Node " << Node->getIndex(); - cout << " - could not find a color (needs spilling)" << endl; + cerr << " Node " << Node->getIndex(); + cerr << " - could not find a color (needs spilling)\n"; } } diff --git a/lib/Target/SparcV9/RegAlloc/RegClass.h b/lib/Target/SparcV9/RegAlloc/RegClass.h index d6cbaf892bb..fe25986f408 100644 --- a/lib/Target/SparcV9/RegAlloc/RegClass.h +++ b/lib/Target/SparcV9/RegAlloc/RegClass.h @@ -13,8 +13,9 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/MachineRegInfo.h" #include +#include -typedef vector ReservedColorListType; +typedef std::vector ReservedColorListType; //----------------------------------------------------------------------------- @@ -46,7 +47,7 @@ class RegClass InterferenceGraph IG; // Interference graph - constructed by // buildInterferenceGraph - stack IGNodeStack; // the stack used for coloring + std::stack IGNodeStack; // the stack used for coloring const ReservedColorListType *const ReservedColorList; // @@ -117,21 +118,14 @@ class RegClass inline void printIGNodeList() const { - cerr << "IG Nodes for Register Class " << RegClassID << ":" << endl; + std::cerr << "IG Nodes for Register Class " << RegClassID << ":" << "\n"; IG.printIGNodeList(); } inline void printIG() { - cerr << "IG for Register Class " << RegClassID << ":" << endl; + std::cerr << "IG for Register Class " << RegClassID << ":" << "\n"; IG.printIG(); } - }; - - - - - - #endif diff --git a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp index fb2888b05d8..098da9074e5 100644 --- a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp +++ b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp @@ -22,16 +22,17 @@ #include "Support/StringExtras.h" #include "Support/HashExtras.h" #include +using std::string; namespace { class SparcAsmPrinter { - typedef hash_map ValIdMap; + typedef std::hash_map ValIdMap; typedef ValIdMap:: iterator ValIdMapIterator; typedef ValIdMap::const_iterator ValIdMapConstIterator; - ostream &toAsm; + std::ostream &toAsm; SlotCalculator Table; // map anonymous values to unique integer IDs ValIdMap valToIdMap; // used for values not handled by SlotCalculator const UltraSparc &Target; @@ -45,7 +46,7 @@ class SparcAsmPrinter { } CurSection; public: - inline SparcAsmPrinter(ostream &o, const Module *M, const UltraSparc &t) + inline SparcAsmPrinter(std::ostream &o, const Module *M, const UltraSparc &t) : toAsm(o), Table(SlotCalculator(M, true)), Target(t), CurSection(Unknown) { emitModule(M); } @@ -61,7 +62,7 @@ private : void printGlobalVariable( const GlobalVariable* GV); void printSingleConstant( const Constant* CV); void printConstantValueOnly(const Constant* CV); - void printConstant( const Constant* CV, string valID=string("")); + void printConstant( const Constant* CV, std::string valID = ""); unsigned int printOperands(const MachineInstr *MI, unsigned int opNum); void printOneOperand(const MachineOperand &Op); @@ -88,7 +89,7 @@ private : toAsm << "\n"; } - string getValidSymbolName(const string &S) { + std::string getValidSymbolName(const string &S) { string Result; // Symbol names in Sparc assembly language have these rules: @@ -318,7 +319,7 @@ SparcAsmPrinter::printOneOperand(const MachineOperand &op) case MachineOperand::MO_SignExtendedImmed: case MachineOperand::MO_UnextendedImmed: - toAsm << op.getImmedValue(); + toAsm << (long)op.getImmedValue(); break; default: @@ -351,7 +352,7 @@ SparcAsmPrinter::emitMachineInst(const MachineInstr *MI) else N = 1; - toAsm << endl; + toAsm << "\n"; } void @@ -393,7 +394,7 @@ SparcAsmPrinter::emitMethod(const Method *M) // Output a .size directive so the debugger knows the extents of the function toAsm << ".EndOf_" << methName << ":\n\t.size " << methName << ", .EndOf_" - << methName << "-" << methName << endl; + << methName << "-" << methName << "\n"; // Put some spaces between the methods toAsm << "\n\n"; @@ -487,7 +488,6 @@ TypeToAlignment(const Type* type, const TargetMachine& target) inline unsigned int ConstantToAlignment(const Constant* CV, const TargetMachine& target) { - unsigned int constantSize; if (ConstantArray* CPA = dyn_cast(CV)) if (ArrayTypeIsString(cast(CPA->getType()))) return SizeToAlignment(1 + CPA->getNumOperands(), target); @@ -515,16 +515,15 @@ SparcAsmPrinter::printSingleConstant(const Constant* CV) { if (CV->getType() == Type::FloatTy || CV->getType() == Type::DoubleTy) toAsm << "0r"; // FP constants must have this prefix - toAsm << CV->getStrValue() << endl; + toAsm << CV->getStrValue() << "\n"; } else if (ConstantPointer* CPP = dyn_cast(CV)) { - if (! CPP->isNullValue()) - assert(0 && "Cannot yet print non-null pointer constants to assembly"); - else - toAsm << (void*) NULL << endl; + assert(CPP->isNullValue() && + "Cannot yet print non-null pointer constants to assembly"); + toAsm << "0\n"; } - else if (ConstantPointerRef* CPRef = dyn_cast(CV)) + else if (isa(CV)) { assert(0 && "Cannot yet initialize pointer refs in assembly"); } @@ -543,17 +542,17 @@ SparcAsmPrinter::printConstantValueOnly(const Constant* CV) if (CPA && isStringCompatible(CPA)) { // print the string alone and return - toAsm << "\t" << ".ascii" << "\t" << getAsCString(CPA) << endl; + toAsm << "\t" << ".ascii" << "\t" << getAsCString(CPA) << "\n"; } else if (CPA) { // Not a string. Print the values in successive locations - const vector& constValues = CPA->getValues(); + const std::vector &constValues = CPA->getValues(); for (unsigned i=1; i < constValues.size(); i++) this->printConstantValueOnly(cast(constValues[i].get())); } else if (ConstantStruct *CPS = dyn_cast(CV)) { // Print the fields in successive locations - const vector& constValues = CPS->getValues(); + const std::vector& constValues = CPS->getValues(); for (unsigned i=1; i < constValues.size(); i++) this->printConstantValueOnly(cast(constValues[i].get())); } @@ -571,25 +570,25 @@ SparcAsmPrinter::printConstant(const Constant* CV, string valID) valID = getID(CV); toAsm << "\t.align\t" << ConstantToAlignment(CV, Target) - << endl; + << "\n"; // Print .size and .type only if it is not a string. ConstantArray *CPA = dyn_cast(CV); if (CPA && isStringCompatible(CPA)) { // print it as a string and return - toAsm << valID << ":" << endl; - toAsm << "\t" << ".ascii" << "\t" << getAsCString(CPA) << endl; + toAsm << valID << ":\n"; + toAsm << "\t" << ".ascii" << "\t" << getAsCString(CPA) << "\n"; return; } - toAsm << "\t.type" << "\t" << valID << ",#object" << endl; + toAsm << "\t.type" << "\t" << valID << ",#object\n"; unsigned int constSize = ConstantToSize(CV, Target); if (constSize) toAsm << "\t.size" << "\t" << valID << "," - << constSize << endl; + << constSize << "\n"; - toAsm << valID << ":" << endl; + toAsm << valID << ":\n"; this->printConstantValueOnly(CV); } @@ -598,29 +597,29 @@ SparcAsmPrinter::printConstant(const Constant* CV, string valID) void SparcAsmPrinter::printGlobalVariable(const GlobalVariable* GV) { - toAsm << "\t.global\t" << getID(GV) << endl; + toAsm << "\t.global\t" << getID(GV) << "\n"; if (GV->hasInitializer()) printConstant(GV->getInitializer(), getID(GV)); else { toAsm << "\t.align\t" - << TypeToAlignment(GV->getType()->getElementType(), Target) << endl; - toAsm << "\t.type\t" << getID(GV) << ",#object" << endl; + << TypeToAlignment(GV->getType()->getElementType(), Target) << "\n"; + toAsm << "\t.type\t" << getID(GV) << ",#object\n"; toAsm << "\t.reserve\t" << getID(GV) << "," << TypeToSize(GV->getType()->getElementType(), Target) - << endl; + << "\n"; } } static void FoldConstants(const Module *M, - hash_set& moduleConstants) + std::hash_set& moduleConstants) { for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) if (! (*I)->isExternal()) { - const hash_set& pool = + const std::hash_set& pool = MachineCodeForMethod::get(*I).getConstantPoolValues(); moduleConstants.insert(pool.begin(), pool.end()); } @@ -636,7 +635,7 @@ SparcAsmPrinter::emitGlobalsAndConstants(const Module *M) // lets force these constants into the slot table so that we can get // unique names for unnamed constants also. // - hash_set moduleConstants; + std::hash_set moduleConstants; FoldConstants(M, moduleConstants); // Now, emit the three data sections separately; the cost of I/O should @@ -654,7 +653,8 @@ SparcAsmPrinter::emitGlobalsAndConstants(const Module *M) } } - for (hash_set::const_iterator I = moduleConstants.begin(), + for (std::hash_set::const_iterator + I = moduleConstants.begin(), E = moduleConstants.end(); I != E; ++I) printConstant(*I); @@ -682,7 +682,7 @@ SparcAsmPrinter::emitGlobalsAndConstants(const Module *M) } } - toAsm << endl; + toAsm << "\n"; } @@ -705,7 +705,7 @@ SparcAsmPrinter::emitModule(const Module *M) // used. // void -UltraSparc::emitAssembly(const Module *M, ostream &toAsm) const +UltraSparc::emitAssembly(const Module *M, std::ostream &toAsm) const { SparcAsmPrinter Print(toAsm, M, *this); } diff --git a/lib/Target/SparcV9/SparcV9InstrInfo.cpp b/lib/Target/SparcV9/SparcV9InstrInfo.cpp index 99bb14d12ed..e00c871545c 100644 --- a/lib/Target/SparcV9/SparcV9InstrInfo.cpp +++ b/lib/Target/SparcV9/SparcV9InstrInfo.cpp @@ -27,7 +27,7 @@ static inline MachineInstr* CreateIntSetInstruction(int64_t C, Value* dest, - vector& tempVec) + std::vector& tempVec) { MachineInstr* minstr; uint64_t absC = (C >= 0)? C : -C; @@ -55,7 +55,7 @@ CreateIntSetInstruction(int64_t C, Value* dest, static inline MachineInstr* CreateUIntSetInstruction(uint64_t C, Value* dest, - vector& tempVec) + std::vector& tempVec) { MachineInstr* minstr; if (C > (unsigned int) ~0) @@ -109,9 +109,9 @@ UltraSparcInstrInfo::UltraSparcInstrInfo(const TargetMachine& tgt) // void UltraSparcInstrInfo::CreateCodeToLoadConst(Value* val, - Instruction* dest, - vector& minstrVec, - vector& tempVec) const + Instruction* dest, + std::vector& minstrVec, + std::vector& tempVec) const { MachineInstr* minstr; @@ -200,19 +200,17 @@ UltraSparcInstrInfo::CreateCodeToLoadConst(Value* val, // void UltraSparcInstrInfo::CreateCodeToCopyIntToFloat(Method* method, - Value* val, - Instruction* dest, - vector& minstrVec, - vector& tempVec, - TargetMachine& target) const + Value* val, + Instruction* dest, + std::vector& minstrVec, + std::vector& tempVec, + TargetMachine& target) const { assert((val->getType()->isIntegral() || val->getType()->isPointerType()) && "Source type must be integral"); assert((dest->getType() ==Type::FloatTy || dest->getType() ==Type::DoubleTy) && "Dest type must be float/double"); - const MachineFrameInfo& frameInfo = ((UltraSparc&) target).getFrameInfo(); - MachineCodeForMethod& mcinfo = MachineCodeForMethod::get(method); int offset = mcinfo.allocateLocalVar(target, val); @@ -246,19 +244,17 @@ UltraSparcInstrInfo::CreateCodeToCopyIntToFloat(Method* method, // void UltraSparcInstrInfo::CreateCodeToCopyFloatToInt(Method* method, - Value* val, - Instruction* dest, - vector& minstrVec, - vector& tempVec, - TargetMachine& target) const + Value* val, + Instruction* dest, + std::vector& minstrVec, + std::vector& tempVec, + TargetMachine& target) const { assert((val->getType() ==Type::FloatTy || val->getType() ==Type::DoubleTy) && "Source type must be float/double"); assert((dest->getType()->isIntegral() || dest->getType()->isPointerType()) && "Dest type must be integral"); - const MachineFrameInfo& frameInfo = ((UltraSparc&) target).getFrameInfo(); - MachineCodeForMethod& mcinfo = MachineCodeForMethod::get(method); int offset = mcinfo.allocateLocalVar(target, val); diff --git a/lib/Target/SparcV9/SparcV9InstrSelection.cpp b/lib/Target/SparcV9/SparcV9InstrSelection.cpp index c4fe7356727..c20c65a5cea 100644 --- a/lib/Target/SparcV9/SparcV9InstrSelection.cpp +++ b/lib/Target/SparcV9/SparcV9InstrSelection.cpp @@ -25,7 +25,7 @@ #include "llvm/ConstantVals.h" #include "Support/MathExtras.h" #include - +using std::vector; //************************* Forward Declarations ***************************/ @@ -34,7 +34,7 @@ static void SetMemOperands_Internal (MachineInstr* minstr, const InstructionNode* vmInstrNode, Value* ptrVal, Value* arrayOffsetVal, - const vector& idxVec, + const std::vector& idxVec, const TargetMachine& target); @@ -143,7 +143,7 @@ ChooseBFpccInstruction(const InstructionNode* instrNode, static TmpInstruction* GetTmpForCC(Value* boolVal, const Method* method, const Type* ccType) { - typedef hash_map BoolTmpCache; + typedef std::hash_map BoolTmpCache; static BoolTmpCache boolToTmpCache; // Map boolVal -> TmpInstruction* static const Method* lastMethod = NULL; // Use to flush cache between methods @@ -519,7 +519,6 @@ CreateMulConstInstruction(TargetMachine &target, { MachineInstr* minstr = NULL; // return NULL if we cannot exploit constant getMinstr2 = NULL; // to create a cheaper instruction - bool needNeg = false; Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue(); assert(isa(constOp)); @@ -1011,8 +1010,6 @@ GetInstructionsForProlog(BasicBlock* entryBB, TargetMachine &target, MachineInstr** mvec) { - int64_t s0=0; // used to avoid overloading ambiguity below - const MachineFrameInfo& frameInfo = target.getFrameInfo(); // The second operand is the stack size. If it does not fit in the @@ -1048,11 +1045,10 @@ GetInstructionsForEpilog(BasicBlock* anExitBB, TargetMachine &target, MachineInstr** mvec) { - int64_t s0=0; // used to avoid overloading ambiguity below - mvec[0] = new MachineInstr(RESTORE); mvec[0]->SetMachineOperand(0, target.getRegInfo().getZeroRegNum()); - mvec[0]->SetMachineOperand(1, MachineOperand::MO_SignExtendedImmed, s0); + mvec[0]->SetMachineOperand(1, MachineOperand::MO_SignExtendedImmed, + (int64_t)0); mvec[0]->SetMachineOperand(2, target.getRegInfo().getZeroRegNum()); return 1; @@ -1118,8 +1114,6 @@ GetInstructionsByRule(InstructionNode* subtreeRoot, bool checkCast = false; // initialize here to use fall-through int nextRule; int forwardOperandNum = -1; - int64_t s0=0, s8=8; // variables holding constants to avoid - uint64_t u0=0; // overloading ambiguities below for (unsigned i=0; i < MAX_INSTR_PER_VMINSTR; i++) mvec[i] = NULL; @@ -1162,7 +1156,8 @@ GetInstructionsByRule(InstructionNode* subtreeRoot, mvec[0] = new MachineInstr(JMPLRET); mvec[0]->SetMachineOperand(0, MachineOperand::MO_VirtualRegister, returnReg); - mvec[0]->SetMachineOperand(1, MachineOperand::MO_SignExtendedImmed,s8); + mvec[0]->SetMachineOperand(1, MachineOperand::MO_SignExtendedImmed, + (int64_t)8); mvec[0]->SetMachineOperand(2, target.getRegInfo().getZeroRegNum()); if (returnInstr->getReturnValue() != NULL) @@ -1775,7 +1770,7 @@ GetInstructionsByRule(InstructionNode* subtreeRoot, int n = numInstr++; mvec[n] = new MachineInstr(SETHI); mvec[n]->SetMachineOperand(0,MachineOperand::MO_UnextendedImmed, - s0); + (int64_t)0); mvec[n]->SetMachineOperand(1,MachineOperand::MO_VirtualRegister, setCCInstr); } @@ -2021,7 +2016,7 @@ GetInstructionsByRule(InstructionNode* subtreeRoot, phi->getOperand(i)); break; } -#endif NEED_PHI_MACHINE_INSTRS +#endif // NEED_PHI_MACHINE_INSTRS case 71: // reg: VReg case 72: // reg: Constant diff --git a/lib/Target/SparcV9/SparcV9InstrSelectionSupport.h b/lib/Target/SparcV9/SparcV9InstrSelectionSupport.h index f62457cb494..848ddddd384 100644 --- a/lib/Target/SparcV9/SparcV9InstrSelectionSupport.h +++ b/lib/Target/SparcV9/SparcV9InstrSelectionSupport.h @@ -58,4 +58,4 @@ ChooseStoreInstruction(const Type *DestTy) return 0; } -#endif SPARC_INSTR_SELECTION_SUPPORT_h +#endif diff --git a/lib/Target/SparcV9/SparcV9Internals.h b/lib/Target/SparcV9/SparcV9Internals.h index 51609f683f2..a82d122336c 100644 --- a/lib/Target/SparcV9/SparcV9Internals.h +++ b/lib/Target/SparcV9/SparcV9Internals.h @@ -128,8 +128,8 @@ public: // virtual void CreateCodeToLoadConst(Value* val, Instruction* dest, - vector& minstrVec, - vector& tempVec) const; + std::vector& minstrVec, + std::vector& tmp) const; // Create an instruction sequence to copy an integer value `val' @@ -141,8 +141,8 @@ public: virtual void CreateCodeToCopyIntToFloat(Method* method, Value* val, Instruction* dest, - vector& minstrVec, - vector& tempVec, + std::vector& minstr, + std::vector& temp, TargetMachine& target) const; // Similarly, create an instruction sequence to copy an FP value @@ -152,8 +152,8 @@ public: virtual void CreateCodeToCopyFloatToInt(Method* method, Value* val, Instruction* dest, - vector& minstrVec, - vector& tempVec, + std::vector& minstr, + std::vector& temp, TargetMachine& target) const; // create copy instruction(s) @@ -161,7 +161,7 @@ public: CreateCopyInstructionsByType(const TargetMachine& target, Value* src, Instruction* dest, - vector& minstrVec) const; + std::vector& minstr) const; }; @@ -245,7 +245,7 @@ class UltraSparcRegInfo : public MachineRegInfo LiveRangeInfo& LRI) const; void suggestReg4CallAddr(const MachineInstr * CallMI, LiveRangeInfo& LRI, - vector RCList) const; + std::vector RCList) const; @@ -348,12 +348,13 @@ class UltraSparcRegInfo : public MachineRegInfo // the register allocator in association with method calling. See // SparcRegInfo.cpp for more details // - void moveInst2OrdVec(vector &OrdVec, MachineInstr *UnordInst, - PhyRegAlloc &PRA ) const; + void moveInst2OrdVec(std::vector &OrdVec, + MachineInstr *UnordInst, + PhyRegAlloc &PRA) const; - void OrderAddedInstrns( vector &UnordVec, - vector &OrdVec, - PhyRegAlloc &PRA) const; + void OrderAddedInstrns(std::vector &UnordVec, + std::vector &OrdVec, + PhyRegAlloc &PRA) const; // To find whether a particular call is to a var arg method @@ -410,7 +411,7 @@ class UltraSparcRegInfo : public MachineRegInfo else if( ty <= Type::DoubleTyID) res = FloatRegClassID; // sparc float reg class else { - cerr << "TypeID: " << ty << endl; + std::cerr << "TypeID: " << ty << "\n"; assert(0 && "Cannot resolve register class for type"); return 0; } @@ -449,10 +450,11 @@ class UltraSparcRegInfo : public MachineRegInfo LiveRangeInfo& LRI) const; void suggestRegs4CallArgs(const MachineInstr *const CallMI, - LiveRangeInfo& LRI, vector RCL) const; + LiveRangeInfo& LRI, + std::vector RCL) const; void suggestReg4RetValue(const MachineInstr *const RetMI, - LiveRangeInfo& LRI ) const; + LiveRangeInfo& LRI) const; void colorMethodArgs(const Method *const Meth, LiveRangeInfo& LRI, @@ -493,7 +495,7 @@ class UltraSparcRegInfo : public MachineRegInfo // given the unified register number, this gives the name // for generating assembly code or debugging. // - inline const string getUnifiedRegName(int reg) const { + inline const std::string getUnifiedRegName(int reg) const { if( reg < 32 ) return SparcIntRegOrder::getRegName(reg); else if ( reg < (64 + 32) ) @@ -513,7 +515,7 @@ class UltraSparcRegInfo : public MachineRegInfo // The fllowing methods are used by instruction selection // - inline unsigned int getRegNumInCallersWindow(int reg) { + inline unsigned getRegNumInCallersWindow(int reg) { if (reg == InvalidRegNum || reg >= 32) return reg; return SparcIntRegOrder::getRegNumInCallersWindow(reg); @@ -1433,7 +1435,7 @@ public: // module. The specified module must have been compiled before this may be // used. // - virtual void emitAssembly(const Module *M, ostream &OutStr) const; + virtual void emitAssembly(const Module *M, std::ostream &OutStr) const; }; diff --git a/lib/Target/SparcV9/SparcV9RegClassInfo.cpp b/lib/Target/SparcV9/SparcV9RegClassInfo.cpp index 6b39d61f5e1..709a8f4c7fe 100644 --- a/lib/Target/SparcV9/SparcV9RegClassInfo.cpp +++ b/lib/Target/SparcV9/SparcV9RegClassInfo.cpp @@ -1,7 +1,8 @@ -#include "llvm/CodeGen/IGNode.h" #include "SparcInternals.h" - +#include "llvm/CodeGen/IGNode.h" #include "llvm/Target/Sparc.h" +#include +using std::cerr; //----------------------------------------------------------------------------- // Int Register Class - method for coloring a node in the interference graph. @@ -37,7 +38,7 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const } if( DEBUG_RA ) { - cout << "\nColoring LR [CallInt=" << LR->isCallInterference() <<"]:"; + cerr << "\nColoring LR [CallInt=" << LR->isCallInterference() <<"]:"; LR->printSet(); } @@ -53,18 +54,18 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const // there are no call interferences. Otherwise, it will get spilled. if (DEBUG_RA) - cout << "\n -Coloring with sug color: " << SugCol; + cerr << "\n -Coloring with sug color: " << SugCol; LR->setColor( LR->getSuggestedColor() ); return; } else if(DEBUG_RA) - cout << "\n Couldn't alloc Sug col - LR voloatile & calls interf"; + cerr << "\n Couldn't alloc Sug col - LR voloatile & calls interf"; } else if ( DEBUG_RA ) { // can't allocate the suggested col cerr << " \n Could NOT allocate the suggested color (already used) "; - LR->printSet(); cerr << endl; + LR->printSet(); cerr << "\n"; } } @@ -91,7 +92,7 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const if( ColorFound) { LR->setColor(c); // first color found in preffered order - if (DEBUG_RA) cout << "\n Colored after first search with col " << c ; + if (DEBUG_RA) cerr << "\n Colored after first search with col " << c ; } // if color is not found because of call interference @@ -113,7 +114,7 @@ void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const // since LR span across calls, must save across calls // LR->markForSaveAcrossCalls(); - if(DEBUG_RA) cout << "\n Colored after SECOND search with col " << c ; + if(DEBUG_RA) cerr << "\n Colored after SECOND search with col " << c ; } } @@ -193,7 +194,7 @@ void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const } else if (DEBUG_RA) { // can't allocate the suggested col cerr << " Could NOT allocate the suggested color for LR "; - LR->printSet(); cerr << endl; + LR->printSet(); cerr << "\n"; } } diff --git a/lib/Target/SparcV9/SparcV9RegClassInfo.h b/lib/Target/SparcV9/SparcV9RegClassInfo.h index 0a5f5169d16..9127ffdaf63 100644 --- a/lib/Target/SparcV9/SparcV9RegClassInfo.h +++ b/lib/Target/SparcV9/SparcV9RegClassInfo.h @@ -17,7 +17,7 @@ // Int register names in same order as enum in class SparcIntRegOrder -static string const IntRegNames[] = +static const std::string IntRegNames[] = { "o0", "o1", "o2", "o3", "o4", "o5", "o7", "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", @@ -75,7 +75,7 @@ class SparcIntRegOrder{ static unsigned int const NumOfAllRegs = o6 + 1; - static const string getRegName(const unsigned reg) { + static const std::string getRegName(const unsigned reg) { assert( reg < NumOfAllRegs ); return IntRegNames[reg]; } @@ -119,7 +119,7 @@ class SparcIntRegClass : public MachineRegClassInfo // Float Register Class //----------------------------------------------------------------------------- -static string const FloatRegNames[] = +static const std::string FloatRegNames[] = { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", @@ -157,7 +157,7 @@ class SparcFloatRegOrder{ static unsigned int const StartOfAllRegs = f0; - static const string getRegName(const unsigned reg) { + static const std::string getRegName(const unsigned reg) { assert( reg < NumOfAllRegs ); return FloatRegNames[reg]; } @@ -203,7 +203,7 @@ class SparcFloatRegClass : public MachineRegClassInfo //----------------------------------------------------------------------------- -static string const IntCCRegNames[] = +static const std::string IntCCRegNames[] = { "xcc", "ccr" }; @@ -218,7 +218,7 @@ class SparcIntCCRegOrder{ xcc, ccr // only one is available - see the note above }; - static const string getRegName(const unsigned reg) { + static const std::string getRegName(const unsigned reg) { assert( reg < 2 ); return IntCCRegNames[reg]; } @@ -253,7 +253,7 @@ public: //----------------------------------------------------------------------------- -static string const FloatCCRegNames[] = +static const std::string FloatCCRegNames[] = { "fcc0", "fcc1", "fcc2", "fcc3" }; @@ -268,7 +268,7 @@ class SparcFloatCCRegOrder{ fcc0, fcc1, fcc2, fcc3 }; - static const string getRegName(const unsigned reg) { + static const std::string getRegName(const unsigned reg) { assert( reg < 4 ); return FloatCCRegNames[reg]; } diff --git a/lib/Target/SparcV9/SparcV9RegInfo.cpp b/lib/Target/SparcV9/SparcV9RegInfo.cpp index 65433979572..dcfc5fa378c 100644 --- a/lib/Target/SparcV9/SparcV9RegInfo.cpp +++ b/lib/Target/SparcV9/SparcV9RegInfo.cpp @@ -8,6 +8,8 @@ #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" #include "llvm/CodeGen/PhyRegAlloc.h" #include "llvm/DerivedTypes.h" +#include +using std::cerr; //--------------------------------------------------------------------------- // Purpose: @@ -21,11 +23,10 @@ //--------------------------------------------------------------------------- const Value * UltraSparcRegInfo::getCallInstRetVal(const MachineInstr *CallMI) const { - unsigned OpCode = CallMI->getOpCode(); - unsigned NumOfImpRefs = CallMI->getNumImplicitRefs(); + unsigned NumOfImpRefs = CallMI->getNumImplicitRefs(); - if( OpCode == CALL ) { + if (OpCode == CALL) { // The one before the last implicit operand is the return value of // a CALL instr @@ -34,14 +35,13 @@ UltraSparcRegInfo::getCallInstRetVal(const MachineInstr *CallMI) const { if( CallMI->implicitRefIsDefined(NumOfImpRefs-2) ) return CallMI->getImplicitRef(NumOfImpRefs-2); - } - else if( OpCode == JMPLCALL) { + } else if (OpCode == JMPLCALL) { // The last implicit operand is the return value of a JMPL // - if( NumOfImpRefs > 0 ) - if( CallMI->implicitRefIsDefined(NumOfImpRefs-1) ) - return CallMI->getImplicitRef(NumOfImpRefs-1); + if(NumOfImpRefs > 0) + if (CallMI->implicitRefIsDefined(NumOfImpRefs-1)) + return CallMI->getImplicitRef(NumOfImpRefs-1); } else assert(0 && "OpCode must be CALL/JMPL for a call instr"); @@ -189,7 +189,7 @@ void UltraSparcRegInfo::suggestReg4RetAddr(const MachineInstr * RetMI, //--------------------------------------------------------------------------- void UltraSparcRegInfo::suggestReg4CallAddr(const MachineInstr * CallMI, LiveRangeInfo& LRI, - vector RCList) const { + std::vector RCList) const { const Value *RetAddrVal = getCallInstRetAddr( CallMI ); @@ -361,10 +361,8 @@ void UltraSparcRegInfo::colorMethodArgs(const Method *const Meth, // that on to the stack pos of LR if( isArgInReg ) { - - MachineInstr *AdIBef = - cpReg2MemMI(UniArgReg, getFramePointer(), - LR->getSpillOffFromFP(), RegType ); + cpReg2MemMI(UniArgReg, getFramePointer(), + LR->getSpillOffFromFP(), RegType ); FirstAI->InstrnsBefore.push_back( AdMI ); } @@ -404,7 +402,7 @@ void UltraSparcRegInfo::colorMethodArgs(const Method *const Meth, //--------------------------------------------------------------------------- void UltraSparcRegInfo::suggestRegs4CallArgs(const MachineInstr *const CallMI, LiveRangeInfo& LRI, - vector RCList) const { + std::vector RCList) const { assert ( (UltraSparcInfo->getInstrInfo()).isCall(CallMI->getOpCode()) ); @@ -469,7 +467,7 @@ void UltraSparcRegInfo::suggestRegs4CallArgs(const MachineInstr *const CallMI, if( !LR ) { if( DEBUG_RA) { cerr << " ERROR: In call instr, no LR for arg: " ; - printValue(CallArg); cerr << endl; + printValue(CallArg); cerr << "\n"; } assert(0 && "NO LR for call arg"); // continue; @@ -485,7 +483,7 @@ void UltraSparcRegInfo::suggestRegs4CallArgs(const MachineInstr *const CallMI, else if (DEBUG_RA) // Do NOTHING as this will be colored as a normal value. - cerr << " Regr not suggested for int call arg" << endl; + cerr << " Regr not suggested for int call arg\n"; } else if( RegType == FPSingleRegType && (argNo*2 +1)< NumOfFloatArgRegs) @@ -535,7 +533,7 @@ void UltraSparcRegInfo::colorCallArgs(const MachineInstr *const CallMI, if( !RetValLR ) { cerr << "\nNo LR for:"; printValue( RetVal ); - cerr << endl; + cerr << "\n"; assert( RetValLR && "ERR:No LR for non-void return value"); //return; } @@ -601,7 +599,7 @@ void UltraSparcRegInfo::colorCallArgs(const MachineInstr *const CallMI, // Now color all args of the call instruction //------------------------------------------- - vector AddedInstrnsBefore; + std::vector AddedInstrnsBefore; unsigned NumOfCallArgs = getCallInstNumArgs( CallMI ); @@ -662,7 +660,7 @@ void UltraSparcRegInfo::colorCallArgs(const MachineInstr *const CallMI, if( !LR ) { if( DEBUG_RA) { cerr << " ERROR: In call instr, no LR for arg: " ; - printValue(CallArg); cerr << endl; + printValue(CallArg); cerr << "\n"; } assert(0 && "NO LR for call arg"); // continue; @@ -812,7 +810,7 @@ void UltraSparcRegInfo::colorCallArgs(const MachineInstr *const CallMI, cerr << *(AddedInstrnsBefore[i]); } - vector TmpVec; + std::vector TmpVec; OrderAddedInstrns(AddedInstrnsBefore, TmpVec, PRA); if( DEBUG_RA ) { @@ -855,13 +853,12 @@ void UltraSparcRegInfo::suggestReg4RetValue(const MachineInstr *const RetMI, // The first implicit operand is the return value of a return instr const Value *RetVal = RetMI->getImplicitRef(0); - MachineInstr *AdMI; LiveRange *const LR = LRI.getLiveRangeForValue( RetVal ); if( !LR ) { cerr << "\nNo LR for:"; printValue( RetVal ); - cerr << endl; + cerr << "\n"; assert( LR && "No LR for return value of non-void method"); //return; } @@ -898,13 +895,12 @@ void UltraSparcRegInfo::colorRetValue(const MachineInstr *const RetMI, // The first implicit operand is the return value of a return instr const Value *RetVal = RetMI->getImplicitRef(0); - MachineInstr *AdMI; LiveRange *const LR = LRI.getLiveRangeForValue( RetVal ); if( ! LR ) { cerr << "\nNo LR for:"; printValue( RetVal ); - cerr << endl; + cerr << "\n"; // assert( LR && "No LR for return value of non-void method"); return; } @@ -941,16 +937,14 @@ void UltraSparcRegInfo::colorRetValue(const MachineInstr *const RetMI, // the LR received UniLRReg but must be colored with UniRetReg // to pass as the return value - - AdMI = cpReg2RegMI( UniLRReg, UniRetReg, RegType); - RetAI->InstrnsBefore.push_back( AdMI ); + RetAI->InstrnsBefore.push_back(cpReg2RegMI(UniLRReg, UniRetReg, RegType)); } else { // if the LR is spilled - - AdMI = cpMem2RegMI(getFramePointer(), LR->getSpillOffFromFP(), - UniRetReg, RegType); - RetAI->InstrnsBefore.push_back( AdMI ); - cout << "\nCopied the return value from stack"; + MachineInstr *AdMI = cpMem2RegMI(getFramePointer(), + LR->getSpillOffFromFP(), + UniRetReg, RegType); + RetAI->InstrnsBefore.push_back(AdMI); + cerr << "\nCopied the return value from stack\n"; } } // if there is a return value @@ -1179,9 +1173,7 @@ void UltraSparcRegInfo::insertCallerSavingCode(const MachineInstr *MInst, // has set to record which registers were saved/restored // - hash_set PushedRegSet; - - + std::hash_set PushedRegSet; // Now find the LR of the return value of the call // The last *implicit operand* is the return value of a call @@ -1394,7 +1386,7 @@ void UltraSparcRegInfo::printReg(const LiveRange *const LR) { cerr << " *Node " << (LR->getUserIGNode())->getIndex(); if( ! LR->hasColor() ) { - cerr << " - could not find a color" << endl; + cerr << " - could not find a color\n"; return; } @@ -1403,15 +1395,13 @@ void UltraSparcRegInfo::printReg(const LiveRange *const LR) { cerr << " colored with color "<< LR->getColor(); if( RegClassID == IntRegClassID ) { + cerr<< " [" << SparcIntRegOrder::getRegName(LR->getColor()) << "]\n"; - cerr<< " [" << SparcIntRegOrder::getRegName(LR->getColor()) ; - cerr << "]" << endl; - } - else if ( RegClassID == FloatRegClassID) { + } else if ( RegClassID == FloatRegClassID) { cerr << "[" << SparcFloatRegOrder::getRegName(LR->getColor()); if( LR->getTypeID() == Type::DoubleTyID ) cerr << "+" << SparcFloatRegOrder::getRegName(LR->getColor()+1); - cerr << "]" << endl; + cerr << "]\n"; } } @@ -1436,9 +1426,9 @@ void UltraSparcRegInfo::printReg(const LiveRange *const LR) { //--------------------------------------------------------------------------- -void UltraSparcRegInfo::OrderAddedInstrns( vector &UnordVec, - vector &OrdVec, - PhyRegAlloc &PRA) const{ +void UltraSparcRegInfo::OrderAddedInstrns(std::vector &UnordVec, + std::vector &OrdVec, + PhyRegAlloc &PRA) const{ /* Problem: We can have instructions inserted by RegAlloc like @@ -1476,7 +1466,7 @@ void UltraSparcRegInfo::OrderAddedInstrns( vector &UnordVec, CouldMoveAll = true; - vector::iterator DefIt = UnordVec.begin(); + std::vector::iterator DefIt = UnordVec.begin(); for( ; DefIt != UnordVec.end(); ++DefIt ) { @@ -1498,7 +1488,7 @@ void UltraSparcRegInfo::OrderAddedInstrns( vector &UnordVec, bool DefEqUse = false; - vector::iterator UseIt = DefIt; + std::vector::iterator UseIt = DefIt; UseIt++; for( ; UseIt != UnordVec.end(); ++UseIt ) { @@ -1572,7 +1562,7 @@ void UltraSparcRegInfo::OrderAddedInstrns( vector &UnordVec, -void UltraSparcRegInfo::moveInst2OrdVec(vector &OrdVec, +void UltraSparcRegInfo::moveInst2OrdVec(std::vector &OrdVec, MachineInstr *UnordInst, PhyRegAlloc &PRA ) const { @@ -1585,7 +1575,7 @@ void UltraSparcRegInfo::moveInst2OrdVec(vector &OrdVec, // before in the OrdVec bool DefEqUse = false; - vector::iterator OrdIt = OrdVec.begin(); + std::vector::iterator OrdIt = OrdVec.begin(); for( ; OrdIt != OrdVec.end(); ++OrdIt ) { diff --git a/lib/Target/SparcV9/SparcV9TargetMachine.cpp b/lib/Target/SparcV9/SparcV9TargetMachine.cpp index 9524e805159..dd9e3304746 100644 --- a/lib/Target/SparcV9/SparcV9TargetMachine.cpp +++ b/lib/Target/SparcV9/SparcV9TargetMachine.cpp @@ -17,7 +17,8 @@ #include "llvm/CodeGen/PhyRegAlloc.h" #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" #include "llvm/Method.h" - +#include +using std::cerr; // Build the MachineInstruction Description Array... const MachineInstrDescriptor SparcMachineInstrDesc[] = { @@ -47,10 +48,9 @@ void AllocateRegisters(Method *M, TargetMachine &target) if ( (M)->isExternal() ) // don't process prototypes return; - if( DEBUG_RA ) { - cerr << endl << "******************** Method "<< (M)->getName(); - cerr << " ********************" <getName() + << " ********************\n"; MethodLiveVarInfo LVI(M ); // Analyze live varaibles LVI.analyze(); @@ -60,7 +60,7 @@ void AllocateRegisters(Method *M, TargetMachine &target) PRA.allocateRegisters(); - if( DEBUG_RA ) cerr << endl << "Register allocation complete!" << endl; + if( DEBUG_RA ) cerr << "\nRegister allocation complete!\n"; } diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index b290f29b856..0df60fde679 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -40,7 +40,7 @@ StructLayout::StructLayout(const StructType *ST, const TargetData &TD) StructSize = (StructSize/TyAlign + 1) * TyAlign; // Add padding... // Keep track of maximum alignment constraint - StructAlignment = max(TyAlign, StructAlignment); + StructAlignment = std::max(TyAlign, StructAlignment); MemberOffsets.push_back(StructSize); StructSize += TySize; // Consume space for this data item... @@ -71,7 +71,7 @@ Annotation *TargetData::TypeAnFactory(AnnotationID AID, const Annotable *T, // TargetData Class Implementation //===----------------------------------------------------------------------===// -TargetData::TargetData(const string &TargetName, unsigned char PtrSize = 8, +TargetData::TargetData(const std::string &TargetName, unsigned char PtrSize = 8, unsigned char PtrAl = 8, unsigned char DoubleAl = 8, unsigned char FloatAl = 4, unsigned char LongAl = 8, unsigned char IntAl = 4, unsigned char ShortAl = 2, @@ -146,7 +146,7 @@ unsigned char TargetData::getTypeAlignment(const Type *Ty) const { } unsigned TargetData::getIndexedOffset(const Type *ptrTy, - const vector &Idx) const { + const std::vector &Idx) const { const PointerType *PtrTy = cast(ptrTy); unsigned Result = 0; diff --git a/lib/Target/TargetSchedInfo.cpp b/lib/Target/TargetSchedInfo.cpp index f9dca290b06..c02654f03b6 100644 --- a/lib/Target/TargetSchedInfo.cpp +++ b/lib/Target/TargetSchedInfo.cpp @@ -21,8 +21,8 @@ resourceId_t MachineResource::nextId = 0; // (stl_algo.h). // inline static bool -RUConflict(const vector& fromRVec, - const vector& toRVec) +RUConflict(const std::vector& fromRVec, + const std::vector& toRVec) { unsigned fN = fromRVec.size(), tN = toRVec.size(); @@ -57,7 +57,7 @@ ComputeMinGap(const InstrRUsage &fromRU, { // check if instr. #2 can start executing `gap' cycles after #1 // by checking for resource conflicts in each overlapping cycle - cycles_t numOverlap = min(fromRU.numCycles - gap, toRU.numCycles); + cycles_t numOverlap =std::min(fromRU.numCycles - gap, toRU.numCycles); for (cycles_t c = 0; c <= numOverlap-1; c++) if (RUConflict(fromRU.resourcesByCycle[gap + c], toRU.resourcesByCycle[c])) @@ -102,7 +102,7 @@ MachineSchedInfo::initializeResources() // most instructions will probably behave the same as their class. // Cannot allocate a vector of InstrRUsage so new each one. // - vector instrRUForClasses; + std::vector instrRUForClasses; instrRUForClasses.resize(numSchedClasses); for (InstrSchedClass sc = 0; sc < numSchedClasses; sc++) { // instrRUForClasses.push_back(new InstrRUsage); @@ -116,7 +116,7 @@ MachineSchedInfo::initializeResources() void -MachineSchedInfo::computeInstrResources(const vector& +MachineSchedInfo::computeInstrResources(const std::vector& instrRUForClasses) { int numOpCodes = mii->getNumRealOpCodes(); @@ -146,7 +146,7 @@ MachineSchedInfo::computeInstrResources(const vector& void -MachineSchedInfo::computeIssueGaps(const vector& +MachineSchedInfo::computeIssueGaps(const std::vector& instrRUForClasses) { int numOpCodes = mii->getNumRealOpCodes(); @@ -186,7 +186,7 @@ MachineSchedInfo::computeIssueGaps(const vector& { issueGaps[OpCodePair(fromOp,toOp)] = instrPairGap; conflictLists[fromOp].push_back(toOp); - longestIssueConflict = max(longestIssueConflict, instrPairGap); + longestIssueConflict = std::max(longestIssueConflict, instrPairGap); } } } diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp index 02e14b6caaa..7f33fe280b8 100644 --- a/lib/Transforms/ExprTypeConvert.cpp +++ b/lib/Transforms/ExprTypeConvert.cpp @@ -18,6 +18,8 @@ #include "Support/STLExtras.h" #include #include +#include +using std::cerr; #include "llvm/Assembly/Writer.h" @@ -96,7 +98,8 @@ static bool MallocConvertableToType(MallocInst *MI, const Type *Ty, } static Instruction *ConvertMallocToType(MallocInst *MI, const Type *Ty, - const string &Name, ValueMapCache &VMC){ + const std::string &Name, + ValueMapCache &VMC){ BasicBlock *BB = MI->getParent(); BasicBlock::iterator It = BB->end(); @@ -270,7 +273,7 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty, // index array. If there are, check to see if removing them causes us to // get to the right type... // - vector Indices = GEP->copyIndices(); + std::vector Indices = GEP->copyIndices(); const Type *BaseType = GEP->getPointerOperand()->getType(); const Type *ElTy = 0; @@ -302,7 +305,7 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty, // Check to see if 'N' is an expression that can be converted to // the appropriate size... if so, allow it. // - vector Indices; + std::vector Indices; const Type *ElTy = ConvertableToGEP(PTy, I->getOperand(1), Indices); if (ElTy) { assert(ElTy == PVTy && "Internal error, setup wrong!"); @@ -378,7 +381,7 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) { BasicBlock *BB = I->getParent(); BasicBlock::InstListType &BIL = BB->getInstList(); - string Name = I->getName(); if (!Name.empty()) I->setName(""); + std::string Name = I->getName(); if (!Name.empty()) I->setName(""); Instruction *Res; // Result of conversion ValueHandle IHandle(VMC, I); // Prevent I from being removed! @@ -460,7 +463,7 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) { // index array. If there are, check to see if removing them causes us to // get to the right type... // - vector Indices = GEP->copyIndices(); + std::vector Indices = GEP->copyIndices(); const Type *BaseType = GEP->getPointerOperand()->getType(); const Type *PVTy = cast(Ty)->getElementType(); Res = 0; @@ -491,7 +494,7 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) { // Check to see if 'N' is an expression that can be converted to // the appropriate size... if so, allow it. // - vector Indices; + std::vector Indices; const Type *ElTy = ConvertableToGEP(NewSrcTy, I->getOperand(1), Indices, &It); if (ElTy) { @@ -634,7 +637,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty, case Instruction::Add: if (isa(Ty)) { Value *IndexVal = I->getOperand(V == I->getOperand(0) ? 1 : 0); - vector Indices; + std::vector Indices; if (const Type *ETy = ConvertableToGEP(Ty, IndexVal, Indices)) { const Type *RetTy = PointerType::get(ETy); @@ -685,7 +688,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty, // They could be loading the first element of a composite type... if (const CompositeType *CT = dyn_cast(LoadedTy)) { unsigned Offset = 0; // No offset, get first leaf. - vector Indices; // Discarded... + std::vector Indices; // Discarded... LoadedTy = getStructOffsetType(CT, Offset, Indices, false); assert(Offset == 0 && "Offset changed from zero???"); } @@ -751,7 +754,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty, // Check to see if the second argument is an expression that can // be converted to the appropriate size... if so, allow it. // - vector Indices; + std::vector Indices; const Type *ElTy = ConvertableToGEP(Ty, Index, Indices); delete TempScale; // Free our temporary multiply if we made it @@ -823,7 +826,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal, BasicBlock *BB = I->getParent(); BasicBlock::InstListType &BIL = BB->getInstList(); - string Name = I->getName(); if (!Name.empty()) I->setName(""); + std::string Name = I->getName(); if (!Name.empty()) I->setName(""); Instruction *Res; // Result of conversion //cerr << endl << endl << "Type:\t" << Ty << "\nInst: " << I << "BB Before: " << BB << endl; @@ -844,12 +847,12 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal, case Instruction::Add: if (isa(NewTy)) { Value *IndexVal = I->getOperand(OldVal == I->getOperand(0) ? 1 : 0); - vector Indices; + std::vector Indices; BasicBlock::iterator It = find(BIL.begin(), BIL.end(), I); if (const Type *ETy = ConvertableToGEP(NewTy, IndexVal, Indices, &It)) { // If successful, convert the add to a GEP - const Type *RetTy = PointerType::get(ETy); + //const Type *RetTy = PointerType::get(ETy); // First operand is actually the given pointer... Res = new GetElementPtrInst(NewVal, Indices, Name); assert(cast(Res->getType())->getElementType() == ETy && @@ -892,7 +895,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal, const Type *LoadedTy = cast(NewVal->getType())->getElementType(); - vector Indices; + std::vector Indices; Indices.push_back(ConstantUInt::get(Type::UIntTy, 0)); if (const CompositeType *CT = dyn_cast(LoadedTy)) { @@ -914,7 +917,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal, Res->setOperand(1, ConvertExpressionToType(I->getOperand(1), NewPT, VMC)); } else { // Replace the source pointer const Type *ValTy = cast(NewTy)->getElementType(); - vector Indices; + std::vector Indices; #if 0 Indices.push_back(ConstantUInt::get(Type::UIntTy, 0)); while (ArrayType *AT = dyn_cast(ValTy)) { @@ -948,7 +951,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal, // Perform the conversion now... // - vector Indices; + std::vector Indices; const Type *ElTy = ConvertableToGEP(NewVal->getType(), Index, Indices, &It); assert(ElTy != 0 && "GEP Conversion Failure!"); Res = new GetElementPtrInst(NewVal, Indices, Name); @@ -965,7 +968,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal, // Check to see if the second argument is an expression that can // be converted to the appropriate size... if so, allow it. // - vector Indices; + std::vector Indices; const Type *ElTy = ConvertableToGEP(NewVal->getType(), I->getOperand(1), Indices, &It); assert(ElTy != 0 && "GEP Conversion Failure!"); @@ -1001,9 +1004,10 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal, case Instruction::Call: { Value *Meth = I->getOperand(0); - vector Params(I->op_begin()+1, I->op_end()); + std::vector Params(I->op_begin()+1, I->op_end()); - vector::iterator OI = find(Params.begin(), Params.end(), OldVal); + std::vector::iterator OI = + find(Params.begin(), Params.end(), OldVal); assert (OI != Params.end() && "Not using value!"); *OI = NewVal; diff --git a/lib/Transforms/HoistPHIConstants.cpp b/lib/Transforms/HoistPHIConstants.cpp index e28e8a2fe4b..43ed725d945 100644 --- a/lib/Transforms/HoistPHIConstants.cpp +++ b/lib/Transforms/HoistPHIConstants.cpp @@ -14,8 +14,8 @@ #include #include -typedef pair BBConstTy; -typedef map CachedCopyMap; +typedef std::pair BBConstTy; +typedef std::map CachedCopyMap; static Value *NormalizePhiOperand(PHINode *PN, Value *CPV, BasicBlock *Pred, CachedCopyMap &CopyCache) { @@ -33,7 +33,7 @@ static Value *NormalizePhiOperand(PHINode *PN, Value *CPV, // Create a copy instruction and add it to the cache... CastInst *Inst = new CastInst(CPV, CPV->getType()); - CopyCache.insert(make_pair(BBConstTy(Pred, CPV), Inst)); + CopyCache.insert(std::make_pair(BBConstTy(Pred, CPV), Inst)); // Insert the copy just before the terminator inst of the predecessor BB assert(Pred->getTerminator() && "Degenerate BB encountered!"); @@ -52,7 +52,7 @@ bool HoistPHIConstants::doHoistPHIConstants(Method *M) { bool Changed = false; for (Method::iterator BI = M->begin(), BE = M->end(); BI != BE; ++BI) { - vector phis; // normalizing invalidates BB iterator + std::vector phis; // normalizing invalidates BB iterator for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II) { if (PHINode *PN = dyn_cast(*II)) @@ -61,7 +61,7 @@ bool HoistPHIConstants::doHoistPHIConstants(Method *M) { break; // All PHIs occur at top of BB! } - for (vector::iterator PI=phis.begin(); PI != phis.end(); ++PI) + for (std::vector::iterator PI=phis.begin(); PI != phis.end();++PI) for (unsigned i = 0; i < (*PI)->getNumIncomingValues(); ++i) { Value *Op = (*PI)->getIncomingValue(i); diff --git a/lib/Transforms/IPO/ConstantMerge.cpp b/lib/Transforms/IPO/ConstantMerge.cpp index 70e3437bb9e..ff2442d2b65 100644 --- a/lib/Transforms/IPO/ConstantMerge.cpp +++ b/lib/Transforms/IPO/ConstantMerge.cpp @@ -23,7 +23,7 @@ // static inline bool mergeDuplicateConstants(Module *M, unsigned &ConstantNo, - map &CMap) { + std::map &CMap) { Module::GlobalListType &GList = M->getGlobalList(); if (GList.size() <= ConstantNo) return false; // No new constants bool MadeChanges = false; @@ -35,10 +35,10 @@ bool mergeDuplicateConstants(Module *M, unsigned &ConstantNo, Constant *Init = GV->getInitializer(); // Check to see if the initializer is already known... - map::iterator I = CMap.find(Init); + std::map::iterator I = CMap.find(Init); if (I == CMap.end()) { // Nope, add it to the map - CMap.insert(make_pair(Init, GV)); + CMap.insert(std::make_pair(Init, GV)); } else { // Yup, this is a duplicate! // Make all uses of the duplicate constant use the cannonical version... GV->replaceAllUsesWith(I->second); @@ -59,7 +59,7 @@ bool mergeDuplicateConstants(Module *M, unsigned &ConstantNo, // deal with passes. // bool ConstantMerge::mergeDuplicateConstants(Module *M) { - map Constants; + std::map Constants; unsigned LastConstantSeen = 0; return ::mergeDuplicateConstants(M, LastConstantSeen, Constants); } diff --git a/lib/Transforms/IPO/DeadTypeElimination.cpp b/lib/Transforms/IPO/DeadTypeElimination.cpp index ec4c3fd66e6..d5e9ea07bdf 100644 --- a/lib/Transforms/IPO/DeadTypeElimination.cpp +++ b/lib/Transforms/IPO/DeadTypeElimination.cpp @@ -23,6 +23,10 @@ #include "llvm/iTerminators.h" #include "llvm/iOther.h" #include +#include +using std::vector; +using std::string; +using std::cerr; static const Type *PtrSByte = 0; // 'sbyte*' type @@ -78,7 +82,7 @@ bool CleanupGCCOutput::PatchUpMethodReferences(Module *M) { SymbolTable *ST = M->getSymbolTable(); if (!ST) return false; - map > Methods; + std::map > Methods; // Loop over the entries in the symbol table. If an entry is a method pointer, // then add it to the Methods map. We do a two pass algorithm here to avoid @@ -86,7 +90,7 @@ bool CleanupGCCOutput::PatchUpMethodReferences(Module *M) { // for (SymbolTable::iterator I = ST->begin(), E = ST->end(); I != E; ++I) if (const PointerType *PT = dyn_cast(I->first)) - if (const MethodType *MT = dyn_cast(PT->getElementType())) { + if (isa(PT->getElementType())) { SymbolTable::VarMap &Plane = I->second; for (SymbolTable::type_iterator PI = Plane.begin(), PE = Plane.end(); PI != PE; ++PI) { @@ -101,7 +105,7 @@ bool CleanupGCCOutput::PatchUpMethodReferences(Module *M) { // Now we have a list of all methods with a particular name. If there is more // than one entry in a list, merge the methods together. // - for (map >::iterator I = Methods.begin(), + for (std::map >::iterator I = Methods.begin(), E = Methods.end(); I != E; ++I) { vector &Methods = I->second; Method *Implementation = 0; // Find the implementation @@ -145,7 +149,7 @@ bool CleanupGCCOutput::PatchUpMethodReferences(Module *M) { cerr << "Warning: Found methods types that are not compatible:\n"; for (unsigned i = 0; i < Methods.size(); ++i) { cerr << "\t" << Methods[i]->getType()->getDescription() << " %" - << Methods[i]->getName() << endl; + << Methods[i]->getName() << "\n"; } cerr << " No linkage of methods named '" << Methods[0]->getName() << "' performed!\n"; @@ -185,7 +189,7 @@ bool CleanupGCCOutput::PatchUpMethodReferences(Module *M) { ++i; } } else { - cerr << "Cannot convert use of method: " << U << endl; + cerr << "Cannot convert use of method: " << U << "\n"; ++i; } } @@ -201,7 +205,7 @@ bool CleanupGCCOutput::PatchUpMethodReferences(Module *M) { // ShouldNukSymtabEntry - Return true if this module level symbol table entry // should be eliminated. // -static inline bool ShouldNukeSymtabEntry(const pair &E) { +static inline bool ShouldNukeSymtabEntry(const std::pair &E) { // Nuke all names for primitive types! if (cast(E.second)->isPrimitiveType()) return true; @@ -357,8 +361,8 @@ static inline bool FixCastsAndPHIs(BasicBlock *BB) { Value *Src = CI->getOperand(0); // Move the cast instruction to the current insert position... - --InsertPos; // New position for cast to go... - swap(*InsertPos, *I); // Cast goes down, PHI goes up + --InsertPos; // New position for cast to go... + std::swap(*InsertPos, *I); // Cast goes down, PHI goes up if (isa(Src) && // Handle case #1 cast(Src)->getParent() == BB) { @@ -561,7 +565,7 @@ bool CleanupGCCOutput::doPassFinalization(Module *M) { if (M->hasSymbolTable()) { SymbolTable *ST = M->getSymbolTable(); - const set &UsedTypes = FUT.getTypes(); + const std::set &UsedTypes = FUT.getTypes(); // Check the symbol table for superfluous type entries that aren't used in // the program diff --git a/lib/Transforms/IPO/GlobalDCE.cpp b/lib/Transforms/IPO/GlobalDCE.cpp index 7395bab8030..dacd3295ef9 100644 --- a/lib/Transforms/IPO/GlobalDCE.cpp +++ b/lib/Transforms/IPO/GlobalDCE.cpp @@ -18,14 +18,14 @@ static bool RemoveUnreachableMethods(Module *M, cfg::CallGraph *CG) { // Calculate which methods are reachable from the external methods in the call // graph. // - set ReachableNodes(df_begin(&CallGraph), - df_end(&CallGraph)); + std::set ReachableNodes(df_begin(&CallGraph), + df_end(&CallGraph)); // Loop over the methods in the module twice. The first time is used to drop // references that methods have to each other before they are deleted. The // second pass removes the methods that need to be removed. // - vector MethodsToDelete; // Track unused methods + std::vector MethodsToDelete; // Track unused methods for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { cfg::CallGraphNode *N = CallGraph[*I]; if (!ReachableNodes.count(N)) { // Not reachable?? @@ -45,7 +45,7 @@ static bool RemoveUnreachableMethods(Module *M, cfg::CallGraph *CG) { // Unreachables methods have been found and should have no references to them, // delete them now. // - for (vector::iterator I = MethodsToDelete.begin(), + for (std::vector::iterator I = MethodsToDelete.begin(), E = MethodsToDelete.end(); I != E; ++I) delete CallGraph.removeMethodFromModule(*I); diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp index 40b98bd67de..9d86c868953 100644 --- a/lib/Transforms/IPO/InlineSimple.cpp +++ b/lib/Transforms/IPO/InlineSimple.cpp @@ -27,6 +27,8 @@ #include "llvm/iOther.h" #include #include +#include +using std::cerr; #include "llvm/Assembly/Writer.h" @@ -36,7 +38,7 @@ using namespace opt; // current values into those specified by ValueMap. // static inline void RemapInstruction(Instruction *I, - map &ValueMap) { + std::map &ValueMap) { for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) { const Value *Op = I->getOperand(op); @@ -45,8 +47,8 @@ static inline void RemapInstruction(Instruction *I, continue; // Globals and constants don't get relocated if (!V) { - cerr << "Val = " << endl << Op << "Addr = " << (void*)Op << endl; - cerr << "Inst = " << I; + cerr << "Val = \n" << Op << "Addr = " << (void*)Op; + cerr << "\nInst = " << I; } assert(V && "Referenced value not in value map!"); I->setOperand(op, V); @@ -72,10 +74,9 @@ bool opt::InlineMethod(BasicBlock::iterator CIIt) { const Method *CalledMeth = CI->getCalledMethod(); if (CalledMeth == 0 || // Can't inline external method or indirect call! CalledMeth->isExternal()) return false; - Method *CurrentMeth = CI->getParent()->getParent(); //cerr << "Inlining " << CalledMeth->getName() << " into " - // << CurrentMeth->getName() << endl; + // << CurrentMeth->getName() << "\n"; BasicBlock *OrigBB = CI->getParent(); @@ -111,7 +112,7 @@ bool opt::InlineMethod(BasicBlock::iterator CIIt) { // code's values. This includes all of: Method arguments, instruction values, // constant pool entries, and basic blocks. // - map ValueMap; + std::map ValueMap; // Add the method arguments to the mapping: (start counting at 1 to skip the // method reference itself) diff --git a/lib/Transforms/IPO/MutateStructTypes.cpp b/lib/Transforms/IPO/MutateStructTypes.cpp index c91c00c6477..df2b67ef41a 100644 --- a/lib/Transforms/IPO/MutateStructTypes.cpp +++ b/lib/Transforms/IPO/MutateStructTypes.cpp @@ -21,6 +21,9 @@ #include "llvm/iTerminators.h" #include "llvm/iOther.h" #include +using std::map; +using std::make_pair; +using std::vector; // To enable debugging, uncomment this... //#define DEBUG_MST(x) x @@ -37,7 +40,7 @@ struct ValuePlaceHolder : public Instruction { ValuePlaceHolder(const Type *Ty) : Instruction(Ty, UserOp1, "") {} - virtual Instruction *clone() const { abort(); } + virtual Instruction *clone() const { abort(); return 0; } virtual const char *getOpcodeName() const { return "placeholder"; } }; @@ -291,8 +294,8 @@ bool MutateStructTypes::doPassInitialization(Module *M) { // of the methods and global variables that we no longer need. bool MutateStructTypes::doPassFinalization(Module *M) { // The first half of the methods in the module have to go. - unsigned NumMethods = M->size(); - unsigned NumGVars = M->gsize(); + //unsigned NumMethods = M->size(); + //unsigned NumGVars = M->gsize(); // Prepare for deletion of globals by dropping their interdependencies... for(Module::iterator I = M->begin(); I != M->end(); ++I) { @@ -436,12 +439,11 @@ bool MutateStructTypes::doPerMethodWork(Method *m) { AdjustIndices(cast(PTy), Indices); } - if (const LoadInst *LI = dyn_cast(I)) { + if (isa(I)) { NewI = new LoadInst(NewPtr, Indices); - } else if (const StoreInst *SI = dyn_cast(I)) { + } else if (isa(I)) { NewI = new StoreInst(ConvertValue(I->getOperand(0)), NewPtr, Indices); - } else if (const GetElementPtrInst *GEP = - dyn_cast(I)) { + } else if (isa(I)) { NewI = new GetElementPtrInst(NewPtr, Indices); } else { assert(0 && "Unknown memory access inst!!!"); diff --git a/lib/Transforms/IPO/SimpleStructMutation.cpp b/lib/Transforms/IPO/SimpleStructMutation.cpp index d9385453e88..d0b8bb2807c 100644 --- a/lib/Transforms/IPO/SimpleStructMutation.cpp +++ b/lib/Transforms/IPO/SimpleStructMutation.cpp @@ -12,9 +12,14 @@ #include "llvm/Analysis/FindUnsafePointerTypes.h" #include "TransformInternals.h" #include +#include +using std::vector; +using std::set; +using std::pair; #include "llvm/Assembly/Writer.h" + // PruneTypes - Given a type Ty, make sure that neither it, or one of its // subtypes, occur in TypesToModify. // @@ -26,7 +31,7 @@ static void PruneTypes(const Type *Ty, set &TypesToModify, // If the element is in TypesToModify, remove it now... if (const StructType *ST = dyn_cast(Ty)) { TypesToModify.erase(ST); // This doesn't fail if the element isn't present - cerr << "Unable to swap type: " << ST << endl; + std::cerr << "Unable to swap type: " << ST << "\n"; } // Remove all types that this type contains as well... do not remove types @@ -69,7 +74,8 @@ static inline void GetTransformation(const StructType *ST, // Build mapping from index to size for (unsigned i = 0; i < NumElements; ++i) - ElList.push_back(make_pair(i, TD.getTypeSize(ST->getElementTypes()[i]))); + ElList.push_back( + std::make_pair(i, TD.getTypeSize(ST->getElementTypes()[i]))); sort(ElList.begin(), ElList.end(), ptr_fun(FirstLess)); @@ -118,14 +124,14 @@ PrebuiltStructMutation::TransformsType set ProcessedTypes; for (set::const_iterator I = UnsafePTys.begin(), E = UnsafePTys.end(); I != E; ++I) { - //cerr << "Pruning type: " << *I << endl; + //cerr << "Pruning type: " << *I << "\n"; PruneTypes(*I, TypesToModify, ProcessedTypes); } // Build up a set of structure types that we are going to modify, and // information describing how to modify them. - map > Transforms; + std::map > Transforms; for (set::iterator I = TypesToModify.begin(), E = TypesToModify.end(); I != E; ++I) { diff --git a/lib/Transforms/Instrumentation/TraceValues.cpp b/lib/Transforms/Instrumentation/TraceValues.cpp index 7948266c25c..00acac8d1f7 100644 --- a/lib/Transforms/Instrumentation/TraceValues.cpp +++ b/lib/Transforms/Instrumentation/TraceValues.cpp @@ -18,7 +18,8 @@ #include "llvm/Assembly/Writer.h" #include "Support/StringExtras.h" #include - +using std::vector; +using std::string; // Add a prototype for printf if it is not already in the program. // @@ -110,8 +111,6 @@ static void InsertPrintInst(Value *V, BasicBlock *BB, BasicBlock::iterator &BBI, // Escape Message by replacing all % characters with %% chars. unsigned Offset = 0; while ((Offset = Message.find('%', Offset)) != string::npos) { - string::iterator Offs = Message.begin()+Offset; - //Message.replace(Offs, Offs+1, "%%"); Message.replace(Offset, 2, "%%"); Offset += 2; // Skip over the new %'s } @@ -140,7 +139,7 @@ static void InsertPrintInst(Value *V, BasicBlock *BB, BasicBlock::iterator &BBI, static void InsertVerbosePrintInst(Value *V, BasicBlock *BB, BasicBlock::iterator &BBI, const string &Message, Method *Printf) { - ostringstream OutStr; + std::ostringstream OutStr; if (V) WriteAsOperand(OutStr, V); InsertPrintInst(V, BB, BBI, Message+OutStr.str()+" = ", Printf); } @@ -184,7 +183,7 @@ static void TraceValuesAtBBExit(BasicBlock *BB, Method *Printf, // Copy all of the instructions into a vector to avoid problems with Setcc const vector Insts(BB->begin(), InsertPos); - ostringstream OutStr; + std::ostringstream OutStr; WriteAsOperand(OutStr, BB, false); InsertPrintInst(0, BB, InsertPos, "LEAVING BB:" + OutStr.str(), Printf); @@ -211,7 +210,7 @@ static inline void InsertCodeToShowMethodEntry(Method *M, Method *Printf) { BasicBlock *BB = M->getEntryNode(); BasicBlock::iterator BBI = BB->begin(); - ostringstream OutStr; + std::ostringstream OutStr; WriteAsOperand(OutStr, M, true); InsertPrintInst(0, BB, BBI, "ENTERING METHOD: " + OutStr.str(), Printf); @@ -231,7 +230,7 @@ static inline void InsertCodeToShowMethodExit(BasicBlock *BB, Method *Printf) { BasicBlock::iterator BBI = BB->end()-1; ReturnInst *Ret = cast(*BBI); - ostringstream OutStr; + std::ostringstream OutStr; WriteAsOperand(OutStr, BB->getParent(), true); InsertPrintInst(0, BB, BBI, "LEAVING METHOD: " + OutStr.str(), Printf); @@ -249,8 +248,6 @@ bool InsertTraceCode::doit(Method *M, bool traceBasicBlockExits, vector valuesStoredInMethod; vector exitBlocks; - Module *module = M->getParent(); - if (traceMethodEvents) InsertCodeToShowMethodEntry(M, Printf); diff --git a/lib/Transforms/LevelRaise.cpp b/lib/Transforms/LevelRaise.cpp index e47eb906428..f1406769371 100644 --- a/lib/Transforms/LevelRaise.cpp +++ b/lib/Transforms/LevelRaise.cpp @@ -75,7 +75,7 @@ static bool HandleCastToPointer(BasicBlock::iterator BI, } } - vector Indices; + std::vector Indices; Value *Src = CI->getOperand(0); const Type *Result = ConvertableToGEP(DestPTy, Src, Indices, &BI); if (Result == 0) return false; // Not convertable... @@ -137,7 +137,7 @@ static bool PeepholeOptimizeAddCast(BasicBlock *BB, BasicBlock::iterator &BI, if (!CompTy || !SrcPtr || !OffsetVal->getType()->isIntegral()) return false; - vector Indices; + std::vector Indices; if (!ConvertableToGEP(SrcPtr->getType(), OffsetVal, Indices, &BI)) return false; // Not convertable... perhaps next time @@ -174,7 +174,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) { PRINT_PEEPHOLE1("cast-of-self-ty", CI); CI->replaceAllUsesWith(Src); if (!Src->hasName() && CI->hasName()) { - string Name = CI->getName(); + std::string Name = CI->getName(); CI->setName(""); Src->setName(Name, BB->getParent()->getSymbolTable()); } @@ -299,7 +299,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) { const Type *ElTy = 0; // Build the index vector, full of all zeros - vector Indices; + std::vector Indices; Indices.push_back(ConstantUInt::get(Type::UIntTy, 0)); while (CurCTy && !isa(CurCTy)) { if (const StructType *CurSTy = dyn_cast(CurCTy)) { diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index a38dbc56176..45a57a2f438 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -17,6 +17,8 @@ #include "Support/DepthFirstIterator.h" #include #include +#include +using std::cerr; #define DEBUG_ADCE 1 @@ -28,8 +30,8 @@ // class ADCE { Method *M; // The method that we are working on... - vector WorkList; // Instructions that just became live - set LiveSet; // The set of live instructions + std::vector WorkList; // Instructions that just became live + std::set LiveSet; // The set of live instructions bool MadeChanges; //===--------------------------------------------------------------------===// @@ -66,8 +68,8 @@ private: // fixupCFG - Walk the CFG in depth first order, eliminating references to // dead blocks. // - BasicBlock *fixupCFG(BasicBlock *Head, set &VisitedBlocks, - const set &AliveBlocks); + BasicBlock *fixupCFG(BasicBlock *Head, std::set &VisitedBlocks, + const std::set &AliveBlocks); }; @@ -121,7 +123,7 @@ bool ADCE::doADCE() { // AliveBlocks - Set of basic blocks that we know have instructions that are // alive in them... // - set AliveBlocks; + std::set AliveBlocks; // Process the work list of instructions that just became live... if they // became live, then that means that all of their operands are neccesary as @@ -169,7 +171,7 @@ bool ADCE::doADCE() { // After the worklist is processed, recursively walk the CFG in depth first // order, patching up references to dead blocks... // - set VisitedBlocks; + std::set VisitedBlocks; BasicBlock *EntryBlock = fixupCFG(M->front(), VisitedBlocks, AliveBlocks); if (EntryBlock && EntryBlock != M->front()) { if (isa(EntryBlock->front())) { @@ -194,7 +196,7 @@ bool ADCE::doADCE() { } else { // We need to move the new entry block to be the first bb of the method. Method::iterator EBI = find(M->begin(), M->end(), EntryBlock); - swap(*EBI, *M->begin()); // Exchange old location with start of method + std::swap(*EBI, *M->begin());// Exchange old location with start of method MadeChanges = true; } } @@ -242,8 +244,8 @@ bool ADCE::doADCE() { // been in the alive set). // 3. Return the nonnull child, or 0 if no non-null children. // -BasicBlock *ADCE::fixupCFG(BasicBlock *BB, set &VisitedBlocks, - const set &AliveBlocks) { +BasicBlock *ADCE::fixupCFG(BasicBlock *BB, std::set &VisitedBlocks, + const std::set &AliveBlocks) { if (VisitedBlocks.count(BB)) return 0; // Revisiting a node? No update. VisitedBlocks.insert(BB); // We have now visited this node! diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp index c267d95ea49..a961bad927c 100644 --- a/lib/Transforms/Scalar/ConstantProp.cpp +++ b/lib/Transforms/Scalar/ConstantProp.cpp @@ -159,7 +159,7 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) { bool opt::ConstantPropogation::doConstantPropogation(BasicBlock *BB, BasicBlock::iterator &II) { Instruction *Inst = *II; - if (BinaryOperator *BInst = dyn_cast(Inst)) { + if (isa(Inst)) { Constant *D1 = dyn_cast(Inst->getOperand(0)); Constant *D2 = dyn_cast(Inst->getOperand(1)); diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index 6c4e3d2a206..eadf7b18e0a 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -117,7 +117,7 @@ static bool PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) { // If there is more than one predecessor, and there are PHI nodes in // the successor, then we need to add incoming edges for the PHI nodes // - const vector BBPreds(BB->pred_begin(), BB->pred_end()); + const std::vector BBPreds(BB->pred_begin(), BB->pred_end()); // Check to see if one of the predecessors of BB is already a predecessor of // Succ. If so, we cannot do the transformation! @@ -134,7 +134,7 @@ static bool PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) { Value *OldVal = PN->removeIncomingValue(BB); assert(OldVal && "No entry in PHI for Pred BB!"); - for (vector::const_iterator PredI = BBPreds.begin(), + for (std::vector::const_iterator PredI = BBPreds.begin(), End = BBPreds.end(); PredI != End; ++PredI) { // Add an incoming value for each of the new incoming values... PN->addIncoming(OldVal, *PredI); diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index d03b4f3f400..35844cadb6c 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -35,7 +35,7 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) { // Transform all subloops before this loop... bool Changed = reduce_apply_bool(Loop->getSubLoops().begin(), Loop->getSubLoops().end(), - std::bind1st(ptr_fun(TransformLoop), Loops)); + std::bind1st(std::ptr_fun(TransformLoop), Loops)); // Get the header node for this loop. All of the phi nodes that could be // induction variables must live in this basic block. BasicBlock *Header = (BasicBlock*)Loop->getBlocks().front(); @@ -44,7 +44,7 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) { // induction variables that they represent... stuffing the induction variable // info into a vector... // - vector IndVars; // Induction variables for block + std::vector IndVars; // Induction variables for block for (BasicBlock::iterator I = Header->begin(); PHINode *PN = dyn_cast(*I); ++I) IndVars.push_back(InductionVariable(PN, Loops)); @@ -133,7 +133,7 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) { Instruction *Val = IterCount; if (!isa(IV->Step) || // If the step != 1 !cast(IV->Step)->equalsInt(1)) { - string Name; // Create a scale by the step value... + std::string Name; // Create a scale by the step value... if (IV->Phi->hasName()) Name = IV->Phi->getName()+"-scale"; // If the types are not compatible, insert a cast now... @@ -148,7 +148,7 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) { if (!isa(IV->Start) || // If the start != 0 !cast(IV->Start)->isNullValue()) { - string Name; // Create a offset by the start value... + std::string Name; // Create a offset by the start value... if (IV->Phi->hasName()) Name = IV->Phi->getName()+"-offset"; // If the types are not compatible, insert a cast now... @@ -170,7 +170,7 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) { IV->Phi->replaceAllUsesWith(Val); // Move the PHI name to it's new equivalent value... - string OldName = IV->Phi->getName(); + std::string OldName = IV->Phi->getName(); IV->Phi->setName(""); Val->setName(OldName); diff --git a/lib/Transforms/Scalar/InductionVars.cpp b/lib/Transforms/Scalar/InductionVars.cpp index d4b7bc50104..93ab189dee6 100644 --- a/lib/Transforms/Scalar/InductionVars.cpp +++ b/lib/Transforms/Scalar/InductionVars.cpp @@ -27,6 +27,8 @@ #include "llvm/iPHINode.h" #include "Support/STLExtras.h" #include +#include +using std::cerr; #include "llvm/Analysis/LoopDepth.h" @@ -176,7 +178,7 @@ static inline bool isSimpleInductionVar(PHINode *PN) { // present induction variables (instead of always using uint) // static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) { - string PHIName, AddName; + std::string PHIName, AddName; BasicBlock *Header = Int->getHeaderNode(); Method *M = Header->getParent(); @@ -205,7 +207,7 @@ static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) { assert(++PI == Header->pred_end() && "Header node should have 2 preds!"); // Make Pred1 be the loop entrance predecessor, Pred2 be the Loop predecessor - if (Int->contains(Pred1)) swap(Pred1, Pred2); + if (Int->contains(Pred1)) std::swap(Pred1, Pred2); assert(!Int->contains(Pred1) && "Pred1 should be loop entrance!"); assert( Int->contains(Pred2) && "Pred2 should be looping edge!"); @@ -250,7 +252,7 @@ static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) { static bool ProcessInterval(cfg::Interval *Int) { if (!Int->isLoop()) return false; // Not a loop? Ignore it! - vector InductionVars; + std::vector InductionVars; BasicBlock *Header = Int->getHeaderNode(); // Loop over all of the PHI nodes in the interval header... @@ -278,7 +280,7 @@ static bool ProcessInterval(cfg::Interval *Int) { if (isLoopInvariant(Int, V2)) { // They *are* loop invariant. Exchange BB1/BB2 and V1/V2 so that // V1 is always the loop invariant computation. - swap(V1, V2); swap(BB1, BB2); + std::swap(V1, V2); std::swap(BB1, BB2); } else { // Neither value is loop invariant. Must not be an induction variable. // This case can happen if there is an unreachable loop in the CFG that @@ -292,7 +294,7 @@ static bool ProcessInterval(cfg::Interval *Int) { // anything about BB2/V2. Check now to see if V2 is a linear induction // variable. // - cerr << "Found loop invariant computation: " << V1 << endl; + cerr << "Found loop invariant computation: " << V1 << "\n"; if (!isLinearInductionVariable(Int, V2, PN)) continue; // No, it is not a linear ind var, ignore the PHI node. @@ -308,7 +310,7 @@ static bool ProcessInterval(cfg::Interval *Int) { if (InductionVars.empty()) return false; // Search to see if there is already a "simple" induction variable. - vector::iterator It = + std::vector::iterator It = find_if(InductionVars.begin(), InductionVars.end(), isSimpleInductionVar); PHINode *PrimaryIndVar; @@ -329,7 +331,7 @@ static bool ProcessInterval(cfg::Interval *Int) { "How could Primary IndVar not be in the header!?!!?"); if (i != Header->begin()) - iter_swap(i, Header->begin()); + std::iter_swap(i, Header->begin()); } // Now we know that there is a simple induction variable PrimaryIndVar. @@ -364,7 +366,7 @@ static bool ProcessIntervalPartition(cfg::IntervalPartition &IP) { // variables in intervals that represent loops. // return reduce_apply(IP.begin(), IP.end(), bitwise_or(), false, - ptr_fun(ProcessInterval)); + std::ptr_fun(ProcessInterval)); } // DoInductionVariableCannonicalize - Simplify induction variables in loops. diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 87f8ed1897f..795418f939b 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -76,7 +76,7 @@ static Instruction *CombineIndicies(MemAccessInst *MAI) { dyn_cast(MAI->getPointerOperand()); if (!Src) return 0; - vector Indices; + std::vector Indices; // Only special case we have to watch out for is pointer arithmetic on the // 0th index of MAI. @@ -128,7 +128,7 @@ bool InstructionCombining::CombineInstruction(Instruction *I) { bool InstructionCombining::doit(Method *M) { // Start the worklist out with all of the instructions in the method in it. - vector WorkList(M->inst_begin(), M->inst_end()); + std::vector WorkList(M->inst_begin(), M->inst_end()); while (!WorkList.empty()) { Instruction *I = WorkList.back(); // Get an instruction from the worklist diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 26a52d61bf6..68be8440953 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +using std::cerr; // InstVal class - This class represents the different lattice values that an // instruction may occupy. It is a simple class with value semantics. The @@ -84,13 +86,13 @@ public: // It's public interface consists of a constructor and a doSCCP() method. // class SCCP { - Method *M; // The method that we are working on... + Method *M; // The method that we are working on... - set BBExecutable; // The basic blocks that are executable - map ValueState; // The state each value is in... + std::set BBExecutable;// The basic blocks that are executable + std::map ValueState; // The state each value is in... - vector InstWorkList; // The instruction work list - vector BBWorkList; // The BasicBlock work list + std::vector InstWorkList;// The instruction work list + std::vector BBWorkList; // The BasicBlock work list //===--------------------------------------------------------------------===// // The public interface for this class @@ -144,7 +146,7 @@ private: // Instruction object, then use this accessor to get its value from the map. // inline InstVal &getValueState(Value *V) { - map::iterator I = ValueState.find(V); + std::map::iterator I = ValueState.find(V); if (I != ValueState.end()) return I->second; // Common case, in the map if (Constant *CPV = dyn_cast(V)) { // Constants are constant diff --git a/lib/Transforms/Scalar/SymbolStripping.cpp b/lib/Transforms/Scalar/SymbolStripping.cpp index bb4f01c90b5..417376b89db 100644 --- a/lib/Transforms/Scalar/SymbolStripping.cpp +++ b/lib/Transforms/Scalar/SymbolStripping.cpp @@ -24,7 +24,7 @@ static bool StripSymbolTable(SymbolTable *SymTab) { bool RemovedSymbol = false; for (SymbolTable::iterator I = SymTab->begin(); I != SymTab->end(); ++I) { - map &Plane = I->second; + std::map &Plane = I->second; SymbolTable::type_iterator B; while ((B = Plane.begin()) != Plane.end()) { // Found nonempty type plane! diff --git a/lib/Transforms/TransformInternals.cpp b/lib/Transforms/TransformInternals.cpp index cd6288540ac..6c7f8566197 100644 --- a/lib/Transforms/TransformInternals.cpp +++ b/lib/Transforms/TransformInternals.cpp @@ -82,7 +82,7 @@ void ReplaceInstWithInst(Instruction *From, Instruction *To) { // false if you want a leaf // const Type *getStructOffsetType(const Type *Ty, unsigned &Offset, - vector &Offsets, + std::vector &Offsets, bool StopEarly = true) { if (Offset == 0 && StopEarly && !Offsets.empty()) return Ty; // Return the leaf type @@ -130,7 +130,7 @@ const Type *getStructOffsetType(const Type *Ty, unsigned &Offset, // instruction. The type returned is the root type that the GEP would point to // const Type *ConvertableToGEP(const Type *Ty, Value *OffsetVal, - vector &Indices, + std::vector &Indices, BasicBlock::iterator *BI = 0) { const CompositeType *CompTy = dyn_cast(Ty); if (CompTy == 0) return 0; diff --git a/lib/Transforms/TransformInternals.h b/lib/Transforms/TransformInternals.h index 200a4d7b98a..7bc3df4fc37 100644 --- a/lib/Transforms/TransformInternals.h +++ b/lib/Transforms/TransformInternals.h @@ -24,7 +24,7 @@ // extern const TargetData TD; -static int getConstantValue(const ConstantInt *CPI) { +static inline int getConstantValue(const ConstantInt *CPI) { if (const ConstantSInt *CSI = dyn_cast(CPI)) return CSI->getValue(); return cast(CPI)->getValue(); @@ -65,25 +65,26 @@ void ReplaceInstWithInst(Instruction *From, Instruction *To); // If BI is nonnull, cast instructions are inserted as appropriate for the // arguments of the getelementptr. // -const Type *ConvertableToGEP(const Type *Ty, Value *V, vector &Indices, +const Type *ConvertableToGEP(const Type *Ty, Value *V, + std::vector &Indices, BasicBlock::iterator *BI = 0); // ------------- Expression Conversion --------------------- -typedef map ValueTypeCache; +typedef std::map ValueTypeCache; struct ValueMapCache { // Operands mapped - Contains an entry if the first value (the user) has had // the second value (the operand) mapped already. // - set OperandsMapped; + std::set OperandsMapped; // Expression Map - Contains an entry from the old value to the new value of // an expression that has been converted over. // - map ExprMap; - typedef map ExprMapTy; + std::map ExprMap; + typedef std::map ExprMapTy; }; @@ -137,7 +138,7 @@ public: // false if you want a leaf // const Type *getStructOffsetType(const Type *Ty, unsigned &Offset, - vector &Offsets, + std::vector &Offsets, bool StopEarly = true); #endif diff --git a/lib/Transforms/Utils/Linker.cpp b/lib/Transforms/Utils/Linker.cpp index f04c8a46a31..e1622529c26 100644 --- a/lib/Transforms/Utils/Linker.cpp +++ b/lib/Transforms/Utils/Linker.cpp @@ -17,6 +17,10 @@ #include "llvm/DerivedTypes.h" #include "llvm/iOther.h" #include "llvm/ConstantVals.h" +#include +using std::cerr; +using std::string; +using std::map; // Error - Simple wrapper function to conditionally assign to E and return true. // This just makes error return conditions a little bit simpler... @@ -70,7 +74,7 @@ static void PrintMap(const map &M) { for (map::const_iterator I = M.begin(), E = M.end(); I != E; ++I) { cerr << " Fr: " << (void*)I->first << " " << I->first - << " To: " << (void*)I->second << " " << I->second << endl; + << " To: " << (void*)I->second << " " << I->second << "\n"; } } @@ -97,15 +101,15 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Constant *Result = 0; if (ConstantArray *CPA = dyn_cast(CPV)) { - const vector &Ops = CPA->getValues(); - vector Operands(Ops.size()); + const std::vector &Ops = CPA->getValues(); + std::vector Operands(Ops.size()); for (unsigned i = 0; i < Ops.size(); ++i) Operands[i] = cast(RemapOperand(Ops[i], LocalMap, GlobalMap)); Result = ConstantArray::get(cast(CPA->getType()), Operands); } else if (ConstantStruct *CPS = dyn_cast(CPV)) { - const vector &Ops = CPS->getValues(); - vector Operands(Ops.size()); + const std::vector &Ops = CPS->getValues(); + std::vector Operands(Ops.size()); for (unsigned i = 0; i < Ops.size(); ++i) Operands[i] = cast(RemapOperand(Ops[i], LocalMap, GlobalMap)); @@ -120,7 +124,7 @@ static Value *RemapOperand(const Value *In, map &LocalMap, } // Cache the mapping in our local map structure... - LocalMap.insert(make_pair(In, CPV)); + LocalMap.insert(std::make_pair(In, CPV)); return Result; } @@ -132,7 +136,7 @@ static Value *RemapOperand(const Value *In, map &LocalMap, PrintMap(*GlobalMap); } - cerr << "Couldn't remap value: " << (void*)In << " " << In << endl; + cerr << "Couldn't remap value: " << (void*)In << " " << In << "\n"; assert(0 && "Couldn't remap value!"); return 0; } @@ -172,7 +176,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src, " - Global variables differ in const'ness"); // Okay, everything is cool, remember the mapping... - ValueMap.insert(make_pair(SGV, DGV)); + ValueMap.insert(std::make_pair(SGV, DGV)); } else { // No linking to be performed, simply create an identical version of the // symbol over in the dest module... the initializer will be filled in @@ -186,7 +190,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src, Dest->getGlobalList().push_back(DGV); // Make sure to remember this mapping... - ValueMap.insert(make_pair(SGV, DGV)); + ValueMap.insert(std::make_pair(SGV, DGV)); } } return false; @@ -262,7 +266,7 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src, SM->getName() + "\" - Method is already defined!"); // Otherwise, just remember this mapping... - ValueMap.insert(make_pair(SM, DM)); + ValueMap.insert(std::make_pair(SM, DM)); } else { // Method does not already exist, simply insert an external method // signature identical to SM into the dest module... @@ -273,7 +277,7 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src, Dest->getMethodList().push_back(DM); // ... and remember this mapping... - ValueMap.insert(make_pair(SM, DM)); + ValueMap.insert(std::make_pair(SM, DM)); } } return false; @@ -300,7 +304,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src, Dest->getArgumentList().push_back(DMA); // Add a mapping to our local map - LocalMap.insert(make_pair(SMA, DMA)); + LocalMap.insert(std::make_pair(SMA, DMA)); } // Loop over all of the basic blocks, copying the instructions over... @@ -310,7 +314,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src, // Create new basic block and add to mapping and the Dest method... BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest); - LocalMap.insert(make_pair(SBB, DBB)); + LocalMap.insert(std::make_pair(SBB, DBB)); // Loop over all of the instructions in the src basic block, copying them // over. Note that this is broken in a strict sense because the cloned @@ -324,7 +328,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src, Instruction *DI = SI->clone(); DI->setName(SI->getName()); DBB->getInstList().push_back(DI); - LocalMap.insert(make_pair(SI, DI)); + LocalMap.insert(std::make_pair(SI, DI)); } } diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp index 666b6d976eb..ca1085e3edc 100644 --- a/lib/Transforms/Utils/LowerAllocations.cpp +++ b/lib/Transforms/Utils/LowerAllocations.cpp @@ -14,6 +14,8 @@ #include "llvm/iOther.h" #include "llvm/SymbolTable.h" #include "llvm/ConstantVals.h" +using std::vector; + // doPassInitialization - For the lower allocations pass, this ensures that a // module contains a declaration for a malloc and a free function. diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp index efc7676bb71..56c4b204ca9 100644 --- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp +++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp @@ -11,6 +11,7 @@ #include "llvm/iTerminators.h" #include "llvm/iPHINode.h" #include "llvm/Type.h" +using std::vector; // UnifyAllExitNodes - Unify all exit nodes of the CFG by creating a new // BasicBlock, and converting all returns to unconditional branches to this diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 2b3a1c4c220..c218c0fcd00 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -26,6 +26,10 @@ #include "Support/STLExtras.h" #include #include +using std::string; +using std::map; +using std::vector; +using std::ostream; static const Module *getModuleFromVal(const Value *V) { if (const MethodArgument *MA =dyn_cast(V)) @@ -112,7 +116,7 @@ static void fillTypeNameTable(const Module *M, const Type *Ty = cast(I->second); if (!isa(Ty) || !cast(Ty)->getElementType()->isPrimitiveType()) - TypeNames.insert(make_pair(Ty, "%"+I->first)); + TypeNames.insert(std::make_pair(Ty, "%"+I->first)); } } } @@ -215,7 +219,7 @@ static ostream &printTypeInt(ostream &Out, const Type *Ty, // vector TypeStack; string TypeName = calcTypeName(Ty, TypeStack, TypeNames); - TypeNames.insert(make_pair(Ty, TypeName)); // Cache type name for later use + TypeNames.insert(std::make_pair(Ty, TypeName));//Cache type name for later use return Out << TypeName; } @@ -331,7 +335,7 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) { writeOperand(GV->getInitializer(), false, false); printInfoComment(GV); - Out << endl; + Out << "\n"; } @@ -348,7 +352,7 @@ void AssemblyWriter::printSymbolTable(const SymbolTable &ST) { if (const Constant *CPV = dyn_cast(V)) { printConstant(CPV); } else if (const Type *Ty = dyn_cast(V)) { - Out << "\t%" << I->first << " = type " << Ty->getDescription() << endl; + Out << "\t%" << I->first << " = type " << Ty->getDescription() << "\n"; } } } @@ -378,7 +382,7 @@ void AssemblyWriter::printConstant(const Constant *CPV) { else Out << ""; } - Out << endl; + Out << "\n"; } // printMethod - Print all aspects of a method. @@ -614,7 +618,7 @@ void AssemblyWriter::printInstruction(const Instruction *I) { } printInfoComment(I); - Out << endl; + Out << "\n"; } diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 861aea43c25..df999b84bff 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -18,7 +18,7 @@ // template class ValueHolder; -BasicBlock::BasicBlock(const string &name, Method *Parent) +BasicBlock::BasicBlock(const std::string &name, Method *Parent) : Value(Type::LabelTy, Value::BasicBlockVal, name), InstList(this, 0), machineInstrVec(new MachineCodeForBasicBlock) { if (Parent) @@ -32,7 +32,7 @@ BasicBlock::~BasicBlock() { } // Specialize setName to take care of symbol table majik -void BasicBlock::setName(const string &name, SymbolTable *ST) { +void BasicBlock::setName(const std::string &name, SymbolTable *ST) { Method *P; assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) && "Invalid symtab argument!"); diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 257bd7622c9..d9a2fa74314 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -15,6 +15,10 @@ #include #include +using std::map; +using std::pair; +using std::make_pair; + ConstantBool *ConstantBool::True = new ConstantBool(true); ConstantBool *ConstantBool::False = new ConstantBool(false); @@ -24,7 +28,7 @@ ConstantBool *ConstantBool::False = new ConstantBool(false); //===----------------------------------------------------------------------===// // Specialize setName to take care of symbol table majik -void Constant::setName(const string &Name, SymbolTable *ST) { +void Constant::setName(const std::string &Name, SymbolTable *ST) { assert(ST && "Type::setName - Must provide symbol table argument!"); if (Name.size()) ST->insert(Name, this); @@ -56,6 +60,7 @@ Constant *Constant::getNullConstant(const Type *Ty) { #ifndef NDEBUG #include "llvm/Assembly/Writer.h" +using std::cerr; #endif void Constant::destroyConstantImpl() { @@ -70,8 +75,8 @@ void Constant::destroyConstantImpl() { Value *V = use_back(); #ifndef NDEBUG // Only in -g mode... if (!isa(V)) { - cerr << "While deleting: " << this << endl; - cerr << "Use still stuck around after Def is destroyed: " << V << endl; + cerr << "While deleting: " << this << "\n"; + cerr << "Use still stuck around after Def is destroyed: " << V << "\n"; } #endif assert(isa(V) && "References remain to ConstantPointerRef!"); @@ -115,7 +120,7 @@ ConstantFP::ConstantFP(const Type *Ty, double V) : Constant(Ty) { } ConstantArray::ConstantArray(const ArrayType *T, - const vector &V) : Constant(T) { + const std::vector &V) : Constant(T) { for (unsigned i = 0; i < V.size(); i++) { assert(V[i]->getType() == T->getElementType()); Operands.push_back(Use(V[i], this)); @@ -123,7 +128,7 @@ ConstantArray::ConstantArray(const ArrayType *T, } ConstantStruct::ConstantStruct(const StructType *T, - const vector &V) : Constant(T) { + const std::vector &V) : Constant(T) { const StructType::ElementTypes &ETypes = T->getElementTypes(); for (unsigned i = 0; i < V.size(); i++) { @@ -142,24 +147,24 @@ ConstantPointerRef::ConstantPointerRef(GlobalValue *GV) //===----------------------------------------------------------------------===// // getStrValue implementations -string ConstantBool::getStrValue() const { +std::string ConstantBool::getStrValue() const { return Val ? "true" : "false"; } -string ConstantSInt::getStrValue() const { +std::string ConstantSInt::getStrValue() const { return itostr(Val.Signed); } -string ConstantUInt::getStrValue() const { +std::string ConstantUInt::getStrValue() const { return utostr(Val.Unsigned); } -string ConstantFP::getStrValue() const { +std::string ConstantFP::getStrValue() const { return ftostr(Val); } -string ConstantArray::getStrValue() const { - string Result; +std::string ConstantArray::getStrValue() const { + std::string Result; // As a special case, print the array as a string if it is an array of // ubytes or an array of sbytes with positive values. @@ -208,8 +213,8 @@ string ConstantArray::getStrValue() const { return Result; } -string ConstantStruct::getStrValue() const { - string Result = "{"; +std::string ConstantStruct::getStrValue() const { + std::string Result = "{"; if (Operands.size()) { Result += " " + Operands[0]->getType()->getDescription() + " " + cast(Operands[0])->getStrValue(); @@ -221,11 +226,11 @@ string ConstantStruct::getStrValue() const { return Result + " }"; } -string ConstantPointerNull::getStrValue() const { +std::string ConstantPointerNull::getStrValue() const { return "null"; } -string ConstantPointerRef::getStrValue() const { +std::string ConstantPointerRef::getStrValue() const { const GlobalValue *V = getValue(); if (V->hasName()) return "%" + V->getName(); @@ -233,7 +238,7 @@ string ConstantPointerRef::getStrValue() const { int Slot = Table->getValSlot(V); delete Table; - if (Slot >= 0) return string(" %") + itostr(Slot); + if (Slot >= 0) return std::string(" %") + itostr(Slot); else return ""; } @@ -337,7 +342,7 @@ unsigned ConstantFP::hash(const Type *Ty, double V) { } unsigned ConstantArray::hash(const ArrayType *Ty, - const vector &V) { + const std::vector &V) { unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7); for (unsigned i = 0; i < V.size(); ++i) Result ^= V[i]->getHash() << (i & 7); @@ -345,7 +350,7 @@ unsigned ConstantArray::hash(const ArrayType *Ty, } unsigned ConstantStruct::hash(const StructType *Ty, - const vector &V) { + const std::vector &V) { unsigned Result = (Ty->getUniqueID() << 5) ^ (Ty->getUniqueID() * 7); for (unsigned i = 0; i < V.size(); ++i) Result ^= V[i]->getHash() << (i & 7); @@ -418,10 +423,10 @@ ConstantFP *ConstantFP::get(const Type *Ty, double V) { //---- ConstantArray::get() implementation... // -static ValueMap, ConstantArray> ArrayConstants; +static ValueMap, ConstantArray> ArrayConstants; ConstantArray *ConstantArray::get(const ArrayType *Ty, - const vector &V) { + const std::vector &V) { ConstantArray *Result = ArrayConstants.get(Ty, V); if (!Result) // If no preexisting value, create one now... ArrayConstants.add(Ty, V, Result = new ConstantArray(Ty, V)); @@ -432,8 +437,8 @@ ConstantArray *ConstantArray::get(const ArrayType *Ty, // contain the specified string. A null terminator is added to the specified // string so that it may be used in a natural way... // -ConstantArray *ConstantArray::get(const string &Str) { - vector ElementVals; +ConstantArray *ConstantArray::get(const std::string &Str) { + std::vector ElementVals; for (unsigned i = 0; i < Str.length(); ++i) ElementVals.push_back(ConstantSInt::get(Type::SByteTy, Str[i])); @@ -455,10 +460,10 @@ void ConstantArray::destroyConstant() { //---- ConstantStruct::get() implementation... // -static ValueMap, ConstantStruct> StructConstants; +static ValueMap, ConstantStruct> StructConstants; ConstantStruct *ConstantStruct::get(const StructType *Ty, - const vector &V) { + const std::vector &V) { ConstantStruct *Result = StructConstants.get(Ty, V); if (!Result) // If no preexisting value, create one now... StructConstants.add(Ty, V, Result = new ConstantStruct(Ty, V)); diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index 2ed02dbed26..2e4f6e4df1f 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -10,6 +10,8 @@ #include "Support/DepthFirstIterator.h" #include "Support/STLExtras.h" #include +using std::set; + //===----------------------------------------------------------------------===// // Helper Template diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index 4b38ce11965..e7d10c1496f 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -25,7 +25,7 @@ template class ValueHolder; template class ValueHolder; -Method::Method(const MethodType *Ty, bool isInternal, const string &name) +Method::Method(const MethodType *Ty, bool isInternal, const std::string &name) : GlobalValue(PointerType::get(Ty), Value::MethodVal, isInternal, name), SymTabValue(this), BasicBlocks(this), ArgumentList(this, this) { assert(::isa(Ty) && "Method signature must be of method type!"); @@ -45,7 +45,7 @@ Method::~Method() { } // Specialize setName to take care of symbol table majik -void Method::setName(const string &name, SymbolTable *ST) { +void Method::setName(const std::string &name, SymbolTable *ST) { Module *P; assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) && "Invalid symtab argument!"); @@ -87,14 +87,14 @@ void Method::dropAllReferences() { GlobalVariable::GlobalVariable(const Type *Ty, bool constant, bool isIntern, Constant *Initializer = 0, - const string &Name = "") + const std::string &Name = "") : GlobalValue(PointerType::get(Ty), Value::GlobalVariableVal, isIntern, Name), isConstantGlobal(constant) { if (Initializer) Operands.push_back(Use((Value*)Initializer, this)); } // Specialize setName to take care of symbol table majik -void GlobalVariable::setName(const string &name, SymbolTable *ST) { +void GlobalVariable::setName(const std::string &name, SymbolTable *ST) { Module *P; assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) && "Invalid symtab argument!"); diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp index 69a703c0c74..a4c82126323 100644 --- a/lib/VMCore/InstrTypes.cpp +++ b/lib/VMCore/InstrTypes.cpp @@ -21,7 +21,7 @@ TerminatorInst::TerminatorInst(Instruction::TermOps iType) } TerminatorInst::TerminatorInst(const Type *Ty, Instruction::TermOps iType, - const string &Name = "") + const std::string &Name = "") : Instruction(Ty, iType, Name) { } @@ -31,7 +31,7 @@ TerminatorInst::TerminatorInst(const Type *Ty, Instruction::TermOps iType, //===----------------------------------------------------------------------===// // Specialize setName to take care of symbol table majik -void MethodArgument::setName(const string &name, SymbolTable *ST) { +void MethodArgument::setName(const std::string &name, SymbolTable *ST) { Method *P; assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) && "Invalid symtab argument!"); @@ -45,7 +45,7 @@ void MethodArgument::setName(const string &name, SymbolTable *ST) { // PHINode Class //===----------------------------------------------------------------------===// -PHINode::PHINode(const Type *Ty, const string &name) +PHINode::PHINode(const Type *Ty, const std::string &name) : Instruction(Ty, Instruction::PHINode, name) { } diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index 8b37510d354..186c85007ed 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -10,7 +10,7 @@ #include "llvm/SymbolTable.h" #include "llvm/CodeGen/MachineInstr.h" -Instruction::Instruction(const Type *ty, unsigned it, const string &Name) +Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name) : User(ty, Value::InstructionVal, Name), machineInstrVec(new MachineCodeForVMInstr) { Parent = 0; @@ -23,7 +23,7 @@ Instruction::~Instruction() { } // Specialize setName to take care of symbol table majik -void Instruction::setName(const string &name, SymbolTable *ST) { +void Instruction::setName(const std::string &name, SymbolTable *ST) { BasicBlock *P = 0; Method *PP = 0; assert((ST == 0 || !getParent() || !getParent()->getParent() || ST == getParent()->getParent()->getSymbolTable()) && @@ -44,7 +44,7 @@ void Instruction::addMachineInstruction(MachineInstr* minstr) { // sequence of forward declarations. Trying to fix that will // cause a serious circularity in link order. // -const vector &Instruction::getTempValuesForMachineCode() const { +const std::vector &Instruction::getTempValuesForMachineCode() const { return machineInstrVec->getTempValues(); } #endif diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp index f04c8a46a31..e1622529c26 100644 --- a/lib/VMCore/Linker.cpp +++ b/lib/VMCore/Linker.cpp @@ -17,6 +17,10 @@ #include "llvm/DerivedTypes.h" #include "llvm/iOther.h" #include "llvm/ConstantVals.h" +#include +using std::cerr; +using std::string; +using std::map; // Error - Simple wrapper function to conditionally assign to E and return true. // This just makes error return conditions a little bit simpler... @@ -70,7 +74,7 @@ static void PrintMap(const map &M) { for (map::const_iterator I = M.begin(), E = M.end(); I != E; ++I) { cerr << " Fr: " << (void*)I->first << " " << I->first - << " To: " << (void*)I->second << " " << I->second << endl; + << " To: " << (void*)I->second << " " << I->second << "\n"; } } @@ -97,15 +101,15 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Constant *Result = 0; if (ConstantArray *CPA = dyn_cast(CPV)) { - const vector &Ops = CPA->getValues(); - vector Operands(Ops.size()); + const std::vector &Ops = CPA->getValues(); + std::vector Operands(Ops.size()); for (unsigned i = 0; i < Ops.size(); ++i) Operands[i] = cast(RemapOperand(Ops[i], LocalMap, GlobalMap)); Result = ConstantArray::get(cast(CPA->getType()), Operands); } else if (ConstantStruct *CPS = dyn_cast(CPV)) { - const vector &Ops = CPS->getValues(); - vector Operands(Ops.size()); + const std::vector &Ops = CPS->getValues(); + std::vector Operands(Ops.size()); for (unsigned i = 0; i < Ops.size(); ++i) Operands[i] = cast(RemapOperand(Ops[i], LocalMap, GlobalMap)); @@ -120,7 +124,7 @@ static Value *RemapOperand(const Value *In, map &LocalMap, } // Cache the mapping in our local map structure... - LocalMap.insert(make_pair(In, CPV)); + LocalMap.insert(std::make_pair(In, CPV)); return Result; } @@ -132,7 +136,7 @@ static Value *RemapOperand(const Value *In, map &LocalMap, PrintMap(*GlobalMap); } - cerr << "Couldn't remap value: " << (void*)In << " " << In << endl; + cerr << "Couldn't remap value: " << (void*)In << " " << In << "\n"; assert(0 && "Couldn't remap value!"); return 0; } @@ -172,7 +176,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src, " - Global variables differ in const'ness"); // Okay, everything is cool, remember the mapping... - ValueMap.insert(make_pair(SGV, DGV)); + ValueMap.insert(std::make_pair(SGV, DGV)); } else { // No linking to be performed, simply create an identical version of the // symbol over in the dest module... the initializer will be filled in @@ -186,7 +190,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src, Dest->getGlobalList().push_back(DGV); // Make sure to remember this mapping... - ValueMap.insert(make_pair(SGV, DGV)); + ValueMap.insert(std::make_pair(SGV, DGV)); } } return false; @@ -262,7 +266,7 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src, SM->getName() + "\" - Method is already defined!"); // Otherwise, just remember this mapping... - ValueMap.insert(make_pair(SM, DM)); + ValueMap.insert(std::make_pair(SM, DM)); } else { // Method does not already exist, simply insert an external method // signature identical to SM into the dest module... @@ -273,7 +277,7 @@ static bool LinkMethodProtos(Module *Dest, const Module *Src, Dest->getMethodList().push_back(DM); // ... and remember this mapping... - ValueMap.insert(make_pair(SM, DM)); + ValueMap.insert(std::make_pair(SM, DM)); } } return false; @@ -300,7 +304,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src, Dest->getArgumentList().push_back(DMA); // Add a mapping to our local map - LocalMap.insert(make_pair(SMA, DMA)); + LocalMap.insert(std::make_pair(SMA, DMA)); } // Loop over all of the basic blocks, copying the instructions over... @@ -310,7 +314,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src, // Create new basic block and add to mapping and the Dest method... BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest); - LocalMap.insert(make_pair(SBB, DBB)); + LocalMap.insert(std::make_pair(SBB, DBB)); // Loop over all of the instructions in the src basic block, copying them // over. Note that this is broken in a strict sense because the cloned @@ -324,7 +328,7 @@ static bool LinkMethodBody(Method *Dest, const Method *Src, Instruction *DI = SI->clone(); DI->setName(SI->getName()); DBB->getInstList().push_back(DI); - LocalMap.insert(make_pair(SI, DI)); + LocalMap.insert(std::make_pair(SI, DI)); } } diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index a42535580bf..606d3aef142 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -24,7 +24,7 @@ template class ValueHolder; // Define the GlobalValueRefMap as a struct that wraps a map so that we don't // have Module.h depend on // -struct GlobalValueRefMap : public map{ +struct GlobalValueRefMap : public std::map{ }; @@ -97,7 +97,7 @@ ConstantPointerRef *Module::getConstantPointerRef(GlobalValue *V){ if (I != GVRefMap->end()) return I->second; ConstantPointerRef *Ref = new ConstantPointerRef(V); - GVRefMap->insert(make_pair(V, Ref)); + GVRefMap->insert(std::make_pair(V, Ref)); return Ref; } @@ -112,5 +112,5 @@ void Module::mutateConstantPointerRef(GlobalValue *OldGV, GlobalValue *NewGV) { GVRefMap->erase(I); // Insert the new entry... - GVRefMap->insert(make_pair(NewGV, Ref)); + GVRefMap->insert(std::make_pair(NewGV, Ref)); } diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp index ede822846d3..4738f712a16 100644 --- a/lib/VMCore/SlotCalculator.cpp +++ b/lib/VMCore/SlotCalculator.cpp @@ -196,7 +196,8 @@ void SlotCalculator::purgeMethod() { while (CurPlane.size() != ModuleSize) { //SC_DEBUG(" Removing [" << i << "] Value=" << CurPlane.back() << "\n"); - map::iterator NI = NodeMap.find(CurPlane.back()); + std::map::iterator NI = + NodeMap.find(CurPlane.back()); assert(NI != NodeMap.end() && "Node not in nodemap?"); NodeMap.erase(NI); // Erase from nodemap CurPlane.pop_back(); // Shrink plane @@ -223,7 +224,7 @@ void SlotCalculator::purgeMethod() { } int SlotCalculator::getValSlot(const Value *D) const { - map::const_iterator I = NodeMap.find(D); + std::map::const_iterator I = NodeMap.find(D); if (I == NodeMap.end()) return -1; return (int)I->second; diff --git a/lib/VMCore/SymbolTable.cpp b/lib/VMCore/SymbolTable.cpp index dd6329fc97f..ab98a731841 100644 --- a/lib/VMCore/SymbolTable.cpp +++ b/lib/VMCore/SymbolTable.cpp @@ -10,6 +10,14 @@ #include "llvm/Module.h" #include "llvm/Method.h" #include "Support/StringExtras.h" +#include + +using std::string; +using std::pair; +using std::make_pair; +using std::map; +using std::cerr; +using std::cout; #define DEBUG_SYMBOL_TABLE 0 #define DEBUG_ABSTYPE 0 @@ -35,7 +43,8 @@ SymbolTable::~SymbolTable() { for (type_iterator I = i->second.begin(); I != i->second.end(); ++I) if (!isa(I->second) && !isa(I->second)) { cerr << "Value still in symbol table! Type = '" - << i->first->getDescription() << "' Name = '" << I->first << "'\n"; + << i->first->getDescription() << "' Name = '" + << I->first << "'\n"; LeftoverValues = false; } } @@ -305,11 +314,11 @@ void SymbolTable::refineAbstractType(const DerivedType *OldType, #include static void DumpVal(const pair &V) { - cout << " '" << V.first << "' = " << V.second << endl; + cout << " '" << V.first << "' = " << V.second << "\n"; } static void DumpPlane(const pair >&P) { - cout << " Plane: " << P.first << endl; + cout << " Plane: " << P.first << "\n"; for_each(P.second.begin(), P.second.end(), DumpVal); } diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index cbcdf3f37d0..316f97d4392 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -8,6 +8,14 @@ #include "llvm/SymbolTable.h" #include "Support/StringExtras.h" #include "Support/STLExtras.h" +#include + +using std::vector; +using std::string; +using std::map; +using std::swap; +using std::make_pair; +using std::cerr; // DEBUG_MERGE_TYPES - Enable this #define to see how and when derived types are // created and later destroyed, all in an effort to make sure that there is only diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 0ac72051043..af9d2e4f628 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -11,6 +11,8 @@ #include "llvm/Type.h" #ifndef NDEBUG // Only in -g mode... #include "llvm/Assembly/Writer.h" +#include +using std::cerr; #endif #include @@ -23,7 +25,7 @@ static inline const Type *checkType(const Type *Ty) { return Ty; } -Value::Value(const Type *ty, ValueTy vty, const string &name = "") +Value::Value(const Type *ty, ValueTy vty, const std::string &name = "") : Name(name), Ty(checkType(ty), this) { VTy = vty; } @@ -39,7 +41,7 @@ Value::~Value() { if (Uses.begin() != Uses.end()) { cerr << "While deleting: " << this; for (use_const_iterator I = Uses.begin(); I != Uses.end(); ++I) - cerr << "Use still stuck around after Def is destroyed:" << *I << endl; + cerr << "Use still stuck around after Def is destroyed:" << *I << "\n"; } #endif assert(Uses.begin() == Uses.end()); @@ -98,7 +100,7 @@ void Value::dump() const { // User Class //===----------------------------------------------------------------------===// -User::User(const Type *Ty, ValueTy vty, const string &name) +User::User(const Type *Ty, ValueTy vty, const std::string &name) : Value(Ty, vty, name) { } diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 55424fc4784..0702e85f0e0 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -34,6 +34,9 @@ #include "llvm/Module.h" #include "llvm/BasicBlock.h" #include "llvm/Type.h" +using std::string; +using std::vector; + // Error - Define a macro to do the common task of pushing a message onto the // end of the error list and setting Bad to true. diff --git a/lib/VMCore/iBranch.cpp b/lib/VMCore/iBranch.cpp index d0f437e293b..f020ab62137 100644 --- a/lib/VMCore/iBranch.cpp +++ b/lib/VMCore/iBranch.cpp @@ -10,6 +10,7 @@ #ifndef NDEBUG #include "llvm/Type.h" // Only used for assertions... #include "llvm/Assembly/Writer.h" +#include #endif BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond) @@ -27,7 +28,7 @@ BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond) #ifndef NDEBUG if (Cond != 0 && Cond->getType() != Type::BoolTy) - cerr << "Bad Condition: " << Cond << endl; + std::cerr << "Bad Condition: " << Cond << "\n"; #endif assert((Cond == 0 || Cond->getType() == Type::BoolTy) && "May only branch on boolean predicates!!!!"); diff --git a/lib/VMCore/iCall.cpp b/lib/VMCore/iCall.cpp index 7f4efaf7b2c..37eb24e86cb 100644 --- a/lib/VMCore/iCall.cpp +++ b/lib/VMCore/iCall.cpp @@ -13,8 +13,8 @@ // CallInst Implementation //===----------------------------------------------------------------------===// -CallInst::CallInst(Value *Meth, const vector ¶ms, - const string &Name) +CallInst::CallInst(Value *Meth, const std::vector ¶ms, + const std::string &Name) : Instruction(cast(cast(Meth->getType()) ->getElementType())->getReturnType(), Instruction::Call, Name) { @@ -44,8 +44,9 @@ CallInst::CallInst(const CallInst &CI) //===----------------------------------------------------------------------===// InvokeInst::InvokeInst(Value *Meth, BasicBlock *IfNormal, \ - BasicBlock *IfException, const vector¶ms, - const string &Name) + BasicBlock *IfException, + const std::vector ¶ms, + const std::string &Name) : TerminatorInst(cast(cast(Meth->getType()) ->getElementType())->getReturnType(), Instruction::Invoke, Name) { diff --git a/lib/VMCore/iMemory.cpp b/lib/VMCore/iMemory.cpp index c845fd99362..4226a696157 100644 --- a/lib/VMCore/iMemory.cpp +++ b/lib/VMCore/iMemory.cpp @@ -22,7 +22,7 @@ static inline const Type *checkType(const Type *Ty) { // pointer type. // const Type* MemAccessInst::getIndexedType(const Type *Ptr, - const vector &Idx, + const std::vector &Idx, bool AllowCompositeLeaf = false) { if (!Ptr->isPointerType()) return 0; // Type isn't a pointer type! @@ -48,8 +48,8 @@ const Type* MemAccessInst::getIndexedType(const Type *Ptr, // LoadInst Implementation //===----------------------------------------------------------------------===// -LoadInst::LoadInst(Value *Ptr, const vector &Idx, - const string &Name = "") +LoadInst::LoadInst(Value *Ptr, const std::vector &Idx, + const std::string &Name = "") : MemAccessInst(checkType(getIndexedType(Ptr->getType(), Idx)), Load, Name) { assert(getIndexedType(Ptr->getType(), Idx) && "Load operands invalid!"); Operands.reserve(1+Idx.size()); @@ -60,7 +60,7 @@ LoadInst::LoadInst(Value *Ptr, const vector &Idx, } -LoadInst::LoadInst(Value *Ptr, const string &Name = "") +LoadInst::LoadInst(Value *Ptr, const std::string &Name = "") : MemAccessInst(cast(Ptr->getType())->getElementType(), Load, Name) { Operands.reserve(1); @@ -72,8 +72,8 @@ LoadInst::LoadInst(Value *Ptr, const string &Name = "") // StoreInst Implementation //===----------------------------------------------------------------------===// -StoreInst::StoreInst(Value *Val, Value *Ptr, const vector &Idx, - const string &Name = "") +StoreInst::StoreInst(Value *Val, Value *Ptr, const std::vector &Idx, + const std::string &Name = "") : MemAccessInst(Type::VoidTy, Store, Name) { assert(getIndexedType(Ptr->getType(), Idx) && "Store operands invalid!"); @@ -85,7 +85,7 @@ StoreInst::StoreInst(Value *Val, Value *Ptr, const vector &Idx, Operands.push_back(Use(Idx[i], this)); } -StoreInst::StoreInst(Value *Val, Value *Ptr, const string &Name = "") +StoreInst::StoreInst(Value *Val, Value *Ptr, const std::string &Name = "") : MemAccessInst(Type::VoidTy, Store, Name) { Operands.reserve(2); @@ -98,8 +98,8 @@ StoreInst::StoreInst(Value *Val, Value *Ptr, const string &Name = "") // GetElementPtrInst Implementation //===----------------------------------------------------------------------===// -GetElementPtrInst::GetElementPtrInst(Value *Ptr, const vector &Idx, - const string &Name = "") +GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector &Idx, + const std::string &Name = "") : MemAccessInst(PointerType::get(checkType(getIndexedType(Ptr->getType(), Idx, true))), GetElementPtr, Name) { diff --git a/lib/VMCore/iOperators.cpp b/lib/VMCore/iOperators.cpp index cb53d5e0344..c2fe1bc04a1 100644 --- a/lib/VMCore/iOperators.cpp +++ b/lib/VMCore/iOperators.cpp @@ -6,6 +6,8 @@ #include "llvm/iOperators.h" #include "llvm/Type.h" +#include +using std::cerr; //===----------------------------------------------------------------------===// // UnaryOperator Class @@ -15,7 +17,7 @@ UnaryOperator *UnaryOperator::create(UnaryOps Op, Value *Source) { switch (Op) { case Not: return new GenericUnaryInst(Op, Source); default: - cerr << "Don't know how to Create UnaryOperator " << Op << endl; + cerr << "Don't know how to Create UnaryOperator " << Op << "\n"; return 0; } } @@ -30,9 +32,10 @@ const char *GenericUnaryInst::getOpcodeName() const { case Not: return "not"; case Cast: return "cast"; default: - cerr << "Invalid unary operator type!" << getOpcode() << endl; + cerr << "Invalid unary operator type!" << getOpcode() << "\n"; abort(); } + return 0; } @@ -41,7 +44,7 @@ const char *GenericUnaryInst::getOpcodeName() const { //===----------------------------------------------------------------------===// BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2, - const string &Name) { + const std::string &Name) { switch (Op) { // Binary comparison operators... case SetLT: case SetGT: case SetLE: @@ -75,7 +78,7 @@ bool BinaryOperator::swapOperands() { default: return true; } - swap(Operands[0], Operands[1]); + std::swap(Operands[0], Operands[1]); return false; } @@ -98,9 +101,10 @@ const char *GenericBinaryInst::getOpcodeName() const { case Or : return "or"; case Xor: return "xor"; default: - cerr << "Invalid binary operator type!" << getOpcode() << endl; + cerr << "Invalid binary operator type!" << getOpcode() << "\n"; abort(); } + return 0; } @@ -109,7 +113,7 @@ const char *GenericBinaryInst::getOpcodeName() const { //===----------------------------------------------------------------------===// SetCondInst::SetCondInst(BinaryOps opType, Value *S1, Value *S2, - const string &Name) + const std::string &Name) : BinaryOperator(opType, S1, S2, Name) { OpType = opType; diff --git a/support/lib/Support/Annotation.cpp b/support/lib/Support/Annotation.cpp index 65a049d42dc..d0d13cda866 100644 --- a/support/lib/Support/Annotation.cpp +++ b/support/lib/Support/Annotation.cpp @@ -6,6 +6,10 @@ #include #include "llvm/Annotation.h" +using std::string; +using std::map; +using std::pair; +using std::make_pair; typedef map IDMapType; static unsigned IDCounter = 0; // Unique ID counter diff --git a/support/lib/Support/CommandLine.cpp b/support/lib/Support/CommandLine.cpp index f6938169dab..549f42c4e3b 100644 --- a/support/lib/Support/CommandLine.cpp +++ b/support/lib/Support/CommandLine.cpp @@ -15,7 +15,13 @@ #include #include #include +#include using namespace cl; +using std::map; +using std::pair; +using std::vector; +using std::string; +using std::cerr; // Return the global command line option vector. Making it a function scoped // static ensures that it will be initialized correctly before its first use. @@ -31,7 +37,7 @@ static void AddArgument(const string &ArgName, Option *Opt) { << "' specified more than once!\n"; } else { // Add argument to the argument map! - getOpts().insert(make_pair(ArgName, Opt)); + getOpts().insert(std::make_pair(ArgName, Opt)); } } @@ -59,7 +65,7 @@ static inline bool ProvideOption(Option *Handler, const char *ArgName, break; case ValueOptional: break; default: cerr << "Bad ValueMask flag! CommandLine usage error:" - << Handler->getValueExpectedFlag() << endl; abort(); + << Handler->getValueExpectedFlag() << "\n"; abort(); } // Run the handler now! @@ -210,7 +216,7 @@ Option::Option(const char *argStr, const char *helpStr, int flags) bool Option::error(string Message, const char *ArgName = 0) { if (ArgName == 0) ArgName = ArgStr; - cerr << "-" << ArgName << " option" << Message << endl; + cerr << "-" << ArgName << " option" << Message << "\n"; return true; } @@ -244,7 +250,7 @@ void Option::printOptionInfo(unsigned GlobalWidth) const { unsigned L = std::strlen(ArgStr); if (L == 0) return; // Don't print the empty arg like this! cerr << " -" << ArgStr << string(GlobalWidth-L-6, ' ') << " - " - << HelpStr << endl; + << HelpStr << "\n"; } @@ -301,8 +307,8 @@ void EnumBase::processValues(va_list Vals) { while (const char *EnumName = va_arg(Vals, const char *)) { int EnumVal = va_arg(Vals, int); const char *EnumDesc = va_arg(Vals, const char *); - ValueMap.push_back(make_pair(EnumName, // Add value to value map - make_pair(EnumVal, EnumDesc))); + ValueMap.push_back(std::make_pair(EnumName, // Add value to value map + std::make_pair(EnumVal, EnumDesc))); } } @@ -339,7 +345,7 @@ bool EnumValueBase::handleOccurance(const char *ArgName, const string &Arg) { unsigned EnumValueBase::getOptionWidth() const { unsigned BaseSize = Option::getOptionWidth(); for (unsigned i = 0; i < ValueMap.size(); ++i) - BaseSize = max(BaseSize, std::strlen(ValueMap[i].first)+8); + BaseSize = std::max(BaseSize, std::strlen(ValueMap[i].first)+8); return BaseSize; } @@ -354,7 +360,7 @@ void EnumValueBase::printOptionInfo(unsigned GlobalWidth) const { << ValueMap[i].second.second; if (i == 0) cerr << " (default)"; - cerr << endl; + cerr << "\n"; } } @@ -369,7 +375,7 @@ bool EnumFlagsBase::handleOccurance(const char *ArgName, const string &Arg) { unsigned EnumFlagsBase::getOptionWidth() const { unsigned BaseSize = 0; for (unsigned i = 0; i < ValueMap.size(); ++i) - BaseSize = max(BaseSize, std::strlen(ValueMap[i].first)+6); + BaseSize = std::max(BaseSize, std::strlen(ValueMap[i].first)+6); return BaseSize; } @@ -379,7 +385,7 @@ void EnumFlagsBase::printOptionInfo(unsigned GlobalWidth) const { cerr << " -" << ValueMap[i].first << string(GlobalWidth-L-6, ' ') << " - " << ValueMap[i].second.second; if (i == 0) cerr << " (default)"; - cerr << endl; + cerr << "\n"; } } @@ -402,7 +408,7 @@ bool EnumListBase::handleOccurance(const char *ArgName, const string &Arg) { unsigned EnumListBase::getOptionWidth() const { unsigned BaseSize = 0; for (unsigned i = 0; i < ValueMap.size(); ++i) - BaseSize = max(BaseSize, std::strlen(ValueMap[i].first)+6); + BaseSize = std::max(BaseSize, std::strlen(ValueMap[i].first)+6); return BaseSize; } @@ -414,7 +420,7 @@ void EnumListBase::printOptionInfo(unsigned GlobalWidth) const { for (unsigned i = 0; i < ValueMap.size(); ++i) { unsigned L = std::strlen(ValueMap[i].first); cerr << " -" << ValueMap[i].first << string(GlobalWidth-L-6, ' ') << " - " - << ValueMap[i].second.second << endl; + << ValueMap[i].second.second << "\n"; } } @@ -440,15 +446,15 @@ class Help : public Option { virtual bool handleOccurance(const char *ArgName, const string &Arg) { // Copy Options into a vector so we can sort them as we like... vector > Options; - copy(getOpts().begin(), getOpts().end(), back_inserter(Options)); + copy(getOpts().begin(), getOpts().end(), std::back_inserter(Options)); // Eliminate Hidden or ReallyHidden arguments, depending on ShowHidden Options.erase(remove_if(Options.begin(), Options.end(), - ptr_fun(ShowHidden ? isReallyHidden : isHidden)), + std::ptr_fun(ShowHidden ? isReallyHidden : isHidden)), Options.end()); // Eliminate duplicate entries in table (from enum flags options, f.e.) - set OptionSet; + std::set OptionSet; for (unsigned i = 0; i < Options.size(); ) if (OptionSet.count(Options[i].second) == 0) OptionSet.insert(Options[i++].second); // Add to set @@ -457,7 +463,7 @@ class Help : public Option { if (ProgramOverview) - cerr << "OVERVIEW:" << ProgramOverview << endl; + cerr << "OVERVIEW:" << ProgramOverview << "\n"; // TODO: Sort options by some criteria cerr << "USAGE: " << ProgramName << " [options]\n\n"; @@ -478,7 +484,7 @@ class Help : public Option { void getMaxArgLen(pair OptPair) { const Option *Opt = OptPair.second; if (Opt->ArgStr[0] == 0) EmptyArg = Opt; // Capture the empty arg if exists - MaxArgLen = max(MaxArgLen, Opt->getOptionWidth()); + MaxArgLen = std::max(MaxArgLen, Opt->getOptionWidth()); } void printOption(pair OptPair) { diff --git a/support/lib/Support/NameMangling.cpp b/support/lib/Support/NameMangling.cpp index bed520a92bb..2fbcb887e3b 100644 --- a/support/lib/Support/NameMangling.cpp +++ b/support/lib/Support/NameMangling.cpp @@ -7,6 +7,7 @@ #include "llvm/Support/NameMangling.h" #include "llvm/DerivedTypes.h" #include "llvm/GlobalValue.h" +using std::string; // MangleTypeName - Implement a consistent name-mangling scheme for // a given type. diff --git a/tools/analyze/analyze.cpp b/tools/analyze/analyze.cpp index 9a53bd45af1..9241216f347 100644 --- a/tools/analyze/analyze.cpp +++ b/tools/analyze/analyze.cpp @@ -28,6 +28,10 @@ #include "llvm/Analysis/FindUsedTypes.h" #include "Support/CommandLine.h" #include +#include +using std::cout; +using std::cerr; +using std::pair; static void PrintMethod(Method *M) { cout << M; @@ -38,7 +42,7 @@ static void PrintIntervalPartition(Method *M) { } static void PrintClassifiedExprs(Method *M) { - cout << "Classified expressions for: " << M->getName() << endl; + cout << "Classified expressions for: " << M->getName() << "\n"; Method::inst_iterator I = M->inst_begin(), E = M->inst_end(); for (; I != E; ++I) { cout << *I; @@ -61,7 +65,7 @@ static void PrintClassifiedExprs(Method *M) { if (R.Offset) WriteAsOperand(cout, (Value*)R.Offset); else cout << " 0"; break; } - cout << endl << endl; + cout << "\n\n"; } } diff --git a/tools/as/as.cpp b/tools/as/as.cpp index ee664f15249..0fbd1e6cd41 100644 --- a/tools/as/as.cpp +++ b/tools/as/as.cpp @@ -16,6 +16,7 @@ #include "Support/CommandLine.h" #include #include +#include cl::String InputFilename ("", "Parse file, compile to bytecode", 0, "-"); cl::String OutputFilename("o", "Override output filename", cl::NoFlags, ""); @@ -28,46 +29,55 @@ int main(int argc, char **argv) { ostream *Out = 0; try { // Parse the file now... - Module *C = ParseAssemblyFile(InputFilename); - if (C == 0) { + std::auto_ptr C(ParseAssemblyFile(InputFilename)); + if (C.get() == 0) { cerr << "assembly didn't read correctly.\n"; return 1; } if (DumpAsm) - cerr << "Here's the assembly:\n" << C; + cerr << "Here's the assembly:\n" << C.get(); if (OutputFilename != "") { // Specified an output filename? - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + Out = new std::ofstream(OutputFilename.c_str()); } else { if (InputFilename == "-") { OutputFilename = "-"; Out = &cout; } else { - string IFN = InputFilename; + std::string IFN = InputFilename; int Len = IFN.length(); if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') { // Source ends in .ll - OutputFilename = string(IFN.begin(), IFN.end()-3); + OutputFilename = std::string(IFN.begin(), IFN.end()-3); } else { OutputFilename = IFN; // Append a .bc to it } OutputFilename += ".bc"; - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + + Out = new std::ofstream(OutputFilename.c_str()); } + } - if (!Out->good()) { - cerr << "Error opening " << OutputFilename << "!\n"; - delete C; - return 1; - } + if (!Out->good()) { + cerr << "Error opening " << OutputFilename << "!\n"; + return 1; } - WriteBytecodeToFile(C, *Out); - - delete C; + WriteBytecodeToFile(C.get(), *Out); } catch (const ParseException &E) { cerr << E.getMessage() << endl; return 1; diff --git a/tools/dis/dis.cpp b/tools/dis/dis.cpp index 2a7eb4e06ea..55e8d5d6690 100644 --- a/tools/dis/dis.cpp +++ b/tools/dis/dis.cpp @@ -24,6 +24,8 @@ #include "Support/PostOrderIterator.h" #include "Support/CommandLine.h" #include +#include +using std::cerr; // OutputMode - The different orderings to print basic blocks in... enum OutputMode { @@ -47,7 +49,7 @@ cl::EnumFlags WriteMode(cl::NoFlags, int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n"); - ostream *Out = &cout; // Default to printing to stdout... + std::ostream *Out = &std::cout; // Default to printing to stdout... Module *C = ParseBytecodeFile(InputFilename); if (C == 0) { @@ -56,31 +58,41 @@ int main(int argc, char **argv) { } if (OutputFilename != "") { // Specified an output filename? - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename + << "': File exists! Sending to standard output.\n"; + } else { + Out = new std::ofstream(OutputFilename.c_str()); + } } else { if (InputFilename == "-") { OutputFilename = "-"; - Out = &cout; } else { - string IFN = InputFilename; + std::string IFN = InputFilename; int Len = IFN.length(); if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') { // Source ends in .bc - OutputFilename = string(IFN.begin(), IFN.end()-3); + OutputFilename = std::string(IFN.begin(), IFN.end()-3); } else { OutputFilename = IFN; // Append a .ll to it } OutputFilename += ".ll"; - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename + << "': File exists! Sending to standard output.\n"; + } else { + Out = new std::ofstream(OutputFilename.c_str()); + } } } if (!Out->good()) { cerr << "Error opening " << OutputFilename << ": sending to stdout instead!\n"; - Out = &cout; + Out = &std::cout; } // All that dis does is write the assembly out to a file... which is exactly @@ -100,20 +112,20 @@ int main(int argc, char **argv) { switch (WriteMode) { case dfo: // Depth First ordering copy(df_begin(M), df_end(M), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; case rdfo: // Reverse Depth First ordering copy(df_begin(M, true), df_end(M), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; case po: // Post Order copy(po_begin(M), po_end(M), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; case rpo: { // Reverse Post Order ReversePostOrderTraversal RPOT(M); copy(RPOT.begin(), RPOT.end(), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; } default: @@ -124,6 +136,6 @@ int main(int argc, char **argv) { } delete C; - if (Out != &cout) delete Out; + if (Out != &std::cout) delete Out; return 0; } diff --git a/tools/gccas/gccas.cpp b/tools/gccas/gccas.cpp index b9e3a6207db..073b2483499 100644 --- a/tools/gccas/gccas.cpp +++ b/tools/gccas/gccas.cpp @@ -44,17 +44,17 @@ int main(int argc, char **argv) { } if (OutputFilename == "") { // Didn't specify an output filename? - string IFN = InputFilename; + std::string IFN = InputFilename; int Len = IFN.length(); if (IFN[Len-2] == '.' && IFN[Len-1] == 's') { // Source ends in .s? - OutputFilename = string(IFN.begin(), IFN.end()-2); + OutputFilename = std::string(IFN.begin(), IFN.end()-2); } else { OutputFilename = IFN; // Append a .o to it } OutputFilename += ".o"; } - Out = new ofstream(OutputFilename.c_str(), ios::out); + Out = new std::ofstream(OutputFilename.c_str(), ios::out); if (!Out->good()) { cerr << "Error opening " << OutputFilename << "!\n"; return 1; @@ -63,7 +63,7 @@ int main(int argc, char **argv) { // In addition to just parsing the input from GCC, we also want to spiff it up // a little bit. Do this now. // - vector Passes; + std::vector Passes; Passes.push_back(new opt::DeadCodeElimination()); // Remove Dead code/vars Passes.push_back(new CleanupGCCOutput()); // Fix gccisms Passes.push_back(new InductionVariableSimplify()); // Simplify indvars diff --git a/tools/link/link.cpp b/tools/link/link.cpp index 83141c86e7d..ad4cbdbe8cb 100644 --- a/tools/link/link.cpp +++ b/tools/link/link.cpp @@ -19,6 +19,7 @@ #include #include #include // For FileExists +typedef int blksize_t; // SYS/TYPES is broken!!! #include @@ -32,7 +33,7 @@ cl::StringList LibPaths ("L", "Specify a library search path", cl::ZeroOrMore); // FileExists - Return true if the specified string is an openable file... -static inline bool FileExists(const string &FN) { +static inline bool FileExists(const std::string &FN) { struct stat StatBuf; return stat(FN.c_str(), &StatBuf) != -1; } @@ -40,9 +41,9 @@ static inline bool FileExists(const string &FN) { // LoadFile - Read the specified bytecode file in and return it. This routine // searches the link path for the specified file to try to find it... // -static inline std::auto_ptr LoadFile(const string &FN) { - string Filename = FN; - string ErrorMessage; +static inline std::auto_ptr LoadFile(const std::string &FN) { + std::string Filename = FN; + std::string ErrorMessage; unsigned NextLibPathIdx = 0; bool FoundAFile = false; @@ -81,7 +82,7 @@ int main(int argc, char **argv) { assert(InputFilenames.size() > 0 && "OneOrMore is not working"); unsigned BaseArg = 0; - string ErrorMessage; + std::string ErrorMessage; // TODO: TEST argv[0] for llvm-ar forms... for now, this is a huge hack. if (InputFilenames.size() >= 3 && InputFilenames[0] == "rc" && @@ -94,7 +95,7 @@ int main(int argc, char **argv) { if (Composite.get() == 0) return 1; for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) { - auto_ptr M(LoadFile(InputFilenames[i])); + std::auto_ptr M(LoadFile(InputFilenames[i])); if (M.get() == 0) return 1; if (Verbose) cerr << "Linking in '" << InputFilenames[i] << "'\n"; @@ -111,8 +112,13 @@ int main(int argc, char **argv) { ostream *Out = &cout; // Default to printing to stdout... if (OutputFilename != "-") { - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + Out = new std::ofstream(OutputFilename.c_str()); if (!Out->good()) { cerr << "Error opening '" << OutputFilename << "'!\n"; return 1; @@ -122,6 +128,6 @@ int main(int argc, char **argv) { if (Verbose) cerr << "Writing bytecode...\n"; WriteBytecodeToFile(Composite.get(), *Out); - if (Out != &cout) delete Out; + if (Out != &std::cout) delete Out; return 0; } diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 7c8c3a608b6..6b51f79b380 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -19,6 +19,7 @@ #include #include #include +using std::string; cl::String InputFilename ("", "Input filename", cl::NoFlags, "-"); cl::String OutputFilename("o", "Output filename", cl::NoFlags, ""); @@ -78,10 +79,10 @@ public: class EmitAssembly : public Pass { const TargetMachine &Target; // Target to compile for - ostream *Out; // Stream to print on + std::ostream *Out; // Stream to print on bool DeleteStream; // Delete stream in dtor? public: - inline EmitAssembly(const TargetMachine &T, ostream *O, bool D) + inline EmitAssembly(const TargetMachine &T, std::ostream *O, bool D) : Target(T), Out(O), DeleteStream(D) {} @@ -105,20 +106,20 @@ int main(int argc, char **argv) { // Allocate a target... in the future this will be controllable on the // command line. - auto_ptr target(allocateSparcTargetMachine()); + std::auto_ptr target(allocateSparcTargetMachine()); assert(target.get() && "Could not allocate target machine!"); TargetMachine &Target = *target.get(); // Load the module to be compiled... - auto_ptr M(ParseBytecodeFile(InputFilename)); + std::auto_ptr M(ParseBytecodeFile(InputFilename)); if (M.get() == 0) { cerr << "bytecode didn't read correctly.\n"; return 1; } // Build up all of the passes that we want to do to the module... - vector Passes; + std::vector Passes; // Hoist constants out of PHI nodes into predecessor BB's Passes.push_back(new HoistPHIConstants()); @@ -135,8 +136,15 @@ int main(int argc, char **argv) { assert(InputFilename != "-" && "files on stdin not supported with tracing"); string traceFileName = GetFileNameRoot(InputFilename) + ".trace.bc"; - ostream *os = new ofstream(traceFileName.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + + std::ostream *os = new std::ofstream(traceFileName.c_str()); if (!os->good()) { cerr << "Error opening " << traceFileName << "! SKIPPING OUTPUT OF TRACE CODE\n"; @@ -161,19 +169,31 @@ int main(int argc, char **argv) { if (!DoNotEmitAssembly) { // If asm output is enabled... // Figure out where we are going to send the output... - ostream *Out = 0; + std::ostream *Out = 0; if (OutputFilename != "") { // Specified an output filename? - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + Out = new std::ofstream(OutputFilename.c_str()); } else { if (InputFilename == "-") { OutputFilename = "-"; - Out = &cout; + Out = &std::cout; } else { string OutputFilename = GetFileNameRoot(InputFilename); OutputFilename += ".s"; - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + + Out = new std::ofstream(OutputFilename.c_str()); if (!Out->good()) { cerr << "Error opening " << OutputFilename << "!\n"; delete Out; @@ -183,7 +203,7 @@ int main(int argc, char **argv) { } // Output assembly language to the .s file - Passes.push_back(new EmitAssembly(Target, Out, Out != &cout)); + Passes.push_back(new EmitAssembly(Target, Out, Out != &std::cout)); } // Run our queue of passes all at once now, efficiently. This form of diff --git a/tools/llvm-as/as.cpp b/tools/llvm-as/as.cpp index ee664f15249..0fbd1e6cd41 100644 --- a/tools/llvm-as/as.cpp +++ b/tools/llvm-as/as.cpp @@ -16,6 +16,7 @@ #include "Support/CommandLine.h" #include #include +#include cl::String InputFilename ("", "Parse file, compile to bytecode", 0, "-"); cl::String OutputFilename("o", "Override output filename", cl::NoFlags, ""); @@ -28,46 +29,55 @@ int main(int argc, char **argv) { ostream *Out = 0; try { // Parse the file now... - Module *C = ParseAssemblyFile(InputFilename); - if (C == 0) { + std::auto_ptr C(ParseAssemblyFile(InputFilename)); + if (C.get() == 0) { cerr << "assembly didn't read correctly.\n"; return 1; } if (DumpAsm) - cerr << "Here's the assembly:\n" << C; + cerr << "Here's the assembly:\n" << C.get(); if (OutputFilename != "") { // Specified an output filename? - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + Out = new std::ofstream(OutputFilename.c_str()); } else { if (InputFilename == "-") { OutputFilename = "-"; Out = &cout; } else { - string IFN = InputFilename; + std::string IFN = InputFilename; int Len = IFN.length(); if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') { // Source ends in .ll - OutputFilename = string(IFN.begin(), IFN.end()-3); + OutputFilename = std::string(IFN.begin(), IFN.end()-3); } else { OutputFilename = IFN; // Append a .bc to it } OutputFilename += ".bc"; - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + + Out = new std::ofstream(OutputFilename.c_str()); } + } - if (!Out->good()) { - cerr << "Error opening " << OutputFilename << "!\n"; - delete C; - return 1; - } + if (!Out->good()) { + cerr << "Error opening " << OutputFilename << "!\n"; + return 1; } - WriteBytecodeToFile(C, *Out); - - delete C; + WriteBytecodeToFile(C.get(), *Out); } catch (const ParseException &E) { cerr << E.getMessage() << endl; return 1; diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index ee664f15249..0fbd1e6cd41 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -16,6 +16,7 @@ #include "Support/CommandLine.h" #include #include +#include cl::String InputFilename ("", "Parse file, compile to bytecode", 0, "-"); cl::String OutputFilename("o", "Override output filename", cl::NoFlags, ""); @@ -28,46 +29,55 @@ int main(int argc, char **argv) { ostream *Out = 0; try { // Parse the file now... - Module *C = ParseAssemblyFile(InputFilename); - if (C == 0) { + std::auto_ptr C(ParseAssemblyFile(InputFilename)); + if (C.get() == 0) { cerr << "assembly didn't read correctly.\n"; return 1; } if (DumpAsm) - cerr << "Here's the assembly:\n" << C; + cerr << "Here's the assembly:\n" << C.get(); if (OutputFilename != "") { // Specified an output filename? - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + Out = new std::ofstream(OutputFilename.c_str()); } else { if (InputFilename == "-") { OutputFilename = "-"; Out = &cout; } else { - string IFN = InputFilename; + std::string IFN = InputFilename; int Len = IFN.length(); if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') { // Source ends in .ll - OutputFilename = string(IFN.begin(), IFN.end()-3); + OutputFilename = std::string(IFN.begin(), IFN.end()-3); } else { OutputFilename = IFN; // Append a .bc to it } OutputFilename += ".bc"; - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + + Out = new std::ofstream(OutputFilename.c_str()); } + } - if (!Out->good()) { - cerr << "Error opening " << OutputFilename << "!\n"; - delete C; - return 1; - } + if (!Out->good()) { + cerr << "Error opening " << OutputFilename << "!\n"; + return 1; } - WriteBytecodeToFile(C, *Out); - - delete C; + WriteBytecodeToFile(C.get(), *Out); } catch (const ParseException &E) { cerr << E.getMessage() << endl; return 1; diff --git a/tools/llvm-dis/dis.cpp b/tools/llvm-dis/dis.cpp index 2a7eb4e06ea..55e8d5d6690 100644 --- a/tools/llvm-dis/dis.cpp +++ b/tools/llvm-dis/dis.cpp @@ -24,6 +24,8 @@ #include "Support/PostOrderIterator.h" #include "Support/CommandLine.h" #include +#include +using std::cerr; // OutputMode - The different orderings to print basic blocks in... enum OutputMode { @@ -47,7 +49,7 @@ cl::EnumFlags WriteMode(cl::NoFlags, int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n"); - ostream *Out = &cout; // Default to printing to stdout... + std::ostream *Out = &std::cout; // Default to printing to stdout... Module *C = ParseBytecodeFile(InputFilename); if (C == 0) { @@ -56,31 +58,41 @@ int main(int argc, char **argv) { } if (OutputFilename != "") { // Specified an output filename? - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename + << "': File exists! Sending to standard output.\n"; + } else { + Out = new std::ofstream(OutputFilename.c_str()); + } } else { if (InputFilename == "-") { OutputFilename = "-"; - Out = &cout; } else { - string IFN = InputFilename; + std::string IFN = InputFilename; int Len = IFN.length(); if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') { // Source ends in .bc - OutputFilename = string(IFN.begin(), IFN.end()-3); + OutputFilename = std::string(IFN.begin(), IFN.end()-3); } else { OutputFilename = IFN; // Append a .ll to it } OutputFilename += ".ll"; - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename + << "': File exists! Sending to standard output.\n"; + } else { + Out = new std::ofstream(OutputFilename.c_str()); + } } } if (!Out->good()) { cerr << "Error opening " << OutputFilename << ": sending to stdout instead!\n"; - Out = &cout; + Out = &std::cout; } // All that dis does is write the assembly out to a file... which is exactly @@ -100,20 +112,20 @@ int main(int argc, char **argv) { switch (WriteMode) { case dfo: // Depth First ordering copy(df_begin(M), df_end(M), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; case rdfo: // Reverse Depth First ordering copy(df_begin(M, true), df_end(M), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; case po: // Post Order copy(po_begin(M), po_end(M), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; case rpo: { // Reverse Post Order ReversePostOrderTraversal RPOT(M); copy(RPOT.begin(), RPOT.end(), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; } default: @@ -124,6 +136,6 @@ int main(int argc, char **argv) { } delete C; - if (Out != &cout) delete Out; + if (Out != &std::cout) delete Out; return 0; } diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index 2a7eb4e06ea..55e8d5d6690 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -24,6 +24,8 @@ #include "Support/PostOrderIterator.h" #include "Support/CommandLine.h" #include +#include +using std::cerr; // OutputMode - The different orderings to print basic blocks in... enum OutputMode { @@ -47,7 +49,7 @@ cl::EnumFlags WriteMode(cl::NoFlags, int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n"); - ostream *Out = &cout; // Default to printing to stdout... + std::ostream *Out = &std::cout; // Default to printing to stdout... Module *C = ParseBytecodeFile(InputFilename); if (C == 0) { @@ -56,31 +58,41 @@ int main(int argc, char **argv) { } if (OutputFilename != "") { // Specified an output filename? - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename + << "': File exists! Sending to standard output.\n"; + } else { + Out = new std::ofstream(OutputFilename.c_str()); + } } else { if (InputFilename == "-") { OutputFilename = "-"; - Out = &cout; } else { - string IFN = InputFilename; + std::string IFN = InputFilename; int Len = IFN.length(); if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') { // Source ends in .bc - OutputFilename = string(IFN.begin(), IFN.end()-3); + OutputFilename = std::string(IFN.begin(), IFN.end()-3); } else { OutputFilename = IFN; // Append a .ll to it } OutputFilename += ".ll"; - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename + << "': File exists! Sending to standard output.\n"; + } else { + Out = new std::ofstream(OutputFilename.c_str()); + } } } if (!Out->good()) { cerr << "Error opening " << OutputFilename << ": sending to stdout instead!\n"; - Out = &cout; + Out = &std::cout; } // All that dis does is write the assembly out to a file... which is exactly @@ -100,20 +112,20 @@ int main(int argc, char **argv) { switch (WriteMode) { case dfo: // Depth First ordering copy(df_begin(M), df_end(M), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; case rdfo: // Reverse Depth First ordering copy(df_begin(M, true), df_end(M), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; case po: // Post Order copy(po_begin(M), po_end(M), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; case rpo: { // Reverse Post Order ReversePostOrderTraversal RPOT(M); copy(RPOT.begin(), RPOT.end(), - ostream_iterator(*Out, "\n")); + std::ostream_iterator(*Out, "\n")); break; } default: @@ -124,6 +136,6 @@ int main(int argc, char **argv) { } delete C; - if (Out != &cout) delete Out; + if (Out != &std::cout) delete Out; return 0; } diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index 83141c86e7d..ad4cbdbe8cb 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -19,6 +19,7 @@ #include #include #include // For FileExists +typedef int blksize_t; // SYS/TYPES is broken!!! #include @@ -32,7 +33,7 @@ cl::StringList LibPaths ("L", "Specify a library search path", cl::ZeroOrMore); // FileExists - Return true if the specified string is an openable file... -static inline bool FileExists(const string &FN) { +static inline bool FileExists(const std::string &FN) { struct stat StatBuf; return stat(FN.c_str(), &StatBuf) != -1; } @@ -40,9 +41,9 @@ static inline bool FileExists(const string &FN) { // LoadFile - Read the specified bytecode file in and return it. This routine // searches the link path for the specified file to try to find it... // -static inline std::auto_ptr LoadFile(const string &FN) { - string Filename = FN; - string ErrorMessage; +static inline std::auto_ptr LoadFile(const std::string &FN) { + std::string Filename = FN; + std::string ErrorMessage; unsigned NextLibPathIdx = 0; bool FoundAFile = false; @@ -81,7 +82,7 @@ int main(int argc, char **argv) { assert(InputFilenames.size() > 0 && "OneOrMore is not working"); unsigned BaseArg = 0; - string ErrorMessage; + std::string ErrorMessage; // TODO: TEST argv[0] for llvm-ar forms... for now, this is a huge hack. if (InputFilenames.size() >= 3 && InputFilenames[0] == "rc" && @@ -94,7 +95,7 @@ int main(int argc, char **argv) { if (Composite.get() == 0) return 1; for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) { - auto_ptr M(LoadFile(InputFilenames[i])); + std::auto_ptr M(LoadFile(InputFilenames[i])); if (M.get() == 0) return 1; if (Verbose) cerr << "Linking in '" << InputFilenames[i] << "'\n"; @@ -111,8 +112,13 @@ int main(int argc, char **argv) { ostream *Out = &cout; // Default to printing to stdout... if (OutputFilename != "-") { - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + Out = new std::ofstream(OutputFilename.c_str()); if (!Out->good()) { cerr << "Error opening '" << OutputFilename << "'!\n"; return 1; @@ -122,6 +128,6 @@ int main(int argc, char **argv) { if (Verbose) cerr << "Writing bytecode...\n"; WriteBytecodeToFile(Composite.get(), *Out); - if (Out != &cout) delete Out; + if (Out != &std::cout) delete Out; return 0; } diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 9dfb51a4871..8a2208d92d3 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -122,10 +122,16 @@ int main(int argc, char **argv) { for (unsigned i = 0; i < OptimizationList.size(); ++i) RunOptimization(M.get(), OptimizationList[i]); - ostream *Out = &cout; // Default to printing to stdout... + std::ostream *Out = &std::cout; // Default to printing to stdout... if (OutputFilename != "") { - Out = new ofstream(OutputFilename.c_str(), - (Force ? 0 : ios::noreplace)|ios::out); + if (!Force && !std::ifstream(OutputFilename.c_str())) { + // If force is not specified, make sure not to overwrite a file! + cerr << "Error opening '" << OutputFilename << "': File exists!\n" + << "Use -f command line argument to force output\n"; + return 1; + } + Out = new std::ofstream(OutputFilename.c_str()); + if (!Out->good()) { cerr << "Error opening " << OutputFilename << "!\n"; return 1;