Make OProfile support compile again after r93630 removed

DebugLocTuple.  Also use an AssertingVH to ensure that MDNodes aren't
destroyed while the FilenameCache is using them.

llvm-svn: 94245
This commit is contained in:
Jeffrey Yasskin 2010-01-22 23:04:39 +00:00
parent 2303145081
commit 690818fc27
1 changed files with 11 additions and 9 deletions

View File

@ -18,10 +18,12 @@
#define DEBUG_TYPE "oprofile-jit-event-listener" #define DEBUG_TYPE "oprofile-jit-event-listener"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/Metadata.h"
#include "llvm/Analysis/DebugInfo.h" #include "llvm/Analysis/DebugInfo.h"
#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunction.h"
#include "llvm/ExecutionEngine/JITEventListener.h" #include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/ValueHandle.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/System/Errno.h" #include "llvm/System/Errno.h"
#include "llvm/Config/config.h" #include "llvm/Config/config.h"
@ -70,15 +72,15 @@ OProfileJITEventListener::~OProfileJITEventListener() {
class FilenameCache { class FilenameCache {
// Holds the filename of each Scope, so that we can pass a null-terminated // Holds the filename of each Scope, so that we can pass a null-terminated
// string into oprofile. // string into oprofile. Use an AssertingVH rather than a ValueMap because we
DenseMap<MDNode*, std::string> Filenames; // shouldn't be modifying any MDNodes while this map is alive.
DenseMap<AssertingVH<MDNode>, std::string> Filenames;
public: public:
const char *getFilename(MDNode *Scope) { const char *getFilename(DIScope Scope) {
std::string &Filename = Filenames[Scope]; std::string &Filename = Filenames[Scope.getNode()];
if (Filename.empty()) { if (Filename.empty()) {
DIScope S(Scope); Filename = Scope.getFilename();
Filename = S.getFilename();
} }
return Filename.c_str(); return Filename.c_str();
} }
@ -89,9 +91,9 @@ static debug_line_info LineStartToOProfileFormat(
uintptr_t Address, DebugLoc Loc) { uintptr_t Address, DebugLoc Loc) {
debug_line_info Result; debug_line_info Result;
Result.vma = Address; Result.vma = Address;
const DebugLocTuple &tuple = MF.getDebugLocTuple(Loc); DILocation DILoc = MF.getDILocation(Loc);
Result.lineno = tuple.Line; Result.lineno = DILoc.getLineNumber();
Result.filename = Filenames.getFilename(tuple.Scope); Result.filename = Filenames.getFilename(DILoc.getScope());
DEBUG(dbgs() << "Mapping " << reinterpret_cast<void*>(Result.vma) << " to " DEBUG(dbgs() << "Mapping " << reinterpret_cast<void*>(Result.vma) << " to "
<< Result.filename << ":" << Result.lineno << "\n"); << Result.filename << ":" << Result.lineno << "\n");
return Result; return Result;