38 MachineFunction *MF =
nullptr;
39 const TargetInstrInfo *TII =
nullptr;
40 const TargetRegisterInfo *TRI =
nullptr;
41 RegisterClassInfo RegClassInfo;
44 std::vector<std::pair<MachineInstr *, unsigned>> UndefReads;
47 LivePhysRegs LiveRegSet;
49 ReachingDefInfo *RDI =
nullptr;
54 BreakFalseDeps() : MachineFunctionPass(ID) {}
56 void getAnalysisUsage(AnalysisUsage &AU)
const override {
62 bool runOnMachineFunction(MachineFunction &MF)
override;
64 MachineFunctionProperties getRequiredProperties()
const override {
65 return MachineFunctionProperties().setNoVRegs();
70 void processBasicBlock(MachineBasicBlock *
MBB);
74 void processDefs(MachineInstr *
MI);
81 bool pickBestRegisterForUndef(MachineInstr *
MI,
unsigned OpIdx,
86 bool shouldBreakDependence(MachineInstr *,
unsigned OpIdx,
unsigned Pref);
93 void processUndefReads(MachineBasicBlock *);
98#define DEBUG_TYPE "break-false-deps"
100char BreakFalseDeps::ID = 0;
111 if (
MI->isRegTiedToDefOperand(
OpIdx))
124 for (MCRegUnit Unit :
TRI->regunits(OriginalReg)) {
125 unsigned NumRoots = 0;
134 const TargetRegisterClass *OpRC =
TII->getRegClass(
MI->getDesc(),
OpIdx);
135 assert(OpRC &&
"Not a valid register class");
139 for (MachineOperand &CurrMO :
MI->all_uses()) {
140 if (CurrMO.isUndef() || !OpRC->
contains(CurrMO.getReg()))
144 MO.
setReg(CurrMO.getReg());
150 unsigned MaxClearance = 0;
151 unsigned MaxClearanceReg = OriginalReg;
155 if (Clearance <= MaxClearance)
157 MaxClearance = Clearance;
158 MaxClearanceReg =
Reg;
160 if (MaxClearance > Pref)
165 if (MaxClearanceReg != OriginalReg)
166 MO.
setReg(MaxClearanceReg);
171bool BreakFalseDeps::shouldBreakDependence(MachineInstr *
MI,
unsigned OpIdx,
173 MCRegister
Reg =
MI->getOperand(
OpIdx).getReg().asMCReg();
175 LLVM_DEBUG(
dbgs() <<
"Clearance: " << Clearance <<
", want " << Pref);
177 if (Pref > Clearance) {
185void BreakFalseDeps::processDefs(MachineInstr *
MI) {
186 assert(!
MI->isDebugInstr() &&
"Won't process debug values");
188 const MCInstrDesc &MCID =
MI->getDesc();
193 MachineOperand &MO =
MI->getOperand(i);
197 unsigned Pref =
TII->getUndefRegClearance(*
MI, i,
TRI);
199 bool HadTrueDependency = pickBestRegisterForUndef(
MI, i, Pref);
203 if (!HadTrueDependency && shouldBreakDependence(
MI, i, Pref))
204 UndefReads.push_back(std::make_pair(
MI, i));
216 MachineOperand &MO =
MI->getOperand(i);
222 unsigned Pref =
TII->getPartialRegUpdateClearance(*
MI, i,
TRI);
223 if (Pref && shouldBreakDependence(
MI, i, Pref))
224 TII->breakPartialRegDependency(*
MI, i,
TRI);
228void BreakFalseDeps::processUndefReads(MachineBasicBlock *
MBB) {
229 if (UndefReads.empty())
243 MachineInstr *UndefMI = UndefReads.back().first;
244 unsigned OpIdx = UndefReads.back().second;
252 TII->breakPartialRegDependency(*UndefMI,
OpIdx,
TRI);
254 UndefReads.pop_back();
255 if (UndefReads.empty())
258 UndefMI = UndefReads.back().first;
259 OpIdx = UndefReads.back().second;
264void BreakFalseDeps::processBasicBlock(MachineBasicBlock *
MBB) {
270 for (MachineInstr &
MI : *
MBB) {
271 if (!
MI.isDebugInstr())
274 processUndefReads(
MBB);
277bool BreakFalseDeps::runOnMachineFunction(MachineFunction &mf) {
283 RDI = &getAnalysis<ReachingDefInfoWrapperPass>().getRDI();
287 LLVM_DEBUG(
dbgs() <<
"********** BREAK FALSE DEPENDENCIES **********\n");
291 df_iterator_default_set<MachineBasicBlock *> Reachable;
296 for (MachineBasicBlock &
MBB : mf)
298 processBasicBlock(&
MBB);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
const HexagonInstrInfo * TII
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
Register const TargetRegisterInfo * TRI
MachineInstr unsigned OpIdx
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
FunctionPass class - This class is used to implement most global optimizations.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
void stepBackward(const MachineInstr &MI)
Simulates liveness when stepping backwards over an instruction(bundle).
void init(const TargetRegisterInfo &TRI)
(re-)initializes and clears the set.
void addLiveOutsNoPristines(const MachineBasicBlock &MBB)
Adds all live-out registers of basic block MBB but skips pristine registers.
bool contains(MCRegister Reg) const
Returns true if register Reg is contained in the set.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
MCRegUnitRootIterator enumerates the root registers of a register unit.
bool isValid() const
Check if the iterator is at the end of the list.
Wrapper class representing physical registers. Should be passed by value.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
LLVM_ABI bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
Register getReg() const
getReg - Returns the register number.
int getClearance(MachineInstr *MI, Register Reg) const
Provides the clearance - the number of instructions since the closest reaching def instuction of Reg ...
LLVM_ABI void runOnMachineFunction(const MachineFunction &MF, bool Rev=false)
runOnFunction - Prepare to answer questions about MF.
ArrayRef< MCPhysReg > getOrder(const TargetRegisterClass *RC) const
getOrder - Returns the preferred allocation order for RC.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
bool contains(Register Reg) const
Return true if the specified register is included in this register class.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< df_ext_iterator< T, SetTy > > depth_first_ext(const T &G, SetTy &S)
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI FunctionPass * createBreakFalseDeps()
Creates Break False Dependencies pass.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
ArrayRef(const T &OneElt) -> ArrayRef< T >