llvm.org GIT mirror llvm / 29c7b3a
Move most EH from MachineModuleInfo to MachineFunction Most of the exception handling members in MachineModuleInfo is actually per function data (talks about the "current function") so it is better to keep it at the function instead of the module. This is a necessary step to have machine module passes work properly. Also: - Rename TidyLandingPads() to tidyLandingPads() - Use doxygen member groups instead of "//===- EH ---"... so it is clear where a group ends. - I had to add an ugly const_cast at two places in the AsmPrinter because the available MachineFunction pointers are const, but the code wants to call tidyLandingPads() in between (markFunctionEnd()/endFunction()). Differential Revision: https://reviews.llvm.org/D27227 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288293 91177308-0d34-0410-b5e6-96231b3b80d8 Matthias Braun 4 years ago
21 changed file(s) with 431 addition(s) and 428 deletion(s). Raw diff Collapse all Expand all
2020 #include "llvm/ADT/BitVector.h"
2121 #include "llvm/ADT/ilist.h"
2222 #include "llvm/ADT/Optional.h"
23 #include "llvm/Analysis/EHPersonalities.h"
2324 #include "llvm/CodeGen/MachineBasicBlock.h"
2425 #include "llvm/CodeGen/MachineMemOperand.h"
2526 #include "llvm/IR/DebugLoc.h"
2627 #include "llvm/IR/Metadata.h"
2728 #include "llvm/MC/MCDwarf.h"
29 #include "llvm/MC/MCSymbol.h"
2830 #include "llvm/Support/Allocator.h"
2931 #include "llvm/Support/ArrayRecycler.h"
3032 #include "llvm/Support/Compiler.h"
169171 BitVector(static_cast(Property::LastProperty)+1);
170172 };
171173
174 struct SEHHandler {
175 /// Filter or finally function. Null indicates a catch-all.
176 const Function *FilterOrFinally;
177
178 /// Address of block to recover at. Null for a finally handler.
179 const BlockAddress *RecoverBA;
180 };
181
182
183 /// This structure is used to retain landing pad info for the current function.
184 struct LandingPadInfo {
185 MachineBasicBlock *LandingPadBlock; // Landing pad block.
186 SmallVector BeginLabels; // Labels prior to invoke.
187 SmallVector EndLabels; // Labels after invoke.
188 SmallVector SEHHandlers; // SEH handlers active at this lpad.
189 MCSymbol *LandingPadLabel; // Label at beginning of landing pad.
190 std::vector TypeIds; // List of type ids (filters negative).
191
192 explicit LandingPadInfo(MachineBasicBlock *MBB)
193 : LandingPadBlock(MBB), LandingPadLabel(nullptr) {}
194 };
195
172196 class MachineFunction {
173197 const Function *Fn;
174198 const TargetMachine &Target;
248272 /// List of moves done by a function's prolog. Used to construct frame maps
249273 /// by debug and exception handling consumers.
250274 std::vector FrameInstructions;
275
276 /// \name Exception Handling
277 /// \{
278
279 /// List of LandingPadInfo describing the landing pad information.
280 std::vector LandingPads;
281
282 /// Map a landing pad's EH symbol to the call site indexes.
283 DenseMap > LPadToCallSiteMap;
284
285 /// Map of invoke call site index values to associated begin EH_LABEL.
286 DenseMap CallSiteMap;
287
288 bool CallsEHReturn = false;
289 bool CallsUnwindInit = false;
290 bool HasEHFunclets = false;
291
292 /// List of C++ TypeInfo used.
293 std::vector TypeInfos;
294
295 /// List of typeids encoding filters used.
296 std::vector FilterIds;
297
298 /// List of the indices in FilterIds corresponding to filter terminators.
299 std::vector FilterEnds;
300
301 EHPersonality PersonalityTypeCache = EHPersonality::Unknown;
302
303 /// \}
251304
252305 MachineFunction(const MachineFunction &) = delete;
253306 void operator=(const MachineFunction&) = delete;
671724 return FrameInstructions.size() - 1;
672725 }
673726
727 /// \name Exception Handling
728 /// \{
729
730 bool callsEHReturn() const { return CallsEHReturn; }
731 void setCallsEHReturn(bool b) { CallsEHReturn = b; }
732
733 bool callsUnwindInit() const { return CallsUnwindInit; }
734 void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
735
736 bool hasEHFunclets() const { return HasEHFunclets; }
737 void setHasEHFunclets(bool V) { HasEHFunclets = V; }
738
739 /// Find or create an LandingPadInfo for the specified MachineBasicBlock.
740 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
741
742 /// Remap landing pad labels and remove any deleted landing pads.
743 void tidyLandingPads(DenseMap *LPMap = nullptr);
744
745 /// Return a reference to the landing pad info for the current function.
746 const std::vector &getLandingPads() const {
747 return LandingPads;
748 }
749
750 /// Provide the begin and end labels of an invoke style call and associate it
751 /// with a try landing pad block.
752 void addInvoke(MachineBasicBlock *LandingPad,
753 MCSymbol *BeginLabel, MCSymbol *EndLabel);
754
755 /// Add a new panding pad. Returns the label ID for the landing pad entry.
756 MCSymbol *addLandingPad(MachineBasicBlock *LandingPad);
757
758 /// Provide the catch typeinfo for a landing pad.
759 void addCatchTypeInfo(MachineBasicBlock *LandingPad,
760 ArrayRef TyInfo);
761
762 /// Provide the filter typeinfo for a landing pad.
763 void addFilterTypeInfo(MachineBasicBlock *LandingPad,
764 ArrayRef TyInfo);
765
766 /// Add a cleanup action for a landing pad.
767 void addCleanup(MachineBasicBlock *LandingPad);
768
769 void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter,
770 const BlockAddress *RecoverLabel);
771
772 void addSEHCleanupHandler(MachineBasicBlock *LandingPad,
773 const Function *Cleanup);
774
775 /// Return the type id for the specified typeinfo. This is function wide.
776 unsigned getTypeIDFor(const GlobalValue *TI);
777
778 /// Return the id of the filter encoded by TyIds. This is function wide.
779 int getFilterIDFor(std::vector &TyIds);
780
781 /// Map the landing pad's EH symbol to the call site indexes.
782 void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef Sites);
783
784 /// Get the call site indexes for a landing pad EH symbol.
785 SmallVectorImpl &getCallSiteLandingPad(MCSymbol *Sym) {
786 assert(hasCallSiteLandingPad(Sym) &&
787 "missing call site number for landing pad!");
788 return LPadToCallSiteMap[Sym];
789 }
790
791 /// Return true if the landing pad Eh symbol has an associated call site.
792 bool hasCallSiteLandingPad(MCSymbol *Sym) {
793 return !LPadToCallSiteMap[Sym].empty();
794 }
795
796 /// Map the begin label for a call site.
797 void setCallSiteBeginLabel(MCSymbol *BeginLabel, unsigned Site) {
798 CallSiteMap[BeginLabel] = Site;
799 }
800
801 /// Get the call site number for a begin label.
802 unsigned getCallSiteBeginLabel(MCSymbol *BeginLabel) const {
803 assert(hasCallSiteBeginLabel(BeginLabel) &&
804 "Missing call site number for EH_LABEL!");
805 return CallSiteMap.lookup(BeginLabel);
806 }
807
808 /// Return true if the begin label has a call site number associated with it.
809 bool hasCallSiteBeginLabel(MCSymbol *BeginLabel) const {
810 return CallSiteMap.count(BeginLabel);
811 }
812
813 /// Return a reference to the C++ typeinfo for the current function.
814 const std::vector &getTypeInfos() const {
815 return TypeInfos;
816 }
817
818 /// Return a reference to the typeids encoding filters used in the current
819 /// function.
820 const std::vector &getFilterIds() const {
821 return FilterIds;
822 }
823
824 /// \}
825
674826 /// Collect information used to emit debugging information of a variable.
675827 void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
676828 unsigned Slot, const DILocation *Loc) {
682834 return VariableDbgInfos;
683835 }
684836 };
837
838 /// \name Exception Handling
839 /// \{
840
841 /// Extract the exception handling information from the landingpad instruction
842 /// and add them to the specified machine module info.
843 void addLandingPadInfo(const LandingPadInst &I, MachineBasicBlock &MBB);
844
845 /// \}
685846
686847 //===--------------------------------------------------------------------===//
687848 // GraphTraits specializations for function basic block graphs (CFGs)
3434 #include "llvm/ADT/PointerIntPair.h"
3535 #include "llvm/ADT/SmallPtrSet.h"
3636 #include "llvm/ADT/SmallVector.h"
37 #include "llvm/Analysis/EHPersonalities.h"
3837 #include "llvm/IR/DebugLoc.h"
3938 #include "llvm/IR/ValueHandle.h"
4039 #include "llvm/MC/MCContext.h"
6160 class PointerType;
6261 class StructType;
6362
64 struct SEHHandler {
65 // Filter or finally function. Null indicates a catch-all.
66 const Function *FilterOrFinally;
67
68 // Address of block to recover at. Null for a finally handler.
69 const BlockAddress *RecoverBA;
70 };
71
72 //===----------------------------------------------------------------------===//
73 /// This structure is used to retain landing pad info for the current function.
74 ///
75 struct LandingPadInfo {
76 MachineBasicBlock *LandingPadBlock; // Landing pad block.
77 SmallVector BeginLabels; // Labels prior to invoke.
78 SmallVector EndLabels; // Labels after invoke.
79 SmallVector SEHHandlers; // SEH handlers active at this lpad.
80 MCSymbol *LandingPadLabel; // Label at beginning of landing pad.
81 std::vector TypeIds; // List of type ids (filters negative).
82
83 explicit LandingPadInfo(MachineBasicBlock *MBB)
84 : LandingPadBlock(MBB), LandingPadLabel(nullptr) {}
85 };
86
8763 //===----------------------------------------------------------------------===//
8864 /// This class can be derived from and used by targets to hold private
8965 /// target-specific information for each Module. Objects of type are
12197 /// want.
12298 MachineModuleInfoImpl *ObjFileMMI;
12399
124 /// List of LandingPadInfo describing the landing pad information in the
125 /// current function.
126 std::vector LandingPads;
127
128 /// Map a landing pad's EH symbol to the call site indexes.
129 DenseMap > LPadToCallSiteMap;
130
131 /// Map of invoke call site index values to associated begin EH_LABEL for the
132 /// current function.
133 DenseMap CallSiteMap;
134
135 /// The current call site index being processed, if any. 0 if none.
136 unsigned CurCallSite;
137
138 /// List of C++ TypeInfo used in the current function.
139 std::vector TypeInfos;
140
141 /// List of typeids encoding filters used in the current function.
142 std::vector FilterIds;
143
144 /// List of the indices in FilterIds corresponding to filter terminators.
145 std::vector FilterEnds;
100 /// \name Exception Handling
101 /// \{
146102
147103 /// Vector of all personality functions ever seen. Used to emit common EH
148104 /// frames.
149105 std::vector Personalities;
150106
107 /// The current call site index being processed, if any. 0 if none.
108 unsigned CurCallSite;
109
110 /// \}
111
151112 /// This map keeps track of which symbol is being used for the specified
152113 /// basic block's address of label.
153114 MMIAddrLabelMap *AddrLabelSymbols;
154
155 bool CallsEHReturn;
156 bool CallsUnwindInit;
157 bool HasEHFunclets;
158115
159116 // TODO: Ideally, what we'd like is to have a switch that allows emitting
160117 // synchronous (precise at call-sites only) CFA into .eh_frame. However,
175132 /// a definition of a symbol, __morestack_addr, containing the address. See
176133 /// comments in lib/Target/X86/X86FrameLowering.cpp for more details.
177134 bool UsesMorestackAddr;
178
179 EHPersonality PersonalityTypeCache;
180135
181136 MachineFunctionInitializer *MFInitializer;
182137 /// Maps IR Functions to their corresponding MachineFunctions.
196151 bool doInitialization(Module &) override;
197152 bool doFinalization(Module &) override;
198153
199 /// Discard function meta information.
200 void EndFunction();
201
202154 const MCContext &getContext() const { return Context; }
203155 MCContext &getContext() { return Context; }
204156
236188 bool hasDebugInfo() const { return DbgInfoAvailable; }
237189 void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = avail; }
238190
239 bool callsEHReturn() const { return CallsEHReturn; }
240 void setCallsEHReturn(bool b) { CallsEHReturn = b; }
241
242 bool callsUnwindInit() const { return CallsUnwindInit; }
243 void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
244
245 bool hasEHFunclets() const { return HasEHFunclets; }
246 void setHasEHFunclets(bool V) { HasEHFunclets = V; }
247
248191 bool usesVAFloatArgument() const {
249192 return UsesVAFloatArgument;
250193 }
280223 void takeDeletedSymbolsForFunction(const Function *F,
281224 std::vector &Result);
282225
283
284 //===- EH ---------------------------------------------------------------===//
285
286 /// Find or create an LandingPadInfo for the specified MachineBasicBlock.
287 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
288
289 /// Provide the begin and end labels of an invoke style call and associate it
290 /// with a try landing pad block.
291 void addInvoke(MachineBasicBlock *LandingPad,
292 MCSymbol *BeginLabel, MCSymbol *EndLabel);
293
294 /// Add a new panding pad. Returns the label ID for the landing pad entry.
295 MCSymbol *addLandingPad(MachineBasicBlock *LandingPad);
226 /// \name Exception Handling
227 /// \{
228
229 /// Set the call site currently being processed.
230 void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }
231
232 /// Get the call site currently being processed, if any. return zero if
233 /// none.
234 unsigned getCurrentCallSite() { return CurCallSite; }
296235
297236 /// Provide the personality function for the exception information.
298237 void addPersonality(const Function *Personality);
301240 const std::vector& getPersonalities() const {
302241 return Personalities;
303242 }
304
305 /// Provide the catch typeinfo for a landing pad.
306 void addCatchTypeInfo(MachineBasicBlock *LandingPad,
307 ArrayRef TyInfo);
308
309 /// Provide the filter typeinfo for a landing pad.
310 void addFilterTypeInfo(MachineBasicBlock *LandingPad,
311 ArrayRef TyInfo);
312
313 /// Add a cleanup action for a landing pad.
314 void addCleanup(MachineBasicBlock *LandingPad);
315
316 void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter,
317 const BlockAddress *RecoverLabel);
318
319 void addSEHCleanupHandler(MachineBasicBlock *LandingPad,
320 const Function *Cleanup);
321
322 /// Return the type id for the specified typeinfo. This is function wide.
323 unsigned getTypeIDFor(const GlobalValue *TI);
324
325 /// Return the id of the filter encoded by TyIds. This is function wide.
326 int getFilterIDFor(std::vector &TyIds);
327
328 /// Remap landing pad labels and remove any deleted landing pads.
329 void TidyLandingPads(DenseMap *LPMap = nullptr);
330
331 /// Return a reference to the landing pad info for the current function.
332 const std::vector &getLandingPads() const {
333 return LandingPads;
334 }
335
336 /// Map the landing pad's EH symbol to the call site indexes.
337 void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef Sites);
338
339 /// Get the call site indexes for a landing pad EH symbol.
340 SmallVectorImpl &getCallSiteLandingPad(MCSymbol *Sym) {
341 assert(hasCallSiteLandingPad(Sym) &&
342 "missing call site number for landing pad!");
343 return LPadToCallSiteMap[Sym];
344 }
345
346 /// Return true if the landing pad Eh symbol has an associated call site.
347 bool hasCallSiteLandingPad(MCSymbol *Sym) {
348 return !LPadToCallSiteMap[Sym].empty();
349 }
350
351 /// Map the begin label for a call site.
352 void setCallSiteBeginLabel(MCSymbol *BeginLabel, unsigned Site) {
353 CallSiteMap[BeginLabel] = Site;
354 }
355
356 /// Get the call site number for a begin label.
357 unsigned getCallSiteBeginLabel(MCSymbol *BeginLabel) {
358 assert(hasCallSiteBeginLabel(BeginLabel) &&
359 "Missing call site number for EH_LABEL!");
360 return CallSiteMap[BeginLabel];
361 }
362
363 /// Return true if the begin label has a call site number associated with it.
364 bool hasCallSiteBeginLabel(MCSymbol *BeginLabel) {
365 return CallSiteMap[BeginLabel] != 0;
366 }
367
368 /// Set the call site currently being processed.
369 void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }
370
371 /// Get the call site currently being processed, if any. return zero if
372 /// none.
373 unsigned getCurrentCallSite() { return CurCallSite; }
374
375 /// Return a reference to the C++ typeinfo for the current function.
376 const std::vector &getTypeInfos() const {
377 return TypeInfos;
378 }
379
380 /// Return a reference to the typeids encoding filters used in the current
381 /// function.
382 const std::vector &getFilterIds() const {
383 return FilterIds;
384 }
243 /// \}
385244 }; // End class MachineModuleInfo
386245
387246 //===- MMI building helpers -----------------------------------------------===//
392251 /// which will link in MSVCRT's floating-point support.
393252 void computeUsesVAFloatArgument(const CallInst &I, MachineModuleInfo &MMI);
394253
395 /// Extract the exception handling information from the landingpad instruction
396 /// and add them to the specified machine module info.
397 void addLandingPadInfo(const LandingPadInst &I, MachineModuleInfo &MMI,
398 MachineBasicBlock &MBB);
399
400
401254 } // End llvm namespace
402255
403256 #endif
683683 DenseMap FuncletMembership;
684684
685685 // We don't have anything to do if there aren't any EH pads.
686 if (!MF.getMMI().hasEHFunclets())
686 if (!MF.hasEHFunclets())
687687 return FuncletMembership;
688688
689689 int EntryBBNumber = MF.front().getNumber();
7474 F->hasPersonalityFn() && !isNoOpWithoutInvoke(classifyEHPersonality(Per)) &&
7575 F->needsUnwindTableEntry();
7676 bool shouldEmitPersonality = forceEmitPersonality ||
77 !MMI->getLandingPads().empty();
77 !MF->getLandingPads().empty();
7878 if (!Asm->MF->getFunction()->needsUnwindTableEntry() &&
7979 !shouldEmitPersonality)
8080 ATS.emitCantUnwind();
9898 }
9999
100100 void ARMException::emitTypeInfos(unsigned TTypeEncoding) {
101 const std::vector &TypeInfos = MMI->getTypeInfos();
102 const std::vector &FilterIds = MMI->getFilterIds();
101 const MachineFunction *MF = Asm->MF;
102 const std::vector &TypeInfos = MF->getTypeInfos();
103 const std::vector &FilterIds = MF->getFilterIds();
103104
104105 bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
105106
946946 // Emit target-specific gunk after the function body.
947947 EmitFunctionBodyEnd();
948948
949 if (!MMI->getLandingPads().empty() || MMI->hasDebugInfo() ||
950 MMI->hasEHFunclets() || MAI->hasDotTypeDotSizeDirective()) {
949 if (!MF->getLandingPads().empty() || MMI->hasDebugInfo() ||
950 MF->hasEHFunclets() || MAI->hasDotTypeDotSizeDirective()) {
951951 // Create a symbol for the end of function.
952952 CurrentFnEnd = createTempSymbol("func_end");
953953 OutStreamer->EmitLabel(CurrentFnEnd);
980980 HI.TimerGroupDescription, TimePassesIsEnabled);
981981 HI.Handler->endFunction(MF);
982982 }
983 MMI->EndFunction();
984983
985984 OutStreamer->AddBlankLine();
986985 }
12721271 CurrentFnBegin = nullptr;
12731272 CurExceptionSym = nullptr;
12741273 bool NeedsLocalForSize = MAI->needsLocalForSize();
1275 if (!MMI->getLandingPads().empty() || MMI->hasDebugInfo() ||
1276 MMI->hasEHFunclets() || NeedsLocalForSize) {
1274 if (!MF.getLandingPads().empty() || MMI->hasDebugInfo() ||
1275 MF.hasEHFunclets() || NeedsLocalForSize) {
12771276 CurrentFnBegin = createTempSymbol("func_begin");
12781277 if (NeedsLocalForSize)
12791278 CurrentFnSymForSize = CurrentFnBegin;
4343 void DwarfCFIExceptionBase::markFunctionEnd() {
4444 endFragment();
4545
46 if (MMI->getLandingPads().empty())
47 return;
48
4946 // Map all labels and get rid of any dead landing pads.
50 MMI->TidyLandingPads();
47 if (!Asm->MF->getLandingPads().empty()) {
48 MachineFunction *NonConstMF = const_cast(Asm->MF);
49 NonConstMF->tidyLandingPads();
50 }
5151 }
5252
5353 void DwarfCFIExceptionBase::endFragment() {
9797 const Function *F = MF->getFunction();
9898
9999 // If any landing pads survive, we need an EH table.
100 bool hasLandingPads = !MMI->getLandingPads().empty();
100 bool hasLandingPads = !MF->getLandingPads().empty();
101101
102102 // See if we need frame move info.
103103 AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
169169
170170 /// endFunction - Gather and emit post-function exception information.
171171 ///
172 void DwarfCFIException::endFunction(const MachineFunction *) {
172 void DwarfCFIException::endFunction(const MachineFunction *MF) {
173173 if (!shouldEmitPersonality)
174174 return;
175175
7373 // output using a fixed width encoding. FilterOffsets[i] holds the byte
7474 // offset corresponding to FilterIds[i].
7575
76 const std::vector &FilterIds = MMI->getFilterIds();
76 const std::vector &FilterIds = Asm->MF->getFilterIds();
7777 SmallVector FilterOffsets;
7878 FilterOffsets.reserve(FilterIds.size());
7979 int Offset = -1;
295295 else {
296296 // SjLj EH must maintain the call sites in the order assigned
297297 // to them by the SjLjPrepare pass.
298 unsigned SiteNo = MMI->getCallSiteBeginLabel(BeginLabel);
298 unsigned SiteNo = Asm->MF->getCallSiteBeginLabel(BeginLabel);
299299 if (CallSites.size() < SiteNo)
300300 CallSites.resize(SiteNo);
301301 CallSites[SiteNo - 1] = Site;
335335 /// 3. Type ID table contains references to all the C++ typeinfo for all
336336 /// catches in the function. This tables is reverse indexed base 1.
337337 void EHStreamer::emitExceptionTable() {
338 const std::vector &TypeInfos = MMI->getTypeInfos();
339 const std::vector &FilterIds = MMI->getFilterIds();
340 const std::vector &PadInfos = MMI->getLandingPads();
338 const MachineFunction *MF = Asm->MF;
339 const std::vector &TypeInfos = MF->getTypeInfos();
340 const std::vector &FilterIds = MF->getFilterIds();
341 const std::vector &PadInfos = MF->getLandingPads();
341342
342343 // Sort the landing pads in order of their type ids. This is used to fold
343344 // duplicate actions.
648649 }
649650
650651 void EHStreamer::emitTypeInfos(unsigned TTypeEncoding) {
651 const std::vector &TypeInfos = MMI->getTypeInfos();
652 const std::vector &FilterIds = MMI->getFilterIds();
652 const MachineFunction *MF = Asm->MF;
653 const std::vector &TypeInfos = MF->getTypeInfos();
654 const std::vector &FilterIds = MF->getFilterIds();
653655
654656 bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
655657
6262 shouldEmitMoves = shouldEmitPersonality = shouldEmitLSDA = false;
6363
6464 // If any landing pads survive, we need an EH table.
65 bool hasLandingPads = !MMI->getLandingPads().empty();
66 bool hasEHFunclets = MMI->hasEHFunclets();
65 bool hasLandingPads = !MF->getLandingPads().empty();
66 bool hasEHFunclets = MF->hasEHFunclets();
6767
6868 const Function *F = MF->getFunction();
6969
125125 // Get rid of any dead landing pads if we're not using funclets. In funclet
126126 // schemes, the landing pad is not actually reachable. It only exists so
127127 // that we can emit the right table data.
128 if (!isFuncletEHPersonality(Per))
129 MMI->TidyLandingPads();
128 if (!isFuncletEHPersonality(Per)) {
129 MachineFunction *NonConstMF = const_cast(MF);
130 NonConstMF->tidyLandingPads();
131 }
130132
131133 endFunclet();
132134
133135 // endFunclet will emit the necessary .xdata tables for x64 SEH.
134 if (Per == EHPersonality::MSVC_Win64SEH && MMI->hasEHFunclets())
136 if (Per == EHPersonality::MSVC_Win64SEH && MF->hasEHFunclets())
135137 return;
136138
137139 if (shouldEmitPersonality || shouldEmitLSDA) {
233235 if (!CurrentFuncletEntry)
234236 return;
235237
238 const MachineFunction *MF = Asm->MF;
236239 if (shouldEmitMoves || shouldEmitPersonality) {
237 const Function *F = Asm->MF->getFunction();
240 const Function *F = MF->getFunction();
238241 EHPersonality Per = EHPersonality::Unknown;
239242 if (F->hasPersonalityFn())
240243 Per = classifyEHPersonality(F->getPersonalityFn()->stripPointerCasts());
254257 MCSymbol *FuncInfoXData = Asm->OutContext.getOrCreateSymbol(
255258 Twine("$cppxdata$", FuncLinkageName));
256259 Asm->OutStreamer->EmitValue(create32bitRef(FuncInfoXData), 4);
257 } else if (Per == EHPersonality::MSVC_Win64SEH && MMI->hasEHFunclets() &&
260 } else if (Per == EHPersonality::MSVC_Win64SEH && MF->hasEHFunclets() &&
258261 !CurrentFuncletEntry->isEHFuncletEntry()) {
259262 // If this is the parent function in Win64 SEH, emit the LSDA immediately
260263 // following .seh_handlerdata.
261 emitCSpecificHandlerTable(Asm->MF);
264 emitCSpecificHandlerTable(MF);
262265 }
263266
264267 // Switch back to the previous section now that we are done writing to
567567 Twine(getFunctionNumber()) + "$pb");
568568 }
569569
570 /// \name Exception Handling
571 /// \{
572
573 LandingPadInfo &
574 MachineFunction::getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad) {
575 unsigned N = LandingPads.size();
576 for (unsigned i = 0; i < N; ++i) {
577 LandingPadInfo &LP = LandingPads[i];
578 if (LP.LandingPadBlock == LandingPad)
579 return LP;
580 }
581
582 LandingPads.push_back(LandingPadInfo(LandingPad));
583 return LandingPads[N];
584 }
585
586 void MachineFunction::addInvoke(MachineBasicBlock *LandingPad,
587 MCSymbol *BeginLabel, MCSymbol *EndLabel) {
588 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
589 LP.BeginLabels.push_back(BeginLabel);
590 LP.EndLabels.push_back(EndLabel);
591 }
592
593 MCSymbol *MachineFunction::addLandingPad(MachineBasicBlock *LandingPad) {
594 MCSymbol *LandingPadLabel = Ctx.createTempSymbol();
595 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
596 LP.LandingPadLabel = LandingPadLabel;
597 return LandingPadLabel;
598 }
599
600 void MachineFunction::addCatchTypeInfo(MachineBasicBlock *LandingPad,
601 ArrayRef TyInfo) {
602 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
603 for (unsigned N = TyInfo.size(); N; --N)
604 LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1]));
605 }
606
607 void MachineFunction::addFilterTypeInfo(MachineBasicBlock *LandingPad,
608 ArrayRef TyInfo) {
609 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
610 std::vector IdsInFilter(TyInfo.size());
611 for (unsigned I = 0, E = TyInfo.size(); I != E; ++I)
612 IdsInFilter[I] = getTypeIDFor(TyInfo[I]);
613 LP.TypeIds.push_back(getFilterIDFor(IdsInFilter));
614 }
615
616 void MachineFunction::tidyLandingPads(DenseMap *LPMap) {
617 for (unsigned i = 0; i != LandingPads.size(); ) {
618 LandingPadInfo &LandingPad = LandingPads[i];
619 if (LandingPad.LandingPadLabel &&
620 !LandingPad.LandingPadLabel->isDefined() &&
621 (!LPMap || (*LPMap)[LandingPad.LandingPadLabel] == 0))
622 LandingPad.LandingPadLabel = nullptr;
623
624 // Special case: we *should* emit LPs with null LP MBB. This indicates
625 // "nounwind" case.
626 if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) {
627 LandingPads.erase(LandingPads.begin() + i);
628 continue;
629 }
630
631 for (unsigned j = 0, e = LandingPads[i].BeginLabels.size(); j != e; ++j) {
632 MCSymbol *BeginLabel = LandingPad.BeginLabels[j];
633 MCSymbol *EndLabel = LandingPad.EndLabels[j];
634 if ((BeginLabel->isDefined() ||
635 (LPMap && (*LPMap)[BeginLabel] != 0)) &&
636 (EndLabel->isDefined() ||
637 (LPMap && (*LPMap)[EndLabel] != 0))) continue;
638
639 LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j);
640 LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j);
641 --j;
642 --e;
643 }
644
645 // Remove landing pads with no try-ranges.
646 if (LandingPads[i].BeginLabels.empty()) {
647 LandingPads.erase(LandingPads.begin() + i);
648 continue;
649 }
650
651 // If there is no landing pad, ensure that the list of typeids is empty.
652 // If the only typeid is a cleanup, this is the same as having no typeids.
653 if (!LandingPad.LandingPadBlock ||
654 (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0]))
655 LandingPad.TypeIds.clear();
656 ++i;
657 }
658 }
659
660 void MachineFunction::addCleanup(MachineBasicBlock *LandingPad) {
661 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
662 LP.TypeIds.push_back(0);
663 }
664
665 void MachineFunction::addSEHCatchHandler(MachineBasicBlock *LandingPad,
666 const Function *Filter,
667 const BlockAddress *RecoverBA) {
668 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
669 SEHHandler Handler;
670 Handler.FilterOrFinally = Filter;
671 Handler.RecoverBA = RecoverBA;
672 LP.SEHHandlers.push_back(Handler);
673 }
674
675 void MachineFunction::addSEHCleanupHandler(MachineBasicBlock *LandingPad,
676 const Function *Cleanup) {
677 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
678 SEHHandler Handler;
679 Handler.FilterOrFinally = Cleanup;
680 Handler.RecoverBA = nullptr;
681 LP.SEHHandlers.push_back(Handler);
682 }
683
684 void MachineFunction::setCallSiteLandingPad(MCSymbol *Sym,
685 ArrayRef Sites) {
686 LPadToCallSiteMap[Sym].append(Sites.begin(), Sites.end());
687 }
688
689 unsigned MachineFunction::getTypeIDFor(const GlobalValue *TI) {
690 for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i)
691 if (TypeInfos[i] == TI) return i + 1;
692
693 TypeInfos.push_back(TI);
694 return TypeInfos.size();
695 }
696
697 int MachineFunction::getFilterIDFor(std::vector &TyIds) {
698 // If the new filter coincides with the tail of an existing filter, then
699 // re-use the existing filter. Folding filters more than this requires
700 // re-ordering filters and/or their elements - probably not worth it.
701 for (std::vector::iterator I = FilterEnds.begin(),
702 E = FilterEnds.end(); I != E; ++I) {
703 unsigned i = *I, j = TyIds.size();
704
705 while (i && j)
706 if (FilterIds[--i] != TyIds[--j])
707 goto try_next;
708
709 if (!j)
710 // The new filter coincides with range [i, end) of the existing filter.
711 return -(1 + i);
712
713 try_next:;
714 }
715
716 // Add the new filter.
717 int FilterID = -(1 + FilterIds.size());
718 FilterIds.reserve(FilterIds.size() + TyIds.size() + 1);
719 FilterIds.insert(FilterIds.end(), TyIds.begin(), TyIds.end());
720 FilterEnds.push_back(FilterIds.size());
721 FilterIds.push_back(0); // terminator
722 return FilterID;
723 }
724
725 void llvm::addLandingPadInfo(const LandingPadInst &I, MachineBasicBlock &MBB) {
726 MachineFunction &MF = *MBB.getParent();
727 if (const auto *PF = dyn_cast(
728 I.getParent()->getParent()->getPersonalityFn()->stripPointerCasts()))
729 MF.getMMI().addPersonality(PF);
730
731 if (I.isCleanup())
732 MF.addCleanup(&MBB);
733
734 // FIXME: New EH - Add the clauses in reverse order. This isn't 100% correct,
735 // but we need to do it this way because of how the DWARF EH emitter
736 // processes the clauses.
737 for (unsigned i = I.getNumClauses(); i != 0; --i) {
738 Value *Val = I.getClause(i - 1);
739 if (I.isCatch(i - 1)) {
740 MF.addCatchTypeInfo(&MBB,
741 dyn_cast(Val->stripPointerCasts()));
742 } else {
743 // Add filters in a list.
744 Constant *CVal = cast(Val);
745 SmallVector FilterList;
746 for (User::op_iterator II = CVal->op_begin(), IE = CVal->op_end();
747 II != IE; ++II)
748 FilterList.push_back(cast((*II)->stripPointerCasts()));
749
750 MF.addFilterTypeInfo(&MBB, FilterList);
751 }
752 }
753 }
754
755 /// \}
756
570757 //===----------------------------------------------------------------------===//
571758 // MachineFrameInfo implementation
572759 //===----------------------------------------------------------------------===//
202202
203203 ObjFileMMI = nullptr;
204204 CurCallSite = 0;
205 CallsEHReturn = false;
206 CallsUnwindInit = false;
207 HasEHFunclets = false;
208205 DbgInfoAvailable = UsesVAFloatArgument = UsesMorestackAddr = false;
209 PersonalityTypeCache = EHPersonality::Unknown;
210206 AddrLabelSymbols = nullptr;
211207 TheModule = &M;
212208
226222 ObjFileMMI = nullptr;
227223
228224 return false;
229 }
230
231 void MachineModuleInfo::EndFunction() {
232 // Clean up exception info.
233 LandingPads.clear();
234 PersonalityTypeCache = EHPersonality::Unknown;
235 CallSiteMap.clear();
236 TypeInfos.clear();
237 FilterIds.clear();
238 FilterEnds.clear();
239 CallsEHReturn = false;
240 CallsUnwindInit = false;
241 HasEHFunclets = false;
242225 }
243226
244227 //===- Address of Block Management ----------------------------------------===//
260243 takeDeletedSymbolsForFunction(const_cast(F), Result);
261244 }
262245
263 //===- EH -----------------------------------------------------------------===//
264
265 LandingPadInfo &MachineModuleInfo::getOrCreateLandingPadInfo
266 (MachineBasicBlock *LandingPad) {
267 unsigned N = LandingPads.size();
268 for (unsigned i = 0; i < N; ++i) {
269 LandingPadInfo &LP = LandingPads[i];
270 if (LP.LandingPadBlock == LandingPad)
271 return LP;
272 }
273
274 LandingPads.push_back(LandingPadInfo(LandingPad));
275 return LandingPads[N];
276 }
277
278 void MachineModuleInfo::addInvoke(MachineBasicBlock *LandingPad,
279 MCSymbol *BeginLabel, MCSymbol *EndLabel) {
280 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
281 LP.BeginLabels.push_back(BeginLabel);
282 LP.EndLabels.push_back(EndLabel);
283 }
284
285 MCSymbol *MachineModuleInfo::addLandingPad(MachineBasicBlock *LandingPad) {
286 MCSymbol *LandingPadLabel = Context.createTempSymbol();
287 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
288 LP.LandingPadLabel = LandingPadLabel;
289 return LandingPadLabel;
290 }
246 /// \name Exception Handling
247 /// \{
291248
292249 void MachineModuleInfo::addPersonality(const Function *Personality) {
293250 for (unsigned i = 0; i < Personalities.size(); ++i)
296253 Personalities.push_back(Personality);
297254 }
298255
299 void MachineModuleInfo::
300 addCatchTypeInfo(MachineBasicBlock *LandingPad,
301 ArrayRef TyInfo) {
302 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
303 for (unsigned N = TyInfo.size(); N; --N)
304 LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1]));
305 }
306
307 void MachineModuleInfo::
308 addFilterTypeInfo(MachineBasicBlock *LandingPad,
309 ArrayRef TyInfo) {
310 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
311 std::vector IdsInFilter(TyInfo.size());
312 for (unsigned I = 0, E = TyInfo.size(); I != E; ++I)
313 IdsInFilter[I] = getTypeIDFor(TyInfo[I]);
314 LP.TypeIds.push_back(getFilterIDFor(IdsInFilter));
315 }
316
317 void MachineModuleInfo::addCleanup(MachineBasicBlock *LandingPad) {
318 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
319 LP.TypeIds.push_back(0);
320 }
321
322 void MachineModuleInfo::addSEHCatchHandler(MachineBasicBlock *LandingPad,
323 const Function *Filter,
324 const BlockAddress *RecoverBA) {
325 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
326 SEHHandler Handler;
327 Handler.FilterOrFinally = Filter;
328 Handler.RecoverBA = RecoverBA;
329 LP.SEHHandlers.push_back(Handler);
330 }
331
332 void MachineModuleInfo::addSEHCleanupHandler(MachineBasicBlock *LandingPad,
333 const Function *Cleanup) {
334 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
335 SEHHandler Handler;
336 Handler.FilterOrFinally = Cleanup;
337 Handler.RecoverBA = nullptr;
338 LP.SEHHandlers.push_back(Handler);
339 }
340
341 void MachineModuleInfo::TidyLandingPads(DenseMap *LPMap) {
342 for (unsigned i = 0; i != LandingPads.size(); ) {
343 LandingPadInfo &LandingPad = LandingPads[i];
344 if (LandingPad.LandingPadLabel &&
345 !LandingPad.LandingPadLabel->isDefined() &&
346 (!LPMap || (*LPMap)[LandingPad.LandingPadLabel] == 0))
347 LandingPad.LandingPadLabel = nullptr;
348
349 // Special case: we *should* emit LPs with null LP MBB. This indicates
350 // "nounwind" case.
351 if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) {
352 LandingPads.erase(LandingPads.begin() + i);
353 continue;
354 }
355
356 for (unsigned j = 0, e = LandingPads[i].BeginLabels.size(); j != e; ++j) {
357 MCSymbol *BeginLabel = LandingPad.BeginLabels[j];
358 MCSymbol *EndLabel = LandingPad.EndLabels[j];
359 if ((BeginLabel->isDefined() ||
360 (LPMap && (*LPMap)[BeginLabel] != 0)) &&
361 (EndLabel->isDefined() ||
362 (LPMap && (*LPMap)[EndLabel] != 0))) continue;
363
364 LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j);
365 LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j);
366 --j;
367 --e;
368 }
369
370 // Remove landing pads with no try-ranges.
371 if (LandingPads[i].BeginLabels.empty()) {
372 LandingPads.erase(LandingPads.begin() + i);
373 continue;
374 }
375
376 // If there is no landing pad, ensure that the list of typeids is empty.
377 // If the only typeid is a cleanup, this is the same as having no typeids.
378 if (!LandingPad.LandingPadBlock ||
379 (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0]))
380 LandingPad.TypeIds.clear();
381 ++i;
382 }
383 }
384
385 void MachineModuleInfo::setCallSiteLandingPad(MCSymbol *Sym,
386 ArrayRef Sites) {
387 LPadToCallSiteMap[Sym].append(Sites.begin(), Sites.end());
388 }
389
390 unsigned MachineModuleInfo::getTypeIDFor(const GlobalValue *TI) {
391 for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i)
392 if (TypeInfos[i] == TI) return i + 1;
393
394 TypeInfos.push_back(TI);
395 return TypeInfos.size();
396 }
397
398 int MachineModuleInfo::getFilterIDFor(std::vector &TyIds) {
399 // If the new filter coincides with the tail of an existing filter, then
400 // re-use the existing filter. Folding filters more than this requires
401 // re-ordering filters and/or their elements - probably not worth it.
402 for (std::vector::iterator I = FilterEnds.begin(),
403 E = FilterEnds.end(); I != E; ++I) {
404 unsigned i = *I, j = TyIds.size();
405
406 while (i && j)
407 if (FilterIds[--i] != TyIds[--j])
408 goto try_next;
409
410 if (!j)
411 // The new filter coincides with range [i, end) of the existing filter.
412 return -(1 + i);
413
414 try_next:;
415 }
416
417 // Add the new filter.
418 int FilterID = -(1 + FilterIds.size());
419 FilterIds.reserve(FilterIds.size() + TyIds.size() + 1);
420 FilterIds.insert(FilterIds.end(), TyIds.begin(), TyIds.end());
421 FilterEnds.push_back(FilterIds.size());
422 FilterIds.push_back(0); // terminator
423 return FilterID;
424 }
256 /// \}
425257
426258 MachineFunction &MachineModuleInfo::getMachineFunction(const Function &F) {
427259 // Shortcut for the common case where a sequence of MachineFunctionPasses
501333 }
502334 }
503335 }
504
505 void llvm::addLandingPadInfo(const LandingPadInst &I, MachineModuleInfo &MMI,
506 MachineBasicBlock &MBB) {
507 if (const auto *PF = dyn_cast(
508 I.getParent()->getParent()->getPersonalityFn()->stripPointerCasts()))
509 MMI.addPersonality(PF);
510
511 if (I.isCleanup())
512 MMI.addCleanup(&MBB);
513
514 // FIXME: New EH - Add the clauses in reverse order. This isn't 100% correct,
515 // but we need to do it this way because of how the DWARF EH emitter
516 // processes the clauses.
517 for (unsigned i = I.getNumClauses(); i != 0; --i) {
518 Value *Val = I.getClause(i - 1);
519 if (I.isCatch(i - 1)) {
520 MMI.addCatchTypeInfo(&MBB,
521 dyn_cast(Val->stripPointerCasts()));
522 } else {
523 // Add filters in a list.
524 Constant *CVal = cast(Val);
525 SmallVector FilterList;
526 for (User::op_iterator II = CVal->op_begin(), IE = CVal->op_end();
527 II != IE; ++II)
528 FilterList.push_back(cast((*II)->stripPointerCasts()));
529
530 MMI.addFilterTypeInfo(&MBB, FilterList);
531 }
532 }
533 }
260260 // FIXME: SEH catchpads do not create funclets, so we could avoid setting
261261 // this in such cases in order to improve frame layout.
262262 if (!isa(I)) {
263 MMI.setHasEHFunclets(true);
263 MF->setHasEHFunclets(true);
264264 MF->getFrameInfo().setHasOpaqueSPAdjustment(true);
265265 }
266266 if (isa(I)) {
22922292 "Call to landingpad not in landing pad!");
22932293
22942294 MachineBasicBlock *MBB = FuncInfo.MBB;
2295 MachineModuleInfo &MMI = DAG.getMachineFunction().getMMI();
2296 addLandingPadInfo(LP, MMI, *MBB);
2295 addLandingPadInfo(LP, *MBB);
22972296
22982297 // If there aren't registers to copy the values into (e.g., during SjLj
22992298 // exceptions), then don't bother to create these DAG nodes.
50265025 case Intrinsic::eh_typeid_for: {
50275026 // Find the type id for the given typeinfo.
50285027 GlobalValue *GV = ExtractTypeInfo(I.getArgOperand(0));
5029 unsigned TypeID = DAG.getMachineFunction().getMMI().getTypeIDFor(GV);
5028 unsigned TypeID = DAG.getMachineFunction().getTypeIDFor(GV);
50305029 Res = DAG.getConstant(TypeID, sdl, MVT::i32);
50315030 setValue(&I, Res);
50325031 return nullptr;
50345033
50355034 case Intrinsic::eh_return_i32:
50365035 case Intrinsic::eh_return_i64:
5037 DAG.getMachineFunction().getMMI().setCallsEHReturn(true);
5036 DAG.getMachineFunction().setCallsEHReturn(true);
50385037 DAG.setRoot(DAG.getNode(ISD::EH_RETURN, sdl,
50395038 MVT::Other,
50405039 getControlRoot(),
50425041 getValue(I.getArgOperand(1))));
50435042 return nullptr;
50445043 case Intrinsic::eh_unwind_init:
5045 DAG.getMachineFunction().getMMI().setCallsUnwindInit(true);
5044 DAG.getMachineFunction().setCallsUnwindInit(true);
50465045 return nullptr;
50475046 case Intrinsic::eh_dwarf_cfa: {
50485047 setValue(&I, DAG.getNode(ISD::EH_DWARF_CFA, sdl,
57405739 std::pair
57415740 SelectionDAGBuilder::lowerInvokable(TargetLowering::CallLoweringInfo &CLI,
57425741 const BasicBlock *EHPadBB) {
5743 MachineModuleInfo &MMI = DAG.getMachineFunction().getMMI();
5742 MachineFunction &MF = DAG.getMachineFunction();
5743 MachineModuleInfo &MMI = MF.getMMI();
57445744 MCSymbol *BeginLabel = nullptr;
57455745
57465746 if (EHPadBB) {
57525752 // so as to maintain the ordering of pads in the LSDA.
57535753 unsigned CallSiteIndex = MMI.getCurrentCallSite();
57545754 if (CallSiteIndex) {
5755 MMI.setCallSiteBeginLabel(BeginLabel, CallSiteIndex);
5755 MF.setCallSiteBeginLabel(BeginLabel, CallSiteIndex);
57565756 LPadToCallSiteMap[FuncInfo.MBBMap[EHPadBB]].push_back(CallSiteIndex);
57575757
57585758 // Now that the call site is handled, stop tracking it.
57935793 DAG.setRoot(DAG.getEHLabel(getCurSDLoc(), getRoot(), EndLabel));
57945794
57955795 // Inform MachineModuleInfo of range.
5796 if (MMI.hasEHFunclets()) {
5796 if (MF.hasEHFunclets()) {
57975797 assert(CLI.CS);
57985798 WinEHFuncInfo *EHInfo = DAG.getMachineFunction().getWinEHFuncInfo();
57995799 EHInfo->addIPToStateRange(cast(CLI.CS->getInstruction()),
58005800 BeginLabel, EndLabel);
58015801 } else {
5802 MMI.addInvoke(FuncInfo.MBBMap[EHPadBB], BeginLabel, EndLabel);
5802 MF.addInvoke(FuncInfo.MBBMap[EHPadBB], BeginLabel, EndLabel);
58035803 }
58045804 }
58055805
10131013
10141014 // Add a label to mark the beginning of the landing pad. Deletion of the
10151015 // landing pad can thus be detected via the MachineModuleInfo.
1016 MCSymbol *Label = MF->getMMI().addLandingPad(MBB);
1016 MCSymbol *Label = MF->addLandingPad(MBB);
10171017
10181018 // Assign the call site to the landing pad's begin label.
1019 MF->getMMI().setCallSiteLandingPad(Label, SDB->LPadToCallSiteMap[MBB]);
1019 MF->setCallSiteLandingPad(Label, SDB->LPadToCallSiteMap[MBB]);
10201020
10211021 const MCInstrDesc &II = TII->get(TargetOpcode::EH_LABEL);
10221022 BuildMI(*MBB, FuncInfo->InsertPt, SDB->getCurDebugLoc(), II)
8383 return;
8484
8585 // Functions which call __builtin_unwind_init get all their registers saved.
86 bool CallsUnwindInit = MF.getMMI().callsUnwindInit();
86 bool CallsUnwindInit = MF.callsUnwindInit();
8787 const MachineRegisterInfo &MRI = MF.getRegInfo();
8888 for (unsigned i = 0; CSRegs[i]; ++i) {
8989 unsigned Reg = CSRegs[i];
78667866 // associated with.
78677867 DenseMap > CallSiteNumToLPad;
78687868 unsigned MaxCSNum = 0;
7869 MachineModuleInfo &MMI = MF->getMMI();
78707869 for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E;
78717870 ++BB) {
78727871 if (!BB->isEHPad()) continue;
78787877 if (!II->isEHLabel()) continue;
78797878
78807879 MCSymbol *Sym = II->getOperand(0).getMCSymbol();
7881 if (!MMI.hasCallSiteLandingPad(Sym)) continue;
7882
7883 SmallVectorImpl &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym);
7880 if (!MF->hasCallSiteLandingPad(Sym)) continue;
7881
7882 SmallVectorImpl &CallSiteIdxs = MF->getCallSiteLandingPad(Sym);
78847883 for (SmallVectorImpl::iterator
78857884 CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end();
78867885 CSI != CSE; ++CSI) {
8181 SavedRegs.set(SystemZ::ArgGPRs[I]);
8282
8383 // If there are any landing pads, entering them will modify r6/r7.
84 if (!MF.getMMI().getLandingPads().empty()) {
84 if (!MF.getLandingPads().empty()) {
8585 SavedRegs.set(SystemZ::R6D);
8686 SavedRegs.set(SystemZ::R7D);
8787 }
128128 // in the compact unwind encoding that Darwin uses. So, bail if there
129129 // is a danger of that being generated.
130130 if (STI->isTargetDarwin() &&
131 (!MF.getMMI().getLandingPads().empty() ||
131 (!MF.getLandingPads().empty() ||
132132 (MF.getFunction()->needsUnwindTableEntry() && !TFL->hasFP(MF))))
133133 return false;
134134
8282 /// or if frame pointer elimination is disabled.
8383 bool X86FrameLowering::hasFP(const MachineFunction &MF) const {
8484 const MachineFrameInfo &MFI = MF.getFrameInfo();
85 const MachineModuleInfo &MMI = MF.getMMI();
86
8785 return (MF.getTarget().Options.DisableFramePointerElim(MF) ||
8886 TRI->needsStackRealignment(MF) ||
8987 MFI.hasVarSizedObjects() ||
9088 MFI.isFrameAddressTaken() || MFI.hasOpaqueSPAdjustment() ||
9189 MF.getInfo()->getForceFramePointer() ||
92 MMI.callsUnwindInit() || MMI.hasEHFunclets() || MMI.callsEHReturn() ||
90 MF.callsUnwindInit() || MF.hasEHFunclets() || MF.callsEHReturn() ||
9391 MFI.hasStackMap() || MFI.hasPatchPoint() ||
9492 MFI.hasCopyImplyingStackAdjustment());
9593 }
150148 bool Is64Bit) {
151149 const MachineFunction *MF = MBB.getParent();
152150 const Function *F = MF->getFunction();
153 if (!F || MF->getMMI().callsEHReturn())
151 if (!F || MF->callsEHReturn())
154152 return 0;
155153
156154 const TargetRegisterClass &AvailableRegs = *TRI->getGPRsForTailCall(*MF);
918916 if (Fn->hasPersonalityFn())
919917 Personality = classifyEHPersonality(Fn->getPersonalityFn());
920918 bool FnHasClrFunclet =
921 MMI.hasEHFunclets() && Personality == EHPersonality::CoreCLR;
919 MF.hasEHFunclets() && Personality == EHPersonality::CoreCLR;
922920 bool IsClrFunclet = IsFunclet && FnHasClrFunclet;
923921 bool HasFP = hasFP(MF);
924922 bool IsWin64CC = STI.isCallingConvWin64(Fn->getCallingConv());
20392037 SavedRegs.set(TRI->getBaseRegister());
20402038
20412039 // Allocate a spill slot for EBP if we have a base pointer and EH funclets.
2042 if (MF.getMMI().hasEHFunclets()) {
2040 if (MF.hasEHFunclets()) {
20432041 int FI = MFI.CreateSpillStackObject(SlotSize, SlotSize);
20442042 X86FI->setHasSEHFramePtrSave(true);
20452043 X86FI->setSEHFramePtrSaveIndex(FI);
26092607 // GNU_ARGS_SIZE.
26102608 // TODO: We don't need to reset this between subsequent functions,
26112609 // if it didn't change.
2612 bool HasDwarfEHHandlers = !WindowsCFI &&
2613 !MF.getMMI().getLandingPads().empty();
2610 bool HasDwarfEHHandlers = !WindowsCFI && !MF.getLandingPads().empty();
26142611
26152612 if (HasDwarfEHHandlers && !isDestroy &&
26162613 MF.getInfo()->getHasPushSequences())
29482945 // If this function isn't doing Win64-style C++ EH, we don't need to do
29492946 // anything.
29502947 const Function *Fn = MF.getFunction();
2951 if (!STI.is64Bit() || !MF.getMMI().hasEHFunclets() ||
2948 if (!STI.is64Bit() || !MF.hasEHFunclets() ||
29522949 classifyEHPersonality(Fn->getPersonalityFn()) != EHPersonality::MSVC_CXX)
29532950 return;
29542951
2497924979 MachineBasicBlock *BB) const {
2498024980 DebugLoc DL = MI.getDebugLoc();
2498124981 MachineFunction *MF = BB->getParent();
24982 MachineModuleInfo *MMI = &MF->getMMI();
2498324982 MachineFrameInfo &MFI = MF->getFrameInfo();
2498424983 MachineRegisterInfo *MRI = &MF->getRegInfo();
2498524984 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
2500325002 break;
2500425003 }
2500525004
25006 if (!MMI->hasCallSiteLandingPad(Sym))
25005 if (!MF->hasCallSiteLandingPad(Sym))
2500725006 continue;
2500825007
25009 for (unsigned CSI : MMI->getCallSiteLandingPad(Sym)) {
25008 for (unsigned CSI : MF->getCallSiteLandingPad(Sym)) {
2501025009 CallSiteNumToLPad[CSI].push_back(&MBB);
2501125010 MaxCSNum = std::max(MaxCSNum, CSI);
2501225011 }
269269 bool HasSSE = Subtarget.hasSSE1();
270270 bool HasAVX = Subtarget.hasAVX();
271271 bool HasAVX512 = Subtarget.hasAVX512();
272 bool CallsEHReturn = MF->getMMI().callsEHReturn();
272 bool CallsEHReturn = MF->callsEHReturn();
273273
274274 switch (MF->getFunction()->getCallingConv()) {
275275 case CallingConv::GHC:
547547 // We force the LR to be saved so these instructions are used.
548548 LRUsed = true;
549549
550 if (MF.getMMI().callsUnwindInit() || MF.getMMI().callsEHReturn()) {
550 if (MF.callsUnwindInit() || MF.callsEHReturn()) {
551551 // The unwinder expects to find spill slots for the exception info regs R0
552552 // & R1. These are used during llvm.eh.return() to 'restore' the exception
553553 // info. N.B. we do not spill or restore R0, R1 during normal operation.