Today the front-ends (llvm-gcc and clang) generate multiple llvm.dbg.compile_units...
[oota-llvm.git] / include / llvm / CodeGen / MachineModuleInfo.h
index 71ec90a9f2e0f10e4b42d8096b7c15b636059e65..1f4c534f8f8db214d4bee6bd28117ac9c8d71d85 100644 (file)
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/UniqueVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/CodeGen/MachineLocation.h"
 #include "llvm/GlobalValue.h"
 #include "llvm/Pass.h"
 
@@ -48,7 +51,6 @@ class DebugInfoDesc;
 class GlobalVariable;
 class MachineBasicBlock;
 class MachineFunction;
-class MachineMove;
 class Module;
 class PointerType;
 class StructType;
@@ -57,7 +59,8 @@ class StructType;
 // Debug info constants.
 
 enum {
-  LLVMDebugVersion = (6 << 16),         // Current version of debug information.
+  LLVMDebugVersion = (7 << 16),         // Current version of debug information.
+  LLVMDebugVersion6 = (6 << 16),        // Constant for version 6.
   LLVMDebugVersion5 = (5 << 16),        // Constant for version 5.
   LLVMDebugVersion4 = (4 << 16),        // Constant for version 4.
   LLVMDebugVersionMask = 0xffff0000     // Mask for version number.
@@ -265,7 +268,7 @@ public:
   
   /// getAnchorString - Return a string used to label this descriptor's anchor.
   ///
-  static const char *AnchorString;
+  static const char *const AnchorString;
   virtual const char *getAnchorString() const;
     
 #ifndef NDEBUG
@@ -280,7 +283,8 @@ class TypeDesc : public DebugInfoDesc {
 private:
   enum {
     FlagPrivate    = 1 << 0,
-    FlagProtected  = 1 << 1
+    FlagProtected  = 1 << 1,
+    FlagFwdDecl    = 1 << 2
   };
   DebugInfoDesc *Context;               // Context debug descriptor.
   std::string Name;                     // Type name (may be empty.)
@@ -289,6 +293,8 @@ private:
   uint64_t Size;                        // Type bit size (may be zero.)
   uint64_t Align;                       // Type bit alignment (may be zero.)
   uint64_t Offset;                      // Type bit offset (may be zero.)
+
+protected:
   unsigned Flags;                       // Miscellaneous flags.
 
 public:
@@ -310,6 +316,9 @@ public:
   bool isProtected() const {
     return (Flags & FlagProtected) != 0;
   }
+  bool isForwardDecl() const {
+    return (Flags & FlagFwdDecl) != 0;
+  }
   void setContext(DebugInfoDesc *C)                { Context = C; }
   void setName(const std::string &N)               { Name = N; }
   void setFile(CompileUnitDesc *U) {
@@ -321,6 +330,7 @@ public:
   void setOffset(uint64_t O)                       { Offset = O; }
   void setIsPrivate()                              { Flags |= FlagPrivate; }
   void setIsProtected()                            { Flags |= FlagProtected; }
+  void setIsForwardDecl()                          { Flags |= FlagFwdDecl; }
   
   /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
   ///
@@ -664,7 +674,7 @@ public:
   
   /// getAnchorString - Return a string used to label this descriptor's anchor.
   ///
-  static const char *AnchorString;
+  static const char *const AnchorString;
   virtual const char *getAnchorString() const;
     
 #ifndef NDEBUG
@@ -701,7 +711,7 @@ public:
   
   /// getAnchorString - Return a string used to label this descriptor's anchor.
   ///
-  static const char *AnchorString;
+  static const char *const AnchorString;
   virtual const char *getAnchorString() const;
     
 #ifndef NDEBUG
@@ -748,14 +758,9 @@ public:
 /// DIDeserializer - This class is responsible for casting GlobalVariables
 /// into DebugInfoDesc objects.
 class DIDeserializer {
-private:
-  std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
-                                        // Previously defined gloabls.
-  
+  // Previously defined gloabls.
+  std::map<GlobalVariable*, DebugInfoDesc*> GlobalDescs;
 public:
-  DIDeserializer() {}
-  ~DIDeserializer() {}
-  
   const std::map<GlobalVariable *, DebugInfoDesc *> &getGlobalDescs() const {
     return GlobalDescs;
   }
@@ -770,33 +775,29 @@ public:
 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
 /// into GlobalVariables.
 class DISerializer {
-private:
   Module *M;                            // Definition space module.
-  PointerType *StrPtrTy;                // A "sbyte *" type.  Created lazily.
+  PointerType *StrPtrTy;                // A "i8*" type.  Created lazily.
   PointerType *EmptyStructPtrTy;        // A "{ }*" type.  Created lazily.
+
+  // Types per Tag. Created lazily.
   std::map<unsigned, StructType *> TagTypes;
-                                        // Types per Tag.  Created lazily.
-  std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
-                                        // Previously defined descriptors.
-  std::map<const std::string, Constant *> StringCache;
-                                        // Previously defined strings.
-                                          
+
+  // Previously defined descriptors.
+  DenseMap<DebugInfoDesc *, GlobalVariable *> DescGlobals;
+
+  // Previously defined strings.
+  StringMap<Constant*> StringCache;
 public:
   DISerializer()
-  : M(NULL)
-  , StrPtrTy(NULL)
-  , EmptyStructPtrTy(NULL)
-  , TagTypes()
-  , DescGlobals()
-  , StringCache()
+    : M(NULL), StrPtrTy(NULL), EmptyStructPtrTy(NULL), TagTypes(),
+      DescGlobals(), StringCache()
   {}
-  ~DISerializer() {}
   
   // Accessors
   Module *getModule()        const { return M; };
   void setModule(Module *module)  { M = module; }
 
-  /// getStrPtrType - Return a "sbyte *" type.
+  /// getStrPtrType - Return a "i8*" type.
   ///
   const PointerType *getStrPtrType();
   
@@ -824,38 +825,36 @@ public:
 /// DIVerifier - This class is responsible for verifying the given network of
 /// GlobalVariables are valid as DebugInfoDesc objects.
 class DIVerifier {
-private:
   enum {
     Unknown = 0,
     Invalid,
     Valid
   };
-  std::map<GlobalVariable *, unsigned> Validity;// Tracks prior results.
-  std::map<unsigned, unsigned> Counts;  // Count of fields per Tag type.
-  
+  DenseMap<GlobalVariable *, unsigned> Validity; // Tracks prior results.
+  std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
 public:
   DIVerifier()
-  : Validity()
-  , Counts()
+    : Validity(), Counts()
   {}
-  ~DIVerifier() {}
   
   /// Verify - Return true if the GlobalVariable appears to be a valid
   /// serialization of a DebugInfoDesc.
   bool Verify(Value *V);
   bool Verify(GlobalVariable *GV);
+
+  /// isVerified - Return true if the specified GV has already been
+  /// verified as a debug information descriptor.
+  bool isVerified(GlobalVariable *GV);
 };
 
 //===----------------------------------------------------------------------===//
 /// SourceLineInfo - This class is used to record source line correspondence.
 ///
 class SourceLineInfo {
-private:
   unsigned Line;                        // Source line number.
   unsigned Column;                      // Source column.
   unsigned SourceID;                    // Source ID number.
   unsigned LabelID;                     // Label in code ID number.
-
 public:
   SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
   : Line(L), Column(C), SourceID(S), LabelID(I) {}
@@ -871,10 +870,8 @@ public:
 /// SourceFileInfo - This class is used to track source information.
 ///
 class SourceFileInfo {
-private:
   unsigned DirectoryID;                 // Directory ID number.
   std::string Name;                     // File name (not including directory.)
-  
 public:
   SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
             
@@ -1073,7 +1070,11 @@ public:
   
   /// Verify - Verify that a Value is debug information descriptor.
   ///
-  bool Verify(Value *V);
+  bool Verify(Value *V) { return VR.Verify(V); }
+
+  /// isVerified - Return true if the specified GV has already been
+  /// verified as a debug information descriptor.
+  bool isVerified(GlobalVariable *GV) { return VR.isVerified(GV); }
   
   /// AnalyzeModule - Scan the module for global debug information.
   ///
@@ -1083,10 +1084,6 @@ public:
   ///
   bool hasDebugInfo() const { return !CompileUnits.empty(); }
   
-  /// needsFrameInfo - Returns true if we need to gather callee-saved register
-  /// move info for the frame.
-  bool needsFrameInfo() const;
-
   bool callsEHReturn() const { return CallsEHReturn; }
   void setCallsEHReturn(bool b) { CallsEHReturn = b; }
 
@@ -1096,15 +1093,15 @@ public:
   /// NextLabelID - Return the next unique label id.
   ///
   unsigned NextLabelID() {
-    unsigned ID = LabelIDList.size() + 1;
+    unsigned ID = (unsigned)LabelIDList.size() + 1;
     LabelIDList.push_back(ID);
     return ID;
   }
   
-  /// RecordLabel - Records location information and associates it with a
+  /// RecordSourceLine - Records location information and associates it with a
   /// label.  Returns a unique label ID used to generate a label and 
   /// provide correspondence to the source line list.
-  unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
+  unsigned RecordSourceLine(unsigned Line, unsigned Column, unsigned Source);
   
   /// InvalidateLabel - Inhibit use of the specified label # from
   /// MachineModuleInfo, for example because the code was deleted.
@@ -1164,16 +1161,17 @@ public:
   
   /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
   /// named GlobalVariable.
-  std::vector<GlobalVariable*>
-  getGlobalVariablesUsing(Module &M, const std::string &RootName);
+  void getGlobalVariablesUsing(Module &M, const std::string &RootName,
+                               std::vector<GlobalVariable*> &Result);
 
   /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
   ///
-  template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
+  template <class T>
+  void getAnchoredDescriptors(Module &M, std::vector<T*> &AnchoredDescs) {
     T Desc;
-    std::vector<GlobalVariable *> Globals =
-                             getGlobalVariablesUsing(M, Desc.getAnchorString());
-    std::vector<T *> AnchoredDescs;
+    std::vector<GlobalVariable *> Globals;
+    getGlobalVariablesUsing(M, Desc.getAnchorString(), Globals);
+
     for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
       GlobalVariable *GV = Globals[i];
 
@@ -1183,8 +1181,6 @@ public:
         AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
       }
     }
-
-    return AnchoredDescs;
   }
   
   /// RecordRegionStart - Indicate the start of a region.
@@ -1197,7 +1193,7 @@ public:
 
   /// RecordVariable - Indicate the declaration of  a local variable.
   ///
-  void RecordVariable(Value *V, unsigned FrameIndex);
+  void RecordVariable(GlobalValue *GV, unsigned FrameIndex);
   
   /// getRootScope - Return current functions root scope.
   ///