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) {
58 void getAnalysisUsage(AnalysisUsage &AU)
const override {
64 bool runOnMachineFunction(MachineFunction &MF)
override;
66 MachineFunctionProperties getRequiredProperties()
const override {
67 return MachineFunctionProperties().setNoVRegs();
72 void processBasicBlock(MachineBasicBlock *
MBB);
76 void processDefs(MachineInstr *
MI);
83 bool pickBestRegisterForUndef(MachineInstr *
MI,
unsigned OpIdx,
88 bool shouldBreakDependence(MachineInstr *,
unsigned OpIdx,
unsigned Pref);
95 void processUndefReads(MachineBasicBlock *);
100#define DEBUG_TYPE "break-false-deps"
102char BreakFalseDeps::ID = 0;
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;
157 if (Clearance <= MaxClearance)
159 MaxClearance = Clearance;
160 MaxClearanceReg =
Reg;
162 if (MaxClearance > Pref)
167 if (MaxClearanceReg != OriginalReg)
168 MO.
setReg(MaxClearanceReg);
173bool BreakFalseDeps::shouldBreakDependence(MachineInstr *
MI,
unsigned OpIdx,
175 MCRegister
Reg =
MI->getOperand(
OpIdx).getReg().asMCReg();
177 LLVM_DEBUG(
dbgs() <<
"Clearance: " << Clearance <<
", want " << Pref);
179 if (Pref > Clearance) {
187void BreakFalseDeps::processDefs(MachineInstr *
MI) {
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));
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);
230void BreakFalseDeps::processUndefReads(MachineBasicBlock *
MBB) {
231 if (UndefReads.empty())
245 MachineInstr *UndefMI = UndefReads.back().first;
246 unsigned OpIdx = UndefReads.back().second;
254 TII->breakPartialRegDependency(*UndefMI,
OpIdx,
TRI);
256 UndefReads.pop_back();
257 if (UndefReads.empty())
260 UndefMI = UndefReads.back().first;
261 OpIdx = UndefReads.back().second;
266void BreakFalseDeps::processBasicBlock(MachineBasicBlock *
MBB) {
272 for (MachineInstr &
MI : *
MBB) {
273 if (!
MI.isDebugInstr())
276 processUndefReads(
MBB);
279bool BreakFalseDeps::runOnMachineFunction(MachineFunction &mf) {
285 RDI = &getAnalysis<ReachingDefInfoWrapperPass>().getRDI();
289 LLVM_DEBUG(
dbgs() <<
"********** BREAK FALSE DEPENDENCIES **********\n");
293 df_iterator_default_set<MachineBasicBlock *> Reachable;
298 for (MachineBasicBlock &
MBB : mf)
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.
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.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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)
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 >