Skip to content

Commit

Permalink
[X86] Cleanup the WinEHState pass
Browse files Browse the repository at this point in the history
Remove unnecessary includes and class state.

No functional change intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259340 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
majnemer committed Feb 1, 2016
1 parent f768b25 commit 8eacdc2
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions lib/Target/X86/X86WinEHState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,22 @@
//===----------------------------------------------------------------------===//

#include "X86.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/EHPersonalities.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/Passes.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/IntrinsicInst.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PatternMatch.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::PatternMatch;

#define DEBUG_TYPE "winehstate"

namespace llvm { void initializeWinEHStatePassPass(PassRegistry &); }
namespace llvm {
void initializeWinEHStatePassPass(PassRegistry &);
}

namespace {
class WinEHStatePass : public FunctionPass {
Expand Down Expand Up @@ -68,7 +59,7 @@ class WinEHStatePass : public FunctionPass {
void linkExceptionRegistration(IRBuilder<> &Builder, Function *Handler);
void unlinkExceptionRegistration(IRBuilder<> &Builder);
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);

Expand Down Expand Up @@ -96,9 +87,6 @@ class WinEHStatePass : public FunctionPass {
/// fs:00 chain and the current state.
AllocaInst *RegNode = nullptr;

/// Struct type of RegNode. Used for GEPing.
Type *RegNodeTy = nullptr;

/// The index of the state field of RegNode.
int StateFieldIndex = ~0U;

Expand Down Expand Up @@ -256,6 +244,9 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
assert(Personality == EHPersonality::MSVC_CXX ||
Personality == EHPersonality::MSVC_X86SEH);

// Struct type of RegNode. Used for GEPing.
Type *RegNodeTy;

StringRef PersonalityName = PersonalityFn->getName();
IRBuilder<> Builder(&F->getEntryBlock(), F->getEntryBlock().begin());
Type *Int8PtrType = Builder.getInt8PtrTy();
Expand All @@ -268,7 +259,7 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
// TryLevel = -1
StateFieldIndex = 2;
insertStateNumberStore(RegNode, &*Builder.GetInsertPoint(), -1);
insertStateNumberStore(&*Builder.GetInsertPoint(), -1);
// Handler = __ehhandler$F
Function *Trampoline = generateLSDAInEAXThunk(F);
Link = Builder.CreateStructGEP(RegNodeTy, RegNode, 1);
Expand All @@ -285,8 +276,7 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
// TryLevel = -2 / -1
StateFieldIndex = 4;
insertStateNumberStore(RegNode, &*Builder.GetInsertPoint(),
UseStackGuard ? -2 : -1);
insertStateNumberStore(&*Builder.GetInsertPoint(), UseStackGuard ? -2 : -1);
// ScopeTable = llvm.x86.seh.lsda(F)
Value *FI8 = Builder.CreateBitCast(F, Int8PtrType);
Value *LSDA = Builder.CreateCall(
Expand Down Expand Up @@ -440,21 +430,20 @@ void WinEHStatePass::addStateStores(Function &F, WinEHFuncInfo &FuncInfo) {
// an unwind. Ensure they are in the -1 state.
if (CI->doesNotThrow())
continue;
insertStateNumberStore(RegNode, CI, BaseState);
insertStateNumberStore(CI, BaseState);
} else if (auto *II = dyn_cast<InvokeInst>(&I)) {
// Look up the state number of the landingpad this unwinds to.
assert(FuncInfo.InvokeStateMap.count(II) && "invoke has no state!");
int State = FuncInfo.InvokeStateMap[II];
insertStateNumberStore(RegNode, II, State);
insertStateNumberStore(II, State);
}
}
}
}

void WinEHStatePass::insertStateNumberStore(Value *ParentRegNode,
Instruction *IP, int State) {
void WinEHStatePass::insertStateNumberStore(Instruction *IP, int State) {
IRBuilder<> Builder(IP);
Value *StateField =
Builder.CreateStructGEP(RegNodeTy, ParentRegNode, StateFieldIndex);
Builder.CreateStructGEP(nullptr, RegNode, StateFieldIndex);
Builder.CreateStore(Builder.getInt32(State), StateField);
}

0 comments on commit 8eacdc2

Please sign in to comment.