LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventListenerCommon.h
Go to the documentation of this file.
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/DebugInfo.h"
19 #include "llvm/IR/Metadata.h"
20 #include "llvm/Support/Path.h"
22 
23 namespace llvm {
24 
25 namespace jitprofiling {
26 
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;
33 
34  public:
35  const char *getFilename(MDNode *Scope) {
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  std::string &P = Paths[Scope];
46  if (P.empty()) {
47  DIScope DIScope(Scope);
48  StringRef DirName = DIScope.getDirectory();
49  StringRef FileName = DIScope.getFilename();
50  SmallString<256> FullPath;
51  if (DirName != "." && DirName != "") {
52  FullPath = DirName;
53  }
54  if (FileName != "") {
55  sys::path::append(FullPath, FileName);
56  }
57  P = FullPath.str();
58  }
59  return P.c_str();
60  }
61 };
62 
63 } // namespace jitprofiling
64 
65 } // namespace llvm
66 
67 #endif //EVENT_LISTENER_COMMON_H
MDNode - a tuple of other values.
Definition: Metadata.h:69
const char * getFilename(MDNode *Scope)
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:372
StringRef getDirectory() const
Definition: DebugInfo.cpp:779
#define P(N)
StringRef getFilename() const
Definition: DebugInfo.cpp:773
DIScope - A base class for various scopes.
Definition: DebugInfo.h:197
const char * getFullPath(MDNode *Scope)
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:270