forked from OSchip/llvm-project
[X86] Cleanup the WinEHState pass
Remove unnecessary includes and class state. No functional change intended. llvm-svn: 259340
This commit is contained in:
parent
0314e1e1ef
commit
efb41741f2
|
@ -15,31 +15,22 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "X86.h"
|
#include "X86.h"
|
||||||
#include "llvm/Analysis/CFG.h"
|
|
||||||
#include "llvm/Analysis/EHPersonalities.h"
|
#include "llvm/Analysis/EHPersonalities.h"
|
||||||
#include "llvm/CodeGen/MachineModuleInfo.h"
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
||||||
#include "llvm/CodeGen/Passes.h"
|
|
||||||
#include "llvm/CodeGen/WinEHFuncInfo.h"
|
#include "llvm/CodeGen/WinEHFuncInfo.h"
|
||||||
#include "llvm/IR/Dominators.h"
|
|
||||||
#include "llvm/IR/Function.h"
|
|
||||||
#include "llvm/IR/IRBuilder.h"
|
|
||||||
#include "llvm/IR/Instructions.h"
|
#include "llvm/IR/Instructions.h"
|
||||||
#include "llvm/IR/IntrinsicInst.h"
|
#include "llvm/IR/IntrinsicInst.h"
|
||||||
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/IR/PatternMatch.h"
|
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Support/Debug.h"
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
|
||||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
|
||||||
#include "llvm/Transforms/Utils/Cloning.h"
|
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace llvm::PatternMatch;
|
|
||||||
|
|
||||||
#define DEBUG_TYPE "winehstate"
|
#define DEBUG_TYPE "winehstate"
|
||||||
|
|
||||||
namespace llvm { void initializeWinEHStatePassPass(PassRegistry &); }
|
namespace llvm {
|
||||||
|
void initializeWinEHStatePassPass(PassRegistry &);
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class WinEHStatePass : public FunctionPass {
|
class WinEHStatePass : public FunctionPass {
|
||||||
|
@ -68,7 +59,7 @@ private:
|
||||||
void linkExceptionRegistration(IRBuilder<> &Builder, Function *Handler);
|
void linkExceptionRegistration(IRBuilder<> &Builder, Function *Handler);
|
||||||
void unlinkExceptionRegistration(IRBuilder<> &Builder);
|
void unlinkExceptionRegistration(IRBuilder<> &Builder);
|
||||||
void addStateStores(Function &F, WinEHFuncInfo &FuncInfo);
|
void addStateStores(Function &F, WinEHFuncInfo &FuncInfo);
|
||||||
void insertStateNumberStore(Value *ParentRegNode, Instruction *IP, int State);
|
void insertStateNumberStore(Instruction *IP, int State);
|
||||||
|
|
||||||
Value *emitEHLSDA(IRBuilder<> &Builder, Function *F);
|
Value *emitEHLSDA(IRBuilder<> &Builder, Function *F);
|
||||||
|
|
||||||
|
@ -96,9 +87,6 @@ private:
|
||||||
/// fs:00 chain and the current state.
|
/// fs:00 chain and the current state.
|
||||||
AllocaInst *RegNode = nullptr;
|
AllocaInst *RegNode = nullptr;
|
||||||
|
|
||||||
/// Struct type of RegNode. Used for GEPing.
|
|
||||||
Type *RegNodeTy = nullptr;
|
|
||||||
|
|
||||||
/// The index of the state field of RegNode.
|
/// The index of the state field of RegNode.
|
||||||
int StateFieldIndex = ~0U;
|
int StateFieldIndex = ~0U;
|
||||||
|
|
||||||
|
@ -256,6 +244,9 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
|
||||||
assert(Personality == EHPersonality::MSVC_CXX ||
|
assert(Personality == EHPersonality::MSVC_CXX ||
|
||||||
Personality == EHPersonality::MSVC_X86SEH);
|
Personality == EHPersonality::MSVC_X86SEH);
|
||||||
|
|
||||||
|
// Struct type of RegNode. Used for GEPing.
|
||||||
|
Type *RegNodeTy;
|
||||||
|
|
||||||
StringRef PersonalityName = PersonalityFn->getName();
|
StringRef PersonalityName = PersonalityFn->getName();
|
||||||
IRBuilder<> Builder(&F->getEntryBlock(), F->getEntryBlock().begin());
|
IRBuilder<> Builder(&F->getEntryBlock(), F->getEntryBlock().begin());
|
||||||
Type *Int8PtrType = Builder.getInt8PtrTy();
|
Type *Int8PtrType = Builder.getInt8PtrTy();
|
||||||
|
@ -268,7 +259,7 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
|
||||||
Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
|
Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
|
||||||
// TryLevel = -1
|
// TryLevel = -1
|
||||||
StateFieldIndex = 2;
|
StateFieldIndex = 2;
|
||||||
insertStateNumberStore(RegNode, &*Builder.GetInsertPoint(), -1);
|
insertStateNumberStore(&*Builder.GetInsertPoint(), -1);
|
||||||
// Handler = __ehhandler$F
|
// Handler = __ehhandler$F
|
||||||
Function *Trampoline = generateLSDAInEAXThunk(F);
|
Function *Trampoline = generateLSDAInEAXThunk(F);
|
||||||
Link = Builder.CreateStructGEP(RegNodeTy, RegNode, 1);
|
Link = Builder.CreateStructGEP(RegNodeTy, RegNode, 1);
|
||||||
|
@ -285,8 +276,7 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
|
||||||
Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
|
Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
|
||||||
// TryLevel = -2 / -1
|
// TryLevel = -2 / -1
|
||||||
StateFieldIndex = 4;
|
StateFieldIndex = 4;
|
||||||
insertStateNumberStore(RegNode, &*Builder.GetInsertPoint(),
|
insertStateNumberStore(&*Builder.GetInsertPoint(), UseStackGuard ? -2 : -1);
|
||||||
UseStackGuard ? -2 : -1);
|
|
||||||
// ScopeTable = llvm.x86.seh.lsda(F)
|
// ScopeTable = llvm.x86.seh.lsda(F)
|
||||||
Value *FI8 = Builder.CreateBitCast(F, Int8PtrType);
|
Value *FI8 = Builder.CreateBitCast(F, Int8PtrType);
|
||||||
Value *LSDA = Builder.CreateCall(
|
Value *LSDA = Builder.CreateCall(
|
||||||
|
@ -440,21 +430,20 @@ void WinEHStatePass::addStateStores(Function &F, WinEHFuncInfo &FuncInfo) {
|
||||||
// an unwind. Ensure they are in the -1 state.
|
// an unwind. Ensure they are in the -1 state.
|
||||||
if (CI->doesNotThrow())
|
if (CI->doesNotThrow())
|
||||||
continue;
|
continue;
|
||||||
insertStateNumberStore(RegNode, CI, BaseState);
|
insertStateNumberStore(CI, BaseState);
|
||||||
} else if (auto *II = dyn_cast<InvokeInst>(&I)) {
|
} else if (auto *II = dyn_cast<InvokeInst>(&I)) {
|
||||||
// Look up the state number of the landingpad this unwinds to.
|
// Look up the state number of the landingpad this unwinds to.
|
||||||
assert(FuncInfo.InvokeStateMap.count(II) && "invoke has no state!");
|
assert(FuncInfo.InvokeStateMap.count(II) && "invoke has no state!");
|
||||||
int State = FuncInfo.InvokeStateMap[II];
|
int State = FuncInfo.InvokeStateMap[II];
|
||||||
insertStateNumberStore(RegNode, II, State);
|
insertStateNumberStore(II, State);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinEHStatePass::insertStateNumberStore(Value *ParentRegNode,
|
void WinEHStatePass::insertStateNumberStore(Instruction *IP, int State) {
|
||||||
Instruction *IP, int State) {
|
|
||||||
IRBuilder<> Builder(IP);
|
IRBuilder<> Builder(IP);
|
||||||
Value *StateField =
|
Value *StateField =
|
||||||
Builder.CreateStructGEP(RegNodeTy, ParentRegNode, StateFieldIndex);
|
Builder.CreateStructGEP(nullptr, RegNode, StateFieldIndex);
|
||||||
Builder.CreateStore(Builder.getInt32(State), StateField);
|
Builder.CreateStore(Builder.getInt32(State), StateField);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue