LLVM 23.0.0git
AggressiveAntiDepBreaker.h
Go to the documentation of this file.
1//==- llvm/CodeGen/AggressiveAntiDepBreaker.h - Anti-Dep Support -*- 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 implements the AggressiveAntiDepBreaker class, which
10// implements register anti-dependence breaking during post-RA
11// scheduling. It attempts to break all anti-dependencies within a
12// block.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_CODEGEN_AGGRESSIVEANTIDEPBREAKER_H
17#define LLVM_LIB_CODEGEN_AGGRESSIVEANTIDEPBREAKER_H
18
19#include "llvm/ADT/BitVector.h"
23#include <map>
24#include <set>
25#include <vector>
26
27namespace llvm {
28
30class MachineFunction;
31class MachineInstr;
32class MachineOperand;
35class TargetInstrInfo;
36class MCRegisterClass;
39
40 /// Contains all the state necessary for anti-dep breaking.
42 public:
43 /// Information about a register reference within a liverange
45 /// The registers operand
47
48 /// The register class
50 };
51
52 private:
53 /// Number of non-virtual target registers (i.e. TRI->getNumRegs()).
54 const unsigned NumTargetRegs;
55
56 /// Implements a disjoint-union data structure to
57 /// form register groups. A node is represented by an index into
58 /// the vector. A node can "point to" itself to indicate that it
59 /// is the parent of a group, or point to another node to indicate
60 /// that it is a member of the same group as that node.
61 std::vector<unsigned> GroupNodes;
62
63 /// For each register, the index of the GroupNode
64 /// currently representing the group that the register belongs to.
65 /// Register 0 is always represented by the 0 group, a group
66 /// composed of registers that are not eligible for anti-aliasing.
67 std::vector<unsigned> GroupNodeIndices;
68
69 /// Map registers to all their references within a live range.
70 std::multimap<MCRegister, RegisterReference> RegRefs;
71
72 /// The index of the most recent kill (proceeding bottom-up),
73 /// or ~0u if the register is not live.
74 std::vector<unsigned> KillIndices;
75
76 /// The index of the most recent complete def (proceeding bottom
77 /// up), or ~0u if the register is live.
78 std::vector<unsigned> DefIndices;
79
80 public:
81 AggressiveAntiDepState(const unsigned TargetRegs, MachineBasicBlock *BB);
82
83 /// Return the kill indices.
84 std::vector<unsigned> &GetKillIndices() { return KillIndices; }
85
86 /// Return the define indices.
87 std::vector<unsigned> &GetDefIndices() { return DefIndices; }
88
89 /// Return the RegRefs map.
90 std::multimap<MCRegister, RegisterReference> &GetRegRefs() {
91 return RegRefs;
92 }
93
94 // Get the group for a register. The returned value is
95 // the index of the GroupNode representing the group.
96 unsigned GetGroup(MCRegister Reg);
97
98 // Return a vector of the registers belonging to a group.
99 // If RegRefs is non-NULL then only included referenced registers.
100 void GetGroupRegs(
101 unsigned Group, std::vector<MCRegister> &Regs,
102 std::multimap<MCRegister, AggressiveAntiDepState::RegisterReference>
103 *RegRefs);
104
105 // Union Reg1's and Reg2's groups to form a new group.
106 // Return the index of the GroupNode representing the group.
107 unsigned UnionGroups(MCRegister Reg1, MCRegister Reg2);
108
109 // Remove a register from its current group and place
110 // it alone in its own group. Return the index of the GroupNode
111 // representing the registers new group.
112 unsigned LeaveGroup(MCRegister Reg);
113
114 /// Return true if Reg is live.
115 bool IsLive(MCRegister Reg);
116 };
117
119 : public AntiDepBreaker {
120 MachineFunction &MF;
122 const TargetInstrInfo *TII;
123 const TargetRegisterInfo *TRI;
124 const RegisterClassInfo &RegClassInfo;
125
126 /// The set of registers that should only be
127 /// renamed if they are on the critical path.
128 BitVector CriticalPathSet;
129
130 /// The state used to identify and rename anti-dependence registers.
131 AggressiveAntiDepState *State = nullptr;
132
133 public:
135 const RegisterClassInfo &RCI,
136 TargetSubtargetInfo::RegClassVector& CriticalPathRCs);
138 operator=(const AggressiveAntiDepBreaker &other) = delete;
140 ~AggressiveAntiDepBreaker() override;
141
142 /// Initialize anti-dep breaking for a new basic block.
143 void StartBlock(MachineBasicBlock *BB) override;
144
145 /// Identifiy anti-dependencies along the critical path
146 /// of the ScheduleDAG and break them by renaming registers.
147 unsigned BreakAntiDependencies(const std::vector<SUnit> &SUnits,
150 unsigned InsertPosIndex,
151 DbgValueVector &DbgValues) override;
152
153 /// Update liveness information to account for the current
154 /// instruction, which will not be scheduled.
155 void Observe(MachineInstr &MI, unsigned Count,
156 unsigned InsertPosIndex) override;
157
158 /// Finish anti-dep breaking for a basic block.
159 void FinishBlock() override;
160
161 private:
162 /// Keep track of a position in the allocation order for each regclass.
163 using RenameOrderType = std::map<const TargetRegisterClass *, unsigned>;
164
165 /// Return true if MO represents a register
166 /// that is both implicitly used and defined in MI
167 bool IsImplicitDefUse(MachineInstr &MI, MachineOperand &MO);
168
169 /// If MI implicitly def/uses a register, then
170 /// return that register and all subregisters.
171 void GetPassthruRegs(MachineInstr &MI, std::set<MCRegister> &PassthruRegs);
172
173 void HandleLastUse(MCRegister Reg, unsigned KillIdx, const char *tag,
174 const char *header = nullptr,
175 const char *footer = nullptr);
176
177 void PrescanInstruction(MachineInstr &MI, unsigned Count,
178 const std::set<MCRegister> &PassthruRegs);
179 void ScanInstruction(MachineInstr &MI, unsigned Count);
180 BitVector GetRenameRegisters(MCRegister Reg);
181 bool FindSuitableFreeRegisters(MCRegister SuperReg,
182 unsigned AntiDepGroupIndex,
183 RenameOrderType &RenameOrder,
184 std::map<MCRegister, MCRegister> &RenameMap);
185 };
186
187} // end namespace llvm
188
189#endif // LLVM_LIB_CODEGEN_AGGRESSIVEANTIDEPBREAKER_H
This file implements the BitVector class.
#define LLVM_LIBRARY_VISIBILITY
Definition Compiler.h:137
IRTranslator LLVM IR MI
Register Reg
void Observe(MachineInstr &MI, unsigned Count, unsigned InsertPosIndex) override
Update liveness information to account for the current instruction, which will not be scheduled.
AggressiveAntiDepBreaker & operator=(const AggressiveAntiDepBreaker &other)=delete
AggressiveAntiDepBreaker(const AggressiveAntiDepBreaker &other)=delete
void FinishBlock() override
Finish anti-dep breaking for a basic block.
unsigned BreakAntiDependencies(const std::vector< SUnit > &SUnits, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, unsigned InsertPosIndex, DbgValueVector &DbgValues) override
Identifiy anti-dependencies along the critical path of the ScheduleDAG and break them by renaming reg...
void StartBlock(MachineBasicBlock *BB) override
Initialize anti-dep breaking for a new basic block.
AggressiveAntiDepBreaker(MachineFunction &MFi, const RegisterClassInfo &RCI, TargetSubtargetInfo::RegClassVector &CriticalPathRCs)
Contains all the state necessary for anti-dep breaking.
AggressiveAntiDepState(const unsigned TargetRegs, MachineBasicBlock *BB)
std::vector< unsigned > & GetDefIndices()
Return the define indices.
std::vector< unsigned > & GetKillIndices()
Return the kill indices.
std::multimap< MCRegister, RegisterReference > & GetRegRefs()
Return the RegRefs map.
This class works in conjunction with the post-RA scheduler to rename registers to break register anti...
std::vector< std::pair< MachineInstr *, MachineInstr * > > DbgValueVector
MCRegisterClass - Base class of TargetRegisterClass.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
SmallVectorImpl< const TargetRegisterClass * > RegClassVector
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
Information about a register reference within a liverange.
MachineOperand * Operand
The registers operand.
const TargetRegisterClass * RC
The register class.