summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2015-05-01 20:14:04 +0000
committerReid Kleckner <reid@kleckner.net>2015-05-01 20:14:04 +0000
commit2747d3d55a2a4c67c2126b42c4eb823ed456b2a4 (patch)
treef175df2251cd7dde883fddb098ff5c5354eee7e1 /llvm/lib
parent4856fc61b4820992534be6a0040dfc4ab9c7b207 (diff)
downloadbcm5719-llvm-2747d3d55a2a4c67c2126b42c4eb823ed456b2a4.tar.gz
bcm5719-llvm-2747d3d55a2a4c67c2126b42c4eb823ed456b2a4.zip
Revert "[WinEH] Add an EH registration and state insertion pass for 32-bit x86"
This reverts commit r236339, it breaks the win32 clang-cl self-host. llvm-svn: 236340
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp2
-rw-r--r--llvm/lib/CodeGen/WinEHPrepare.cpp11
-rw-r--r--llvm/lib/Target/X86/CMakeLists.txt1
-rw-r--r--llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp3
-rw-r--r--llvm/lib/Target/X86/X86.h6
-rw-r--r--llvm/lib/Target/X86/X86TargetMachine.cpp9
-rw-r--r--llvm/lib/Target/X86/X86WinEHState.cpp317
7 files changed, 6 insertions, 343 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index f385ac3c3d5..d56a1808049 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -266,8 +266,6 @@ bool AsmPrinter::doInitialization(Module &M) {
case ExceptionHandling::WinEH:
switch (MAI->getWinEHEncodingType()) {
default: llvm_unreachable("unsupported unwinding information encoding");
- case WinEH::EncodingType::Invalid:
- break;
case WinEH::EncodingType::Itanium:
ES = new Win64Exception(this);
break;
diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp
index db91c02ee46..c1067c5d560 100644
--- a/llvm/lib/CodeGen/WinEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WinEHPrepare.cpp
@@ -8,11 +8,9 @@
//===----------------------------------------------------------------------===//
//
// This pass lowers LLVM IR exception handling into something closer to what the
-// backend wants for functions using a personality function from a runtime
-// provided by MSVC. Functions with other personality functions are left alone
-// and may be prepared by other passes. In particular, all supported MSVC
-// personality functions require cleanup code to be outlined, and the C++
-// personality requires catch handler code to be outlined.
+// backend wants. It snifs the personality function to see which kind of
+// preparation is necessary. If the personality function uses the Itanium LSDA,
+// this pass delegates to the DWARF EH preparation pass.
//
//===----------------------------------------------------------------------===//
@@ -33,6 +31,7 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Pass.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -923,7 +922,7 @@ bool WinEHPrepare::prepareExceptionHandlers(
if (SEHExceptionCodeSlot) {
if (SEHExceptionCodeSlot->hasNUses(0))
SEHExceptionCodeSlot->eraseFromParent();
- else if (isAllocaPromotable(SEHExceptionCodeSlot))
+ else
PromoteMemToReg(SEHExceptionCodeSlot, *DT);
}
diff --git a/llvm/lib/Target/X86/CMakeLists.txt b/llvm/lib/Target/X86/CMakeLists.txt
index be8e7f6b7c5..be61b4701aa 100644
--- a/llvm/lib/Target/X86/CMakeLists.txt
+++ b/llvm/lib/Target/X86/CMakeLists.txt
@@ -32,7 +32,6 @@ set(sources
X86TargetTransformInfo.cpp
X86VZeroUpper.cpp
X86FixupLEAs.cpp
- X86WinEHState.cpp
)
if( CMAKE_CL_64 )
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
index bda35f2b972..e64b9635ba0 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
@@ -132,10 +132,9 @@ X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
PrivateLabelPrefix = ".L";
PointerSize = 8;
WinEHEncodingType = WinEH::EncodingType::Itanium;
+ ExceptionsType = ExceptionHandling::WinEH;
}
- ExceptionsType = ExceptionHandling::WinEH;
-
AssemblerDialect = AsmWriterFlavor;
TextAlignFillValue = 0x90;
diff --git a/llvm/lib/Target/X86/X86.h b/llvm/lib/Target/X86/X86.h
index 62c65bacef5..8b0a4cf477f 100644
--- a/llvm/lib/Target/X86/X86.h
+++ b/llvm/lib/Target/X86/X86.h
@@ -69,12 +69,6 @@ FunctionPass *createX86FixupLEAs();
/// esp-relative movs with pushes.
FunctionPass *createX86CallFrameOptimization();
-/// createX86WinEHStatePass - Return an IR pass that inserts EH registration
-/// stack objects and explicit EH state updates. This pass must run after EH
-/// preparation, which does Windows-specific but architecture-neutral
-/// preparation.
-FunctionPass *createX86WinEHStatePass();
-
} // End llvm namespace
#endif
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index 9484f678808..919072aa913 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -185,7 +185,6 @@ public:
void addIRPasses() override;
bool addInstSelector() override;
bool addILPOpts() override;
- bool addPreISel() override;
void addPreRegAlloc() override;
void addPostRegAlloc() override;
void addPreEmitPass() override;
@@ -221,14 +220,6 @@ bool X86PassConfig::addILPOpts() {
return true;
}
-bool X86PassConfig::addPreISel() {
- // Only add this pass for 32-bit x86.
- Triple TT(TM->getTargetTriple());
- if (TT.getArch() == Triple::x86)
- addPass(createX86WinEHStatePass());
- return true;
-}
-
void X86PassConfig::addPreRegAlloc() {
addPass(createX86CallFrameOptimization());
}
diff --git a/llvm/lib/Target/X86/X86WinEHState.cpp b/llvm/lib/Target/X86/X86WinEHState.cpp
deleted file mode 100644
index e4bbffcc55a..00000000000
--- a/llvm/lib/Target/X86/X86WinEHState.cpp
+++ /dev/null
@@ -1,317 +0,0 @@
-//===-- X86WinEHState - Insert EH state updates for win32 exceptions ------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// All functions using an MSVC EH personality use an explicitly updated state
-// number stored in an exception registration stack object. The registration
-// object is linked into a thread-local chain of registrations stored at fs:00.
-// This pass adds the registration object and EH state updates.
-//
-//===----------------------------------------------------------------------===//
-
-#include "X86.h"
-#include "llvm/Analysis/LibCallSemantics.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/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 {
-class WinEHStatePass : public FunctionPass {
-public:
- static char ID; // Pass identification, replacement for typeid.
-
- WinEHStatePass() : FunctionPass(ID) {}
-
- bool runOnFunction(Function &Fn) override;
-
- bool doInitialization(Module &M) override;
-
- bool doFinalization(Module &M) override;
-
- void getAnalysisUsage(AnalysisUsage &AU) const override;
-
- const char *getPassName() const override {
- return "Windows 32-bit x86 EH state insertion";
- }
-
-private:
- void emitExceptionRegistrationRecord(Function *F);
-
- void linkExceptionRegistration(IRBuilder<> &Builder, Value *RegNode,
- Value *Handler);
- void unlinkExceptionRegistration(IRBuilder<> &Builder, Value *RegNode);
-
- // Module-level type getters.
- Type *getEHRegistrationType();
- Type *getSEH3RegistrationType();
- Type *getSEH4RegistrationType();
- Type *getCXXEH3RegistrationType();
-
- // Per-module data.
- Module *TheModule = nullptr;
- StructType *EHRegistrationTy = nullptr;
- StructType *CXXEH3RegistrationTy = nullptr;
- StructType *SEH3RegistrationTy = nullptr;
- StructType *SEH4RegistrationTy = nullptr;
-
- // Per-function state
- EHPersonality Personality = EHPersonality::Unknown;
- Function *PersonalityFn = nullptr;
-};
-}
-
-FunctionPass *llvm::createX86WinEHStatePass() { return new WinEHStatePass(); }
-
-char WinEHStatePass::ID = 0;
-
-bool WinEHStatePass::doInitialization(Module &M) {
- TheModule = &M;
- return false;
-}
-
-bool WinEHStatePass::doFinalization(Module &M) {
- assert(TheModule == &M);
- TheModule = nullptr;
- EHRegistrationTy = nullptr;
- CXXEH3RegistrationTy = nullptr;
- SEH3RegistrationTy = nullptr;
- SEH4RegistrationTy = nullptr;
- return false;
-}
-
-void WinEHStatePass::getAnalysisUsage(AnalysisUsage &AU) const {
- // This pass should only insert a stack allocation, memory accesses, and
- // framerecovers.
- AU.setPreservesCFG();
-}
-
-bool WinEHStatePass::runOnFunction(Function &F) {
- // Check the personality. Do nothing if this is not an MSVC personality.
- LandingPadInst *LP = nullptr;
- for (BasicBlock &BB : F) {
- LP = BB.getLandingPadInst();
- if (LP)
- break;
- }
- if (!LP)
- return false;
- PersonalityFn =
- dyn_cast<Function>(LP->getPersonalityFn()->stripPointerCasts());
- if (!PersonalityFn)
- return false;
- Personality = classifyEHPersonality(PersonalityFn);
- if (!isMSVCEHPersonality(Personality))
- return false;
-
- emitExceptionRegistrationRecord(&F);
- // FIXME: State insertion.
-
- // Reset per-function state.
- PersonalityFn = nullptr;
- Personality = EHPersonality::Unknown;
- return true;
-}
-
-/// Get the common EH registration subobject:
-/// struct EHRegistrationNode {
-/// EHRegistrationNode *Next;
-/// EXCEPTION_DISPOSITION (*Handler)(...);
-/// };
-Type *WinEHStatePass::getEHRegistrationType() {
- if (EHRegistrationTy)
- return EHRegistrationTy;
- LLVMContext &Context = TheModule->getContext();
- EHRegistrationTy = StructType::create(Context, "EHRegistrationNode");
- Type *FieldTys[] = {
- EHRegistrationTy->getPointerTo(0), // EHRegistrationNode *Next
- Type::getInt8PtrTy(Context) // EXCEPTION_DISPOSITION (*Handler)(...)
- };
- EHRegistrationTy->setBody(FieldTys, false);
- return EHRegistrationTy;
-}
-
-/// The __CxxFrameHandler3 registration node:
-/// struct CXXExceptionRegistration {
-/// void *SavedESP;
-/// EHRegistrationNode SubRecord;
-/// int32_t TryLevel;
-/// };
-Type *WinEHStatePass::getCXXEH3RegistrationType() {
- if (CXXEH3RegistrationTy)
- return CXXEH3RegistrationTy;
- LLVMContext &Context = TheModule->getContext();
- Type *FieldTys[] = {
- Type::getInt8PtrTy(Context), // void *SavedESP
- getEHRegistrationType(), // EHRegistrationNode SubRecord
- Type::getInt32Ty(Context) // int32_t TryLevel
- };
- CXXEH3RegistrationTy =
- StructType::create(FieldTys, "CXXExceptionRegistration");
- return CXXEH3RegistrationTy;
-}
-
-/// The _except_handler3 registration node:
-/// struct EH3ExceptionRegistration {
-/// EHRegistrationNode SubRecord;
-/// void *ScopeTable;
-/// int32_t TryLevel;
-/// };
-Type *WinEHStatePass::getSEH3RegistrationType() {
- if (SEH3RegistrationTy)
- return SEH3RegistrationTy;
- LLVMContext &Context = TheModule->getContext();
- Type *FieldTys[] = {
- getEHRegistrationType(), // EHRegistrationNode SubRecord
- Type::getInt8PtrTy(Context), // void *ScopeTable
- Type::getInt32Ty(Context) // int32_t TryLevel
- };
- SEH3RegistrationTy = StructType::create(FieldTys, "EH3ExceptionRegistration");
- return SEH3RegistrationTy;
-}
-
-/// The _except_handler4 registration node:
-/// struct EH4ExceptionRegistration {
-/// void *SavedESP;
-/// _EXCEPTION_POINTERS *ExceptionPointers;
-/// EHRegistrationNode SubRecord;
-/// int32_t EncodedScopeTable;
-/// int32_t TryLevel;
-/// };
-Type *WinEHStatePass::getSEH4RegistrationType() {
- if (SEH4RegistrationTy)
- return SEH4RegistrationTy;
- LLVMContext &Context = TheModule->getContext();
- Type *FieldTys[] = {
- Type::getInt8PtrTy(Context), // void *SavedESP
- Type::getInt8PtrTy(Context), // void *ExceptionPointers
- getEHRegistrationType(), // EHRegistrationNode SubRecord
- Type::getInt32Ty(Context), // int32_t EncodedScopeTable
- Type::getInt32Ty(Context) // int32_t TryLevel
- };
- SEH4RegistrationTy = StructType::create(FieldTys, "EH4ExceptionRegistration");
- return SEH4RegistrationTy;
-}
-
-// Emit an exception registration record. These are stack allocations with the
-// common subobject of two pointers: the previous registration record (the old
-// fs:00) and the personality function for the current frame. The data before
-// and after that is personality function specific.
-void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
- assert(Personality == EHPersonality::MSVC_CXX ||
- Personality == EHPersonality::MSVC_X86SEH);
-
- StringRef PersonalityName = PersonalityFn->getName();
- IRBuilder<> Builder(&F->getEntryBlock(), F->getEntryBlock().begin());
- Type *Int8PtrType = Builder.getInt8PtrTy();
- Value *SubRecord = nullptr;
- if (PersonalityName == "__CxxFrameHandler3") {
- Type *RegNodeTy = getCXXEH3RegistrationType();
- Value *RegNode = Builder.CreateAlloca(RegNodeTy);
- // FIXME: We can skip this in -GS- mode, when we figure that out.
- // SavedESP = llvm.stacksave()
- Value *SP = Builder.CreateCall(
- Intrinsic::getDeclaration(TheModule, Intrinsic::stacksave));
- Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
- // TryLevel = -1
- Builder.CreateStore(Builder.getInt32(-1),
- Builder.CreateStructGEP(RegNodeTy, RegNode, 2));
- // FIXME: 'Personality' is incorrect here. We need to generate a trampoline
- // that effectively gets the LSDA.
- SubRecord = Builder.CreateStructGEP(RegNodeTy, RegNode, 1);
- linkExceptionRegistration(Builder, SubRecord, PersonalityFn);
- } else if (PersonalityName == "_except_handler3") {
- Type *RegNodeTy = getSEH3RegistrationType();
- Value *RegNode = Builder.CreateAlloca(RegNodeTy);
- // TryLevel = -1
- Builder.CreateStore(Builder.getInt32(-1),
- Builder.CreateStructGEP(RegNodeTy, RegNode, 2));
- // FIXME: Generalize llvm.eh.sjljl.lsda for this.
- // ScopeTable = nullptr
- Builder.CreateStore(Constant::getNullValue(Int8PtrType),
- Builder.CreateStructGEP(RegNodeTy, RegNode, 1));
- SubRecord = Builder.CreateStructGEP(RegNodeTy, RegNode, 0);
- linkExceptionRegistration(Builder, SubRecord, PersonalityFn);
- } else if (PersonalityName == "_except_handler4") {
- Type *RegNodeTy = getSEH4RegistrationType();
- Value *RegNode = Builder.CreateAlloca(RegNodeTy);
- // SavedESP = llvm.stacksave()
- Value *SP = Builder.CreateCall(
- Intrinsic::getDeclaration(TheModule, Intrinsic::stacksave));
- Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
- // TryLevel = -2
- Builder.CreateStore(Builder.getInt32(-2),
- Builder.CreateStructGEP(RegNodeTy, RegNode, 4));
- // FIXME: Generalize llvm.eh.sjljl.lsda for this, and then do the stack
- // cookie xor.
- // ScopeTable = nullptr
- Builder.CreateStore(Builder.getInt32(0),
- Builder.CreateStructGEP(RegNodeTy, RegNode, 3));
- SubRecord = Builder.CreateStructGEP(RegNodeTy, RegNode, 2);
- linkExceptionRegistration(Builder, SubRecord, PersonalityFn);
- } else {
- llvm_unreachable("unexpected personality function");
- }
-
- // FIXME: Insert an unlink before all returns.
- for (BasicBlock &BB : *F) {
- TerminatorInst *T = BB.getTerminator();
- if (!isa<ReturnInst>(T))
- continue;
- Builder.SetInsertPoint(T);
- unlinkExceptionRegistration(Builder, SubRecord);
- }
-}
-
-void WinEHStatePass::linkExceptionRegistration(IRBuilder<> &Builder,
- Value *RegNode, Value *Handler) {
- Type *RegNodeTy = getEHRegistrationType();
- // Handler = Handler
- Handler = Builder.CreateBitCast(Handler, Builder.getInt8PtrTy());
- Builder.CreateStore(Handler, Builder.CreateStructGEP(RegNodeTy, RegNode, 1));
- // Next = [fs:00]
- Constant *FSZero =
- Constant::getNullValue(RegNodeTy->getPointerTo()->getPointerTo(257));
- Value *Next = Builder.CreateLoad(FSZero);
- Builder.CreateStore(Next, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
- // [fs:00] = RegNode
- Builder.CreateStore(RegNode, FSZero);
-}
-
-void WinEHStatePass::unlinkExceptionRegistration(IRBuilder<> &Builder,
- Value *RegNode) {
- // Clone RegNode into the current BB for better address mode folding.
- if (auto *GEP = dyn_cast<GetElementPtrInst>(RegNode)) {
- GEP = cast<GetElementPtrInst>(GEP->clone());
- Builder.Insert(GEP);
- RegNode = GEP;
- }
- Type *RegNodeTy = getEHRegistrationType();
- // [fs:00] = RegNode->Next
- Value *Next =
- Builder.CreateLoad(Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
- Constant *FSZero =
- Constant::getNullValue(RegNodeTy->getPointerTo()->getPointerTo(257));
- Builder.CreateStore(Next, FSZero);
-}
OpenPOWER on IntegriCloud