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;
59 bool run(MachineFunction &CurMF);
67 void processDefs(MachineInstr *
MI);
74 bool pickBestRegisterForUndef(MachineInstr *
MI,
unsigned OpIdx,
79 bool shouldBreakDependence(MachineInstr *,
unsigned OpIdx,
unsigned Pref);
86 void processUndefReads(MachineBasicBlock *);
93 BreakFalseDepsLegacy() : MachineFunctionPass(ID) {}
95 void getAnalysisUsage(AnalysisUsage &AU)
const override {
101 bool runOnMachineFunction(MachineFunction &MF)
override;
103 MachineFunctionProperties getRequiredProperties()
const override {
104 return MachineFunctionProperties().setNoVRegs();
110#define DEBUG_TYPE "break-false-deps"
112char BreakFalseDepsLegacy::ID = 0;
120 return new BreakFalseDepsLegacy();
127 if (
MI->isRegTiedToDefOperand(
OpIdx))
140 for (MCRegUnit Unit :
TRI->regunits(OriginalReg)) {
141 unsigned NumRoots = 0;
150 const TargetRegisterClass *OpRC =
TII->getRegClass(
MI->getDesc(),
OpIdx);
151 assert(OpRC &&
"Not a valid register class");
155 for (MachineOperand &CurrMO :
MI->all_uses()) {
156 if (CurrMO.isUndef() || !OpRC->
contains(CurrMO.getReg()))
160 MO.
setReg(CurrMO.getReg());
167 unsigned MaxClearance = 0;
168 unsigned MaxClearanceReg = OriginalReg;
172 if (Clearance <= MaxClearance)
174 MaxClearance = Clearance;
175 MaxClearanceReg =
Reg;
177 if (MaxClearance > Pref)
182 if (MaxClearanceReg != OriginalReg) {
183 MO.
setReg(MaxClearanceReg);
190bool BreakFalseDeps::shouldBreakDependence(MachineInstr *
MI,
unsigned OpIdx,
192 MCRegister
Reg =
MI->getOperand(
OpIdx).getReg().asMCReg();
194 LLVM_DEBUG(
dbgs() <<
"Clearance: " << Clearance <<
", want " << Pref);
196 if (Pref > Clearance) {
204void BreakFalseDeps::processDefs(MachineInstr *
MI) {
205 assert(!
MI->isDebugInstr() &&
"Won't process debug values");
207 const MCInstrDesc &MCID =
MI->getDesc();
212 MachineOperand &MO =
MI->getOperand(i);
216 unsigned Pref =
TII->getUndefRegClearance(*
MI, i,
TRI);
218 bool HadTrueDependency = pickBestRegisterForUndef(
MI, i, Pref);
222 if (!HadTrueDependency && shouldBreakDependence(
MI, i, Pref))
223 UndefReads.push_back(std::make_pair(
MI, i));
235 MachineOperand &MO =
MI->getOperand(i);
241 unsigned Pref =
TII->getPartialRegUpdateClearance(*
MI, i,
TRI);
242 if (Pref && shouldBreakDependence(
MI, i, Pref)) {
243 TII->breakPartialRegDependency(*
MI, i,
TRI);
249void BreakFalseDeps::processUndefReads(MachineBasicBlock *
MBB) {
250 if (UndefReads.empty())
264 MachineInstr *UndefMI = UndefReads.back().first;
265 unsigned OpIdx = UndefReads.back().second;
273 TII->breakPartialRegDependency(*UndefMI,
OpIdx,
TRI);
277 UndefReads.pop_back();
278 if (UndefReads.empty())
281 UndefMI = UndefReads.back().first;
282 OpIdx = UndefReads.back().second;
287void BreakFalseDeps::processBasicBlock(MachineBasicBlock *
MBB) {
293 for (MachineInstr &
MI : *
MBB) {
294 if (!
MI.isDebugInstr())
297 processUndefReads(
MBB);
300bool BreakFalseDeps::run(MachineFunction &CurMF) {
307 LLVM_DEBUG(
dbgs() <<
"********** BREAK FALSE DEPENDENCIES **********\n");
311 df_iterator_default_set<MachineBasicBlock *> Reachable;
316 for (MachineBasicBlock &
MBB : CurMF)
323bool BreakFalseDepsLegacy::runOnMachineFunction(MachineFunction &MF) {
327 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()
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.
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.
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 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.