44 std::vector<std::pair<MachineInstr *, unsigned>> UndefReads;
100#define DEBUG_TYPE "break-false-deps"
113 if (
MI->isRegTiedToDefOperand(
OpIdx))
127 unsigned NumRoots = 0;
136 const TargetRegisterClass *OpRC = TII->getRegClass(
MI->getDesc(),
OpIdx, TRI);
137 assert(OpRC &&
"Not a valid register class");
141 for (MachineOperand &CurrMO :
MI->all_uses()) {
142 if (CurrMO.isUndef() || !OpRC->
contains(CurrMO.getReg()))
146 MO.
setReg(CurrMO.getReg());
152 unsigned MaxClearance = 0;
153 unsigned MaxClearanceReg = OriginalReg;
156 unsigned Clearance = RDA->getClearance(
MI,
Reg);
157 if (Clearance <= MaxClearance)
159 MaxClearance = Clearance;
160 MaxClearanceReg =
Reg;
162 if (MaxClearance > Pref)
167 if (MaxClearanceReg != OriginalReg)
168 MO.
setReg(MaxClearanceReg);
175 MCRegister
Reg =
MI->getOperand(
OpIdx).getReg().asMCReg();
176 unsigned Clearance = RDA->getClearance(
MI,
Reg);
177 LLVM_DEBUG(
dbgs() <<
"Clearance: " << Clearance <<
", want " << Pref);
179 if (Pref > Clearance) {
188 assert(!
MI->isDebugInstr() &&
"Won't process debug values");
190 const MCInstrDesc &MCID =
MI->getDesc();
195 MachineOperand &MO =
MI->getOperand(i);
199 unsigned Pref = TII->getUndefRegClearance(*
MI, i, TRI);
201 bool HadTrueDependency = pickBestRegisterForUndef(
MI, i, Pref);
205 if (!HadTrueDependency && shouldBreakDependence(
MI, i, Pref))
206 UndefReads.push_back(std::make_pair(
MI, i));
212 if (MF->getFunction().hasMinSize())
218 MachineOperand &MO =
MI->getOperand(i);
224 unsigned Pref = TII->getPartialRegUpdateClearance(*
MI, i, TRI);
225 if (Pref && shouldBreakDependence(
MI, i, Pref))
226 TII->breakPartialRegDependency(*
MI, i, TRI);
231 if (UndefReads.empty())
236 if (MF->getFunction().hasMinSize())
240 LiveRegSet.init(*TRI);
243 LiveRegSet.addLiveOutsNoPristines(*
MBB);
245 MachineInstr *UndefMI = UndefReads.back().first;
246 unsigned OpIdx = UndefReads.back().second;
250 LiveRegSet.stepBackward(
I);
254 TII->breakPartialRegDependency(*UndefMI,
OpIdx, TRI);
256 UndefReads.pop_back();
257 if (UndefReads.empty())
260 UndefMI = UndefReads.back().first;
261 OpIdx = UndefReads.back().second;
272 for (MachineInstr &
MI : *
MBB) {
273 if (!
MI.isDebugInstr())
276 processUndefReads(
MBB);
284 TRI = MF->getSubtarget().getRegisterInfo();
287 RegClassInfo.runOnMachineFunction(mf,
true);
289 LLVM_DEBUG(
dbgs() <<
"********** BREAK FALSE DEPENDENCIES **********\n");
299 if (Reachable.count(&
MBB))
300 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.
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)
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
MachineFunctionProperties getRequiredProperties() const override
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
FunctionPass class - This class is used to implement most global optimizations.
bool skipFunction(const Function &F) const
Optional passes call this function to check whether the pass should be skipped.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
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(char &ID)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Properties which a MachineFunction may have at a given point in time.
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.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
This class provides the reaching def analysis.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
TargetInstrInfo - Interface to description of machine instruction set.
bool contains(Register Reg) const
Return true if the specified register is included in this register class.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
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)
LLVM_ABI void initializeBreakFalseDepsPass(PassRegistry &)
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned MCRegUnit
Register units are used to compute register aliasing.
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 >