SamplePGO - Clear coverage tracking when clearing per-function data.
[oota-llvm.git] / tools / dsymutil / DebugMap.h
index 8d76f113e91e01bfd422c890b101fd3f5bf720e8..06ac5a503dcd1bf0c68c6ea5269a755c741cd20d 100644 (file)
@@ -28,6 +28,8 @@
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/TimeValue.h"
 #include "llvm/Support/YAMLTraits.h"
 #include <vector>
 
@@ -64,16 +66,19 @@ class DebugMapObject;
 /// }
 class DebugMap {
   Triple BinaryTriple;
+  std::string BinaryPath;
   typedef std::vector<std::unique_ptr<DebugMapObject>> ObjectContainer;
   ObjectContainer Objects;
 
   /// For YAML IO support.
   ///@{
+  friend yaml::MappingTraits<std::unique_ptr<DebugMap>>;
   friend yaml::MappingTraits<DebugMap>;
   DebugMap() = default;
   ///@}
 public:
-  DebugMap(const Triple &BinaryTriple) : BinaryTriple(BinaryTriple) {}
+  DebugMap(const Triple &BinaryTriple, StringRef BinaryPath)
+      : BinaryTriple(BinaryTriple), BinaryPath(BinaryPath) {}
 
   typedef ObjectContainer::const_iterator const_iterator;
 
@@ -87,15 +92,22 @@ public:
 
   /// This function adds an DebugMapObject to the list owned by this
   /// debug map.
-  DebugMapObject &addDebugMapObject(StringRef ObjectFilePath);
+  DebugMapObject &addDebugMapObject(StringRef ObjectFilePath,
+                                    sys::TimeValue Timestamp);
 
   const Triple &getTriple() const { return BinaryTriple; }
 
+  StringRef getBinaryPath() const { return BinaryPath; }
+
   void print(raw_ostream &OS) const;
 
 #ifndef NDEBUG
   void dump() const;
 #endif
+
+  /// Read a debug map for \a InputFile.
+  static ErrorOr<std::vector<std::unique_ptr<DebugMap>>>
+  parseYAMLDebugMap(StringRef InputFile, StringRef PrependPath, bool Verbose);
 };
 
 /// \brief The DebugMapObject represents one object file described by
@@ -133,6 +145,8 @@ public:
 
   llvm::StringRef getObjectFilename() const { return Filename; }
 
+  sys::TimeValue getTimestamp() const { return Timestamp; }
+
   iterator_range<StringMap<SymbolMapping>::const_iterator> symbols() const {
     return make_range(Symbols.begin(), Symbols.end());
   }
@@ -144,9 +158,10 @@ public:
 private:
   friend class DebugMap;
   /// DebugMapObjects can only be constructed by the owning DebugMap.
-  DebugMapObject(StringRef ObjectFilename);
+  DebugMapObject(StringRef ObjectFilename, sys::TimeValue Timestamp);
 
   std::string Filename;
+  sys::TimeValue Timestamp;
   StringMap<SymbolMapping> Symbols;
   DenseMap<uint64_t, DebugMapEntry *> AddressToMapping;
 
@@ -157,6 +172,21 @@ private:
   friend yaml::SequenceTraits<std::vector<std::unique_ptr<DebugMapObject>>>;
   friend yaml::SequenceTraits<std::vector<YAMLSymbolMapping>>;
   DebugMapObject() = default;
+
+public:
+  DebugMapObject &operator=(DebugMapObject RHS) {
+    std::swap(Filename, RHS.Filename);
+    std::swap(Timestamp, RHS.Timestamp);
+    std::swap(Symbols, RHS.Symbols);
+    std::swap(AddressToMapping, RHS.AddressToMapping);
+    return *this;
+  }
+  DebugMapObject(DebugMapObject &&RHS) {
+    Filename = std::move(RHS.Filename);
+    Timestamp = std::move(RHS.Timestamp);
+    Symbols = std::move(RHS.Symbols);
+    AddressToMapping = std::move(RHS.AddressToMapping);
+  }
   ///@}
 };
 }
