[llvm] r284612 - [WinEH] Allow catchpads to reuse the same catch object
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 19 10:08:24 PDT 2016
Author: rnk
Date: Wed Oct 19 12:08:23 2016
New Revision: 284612
URL: http://llvm.org/viewvc/llvm-project?rev=284612&view=rev
Log:
[WinEH] Allow catchpads to reuse the same catch object
This code used a regular when it should have used a multimap.
Added:
llvm/trunk/test/CodeGen/X86/catchpad-reuse.ll
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp?rev=284612&r1=284611&r2=284612&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp Wed Oct 19 12:08:23 2016
@@ -98,7 +98,7 @@ void FunctionLoweringInfo::set(const Fun
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 Fun
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 Fun
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
Added: llvm/trunk/test/CodeGen/X86/catchpad-reuse.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/catchpad-reuse.ll?rev=284612&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/catchpad-reuse.ll (added)
+++ llvm/trunk/test/CodeGen/X86/catchpad-reuse.ll Wed Oct 19 12:08:23 2016
@@ -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 at 8"@IMGREL # Type
+; CHECK-NEXT: .long [[v_offset:[0-9]+]] # CatchObjOffset
+; CHECK-NEXT: .long "?catch$2@?0?main at 4HA"@IMGREL # Handler
+; CHECK-NEXT: .long {{.*}} # ParentFrameOffset
+
+; CHECK: $handlerMap$1$main:
+; CHECK-NEXT: .long 0 # Adjectives
+; CHECK-NEXT: .long "??_R0H at 8"@IMGREL # Type
+; CHECK-NEXT: .long [[v_offset]] # CatchObjOffset
+; CHECK-NEXT: .long "?catch$4@?0?main at 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 at 8" = comdat any
+
+@"\01??_7type_info@@6B@" = external constant i8*
+@"\01??_R0H at 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 at 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 at 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 "}
More information about the llvm-commits
mailing list