Evan Cheng | 651ea53 | 2009-12-02 22:02:52 +0000 | [diff] [blame] | 1 | //===- MachineSSAUpdater.cpp - Unstructured SSA Update Tool ---------------===// |
| 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 implements the MachineSSAUpdater class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/CodeGen/MachineSSAUpdater.h" |
| 15 | #include "llvm/CodeGen/MachineInstr.h" |
| 16 | #include "llvm/ADT/DenseMap.h" |
| 17 | using namespace llvm; |
| 18 | |
| 19 | typedef DenseMap<MachineBasicBlock*, unsigned > AvailableValsTy; |
| 20 | typedef std::vector<std::pair<MachineBasicBlock*, unsigned> > |
| 21 | IncomingPredInfoTy; |
| 22 | |
| 23 | static AvailableValsTy &getAvailableVals(void *AV) { |
| 24 | return *static_cast<AvailableValsTy*>(AV); |
| 25 | } |
| 26 | |
| 27 | static IncomingPredInfoTy &getIncomingPredInfo(void *IPI) { |
| 28 | return *static_cast<IncomingPredInfoTy*>(IPI); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | MachineSSAUpdater::MachineSSAUpdater(SmallVectorImpl<MachineInstr*> *NewPHI) |
| 33 | : AV(0), IPI(0), InsertedPHIs(NewPHI) {} |
| 34 | |
| 35 | MachineSSAUpdater::~MachineSSAUpdater() { |
| 36 | delete &getAvailableVals(AV); |
| 37 | delete &getIncomingPredInfo(IPI); |
| 38 | } |
| 39 | |
| 40 | /// Initialize - Reset this object to get ready for a new set of SSA |
| 41 | /// updates. ProtoValue is the value used to name PHI nodes. |
| 42 | void MachineSSAUpdater::Initialize() { |
| 43 | if (AV == 0) |
| 44 | AV = new AvailableValsTy(); |
| 45 | else |
| 46 | getAvailableVals(AV).clear(); |
| 47 | |
| 48 | if (IPI == 0) |
| 49 | IPI = new IncomingPredInfoTy(); |
| 50 | else |
| 51 | getIncomingPredInfo(IPI).clear(); |
| 52 | } |
| 53 | |
| 54 | /// HasValueForBlock - Return true if the MachineSSAUpdater already has a value for |
| 55 | /// the specified block. |
| 56 | bool MachineSSAUpdater::HasValueForBlock(MachineBasicBlock *BB) const { |
| 57 | return getAvailableVals(AV).count(BB); |
| 58 | } |
| 59 | |
| 60 | /// AddAvailableValue - Indicate that a rewritten value is available in the |
| 61 | /// specified block with the specified value. |
| 62 | void MachineSSAUpdater::AddAvailableValue(MachineBasicBlock *BB, unsigned V) { |
| 63 | getAvailableVals(AV)[BB] = V; |
| 64 | } |
| 65 | |
| 66 | /// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is |
| 67 | /// live at the end of the specified block. |
| 68 | unsigned MachineSSAUpdater::GetValueAtEndOfBlock(MachineBasicBlock *BB) { |
| 69 | return GetValueAtEndOfBlockInternal(BB); |
| 70 | } |
| 71 | |
| 72 | /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that |
| 73 | /// is live in the middle of the specified block. |
| 74 | /// |
| 75 | /// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one |
| 76 | /// important case: if there is a definition of the rewritten value after the |
| 77 | /// 'use' in BB. Consider code like this: |
| 78 | /// |
| 79 | /// X1 = ... |
| 80 | /// SomeBB: |
| 81 | /// use(X) |
| 82 | /// X2 = ... |
| 83 | /// br Cond, SomeBB, OutBB |
| 84 | /// |
| 85 | /// In this case, there are two values (X1 and X2) added to the AvailableVals |
| 86 | /// set by the client of the rewriter, and those values are both live out of |
| 87 | /// their respective blocks. However, the use of X happens in the *middle* of |
| 88 | /// a block. Because of this, we need to insert a new PHI node in SomeBB to |
| 89 | /// merge the appropriate values, and this value isn't live out of the block. |
| 90 | /// |
| 91 | unsigned MachineSSAUpdater::GetValueInMiddleOfBlock(MachineBasicBlock *BB) { |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | /// RewriteUse - Rewrite a use of the symbolic value. This handles PHI nodes, |
| 96 | /// which use their value in the corresponding predecessor. |
| 97 | void MachineSSAUpdater::RewriteUse(unsigned &U) { |
| 98 | } |
| 99 | |
| 100 | |
| 101 | /// GetValueAtEndOfBlockInternal - Check to see if AvailableVals has an entry |
| 102 | /// for the specified BB and if so, return it. If not, construct SSA form by |
| 103 | /// walking predecessors inserting PHI nodes as needed until we get to a block |
| 104 | /// where the value is available. |
| 105 | /// |
| 106 | unsigned MachineSSAUpdater::GetValueAtEndOfBlockInternal(MachineBasicBlock *BB){ |
| 107 | return 0; |
| 108 | } |