forked from OSchip/llvm-project
[WinEH] Start EH preparation for 32-bit x86, it uses no arguments
32-bit x86 MSVC-style exceptions are functionaly similar to 64-bit, but they take no arguments. Instead, they implicitly use the value of EBP passed in by the caller as a pointer to the parent's frame. In LLVM, we can represent this as llvm.frameaddress(1), and feed that into all of our calls to llvm.framerecover. The next steps are: - Add an alloca to the fs:00 linked list of handlers - Add something like llvm.sjlj.lsda or generalize it to store in the alloca - Move state number calculation to WinEHPrepare, arrange for FunctionLoweringInfo to call it - Use the state numbers to insert explicit loads and stores in the IR llvm-svn: 236172
This commit is contained in:
parent
04b0e92766
commit
bcda1cd45a
|
@ -73,8 +73,8 @@ EHPersonality llvm::classifyEHPersonality(const Value *Pers) {
|
||||||
.Case("__gxx_personality_v0", EHPersonality::GNU_CXX)
|
.Case("__gxx_personality_v0", EHPersonality::GNU_CXX)
|
||||||
.Case("__gcc_personality_v0", EHPersonality::GNU_C)
|
.Case("__gcc_personality_v0", EHPersonality::GNU_C)
|
||||||
.Case("__objc_personality_v0", EHPersonality::GNU_ObjC)
|
.Case("__objc_personality_v0", EHPersonality::GNU_ObjC)
|
||||||
.Case("__except_handler3", EHPersonality::MSVC_X86SEH)
|
.Case("_except_handler3", EHPersonality::MSVC_X86SEH)
|
||||||
.Case("__except_handler4", EHPersonality::MSVC_X86SEH)
|
.Case("_except_handler4", EHPersonality::MSVC_X86SEH)
|
||||||
.Case("__C_specific_handler", EHPersonality::MSVC_Win64SEH)
|
.Case("__C_specific_handler", EHPersonality::MSVC_Win64SEH)
|
||||||
.Case("__CxxFrameHandler3", EHPersonality::MSVC_CXX)
|
.Case("__CxxFrameHandler3", EHPersonality::MSVC_CXX)
|
||||||
.Default(EHPersonality::Unknown);
|
.Default(EHPersonality::Unknown);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/ADT/SmallSet.h"
|
#include "llvm/ADT/SmallSet.h"
|
||||||
#include "llvm/ADT/SetVector.h"
|
#include "llvm/ADT/SetVector.h"
|
||||||
|
#include "llvm/ADT/Triple.h"
|
||||||
#include "llvm/ADT/TinyPtrVector.h"
|
#include "llvm/ADT/TinyPtrVector.h"
|
||||||
#include "llvm/Analysis/LibCallSemantics.h"
|
#include "llvm/Analysis/LibCallSemantics.h"
|
||||||
#include "llvm/CodeGen/WinEHFuncInfo.h"
|
#include "llvm/CodeGen/WinEHFuncInfo.h"
|
||||||
|
@ -71,7 +72,10 @@ class WinEHPrepare : public FunctionPass {
|
||||||
public:
|
public:
|
||||||
static char ID; // Pass identification, replacement for typeid.
|
static char ID; // Pass identification, replacement for typeid.
|
||||||
WinEHPrepare(const TargetMachine *TM = nullptr)
|
WinEHPrepare(const TargetMachine *TM = nullptr)
|
||||||
: FunctionPass(ID), DT(nullptr), SEHExceptionCodeSlot(nullptr) {}
|
: FunctionPass(ID), DT(nullptr), SEHExceptionCodeSlot(nullptr) {
|
||||||
|
if (TM)
|
||||||
|
TheTriple = Triple(TM->getTargetTriple());
|
||||||
|
}
|
||||||
|
|
||||||
bool runOnFunction(Function &Fn) override;
|
bool runOnFunction(Function &Fn) override;
|
||||||
|
|
||||||
|
@ -97,6 +101,8 @@ private:
|
||||||
LandingPadInst *OutlinedLPad,
|
LandingPadInst *OutlinedLPad,
|
||||||
const LandingPadInst *OriginalLPad,
|
const LandingPadInst *OriginalLPad,
|
||||||
FrameVarInfoMap &VarInfo);
|
FrameVarInfoMap &VarInfo);
|
||||||
|
Function *createHandlerFunc(Type *RetTy, const Twine &Name, Module *M,
|
||||||
|
Value *&ParentFP);
|
||||||
bool outlineHandler(ActionHandler *Action, Function *SrcFn,
|
bool outlineHandler(ActionHandler *Action, Function *SrcFn,
|
||||||
LandingPadInst *LPad, BasicBlock *StartBB,
|
LandingPadInst *LPad, BasicBlock *StartBB,
|
||||||
FrameVarInfoMap &VarInfo);
|
FrameVarInfoMap &VarInfo);
|
||||||
|
@ -110,6 +116,8 @@ private:
|
||||||
|
|
||||||
void processSEHCatchHandler(CatchHandler *Handler, BasicBlock *StartBB);
|
void processSEHCatchHandler(CatchHandler *Handler, BasicBlock *StartBB);
|
||||||
|
|
||||||
|
Triple TheTriple;
|
||||||
|
|
||||||
// All fields are reset by runOnFunction.
|
// All fields are reset by runOnFunction.
|
||||||
DominatorTree *DT;
|
DominatorTree *DT;
|
||||||
EHPersonality Personality;
|
EHPersonality Personality;
|
||||||
|
@ -138,12 +146,16 @@ private:
|
||||||
// outlined but before the outlined code is pruned from the parent function.
|
// outlined but before the outlined code is pruned from the parent function.
|
||||||
DenseMap<const BasicBlock *, BasicBlock *> LPadTargetBlocks;
|
DenseMap<const BasicBlock *, BasicBlock *> LPadTargetBlocks;
|
||||||
|
|
||||||
|
// Map from outlined handler to call to llvm.frameaddress(1). Only used for
|
||||||
|
// 32-bit EH.
|
||||||
|
DenseMap<Function *, Value *> HandlerToParentFP;
|
||||||
|
|
||||||
AllocaInst *SEHExceptionCodeSlot;
|
AllocaInst *SEHExceptionCodeSlot;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WinEHFrameVariableMaterializer : public ValueMaterializer {
|
class WinEHFrameVariableMaterializer : public ValueMaterializer {
|
||||||
public:
|
public:
|
||||||
WinEHFrameVariableMaterializer(Function *OutlinedFn,
|
WinEHFrameVariableMaterializer(Function *OutlinedFn, Value *ParentFP,
|
||||||
FrameVarInfoMap &FrameVarInfo);
|
FrameVarInfoMap &FrameVarInfo);
|
||||||
~WinEHFrameVariableMaterializer() override {}
|
~WinEHFrameVariableMaterializer() override {}
|
||||||
|
|
||||||
|
@ -179,16 +191,12 @@ private:
|
||||||
|
|
||||||
class WinEHCloningDirectorBase : public CloningDirector {
|
class WinEHCloningDirectorBase : public CloningDirector {
|
||||||
public:
|
public:
|
||||||
WinEHCloningDirectorBase(Function *HandlerFn, FrameVarInfoMap &VarInfo,
|
WinEHCloningDirectorBase(Function *HandlerFn, Value *ParentFP,
|
||||||
LandingPadMap &LPadMap)
|
FrameVarInfoMap &VarInfo, LandingPadMap &LPadMap)
|
||||||
: Materializer(HandlerFn, VarInfo),
|
: Materializer(HandlerFn, ParentFP, VarInfo),
|
||||||
SelectorIDType(Type::getInt32Ty(HandlerFn->getContext())),
|
SelectorIDType(Type::getInt32Ty(HandlerFn->getContext())),
|
||||||
Int8PtrType(Type::getInt8PtrTy(HandlerFn->getContext())),
|
Int8PtrType(Type::getInt8PtrTy(HandlerFn->getContext())),
|
||||||
LPadMap(LPadMap) {
|
LPadMap(LPadMap), ParentFP(ParentFP) {}
|
||||||
auto AI = HandlerFn->getArgumentList().begin();
|
|
||||||
++AI;
|
|
||||||
EstablisherFrame = AI;
|
|
||||||
}
|
|
||||||
|
|
||||||
CloningAction handleInstruction(ValueToValueMapTy &VMap,
|
CloningAction handleInstruction(ValueToValueMapTy &VMap,
|
||||||
const Instruction *Inst,
|
const Instruction *Inst,
|
||||||
|
@ -225,16 +233,16 @@ protected:
|
||||||
LandingPadMap &LPadMap;
|
LandingPadMap &LPadMap;
|
||||||
|
|
||||||
/// The value representing the parent frame pointer.
|
/// The value representing the parent frame pointer.
|
||||||
Value *EstablisherFrame;
|
Value *ParentFP;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WinEHCatchDirector : public WinEHCloningDirectorBase {
|
class WinEHCatchDirector : public WinEHCloningDirectorBase {
|
||||||
public:
|
public:
|
||||||
WinEHCatchDirector(
|
WinEHCatchDirector(
|
||||||
Function *CatchFn, Value *Selector, FrameVarInfoMap &VarInfo,
|
Function *CatchFn, Value *ParentFP, Value *Selector,
|
||||||
LandingPadMap &LPadMap,
|
FrameVarInfoMap &VarInfo, LandingPadMap &LPadMap,
|
||||||
DenseMap<LandingPadInst *, const LandingPadInst *> &NestedLPads)
|
DenseMap<LandingPadInst *, const LandingPadInst *> &NestedLPads)
|
||||||
: WinEHCloningDirectorBase(CatchFn, VarInfo, LPadMap),
|
: WinEHCloningDirectorBase(CatchFn, ParentFP, VarInfo, LPadMap),
|
||||||
CurrentSelector(Selector->stripPointerCasts()),
|
CurrentSelector(Selector->stripPointerCasts()),
|
||||||
ExceptionObjectVar(nullptr), NestedLPtoOriginalLP(NestedLPads) {}
|
ExceptionObjectVar(nullptr), NestedLPtoOriginalLP(NestedLPads) {}
|
||||||
|
|
||||||
|
@ -272,9 +280,10 @@ private:
|
||||||
|
|
||||||
class WinEHCleanupDirector : public WinEHCloningDirectorBase {
|
class WinEHCleanupDirector : public WinEHCloningDirectorBase {
|
||||||
public:
|
public:
|
||||||
WinEHCleanupDirector(Function *CleanupFn, FrameVarInfoMap &VarInfo,
|
WinEHCleanupDirector(Function *CleanupFn, Value *ParentFP,
|
||||||
LandingPadMap &LPadMap)
|
FrameVarInfoMap &VarInfo, LandingPadMap &LPadMap)
|
||||||
: WinEHCloningDirectorBase(CleanupFn, VarInfo, LPadMap) {}
|
: WinEHCloningDirectorBase(CleanupFn, ParentFP, VarInfo,
|
||||||
|
LPadMap) {}
|
||||||
|
|
||||||
CloningAction handleBeginCatch(ValueToValueMapTy &VMap,
|
CloningAction handleBeginCatch(ValueToValueMapTy &VMap,
|
||||||
const Instruction *Inst,
|
const Instruction *Inst,
|
||||||
|
@ -880,19 +889,23 @@ bool WinEHPrepare::prepareExceptionHandlers(
|
||||||
if (TempAlloca == getCatchObjectSentinel())
|
if (TempAlloca == getCatchObjectSentinel())
|
||||||
continue; // Skip catch parameter sentinels.
|
continue; // Skip catch parameter sentinels.
|
||||||
Function *HandlerFn = TempAlloca->getParent()->getParent();
|
Function *HandlerFn = TempAlloca->getParent()->getParent();
|
||||||
// FIXME: Sink this GEP into the blocks where it is used.
|
llvm::Value *FP = HandlerToParentFP[HandlerFn];
|
||||||
|
assert(FP);
|
||||||
|
|
||||||
|
// FIXME: Sink this framerecover into the blocks where it is used.
|
||||||
Builder.SetInsertPoint(TempAlloca);
|
Builder.SetInsertPoint(TempAlloca);
|
||||||
Builder.SetCurrentDebugLocation(TempAlloca->getDebugLoc());
|
Builder.SetCurrentDebugLocation(TempAlloca->getDebugLoc());
|
||||||
Value *RecoverArgs[] = {
|
Value *RecoverArgs[] = {
|
||||||
Builder.CreateBitCast(&F, Int8PtrType, ""),
|
Builder.CreateBitCast(&F, Int8PtrType, ""), FP,
|
||||||
&(HandlerFn->getArgumentList().back()),
|
|
||||||
llvm::ConstantInt::get(Int32Type, AllocasToEscape.size() - 1)};
|
llvm::ConstantInt::get(Int32Type, AllocasToEscape.size() - 1)};
|
||||||
Value *RecoveredAlloca = Builder.CreateCall(RecoverFrameFn, RecoverArgs);
|
Instruction *RecoveredAlloca =
|
||||||
|
Builder.CreateCall(RecoverFrameFn, RecoverArgs);
|
||||||
|
|
||||||
// Add a pointer bitcast if the alloca wasn't an i8.
|
// Add a pointer bitcast if the alloca wasn't an i8.
|
||||||
if (RecoveredAlloca->getType() != TempAlloca->getType()) {
|
if (RecoveredAlloca->getType() != TempAlloca->getType()) {
|
||||||
RecoveredAlloca->setName(Twine(TempAlloca->getName()) + ".i8");
|
RecoveredAlloca->setName(Twine(TempAlloca->getName()) + ".i8");
|
||||||
RecoveredAlloca =
|
RecoveredAlloca = cast<Instruction>(
|
||||||
Builder.CreateBitCast(RecoveredAlloca, TempAlloca->getType());
|
Builder.CreateBitCast(RecoveredAlloca, TempAlloca->getType()));
|
||||||
}
|
}
|
||||||
TempAlloca->replaceAllUsesWith(RecoveredAlloca);
|
TempAlloca->replaceAllUsesWith(RecoveredAlloca);
|
||||||
TempAlloca->removeFromParent();
|
TempAlloca->removeFromParent();
|
||||||
|
@ -918,6 +931,8 @@ bool WinEHPrepare::prepareExceptionHandlers(
|
||||||
CatchHandlerMap.clear();
|
CatchHandlerMap.clear();
|
||||||
DeleteContainerSeconds(CleanupHandlerMap);
|
DeleteContainerSeconds(CleanupHandlerMap);
|
||||||
CleanupHandlerMap.clear();
|
CleanupHandlerMap.clear();
|
||||||
|
HandlerToParentFP.clear();
|
||||||
|
DT = nullptr;
|
||||||
|
|
||||||
return HandlersOutlined;
|
return HandlersOutlined;
|
||||||
}
|
}
|
||||||
|
@ -987,7 +1002,6 @@ void WinEHPrepare::completeNestedLandingPad(Function *ParentFn,
|
||||||
IntrinsicInst *EHActions = cast<IntrinsicInst>(Recover->clone());
|
IntrinsicInst *EHActions = cast<IntrinsicInst>(Recover->clone());
|
||||||
|
|
||||||
// Remap the exception variables into the outlined function.
|
// Remap the exception variables into the outlined function.
|
||||||
WinEHFrameVariableMaterializer Materializer(OutlinedHandlerFn, FrameVarInfo);
|
|
||||||
SmallVector<BlockAddress *, 4> ActionTargets;
|
SmallVector<BlockAddress *, 4> ActionTargets;
|
||||||
SmallVector<ActionHandler *, 4> ActionList;
|
SmallVector<ActionHandler *, 4> ActionList;
|
||||||
parseEHActions(EHActions, ActionList);
|
parseEHActions(EHActions, ActionList);
|
||||||
|
@ -1148,35 +1162,62 @@ void WinEHPrepare::addStubInvokeToHandlerIfNeeded(Function *Handler,
|
||||||
InvokeInst::Create(F, NewRetBB, StubLandingPad, None, "", OldRetBB);
|
InvokeInst::Create(F, NewRetBB, StubLandingPad, None, "", OldRetBB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Consider sinking this into lib/Target/X86 somehow. TargetLowering
|
||||||
|
// usually doesn't build LLVM IR, so that's probably the wrong place.
|
||||||
|
Function *WinEHPrepare::createHandlerFunc(Type *RetTy, const Twine &Name,
|
||||||
|
Module *M, Value *&ParentFP) {
|
||||||
|
// x64 uses a two-argument prototype where the parent FP is the second
|
||||||
|
// argument. x86 uses no arguments, just the incoming EBP value.
|
||||||
|
LLVMContext &Context = M->getContext();
|
||||||
|
FunctionType *FnType;
|
||||||
|
if (TheTriple.getArch() == Triple::x86_64) {
|
||||||
|
Type *Int8PtrType = Type::getInt8PtrTy(Context);
|
||||||
|
Type *ArgTys[2] = {Int8PtrType, Int8PtrType};
|
||||||
|
FnType = FunctionType::get(RetTy, ArgTys, false);
|
||||||
|
} else {
|
||||||
|
FnType = FunctionType::get(RetTy, None, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Function *Handler =
|
||||||
|
Function::Create(FnType, GlobalVariable::InternalLinkage, Name, M);
|
||||||
|
BasicBlock *Entry = BasicBlock::Create(Context, "entry");
|
||||||
|
Handler->getBasicBlockList().push_front(Entry);
|
||||||
|
if (TheTriple.getArch() == Triple::x86_64) {
|
||||||
|
ParentFP = &(Handler->getArgumentList().back());
|
||||||
|
} else {
|
||||||
|
assert(M);
|
||||||
|
Function *FrameAddressFn =
|
||||||
|
Intrinsic::getDeclaration(M, Intrinsic::frameaddress);
|
||||||
|
Value *Args[1] = {ConstantInt::get(Type::getInt32Ty(Context), 1)};
|
||||||
|
ParentFP = CallInst::Create(FrameAddressFn, Args, "parent_fp",
|
||||||
|
&Handler->getEntryBlock());
|
||||||
|
}
|
||||||
|
return Handler;
|
||||||
|
}
|
||||||
|
|
||||||
bool WinEHPrepare::outlineHandler(ActionHandler *Action, Function *SrcFn,
|
bool WinEHPrepare::outlineHandler(ActionHandler *Action, Function *SrcFn,
|
||||||
LandingPadInst *LPad, BasicBlock *StartBB,
|
LandingPadInst *LPad, BasicBlock *StartBB,
|
||||||
FrameVarInfoMap &VarInfo) {
|
FrameVarInfoMap &VarInfo) {
|
||||||
Module *M = SrcFn->getParent();
|
Module *M = SrcFn->getParent();
|
||||||
LLVMContext &Context = M->getContext();
|
LLVMContext &Context = M->getContext();
|
||||||
|
Type *Int8PtrType = Type::getInt8PtrTy(Context);
|
||||||
|
|
||||||
// Create a new function to receive the handler contents.
|
// Create a new function to receive the handler contents.
|
||||||
Type *Int8PtrType = Type::getInt8PtrTy(Context);
|
Value *ParentFP;
|
||||||
std::vector<Type *> ArgTys;
|
|
||||||
ArgTys.push_back(Int8PtrType);
|
|
||||||
ArgTys.push_back(Int8PtrType);
|
|
||||||
Function *Handler;
|
Function *Handler;
|
||||||
if (Action->getType() == Catch) {
|
if (Action->getType() == Catch) {
|
||||||
FunctionType *FnType = FunctionType::get(Int8PtrType, ArgTys, false);
|
Handler = createHandlerFunc(Int8PtrType, SrcFn->getName() + ".catch", M,
|
||||||
Handler = Function::Create(FnType, GlobalVariable::InternalLinkage,
|
ParentFP);
|
||||||
SrcFn->getName() + ".catch", M);
|
|
||||||
} else {
|
} else {
|
||||||
FunctionType *FnType =
|
Handler = createHandlerFunc(Type::getVoidTy(Context),
|
||||||
FunctionType::get(Type::getVoidTy(Context), ArgTys, false);
|
SrcFn->getName() + ".cleanup", M, ParentFP);
|
||||||
Handler = Function::Create(FnType, GlobalVariable::InternalLinkage,
|
|
||||||
SrcFn->getName() + ".cleanup", M);
|
|
||||||
}
|
}
|
||||||
|
HandlerToParentFP[Handler] = ParentFP;
|
||||||
Handler->addFnAttr("wineh-parent", SrcFn->getName());
|
Handler->addFnAttr("wineh-parent", SrcFn->getName());
|
||||||
|
BasicBlock *Entry = &Handler->getEntryBlock();
|
||||||
|
|
||||||
// Generate a standard prolog to setup the frame recovery structure.
|
// Generate a standard prolog to setup the frame recovery structure.
|
||||||
IRBuilder<> Builder(Context);
|
IRBuilder<> Builder(Context);
|
||||||
BasicBlock *Entry = BasicBlock::Create(Context, "entry");
|
|
||||||
Handler->getBasicBlockList().push_front(Entry);
|
|
||||||
Builder.SetInsertPoint(Entry);
|
Builder.SetInsertPoint(Entry);
|
||||||
Builder.SetCurrentDebugLocation(LPad->getDebugLoc());
|
Builder.SetCurrentDebugLocation(LPad->getDebugLoc());
|
||||||
|
|
||||||
|
@ -1189,12 +1230,14 @@ bool WinEHPrepare::outlineHandler(ActionHandler *Action, Function *SrcFn,
|
||||||
LPadMap.mapLandingPad(LPad);
|
LPadMap.mapLandingPad(LPad);
|
||||||
if (auto *CatchAction = dyn_cast<CatchHandler>(Action)) {
|
if (auto *CatchAction = dyn_cast<CatchHandler>(Action)) {
|
||||||
Constant *Sel = CatchAction->getSelector();
|
Constant *Sel = CatchAction->getSelector();
|
||||||
Director.reset(new WinEHCatchDirector(Handler, Sel, VarInfo, LPadMap,
|
Director.reset(new WinEHCatchDirector(Handler, ParentFP, Sel,
|
||||||
|
VarInfo, LPadMap,
|
||||||
NestedLPtoOriginalLP));
|
NestedLPtoOriginalLP));
|
||||||
LPadMap.remapEHValues(VMap, UndefValue::get(Int8PtrType),
|
LPadMap.remapEHValues(VMap, UndefValue::get(Int8PtrType),
|
||||||
ConstantInt::get(Type::getInt32Ty(Context), 1));
|
ConstantInt::get(Type::getInt32Ty(Context), 1));
|
||||||
} else {
|
} else {
|
||||||
Director.reset(new WinEHCleanupDirector(Handler, VarInfo, LPadMap));
|
Director.reset(
|
||||||
|
new WinEHCleanupDirector(Handler, ParentFP, VarInfo, LPadMap));
|
||||||
LPadMap.remapEHValues(VMap, UndefValue::get(Int8PtrType),
|
LPadMap.remapEHValues(VMap, UndefValue::get(Int8PtrType),
|
||||||
UndefValue::get(Type::getInt32Ty(Context)));
|
UndefValue::get(Type::getInt32Ty(Context)));
|
||||||
}
|
}
|
||||||
|
@ -1421,7 +1464,7 @@ CloningDirector::CloningAction WinEHCloningDirectorBase::handleInstruction(
|
||||||
// When outlining llvm.frameaddress(i32 0), remap that to the second argument,
|
// When outlining llvm.frameaddress(i32 0), remap that to the second argument,
|
||||||
// which is the FP of the parent.
|
// which is the FP of the parent.
|
||||||
if (isFrameAddressCall(Inst)) {
|
if (isFrameAddressCall(Inst)) {
|
||||||
VMap[Inst] = EstablisherFrame;
|
VMap[Inst] = ParentFP;
|
||||||
return CloningDirector::SkipInstruction;
|
return CloningDirector::SkipInstruction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1660,10 +1703,16 @@ WinEHCleanupDirector::handleCompare(ValueToValueMapTy &VMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
WinEHFrameVariableMaterializer::WinEHFrameVariableMaterializer(
|
WinEHFrameVariableMaterializer::WinEHFrameVariableMaterializer(
|
||||||
Function *OutlinedFn, FrameVarInfoMap &FrameVarInfo)
|
Function *OutlinedFn, Value *ParentFP, FrameVarInfoMap &FrameVarInfo)
|
||||||
: FrameVarInfo(FrameVarInfo), Builder(OutlinedFn->getContext()) {
|
: FrameVarInfo(FrameVarInfo), Builder(OutlinedFn->getContext()) {
|
||||||
BasicBlock *EntryBB = &OutlinedFn->getEntryBlock();
|
BasicBlock *EntryBB = &OutlinedFn->getEntryBlock();
|
||||||
Builder.SetInsertPoint(EntryBB, EntryBB->getFirstInsertionPt());
|
|
||||||
|
// New allocas should be inserted in the entry block, but after the parent FP
|
||||||
|
// is established if it is an instruction.
|
||||||
|
Instruction *InsertPoint = EntryBB->getFirstInsertionPt();
|
||||||
|
if (auto *FPInst = dyn_cast<Instruction>(ParentFP))
|
||||||
|
InsertPoint = FPInst->getNextNode();
|
||||||
|
Builder.SetInsertPoint(EntryBB, InsertPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *WinEHFrameVariableMaterializer::materializeValueFor(Value *V) {
|
Value *WinEHFrameVariableMaterializer::materializeValueFor(Value *V) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
; RUN: opt -winehprepare -S < %s | FileCheck %s
|
; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S < %s | FileCheck %s
|
||||||
|
|
||||||
; Notionally based on this C++ source:
|
; Notionally based on this C++ source:
|
||||||
; int liveout_catch(int p) {
|
; int liveout_catch(int p) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
; RUN: opt -mtriple=i386-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
|
; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
|
||||||
|
|
||||||
; This test is built from the following code:
|
; This test is built from the following code:
|
||||||
; struct A {
|
; struct A {
|
||||||
|
@ -24,8 +24,6 @@
|
||||||
; the inalloca instruction was manually sunk into the landingpad.
|
; the inalloca instruction was manually sunk into the landingpad.
|
||||||
|
|
||||||
; ModuleID = 'cppeh-inalloca.cpp'
|
; ModuleID = 'cppeh-inalloca.cpp'
|
||||||
target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
|
|
||||||
target triple = "i386-pc-windows-msvc"
|
|
||||||
|
|
||||||
%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
|
%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
|
||||||
%struct.A = type { i32 }
|
%struct.A = type { i32 }
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
; RUN: opt -S -winehprepare -mtriple=x86_64-windows-msvc < %s | FileCheck %s
|
; RUN: opt -S -winehprepare -mtriple=x86_64-windows-msvc < %s \
|
||||||
|
; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=X64
|
||||||
|
|
||||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
; This test should also pass in 32-bit using _except_handler3.
|
||||||
target triple = "x86_64-pc-windows-msvc"
|
; RUN: sed %s -e 's/__C_specific_handler/_except_handler3/' \
|
||||||
|
; RUN: | opt -S -winehprepare -mtriple=i686-windows-msvc \
|
||||||
|
; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=X86
|
||||||
|
|
||||||
declare void @cleanup()
|
declare void @cleanup()
|
||||||
declare i32 @filt()
|
declare i32 @filt()
|
||||||
|
@ -139,7 +142,7 @@ eh.resume:
|
||||||
; CHECK: landingpad { i8*, i32 }
|
; CHECK: landingpad { i8*, i32 }
|
||||||
; CHECK-NEXT: cleanup
|
; CHECK-NEXT: cleanup
|
||||||
; CHECK-NEXT: catch i32 ()* @filt
|
; CHECK-NEXT: catch i32 ()* @filt
|
||||||
; CHECK-NEXT: call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @lpad_phi.cleanup, i32 1, i8* bitcast (i32 ()* @filt to i8*), i32 -1, i8* blockaddress(@lpad_phi, %lpad.return_crit_edge))
|
; CHECK-NEXT: call i8* (...) @llvm.eh.actions(i32 0, void ({{.*}})* @lpad_phi.cleanup, i32 1, i8* bitcast (i32 ()* @filt to i8*), i32 -1, i8* blockaddress(@lpad_phi, %lpad.return_crit_edge))
|
||||||
; CHECK-NEXT: indirectbr {{.*}} [label %lpad.return_crit_edge]
|
; CHECK-NEXT: indirectbr {{.*}} [label %lpad.return_crit_edge]
|
||||||
;
|
;
|
||||||
; CHECK: lpad.return_crit_edge:
|
; CHECK: lpad.return_crit_edge:
|
||||||
|
@ -178,7 +181,7 @@ eh.resume:
|
||||||
; CHECK-NEXT: cleanup
|
; CHECK-NEXT: cleanup
|
||||||
; CHECK-NEXT: catch i32 ()* @filt
|
; CHECK-NEXT: catch i32 ()* @filt
|
||||||
; CHECK-NEXT: call i8* (...) @llvm.eh.actions(
|
; CHECK-NEXT: call i8* (...) @llvm.eh.actions(
|
||||||
; CHECK: i32 0, void (i8*, i8*)* @cleanup_and_except.cleanup,
|
; CHECK: i32 0, void ({{.*}})* @cleanup_and_except.cleanup,
|
||||||
; CHECK: i32 1, i8* bitcast (i32 ()* @filt to i8*), i32 -1, i8* blockaddress(@cleanup_and_except, %lpad.return_crit_edge))
|
; CHECK: i32 1, i8* bitcast (i32 ()* @filt to i8*), i32 -1, i8* blockaddress(@cleanup_and_except, %lpad.return_crit_edge))
|
||||||
; CHECK-NEXT: indirectbr {{.*}} [label %lpad.return_crit_edge]
|
; CHECK-NEXT: indirectbr {{.*}} [label %lpad.return_crit_edge]
|
||||||
;
|
;
|
||||||
|
@ -190,6 +193,9 @@ eh.resume:
|
||||||
; CHECK-NEXT: ret i32 %r
|
; CHECK-NEXT: ret i32 %r
|
||||||
|
|
||||||
; FIXME: This cleanup is an artifact of bad demotion.
|
; FIXME: This cleanup is an artifact of bad demotion.
|
||||||
; CHECK-LABEL: define internal void @lpad_phi.cleanup(i8*, i8*)
|
; X64-LABEL: define internal void @lpad_phi.cleanup(i8*, i8*)
|
||||||
|
; X86-LABEL: define internal void @lpad_phi.cleanup()
|
||||||
|
; X86: call i8* @llvm.frameaddress(i32 1)
|
||||||
|
; CHECK: call i8* @llvm.framerecover({{.*}})
|
||||||
; CHECK: load i32
|
; CHECK: load i32
|
||||||
; CHECK: store i32 %{{.*}}, i32*
|
; CHECK: store i32 %{{.*}}, i32*
|
||||||
|
|
Loading…
Reference in New Issue