a785ab8cfaa236279eaebee3dace1ce38e8bef33
[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 MachineInstr;
20   template<typename T> class SmallVectorImpl;
21
22 /// SSAUpdater - This class updates SSA form for a set of values defined in
23 /// multiple blocks.  This is used when code duplication or another unstructured
24 /// transformation wants to rewrite a set of uses of one value with uses of a
25 /// set of values.
26 class MachineSSAUpdater {
27   /// AvailableVals - This keeps track of which value to use on a per-block
28   /// basis.  When we insert PHI nodes, we keep track of them here.
29   //typedef DenseMap<MachineBasicBlock*, unsigned > AvailableValsTy;
30   void *AV;
31
32   /// IncomingPredInfo - We use this as scratch space when doing our recursive
33   /// walk.  This should only be used in GetValueInBlockInternal, normally it
34   /// should be empty.
35   //std::vector<std::pair<MachineBasicBlock*, unsigned > > IncomingPredInfo;
36   void *IPI;
37
38   /// InsertedPHIs - If this is non-null, the MachineSSAUpdater adds all PHI
39   /// nodes that it creates to the vector.
40   SmallVectorImpl<MachineInstr*> *InsertedPHIs;
41 public:
42   /// MachineSSAUpdater constructor.  If InsertedPHIs is specified, it will be
43   /// filled in with all PHI Nodes created by rewriting.
44   explicit MachineSSAUpdater(SmallVectorImpl<MachineInstr*> *InsertedPHIs = 0);
45   ~MachineSSAUpdater();
46
47   /// Initialize - Reset this object to get ready for a new set of SSA
48   /// updates.
49   void Initialize();
50
51   /// AddAvailableValue - Indicate that a rewritten value is available at the
52   /// end of the specified block with the specified value.
53   void AddAvailableValue(MachineBasicBlock *BB, unsigned V);
54
55   /// HasValueForBlock - Return true if the MachineSSAUpdater already has a
56   /// value for the specified block.
57   bool HasValueForBlock(MachineBasicBlock *BB) const;
58
59   /// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
60   /// live at the end of the specified block.
61   unsigned GetValueAtEndOfBlock(MachineBasicBlock *BB);
62
63   /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
64   /// is live in the middle of the specified block.
65   ///
66   /// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one
67   /// important case: if there is a definition of the rewritten value after the
68   /// 'use' in BB.  Consider code like this:
69   ///
70   ///      X1 = ...
71   ///   SomeBB:
72   ///      use(X)
73   ///      X2 = ...
74   ///      br Cond, SomeBB, OutBB
75   ///
76   /// In this case, there are two values (X1 and X2) added to the AvailableVals
77   /// set by the client of the rewriter, and those values are both live out of
78   /// their respective blocks.  However, the use of X happens in the *middle* of
79   /// a block.  Because of this, we need to insert a new PHI node in SomeBB to
80   /// merge the appropriate values, and this value isn't live out of the block.
81   ///
82   unsigned GetValueInMiddleOfBlock(MachineBasicBlock *BB);
83
84   /// RewriteUse - Rewrite a use of the symbolic value.  This handles PHI nodes,
85   /// which use their value in the corresponding predecessor.  Note that this
86   /// will not work if the use is supposed to be rewritten to a value defined in
87   /// the same block as the use, but above it.  Any 'AddAvailableValue's added
88   /// for the use's block will be considered to be below it.
89   void RewriteUse(unsigned &U);
90
91 private:
92   unsigned GetValueAtEndOfBlockInternal(MachineBasicBlock *BB);
93   void operator=(const MachineSSAUpdater&); // DO NOT IMPLEMENT
94   MachineSSAUpdater(const MachineSSAUpdater&);     // DO NOT IMPLEMENT
95 };
96
97 } // End llvm namespace
98
99 #endif