1 //===-- MachineSSAUpdater.h - Unstructured SSA Update Tool ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the MachineSSAUpdater class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_MACHINESSAUPDATER_H
15 #define LLVM_CODEGEN_MACHINESSAUPDATER_H
17 #include "llvm/Support/Compiler.h"
20 class MachineBasicBlock;
21 class MachineFunction;
24 class MachineRegisterInfo;
25 class TargetInstrInfo;
26 class TargetRegisterClass;
27 template<typename T> class SmallVectorImpl;
28 template<typename T> class SSAUpdaterTraits;
29 class BumpPtrAllocator;
31 /// MachineSSAUpdater - This class updates SSA form for a set of virtual
32 /// registers defined in multiple blocks. This is used when code duplication
33 /// or another unstructured transformation wants to rewrite a set of uses of one
34 /// vreg with uses of a set of vregs.
35 class MachineSSAUpdater {
36 friend class SSAUpdaterTraits<MachineSSAUpdater>;
39 /// AvailableVals - This keeps track of which value to use on a per-block
40 /// basis. When we insert PHI nodes, we keep track of them here.
41 //typedef DenseMap<MachineBasicBlock*, unsigned > AvailableValsTy;
44 /// VR - Current virtual register whose uses are being updated.
47 /// VRC - Register class of the current virtual register.
48 const TargetRegisterClass *VRC;
50 /// InsertedPHIs - If this is non-null, the MachineSSAUpdater adds all PHI
51 /// nodes that it creates to the vector.
52 SmallVectorImpl<MachineInstr*> *InsertedPHIs;
54 const TargetInstrInfo *TII;
55 MachineRegisterInfo *MRI;
57 /// MachineSSAUpdater constructor. If InsertedPHIs is specified, it will be
58 /// filled in with all PHI Nodes created by rewriting.
59 explicit MachineSSAUpdater(MachineFunction &MF,
60 SmallVectorImpl<MachineInstr*> *InsertedPHIs = 0);
63 /// Initialize - Reset this object to get ready for a new set of SSA
65 void Initialize(unsigned V);
67 /// AddAvailableValue - Indicate that a rewritten value is available at the
68 /// end of the specified block with the specified value.
69 void AddAvailableValue(MachineBasicBlock *BB, unsigned V);
71 /// HasValueForBlock - Return true if the MachineSSAUpdater already has a
72 /// value for the specified block.
73 bool HasValueForBlock(MachineBasicBlock *BB) const;
75 /// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
76 /// live at the end of the specified block.
77 unsigned GetValueAtEndOfBlock(MachineBasicBlock *BB);
79 /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
80 /// is live in the middle of the specified block.
82 /// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one
83 /// important case: if there is a definition of the rewritten value after the
84 /// 'use' in BB. Consider code like this:
90 /// br Cond, SomeBB, OutBB
92 /// In this case, there are two values (X1 and X2) added to the AvailableVals
93 /// set by the client of the rewriter, and those values are both live out of
94 /// their respective blocks. However, the use of X happens in the *middle* of
95 /// a block. Because of this, we need to insert a new PHI node in SomeBB to
96 /// merge the appropriate values, and this value isn't live out of the block.
98 unsigned GetValueInMiddleOfBlock(MachineBasicBlock *BB);
100 /// RewriteUse - Rewrite a use of the symbolic value. This handles PHI nodes,
101 /// which use their value in the corresponding predecessor. Note that this
102 /// will not work if the use is supposed to be rewritten to a value defined in
103 /// the same block as the use, but above it. Any 'AddAvailableValue's added
104 /// for the use's block will be considered to be below it.
105 void RewriteUse(MachineOperand &U);
108 void ReplaceRegWith(unsigned OldReg, unsigned NewReg);
109 unsigned GetValueAtEndOfBlockInternal(MachineBasicBlock *BB);
111 void operator=(const MachineSSAUpdater&) LLVM_DELETED_FUNCTION;
112 MachineSSAUpdater(const MachineSSAUpdater&) LLVM_DELETED_FUNCTION;
115 } // End llvm namespace