MachineFunction.h revision c76909abfec876c6b751d693ebd3df07df686aa0
19c6342d0cc919711ea1024b98b1b387573995922Chris Lattner//===-- llvm/CodeGen/MachineFunction.h --------------------------*- C++ -*-===//
2ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//                     The LLVM Compiler Infrastructure
46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//
57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source
67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details.
7ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===//
9ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
10cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner// Collect native machine code for a function.  This class contains a list of
11cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner// MachineBasicBlock instances that make up the current compiled function.
12cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner//
13cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner// This class also contains pointers to various classes which hold
14cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner// target-specific information about the generated code.
15ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
16f2868ce228ca20f72d1c6fbe241de01975cfe609Chris Lattner//===----------------------------------------------------------------------===//
17f2868ce228ca20f72d1c6fbe241de01975cfe609Chris Lattner
18fce1143bcfa73f61845002fa50473d1a01384202Misha Brukman#ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
19fce1143bcfa73f61845002fa50473d1a01384202Misha Brukman#define LLVM_CODEGEN_MACHINEFUNCTION_H
20f2868ce228ca20f72d1c6fbe241de01975cfe609Chris Lattner
212d8e3d20be377112999670f210200b3658762571Chris Lattner#include "llvm/CodeGen/MachineBasicBlock.h"
22fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman#include "llvm/ADT/ilist.h"
231e86a66b00b94adc4ad6977ef6b47c516ac62cecDevang Patel#include "llvm/Support/DebugLoc.h"
248e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman#include "llvm/Support/Allocator.h"
258e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman#include "llvm/Support/Recycler.h"
262d8e3d20be377112999670f210200b3658762571Chris Lattner#include <map>
278e7ae9860bd1f29c95e4e10fe151a22aaafafef9Chris Lattner
28d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
29d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
30c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohmanclass Value;
318bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattnerclass Function;
3284bc5427d6883f73cfeae3da640acd011d35c006Chris Lattnerclass MachineRegisterInfo;
338bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattnerclass MachineFrameInfo;
348bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattnerclass MachineConstantPool;
3537efe6764568a3829fee26aba532283131d1a104Nate Begemanclass MachineJumpTableInfo;
36d0adbb5b7da2d1238fdf1a30734a001a0103aab0Evan Chengclass TargetMachine;
37998e125a87d49f28c714d8223a37746850401057Bob Wilsonclass TargetRegisterClass;
388bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner
39792699c46ef9bfc47dd459bbfa7e71bcb2cee29aTanya Lattnertemplate <>
408e4018e2de52c534405d7155c7009d0b35afb861Cedric Venetstruct ilist_traits<MachineBasicBlock>
41fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman    : public ilist_default_traits<MachineBasicBlock> {
427309be6735666143bd9835b275dc8501617a2591Gabor Greif  mutable ilist_half_node<MachineBasicBlock> Sentinel;
43792699c46ef9bfc47dd459bbfa7e71bcb2cee29aTanya Lattnerpublic:
44c7f6b8c5d40e17bf43fd3a1549d7d89c9da735e1Gabor Greif  MachineBasicBlock *createSentinel() const {
45c7f6b8c5d40e17bf43fd3a1549d7d89c9da735e1Gabor Greif    return static_cast<MachineBasicBlock*>(&Sentinel);
46c7f6b8c5d40e17bf43fd3a1549d7d89c9da735e1Gabor Greif  }
47fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  void destroySentinel(MachineBasicBlock *) const {}
48fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
49c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  MachineBasicBlock *provideInitialHead() const { return createSentinel(); }
50c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  MachineBasicBlock *ensureHead(MachineBasicBlock*) const {
51c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif    return createSentinel();
52c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  }
53f3841fcbd587c31aa9842b3f33bd57de40c9f443Gabor Greif  static void noteHead(MachineBasicBlock*, MachineBasicBlock*) {}
54c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif
558e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void addNodeToList(MachineBasicBlock* MBB);
568e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void removeNodeFromList(MachineBasicBlock* MBB);
578e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void deleteNode(MachineBasicBlock *MBB);
58fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanprivate:
59fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  void createNode(const MachineBasicBlock &);
60792699c46ef9bfc47dd459bbfa7e71bcb2cee29aTanya Lattner};
61792699c46ef9bfc47dd459bbfa7e71bcb2cee29aTanya Lattner
628bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner/// MachineFunctionInfo - This class can be derived from and used by targets to
638bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner/// hold private target-specific information for each MachineFunction.  Objects
648bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner/// of type are accessed/created with MF::getInfo and destroyed when the
658bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner/// MachineFunction is destroyed.
668bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattnerstruct MachineFunctionInfo {
67a70e2e3d4831b8a39ea6bae5c62df29fa82a86f3Chris Lattner  virtual ~MachineFunctionInfo();
688bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner};
69f2868ce228ca20f72d1c6fbe241de01975cfe609Chris Lattner
70f266f89634363cb067a5b43cbe33f79c4397c08cDan Gohmanclass MachineFunction {
71ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman  Function *Fn;
72335d5c399b52c2507ad11048310edc51462f4811Chris Lattner  const TargetMachine &Target;
738e7ae9860bd1f29c95e4e10fe151a22aaafafef9Chris Lattner
7484bc5427d6883f73cfeae3da640acd011d35c006Chris Lattner  // RegInfo - Information about each register in use in the function.
7584bc5427d6883f73cfeae3da640acd011d35c006Chris Lattner  MachineRegisterInfo *RegInfo;
7603ab7af4dec01a3003e469c458e37bbf4ce4f2f3Chris Lattner
778bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner  // Used to keep track of target-specific per-machine function information for
788bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner  // the target implementation.
798bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner  MachineFunctionInfo *MFInfo;
80cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner
81cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner  // Keep track of objects allocated on the stack.
82aa09b75d2257545c4583265c7ce10f2d0e3be72bChris Lattner  MachineFrameInfo *FrameInfo;
831617e6c9974813030c8294243bf9e152f89ffd9bMisha Brukman
8440a75577ea6b4fb9cc92780ca0caa21604246b1bChris Lattner  // Keep track of constants which are spilled to memory
8540a75577ea6b4fb9cc92780ca0caa21604246b1bChris Lattner  MachineConstantPool *ConstantPool;
8637efe6764568a3829fee26aba532283131d1a104Nate Begeman
8737efe6764568a3829fee26aba532283131d1a104Nate Begeman  // Keep track of jump tables for switch instructions
8837efe6764568a3829fee26aba532283131d1a104Nate Begeman  MachineJumpTableInfo *JumpTableInfo;
8940a75577ea6b4fb9cc92780ca0caa21604246b1bChris Lattner
9025d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  // Function-level unique numbering for MachineBasicBlocks.  When a
9125d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  // MachineBasicBlock is inserted into a MachineFunction is it automatically
9225d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  // numbered and this vector keeps track of the mapping from ID's to MBB's.
9325d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  std::vector<MachineBasicBlock*> MBBNumbering;
94f460f1679e8ac1935220e1878fd97cf44f093659Brian Gaeke
958e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  // Pool-allocate MachineFunction-lifetime and IR objects.
968e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  BumpPtrAllocator Allocator;
978e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
988e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  // Allocation management for instructions in function.
998e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  Recycler<MachineInstr> InstructionRecycler;
1008e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
1018e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  // Allocation management for basic blocks in function.
1028e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  Recycler<MachineBasicBlock> BasicBlockRecycler;
1038e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
1048e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  // List of machine basic blocks in function
105fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  typedef ilist<MachineBasicBlock> BasicBlockListType;
1068e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  BasicBlockListType BasicBlocks;
1078e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
1085d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling  // Default debug location. Used to print out the debug label at the beginning
1095d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling  // of a function.
1105d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling  DebugLoc DefaultDebugLoc;
1115d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling
112d0adbb5b7da2d1238fdf1a30734a001a0103aab0Evan Cheng  // Tracks debug locations.
113d0adbb5b7da2d1238fdf1a30734a001a0103aab0Evan Cheng  DebugLocTracker DebugLocInfo;
114d0adbb5b7da2d1238fdf1a30734a001a0103aab0Evan Cheng
11520c568f366be211323eeaf0e45ef053278ec9ddcBill Wendling  // The alignment of the function.
11620c568f366be211323eeaf0e45ef053278ec9ddcBill Wendling  unsigned Alignment;
11720c568f366be211323eeaf0e45ef053278ec9ddcBill Wendling
118f2868ce228ca20f72d1c6fbe241de01975cfe609Chris Lattnerpublic:
119ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman  MachineFunction(Function *Fn, const TargetMachine &TM);
12003ab7af4dec01a3003e469c458e37bbf4ce4f2f3Chris Lattner  ~MachineFunction();
121335d5c399b52c2507ad11048310edc51462f4811Chris Lattner
122335d5c399b52c2507ad11048310edc51462f4811Chris Lattner  /// getFunction - Return the LLVM function that this machine code represents
123335d5c399b52c2507ad11048310edc51462f4811Chris Lattner  ///
124ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman  Function *getFunction() const { return Fn; }
125335d5c399b52c2507ad11048310edc51462f4811Chris Lattner
126335d5c399b52c2507ad11048310edc51462f4811Chris Lattner  /// getTarget - Return the target machine this machine code is compiled with
127335d5c399b52c2507ad11048310edc51462f4811Chris Lattner  ///
128335d5c399b52c2507ad11048310edc51462f4811Chris Lattner  const TargetMachine &getTarget() const { return Target; }
129dea73839f69b004314d223f75d136551132108ccChris Lattner
13084bc5427d6883f73cfeae3da640acd011d35c006Chris Lattner  /// getRegInfo - Return information about the registers currently in use.
131cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner  ///
1328e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineRegisterInfo &getRegInfo() { return *RegInfo; }
1338e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  const MachineRegisterInfo &getRegInfo() const { return *RegInfo; }
134cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner
135cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner  /// getFrameInfo - Return the frame info object for the current function.
136cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner  /// This object contains information about objects allocated on the stack
137cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner  /// frame of the current function in an abstract way.
138cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner  ///
1398e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineFrameInfo *getFrameInfo() { return FrameInfo; }
1408e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  const MachineFrameInfo *getFrameInfo() const { return FrameInfo; }
141cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner
14237efe6764568a3829fee26aba532283131d1a104Nate Begeman  /// getJumpTableInfo - Return the jump table info object for the current
14337efe6764568a3829fee26aba532283131d1a104Nate Begeman  /// function.  This object contains information about jump tables for switch
14437efe6764568a3829fee26aba532283131d1a104Nate Begeman  /// instructions in the current function.
14537efe6764568a3829fee26aba532283131d1a104Nate Begeman  ///
1468e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineJumpTableInfo *getJumpTableInfo() { return JumpTableInfo; }
1478e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  const MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; }
14837efe6764568a3829fee26aba532283131d1a104Nate Begeman
14940a75577ea6b4fb9cc92780ca0caa21604246b1bChris Lattner  /// getConstantPool - Return the constant pool object for the current
15040a75577ea6b4fb9cc92780ca0caa21604246b1bChris Lattner  /// function.
151274ba03f49e78ccb5670292a8cab53009dcca896Misha Brukman  ///
1528e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineConstantPool *getConstantPool() { return ConstantPool; }
1538e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  const MachineConstantPool *getConstantPool() const { return ConstantPool; }
15440a75577ea6b4fb9cc92780ca0caa21604246b1bChris Lattner
155b4202b84d7e54efe5e144885c7da63e6cc465f80Bill Wendling  /// getAlignment - Return the alignment (log2, not bytes) of the function.
15620c568f366be211323eeaf0e45ef053278ec9ddcBill Wendling  ///
15720c568f366be211323eeaf0e45ef053278ec9ddcBill Wendling  unsigned getAlignment() const { return Alignment; }
15820c568f366be211323eeaf0e45ef053278ec9ddcBill Wendling
159b4202b84d7e54efe5e144885c7da63e6cc465f80Bill Wendling  /// setAlignment - Set the alignment (log2, not bytes) of the function.
16020c568f366be211323eeaf0e45ef053278ec9ddcBill Wendling  ///
16120c568f366be211323eeaf0e45ef053278ec9ddcBill Wendling  void setAlignment(unsigned A) { Alignment = A; }
16220c568f366be211323eeaf0e45ef053278ec9ddcBill Wendling
163a70e2e3d4831b8a39ea6bae5c62df29fa82a86f3Chris Lattner  /// getInfo - Keep track of various per-function pieces of information for
164a70e2e3d4831b8a39ea6bae5c62df29fa82a86f3Chris Lattner  /// backends that would like to do so.
165cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner  ///
1668bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner  template<typename Ty>
1678bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner  Ty *getInfo() {
168219c7905c503ece263bb755479edc16430870e83Dan Gohman    if (!MFInfo) {
169219c7905c503ece263bb755479edc16430870e83Dan Gohman        // This should be just `new (Allocator.Allocate<Ty>()) Ty(*this)', but
170219c7905c503ece263bb755479edc16430870e83Dan Gohman        // that apparently breaks GCC 3.3.
171219c7905c503ece263bb755479edc16430870e83Dan Gohman        Ty *Loc = static_cast<Ty*>(Allocator.Allocate(sizeof(Ty),
172219c7905c503ece263bb755479edc16430870e83Dan Gohman                                                      AlignOf<Ty>::Alignment));
173219c7905c503ece263bb755479edc16430870e83Dan Gohman        MFInfo = new (Loc) Ty(*this);
174219c7905c503ece263bb755479edc16430870e83Dan Gohman    }
1758bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner
1768bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner    assert((void*)dynamic_cast<Ty*>(MFInfo) == (void*)MFInfo &&
1778bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner           "Invalid concrete type or multiple inheritence for getInfo");
1788bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner    return static_cast<Ty*>(MFInfo);
1798bdf87d1d8abde45c40b2698dd9af8407007281cChris Lattner  }
180cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner
1815ea64fd9eb0027ad20a66ea29211eef79d8842a0Chris Lattner  template<typename Ty>
1825ea64fd9eb0027ad20a66ea29211eef79d8842a0Chris Lattner  const Ty *getInfo() const {
1835ea64fd9eb0027ad20a66ea29211eef79d8842a0Chris Lattner     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
1845ea64fd9eb0027ad20a66ea29211eef79d8842a0Chris Lattner  }
1855ea64fd9eb0027ad20a66ea29211eef79d8842a0Chris Lattner
18625d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they
18725d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  /// are inserted into the machine function.  The block number for a machine
18825d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  /// basic block can be found by using the MBB::getBlockNumber method, this
18925d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  /// method provides the inverse mapping.
190274ba03f49e78ccb5670292a8cab53009dcca896Misha Brukman  ///
19120683f94809ef74c11ea7ef6215405fd0dd18e3aJakob Stoklund Olesen  MachineBasicBlock *getBlockNumbered(unsigned N) const {
19225d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner    assert(N < MBBNumbering.size() && "Illegal block number");
19325d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner    assert(MBBNumbering[N] && "Block was removed from the machine function!");
19425d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner    return MBBNumbering[N];
19525d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  }
196cd0d1d1f0f44773b5c4bb57f557e6187891ff1d5Chris Lattner
1972540813e5d583fdc40458a53badb323ae5d83a07Chris Lattner  /// getNumBlockIDs - Return the number of MBB ID's allocated.
198e70cab0ca4d7835c8e1e0ee6a125be8f2790a136Chris Lattner  ///
19934cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng  unsigned getNumBlockIDs() const { return (unsigned)MBBNumbering.size(); }
200f5395cee6a24699a016b2e379cf4804b09ce5030Jim Laskey
201e70cab0ca4d7835c8e1e0ee6a125be8f2790a136Chris Lattner  /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and
202e70cab0ca4d7835c8e1e0ee6a125be8f2790a136Chris Lattner  /// recomputes them.  This guarantees that the MBB numbers are sequential,
203e70cab0ca4d7835c8e1e0ee6a125be8f2790a136Chris Lattner  /// dense, and match the ordering of the blocks within the function.  If a
204e70cab0ca4d7835c8e1e0ee6a125be8f2790a136Chris Lattner  /// specific MachineBasicBlock is specified, only that block and those after
205e70cab0ca4d7835c8e1e0ee6a125be8f2790a136Chris Lattner  /// it are renumbered.
206e70cab0ca4d7835c8e1e0ee6a125be8f2790a136Chris Lattner  void RenumberBlocks(MachineBasicBlock *MBBFrom = 0);
207e70cab0ca4d7835c8e1e0ee6a125be8f2790a136Chris Lattner
208dea73839f69b004314d223f75d136551132108ccChris Lattner  /// print - Print out the MachineFunction in a format suitable for debugging
209dea73839f69b004314d223f75d136551132108ccChris Lattner  /// to the specified stream.
210dea73839f69b004314d223f75d136551132108ccChris Lattner  ///
2111d7fb4eae53c7ec5f9c5c18d603b50dfb9425862Chris Lattner  void print(raw_ostream &OS) const;
212dea73839f69b004314d223f75d136551132108ccChris Lattner
21371bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  /// viewCFG - This function is meant for use from the debugger.  You can just
21471bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  /// say 'call F->viewCFG()' and a ghostview window should pop up from the
21571bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  /// program, displaying the CFG of the current function with the code for each
21671bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  /// basic block inside.  This depends on there being a 'dot' and 'gv' program
21771bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  /// in your path.
21871bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  ///
21971bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  void viewCFG() const;
220ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
22171bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  /// viewCFGOnly - This function is meant for use from the debugger.  It works
22271bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  /// just like viewCFG, but it does not include the contents of basic blocks
22371bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  /// into the nodes, just the label.  If you are only interested in the CFG
22471bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  /// this can make the graph smaller.
22571bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  ///
22671bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  void viewCFGOnly() const;
22771bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos
228dea73839f69b004314d223f75d136551132108ccChris Lattner  /// dump - Print the current MachineFunction to cerr, useful for debugger use.
229dea73839f69b004314d223f75d136551132108ccChris Lattner  ///
230dea73839f69b004314d223f75d136551132108ccChris Lattner  void dump() const;
231dea73839f69b004314d223f75d136551132108ccChris Lattner
232d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  // Provide accessors for the MachineBasicBlock list...
233d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  typedef BasicBlockListType::iterator iterator;
234d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  typedef BasicBlockListType::const_iterator const_iterator;
235d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
236d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  typedef std::reverse_iterator<iterator>             reverse_iterator;
237d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner
238998e125a87d49f28c714d8223a37746850401057Bob Wilson  /// addLiveIn - Add the specified physical register as a live-in value and
239998e125a87d49f28c714d8223a37746850401057Bob Wilson  /// create a corresponding virtual register for it.
240998e125a87d49f28c714d8223a37746850401057Bob Wilson  unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC);
241998e125a87d49f28c714d8223a37746850401057Bob Wilson
242d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  //===--------------------------------------------------------------------===//
2438e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  // BasicBlock accessor functions.
244d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  //
245d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  iterator                 begin()       { return BasicBlocks.begin(); }
246d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  const_iterator           begin() const { return BasicBlocks.begin(); }
247d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  iterator                 end  ()       { return BasicBlocks.end();   }
248d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  const_iterator           end  () const { return BasicBlocks.end();   }
249d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner
250d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  reverse_iterator        rbegin()       { return BasicBlocks.rbegin(); }
251d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  const_reverse_iterator  rbegin() const { return BasicBlocks.rbegin(); }
252d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  reverse_iterator        rend  ()       { return BasicBlocks.rend();   }
253d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  const_reverse_iterator  rend  () const { return BasicBlocks.rend();   }
2549c6342d0cc919711ea1024b98b1b387573995922Chris Lattner
25534cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng  unsigned                  size() const { return (unsigned)BasicBlocks.size();}
256d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  bool                     empty() const { return BasicBlocks.empty(); }
257d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner  const MachineBasicBlock &front() const { return BasicBlocks.front(); }
258d0aa0cdbc6fee00f2b2019633a9b9d00d301ac68Chris Lattner        MachineBasicBlock &front()       { return BasicBlocks.front(); }
259d5806ffb40899aca4f3c23442645ed0ef4fa390fMisha Brukman  const MachineBasicBlock & back() const { return BasicBlocks.back(); }
260d5806ffb40899aca4f3c23442645ed0ef4fa390fMisha Brukman        MachineBasicBlock & back()       { return BasicBlocks.back(); }
26125d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner
2628e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void push_back (MachineBasicBlock *MBB) { BasicBlocks.push_back (MBB); }
2638e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void push_front(MachineBasicBlock *MBB) { BasicBlocks.push_front(MBB); }
2648e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void insert(iterator MBBI, MachineBasicBlock *MBB) {
2658e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman    BasicBlocks.insert(MBBI, MBB);
2668e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  }
2678e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void splice(iterator InsertPt, iterator MBBI) {
2688e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman    BasicBlocks.splice(InsertPt, BasicBlocks, MBBI);
2698e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  }
2708e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
2718e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void remove(iterator MBBI) {
2728e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman    BasicBlocks.remove(MBBI);
2738e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  }
2748e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void erase(iterator MBBI) {
2758e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman    BasicBlocks.erase(MBBI);
2768e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  }
2778e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
27825d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  //===--------------------------------------------------------------------===//
27925d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  // Internal functions used to automatically number MachineBasicBlocks
28025d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  //
28125d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner
28225d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  /// getNextMBBNumber - Returns the next unique number to be assigned
28325d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  /// to a MachineBasicBlock in this MachineFunction.
28425d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  ///
28525d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  unsigned addToMBBNumbering(MachineBasicBlock *MBB) {
28625d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner    MBBNumbering.push_back(MBB);
28734cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng    return (unsigned)MBBNumbering.size()-1;
28825d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  }
28925d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner
29025d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  /// removeFromMBBNumbering - Remove the specific machine basic block from our
29125d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  /// tracker, this is only really to be used by the MachineBasicBlock
29225d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  /// implementation.
29325d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  void removeFromMBBNumbering(unsigned N) {
29425d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner    assert(N < MBBNumbering.size() && "Illegal basic block #");
29525d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner    MBBNumbering[N] = 0;
29625d8039bd6bdb53330c2d0968a5505e42d568048Chris Lattner  }
2978e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
2988e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead
2998e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// of `new MachineInstr'.
3008e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  ///
3018e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineInstr *CreateMachineInstr(const TargetInstrDesc &TID,
3029bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling                                   DebugLoc DL,
3038e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman                                   bool NoImp = false);
3048e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
3058e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// CloneMachineInstr - Create a new MachineInstr which is a copy of the
3068e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// 'Orig' instruction, identical in all ways except the the instruction
3078e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// has no parent, prev, or next.
3088e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  ///
3098e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineInstr *CloneMachineInstr(const MachineInstr *Orig);
3108e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
3118e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// DeleteMachineInstr - Delete the given MachineInstr.
3128e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  ///
3138e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void DeleteMachineInstr(MachineInstr *MI);
3148e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
3158e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this
3168e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// instead of `new MachineBasicBlock'.
3178e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  ///
3188e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  MachineBasicBlock *CreateMachineBasicBlock(const BasicBlock *bb = 0);
3198e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman
3208e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
3218e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  ///
3228e5f2c6f65841542e2a7092553fe42a00048e4c7Dan Gohman  void DeleteMachineBasicBlock(MachineBasicBlock *MBB);
323d0adbb5b7da2d1238fdf1a30734a001a0103aab0Evan Cheng
324c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// getMachineMemOperand - Allocate a new MachineMemOperand.
325c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// MachineMemOperands are owned by the MachineFunction and need not be
326c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// explicitly deallocated.
327c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  MachineMemOperand *getMachineMemOperand(const Value *v, unsigned f,
328c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman                                          int64_t o, uint64_t s,
329c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman                                          unsigned base_alignment);
330c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman
331c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// getMachineMemOperand - Allocate a new MachineMemOperand by copying
332c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// an existing one, adjusting by an offset and using the given EVT.
333c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// MachineMemOperands are owned by the MachineFunction and need not be
334c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// explicitly deallocated.
335c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
336c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman                                          int64_t Offset, uint64_t Size);
337c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman
338c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// allocateMemRefsArray - Allocate an array to hold MachineMemOperand
339c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  /// pointers.  This array is owned by the MachineFunction.
340c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman  MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num);
341c76909abfec876c6b751d693ebd3df07df686aa0Dan Gohman
342d0adbb5b7da2d1238fdf1a30734a001a0103aab0Evan Cheng  //===--------------------------------------------------------------------===//
343d0adbb5b7da2d1238fdf1a30734a001a0103aab0Evan Cheng  // Debug location.
344d0adbb5b7da2d1238fdf1a30734a001a0103aab0Evan Cheng  //
345d0adbb5b7da2d1238fdf1a30734a001a0103aab0Evan Cheng
346aaeea9e64f7c0f45380d323a32501c4da59a2c4dEvan Cheng  /// getOrCreateDebugLocID - Look up the DebugLocTuple index with the given
34785e3af9b70cc48535b3d41049bae907335f184abBill Wendling  /// source file, line, and column. If none currently exists, create a new
34885e3af9b70cc48535b3d41049bae907335f184abBill Wendling  /// DebugLocTuple, and insert it into the DebugIdMap.
349e4b275610a7a05b7ee4c0378a906a6330e4c4ab0Devang Patel  unsigned getOrCreateDebugLocID(MDNode *CompileUnit,
350a26eae64ddf607549f9e47046d46ea5b9ec648b4Argyrios Kyrtzidis                                 unsigned Line, unsigned Col);
35185e3af9b70cc48535b3d41049bae907335f184abBill Wendling
35285e3af9b70cc48535b3d41049bae907335f184abBill Wendling  /// getDebugLocTuple - Get the DebugLocTuple for a given DebugLoc object.
353a929c68bfcbe840bd26d336efaa80a6a275e802cBill Wendling  DebugLocTuple getDebugLocTuple(DebugLoc DL) const;
3545d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling
3555d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling  /// getDefaultDebugLoc - Get the default debug location for the machine
3565d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling  /// function.
3575d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling  DebugLoc getDefaultDebugLoc() const { return DefaultDebugLoc; }
3585d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling
3595d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling  /// setDefaultDebugLoc - Get the default debug location for the machine
3605d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling  /// function.
3615d0f68134e66956242bc93843f56634bfc4df3a8Bill Wendling  void setDefaultDebugLoc(DebugLoc DL) { DefaultDebugLoc = DL; }
3627e1e31f467d87c834d8baf673929865907901313Devang Patel
3637e1e31f467d87c834d8baf673929865907901313Devang Patel  /// getDebugLocInfo - Get the debug info location tracker.
3647e1e31f467d87c834d8baf673929865907901313Devang Patel  DebugLocTracker &getDebugLocInfo() { return DebugLocInfo; }
365f2868ce228ca20f72d1c6fbe241de01975cfe609Chris Lattner};
366f2868ce228ca20f72d1c6fbe241de01975cfe609Chris Lattner
36771bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos//===--------------------------------------------------------------------===//
36871bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos// GraphTraits specializations for function basic block graphs (CFGs)
36971bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos//===--------------------------------------------------------------------===//
37071bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos
37171bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos// Provide specializations of GraphTraits to be able to treat a
37271bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos// machine function as a graph of machine basic blocks... these are
37371bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos// the same as the machine basic block iterators, except that the root
37471bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos// node is implicitly the first node of the function.
37571bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos//
37671bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenostemplate <> struct GraphTraits<MachineFunction*> :
37771bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  public GraphTraits<MachineBasicBlock*> {
37871bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  static NodeType *getEntryNode(MachineFunction *F) {
37971bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos    return &F->front();
38071bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  }
38171bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos
38271bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
38371bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  typedef MachineFunction::iterator nodes_iterator;
38471bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  static nodes_iterator nodes_begin(MachineFunction *F) { return F->begin(); }
38571bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  static nodes_iterator nodes_end  (MachineFunction *F) { return F->end(); }
38671bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos};
38771bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenostemplate <> struct GraphTraits<const MachineFunction*> :
38871bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  public GraphTraits<const MachineBasicBlock*> {
38971bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  static NodeType *getEntryNode(const MachineFunction *F) {
39071bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos    return &F->front();
39171bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  }
39271bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos
39371bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
39471bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  typedef MachineFunction::const_iterator nodes_iterator;
395c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  static nodes_iterator nodes_begin(const MachineFunction *F) {
396c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif    return F->begin();
397c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  }
398c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  static nodes_iterator nodes_end  (const MachineFunction *F) {
399c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif    return F->end();
400c23b8719ef9d6b1220e854b37d40e9e1c48a82bcGabor Greif  }
40171bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos};
40271bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos
40371bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos
404ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman// Provide specializations of GraphTraits to be able to treat a function as a
40571bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos// graph of basic blocks... and to walk it in inverse order.  Inverse order for
40671bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos// a function is considered to be when traversing the predecessor edges of a BB
40771bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos// instead of the successor edges.
40871bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos//
40971bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenostemplate <> struct GraphTraits<Inverse<MachineFunction*> > :
41071bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  public GraphTraits<Inverse<MachineBasicBlock*> > {
41171bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  static NodeType *getEntryNode(Inverse<MachineFunction*> G) {
41271bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos    return &G.Graph->front();
41371bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  }
41471bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos};
41571bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenostemplate <> struct GraphTraits<Inverse<const MachineFunction*> > :
41671bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  public GraphTraits<Inverse<const MachineBasicBlock*> > {
41771bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  static NodeType *getEntryNode(Inverse<const MachineFunction *> G) {
41871bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos    return &G.Graph->front();
41971bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos  }
42071bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos};
42171bf404e9b69122c276ad7ce66f38bf1e57cafebAlkis Evlogimenos
422d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
423d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
424f2868ce228ca20f72d1c6fbe241de01975cfe609Chris Lattner#endif
425