llvm.org GIT mirror llvm / a03aa8f
[WinEH] Remove more dead code wineh-parent is dead, so is ValueOrMBB. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249920 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 4 years ago
8 changed file(s) with 46 addition(s) and 79 deletion(s). Raw diff Collapse all Expand all
219219 void setModule(const Module *M) { TheModule = M; }
220220 const Module *getModule() const { return TheModule; }
221221
222 const Function *getWinEHParent(const Function *F) const;
223222 WinEHFuncInfo &getWinEHFuncInfo(const Function *F);
224223 bool hasWinEHFuncInfo(const Function *F) const {
225 return FuncInfoMap.count(getWinEHParent(F)) > 0;
224 return FuncInfoMap.count(F) > 0;
226225 }
227226
228227 /// getInfo - Keep track of various per-function pieces of information for
3636 // Windows-related EH personalities.
3737
3838 typedef PointerUnion MBBOrBasicBlock;
39 typedef PointerUnion ValueOrMBB;
4039
4140 struct CxxUnwindMapEntry {
4241 int ToState;
43 ValueOrMBB Cleanup;
42 MBBOrBasicBlock Cleanup;
4443 };
4544
4645 /// Similar to CxxUnwindMapEntry, but supports SEH filters.
6867 int FrameIndex;
6968 } CatchObj = {};
7069 GlobalVariable *TypeDescriptor;
71 ValueOrMBB Handler;
70 MBBOrBasicBlock Handler;
7271 };
7372
7473 struct WinEHTryBlockMapEntry {
6666 bool hasEHFunclets = MMI->hasEHFunclets();
6767
6868 const Function *F = MF->getFunction();
69 const Function *ParentF = MMI->getWinEHParent(F);
7069
7170 shouldEmitMoves = Asm->needsSEHMoves();
7271
9089
9190 // If we're not using CFI, we don't want the CFI or the personality, but we
9291 // might want EH tables if we had EH pads.
93 // FIXME: If WinEHPrepare outlined something, we should emit the LSDA. Remove
94 // this once WinEHPrepare stops doing that.
9592 if (!Asm->MAI->usesWindowsCFI()) {
96 shouldEmitLSDA =
97 hasEHFunclets || (F->hasFnAttribute("wineh-parent") && F == ParentF);
93 shouldEmitLSDA = hasEHFunclets;
9894 shouldEmitPersonality = false;
9995 return;
10096 }
151147
152148 /// Retreive the MCSymbol for a GlobalValue or MachineBasicBlock. GlobalValues
153149 /// are used in the old WinEH scheme, and they will be removed eventually.
154 static MCSymbol *getMCSymbolForMBBOrGV(AsmPrinter *Asm, ValueOrMBB Handler) {
155 if (!Handler)
150 static MCSymbol *getMCSymbolForMBB(AsmPrinter *Asm,
151 const MachineBasicBlock *MBB) {
152 if (!MBB)
156153 return nullptr;
157 if (Handler.is()) {
158 auto *MBB = Handler.get();
159 assert(MBB->isEHFuncletEntry());
160
161 // Give catches and cleanups a name based off of their parent function and
162 // their funclet entry block's number.
163 const MachineFunction *MF = MBB->getParent();
164 const Function *F = MF->getFunction();
165 StringRef FuncLinkageName = GlobalValue::getRealLinkageName(F->getName());
166 MCContext &Ctx = MF->getContext();
167 StringRef HandlerPrefix = MBB->isCleanupFuncletEntry() ? "dtor" : "catch";
168 return Ctx.getOrCreateSymbol("?" + HandlerPrefix + "$" +
169 Twine(MBB->getNumber()) + "@?0?" +
170 FuncLinkageName + "@4HA");
171 }
172 return Asm->getSymbol(cast(Handler.get()));
154
155 assert(MBB->isEHFuncletEntry());
156
157 // Give catches and cleanups a name based off of their parent function and
158 // their funclet entry block's number.
159 const MachineFunction *MF = MBB->getParent();
160 const Function *F = MF->getFunction();
161 StringRef FuncLinkageName = GlobalValue::getRealLinkageName(F->getName());
162 MCContext &Ctx = MF->getContext();
163 StringRef HandlerPrefix = MBB->isCleanupFuncletEntry() ? "dtor" : "catch";
164 return Ctx.getOrCreateSymbol("?" + HandlerPrefix + "$" +
165 Twine(MBB->getNumber()) + "@?0?" +
166 FuncLinkageName + "@4HA");
173167 }
174168
175169 void WinException::beginFunclet(const MachineBasicBlock &MBB,
179173 const Function *F = Asm->MF->getFunction();
180174 // If a symbol was not provided for the funclet, invent one.
181175 if (!Sym) {
182 Sym = getMCSymbolForMBBOrGV(Asm, &MBB);
176 Sym = getMCSymbolForMBB(Asm, &MBB);
183177
184178 // Describe our funclet symbol as a function with internal linkage.
185179 Asm->OutStreamer->BeginCOFFSymbolDef(Sym);
503497 const MCExpr *ExceptOrNull;
504498 auto *Handler = UME.Handler.get();
505499 if (UME.IsFinally) {
506 FilterOrFinally = create32bitRef(getMCSymbolForMBBOrGV(Asm, Handler));
500 FilterOrFinally = create32bitRef(getMCSymbolForMBB(Asm, Handler));
507501 ExceptOrNull = MCConstantExpr::create(0, Ctx);
508502 } else {
509503 // For an except, the filter can be 1 (catch-all) or a function
596590 if (UnwindMapXData) {
597591 OS.EmitLabel(UnwindMapXData);
598592 for (const CxxUnwindMapEntry &UME : FuncInfo.CxxUnwindMap) {
599 MCSymbol *CleanupSym = getMCSymbolForMBBOrGV(Asm, UME.Cleanup);
593 MCSymbol *CleanupSym =
594 getMCSymbolForMBB(Asm, UME.Cleanup.dyn_cast());
600595 OS.EmitIntValue(UME.ToState, 4); // ToState
601596 OS.EmitValue(create32bitRef(CleanupSym), 4); // Action
602597 }
676671 FrameAllocOffsetRef = MCConstantExpr::create(0, Asm->OutContext);
677672 }
678673
679 MCSymbol *HandlerSym = getMCSymbolForMBBOrGV(Asm, HT.Handler);
674 MCSymbol *HandlerSym =
675 getMCSymbolForMBB(Asm, HT.Handler.dyn_cast());
680676
681677 OS.EmitIntValue(HT.Adjectives, 4); // Adjectives
682678 OS.EmitValue(create32bitRef(HT.TypeDescriptor), 4); // Type
466466 return FilterID;
467467 }
468468
469 const Function *MachineModuleInfo::getWinEHParent(const Function *F) const {
470 StringRef WinEHParentName =
471 F->getFnAttribute("wineh-parent").getValueAsString();
472 if (WinEHParentName.empty() || WinEHParentName == F->getName())
473 return F;
474 return F->getParent()->getFunction(WinEHParentName);
475 }
476
477469 WinEHFuncInfo &MachineModuleInfo::getWinEHFuncInfo(const Function *F) {
478 auto &Ptr = FuncInfoMap[getWinEHParent(F)];
470 auto &Ptr = FuncInfoMap[F];
479471 if (!Ptr)
480472 Ptr.reset(new WinEHFuncInfo);
481473 return *Ptr;
284284
285285 // Calculate state numbers if we haven't already.
286286 WinEHFuncInfo &EHInfo = MMI.getWinEHFuncInfo(&fn);
287 const Function *WinEHParentFn = MMI.getWinEHParent(&fn);
288287 if (Personality == EHPersonality::MSVC_CXX)
289 calculateWinCXXEHStateNumbers(WinEHParentFn, EHInfo);
288 calculateWinCXXEHStateNumbers(&fn, EHInfo);
290289 else if (isAsynchronousEHPersonality(Personality))
291 calculateSEHStateNumbers(WinEHParentFn, EHInfo);
290 calculateSEHStateNumbers(&fn, EHInfo);
292291 else if (Personality == EHPersonality::CoreCLR)
293 calculateClrEHStateNumbers(WinEHParentFn, EHInfo);
294
295 calculateCatchReturnSuccessorColors(WinEHParentFn, EHInfo);
292 calculateClrEHStateNumbers(&fn, EHInfo);
293
294 calculateCatchReturnSuccessorColors(&fn, EHInfo);
296295
297296 // Map all BB references in the WinEH data to MBBs.
298297 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
303302 } else {
304303 H.CatchObj.FrameIndex = INT_MAX;
305304 }
306 if (const auto *BB = dyn_cast(H.Handler.get()))
307 H.Handler = MBBMap[BB];
305 if (H.Handler)
306 H.Handler = MBBMap[H.Handler.get()];
308307 }
309308 }
310309 for (CxxUnwindMapEntry &UME : EHInfo.CxxUnwindMap)
311310 if (UME.Cleanup)
312 if (const auto *BB = dyn_cast(UME.Cleanup.get()))
313 UME.Cleanup = MBBMap[BB];
311 UME.Cleanup = MBBMap[UME.Cleanup.get()];
314312 for (SEHUnwindMapEntry &UME : EHInfo.SEHUnwindMap) {
315313 const BasicBlock *BB = UME.Handler.get();
316314 UME.Handler = MBBMap[BB];
143143 if (!Fn.hasPersonalityFn())
144144 return false;
145145
146 // No need to prepare outlined handlers.
147 if (Fn.hasFnAttribute("wineh-parent"))
148 return false;
149
150146 // Classify the personality to see what kind of preparation we need.
151147 Personality = classifyEHPersonality(Fn.getPersonalityFn());
152148
172168 }
173169
174170 static int addUnwindMapEntry(WinEHFuncInfo &FuncInfo, int ToState,
175 const Value *V) {
171 const BasicBlock *BB) {
176172 CxxUnwindMapEntry UME;
177173 UME.ToState = ToState;
178 UME.Cleanup = V;
174 UME.Cleanup = BB;
179175 FuncInfo.CxxUnwindMap.push_back(UME);
180176 return FuncInfo.getLastStateNumber();
181177 }
27002700 }
27012701
27022702 MachineModuleInfo &MMI = MF.getMMI();
2703 const Function *WinEHParent = nullptr;
2704 if (MMI.hasWinEHFuncInfo(Fn))
2705 WinEHParent = MMI.getWinEHParent(Fn);
2706 bool IsWinEHParent = WinEHParent && WinEHParent == Fn;
27072703
27082704 // Figure out if XMM registers are in use.
27092705 assert(!(Subtarget->useSoftFloat() &&
28602856
28612857 FuncInfo->setArgumentStackSize(StackSize);
28622858
2863 if (IsWinEHParent) {
2859 if (MMI.hasWinEHFuncInfo(Fn)) {
28642860 if (Is64Bit) {
28652861 int UnwindHelpFI = MFI->CreateStackObject(8, 8, /*isSS=*/false);
28662862 SDValue StackSlot = DAG.getFrameIndex(UnwindHelpFI, MVT::i64);
148148 }
149149
150150 bool WinEHStatePass::runOnFunction(Function &F) {
151 // If this is an outlined handler, don't do anything. We'll do state insertion
152 // for it in the parent.
153 StringRef WinEHParentName =
154 F.getFnAttribute("wineh-parent").getValueAsString();
155 if (WinEHParentName != F.getName() && !WinEHParentName.empty())
156 return false;
157
158151 // Check the personality. Do nothing if this personality doesn't use funclets.
159152 if (!F.hasPersonalityFn())
160153 return false;
168161
169162 // Skip this function if there are no EH pads and we aren't using IR-level
170163 // outlining.
171 if (WinEHParentName.empty()) {
172 bool HasPads = false;
173 for (BasicBlock &BB : F) {
174 if (BB.isEHPad()) {
175 HasPads = true;
176 break;
177 }
164 bool HasPads = false;
165 for (BasicBlock &BB : F) {
166 if (BB.isEHPad()) {
167 HasPads = true;
168 break;
178169 }
179 if (!HasPads)
180 return false;
181 }
170 }
171 if (!HasPads)
172 return false;
182173
183174 // Disable frame pointer elimination in this function.
184175 // FIXME: Do the nested handlers need to keep the parent ebp in ebp, or can we