InstrProfWriter.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //=-- InstrProfWriter.h - Instrumented profiling writer -----------*- C++ -*-=//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file contains support for writing profiling data for instrumentation
  11. // based PGO and coverage.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_PROFILEDATA_INSTRPROFWRITER_H
  15. #define LLVM_PROFILEDATA_INSTRPROFWRITER_H
  16. #include "llvm/ADT/ArrayRef.h"
  17. #include "llvm/ADT/DenseMap.h"
  18. #include "llvm/ADT/StringMap.h"
  19. #include "llvm/ProfileData/InstrProf.h"
  20. #include "llvm/Support/DataTypes.h"
  21. #include "llvm/Support/MemoryBuffer.h"
  22. #include "llvm/Support/raw_ostream.h"
  23. #include <vector>
  24. namespace llvm {
  25. /// Writer for instrumentation based profile data.
  26. class InstrProfWriter {
  27. public:
  28. typedef SmallDenseMap<uint64_t, std::vector<uint64_t>, 1> CounterData;
  29. private:
  30. StringMap<CounterData> FunctionData;
  31. uint64_t MaxFunctionCount;
  32. public:
  33. InstrProfWriter() : MaxFunctionCount(0) {}
  34. /// Add function counts for the given function. If there are already counts
  35. /// for this function and the hash and number of counts match, each counter is
  36. /// summed.
  37. std::error_code addFunctionCounts(StringRef FunctionName,
  38. uint64_t FunctionHash,
  39. ArrayRef<uint64_t> Counters);
  40. /// Write the profile to \c OS
  41. void write(raw_fd_ostream &OS);
  42. /// Write the profile, returning the raw data. For testing.
  43. std::unique_ptr<MemoryBuffer> writeBuffer();
  44. private:
  45. std::pair<uint64_t, uint64_t> writeImpl(raw_ostream &OS);
  46. };
  47. } // end namespace llvm
  48. #endif