summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2015-11-17 21:10:25 +0000
committerReid Kleckner <rnk@google.com>2015-11-17 21:10:25 +0000
commitc20276d0b2da8bff1e3da2fd80fc4d17f861eddd (patch)
treeb9a45ab78fbb27616e40726209077d3acac213cc /llvm/lib/CodeGen
parentc4e2bed73885b35ba82dd872cc20c9aa46ec774a (diff)
downloadbcm5719-llvm-c20276d0b2da8bff1e3da2fd80fc4d17f861eddd.tar.gz
bcm5719-llvm-c20276d0b2da8bff1e3da2fd80fc4d17f861eddd.zip
[WinEH] Move WinEHFuncInfo from MachineModuleInfo to MachineFunction
Summary: Now that there is a one-to-one mapping from MachineFunction to WinEHFuncInfo, we don't need to use a DenseMap to select the right WinEHFuncInfo for the current funclet. The main challenge here is that X86WinEHStatePass is an IR pass that doesn't have access to the MachineFunction. I gave it its own WinEHFuncInfo object that it uses to calculate state numbers, which it then throws away. As long as nobody creates or removes EH pads between this pass and SDAG construction, we will get the same state numbers. The other thing X86WinEHStatePass does is to mark the EH registration node. Instead of communicating which alloca was the registration through WinEHFuncInfo, I added the llvm.x86.seh.ehregnode intrinsic. This intrinsic generates no code and simply marks the alloca in use. Reviewers: JCTremoulet Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D14668 llvm-svn: 253378
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/WinException.cpp54
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/WinException.h6
-rw-r--r--llvm/lib/CodeGen/MachineFunction.cpp12
-rw-r--r--llvm/lib/CodeGen/MachineModuleInfo.cpp15
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp20
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp11
6 files changed, 48 insertions, 70 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp
index 33eb3906fce..cd1f3f51bc4 100644
--- a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp
@@ -299,7 +299,8 @@ const MCExpr *WinException::getOffsetPlusOne(const MCSymbol *OffsetOf,
Asm->OutContext);
}
-int WinException::getFrameIndexOffset(int FrameIndex, WinEHFuncInfo &FuncInfo) {
+int WinException::getFrameIndexOffset(int FrameIndex,
+ const WinEHFuncInfo &FuncInfo) {
const TargetFrameLowering &TFI = *Asm->MF->getSubtarget().getFrameLowering();
unsigned UnusedReg;
if (Asm->MAI->usesWindowsCFI())
@@ -340,7 +341,7 @@ struct InvokeStateChange {
/// reported is the first change to something other than NullState, and a
/// change back to NullState is always reported at the end of iteration).
class InvokeStateChangeIterator {
- InvokeStateChangeIterator(WinEHFuncInfo &EHInfo,
+ InvokeStateChangeIterator(const WinEHFuncInfo &EHInfo,
MachineFunction::const_iterator MFI,
MachineFunction::const_iterator MFE,
MachineBasicBlock::const_iterator MBBI)
@@ -353,7 +354,7 @@ class InvokeStateChangeIterator {
public:
static iterator_range<InvokeStateChangeIterator>
- range(WinEHFuncInfo &EHInfo, const MachineFunction &MF) {
+ range(const WinEHFuncInfo &EHInfo, const MachineFunction &MF) {
// Reject empty MFs to simplify bookkeeping by ensuring that we can get the
// end of the last block.
assert(!MF.empty());
@@ -366,7 +367,7 @@ public:
InvokeStateChangeIterator(EHInfo, FuncEnd, FuncEnd, BlockEnd));
}
static iterator_range<InvokeStateChangeIterator>
- range(WinEHFuncInfo &EHInfo, MachineFunction::const_iterator Begin,
+ range(const WinEHFuncInfo &EHInfo, MachineFunction::const_iterator Begin,
MachineFunction::const_iterator End) {
// Reject empty ranges to simplify bookkeeping by ensuring that we can get
// the end of the last block.
@@ -402,7 +403,7 @@ public:
private:
InvokeStateChangeIterator &scan();
- WinEHFuncInfo &EHInfo;
+ const WinEHFuncInfo &EHInfo;
const MCSymbol *CurrentEndLabel = nullptr;
MachineFunction::const_iterator MFI;
MachineFunction::const_iterator MFE;
@@ -521,7 +522,7 @@ void WinException::emitCSpecificHandlerTable(const MachineFunction *MF) {
auto &OS = *Asm->OutStreamer;
MCContext &Ctx = Asm->OutContext;
- WinEHFuncInfo &FuncInfo = MMI->getWinEHFuncInfo(MF->getFunction());
+ const WinEHFuncInfo &FuncInfo = *MF->getWinEHFuncInfo();
// Use the assembler to compute the number of table entries through label
// difference and division.
MCSymbol *TableBegin =
@@ -564,7 +565,7 @@ void WinException::emitCSpecificHandlerTable(const MachineFunction *MF) {
OS.EmitLabel(TableEnd);
}
-void WinException::emitSEHActionsForRange(WinEHFuncInfo &FuncInfo,
+void WinException::emitSEHActionsForRange(const WinEHFuncInfo &FuncInfo,
const MCSymbol *BeginLabel,
const MCSymbol *EndLabel, int State) {
auto &OS = *Asm->OutStreamer;
@@ -572,7 +573,7 @@ void WinException::emitSEHActionsForRange(WinEHFuncInfo &FuncInfo,
assert(BeginLabel && EndLabel);
while (State != -1) {
- SEHUnwindMapEntry &UME = FuncInfo.SEHUnwindMap[State];
+ const SEHUnwindMapEntry &UME = FuncInfo.SEHUnwindMap[State];
const MCExpr *FilterOrFinally;
const MCExpr *ExceptOrNull;
auto *Handler = UME.Handler.get<MachineBasicBlock *>();
@@ -600,7 +601,7 @@ void WinException::emitSEHActionsForRange(WinEHFuncInfo &FuncInfo,
void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) {
const Function *F = MF->getFunction();
auto &OS = *Asm->OutStreamer;
- WinEHFuncInfo &FuncInfo = MMI->getWinEHFuncInfo(F);
+ const WinEHFuncInfo &FuncInfo = *MF->getWinEHFuncInfo();
StringRef FuncLinkageName = GlobalValue::getRealLinkageName(F->getName());
@@ -688,7 +689,7 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) {
OS.EmitLabel(TryBlockMapXData);
SmallVector<MCSymbol *, 1> HandlerMaps;
for (size_t I = 0, E = FuncInfo.TryBlockMap.size(); I != E; ++I) {
- WinEHTryBlockMapEntry &TBME = FuncInfo.TryBlockMap[I];
+ const WinEHTryBlockMapEntry &TBME = FuncInfo.TryBlockMap[I];
MCSymbol *HandlerMapXData = nullptr;
if (!TBME.HandlerArray.empty())
@@ -721,7 +722,7 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) {
}
for (size_t I = 0, E = FuncInfo.TryBlockMap.size(); I != E; ++I) {
- WinEHTryBlockMapEntry &TBME = FuncInfo.TryBlockMap[I];
+ const WinEHTryBlockMapEntry &TBME = FuncInfo.TryBlockMap[I];
MCSymbol *HandlerMapXData = HandlerMaps[I];
if (!HandlerMapXData)
continue;
@@ -772,7 +773,7 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) {
}
void WinException::computeIP2StateTable(
- const MachineFunction *MF, WinEHFuncInfo &FuncInfo,
+ const MachineFunction *MF, const WinEHFuncInfo &FuncInfo,
SmallVectorImpl<std::pair<const MCExpr *, int>> &IPToStateTable) {
// Indicate that all calls from the prologue to the first invoke unwind to
// caller. We handle this as a special case since other ranges starting at end
@@ -803,15 +804,15 @@ void WinException::emitEHRegistrationOffsetLabel(const WinEHFuncInfo &FuncInfo,
// registration in order to recover the parent frame pointer. Now that we know
// we've code generated the parent, we can emit the label assignment that
// those helpers use to get the offset of the registration node.
- assert(FuncInfo.EHRegNodeEscapeIndex != INT_MAX &&
- "no EH reg node localescape index");
+ MCContext &Ctx = Asm->OutContext;
MCSymbol *ParentFrameOffset =
- Asm->OutContext.getOrCreateParentFrameOffsetSymbol(FLinkageName);
- MCSymbol *RegistrationOffsetSym = Asm->OutContext.getOrCreateFrameAllocSymbol(
- FLinkageName, FuncInfo.EHRegNodeEscapeIndex);
- const MCExpr *RegistrationOffsetSymRef =
- MCSymbolRefExpr::create(RegistrationOffsetSym, Asm->OutContext);
- Asm->OutStreamer->EmitAssignment(ParentFrameOffset, RegistrationOffsetSymRef);
+ Ctx.getOrCreateParentFrameOffsetSymbol(FLinkageName);
+ unsigned UnusedReg;
+ const TargetFrameLowering *TFI = Asm->MF->getSubtarget().getFrameLowering();
+ int64_t Offset = TFI->getFrameIndexReference(
+ *Asm->MF, FuncInfo.EHRegNodeFrameIndex, UnusedReg);
+ const MCExpr *MCOffset = MCConstantExpr::create(Offset, Ctx);
+ Asm->OutStreamer->EmitAssignment(ParentFrameOffset, MCOffset);
}
/// Emit the language-specific data that _except_handler3 and 4 expect. This is
@@ -822,7 +823,7 @@ void WinException::emitExceptHandlerTable(const MachineFunction *MF) {
const Function *F = MF->getFunction();
StringRef FLinkageName = GlobalValue::getRealLinkageName(F->getName());
- WinEHFuncInfo &FuncInfo = MMI->getWinEHFuncInfo(F);
+ const WinEHFuncInfo &FuncInfo = *MF->getWinEHFuncInfo();
emitEHRegistrationOffsetLabel(FuncInfo, FLinkageName);
// Emit the __ehtable label that we use for llvm.x86.seh.lsda.
@@ -857,7 +858,7 @@ void WinException::emitExceptHandlerTable(const MachineFunction *MF) {
}
assert(!FuncInfo.SEHUnwindMap.empty());
- for (SEHUnwindMapEntry &UME : FuncInfo.SEHUnwindMap) {
+ for (const SEHUnwindMapEntry &UME : FuncInfo.SEHUnwindMap) {
MCSymbol *ExceptOrFinally =
UME.Handler.get<MachineBasicBlock *>()->getSymbol();
// -1 is usually the base state for "unwind to caller", but for
@@ -869,7 +870,7 @@ void WinException::emitExceptHandlerTable(const MachineFunction *MF) {
}
}
-static int getRank(WinEHFuncInfo &FuncInfo, int State) {
+static int getRank(const WinEHFuncInfo &FuncInfo, int State) {
int Rank = 0;
while (State != -1) {
++Rank;
@@ -878,7 +879,7 @@ static int getRank(WinEHFuncInfo &FuncInfo, int State) {
return Rank;
}
-static int getAncestor(WinEHFuncInfo &FuncInfo, int Left, int Right) {
+static int getAncestor(const WinEHFuncInfo &FuncInfo, int Left, int Right) {
int LeftRank = getRank(FuncInfo, Left);
int RightRank = getRank(FuncInfo, Right);
@@ -905,8 +906,7 @@ void WinException::emitCLRExceptionTable(const MachineFunction *MF) {
// states, handlers, and funclets all have 1:1 mappings between them, and a
// handler/funclet's "state" is its index in the ClrEHUnwindMap.
MCStreamer &OS = *Asm->OutStreamer;
- const Function *F = MF->getFunction();
- WinEHFuncInfo &FuncInfo = MMI->getWinEHFuncInfo(F);
+ const WinEHFuncInfo &FuncInfo = *MF->getWinEHFuncInfo();
MCSymbol *FuncBeginSym = Asm->getFunctionBegin();
MCSymbol *FuncEndSym = Asm->getFunctionEnd();
@@ -1085,7 +1085,7 @@ void WinException::emitCLRExceptionTable(const MachineFunction *MF) {
getOffsetPlusOne(Clause.StartLabel, FuncBeginSym);
const MCExpr *ClauseEnd = getOffsetPlusOne(Clause.EndLabel, FuncBeginSym);
- ClrEHUnwindMapEntry &Entry = FuncInfo.ClrEHUnwindMap[Clause.State];
+ const ClrEHUnwindMapEntry &Entry = FuncInfo.ClrEHUnwindMap[Clause.State];
MachineBasicBlock *HandlerBlock = Entry.Handler.get<MachineBasicBlock *>();
MCSymbol *BeginSym = getMCSymbolForMBB(Asm, HandlerBlock);
const MCExpr *HandlerBegin = getOffset(BeginSym, FuncBeginSym);
diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.h b/llvm/lib/CodeGen/AsmPrinter/WinException.h
index 54c5f3a9a0e..acb30101691 100644
--- a/llvm/lib/CodeGen/AsmPrinter/WinException.h
+++ b/llvm/lib/CodeGen/AsmPrinter/WinException.h
@@ -42,7 +42,7 @@ class LLVM_LIBRARY_VISIBILITY WinException : public EHStreamer {
void emitCSpecificHandlerTable(const MachineFunction *MF);
- void emitSEHActionsForRange(WinEHFuncInfo &FuncInfo,
+ void emitSEHActionsForRange(const WinEHFuncInfo &FuncInfo,
const MCSymbol *BeginLabel,
const MCSymbol *EndLabel, int State);
@@ -58,7 +58,7 @@ class LLVM_LIBRARY_VISIBILITY WinException : public EHStreamer {
void emitCLRExceptionTable(const MachineFunction *MF);
void computeIP2StateTable(
- const MachineFunction *MF, WinEHFuncInfo &FuncInfo,
+ const MachineFunction *MF, const WinEHFuncInfo &FuncInfo,
SmallVectorImpl<std::pair<const MCExpr *, int>> &IPToStateTable);
/// Emits the label used with llvm.x86.seh.recoverfp, which is used by
@@ -77,7 +77,7 @@ class LLVM_LIBRARY_VISIBILITY WinException : public EHStreamer {
/// given index. For targets using CFI (Win64, etc), this is relative to the
/// established SP at the end of the prologue. For targets without CFI (Win32
/// only), it is relative to the frame pointer.
- int getFrameIndexOffset(int FrameIndex, WinEHFuncInfo &FuncInfo);
+ int getFrameIndexOffset(int FrameIndex, const WinEHFuncInfo &FuncInfo);
public:
//===--------------------------------------------------------------------===//
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp
index fa6849fcfdc..7e4c9b779f2 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -17,6 +17,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Analysis/ConstantFolding.h"
+#include "llvm/Analysis/LibCallSemantics.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunctionInitializer.h"
@@ -27,6 +28,7 @@
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/PseudoSourceValue.h"
+#include "llvm/CodeGen/WinEHFuncInfo.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/Function.h"
@@ -88,6 +90,11 @@ MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM,
FunctionNumber = FunctionNum;
JumpTableInfo = nullptr;
+ if (isFuncletEHPersonality(classifyEHPersonality(
+ F->hasPersonalityFn() ? F->getPersonalityFn() : nullptr))) {
+ WinEHInfo = new (Allocator) WinEHFuncInfo();
+ }
+
assert(TM.isCompatibleDataLayout(getDataLayout()) &&
"Can't create a MachineFunction using a Module with a "
"Target-incompatible DataLayout attached\n");
@@ -125,6 +132,11 @@ MachineFunction::~MachineFunction() {
JumpTableInfo->~MachineJumpTableInfo();
Allocator.Deallocate(JumpTableInfo);
}
+
+ if (WinEHInfo) {
+ WinEHInfo->~WinEHFuncInfo();
+ Allocator.Deallocate(WinEHInfo);
+ }
}
const DataLayout &MachineFunction::getDataLayout() const {
diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp
index 33db3edffb7..18efcf39c45 100644
--- a/llvm/lib/CodeGen/MachineModuleInfo.cpp
+++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp
@@ -9,12 +9,12 @@
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/Analysis/LibCallSemantics.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/Passes.h"
-#include "llvm/CodeGen/WinEHFuncInfo.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/GlobalVariable.h"
@@ -321,12 +321,6 @@ void MachineModuleInfo::addPersonality(const Function *Personality) {
Personalities.push_back(Personality);
}
-void MachineModuleInfo::addWinEHState(MachineBasicBlock *LandingPad,
- int State) {
- LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
- LP.WinEHState = State;
-}
-
/// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
///
void MachineModuleInfo::
@@ -466,10 +460,3 @@ try_next:;
FilterIds.push_back(0); // terminator
return FilterID;
}
-
-WinEHFuncInfo &MachineModuleInfo::getWinEHFuncInfo(const Function *F) {
- auto &Ptr = FuncInfoMap[F];
- if (!Ptr)
- Ptr.reset(new WinEHFuncInfo);
- return *Ptr;
-}
diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
index 52216c2c1e8..8d42dcef140 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
@@ -287,7 +287,7 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
return;
// Calculate state numbers if we haven't already.
- WinEHFuncInfo &EHInfo = MMI.getWinEHFuncInfo(&fn);
+ WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo();
if (Personality == EHPersonality::MSVC_CXX)
calculateWinCXXEHStateNumbers(&fn, EHInfo);
else if (isAsynchronousEHPersonality(Personality))
@@ -321,24 +321,6 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
const BasicBlock *BB = CME.Handler.get<const BasicBlock *>();
CME.Handler = MBBMap[BB];
}
-
- // If there's an explicit EH registration node on the stack, record its
- // frame index.
- if (EHInfo.EHRegNode && EHInfo.EHRegNode->getParent()->getParent() == Fn) {
- assert(StaticAllocaMap.count(EHInfo.EHRegNode));
- EHInfo.EHRegNodeFrameIndex = StaticAllocaMap[EHInfo.EHRegNode];
- }
-
- // Copy the state numbers to LandingPadInfo for the current function, which
- // could be a handler or the parent. This should happen for 32-bit SEH and
- // C++ EH.
- if (Personality == EHPersonality::MSVC_CXX ||
- Personality == EHPersonality::MSVC_X86SEH) {
- for (const LandingPadInst *LP : LPads) {
- MachineBasicBlock *LPadMBB = MBBMap[LP->getParent()];
- MMI.addWinEHState(LPadMBB, EHInfo.EHPadStateMap[LP]);
- }
- }
}
/// clear - Clear out all the function-specific state. This returns this
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 63b5d02a65a..a699f9c56f2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1221,10 +1221,8 @@ void SelectionDAGBuilder::visitCatchRet(const CatchReturnInst &I) {
// Figure out the funclet membership for the catchret's successor.
// This will be used by the FuncletLayout pass to determine how to order the
// BB's.
- MachineModuleInfo &MMI = DAG.getMachineFunction().getMMI();
- WinEHFuncInfo &EHInfo =
- MMI.getWinEHFuncInfo(DAG.getMachineFunction().getFunction());
- const BasicBlock *SuccessorColor = EHInfo.CatchRetSuccessorColorMap[&I];
+ WinEHFuncInfo *EHInfo = DAG.getMachineFunction().getWinEHFuncInfo();
+ const BasicBlock *SuccessorColor = EHInfo->CatchRetSuccessorColorMap[&I];
assert(SuccessorColor && "No parent funclet for catchret!");
MachineBasicBlock *SuccessorColorMBB = FuncInfo.MBBMap[SuccessorColor];
assert(SuccessorColorMBB && "No MBB for SuccessorColor!");
@@ -5341,9 +5339,8 @@ SelectionDAGBuilder::lowerInvokable(TargetLowering::CallLoweringInfo &CLI,
// Inform MachineModuleInfo of range.
if (MMI.hasEHFunclets()) {
- WinEHFuncInfo &EHInfo =
- MMI.getWinEHFuncInfo(DAG.getMachineFunction().getFunction());
- EHInfo.addIPToStateRange(EHPadBB, BeginLabel, EndLabel);
+ WinEHFuncInfo *EHInfo = DAG.getMachineFunction().getWinEHFuncInfo();
+ EHInfo->addIPToStateRange(EHPadBB, BeginLabel, EndLabel);
} else {
MMI.addInvoke(FuncInfo.MBBMap[EHPadBB], BeginLabel, EndLabel);
}
OpenPOWER on IntegriCloud