Remove unused function in sample profile writer API - NFC.
[oota-llvm.git] / include / llvm / ProfileData / SampleProfWriter.h
1 //===- SampleProfWriter.h - Write LLVM sample profile data ----------------===//
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 definitions needed for writing sample profiles.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
14 #define LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
15
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/ProfileData/SampleProf.h"
20 #include "llvm/Support/ErrorOr.h"
21 #include "llvm/Support/FileSystem.h"
22 #include "llvm/Support/raw_ostream.h"
23
24 namespace llvm {
25
26 namespace sampleprof {
27
28 enum SampleProfileFormat { SPF_None = 0, SPF_Text, SPF_Binary, SPF_GCC };
29
30 /// \brief Sample-based profile writer. Base class.
31 class SampleProfileWriter {
32 public:
33   SampleProfileWriter(StringRef Filename, std::error_code &EC,
34                       sys::fs::OpenFlags Flags)
35       : OS(Filename, EC, Flags) {}
36   virtual ~SampleProfileWriter() {}
37
38   /// \brief Write sample profiles in \p S for function \p FName.
39   ///
40   /// \returns true if the file was updated successfully. False, otherwise.
41   virtual bool write(StringRef FName, const FunctionSamples &S) = 0;
42
43   /// \brief Write all the sample profiles in the given map of samples.
44   ///
45   /// \returns true if the file was updated successfully. False, otherwise.
46   bool write(StringMap<FunctionSamples> &ProfileMap) {
47     for (auto &I : ProfileMap) {
48       StringRef FName = I.first();
49       FunctionSamples &Profile = I.second;
50       if (!write(FName, Profile))
51         return false;
52     }
53     return true;
54   }
55
56   /// \brief Profile writer factory. Create a new writer based on the value of
57   /// \p Format.
58   static ErrorOr<std::unique_ptr<SampleProfileWriter>>
59   create(StringRef Filename, SampleProfileFormat Format);
60
61 protected:
62   /// \brief Output stream where to emit the profile to.
63   raw_fd_ostream OS;
64 };
65
66 /// \brief Sample-based profile writer (text format).
67 class SampleProfileWriterText : public SampleProfileWriter {
68 public:
69   SampleProfileWriterText(StringRef F, std::error_code &EC)
70       : SampleProfileWriter(F, EC, sys::fs::F_Text), Indent(0) {}
71
72   bool write(StringRef FName, const FunctionSamples &S) override;
73
74 private:
75   /// Indent level to use when writing.
76   ///
77   /// This is used when printing inlined callees.
78   unsigned Indent;
79 };
80
81 /// \brief Sample-based profile writer (binary format).
82 class SampleProfileWriterBinary : public SampleProfileWriter {
83 public:
84   SampleProfileWriterBinary(StringRef F, std::error_code &EC);
85
86   bool write(StringRef F, const FunctionSamples &S) override;
87 };
88
89 } // End namespace sampleprof
90
91 } // End namespace llvm
92
93 #endif // LLVM_PROFILEDATA_SAMPLEPROFWRITER_H