39 MachineFunction *MF =
nullptr;
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 ReachingDefInfo *RDI =
nullptr;
55 bool run(MachineFunction &CurMF);
63 void processDefs(MachineInstr *
MI);
70 bool pickBestRegisterForUndef(MachineInstr *
MI,
unsigned OpIdx,
75 bool shouldBreakDependence(MachineInstr *,
unsigned OpIdx,
unsigned Pref);
82 void processUndefReads(MachineBasicBlock *);
89 BreakFalseDepsLegacy() : MachineFunctionPass(ID) {}
91 void getAnalysisUsage(AnalysisUsage &AU)
const override {
97 bool runOnMachineFunction(MachineFunction &MF)
override;
99 MachineFunctionProperties getRequiredProperties()
const override {
100 return MachineFunctionProperties().setNoVRegs();
106#define DEBUG_TYPE "break-false-deps"
108char BreakFalseDepsLegacy::ID = 0;
116 return new BreakFalseDepsLegacy();
123 if (
MI->isRegTiedToDefOperand(
OpIdx))
136 for (MCRegUnit Unit :
TRI->regunits(OriginalReg)) {
137 unsigned NumRoots = 0;
146 const TargetRegisterClass *OpRC =
TII->getRegClass(
MI->getDesc(),
OpIdx);
147 assert(OpRC &&
"Not a valid register class");
151 for (MachineOperand &CurrMO :
MI->all_uses()) {
152 if (CurrMO.isUndef() || !OpRC->
contains(CurrMO.getReg()))
156 MO.
setReg(CurrMO.getReg());
162 unsigned MaxClearance = 0;
163 unsigned MaxClearanceReg = OriginalReg;
167 if (Clearance <= MaxClearance)
169 MaxClearance = Clearance;
170 MaxClearanceReg =
Reg;
172 if (MaxClearance > Pref)
177 if (MaxClearanceReg != OriginalReg)
178 MO.
setReg(MaxClearanceReg);
183bool BreakFalseDeps::shouldBreakDependence(MachineInstr *
MI,
unsigned OpIdx,
185 MCRegister
Reg =
MI->getOperand(
OpIdx).getReg().asMCReg();
187 LLVM_DEBUG(
dbgs() <<
"Clearance: " << Clearance <<
", want " << Pref);
189 if (Pref > Clearance) {
197void BreakFalseDeps::processDefs(MachineInstr *
MI) {
198 assert(!
MI->isDebugInstr() &&
"Won't process debug values");
200 const MCInstrDesc &MCID =
MI->getDesc();
205 MachineOperand &MO =
MI->getOperand(i);
209 unsigned Pref =
TII->getUndefRegClearance(*
MI, i,
TRI);
211 bool HadTrueDependency = pickBestRegisterForUndef(
MI, i, Pref);
215 if (!HadTrueDependency && shouldBreakDependence(
MI, i, Pref))
216 UndefReads.push_back(std::make_pair(
MI, i));
228 MachineOperand &MO =
MI->getOperand(i);
234 unsigned Pref =
TII->getPartialRegUpdateClearance(*
MI, i,
TRI);
235 if (Pref && shouldBreakDependence(
MI, i, Pref))
236 TII->breakPartialRegDependency(*
MI, i,
TRI);
240void BreakFalseDeps::processUndefReads(MachineBasicBlock *
MBB) {
241 if (UndefReads.empty())
255 MachineInstr *UndefMI = UndefReads.back().first;
256 unsigned OpIdx = UndefReads.back().second;
264 TII->breakPartialRegDependency(*UndefMI,
OpIdx,
TRI);
266 UndefReads.pop_back();
267 if (UndefReads.empty())
270 UndefMI = UndefReads.back().first;
271 OpIdx = UndefReads.back().second;
276void BreakFalseDeps::processBasicBlock(MachineBasicBlock *
MBB) {
282 for (MachineInstr &
MI : *
MBB) {
283 if (!
MI.isDebugInstr())
286 processUndefReads(
MBB);
289bool BreakFalseDeps::run(MachineFunction &CurMF) {
296 LLVM_DEBUG(
dbgs() <<
"********** BREAK FALSE DEPENDENCIES **********\n");
300 df_iterator_default_set<MachineBasicBlock *> Reachable;
305 for (MachineBasicBlock &
MBB : CurMF)
312bool BreakFalseDepsLegacy::runOnMachineFunction(MachineFunction &MF) {
316 ReachingDefInfo *
RDI = &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
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)
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()
void setPreservesAll()
Set by analyses that do not transform their input at all.
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.
Wrapper class representing physical registers. Should be passed by value.
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.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
This class provides the reaching def analysis.
LLVM_ABI 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.
DXILDebugInfoMap run(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.