@@ -171,87 +201,37 @@ using namespace llvm::dsymutil;
 
 template <>
 struct MappingTraits<std::pair<std::string, DebugMapObject::SymbolMapping>> {
-
-  static void
-  mapping(IO &io, std::pair<std::string, DebugMapObject::SymbolMapping> &s) {
-    io.mapRequired("sym", s.first);
-    io.mapRequired("objAddr", s.second.ObjectAddress);
-    io.mapRequired("binAddr", s.second.BinaryAddress);
-    io.mapOptional("size", s.second.Size);
-  }
-
+  static void mapping(IO &io,
+                      std::pair<std::string, DebugMapObject::SymbolMapping> &s);
   static const bool flow = true;
 };
 
 template <> struct MappingTraits<dsymutil::DebugMapObject> {
-  typedef StringMap<dsymutil::DebugMapObject::SymbolMapping> SymbolMap;
-
-  struct SequencedStringMap {
-    SequencedStringMap(IO &io) {}
-
-    SequencedStringMap(IO &io, SymbolMap &Map) {
-      Entries.reserve(Map.size());
-      for (auto &Entry : Map)
-        Entries.push_back(std::make_pair(Entry.getKey(), Entry.getValue()));
-    }
-
-    SymbolMap denormalize(IO &) {
-      SymbolMap Res;
-
-      for (auto &Entry : Entries)
-        Res[Entry.first] = Entry.second;
-
-      return Res;
-    }
-
-    std::vector<dsymutil::DebugMapObject::YAMLSymbolMapping> Entries;
-  };
-
-  static void mapping(IO &io, dsymutil::DebugMapObject &s) {
-    MappingNormalization<SequencedStringMap, SymbolMap> seq(io, s.Symbols);
-    io.mapRequired("filename", s.Filename);
-    io.mapRequired("symbols", seq->Entries);
-  }
+  struct YamlDMO;
+  static void mapping(IO &io, dsymutil::DebugMapObject &DMO);
 };
 
 template <> struct ScalarTraits<Triple> {
-
-  static void output(const Triple &val, void *, llvm::raw_ostream &out) {
-    out << val.str();
-  }
-
-  static StringRef input(StringRef scalar, void *, Triple &value) {
-    value = Triple(scalar);
-    return value.str();
-  }
-
+  static void output(const Triple &val, void *, llvm::raw_ostream &out);
+  static StringRef input(StringRef scalar, void *, Triple &value);
   static bool mustQuote(StringRef) { return true; }
 };
 
 template <>
 struct SequenceTraits<std::vector<std::unique_ptr<dsymutil::DebugMapObject>>> {
-
   static size_t
-  size(IO &io, std::vector<std::unique_ptr<dsymutil::DebugMapObject>> &seq) {
-    return seq.size();
-  }
-
+  size(IO &io, std::vector<std::unique_ptr<dsymutil::DebugMapObject>> &seq);
   static dsymutil::DebugMapObject &
   element(IO &, std::vector<std::unique_ptr<dsymutil::DebugMapObject>> &seq,
-          size_t index) {
-    if (index >= seq.size()) {
-      seq.resize(index + 1);
-      seq[index].reset(new dsymutil::DebugMapObject);
-    }
-    return *seq[index];
-  }
+          size_t index);
 };
 
 template <> struct MappingTraits<dsymutil::DebugMap> {
-  static void mapping(IO &io, dsymutil::DebugMap &DM) {
-    io.mapRequired("triple", DM.BinaryTriple);
-    io.mapOptional("objects", DM.Objects);
-  }
+  static void mapping(IO &io, dsymutil::DebugMap &DM);
+};
+
+template <> struct MappingTraits<std::unique_ptr<dsymutil::DebugMap>> {
+  static void mapping(IO &io, std::unique_ptr<dsymutil::DebugMap> &DM);
 };
 }
 }