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
18
class MachineBasicBlock;
19
class MachineFunction;
22
class MachineRegisterInfo;
23
class TargetInstrInfo;
24
class TargetRegisterClass;
25
template<typename T> class SmallVectorImpl;
27
/// MachineSSAUpdater - This class updates SSA form for a set of virtual
28
/// registers defined in multiple blocks. This is used when code duplication
29
/// or another unstructured transformation wants to rewrite a set of uses of one
30
/// vreg with uses of a set of vregs.
31
class MachineSSAUpdater {
32
/// AvailableVals - This keeps track of which value to use on a per-block
33
/// basis. When we insert PHI nodes, we keep track of them here.
34
//typedef DenseMap<MachineBasicBlock*, unsigned > AvailableValsTy;
37
/// IncomingPredInfo - We use this as scratch space when doing our recursive
38
/// walk. This should only be used in GetValueInBlockInternal, normally it
40
//std::vector<std::pair<MachineBasicBlock*, unsigned > > IncomingPredInfo;
43
/// VR - Current virtual register whose uses are being updated.
46
/// VRC - Register class of the current virtual register.
47
const TargetRegisterClass *VRC;
49
/// InsertedPHIs - If this is non-null, the MachineSSAUpdater adds all PHI
50
/// nodes that it creates to the vector.
51
SmallVectorImpl<MachineInstr*> *InsertedPHIs;
53
const TargetInstrInfo *TII;
54
MachineRegisterInfo *MRI;
56
/// MachineSSAUpdater constructor. If InsertedPHIs is specified, it will be
57
/// filled in with all PHI Nodes created by rewriting.
58
explicit MachineSSAUpdater(MachineFunction &MF,
59
SmallVectorImpl<MachineInstr*> *InsertedPHIs = 0);
62
/// Initialize - Reset this object to get ready for a new set of SSA
64
void Initialize(unsigned V);
66
/// AddAvailableValue - Indicate that a rewritten value is available at the
67
/// end of the specified block with the specified value.
68
void AddAvailableValue(MachineBasicBlock *BB, unsigned V);
70
/// HasValueForBlock - Return true if the MachineSSAUpdater already has a
71
/// value for the specified block.
72
bool HasValueForBlock(MachineBasicBlock *BB) const;
74
/// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
75
/// live at the end of the specified block.
76
unsigned GetValueAtEndOfBlock(MachineBasicBlock *BB);
78
/// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
79
/// is live in the middle of the specified block.
81
/// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one
82
/// important case: if there is a definition of the rewritten value after the
83
/// 'use' in BB. Consider code like this:
89
/// br Cond, SomeBB, OutBB
91
/// In this case, there are two values (X1 and X2) added to the AvailableVals
92
/// set by the client of the rewriter, and those values are both live out of
93
/// their respective blocks. However, the use of X happens in the *middle* of
94
/// a block. Because of this, we need to insert a new PHI node in SomeBB to
95
/// merge the appropriate values, and this value isn't live out of the block.
97
unsigned GetValueInMiddleOfBlock(MachineBasicBlock *BB);
99
/// RewriteUse - Rewrite a use of the symbolic value. This handles PHI nodes,
100
/// which use their value in the corresponding predecessor. Note that this
101
/// will not work if the use is supposed to be rewritten to a value defined in
102
/// the same block as the use, but above it. Any 'AddAvailableValue's added
103
/// for the use's block will be considered to be below it.
104
void RewriteUse(MachineOperand &U);
107
void ReplaceRegWith(unsigned OldReg, unsigned NewReg);
108
unsigned GetValueAtEndOfBlockInternal(MachineBasicBlock *BB);
109
void operator=(const MachineSSAUpdater&); // DO NOT IMPLEMENT
110
MachineSSAUpdater(const MachineSSAUpdater&); // DO NOT IMPLEMENT
113
} // End llvm namespace