LLVM  4.0.0
MachineSSAUpdater.h
Go to the documentation of this file.
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 #include "llvm/Support/Compiler.h"
18 
19 namespace llvm {
20  class MachineBasicBlock;
21  class MachineFunction;
22  class MachineInstr;
23  class MachineOperand;
24  class MachineRegisterInfo;
25  class TargetInstrInfo;
26  class TargetRegisterClass;
27  template<typename T> class SmallVectorImpl;
28  template<typename T> class SSAUpdaterTraits;
29 
30 /// MachineSSAUpdater - This class updates SSA form for a set of virtual
31 /// registers defined in multiple blocks. This is used when code duplication
32 /// or another unstructured transformation wants to rewrite a set of uses of one
33 /// vreg with uses of a set of vregs.
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  /// VR - Current virtual register whose uses are being updated.
44  unsigned VR;
45 
46  /// VRC - Register class of the current virtual register.
47  const TargetRegisterClass *VRC;
48 
49  /// InsertedPHIs - If this is non-null, the MachineSSAUpdater adds all PHI
50  /// nodes that it creates to the vector.
51  SmallVectorImpl<MachineInstr*> *InsertedPHIs;
52 
53  const TargetInstrInfo *TII;
55 public:
56  /// MachineSSAUpdater constructor. If InsertedPHIs is specified, it will be
57  /// filled in with all PHI Nodes created by rewriting.
59  SmallVectorImpl<MachineInstr*> *InsertedPHIs = nullptr);
61 
62  /// Initialize - Reset this object to get ready for a new set of SSA
63  /// updates.
64  void Initialize(unsigned V);
65 
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);
69 
70  /// HasValueForBlock - Return true if the MachineSSAUpdater already has a
71  /// value for the specified block.
72  bool HasValueForBlock(MachineBasicBlock *BB) const;
73 
74  /// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
75  /// live at the end of the specified block.
77 
78  /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
79  /// is live in the middle of the specified block.
80  ///
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:
84  ///
85  /// X1 = ...
86  /// SomeBB:
87  /// use(X)
88  /// X2 = ...
89  /// br Cond, SomeBB, OutBB
90  ///
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.
96  ///
98 
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);
105 
106 private:
107  unsigned GetValueAtEndOfBlockInternal(MachineBasicBlock *BB);
108 
109  void operator=(const MachineSSAUpdater&) = delete;
110  MachineSSAUpdater(const MachineSSAUpdater&) = delete;
111 };
112 
113 } // End llvm namespace
114 
115 #endif
void RewriteUse(MachineOperand &U)
RewriteUse - Rewrite a use of the symbolic value.
MachineSSAUpdater - This class updates SSA form for a set of virtual registers defined in multiple bl...
unsigned GetValueAtEndOfBlock(MachineBasicBlock *BB)
GetValueAtEndOfBlock - Construct SSA form, materializing a value that is live at the end of the speci...
const HexagonInstrInfo * TII
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:32
bool HasValueForBlock(MachineBasicBlock *BB) const
HasValueForBlock - Return true if the MachineSSAUpdater already has a value for the specified block...
void Initialize(unsigned V)
Initialize - Reset this object to get ready for a new set of SSA updates.
TargetInstrInfo - Interface to description of machine instruction set.
unsigned const MachineRegisterInfo * MRI
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
unsigned GetValueInMiddleOfBlock(MachineBasicBlock *BB)
GetValueInMiddleOfBlock - Construct SSA form, materializing a value that is live in the middle of the...
void AddAvailableValue(MachineBasicBlock *BB, unsigned V)
AddAvailableValue - Indicate that a rewritten value is available at the end of the specified block wi...
MachineSSAUpdater(MachineFunction &MF, SmallVectorImpl< MachineInstr * > *InsertedPHIs=nullptr)
MachineSSAUpdater constructor.