Skip to content

Commit db6a979

Browse files
committed
Revert "[Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 2"
This reverts commit 1a949c8.
1 parent c8e15af commit db6a979

15 files changed

+4
-1558
lines changed

llvm/include/llvm/CodeGen/SelectionDAGISel.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,6 @@ class SelectionDAGISel : public MachineFunctionPass {
339339
/// instruction selected, false if no code should be emitted for it.
340340
bool PrepareEHLandingPad();
341341

342-
// Mark and Report IPToState for each Block under AsynchEH
343-
void reportIPToStateForBlocks(MachineFunction *Fn);
344-
345342
/// Perform instruction selection on all basic blocks in the function.
346343
void SelectAllBasicBlocks(const Function &Fn);
347344

llvm/include/llvm/CodeGen/WinEHFuncInfo.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ struct WinEHFuncInfo {
9292
DenseMap<const FuncletPadInst *, int> FuncletBaseStateMap;
9393
DenseMap<const InvokeInst *, int> InvokeStateMap;
9494
DenseMap<MCSymbol *, std::pair<int, MCSymbol *>> LabelToStateMap;
95-
DenseMap<const BasicBlock *, int> BlockToStateMap; // for AsynchEH
9695
SmallVector<CxxUnwindMapEntry, 4> CxxUnwindMap;
9796
SmallVector<WinEHTryBlockMapEntry, 4> TryBlockMap;
9897
SmallVector<SEHUnwindMapEntry, 4> SEHUnwindMap;
@@ -105,8 +104,6 @@ struct WinEHFuncInfo {
105104
void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin,
106105
MCSymbol *InvokeEnd);
107106

108-
void addIPToStateRange(int State, MCSymbol *InvokeBegin, MCSymbol *InvokeEnd);
109-
110107
int EHRegNodeFrameIndex = std::numeric_limits<int>::max();
111108
int EHRegNodeEndOffset = std::numeric_limits<int>::max();
112109
int EHGuardFrameIndex = std::numeric_limits<int>::max();
@@ -126,12 +123,6 @@ void calculateSEHStateNumbers(const Function *ParentFn,
126123

127124
void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);
128125

129-
// For AsynchEH (VC++ option -EHa)
130-
void calculateCXXStateForAsynchEH(const BasicBlock *BB, int State,
131-
WinEHFuncInfo &FuncInfo);
132-
void calculateSEHStateForAsynchEH(const BasicBlock *BB, int State,
133-
WinEHFuncInfo &FuncInfo);
134-
135126
} // end namespace llvm
136127

137128
#endif // LLVM_CODEGEN_WINEHFUNCINFO_H

llvm/include/llvm/IR/BasicBlock.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,6 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
205205
.getNonConst();
206206
}
207207

208-
/// Returns the first potential AsynchEH faulty instruction
209-
/// currently it checks for loads/stores (which may dereference a null
210-
/// pointer) and calls/invokes (which may propagate exceptions)
211-
const Instruction* getFirstMayFaultInst() const;
212-
Instruction* getFirstMayFaultInst() {
213-
return const_cast<Instruction*>(
214-
static_cast<const BasicBlock*>(this)->getFirstMayFaultInst());
215-
}
216-
217208
/// Return a const iterator range over the instructions in the block, skipping
218209
/// any debug instructions. Skip any pseudo operations as well if \c
219210
/// SkipPseudoOp is true.

llvm/lib/Analysis/EHPersonalities.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "llvm/IR/Constants.h"
1414
#include "llvm/IR/Function.h"
1515
#include "llvm/IR/Instructions.h"
16-
#include "llvm/IR/Module.h"
1716
#include "llvm/Support/Debug.h"
1817
#include "llvm/Support/raw_ostream.h"
1918
using namespace llvm;
@@ -80,11 +79,7 @@ bool llvm::canSimplifyInvokeNoUnwind(const Function *F) {
8079
// We can't simplify any invokes to nounwind functions if the personality
8180
// function wants to catch asynch exceptions. The nounwind attribute only
8281
// implies that the function does not throw synchronous exceptions.
83-
84-
// Cannot simplify CXX Personality under AsynchEH
85-
const llvm::Module *M = (const llvm::Module *)F->getParent();
86-
bool EHa = M->getModuleFlag("eh-asynch");
87-
return !EHa && !isAsynchronousEHPersonality(Personality);
82+
return !isAsynchronousEHPersonality(Personality);
8883
}
8984

