[llvm] r180883 - Add support for other typeinfo encodings in the ExceptionDemo.
Rafael Espindola
rafael.espindola at gmail.com
Wed May 1 14:05:05 PDT 2013
Author: rafael
Date: Wed May 1 16:05:05 2013
New Revision: 180883
URL: http://llvm.org/viewvc/llvm-project?rev=180883&view=rev
Log:
Add support for other typeinfo encodings in the ExceptionDemo.
The old jit always uses DW_EH_PE_absptr, but MCJIT can use other encodings.
This is in preparation for adding EH support to MCJIT, but not directly
related, so I am committing it first.
Modified:
llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp
Modified: llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp?rev=180883&r1=180882&r2=180883&view=diff
==============================================================================
--- llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp (original)
+++ llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp Wed May 1 16:05:05 2013
@@ -418,6 +418,30 @@ static uintptr_t readSLEB128(const uint8
return result;
}
+unsigned getEncodingSize(uint8_t Encoding) {
+ if (Encoding == llvm::dwarf::DW_EH_PE_omit)
+ return 0;
+
+ switch (Encoding & 0x0F) {
+ case llvm::dwarf::DW_EH_PE_absptr:
+ return sizeof(uintptr_t);
+ case llvm::dwarf::DW_EH_PE_udata2:
+ return sizeof(uint16_t);
+ case llvm::dwarf::DW_EH_PE_udata4:
+ return sizeof(uint32_t);
+ case llvm::dwarf::DW_EH_PE_udata8:
+ return sizeof(uint64_t);
+ case llvm::dwarf::DW_EH_PE_sdata2:
+ return sizeof(int16_t);
+ case llvm::dwarf::DW_EH_PE_sdata4:
+ return sizeof(int32_t);
+ case llvm::dwarf::DW_EH_PE_sdata8:
+ return sizeof(int64_t);
+ default:
+ // not supported
+ abort();
+ }
+}
/// Read a pointer encoded value and advance pointer
/// See Variable Length Data in:
@@ -523,7 +547,8 @@ static uintptr_t readEncodedPointer(cons
/// @returns whether or not a type info was found. False is returned if only
/// a cleanup was found
static bool handleActionValue(int64_t *resultAction,
- struct OurExceptionType_t **classInfo,
+ uint8_t TTypeEncoding,
+ const uint8_t *ClassInfo,
uintptr_t actionEntry,
uint64_t exceptionClass,
struct _Unwind_Exception *exceptionObject) {
@@ -572,16 +597,22 @@ static bool handleActionValue(int64_t *r
// Note: A typeOffset == 0 implies that a cleanup llvm.eh.selector
// argument has been matched.
- if ((typeOffset > 0) &&
- (type == (classInfo[-typeOffset])->type)) {
+ if (typeOffset > 0) {
#ifdef DEBUG
fprintf(stderr,
"handleActionValue(...):actionValue <%d> found.\n",
i);
#endif
- *resultAction = i + 1;
- ret = true;
- break;
+ unsigned EncSize = getEncodingSize(TTypeEncoding);
+ const uint8_t *EntryP = ClassInfo - typeOffset * EncSize;
+ uintptr_t P = readEncodedPointer(&EntryP, TTypeEncoding);
+ struct OurExceptionType_t *ThisClassInfo =
+ reinterpret_cast<struct OurExceptionType_t *>(P);
+ if (ThisClassInfo->type == type) {
+ *resultAction = i + 1;
+ ret = true;
+ break;
+ }
}
#ifdef DEBUG
@@ -633,7 +664,7 @@ static _Unwind_Reason_Code handleLsda(in
// emitted dwarf code)
uintptr_t funcStart = _Unwind_GetRegionStart(context);
uintptr_t pcOffset = pc - funcStart;
- struct OurExceptionType_t **classInfo = NULL;
+ const uint8_t *ClassInfo = NULL;
// Note: See JITDwarfEmitter::EmitExceptionTable(...) for corresponding
// dwarf emission
@@ -653,7 +684,7 @@ static _Unwind_Reason_Code handleLsda(in
// were flagged by type info arguments to llvm.eh.selector
// intrinsic
classInfoOffset = readULEB128(&lsda);
- classInfo = (struct OurExceptionType_t**) (lsda + classInfoOffset);
+ ClassInfo = lsda + classInfoOffset;
}
// Walk call-site table looking for range that
@@ -714,7 +745,8 @@ static _Unwind_Reason_Code handleLsda(in
if (actionEntry) {
exceptionMatched = handleActionValue(&actionValue,
- classInfo,
+ ttypeEncoding,
+ ClassInfo,
actionEntry,
exceptionClass,
exceptionObject);
More information about the llvm-commits
mailing list