Create a new #include "Support/..." directory structure to move things
authorChris Lattner <sabre@nondot.org>
Tue, 27 Nov 2001 00:03:19 +0000 (00:03 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 27 Nov 2001 00:03:19 +0000 (00:03 +0000)
from "llvm/Support/..." that are not llvm dependant.

Move files and fix #includes

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1400 91177308-0d34-0410-b5e6-96231b3b80d8

99 files changed:
docs/CommandLine.html
include/Support/CommandLine.h [new file with mode: 0644]
include/Support/DepthFirstIterator.h [new file with mode: 0644]
include/Support/GraphTraits.h [new file with mode: 0644]
include/Support/HashExtras.h [new file with mode: 0644]
include/Support/MathExtras.h [new file with mode: 0644]
include/Support/NonCopyable.h [new file with mode: 0644]
include/Support/PostOrderIterator.h [new file with mode: 0644]
include/Support/STLExtras.h [new file with mode: 0644]
include/Support/StringExtras.h [new file with mode: 0644]
include/Support/Tree.h [new file with mode: 0644]
include/llvm/ADT/DepthFirstIterator.h [new file with mode: 0644]
include/llvm/ADT/GraphTraits.h [new file with mode: 0644]
include/llvm/ADT/HashExtras.h [new file with mode: 0644]
include/llvm/ADT/PostOrderIterator.h [new file with mode: 0644]
include/llvm/ADT/STLExtras.h [new file with mode: 0644]
include/llvm/ADT/StringExtras.h [new file with mode: 0644]
include/llvm/ADT/Tree.h [new file with mode: 0644]
include/llvm/Analysis/CallGraph.h
include/llvm/Analysis/InstForest.h
include/llvm/BasicBlock.h
include/llvm/CodeGen/InstrForest.h
include/llvm/CodeGen/InstrScheduling.h
include/llvm/CodeGen/MachineInstr.h
include/llvm/CodeGen/RegAllocCommon.h
include/llvm/Support/CommandLine.h [new file with mode: 0644]
include/llvm/Support/DepthFirstIterator.h [deleted file]
include/llvm/Support/GraphTraits.h [deleted file]
include/llvm/Support/HashExtras.h [deleted file]
include/llvm/Support/MathExtras.h [new file with mode: 0644]
include/llvm/Support/NonCopyable.h [deleted file]
include/llvm/Support/PostOrderIterator.h [deleted file]
include/llvm/Support/STLExtras.h [deleted file]
include/llvm/Support/StringExtras.h [deleted file]
include/llvm/Support/Tree.h [deleted file]
include/llvm/Target/TargetFrameInfo.h
include/llvm/Target/TargetMachine.h
include/llvm/Target/TargetRegInfo.h
include/llvm/Type.h
lib/Analysis/IPA/CallGraph.cpp
lib/Analysis/IPA/FindUnsafePointerTypes.cpp
lib/Analysis/IntervalPartition.cpp
lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
lib/Analysis/LoopDepth.cpp
lib/Analysis/LoopInfo.cpp
lib/Analysis/ModuleAnalyzer.cpp
lib/Analysis/PostDominators.cpp
lib/AsmParser/ParserInternals.h
lib/AsmParser/llvmAsmParser.y
lib/Bytecode/Writer/SlotCalculator.cpp
lib/CodeGen/InstrSched/InstrScheduling.cpp
lib/CodeGen/InstrSched/SchedGraph.cpp
lib/CodeGen/InstrSched/SchedGraph.h
lib/CodeGen/InstrSched/SchedPriorities.cpp
lib/CodeGen/InstrSelection/InstrForest.cpp
lib/CodeGen/InstrSelection/InstrSelection.cpp
lib/CodeGen/RegAlloc/RegAllocCommon.h
lib/ExecutionEngine/Interpreter/Execution.cpp
lib/Support/CommandLine.cpp
lib/Target/SparcV9/InstrSched/InstrScheduling.cpp
lib/Target/SparcV9/InstrSched/SchedGraph.cpp
lib/Target/SparcV9/InstrSched/SchedGraph.h
lib/Target/SparcV9/InstrSched/SchedPriorities.cpp
lib/Target/SparcV9/InstrSelection/InstrForest.cpp
lib/Target/SparcV9/InstrSelection/InstrSelection.cpp
lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
lib/Target/SparcV9/RegAlloc/RegAllocCommon.h
lib/Target/SparcV9/SparcV9AsmPrinter.cpp
lib/Target/SparcV9/SparcV9InstrSelection.cpp
lib/Transforms/ExprTypeConvert.cpp
lib/Transforms/IPO/GlobalDCE.cpp
lib/Transforms/Instrumentation/TraceValues.cpp
lib/Transforms/LevelRaise.cpp
lib/Transforms/Scalar/ADCE.cpp
lib/Transforms/Scalar/DCE.cpp
lib/Transforms/Scalar/InductionVars.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/ConstPoolVals.cpp
lib/VMCore/Dominators.cpp
lib/VMCore/Module.cpp
lib/VMCore/SlotCalculator.cpp
lib/VMCore/SymbolTable.cpp
lib/VMCore/Type.cpp
support/lib/Support/CommandLine.cpp
support/lib/Support/StringExtras.cpp [deleted file]
tools/analyze/analyze.cpp
tools/as/as.cpp
tools/dis/dis.cpp
tools/gccas/gccas.cpp
tools/link/link.cpp
tools/llc/llc.cpp
tools/lli/lli.cpp
tools/llvm-as/as.cpp
tools/llvm-as/llvm-as.cpp
tools/llvm-dis/dis.cpp
tools/llvm-dis/llvm-dis.cpp
tools/llvm-link/llvm-link.cpp
tools/opt/opt.cpp

index 1660639dcb18fb058b7d938cb14b1f30ba6260d3..f12525b263ed623d71222212e022369665466d27 100644 (file)
@@ -64,7 +64,7 @@ This section of the manual runs through a simple CommandLine'ification of a util
 To start out, you need to include the CommandLine header file into your program:<p>
 
 <pre>
-  #include "llvm/Support/CommandLine.h"
+  #include "Support/CommandLine.h"
 </pre><p>
 
 Additionally, you need to add this as the first line of your main program:<p>
@@ -353,7 +353,7 @@ Extension Guide: TODO
 <address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
 <!-- Created: Tue Jan 23 15:19:28 CST 2001 -->
 <!-- hhmts start -->
-Last modified: Mon Jul 23 17:33:57 CDT 2001
+Last modified: Mon Nov 26 17:09:39 CST 2001
 <!-- hhmts end -->
 </font>
 </body></html>
diff --git a/include/Support/CommandLine.h b/include/Support/CommandLine.h
new file mode 100644 (file)
index 0000000..84a3bc9
--- /dev/null
@@ -0,0 +1,399 @@
+//===- Support/CommandLine.h - Flexible Command line parser ------*- C++ -*--=//
+//
+// This class implements a command line argument processor that is useful when
+// creating a tool.  It provides a simple, minimalistic interface that is easily
+// extensible and supports nonlocal (library) command line options.
+//
+// Note that rather than trying to figure out what this code does, you could try
+// reading the library documentation located in docs/CommandLine.html
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_COMMANDLINE_H
+#define LLVM_SUPPORT_COMMANDLINE_H
+
+#include <string>
+#include <vector>
+#include <utility>
+#include <stdarg.h>
+
+namespace cl {   // Short namespace to make usage concise
+
+//===----------------------------------------------------------------------===//
+// ParseCommandLineOptions - Minimalistic command line option processing entry
+//
+void cl::ParseCommandLineOptions(int &argc, char **argv,
+                                const char *Overview = 0,
+                                int Flags = 0);
+
+// ParserOptions - This set of option is use to control global behavior of the
+// command line processor.
+//
+enum ParserOptions {
+  // DisableSingleLetterArgGrouping - With this option enabled, multiple letter
+  // options are allowed to bunch together with only a single hyphen for the
+  // whole group.  This allows emulation of the behavior that ls uses for
+  // example:  ls -la === ls -l -a    Providing this option, disables this.
+  //
+  DisableSingleLetterArgGrouping = 0x0001,
+
+  // EnableSingleLetterArgValue - This option allows arguments that are
+  // otherwise unrecognized to match single letter flags that take a value. 
+  // This is useful for cases like a linker, where options are typically of the
+  // form '-lfoo' or '-L../../include' where -l or -L are the actual flags.
+  //
+  EnableSingleLetterArgValue     = 0x0002,
+};
+
+
+//===----------------------------------------------------------------------===//
+// Global flags permitted to be passed to command line arguments
+
+enum FlagsOptions {
+  NoFlags         = 0x00,      // Marker to make explicit that we have no flags
+  Default         = 0x00,      // Equally, marker to use the default flags
+
+  GlobalsMask     = 0x80, 
+};
+
+enum NumOccurances {           // Flags for the number of occurances allowed...
+  Optional        = 0x01,      // Zero or One occurance
+  ZeroOrMore      = 0x02,      // Zero or more occurances allowed
+  Required        = 0x03,      // One occurance required
+  OneOrMore       = 0x04,      // One or more occurances required
+
+  // ConsumeAfter - Marker for a null ("") flag that can be used to indicate
+  // that anything that matches the null marker starts a sequence of options
+  // that all get sent to the null marker.  Thus, for example, all arguments
+  // to LLI are processed until a filename is found.  Once a filename is found,
+  // all of the succeeding arguments are passed, unprocessed, to the null flag.
+  //
+  ConsumeAfter    = 0x05,
+
+  OccurancesMask  = 0x07,
+};
+
+enum ValueExpected {           // Is a value required for the option?
+  ValueOptional   = 0x08,      // The value can oppear... or not
+  ValueRequired   = 0x10,      // The value is required to appear!
+  ValueDisallowed = 0x18,      // A value may not be specified (for flags)
+  ValueMask       = 0x18,
+};
+
+enum OptionHidden {            // Control whether -help shows this option
+  NotHidden       = 0x20,      // Option included in --help & --help-hidden
+  Hidden          = 0x40,      // -help doesn't, but --help-hidden does
+  ReallyHidden    = 0x60,      // Neither --help nor --help-hidden show this arg
+  HiddenMask      = 0x60,
+};
+
+
+//===----------------------------------------------------------------------===//
+// Option Base class
+//
+class Alias;
+class Option {
+  friend void cl::ParseCommandLineOptions(int &, char **, const char *, int);
+  friend class Alias;
+
+  // handleOccurances - Overriden by subclasses to handle the value passed into
+  // 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 enum NumOccurances getNumOccurancesFlagDefault() const { 
+    return Optional;
+  }
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueOptional; 
+  }
+  virtual enum OptionHidden getOptionHiddenFlagDefault() const {
+    return NotHidden;
+  }
+
+  int NumOccurances;          // The number of times specified
+  const int Flags;            // Flags for the argument
+public:
+  const char * const ArgStr;  // The argument string itself (ex: "help", "o")
+  const char * const HelpStr; // The descriptive text message for --help
+
+  inline enum NumOccurances getNumOccurancesFlag() const {
+    int NO = Flags & OccurancesMask;
+    return NO ? (enum NumOccurances)NO : getNumOccurancesFlagDefault();
+  }
+  inline enum ValueExpected getValueExpectedFlag() const {
+    int VE = Flags & ValueMask;
+    return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
+  }
+  inline enum OptionHidden getOptionHiddenFlag() const {
+    int OH = Flags & HiddenMask;
+    return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
+  }
+
+protected:
+  Option(const char *ArgStr, const char *Message, int Flags);
+  Option(int flags) : NumOccurances(0), Flags(flags), ArgStr(""), HelpStr("") {}
+
+public:
+  // Return the width of the option tag for printing...
+  virtual unsigned getOptionWidth() const;
+
+  // printOptionInfo - Print out information about this option.  The 
+  // to-be-maintained width is specified.
+  //
+  virtual void printOptionInfo(unsigned GlobalWidth) const;
+
+  // addOccurance - Wrapper around handleOccurance that enforces Flags
+  //
+  bool addOccurance(const char *ArgName, const string &Value);
+
+  // Prints option name followed by message.  Always returns true.
+  bool error(string Message, const char *ArgName = 0);
+
+public:
+  inline int getNumOccurances() const { return NumOccurances; }
+  virtual ~Option() {}
+};
+
+
+//===----------------------------------------------------------------------===//
+// Aliased command line option (alias this name to a preexisting name)
+//
+class Alias : public Option {
+  Option &AliasFor;
+  virtual bool handleOccurance(const char *ArgName, const string &Arg) {
+    return AliasFor.handleOccurance(AliasFor.ArgStr, Arg);
+  }
+  virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;}
+public:
+  inline Alias(const char *ArgStr, const char *Message, int Flags,
+              Option &aliasFor) : Option(ArgStr, Message, Flags), 
+                                  AliasFor(aliasFor) {}
+};
+
+//===----------------------------------------------------------------------===//
+// Boolean/flag command line option
+//
+class Flag : public Option {
+  bool Value;
+  virtual bool handleOccurance(const char *ArgName, const string &Arg);
+public:
+  inline Flag(const char *ArgStr, const char *Message, int Flags = 0, 
+             bool DefaultVal = 0) : Option(ArgStr, Message, Flags), 
+                                    Value(DefaultVal) {}
+  operator const bool() const { return Value; }
+  inline bool operator=(bool Val) { Value = Val; return Val; }
+};
+
+
+
+//===----------------------------------------------------------------------===//
+// Integer valued command line option
+//
+class Int : public Option {
+  int Value;
+  virtual bool handleOccurance(const char *ArgName, const string &Arg);
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueRequired; 
+  }
+public:
+  inline Int(const char *ArgStr, const char *Help, int Flags = 0,
+            int DefaultVal = 0) : Option(ArgStr, Help, Flags),
+                                  Value(DefaultVal) {}
+  inline operator int() const { return Value; }
+  inline int operator=(int Val) { Value = Val; return Val; }
+};
+
+
+//===----------------------------------------------------------------------===//
+// String valued command line option
+//
+class String : public Option, public string {
+  virtual bool handleOccurance(const char *ArgName, const 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) {}
+
+  inline const string &operator=(const string &Val) { 
+    return string::operator=(Val);
+  }
+};
+
+
+//===----------------------------------------------------------------------===//
+// String list command line option
+//
+class StringList : public Option, public vector<string> {
+
+  virtual enum NumOccurances getNumOccurancesFlagDefault() const { 
+    return ZeroOrMore;
+  }
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueRequired;
+  }
+  virtual bool handleOccurance(const char *ArgName, const string &Arg);
+
+public:
+  inline StringList(const char *ArgStr, const char *Help, int Flags = 0)
+    : Option(ArgStr, Help, Flags) {}
+};
+
+
+//===----------------------------------------------------------------------===//
+// Enum valued command line option
+//
+#define clEnumVal(ENUMVAL, DESC) #ENUMVAL, ENUMVAL, DESC
+#define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, ENUMVAL, DESC
+
+// EnumBase - Base class for all enum/varargs related argument types...
+class EnumBase : public Option {
+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<pair<const char *, pair<int, const char *> > > ValueMap;
+
+  inline EnumBase(const char *ArgStr, const char *Help, int Flags)
+    : Option(ArgStr, Help, Flags) {}
+  inline EnumBase(int Flags) : Option(Flags) {}
+
+  // processValues - Incorporate the specifed varargs arglist into the 
+  // ValueMap.
+  //
+  void processValues(va_list Vals);
+
+  // registerArgs - notify the system about these new arguments
+  void registerArgs();
+
+public:
+  // Turn an enum into the arg name that activates it
+  const char *getArgName(int ID) const;
+  const char *getArgDescription(int ID) const;
+};
+
+class EnumValueBase : public EnumBase {
+protected:
+  int Value;
+  inline EnumValueBase(const char *ArgStr, const char *Help, int Flags)
+    : EnumBase(ArgStr, Help, Flags) {}
+  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);
+
+  // Return the width of the option tag for printing...
+  virtual unsigned getOptionWidth() const;
+
+  // printOptionInfo - Print out information about this option.  The 
+  // to-be-maintained width is specified.
+  //
+  virtual void printOptionInfo(unsigned GlobalWidth) const;
+};
+
+template <class E>  // The enum we are representing
+class Enum : public EnumValueBase {
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueRequired;
+  }
+public:
+  inline Enum(const char *ArgStr, int Flags, const char *Help, ...)
+    : EnumValueBase(ArgStr, Help, Flags) {
+    va_list Values;
+    va_start(Values, Help);
+    processValues(Values);
+    va_end(Values);
+    Value = ValueMap.front().second.first; // Grab default value
+  }
+
+  inline operator E() const { return (E)Value; }
+  inline E operator=(E Val) { Value = Val; return Val; }
+};
+
+
+//===----------------------------------------------------------------------===//
+// Enum flags command line option
+//
+class EnumFlagsBase : public EnumValueBase {
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueDisallowed;
+  }
+protected:
+  virtual bool handleOccurance(const char *ArgName, const string &Arg);
+  inline EnumFlagsBase(int Flags) : EnumValueBase(Flags) {}
+
+  // Return the width of the option tag for printing...
+  virtual unsigned getOptionWidth() const;
+
+  // printOptionInfo - Print out information about this option.  The 
+  // to-be-maintained width is specified.
+  //
+  virtual void printOptionInfo(unsigned GlobalWidth) const;
+};
+
+template <class E>  // The enum we are representing
+class EnumFlags : public EnumFlagsBase {
+public:
+  inline EnumFlags(int Flags, ...) : EnumFlagsBase(Flags) {
+    va_list Values;
+    va_start(Values, Flags);
+    processValues(Values);
+    va_end(Values);
+    registerArgs();
+    Value = ValueMap.front().second.first; // Grab default value
+  }
+
+  inline operator E() const { return (E)Value; }
+  inline E operator=(E Val) { Value = Val; return Val; }
+};
+
+
+//===----------------------------------------------------------------------===//
+// Enum list command line option
+//
+class EnumListBase : public EnumBase {
+  virtual enum NumOccurances getNumOccurancesFlagDefault() const { 
+    return ZeroOrMore;
+  }
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueDisallowed;
+  }
+protected:
+  vector<int> Values;  // The options specified so far.
+
+  inline EnumListBase(int Flags) 
+    : EnumBase(Flags) {}
+  virtual bool handleOccurance(const char *ArgName, const string &Arg);
+
+  // Return the width of the option tag for printing...
+  virtual unsigned getOptionWidth() const;
+
+  // printOptionInfo - Print out information about this option.  The 
+  // to-be-maintained width is specified.
+  //
+  virtual void printOptionInfo(unsigned GlobalWidth) const;
+public:
+  inline unsigned size() { return Values.size(); }
+};
+
+template <class E>  // The enum we are representing
+class EnumList : public EnumListBase {
+public:
+  inline EnumList(int Flags, ...) : EnumListBase(Flags) {
+    va_list Values;
+    va_start(Values, Flags);
+    processValues(Values);
+    va_end(Values);
+    registerArgs();
+  }
+  inline E  operator[](unsigned i) const { return (E)Values[i]; }
+  inline E &operator[](unsigned i)       { return (E&)Values[i]; }
+};
+
+} // End namespace cl
+
+#endif
diff --git a/include/Support/DepthFirstIterator.h b/include/Support/DepthFirstIterator.h
new file mode 100644 (file)
index 0000000..a2d5a9d
--- /dev/null
@@ -0,0 +1,147 @@
+//===- Support/DepthFirstIterator.h - Depth First iterator -------*- C++ -*--=//
+//
+// This file builds on the Support/GraphTraits.h file to build generic depth
+// first graph iterator.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_DEPTH_FIRST_ITERATOR_H
+#define LLVM_SUPPORT_DEPTH_FIRST_ITERATOR_H
+
+#include "Support/GraphTraits.h"
+#include <iterator>
+#include <stack>
+#include <set>
+
+// Generic Depth First Iterator
+template<class GraphT, class GT = GraphTraits<GraphT> >
+class df_iterator : public std::forward_iterator<typename GT::NodeType,
+                                                 ptrdiff_t> {
+  typedef typename GT::NodeType          NodeType;
+  typedef typename GT::ChildIteratorType ChildItTy;
+
+  set<NodeType *>   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<pair<NodeType *, ChildItTy> > VisitStack;
+  const bool Reverse;         // Iterate over children before self?
+private:
+  void reverseEnterNode() {
+    pair<NodeType *, ChildItTy> &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)));
+       reverseEnterNode();
+       return;
+      }
+    }
+  }
+
+  inline df_iterator(NodeType *Node, bool reverse) : Reverse(reverse) {
+    Visited.insert(Node);
+    VisitStack.push(make_pair(Node, GT::child_begin(Node)));
+    if (Reverse) reverseEnterNode();
+  }
+  inline df_iterator() { /* End is when stack is empty */ }
+
+public:
+  typedef df_iterator<GraphT, GT> _Self;
+
+  // Provide static begin and end methods as our public "constructors"
+  static inline _Self begin(GraphT G, bool Reverse = false) {
+    return _Self(GT::getEntryNode(G), Reverse);
+  }
+  static inline _Self end(GraphT G) { return _Self(); }
+
+
+  inline bool operator==(const _Self& x) const { 
+    return VisitStack == x.VisitStack;
+  }
+  inline bool operator!=(const _Self& x) const { return !operator==(x); }
+
+  inline pointer operator*() const { 
+    return VisitStack.top().first;
+  }
+
+  // This is a nonstandard operator-> that dereferences the pointer an extra
+  // time... so that you can actually call methods ON the Node, because
+  // the contained type is a pointer.  This allows BBIt->getTerminator() f.e.
+  //
+  inline NodeType *operator->() const { return operator*(); }
+
+  inline _Self& operator++() {   // Preincrement
+    if (Reverse) {               // Reverse Depth First Iterator
+      if (VisitStack.top().second == GT::child_end(VisitStack.top().first))
+       VisitStack.pop();
+      if (!VisitStack.empty())
+       reverseEnterNode();
+    } else {                     // Normal Depth First Iterator
+      do {
+       pair<NodeType *, ChildItTy> &Top = VisitStack.top();
+       NodeType *Node = Top.first;
+       ChildItTy &It  = Top.second;
+
+       while (It != GT::child_end(Node)) {
+         NodeType *Next = *It++;
+         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)));
+           return *this;
+         }
+       }
+       
+       // Oops, ran out of successors... go up a level on the stack.
+       VisitStack.pop();
+      } while (!VisitStack.empty());
+    }
+    return *this; 
+  }
+
+  inline _Self operator++(int) { // Postincrement
+    _Self tmp = *this; ++*this; return tmp; 
+  }
+
+  // nodeVisited - return true if this iterator has already visited the
+  // specified node.  This is public, and will probably be used to iterate over
+  // nodes that a depth first iteration did not find: ie unreachable nodes.
+  //
+  inline bool nodeVisited(NodeType *Node) const { 
+    return Visited.count(Node) != 0;
+  }
+};
+
+
+// Provide global constructors that automatically figure out correct types...
+//
+template <class T>
+df_iterator<T> df_begin(T G, bool Reverse = false) {
+  return df_iterator<T>::begin(G, Reverse);
+}
+
+template <class T>
+df_iterator<T> df_end(T G) {
+  return df_iterator<T>::end(G);
+}
+
+// Provide global definitions of inverse depth first iterators...
+template <class T>
+struct idf_iterator : public df_iterator<Inverse<T> > {
+  idf_iterator(const df_iterator<Inverse<T> > &V) :df_iterator<Inverse<T> >(V){}
+};
+
+template <class T>
+idf_iterator<T> idf_begin(T G, bool Reverse = false) {
+  return idf_iterator<T>::begin(G, Reverse);
+}
+
+template <class T>
+idf_iterator<T> idf_end(T G){
+  return idf_iterator<T>::end(G);
+}
+
+#endif
diff --git a/include/Support/GraphTraits.h b/include/Support/GraphTraits.h
new file mode 100644 (file)
index 0000000..00973d5
--- /dev/null
@@ -0,0 +1,65 @@
+//===-- Support/GraphTraits.h - Graph traits template ------------*- C++ -*--=//
+//
+// This file defines the little GraphTraits<X> template class that should be 
+// specialized by classes that want to be iteratable by generic graph iterators.
+//
+// This file also defines the marker class Inverse that is used to iterate over
+// graphs in a graph defined, inverse ordering...
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_GRAPH_TRAITS_H
+#define LLVM_SUPPORT_GRAPH_TRAITS_H
+
+// GraphTraits - This class should be specialized by different graph types...
+// which is why the default version is empty.
+//
+template<class GraphType>
+struct GraphTraits {
+  // Elements to provide:
+
+  // typedef NodeType          - Type of Node in the graph
+  // typedef ChildIteratorType - Type used to iterate over children in graph
+
+  // static NodeType *getEntryNode(GraphType *)
+  //    Return the entry node of the graph
+
+  // static ChildIteratorType child_begin(NodeType *)
+  // static ChildIteratorType child_end  (NodeType *)
+  //    Return iterators that point to the beginning and ending of the child 
+  //    node list for the specified node.
+  //  
+
+
+  // If anyone tries to use this class without having an appropriate
+  // specialization, make an error.  If you get this error, it's because you
+  // need to include the appropriate specialization of GraphTraits<> for your
+  // graph, or you need to define it for a new graph type. Either that or 
+  // your argument to XXX_begin(...) is unknown or needs to have the proper .h
+  // file #include'd.
+  //
+  typedef typename GraphType::UnknownGraphTypeError NodeType;
+};
+
+
+// Inverse - This class is used as a little marker class to tell the graph
+// iterator to iterate over the graph in a graph defined "Inverse" ordering.
+// Not all graphs define an inverse ordering, and if they do, it depends on
+// the graph exactly what that is.  Here's an example of usage with the
+// df_iterator:
+//
+// idf_iterator<Method*> I = idf_begin(M), E = idf_end(M);
+// for (; I != E; ++I) { ... }
+//
+// Which is equivalent to:
+// df_iterator<Inverse<Method*> > I = idf_begin(M), E = idf_end(M);
+// for (; I != E; ++I) { ... }
+//
+template <class GraphType>
+struct Inverse {
+  GraphType &Graph;
+
+  inline Inverse(GraphType &G) : Graph(G) {}
+};
+
+#endif
diff --git a/include/Support/HashExtras.h b/include/Support/HashExtras.h
new file mode 100644 (file)
index 0000000..6ea831e
--- /dev/null
@@ -0,0 +1,27 @@
+//===-- HashExtras.h - Useful functions for STL hash containers --*- C++ -*--=//
+//
+// This file contains some templates that are useful if you are working with the
+// STL Hashed containers.
+//
+// No library is required when using these functinons.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_HASHEXTRAS_H
+#define LLVM_SUPPORT_HASHEXTRAS_H
+
+#include <string>
+#include <hash_map>
+
+template <> struct hash<string> {
+  size_t operator()(string const &str) const {
+    return hash<char const *>()(str.c_str());
+  }
+};
+
+// Provide a hash function for arbitrary pointers...
+template <class T> struct hash<T *> {
+  inline size_t operator()(const T *Val) const { return (size_t)Val; }
+};
+
+#endif
diff --git a/include/Support/MathExtras.h b/include/Support/MathExtras.h
new file mode 100644 (file)
index 0000000..f3dc3de
--- /dev/null
@@ -0,0 +1,32 @@
+// $Id$ -*-c++-*-
+//***************************************************************************
+// File:
+//     MathExtras.h
+// 
+// Purpose:
+//     
+// History:
+//     8/25/01  -  Vikram Adve  -  Created
+//**************************************************************************/
+
+#ifndef LLVM_SUPPORT_MATH_EXTRAS_H
+#define LLVM_SUPPORT_MATH_EXTRAS_H
+
+#include <sys/types.h>
+
+inline bool    IsPowerOf2      (int64_t C, unsigned& getPow);
+
+inline
+bool IsPowerOf2(int64_t C, unsigned& getPow)
+{
+  if (C < 0)
+    C = -C;
+  bool isBool = C > 0 && (C == (C & ~(C - 1)));
+  if (isBool)
+    for (getPow = 0; C > 1; getPow++)
+      C = C >> 1;
+  
+  return isBool;
+}
+
+#endif /*LLVM_SUPPORT_MATH_EXTRAS_H*/
diff --git a/include/Support/NonCopyable.h b/include/Support/NonCopyable.h
new file mode 100644 (file)
index 0000000..f4fc268
--- /dev/null
@@ -0,0 +1,37 @@
+//===-- NonCopyable.h - Disable copy ctor and op= in subclasses --*- C++ -*--=//
+//
+// This file defines the NonCopyable and NonCopyableV classes.  These mixin
+// classes may be used to mark a class not being copyable.  You should derive
+// from NonCopyable if you don't want to have a virtual dtor, or NonCopyableV
+// if you do want polymorphic behavior in your class.
+//
+// No library is required when using these functinons.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_NONCOPYABLE_H
+#define LLVM_SUPPORT_NONCOPYABLE_H
+
+class NonCopyable {
+  // Disable the copy constructor and the assignment operator
+  // by making them both private:
+  // 
+  NonCopyable(const NonCopyable &);            // DO NOT IMPLEMENT
+  NonCopyable &operator=(const NonCopyable &); // DO NOT IMPLEMENT
+protected:
+  inline NonCopyable() {}
+  inline ~NonCopyable() {}
+};
+
+class NonCopyableV {
+  // Disable the copy constructor and the assignment operator
+  // by making them both private:
+  // 
+  NonCopyableV(const NonCopyableV &);            // DO NOT IMPLEMENT
+  NonCopyableV &operator=(const NonCopyableV &); // DO NOT IMPLEMENT
+protected:
+  inline NonCopyableV() {}
+  virtual ~NonCopyableV() {}
+};
+
+#endif
diff --git a/include/Support/PostOrderIterator.h b/include/Support/PostOrderIterator.h
new file mode 100644 (file)
index 0000000..89a9b4d
--- /dev/null
@@ -0,0 +1,145 @@
+//===-- Support/PostOrderIterator.h - Generic PostOrder iterator -*- C++ -*--=//
+//
+// This file builds on the Support/GraphTraits.h file to build a generic graph
+// post order iterator.  This should work over any graph type that has a
+// GraphTraits specialization.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_POSTORDER_ITERATOR_H
+#define LLVM_SUPPORT_POSTORDER_ITERATOR_H
+
+#include "Support/GraphTraits.h"
+#include <iterator>
+#include <stack>
+#include <set>
+
+template<class GraphT, class GT = GraphTraits<GraphT> >
+class po_iterator : public std::forward_iterator<typename GT::NodeType,
+                                                 ptrdiff_t> {
+  typedef typename GT::NodeType          NodeType;
+  typedef typename GT::ChildIteratorType ChildItTy;
+
+  set<NodeType *>   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<pair<NodeType *, ChildItTy> > VisitStack;
+
+  void traverseChild() {
+    while (VisitStack.top().second != GT::child_end(VisitStack.top().first)) {
+      NodeType *BB = *VisitStack.top().second++;
+      if (!Visited.count(BB)) {  // If the block is not visited...
+       Visited.insert(BB);
+       VisitStack.push(make_pair(BB, GT::child_begin(BB)));
+      }
+    }
+  }
+
+  inline po_iterator(NodeType *BB) {
+    Visited.insert(BB);
+    VisitStack.push(make_pair(BB, GT::child_begin(BB)));
+    traverseChild();
+  }
+  inline po_iterator() { /* End is when stack is empty */ }
+public:
+  typedef po_iterator<GraphT, GT> _Self;
+
+  // Provide static "constructors"...
+  static inline _Self begin(GraphT G) { return _Self(GT::getEntryNode(G)); }
+  static inline _Self end  (GraphT G) { return _Self(); }
+
+  inline bool operator==(const _Self& x) const { 
+    return VisitStack == x.VisitStack;
+  }
+  inline bool operator!=(const _Self& x) const { return !operator==(x); }
+
+  inline pointer operator*() const { 
+    return VisitStack.top().first;
+  }
+
+  // This is a nonstandard operator-> that dereferences the pointer an extra
+  // time... so that you can actually call methods ON the BasicBlock, because
+  // the contained type is a pointer.  This allows BBIt->getTerminator() f.e.
+  //
+  inline NodeType *operator->() const { return operator*(); }
+
+  inline _Self& operator++() {   // Preincrement
+    VisitStack.pop();
+    if (!VisitStack.empty())
+      traverseChild();
+    return *this; 
+  }
+
+  inline _Self operator++(int) { // Postincrement
+    _Self tmp = *this; ++*this; return tmp; 
+  }
+};
+
+// Provide global constructors that automatically figure out correct types...
+//
+template <class T>
+po_iterator<T> po_begin(T G) { return po_iterator<T>::begin(G); }
+template <class T>
+po_iterator<T> po_end  (T G) { return po_iterator<T>::end(G); }
+
+// Provide global definitions of inverse post order iterators...
+template <class T>
+struct ipo_iterator : public po_iterator<Inverse<T> > {
+  ipo_iterator(const po_iterator<Inverse<T> > &V) :po_iterator<Inverse<T> >(V){}
+};
+
+template <class T>
+ipo_iterator<T> ipo_begin(T G, bool Reverse = false) {
+  return ipo_iterator<T>::begin(G, Reverse);
+}
+
+template <class T>
+ipo_iterator<T> ipo_end(T G){
+  return ipo_iterator<T>::end(G);
+}
+
+
+//===--------------------------------------------------------------------===//
+// Reverse Post Order CFG iterator code
+//===--------------------------------------------------------------------===//
+// 
+// This is used to visit basic blocks in a method in reverse post order.  This
+// class is awkward to use because I don't know a good incremental algorithm to
+// computer RPO from a graph.  Because of this, the construction of the 
+// ReversePostOrderTraversal object is expensive (it must walk the entire graph
+// with a postorder iterator to build the data structures).  The moral of this
+// story is: Don't create more ReversePostOrderTraversal classes than neccesary.
+//
+// This class should be used like this:
+// {
+//   cfg::ReversePostOrderTraversal RPOT(MethodPtr);   // Expensive to create
+//   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
+//      ...
+//   }
+//   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
+//      ...
+//   }
+// }
+//
+
+typedef reverse_iterator<vector<BasicBlock*>::iterator> rpo_iterator;
+// TODO: FIXME: ReversePostOrderTraversal is not generic!
+class ReversePostOrderTraversal {
+  vector<BasicBlock*> Blocks;       // Block list in normal PO order
+  inline void Initialize(BasicBlock *BB) {
+    copy(po_begin(BB), po_end(BB), back_inserter(Blocks));
+  }
+public:
+  inline ReversePostOrderTraversal(Method *M) {
+    Initialize(M->front());
+  }
+  inline ReversePostOrderTraversal(BasicBlock *BB) {
+    Initialize(BB);
+  }
+
+  // Because we want a reverse post order, use reverse iterators from the vector
+  inline rpo_iterator begin() { return Blocks.rbegin(); }
+  inline rpo_iterator end()   { return Blocks.rend(); }
+};
+
+#endif
diff --git a/include/Support/STLExtras.h b/include/Support/STLExtras.h
new file mode 100644 (file)
index 0000000..44d789d
--- /dev/null
@@ -0,0 +1,222 @@
+//===-- STLExtras.h - Useful functions when working with the STL -*- C++ -*--=//
+//
+// This file contains some templates that are useful if you are working with the
+// STL at all.
+//
+// No library is required when using these functinons.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_STL_EXTRAS_H
+#define LLVM_SUPPORT_STL_EXTRAS_H
+
+#include <functional>
+
+//===----------------------------------------------------------------------===//
+//     Extra additions to <functional>
+//===----------------------------------------------------------------------===//
+
+// bind_obj - Often times you want to apply the member function of an object
+// as a unary functor.  This macro is shorthand that makes it happen less
+// verbosely.
+//
+// Example:
+//  struct Summer { void accumulate(int x); }
+//  vector<int> Numbers;
+//  Summer MyS;
+//  for_each(Numbers.begin(), Numbers.end(),
+//           bind_obj(&MyS, &Summer::accumulate));
+//
+// TODO: When I get lots of extra time, convert this from an evil macro
+//
+#define bind_obj(OBJ, METHOD) std::bind1st(std::mem_fun(METHOD), OBJ)
+
+
+// bitwise_or - This is a simple functor that applys operator| on its two 
+// arguments to get a boolean result.
+//
+template<class Ty>
+struct bitwise_or : public binary_function<Ty, Ty, bool> {
+  bool operator()(const Ty& left, const Ty& right) const {
+    return left | right;
+  }
+};
+
+
+// deleter - Very very very simple method that is used to invoke operator
+// delete on something.  It is used like this: 
+//
+//   for_each(V.begin(), B.end(), deleter<cfg::Interval>);
+//
+template <class T> 
+static inline void deleter(T *Ptr) { 
+  delete Ptr; 
+}
+
+
+
+//===----------------------------------------------------------------------===//
+//     Extra additions to <iterator>
+//===----------------------------------------------------------------------===//
+
+// mapped_iterator - This is a simple iterator adapter that causes a function to
+// be dereferenced whenever operator* is invoked on the iterator.
+//
+// It turns out that this is disturbingly similar to boost::transform_iterator
+//
+#if 1
+template <class RootIt, class UnaryFunc>
+class mapped_iterator {
+  RootIt current;
+  UnaryFunc Fn;
+public:
+  typedef typename iterator_traits<RootIt>::iterator_category
+          iterator_category;
+  typedef typename iterator_traits<RootIt>::difference_type
+          difference_type;
+  typedef typename UnaryFunc::result_type value_type;
+  typedef typename UnaryFunc::result_type *pointer;
+  typedef void reference;        // Can't modify value returned by fn
+
+  typedef RootIt iterator_type;
+  typedef mapped_iterator<RootIt, UnaryFunc> _Self;
+
+  inline RootIt &getCurrent() const { return current; }
+
+  inline explicit mapped_iterator(const RootIt &I, UnaryFunc F)
+    : current(I), Fn(F) {}
+  inline mapped_iterator(const mapped_iterator &It)
+    : current(It.current), Fn(It.Fn) {}
+
+  inline value_type operator*() const {   // All this work to do this 
+    return Fn(*current);         // little change
+  }
+
+  _Self& operator++() { ++current; return *this; }
+  _Self& operator--() { --current; return *this; }
+  _Self  operator++(int) { _Self __tmp = *this; ++current; return __tmp; }
+  _Self  operator--(int) { _Self __tmp = *this; --current; return __tmp; }
+  _Self  operator+    (difference_type n) const { return _Self(current + n); }
+  _Self& operator+=   (difference_type n) { current += n; return *this; }
+  _Self  operator-    (difference_type n) const { return _Self(current - n); }
+  _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 current == X.current; }
+  inline bool operator< (const _Self &X) const { return current <  X.current; }
+
+  inline difference_type operator-(const _Self &X) const {
+    return current - X.current;
+  }
+};
+
+template <class _Iterator, class Func>
+inline mapped_iterator<_Iterator, Func> 
+operator+(typename mapped_iterator<_Iterator, Func>::difference_type N,
+          const mapped_iterator<_Iterator, Func>& X) {
+  return mapped_iterator<_Iterator, Func>(X.getCurrent() - N);
+}
+
+#else
+
+// This fails to work, because some iterators are not classes, for example
+// vector iterators are commonly value_type **'s
+template <class RootIt, class UnaryFunc>
+class mapped_iterator : public RootIt {
+  UnaryFunc Fn;
+public:
+  typedef typename UnaryFunc::result_type value_type;
+  typedef typename UnaryFunc::result_type *pointer;
+  typedef void reference;        // Can't modify value returned by fn
+
+  typedef mapped_iterator<RootIt, UnaryFunc> _Self;
+  typedef RootIt super;
+  inline explicit mapped_iterator(const RootIt &I) : super(I) {}
+  inline mapped_iterator(const super &It) : super(It) {}
+
+  inline value_type operator*() const {     // All this work to do 
+    return Fn(super::operator*());   // this little thing
+  }
+};
+#endif
+
+// map_iterator - Provide a convenient way to create mapped_iterators, just like
+// make_pair is useful for creating pairs...
+//
+template <class ItTy, class FuncTy>
+inline mapped_iterator<ItTy, FuncTy> map_iterator(const ItTy &I, FuncTy F) {
+  return mapped_iterator<ItTy, FuncTy>(I, F);
+}
+
+
+//===----------------------------------------------------------------------===//
+//     Extra additions to <algorithm>
+//===----------------------------------------------------------------------===//
+
+// apply_until - Apply a functor to a sequence continually, unless the
+// functor returns true.  Return true if the functor returned true, return false
+// if the functor never returned true.
+//
+template <class InputIt, class Function>
+bool apply_until(InputIt First, InputIt Last, Function Func) {
+  for ( ; First != Last; ++First)
+    if (Func(*First)) return true;
+  return false;
+}
+
+
+// reduce - Reduce a sequence values into a single value, given an initial
+// value and an operator.
+//
+template <class InputIt, class Function, class ValueType>
+ValueType reduce(InputIt First, InputIt Last, Function Func, ValueType Value) {
+  for ( ; First != Last; ++First)
+    Value = Func(*First, Value);
+  return Value;
+}
+
+#if 1   // This is likely to be more efficient
+
+// reduce_apply - Reduce the result of applying a function to each value in a
+// sequence, given an initial value, an operator, a function, and a sequence.
+//
+template <class InputIt, class Function, class ValueType, class TransFunc>
+inline ValueType reduce_apply(InputIt First, InputIt Last, Function Func, 
+                             ValueType Value, TransFunc XForm) {
+  for ( ; First != Last; ++First)
+    Value = Func(XForm(*First), Value);
+  return Value;
+}
+
+#else  // This is arguably more elegant
+
+// reduce_apply - Reduce the result of applying a function to each value in a
+// sequence, given an initial value, an operator, a function, and a sequence.
+//
+template <class InputIt, class Function, class ValueType, class TransFunc>
+inline ValueType reduce_apply2(InputIt First, InputIt Last, Function Func, 
+                              ValueType Value, TransFunc XForm) {
+  return reduce(map_iterator(First, XForm), map_iterator(Last, XForm),
+               Func, Value);
+}
+#endif
+
+
+// reduce_apply_bool - Reduce the result of applying a (bool returning) function
+// to each value in a sequence.  All of the bools returned by the mapped
+// function are bitwise or'd together, and the result is returned.
+//
+template <class InputIt, class Function>
+inline bool reduce_apply_bool(InputIt First, InputIt Last, Function Func) {
+  return reduce_apply(First, Last, bitwise_or<bool>(), false, Func);
+}
+
+
+// map - This function maps the specified input sequence into the specified
+// output iterator, applying a unary function in between.
+//
+template <class InIt, class OutIt, class Functor>
+inline OutIt mapto(InIt Begin, InIt End, OutIt Dest, Functor F) {
+  return copy(map_iterator(Begin, F), map_iterator(End, F), Dest);
+}
+#endif
diff --git a/include/Support/StringExtras.h b/include/Support/StringExtras.h
new file mode 100644 (file)
index 0000000..e67e25c
--- /dev/null
@@ -0,0 +1,69 @@
+//===-- Support/StringExtras.h - Useful string functions ---------*- C++ -*--=//
+//
+// This file contains some functions that are useful when dealing with strings.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SUPPORT_STRING_EXTRAS_H
+#define SUPPORT_STRING_EXTRAS_H
+
+#include "Support/DataTypes.h"
+#include <string>
+#include <stdio.h>
+
+static inline string utostr(uint64_t X, bool isNeg = false) {
+  char Buffer[40];
+  char *BufPtr = Buffer+39;
+
+  *BufPtr = 0;                  // Null terminate buffer...
+  if (X == 0) *--BufPtr = '0';  // Handle special case...
+
+  while (X) {
+    *--BufPtr = '0' + (X % 10);
+    X /= 10;
+  }
+
+  if (isNeg) *--BufPtr = '-';   // Add negative sign...
+
+  return string(BufPtr);
+}
+
+static inline string itostr(int64_t X) {
+  if (X < 0) 
+    return utostr((uint64_t)-X, true);
+  else
+    return utostr((uint64_t)X);
+}
+
+
+static inline string utostr(unsigned X, bool isNeg = false) {
+  char Buffer[20];
+  char *BufPtr = Buffer+19;
+
+  *BufPtr = 0;                  // Null terminate buffer...
+  if (X == 0) *--BufPtr = '0';  // Handle special case...
+
+  while (X) {
+    *--BufPtr = '0' + (X % 10);
+    X /= 10;
+  }
+
+  if (isNeg) *--BufPtr = '-';   // Add negative sign...
+
+  return string(BufPtr);
+}
+
+static inline string itostr(int X) {
+  if (X < 0) 
+    return utostr((unsigned)-X, true);
+  else
+    return utostr((unsigned)X);
+}
+
+static inline string ftostr(double V) {
+  char Buffer[200];
+  snprintf(Buffer, 200, "%e", V);
+  return Buffer;
+}
+
+#endif
diff --git a/include/Support/Tree.h b/include/Support/Tree.h
new file mode 100644 (file)
index 0000000..33b0bb7
--- /dev/null
@@ -0,0 +1,52 @@
+//===- Support/Tree.h - Generic n-way tree structure -------------*- C++ -*--=//
+//
+// This class defines a generic N way tree node structure.  The tree structure
+// is immutable after creation, but the payload contained within it is not.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_TREE_H
+#define LLVM_SUPPORT_TREE_H
+
+#include <vector>
+
+template<class ConcreteTreeNode, class Payload>
+class Tree {
+  vector<ConcreteTreeNode*>    Children;        // This nodes children, if any
+  ConcreteTreeNode            *Parent;          // Parent of this node...
+  Payload                      Data;            // Data held in this node...
+
+protected:
+  void setChildren(const vector<ConcreteTreeNode*> &children) {
+    Children = children;
+  }
+public:
+  inline Tree(ConcreteTreeNode *parent) : Parent(parent) {}
+  inline Tree(const vector<ConcreteTreeNode*> &children, ConcreteTreeNode *par)
+    : Children(children), Parent(par) {}
+
+  inline Tree(const vector<ConcreteTreeNode*> &children, ConcreteTreeNode *par,
+             const Payload &data) 
+    : Children(children), Parent(parent), Data(data) {}
+
+  // Tree dtor - Free all children
+  inline ~Tree() {
+    for (unsigned i = Children.size(); i > 0; --i)
+      delete Children[i-1];
+  }
+
+  // Tree manipulation/walking routines...
+  inline ConcreteTreeNode *getParent() const { return Parent; }
+  inline unsigned getNumChildren() const { return Children.size(); }
+  inline ConcreteTreeNode *getChild(unsigned i) const {
+    assert(i < Children.size() && "Tree::getChild with index out of range!");
+    return Children[i];
+  }
+
+  // Payload access...
+  inline Payload &getTreeData() { return Data; }
+  inline const Payload &getTreeData() const { return Data; }
+};
+
+
+#endif
diff --git a/include/llvm/ADT/DepthFirstIterator.h b/include/llvm/ADT/DepthFirstIterator.h
new file mode 100644 (file)
index 0000000..a2d5a9d
--- /dev/null
@@ -0,0 +1,147 @@
+//===- Support/DepthFirstIterator.h - Depth First iterator -------*- C++ -*--=//
+//
+// This file builds on the Support/GraphTraits.h file to build generic depth
+// first graph iterator.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_DEPTH_FIRST_ITERATOR_H
+#define LLVM_SUPPORT_DEPTH_FIRST_ITERATOR_H
+
+#include "Support/GraphTraits.h"
+#include <iterator>
+#include <stack>
+#include <set>
+
+// Generic Depth First Iterator
+template<class GraphT, class GT = GraphTraits<GraphT> >
+class df_iterator : public std::forward_iterator<typename GT::NodeType,
+                                                 ptrdiff_t> {
+  typedef typename GT::NodeType          NodeType;
+  typedef typename GT::ChildIteratorType ChildItTy;
+
+  set<NodeType *>   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<pair<NodeType *, ChildItTy> > VisitStack;
+  const bool Reverse;         // Iterate over children before self?
+private:
+  void reverseEnterNode() {
+    pair<NodeType *, ChildItTy> &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)));
+       reverseEnterNode();
+       return;
+      }
+    }
+  }
+
+  inline df_iterator(NodeType *Node, bool reverse) : Reverse(reverse) {
+    Visited.insert(Node);
+    VisitStack.push(make_pair(Node, GT::child_begin(Node)));
+    if (Reverse) reverseEnterNode();
+  }
+  inline df_iterator() { /* End is when stack is empty */ }
+
+public:
+  typedef df_iterator<GraphT, GT> _Self;
+
+  // Provide static begin and end methods as our public "constructors"
+  static inline _Self begin(GraphT G, bool Reverse = false) {
+    return _Self(GT::getEntryNode(G), Reverse);
+  }
+  static inline _Self end(GraphT G) { return _Self(); }
+
+
+  inline bool operator==(const _Self& x) const { 
+    return VisitStack == x.VisitStack;
+  }
+  inline bool operator!=(const _Self& x) const { return !operator==(x); }
+
+  inline pointer operator*() const { 
+    return VisitStack.top().first;
+  }
+
+  // This is a nonstandard operator-> that dereferences the pointer an extra
+  // time... so that you can actually call methods ON the Node, because
+  // the contained type is a pointer.  This allows BBIt->getTerminator() f.e.
+  //
+  inline NodeType *operator->() const { return operator*(); }
+
+  inline _Self& operator++() {   // Preincrement
+    if (Reverse) {               // Reverse Depth First Iterator
+      if (VisitStack.top().second == GT::child_end(VisitStack.top().first))
+       VisitStack.pop();
+      if (!VisitStack.empty())
+       reverseEnterNode();
+    } else {                     // Normal Depth First Iterator
+      do {
+       pair<NodeType *, ChildItTy> &Top = VisitStack.top();
+       NodeType *Node = Top.first;
+       ChildItTy &It  = Top.second;
+
+       while (It != GT::child_end(Node)) {
+         NodeType *Next = *It++;
+         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)));
+           return *this;
+         }
+       }
+       
+       // Oops, ran out of successors... go up a level on the stack.
+       VisitStack.pop();
+      } while (!VisitStack.empty());
+    }
+    return *this; 
+  }
+
+  inline _Self operator++(int) { // Postincrement
+    _Self tmp = *this; ++*this; return tmp; 
+  }
+
+  // nodeVisited - return true if this iterator has already visited the
+  // specified node.  This is public, and will probably be used to iterate over
+  // nodes that a depth first iteration did not find: ie unreachable nodes.
+  //
+  inline bool nodeVisited(NodeType *Node) const { 
+    return Visited.count(Node) != 0;
+  }
+};
+
+
+// Provide global constructors that automatically figure out correct types...
+//
+template <class T>
+df_iterator<T> df_begin(T G, bool Reverse = false) {
+  return df_iterator<T>::begin(G, Reverse);
+}
+
+template <class T>
+df_iterator<T> df_end(T G) {
+  return df_iterator<T>::end(G);
+}
+
+// Provide global definitions of inverse depth first iterators...
+template <class T>
+struct idf_iterator : public df_iterator<Inverse<T> > {
+  idf_iterator(const df_iterator<Inverse<T> > &V) :df_iterator<Inverse<T> >(V){}
+};
+
+template <class T>
+idf_iterator<T> idf_begin(T G, bool Reverse = false) {
+  return idf_iterator<T>::begin(G, Reverse);
+}
+
+template <class T>
+idf_iterator<T> idf_end(T G){
+  return idf_iterator<T>::end(G);
+}
+
+#endif
diff --git a/include/llvm/ADT/GraphTraits.h b/include/llvm/ADT/GraphTraits.h
new file mode 100644 (file)
index 0000000..00973d5
--- /dev/null
@@ -0,0 +1,65 @@
+//===-- Support/GraphTraits.h - Graph traits template ------------*- C++ -*--=//
+//
+// This file defines the little GraphTraits<X> template class that should be 
+// specialized by classes that want to be iteratable by generic graph iterators.
+//
+// This file also defines the marker class Inverse that is used to iterate over
+// graphs in a graph defined, inverse ordering...
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_GRAPH_TRAITS_H
+#define LLVM_SUPPORT_GRAPH_TRAITS_H
+
+// GraphTraits - This class should be specialized by different graph types...
+// which is why the default version is empty.
+//
+template<class GraphType>
+struct GraphTraits {
+  // Elements to provide:
+
+  // typedef NodeType          - Type of Node in the graph
+  // typedef ChildIteratorType - Type used to iterate over children in graph
+
+  // static NodeType *getEntryNode(GraphType *)
+  //    Return the entry node of the graph
+
+  // static ChildIteratorType child_begin(NodeType *)
+  // static ChildIteratorType child_end  (NodeType *)
+  //    Return iterators that point to the beginning and ending of the child 
+  //    node list for the specified node.
+  //  
+
+
+  // If anyone tries to use this class without having an appropriate
+  // specialization, make an error.  If you get this error, it's because you
+  // need to include the appropriate specialization of GraphTraits<> for your
+  // graph, or you need to define it for a new graph type. Either that or 
+  // your argument to XXX_begin(...) is unknown or needs to have the proper .h
+  // file #include'd.
+  //
+  typedef typename GraphType::UnknownGraphTypeError NodeType;
+};
+
+
+// Inverse - This class is used as a little marker class to tell the graph
+// iterator to iterate over the graph in a graph defined "Inverse" ordering.
+// Not all graphs define an inverse ordering, and if they do, it depends on
+// the graph exactly what that is.  Here's an example of usage with the
+// df_iterator:
+//
+// idf_iterator<Method*> I = idf_begin(M), E = idf_end(M);
+// for (; I != E; ++I) { ... }
+//
+// Which is equivalent to:
+// df_iterator<Inverse<Method*> > I = idf_begin(M), E = idf_end(M);
+// for (; I != E; ++I) { ... }
+//
+template <class GraphType>
+struct Inverse {
+  GraphType &Graph;
+
+  inline Inverse(GraphType &G) : Graph(G) {}
+};
+
+#endif
diff --git a/include/llvm/ADT/HashExtras.h b/include/llvm/ADT/HashExtras.h
new file mode 100644 (file)
index 0000000..6ea831e
--- /dev/null
@@ -0,0 +1,27 @@
+//===-- HashExtras.h - Useful functions for STL hash containers --*- C++ -*--=//
+//
+// This file contains some templates that are useful if you are working with the
+// STL Hashed containers.
+//
+// No library is required when using these functinons.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_HASHEXTRAS_H
+#define LLVM_SUPPORT_HASHEXTRAS_H
+
+#include <string>
+#include <hash_map>
+
+template <> struct hash<string> {
+  size_t operator()(string const &str) const {
+    return hash<char const *>()(str.c_str());
+  }
+};
+
+// Provide a hash function for arbitrary pointers...
+template <class T> struct hash<T *> {
+  inline size_t operator()(const T *Val) const { return (size_t)Val; }
+};
+
+#endif
diff --git a/include/llvm/ADT/PostOrderIterator.h b/include/llvm/ADT/PostOrderIterator.h
new file mode 100644 (file)
index 0000000..89a9b4d
--- /dev/null
@@ -0,0 +1,145 @@
+//===-- Support/PostOrderIterator.h - Generic PostOrder iterator -*- C++ -*--=//
+//
+// This file builds on the Support/GraphTraits.h file to build a generic graph
+// post order iterator.  This should work over any graph type that has a
+// GraphTraits specialization.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_POSTORDER_ITERATOR_H
+#define LLVM_SUPPORT_POSTORDER_ITERATOR_H
+
+#include "Support/GraphTraits.h"
+#include <iterator>
+#include <stack>
+#include <set>
+
+template<class GraphT, class GT = GraphTraits<GraphT> >
+class po_iterator : public std::forward_iterator<typename GT::NodeType,
+                                                 ptrdiff_t> {
+  typedef typename GT::NodeType          NodeType;
+  typedef typename GT::ChildIteratorType ChildItTy;
+
+  set<NodeType *>   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<pair<NodeType *, ChildItTy> > VisitStack;
+
+  void traverseChild() {
+    while (VisitStack.top().second != GT::child_end(VisitStack.top().first)) {
+      NodeType *BB = *VisitStack.top().second++;
+      if (!Visited.count(BB)) {  // If the block is not visited...
+       Visited.insert(BB);
+       VisitStack.push(make_pair(BB, GT::child_begin(BB)));
+      }
+    }
+  }
+
+  inline po_iterator(NodeType *BB) {
+    Visited.insert(BB);
+    VisitStack.push(make_pair(BB, GT::child_begin(BB)));
+    traverseChild();
+  }
+  inline po_iterator() { /* End is when stack is empty */ }
+public:
+  typedef po_iterator<GraphT, GT> _Self;
+
+  // Provide static "constructors"...
+  static inline _Self begin(GraphT G) { return _Self(GT::getEntryNode(G)); }
+  static inline _Self end  (GraphT G) { return _Self(); }
+
+  inline bool operator==(const _Self& x) const { 
+    return VisitStack == x.VisitStack;
+  }
+  inline bool operator!=(const _Self& x) const { return !operator==(x); }
+
+  inline pointer operator*() const { 
+    return VisitStack.top().first;
+  }
+
+  // This is a nonstandard operator-> that dereferences the pointer an extra
+  // time... so that you can actually call methods ON the BasicBlock, because
+  // the contained type is a pointer.  This allows BBIt->getTerminator() f.e.
+  //
+  inline NodeType *operator->() const { return operator*(); }
+
+  inline _Self& operator++() {   // Preincrement
+    VisitStack.pop();
+    if (!VisitStack.empty())
+      traverseChild();
+    return *this; 
+  }
+
+  inline _Self operator++(int) { // Postincrement
+    _Self tmp = *this; ++*this; return tmp; 
+  }
+};
+
+// Provide global constructors that automatically figure out correct types...
+//
+template <class T>
+po_iterator<T> po_begin(T G) { return po_iterator<T>::begin(G); }
+template <class T>
+po_iterator<T> po_end  (T G) { return po_iterator<T>::end(G); }
+
+// Provide global definitions of inverse post order iterators...
+template <class T>
+struct ipo_iterator : public po_iterator<Inverse<T> > {
+  ipo_iterator(const po_iterator<Inverse<T> > &V) :po_iterator<Inverse<T> >(V){}
+};
+
+template <class T>
+ipo_iterator<T> ipo_begin(T G, bool Reverse = false) {
+  return ipo_iterator<T>::begin(G, Reverse);
+}
+
+template <class T>
+ipo_iterator<T> ipo_end(T G){
+  return ipo_iterator<T>::end(G);
+}
+
+
+//===--------------------------------------------------------------------===//
+// Reverse Post Order CFG iterator code
+//===--------------------------------------------------------------------===//
+// 
+// This is used to visit basic blocks in a method in reverse post order.  This
+// class is awkward to use because I don't know a good incremental algorithm to
+// computer RPO from a graph.  Because of this, the construction of the 
+// ReversePostOrderTraversal object is expensive (it must walk the entire graph
+// with a postorder iterator to build the data structures).  The moral of this
+// story is: Don't create more ReversePostOrderTraversal classes than neccesary.
+//
+// This class should be used like this:
+// {
+//   cfg::ReversePostOrderTraversal RPOT(MethodPtr);   // Expensive to create
+//   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
+//      ...
+//   }
+//   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
+//      ...
+//   }
+// }
+//
+
+typedef reverse_iterator<vector<BasicBlock*>::iterator> rpo_iterator;
+// TODO: FIXME: ReversePostOrderTraversal is not generic!
+class ReversePostOrderTraversal {
+  vector<BasicBlock*> Blocks;       // Block list in normal PO order
+  inline void Initialize(BasicBlock *BB) {
+    copy(po_begin(BB), po_end(BB), back_inserter(Blocks));
+  }
+public:
+  inline ReversePostOrderTraversal(Method *M) {
+    Initialize(M->front());
+  }
+  inline ReversePostOrderTraversal(BasicBlock *BB) {
+    Initialize(BB);
+  }
+
+  // Because we want a reverse post order, use reverse iterators from the vector
+  inline rpo_iterator begin() { return Blocks.rbegin(); }
+  inline rpo_iterator end()   { return Blocks.rend(); }
+};
+
+#endif
diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h
new file mode 100644 (file)
index 0000000..44d789d
--- /dev/null
@@ -0,0 +1,222 @@
+//===-- STLExtras.h - Useful functions when working with the STL -*- C++ -*--=//
+//
+// This file contains some templates that are useful if you are working with the
+// STL at all.
+//
+// No library is required when using these functinons.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_STL_EXTRAS_H
+#define LLVM_SUPPORT_STL_EXTRAS_H
+
+#include <functional>
+
+//===----------------------------------------------------------------------===//
+//     Extra additions to <functional>
+//===----------------------------------------------------------------------===//
+
+// bind_obj - Often times you want to apply the member function of an object
+// as a unary functor.  This macro is shorthand that makes it happen less
+// verbosely.
+//
+// Example:
+//  struct Summer { void accumulate(int x); }
+//  vector<int> Numbers;
+//  Summer MyS;
+//  for_each(Numbers.begin(), Numbers.end(),
+//           bind_obj(&MyS, &Summer::accumulate));
+//
+// TODO: When I get lots of extra time, convert this from an evil macro
+//
+#define bind_obj(OBJ, METHOD) std::bind1st(std::mem_fun(METHOD), OBJ)
+
+
+// bitwise_or - This is a simple functor that applys operator| on its two 
+// arguments to get a boolean result.
+//
+template<class Ty>
+struct bitwise_or : public binary_function<Ty, Ty, bool> {
+  bool operator()(const Ty& left, const Ty& right) const {
+    return left | right;
+  }
+};
+
+
+// deleter - Very very very simple method that is used to invoke operator
+// delete on something.  It is used like this: 
+//
+//   for_each(V.begin(), B.end(), deleter<cfg::Interval>);
+//
+template <class T> 
+static inline void deleter(T *Ptr) { 
+  delete Ptr; 
+}
+
+
+
+//===----------------------------------------------------------------------===//
+//     Extra additions to <iterator>
+//===----------------------------------------------------------------------===//
+
+// mapped_iterator - This is a simple iterator adapter that causes a function to
+// be dereferenced whenever operator* is invoked on the iterator.
+//
+// It turns out that this is disturbingly similar to boost::transform_iterator
+//
+#if 1
+template <class RootIt, class UnaryFunc>
+class mapped_iterator {
+  RootIt current;
+  UnaryFunc Fn;
+public:
+  typedef typename iterator_traits<RootIt>::iterator_category
+          iterator_category;
+  typedef typename iterator_traits<RootIt>::difference_type
+          difference_type;
+  typedef typename UnaryFunc::result_type value_type;
+  typedef typename UnaryFunc::result_type *pointer;
+  typedef void reference;        // Can't modify value returned by fn
+
+  typedef RootIt iterator_type;
+  typedef mapped_iterator<RootIt, UnaryFunc> _Self;
+
+  inline RootIt &getCurrent() const { return current; }
+
+  inline explicit mapped_iterator(const RootIt &I, UnaryFunc F)
+    : current(I), Fn(F) {}
+  inline mapped_iterator(const mapped_iterator &It)
+    : current(It.current), Fn(It.Fn) {}
+
+  inline value_type operator*() const {   // All this work to do this 
+    return Fn(*current);         // little change
+  }
+
+  _Self& operator++() { ++current; return *this; }
+  _Self& operator--() { --current; return *this; }
+  _Self  operator++(int) { _Self __tmp = *this; ++current; return __tmp; }
+  _Self  operator--(int) { _Self __tmp = *this; --current; return __tmp; }
+  _Self  operator+    (difference_type n) const { return _Self(current + n); }
+  _Self& operator+=   (difference_type n) { current += n; return *this; }
+  _Self  operator-    (difference_type n) const { return _Self(current - n); }
+  _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 current == X.current; }
+  inline bool operator< (const _Self &X) const { return current <  X.current; }
+
+  inline difference_type operator-(const _Self &X) const {
+    return current - X.current;
+  }
+};
+
+template <class _Iterator, class Func>
+inline mapped_iterator<_Iterator, Func> 
+operator+(typename mapped_iterator<_Iterator, Func>::difference_type N,
+          const mapped_iterator<_Iterator, Func>& X) {
+  return mapped_iterator<_Iterator, Func>(X.getCurrent() - N);
+}
+
+#else
+
+// This fails to work, because some iterators are not classes, for example
+// vector iterators are commonly value_type **'s
+template <class RootIt, class UnaryFunc>
+class mapped_iterator : public RootIt {
+  UnaryFunc Fn;
+public:
+  typedef typename UnaryFunc::result_type value_type;
+  typedef typename UnaryFunc::result_type *pointer;
+  typedef void reference;        // Can't modify value returned by fn
+
+  typedef mapped_iterator<RootIt, UnaryFunc> _Self;
+  typedef RootIt super;
+  inline explicit mapped_iterator(const RootIt &I) : super(I) {}
+  inline mapped_iterator(const super &It) : super(It) {}
+
+  inline value_type operator*() const {     // All this work to do 
+    return Fn(super::operator*());   // this little thing
+  }
+};
+#endif
+
+// map_iterator - Provide a convenient way to create mapped_iterators, just like
+// make_pair is useful for creating pairs...
+//
+template <class ItTy, class FuncTy>
+inline mapped_iterator<ItTy, FuncTy> map_iterator(const ItTy &I, FuncTy F) {
+  return mapped_iterator<ItTy, FuncTy>(I, F);
+}
+
+
+//===----------------------------------------------------------------------===//
+//     Extra additions to <algorithm>
+//===----------------------------------------------------------------------===//
+
+// apply_until - Apply a functor to a sequence continually, unless the
+// functor returns true.  Return true if the functor returned true, return false
+// if the functor never returned true.
+//
+template <class InputIt, class Function>
+bool apply_until(InputIt First, InputIt Last, Function Func) {
+  for ( ; First != Last; ++First)
+    if (Func(*First)) return true;
+  return false;
+}
+
+
+// reduce - Reduce a sequence values into a single value, given an initial
+// value and an operator.
+//
+template <class InputIt, class Function, class ValueType>
+ValueType reduce(InputIt First, InputIt Last, Function Func, ValueType Value) {
+  for ( ; First != Last; ++First)
+    Value = Func(*First, Value);
+  return Value;
+}
+
+#if 1   // This is likely to be more efficient
+
+// reduce_apply - Reduce the result of applying a function to each value in a
+// sequence, given an initial value, an operator, a function, and a sequence.
+//
+template <class InputIt, class Function, class ValueType, class TransFunc>
+inline ValueType reduce_apply(InputIt First, InputIt Last, Function Func, 
+                             ValueType Value, TransFunc XForm) {
+  for ( ; First != Last; ++First)
+    Value = Func(XForm(*First), Value);
+  return Value;
+}
+
+#else  // This is arguably more elegant
+
+// reduce_apply - Reduce the result of applying a function to each value in a
+// sequence, given an initial value, an operator, a function, and a sequence.
+//
+template <class InputIt, class Function, class ValueType, class TransFunc>
+inline ValueType reduce_apply2(InputIt First, InputIt Last, Function Func, 
+                              ValueType Value, TransFunc XForm) {
+  return reduce(map_iterator(First, XForm), map_iterator(Last, XForm),
+               Func, Value);
+}
+#endif
+
+
+// reduce_apply_bool - Reduce the result of applying a (bool returning) function
+// to each value in a sequence.  All of the bools returned by the mapped
+// function are bitwise or'd together, and the result is returned.
+//
+template <class InputIt, class Function>
+inline bool reduce_apply_bool(InputIt First, InputIt Last, Function Func) {
+  return reduce_apply(First, Last, bitwise_or<bool>(), false, Func);
+}
+
+
+// map - This function maps the specified input sequence into the specified
+// output iterator, applying a unary function in between.
+//
+template <class InIt, class OutIt, class Functor>
+inline OutIt mapto(InIt Begin, InIt End, OutIt Dest, Functor F) {
+  return copy(map_iterator(Begin, F), map_iterator(End, F), Dest);
+}
+#endif
diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h
new file mode 100644 (file)
index 0000000..e67e25c
--- /dev/null
@@ -0,0 +1,69 @@
+//===-- Support/StringExtras.h - Useful string functions ---------*- C++ -*--=//
+//
+// This file contains some functions that are useful when dealing with strings.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SUPPORT_STRING_EXTRAS_H
+#define SUPPORT_STRING_EXTRAS_H
+
+#include "Support/DataTypes.h"
+#include <string>
+#include <stdio.h>
+
+static inline string utostr(uint64_t X, bool isNeg = false) {
+  char Buffer[40];
+  char *BufPtr = Buffer+39;
+
+  *BufPtr = 0;                  // Null terminate buffer...
+  if (X == 0) *--BufPtr = '0';  // Handle special case...
+
+  while (X) {
+    *--BufPtr = '0' + (X % 10);
+    X /= 10;
+  }
+
+  if (isNeg) *--BufPtr = '-';   // Add negative sign...
+
+  return string(BufPtr);
+}
+
+static inline string itostr(int64_t X) {
+  if (X < 0) 
+    return utostr((uint64_t)-X, true);
+  else
+    return utostr((uint64_t)X);
+}
+
+
+static inline string utostr(unsigned X, bool isNeg = false) {
+  char Buffer[20];
+  char *BufPtr = Buffer+19;
+
+  *BufPtr = 0;                  // Null terminate buffer...
+  if (X == 0) *--BufPtr = '0';  // Handle special case...
+
+  while (X) {
+    *--BufPtr = '0' + (X % 10);
+    X /= 10;
+  }
+
+  if (isNeg) *--BufPtr = '-';   // Add negative sign...
+
+  return string(BufPtr);
+}
+
+static inline string itostr(int X) {
+  if (X < 0) 
+    return utostr((unsigned)-X, true);
+  else
+    return utostr((unsigned)X);
+}
+
+static inline string ftostr(double V) {
+  char Buffer[200];
+  snprintf(Buffer, 200, "%e", V);
+  return Buffer;
+}
+
+#endif
diff --git a/include/llvm/ADT/Tree.h b/include/llvm/ADT/Tree.h
new file mode 100644 (file)
index 0000000..33b0bb7
--- /dev/null
@@ -0,0 +1,52 @@
+//===- Support/Tree.h - Generic n-way tree structure -------------*- C++ -*--=//
+//
+// This class defines a generic N way tree node structure.  The tree structure
+// is immutable after creation, but the payload contained within it is not.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_TREE_H
+#define LLVM_SUPPORT_TREE_H
+
+#include <vector>
+
+template<class ConcreteTreeNode, class Payload>
+class Tree {
+  vector<ConcreteTreeNode*>    Children;        // This nodes children, if any
+  ConcreteTreeNode            *Parent;          // Parent of this node...
+  Payload                      Data;            // Data held in this node...
+
+protected:
+  void setChildren(const vector<ConcreteTreeNode*> &children) {
+    Children = children;
+  }
+public:
+  inline Tree(ConcreteTreeNode *parent) : Parent(parent) {}
+  inline Tree(const vector<ConcreteTreeNode*> &children, ConcreteTreeNode *par)
+    : Children(children), Parent(par) {}
+
+  inline Tree(const vector<ConcreteTreeNode*> &children, ConcreteTreeNode *par,
+             const Payload &data) 
+    : Children(children), Parent(parent), Data(data) {}
+
+  // Tree dtor - Free all children
+  inline ~Tree() {
+    for (unsigned i = Children.size(); i > 0; --i)
+      delete Children[i-1];
+  }
+
+  // Tree manipulation/walking routines...
+  inline ConcreteTreeNode *getParent() const { return Parent; }
+  inline unsigned getNumChildren() const { return Children.size(); }
+  inline ConcreteTreeNode *getChild(unsigned i) const {
+    assert(i < Children.size() && "Tree::getChild with index out of range!");
+    return Children[i];
+  }
+
+  // Payload access...
+  inline Payload &getTreeData() { return Data; }
+  inline const Payload &getTreeData() const { return Data; }
+};
+
+
+#endif
index 62b1846952ba0f3ce0ca9c7bd050b04a29573524..8365a4f397c290d70ea86f329cae09ab3f297de2 100644 (file)
@@ -16,7 +16,7 @@
 #ifndef LLVM_ANALYSIS_CALLGRAPH_H
 #define LLVM_ANALYSIS_CALLGRAPH_H
 
