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