9085
DenseMap<BasicBlock *, ColorVector> llvm::colorEHFunclets(Function &F) {

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,6 @@ void AsmPrinter::emitFunctionBody() {
15841584
// Print out code for the function.
15851585
bool HasAnyRealCode = false;
15861586
int NumInstsInFunction = 0;
1587-
bool IsEHa = MMI->getModule()->getModuleFlag("eh-asynch");
15881587

15891588
bool CanDoExtraAnalysis = ORE->allowExtraAnalysis(DEBUG_TYPE);
15901589
for (auto &MBB : *MF) {
@@ -1623,24 +1622,9 @@ void AsmPrinter::emitFunctionBody() {
16231622
emitFrameAlloc(MI);
16241623
break;
16251624
case TargetOpcode::ANNOTATION_LABEL:
1626-
case TargetOpcode::GC_LABEL:
1627-
OutStreamer->emitLabel(MI.getOperand(0).getMCSymbol());
1628-
break;
16291625
case TargetOpcode::EH_LABEL:
1626+
case TargetOpcode::GC_LABEL:
16301627
OutStreamer->emitLabel(MI.getOperand(0).getMCSymbol());
1631-
// For AsynchEH, insert a Nop if followed by a trap inst
1632-
// Or the exception won't be caught.
1633-
// (see MCConstantExpr::create(1,..) in WinException.cpp)
1634-
// Ignore SDiv/UDiv because a DIV with Const-0 divisor
1635-
// must have being turned into an UndefValue.
1636-
// Div with variable opnds won't be the first instruction in
1637-
// an EH region as it must be led by at least a Load
1638-
{
1639-
auto MI2 = std::next(MI.getIterator());
1640-
if (IsEHa && MI2 != MBB.end() &&
1641-
(MI2->mayLoadOrStore() || MI2->mayRaiseFPException()))
1642-
emitNops(1);
1643-
}
16441628
break;
16451629
case TargetOpcode::INLINEASM:
16461630
case TargetOpcode::INLINEASM_BR:

llvm/lib/CodeGen/AsmPrinter/WinException.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,7 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) {
770770
OS.emitInt32(0);
771771

772772
AddComment("EHFlags");
773-
if (MMI->getModule()->getModuleFlag("eh-asynch")) {
774-
OS.emitInt32(0);
775-
} else {
776-
OS.emitInt32(1);
777-
}
773+
OS.emitInt32(1);
778774

779775
// UnwindMapEntry {
780776
// int32_t ToState;

llvm/lib/CodeGen/BranchFolding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ bool BranchFolder::OptimizeBranches(MachineFunction &MF) {
12071207
MadeChange |= OptimizeBlock(&MBB);
12081208

12091209
// If it is dead, remove it.
1210-
if (MBB.pred_empty() && !MBB.isMachineBlockAddressTaken()) {
1210+
if (MBB.pred_empty()) {
12111211
RemoveDeadBlock(&MBB);
12121212
MadeChange = true;
12131213
++NumDeadBlocks;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,6 @@ void SelectionDAGBuilder::visitInvoke(const InvokeInst &I) {
29262926
// catchswitch for successors.
29272927
MachineBasicBlock *Return = FuncInfo.MBBMap[I.getSuccessor(0)];
29282928
const BasicBlock *EHPadBB = I.getSuccessor(1);
2929-
MachineBasicBlock *EHPadMBB = FuncInfo.MBBMap[EHPadBB];
29302929

29312930
// Deopt bundles are lowered in LowerCallSiteWithDeoptBundle, and we don't
29322931
// have to do anything here to lower funclet bundles.
@@ -2951,10 +2950,6 @@ void SelectionDAGBuilder::visitInvoke(const InvokeInst &I) {
29512950
case Intrinsic::seh_scope_begin:
29522951
case Intrinsic::seh_try_end:
29532952
case Intrinsic::seh_scope_end:
2954-
if (EHPadMBB)
2955-
// a block referenced by EH table
2956-
// so dtor-funclet not removed by opts
2957-
EHPadMBB->setMachineBlockAddressTaken();
29582953
break;
29592954
case Intrinsic::experimental_patchpoint_void:
29602955
case Intrinsic::experimental_patchpoint_i64:

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
#include "llvm/CodeGen/TargetRegisterInfo.h"
6060
#include "llvm/CodeGen/TargetSubtargetInfo.h"
6161
#include "llvm/CodeGen/ValueTypes.h"
62-
#include "llvm/CodeGen/WinEHFuncInfo.h"
6362
#include "llvm/IR/BasicBlock.h"
6463
#include "llvm/IR/Constants.h"
6564
#include "llvm/IR/DataLayout.h"
@@ -1281,43 +1280,6 @@ bool SelectionDAGISel::PrepareEHLandingPad() {
12811280
return true;
12821281
}
12831282

1284-
// Mark and Report IPToState for each Block under IsEHa
1285-
void SelectionDAGISel::reportIPToStateForBlocks(MachineFunction *MF) {
1286-
MachineModuleInfo &MMI = MF->getMMI();
1287-
llvm::WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo();
1288-
if (!EHInfo)
1289-
return;
1290-
for (auto MBBI = MF->begin(), E = MF->end(); MBBI != E; ++MBBI) {
1291-
MachineBasicBlock *MBB = &*MBBI;
1292-
const BasicBlock *BB = MBB->getBasicBlock();
1293-
int State = EHInfo->BlockToStateMap[BB];
1294-
if (BB->getFirstMayFaultInst()) {
1295-
// Report IP range only for blocks with Faulty inst
1296-
auto MBBb = MBB->getFirstNonPHI();
1297-
MachineInstr *MIb = &*MBBb;
1298-
if (MIb->isTerminator())
1299-
continue;
1300-
1301-
// Insert EH Labels
1302-
MCSymbol *BeginLabel = MMI.getContext().createTempSymbol();
1303-
MCSymbol *EndLabel = MMI.getContext().createTempSymbol();
1304-
EHInfo->addIPToStateRange(State, BeginLabel, EndLabel);
1305-
BuildMI(*MBB, MBBb, SDB->getCurDebugLoc(),
1306-
TII->get(TargetOpcode::EH_LABEL))
1307-
.addSym(BeginLabel);
1308-
auto MBBe = MBB->instr_end();
1309-
MachineInstr *MIe = &*(--MBBe);
1310-
// insert before (possible multiple) terminators
1311-
while (MIe->isTerminator())
1312-
MIe = &*(--MBBe);
1313-
++MBBe;
1314-
BuildMI(*MBB, MBBe, SDB->getCurDebugLoc(),
1315-
TII->get(TargetOpcode::EH_LABEL))
1316-
.addSym(EndLabel);
1317-
}
1318-
}
1319-
}
1320-
13211283
/// isFoldedOrDeadInstruction - Return true if the specified instruction is
13221284
/// side-effect free and is either dead or folded into a generated instruction.
13231285
/// Return false if it needs to be emitted.
@@ -1650,10 +1612,6 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {
16501612
ElidedArgCopyInstrs.clear();
16511613
}
16521614

1653-
// AsynchEH: Report Block State under -AsynchEH
1654-
if (Fn.getParent()->getModuleFlag("eh-asynch"))
1655-
reportIPToStateForBlocks(MF);
1656-
16571615
SP.copyToMachineFrameInfo(MF->getFrameInfo());
16581616

16591617
SwiftError->propagateVRegs();

llvm/lib/CodeGen/WinEHPrepare.cpp

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -216,127 +216,6 @@ static void calculateStateNumbersForInvokes(const Function *Fn,
216216
}
217217
}
218218

219-
// See comments below for calculateSEHStateForAsynchEH().
220-
// State - incoming State of normal paths
221-
struct WorkItem {
222-
const BasicBlock *Block;
223-
int State;
224-
WorkItem(const BasicBlock *BB, int St) {
225-
Block = BB;
226-
State = St;
227-
}
228-
};
229-
void llvm::calculateCXXStateForAsynchEH(const BasicBlock *BB, int State,
230-
WinEHFuncInfo &EHInfo) {
231-
SmallVector<struct WorkItem *, 8> WorkList;
232-
struct WorkItem *WI = new WorkItem(BB, State);
233-
WorkList.push_back(WI);
234-
235-
while (!WorkList.empty()) {
236-
WI = WorkList.pop_back_val();
237-
const BasicBlock *BB = WI->Block;
238-
int State = WI->State;
239-
delete WI;
240-
if (EHInfo.BlockToStateMap.count(BB) && EHInfo.BlockToStateMap[BB] <= State)
241-
continue; // skip blocks already visited by lower State
242-
243-
const llvm::Instruction *I = BB->getFirstNonPHI();
244-
const llvm::Instruction *TI = BB->getTerminator();
245-
if (I->isEHPad())
246-
State = EHInfo.EHPadStateMap[I];
247-
EHInfo.BlockToStateMap[BB] = State; // Record state, also flag visiting
248-
249-
if ((isa<CleanupReturnInst>(TI) || isa<CatchReturnInst>(TI)) && State > 0) {
250-
// Retrive the new State
251-
State = EHInfo.CxxUnwindMap[State].ToState; // Retrive next State
252-
} else if (isa<InvokeInst>(TI)) {
253-
auto *Call = dyn_cast<CallBase>(TI);
254-
const Function *Fn = Call->getCalledFunction();
255-
if (Fn && Fn->isIntrinsic() &&
256-
(Fn->getIntrinsicID() == Intrinsic::seh_scope_begin ||
257-
Fn->getIntrinsicID() == Intrinsic::seh_try_begin))
258-
// Retrive the new State from seh_scope_begin
259-
State = EHInfo.InvokeStateMap[cast<InvokeInst>(TI)];
260-
else if (Fn && Fn->isIntrinsic() &&
261-
(Fn->getIntrinsicID() == Intrinsic::seh_scope_end ||
262-
Fn->getIntrinsicID() == Intrinsic::seh_try_end)) {
263-
// In case of conditional ctor, let's retrieve State from Invoke
264-
State = EHInfo.InvokeStateMap[cast<InvokeInst>(TI)];
265-
// end of current state, retrive new state from UnwindMap
266-
State = EHInfo.CxxUnwindMap[State].ToState;
267-
}
268-
}
269-
// Continue push successors into worklist
270-
for (auto *SuccBB : successors(BB)) {
271-
WI = new WorkItem(SuccBB, State);
272-
WorkList.push_back(WI);
273-
}
274-
}
275-
}
276-
277-
// The central theory of this routine is based on the following:
278-
// A _try scope is always a SEME (Single Entry Multiple Exits) region
279-
// as jumping into a _try is not allowed
280-
// The single entry must start with a seh_try_begin() invoke with a
281-
// correct State number that is the initial state of the SEME.
282-
// Through control-flow, state number is propagated into all blocks.
283-
// Side exits marked by seh_try_end() will unwind to parent state via
284-
// existing SEHUnwindMap[].
285-
// Side exits can ONLY jump into parent scopes (lower state number).
286-
// Thus, when a block succeeds various states from its predecessors,
287-
// the lowest State trumphs others.
288-
// If some exits flow to unreachable, propagation on those paths terminate,
289-
// not affecting remaining blocks.
290-
void llvm::calculateSEHStateForAsynchEH(const BasicBlock *BB, int State,
291-
WinEHFuncInfo &EHInfo) {
292-
SmallVector<struct WorkItem *, 8> WorkList;
293-
struct WorkItem *WI = new WorkItem(BB, State);
294-
WorkList.push_back(WI);
295-
296-
while (!WorkList.empty()) {
297-
WI = WorkList.pop_back_val();
298-
const BasicBlock *BB = WI->Block;
299-
int State = WI->State;
300-
delete WI;
301-
if (EHInfo.BlockToStateMap.count(BB) && EHInfo.BlockToStateMap[BB] <= State)
302-
continue; // skip blocks already visited by lower State
303-
304-
const llvm::Instruction *I = BB->getFirstNonPHI();
305-
const llvm::Instruction *TI = BB->getTerminator();
306-
if (I->isEHPad())
307-
State = EHInfo.EHPadStateMap[I];
308-
EHInfo.BlockToStateMap[BB] = State; // Record state
309-
310-
if (isa<CatchPadInst>(I) && isa<CatchReturnInst>(TI)) {
311-
const Constant *FilterOrNull = cast<Constant>(
312-
cast<CatchPadInst>(I)->getArgOperand(0)->stripPointerCasts());
313-
const Function *Filter = dyn_cast<Function>(FilterOrNull);
314-
if (!Filter || !Filter->getName().startswith("__IsLocalUnwind"))
315-
State = EHInfo.SEHUnwindMap[State].ToState; // Retrive next State
316-
} else if ((isa<CleanupReturnInst>(TI) || isa<CatchReturnInst>(TI)) &&
317-
State > 0) {
318-
// Retrive the new State.
319-
State = EHInfo.SEHUnwindMap[State].ToState; // Retrive next State
320-
} else if (isa<InvokeInst>(TI)) {
321-
auto *Call = dyn_cast<CallBase>(TI);
322-
const Function *Fn = Call->getCalledFunction();
323-
if (Fn && Fn->isIntrinsic() &&
324-
Fn->getIntrinsicID() == Intrinsic::seh_try_begin)
325-
// Retrive the new State from seh_try_begin
326-
State = EHInfo.InvokeStateMap[cast<InvokeInst>(TI)];
327-
else if (Fn && Fn->isIntrinsic() &&
328-
Fn->getIntrinsicID() == Intrinsic::seh_try_end)
329-
// end of current state, retrive new state from UnwindMap
330-
State = EHInfo.SEHUnwindMap[State].ToState;
331-
}
332-
// Continue push successors into worklist
333-
for (auto *SuccBB : successors(BB)) {
334-
WI = new WorkItem(SuccBB, State);
335-
WorkList.push_back(WI);
336-
}
337-
}
338-
}
339-
340219
// Given BB which ends in an unwind edge, return the EHPad that this BB belongs
341220
// to. If the unwind edge came from an invoke, return null.
342221
static const BasicBlock *getEHPadFromPredecessor(const BasicBlock *BB,
@@ -397,7 +276,6 @@ static void calculateCXXStateNumbers(WinEHFuncInfo &FuncInfo,
397276

398277
for (const auto *CatchPad : Handlers) {
399278
FuncInfo.FuncletBaseStateMap[CatchPad] = CatchLow;
400-
FuncInfo.EHPadStateMap[CatchPad] = CatchLow;
401279
for (const User *U : CatchPad->users()) {
402280
const auto *UserI = cast<Instruction>(U);
403281
if (auto *InnerCatchSwitch = dyn_cast<CatchSwitchInst>(UserI)) {
@@ -506,7 +384,6 @@ static void calculateSEHStateNumbers(WinEHFuncInfo &FuncInfo,
506384

507385
// Everything in the __try block uses TryState as its parent state.
508386
FuncInfo.EHPadStateMap[CatchSwitch] = TryState;
509-
FuncInfo.EHPadStateMap[CatchPad] = TryState;
510387
LLVM_DEBUG(dbgs() << "Assigning state #" << TryState << " to BB "
511388
<< CatchPadBB->getName() << '\n');
512389
for (const BasicBlock *PredBlock : predecessors(BB))
@@ -587,12 +464,6 @@ void llvm::calculateSEHStateNumbers(const Function *Fn,
587464
}
588465

589466
calculateStateNumbersForInvokes(Fn, FuncInfo);
590-
591-
bool IsEHa = Fn->getParent()->getModuleFlag("eh-asynch");
592-
if (IsEHa) {
593-
const BasicBlock *EntryBB = &(Fn->getEntryBlock());
594-
calculateSEHStateForAsynchEH(EntryBB, -1, FuncInfo);
595-
}
596467
}
597468

598469
void llvm::calculateWinCXXEHStateNumbers(const Function *Fn,
@@ -611,12 +482,6 @@ void llvm::calculateWinCXXEHStateNumbers(const Function *Fn,
611482
}
612483

613484
calculateStateNumbersForInvokes(Fn, FuncInfo);
614-
615-
bool IsEHa = Fn->getParent()->getModuleFlag("eh-asynch");
616-
if (IsEHa) {
617-
const BasicBlock *EntryBB = &(Fn->getEntryBlock());
618-
calculateCXXStateForAsynchEH(EntryBB, -1, FuncInfo);
619-
}
620485
}
621486

622487
static int addClrEHHandler(WinEHFuncInfo &FuncInfo, int HandlerParentState,
@@ -1388,9 +1253,4 @@ void WinEHFuncInfo::addIPToStateRange(const InvokeInst *II,
13881253
LabelToStateMap[InvokeBegin] = std::make_pair(InvokeStateMap[II], InvokeEnd);
13891254
}
13901255

1391-
void WinEHFuncInfo::addIPToStateRange(int State, MCSymbol* InvokeBegin,
1392-
MCSymbol* InvokeEnd) {
1393-
LabelToStateMap[InvokeBegin] = std::make_pair(State, InvokeEnd);
1394-
}
1395-
13961256
WinEHFuncInfo::WinEHFuncInfo() = default;

0 commit comments

Comments
 (0)