From c052fa0bd384f52bcf4c5ddb510b9b0939183edc Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 9 Feb 2018 17:13:37 +0000 Subject: [PATCH] Emit smaller exception tables for non-SJLJ mode. * Use uleb128 for code offsets in the LSDA call site table. * Omit the TTBase offset if the type table is empty. This change can reduce the size of the DWARF/Itanium LSDA by about half. Patch by Ryan Prichard! llvm-svn: 324750 --- llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp | 19 +++++++++++-------- llvm/test/CodeGen/ARM/dwarf-eh.ll | 4 ++-- llvm/test/CodeGen/ARM/ehabi-handlerdata-nounwind.ll | 2 +- llvm/test/CodeGen/ARM/ehabi-handlerdata.ll | 8 ++++---- llvm/test/CodeGen/X86/eh-label.ll | 2 +- llvm/test/CodeGen/X86/eh-unknown.ll | 12 +++++------- llvm/test/CodeGen/X86/patchpoint-invoke.ll | 6 +++--- llvm/test/CodeGen/X86/push-cfi-obj.ll | 2 +- llvm/test/CodeGen/X86/statepoint-invoke.ll | 8 ++++---- llvm/test/CodeGen/XCore/exception.ll | 14 +++++++------- 10 files changed, 39 insertions(+), 38 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp index d9db783..094e4c9 100644 --- a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp @@ -374,15 +374,17 @@ void EHStreamer::emitExceptionTable() { computeCallSiteTable(CallSites, LandingPads, FirstActions); bool IsSJLJ = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::SjLj; - bool HaveTTData = IsSJLJ ? (!TypeInfos.empty() || !FilterIds.empty()) : true; + unsigned CallSiteEncoding = + IsSJLJ ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_uleb128; + bool HaveTTData = !TypeInfos.empty() || !FilterIds.empty(); // Type infos. MCSection *LSDASection = Asm->getObjFileLowering().getLSDASection(); unsigned TTypeEncoding; if (!HaveTTData) { - // For SjLj exceptions, if there is no TypeInfo, then we just explicitly say - // that we're omitting that bit. + // If there is no TypeInfo, then we just explicitly say that we're omitting + // that bit. TTypeEncoding = dwarf::DW_EH_PE_omit; } else { // Okay, we have actual filters or typeinfos to emit. As such, we need to @@ -450,7 +452,7 @@ void EHStreamer::emitExceptionTable() { // Emit the landing pad call site table. MCSymbol *CstBeginLabel = Asm->createTempSymbol("cst_begin"); MCSymbol *CstEndLabel = Asm->createTempSymbol("cst_end"); - Asm->EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site"); + Asm->EmitEncodingByte(CallSiteEncoding, "Call site"); Asm->EmitLabelDifferenceAsULEB128(CstEndLabel, CstBeginLabel); Asm->OutStreamer->EmitLabel(CstBeginLabel); @@ -518,23 +520,24 @@ void EHStreamer::emitExceptionTable() { // Offset of the call site relative to the start of the procedure. if (VerboseAsm) Asm->OutStreamer->AddComment(">> Call Site " + Twine(++Entry) + " <<"); - Asm->EmitLabelDifference(BeginLabel, EHFuncBeginSym, 4); + Asm->EmitLabelDifferenceAsULEB128(BeginLabel, EHFuncBeginSym); if (VerboseAsm) Asm->OutStreamer->AddComment(Twine(" Call between ") + BeginLabel->getName() + " and " + EndLabel->getName()); - Asm->EmitLabelDifference(EndLabel, BeginLabel, 4); + Asm->EmitLabelDifferenceAsULEB128(EndLabel, BeginLabel); // Offset of the landing pad relative to the start of the procedure. if (!S.LPad) { if (VerboseAsm) Asm->OutStreamer->AddComment(" has no landing pad"); - Asm->OutStreamer->EmitIntValue(0, 4/*size*/); + Asm->EmitULEB128(0); } else { if (VerboseAsm) Asm->OutStreamer->AddComment(Twine(" jumps to ") + S.LPad->LandingPadLabel->getName()); - Asm->EmitLabelDifference(S.LPad->LandingPadLabel, EHFuncBeginSym, 4); + Asm->EmitLabelDifferenceAsULEB128(S.LPad->LandingPadLabel, + EHFuncBeginSym); } // Offset of the first associated action record, relative to the start of diff --git a/llvm/test/CodeGen/ARM/dwarf-eh.ll b/llvm/test/CodeGen/ARM/dwarf-eh.ll index 07a0714..2731cbc 100644 --- a/llvm/test/CodeGen/ARM/dwarf-eh.ll +++ b/llvm/test/CodeGen/ARM/dwarf-eh.ll @@ -64,8 +64,8 @@ declare void @__cxa_end_catch() ; CHECK: .cfi_personality 0, ; CHECK: .cfi_lsda 0, ; CHECK: @TType Encoding = absptr -; CHECK: @ Call site Encoding = udata4 +; CHECK: @ Call site Encoding = uleb128 ; CHECK-PIC: .cfi_personality 155, ; CHECK-PIC: .cfi_lsda 27, ; CHECK-PIC: @TType Encoding = indirect pcrel sdata4 -; CHECK-PIC: @ Call site Encoding = udata4 +; CHECK-PIC: @ Call site Encoding = uleb128 diff --git a/llvm/test/CodeGen/ARM/ehabi-handlerdata-nounwind.ll b/llvm/test/CodeGen/ARM/ehabi-handlerdata-nounwind.ll index ec7a002..e38c69b 100644 --- a/llvm/test/CodeGen/ARM/ehabi-handlerdata-nounwind.ll +++ b/llvm/test/CodeGen/ARM/ehabi-handlerdata-nounwind.ll @@ -57,5 +57,5 @@ try.cont: ; CHECK: .byte 255 @ @LPStart Encoding = omit ; CHECK: .byte 0 @ @TType Encoding = absptr ; CHECK: .uleb128 .Lttbase -; CHECK: .byte 3 @ Call site Encoding = udata4 +; CHECK: .byte 1 @ Call site Encoding = uleb128 ; CHECK: .fnend diff --git a/llvm/test/CodeGen/ARM/ehabi-handlerdata.ll b/llvm/test/CodeGen/ARM/ehabi-handlerdata.ll index af5728b..2f43549 100644 --- a/llvm/test/CodeGen/ARM/ehabi-handlerdata.ll +++ b/llvm/test/CodeGen/ARM/ehabi-handlerdata.ll @@ -52,9 +52,9 @@ try.cont: ; CHECK: .byte 255 @ @LPStart Encoding = omit ; CHECK: .byte 0 @ @TType Encoding = absptr ; CHECK: .uleb128 .Lttbase -; CHECK: .byte 3 @ Call site Encoding = udata4 +; CHECK: .byte 1 @ Call site Encoding = uleb128 ; CHECK: .uleb128 .Lcst_end -; CHECK: .long -; CHECK: .long -; CHECK: .long +; CHECK: .uleb128 +; CHECK: .uleb128 +; CHECK: .uleb128 ; CHECK: .fnend diff --git a/llvm/test/CodeGen/X86/eh-label.ll b/llvm/test/CodeGen/X86/eh-label.ll index d349174..26c3f37 100644 --- a/llvm/test/CodeGen/X86/eh-label.ll +++ b/llvm/test/CodeGen/X86/eh-label.ll @@ -20,5 +20,5 @@ bb2: ret void ; CHECK: [[END:.Lfunc_end.*]]: -; CHECK: .long [[END]]- +; CHECK: .uleb128 [[END]]- } diff --git a/llvm/test/CodeGen/X86/eh-unknown.ll b/llvm/test/CodeGen/X86/eh-unknown.ll index f9f3696..28b5a8a 100644 --- a/llvm/test/CodeGen/X86/eh-unknown.ll +++ b/llvm/test/CodeGen/X86/eh-unknown.ll @@ -22,14 +22,12 @@ entry: ; CHECK: .seh_handlerdata ; CHECK: .Lexception0: ; CHECK: .byte 255 # @LPStart Encoding = omit -; CHECK: .byte 0 # @TType Encoding = absptr -; CHECK: .uleb128 .Lttbase0-.Lttbaseref0 -; CHECK: .Lttbaseref0: -; CHECK: .byte 3 # Call site Encoding = udata4 +; CHECK: .byte 255 # @TType Encoding = omit +; CHECK: .byte 1 # Call site Encoding = uleb128 ; CHECK: .uleb128 .Lcst_end0-.Lcst_begin0 ; CHECK: .Lcst_begin0: -; CHECK: .long .Lfunc_begin0-.Lfunc_begin0 # >> Call Site 1 << -; CHECK: .long .Lfunc_end0-.Lfunc_begin0 # Call between .Lfunc_begin0 and .Lfunc_end0 -; CHECK: .long 0 # has no landing pad +; CHECK: .uleb128 .Lfunc_begin0-.Lfunc_begin0 # >> Call Site 1 << +; CHECK: .uleb128 .Lfunc_end0-.Lfunc_begin0 # Call between .Lfunc_begin0 and .Lfunc_end0 +; CHECK: .byte 0 # has no landing pad ; CHECK: .byte 0 # On action: cleanup ; CHECK: .Lcst_end0: diff --git a/llvm/test/CodeGen/X86/patchpoint-invoke.ll b/llvm/test/CodeGen/X86/patchpoint-invoke.ll index df27377..d888fb5 100644 --- a/llvm/test/CodeGen/X86/patchpoint-invoke.ll +++ b/llvm/test/CodeGen/X86/patchpoint-invoke.ll @@ -36,12 +36,12 @@ threw: ; CHECK-NEXT: .byte 3 ; CHECK-NEXT: .uleb128 .Lttbase{{[0-9]+}}-[[TTBASEREF:.Lttbaseref[0-9]+]] ; CHECK-NEXT: [[TTBASEREF]]: -; CHECK-NEXT: .byte 3 +; CHECK-NEXT: .byte 1 ; CHECK-NEXT: .uleb128 .Lcst_end{{[0-9]+}}-[[CST_BEGIN:.Lcst_begin[0-9]+]] ; CHECK-NEXT: [[CST_BEGIN]]: ; Verify that the unwind data covers the entire patchpoint region: -; CHECK-NEXT: .long .Ltmp0-[[FUNC_BEGIN]] -; CHECK-NEXT: .long [[PP_END]]-.Ltmp0 +; CHECK-NEXT: .uleb128 .Ltmp0-[[FUNC_BEGIN]] +; CHECK-NEXT: .uleb128 [[PP_END]]-.Ltmp0 ; Verify that the stackmap section got emitted: diff --git a/llvm/test/CodeGen/X86/push-cfi-obj.ll b/llvm/test/CodeGen/X86/push-cfi-obj.ll index 33291ec..8b3c3ad 100644 --- a/llvm/test/CodeGen/X86/push-cfi-obj.ll +++ b/llvm/test/CodeGen/X86/push-cfi-obj.ll @@ -11,7 +11,7 @@ ; LINUX-NEXT: SHF_ALLOC (0x2) ; LINUX-NEXT: ] ; LINUX-NEXT: Address: 0x0 -; LINUX-NEXT: Offset: 0x68 +; LINUX-NEXT: Offset: 0x5C ; LINUX-NEXT: Size: 64 ; LINUX-NEXT: Link: 0 ; LINUX-NEXT: Info: 0 diff --git a/llvm/test/CodeGen/X86/statepoint-invoke.ll b/llvm/test/CodeGen/X86/statepoint-invoke.ll index 784b932..12a1226 100644 --- a/llvm/test/CodeGen/X86/statepoint-invoke.ll +++ b/llvm/test/CodeGen/X86/statepoint-invoke.ll @@ -38,8 +38,8 @@ exceptional_return: ret i64 addrspace(1)* %obj1.relocated1 } ; CHECK-LABEL: GCC_except_table{{[0-9]+}}: -; CHECK: .long .Ltmp{{[0-9]+}}-.Ltmp{{[0-9]+}} -; CHECK: .long .Ltmp{{[0-9]+}}-.Lfunc_begin{{[0-9]+}} +; CHECK: .uleb128 .Ltmp{{[0-9]+}}-.Ltmp{{[0-9]+}} +; CHECK: .uleb128 .Ltmp{{[0-9]+}}-.Lfunc_begin{{[0-9]+}} ; CHECK: .byte 0 ; CHECK: .p2align 4 @@ -68,8 +68,8 @@ exceptional_return: ret i64 addrspace(1)* %obj.relocated } ; CHECK-LABEL: GCC_except_table{{[0-9]+}}: -; CHECK: .long .Ltmp{{[0-9]+}}-.Ltmp{{[0-9]+}} -; CHECK: .long .Ltmp{{[0-9]+}}-.Lfunc_begin{{[0-9]+}} +; CHECK: .uleb128 .Ltmp{{[0-9]+}}-.Ltmp{{[0-9]+}} +; CHECK: .uleb128 .Ltmp{{[0-9]+}}-.Lfunc_begin{{[0-9]+}} ; CHECK: .byte 0 ; CHECK: .p2align 4 diff --git a/llvm/test/CodeGen/XCore/exception.ll b/llvm/test/CodeGen/XCore/exception.ll index 9880010..48845a5 100644 --- a/llvm/test/CodeGen/XCore/exception.ll +++ b/llvm/test/CodeGen/XCore/exception.ll @@ -107,16 +107,16 @@ Exit: ; CHECK: .byte 0 ; CHECK: .uleb128 [[TTBASE:.Lttbase[0-9]+]]-[[TTBASEREF:.Lttbaseref[0-9]+]] ; CHECK: [[TTBASEREF]]: -; CHECK: .byte 3 +; CHECK: .byte 1 ; CHECK: .uleb128 [[CST_END:.Lcst_end[0-9]+]]-[[CST_BEGIN:.Lcst_begin[0-9]+]] ; CHECK: [[CST_BEGIN]]: -; CHECK: .long [[PRE_G]]-[[START]] -; CHECK: .long [[POST_G]]-[[PRE_G]] -; CHECK: .long [[LANDING]]-[[START]] +; CHECK: .uleb128 [[PRE_G]]-[[START]] +; CHECK: .uleb128 [[POST_G]]-[[PRE_G]] +; CHECK: .uleb128 [[LANDING]]-[[START]] ; CHECK: .byte 5 -; CHECK: .long [[POST_G]]-[[START]] -; CHECK: .long [[END]]-[[POST_G]] -; CHECK: .long 0 +; CHECK: .uleb128 [[POST_G]]-[[START]] +; CHECK: .uleb128 [[END]]-[[POST_G]] +; CHECK: .byte 0 ; CHECK: .byte 0 ; CHECK: [[CST_END]]: ; CHECK: .byte 0 -- 2.7.4