diff options
author | Reid Kleckner <rnk@google.com> | 2015-09-16 20:16:27 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2015-09-16 20:16:27 +0000 |
commit | b005d281c36c09eda1b85db59e2c183ed5defca5 (patch) | |
tree | 8263838e6c8079eceaccb60c61aa8c393205aa95 /llvm/lib | |
parent | 10aa77032de43681231e81ee3f2e7d232b16dc9c (diff) | |
download | bcm5719-llvm-b005d281c36c09eda1b85db59e2c183ed5defca5.tar.gz bcm5719-llvm-b005d281c36c09eda1b85db59e2c183ed5defca5.zip |
[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.
llvm-svn: 247844
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/WinException.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/CodeGen/PrologEpilogInserter.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/CodeGen/WinEHPrepare.cpp | 24 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86FrameLowering.cpp | 1 |
5 files changed, 42 insertions, 18 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp index cd360218f36..1b75051dd67 100644 --- a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp @@ -475,6 +475,16 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) { 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); } diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp index f169f485af3..54f5553d3e1 100644 --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -819,6 +819,16 @@ void PEI::replaceFrameIndices(MachineFunction &Fn) { 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); diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp index fe359777a36..baf9ee990ea 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp @@ -294,11 +294,18 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf, 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 *>())) diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp index 8ba6f5ef525..fefb444cea9 100644 --- a/llvm/lib/CodeGen/WinEHPrepare.cpp +++ b/llvm/lib/CodeGen/WinEHPrepare.cpp @@ -2622,22 +2622,17 @@ static void addTryBlockMapEntry(WinEHFuncInfo &FuncInfo, int TryLow, 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::createTryBlockMapEntry(int TryLow, int TryHigh, } HT.Handler = cast<Function>(CH->getHandlerBlockOrFunc()); HT.CatchObjRecoverIdx = CH->getExceptionVarIndex(); + HT.CatchObj.Alloca = nullptr; TBME.HandlerArray.push_back(HT); } FuncInfo.TryBlockMap.push_back(TBME); diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp index c9715f1ae84..489ab1a94a0 100644 --- a/llvm/lib/Target/X86/X86FrameLowering.cpp +++ b/llvm/lib/Target/X86/X86FrameLowering.cpp @@ -2091,6 +2091,7 @@ MachineBasicBlock::iterator X86FrameLowering::restoreWin32EHFrameAndBasePtr( 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) { |