[llvm] r247844 - [WinEH] Pull Adjectives and CatchObj out of the catchpad arg list
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 16 13:16:27 PDT 2015
Author: rnk
Date: Wed Sep 16 15:16:27 2015
New Revision: 247844
URL: http://llvm.org/viewvc/llvm-project?rev=247844&view=rev
Log:
[WinEH] Pull Adjectives and CatchObj out of the catchpad arg list
Clang now passes the adjectives as an argument to catchpad.
Getting the CatchObj working is simply a matter of threading another
static alloca through codegen, first as an alloca, then as a frame
index, and finally as a frame offset.
Modified:
llvm/trunk/include/llvm/CodeGen/WinEHFuncInfo.h
llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
llvm/trunk/lib/CodeGen/WinEHPrepare.cpp
llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
llvm/trunk/test/CodeGen/WinEH/wineh-statenumbering.ll
llvm/trunk/test/CodeGen/X86/win-catchpad-csrs.ll
llvm/trunk/test/CodeGen/X86/win-catchpad.ll
llvm/trunk/test/Transforms/SimplifyCFG/empty-cleanuppad.ll
Modified: llvm/trunk/include/llvm/CodeGen/WinEHFuncInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/WinEHFuncInfo.h?rev=247844&r1=247843&r2=247844&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/WinEHFuncInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/WinEHFuncInfo.h Wed Sep 16 15:16:27 2015
@@ -139,8 +139,15 @@ struct SEHUnwindMapEntry {
struct WinEHHandlerType {
int Adjectives;
- GlobalVariable *TypeDescriptor;
int CatchObjRecoverIdx;
+ /// The CatchObj starts out life as an LLVM alloca, is turned into a frame
+ /// index, and after PEI, becomes a raw offset.
+ union {
+ const AllocaInst *Alloca;
+ int FrameOffset;
+ int FrameIndex;
+ } CatchObj = {};
+ GlobalVariable *TypeDescriptor;
ValueOrMBB Handler;
};
@@ -176,6 +183,7 @@ struct WinEHFuncInfo {
int EHRegNodeEscapeIndex = INT_MAX;
const AllocaInst *EHRegNode = nullptr;
int EHRegNodeFrameIndex = INT_MAX;
+ int EHRegNodeEndOffset = INT_MAX;
WinEHFuncInfo() {}
};
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp?rev=247844&r1=247843&r2=247844&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp Wed Sep 16 15:16:27 2015
@@ -475,6 +475,16 @@ void WinException::emitCXXFrameHandler3T
HT.CatchObjRecoverIdx);
FrameAllocOffsetRef = MCSymbolRefExpr::create(
FrameAllocOffset, MCSymbolRefExpr::VK_None, Asm->OutContext);
+ } else if (HT.CatchObj.FrameOffset != INT_MAX) {
+ int Offset = HT.CatchObj.FrameOffset;
+ // For 32-bit, the catch object offset is relative to the end of the
+ // EH registration node. For 64-bit, it's relative to SP at the end of
+ // the prologue.
+ if (!shouldEmitPersonality) {
+ assert(FuncInfo.EHRegNodeEndOffset != INT_MAX);
+ Offset += FuncInfo.EHRegNodeEndOffset;
+ }
+ FrameAllocOffsetRef = MCConstantExpr::create(Offset, Asm->OutContext);
} else {
FrameAllocOffsetRef = MCConstantExpr::create(0, Asm->OutContext);
}
Modified: llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp?rev=247844&r1=247843&r2=247844&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp (original)
+++ llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp Wed Sep 16 15:16:27 2015
@@ -819,6 +819,16 @@ void PEI::replaceFrameIndices(MachineFun
if (FuncInfo.UnwindHelpFrameIdx != INT_MAX)
FuncInfo.UnwindHelpFrameOffset = TFI.getFrameIndexReferenceFromSP(
Fn, FuncInfo.UnwindHelpFrameIdx, FrameReg);
+ for (WinEHTryBlockMapEntry &TBME : FuncInfo.TryBlockMap) {
+ for (WinEHHandlerType &H : TBME.HandlerArray) {
+ unsigned UnusedReg;
+ if (H.CatchObj.FrameIndex == INT_MAX)
+ H.CatchObj.FrameOffset = INT_MAX;
+ else
+ H.CatchObj.FrameOffset =
+ TFI.getFrameIndexReference(Fn, H.CatchObj.FrameIndex, UnusedReg);
+ }
+ }
} else if (MMI.hasWinEHFuncInfo(F)) {
WinEHFuncInfo &FuncInfo = MMI.getWinEHFuncInfo(Fn.getFunction());
auto I = FuncInfo.CatchHandlerParentFrameObjIdx.find(F);
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp?rev=247844&r1=247843&r2=247844&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp Wed Sep 16 15:16:27 2015
@@ -294,11 +294,18 @@ void FunctionLoweringInfo::set(const Fun
calculateSEHStateNumbers(WinEHParentFn, EHInfo);
// Map all BB references in the WinEH data to MBBs.
- for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap)
- for (WinEHHandlerType &H : TBME.HandlerArray)
- if (const auto *BB =
- dyn_cast<BasicBlock>(H.Handler.get<const Value *>()))
+ for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
+ for (WinEHHandlerType &H : TBME.HandlerArray) {
+ if (H.CatchObjRecoverIdx == -2 && H.CatchObj.Alloca) {
+ assert(StaticAllocaMap.count(H.CatchObj.Alloca));
+ H.CatchObj.FrameIndex = StaticAllocaMap[H.CatchObj.Alloca];
+ } else {
+ H.CatchObj.FrameIndex = INT_MAX;
+ }
+ if (const auto *BB = dyn_cast<BasicBlock>(H.Handler.get<const Value *>()))
H.Handler = MBBMap[BB];
+ }
+ }
for (WinEHUnwindMapEntry &UME : EHInfo.UnwindMap)
if (UME.Cleanup)
if (const auto *BB = dyn_cast<BasicBlock>(UME.Cleanup.get<const Value *>()))
Modified: llvm/trunk/lib/CodeGen/WinEHPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/WinEHPrepare.cpp?rev=247844&r1=247843&r2=247844&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/WinEHPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/WinEHPrepare.cpp Wed Sep 16 15:16:27 2015
@@ -2622,22 +2622,17 @@ static void addTryBlockMapEntry(WinEHFun
for (const CatchPadInst *CPI : Handlers) {
WinEHHandlerType HT;
Constant *TypeInfo = cast<Constant>(CPI->getArgOperand(0));
- if (TypeInfo->isNullValue()) {
- HT.Adjectives = 0x40;
+ if (TypeInfo->isNullValue())
HT.TypeDescriptor = nullptr;
- } else {
- auto *GV = cast<GlobalVariable>(TypeInfo->stripPointerCasts());
- // Selectors are always pointers to GlobalVariables with 'struct' type.
- // The struct has two fields, adjectives and a type descriptor.
- auto *CS = cast<ConstantStruct>(GV->getInitializer());
- HT.Adjectives =
- cast<ConstantInt>(CS->getAggregateElement(0U))->getZExtValue();
- HT.TypeDescriptor =
- cast<GlobalVariable>(CS->getAggregateElement(1)->stripPointerCasts());
- }
+ else
+ HT.TypeDescriptor = cast<GlobalVariable>(TypeInfo->stripPointerCasts());
+ HT.Adjectives = cast<ConstantInt>(CPI->getArgOperand(1))->getZExtValue();
HT.Handler = CPI->getNormalDest();
- // FIXME: Pass CPI->getArgOperand(1).
- HT.CatchObjRecoverIdx = -1;
+ HT.CatchObjRecoverIdx = -2;
+ if (isa<ConstantPointerNull>(CPI->getArgOperand(2)))
+ HT.CatchObj.Alloca = nullptr;
+ else
+ HT.CatchObj.Alloca = cast<AllocaInst>(CPI->getArgOperand(2));
TBME.HandlerArray.push_back(HT);
}
FuncInfo.TryBlockMap.push_back(TBME);
@@ -2713,6 +2708,7 @@ void WinEHNumbering::createTryBlockMapEn
}
HT.Handler = cast<Function>(CH->getHandlerBlockOrFunc());
HT.CatchObjRecoverIdx = CH->getExceptionVarIndex();
+ HT.CatchObj.Alloca = nullptr;
TBME.HandlerArray.push_back(HT);
}
FuncInfo.TryBlockMap.push_back(TBME);
Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=247844&r1=247843&r2=247844&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Wed Sep 16 15:16:27 2015
@@ -2091,6 +2091,7 @@ MachineBasicBlock::iterator X86FrameLowe
int EHRegOffset = getFrameIndexReference(MF, FI, UsedReg);
int EHRegSize = MFI->getObjectSize(FI);
int EndOffset = -EHRegOffset - EHRegSize;
+ FuncInfo.EHRegNodeEndOffset = EndOffset;
assert(EndOffset >= 0 &&
"end of registration object above normal EBP position!");
if (UsedReg == FramePtr) {
Modified: llvm/trunk/test/CodeGen/WinEH/wineh-statenumbering.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WinEH/wineh-statenumbering.ll?rev=247844&r1=247843&r2=247844&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WinEH/wineh-statenumbering.ll (original)
+++ llvm/trunk/test/CodeGen/WinEH/wineh-statenumbering.ll Wed Sep 16 15:16:27 2015
@@ -37,7 +37,7 @@ entry:
to label %unreachable.for.entry unwind label %catch.dispatch
catch.dispatch: ; preds = %entry
- %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
+ %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
catch: ; preds = %catch.dispatch
; CHECK: catch:
@@ -47,7 +47,7 @@ catch:
to label %unreachable unwind label %catch.dispatch.1
catch.dispatch.1: ; preds = %catch
- %2 = catchpad [i8* null, i8* null] to label %catch.3 unwind label %catchendblock.2
+ %2 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch.3 unwind label %catchendblock.2
catch.3: ; preds = %catch.dispatch.1
; CHECK: catch.3:
Modified: llvm/trunk/test/CodeGen/X86/win-catchpad-csrs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/win-catchpad-csrs.ll?rev=247844&r1=247843&r2=247844&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/win-catchpad-csrs.ll (original)
+++ llvm/trunk/test/CodeGen/X86/win-catchpad-csrs.ll Wed Sep 16 15:16:27 2015
@@ -5,16 +5,12 @@
%eh.CatchableType = type { i32, i8*, i32, i32, i32, i32, i8* }
%eh.CatchableTypeArray.1 = type { i32, [1 x %eh.CatchableType*] }
%eh.ThrowInfo = type { i32, i8*, i8*, i8* }
-%eh.CatchHandlerType = type { i32, 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
- at llvm.eh.handlertype.H.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H at 8" to i8*) }, section "llvm.metadata"
- at llvm.eh.handlertype.H.1 = private unnamed_addr constant %eh.CatchHandlerType { i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H at 8" to i8*) }, section "llvm.metadata"
-
declare i32 @getint()
declare void @useints(...)
declare void @f(i32 %p)
@@ -31,7 +27,7 @@ entry:
to label %try.cont unwind label %catch.dispatch
catch.dispatch: ; preds = %entry
- %0 = catchpad [%eh.CatchHandlerType* @llvm.eh.handlertype.H.0, i8* null]
+ %0 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H at 8", i32 0, i8* null]
to label %catch unwind label %catchendblock
catch:
Modified: llvm/trunk/test/CodeGen/X86/win-catchpad.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/win-catchpad.ll?rev=247844&r1=247843&r2=247844&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/win-catchpad.ll (original)
+++ llvm/trunk/test/CodeGen/X86/win-catchpad.ll Wed Sep 16 15:16:27 2015
@@ -6,8 +6,8 @@
; int main() {
; try {
; f(1);
-; } catch (int) {
-; f(2);
+; } catch (int e) {
+; f(e);
; } catch (...) {
; f(3);
; }
@@ -17,38 +17,37 @@
%eh.CatchableType = type { i32, i8*, i32, i32, i32, i32, i8* }
%eh.CatchableTypeArray.1 = type { i32, [1 x %eh.CatchableType*] }
%eh.ThrowInfo = type { i32, i8*, i8*, i8* }
-%eh.CatchHandlerType = type { i32, 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
- at llvm.eh.handlertype.H.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H at 8" to i8*) }, section "llvm.metadata"
- at llvm.eh.handlertype.H.1 = private unnamed_addr constant %eh.CatchHandlerType { i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H at 8" to i8*) }, section "llvm.metadata"
declare void @f(i32 %p, i32* %l)
declare i32 @__CxxFrameHandler3(...)
define i32 @try_catch_catch() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
entry:
+ %e.addr = alloca i32
%local = alloca i32
invoke void @f(i32 1, i32* %local)
to label %try.cont unwind label %catch.dispatch
catch.dispatch: ; preds = %entry
- %0 = catchpad [%eh.CatchHandlerType* @llvm.eh.handlertype.H.0, i8* null]
+ %0 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H at 8", i32 0, i32* %e.addr]
to label %catch unwind label %catch.dispatch.2
catch: ; preds = %catch.dispatch
- invoke void @f(i32 2, i32* %local)
+ %e = load i32, i32* %e.addr
+ invoke void @f(i32 %e, i32* %local)
to label %invoke.cont.2 unwind label %catchendblock
invoke.cont.2: ; preds = %catch
catchret %0 to label %try.cont
catch.dispatch.2: ; preds = %catch.dispatch
- %1 = catchpad [%eh.CatchHandlerType* @llvm.eh.handlertype.H.0, i8* null]
+ %1 = catchpad [i8* null, i32 u0x40, i8* null]
to label %catch.2 unwind label %catchendblock
catch.2: ; preds = %catch.dispatch.2
@@ -79,10 +78,11 @@ catchendblock:
; X86: pushl %ebp
; X86: addl $12, %ebp
; X86: subl $8, %esp
+; X86: movl -32(%ebp), %[[e_reg:[a-z]+]]
; X86: movl $1, -{{[0-9]+}}(%ebp)
; X86: leal -[[local_offs]](%ebp), %[[addr_reg:[a-z]+]]
; X86-DAG: movl %[[addr_reg]], 4(%esp)
-; X86-DAG: movl $2, (%esp)
+; X86-DAG: movl %[[e_reg]], (%esp)
; X86: calll _f
; X86: movl $[[contbb]], %eax
; X86-NEXT: addl $8, %esp
@@ -105,14 +105,14 @@ catchendblock:
; X86: L__ehtable$try_catch_catch:
; X86: $handlerMap$0$try_catch_catch:
-; X86: .long 0
-; X86: .long "??_R0H at 8"
-; X86: .long 0
-; X86: .long [[catch1bb]]
-; X86: .long 0
-; X86: .long "??_R0H at 8"
-; X86: .long 0
-; X86: .long [[catch2bb]]
+; X86-NEXT: .long 0
+; X86-NEXT: .long "??_R0H at 8"
+; X86-NEXT: .long -20
+; X86-NEXT: .long [[catch1bb]]
+; X86-NEXT: .long 64
+; X86-NEXT: .long 0
+; X86-NEXT: .long 0
+; X86-NEXT: .long [[catch2bb]]
; X64-LABEL: try_catch_catch:
; X64: pushq %rbp
@@ -135,7 +135,7 @@ catchendblock:
; X64: movq %rdx, %rbp
; X64: subq $32, %rsp
; X64-DAG: leaq -[[local_offs]](%rbp), %rdx
-; X64-DAG: movl $2, %ecx
+; X64-DAG: movl [[e_addr:[-0-9]+]](%rbp), %ecx
; X64: callq f
; X64: leaq [[contbb]](%rip), %rax
; X64: addq $32, %rsp
@@ -158,11 +158,12 @@ catchendblock:
; X64: $handlerMap$0$try_catch_catch:
; X64: .long 0
; X64: .long "??_R0H at 8"@IMGREL
-; X64: .long 0
+; FIXME: This should probably be offset from rsp, not rbp.
+; X64: .long [[e_addr]]
; X64: .long [[catch1bb]]@IMGREL
; X64: .long 56
+; X64: .long 64
; X64: .long 0
-; X64: .long "??_R0H at 8"@IMGREL
; X64: .long 0
; X64: .long [[catch2bb]]@IMGREL
; X64: .long 56
Modified: llvm/trunk/test/Transforms/SimplifyCFG/empty-cleanuppad.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/empty-cleanuppad.ll?rev=247844&r1=247843&r2=247844&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/empty-cleanuppad.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/empty-cleanuppad.ll Wed Sep 16 15:16:27 2015
@@ -86,7 +86,7 @@ ehcleanup:
cleanupret %0 unwind label %catch.dispatch
catch.dispatch: ; preds = %ehcleanup
- %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
+ %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
catch: ; preds = %catch.dispatch
catchret %1 to label %catchret.dest
@@ -126,7 +126,7 @@ ehcleanup.1:
; CHECK: invoke void @g()
; CHECK: to label %try.cont unwind label %catch.dispatch
; CHECK: catch.dispatch:
-; CHECK: catchpad [i8* null, i8* null]
+; CHECK: catchpad [i8* null, i32 64, i8* null]
; CHECK-NEXT: to label %catch unwind label %catchendblock
; CHECK: catch:
; CHECK: catchret
@@ -151,7 +151,7 @@ ehcleanup:
cleanupret %0 unwind label %catch.dispatch
catch.dispatch: ; preds = %ehcleanup
- %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
+ %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
catch: ; preds = %catch.dispatch
catchret %1 to label %catchret.dest
@@ -214,7 +214,7 @@ invoke.cont:
to label %try.cont unwind label %catch.dispatch
catch.dispatch: ; preds = %invoke.cont
- %0 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
+ %0 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
catch: ; preds = %catch.dispatch
catchret %0 to label %try.cont
@@ -329,7 +329,7 @@ ehcleanup:
cleanupret %0 unwind label %catch.dispatch
catch.dispatch: ; preds = %ehcleanup
- %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
+ %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
catch: ; preds = %catch.dispatch
catchret %1 to label %return
@@ -395,7 +395,7 @@ ehcleanup:
catch.dispatch: ; preds = %ehcleanup, %entry
%state.1 = phi i32 [ %state.0, %ehcleanup ], [ 1, %entry ]
- %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
+ %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
catch: ; preds = %catch.dispatch
catchret %1 to label %return
@@ -460,7 +460,7 @@ ehcleanup:
cleanupret %0 unwind label %catch.dispatch
catch.dispatch: ; preds = %ehcleanup, %catch.cont
- %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
+ %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
catch: ; preds = %catch.dispatch
call void @use_x(i32 %x)
More information about the llvm-commits
mailing list