• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- llvm/CodeGen/MachineFunction.h --------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Collect native machine code for a function.  This class contains a list of
11 // MachineBasicBlock instances that make up the current compiled function.
12 //
13 // This class also contains pointers to various classes which hold
14 // target-specific information about the generated code.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
19 #define LLVM_CODEGEN_MACHINEFUNCTION_H
20 
21 #include "llvm/ADT/BitVector.h"
22 #include "llvm/ADT/ilist.h"
23 #include "llvm/CodeGen/MachineBasicBlock.h"
24 #include "llvm/IR/DebugLoc.h"
25 #include "llvm/IR/Metadata.h"
26 #include "llvm/Support/Allocator.h"
27 #include "llvm/Support/ArrayRecycler.h"
28 #include "llvm/Support/Compiler.h"
29 #include "llvm/Support/Recycler.h"
30 
31 namespace llvm {
32 
33 class Value;
34 class Function;
35 class GCModuleInfo;
36 class MachineRegisterInfo;
37 class MachineFrameInfo;
38 class MachineConstantPool;
39 class MachineJumpTableInfo;
40 class MachineModuleInfo;
41 class MCContext;
42 class Pass;
43 class PseudoSourceValueManager;
44 class TargetMachine;
45 class TargetSubtargetInfo;
46 class TargetRegisterClass;
47 struct MachinePointerInfo;
48 struct WinEHFuncInfo;
49 
50 template <>
51 struct ilist_traits<MachineBasicBlock>
52     : public ilist_default_traits<MachineBasicBlock> {
53   mutable ilist_half_node<MachineBasicBlock> Sentinel;
54 public:
55   // FIXME: This downcast is UB. See llvm.org/PR26753.
56   LLVM_NO_SANITIZE("object-size")
57   MachineBasicBlock *createSentinel() const {
58     return static_cast<MachineBasicBlock*>(&Sentinel);
59   }
60   void destroySentinel(MachineBasicBlock *) const {}
61 
62   MachineBasicBlock *provideInitialHead() const { return createSentinel(); }
63   MachineBasicBlock *ensureHead(MachineBasicBlock*) const {
64     return createSentinel();
65   }
66   static void noteHead(MachineBasicBlock*, MachineBasicBlock*) {}
67 
68   void addNodeToList(MachineBasicBlock* MBB);
69   void removeNodeFromList(MachineBasicBlock* MBB);
70   void deleteNode(MachineBasicBlock *MBB);
71 private:
72   void createNode(const MachineBasicBlock &);
73 };
74 
75 /// MachineFunctionInfo - This class can be derived from and used by targets to
76 /// hold private target-specific information for each MachineFunction.  Objects
77 /// of type are accessed/created with MF::getInfo and destroyed when the
78 /// MachineFunction is destroyed.
79 struct MachineFunctionInfo {
80   virtual ~MachineFunctionInfo();
81 
82   /// \brief Factory function: default behavior is to call new using the
83   /// supplied allocator.
84   ///
85   /// This function can be overridden in a derive class.
86   template<typename Ty>
87   static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
88     return new (Allocator.Allocate<Ty>()) Ty(MF);
89   }
90 };
91 
92 /// Properties which a MachineFunction may have at a given point in time.
93 /// Each of these has checking code in the MachineVerifier, and passes can
94 /// require that a property be set.
95 class MachineFunctionProperties {
96   // TODO: Add MachineVerifier checks for AllVRegsAllocated
97   // TODO: Add a way to print the properties and make more useful error messages
98   // Possible TODO: Allow targets to extend this (perhaps by allowing the
99   // constructor to specify the size of the bit vector)
100   // Possible TODO: Allow requiring the negative (e.g. VRegsAllocated could be
101   // stated as the negative of "has vregs"
102 
103 public:
104   // The properties are stated in "positive" form; i.e. a pass could require
105   // that the property hold, but not that it does not hold.
106 
107   // Property descriptions:
108   // IsSSA: True when the machine function is in SSA form and virtual registers
109   //  have a single def.
110   // TracksLiveness: True when tracking register liveness accurately.
111   //  While this property is set, register liveness information in basic block
112   //  live-in lists and machine instruction operands (e.g. kill flags, implicit
113   //  defs) is accurate. This means it can be used to change the code in ways
114   //  that affect the values in registers, for example by the register
115   //  scavenger.
116   //  When this property is clear, liveness is no longer reliable.
117   // AllVRegsAllocated: All virtual registers have been allocated; i.e. all
118   //  register operands are physical registers.
119   enum class Property : unsigned {
120     IsSSA,
121     TracksLiveness,
122     AllVRegsAllocated,
123     LastProperty,
124   };
125 
126   bool hasProperty(Property P) const {
127     return Properties[static_cast<unsigned>(P)];
128   }
129   MachineFunctionProperties &set(Property P) {
130     Properties.set(static_cast<unsigned>(P));
131     return *this;
132   }
133   MachineFunctionProperties &clear(Property P) {
134     Properties.reset(static_cast<unsigned>(P));
135     return *this;
136   }
137   MachineFunctionProperties &set(const MachineFunctionProperties &MFP) {
138     Properties |= MFP.Properties;
139     return *this;
140   }
141   MachineFunctionProperties &clear(const MachineFunctionProperties &MFP) {
142     Properties.reset(MFP.Properties);
143     return *this;
144   }
145   // Returns true if all properties set in V (i.e. required by a pass) are set
146   // in this.
147   bool verifyRequiredProperties(const MachineFunctionProperties &V) const {
148     return !V.Properties.test(Properties);
149   }
150 
151   // Print the MachineFunctionProperties in human-readable form. If OnlySet is
152   // true, only print the properties that are set.
153   void print(raw_ostream &ROS, bool OnlySet=false) const;
154 
155 private:
156   BitVector Properties =
157       BitVector(static_cast<unsigned>(Property::LastProperty));
158 };
159 
160 class MachineFunction {
161   const Function *Fn;
162   const TargetMachine &Target;
163   const TargetSubtargetInfo *STI;
164   MCContext &Ctx;
165   MachineModuleInfo &MMI;
166 
167   // RegInfo - Information about each register in use in the function.
168   MachineRegisterInfo *RegInfo;
169 
170   // Used to keep track of target-specific per-machine function information for
171   // the target implementation.
172   MachineFunctionInfo *MFInfo;
173 
174   // Keep track of objects allocated on the stack.
175   MachineFrameInfo *FrameInfo;
176 
177   // Keep track of constants which are spilled to memory
178   MachineConstantPool *ConstantPool;
179 
180   // Keep track of jump tables for switch instructions
181   MachineJumpTableInfo *JumpTableInfo;
182 
183   // Keeps track of Windows exception handling related data. This will be null
184   // for functions that aren't using a funclet-based EH personality.
185   WinEHFuncInfo *WinEHInfo = nullptr;
186 
187   // Function-level unique numbering for MachineBasicBlocks.  When a
188   // MachineBasicBlock is inserted into a MachineFunction is it automatically
189   // numbered and this vector keeps track of the mapping from ID's to MBB's.
190   std::vector<MachineBasicBlock*> MBBNumbering;
191 
192   // Pool-allocate MachineFunction-lifetime and IR objects.
193   BumpPtrAllocator Allocator;
194 
195   // Allocation management for instructions in function.
196   Recycler<MachineInstr> InstructionRecycler;
197 
198   // Allocation management for operand arrays on instructions.
199   ArrayRecycler<MachineOperand> OperandRecycler;
200 
201   // Allocation management for basic blocks in function.
202   Recycler<MachineBasicBlock> BasicBlockRecycler;
203 
204   // List of machine basic blocks in function
205   typedef ilist<MachineBasicBlock> BasicBlockListType;
206   BasicBlockListType BasicBlocks;
207 
208   /// FunctionNumber - This provides a unique ID for each function emitted in
209   /// this translation unit.
210   ///
211   unsigned FunctionNumber;
212 
213   /// Alignment - The alignment of the function.
214   unsigned Alignment;
215 
216   /// ExposesReturnsTwice - True if the function calls setjmp or related
217   /// functions with attribute "returns twice", but doesn't have
218   /// the attribute itself.
219   /// This is used to limit optimizations which cannot reason
220   /// about the control flow of such functions.
221   bool ExposesReturnsTwice = false;
222 
223   /// True if the function includes any inline assembly.
224   bool HasInlineAsm = false;
225 
226   /// Current high-level properties of the IR of the function (e.g. is in SSA
227   /// form or whether registers have been allocated)
228   MachineFunctionProperties Properties;
229 
230   // Allocation management for pseudo source values.
231   std::unique_ptr<PseudoSourceValueManager> PSVManager;
232 
233   MachineFunction(const MachineFunction &) = delete;
234   void operator=(const MachineFunction&) = delete;
235 public:
236   MachineFunction(const Function *Fn, const TargetMachine &TM,
237                   unsigned FunctionNum, MachineModuleInfo &MMI);
238   ~MachineFunction();
239 
240   MachineModuleInfo &getMMI() const { return MMI; }
241   MCContext &getContext() const { return Ctx; }
242 
243   PseudoSourceValueManager &getPSVManager() const { return *PSVManager; }
244 
245   /// Return the DataLayout attached to the Module associated to this MF.
246   const DataLayout &getDataLayout() const;
247 
248   /// getFunction - Return the LLVM function that this machine code represents
249   ///
250   const Function *getFunction() const { return Fn; }
251 
252   /// getName - Return the name of the corresponding LLVM function.
253   ///
254   StringRef getName() const;
255 
256   /// getFunctionNumber - Return a unique ID for the current function.
257   ///
258   unsigned getFunctionNumber() const { return FunctionNumber; }
259 
260   /// getTarget - Return the target machine this machine code is compiled with
261   ///
262   const TargetMachine &getTarget() const { return Target; }
263 
264   /// getSubtarget - Return the subtarget for which this machine code is being
265   /// compiled.
266   const TargetSubtargetInfo &getSubtarget() const { return *STI; }
267   void setSubtarget(const TargetSubtargetInfo *ST) { STI = ST; }
268 
269   /// getSubtarget - This method returns a pointer to the specified type of
270   /// TargetSubtargetInfo.  In debug builds, it verifies that the object being
271   /// returned is of the correct type.
272   template<typename STC> const STC &getSubtarget() const {
273     return *static_cast<const STC *>(STI);
274   }
275 
276   /// getRegInfo - Return information about the registers currently in use.
277   ///
278   MachineRegisterInfo &getRegInfo() { return *RegInfo; }
279   const MachineRegisterInfo &getRegInfo() const { return *RegInfo; }
280 
281   /// getFrameInfo - Return the frame info object for the current function.
282   /// This object contains information about objects allocated on the stack
283   /// frame of the current function in an abstract way.
284   ///
285   MachineFrameInfo *getFrameInfo() { return FrameInfo; }
286   const MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
287 
288   /// getJumpTableInfo - Return the jump table info object for the current
289   /// function.  This object contains information about jump tables in the
290   /// current function.  If the current function has no jump tables, this will
291   /// return null.
292   const MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; }
293   MachineJumpTableInfo *getJumpTableInfo() { return JumpTableInfo; }
294 
295   /// getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it
296   /// does already exist, allocate one.
297   MachineJumpTableInfo *getOrCreateJumpTableInfo(unsigned JTEntryKind);
298 
299   /// getConstantPool - Return the constant pool object for the current
300   /// function.
301   ///
302   MachineConstantPool *getConstantPool() { return ConstantPool; }
303   const MachineConstantPool *getConstantPool() const { return ConstantPool; }
304 
305   /// getWinEHFuncInfo - Return information about how the current function uses
306   /// Windows exception handling. Returns null for functions that don't use
307   /// funclets for exception handling.
308   const WinEHFuncInfo *getWinEHFuncInfo() const { return WinEHInfo; }
309   WinEHFuncInfo *getWinEHFuncInfo() { return WinEHInfo; }
310 
311   /// getAlignment - Return the alignment (log2, not bytes) of the function.
312   ///
313   unsigned getAlignment() const { return Alignment; }
314 
315   /// setAlignment - Set the alignment (log2, not bytes) of the function.
316   ///
317   void setAlignment(unsigned A) { Alignment = A; }
318 
319   /// ensureAlignment - Make sure the function is at least 1 << A bytes aligned.
320   void ensureAlignment(unsigned A) {
321     if (Alignment < A) Alignment = A;
322   }
323 
324   /// exposesReturnsTwice - Returns true if the function calls setjmp or
325   /// any other similar functions with attribute "returns twice" without
326   /// having the attribute itself.
327   bool exposesReturnsTwice() const {
328     return ExposesReturnsTwice;
329   }
330 
331   /// setCallsSetJmp - Set a flag that indicates if there's a call to
332   /// a "returns twice" function.
333   void setExposesReturnsTwice(bool B) {
334     ExposesReturnsTwice = B;
335   }
336 
337   /// Returns true if the function contains any inline assembly.
338   bool hasInlineAsm() const {
339     return HasInlineAsm;
340   }
341 
342   /// Set a flag that indicates that the function contains inline assembly.
343   void setHasInlineAsm(bool B) {
344     HasInlineAsm = B;
345   }
346 
347   /// Get the function properties
348   const MachineFunctionProperties &getProperties() const { return Properties; }
349   MachineFunctionProperties &getProperties() { return Properties; }
350 
351   /// getInfo - Keep track of various per-function pieces of information for
352   /// backends that would like to do so.
353   ///
354   template<typename Ty>
355   Ty *getInfo() {
356     if (!MFInfo)
357       MFInfo = Ty::template create<Ty>(Allocator, *this);
358     return static_cast<Ty*>(MFInfo);
359   }
360 
361   template<typename Ty>
362   const Ty *getInfo() const {
363      return const_cast<MachineFunction*>(this)->getInfo<Ty>();
364   }
365 
366   /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they
367   /// are inserted into the machine function.  The block number for a machine
368   /// basic block can be found by using the MBB::getBlockNumber method, this
369   /// method provides the inverse mapping.
370   ///
371   MachineBasicBlock *getBlockNumbered(unsigned N) const {
372     assert(N < MBBNumbering.size() && "Illegal block number");
373     assert(MBBNumbering[N] && "Block was removed from the machine function!");
374     return MBBNumbering[N];
375   }
376 
377   /// Should we be emitting segmented stack stuff for the function
378   bool shouldSplitStack() const;
379 
380   /// getNumBlockIDs - Return the number of MBB ID's allocated.
381   ///
382   unsigned getNumBlockIDs() const { return (unsigned)MBBNumbering.size(); }
383 
384   /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and
385   /// recomputes them.  This guarantees that the MBB numbers are sequential,
386   /// dense, and match the ordering of the blocks within the function.  If a
387   /// specific MachineBasicBlock is specified, only that block and those after
388   /// it are renumbered.
389   void RenumberBlocks(MachineBasicBlock *MBBFrom = nullptr);
390 
391   /// print - Print out the MachineFunction in a format suitable for debugging
392   /// to the specified stream.
393   ///
394   void print(raw_ostream &OS, const SlotIndexes* = nullptr) const;
395 
396   /// viewCFG - This function is meant for use from the debugger.  You can just
397   /// say 'call F->viewCFG()' and a ghostview window should pop up from the
398   /// program, displaying the CFG of the current function with the code for each
399   /// basic block inside.  This depends on there being a 'dot' and 'gv' program
400   /// in your path.
401   ///
402   void viewCFG() const;
403 
404   /// viewCFGOnly - This function is meant for use from the debugger.  It works
405   /// just like viewCFG, but it does not include the contents of basic blocks
406   /// into the nodes, just the label.  If you are only interested in the CFG
407   /// this can make the graph smaller.
408   ///
409   void viewCFGOnly() const;
410 
411   /// dump - Print the current MachineFunction to cerr, useful for debugger use.
412   ///
413   void dump() const;
414 
415   /// Run the current MachineFunction through the machine code verifier, useful
416   /// for debugger use.
417   /// \returns true if no problems were found.
418   bool verify(Pass *p = nullptr, const char *Banner = nullptr,
419               bool AbortOnError = true) const;
420 
421   // Provide accessors for the MachineBasicBlock list...
422   typedef BasicBlockListType::iterator iterator;
423   typedef BasicBlockListType::const_iterator const_iterator;
424   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
425   typedef std::reverse_iterator<iterator>             reverse_iterator;
426 
427   /// Support for MachineBasicBlock::getNextNode().
428   static BasicBlockListType MachineFunction::*
429   getSublistAccess(MachineBasicBlock *) {
430     return &MachineFunction::BasicBlocks;
431   }
432 
433   /// addLiveIn - Add the specified physical register as a live-in value and
434   /// create a corresponding virtual register for it.
435   unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC);
436 
437   //===--------------------------------------------------------------------===//
438   // BasicBlock accessor functions.
439   //
440   iterator                 begin()       { return BasicBlocks.begin(); }
441   const_iterator           begin() const { return BasicBlocks.begin(); }
442   iterator                 end  ()       { return BasicBlocks.end();   }
443   const_iterator           end  () const { return BasicBlocks.end();   }
444 
445   reverse_iterator        rbegin()       { return BasicBlocks.rbegin(); }
446   const_reverse_iterator  rbegin() const { return BasicBlocks.rbegin(); }
447   reverse_iterator        rend  ()       { return BasicBlocks.rend();   }
448   const_reverse_iterator  rend  () const { return BasicBlocks.rend();   }
449 
450   unsigned                  size() const { return (unsigned)BasicBlocks.size();}
451   bool                     empty() const { return BasicBlocks.empty(); }
452   const MachineBasicBlock &front() const { return BasicBlocks.front(); }
453         MachineBasicBlock &front()       { return BasicBlocks.front(); }
454   const MachineBasicBlock & back() const { return BasicBlocks.back(); }
455         MachineBasicBlock & back()       { return BasicBlocks.back(); }
456 
457   void push_back (MachineBasicBlock *MBB) { BasicBlocks.push_back (MBB); }
458   void push_front(MachineBasicBlock *MBB) { BasicBlocks.push_front(MBB); }
459   void insert(iterator MBBI, MachineBasicBlock *MBB) {
460     BasicBlocks.insert(MBBI, MBB);
461   }
462   void splice(iterator InsertPt, iterator MBBI) {
463     BasicBlocks.splice(InsertPt, BasicBlocks, MBBI);
464   }
465   void splice(iterator InsertPt, MachineBasicBlock *MBB) {
466     BasicBlocks.splice(InsertPt, BasicBlocks, MBB);
467   }
468   void splice(iterator InsertPt, iterator MBBI, iterator MBBE) {
469     BasicBlocks.splice(InsertPt, BasicBlocks, MBBI, MBBE);
470   }
471 
472   void remove(iterator MBBI) { BasicBlocks.remove(MBBI); }
473   void remove(MachineBasicBlock *MBBI) { BasicBlocks.remove(MBBI); }
474   void erase(iterator MBBI) { BasicBlocks.erase(MBBI); }
475   void erase(MachineBasicBlock *MBBI) { BasicBlocks.erase(MBBI); }
476 
477   template <typename Comp>
478   void sort(Comp comp) {
479     BasicBlocks.sort(comp);
480   }
481 
482   //===--------------------------------------------------------------------===//
483   // Internal functions used to automatically number MachineBasicBlocks
484   //
485 
486   /// \brief Adds the MBB to the internal numbering. Returns the unique number
487   /// assigned to the MBB.
488   ///
489   unsigned addToMBBNumbering(MachineBasicBlock *MBB) {
490     MBBNumbering.push_back(MBB);
491     return (unsigned)MBBNumbering.size()-1;
492   }
493 
494   /// removeFromMBBNumbering - Remove the specific machine basic block from our
495   /// tracker, this is only really to be used by the MachineBasicBlock
496   /// implementation.
497   void removeFromMBBNumbering(unsigned N) {
498     assert(N < MBBNumbering.size() && "Illegal basic block #");
499     MBBNumbering[N] = nullptr;
500   }
501 
502   /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead
503   /// of `new MachineInstr'.
504   ///
505   MachineInstr *CreateMachineInstr(const MCInstrDesc &MCID, const DebugLoc &DL,
506                                    bool NoImp = false);
507 
508   /// CloneMachineInstr - Create a new MachineInstr which is a copy of the
509   /// 'Orig' instruction, identical in all ways except the instruction
510   /// has no parent, prev, or next.
511   ///
512   /// See also TargetInstrInfo::duplicate() for target-specific fixes to cloned
513   /// instructions.
514   MachineInstr *CloneMachineInstr(const MachineInstr *Orig);
515 
516   /// DeleteMachineInstr - Delete the given MachineInstr.
517   ///
518   void DeleteMachineInstr(MachineInstr *MI);
519 
520   /// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this
521   /// instead of `new MachineBasicBlock'.
522   ///
523   MachineBasicBlock *CreateMachineBasicBlock(const BasicBlock *bb = nullptr);
524 
525   /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
526   ///
527   void DeleteMachineBasicBlock(MachineBasicBlock *MBB);
528 
529   /// getMachineMemOperand - Allocate a new MachineMemOperand.
530   /// MachineMemOperands are owned by the MachineFunction and need not be
531   /// explicitly deallocated.
532   MachineMemOperand *getMachineMemOperand(MachinePointerInfo PtrInfo,
533                                           unsigned f, uint64_t s,
534                                           unsigned base_alignment,
535                                           const AAMDNodes &AAInfo = AAMDNodes(),
536                                           const MDNode *Ranges = nullptr);
537 
538   /// getMachineMemOperand - Allocate a new MachineMemOperand by copying
539   /// an existing one, adjusting by an offset and using the given size.
540   /// MachineMemOperands are owned by the MachineFunction and need not be
541   /// explicitly deallocated.
542   MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
543                                           int64_t Offset, uint64_t Size);
544 
545   typedef ArrayRecycler<MachineOperand>::Capacity OperandCapacity;
546 
547   /// Allocate an array of MachineOperands. This is only intended for use by
548   /// internal MachineInstr functions.
549   MachineOperand *allocateOperandArray(OperandCapacity Cap) {
550     return OperandRecycler.allocate(Cap, Allocator);
551   }
552 
553   /// Dellocate an array of MachineOperands and recycle the memory. This is
554   /// only intended for use by internal MachineInstr functions.
555   /// Cap must be the same capacity that was used to allocate the array.
556   void deallocateOperandArray(OperandCapacity Cap, MachineOperand *Array) {
557     OperandRecycler.deallocate(Cap, Array);
558   }
559 
560   /// \brief Allocate and initialize a register mask with @p NumRegister bits.
561   uint32_t *allocateRegisterMask(unsigned NumRegister) {
562     unsigned Size = (NumRegister + 31) / 32;
563     uint32_t *Mask = Allocator.Allocate<uint32_t>(Size);
564     for (unsigned i = 0; i != Size; ++i)
565       Mask[i] = 0;
566     return Mask;
567   }
568 
569   /// allocateMemRefsArray - Allocate an array to hold MachineMemOperand
570   /// pointers.  This array is owned by the MachineFunction.
571   MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num);
572 
573   /// extractLoadMemRefs - Allocate an array and populate it with just the
574   /// load information from the given MachineMemOperand sequence.
575   std::pair<MachineInstr::mmo_iterator,
576             MachineInstr::mmo_iterator>
577     extractLoadMemRefs(MachineInstr::mmo_iterator Begin,
578                        MachineInstr::mmo_iterator End);
579 
580   /// extractStoreMemRefs - Allocate an array and populate it with just the
581   /// store information from the given MachineMemOperand sequence.
582   std::pair<MachineInstr::mmo_iterator,
583             MachineInstr::mmo_iterator>
584     extractStoreMemRefs(MachineInstr::mmo_iterator Begin,
585                         MachineInstr::mmo_iterator End);
586 
587   /// Allocate a string and populate it with the given external symbol name.
588   const char *createExternalSymbolName(StringRef Name);
589 
590   //===--------------------------------------------------------------------===//
591   // Label Manipulation.
592   //
593 
594   /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
595   /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
596   /// normal 'L' label is returned.
597   MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx,
598                          bool isLinkerPrivate = false) const;
599 
600   /// getPICBaseSymbol - Return a function-local symbol to represent the PIC
601   /// base.
602   MCSymbol *getPICBaseSymbol() const;
603 };
604 
605 //===--------------------------------------------------------------------===//
606 // GraphTraits specializations for function basic block graphs (CFGs)
607 //===--------------------------------------------------------------------===//
608 
609 // Provide specializations of GraphTraits to be able to treat a
610 // machine function as a graph of machine basic blocks... these are
611 // the same as the machine basic block iterators, except that the root
612 // node is implicitly the first node of the function.
613 //
614 template <> struct GraphTraits<MachineFunction*> :
615   public GraphTraits<MachineBasicBlock*> {
616   static NodeType *getEntryNode(MachineFunction *F) {
617     return &F->front();
618   }
619 
620   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
621   typedef MachineFunction::iterator nodes_iterator;
622   static nodes_iterator nodes_begin(MachineFunction *F) { return F->begin(); }
623   static nodes_iterator nodes_end  (MachineFunction *F) { return F->end(); }
624   static unsigned       size       (MachineFunction *F) { return F->size(); }
625 };
626 template <> struct GraphTraits<const MachineFunction*> :
627   public GraphTraits<const MachineBasicBlock*> {
628   static NodeType *getEntryNode(const MachineFunction *F) {
629     return &F->front();
630   }
631 
632   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
633   typedef MachineFunction::const_iterator nodes_iterator;
634   static nodes_iterator nodes_begin(const MachineFunction *F) {
635     return F->begin();
636   }
637   static nodes_iterator nodes_end  (const MachineFunction *F) {
638     return F->end();
639   }
640   static unsigned       size       (const MachineFunction *F)  {
641     return F->size();
642   }
643 };
644 
645 
646 // Provide specializations of GraphTraits to be able to treat a function as a
647 // graph of basic blocks... and to walk it in inverse order.  Inverse order for
648 // a function is considered to be when traversing the predecessor edges of a BB
649 // instead of the successor edges.
650 //
651 template <> struct GraphTraits<Inverse<MachineFunction*> > :
652   public GraphTraits<Inverse<MachineBasicBlock*> > {
653   static NodeType *getEntryNode(Inverse<MachineFunction*> G) {
654     return &G.Graph->front();
655   }
656 };
657 template <> struct GraphTraits<Inverse<const MachineFunction*> > :
658   public GraphTraits<Inverse<const MachineBasicBlock*> > {
659   static NodeType *getEntryNode(Inverse<const MachineFunction *> G) {
660     return &G.Graph->front();
661   }
662 };
663 
664 } // End llvm namespace
665 
666 #endif
667