-#include "llvm/Support/GraphTraits.h"
+#include "Support/GraphTraits.h"
 #include <map>
 #include <vector>
 class Method;
index 967ed45ec967022374778e3c89980051a3c4a4b1..497bb46188bb638d4a04ea38762edeb1ec2c8605 100644 (file)
@@ -14,8 +14,8 @@
 #ifndef LLVM_ANALYSIS_INSTFOREST_H
 #define LLVM_ANALYSIS_INSTFOREST_H
 
-#include "llvm/Support/Tree.h"
 #include "llvm/Instruction.h"
+#include "Support/Tree.h"
 #include <map>
 
 namespace analysis {
index cf29cbd00e7ba84dedd1010e2bf8b94faaa36ad2..df9447fb09cea4fc1eed467615e36bd110b82a79 100644 (file)
@@ -24,8 +24,8 @@
 
 #include "llvm/Value.h"
 #include "llvm/ValueHolder.h"
-#include "llvm/Support/GraphTraits.h"
 #include "llvm/InstrTypes.h"
+#include "Support/GraphTraits.h"
 #include <iterator>
 
 class Instruction;
index 1b9af714b9bcb8d7505ad928017c7f152e12fc1f..e7bd3ad145d1631a10479edc72beaad459af68a8 100644 (file)
@@ -24,9 +24,9 @@
 #ifndef LLVM_CODEGEN_INSTRFOREST_H
 #define LLVM_CODEGEN_INSTRFOREST_H
 
-#include "llvm/Support/NonCopyable.h"
-#include "llvm/Support/HashExtras.h"
 #include "llvm/Instruction.h"
+#include "Support/NonCopyable.h"
+#include "Support/HashExtras.h"
 #include <hash_map>
 #include <hash_set>
 
index 8f88a61590a14dbdb9cf9e8c06f3692cd6acae0f..69390fae96676054cf0b7b40f59efd1cdbec96bd 100644 (file)
@@ -12,8 +12,8 @@
 #ifndef LLVM_CODEGEN_INSTR_SCHEDULING_H
 #define LLVM_CODEGEN_INSTR_SCHEDULING_H
 
-#include "llvm/Support/CommandLine.h"
 #include "llvm/CodeGen/MachineInstr.h"
+#include "Support/CommandLine.h"
 
 class Method;
 class SchedulingManager;
index 91ae9def7fc2a7bb6669734ed0ea1a6141f6dc92..a20431848eefdeeb609a83e96bef0b40d009fc14 100644 (file)
 #ifndef LLVM_CODEGEN_MACHINEINSTR_H
 #define LLVM_CODEGEN_MACHINEINSTR_H
 
-#include <iterator>
-#include "llvm/CodeGen/InstrForest.h"
 #include "Support/DataTypes.h"
-#include "llvm/Support/NonCopyable.h"
+#include "Support/NonCopyable.h"
+#include "llvm/CodeGen/InstrForest.h"
 #include "llvm/Target/MachineInstrInfo.h"
 #include "llvm/Annotation.h"
 #include "llvm/Method.h"
+#include <iterator>
 #include <hash_map>
 #include <hash_set>
 #include <values.h>
index 5fa51c034f632d908b01d5cda809343e46bee4fb..02b333113216ff362d990f5abd83ba07f93da927 100644 (file)
@@ -1,5 +1,5 @@
 
-#include "llvm/Support/CommandLine.h"
+#include "Support/CommandLine.h"
 
 #ifndef REG_ALLOC_COMMON_H
 #define  REG_ALLOC_COMMON_H
diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h
new file mode 100644 (file)
index 0000000..84a3bc9
--- /dev/null
@@ -0,0 +1,399 @@
+//===- Support/CommandLine.h - Flexible Command line parser ------*- C++ -*--=//
+//
+// This class implements a command line argument processor that is useful when
+// creating a tool.  It provides a simple, minimalistic interface that is easily
+// extensible and supports nonlocal (library) command line options.
+//
+// Note that rather than trying to figure out what this code does, you could try
+// reading the library documentation located in docs/CommandLine.html
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_COMMANDLINE_H
+#define LLVM_SUPPORT_COMMANDLINE_H
+
+#include <string>
+#include <vector>
+#include <utility>
+#include <stdarg.h>
+
+namespace cl {   // Short namespace to make usage concise
+
+//===----------------------------------------------------------------------===//
+// ParseCommandLineOptions - Minimalistic command line option processing entry
+//
+void cl::ParseCommandLineOptions(int &argc, char **argv,
+                                const char *Overview = 0,
+                                int Flags = 0);
+
+// ParserOptions - This set of option is use to control global behavior of the
+// command line processor.
+//
+enum ParserOptions {
+  // DisableSingleLetterArgGrouping - With this option enabled, multiple letter
+  // options are allowed to bunch together with only a single hyphen for the
+  // whole group.  This allows emulation of the behavior that ls uses for
+  // example:  ls -la === ls -l -a    Providing this option, disables this.
+  //
+  DisableSingleLetterArgGrouping = 0x0001,
+
+  // EnableSingleLetterArgValue - This option allows arguments that are
+  // otherwise unrecognized to match single letter flags that take a value. 
+  // This is useful for cases like a linker, where options are typically of the
+  // form '-lfoo' or '-L../../include' where -l or -L are the actual flags.
+  //
+  EnableSingleLetterArgValue     = 0x0002,
+};
+
+
+//===----------------------------------------------------------------------===//
+// Global flags permitted to be passed to command line arguments
+
+enum FlagsOptions {
+  NoFlags         = 0x00,      // Marker to make explicit that we have no flags
+  Default         = 0x00,      // Equally, marker to use the default flags
+
+  GlobalsMask     = 0x80, 
+};
+
+enum NumOccurances {           // Flags for the number of occurances allowed...
+  Optional        = 0x01,      // Zero or One occurance
+  ZeroOrMore      = 0x02,      // Zero or more occurances allowed
+  Required        = 0x03,      // One occurance required
+  OneOrMore       = 0x04,      // One or more occurances required
+
+  // ConsumeAfter - Marker for a null ("") flag that can be used to indicate
+  // that anything that matches the null marker starts a sequence of options
+  // that all get sent to the null marker.  Thus, for example, all arguments
+  // to LLI are processed until a filename is found.  Once a filename is found,
+  // all of the succeeding arguments are passed, unprocessed, to the null flag.
+  //
+  ConsumeAfter    = 0x05,
+
+  OccurancesMask  = 0x07,
+};
+
+enum ValueExpected {           // Is a value required for the option?
+  ValueOptional   = 0x08,      // The value can oppear... or not
+  ValueRequired   = 0x10,      // The value is required to appear!
+  ValueDisallowed = 0x18,      // A value may not be specified (for flags)
+  ValueMask       = 0x18,
+};
+
+enum OptionHidden {            // Control whether -help shows this option
+  NotHidden       = 0x20,      // Option included in --help & --help-hidden
+  Hidden          = 0x40,      // -help doesn't, but --help-hidden does
+  ReallyHidden    = 0x60,      // Neither --help nor --help-hidden show this arg
+  HiddenMask      = 0x60,
+};
+
+
+//===----------------------------------------------------------------------===//
+// Option Base class
+//
+class Alias;
+class Option {
+  friend void cl::ParseCommandLineOptions(int &, char **, const char *, int);
+  friend class Alias;
+
+  // handleOccurances - Overriden by subclasses to handle the value passed into
+  // 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 enum NumOccurances getNumOccurancesFlagDefault() const { 
+    return Optional;
+  }
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueOptional; 
+  }
+  virtual enum OptionHidden getOptionHiddenFlagDefault() const {
+    return NotHidden;
+  }
+
+  int NumOccurances;          // The number of times specified
+  const int Flags;            // Flags for the argument
+public:
+  const char * const ArgStr;  // The argument string itself (ex: "help", "o")
+  const char * const HelpStr; // The descriptive text message for --help
+
+  inline enum NumOccurances getNumOccurancesFlag() const {
+    int NO = Flags & OccurancesMask;
+    return NO ? (enum NumOccurances)NO : getNumOccurancesFlagDefault();
+  }
+  inline enum ValueExpected getValueExpectedFlag() const {
+    int VE = Flags & ValueMask;
+    return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
+  }
+  inline enum OptionHidden getOptionHiddenFlag() const {
+    int OH = Flags & HiddenMask;
+    return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
+  }
+
+protected:
+  Option(const char *ArgStr, const char *Message, int Flags);
+  Option(int flags) : NumOccurances(0), Flags(flags), ArgStr(""), HelpStr("") {}
+
+public:
+  // Return the width of the option tag for printing...
+  virtual unsigned getOptionWidth() const;
+
+  // printOptionInfo - Print out information about this option.  The 
+  // to-be-maintained width is specified.
+  //
+  virtual void printOptionInfo(unsigned GlobalWidth) const;
+
+  // addOccurance - Wrapper around handleOccurance that enforces Flags
+  //
+  bool addOccurance(const char *ArgName, const string &Value);
+
+  // Prints option name followed by message.  Always returns true.
+  bool error(string Message, const char *ArgName = 0);
+
+public:
+  inline int getNumOccurances() const { return NumOccurances; }
+  virtual ~Option() {}
+};
+
+
+//===----------------------------------------------------------------------===//
+// Aliased command line option (alias this name to a preexisting name)
+//
+class Alias : public Option {
+  Option &AliasFor;
+  virtual bool handleOccurance(const char *ArgName, const string &Arg) {
+    return AliasFor.handleOccurance(AliasFor.ArgStr, Arg);
+  }
+  virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;}
+public:
+  inline Alias(const char *ArgStr, const char *Message, int Flags,
+              Option &aliasFor) : Option(ArgStr, Message, Flags), 
+                                  AliasFor(aliasFor) {}
+};
+
+//===----------------------------------------------------------------------===//
+// Boolean/flag command line option
+//
+class Flag : public Option {
+  bool Value;
+  virtual bool handleOccurance(const char *ArgName, const string &Arg);
+public:
+  inline Flag(const char *ArgStr, const char *Message, int Flags = 0, 
+             bool DefaultVal = 0) : Option(ArgStr, Message, Flags), 
+                                    Value(DefaultVal) {}
+  operator const bool() const { return Value; }
+  inline bool operator=(bool Val) { Value = Val; return Val; }
+};
+
+
+
+//===----------------------------------------------------------------------===//
+// Integer valued command line option
+//
+class Int : public Option {
+  int Value;
+  virtual bool handleOccurance(const char *ArgName, const string &Arg);
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueRequired; 
+  }
+public:
+  inline Int(const char *ArgStr, const char *Help, int Flags = 0,
+            int DefaultVal = 0) : Option(ArgStr, Help, Flags),
+                                  Value(DefaultVal) {}
+  inline operator int() const { return Value; }
+  inline int operator=(int Val) { Value = Val; return Val; }
+};
+
+
+//===----------------------------------------------------------------------===//
+// String valued command line option
+//
+class String : public Option, public string {
+  virtual bool handleOccurance(const char *ArgName, const 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) {}
+
+  inline const string &operator=(const string &Val) { 
+    return string::operator=(Val);
+  }
+};
+
+
+//===----------------------------------------------------------------------===//
+// String list command line option
+//
+class StringList : public Option, public vector<string> {
+
+  virtual enum NumOccurances getNumOccurancesFlagDefault() const { 
+    return ZeroOrMore;
+  }
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueRequired;
+  }
+  virtual bool handleOccurance(const char *ArgName, const string &Arg);
+
+public:
+  inline StringList(const char *ArgStr, const char *Help, int Flags = 0)
+    : Option(ArgStr, Help, Flags) {}
+};
+
+
+//===----------------------------------------------------------------------===//
+// Enum valued command line option
+//
+#define clEnumVal(ENUMVAL, DESC) #ENUMVAL, ENUMVAL, DESC
+#define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, ENUMVAL, DESC
+
+// EnumBase - Base class for all enum/varargs related argument types...
+class EnumBase : public Option {
+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<pair<const char *, pair<int, const char *> > > ValueMap;
+
+  inline EnumBase(const char *ArgStr, const char *Help, int Flags)
+    : Option(ArgStr, Help, Flags) {}
+  inline EnumBase(int Flags) : Option(Flags) {}
+
+  // processValues - Incorporate the specifed varargs arglist into the 
+  // ValueMap.
+  //
+  void processValues(va_list Vals);
+
+  // registerArgs - notify the system about these new arguments
+  void registerArgs();
+
+public:
+  // Turn an enum into the arg name that activates it
+  const char *getArgName(int ID) const;
+  const char *getArgDescription(int ID) const;
+};
+
+class EnumValueBase : public EnumBase {
+protected:
+  int Value;
+  inline EnumValueBase(const char *ArgStr, const char *Help, int Flags)
+    : EnumBase(ArgStr, Help, Flags) {}
+  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);
+
+  // Return the width of the option tag for printing...
+  virtual unsigned getOptionWidth() const;
+
+  // printOptionInfo - Print out information about this option.  The 
+  // to-be-maintained width is specified.
+  //
+  virtual void printOptionInfo(unsigned GlobalWidth) const;
+};
+
+template <class E>  // The enum we are representing
+class Enum : public EnumValueBase {
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueRequired;
+  }
+public:
+  inline Enum(const char *ArgStr, int Flags, const char *Help, ...)
+    : EnumValueBase(ArgStr, Help, Flags) {
+    va_list Values;
+    va_start(Values, Help);
+    processValues(Values);
+    va_end(Values);
+    Value = ValueMap.front().second.first; // Grab default value
+  }
+
+  inline operator E() const { return (E)Value; }
+  inline E operator=(E Val) { Value = Val; return Val; }
+};
+
+
+//===----------------------------------------------------------------------===//
+// Enum flags command line option
+//
+class EnumFlagsBase : public EnumValueBase {
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueDisallowed;
+  }
+protected:
+  virtual bool handleOccurance(const char *ArgName, const string &Arg);
+  inline EnumFlagsBase(int Flags) : EnumValueBase(Flags) {}
+
+  // Return the width of the option tag for printing...
+  virtual unsigned getOptionWidth() const;
+
+  // printOptionInfo - Print out information about this option.  The 
+  // to-be-maintained width is specified.
+  //
+  virtual void printOptionInfo(unsigned GlobalWidth) const;
+};
+
+template <class E>  // The enum we are representing
+class EnumFlags : public EnumFlagsBase {
+public:
+  inline EnumFlags(int Flags, ...) : EnumFlagsBase(Flags) {
+    va_list Values;
+    va_start(Values, Flags);
+    processValues(Values);
+    va_end(Values);
+    registerArgs();
+    Value = ValueMap.front().second.first; // Grab default value
+  }
+
+  inline operator E() const { return (E)Value; }
+  inline E operator=(E Val) { Value = Val; return Val; }
+};
+
+
+//===----------------------------------------------------------------------===//
+// Enum list command line option
+//
+class EnumListBase : public EnumBase {
+  virtual enum NumOccurances getNumOccurancesFlagDefault() const { 
+    return ZeroOrMore;
+  }
+  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+    return ValueDisallowed;
+  }
+protected:
+  vector<int> Values;  // The options specified so far.
+
+  inline EnumListBase(int Flags) 
+    : EnumBase(Flags) {}
+  virtual bool handleOccurance(const char *ArgName, const string &Arg);
+
+  // Return the width of the option tag for printing...
+  virtual unsigned getOptionWidth() const;
+
+  // printOptionInfo - Print out information about this option.  The 
+  // to-be-maintained width is specified.
+  //
+  virtual void printOptionInfo(unsigned GlobalWidth) const;
+public:
+  inline unsigned size() { return Values.size(); }
+};
+
+template <class E>  // The enum we are representing
+class EnumList : public EnumListBase {
+public:
+  inline EnumList(int Flags, ...) : EnumListBase(Flags) {
+    va_list Values;
+    va_start(Values, Flags);
+    processValues(Values);
+    va_end(Values);
+    registerArgs();
+  }
+  inline E  operator[](unsigned i) const { return (E)Values[i]; }
+  inline E &operator[](unsigned i)       { return (E&)Values[i]; }
+};
+
+} // End namespace cl
+
+#endif
diff --git a/include/llvm/Support/DepthFirstIterator.h b/include/llvm/Support/DepthFirstIterator.h
deleted file mode 100644 (file)
index 7301706..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-//===- llvm/Support/DepthFirstIterator.h - Depth First iterators -*- C++ -*--=//
-//
-// This file builds on the Support/GraphTraits.h file to build generic depth
-// first graph iterator.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_DEPTH_FIRST_ITERATOR_H
-#define LLVM_SUPPORT_DEPTH_FIRST_ITERATOR_H
-
-#include "llvm/Support/GraphTraits.h"
-#include <iterator>
-#include <stack>
-#include <set>
-
-// Generic Depth First Iterator
-template<class GraphT, class GT = GraphTraits<GraphT> >
-class df_iterator : public std::forward_iterator<typename GT::NodeType,
-                                                 ptrdiff_t> {
-  typedef typename GT::NodeType          NodeType;
-  typedef typename GT::ChildIteratorType ChildItTy;
-
-  set<NodeType *>   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<pair<NodeType *, ChildItTy> > VisitStack;
-  const bool Reverse;         // Iterate over children before self?
-private:
-  void reverseEnterNode() {
-    pair<NodeType *, ChildItTy> &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)));
-       reverseEnterNode();
-       return;
-      }
-    }
-  }
-
-  inline df_iterator(NodeType *Node, bool reverse) : Reverse(reverse) {
-    Visited.insert(Node);
-    VisitStack.push(make_pair(Node, GT::child_begin(Node)));
-    if (Reverse) reverseEnterNode();
-  }
-  inline df_iterator() { /* End is when stack is empty */ }
-
-public:
-  typedef df_iterator<GraphT, GT> _Self;
-
-  // Provide static begin and end methods as our public "constructors"
-  static inline _Self begin(GraphT G, bool Reverse = false) {
-    return _Self(GT::getEntryNode(G), Reverse);
-  }
-  static inline _Self end(GraphT G) { return _Self(); }
-
-
-  inline bool operator==(const _Self& x) const { 
-    return VisitStack == x.VisitStack;
-  }
-  inline bool operator!=(const _Self& x) const { return !operator==(x); }
-
-  inline pointer operator*() const { 
-    return VisitStack.top().first;
-  }
-
-  // This is a nonstandard operator-> that dereferences the pointer an extra
-  // time... so that you can actually call methods ON the Node, because
-  // the contained type is a pointer.  This allows BBIt->getTerminator() f.e.
-  //
-  inline NodeType *operator->() const { return operator*(); }
-
-  inline _Self& operator++() {   // Preincrement
-    if (Reverse) {               // Reverse Depth First Iterator
-      if (VisitStack.top().second == GT::child_end(VisitStack.top().first))
-       VisitStack.pop();
-      if (!VisitStack.empty())
-       reverseEnterNode();
-    } else {                     // Normal Depth First Iterator
-      do {
-       pair<NodeType *, ChildItTy> &Top = VisitStack.top();
-       NodeType *Node = Top.first;
-       ChildItTy &It  = Top.second;
-
-       while (It != GT::child_end(Node)) {
-         NodeType *Next = *It++;
-         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)));
-           return *this;
-         }
-       }
-       
-       // Oops, ran out of successors... go up a level on the stack.
-       VisitStack.pop();
-      } while (!VisitStack.empty());
-    }
-    return *this; 
-  }
-
-  inline _Self operator++(int) { // Postincrement
-    _Self tmp = *this; ++*this; return tmp; 
-  }
-
-  // nodeVisited - return true if this iterator has already visited the
-  // specified node.  This is public, and will probably be used to iterate over
-  // nodes that a depth first iteration did not find: ie unreachable nodes.
-  //
-  inline bool nodeVisited(NodeType *Node) const { 
-    return Visited.count(Node) != 0;
-  }
-};
-
-
-// Provide global constructors that automatically figure out correct types...
-//
-template <class T>
-df_iterator<T> df_begin(T G, bool Reverse = false) {
-  return df_iterator<T>::begin(G, Reverse);
-}
-
-template <class T>
-df_iterator<T> df_end(T G) {
-  return df_iterator<T>::end(G);
-}
-
-// Provide global definitions of inverse depth first iterators...
-template <class T>
-struct idf_iterator : public df_iterator<Inverse<T> > {
-  idf_iterator(const df_iterator<Inverse<T> > &V) :df_iterator<Inverse<T> >(V){}
-};
-
-template <class T>
-idf_iterator<T> idf_begin(T G, bool Reverse = false) {
-  return idf_iterator<T>::begin(G, Reverse);
-}
-
-template <class T>
-idf_iterator<T> idf_end(T G){
-  return idf_iterator<T>::end(G);
-}
-
-#endif
diff --git a/include/llvm/Support/GraphTraits.h b/include/llvm/Support/GraphTraits.h
deleted file mode 100644 (file)
index 67fe7c9..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-//===-- llvm/Support/GraphTraits.h - Graph traits template -------*- C++ -*--=//
-//
-// This file defines the little GraphTraits<X> template class that should be 
-// specialized by classes that want to be iteratable by generic graph iterators.
-//
-// This file also defines the marker class Inverse that is used to iterate over
-// graphs in a graph defined, inverse ordering...
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_GRAPH_TRAITS_H
-#define LLVM_SUPPORT_GRAPH_TRAITS_H
-
-// GraphTraits - This class should be specialized by different graph types...
-// which is why the default version is empty.
-//
-template<class GraphType>
-struct GraphTraits {
-  // Elements to provide:
-
-  // typedef NodeType          - Type of Node in the graph
-  // typedef ChildIteratorType - Type used to iterate over children in graph
-
-  // static NodeType *getEntryNode(GraphType *)
-  //    Return the entry node of the graph
-
-  // static ChildIteratorType child_begin(NodeType *)
-  // static ChildIteratorType child_end  (NodeType *)
-  //    Return iterators that point to the beginning and ending of the child 
-  //    node list for the specified node.
-  //  
-
-
-  // If anyone tries to use this class without having an appropriate
-  // specialization, make an error.  If you get this error, it's because you
-  // need to include the appropriate specialization of GraphTraits<> for your
-  // graph, or you need to define it for a new graph type. Either that or 
-  // your argument to XXX_begin(...) is unknown or needs to have the proper .h
-  // file #include'd.
-  //
-  typedef typename GraphType::UnknownGraphTypeError NodeType;
-};
-
-
-// Inverse - This class is used as a little marker class to tell the graph
-// iterator to iterate over the graph in a graph defined "Inverse" ordering.
-// Not all graphs define an inverse ordering, and if they do, it depends on
-// the graph exactly what that is.  Here's an example of usage with the
-// df_iterator:
-//
-// idf_iterator<Method*> I = idf_begin(M), E = idf_end(M);
-// for (; I != E; ++I) { ... }
-//
-// Which is equivalent to:
-// df_iterator<Inverse<Method*> > I = idf_begin(M), E = idf_end(M);
-// for (; I != E; ++I) { ... }
-//
-template <class GraphType>
-struct Inverse {
-  GraphType &Graph;
-
-  inline Inverse(GraphType &G) : Graph(G) {}
-};
-
-#endif
diff --git a/include/llvm/Support/HashExtras.h b/include/llvm/Support/HashExtras.h
deleted file mode 100644 (file)
index 6ea831e..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-//===-- HashExtras.h - Useful functions for STL hash containers --*- C++ -*--=//
-//
-// This file contains some templates that are useful if you are working with the
-// STL Hashed containers.
-//
-// No library is required when using these functinons.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_HASHEXTRAS_H
-#define LLVM_SUPPORT_HASHEXTRAS_H
-
-#include <string>
-#include <hash_map>
-
-template <> struct hash<string> {
-  size_t operator()(string const &str) const {
-    return hash<char const *>()(str.c_str());
-  }
-};
-
-// Provide a hash function for arbitrary pointers...
-template <class T> struct hash<T *> {
-  inline size_t operator()(const T *Val) const { return (size_t)Val; }
-};
-
-#endif
diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h
new file mode 100644 (file)
index 0000000..f3dc3de
--- /dev/null
@@ -0,0 +1,32 @@
+// $Id$ -*-c++-*-
+//***************************************************************************
+// File:
+//     MathExtras.h
+// 
+// Purpose:
+//     
+// History:
+//     8/25/01  -  Vikram Adve  -  Created
+//**************************************************************************/
+
+#ifndef LLVM_SUPPORT_MATH_EXTRAS_H
+#define LLVM_SUPPORT_MATH_EXTRAS_H
+
+#include <sys/types.h>
+
+inline bool    IsPowerOf2      (int64_t C, unsigned& getPow);
+
+inline
+bool IsPowerOf2(int64_t C, unsigned& getPow)
+{
+  if (C < 0)
+    C = -C;
+  bool isBool = C > 0 && (C == (C & ~(C - 1)));
+  if (isBool)
+    for (getPow = 0; C > 1; getPow++)
+      C = C >> 1;
+  
+  return isBool;
+}
+
+#endif /*LLVM_SUPPORT_MATH_EXTRAS_H*/
diff --git a/include/llvm/Support/NonCopyable.h b/include/llvm/Support/NonCopyable.h
deleted file mode 100644 (file)
index f4fc268..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-//===-- NonCopyable.h - Disable copy ctor and op= in subclasses --*- C++ -*--=//
-//
-// This file defines the NonCopyable and NonCopyableV classes.  These mixin
-// classes may be used to mark a class not being copyable.  You should derive
-// from NonCopyable if you don't want to have a virtual dtor, or NonCopyableV
-// if you do want polymorphic behavior in your class.
-//
-// No library is required when using these functinons.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_NONCOPYABLE_H
-#define LLVM_SUPPORT_NONCOPYABLE_H
-
-class NonCopyable {
-  // Disable the copy constructor and the assignment operator
-  // by making them both private:
-  // 
-  NonCopyable(const NonCopyable &);            // DO NOT IMPLEMENT
-  NonCopyable &operator=(const NonCopyable &); // DO NOT IMPLEMENT
-protected:
-  inline NonCopyable() {}
-  inline ~NonCopyable() {}
-};
-
-class NonCopyableV {
-  // Disable the copy constructor and the assignment operator
-  // by making them both private:
-  // 
-  NonCopyableV(const NonCopyableV &);            // DO NOT IMPLEMENT
-  NonCopyableV &operator=(const NonCopyableV &); // DO NOT IMPLEMENT
-protected:
-  inline NonCopyableV() {}
-  virtual ~NonCopyableV() {}
-};
-
-#endif
diff --git a/include/llvm/Support/PostOrderIterator.h b/include/llvm/Support/PostOrderIterator.h
deleted file mode 100644 (file)
index fa135f8..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-//===-- llvm/Support/PostOrderIterator.h - Generic PO iterator ---*- C++ -*--=//
-//
-// This file builds on the Support/GraphTraits.h file to build a generic graph
-// post order iterator.  This should work over any graph type that has a
-// GraphTraits specialization.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_POSTORDER_ITERATOR_H
-#define LLVM_SUPPORT_POSTORDER_ITERATOR_H
-
-#include "llvm/Support/GraphTraits.h"
-#include <iterator>
-#include <stack>
-#include <set>
-
-template<class GraphT, class GT = GraphTraits<GraphT> >
-class po_iterator : public std::forward_iterator<typename GT::NodeType,
-                                                 ptrdiff_t> {
-  typedef typename GT::NodeType          NodeType;
-  typedef typename GT::ChildIteratorType ChildItTy;
-
-  set<NodeType *>   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<pair<NodeType *, ChildItTy> > VisitStack;
-
-  void traverseChild() {
-    while (VisitStack.top().second != GT::child_end(VisitStack.top().first)) {
-      NodeType *BB = *VisitStack.top().second++;
-      if (!Visited.count(BB)) {  // If the block is not visited...
-       Visited.insert(BB);
-       VisitStack.push(make_pair(BB, GT::child_begin(BB)));
-      }
-    }
-  }
-
-  inline po_iterator(NodeType *BB) {
-    Visited.insert(BB);
-    VisitStack.push(make_pair(BB, GT::child_begin(BB)));
-    traverseChild();
-  }
-  inline po_iterator() { /* End is when stack is empty */ }
-public:
-  typedef po_iterator<GraphT, GT> _Self;
-
-  // Provide static "constructors"...
-  static inline _Self begin(GraphT G) { return _Self(GT::getEntryNode(G)); }
-  static inline _Self end  (GraphT G) { return _Self(); }
-
-  inline bool operator==(const _Self& x) const { 
-    return VisitStack == x.VisitStack;
-  }
-  inline bool operator!=(const _Self& x) const { return !operator==(x); }
-
-  inline pointer operator*() const { 
-    return VisitStack.top().first;
-  }
-
-  // This is a nonstandard operator-> that dereferences the pointer an extra
-  // time... so that you can actually call methods ON the BasicBlock, because
-  // the contained type is a pointer.  This allows BBIt->getTerminator() f.e.
-  //
-  inline NodeType *operator->() const { return operator*(); }
-
-  inline _Self& operator++() {   // Preincrement
-    VisitStack.pop();
-    if (!VisitStack.empty())
-      traverseChild();
-    return *this; 
-  }
-
-  inline _Self operator++(int) { // Postincrement
-    _Self tmp = *this; ++*this; return tmp; 
-  }
-};
-
-// Provide global constructors that automatically figure out correct types...
-//
-template <class T>
-po_iterator<T> po_begin(T G) { return po_iterator<T>::begin(G); }
-template <class T>
-po_iterator<T> po_end  (T G) { return po_iterator<T>::end(G); }
-
-// Provide global definitions of inverse post order iterators...
-template <class T>
-struct ipo_iterator : public po_iterator<Inverse<T> > {
-  ipo_iterator(const po_iterator<Inverse<T> > &V) :po_iterator<Inverse<T> >(V){}
-};
-
-template <class T>
-ipo_iterator<T> ipo_begin(T G, bool Reverse = false) {
-  return ipo_iterator<T>::begin(G, Reverse);
-}
-
-template <class T>
-ipo_iterator<T> ipo_end(T G){
-  return ipo_iterator<T>::end(G);
-}
-
-
-//===--------------------------------------------------------------------===//
-// Reverse Post Order CFG iterator code
-//===--------------------------------------------------------------------===//
-// 
-// This is used to visit basic blocks in a method in reverse post order.  This
-// class is awkward to use because I don't know a good incremental algorithm to
-// computer RPO from a graph.  Because of this, the construction of the 
-// ReversePostOrderTraversal object is expensive (it must walk the entire graph
-// with a postorder iterator to build the data structures).  The moral of this
-// story is: Don't create more ReversePostOrderTraversal classes than neccesary.
-//
-// This class should be used like this:
-// {
-//   cfg::ReversePostOrderTraversal RPOT(MethodPtr);   // Expensive to create
-//   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
-//      ...
-//   }
-//   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
-//      ...
-//   }
-// }
-//
-
-typedef reverse_iterator<vector<BasicBlock*>::iterator> rpo_iterator;
-// TODO: FIXME: ReversePostOrderTraversal is not generic!
-class ReversePostOrderTraversal {
-  vector<BasicBlock*> Blocks;       // Block list in normal PO order
-  inline void Initialize(BasicBlock *BB) {
-    copy(po_begin(BB), po_end(BB), back_inserter(Blocks));
-  }
-public:
-  inline ReversePostOrderTraversal(Method *M) {
-    Initialize(M->front());
-  }
-  inline ReversePostOrderTraversal(BasicBlock *BB) {
-    Initialize(BB);
-  }
-
-  // Because we want a reverse post order, use reverse iterators from the vector
-  inline rpo_iterator begin() { return Blocks.rbegin(); }
-  inline rpo_iterator end()   { return Blocks.rend(); }
-};
-
-#endif
diff --git a/include/llvm/Support/STLExtras.h b/include/llvm/Support/STLExtras.h
deleted file mode 100644 (file)
index 44d789d..0000000
+++ /dev/null
@@ -1,222 +0,0 @@
-//===-- STLExtras.h - Useful functions when working with the STL -*- C++ -*--=//
-//
-// This file contains some templates that are useful if you are working with the
-// STL at all.
-//
-// No library is required when using these functinons.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_STL_EXTRAS_H
-#define LLVM_SUPPORT_STL_EXTRAS_H
-
-#include <functional>
-
-//===----------------------------------------------------------------------===//
-//     Extra additions to <functional>
-//===----------------------------------------------------------------------===//
-
-// bind_obj - Often times you want to apply the member function of an object
-// as a unary functor.  This macro is shorthand that makes it happen less
-// verbosely.
-//
-// Example:
-//  struct Summer { void accumulate(int x); }
-//  vector<int> Numbers;
-//  Summer MyS;
-//  for_each(Numbers.begin(), Numbers.end(),
-//           bind_obj(&MyS, &Summer::accumulate));
-//
-// TODO: When I get lots of extra time, convert this from an evil macro
-//
-#define bind_obj(OBJ, METHOD) std::bind1st(std::mem_fun(METHOD), OBJ)
-
-
-// bitwise_or - This is a simple functor that applys operator| on its two 
-// arguments to get a boolean result.
-//
-template<class Ty>
-struct bitwise_or : public binary_function<Ty, Ty, bool> {
-  bool operator()(const Ty& left, const Ty& right) const {
-    return left | right;
-  }
-};
-
-
-// deleter - Very very very simple method that is used to invoke operator
-// delete on something.  It is used like this: 
-//
-//   for_each(V.begin(), B.end(), deleter<cfg::Interval>);
-//
-template <class T> 
-static inline void deleter(T *Ptr) { 
-  delete Ptr; 
-}
-
-
-
-//===----------------------------------------------------------------------===//
-//     Extra additions to <iterator>
-//===----------------------------------------------------------------------===//
-
-// mapped_iterator - This is a simple iterator adapter that causes a function to
-// be dereferenced whenever operator* is invoked on the iterator.
-//
-// It turns out that this is disturbingly similar to boost::transform_iterator
-//
-#if 1
-template <class RootIt, class UnaryFunc>
-class mapped_iterator {
-  RootIt current;
-  UnaryFunc Fn;
-public:
-  typedef typename iterator_traits<RootIt>::iterator_category
-          iterator_category;
-  typedef typename iterator_traits<RootIt>::difference_type
-          difference_type;
-  typedef typename UnaryFunc::result_type value_type;
-  typedef typename UnaryFunc::result_type *pointer;
-  typedef void reference;        // Can't modify value returned by fn
-
-  typedef RootIt iterator_type;
-  typedef mapped_iterator<RootIt, UnaryFunc> _Self;
-
-  inline RootIt &getCurrent() const { return current; }
-
-  inline explicit mapped_iterator(const RootIt &I, UnaryFunc F)
-    : current(I), Fn(F) {}
-  inline mapped_iterator(const mapped_iterator &It)
-    : current(It.current), Fn(It.Fn) {}
-
-  inline value_type operator*() const {   // All this work to do this 
-    return Fn(*current);         // little change
-  }
-
-  _Self& operator++() { ++current; return *this; }
-  _Self& operator--() { --current; return *this; }
-  _Self  operator++(int) { _Self __tmp = *this; ++current; return __tmp; }
-  _Self  operator--(int) { _Self __tmp = *this; --current; return __tmp; }
-  _Self  operator+    (difference_type n) const { return _Self(current + n); }
-  _Self& operator+=   (difference_type n) { current += n; return *this; }
-  _Self  operator-    (difference_type n) const { return _Self(current - n); }
-  _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 current == X.current; }
-  inline bool operator< (const _Self &X) const { return current <  X.current; }
-
-  inline difference_type operator-(const _Self &X) const {
-    return current - X.current;
-  }
-};
-
-template <class _Iterator, class Func>
-inline mapped_iterator<_Iterator, Func> 
-operator+(typename mapped_iterator<_Iterator, Func>::difference_type N,
-          const mapped_iterator<_Iterator, Func>& X) {
-  return mapped_iterator<_Iterator, Func>(X.getCurrent() - N);
-}
-
-#else
-
-// This fails to work, because some iterators are not classes, for example
-// vector iterators are commonly value_type **'s
-template <class RootIt, class UnaryFunc>
-class mapped_iterator : public RootIt {
-  UnaryFunc Fn;
-public:
-  typedef typename UnaryFunc::result_type value_type;
-  typedef typename UnaryFunc::result_type *pointer;
-  typedef void reference;        // Can't modify value returned by fn
-
-  typedef mapped_iterator<RootIt, UnaryFunc> _Self;
-  typedef RootIt super;
-  inline explicit mapped_iterator(const RootIt &I) : super(I) {}
-  inline mapped_iterator(const super &It) : super(It) {}
-
-  inline value_type operator*() const {     // All this work to do 
-    return Fn(super::operator*());   // this little thing
-  }
-};
-#endif
-
-// map_iterator - Provide a convenient way to create mapped_iterators, just like
-// make_pair is useful for creating pairs...
-//
-template <class ItTy, class FuncTy>
-inline mapped_iterator<ItTy, FuncTy> map_iterator(const ItTy &I, FuncTy F) {
-  return mapped_iterator<ItTy, FuncTy>(I, F);
-}
-
-
-//===----------------------------------------------------------------------===//
-//     Extra additions to <algorithm>
-//===----------------------------------------------------------------------===//
-
-// apply_until - Apply a functor to a sequence continually, unless the
-// functor returns true.  Return true if the functor returned true, return false
-// if the functor never returned true.
-//
-template <class InputIt, class Function>
-bool apply_until(InputIt First, InputIt Last, Function Func) {
-  for ( ; First != Last; ++First)
-    if (Func(*First)) return true;
-  return false;
-}
-
-
-// reduce - Reduce a sequence values into a single value, given an initial
-// value and an operator.
-//
-template <class InputIt, class Function, class ValueType>
-ValueType reduce(InputIt First, InputIt Last, Function Func, ValueType Value) {
-  for ( ; First != Last; ++First)
-    Value = Func(*First, Value);
-  return Value;
-}
-
-#if 1   // This is likely to be more efficient
-
-// reduce_apply - Reduce the result of applying a function to each value in a
-// sequence, given an initial value, an operator, a function, and a sequence.
-//
-template <class InputIt, class Function, class ValueType, class TransFunc>
-inline ValueType reduce_apply(InputIt First, InputIt Last, Function Func, 
-                             ValueType Value, TransFunc XForm) {
-  for ( ; First != Last; ++First)
-    Value = Func(XForm(*First), Value);
-  return Value;
-}
-
-#else  // This is arguably more elegant
-
-// reduce_apply - Reduce the result of applying a function to each value in a
-// sequence, given an initial value, an operator, a function, and a sequence.
-//
-template <class InputIt, class Function, class ValueType, class TransFunc>
-inline ValueType reduce_apply2(InputIt First, InputIt Last, Function Func, 
-                              ValueType Value, TransFunc XForm) {
-  return reduce(map_iterator(First, XForm), map_iterator(Last, XForm),
-               Func, Value);
-}
-#endif
-
-
-// reduce_apply_bool - Reduce the result of applying a (bool returning) function
-// to each value in a sequence.  All of the bools returned by the mapped
-// function are bitwise or'd together, and the result is returned.
-//
-template <class InputIt, class Function>
-inline bool reduce_apply_bool(InputIt First, InputIt Last, Function Func) {
-  return reduce_apply(First, Last, bitwise_or<bool>(), false, Func);
-}
-
-
-// map - This function maps the specified input sequence into the specified
-// output iterator, applying a unary function in between.
-//
-template <class InIt, class OutIt, class Functor>
-inline OutIt mapto(InIt Begin, InIt End, OutIt Dest, Functor F) {
-  return copy(map_iterator(Begin, F), map_iterator(End, F), Dest);
-}
-#endif
diff --git a/include/llvm/Support/StringExtras.h b/include/llvm/Support/StringExtras.h
deleted file mode 100644 (file)
index aaae857..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-//===-- StringExtras.h - Useful string functions -----------------*- C++ -*--=//
-//
-// This file contains some functions that are useful when dealing with strings.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TOOLS_STRING_EXTRAS_H
-#define LLVM_TOOLS_STRING_EXTRAS_H
-
-#include <string>
-#include <stdio.h>
-#include "Support/DataTypes.h"
-
-class ConstPoolArray;
-
-static inline string utostr(uint64_t X, bool isNeg = false) {
-  char Buffer[40];
-  char *BufPtr = Buffer+39;
-
-  *BufPtr = 0;                  // Null terminate buffer...
-  if (X == 0) *--BufPtr = '0';  // Handle special case...
-
-  while (X) {
-    *--BufPtr = '0' + (X % 10);
-    X /= 10;
-  }
-
-  if (isNeg) *--BufPtr = '-';   // Add negative sign...
-
-  return string(BufPtr);
-}
-
-static inline string itostr(int64_t X) {
-  if (X < 0) 
-    return utostr((uint64_t)-X, true);
-  else
-    return utostr((uint64_t)X);
-}
-
-
-static inline string utostr(unsigned X, bool isNeg = false) {
-  char Buffer[20];
-  char *BufPtr = Buffer+19;
-
-  *BufPtr = 0;                  // Null terminate buffer...
-  if (X == 0) *--BufPtr = '0';  // Handle special case...
-
-  while (X) {
-    *--BufPtr = '0' + (X % 10);
-    X /= 10;
-  }
-
-  if (isNeg) *--BufPtr = '-';   // Add negative sign...
-
-  return string(BufPtr);
-}
-
-static inline string itostr(int X) {
-  if (X < 0) 
-    return utostr((unsigned)-X, true);
-  else
-    return utostr((unsigned)X);
-}
-
-static inline string ftostr(double V) {
-  char Buffer[200];
-  snprintf(Buffer, 200, "%e", V);
-  return Buffer;
-}
-
-static inline void
-printIndent(unsigned int indent, ostream& os=cout, const char* const istr="  ")
-{
-  for (unsigned i=0; i < indent; i++)
-    os << istr;
-}
-
-// Can we treat the specified array as a string?  Only if it is an array of
-// ubytes or non-negative sbytes.
-//
-bool isStringCompatible(ConstPoolArray *CPA);
-
-// getAsCString - Return the specified array as a C compatible string, only if
-// the predicate isStringCompatible is true.
-//
-string getAsCString(ConstPoolArray *CPA);
-
-#endif
diff --git a/include/llvm/Support/Tree.h b/include/llvm/Support/Tree.h
deleted file mode 100644 (file)
index 679b6df..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-//===- llvm/Support/Tree.h - Generic n-way tree structure --------*- C++ -*--=//
-//
-// This class defines a generic N way tree node structure.  The tree structure
-// is immutable after creation, but the payload contained within it is not.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_TREE_H
-#define LLVM_SUPPORT_TREE_H
-
-#include <vector>
-
-template<class ConcreteTreeNode, class Payload>
-class Tree {
-  vector<ConcreteTreeNode*>    Children;        // This nodes children, if any
-  ConcreteTreeNode            *Parent;          // Parent of this node...
-  Payload                      Data;            // Data held in this node...
-
-protected:
-  void setChildren(const vector<ConcreteTreeNode*> &children) {
-    Children = children;
-  }
-public:
-  inline Tree(ConcreteTreeNode *parent) : Parent(parent) {}
-  inline Tree(const vector<ConcreteTreeNode*> &children, ConcreteTreeNode *par)
-    : Children(children), Parent(par) {}
-
-  inline Tree(const vector<ConcreteTreeNode*> &children, ConcreteTreeNode *par,
-             const Payload &data) 
-    : Children(children), Parent(parent), Data(data) {}
-
-  // Tree dtor - Free all children
-  inline ~Tree() {
-    for (unsigned i = Children.size(); i > 0; --i)
-      delete Children[i-1];
-  }
-
-  // Tree manipulation/walking routines...
-  inline ConcreteTreeNode *getParent() const { return Parent; }
-  inline unsigned getNumChildren() const { return Children.size(); }
-  inline ConcreteTreeNode *getChild(unsigned i) const {
-    assert(i < Children.size() && "Tree::getChild with index out of range!");
-    return Children[i];
-  }
-
-  // Payload access...
-  inline Payload &getTreeData() { return Data; }
-  inline const Payload &getTreeData() const { return Data; }
-};
-
-
-#endif
index 4f19cc95c3cbf421f3bacc658679a6083c36b91e..df16c730b2232abed957eedc591962a3ecdfeaa9 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef LLVM_CODEGEN_FRAMEINFO_H
 #define LLVM_CODEGEN_FRAMEINFO_H
 
