LLVM  14.0.0git
MachineSSAUpdater.h
Go to the documentation of this file.
1 //===- MachineSSAUpdater.h - Unstructured SSA Update Tool -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the MachineSSAUpdater class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CODEGEN_MACHINESSAUPDATER_H
14 #define LLVM_CODEGEN_MACHINESSAUPDATER_H
15 
16 #include "llvm/CodeGen/Register.h"
17 
18 namespace llvm {
19 
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*, Register> AvailableValsTy;
41  void *AV = nullptr;
42 
43  /// VRC - Register class of the current virtual register.
44  const TargetRegisterClass *VRC;
45 
46  /// InsertedPHIs - If this is non-null, the MachineSSAUpdater adds all PHI
47  /// nodes that it creates to the vector.
48  SmallVectorImpl<MachineInstr*> *InsertedPHIs;
49 
50  const TargetInstrInfo *TII;
52 
53 public:
54  /// MachineSSAUpdater constructor. If InsertedPHIs is specified, it will be
55  /// filled in with all PHI Nodes created by rewriting.
57  SmallVectorImpl<MachineInstr*> *NewPHI = nullptr);
58  MachineSSAUpdater(const MachineSSAUpdater &) = delete;
61 
62  /// Initialize - Reset this object to get ready for a new set of SSA
63  /// updates.
64  void Initialize(Register V);
65  void Initialize(const TargetRegisterClass *RC);
66 
67  /// AddAvailableValue - Indicate that a rewritten value is available at the
68  /// end of the specified block with the specified value.
70 
71  /// HasValueForBlock - Return true if the MachineSSAUpdater already has a
72  /// value for the specified block.
74 
75  /// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
76  /// live at the end of the specified block.
78 
79  /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
80  /// is live in the middle of the specified block. If ExistingValueOnly is
81  /// true then this will only return an existing value or $noreg; otherwise new
82  /// instructions may be inserted to materialize a value.
83  ///
84  /// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one
85  /// important case: if there is a definition of the rewritten value after the
86  /// 'use' in BB. Consider code like this:
87  ///
88  /// X1 = ...
89  /// SomeBB:
90  /// use(X)
91  /// X2 = ...
92  /// br Cond, SomeBB, OutBB
93  ///
94  /// In this case, there are two values (X1 and X2) added to the AvailableVals
95  /// set by the client of the rewriter, and those values are both live out of
96  /// their respective blocks. However, the use of X happens in the *middle* of
97  /// a block. Because of this, we need to insert a new PHI node in SomeBB to
98  /// merge the appropriate values, and this value isn't live out of the block.
100  bool ExistingValueOnly = false);
101 
102  /// RewriteUse - Rewrite a use of the symbolic value. This handles PHI nodes,
103  /// which use their value in the corresponding predecessor. Note that this
104  /// will not work if the use is supposed to be rewritten to a value defined in
105  /// the same block as the use, but above it. Any 'AddAvailableValue's added
106  /// for the use's block will be considered to be below it.
107  void RewriteUse(MachineOperand &U);
108 
109 private:
110  // If ExistingValueOnly is true, will not create any new instructions. Used
111  // for debug values, which cannot modify Codegen.
112  Register GetValueAtEndOfBlockInternal(MachineBasicBlock *BB,
113  bool ExistingValueOnly = false);
114 };
115 
116 } // end namespace llvm
117 
118 #endif // LLVM_CODEGEN_MACHINESSAUPDATER_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::MachineSSAUpdater::operator=
MachineSSAUpdater & operator=(const MachineSSAUpdater &)=delete
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition: TargetInstrInfo.h:97
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:129
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineSSAUpdater::~MachineSSAUpdater
~MachineSSAUpdater()
Definition: MachineSSAUpdater.cpp:48
llvm::MachineSSAUpdater::MachineSSAUpdater
MachineSSAUpdater(MachineFunction &MF, SmallVectorImpl< MachineInstr * > *NewPHI=nullptr)
MachineSSAUpdater constructor.
Definition: MachineSSAUpdater.cpp:43
llvm::MachineSSAUpdater::HasValueForBlock
bool HasValueForBlock(MachineBasicBlock *BB) const
HasValueForBlock - Return true if the MachineSSAUpdater already has a value for the specified block.
Definition: MachineSSAUpdater.cpp:69
llvm::MachineFunction
Definition: MachineFunction.h:241
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::MachineSSAUpdater::GetValueAtEndOfBlock
Register GetValueAtEndOfBlock(MachineBasicBlock *BB)
GetValueAtEndOfBlock - Construct SSA form, materializing a value that is live at the end of the speci...
Definition: MachineSSAUpdater.cpp:81
llvm::MachineSSAUpdater::RewriteUse
void RewriteUse(MachineOperand &U)
RewriteUse - Rewrite a use of the symbolic value.
Definition: MachineSSAUpdater.cpp:234
llvm::SSAUpdaterTraits
Definition: MachineSSAUpdater.h:28
llvm::MachineSSAUpdater::GetValueInMiddleOfBlock
Register GetValueInMiddleOfBlock(MachineBasicBlock *BB, bool ExistingValueOnly=false)
GetValueInMiddleOfBlock - Construct SSA form, materializing a value that is live in the middle of the...
Definition: MachineSSAUpdater.cpp:148
llvm::MachineSSAUpdater
MachineSSAUpdater - This class updates SSA form for a set of virtual registers defined in multiple bl...
Definition: MachineSSAUpdater.h:34
llvm::SmallVectorImpl< MachineInstr * >
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::MachineSSAUpdater::AddAvailableValue
void AddAvailableValue(MachineBasicBlock *BB, Register V)
AddAvailableValue - Indicate that a rewritten value is available at the end of the specified block wi...
Definition: MachineSSAUpdater.cpp:75
Register.h
llvm::MachineSSAUpdater::Initialize
void Initialize(Register V)
Initialize - Reset this object to get ready for a new set of SSA updates.
Definition: MachineSSAUpdater.cpp:63