WinEH: Remove vestigial EH object

Ultimately, we'll need to leave something behind to indicate which
alloca will hold the exception, but we can figure that out when it comes
time to emit the __CxxFrameHandler3 catch handler table.

llvm-svn: 231164
This commit is contained in:
Reid Kleckner 2015-03-03 23:20:30 +00:00
parent dd4b678499
commit 423665311d
6 changed files with 13 additions and 53 deletions

View File

@ -73,8 +73,7 @@ private:
SmallVectorImpl<LandingPadInst *> &LPads);
bool outlineHandler(HandlerType CatchOrCleanup, Function *SrcFn,
Constant *SelectorType, LandingPadInst *LPad,
CallInst *&EHAlloc, AllocaInst *&EHObjPtr,
FrameVarInfoMap &VarInfo);
CallInst *&EHAlloc, FrameVarInfoMap &VarInfo);
};
class WinEHFrameVariableMaterializer : public ValueMaterializer {
@ -132,9 +131,9 @@ protected:
class WinEHCatchDirector : public WinEHCloningDirectorBase {
public:
WinEHCatchDirector(LandingPadInst *LPI, Function *CatchFn, Value *Selector,
Value *EHObj, FrameVarInfoMap &VarInfo)
FrameVarInfoMap &VarInfo)
: WinEHCloningDirectorBase(LPI, CatchFn, VarInfo),
CurrentSelector(Selector->stripPointerCasts()), EHObj(EHObj) {}
CurrentSelector(Selector->stripPointerCasts()) {}
CloningAction handleBeginCatch(ValueToValueMapTy &VMap,
const Instruction *Inst,
@ -149,7 +148,6 @@ public:
private:
Value *CurrentSelector;
Value *EHObj;
};
class WinEHCleanupDirector : public WinEHCloningDirectorBase {
@ -239,7 +237,6 @@ bool WinEHPrepare::prepareCPPEHHandlers(
// handlers are outlined.
FrameVarInfoMap FrameVarInfo;
SmallVector<CallInst *, 4> HandlerAllocs;
SmallVector<AllocaInst *, 4> HandlerEHObjPtrs;
bool HandlersOutlined = false;
@ -267,17 +264,14 @@ bool WinEHPrepare::prepareCPPEHHandlers(
// Create a new instance of the handler data structure in the
// HandlerData vector.
CallInst *EHAlloc = nullptr;
AllocaInst *EHObjPtr = nullptr;
bool Outlined = outlineHandler(Catch, &F, LPad->getClause(Idx), LPad,
EHAlloc, EHObjPtr, FrameVarInfo);
EHAlloc, FrameVarInfo);
if (Outlined) {
HandlersOutlined = true;
// These values must be resolved after all handlers have been
// outlined.
if (EHAlloc)
HandlerAllocs.push_back(EHAlloc);
if (EHObjPtr)
HandlerEHObjPtrs.push_back(EHObjPtr);
}
} // End if (isCatch)
} // End for each clause
@ -290,9 +284,8 @@ bool WinEHPrepare::prepareCPPEHHandlers(
// when landing pad block analysis is added.
if (LPad->isCleanup()) {
CallInst *EHAlloc = nullptr;
AllocaInst *IgnoreEHObjPtr = nullptr;
bool Outlined = outlineHandler(Cleanup, &F, nullptr, LPad, EHAlloc,
IgnoreEHObjPtr, FrameVarInfo);
bool Outlined =
outlineHandler(Cleanup, &F, nullptr, LPad, EHAlloc, FrameVarInfo);
if (Outlined) {
HandlersOutlined = true;
// This value must be resolved after all handlers have been outlined.
@ -399,18 +392,6 @@ bool WinEHPrepare::prepareCPPEHHandlers(
EHDataMap[EHAlloc->getParent()->getParent()] = EHData;
}
// Next, replace the place-holder EHObjPtr allocas with GEP instructions
// that pull the EHObjPtr from the frame alloc structure
for (AllocaInst *EHObjPtr : HandlerEHObjPtrs) {
Value *EHData = EHDataMap[EHObjPtr->getParent()->getParent()];
Builder.SetInsertPoint(EHObjPtr);
Value *ElementPtr = Builder.CreateConstInBoundsGEP2_32(EHData, 0, 1);
EHObjPtr->replaceAllUsesWith(ElementPtr);
EHObjPtr->removeFromParent();
ElementPtr->takeName(EHObjPtr);
delete EHObjPtr;
}
// Finally, replace all of the temporary allocas for frame variables used in
// the outlined handlers and the original frame allocas with GEP instructions
// that get the equivalent pointer from the frame allocation struct.
@ -490,7 +471,7 @@ bool WinEHPrepare::prepareCPPEHHandlers(
bool WinEHPrepare::outlineHandler(HandlerType CatchOrCleanup, Function *SrcFn,
Constant *SelectorType, LandingPadInst *LPad,
CallInst *&EHAlloc, AllocaInst *&EHObjPtr,
CallInst *&EHAlloc,
FrameVarInfoMap &VarInfo) {
Module *M = SrcFn->getParent();
LLVMContext &Context = M->getContext();
@ -539,20 +520,8 @@ bool WinEHPrepare::outlineHandler(HandlerType CatchOrCleanup, Function *SrcFn,
std::unique_ptr<WinEHCloningDirectorBase> Director;
if (CatchOrCleanup == Catch) {
// This alloca is only temporary. We'll be replacing it once we know all
// the frame variables that need to go in the frame allocation structure.
EHObjPtr = Builder.CreateAlloca(Int8PtrType, 0, "eh.obj.ptr");
// This will give us a raw pointer to the exception object, which
// corresponds to the formal parameter of the catch statement. If the
// handler uses this object, we will generate code during the outlining
// process to cast the pointer to the appropriate type and deference it
// as necessary. The un-outlined landing pad code represents the
// exception object as the result of the llvm.eh.begincatch call.
Value *EHObj = Builder.CreateLoad(EHObjPtr, false, "eh.obj");
Director.reset(
new WinEHCatchDirector(LPad, Handler, SelectorType, EHObj, VarInfo));
new WinEHCatchDirector(LPad, Handler, SelectorType, VarInfo));
} else {
Director.reset(new WinEHCleanupDirector(LPad, Handler, VarInfo));
}
@ -668,10 +637,11 @@ CloningDirector::CloningAction WinEHCatchDirector::handleBeginCatch(
// The argument to the call is some form of the first element of the
// landingpad aggregate value, but that doesn't matter. It isn't used
// here.
// The return value of this instruction, however, is used to access the
// EH object pointer. We have generated an instruction to get that value
// from the EH alloc block, so we can just map to that here.
VMap[Inst] = EHObj;
// The second argument is an outparameter where the exception object will be
// stored. Typically the exception object is a scalar, but it can be an
// aggregate when catching by value.
// FIXME: Leave something behind to indicate where the exception object lives
// for this handler. Should it be part of llvm.eh.actions?
return CloningDirector::SkipInstruction;
}

View File

@ -56,8 +56,6 @@ try.cont: ; preds = %invoke.cont2, %invo
; CHECK: entry:
; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 1
; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
; CHECK: call void @_Z16handle_exceptionv()
; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
; CHECK: }

View File

@ -87,8 +87,6 @@ eh.resume: ; preds = %catch.dispatch
; CHECK: entry:
; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 1
; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
; CHECK: %tmp7 = load i32, i32* %i, align 4
; CHECK: call void @_Z10handle_inti(i32 %tmp7)

View File

@ -181,8 +181,6 @@ eh.resume: ; preds = %catch.dispatch
; CHECK: entry:
; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1)
; CHECK: %eh.data = bitcast i8* %eh.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
; CHECK: %eh.obj.ptr = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 1
; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 2
; CHECK: %NumExceptions = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
; CHECK: %ExceptionVal = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 4

View File

@ -134,8 +134,6 @@ eh.resume: ; preds = %ehcleanup
; CHECK: entry:
; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1)
; CHECK: %eh.data = bitcast i8* %eh.alloc to %"struct.\01?test@@YAHUA@@@Z.ehdata"*
; CHECK: %eh.obj.ptr = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 1
; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 2
; CHECK: %eh.temp.alloca = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 3
; CHECK: %.reload = load <{ %struct.A }>*, <{ %struct.A }>** %eh.temp.alloca

View File

@ -189,8 +189,6 @@ eh.resume: ; preds = %lpad
; CHECK: entry:
; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1)
; CHECK: %eh.data = bitcast i8* %eh.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
; CHECK: %eh.obj.ptr = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 1
; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 2
; CHECK: %eh.temp.alloca = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
; CHECK: %NumExceptions.020.reload = load i32, i32* %eh.temp.alloca