-#include "llvm/Support/NonCopyable.h"
+#include "Support/NonCopyable.h"
 #include <vector>
 
 
index 4f0b934bb92541886d6f24ece940f2b4460b5c34..ad1f105958171c43dcaa73b853049d1e0bcc9d7d 100644 (file)
@@ -8,7 +8,7 @@
 #define LLVM_TARGET_TARGETMACHINE_H
 
 #include "llvm/Target/TargetData.h"
-#include "llvm/Support/NonCopyable.h"
+#include "Support/NonCopyable.h"
 
 class TargetMachine;
 class MachineInstrInfo;
index 8f7fad57115650b002024d56dca8d4a16bbf674c..4bd2319d02f5b918861b0927d287ae34f586bef2 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef LLVM_TARGET_MACHINEREGINFO_H
 #define LLVM_TARGET_MACHINEREGINFO_H
 
-#include "llvm/Support/NonCopyable.h"
+#include "Support/NonCopyable.h"
 #include <hash_map>
 #include <string>
 
index 04780e9e3c2c99447a957bd9902af8653a513fc1..905aa2d11f5aa6c796825890290cd0babcda2d1d 100644 (file)
@@ -27,7 +27,7 @@
 #define LLVM_TYPE_H
 
 #include "llvm/Value.h"
