]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/CodeGen/MachineSSAUpdater.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / 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
19 class MachineBasicBlock;
20 class MachineFunction;
21 class MachineInstr;
22 class MachineOperand;
23 class MachineRegisterInfo;
24 class TargetInstrInfo;
25 class TargetRegisterClass;
26 template<typename T> class SmallVectorImpl;
27 template<typename T> class SSAUpdaterTraits;
28
29 /// MachineSSAUpdater - This class updates SSA form for a set of virtual
30 /// registers defined in multiple blocks.  This is used when code duplication
31 /// or another unstructured transformation wants to rewrite a set of uses of one
32 /// vreg with uses of a set of vregs.
33 class MachineSSAUpdater {
34   friend class SSAUpdaterTraits<MachineSSAUpdater>;
35
36 private:
37   /// AvailableVals - This keeps track of which value to use on a per-block
38   /// basis.  When we insert PHI nodes, we keep track of them here.
39   //typedef DenseMap<MachineBasicBlock*, unsigned > AvailableValsTy;
40   void *AV = nullptr;
41
42   /// VR - Current virtual register whose uses are being updated.
43   unsigned VR;
44
45   /// VRC - Register class of the current virtual register.
46   const TargetRegisterClass *VRC;
47
48   /// InsertedPHIs - If this is non-null, the MachineSSAUpdater adds all PHI
49   /// nodes that it creates to the vector.
50   SmallVectorImpl<MachineInstr*> *InsertedPHIs;
51
52   const TargetInstrInfo *TII;
53   MachineRegisterInfo *MRI;
54
55 public:
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*> *NewPHI = nullptr);
60   MachineSSAUpdater(const MachineSSAUpdater &) = delete;
61   MachineSSAUpdater &operator=(const MachineSSAUpdater &) = delete;
62   ~MachineSSAUpdater();
63
64   /// Initialize - Reset this object to get ready for a new set of SSA
65   /// updates.
66   void Initialize(unsigned V);
67
68   /// AddAvailableValue - Indicate that a rewritten value is available at the
69   /// end of the specified block with the specified value.
70   void AddAvailableValue(MachineBasicBlock *BB, unsigned V);
71
72   /// HasValueForBlock - Return true if the MachineSSAUpdater already has a
73   /// value for the specified block.
74   bool HasValueForBlock(MachineBasicBlock *BB) const;
75
76   /// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
77   /// live at the end of the specified block.
78   unsigned GetValueAtEndOfBlock(MachineBasicBlock *BB);
79
80   /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
81   /// is live in the middle of the specified block.
82   ///
83   /// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one
84   /// important case: if there is a definition of the rewritten value after the
85   /// 'use' in BB.  Consider code like this:
86   ///
87   ///      X1 = ...
88   ///   SomeBB:
89   ///      use(X)
90   ///      X2 = ...
91   ///      br Cond, SomeBB, OutBB
92   ///
93   /// In this case, there are two values (X1 and X2) added to the AvailableVals
94   /// set by the client of the rewriter, and those values are both live out of
95   /// their respective blocks.  However, the use of X happens in the *middle* of
96   /// a block.  Because of this, we need to insert a new PHI node in SomeBB to
97   /// merge the appropriate values, and this value isn't live out of the block.
98   unsigned GetValueInMiddleOfBlock(MachineBasicBlock *BB);
99
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);
106
107 private:
108   unsigned GetValueAtEndOfBlockInternal(MachineBasicBlock *BB);
109 };
110
111 } // end namespace llvm
112
113 #endif // LLVM_CODEGEN_MACHINESSAUPDATER_H