Skip to content

Commit

Permalink
Add support for source and line information to IntelJITEventListener …
Browse files Browse the repository at this point in the history
…for object emitted by MCJIT.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173712 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Andrew Kaylor committed Jan 28, 2013
1 parent 3c1c042 commit 710cb0c
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 313 deletions.
53 changes: 45 additions & 8 deletions lib/ExecutionEngine/IntelJITEvents/IntelJITEventListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Errno.h"
Expand Down Expand Up @@ -78,6 +80,18 @@ static LineNumberInfo LineStartToIntelJITFormat(
return Result;
}

static LineNumberInfo DILineInfoToIntelJITFormat(uintptr_t StartAddress,
uintptr_t Address,
DILineInfo Line)
{
LineNumberInfo Result;

Result.Offset = Address - StartAddress;
Result.LineNumber = Line.getLine();

return Result;
}

static iJIT_Method_Load FunctionDescToIntelJITFormat(
IntelJITEventsWrapper& Wrapper,
const char* FnName,
Expand Down Expand Up @@ -177,6 +191,7 @@ void IntelJITEventListener::NotifyFreeingMachineCode(void *FnStart) {
void IntelJITEventListener::NotifyObjectEmitted(const ObjectImage &Obj) {
// Get the address of the object image for use as a unique identifier
const void* ObjData = Obj.getData().data();
DIContext* Context = DIContext::getDWARFContext(Obj.getObjectFile());
MethodAddressVector Functions;

// Use symbol info to iterate functions in the object.
Expand All @@ -185,12 +200,15 @@ void IntelJITEventListener::NotifyObjectEmitted(const ObjectImage &Obj) {
E = Obj.end_symbols();
I != E && !ec;
I.increment(ec)) {
std::vector<LineNumberInfo> LineInfo;
std::string SourceFileName;

object::SymbolRef::Type SymType;
if (I->getType(SymType)) continue;
if (SymType == object::SymbolRef::ST_Function) {
StringRef Name;
uint64_t Addr;
uint64_t Size;
StringRef Name;
uint64_t Addr;
uint64_t Size;
if (I->getName(Name)) continue;
if (I->getAddress(Addr)) continue;
if (I->getSize(Size)) continue;
Expand All @@ -203,11 +221,30 @@ void IntelJITEventListener::NotifyObjectEmitted(const ObjectImage &Obj) {
Name.data(),
Addr,
Size);

// FIXME: Try to find line info for this function in the DWARF sections.
FunctionMessage.source_file_name = 0;
FunctionMessage.line_number_size = 0;
FunctionMessage.line_number_table = 0;
if (Context) {
DILineInfoTable Lines = Context->getLineInfoForAddressRange(Addr, Size);
DILineInfoTable::iterator Begin = Lines.begin();
DILineInfoTable::iterator End = Lines.end();
for (DILineInfoTable::iterator It = Begin; It != End; ++It) {
LineInfo.push_back(DILineInfoToIntelJITFormat((uintptr_t)Addr,
It->first,
It->second));
}
if (LineInfo.size() == 0) {
FunctionMessage.source_file_name = 0;
FunctionMessage.line_number_size = 0;
FunctionMessage.line_number_table = 0;
} else {
SourceFileName = Lines.front().second.getFileName();
FunctionMessage.source_file_name = (char *)SourceFileName.c_str();
FunctionMessage.line_number_size = LineInfo.size();
FunctionMessage.line_number_table = &*LineInfo.begin();
}
} else {
FunctionMessage.source_file_name = 0;
FunctionMessage.line_number_size = 0;
FunctionMessage.line_number_table = 0;
}

Wrapper->iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
&FunctionMessage);
Expand Down
313 changes: 153 additions & 160 deletions test/JitListener/test-inline.ll

Large diffs are not rendered by default.

290 changes: 148 additions & 142 deletions test/JitListener/test-parameters.ll

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tools/lli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ endif( LLVM_USE_OPROFILE )
if( LLVM_USE_INTEL_JITEVENTS )
set(LLVM_LINK_COMPONENTS
${LLVM_LINK_COMPONENTS}
DebugInfo
IntelJITEvents
Object
)
endif( LLVM_USE_INTEL_JITEVENTS )

Expand Down
2 changes: 1 addition & 1 deletion tools/lli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LINK_COMPONENTS := mcjit jit interpreter nativecodegen bitreader asmparser selec
# If Intel JIT Events support is confiured, link against the LLVM Intel JIT
# Events interface library
ifeq ($(USE_INTEL_JITEVENTS), 1)
LINK_COMPONENTS += inteljitevents
LINK_COMPONENTS += debuginfo inteljitevents object
endif

# If oprofile support is confiured, link against the LLVM oprofile interface
Expand Down
1 change: 1 addition & 0 deletions tools/llvm-jitlistener/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include_directories( ${LLVM_INTEL_JITEVENTS_INCDIR} )
set(LLVM_LINK_COMPONENTS
asmparser
bitreader
debuginfo
inteljitevents
interpreter
jit
Expand Down
2 changes: 1 addition & 1 deletion tools/llvm-jitlistener/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LINK_COMPONENTS := mcjit jit interpreter nativecodegen bitreader asmparser selec
# Events interface library. If not, this tool will do nothing useful, but it
# will build correctly.
ifeq ($(USE_INTEL_JITEVENTS), 1)
LINK_COMPONENTS += inteljitevents
LINK_COMPONENTS += debuginfo inteljitevents
endif

# This tool has no plugins, optimize startup time.
Expand Down
2 changes: 2 additions & 0 deletions unittests/ExecutionEngine/JIT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ if( LLVM_USE_INTEL_JITEVENTS )
)
set(LLVM_LINK_COMPONENTS
${LLVM_LINK_COMPONENTS}
DebugInfo
IntelJITEvents
Object
)
endif( LLVM_USE_INTEL_JITEVENTS )

Expand Down
2 changes: 1 addition & 1 deletion unittests/ExecutionEngine/JIT/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ifeq ($(USE_INTEL_JITEVENTS), 1)
CPPFLAGS += -I$(INTEL_JITEVENTS_INCDIR)

# Link against the LLVM Intel JIT Evens interface library
LINK_COMPONENTS += inteljitevents
LINK_COMPONENTS += debuginfo inteljitevents object
endif

ifeq ($(USE_OPROFILE), 1)
Expand Down

0 comments on commit 710cb0c

Please sign in to comment.