[WinEH] Allow catchpads to reuse the same catch object

This code used a regular when it should have used a multimap.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284612 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Kleckner 2016-10-19 17:08:23 +00:00
parent 85745f9561
commit 0c4885106a
2 changed files with 114 additions and 4 deletions

View File

@ -98,7 +98,7 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
Fn->isVarArg(), Outs, Fn->getContext());
// If this personality uses funclets, we need to do a bit more work.
DenseMap<const AllocaInst *, int *> CatchObjects;
DenseMap<const AllocaInst *, TinyPtrVector<int *>> CatchObjects;
EHPersonality Personality = classifyEHPersonality(
Fn->hasPersonalityFn() ? Fn->getPersonalityFn() : nullptr);
if (isFuncletEHPersonality(Personality)) {
@ -115,7 +115,8 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
for (WinEHHandlerType &H : TBME.HandlerArray) {
if (const AllocaInst *AI = H.CatchObj.Alloca)
CatchObjects.insert({AI, &H.CatchObj.FrameIndex});
CatchObjects.insert({AI, {}}).first->second.push_back(
&H.CatchObj.FrameIndex);
else
H.CatchObj.FrameIndex = INT_MAX;
}
@ -158,8 +159,10 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
StaticAllocaMap[AI] = FrameIndex;
// Update the catch handler information.
if (Iter != CatchObjects.end())
*Iter->second = FrameIndex;
if (Iter != CatchObjects.end()) {
for (int *CatchObjPtr : Iter->second)
*CatchObjPtr = FrameIndex;
}
} else {
// FIXME: Overaligned static allocas should be grouped into
// a single dynamic allocation instead of using a separate

View File

@ -0,0 +1,107 @@
; RUN: llc < %s | FileCheck %s
; IR generated by the following C++ source with modifications to reuse the 'v'
; alloca between catchpads:
; extern "C" void maythrow();
; int main() {
; try {
; try {
; maythrow();
; } catch (int v) {
; maythrow();
; }
; } catch (int v) {
; maythrow();
; }
; return 0;
; }
; CHECK: $cppxdata$main:
; CHECK-NEXT: .long 429065506 # MagicNumber
; CHECK-NEXT: .long 4 # MaxState
; CHECK-NEXT: .long ($stateUnwindMap$main)@IMGREL # UnwindMap
; CHECK-NEXT: .long 2 # NumTryBlocks
; CHECK-NEXT: .long ($tryMap$main)@IMGREL # TryBlockMap
; CHECK-NEXT: .long 5 # IPMapEntries
; CHECK-NEXT: .long ($ip2state$main)@IMGREL # IPToStateXData
; CHECK-NEXT: .long 32 # UnwindHelp
; CHECK-NEXT: .long 0 # ESTypeList
; CHECK-NEXT: .long 1 # EHFlags
; CHECK: $tryMap$main:
; CHECK-NEXT: .long 1 # TryLow
; CHECK-NEXT: .long 1 # TryHigh
; CHECK-NEXT: .long 2 # CatchHigh
; CHECK-NEXT: .long 1 # NumCatches
; CHECK-NEXT: .long ($handlerMap$0$main)@IMGREL # HandlerArray
; CHECK-NEXT: .long 0 # TryLow
; CHECK-NEXT: .long 2 # TryHigh
; CHECK-NEXT: .long 3 # CatchHigh
; CHECK-NEXT: .long 1 # NumCatches
; CHECK-NEXT: .long ($handlerMap$1$main)@IMGREL # HandlerArray
; CHECK: $handlerMap$0$main:
; CHECK-NEXT: .long 0 # Adjectives
; CHECK-NEXT: .long "??_R0H@8"@IMGREL # Type
; CHECK-NEXT: .long [[v_offset:[0-9]+]] # CatchObjOffset
; CHECK-NEXT: .long "?catch$2@?0?main@4HA"@IMGREL # Handler
; CHECK-NEXT: .long {{.*}} # ParentFrameOffset
; CHECK: $handlerMap$1$main:
; CHECK-NEXT: .long 0 # Adjectives
; CHECK-NEXT: .long "??_R0H@8"@IMGREL # Type
; CHECK-NEXT: .long [[v_offset]] # CatchObjOffset
; CHECK-NEXT: .long "?catch$4@?0?main@4HA"@IMGREL # Handler
; CHECK-NEXT: .long {{.*}} # ParentFrameOffset
; ModuleID = 't.cpp'
source_filename = "t.cpp"
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.0.24210"
%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
$"\01??_R0H@8" = comdat any
@"\01??_7type_info@@6B@" = external constant i8*
@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
; Function Attrs: norecurse uwtable
define i32 @main() local_unnamed_addr personality i32 (...)* @__CxxFrameHandler3 {
entry:
%v = alloca i32, align 4
invoke void @maythrow()
to label %try.cont6 unwind label %catch.dispatch
catch.dispatch: ; preds = %entry
%0 = catchswitch within none [label %catch] unwind label %catch.dispatch2
catch: ; preds = %catch.dispatch
%1 = catchpad within %0 [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i32* %v]
invoke void @maythrow() [ "funclet"(token %1) ]
to label %invoke.cont1 unwind label %catch.dispatch2
catch.dispatch2: ; preds = %catch, %catch.dispatch
%2 = catchswitch within none [label %catch3] unwind to caller
catch3: ; preds = %catch.dispatch2
%3 = catchpad within %2 [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i32* %v]
call void @maythrow() [ "funclet"(token %3) ]
catchret from %3 to label %try.cont6
try.cont6: ; preds = %entry, %invoke.cont1, %catch3
ret i32 0
invoke.cont1: ; preds = %catch
catchret from %1 to label %try.cont6
}
declare void @maythrow() local_unnamed_addr #1
declare i32 @__CxxFrameHandler3(...)
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"PIC Level", i32 2}
!1 = !{!"clang version 4.0.0 "}