-#include "llvm/Support/GraphTraits.h"
+#include "Support/GraphTraits.h"
 
 class DerivedType;
 class MethodType;
index a323610427bc83892c0f42f5006631f887d745c2..47dbde7148306dd37b7ddc86c53ac5252f52c7f1 100644 (file)
 
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Analysis/Writer.h"
-#include "llvm/Support/STLExtras.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
 #include "llvm/iOther.h"
 #include "llvm/iTerminators.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 
 // getNodeFor - Return the node for the specified method or create one if it
index d47e1d7f6ad579906ab0e60066c66f8adc9ec18e..852763755aa6ac7642f1d55407f53dd63cdfe3cd 100644 (file)
@@ -18,8 +18,8 @@
 
 #include "llvm/Analysis/FindUnsafePointerTypes.h"
 #include "llvm/Assembly/CachedWriter.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Type.h"
+#include "Support/CommandLine.h"
 
 // Provide a command line option to turn on printing of which instructions cause
 // a type to become invalid
index 4bff950a82e9528a9b942a91610f5d26edfdf9be..8616cb721cec0178ad40e99a86a14f6f2e42cc6d 100644 (file)
@@ -6,7 +6,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/IntervalIterator.h"
-#include "llvm/Support/STLExtras.h"
+#include "Support/STLExtras.h"
 
 using namespace cfg;
 
