blob: 314db8bd84c2cad6387938280574207cef6be880 (
plain)
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
|
//===-- JIT.h - Abstract Execution Engine Interface -------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Common functionality for JITEventListener implementations
//
//===----------------------------------------------------------------------===//
#ifndef EVENT_LISTENER_COMMON_H
#define EVENT_LISTENER_COMMON_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/DebugInfo.h"
#include "llvm/IR/Metadata.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/ValueHandle.h"
namespace llvm {
namespace jitprofiling {
class FilenameCache {
// Holds the filename of each Scope, so that we can pass a null-terminated
// string into oprofile. Use an AssertingVH rather than a ValueMap because we
// shouldn't be modifying any MDNodes while this map is alive.
DenseMap<AssertingVH<MDNode>, std::string> Filenames;
DenseMap<AssertingVH<MDNode>, std::string> Paths;
public:
const char *getFilename(MDNode *Scope) {
std::string &Filename = Filenames[Scope];
if (Filename.empty()) {
DIScope DIScope(Scope);
Filename = DIScope.getFilename();
}
return Filename.c_str();
}
const char *getFullPath(MDNode *Scope) {
std::string &P = Paths[Scope];
if (P.empty()) {
DIScope DIScope(Scope);
StringRef DirName = DIScope.getDirectory();
StringRef FileName = DIScope.getFilename();
SmallString<256> FullPath;
if (DirName != "." && DirName != "") {
FullPath = DirName;
}
if (FileName != "") {
sys::path::append(FullPath, FileName);
}
P = FullPath.str();
}
return P.c_str();
}
};
} // namespace jitprofiling
} // namespace llvm
#endif //EVENT_LISTENER_COMMON_H
|