Emit debug info for byval parameters.
[oota-llvm.git] / include / llvm / CodeGen / MachineSSAUpdater.h
1 //===-- MachineSSAUpdater.h - Unstructured SSA Update Tool ------*- 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 // This file declares the MachineSSAUpdater class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CODEGEN_MACHINESSAUPDATER_H
15 #define LLVM_CODEGEN_MACHINESSAUPDATER_H
16
17 namespace llvm {
18   class MachineBasicBlock;
19   class MachineFunction;
20   class MachineInstr;
21   class MachineOperand;
22   class MachineRegisterInfo;
23   class TargetInstrInfo;
24   class TargetRegisterClass;
25   template<typename T> class SmallVectorImpl;
26   class BumpPtrAllocator;
27
28 /// MachineSSAUpdater - This class updates SSA form for a set of virtual
29 /// registers defined in multiple blocks.  This is used when code duplication
30 /// or another unstructured transformation wants to rewrite a set of uses of one
31 /// vreg with uses of a set of vregs.
32 class MachineSSAUpdater {
33 public:
34   class BBInfo;
35   typedef SmallVectorImpl<BBInfo*> BlockListTy;
36
37 private:
38   /// AvailableVals - This keeps track of which value to use on a per-block
39   /// basis.  When we insert PHI nodes, we keep track of them here.
40   //typedef DenseMap<MachineBasicBlock*, unsigned > AvailableValsTy;
41   void *AV;
42
43   /// BBMap - The GetValueAtEndOfBlock method maintains this mapping from
44   /// basic blocks to BBInfo structures.
45   /// typedef DenseMap<MachineBasicBlock*, BBInfo*> BBMapTy;
46   void *BM;
47
48   /// VR - Current virtual register whose uses are being updated.
49   unsigned VR;
50
51   /// VRC - Register class of the current virtual register.
52   const TargetRegisterClass *VRC;
53
54   /// InsertedPHIs - If this is non-null, the MachineSSAUpdater adds all PHI
55   /// nodes that it creates to the vector.
56   SmallVectorImpl<MachineInstr*> *InsertedPHIs;
57
58   const TargetInstrInfo *TII;
59   MachineRegisterInfo *MRI;
60 public:
61   /// MachineSSAUpdater constructor.  If InsertedPHIs is specified, it will be
62   /// filled in with all PHI Nodes created by rewriting.
63   explicit MachineSSAUpdater(MachineFunction &MF,
64                              SmallVectorImpl<MachineInstr*> *InsertedPHIs = 0);
65   ~MachineSSAUpdater();
66
67   /// Initialize - Reset this object to get ready for a new set of SSA
68   /// updates.
69   void Initialize(unsigned V);
70
71   /// AddAvailableValue - Indicate that a rewritten value is available at the
72   /// end of the specified block with the specified value.
73   void AddAvailableValue(MachineBasicBlock *BB, unsigned V);
74
75   /// HasValueForBlock - Return true if the MachineSSAUpdater already has a
76   /// value for the specified block.
77   bool HasValueForBlock(MachineBasicBlock *BB) const;
78
79   /// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
80   /// live at the end of the specified block.
81   unsigned GetValueAtEndOfBlock(MachineBasicBlock *BB);
82
83   /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
84   /// is live in the middle of the specified block.
85   ///
86   /// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one
87   /// important case: if there is a definition of the rewritten value after the
88   /// 'use' in BB.  Consider code like this:
89   ///
90   ///      X1 = ...
91   ///   SomeBB:
92   ///      use(X)
93   ///      X2 = ...
94   ///      br Cond, SomeBB, OutBB
95   ///
96   /// In this case, there are two values (X1 and X2) added to the AvailableVals
97   /// set by the client of the rewriter, and those values are both live out of
98   /// their respective blocks.  However, the use of X happens in the *middle* of
99   /// a block.  Because of this, we need to insert a new PHI node in SomeBB to
100   /// merge the appropriate values, and this value isn't live out of the block.
101   ///
102   unsigned GetValueInMiddleOfBlock(MachineBasicBlock *BB);
103
104   /// RewriteUse - Rewrite a use of the symbolic value.  This handles PHI nodes,
105   /// which use their value in the corresponding predecessor.  Note that this
106   /// will not work if the use is supposed to be rewritten to a value defined in
107   /// the same block as the use, but above it.  Any 'AddAvailableValue's added
108   /// for the use's block will be considered to be below it.
109   void RewriteUse(MachineOperand &U);
110
111 private:
112   void ReplaceRegWith(unsigned OldReg, unsigned NewReg);
113   unsigned GetValueAtEndOfBlockInternal(MachineBasicBlock *BB);
114   void BuildBlockList(MachineBasicBlock *BB, BlockListTy *BlockList,
115                       BumpPtrAllocator *Allocator);
116   void FindDominators(BlockListTy *BlockList);
117   void FindPHIPlacement(BlockListTy *BlockList);
118   void FindAvailableVals(BlockListTy *BlockList);
119   void FindExistingPHI(MachineBasicBlock *BB, BlockListTy *BlockList);
120   bool CheckIfPHIMatches(MachineInstr *PHI);
121   void RecordMatchingPHI(MachineInstr *PHI);
122
123   void operator=(const MachineSSAUpdater&); // DO NOT IMPLEMENT
124   MachineSSAUpdater(const MachineSSAUpdater&);     // DO NOT IMPLEMENT
125 };
126
127 } // End llvm namespace
128
129 #endif