1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===-- llvm/CodeGen/MachineFunction.h --------------------------*- C++ -*-===//
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//                     The LLVM Compiler Infrastructure
4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details.
7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Collect native machine code for a function.  This class contains a list of
11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// MachineBasicBlock instances that make up the current compiled function.
12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This class also contains pointers to various classes which hold
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// target-specific information about the generated code.
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_CODEGEN_MACHINEFUNCTION_H
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/CodeGen/MachineBasicBlock.h"
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/ADT/ilist.h"
23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/DebugLoc.h"
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/Allocator.h"
25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/Recycler.h"
26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm {
28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass Value;
30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass Function;
3119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanclass GCModuleInfo;
32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MachineRegisterInfo;
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MachineFrameInfo;
34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MachineConstantPool;
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MachineJumpTableInfo;
36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MachineModuleInfo;
37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MCContext;
38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass Pass;
39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass TargetMachine;
40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass TargetRegisterClass;
4119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanstruct MachinePointerInfo;
42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumantemplate <>
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanstruct ilist_traits<MachineBasicBlock>
45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    : public ilist_default_traits<MachineBasicBlock> {
46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  mutable ilist_half_node<MachineBasicBlock> Sentinel;
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic:
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineBasicBlock *createSentinel() const {
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return static_cast<MachineBasicBlock*>(&Sentinel);
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void destroySentinel(MachineBasicBlock *) const {}
52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineBasicBlock *provideInitialHead() const { return createSentinel(); }
54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineBasicBlock *ensureHead(MachineBasicBlock*) const {
55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return createSentinel();
56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static void noteHead(MachineBasicBlock*, MachineBasicBlock*) {}
58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void addNodeToList(MachineBasicBlock* MBB);
60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void removeNodeFromList(MachineBasicBlock* MBB);
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void deleteNode(MachineBasicBlock *MBB);
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanprivate:
63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void createNode(const MachineBasicBlock &);
64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
66894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// MachineFunctionInfo - This class can be derived from and used by targets to
67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// hold private target-specific information for each MachineFunction.  Objects
68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// of type are accessed/created with MF::getInfo and destroyed when the
69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// MachineFunction is destroyed.
70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanstruct MachineFunctionInfo {
71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual ~MachineFunctionInfo();
72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass MachineFunction {
75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const Function *Fn;
76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const TargetMachine &Target;
77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MCContext &Ctx;
78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineModuleInfo &MMI;
7919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  GCModuleInfo *GMI;
80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // RegInfo - Information about each register in use in the function.
82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineRegisterInfo *RegInfo;
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Used to keep track of target-specific per-machine function information for
85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // the target implementation.
86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineFunctionInfo *MFInfo;
87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
88894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Keep track of objects allocated on the stack.
89894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineFrameInfo *FrameInfo;
90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Keep track of constants which are spilled to memory
92894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineConstantPool *ConstantPool;
93894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Keep track of jump tables for switch instructions
95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineJumpTableInfo *JumpTableInfo;
96894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Function-level unique numbering for MachineBasicBlocks.  When a
98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // MachineBasicBlock is inserted into a MachineFunction is it automatically
99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // numbered and this vector keeps track of the mapping from ID's to MBB's.
100894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  std::vector<MachineBasicBlock*> MBBNumbering;
101894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Pool-allocate MachineFunction-lifetime and IR objects.
103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  BumpPtrAllocator Allocator;
104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Allocation management for instructions in function.
106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  Recycler<MachineInstr> InstructionRecycler;
107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Allocation management for basic blocks in function.
109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  Recycler<MachineBasicBlock> BasicBlockRecycler;
110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // List of machine basic blocks in function
112894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  typedef ilist<MachineBasicBlock> BasicBlockListType;
113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  BasicBlockListType BasicBlocks;
114894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// FunctionNumber - This provides a unique ID for each function emitted in
116894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// this translation unit.
117894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
118894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned FunctionNumber;
119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// Alignment - The alignment of the function.
121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned Alignment;
122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// CallsSetJmp - True if the function calls setjmp or sigsetjmp. This is used
124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// to limit optimizations which cannot reason about the control flow of
125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// setjmp.
126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool CallsSetJmp;
127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineFunction(const MachineFunction &); // DO NOT IMPLEMENT
129894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void operator=(const MachineFunction&);   // DO NOT IMPLEMENT
130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic:
131894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineFunction(const Function *Fn, const TargetMachine &TM,
13219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                  unsigned FunctionNum, MachineModuleInfo &MMI,
13319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                  GCModuleInfo* GMI);
134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ~MachineFunction();
135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineModuleInfo &getMMI() const { return MMI; }
13719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  GCModuleInfo *getGMI() const { return GMI; }
138894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MCContext &getContext() const { return Ctx; }
139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
140894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getFunction - Return the LLVM function that this machine code represents
141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
142894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const Function *getFunction() const { return Fn; }
143894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getFunctionNumber - Return a unique ID for the current function.
145894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned getFunctionNumber() const { return FunctionNumber; }
147894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getTarget - Return the target machine this machine code is compiled with
149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const TargetMachine &getTarget() const { return Target; }
151894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getRegInfo - Return information about the registers currently in use.
153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
154894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineRegisterInfo &getRegInfo() { return *RegInfo; }
155894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const MachineRegisterInfo &getRegInfo() const { return *RegInfo; }
156894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
157894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getFrameInfo - Return the frame info object for the current function.
158894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// This object contains information about objects allocated on the stack
159894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// frame of the current function in an abstract way.
160894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
161894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineFrameInfo *getFrameInfo() { return FrameInfo; }
162894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
163894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
164894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getJumpTableInfo - Return the jump table info object for the current
165894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// function.  This object contains information about jump tables in the
166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// current function.  If the current function has no jump tables, this will
167894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// return null.
168894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; }
169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineJumpTableInfo *getJumpTableInfo() { return JumpTableInfo; }
170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
171894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it
172894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// does already exist, allocate one.
173894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineJumpTableInfo *getOrCreateJumpTableInfo(unsigned JTEntryKind);
174894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
175894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
176894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getConstantPool - Return the constant pool object for the current
177894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// function.
178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineConstantPool *getConstantPool() { return ConstantPool; }
180894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const MachineConstantPool *getConstantPool() const { return ConstantPool; }
181894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
182894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getAlignment - Return the alignment (log2, not bytes) of the function.
183894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned getAlignment() const { return Alignment; }
185894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// setAlignment - Set the alignment (log2, not bytes) of the function.
187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setAlignment(unsigned A) { Alignment = A; }
189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
190894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// EnsureAlignment - Make sure the function is at least 'A' bits aligned.
191894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void EnsureAlignment(unsigned A) {
192894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    if (Alignment < A) Alignment = A;
193894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
194894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
195894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// callsSetJmp - Returns true if the function calls setjmp or sigsetjmp.
196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool callsSetJmp() const {
197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return CallsSetJmp;
198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// setCallsSetJmp - Set a flag that indicates if there's a call to setjmp or
201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// sigsetjmp.
202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void setCallsSetJmp(bool B) {
203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    CallsSetJmp = B;
204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
205894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
206894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getInfo - Keep track of various per-function pieces of information for
207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// backends that would like to do so.
208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  template<typename Ty>
210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  Ty *getInfo() {
211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    if (!MFInfo) {
212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        // This should be just `new (Allocator.Allocate<Ty>()) Ty(*this)', but
213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        // that apparently breaks GCC 3.3.
214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        Ty *Loc = static_cast<Ty*>(Allocator.Allocate(sizeof(Ty),
215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                                      AlignOf<Ty>::Alignment));
216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        MFInfo = new (Loc) Ty(*this);
217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
218894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return static_cast<Ty*>(MFInfo);
219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  template<typename Ty>
222894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const Ty *getInfo() const {
223894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
224894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
225894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
226894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they
227894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// are inserted into the machine function.  The block number for a machine
228894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// basic block can be found by using the MBB::getBlockNumber method, this
229894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// method provides the inverse mapping.
230894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
231894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineBasicBlock *getBlockNumbered(unsigned N) const {
232894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(N < MBBNumbering.size() && "Illegal block number");
233894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(MBBNumbering[N] && "Block was removed from the machine function!");
234894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return MBBNumbering[N];
235894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
236894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
237894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getNumBlockIDs - Return the number of MBB ID's allocated.
238894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
239894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned getNumBlockIDs() const { return (unsigned)MBBNumbering.size(); }
240894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
241894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and
242894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// recomputes them.  This guarantees that the MBB numbers are sequential,
243894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// dense, and match the ordering of the blocks within the function.  If a
244894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// specific MachineBasicBlock is specified, only that block and those after
245894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// it are renumbered.
246894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void RenumberBlocks(MachineBasicBlock *MBBFrom = 0);
247894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
248894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// print - Print out the MachineFunction in a format suitable for debugging
249894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// to the specified stream.
250894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
25119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  void print(raw_ostream &OS, SlotIndexes* = 0) const;
252894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
253894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// viewCFG - This function is meant for use from the debugger.  You can just
254894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// say 'call F->viewCFG()' and a ghostview window should pop up from the
255894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// program, displaying the CFG of the current function with the code for each
256894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// basic block inside.  This depends on there being a 'dot' and 'gv' program
257894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// in your path.
258894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
259894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void viewCFG() const;
260894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
261894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// viewCFGOnly - This function is meant for use from the debugger.  It works
262894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// just like viewCFG, but it does not include the contents of basic blocks
263894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// into the nodes, just the label.  If you are only interested in the CFG
264894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// this can make the graph smaller.
265894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
266894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void viewCFGOnly() const;
267894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
268894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// dump - Print the current MachineFunction to cerr, useful for debugger use.
269894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
270894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void dump() const;
271894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
272894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// verify - Run the current MachineFunction through the machine code
273894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// verifier, useful for debugger use.
27419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  void verify(Pass *p = NULL, const char *Banner = NULL) const;
275894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
276894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Provide accessors for the MachineBasicBlock list...
277894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  typedef BasicBlockListType::iterator iterator;
278894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  typedef BasicBlockListType::const_iterator const_iterator;
279894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
280894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  typedef std::reverse_iterator<iterator>             reverse_iterator;
281894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
282894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// addLiveIn - Add the specified physical register as a live-in value and
283894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// create a corresponding virtual register for it.
284894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC);
285894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
286894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
287894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // BasicBlock accessor functions.
288894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //
289894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  iterator                 begin()       { return BasicBlocks.begin(); }
290894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const_iterator           begin() const { return BasicBlocks.begin(); }
291894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  iterator                 end  ()       { return BasicBlocks.end();   }
292894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const_iterator           end  () const { return BasicBlocks.end();   }
293894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
294894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  reverse_iterator        rbegin()       { return BasicBlocks.rbegin(); }
295894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const_reverse_iterator  rbegin() const { return BasicBlocks.rbegin(); }
296894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  reverse_iterator        rend  ()       { return BasicBlocks.rend();   }
297894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const_reverse_iterator  rend  () const { return BasicBlocks.rend();   }
298894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
299894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned                  size() const { return (unsigned)BasicBlocks.size();}
300894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool                     empty() const { return BasicBlocks.empty(); }
301894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const MachineBasicBlock &front() const { return BasicBlocks.front(); }
302894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        MachineBasicBlock &front()       { return BasicBlocks.front(); }
303894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const MachineBasicBlock & back() const { return BasicBlocks.back(); }
304894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        MachineBasicBlock & back()       { return BasicBlocks.back(); }
305894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
306894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void push_back (MachineBasicBlock *MBB) { BasicBlocks.push_back (MBB); }
307894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void push_front(MachineBasicBlock *MBB) { BasicBlocks.push_front(MBB); }
308894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void insert(iterator MBBI, MachineBasicBlock *MBB) {
309894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    BasicBlocks.insert(MBBI, MBB);
310894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
311894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void splice(iterator InsertPt, iterator MBBI) {
312894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    BasicBlocks.splice(InsertPt, BasicBlocks, MBBI);
313894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
314894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void splice(iterator InsertPt, iterator MBBI, iterator MBBE) {
315894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    BasicBlocks.splice(InsertPt, BasicBlocks, MBBI, MBBE);
316894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
317894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
318894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void remove(iterator MBBI) {
319894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    BasicBlocks.remove(MBBI);
320894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
321894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void erase(iterator MBBI) {
322894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    BasicBlocks.erase(MBBI);
323894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
324894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
325894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
326894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Internal functions used to automatically number MachineBasicBlocks
327894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //
328894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
329894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getNextMBBNumber - Returns the next unique number to be assigned
330894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// to a MachineBasicBlock in this MachineFunction.
331894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
332894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned addToMBBNumbering(MachineBasicBlock *MBB) {
333894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MBBNumbering.push_back(MBB);
334894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return (unsigned)MBBNumbering.size()-1;
335894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
336894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
337894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// removeFromMBBNumbering - Remove the specific machine basic block from our
338894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// tracker, this is only really to be used by the MachineBasicBlock
339894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// implementation.
340894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void removeFromMBBNumbering(unsigned N) {
341894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    assert(N < MBBNumbering.size() && "Illegal basic block #");
342894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MBBNumbering[N] = 0;
343894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
344894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
345894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead
346894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// of `new MachineInstr'.
347894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
34819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  MachineInstr *CreateMachineInstr(const MCInstrDesc &MCID,
349894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                   DebugLoc DL,
350894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                   bool NoImp = false);
351894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
352894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// CloneMachineInstr - Create a new MachineInstr which is a copy of the
353894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// 'Orig' instruction, identical in all ways except the instruction
354894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// has no parent, prev, or next.
355894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
356894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// See also TargetInstrInfo::duplicate() for target-specific fixes to cloned
357894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// instructions.
358894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineInstr *CloneMachineInstr(const MachineInstr *Orig);
359894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
360894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// DeleteMachineInstr - Delete the given MachineInstr.
361894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
362894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void DeleteMachineInstr(MachineInstr *MI);
363894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
364894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this
365894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// instead of `new MachineBasicBlock'.
366894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
367894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineBasicBlock *CreateMachineBasicBlock(const BasicBlock *bb = 0);
368894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
369894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
370894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
371894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void DeleteMachineBasicBlock(MachineBasicBlock *MBB);
372894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
373894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getMachineMemOperand - Allocate a new MachineMemOperand.
374894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// MachineMemOperands are owned by the MachineFunction and need not be
375894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// explicitly deallocated.
37619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  MachineMemOperand *getMachineMemOperand(MachinePointerInfo PtrInfo,
37719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                                          unsigned f, uint64_t s,
37819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                                          unsigned base_alignment,
37919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                                          const MDNode *TBAAInfo = 0);
38019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
381894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getMachineMemOperand - Allocate a new MachineMemOperand by copying
382894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// an existing one, adjusting by an offset and using the given size.
383894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// MachineMemOperands are owned by the MachineFunction and need not be
384894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// explicitly deallocated.
385894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
386894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                          int64_t Offset, uint64_t Size);
387894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
388894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// allocateMemRefsArray - Allocate an array to hold MachineMemOperand
389894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// pointers.  This array is owned by the MachineFunction.
390894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num);
391894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
392894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// extractLoadMemRefs - Allocate an array and populate it with just the
393894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// load information from the given MachineMemOperand sequence.
394894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  std::pair<MachineInstr::mmo_iterator,
395894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman            MachineInstr::mmo_iterator>
396894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    extractLoadMemRefs(MachineInstr::mmo_iterator Begin,
397894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                       MachineInstr::mmo_iterator End);
398894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
399894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// extractStoreMemRefs - Allocate an array and populate it with just the
400894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// store information from the given MachineMemOperand sequence.
401894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  std::pair<MachineInstr::mmo_iterator,
402894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman            MachineInstr::mmo_iterator>
403894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    extractStoreMemRefs(MachineInstr::mmo_iterator Begin,
404894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                        MachineInstr::mmo_iterator End);
405894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
406894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //===--------------------------------------------------------------------===//
407894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Label Manipulation.
408894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //
409894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
410894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
411894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
412894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// normal 'L' label is returned.
413894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx,
414894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                         bool isLinkerPrivate = false) const;
41519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
41619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// getPICBaseSymbol - Return a function-local symbol to represent the PIC
41719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// base.
41819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  MCSymbol *getPICBaseSymbol() const;
419894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
420894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
421894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===--------------------------------------------------------------------===//
422894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// GraphTraits specializations for function basic block graphs (CFGs)
423894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===--------------------------------------------------------------------===//
424894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
425894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Provide specializations of GraphTraits to be able to treat a
426894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// machine function as a graph of machine basic blocks... these are
427894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// the same as the machine basic block iterators, except that the root
428894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// node is implicitly the first node of the function.
429894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
430894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumantemplate <> struct GraphTraits<MachineFunction*> :
431894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  public GraphTraits<MachineBasicBlock*> {
432894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static NodeType *getEntryNode(MachineFunction *F) {
433894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return &F->front();
434894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
435894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
436894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
437894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  typedef MachineFunction::iterator nodes_iterator;
438894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static nodes_iterator nodes_begin(MachineFunction *F) { return F->begin(); }
439894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static nodes_iterator nodes_end  (MachineFunction *F) { return F->end(); }
440894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
441894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumantemplate <> struct GraphTraits<const MachineFunction*> :
442894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  public GraphTraits<const MachineBasicBlock*> {
443894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static NodeType *getEntryNode(const MachineFunction *F) {
444894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return &F->front();
445894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
446894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
447894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
448894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  typedef MachineFunction::const_iterator nodes_iterator;
449894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static nodes_iterator nodes_begin(const MachineFunction *F) {
450894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return F->begin();
451894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
452894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static nodes_iterator nodes_end  (const MachineFunction *F) {
453894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return F->end();
454894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
455894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
456894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
457894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
458894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Provide specializations of GraphTraits to be able to treat a function as a
459894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// graph of basic blocks... and to walk it in inverse order.  Inverse order for
460894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// a function is considered to be when traversing the predecessor edges of a BB
461894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// instead of the successor edges.
462894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
463894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumantemplate <> struct GraphTraits<Inverse<MachineFunction*> > :
464894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  public GraphTraits<Inverse<MachineBasicBlock*> > {
465894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static NodeType *getEntryNode(Inverse<MachineFunction*> G) {
466894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return &G.Graph->front();
467894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
468894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
469894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumantemplate <> struct GraphTraits<Inverse<const MachineFunction*> > :
470894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  public GraphTraits<Inverse<const MachineBasicBlock*> > {
471894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static NodeType *getEntryNode(Inverse<const MachineFunction *> G) {
472894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    return &G.Graph->front();
473894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  }
474894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
475894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
476894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // End llvm namespace
477894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
478894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif
479