20 #define DEBUG_TYPE "llvm-mca" 28 RegisterMappings(mri.getNumRegs(), {
WriteRef(), RegisterRenamingInfo()}),
29 ZeroRegisters(mri.getNumRegs(),
false) {
30 initialize(SM, NumRegs);
33 void RegisterFile::initialize(
const MCSchedModel &SM,
unsigned NumRegs) {
62 for (RegisterMappingTracker &RMT : RegisterFiles)
63 RMT.NumMoveEliminated = 0;
73 unsigned RegisterFileIndex = RegisterFiles.
size();
90 RegisterRenamingInfo &
Entry = RegisterMappings[
Reg].second;
91 IndexPlusCostPairTy &IPC = Entry.IndexPlusCost;
92 if (IPC.first && IPC.first != RegisterFileIndex) {
97 <<
" defined in multiple register files.";
99 IPC = std::make_pair(RegisterFileIndex, RCE.Cost);
100 Entry.RenameAs =
Reg;
101 Entry.AllowMoveElimination = RCE.AllowMoveElimination;
105 RegisterRenamingInfo &OtherEntry = RegisterMappings[*
I].second;
106 if (!OtherEntry.IndexPlusCost.first &&
107 (!OtherEntry.RenameAs ||
109 OtherEntry.IndexPlusCost = IPC;
110 OtherEntry.RenameAs =
Reg;
117 void RegisterFile::allocatePhysRegs(
const RegisterRenamingInfo &
Entry,
119 unsigned RegisterFileIndex = Entry.IndexPlusCost.first;
120 unsigned Cost = Entry.IndexPlusCost.second;
121 if (RegisterFileIndex) {
122 RegisterMappingTracker &RMT = RegisterFiles[RegisterFileIndex];
123 RMT.NumUsedPhysRegs += Cost;
124 UsedPhysRegs[RegisterFileIndex] += Cost;
128 RegisterFiles[0].NumUsedPhysRegs += Cost;
129 UsedPhysRegs[0] += Cost;
132 void RegisterFile::freePhysRegs(
const RegisterRenamingInfo &Entry,
134 unsigned RegisterFileIndex = Entry.IndexPlusCost.first;
135 unsigned Cost = Entry.IndexPlusCost.second;
136 if (RegisterFileIndex) {
137 RegisterMappingTracker &RMT = RegisterFiles[RegisterFileIndex];
138 RMT.NumUsedPhysRegs -= Cost;
139 FreedPhysRegs[RegisterFileIndex] += Cost;
143 RegisterFiles[0].NumUsedPhysRegs -= Cost;
144 FreedPhysRegs[0] += Cost;
151 assert(RegID &&
"Adding an invalid register definition?");
155 <<
", " << MRI.
getName(RegID) <<
"]\n";
173 bool ShouldAllocatePhysRegs = !IsWriteZero && !IsEliminated;
174 const RegisterRenamingInfo &RRI = RegisterMappings[RegID].second;
175 WS.
setPRF(RRI.IndexPlusCost.first);
177 if (RRI.RenameAs && RRI.RenameAs != RegID) {
178 RegID = RRI.RenameAs;
179 WriteRef &OtherWrite = RegisterMappings[RegID].first;
185 ShouldAllocatePhysRegs =
false;
190 assert(!IsEliminated &&
"Unexpected partial update!");
200 ZeroRegisters.
setBit(ZeroRegisterID);
204 ZeroRegisters.
clearBit(ZeroRegisterID);
213 RegisterMappings[RegID].first = Write;
214 RegisterMappings[RegID].second.AliasRegID = 0U;
216 RegisterMappings[*
I].first = Write;
217 RegisterMappings[*
I].second.AliasRegID = 0U;
223 if (ShouldAllocatePhysRegs)
224 allocatePhysRegs(RegisterMappings[RegID].
second, UsedPhysRegs);
232 RegisterMappings[*
I].first = Write;
233 RegisterMappings[*
I].second.AliasRegID = 0U;
252 assert(RegID != 0 &&
"Invalidating an already invalid register?");
254 "Invalidating a write of unknown cycles!");
258 MCPhysReg RenameAs = RegisterMappings[RegID].second.RenameAs;
259 if (RenameAs && RenameAs != RegID) {
264 ShouldFreePhysRegs =
false;
268 if (ShouldFreePhysRegs)
269 freePhysRegs(RegisterMappings[RegID].
second, FreedPhysRegs);
271 WriteRef &WR = RegisterMappings[RegID].first;
276 WriteRef &OtherWR = RegisterMappings[*
I].first;
285 WriteRef &OtherWR = RegisterMappings[*
I].first;
292 const RegisterMapping &RMFrom = RegisterMappings[RS.
getRegisterID()];
293 const RegisterMapping &RMTo = RegisterMappings[WS.
getRegisterID()];
296 const RegisterRenamingInfo &RRIFrom = RMFrom.second;
297 const RegisterRenamingInfo &RRITo = RMTo.second;
298 unsigned RegisterFileIndex = RRIFrom.IndexPlusCost.first;
299 if (RegisterFileIndex != RRITo.IndexPlusCost.first)
316 if (RRITo.RenameAs && RRITo.RenameAs != WS.
getRegisterID()) {
318 if (!RegisterMappings[RRITo.RenameAs].second.AllowMoveElimination)
324 RegisterMappingTracker &RMT = RegisterFiles[RegisterFileIndex];
325 if (RMT.MaxMoveEliminatedPerCycle &&
326 RMT.NumMoveEliminated == RMT.MaxMoveEliminatedPerCycle)
330 if (RMT.AllowZeroMoveEliminationOnly && !IsZeroMove)
338 const RegisterRenamingInfo &RMAlias = RegisterMappings[AliasedReg].second;
339 if (RMAlias.AliasRegID)
340 AliasedReg = RMAlias.AliasRegID;
342 RegisterMappings[AliasReg].second.AliasRegID = AliasedReg;
344 RegisterMappings[*
I].
second.AliasRegID = AliasedReg;
351 RMT.NumMoveEliminated++;
356 void RegisterFile::collectWrites(
const ReadState &RS,
359 assert(RegID && RegID < RegisterMappings.size());
360 LLVM_DEBUG(
dbgs() <<
"RegisterFile: collecting writes for register " 361 << MRI.
getName(RegID) <<
'\n');
364 const RegisterRenamingInfo &RRI = RegisterMappings[RegID].second;
366 RegID = RRI.AliasRegID;
368 const WriteRef &WR = RegisterMappings[RegID].first;
374 const WriteRef &WR = RegisterMappings[*
I].first;
380 if (Writes.
size() > 1) {
384 auto It = std::unique(Writes.
begin(), Writes.
end());
391 dbgs() <<
"[PRF] Found a dependent use of Register " 401 const RegisterRenamingInfo &RRI = RegisterMappings[RegID].second;
402 RS.
setPRF(RRI.IndexPlusCost.first);
410 collectWrites(RS, DependentWrites);
419 for (
WriteRef &WR : DependentWrites) {
423 WS.
addUser(WR.getSourceIndex(), &RS, ReadAdvance);
432 const RegisterRenamingInfo &RRI = RegisterMappings[RegID].second;
433 const IndexPlusCostPairTy &Entry = RRI.IndexPlusCost;
435 NumPhysRegs[Entry.first] += Entry.second;
436 NumPhysRegs[0] += Entry.second;
439 unsigned Response = 0;
441 unsigned NumRegs = NumPhysRegs[
I];
445 const RegisterMappingTracker &RMT = RegisterFiles[
I];
446 if (!RMT.NumPhysRegs) {
452 if (RMT.NumPhysRegs < NumRegs) {
457 LLVM_DEBUG(
dbgs() <<
"Not enough registers in the register file.\n");
464 NumRegs = RMT.NumPhysRegs;
467 if (RMT.NumPhysRegs < (RMT.NumUsedPhysRegs + NumRegs))
468 Response |= (1U <<
I);
477 const RegisterMapping &
RM = RegisterMappings[
I];
478 const RegisterRenamingInfo &RRI = RM.second;
479 if (ZeroRegisters[
I]) {
481 <<
", PRF=" << RRI.IndexPlusCost.first
482 <<
", Cost=" << RRI.IndexPlusCost.second
483 <<
", RenameAs=" << RRI.RenameAs <<
", IsZero=" << ZeroRegisters[
I]
491 dbgs() <<
"Register File #" <<
I;
492 const RegisterMappingTracker &RMT = RegisterFiles[
I];
493 dbgs() <<
"\n TotalMappings: " << RMT.NumPhysRegs
494 <<
"\n NumUsedMappings: " << RMT.NumUsedPhysRegs <<
'\n';
const WriteState * getWriteState() const
reference emplace_back(ArgTypes &&... Args)
bool isEliminated() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void addUser(unsigned IID, ReadState *Use, int ReadAdvance)
This class represents lattice values for constants.
void addRegisterWrite(WriteRef Write, MutableArrayRef< unsigned > UsedPhysRegs)
constexpr int UNKNOWN_CYCLES
void push_back(const T &Elt)
A register read descriptor.
unsigned getNumRegisterFiles() const
bool AllowZeroMoveEliminationOnly
MCPhysReg getRegisterID() const
const MCSchedClassDesc * getSchedClassDesc(unsigned SchedClassIdx) const
void dump() const
debug method
const ReadDescriptor & getDescriptor() const
unsigned isAvailable(ArrayRef< MCPhysReg > Regs) const
void setBit(unsigned BitPosition)
Set a given bit to 1.
MCSuperRegIterator enumerates all super-registers of Reg.
Tracks register operand latency in cycles.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
A register file descriptor.
Specify the cost of a register definition in terms of number of physical register allocated at regist...
uint16_t MaxMovesEliminatedPerCycle
void clearBit(unsigned BitPosition)
Set a given bit to 0.
This file defines a register mapping file class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
MCPhysReg getRegisterID() const
MCRegisterClass - Base class of TargetRegisterClass.
Analysis containing CSE Info
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
int getCyclesLeft() const
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
unsigned const MachineRegisterInfo * MRI
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
bool hasExtraProcessorInfo() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Summarize the scheduling resources required for an instruction of a particular scheduling class...
RegisterFile(const MCSchedModel &SM, const MCRegisterInfo &mri, unsigned NumRegs=0)
bool isSuperRegister(MCRegister RegA, MCRegister RegB) const
Returns true if RegB is a super-register of RegA.
MCSubRegIterator enumerates all sub-registers of Reg.
void removeRegisterWrite(const WriteState &WS, MutableArrayRef< unsigned > FreedPhysRegs)
void setDependentWrites(unsigned Writes)
void sort(IteratorTy Start, IteratorTy End)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Tracks uses of a register definition (e.g.
CHAIN = SC CHAIN, Imm128 - System call.
A reference to a register write.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const char * getName(MCRegister RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register...
bool isIndependentFromDef() const
void setPRF(unsigned PRF)
unsigned getSourceIndex() const
void addRegisterRead(ReadState &RS, const MCSubtargetInfo &STI) const
Generic base class for all target subtargets.
This file defines abstractions used by the Pipeline to model register reads, register writes and inst...
bool tryEliminateMove(WriteState &WS, ReadState &RS)
const MCExtraProcessorInfo & getExtraProcessorInfo() const
unsigned getWriteResourceID() const
int getReadAdvanceCycles(const MCSchedClassDesc *SC, unsigned UseIdx, unsigned WriteResID) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint16_t NumRegisterCostEntries
bool clearsSuperRegisters() const
Machine model for scheduling, bundling, and heuristics.
const MCSchedModel & getSchedModel() const
Get the machine model for this subtarget's CPU.
bool empty() const
empty - Check if the array is empty.
const MCRegisterClass & getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
uint16_t RegisterCostEntryIdx