File: llvm_profile_writer.h

package info (click to toggle)
autofdo 0.18-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 92,568 kB
  • sloc: cpp: 26,830; sh: 12,538; makefile: 344; ansic: 134; python: 95
file content (67 lines) | stat: -rw-r--r-- 2,020 bytes parent folder | download | duplicates (2)
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_