|
1 |
| -//===-- JIT.h - Abstract Execution Engine Interface -------------*- 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 |
| -// Common functionality for JITEventListener implementations |
11 |
| -// |
12 |
| -//===----------------------------------------------------------------------===// |
13 |
| - |
14 |
| -#ifndef EVENT_LISTENER_COMMON_H |
15 |
| -#define EVENT_LISTENER_COMMON_H |
16 |
| - |
17 |
| -#include "llvm/ADT/DenseMap.h" |
18 |
| -#include "llvm/IR/DebugInfo.h" |
19 |
| -#include "llvm/IR/Metadata.h" |
20 |
| -#include "llvm/IR/ValueHandle.h" |
21 |
| -#include "llvm/Support/Path.h" |
22 |
| - |
23 |
| -namespace llvm { |
24 |
| - |
25 |
| -namespace jitprofiling { |
26 |
| - |
27 |
| -class FilenameCache { |
28 |
| - // Holds the filename of each Scope, so that we can pass a null-terminated |
29 |
| - // string into oprofile. |
30 |
| - DenseMap<const MDNode *, std::string> Filenames; |
31 |
| - DenseMap<const MDNode *, std::string> Paths; |
32 |
| - |
33 |
| - public: |
34 |
| - const char *getFilename(MDNode *Scope) { |
35 |
| - assert(Scope->isResolved() && "Expected Scope to be resolved"); |
36 |
| - std::string &Filename = Filenames[Scope]; |
37 |
| - if (Filename.empty()) { |
38 |
| - DIScope DIScope(Scope); |
39 |
| - Filename = DIScope.getFilename(); |
40 |
| - } |
41 |
| - return Filename.c_str(); |
42 |
| - } |
43 |
| - |
44 |
| - const char *getFullPath(MDNode *Scope) { |
45 |
| - assert(Scope->isResolved() && "Expected Scope to be resolved"); |
46 |
| - std::string &P = Paths[Scope]; |
47 |
| - if (P.empty()) { |
48 |
| - DIScope DIScope(Scope); |
49 |
| - StringRef DirName = DIScope.getDirectory(); |
50 |
| - StringRef FileName = DIScope.getFilename(); |
51 |
| - SmallString<256> FullPath; |
52 |
| - if (DirName != "." && DirName != "") { |
53 |
| - FullPath = DirName; |
54 |
| - } |
55 |
| - if (FileName != "") { |
56 |
| - sys::path::append(FullPath, FileName); |
57 |
| - } |
58 |
| - P = FullPath.str(); |
59 |
| - } |
60 |
| - return P.c_str(); |
61 |
| - } |
62 |
| -}; |
63 |
| - |
64 |
| -} // namespace jitprofiling |
65 |
| - |
66 |
| -} // namespace llvm |
67 |
| - |
68 |
| -#endif //EVENT_LISTENER_COMMON_H |
| 1 | +//===-- JIT.h - Abstract Execution Engine Interface -------------*- 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 | +// Common functionality for JITEventListener implementations |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#ifndef EVENT_LISTENER_COMMON_H |
| 15 | +#define EVENT_LISTENER_COMMON_H |
| 16 | + |
| 17 | +#include "llvm/ADT/DenseMap.h" |
| 18 | +#include "llvm/IR/DebugInfo.h" |
| 19 | +#include "llvm/IR/Metadata.h" |
| 20 | +#include "llvm/IR/ValueHandle.h" |
| 21 | +#include "llvm/Support/Path.h" |
| 22 | + |
| 23 | +namespace llvm { |
| 24 | + |
| 25 | +namespace jitprofiling { |
| 26 | + |
| 27 | +class FilenameCache { |
| 28 | + // Holds the filename of each Scope, so that we can pass a null-terminated |
| 29 | + // string into oprofile. |
| 30 | + DenseMap<const MDNode *, std::string> Filenames; |
| 31 | + DenseMap<const MDNode *, std::string> Paths; |
| 32 | + |
| 33 | + public: |
| 34 | + const char *getFilename(MDNode *Scope) { |
| 35 | + assert(Scope->isResolved() && "Expected Scope to be resolved"); |
| 36 | + std::string &Filename = Filenames[Scope]; |
| 37 | + if (Filename.empty()) { |
| 38 | + DIScope DIScope(Scope); |
| 39 | + Filename = DIScope.getFilename(); |
| 40 | + } |
| 41 | + return Filename.c_str(); |
| 42 | + } |
| 43 | + |
| 44 | + const char *getFullPath(MDNode *Scope) { |
| 45 | + assert(Scope->isResolved() && "Expected Scope to be resolved"); |
| 46 | + std::string &P = Paths[Scope]; |
| 47 | + if (P.empty()) { |
| 48 | + DIScope DIScope(Scope); |
| 49 | + StringRef DirName = DIScope.getDirectory(); |
| 50 | + StringRef FileName = DIScope.getFilename(); |
| 51 | + SmallString<256> FullPath; |
| 52 | + if (DirName != "." && DirName != "") { |
| 53 | + FullPath = DirName; |
| 54 | + } |
| 55 | + if (FileName != "") { |
| 56 | + sys::path::append(FullPath, FileName); |
| 57 | + } |
| 58 | + P = FullPath.str(); |
| 59 | + } |
| 60 | + return P.c_str(); |
| 61 | + } |
| 62 | +}; |
| 63 | + |
| 64 | +} // namespace jitprofiling |
| 65 | + |
| 66 | +} // namespace llvm |
| 67 | + |
| 68 | +#endif //EVENT_LISTENER_COMMON_H |
0 commit comments