1 //===- llvm/CodeGen/MachineFunction.h ---------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Collect native machine code for a function.  This class contains a list of
10 // MachineBasicBlock instances that make up the current compiled function.
11 //
12 // This class also contains pointers to various classes which hold
13 // target-specific information about the generated code.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
18 #define LLVM_CODEGEN_MACHINEFUNCTION_H
19 
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/BitVector.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/GraphTraits.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/ilist.h"
26 #include "llvm/ADT/iterator.h"
27 #include "llvm/Analysis/EHPersonalities.h"
28 #include "llvm/CodeGen/MachineBasicBlock.h"
29 #include "llvm/CodeGen/MachineInstr.h"
30 #include "llvm/CodeGen/MachineMemOperand.h"
31 #include "llvm/Support/Allocator.h"
32 #include "llvm/Support/ArrayRecycler.h"
33 #include "llvm/Support/AtomicOrdering.h"
34 #include "llvm/Support/Compiler.h"
35 #include "llvm/Support/Recycler.h"
36 #include "llvm/Target/TargetOptions.h"
37 #include <cassert>
38 #include <cstdint>
39 #include <memory>
40 #include <utility>
41 #include <vector>
42 
43 namespace llvm {
44 
45 class BasicBlock;
46 class BlockAddress;
47 class DataLayout;
48 class DebugLoc;
49 struct DenormalMode;
50 class DIExpression;
51 class DILocalVariable;
52 class DILocation;
53 class Function;
54 class GISelChangeObserver;
55 class GlobalValue;
56 class LLVMTargetMachine;
57 class MachineConstantPool;
58 class MachineFrameInfo;
59 class MachineFunction;
60 class MachineJumpTableInfo;
61 class MachineModuleInfo;
62 class MachineRegisterInfo;
63 class MCContext;
64 class MCInstrDesc;
65 class MCSymbol;
66 class MCSection;
67 class Pass;
68 class PseudoSourceValueManager;
69 class raw_ostream;
70 class SlotIndexes;
71 class StringRef;
72 class TargetRegisterClass;
73 class TargetSubtargetInfo;
74 struct WasmEHFuncInfo;
75 struct WinEHFuncInfo;
76 
77 template <> struct ilist_alloc_traits<MachineBasicBlock> {
78   void deleteNode(MachineBasicBlock *MBB);
79 };
80 
81 template <> struct ilist_callback_traits<MachineBasicBlock> {
82   void addNodeToList(MachineBasicBlock* N);
83   void removeNodeFromList(MachineBasicBlock* N);
84 
85   template <class Iterator>
86   void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator) {
87     assert(this == &OldList && "never transfer MBBs between functions");
88   }
89 };
90 
91 /// MachineFunctionInfo - This class can be derived from and used by targets to
92 /// hold private target-specific information for each MachineFunction.  Objects
93 /// of type are accessed/created with MF::getInfo and destroyed when the
94 /// MachineFunction is destroyed.
95 struct MachineFunctionInfo {
96   virtual ~MachineFunctionInfo();
97 
98   /// Factory function: default behavior is to call new using the
99   /// supplied allocator.
100   ///
101   /// This function can be overridden in a derive class.
102   template<typename Ty>
103   static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
104     return new (Allocator.Allocate<Ty>()) Ty(MF);
105   }
106 };
107 
108 /// Properties which a MachineFunction may have at a given point in time.
109 /// Each of these has checking code in the MachineVerifier, and passes can
110 /// require that a property be set.
111 class MachineFunctionProperties {
112   // Possible TODO: Allow targets to extend this (perhaps by allowing the
113   // constructor to specify the size of the bit vector)
114   // Possible TODO: Allow requiring the negative (e.g. VRegsAllocated could be
115   // stated as the negative of "has vregs"
116 
117 public:
118   // The properties are stated in "positive" form; i.e. a pass could require
119   // that the property hold, but not that it does not hold.
120 
121   // Property descriptions:
122   // IsSSA: True when the machine function is in SSA form and virtual registers
123   //  have a single def.
124   // NoPHIs: The machine function does not contain any PHI instruction.
125   // TracksLiveness: True when tracking register liveness accurately.
126   //  While this property is set, register liveness information in basic block
127   //  live-in lists and machine instruction operands (e.g. kill flags, implicit
128   //  defs) is accurate. This means it can be used to change the code in ways
129   //  that affect the values in registers, for example by the register
130   //  scavenger.
131   //  When this property is clear, liveness is no longer reliable.
132   // NoVRegs: The machine function does not use any virtual registers.
133   // Legalized: In GlobalISel: the MachineLegalizer ran and all pre-isel generic
134   //  instructions have been legalized; i.e., all instructions are now one of:
135   //   - generic and always legal (e.g., COPY)
136   //   - target-specific
137   //   - legal pre-isel generic instructions.
138   // RegBankSelected: In GlobalISel: the RegBankSelect pass ran and all generic
139   //  virtual registers have been assigned to a register bank.
140   // Selected: In GlobalISel: the InstructionSelect pass ran and all pre-isel
141   //  generic instructions have been eliminated; i.e., all instructions are now
142   //  target-specific or non-pre-isel generic instructions (e.g., COPY).
143   //  Since only pre-isel generic instructions can have generic virtual register
144   //  operands, this also means that all generic virtual registers have been
145   //  constrained to virtual registers (assigned to register classes) and that
146   //  all sizes attached to them have been eliminated.
147   // TiedOpsRewritten: The twoaddressinstruction pass will set this flag, it
148   //  means that tied-def have been rewritten to meet the RegConstraint.
149   enum class Property : unsigned {
150     IsSSA,
151     NoPHIs,
152     TracksLiveness,
153     NoVRegs,
154     FailedISel,
155     Legalized,
156     RegBankSelected,
157     Selected,
158     TiedOpsRewritten,
159     LastProperty = TiedOpsRewritten,
160   };
161 
162   bool hasProperty(Property P) const {
163     return Properties[static_cast<unsigned>(P)];
164   }
165 
166   MachineFunctionProperties &set(Property P) {
167     Properties.set(static_cast<unsigned>(P));
168     return *this;
169   }
170 
171   MachineFunctionProperties &reset(Property P) {
172     Properties.reset(static_cast<unsigned>(P));
173     return *this;
174   }
175 
176   /// Reset all the properties.
177   MachineFunctionProperties &reset() {
178     Properties.reset();
179     return *this;
180   }
181 
182   MachineFunctionProperties &set(const MachineFunctionProperties &MFP) {
183     Properties |= MFP.Properties;
184     return *this;
185   }
186 
187   MachineFunctionProperties &reset(const MachineFunctionProperties &MFP) {
188     Properties.reset(MFP.Properties);
189     return *this;
190   }
191 
192   // Returns true if all properties set in V (i.e. required by a pass) are set
193   // in this.
194   bool verifyRequiredProperties(const MachineFunctionProperties &V) const {
195     return !V.Properties.test(Properties);
196   }
197 
198   /// Print the MachineFunctionProperties in human-readable form.
199   void print(raw_ostream &OS) const;
200 
201 private:
202   BitVector Properties =
203       BitVector(static_cast<unsigned>(Property::LastProperty)+1);
204 };
205 
206 struct SEHHandler {
207   /// Filter or finally function. Null indicates a catch-all.
208   const Function *FilterOrFinally;
209 
210   /// Address of block to recover at. Null for a finally handler.
211   const BlockAddress *RecoverBA;
212 };
213 
214 /// This structure is used to retain landing pad info for the current function.
215 struct LandingPadInfo {
216   MachineBasicBlock *LandingPadBlock;      // Landing pad block.
217   SmallVector<MCSymbol *, 1> BeginLabels;  // Labels prior to invoke.
218   SmallVector<MCSymbol *, 1> EndLabels;    // Labels after invoke.
219   SmallVector<SEHHandler, 1> SEHHandlers;  // SEH handlers active at this lpad.
220   MCSymbol *LandingPadLabel = nullptr;     // Label at beginning of landing pad.
221   std::vector<int> TypeIds;                // List of type ids (filters negative).
222 
223   explicit LandingPadInfo(MachineBasicBlock *MBB)
224       : LandingPadBlock(MBB) {}
225 };
226 
227 class MachineFunction {
228   Function &F;
229   const LLVMTargetMachine &Target;
230   const TargetSubtargetInfo *STI;
231   MCContext &Ctx;
232   MachineModuleInfo &MMI;
233 
234   // RegInfo - Information about each register in use in the function.
235   MachineRegisterInfo *RegInfo;
236 
237   // Used to keep track of target-specific per-machine function information for
238   // the target implementation.
239   MachineFunctionInfo *MFInfo;
240 
241   // Keep track of objects allocated on the stack.
242   MachineFrameInfo *FrameInfo;
243 
244   // Keep track of constants which are spilled to memory
245   MachineConstantPool *ConstantPool;
246 
247   // Keep track of jump tables for switch instructions
248   MachineJumpTableInfo *JumpTableInfo;
249 
250   // Keep track of the function section.
251   MCSection *Section = nullptr;
252 
253   // Keeps track of Wasm exception handling related data. This will be null for
254   // functions that aren't using a wasm EH personality.
255   WasmEHFuncInfo *WasmEHInfo = nullptr;
256 
257   // Keeps track of Windows exception handling related data. This will be null
258   // for functions that aren't using a funclet-based EH personality.
259   WinEHFuncInfo *WinEHInfo = nullptr;
260 
261   // Function-level unique numbering for MachineBasicBlocks.  When a
262   // MachineBasicBlock is inserted into a MachineFunction is it automatically
263   // numbered and this vector keeps track of the mapping from ID's to MBB's.
264   std::vector<MachineBasicBlock*> MBBNumbering;
265 
266   // Unary encoding of basic block symbols is used to reduce size of ".strtab".
267   // Basic block number 'i' gets a prefix of length 'i'.  The ith character also
268   // denotes the type of basic block number 'i'.  Return blocks are marked with
269   // 'r', landing pads with 'l' and regular blocks with 'a'.
270   std::vector<char> BBSectionsSymbolPrefix;
271 
272   // Pool-allocate MachineFunction-lifetime and IR objects.
273   BumpPtrAllocator Allocator;
274 
275   // Allocation management for instructions in function.
276   Recycler<MachineInstr> InstructionRecycler;
277 
278   // Allocation management for operand arrays on instructions.
279   ArrayRecycler<MachineOperand> OperandRecycler;
280 
281   // Allocation management for basic blocks in function.
282   Recycler<MachineBasicBlock> BasicBlockRecycler;
283 
284   // List of machine basic blocks in function
285   using BasicBlockListType = ilist<MachineBasicBlock>;
286   BasicBlockListType BasicBlocks;
287 
288   /// FunctionNumber - This provides a unique ID for each function emitted in
289   /// this translation unit.
290   ///
291   unsigned FunctionNumber;
292 
293   /// Alignment - The alignment of the function.
294   Align Alignment;
295 
296   /// ExposesReturnsTwice - True if the function calls setjmp or related
297   /// functions with attribute "returns twice", but doesn't have
298   /// the attribute itself.
299   /// This is used to limit optimizations which cannot reason
300   /// about the control flow of such functions.
301   bool ExposesReturnsTwice = false;
302 
303   /// True if the function includes any inline assembly.
304   bool HasInlineAsm = false;
305 
306   /// True if any WinCFI instruction have been emitted in this function.
307   bool HasWinCFI = false;
308 
309   /// Current high-level properties of the IR of the function (e.g. is in SSA
310   /// form or whether registers have been allocated)
311   MachineFunctionProperties Properties;
312 
313   // Allocation management for pseudo source values.
314   std::unique_ptr<PseudoSourceValueManager> PSVManager;
315 
316   /// List of moves done by a function's prolog.  Used to construct frame maps
317   /// by debug and exception handling consumers.
318   std::vector<MCCFIInstruction> FrameInstructions;
319 
320   /// List of basic blocks immediately following calls to _setjmp. Used to
321   /// construct a table of valid longjmp targets for Windows Control Flow Guard.
322   std::vector<MCSymbol *> LongjmpTargets;
323 
324   /// \name Exception Handling
325   /// \{
326 
327   /// List of LandingPadInfo describing the landing pad information.
328   std::vector<LandingPadInfo> LandingPads;
329 
330   /// Map a landing pad's EH symbol to the call site indexes.
331   DenseMap<MCSymbol*, SmallVector<unsigned, 4>> LPadToCallSiteMap;
332 
333   /// Map a landing pad to its index.
334   DenseMap<const MachineBasicBlock *, unsigned> WasmLPadToIndexMap;
335 
336   /// Map of invoke call site index values to associated begin EH_LABEL.
337   DenseMap<MCSymbol*, unsigned> CallSiteMap;
338 
339   /// CodeView label annotations.
340   std::vector<std::pair<MCSymbol *, MDNode *>> CodeViewAnnotations;
341 
342   bool CallsEHReturn = false;
343   bool CallsUnwindInit = false;
344   bool HasEHScopes = false;
345   bool HasEHFunclets = false;
346 
347   /// Section Type for basic blocks, only relevant with basic block sections.
348   BasicBlockSection BBSectionsType = BasicBlockSection::None;
349 
350   /// List of C++ TypeInfo used.
351   std::vector<const GlobalValue *> TypeInfos;
352 
353   /// List of typeids encoding filters used.
354   std::vector<unsigned> FilterIds;
355 
356   /// List of the indices in FilterIds corresponding to filter terminators.
357   std::vector<unsigned> FilterEnds;
358 
359   EHPersonality PersonalityTypeCache = EHPersonality::Unknown;
360 
361   /// \}
362 
363   /// Clear all the members of this MachineFunction, but the ones used
364   /// to initialize again the MachineFunction.
365   /// More specifically, this deallocates all the dynamically allocated
366   /// objects and get rid of all the XXXInfo data structure, but keep
367   /// unchanged the references to Fn, Target, MMI, and FunctionNumber.
368   void clear();
369   /// Allocate and initialize the different members.
370   /// In particular, the XXXInfo data structure.
371   /// \pre Fn, Target, MMI, and FunctionNumber are properly set.
372   void init();
373 
374 public:
375   struct VariableDbgInfo {
376     const DILocalVariable *Var;
377     const DIExpression *Expr;
378     // The Slot can be negative for fixed stack objects.
379     int Slot;
380     const DILocation *Loc;
381 
382     VariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
383                     int Slot, const DILocation *Loc)
384         : Var(Var), Expr(Expr), Slot(Slot), Loc(Loc) {}
385   };
386 
387   class Delegate {
388     virtual void anchor();
389 
390   public:
391     virtual ~Delegate() = default;
392     /// Callback after an insertion. This should not modify the MI directly.
393     virtual void MF_HandleInsertion(MachineInstr &MI) = 0;
394     /// Callback before a removal. This should not modify the MI directly.
395     virtual void MF_HandleRemoval(MachineInstr &MI) = 0;
396   };
397 
398   /// Structure used to represent pair of argument number after call lowering
399   /// and register used to transfer that argument.
400   /// For now we support only cases when argument is transferred through one
401   /// register.
402   struct ArgRegPair {
403     Register Reg;
404     uint16_t ArgNo;
405     ArgRegPair(Register R, unsigned Arg) : Reg(R), ArgNo(Arg) {
406       assert(Arg < (1 << 16) && "Arg out of range");
407     }
408   };
409   /// Vector of call argument and its forwarding register.
410   using CallSiteInfo = SmallVector<ArgRegPair, 1>;
411   using CallSiteInfoImpl = SmallVectorImpl<ArgRegPair>;
412 
413 private:
414   Delegate *TheDelegate = nullptr;
415   GISelChangeObserver *Observer = nullptr;
416 
417   using CallSiteInfoMap = DenseMap<const MachineInstr *, CallSiteInfo>;
418   /// Map a call instruction to call site arguments forwarding info.
419   CallSiteInfoMap CallSitesInfo;
420 
421   /// A helper function that returns call site info for a give call
422   /// instruction if debug entry value support is enabled.
423   CallSiteInfoMap::iterator getCallSiteInfo(const MachineInstr *MI);
424 
425   // Callbacks for insertion and removal.
426   void handleInsertion(MachineInstr &MI);
427   void handleRemoval(MachineInstr &MI);
428   friend struct ilist_traits<MachineInstr>;
429 
430 public:
431   using VariableDbgInfoMapTy = SmallVector<VariableDbgInfo, 4>;
432   VariableDbgInfoMapTy VariableDbgInfos;
433 
434   /// A count of how many instructions in the function have had numbers
435   /// assigned to them. Used for debug value tracking, to determine the
436   /// next instruction number.
437   unsigned DebugInstrNumberingCount = 0;
438 
439   /// Set value of DebugInstrNumberingCount field. Avoid using this unless
440   /// you're deserializing this data.
441   void setDebugInstrNumberingCount(unsigned Num);
442 
443   /// Pair of instruction number and operand number.
444   using DebugInstrOperandPair = std::pair<unsigned, unsigned>;
445 
446   /// Substitution map: from one <inst,operand> pair to another. Used to
447   /// record changes in where a value is defined, so that debug variable
448   /// locations can find it later.
449   std::map<DebugInstrOperandPair, DebugInstrOperandPair>
450       DebugValueSubstitutions;
451 
452   /// Create a substitution between one <instr,operand> value to a different,
453   /// new value.
454   void makeDebugValueSubstitution(DebugInstrOperandPair, DebugInstrOperandPair);
455 
456   /// Create substitutions for any tracked values in \p Old, to point at
457   /// \p New. Needed when we re-create an instruction during optimization,
458   /// which has the same signature (i.e., def operands in the same place) but
459   /// a modified instruction type, flags, or otherwise. An example: X86 moves
460   /// are sometimes transformed into equivalent LEAs.
461   /// If the two instructions are not the same opcode, limit which operands to
462   /// examine for substitutions to the first N operands by setting
463   /// \p MaxOperand.
464   void substituteDebugValuesForInst(const MachineInstr &Old, MachineInstr &New,
465                                     unsigned MaxOperand = UINT_MAX);
466 
467   MachineFunction(Function &F, const LLVMTargetMachine &Target,
468                   const TargetSubtargetInfo &STI, unsigned FunctionNum,
469                   MachineModuleInfo &MMI);
470   MachineFunction(const MachineFunction &) = delete;
471   MachineFunction &operator=(const MachineFunction &) = delete;
472   ~MachineFunction();
473 
474   /// Reset the instance as if it was just created.
475   void reset() {
476     clear();
477     init();
478   }
479 
480   /// Reset the currently registered delegate - otherwise assert.
481   void resetDelegate(Delegate *delegate) {
482     assert(TheDelegate == delegate &&
483            "Only the current delegate can perform reset!");
484     TheDelegate = nullptr;
485   }
486 
487   /// Set the delegate. resetDelegate must be called before attempting
488   /// to set.
489   void setDelegate(Delegate *delegate) {
490     assert(delegate && !TheDelegate &&
491            "Attempted to set delegate to null, or to change it without "
492            "first resetting it!");
493 
494     TheDelegate = delegate;
495   }
496 
497   void setObserver(GISelChangeObserver *O) { Observer = O; }
498 
499   GISelChangeObserver *getObserver() const { return Observer; }
500 
501   MachineModuleInfo &getMMI() const { return MMI; }
502   MCContext &getContext() const { return Ctx; }
503 
504   /// Returns the Section this function belongs to.
505   MCSection *getSection() const { return Section; }
506 
507   /// Indicates the Section this function belongs to.
508   void setSection(MCSection *S) { Section = S; }
509 
510   PseudoSourceValueManager &getPSVManager() const { return *PSVManager; }
511 
512   /// Return the DataLayout attached to the Module associated to this MF.
513   const DataLayout &getDataLayout() const;
514 
515   /// Return the LLVM function that this machine code represents
516   Function &getFunction() { return F; }
517 
518   /// Return the LLVM function that this machine code represents
519   const Function &getFunction() const { return F; }
520 
521   /// getName - Return the name of the corresponding LLVM function.
522   StringRef getName() const;
523 
524   /// getFunctionNumber - Return a unique ID for the current function.
525   unsigned getFunctionNumber() const { return FunctionNumber; }
526 
527   /// Returns true if this function has basic block sections enabled.
528   bool hasBBSections() const {
529     return (BBSectionsType == BasicBlockSection::All ||
530             BBSectionsType == BasicBlockSection::List ||
531             BBSectionsType == BasicBlockSection::Preset);
532   }
533 
534   /// Returns true if basic block labels are to be generated for this function.
535   bool hasBBLabels() const {
536     return BBSectionsType == BasicBlockSection::Labels;
537   }
538 
539   void setBBSectionsType(BasicBlockSection V) { BBSectionsType = V; }
540 
541   /// Assign IsBeginSection IsEndSection fields for basic blocks in this
542   /// function.
543   void assignBeginEndSections();
544 
545   /// getTarget - Return the target machine this machine code is compiled with
546   const LLVMTargetMachine &getTarget() const { return Target; }
547 
548   /// getSubtarget - Return the subtarget for which this machine code is being
549   /// compiled.
550   const TargetSubtargetInfo &getSubtarget() const { return *STI; }
551 
552   /// getSubtarget - This method returns a pointer to the specified type of
553   /// TargetSubtargetInfo.  In debug builds, it verifies that the object being
554   /// returned is of the correct type.
555   template<typename STC> const STC &getSubtarget() const {
556     return *static_cast<const STC *>(STI);
557   }
558 
559   /// getRegInfo - Return information about the registers currently in use.
560   MachineRegisterInfo &getRegInfo() { return *RegInfo; }
561   const MachineRegisterInfo &getRegInfo() const { return *RegInfo; }
562 
563   /// getFrameInfo - Return the frame info object for the current function.
564   /// This object contains information about objects allocated on the stack
565   /// frame of the current function in an abstract way.
566   MachineFrameInfo &getFrameInfo() { return *FrameInfo; }
567   const MachineFrameInfo &getFrameInfo() const { return *FrameInfo; }
568 
569   /// getJumpTableInfo - Return the jump table info object for the current
570   /// function.  This object contains information about jump tables in the
571   /// current function.  If the current function has no jump tables, this will
572   /// return null.
573   const MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; }
574   MachineJumpTableInfo *getJumpTableInfo() { return JumpTableInfo; }
575 
576   /// getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it
577   /// does already exist, allocate one.
578   MachineJumpTableInfo *getOrCreateJumpTableInfo(unsigned JTEntryKind);
579 
580   /// getConstantPool - Return the constant pool object for the current
581   /// function.
582   MachineConstantPool *getConstantPool() { return ConstantPool; }
583   const MachineConstantPool *getConstantPool() const { return ConstantPool; }
584 
585   /// getWasmEHFuncInfo - Return information about how the current function uses
586   /// Wasm exception handling. Returns null for functions that don't use wasm
587   /// exception handling.
588   const WasmEHFuncInfo *getWasmEHFuncInfo() const { return WasmEHInfo; }
589   WasmEHFuncInfo *getWasmEHFuncInfo() { return WasmEHInfo; }
590 
591   /// getWinEHFuncInfo - Return information about how the current function uses
592   /// Windows exception handling. Returns null for functions that don't use
593   /// funclets for exception handling.
594   const WinEHFuncInfo *getWinEHFuncInfo() const { return WinEHInfo; }
595   WinEHFuncInfo *getWinEHFuncInfo() { return WinEHInfo; }
596 
597   /// getAlignment - Return the alignment of the function.
598   Align getAlignment() const { return Alignment; }
599 
600   /// setAlignment - Set the alignment of the function.
601   void setAlignment(Align A) { Alignment = A; }
602 
603   /// ensureAlignment - Make sure the function is at least A bytes aligned.
604   void ensureAlignment(Align A) {
605     if (Alignment < A)
606       Alignment = A;
607   }
608 
609   /// exposesReturnsTwice - Returns true if the function calls setjmp or
610   /// any other similar functions with attribute "returns twice" without
611   /// having the attribute itself.
612   bool exposesReturnsTwice() const {
613     return ExposesReturnsTwice;
614   }
615 
616   /// setCallsSetJmp - Set a flag that indicates if there's a call to
617   /// a "returns twice" function.
618   void setExposesReturnsTwice(bool B) {
619     ExposesReturnsTwice = B;
620   }
621 
622   /// Returns true if the function contains any inline assembly.
623   bool hasInlineAsm() const {
624     return HasInlineAsm;
625   }
626 
627   /// Set a flag that indicates that the function contains inline assembly.
628   void setHasInlineAsm(bool B) {
629     HasInlineAsm = B;
630   }
631 
632   bool hasWinCFI() const {
633     return HasWinCFI;
634   }
635   void setHasWinCFI(bool v) { HasWinCFI = v; }
636 
637   /// True if this function needs frame moves for debug or exceptions.
638   bool needsFrameMoves() const;
639 
640   /// Get the function properties
641   const MachineFunctionProperties &getProperties() const { return Properties; }
642   MachineFunctionProperties &getProperties() { return Properties; }
643 
644   /// getInfo - Keep track of various per-function pieces of information for
645   /// backends that would like to do so.
646   ///
647   template<typename Ty>
648   Ty *getInfo() {
649     if (!MFInfo)
650       MFInfo = Ty::template create<Ty>(Allocator, *this);
651     return static_cast<Ty*>(MFInfo);
652   }
653 
654   template<typename Ty>
655   const Ty *getInfo() const {
656      return const_cast<MachineFunction*>(this)->getInfo<Ty>();
657   }
658 
659   /// Returns the denormal handling type for the default rounding mode of the
660   /// function.
661   DenormalMode getDenormalMode(const fltSemantics &FPType) const;
662 
663   /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they
664   /// are inserted into the machine function.  The block number for a machine
665   /// basic block can be found by using the MBB::getNumber method, this method
666   /// provides the inverse mapping.
667   MachineBasicBlock *getBlockNumbered(unsigned N) const {
668     assert(N < MBBNumbering.size() && "Illegal block number");
669     assert(MBBNumbering[N] && "Block was removed from the machine function!");
670     return MBBNumbering[N];
671   }
672 
673   /// Should we be emitting segmented stack stuff for the function
674   bool shouldSplitStack() const;
675 
676   /// getNumBlockIDs - Return the number of MBB ID's allocated.
677   unsigned getNumBlockIDs() const { return (unsigned)MBBNumbering.size(); }
678 
679   /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and
680   /// recomputes them.  This guarantees that the MBB numbers are sequential,
681   /// dense, and match the ordering of the blocks within the function.  If a
682   /// specific MachineBasicBlock is specified, only that block and those after
683   /// it are renumbered.
684   void RenumberBlocks(MachineBasicBlock *MBBFrom = nullptr);
685 
686   /// print - Print out the MachineFunction in a format suitable for debugging
687   /// to the specified stream.
688   void print(raw_ostream &OS, const SlotIndexes* = nullptr) const;
689 
690   /// viewCFG - This function is meant for use from the debugger.  You can just
691   /// say 'call F->viewCFG()' and a ghostview window should pop up from the
692   /// program, displaying the CFG of the current function with the code for each
693   /// basic block inside.  This depends on there being a 'dot' and 'gv' program
694   /// in your path.
695   void viewCFG() const;
696 
697   /// viewCFGOnly - This function is meant for use from the debugger.  It works
698   /// just like viewCFG, but it does not include the contents of basic blocks
699   /// into the nodes, just the label.  If you are only interested in the CFG
700   /// this can make the graph smaller.
701   ///
702   void viewCFGOnly() const;
703 
704   /// dump - Print the current MachineFunction to cerr, useful for debugger use.
705   void dump() const;
706 
707   /// Run the current MachineFunction through the machine code verifier, useful
708   /// for debugger use.
709   /// \returns true if no problems were found.
710   bool verify(Pass *p = nullptr, const char *Banner = nullptr,
711               bool AbortOnError = true) const;
712 
713   // Provide accessors for the MachineBasicBlock list...
714   using iterator = BasicBlockListType::iterator;
715   using const_iterator = BasicBlockListType::const_iterator;
716   using const_reverse_iterator = BasicBlockListType::const_reverse_iterator;
717   using reverse_iterator = BasicBlockListType::reverse_iterator;
718 
719   /// Support for MachineBasicBlock::getNextNode().
720   static BasicBlockListType MachineFunction::*
721   getSublistAccess(MachineBasicBlock *) {
722     return &MachineFunction::BasicBlocks;
723   }
724 
725   /// addLiveIn - Add the specified physical register as a live-in value and
726   /// create a corresponding virtual register for it.
727   Register addLiveIn(MCRegister PReg, const TargetRegisterClass *RC);
728 
729   //===--------------------------------------------------------------------===//
730   // BasicBlock accessor functions.
731   //
732   iterator                 begin()       { return BasicBlocks.begin(); }
733   const_iterator           begin() const { return BasicBlocks.begin(); }
734   iterator                 end  ()       { return BasicBlocks.end();   }
735   const_iterator           end  () const { return BasicBlocks.end();   }
736 
737   reverse_iterator        rbegin()       { return BasicBlocks.rbegin(); }
738   const_reverse_iterator  rbegin() const { return BasicBlocks.rbegin(); }
739   reverse_iterator        rend  ()       { return BasicBlocks.rend();   }
740   const_reverse_iterator  rend  () const { return BasicBlocks.rend();   }
741 
742   unsigned                  size() const { return (unsigned)BasicBlocks.size();}
743   bool                     empty() const { return BasicBlocks.empty(); }
744   const MachineBasicBlock &front() const { return BasicBlocks.front(); }
745         MachineBasicBlock &front()       { return BasicBlocks.front(); }
746   const MachineBasicBlock & back() const { return BasicBlocks.back(); }
747         MachineBasicBlock & back()       { return BasicBlocks.back(); }
748 
749   void push_back (MachineBasicBlock *MBB) { BasicBlocks.push_back (MBB); }
750   void push_front(MachineBasicBlock *MBB) { BasicBlocks.push_front(MBB); }
751   void insert(iterator MBBI, MachineBasicBlock *MBB) {
752     BasicBlocks.insert(MBBI, MBB);
753   }
754   void splice(iterator InsertPt, iterator MBBI) {
755     BasicBlocks.splice(InsertPt, BasicBlocks, MBBI);
756   }
757   void splice(iterator InsertPt, MachineBasicBlock *MBB) {
758     BasicBlocks.splice(InsertPt, BasicBlocks, MBB);
759   }
760   void splice(iterator InsertPt, iterator MBBI, iterator MBBE) {
761     BasicBlocks.splice(InsertPt, BasicBlocks, MBBI, MBBE);
762   }
763 
764   void remove(iterator MBBI) { BasicBlocks.remove(MBBI); }
765   void remove(MachineBasicBlock *MBBI) { BasicBlocks.remove(MBBI); }
766   void erase(iterator MBBI) { BasicBlocks.erase(MBBI); }
767   void erase(MachineBasicBlock *MBBI) { BasicBlocks.erase(MBBI); }
768 
769   template <typename Comp>
770   void sort(Comp comp) {
771     BasicBlocks.sort(comp);
772   }
773 
774   /// Return the number of \p MachineInstrs in this \p MachineFunction.
775   unsigned getInstructionCount() const {
776     unsigned InstrCount = 0;
777     for (const MachineBasicBlock &MBB : BasicBlocks)
778       InstrCount += MBB.size();
779     return InstrCount;
780   }
781 
782   //===--------------------------------------------------------------------===//
783   // Internal functions used to automatically number MachineBasicBlocks
784 
785   /// Adds the MBB to the internal numbering. Returns the unique number
786   /// assigned to the MBB.
787   unsigned addToMBBNumbering(MachineBasicBlock *MBB) {
788     MBBNumbering.push_back(MBB);
789     return (unsigned)MBBNumbering.size()-1;
790   }
791 
792   /// removeFromMBBNumbering - Remove the specific machine basic block from our
793   /// tracker, this is only really to be used by the MachineBasicBlock
794   /// implementation.
795   void removeFromMBBNumbering(unsigned N) {
796     assert(N < MBBNumbering.size() && "Illegal basic block #");
797     MBBNumbering[N] = nullptr;
798   }
799 
800   /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead
801   /// of `new MachineInstr'.
802   MachineInstr *CreateMachineInstr(const MCInstrDesc &MCID, const DebugLoc &DL,
803                                    bool NoImplicit = false);
804 
805   /// Create a new MachineInstr which is a copy of \p Orig, identical in all
806   /// ways except the instruction has no parent, prev, or next. Bundling flags
807   /// are reset.
808   ///
809   /// Note: Clones a single instruction, not whole instruction bundles.
810   /// Does not perform target specific adjustments; consider using
811   /// TargetInstrInfo::duplicate() instead.
812   MachineInstr *CloneMachineInstr(const MachineInstr *Orig);
813 
814   /// Clones instruction or the whole instruction bundle \p Orig and insert
815   /// into \p MBB before \p InsertBefore.
816   ///
817   /// Note: Does not perform target specific adjustments; consider using
818   /// TargetInstrInfo::duplicate() intead.
819   MachineInstr &CloneMachineInstrBundle(MachineBasicBlock &MBB,
820       MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig);
821 
822   /// DeleteMachineInstr - Delete the given MachineInstr.
823   void DeleteMachineInstr(MachineInstr *MI);
824 
825   /// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this
826   /// instead of `new MachineBasicBlock'.
827   MachineBasicBlock *CreateMachineBasicBlock(const BasicBlock *bb = nullptr);
828 
829   /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
830   void DeleteMachineBasicBlock(MachineBasicBlock *MBB);
831 
832   /// getMachineMemOperand - Allocate a new MachineMemOperand.
833   /// MachineMemOperands are owned by the MachineFunction and need not be
834   /// explicitly deallocated.
835   MachineMemOperand *getMachineMemOperand(
836       MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s,
837       Align base_alignment, const AAMDNodes &AAInfo = AAMDNodes(),
838       const MDNode *Ranges = nullptr, SyncScope::ID SSID = SyncScope::System,
839       AtomicOrdering Ordering = AtomicOrdering::NotAtomic,
840       AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic);
841 
842   /// getMachineMemOperand - Allocate a new MachineMemOperand by copying
843   /// an existing one, adjusting by an offset and using the given size.
844   /// MachineMemOperands are owned by the MachineFunction and need not be
845   /// explicitly deallocated.
846   MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
847                                           int64_t Offset, uint64_t Size);
848 
849   /// getMachineMemOperand - Allocate a new MachineMemOperand by copying
850   /// an existing one, replacing only the MachinePointerInfo and size.
851   /// MachineMemOperands are owned by the MachineFunction and need not be
852   /// explicitly deallocated.
853   MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
854                                           MachinePointerInfo &PtrInfo,
855                                           uint64_t Size);
856 
857   /// Allocate a new MachineMemOperand by copying an existing one,
858   /// replacing only AliasAnalysis information. MachineMemOperands are owned
859   /// by the MachineFunction and need not be explicitly deallocated.
860   MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
861                                           const AAMDNodes &AAInfo);
862 
863   /// Allocate a new MachineMemOperand by copying an existing one,
864   /// replacing the flags. MachineMemOperands are owned
865   /// by the MachineFunction and need not be explicitly deallocated.
866   MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
867                                           MachineMemOperand::Flags Flags);
868 
869   using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity;
870 
871   /// Allocate an array of MachineOperands. This is only intended for use by
872   /// internal MachineInstr functions.
873   MachineOperand *allocateOperandArray(OperandCapacity Cap) {
874     return OperandRecycler.allocate(Cap, Allocator);
875   }
876 
877   /// Dellocate an array of MachineOperands and recycle the memory. This is
878   /// only intended for use by internal MachineInstr functions.
879   /// Cap must be the same capacity that was used to allocate the array.
880   void deallocateOperandArray(OperandCapacity Cap, MachineOperand *Array) {
881     OperandRecycler.deallocate(Cap, Array);
882   }
883 
884   /// Allocate and initialize a register mask with @p NumRegister bits.
885   uint32_t *allocateRegMask();
886 
887   ArrayRef<int> allocateShuffleMask(ArrayRef<int> Mask);
888 
889   /// Allocate and construct an extra info structure for a `MachineInstr`.
890   ///
891   /// This is allocated on the function's allocator and so lives the life of
892   /// the function.
893   MachineInstr::ExtraInfo *createMIExtraInfo(
894       ArrayRef<MachineMemOperand *> MMOs, MCSymbol *PreInstrSymbol = nullptr,
895       MCSymbol *PostInstrSymbol = nullptr, MDNode *HeapAllocMarker = nullptr);
896 
897   /// Allocate a string and populate it with the given external symbol name.
898   const char *createExternalSymbolName(StringRef Name);
899 
900   //===--------------------------------------------------------------------===//
901   // Label Manipulation.
902 
903   /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
904   /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
905   /// normal 'L' label is returned.
906   MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx,
907                          bool isLinkerPrivate = false) const;
908 
909   /// getPICBaseSymbol - Return a function-local symbol to represent the PIC
910   /// base.
911   MCSymbol *getPICBaseSymbol() const;
912 
913   /// Returns a reference to a list of cfi instructions in the function's
914   /// prologue.  Used to construct frame maps for debug and exception handling
915   /// comsumers.
916   const std::vector<MCCFIInstruction> &getFrameInstructions() const {
917     return FrameInstructions;
918   }
919 
920   LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst);
921 
922   /// Returns a reference to a list of symbols immediately following calls to
923   /// _setjmp in the function. Used to construct the longjmp target table used
924   /// by Windows Control Flow Guard.
925   const std::vector<MCSymbol *> &getLongjmpTargets() const {
926     return LongjmpTargets;
927   }
928 
929   /// Add the specified symbol to the list of valid longjmp targets for Windows
930   /// Control Flow Guard.
931   void addLongjmpTarget(MCSymbol *Target) { LongjmpTargets.push_back(Target); }
932 
933   /// \name Exception Handling
934   /// \{
935 
936   bool callsEHReturn() const { return CallsEHReturn; }
937   void setCallsEHReturn(bool b) { CallsEHReturn = b; }
938 
939   bool callsUnwindInit() const { return CallsUnwindInit; }
940   void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
941 
942   bool hasEHScopes() const { return HasEHScopes; }
943   void setHasEHScopes(bool V) { HasEHScopes = V; }
944 
945   bool hasEHFunclets() const { return HasEHFunclets; }
946   void setHasEHFunclets(bool V) { HasEHFunclets = V; }
947 
948   /// Find or create an LandingPadInfo for the specified MachineBasicBlock.
949   LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
950 
951   /// Remap landing pad labels and remove any deleted landing pads.
952   void tidyLandingPads(DenseMap<MCSymbol *, uintptr_t> *LPMap = nullptr,
953                        bool TidyIfNoBeginLabels = true);
954 
955   /// Return a reference to the landing pad info for the current function.
956   const std::vector<LandingPadInfo> &getLandingPads() const {
957     return LandingPads;
958   }
959 
960   /// Provide the begin and end labels of an invoke style call and associate it
961   /// with a try landing pad block.
962   void addInvoke(MachineBasicBlock *LandingPad,
963                  MCSymbol *BeginLabel, MCSymbol *EndLabel);
964 
965   /// Add a new panding pad, and extract the exception handling information from
966   /// the landingpad instruction. Returns the label ID for the landing pad
967   /// entry.
968   MCSymbol *addLandingPad(MachineBasicBlock *LandingPad);
969 
970   /// Provide the catch typeinfo for a landing pad.
971   void addCatchTypeInfo(MachineBasicBlock *LandingPad,
972                         ArrayRef<const GlobalValue *> TyInfo);
973 
974   /// Provide the filter typeinfo for a landing pad.
975   void addFilterTypeInfo(MachineBasicBlock *LandingPad,
976                          ArrayRef<const GlobalValue *> TyInfo);
977 
978   /// Add a cleanup action for a landing pad.
979   void addCleanup(MachineBasicBlock *LandingPad);
980 
981   void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter,
982                           const BlockAddress *RecoverBA);
983 
984   void addSEHCleanupHandler(MachineBasicBlock *LandingPad,
985                             const Function *Cleanup);
986 
987   /// Return the type id for the specified typeinfo.  This is function wide.
988   unsigned getTypeIDFor(const GlobalValue *TI);
989 
990   /// Return the id of the filter encoded by TyIds.  This is function wide.
991   int getFilterIDFor(std::vector<unsigned> &TyIds);
992 
993   /// Map the landing pad's EH symbol to the call site indexes.
994   void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef<unsigned> Sites);
995 
996   /// Map the landing pad to its index. Used for Wasm exception handling.
997   void setWasmLandingPadIndex(const MachineBasicBlock *LPad, unsigned Index) {
998     WasmLPadToIndexMap[LPad] = Index;
999   }
1000 
1001   /// Returns true if the landing pad has an associate index in wasm EH.
1002   bool hasWasmLandingPadIndex(const MachineBasicBlock *LPad) const {
1003     return WasmLPadToIndexMap.count(LPad);
1004   }
1005 
1006   /// Get the index in wasm EH for a given landing pad.
1007   unsigned getWasmLandingPadIndex(const MachineBasicBlock *LPad) const {
1008     assert(hasWasmLandingPadIndex(LPad));
1009     return WasmLPadToIndexMap.lookup(LPad);
1010   }
1011 
1012   /// Get the call site indexes for a landing pad EH symbol.
1013   SmallVectorImpl<unsigned> &getCallSiteLandingPad(MCSymbol *Sym) {
1014     assert(hasCallSiteLandingPad(Sym) &&
1015            "missing call site number for landing pad!");
1016     return LPadToCallSiteMap[Sym];
1017   }
1018 
1019   /// Return true if the landing pad Eh symbol has an associated call site.
1020   bool hasCallSiteLandingPad(MCSymbol *Sym) {
1021     return !LPadToCallSiteMap[Sym].empty();
1022   }
1023 
1024   /// Map the begin label for a call site.
1025   void setCallSiteBeginLabel(MCSymbol *BeginLabel, unsigned Site) {
1026     CallSiteMap[BeginLabel] = Site;
1027   }
1028 
1029   /// Get the call site number for a begin label.
1030   unsigned getCallSiteBeginLabel(MCSymbol *BeginLabel) const {
1031     assert(hasCallSiteBeginLabel(BeginLabel) &&
1032            "Missing call site number for EH_LABEL!");
1033     return CallSiteMap.lookup(BeginLabel);
1034   }
1035 
1036   /// Return true if the begin label has a call site number associated with it.
1037   bool hasCallSiteBeginLabel(MCSymbol *BeginLabel) const {
1038     return CallSiteMap.count(BeginLabel);
1039   }
1040 
1041   /// Record annotations associated with a particular label.
1042   void addCodeViewAnnotation(MCSymbol *Label, MDNode *MD) {
1043     CodeViewAnnotations.push_back({Label, MD});
1044   }
1045 
1046   ArrayRef<std::pair<MCSymbol *, MDNode *>> getCodeViewAnnotations() const {
1047     return CodeViewAnnotations;
1048   }
1049 
1050   /// Return a reference to the C++ typeinfo for the current function.
1051   const std::vector<const GlobalValue *> &getTypeInfos() const {
1052     return TypeInfos;
1053   }
1054 
1055   /// Return a reference to the typeids encoding filters used in the current
1056   /// function.
1057   const std::vector<unsigned> &getFilterIds() const {
1058     return FilterIds;
1059   }
1060 
1061   /// \}
1062 
1063   /// Collect information used to emit debugging information of a variable.
1064   void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
1065                           int Slot, const DILocation *Loc) {
1066     VariableDbgInfos.emplace_back(Var, Expr, Slot, Loc);
1067   }
1068 
1069   VariableDbgInfoMapTy &getVariableDbgInfo() { return VariableDbgInfos; }
1070   const VariableDbgInfoMapTy &getVariableDbgInfo() const {
1071     return VariableDbgInfos;
1072   }
1073 
1074   /// Start tracking the arguments passed to the call \p CallI.
1075   void addCallArgsForwardingRegs(const MachineInstr *CallI,
1076                                  CallSiteInfoImpl &&CallInfo) {
1077     assert(CallI->isCandidateForCallSiteEntry());
1078     bool Inserted =
1079         CallSitesInfo.try_emplace(CallI, std::move(CallInfo)).second;
1080     (void)Inserted;
1081     assert(Inserted && "Call site info not unique");
1082   }
1083 
1084   const CallSiteInfoMap &getCallSitesInfo() const {
1085     return CallSitesInfo;
1086   }
1087 
1088   /// Following functions update call site info. They should be called before
1089   /// removing, replacing or copying call instruction.
1090 
1091   /// Erase the call site info for \p MI. It is used to remove a call
1092   /// instruction from the instruction stream.
1093   void eraseCallSiteInfo(const MachineInstr *MI);
1094   /// Copy the call site info from \p Old to \ New. Its usage is when we are
1095   /// making a copy of the instruction that will be inserted at different point
1096   /// of the instruction stream.
1097   void copyCallSiteInfo(const MachineInstr *Old,
1098                         const MachineInstr *New);
1099 
1100   const std::vector<char> &getBBSectionsSymbolPrefix() const {
1101     return BBSectionsSymbolPrefix;
1102   }
1103 
1104   /// Move the call site info from \p Old to \New call site info. This function
1105   /// is used when we are replacing one call instruction with another one to
1106   /// the same callee.
1107   void moveCallSiteInfo(const MachineInstr *Old,
1108                         const MachineInstr *New);
1109 
1110   unsigned getNewDebugInstrNum() {
1111     return ++DebugInstrNumberingCount;
1112   }
1113 };
1114 
1115 //===--------------------------------------------------------------------===//
1116 // GraphTraits specializations for function basic block graphs (CFGs)
1117 //===--------------------------------------------------------------------===//
1118 
1119 // Provide specializations of GraphTraits to be able to treat a
1120 // machine function as a graph of machine basic blocks... these are
1121 // the same as the machine basic block iterators, except that the root
1122 // node is implicitly the first node of the function.
1123 //
1124 template <> struct GraphTraits<MachineFunction*> :
1125   public GraphTraits<MachineBasicBlock*> {
1126   static NodeRef getEntryNode(MachineFunction *F) { return &F->front(); }
1127 
1128   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
1129   using nodes_iterator = pointer_iterator<MachineFunction::iterator>;
1130 
1131   static nodes_iterator nodes_begin(MachineFunction *F) {
1132     return nodes_iterator(F->begin());
1133   }
1134 
1135   static nodes_iterator nodes_end(MachineFunction *F) {
1136     return nodes_iterator(F->end());
1137   }
1138 
1139   static unsigned       size       (MachineFunction *F) { return F->size(); }
1140 };
1141 template <> struct GraphTraits<const MachineFunction*> :
1142   public GraphTraits<const MachineBasicBlock*> {
1143   static NodeRef getEntryNode(const MachineFunction *F) { return &F->front(); }
1144 
1145   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
1146   using nodes_iterator = pointer_iterator<MachineFunction::const_iterator>;
1147 
1148   static nodes_iterator nodes_begin(const MachineFunction *F) {
1149     return nodes_iterator(F->begin());
1150   }
1151 
1152   static nodes_iterator nodes_end  (const MachineFunction *F) {
1153     return nodes_iterator(F->end());
1154   }
1155 
1156   static unsigned       size       (const MachineFunction *F)  {
1157     return F->size();
1158   }
1159 };
1160 
1161 // Provide specializations of GraphTraits to be able to treat a function as a
1162 // graph of basic blocks... and to walk it in inverse order.  Inverse order for
1163 // a function is considered to be when traversing the predecessor edges of a BB
1164 // instead of the successor edges.
1165 //
1166 template <> struct GraphTraits<Inverse<MachineFunction*>> :
1167   public GraphTraits<Inverse<MachineBasicBlock*>> {
1168   static NodeRef getEntryNode(Inverse<MachineFunction *> G) {
1169     return &G.Graph->front();
1170   }
1171 };
1172 template <> struct GraphTraits<Inverse<const MachineFunction*>> :
1173   public GraphTraits<Inverse<const MachineBasicBlock*>> {
1174   static NodeRef getEntryNode(Inverse<const MachineFunction *> G) {
1175     return &G.Graph->front();
1176   }
1177 };
1178 
1179 class MachineFunctionAnalysisManager;
1180 void verifyMachineFunction(MachineFunctionAnalysisManager *,
1181                            const std::string &Banner,
1182                            const MachineFunction &MF);
1183 
1184 } // end namespace llvm
1185 
1186 #endif // LLVM_CODEGEN_MACHINEFUNCTION_H
1187