LLVM 23.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
18
19namespace llvm {
20
22class MachineFunction;
23class MachineInstr;
24class MachineOperand;
26class TargetInstrInfo;
27class MCRegisterClass;
29template<typename T> class SmallVectorImpl;
30template<typename T> class SSAUpdaterTraits;
31
32/// MachineSSAUpdater - This class updates SSA form for a set of virtual
33/// registers defined in multiple blocks. This is used when code duplication
34/// or another unstructured transformation wants to rewrite a set of uses of one
35/// vreg with uses of a set of vregs.
38
39private:
40 /// AvailableVals - This keeps track of which value to use on a per-block
41 /// basis. When we insert PHI nodes, we keep track of them here.
42 //typedef DenseMap<MachineBasicBlock*, Register> AvailableValsTy;
43 void *AV = nullptr;
44
45 /// Register class or bank and LLT of current virtual register.
47
48 /// InsertedPHIs - If this is non-null, the MachineSSAUpdater adds all PHI
49 /// nodes that it creates to the vector.
51
52 const TargetInstrInfo *TII = nullptr;
53 MachineRegisterInfo *MRI = nullptr;
54
55public:
56 /// MachineSSAUpdater constructor. If InsertedPHIs is specified, it will be
57 /// filled in with all PHI Nodes created by rewriting.
63
64 /// Initialize - Reset this object to get ready for a new set of SSA
65 /// updates.
67
68 /// AddAvailableValue - Indicate that a rewritten value is available at the
69 /// end of the specified block with the specified value.
71
72 /// HasValueForBlock - Return true if the MachineSSAUpdater already has a
73 /// value for the specified block.
75
76 /// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
77 /// live at the end of the specified block.
79
80 /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
81 /// is live in the middle of the specified block. If ExistingValueOnly is
82 /// true then this will only return an existing value or $noreg; otherwise new
83 /// instructions may be inserted to materialize a value.
84 ///
85 /// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one
86 /// important case: if there is a definition of the rewritten value after the
87 /// 'use' in BB. Consider code like this:
88 ///
89 /// X1 = ...
90 /// SomeBB:
91 /// use(X)
92 /// X2 = ...
93 /// br Cond, SomeBB, OutBB
94 ///
95 /// In this case, there are two values (X1 and X2) added to the AvailableVals
96 /// set by the client of the rewriter, and those values are both live out of
97 /// their respective blocks. However, the use of X happens in the *middle* of
98 /// a block. Because of this, we need to insert a new PHI node in SomeBB to
99 /// merge the appropriate values, and this value isn't live out of the block.
101 bool ExistingValueOnly = false);
102
103 /// RewriteUse - Rewrite a use of the symbolic value. This handles PHI nodes,
104 /// which use their value in the corresponding predecessor. Note that this
105 /// will not work if the use is supposed to be rewritten to a value defined in
106 /// the same block as the use, but above it. Any 'AddAvailableValue's added
107 /// for the use's block will be considered to be below it.
109
110private:
111 // If ExistingValueOnly is true, will not create any new instructions. Used
112 // for debug values, which cannot modify Codegen.
113 Register GetValueAtEndOfBlockInternal(MachineBasicBlock *BB,
114 bool ExistingValueOnly = false);
115};
116
117} // end namespace llvm
118
119#endif // LLVM_CODEGEN_MACHINESSAUPDATER_H
#define LLVM_ABI
Definition Compiler.h:215
MCRegisterClass - Base class of TargetRegisterClass.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI void Initialize(Register V)
Initialize - Reset this object to get ready for a new set of SSA updates.
LLVM_ABI Register GetValueInMiddleOfBlock(MachineBasicBlock *BB, bool ExistingValueOnly=false)
GetValueInMiddleOfBlock - Construct SSA form, materializing a value that is live in the middle of the...
MachineSSAUpdater(const MachineSSAUpdater &)=delete
LLVM_ABI void RewriteUse(MachineOperand &U)
RewriteUse - Rewrite a use of the symbolic value.
MachineSSAUpdater & operator=(const MachineSSAUpdater &)=delete
LLVM_ABI Register GetValueAtEndOfBlock(MachineBasicBlock *BB)
GetValueAtEndOfBlock - Construct SSA form, materializing a value that is live at the end of the speci...
LLVM_ABI void AddAvailableValue(MachineBasicBlock *BB, Register V)
AddAvailableValue - Indicate that a rewritten value is available at the end of the specified block wi...
LLVM_ABI bool HasValueForBlock(MachineBasicBlock *BB) const
HasValueForBlock - Return true if the MachineSSAUpdater already has a value for the specified block.
LLVM_ABI MachineSSAUpdater(MachineFunction &MF, SmallVectorImpl< MachineInstr * > *NewPHI=nullptr)
MachineSSAUpdater constructor.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
TargetInstrInfo - Interface to description of machine instruction set.
This is an optimization pass for GlobalISel generic memory operations.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
All attributes(register class or bank and low-level type) a virtual register can have.