LLVM 19.0.0git
AntiDepBreaker.h
Go to the documentation of this file.
1//===- llvm/CodeGen/AntiDepBreaker.h - Anti-Dependence Breaking -*- 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 AntiDepBreaker class, which implements
10// anti-dependence breaking heuristics for post-register-allocation scheduling.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CODEGEN_ANTIDEPBREAKER_H
15#define LLVM_CODEGEN_ANTIDEPBREAKER_H
16
22#include <utility>
23#include <vector>
24
25namespace llvm {
26
27class RegisterClassInfo;
28
29/// This class works in conjunction with the post-RA scheduler to rename
30/// registers to break register anti-dependencies (WAR hazards).
32public:
34 std::vector<std::pair<MachineInstr *, MachineInstr *>>;
35
36 virtual ~AntiDepBreaker();
37
38 /// Initialize anti-dep breaking for a new basic block.
39 virtual void StartBlock(MachineBasicBlock *BB) = 0;
40
41 /// Identifiy anti-dependencies within a basic-block region and break them by
42 /// renaming registers. Return the number of anti-dependencies broken.
43 virtual unsigned BreakAntiDependencies(const std::vector<SUnit> &SUnits,
46 unsigned InsertPosIndex,
47 DbgValueVector &DbgValues) = 0;
48
49 /// Update liveness information to account for the current
50 /// instruction, which will not be scheduled.
51 virtual void Observe(MachineInstr &MI, unsigned Count,
52 unsigned InsertPosIndex) = 0;
53
54 /// Finish anti-dep breaking for a basic block.
55 virtual void FinishBlock() = 0;
56
57 /// Update DBG_VALUE or DBG_PHI if dependency breaker is updating
58 /// other machine instruction to use NewReg.
59 void UpdateDbgValue(MachineInstr &MI, unsigned OldReg, unsigned NewReg) {
60 if (MI.isDebugValue()) {
61 if (MI.getDebugOperand(0).isReg() &&
62 MI.getDebugOperand(0).getReg() == OldReg)
63 MI.getDebugOperand(0).setReg(NewReg);
64 } else if (MI.isDebugPHI()) {
65 if (MI.getOperand(0).isReg() &&
66 MI.getOperand(0).getReg() == OldReg)
67 MI.getOperand(0).setReg(NewReg);
68 } else {
69 llvm_unreachable("MI is not DBG_VALUE / DBG_PHI!");
70 }
71 }
72
73 /// Update all DBG_VALUE instructions that may be affected by the dependency
74 /// breaker's update of ParentMI to use NewReg.
75 void UpdateDbgValues(const DbgValueVector &DbgValues, MachineInstr *ParentMI,
76 unsigned OldReg, unsigned NewReg) {
77 // The following code is dependent on the order in which the DbgValues are
78 // constructed in ScheduleDAGInstrs::buildSchedGraph.
79 MachineInstr *PrevDbgMI = nullptr;
80 for (const auto &DV : make_range(DbgValues.crbegin(), DbgValues.crend())) {
81 MachineInstr *PrevMI = DV.second;
82 if ((PrevMI == ParentMI) || (PrevMI == PrevDbgMI)) {
83 MachineInstr *DbgMI = DV.first;
84 UpdateDbgValue(*DbgMI, OldReg, NewReg);
85 PrevDbgMI = DbgMI;
86 } else if (PrevDbgMI) {
87 break; // If no match and already found a DBG_VALUE, we're done.
88 }
89 }
90 }
91};
92
93AntiDepBreaker *createAggressiveAntiDepBreaker(
94 MachineFunction &MFi, const RegisterClassInfo &RCI,
96
97AntiDepBreaker *createCriticalAntiDepBreaker(MachineFunction &MFi,
98 const RegisterClassInfo &RCI);
99
100} // end namespace llvm
101
102#endif // LLVM_CODEGEN_ANTIDEPBREAKER_H
bool End
Definition: ELF_riscv.cpp:480
IRTranslator LLVM IR MI
This class works in conjunction with the post-RA scheduler to rename registers to break register anti...
virtual void FinishBlock()=0
Finish anti-dep breaking for a basic block.
virtual unsigned BreakAntiDependencies(const std::vector< SUnit > &SUnits, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, unsigned InsertPosIndex, DbgValueVector &DbgValues)=0
Identifiy anti-dependencies within a basic-block region and break them by renaming registers.
void UpdateDbgValue(MachineInstr &MI, unsigned OldReg, unsigned NewReg)
Update DBG_VALUE or DBG_PHI if dependency breaker is updating other machine instruction to use NewReg...
virtual void Observe(MachineInstr &MI, unsigned Count, unsigned InsertPosIndex)=0
Update liveness information to account for the current instruction, which will not be scheduled.
virtual ~AntiDepBreaker()
void UpdateDbgValues(const DbgValueVector &DbgValues, MachineInstr *ParentMI, unsigned OldReg, unsigned NewReg)
Update all DBG_VALUE instructions that may be affected by the dependency breaker's update of ParentMI...
virtual void StartBlock(MachineBasicBlock *BB)=0
Initialize anti-dep breaking for a new basic block.
std::vector< std::pair< MachineInstr *, MachineInstr * > > DbgValueVector
Representation of each machine instruction.
Definition: MachineInstr.h:69
SmallVectorImpl< const TargetRegisterClass * > RegClassVector
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
AntiDepBreaker * createAggressiveAntiDepBreaker(MachineFunction &MFi, const RegisterClassInfo &RCI, TargetSubtargetInfo::RegClassVector &CriticalPathRCs)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
AntiDepBreaker * createCriticalAntiDepBreaker(MachineFunction &MFi, const RegisterClassInfo &RCI)