40 const TargetInstrInfo *TII =
nullptr;
41 const TargetRegisterInfo *TRI =
nullptr;
42 RegisterClassInfo RegClassInfo;
45 std::vector<std::pair<MachineInstr *, unsigned>> UndefReads;
48 LivePhysRegs LiveRegSet;
50 function_ref<ReachingDefInfo &()> GetRDI;
51 ReachingDefInfo *RDI =
nullptr;
58 BreakFalseDeps(function_ref<ReachingDefInfo &()> GetRDI) : GetRDI(GetRDI) {}
63 ReachingDefInfo &getRDI() {
74 void processDefs(MachineInstr *
MI);
81 bool pickBestRegisterForUndef(MachineInstr *
MI,
unsigned OpIdx,
86 bool shouldBreakDependence(MachineInstr *,
unsigned OpIdx,
unsigned Pref);
93 void processUndefReads(MachineBasicBlock *);
100 BreakFalseDepsLegacy() : MachineFunctionPass(ID) {}
102 void getAnalysisUsage(AnalysisUsage &AU)
const override {
110 MachineFunctionProperties getRequiredProperties()
const override {
111 return MachineFunctionProperties().setNoVRegs();
117#define DEBUG_TYPE "break-false-deps"
119char BreakFalseDepsLegacy::ID = 0;
127 return new BreakFalseDepsLegacy();
130bool BreakFalseDeps::pickBestRegisterForUndef(
MachineInstr *
MI,
unsigned OpIdx,
134 if (
MI->isRegTiedToDefOperand(OpIdx))
147 for (MCRegUnit Unit :
TRI->regunits(OriginalReg)) {
148 unsigned NumRoots = 0;
158 assert(OpRC &&
"Not a valid register class");
162 for (MachineOperand &CurrMO :
MI->all_uses()) {
163 if (CurrMO.isUndef() || !OpRC->
contains(CurrMO.getReg()))
167 MO.
setReg(CurrMO.getReg());
174 unsigned MaxClearance = 0;
175 MCRegister MaxClearanceReg = OriginalReg;
178 unsigned Clearance = getRDI().getClearance(
MI,
Reg);
179 if (Clearance <= MaxClearance)
181 MaxClearance = Clearance;
182 MaxClearanceReg =
Reg;
184 if (MaxClearance > Pref)
189 if (MaxClearanceReg != OriginalReg) {
190 MO.
setReg(MaxClearanceReg);
197bool BreakFalseDeps::shouldBreakDependence(MachineInstr *
MI,
unsigned OpIdx,
199 MCRegister
Reg =
MI->getOperand(OpIdx).getReg().
asMCReg();
200 unsigned Clearance = getRDI().getClearance(
MI,
Reg);
201 LLVM_DEBUG(
dbgs() <<
"Clearance: " << Clearance <<
", want " << Pref);
203 if (Pref > Clearance) {
211void BreakFalseDeps::processDefs(MachineInstr *
MI) {
212 assert(!
MI->isDebugInstr() &&
"Won't process debug values");
214 const MCInstrDesc &MCID =
MI->getDesc();
219 MachineOperand &MO =
MI->getOperand(i);
223 unsigned Pref =
TII->getUndefRegClearance(*
MI, i);
225 bool HadTrueDependency = pickBestRegisterForUndef(
MI, i, Pref);
229 if (!HadTrueDependency && shouldBreakDependence(
MI, i, Pref))
230 UndefReads.push_back(std::make_pair(
MI, i));
242 MachineOperand &MO =
MI->getOperand(i);
248 unsigned Pref =
TII->getPartialRegUpdateClearance(*
MI, i);
249 if (Pref && shouldBreakDependence(
MI, i, Pref)) {
250 TII->breakPartialRegDependency(*
MI, i);
256void BreakFalseDeps::processUndefReads(MachineBasicBlock *
MBB) {
257 if (UndefReads.empty())
271 MachineInstr *UndefMI = UndefReads.back().first;
272 unsigned OpIdx = UndefReads.back().second;
280 TII->breakPartialRegDependency(*UndefMI, OpIdx);
284 UndefReads.pop_back();
285 if (UndefReads.empty())
288 UndefMI = UndefReads.back().first;
289 OpIdx = UndefReads.back().second;
294void BreakFalseDeps::processBasicBlock(MachineBasicBlock *
MBB) {
300 for (MachineInstr &
MI : *
MBB) {
301 if (!
MI.isDebugInstr())
304 processUndefReads(
MBB);
313 LLVM_DEBUG(
dbgs() <<
"********** BREAK FALSE DEPENDENCIES **********\n");
317 df_iterator_default_set<MachineBasicBlock *> Reachable;
322 for (MachineBasicBlock &
MBB : CurMF)
334 return getAnalysis<ReachingDefInfoWrapperPass>().getRDI();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declaration of the BreakFalseDepsPass class, used to identify and avoid false ...
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
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static bool processBasicBlock(MachineBasicBlock &MBB, BlockStateMap &BlockStates, DirtySuccessorsWorkList &DirtySuccessors, bool IsX86INTR, const TargetInstrInfo *TII)
Loop over all of the instructions in the basic block, inserting vzeroupper instructions before functi...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
LLVM_ABI 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.
LLVM_ABI 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.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
Wrapper class representing physical registers and target specific virtual registers.
An RAII based helper class to modify MachineFunctionProperties when running pass.
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.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
This class provides the reaching def analysis.
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.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
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)
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI FunctionPass * createBreakFalseDepsLegacyPass()
Creates Break False Dependencies pass.
MCRegisterClass TargetRegisterClass