40 #ifndef LLVM_LIB_CODEGEN_MACHINEPIPELINER_H 41 #define LLVM_LIB_CODEGEN_MACHINEPIPELINER_H 119 bool Scheduled =
false;
132 int ZeroLatencyDepth = 0;
133 int ZeroLatencyHeight = 0;
135 NodeInfo() =
default;
138 std::vector<NodeInfo> ScheduleInfo;
140 enum OrderKind { BottomUp = 0, TopDown = 1 };
157 std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
161 std::vector<SUnit> &SUnits;
167 std::vector<int> *Node2Idx;
169 static unsigned MaxPaths;
173 : SUnits(SUs), Blocked(SUs.size()),
B(SUs.size()), AdjK(SUs.size()) {
174 Node2Idx =
new std::vector<int>(SUs.size());
176 for (
const auto &NodeNum : Topo)
177 Node2Idx->at(NodeNum) = Idx++;
180 ~Circuits() {
delete Node2Idx; }
191 bool circuit(
int V,
int S,
NodeSetType &NodeSets,
bool HasBackedge =
false);
203 RegClassInfo(rci), II_setByPragma(II), Topo(SUnits, &ExitSU) {
205 if (SwpEnableCopyToPhi)
206 Mutations.push_back(std::make_unique<CopyToPhiMutation>());
209 void schedule()
override;
210 void finishBlock()
override;
231 return ScheduleInfo[Node->
NodeNum].ZeroLatencyDepth;
240 return ScheduleInfo[Node->
NodeNum].ZeroLatencyHeight;
252 bool isLoopCarriedDep(
SUnit *
Source,
const SDep &Dep,
bool isSucc =
true);
266 void fixupRegisterOverlaps(std::deque<SUnit *> &Instrs);
272 InstrChanges.
find(SU);
273 if (It != InstrChanges.
end())
274 return It->second.first;
279 Mutations.push_back(std::move(Mutation));
286 void updatePhiDependences();
287 void changeDependences();
288 unsigned calculateResMII();
289 unsigned calculateRecMII(
NodeSetType &RecNodeSets);
294 void registerPressureFilter(
NodeSetType &NodeSets);
301 void checkValidNodeOrder(
const NodeSetType &Circuits)
const;
305 bool canUseLastOffsetValue(
MachineInstr *MI,
unsigned &BasePos,
306 unsigned &OffsetPos,
unsigned &NewBase,
308 void postprocessDAG();
310 void setMII(
unsigned ResMII,
unsigned RecMII);
319 bool HasRecurrence =
false;
323 unsigned Colocate = 0;
324 SUnit *ExceedPressure =
nullptr;
333 for (
unsigned i = 0,
e = Nodes.
size(); i <
e; ++i)
334 for (
const SDep &Succ : Nodes[i]->Succs)
335 if (Nodes.
count(Succ.getSUnit()))
336 Latency += Succ.getLatency();
343 template <
typename UnaryPredicate>
bool remove_if(UnaryPredicate
P) {
371 for (
SUnit *SU : *
this) {
384 HasRecurrence =
false;
388 ExceedPressure =
nullptr;
398 if (RecMII == RHS.RecMII) {
399 if (Colocate != 0 && RHS.Colocate != 0 && Colocate != RHS.Colocate)
400 return Colocate < RHS.Colocate;
401 if (MaxMOV == RHS.MaxMOV)
402 return MaxDepth > RHS.MaxDepth;
403 return MaxMOV < RHS.MaxMOV;
405 return RecMII > RHS.RecMII;
409 return RecMII == RHS.RecMII && MaxMOV == RHS.MaxMOV &&
410 MaxDepth == RHS.MaxDepth;
419 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 433 std::unique_ptr<DFAPacketizer> DFAResources;
444 : STI(ST), SM(ST->getSchedModel()), UseDFA(ST->useDFAforSMS()),
445 ProcResourceMasks(SM.getNumProcResourceKinds(), 0),
446 ProcResourceCount(SM.getNumProcResourceKinds(), 0) {
449 initProcResourceVectors(SM, ProcResourceMasks);
456 bool canReserveResources(
const MCInstrDesc *MID)
const;
471 void clearResources();
488 std::map<SUnit *, int> InstrToCycle;
498 int InitiationInterval = 0;
510 : ST(mf->getSubtarget()), MRI(mf->getRegInfo()), ProcItinResources(&ST) {}
513 ScheduledInstrs.
clear();
514 InstrToCycle.clear();
517 InitiationInterval = 0;
532 int earliestCycleInChain(
const SDep &Dep);
536 int latestCycleInChain(
const SDep &Dep);
538 void computeStart(
SUnit *SU,
int *MaxEarlyStart,
int *MinLateStart,
540 bool insert(
SUnit *SU,
int StartCycle,
int EndCycle,
int II);
549 return (stageScheduled(SU) == (
int)StageNum);
555 std::map<SUnit *, int>::const_iterator it = InstrToCycle.find(SU);
556 if (it == InstrToCycle.end())
558 return (it->second - FirstCycle) / InitiationInterval;
564 std::map<SUnit *, int>::const_iterator it = InstrToCycle.find(SU);
565 assert(it != InstrToCycle.end() &&
"Instruction hasn't been scheduled.");
566 return (it->second - FirstCycle) % InitiationInterval;
571 return (LastCycle - FirstCycle) / InitiationInterval;
576 return ScheduledInstrs[cycle];
582 std::deque<SUnit *> &Insts);
592 #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.
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
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...
Describe properties that are true of each instruction in the target description file.
const MachineLoopInfo * MLI
ResourceManager(const TargetSubtargetInfo *ST)
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...
virtual DFAPacketizer * CreateTargetScheduleState(const TargetSubtargetInfo &) const
Create machine specific model for scheduling.
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)
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.
virtual const TargetInstrInfo * getInstrInfo() const
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
SwingSchedulerDAG(MachinePipeliner &P, MachineLoop &L, LiveIntervals &lis, const RegisterClassInfo &rci, unsigned II)
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
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
static const int DefaultProcResSize
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Align max(MaybeAlign Lhs, Align Rhs)
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...
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.
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.
Generic base class for all target subtargets.
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.
Machine model for scheduling, bundling, and heuristics.
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...