index 32201beb6a06b9828434161e40a2a5aa41f293e6..e981a86642086204c872e2056e0b6a42da4282ff 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Support/PostOrderIterator.h"
+#include "Support/PostOrderIterator.h"
 
 
 /************************** Constructor/Destructor ***************************/
index 7518606c89853ad46ae8d6b815fcb2b3093e073b..ed96bd4f577357baa7657266d236dcd52e01200e 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "llvm/Analysis/LoopDepth.h"
 #include "llvm/Analysis/IntervalPartition.h"
-#include "llvm/Support/STLExtras.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 
 inline void LoopDepthCalculator::AddBB(const BasicBlock *BB) {
index a240ec8b8ba06dde5c342378c4d2c4cdf84a106b..40a195b042fe445b0671b0469f04835e14214257 100644 (file)
@@ -9,8 +9,8 @@
 
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/Dominators.h"
-#include "llvm/Support/DepthFirstIterator.h"
 #include "llvm/BasicBlock.h"
+#include "Support/DepthFirstIterator.h"
 #include <algorithm>
 
 bool cfg::Loop::contains(const BasicBlock *BB) const {
index d5432163496cbcd0e5435e6a9b8aa4274867aaba..dc6ee710c459ad860cf91c4196054ea90423a83a 100644 (file)
@@ -12,7 +12,7 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/ConstPoolVals.h"
-#include "llvm/Support/STLExtras.h"
+#include "Support/STLExtras.h"
 #include <map>
 
 // processModule - Driver function to call all of my subclasses virtual methods.
index 2bc3edbc2a82583808d5706a7133465a09cc6e17..2ed02dbed2698af6bae7d9205d1a959ad2e5066f 100644 (file)
@@ -6,9 +6,9 @@
 
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Analysis/SimplifyCFG.h"   // To get cfg::UnifyAllExitNodes
-#include "llvm/Support/DepthFirstIterator.h"
-#include "llvm/Support/STLExtras.h"
 #include "llvm/Method.h"
+#include "Support/DepthFirstIterator.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 
 //===----------------------------------------------------------------------===//
index 0f25f5461d258676881ea99c6693ff46762e2d35..76052fa5410199a19b451efe2471a56cffe11646 100644 (file)
@@ -18,7 +18,7 @@
 #include "llvm/Method.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Assembly/Parser.h"
-#include "llvm/Support/StringExtras.h"
+#include "Support/StringExtras.h"
 
 class Module;
 
index aca9878da397f7146495ce63b72c5b918f0c25c1..0f5c11e1eae514ad55b904a0ba05884722b78e36 100644 (file)
@@ -21,8 +21,8 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iMemory.h"
-#include "llvm/Support/STLExtras.h"
-#include "llvm/Support/DepthFirstIterator.h"
+#include "Support/STLExtras.h"
+#include "Support/DepthFirstIterator.h"
 #include <list>
 #include <utility>            // Get definition of pair class
 #include <algorithm>
index 3211e728ff2ceab10b0893cfb5123addfbcbc9df..6fed526bd6e0ca972228d3b1617414c7d76cfe40 100644 (file)
@@ -19,8 +19,8 @@
 #include "llvm/iOther.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/SymbolTable.h"
-#include "llvm/Support/STLExtras.h"
-#include "llvm/Support/DepthFirstIterator.h"
+#include "Support/DepthFirstIterator.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 
 #if 0
index 0ba218da1c76e69cdc381e1d8e7518cd0f27ad8a..528e5abdd345f916c02bb401f8dd45fe4abb31ed 100644 (file)
 //************************* User Include Files *****************************/
 
 #include "llvm/CodeGen/InstrScheduling.h"
-#include "SchedPriorities.h"
 #include "llvm/Analysis/LiveVar/BBLiveVar.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Instruction.h"
-
-
-//************************ System Include Files *****************************/
-
+#include "Support/CommandLine.h"
+#include "SchedPriorities.h"
 #include <hash_set>
 #include <algorithm>
 #include <iterator>
index 9d3651a256e837fae444dabee69eef4423be28a8..9e9af5b80d816fa365022e1a769ff098fa935d01 100644 (file)
@@ -21,8 +21,8 @@
 #include "llvm/CodeGen/InstrSelection.h"
 #include "llvm/Target/MachineInstrInfo.h"
 #include "llvm/Target/MachineRegInfo.h"
-#include "llvm/Support/StringExtras.h"
 #include "llvm/iOther.h"
+#include "Support/StringExtras.h"
 #include <algorithm>
 #include <hash_map>
 #include <vector>
@@ -132,7 +132,7 @@ SchedGraphEdge::~SchedGraphEdge()
 }
 
 void SchedGraphEdge::dump(int indent=0) const {
-  printIndent(indent); cout << *this; 
+  cout << string(indent*2, ' ') << *this; 
 }
 
 
@@ -168,7 +168,7 @@ SchedGraphNode::~SchedGraphNode()
 }
 
 void SchedGraphNode::dump(int indent=0) const {
-  printIndent(indent); cout << *this; 
+  cout << string(indent*2, ' ') << *this; 
 }
 
 
