41 #ifndef LLVM_LIB_CODEGEN_MACHINEPIPELINER_H 42 #define LLVM_LIB_CODEGEN_MACHINEPIPELINER_H 112 bool Scheduled =
false;
124 int ZeroLatencyDepth = 0;
125 int ZeroLatencyHeight = 0;
127 NodeInfo() =
default;
130 std::vector<NodeInfo> ScheduleInfo;
132 enum OrderKind { BottomUp = 0, TopDown = 1 };
149 std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
153 std::vector<SUnit> &SUnits;
159 std::vector<int> *Node2Idx;
161 static unsigned MaxPaths;
165 : SUnits(SUs), Blocked(SUs.size()),
B(SUs.size()), AdjK(SUs.size()) {
166 Node2Idx =
new std::vector<int>(SUs.size());
168 for (
const auto &NodeNum : Topo)
169 Node2Idx->at(NodeNum) = Idx++;
172 ~Circuits() {
delete Node2Idx; }
183 bool circuit(
int V,
int S,
NodeSetType &NodeSets,
bool HasBackedge =
false);
195 RegClassInfo(rci), Topo(SUnits, &ExitSU) {
197 if (SwpEnableCopyToPhi)
198 Mutations.push_back(llvm::make_unique<CopyToPhiMutation>());
201 void schedule()
override;
202 void finishBlock()
override;
223 return ScheduleInfo[Node->
NodeNum].ZeroLatencyDepth;
232 return ScheduleInfo[Node->
NodeNum].ZeroLatencyHeight;
244 bool isLoopCarriedDep(
SUnit *
Source,
const SDep &Dep,
bool isSucc =
true);
261 void fixupRegisterOverlaps(std::deque<SUnit *> &Instrs);
267 InstrChanges.
find(SU);
268 if (It != InstrChanges.
end())
269 return It->second.first;
274 Mutations.push_back(std::move(Mutation));
281 void updatePhiDependences();
282 void changeDependences();
283 unsigned calculateResMII();
284 unsigned calculateRecMII(
NodeSetType &RecNodeSets);
289 void registerPressureFilter(
NodeSetType &NodeSets);
296 void checkValidNodeOrder(
const NodeSetType &Circuits)
const;
298 void generatePipelinedLoop(
SMSchedule &Schedule);
299 void generateProlog(
SMSchedule &Schedule,
unsigned LastStage,
302 void generateEpilog(
SMSchedule &Schedule,
unsigned LastStage,
309 unsigned CurStageNum,
bool IsLast);
314 unsigned CurStageNum,
bool IsLast);
326 unsigned InstStageNum);
328 unsigned InstStageNum,
330 void updateInstruction(
MachineInstr *NewMI,
bool LastDef,
331 unsigned CurStageNum,
unsigned InstrStageNum,
334 unsigned getPrevMapVal(
unsigned StageNum,
unsigned PhiStage,
unsigned LoopVal,
343 unsigned OldReg,
unsigned NewReg,
344 unsigned PrevReg = 0);
345 bool canUseLastOffsetValue(
MachineInstr *MI,
unsigned &BasePos,
346 unsigned &OffsetPos,
unsigned &NewBase,
348 void postprocessDAG();
355 bool HasRecurrence =
false;
359 unsigned Colocate = 0;
360 SUnit *ExceedPressure =
nullptr;
369 for (
unsigned i = 0, e = Nodes.
size(); i < e; ++i)
370 for (
const SDep &Succ : Nodes[i]->Succs)
371 if (Nodes.
count(Succ.getSUnit()))
372 Latency += Succ.getLatency();
379 template <
typename UnaryPredicate>
bool remove_if(UnaryPredicate
P) {
407 for (
SUnit *SU : *
this) {
420 HasRecurrence =
false;
424 ExceedPressure =
nullptr;
434 if (RecMII == RHS.RecMII) {
435 if (Colocate != 0 && RHS.Colocate != 0 && Colocate != RHS.Colocate)
436 return Colocate < RHS.Colocate;
437 if (MaxMOV == RHS.MaxMOV)
438 return MaxDepth > RHS.MaxDepth;
439 return MaxMOV < RHS.MaxMOV;
441 return RecMII > RHS.RecMII;
445 return RecMII == RHS.RecMII && MaxMOV == RHS.MaxMOV &&
446 MaxDepth == RHS.MaxDepth;
455 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 474 std::map<SUnit *, int> InstrToCycle;
480 std::map<unsigned, std::pair<unsigned, bool>> RegToStageDiff;
490 int InitiationInterval = 0;
498 std::unique_ptr<DFAPacketizer> Resources;
502 : ST(mf->getSubtarget()), MRI(mf->getRegInfo()),
503 Resources(ST.getInstrInfo()->CreateTargetScheduleState(ST)) {}
506 ScheduledInstrs.
clear();
507 InstrToCycle.clear();
508 RegToStageDiff.clear();
511 InitiationInterval = 0;
526 int earliestCycleInChain(
const SDep &Dep);
530 int latestCycleInChain(
const SDep &Dep);
532 void computeStart(
SUnit *SU,
int *MaxEarlyStart,
int *MinLateStart,
534 bool insert(
SUnit *SU,
int StartCycle,
int EndCycle,
int II);
543 return (stageScheduled(SU) == (
int)StageNum);
549 std::map<SUnit *, int>::const_iterator it = InstrToCycle.find(SU);
550 if (it == InstrToCycle.end())
552 return (it->second - FirstCycle) / InitiationInterval;
558 std::map<SUnit *, int>::const_iterator it = InstrToCycle.find(SU);
559 assert(it != InstrToCycle.end() &&
"Instruction hasn't been scheduled.");
560 return (it->second - FirstCycle) % InitiationInterval;
565 return (LastCycle - FirstCycle) / InitiationInterval;
571 std::pair<unsigned, bool> Stages = RegToStageDiff[
Reg];
572 if (CurStage > getMaxStageCount() && Stages.first == 0 && Stages.second)
584 std::pair<unsigned, bool> Stages = RegToStageDiff[
Reg];
587 return Stages.first - 1;
592 return ScheduledInstrs[cycle];
598 std::deque<SUnit *> &Insts);
608 #endif // LLVM_LIB_CODEGEN_MACHINEPIPELINER_H RegisterClassInfo RegClassInfo
MachineInstr * LoopInductionVar
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
int getMOV(SUnit *Node)
The mobility function, which the number of slots in which an instruction may be scheduled.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents lattice values for constants.
size_type size() const
Determine the number of elements in the SetVector.
cl::opt< bool > SwpEnableCopyToPhi
unsigned getHeight(SUnit *Node)
The height, in the dependence graph, for a node.
unsigned getDepth() const
Returns the depth of this node, which is the length of the maximum path up to any node which has no p...
const MachineLoopInfo * MLI
bool operator==(const NodeSet &RHS) const
Mutate the DAG as a postpass after normal DAG building.
block Block Frequency true
iterator end()
Get an iterator to the end of the SetVector.
SUnit * getNode(unsigned i) const
A register anti-dependence (aka WAR).
int compareRecMII(NodeSet &RHS)
AnalysisUsage & addRequired()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
NodeSet(iterator S, iterator E)
void addMutation(std::unique_ptr< ScheduleDAGMutation > Mutation)
void apply(Opt *O, const Mod &M, const Mods &... Ms)
SwingSchedulerDAG(MachinePipeliner &P, MachineLoop &L, LiveIntervals &lis, const RegisterClassInfo &rci)
unsigned cycleScheduled(SUnit *SU) const
Return the cycle for a scheduled instruction.
void assign(size_type NumElts, const T &Elt)
bool insert(const value_type &X)
Insert a new element into the SetVector.
int getZeroLatencyDepth(SUnit *Node)
The maximum unweighted length of a path from an arbitrary node to the given node in which each edge h...
unsigned getDistance(SUnit *U, SUnit *V, const SDep &Dep)
The distance function, which indicates that operation V of iteration I depends on operations U of ite...
iterator begin()
Get an iterator to the beginning of the SetVector.
Itinerary data supplied by a subtarget to be used by a target.
unsigned count(SUnit *SU) const
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
unsigned getDepth(SUnit *Node)
The depth, in the dependence graph, for a node.
TargetInstrInfo - Interface to description of machine instruction set.
iterator find(const_arg_type_t< KeyT > Val)
const MachineDominatorTree * MDT
int getFirstCycle() const
Return the first cycle in the completed schedule.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
The main class in the implementation of the target independent software pipeliner pass...
unsigned const MachineRegisterInfo * MRI
SMSchedule(MachineFunction *mf)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual void getSMSMutations(std::vector< std::unique_ptr< ScheduleDAGMutation >> &Mutations) const
unsigned getStagesForPhi(int Reg)
The number of stages for a Phi is a little different than other instructions.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void computeNodeSetInfo(SwingSchedulerDAG *SSD)
Summarize node functions for the entire node set.
static int64_t computeDelta(SectionEntry *A, SectionEntry *B)
int stageScheduled(SUnit *SU) const
Return the stage for a scheduled instruction.
bool runOnMachineFunction(MachineFunction &MF) override
The "main" function for implementing Swing Modulo Scheduling.
Represent the analysis usage information of a pass.
unsigned getInstrBaseReg(SUnit *SU)
Return the new base register that was stored away for the changed instruction.
const TargetInstrInfo * TII
bool isScheduledAtStage(SUnit *SU, unsigned StageNum)
Return true if the instruction is scheduled at the specified stage.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const InstrItineraryData * InstrItins
typename vector_type::const_iterator const_iterator
static bool classof(const ScheduleDAGInstrs *DAG)
void insert(iterator S, iterator E)
SetVector< SUnit * >::const_iterator iterator
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This class builds the dependence graph for the instructions in a loop, and attempts to schedule the i...
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void setMII(unsigned mii)
Set the Minimum Initiation Interval for this schedule attempt.
bool remove_if(UnaryPredicate P)
void setRecMII(unsigned mii)
MachineInstr * LoopCompare
Pass(PassKind K, char &pid)
void clear()
Completely clear the SetVector.
This class represents the scheduled code.
unsigned getStagesForReg(int Reg, unsigned CurStage)
Return the max.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
void initializeMachinePipelinerPass(PassRegistry &)
TargetSubtargetInfo - Generic base class for all target subtargets.
void setExceedPressure(SUnit *SU)
void setColocate(unsigned c)
std::set< NodeId > NodeSet
unsigned getHeight() const
Returns the height of this node, which is the length of the maximum path down to any node which has n...
A ScheduleDAG for scheduling lists of MachineInstr.
Representation of each machine instruction.
Represents a single loop in the control flow graph.
int getFinalCycle() const
Return the last cycle in the finalized schedule.
int getALAP(SUnit *Node)
Return the latest time an instruction my be scheduled.
bool empty() const
Determine if the SetVector is empty or not.
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
bool operator>(const NodeSet &RHS) const
Sort the node sets by importance.
int getASAP(SUnit *Node)
Return the earliest time an instruction may be scheduled.
Kind getKind() const
Returns an enum value representing the kind of the dependence.
void setInitiationInterval(int ii)
Set the initiation interval for this schedule.
bool hasNewSchedule()
Return true if the loop kernel has been scheduled.
unsigned NodeNum
Entry # of node in the node vector.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A vector that has set insertion semantics.
bool remove_if(UnaryPredicate P)
Remove items from the set vector based on a predicate function.
bool isExceedSU(SUnit *SU)
This class implements an extremely fast bulk output stream that can only output to a stream...
SmallVector< MachineOperand, 4 > BrCond
bool operator==(uint64_t V1, const APInt &V2)
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
Cache the target analysis information about the loop.
bool operator!=(const NodeSet &RHS) const
This class can compute a topological ordering for SUnits and provides methods for dynamically updatin...
unsigned getMaxStageCount()
Return the maximum stage count needed for this schedule.
std::deque< SUnit * > & getInstructions(int cycle)
Return the instructions that are scheduled at the specified cycle.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Scheduling unit. This is a node in the scheduling DAG.
bool isBackedge(SUnit *Source, const SDep &Dep)
Return true if the dependence is a back-edge in the data dependence graph.
A NodeSet contains a set of SUnit DAG nodes with additional information that assigns a priority to th...
int getZeroLatencyHeight(SUnit *Node)
The maximum unweighted length of a path from the given node to an arbitrary node in which each edge h...