-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathllvm_profile_writer.h
100 lines (81 loc) · 3.22 KB
/
llvm_profile_writer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef AUTOFDO_LLVM_PROFILE_WRITER_H_
#define AUTOFDO_LLVM_PROFILE_WRITER_H_
#if defined(HAVE_LLVM)
#include <memory>
#include <string>
#include <vector>
#include "profile_writer.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/ProfileData/SampleProf.h"
#include "llvm/ProfileData/SampleProfWriter.h"
namespace devtools_crosstool_autofdo {
// Writer class for LLVM profiles.
class LLVMProfileWriter : public ProfileWriter {
public:
explicit LLVMProfileWriter(
llvm::sampleprof::SampleProfileFormat output_format)
: format_(output_format) {}
// This type is neither copyable nor movable.
LLVMProfileWriter(const LLVMProfileWriter &) = delete;
LLVMProfileWriter &operator=(const LLVMProfileWriter &) = delete;
llvm::sampleprof::SampleProfileWriter *CreateSampleWriter(
const std::string &output_filename);
bool WriteToFile(const std::string &output_filename) override;
llvm::sampleprof::SampleProfileWriter *GetSampleProfileWriter() {
return sample_prof_writer_.get();
}
private:
llvm::sampleprof::SampleProfileFormat format_;
std::unique_ptr<llvm::sampleprof::SampleProfileWriter> sample_prof_writer_;
};
class LLVMProfileBuilder : public SymbolTraverser {
public:
explicit LLVMProfileBuilder(const StringIndexMap &name_table)
: profiles_(),
result_(llvm::sampleprof_error::success),
inline_stack_(),
name_table_(name_table) {}
// This type is neither copyable nor movable.
LLVMProfileBuilder(const LLVMProfileBuilder &) = delete;
LLVMProfileBuilder &operator=(const LLVMProfileBuilder &) = delete;
static bool Write(
const std::string &output_filename,
llvm::sampleprof::SampleProfileFormat format, const SymbolMap &symbol_map,
const StringIndexMap &name_table,
llvm::sampleprof::SampleProfileWriter *sample_profile_writer);
// LLVM_BEFORE_SAMPLEFDO_SPLIT_CONTEXT is defined when llvm version is before
// https://reviews.llvm.org/rGb9db70369b7799887b817e13109801795e4d70fc
#ifndef LLVM_BEFORE_SAMPLEFDO_SPLIT_CONTEXT
const llvm::sampleprof::SampleProfileMap &ConvertProfiles(
const SymbolMap &symbol_map);
const llvm::sampleprof::SampleProfileMap &GetProfiles() const {
return profiles_;
}
#else
const llvm::StringMap<llvm::sampleprof::FunctionSamples> &ConvertProfiles(
const SymbolMap &symbol_map);
const llvm::StringMap<llvm::sampleprof::FunctionSamples> &GetProfiles()
const {
return profiles_;
}
#endif
protected:
void VisitTopSymbol(const std::string &name, const Symbol *node) override;
void VisitCallsite(const Callsite &callsite) override;
void Visit(const Symbol *node) override;
llvm::StringRef GetNameRef(const std::string &str);
private:
// LLVM_BEFORE_SAMPLEFDO_SPLIT_CONTEXT is defined when llvm version is before
// https://reviews.llvm.org/rGb9db70369b7799887b817e13109801795e4d70fc
#ifndef LLVM_BEFORE_SAMPLEFDO_SPLIT_CONTEXT
llvm::sampleprof::SampleProfileMap profiles_;
#else
llvm::StringMap<llvm::sampleprof::FunctionSamples> profiles_;
#endif
llvm::sampleprof_error result_;
std::vector<llvm::sampleprof::FunctionSamples *> inline_stack_;
const StringIndexMap &name_table_;
};
} // namespace devtools_crosstool_autofdo
#endif // HAVE_LLVM
#endif // AUTOFDO_LLVM_PROFILE_WRITER_H_