1 //===-- JIT.h - Abstract Execution Engine Interface -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Common functionality for JITEventListener implementations
12 //===----------------------------------------------------------------------===//
14 #ifndef EVENT_LISTENER_COMMON_H
15 #define EVENT_LISTENER_COMMON_H
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/DebugInfo.h"
19 #include "llvm/IR/Metadata.h"
20 #include "llvm/Support/Path.h"
21 #include "llvm/Support/ValueHandle.h"
25 namespace jitprofiling {
28 // Holds the filename of each Scope, so that we can pass a null-terminated
29 // string into oprofile. Use an AssertingVH rather than a ValueMap because we
30 // shouldn't be modifying any MDNodes while this map is alive.
31 DenseMap<AssertingVH<MDNode>, std::string> Filenames;
32 DenseMap<AssertingVH<MDNode>, std::string> Paths;
35 const char *getFilename(MDNode *Scope) {
36 std::string &Filename = Filenames[Scope];
37 if (Filename.empty()) {
38 DIScope DIScope(Scope);
39 Filename = DIScope.getFilename();
41 return Filename.c_str();
44 const char *getFullPath(MDNode *Scope) {
45 std::string &P = Paths[Scope];
47 DIScope DIScope(Scope);
48 StringRef DirName = DIScope.getDirectory();
49 StringRef FileName = DIScope.getFilename();
50 SmallString<256> FullPath;
51 if (DirName != "." && DirName != "") {
55 sys::path::append(FullPath, FileName);
63 } // namespace jitprofiling
67 #endif //EVENT_LISTENER_COMMON_H