llvm.org GIT mirror llvm / e7b3959
Temporarily Revert "Move most EH from MachineModuleInfo to MachineFunction" This apprears to have broken the global isel bot: http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-globalisel_build/5174/console This reverts commit r288293. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288322 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 4 years ago
21 changed file(s) with 428 addition(s) and 431 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"
2423 #include "llvm/CodeGen/MachineBasicBlock.h"
2524 #include "llvm/CodeGen/MachineMemOperand.h"
2625 #include "llvm/IR/DebugLoc.h"
2726 #include "llvm/IR/Metadata.h"
2827 #include "llvm/MC/MCDwarf.h"
29 #include "llvm/MC/MCSymbol.h"
3028 #include "llvm/Support/Allocator.h"
3129 #include "llvm/Support/ArrayRecycler.h"
3230 #include "llvm/Support/Compiler.h"
171169 BitVector(static_cast(Property::LastProperty)+1);
172170 };
173171
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
196172 class MachineFunction {
197173 const Function *Fn;
198174 const TargetMachine &Target;
272248 /// List of moves done by a function's prolog. Used to construct frame maps
273249 /// by debug and exception handling consumers.
274250 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 /// \}
304251
305252 MachineFunction(const MachineFunction &) = delete;
306253 void operator=(const MachineFunction&) = delete;
724671 return FrameInstructions.size() - 1;
725672 }
726673
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
826674 /// Collect information used to emit debugging information of a variable.
827675 void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
828676 unsigned Slot, const DILocation *Loc) {
834682 return VariableDbgInfos;
835683 }
836684 };
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 /// \}
846685
847686 //===--------------------------------------------------------------------===//
848687 // 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"
3738 #include "llvm/IR/DebugLoc.h"
3839 #include "llvm/IR/ValueHandle.h"
3940 #include "llvm/MC/MCContext.h"
6061 class PointerType;
6162 class StructType;
6263
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
6387 //===----------------------------------------------------------------------===//
6488 /// This class can be derived from and used by targets to hold private
6589 /// target-specific information for each Module. Objects of type are
97121 /// want.
98122 MachineModuleInfoImpl *ObjFileMMI;
99123
100 /// \name Exception Handling
101 /// \{
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;
102146
103147 /// Vector of all personality functions ever seen. Used to emit common EH
104148 /// frames.
105149 std::vector Personalities;
106150
107 /// The current call site index being processed, if any. 0 if none.
108 unsigned CurCallSite;
109
110 /// \}
111
112151 /// This map keeps track of which symbol is being used for the specified
113152 /// basic block's address of label.
114153 MMIAddrLabelMap *AddrLabelSymbols;
154
155 bool CallsEHReturn;
156 bool CallsUnwindInit;
157 bool HasEHFunclets;
115158
116159 // TODO: Ideally, what we'd like is to have a switch that allows emitting
117160 // synchronous (precise at call-sites only) CFA into .eh_frame. However,
132175 /// a definition of a symbol, __morestack_addr, containing the address. See
133176 /// comments in lib/Target/X86/X86FrameLowering.cpp for more details.
134177 bool UsesMorestackAddr;
178
179 EHPersonality PersonalityTypeCache;
135180
136181 MachineFunctionInitializer *MFInitializer;
137182 /// Maps IR Functions to their corresponding MachineFunctions.
151196 bool doInitialization(Module &) override;
152197 bool doFinalization(Module &) override;
153198
199 /// Discard function meta information.
200 void EndFunction();
201
154202 const MCContext &getContext() const { return Context; }
155203 MCContext &getContext() { return Context; }
156204
188236 bool hasDebugInfo() const { return DbgInfoAvailable; }
189237 void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = avail; }
190238
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
191248 bool usesVAFloatArgument() const {
192249 return UsesVAFloatArgument;
193250 }
223280 void takeDeletedSymbolsForFunction(const Function *F,
224281 std::vector &Result);
225282
226 /// \name Exception Handling
227 /// \{
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);
296
297 /// Provide the personality function for the exception information.
298 void addPersonality(const Function *Personality);
299
300 /// Return array of personality functions ever seen.
301 const std::vector& getPersonalities() const {
302 return Personalities;
303 }
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 }
228367
229368 /// Set the call site currently being processed.
230369 void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }
233372 /// none.
234373 unsigned getCurrentCallSite() { return CurCallSite; }
235374
236 /// Provide the personality function for the exception information.
237 void addPersonality(const Function *Personality);
238
239 /// Return array of personality functions ever seen.
240 const std::vector& getPersonalities() const {
241 return Personalities;
242 }
243 /// \}
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 }
244385 }; // End class MachineModuleInfo
245386
246387 //===- MMI building helpers -----------------------------------------------===//
251392 /// which will link in MSVCRT's floating-point support.
252393 void computeUsesVAFloatArgument(const CallInst &I, MachineModuleInfo &MMI);
253394
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
254401 } // End llvm namespace
255402
256403 #endif
683683 DenseMap FuncletMembership;
684684
685685 // We don't have anything to do if there aren't any EH pads.
686 if (!MF.hasEHFunclets())
686 if (!MF.getMMI().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 !MF->getLandingPads().empty();
77 !MMI->getLandingPads().empty();
7878 if (!Asm->MF->getFunction()->needsUnwindTableEntry() &&
7979 !shouldEmitPersonality)
8080 ATS.emitCantUnwind();
9898 }
9999
100100 void ARMException::emitTypeInfos(unsigned TTypeEncoding) {
101 const MachineFunction *MF = Asm->MF;
102 const std::vector &TypeInfos = MF->getTypeInfos();
103 const std::vector<unsigned> &FilterIds = MF->getFilterIds();
101 const std::vector<const GlobalValue *> &TypeInfos = MMI->getTypeInfos();
102 const std::vector &FilterIds = MMI->getFilterIds();
104103
105104 bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
106105
946946 // Emit target-specific gunk after the function body.
947947 EmitFunctionBodyEnd();
948948
949 if (!MF->getLandingPads().empty() || MMI->hasDebugInfo() ||
950 MF->hasEHFunclets() || MAI->hasDotTypeDotSizeDirective()) {
949 if (!MMI->getLandingPads().empty() || MMI->hasDebugInfo() ||
950 MMI->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();
983984
984985 OutStreamer->AddBlankLine();
985986 }
12711272 CurrentFnBegin = nullptr;
12721273 CurExceptionSym = nullptr;
12731274 bool NeedsLocalForSize = MAI->needsLocalForSize();
1274 if (!MF.getLandingPads().empty() || MMI->hasDebugInfo() ||
1275 MF.hasEHFunclets() || NeedsLocalForSize) {
1275 if (!MMI->getLandingPads().empty() || MMI->hasDebugInfo() ||
1276 MMI->hasEHFunclets() || NeedsLocalForSize) {
12761277 CurrentFnBegin = createTempSymbol("func_begin");
12771278 if (NeedsLocalForSize)
12781279 CurrentFnSymForSize = CurrentFnBegin;
4343 void DwarfCFIExceptionBase::markFunctionEnd() {
4444 endFragment();
4545
46 if (MMI->getLandingPads().empty())
47 return;
48
4649 // Map all labels and get rid of any dead landing pads.
47 if (!Asm->MF->getLandingPads().empty()) {
48 MachineFunction *NonConstMF = const_cast(Asm->MF);
49 NonConstMF->tidyLandingPads();
50 }
50 MMI->TidyLandingPads();
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 = !MF->getLandingPads().empty();
100 bool hasLandingPads = !MMI->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 *MF) {
172 void DwarfCFIException::endFunction(const MachineFunction *) {
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 = Asm->MF->getFilterIds();
76 const std::vector &FilterIds = MMI->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 = Asm->MF->getCallSiteBeginLabel(BeginLabel);
298 unsigned SiteNo = MMI->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 MachineFunction *MF = Asm->MF;
339 const std::vector &TypeInfos = MF->getTypeInfos();
340 const std::vector &FilterIds = MF->getFilterIds();
341 const std::vector<LandingPadInfo> &PadInfos = MF->getLandingPads();
338 const std::vector<const GlobalValue *> &TypeInfos = MMI->getTypeInfos();
339 const std::vector &FilterIds = MMI->getFilterIds();
340 const std::vector &PadInfos = MMI->getLandingPads();
342341
343342 // Sort the landing pads in order of their type ids. This is used to fold
344343 // duplicate actions.
649648 }
650649
651650 void EHStreamer::emitTypeInfos(unsigned TTypeEncoding) {
652 const MachineFunction *MF = Asm->MF;
653 const std::vector &TypeInfos = MF->getTypeInfos();
654 const std::vector<unsigned> &FilterIds = MF->getFilterIds();
651 const std::vector<const GlobalValue *> &TypeInfos = MMI->getTypeInfos();
652 const std::vector &FilterIds = MMI->getFilterIds();
655653
656654 bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
657655
6262 shouldEmitMoves = shouldEmitPersonality = shouldEmitLSDA = false;
6363
6464 // If any landing pads survive, we need an EH table.
65 bool hasLandingPads = !MF->getLandingPads().empty();
66 bool hasEHFunclets = MF->hasEHFunclets();
65 bool hasLandingPads = !MMI->getLandingPads().empty();
66 bool hasEHFunclets = MMI->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 MachineFunction *NonConstMF = const_cast(MF);
130 NonConstMF->tidyLandingPads();
131 }
128 if (!isFuncletEHPersonality(Per))
129 MMI->TidyLandingPads();
132130
133131 endFunclet();
134132
135133 // endFunclet will emit the necessary .xdata tables for x64 SEH.
136 if (Per == EHPersonality::MSVC_Win64SEH && MF->hasEHFunclets())
134 if (Per == EHPersonality::MSVC_Win64SEH && MMI->hasEHFunclets())
137135 return;
138136
139137 if (shouldEmitPersonality || shouldEmitLSDA) {
235233 if (!CurrentFuncletEntry)
236234 return;
237235
238 const MachineFunction *MF = Asm->MF;
239236 if (shouldEmitMoves || shouldEmitPersonality) {
240 const Function *F = MF->getFunction();
237 const Function *F = Asm->MF->getFunction();
241238 EHPersonality Per = EHPersonality::Unknown;
242239 if (F->hasPersonalityFn())
243240 Per = classifyEHPersonality(F->getPersonalityFn()->stripPointerCasts());
257254 MCSymbol *FuncInfoXData = Asm->OutContext.getOrCreateSymbol(
258255 Twine("$cppxdata$", FuncLinkageName));
259256 Asm->OutStreamer->EmitValue(create32bitRef(FuncInfoXData), 4);
260 } else if (Per == EHPersonality::MSVC_Win64SEH && MF->hasEHFunclets() &&
257 } else if (Per == EHPersonality::MSVC_Win64SEH && MMI->hasEHFunclets() &&
261258 !CurrentFuncletEntry->isEHFuncletEntry()) {
262259 // If this is the parent function in Win64 SEH, emit the LSDA immediately
263260 // following .seh_handlerdata.
264 emitCSpecificHandlerTable(MF);
261 emitCSpecificHandlerTable(Asm->MF);
265262 }
266263
267264 // 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
757570 //===----------------------------------------------------------------------===//
758571 // MachineFrameInfo implementation
759572 //===----------------------------------------------------------------------===//
202202
203203 ObjFileMMI = nullptr;
204204 CurCallSite = 0;
205 CallsEHReturn = false;
206 CallsUnwindInit = false;
207 HasEHFunclets = false;
205208 DbgInfoAvailable = UsesVAFloatArgument = UsesMorestackAddr = false;
209 PersonalityTypeCache = EHPersonality::Unknown;
206210 AddrLabelSymbols = nullptr;
207211 TheModule = &M;
208212
222226 ObjFileMMI = nullptr;
223227
224228 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;
225242 }
226243
227244 //===- Address of Block Management ----------------------------------------===//
243260 takeDeletedSymbolsForFunction(const_cast(F), Result);
244261 }
245262
246 /// \name Exception Handling
247 /// \{
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 }
248291
249292 void MachineModuleInfo::addPersonality(const Function *Personality) {
250293 for (unsigned i = 0; i < Personalities.size(); ++i)
253296 Personalities.push_back(Personality);
254297 }
255298
256 /// \}
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 }
257425
258426 MachineFunction &MachineModuleInfo::getMachineFunction(const Function &F) {
259427 // Shortcut for the common case where a sequence of MachineFunctionPasses
333501 }
334502 }
335503 }
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 MF->setHasEHFunclets(true);
263 MMI.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 addLandingPadInfo(LP, *MBB);
2295 MachineModuleInfo &MMI = DAG.getMachineFunction().getMMI();
2296 addLandingPadInfo(LP, MMI, *MBB);
22962297
22972298 // If there aren't registers to copy the values into (e.g., during SjLj
22982299 // exceptions), then don't bother to create these DAG nodes.
50255026 case Intrinsic::eh_typeid_for: {
50265027 // Find the type id for the given typeinfo.
50275028 GlobalValue *GV = ExtractTypeInfo(I.getArgOperand(0));
5028 unsigned TypeID = DAG.getMachineFunction().getTypeIDFor(GV);
5029 unsigned TypeID = DAG.getMachineFunction().getMMI().getTypeIDFor(GV);
50295030 Res = DAG.getConstant(TypeID, sdl, MVT::i32);
50305031 setValue(&I, Res);
50315032 return nullptr;
50335034
50345035 case Intrinsic::eh_return_i32:
50355036 case Intrinsic::eh_return_i64:
5036 DAG.getMachineFunction().setCallsEHReturn(true);
5037 DAG.getMachineFunction().getMMI().setCallsEHReturn(true);
50375038 DAG.setRoot(DAG.getNode(ISD::EH_RETURN, sdl,
50385039 MVT::Other,
50395040 getControlRoot(),
50415042 getValue(I.getArgOperand(1))));
50425043 return nullptr;
50435044 case Intrinsic::eh_unwind_init:
5044 DAG.getMachineFunction().setCallsUnwindInit(true);
5045 DAG.getMachineFunction().getMMI().setCallsUnwindInit(true);
50455046 return nullptr;
50465047 case Intrinsic::eh_dwarf_cfa: {
50475048 setValue(&I, DAG.getNode(ISD::EH_DWARF_CFA, sdl,
57395740 std::pair
57405741 SelectionDAGBuilder::lowerInvokable(TargetLowering::CallLoweringInfo &CLI,
57415742 const BasicBlock *EHPadBB) {
5742 MachineFunction &MF = DAG.getMachineFunction();
5743 MachineModuleInfo &MMI = MF.getMMI();
5743 MachineModuleInfo &MMI = DAG.getMachineFunction().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 MF.setCallSiteBeginLabel(BeginLabel, CallSiteIndex);
5755 MMI.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 (MF.hasEHFunclets()) {
5796 if (MMI.hasEHFunclets()) {
57975797 assert(CLI.CS);
57985798 WinEHFuncInfo *EHInfo = DAG.getMachineFunction().getWinEHFuncInfo();
57995799 EHInfo->addIPToStateRange(cast(CLI.CS->getInstruction()),
58005800 BeginLabel, EndLabel);
58015801 } else {
5802 MF.addInvoke(FuncInfo.MBBMap[EHPadBB], BeginLabel, EndLabel);
5802 MMI.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->addLandingPad(MBB);
1016 MCSymbol *Label = MF->getMMI().addLandingPad(MBB);
10171017
10181018 // Assign the call site to the landing pad's begin label.
1019 MF->setCallSiteLandingPad(Label, SDB->LPadToCallSiteMap[MBB]);
1019 MF->getMMI().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.callsUnwindInit();
86 bool CallsUnwindInit = MF.getMMI().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();
78697870 for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E;
78707871 ++BB) {
78717872 if (!BB->isEHPad()) continue;
78777878 if (!II->isEHLabel()) continue;
78787879
78797880 MCSymbol *Sym = II->getOperand(0).getMCSymbol();
7880 if (!MF->hasCallSiteLandingPad(Sym)) continue;
7881
7882 SmallVectorImpl &CallSiteIdxs = MF->getCallSiteLandingPad(Sym);
7881 if (!MMI.hasCallSiteLandingPad(Sym)) continue;
7882
7883 SmallVectorImpl &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym);
78837884 for (SmallVectorImpl::iterator
78847885 CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end();
78857886 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.getLandingPads().empty()) {
84 if (!MF.getMMI().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.getLandingPads().empty() ||
131 (!MF.getMMI().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
8587 return (MF.getTarget().Options.DisableFramePointerElim(MF) ||
8688 TRI->needsStackRealignment(MF) ||
8789 MFI.hasVarSizedObjects() ||
8890 MFI.isFrameAddressTaken() || MFI.hasOpaqueSPAdjustment() ||
8991 MF.getInfo()->getForceFramePointer() ||
90 MF.callsUnwindInit() || MF.hasEHFunclets() || MF.callsEHReturn() ||
92 MMI.callsUnwindInit() || MMI.hasEHFunclets() || MMI.callsEHReturn() ||
9193 MFI.hasStackMap() || MFI.hasPatchPoint() ||
9294 MFI.hasCopyImplyingStackAdjustment());
9395 }
148150 bool Is64Bit) {
149151 const MachineFunction *MF = MBB.getParent();
150152 const Function *F = MF->getFunction();
151 if (!F || MF->callsEHReturn())
153 if (!F || MF->getMMI().callsEHReturn())
152154 return 0;
153155
154156 const TargetRegisterClass &AvailableRegs = *TRI->getGPRsForTailCall(*MF);
916918 if (Fn->hasPersonalityFn())
917919 Personality = classifyEHPersonality(Fn->getPersonalityFn());
918920 bool FnHasClrFunclet =
919 MF.hasEHFunclets() && Personality == EHPersonality::CoreCLR;
921 MMI.hasEHFunclets() && Personality == EHPersonality::CoreCLR;
920922 bool IsClrFunclet = IsFunclet && FnHasClrFunclet;
921923 bool HasFP = hasFP(MF);
922924 bool IsWin64CC = STI.isCallingConvWin64(Fn->getCallingConv());
20372039 SavedRegs.set(TRI->getBaseRegister());
20382040
20392041 // Allocate a spill slot for EBP if we have a base pointer and EH funclets.
2040 if (MF.hasEHFunclets()) {
2042 if (MF.getMMI().hasEHFunclets()) {
20412043 int FI = MFI.CreateSpillStackObject(SlotSize, SlotSize);
20422044 X86FI->setHasSEHFramePtrSave(true);
20432045 X86FI->setSEHFramePtrSaveIndex(FI);
26072609 // GNU_ARGS_SIZE.
26082610 // TODO: We don't need to reset this between subsequent functions,
26092611 // if it didn't change.
2610 bool HasDwarfEHHandlers = !WindowsCFI && !MF.getLandingPads().empty();
2612 bool HasDwarfEHHandlers = !WindowsCFI &&
2613 !MF.getMMI().getLandingPads().empty();
26112614
26122615 if (HasDwarfEHHandlers && !isDestroy &&
26132616 MF.getInfo()->getHasPushSequences())
29452948 // If this function isn't doing Win64-style C++ EH, we don't need to do
29462949 // anything.
29472950 const Function *Fn = MF.getFunction();
2948 if (!STI.is64Bit() || !MF.hasEHFunclets() ||
2951 if (!STI.is64Bit() || !MF.getMMI().hasEHFunclets() ||
29492952 classifyEHPersonality(Fn->getPersonalityFn()) != EHPersonality::MSVC_CXX)
29502953 return;
29512954
2497924979 MachineBasicBlock *BB) const {
2498024980 DebugLoc DL = MI.getDebugLoc();
2498124981 MachineFunction *MF = BB->getParent();
24982 MachineModuleInfo *MMI = &MF->getMMI();
2498224983 MachineFrameInfo &MFI = MF->getFrameInfo();
2498324984 MachineRegisterInfo *MRI = &MF->getRegInfo();
2498424985 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
2500225003 break;
2500325004 }
2500425005
25005 if (!MF->hasCallSiteLandingPad(Sym))
25006 if (!MMI->hasCallSiteLandingPad(Sym))
2500625007 continue;
2500725008
25008 for (unsigned CSI : MF->getCallSiteLandingPad(Sym)) {
25009 for (unsigned CSI : MMI->getCallSiteLandingPad(Sym)) {
2500925010 CallSiteNumToLPad[CSI].push_back(&MBB);
2501025011 MaxCSNum = std::max(MaxCSNum, CSI);
2501125012 }
269269 bool HasSSE = Subtarget.hasSSE1();
270270 bool HasAVX = Subtarget.hasAVX();
271271 bool HasAVX512 = Subtarget.hasAVX512();
272 bool CallsEHReturn = MF->callsEHReturn();
272 bool CallsEHReturn = MF->getMMI().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.callsUnwindInit() || MF.callsEHReturn()) {
550 if (MF.getMMI().callsUnwindInit() || MF.getMMI().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.