@@ -1023,32 +1023,24 @@ operator<<(ostream& os, const SchedGraphEdge& edge)
 ostream&
 operator<<(ostream& os, const SchedGraphNode& node)
 {
-  printIndent(4, os);
-  os << "Node " << node.nodeId << " : "
-     << "latency = " << node.latency << endl;
-  
-  printIndent(6, os);
+  os << string(8, ' ')
+     << "Node " << node.nodeId << " : "
+     << "latency = " << node.latency << endl << string(12, ' ');
   
   if (node.getMachineInstr() == NULL)
     os << "(Dummy node)" << endl;
   else
     {
-      os << *node.getMachineInstr() << endl;
-  
-      printIndent(6, os);
+      os << *node.getMachineInstr() << endl << string(12, ' ');
       os << node.inEdges.size() << " Incoming Edges:" << endl;
       for (unsigned i=0, N=node.inEdges.size(); i < N; i++)
-       {
-         printIndent(8, os);
-         os << * node.inEdges[i];
-       }
+         os << string(16, ' ') << *node.inEdges[i];
   
-      printIndent(6, os);
-      os << node.outEdges.size() << " Outgoing Edges:" << endl;
+      os << string(12, ' ') << node.outEdges.size()
+         << " Outgoing Edges:" << endl;
       for (unsigned i=0, N=node.outEdges.size(); i < N; i++)
        {
-         printIndent(8, os);
-         os << * node.outEdges[i];
+         os << string(16, ' ') << * node.outEdges[i];
        }
     }
   
index 44d59a1aa52d69c8ff2283fdff83cd758fd5fe37..a4567a5198f909df314b6c7e772e64f49b75ab4c 100644 (file)
 #ifndef LLVM_CODEGEN_SCHEDGRAPH_H
 #define LLVM_CODEGEN_SCHEDGRAPH_H
 
-#include "llvm/Support/NonCopyable.h"
-#include "llvm/Support/HashExtras.h"
-#include "llvm/Support/GraphTraits.h"
 #include "llvm/Target/MachineInstrInfo.h"
 #include "llvm/CodeGen/MachineInstr.h"
+#include "Support/NonCopyable.h"
+#include "Support/HashExtras.h"
+#include "Support/GraphTraits.h"
 #include <hash_map>
 
 class Value;
index 31d9f6c5926d6efbf5caa1616f7506840a149cb1..acbe552d0526a3bb276b74ac9d9d496dcf45378f 100644 (file)
@@ -19,7 +19,7 @@
 //**************************************************************************/
 
 #include "SchedPriorities.h"
-#include "llvm/Support/PostOrderIterator.h"
+#include "Support/PostOrderIterator.h"
 
 
 SchedPriorities::SchedPriorities(const Method* method,
index f928683060a0ba86d8a96113183750fcddf3a503..c6d53674ac77f293bff851947ae601689e913cf5 100644 (file)
@@ -30,7 +30,7 @@
 #include "llvm/ConstPoolVals.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Support/STLExtras.h"
+#include "Support/STLExtras.h"
 
 //------------------------------------------------------------------------ 
 // class InstrTreeNode
index f27ad710e0a18c328c746414b8547aa9187f70a7..ce26a1d073e57948ebc565aa3f51bfdec205cb90 100644 (file)
 #include "llvm/CodeGen/InstrSelection.h"
 #include "llvm/CodeGen/InstrSelectionSupport.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Instruction.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/Method.h"
 #include "llvm/iOther.h"
 #include "llvm/Target/MachineRegInfo.h"
+#include "Support/CommandLine.h"
 #include <string.h>
 
 
index 5fa51c034f632d908b01d5cda809343e46bee4fb..02b333113216ff362d990f5abd83ba07f93da927 100644 (file)
@@ -1,5 +1,5 @@
 
-#include "llvm/Support/CommandLine.h"
+#include "Support/CommandLine.h"
 
 #ifndef REG_ALLOC_COMMON_H
 #define  REG_ALLOC_COMMON_H
index 538e39ad0cb8588fa0c2b796e727de00b0a7c2d4..2f0ee41c52fb6c01dbb493bdec6e76a045a8b0d6 100644 (file)
@@ -26,7 +26,7 @@ CachedWriter CW;     // Object to accelerate printing of LLVM
 
 
 #ifdef PROFILE_STRUCTURE_FIELDS
-#include "llvm/Support/CommandLine.h"
+#include "Support/CommandLine.h"
 static cl::Flag ProfileStructureFields("profilestructfields", 
                                        "Profile Structure Field Accesses");
 #include <map>
index bc337ee8b5c0ae7acf3342e4a4ed74d9a14b4be8..f6938169daba1e3103f84a834fd9dce2e3322bb3 100644 (file)
@@ -9,8 +9,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/STLExtras.h"
+#include "Support/CommandLine.h"
+#include "Support/STLExtras.h"
 #include <vector>
 #include <algorithm>
 #include <map>
index 0ba218da1c76e69cdc381e1d8e7518cd0f27ad8a..528e5abdd345f916c02bb401f8dd45fe4abb31ed 100644 (file)
 //************************* User Include Files *****************************/
 
 #include "llvm/CodeGen/InstrScheduling.h"
-#include "SchedPriorities.h"
 #include "llvm/Analysis/LiveVar/BBLiveVar.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Instruction.h"
-
-
-//************************ System Include Files *****************************/
-
+#include "Support/CommandLine.h"
+#include "SchedPriorities.h"
 #include <hash_set>
 #include <algorithm>
 #include <iterator>
index 9d3651a256e837fae444dabee69eef4423be28a8..9e9af5b80d816fa365022e1a769ff098fa935d01 100644 (file)
@@ -21,8 +21,8 @@
 #include "llvm/CodeGen/InstrSelection.h"
 #include "llvm/Target/MachineInstrInfo.h"
 #include "llvm/Target/MachineRegInfo.h"
-#include "llvm/Support/StringExtras.h"
 #include "llvm/iOther.h"
+#include "Support/StringExtras.h"
 #include <algorithm>
 #include <hash_map>
 #include <vector>
@@ -132,7 +132,7 @@ SchedGraphEdge::~SchedGraphEdge()
 }
 
 void SchedGraphEdge::dump(int indent=0) const {
-  printIndent(indent); cout << *this; 
+  cout << string(indent*2, ' ') << *this; 
 }
 
 
@@ -168,7 +168,7 @@ SchedGraphNode::~SchedGraphNode()
 }
 
 void SchedGraphNode::dump(int indent=0) const {
-  printIndent(indent); cout << *this; 
+  cout << string(indent*2, ' ') << *this; 
 }
 
 
