forked from google/autofdo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllvm_profile_writer.h
67 lines (51 loc) · 1.97 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
#ifndef DEVTOOLS_CROSSTOOL_AUTOFDO_LLVM_PROFILE_WRITER_H_
#define DEVTOOLS_CROSSTOOL_AUTOFDO_LLVM_PROFILE_WRITER_H_
#include "config.h"
#if defined(HAVE_LLVM)
#include "profile_writer.h"
#include "llvm/ProfileData/SampleProf.h"
#include "llvm/ProfileData/SampleProfWriter.h"
namespace autofdo {
// Writer class for LLVM profiles.
class LLVMProfileWriter : public ProfileWriter {
public:
explicit LLVMProfileWriter(
llvm::sampleprof::SampleProfileFormat output_format)
: format_(output_format) {}
bool WriteToFile(const string &output_filename) override;
private:
llvm::sampleprof::SampleProfileFormat format_;
DISALLOW_COPY_AND_ASSIGN(LLVMProfileWriter);
};
class LLVMProfileBuilder : public SymbolTraverser {
public:
explicit LLVMProfileBuilder(const StringIndexMap &name_table)
: profiles_(),
result_(llvm::sampleprof_error::success),
inline_stack_(),
name_table_(name_table) {}
static bool Write(const string &output_filename,
llvm::sampleprof::SampleProfileFormat format,
const SymbolMap &symbol_map,
const StringIndexMap &name_table);
const llvm::StringMap<llvm::sampleprof::FunctionSamples> &ConvertProfiles(
const SymbolMap &symbol_map);
const llvm::StringMap<llvm::sampleprof::FunctionSamples> &GetProfiles()
const {
return profiles_;
}
protected:
void VisitTopSymbol(const string &name, const Symbol *node) override;
void VisitCallsite(const Callsite &callsite) override;
void Visit(const Symbol *node) override;
llvm::StringRef GetNameRef(const string &str);
private:
llvm::StringMap<llvm::sampleprof::FunctionSamples> profiles_;
llvm::sampleprof_error result_;
std::vector<llvm::sampleprof::FunctionSamples *> inline_stack_;
const StringIndexMap &name_table_;
DISALLOW_COPY_AND_ASSIGN(LLVMProfileBuilder);
};
} // namespace devtools_crosstool_autofdo
#endif // HAVE_LLVM
#endif // DEVTOOLS_CROSSTOOL_AUTOFDO_LLVM_PROFILE_WRITER_H_