@@ -1023,32 +1023,24 @@ operator<<(ostream& os, const SchedGraphEdge& edge)
 ostream&
 operator<<(ostream& os, const SchedGraphNode& node)
 {
-  printIndent(4, os);
-  os << "Node " << node.nodeId << " : "
-     << "latency = " << node.latency << endl;
-  
-  printIndent(6, os);
+  os << string(8, ' ')
+     << "Node " << node.nodeId << " : "
+     << "latency = " << node.latency << endl << string(12, ' ');
   
   if (node.getMachineInstr() == NULL)
     os << "(Dummy node)" << endl;
   else
     {
-      os << *node.getMachineInstr() << endl;
-  
-      printIndent(6, os);
+      os << *node.getMachineInstr() << endl << string(12, ' ');
       os << node.inEdges.size() << " Incoming Edges:" << endl;
       for (unsigned i=0, N=node.inEdges.size(); i < N; i++)
-       {
-         printIndent(8, os);
-         os << * node.inEdges[i];
-       }
+         os << string(16, ' ') << *node.inEdges[i];
   
-      printIndent(6, os);
-      os << node.outEdges.size() << " Outgoing Edges:" << endl;
+      os << string(12, ' ') << node.outEdges.size()
+         << " Outgoing Edges:" << endl;
       for (unsigned i=0, N=node.outEdges.size(); i < N; i++)
        {
-         printIndent(8, os);
-         os << * node.outEdges[i];
+         os << string(16, ' ') << * node.outEdges[i];
        }
     }
   
index 44d59a1aa52d69c8ff2283fdff83cd758fd5fe37..a4567a5198f909df314b6c7e772e64f49b75ab4c 100644 (file)
 #ifndef LLVM_CODEGEN_SCHEDGRAPH_H
 #define LLVM_CODEGEN_SCHEDGRAPH_H
 
-#include "llvm/Support/NonCopyable.h"
-#include "llvm/Support/HashExtras.h"
-#include "llvm/Support/GraphTraits.h"
 #include "llvm/Target/MachineInstrInfo.h"
 #include "llvm/CodeGen/MachineInstr.h"
+#include "Support/NonCopyable.h"
+#include "Support/HashExtras.h"
+#include "Support/GraphTraits.h"
 #include <hash_map>
 
 class Value;
index 31d9f6c5926d6efbf5caa1616f7506840a149cb1..acbe552d0526a3bb276b74ac9d9d496dcf45378f 100644 (file)
@@ -19,7 +19,7 @@
 //**************************************************************************/
 
 #include "SchedPriorities.h"
-#include "llvm/Support/PostOrderIterator.h"
+#include "Support/PostOrderIterator.h"
 
 
 SchedPriorities::SchedPriorities(const Method* method,
index f928683060a0ba86d8a96113183750fcddf3a503..c6d53674ac77f293bff851947ae601689e913cf5 100644 (file)
@@ -30,7 +30,7 @@
 #include "llvm/ConstPoolVals.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Support/STLExtras.h"
+#include "Support/STLExtras.h"
 
 //------------------------------------------------------------------------ 
 // class InstrTreeNode
index f27ad710e0a18c328c746414b8547aa9187f70a7..ce26a1d073e57948ebc565aa3f51bfdec205cb90 100644 (file)
 #include "llvm/CodeGen/InstrSelection.h"
 #include "llvm/CodeGen/InstrSelectionSupport.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Instruction.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/Method.h"
 #include "llvm/iOther.h"
 #include "llvm/Target/MachineRegInfo.h"
+#include "Support/CommandLine.h"
 #include <string.h>
 
 
index 32201beb6a06b9828434161e40a2a5aa41f293e6..e981a86642086204c872e2056e0b6a42da4282ff 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Support/PostOrderIterator.h"
+#include "Support/PostOrderIterator.h"
 
 
 /************************** Constructor/Destructor ***************************/
index 5fa51c034f632d908b01d5cda809343e46bee4fb..02b333113216ff362d990f5abd83ba07f93da927 100644 (file)
@@ -1,5 +1,5 @@
 
-#include "llvm/Support/CommandLine.h"
+#include "Support/CommandLine.h"
 
 #ifndef REG_ALLOC_COMMON_H
 #define  REG_ALLOC_COMMON_H
index 618fb6dc30f6411b3b3d08ab2f9558444f997d1a..3edeb962039bb5256411c993316edd15b3dfa2b4 100644 (file)
@@ -19,8 +19,8 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/Method.h"
 #include "llvm/Module.h"
-#include "llvm/Support/HashExtras.h"
-#include "llvm/Support/StringExtras.h"
+#include "Support/StringExtras.h"
+#include "Support/HashExtras.h"
 #include <locale.h>
 
 namespace {
@@ -161,6 +161,69 @@ private :
   }
 };
 
+
+// Can we treat the specified array as a string?  Only if it is an array of
+// ubytes or non-negative sbytes.
+//
+static bool isStringCompatible(ConstPoolArray *CPA) {
+  const Type *ETy = cast<ArrayType>(CPA->getType())->getElementType();
+  if (ETy == Type::UByteTy) return true;
+  if (ETy != Type::SByteTy) return false;
+
+  for (unsigned i = 0; i < CPA->getNumOperands(); ++i)
+    if (cast<ConstPoolSInt>(CPA->getOperand(i))->getValue() < 0)
+      return false;
+
+  return true;
+}
+
+// toOctal - Convert the low order bits of X into an octal letter
+static inline char toOctal(int X) {
+  return (X&7)+'0';
+}
+
+// getAsCString - Return the specified array as a C compatible string, only if
+// the predicate isStringCompatible is true.
+//
+static string getAsCString(ConstPoolArray *CPA) {
+  if (isStringCompatible(CPA)) {
+    string Result;
+    const Type *ETy = cast<ArrayType>(CPA->getType())->getElementType();
+    Result = "\"";
+    for (unsigned i = 0; i < CPA->getNumOperands(); ++i) {
+      unsigned char C = (ETy == Type::SByteTy) ?
+        (unsigned char)cast<ConstPoolSInt>(CPA->getOperand(i))->getValue() :
+        (unsigned char)cast<ConstPoolUInt>(CPA->getOperand(i))->getValue();
+
+      if (isprint(C)) {
+        Result += C;
+      } else {
+        switch(C) {
+        case '\a': Result += "\\a"; break;
+        case '\b': Result += "\\b"; break;
+        case '\f': Result += "\\f"; break;
+        case '\n': Result += "\\n"; break;
+        case '\r': Result += "\\r"; break;
+        case '\t': Result += "\\t"; break;
+        case '\v': Result += "\\v"; break;
+        default:
+          Result += '\\';
+          Result += toOctal(C >> 6);
+          Result += toOctal(C >> 3);
+          Result += toOctal(C >> 0);
+          break;
+        }
+      }
+    }
+    Result += "\"";
+
+    return Result;
+  } else {
+    return CPA->getStrValue();
+  }
+}
+
+
 inline bool
 SparcAsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI,
                                        unsigned int opNum) {
index c1b8aa38c87969ac62c7a66e987ec889933da531..631d609018488cd5c5f08c0ea77ffa8bdb737504 100644 (file)
@@ -16,7 +16,6 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/CodeGen/InstrForest.h"
 #include "llvm/CodeGen/InstrSelection.h"
-#include "llvm/Support/MathExtras.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iMemory.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/Method.h"
 #include "llvm/ConstPoolVals.h"
+#include "Support/MathExtras.h"
 #include <math.h>
 
-//******************** Internal Data Declarations ************************/
-
 
 //************************* Forward Declarations ***************************/
 
index 327cb6301de309af00ebd005045d4bfb2d00a64c..a1d92f1b26987ccccc3a1d2331e01251e4937fb6 100644 (file)
@@ -8,13 +8,13 @@
 
 #include "TransformInternals.h"
 #include "llvm/Method.h"
-#include "llvm/Support/STLExtras.h"
 #include "llvm/iOther.h"
 #include "llvm/iMemory.h"
 #include "llvm/ConstPoolVals.h"
 #include "llvm/Optimizations/ConstantHandling.h"
 #include "llvm/Optimizations/DCE.h"
 #include "llvm/Analysis/Expressions.h"
+#include "Support/STLExtras.h"
 #include <map>
 #include <algorithm>
 
index 24945c02b44b273b5b389184693a95ab79f34731..7395bab803096850e2f41cd9acd318aa010e7ab9 100644 (file)
@@ -6,9 +6,9 @@
 
 #include "llvm/Transforms/IPO/GlobalDCE.h"
 #include "llvm/Analysis/CallGraph.h"
-#include "llvm/Support/DepthFirstIterator.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
+#include "Support/DepthFirstIterator.h"
 #include <set>
 
 static bool RemoveUnreachableMethods(Module *M, cfg::CallGraph *CG) {
index f59b0aed248b9d368dc5cd732d3e8cbf88406407..07db02854efa16ee25aa73d03d4ee016a1174d76 100644 (file)
@@ -27,8 +27,8 @@
 #include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Assembly/Writer.h"
-#include "llvm/Support/HashExtras.h"
-#include "llvm/Support/StringExtras.h"
+#include "Support/StringExtras.h"
+#include "Support/HashExtras.h"
 #include <hash_set>
 #include <sstream>
 
index d4bf823a54ecc60e61d10bd4c1528bb8c6c713a3..f80270567d397dcc08272a886c47272139d584a3 100644 (file)
@@ -9,7 +9,6 @@
 #include "llvm/Transforms/LevelChange.h"
 #include "TransformInternals.h"
 #include "llvm/Method.h"
-#include "llvm/Support/STLExtras.h"
 #include "llvm/iOther.h"
 #include "llvm/iMemory.h"
 #include "llvm/ConstPoolVals.h"
@@ -17,6 +16,7 @@
 #include "llvm/Optimizations/DCE.h"
 #include "llvm/Optimizations/ConstantProp.h"
 #include "llvm/Analysis/Expressions.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 
 #include "llvm/Assembly/Writer.h"
index 14a18116186b63b74d8908df9b49373ff112061d..a5d1d12bcf85761065333630f1a15776bc4961a6 100644 (file)
 #include "llvm/Instruction.h"
 #include "llvm/Type.h"
 #include "llvm/Analysis/Dominators.h"
-#include "llvm/Support/STLExtras.h"
-#include "llvm/Support/DepthFirstIterator.h"
 #include "llvm/Analysis/Writer.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iOther.h"
+#include "Support/STLExtras.h"
+#include "Support/DepthFirstIterator.h"
 #include <set>
 #include <algorithm>
 
index 16d953401889ca581ceeca84f15a3e1a12cc3ca0..caacf32d389d42ac05aaace76127caeb9cc0b8ae 100644 (file)
@@ -24,7 +24,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Optimizations/DCE.h"
-#include "llvm/Support/STLExtras.h"
 #include "llvm/Module.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/Method.h"
@@ -32,6 +31,7 @@
 #include "llvm/iTerminators.h"
 #include "llvm/iOther.h"
 #include "llvm/Assembly/Writer.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 
 // dceInstruction - Inspect the instruction at *BBI and figure out if it's
index 1cec66de71ee2992bee66cf99158ddbce239ab06..9f0513f36e8ad8871719e7575acc0b25abc5080d 100644 (file)
@@ -23,9 +23,9 @@
 #include "llvm/ConstPoolVals.h"
 #include "llvm/Analysis/IntervalPartition.h"
 #include "llvm/Assembly/Writer.h"
-#include "llvm/Support/STLExtras.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/iOther.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 
 #include "llvm/Analysis/LoopDepth.h"
index bca3f9b2f329f52d2d48640570fd7c7582635360..256fadf637123b13a7a724bef67112e190f91bee 100644 (file)
@@ -24,8 +24,8 @@
 #include "llvm/iOther.h"
 #include "llvm/iMemory.h"
 #include "llvm/iTerminators.h"
-#include "llvm/Support/STLExtras.h"
 #include "llvm/Assembly/Writer.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 #include <map>
 #include <set>
index 1bfdff9364abd4c6cc04debbd68ca16fdbac6ee3..2be172324c46b948f291b95e22d891a8cb7f2dcf 100644 (file)
@@ -21,8 +21,8 @@
 #include "llvm/iMemory.h"
 #include "llvm/iTerminators.h"
 #include "llvm/SymbolTable.h"
-#include "llvm/Support/STLExtras.h"
-#include "llvm/Support/StringExtras.h"
+#include "Support/StringExtras.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 #include <map>
 
index 3b8fe10f46f02c226a86637f8362b762db101985..dd301716fb1c532642490a9d95fa6bc3982cd74e 100644 (file)
@@ -6,12 +6,12 @@
 
 #define __STDC_LIMIT_MACROS           // Get defs for INT64_MAX and friends...
 #include "llvm/ConstPoolVals.h"
-#include "llvm/Support/StringExtras.h"  // itostr
 #include "llvm/DerivedTypes.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/GlobalValue.h"
 #include "llvm/Module.h"
 #include "llvm/Analysis/SlotCalculator.h"
+#include "Support/StringExtras.h"
 #include <algorithm>
 #include <assert.h>
 
index 2bc3edbc2a82583808d5706a7133465a09cc6e17..2ed02dbed2698af6bae7d9205d1a959ad2e5066f 100644 (file)
@@ -6,9 +6,9 @@
 
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Analysis/SimplifyCFG.h"   // To get cfg::UnifyAllExitNodes
-#include "llvm/Support/DepthFirstIterator.h"
-#include "llvm/Support/STLExtras.h"
 #include "llvm/Method.h"
+#include "Support/DepthFirstIterator.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 
 //===----------------------------------------------------------------------===//
index bb5e5b5a25c01dc22eec7ee6ec43dcd111c78ecd..86b944d79f5919b4909244d71c9795b21447bbaf 100644 (file)
@@ -10,9 +10,9 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/InstrTypes.h"
 #include "llvm/ValueHolderImpl.h"
-#include "llvm/Support/STLExtras.h"
 #include "llvm/Type.h"
 #include "llvm/ConstPoolVals.h"
+#include "Support/STLExtras.h"
 #include <map>
 
 // Instantiate Templates - This ugliness is the price we have to pay
index 3211e728ff2ceab10b0893cfb5123addfbcbc9df..6fed526bd6e0ca972228d3b1617414c7d76cfe40 100644 (file)
@@ -19,8 +19,8 @@
 #include "llvm/iOther.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/SymbolTable.h"
-#include "llvm/Support/STLExtras.h"
-#include "llvm/Support/DepthFirstIterator.h"
+#include "Support/DepthFirstIterator.h"
+#include "Support/STLExtras.h"
 #include <algorithm>
 
 #if 0
index b8da428a2cb404f7c62bd827d46528c7079b48a3..c32cec936564c45b656b65464669ae26e2eeeb59 100644 (file)
@@ -6,10 +6,10 @@
 
 #include "llvm/SymbolTable.h"
 #include "llvm/InstrTypes.h"
-#include "llvm/Support/StringExtras.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
+#include "Support/StringExtras.h"
 
 #define DEBUG_SYMBOL_TABLE 0
 #define DEBUG_ABSTYPE 0
index 53844d605d38241b4414106be9b2a4263fcb1049..5f39682ca4d7b034ec408401528a49e3de419d77 100644 (file)
@@ -5,9 +5,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/DerivedTypes.h"
-#include "llvm/Support/StringExtras.h"
 #include "llvm/SymbolTable.h"
-#include "llvm/Support/STLExtras.h"
+#include "Support/StringExtras.h"
+#include "Support/STLExtras.h"
 
 // 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
index bc337ee8b5c0ae7acf3342e4a4ed74d9a14b4be8..f6938169daba1e3103f84a834fd9dce2e3322bb3 100644 (file)
@@ -9,8 +9,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/STLExtras.h"
+#include "Support/CommandLine.h"
+#include "Support/STLExtras.h"
 #include <vector>
 #include <algorithm>
 #include <map>
diff --git a/support/lib/Support/StringExtras.cpp b/support/lib/Support/StringExtras.cpp
deleted file mode 100644 (file)
index 2229df0..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-
-
-#include "llvm/Support/StringExtras.h"
-#include "llvm/ConstPoolVals.h"
-#include "llvm/DerivedTypes.h"
-
-// Can we treat the specified array as a string?  Only if it is an array of
-// ubytes or non-negative sbytes.
-//
-bool isStringCompatible(ConstPoolArray *CPA) {
-  const Type *ETy = cast<ArrayType>(CPA->getType())->getElementType();
-  if (ETy == Type::UByteTy) return true;
-  if (ETy != Type::SByteTy) return false;
-
-  for (unsigned i = 0; i < CPA->getNumOperands(); ++i)
-    if (cast<ConstPoolSInt>(CPA->getOperand(i))->getValue() < 0)
-      return false;
-
-  return true;
-}
-
-// toOctal - Convert the low order bits of X into an octal letter
-static inline char toOctal(int X) {
-  return (X&7)+'0';
-}
-
-// getAsCString - Return the specified array as a C compatible string, only if
-// the predicate isStringCompatible is true.
-//
-string getAsCString(ConstPoolArray *CPA) {
-  if (isStringCompatible(CPA)) {
-    string Result;
-    const Type *ETy = cast<ArrayType>(CPA->getType())->getElementType();
-    Result = "\"";
-    for (unsigned i = 0; i < CPA->getNumOperands(); ++i) {
-      unsigned char C = (ETy == Type::SByteTy) ?
-        (unsigned char)cast<ConstPoolSInt>(CPA->getOperand(i))->getValue() :
-        (unsigned char)cast<ConstPoolUInt>(CPA->getOperand(i))->getValue();
-
-      if (isprint(C)) {
-        Result += C;
-      } else {
-        switch(C) {
-        case '\a': Result += "\\a"; break;
-        case '\b': Result += "\\b"; break;
-        case '\f': Result += "\\f"; break;
-        case '\n': Result += "\\n"; break;
-        case '\r': Result += "\\r"; break;
-        case '\t': Result += "\\t"; break;
-        case '\v': Result += "\\v"; break;
-        default:
-          Result += '\\';
-          Result += toOctal(C >> 6);
-          Result += toOctal(C >> 3);
-          Result += toOctal(C >> 0);
-          break;
-        }
-      }
-    }
-    Result += "\"";
-
-    return Result;
-  } else {
-    return CPA->getStrValue();
-  }
-}
index ec5d2c0431de559a44a2e2f89702f6c675658337..da7de6ec9af483089ffa69a516618b031e34624f 100644 (file)
@@ -15,9 +15,7 @@
 #include "llvm/Method.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Assembly/Parser.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Analysis/Writer.h"
-
 #include "llvm/Analysis/InstForest.h"
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Analysis/IntervalPartition.h"
@@ -27,6 +25,7 @@
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/FindUnsafePointerTypes.h"
 #include "llvm/Analysis/FindUsedTypes.h"
+#include "Support/CommandLine.h"
 #include <algorithm>
 
 static void PrintMethod(Method *M) {
index 72b63ecfddebf93cb5f63807cc8355f56fc3fe28..ee664f1524986c36c03e86031cdf6a3899dca43c 100644 (file)
@@ -9,14 +9,13 @@
 //
 //===------------------------------------------------------------------------===
 
-#include <iostream.h>
-#include <fstream.h>
-#include <string>
 #include "llvm/Module.h"
 #include "llvm/Assembly/Parser.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Bytecode/Writer.h"
-#include "llvm/Support/CommandLine.h"
+#include "Support/CommandLine.h"
+#include <fstream>
+#include <string>
 
 cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
 cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
index 712cf85e812726f06dd9ee641faece91b4604c2c..2a7eb4e06ea5875beda1359be3b6f731c95ed954 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#include <iostream.h>
-#include <fstream.h>
 #include "llvm/Module.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Bytecode/Reader.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Method.h"
-#include "llvm/Support/DepthFirstIterator.h"
-#include "llvm/Support/PostOrderIterator.h"
+#include "Support/DepthFirstIterator.h"
+#include "Support/PostOrderIterator.h"
+#include "Support/CommandLine.h"
+#include <fstream>
 
 // OutputMode - The different orderings to print basic blocks in...
 enum OutputMode {
index e19508fdacdf4943cf64ebaca29137d812c188b4..c5ab2dff68dc53b216a80362b0df0f457a2a9cb0 100644 (file)
@@ -15,7 +15,7 @@
 #include "llvm/Optimizations/DCE.h"
 #include "llvm/Transforms/ConstantMerge.h"
 #include "llvm/Bytecode/Writer.h"
-#include "llvm/Support/CommandLine.h"
+#include "Support/CommandLine.h"
 #include <memory>
 #include <fstream>
 #include <string>
index 80a39b2d9c159d38a2361a55dbc3da627fede106..9bf766fcaad66c3cbf388c36d2b4c81dcf509c06 100644 (file)
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Bytecode/Writer.h"
 #include "llvm/Assembly/Writer.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
-#include <fstream.h>
+#include "Support/CommandLine.h"
+#include <fstream>
 #include <memory>
 
 
index 1490cf40d16c2026bcf3585206f8b8c249f35409..7c8c3a608b6d419f24834cddb6291d0d98a202db 100644 (file)
@@ -13,9 +13,9 @@
 #include "llvm/Assembly/PrintModulePass.h"
 #include "llvm/Bytecode/WriteBytecodePass.h"
 #include "llvm/Transforms/ConstantMerge.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
+#include "Support/CommandLine.h"
 #include <memory>
 #include <string>
 #include <fstream>
index ef9dddf750df912963257e5f710e491ecd0ad56e..f4145c169c5cffc03e8e49f9da195ae9ade7d5fe 100644 (file)
@@ -8,7 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Interpreter.h"
-#include "llvm/Support/CommandLine.h"
+#include "Support/CommandLine.h"
 
 cl::StringList InputArgv(""   , "Input command line", cl::ConsumeAfter);
 cl::String MainFunction ("f"      , "Function to execute", cl::NoFlags, "main");
index 72b63ecfddebf93cb5f63807cc8355f56fc3fe28..ee664f1524986c36c03e86031cdf6a3899dca43c 100644 (file)
@@ -9,14 +9,13 @@
 //
 //===------------------------------------------------------------------------===
 
-#include <iostream.h>
-#include <fstream.h>
-#include <string>
 #include "llvm/Module.h"
 #include "llvm/Assembly/Parser.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Bytecode/Writer.h"
-#include "llvm/Support/CommandLine.h"
+#include "Support/CommandLine.h"
+#include <fstream>
+#include <string>
 
 cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
 cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
index 72b63ecfddebf93cb5f63807cc8355f56fc3fe28..ee664f1524986c36c03e86031cdf6a3899dca43c 100644 (file)
@@ -9,14 +9,13 @@
 //
 //===------------------------------------------------------------------------===
 
-#include <iostream.h>
-#include <fstream.h>
-#include <string>
 #include "llvm/Module.h"
 #include "llvm/Assembly/Parser.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Bytecode/Writer.h"
-#include "llvm/Support/CommandLine.h"
+#include "Support/CommandLine.h"
+#include <fstream>
+#include <string>
 
 cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
 cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
index 712cf85e812726f06dd9ee641faece91b4604c2c..2a7eb4e06ea5875beda1359be3b6f731c95ed954 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#include <iostream.h>
-#include <fstream.h>
 #include "llvm/Module.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Bytecode/Reader.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Method.h"
-#include "llvm/Support/DepthFirstIterator.h"
-#include "llvm/Support/PostOrderIterator.h"
+#include "Support/DepthFirstIterator.h"
+#include "Support/PostOrderIterator.h"
+#include "Support/CommandLine.h"
+#include <fstream>
 
 // OutputMode - The different orderings to print basic blocks in...
 enum OutputMode {
index 712cf85e812726f06dd9ee641faece91b4604c2c..2a7eb4e06ea5875beda1359be3b6f731c95ed954 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#include <iostream.h>
-#include <fstream.h>
 #include "llvm/Module.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Bytecode/Reader.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Method.h"
-#include "llvm/Support/DepthFirstIterator.h"
-#include "llvm/Support/PostOrderIterator.h"
+#include "Support/DepthFirstIterator.h"
+#include "Support/PostOrderIterator.h"
+#include "Support/CommandLine.h"
+#include <fstream>
 
 // OutputMode - The different orderings to print basic blocks in...
 enum OutputMode {
index 80a39b2d9c159d38a2361a55dbc3da627fede106..9bf766fcaad66c3cbf388c36d2b4c81dcf509c06 100644 (file)
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Bytecode/Writer.h"
 #include "llvm/Assembly/Writer.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
-#include <fstream.h>
+#include "Support/CommandLine.h"
+#include <fstream>
 #include <memory>
 
 
index 0386a4955fe22a549fee0f3548847a4232aeb25c..927a69a5f32b0b02cac70845e8d6470e953a3fa1 100644 (file)
@@ -9,7 +9,6 @@
 #include "llvm/Module.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Bytecode/Writer.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Optimizations/AllOpts.h"
 #include "llvm/Transforms/Instrumentation/TraceValues.h"
 #include "llvm/Assembly/PrintModulePass.h"
@@ -18,6 +17,7 @@
 #include "llvm/Transforms/LevelChange.h"
 #include "llvm/Transforms/SwapStructContents.h"
 #include "llvm/Transforms/IPO/GlobalDCE.h"
+#include "Support/CommandLine.h"
 #include <fstream>
 #include <memory>