37#define DEBUG_TYPE "machine-trace-metrics"
59 "Machine Trace Metrics",
false,
true)
77 TII = ST.getInstrInfo();
78 TRI = ST.getRegisterInfo();
79 MRI = &MF->getRegInfo();
82 BlockInfo.resize(MF->getNumBlockIDs());
83 ProcReleaseAtCycles.resize(MF->getNumBlockIDs() *
84 SchedModel.getNumProcResourceKinds());
97 for (
auto &E : Ensembles)
121 unsigned PRKinds = SchedModel.getNumProcResourceKinds();
124 for (
const auto &
MI : *
MBB) {
125 if (
MI.isTransient())
132 if (!SchedModel.hasInstrSchedModel())
139 PI = SchedModel.getWriteProcResBegin(SC),
140 PE = SchedModel.getWriteProcResEnd(SC); PI != PE; ++PI) {
141 assert(PI->ProcResourceIdx < PRKinds &&
"Bad processor resource kind");
142 PRCycles[PI->ProcResourceIdx] += PI->ReleaseAtCycle;
148 unsigned PROffset =
MBB->getNumber() * PRKinds;
149 for (
unsigned K = 0; K != PRKinds; ++K)
150 ProcReleaseAtCycles[PROffset + K] =
151 PRCycles[K] * SchedModel.getResourceFactor(K);
158 assert(BlockInfo[MBBNum].hasResources() &&
159 "getResources() must be called before getProcReleaseAtCycles()");
160 unsigned PRKinds = SchedModel.getNumProcResourceKinds();
161 assert((MBBNum+1) * PRKinds <= ProcReleaseAtCycles.size());
162 return ArrayRef(ProcReleaseAtCycles.data() + MBBNum * PRKinds, PRKinds);
171 BlockInfo.resize(
MTM.BlockInfo.size());
172 unsigned PRKinds =
MTM.SchedModel.getNumProcResourceKinds();
173 ProcResourceDepths.resize(
MTM.BlockInfo.size() * PRKinds);
174 ProcResourceHeights.resize(
MTM.BlockInfo.size() * PRKinds);
182 return MTM.Loops->getLoopFor(
MBB);
187void MachineTraceMetrics::Ensemble::
190 unsigned PRKinds = MTM.SchedModel.getNumProcResourceKinds();
191 unsigned PROffset =
MBB->getNumber() * PRKinds;
197 std::fill(ProcResourceDepths.begin() + PROffset,
198 ProcResourceDepths.begin() + PROffset + PRKinds, 0);
205 TraceBlockInfo *PredTBI = &BlockInfo[PredNum];
206 assert(PredTBI->hasValidDepth() &&
"Trace above has not been computed yet");
207 const FixedBlockInfo *PredFBI = MTM.getResources(TBI->
Pred);
208 TBI->
InstrDepth = PredTBI->InstrDepth + PredFBI->InstrCount;
209 TBI->
Head = PredTBI->Head;
214 for (
unsigned K = 0; K != PRKinds; ++K)
215 ProcResourceDepths[PROffset + K] = PredPRDepths[K] + PredPRCycles[K];
220void MachineTraceMetrics::Ensemble::
222 TraceBlockInfo *TBI = &BlockInfo[
MBB->getNumber()];
223 unsigned PRKinds = MTM.SchedModel.getNumProcResourceKinds();
224 unsigned PROffset =
MBB->getNumber() * PRKinds;
227 TBI->InstrHeight = MTM.getResources(
MBB)->InstrCount;
232 TBI->Tail =
MBB->getNumber();
233 llvm::copy(PRCycles, ProcResourceHeights.begin() + PROffset);
239 unsigned SuccNum = TBI->Succ->getNumber();
241 assert(SuccTBI->hasValidHeight() &&
"Trace below has not been computed yet");
242 TBI->InstrHeight += SuccTBI->InstrHeight;
243 TBI->Tail = SuccTBI->Tail;
246 ArrayRef<unsigned> SuccPRHeights = getProcResourceHeights(SuccNum);
247 for (
unsigned K = 0;
K != PRKinds; ++
K)
248 ProcResourceHeights[PROffset + K] = SuccPRHeights[K] + PRCycles[K];
253const MachineTraceMetrics::TraceBlockInfo*
278 unsigned PRKinds =
MTM.SchedModel.getNumProcResourceKinds();
279 assert((MBBNum+1) * PRKinds <= ProcResourceDepths.size());
280 return ArrayRef(ProcResourceDepths.data() + MBBNum * PRKinds, PRKinds);
291 unsigned PRKinds =
MTM.SchedModel.getNumProcResourceKinds();
292 assert((MBBNum+1) * PRKinds <= ProcResourceHeights.size());
293 return ArrayRef(ProcResourceHeights.data() + MBBNum * PRKinds, PRKinds);
325 const char *
getName()
const override {
return "MinInstr"; }
326 const MachineBasicBlock *pickTracePred(
const MachineBasicBlock*)
override;
327 const MachineBasicBlock *pickTraceSucc(
const MachineBasicBlock*)
override;
330 MinInstrCountEnsemble(MachineTraceMetrics *mtm)
331 : MachineTraceMetrics::Ensemble(mtm) {}
337 const char *
getName()
const override {
return "Local"; }
338 const MachineBasicBlock *pickTracePred(
const MachineBasicBlock *)
override {
341 const MachineBasicBlock *pickTraceSucc(
const MachineBasicBlock *)
override {
346 LocalEnsemble(MachineTraceMetrics *MTM)
347 : MachineTraceMetrics::Ensemble(MTM) {}
352const MachineBasicBlock*
353MinInstrCountEnsemble::pickTracePred(
const MachineBasicBlock *
MBB) {
356 const MachineLoop *CurLoop = getLoopFor(
MBB);
360 unsigned CurCount = MTM.getResources(
MBB)->InstrCount;
361 const MachineBasicBlock *Best =
nullptr;
362 unsigned BestDepth = 0;
364 const MachineTraceMetrics::TraceBlockInfo *PredTBI =
365 getDepthResources(Pred);
371 if (!Best ||
Depth < BestDepth) {
380const MachineBasicBlock*
381MinInstrCountEnsemble::pickTraceSucc(
const MachineBasicBlock *
MBB) {
384 const MachineLoop *CurLoop = getLoopFor(
MBB);
385 const MachineBasicBlock *Best =
nullptr;
386 unsigned BestHeight = 0;
389 if (CurLoop && Succ == CurLoop->
getHeader())
394 const MachineTraceMetrics::TraceBlockInfo *SuccTBI =
395 getHeightResources(Succ);
401 if (!Best || Height < BestHeight) {
413 "Invalid trace strategy enum");
414 std::unique_ptr<MachineTraceMetrics::Ensemble> &E =
415 Ensembles[
static_cast<size_t>(strategy)];
422 E = std::make_unique<MinInstrCountEnsemble>(MinInstrCountEnsemble(
this));
425 E = std::make_unique<LocalEnsemble>(LocalEnsemble(
this));
435 BlockInfo[
MBB->getNumber()].invalidate();
436 for (
auto &E : Ensembles)
443 MachineFunctionAnalysisManager::Invalidator &) {
447 return !PAC.preserved() &&
456 assert(BlockInfo.size() == MF->getNumBlockIDs() &&
"Outdated BlockInfo size");
457 for (
auto &E : Ensembles)
477 bool Downward =
false;
487template <
typename GraphT>
490 GraphTraits<GraphT>> {
499 bool insertEdge(std::optional<const MachineBasicBlock *> From,
507 if (
const MachineLoop *FromLoop = LB.Loops->getLoopFor(*From)) {
509 if ((LB.Downward ? To : *From) == FromLoop->getHeader())
518 return LB.Visited.insert(To).second;
523void MachineTraceMetrics::Ensemble::computeTrace(
const MachineBasicBlock *
MBB) {
527 LoopBounds Bounds(BlockInfo, MTM.Loops);
530 Bounds.Downward =
false;
531 Bounds.Visited.clear();
533 LoopBoundsPostOrderTraversal<Inverse<const MachineBasicBlock *>>(
538 TBI.
Pred = pickTracePred(
I);
546 computeDepthResources(
I);
550 Bounds.Downward =
true;
551 Bounds.Visited.clear();
553 LoopBoundsPostOrderTraversal<const MachineBasicBlock *>(
MBB, Bounds)) {
557 TBI.
Succ = pickTraceSucc(
I);
565 computeHeightResources(
I);
597 }
while (!WorkList.
empty());
622 }
while (!WorkList.
empty());
630 for (
const auto &
I : *BadMBB)
636 assert(BlockInfo.size() ==
MTM.MF->getNumBlockIDs() &&
637 "Outdated BlockInfo size");
638 for (
unsigned Num = 0, e = BlockInfo.size(); Num != e; ++Num) {
642 assert(
MBB->isPredecessor(TBI.
Pred) &&
"CFG doesn't match trace");
644 "Trace is broken, depth should have been invalidated.");
650 assert(
MBB->isSuccessor(TBI.
Succ) &&
"CFG doesn't match trace");
652 "Trace is broken, height should have been invalidated.");
656 "Trace contains backedge");
688 assert(DefMO &&
"Register does not have unique def");
702 if (
UseMI.isDebugInstr())
705 bool HasPhysRegs =
false;
712 if (
Reg.isPhysical()) {
734 for (
unsigned i = 1; i !=
UseMI.getNumOperands(); i += 2) {
735 if (
UseMI.getOperand(i + 1).getMBB() == Pred) {
753 if (!MO.isReg() || !MO.getReg().isPhysical())
762 }
else if (MO.isKill())
767 for (MCRegUnit Unit :
TRI->regunits(
Reg)) {
769 if (
I == RegUnits.
end())
771 Deps.
push_back(DataDep(
I->MI,
I->Op, MO.getOperandNo()));
779 for (MCRegUnit Unit :
TRI->regunits(
Kill))
780 RegUnits.
erase(Unit);
783 for (
unsigned DefOp : LiveDefOps) {
784 for (MCRegUnit Unit :
785 TRI->regunits(
UseMI->getOperand(DefOp).getReg().asMCReg())) {
804unsigned MachineTraceMetrics::Ensemble::
806 assert(TBI.HasValidInstrDepths &&
"Missing depth info");
807 assert(TBI.HasValidInstrHeights &&
"Missing height info");
809 for (
const LiveInReg &LIR : TBI.LiveIns) {
810 if (!LIR.VRegOrUnit.isVirtualReg())
812 const MachineInstr *
DefMI =
813 MTM.MRI->getVRegDef(LIR.VRegOrUnit.asVirtualReg());
816 if (!DefTBI.isUsefulDominator(TBI))
818 unsigned Len = LIR.Height + Cycles[
DefMI].Depth;
819 MaxLen = std::max(MaxLen, Len);
836 for (
const DataDep &Dep : Deps) {
838 BlockInfo[Dep.DefMI->getParent()->getNumber()];
843 unsigned DepCycle = Cycles.lookup(Dep.DefMI).Depth;
845 if (!Dep.DefMI->isTransient())
846 DepCycle +=
MTM.SchedModel
847 .computeOperandLatency(Dep.DefMI, Dep.DefOp, &
UseMI, Dep.UseOp);
872 for (; Start != End; Start++)
878void MachineTraceMetrics::Ensemble::
889 Stack.push_back(
MBB);
901 while (!Stack.empty()) {
902 MBB = Stack.pop_back_val();
904 TraceBlockInfo &TBI = BlockInfo[
MBB->getNumber()];
906 TBI.CriticalPath = 0;
910 dbgs() <<
format(
"%7u Instructions\n", TBI.InstrDepth);
912 for (
unsigned K = 0; K != PRDepths.
size(); ++K)
914 unsigned Factor = MTM.SchedModel.getResourceFactor(K);
915 dbgs() <<
format(
"%6uc @ ", MTM.getCycles(PRDepths[K]))
916 << MTM.SchedModel.getProcResource(K)->Name <<
" ("
917 << PRDepths[K]/Factor <<
" ops x" << Factor <<
")\n";
922 if (TBI.HasValidInstrHeights)
923 TBI.CriticalPath = computeCrossBlockCriticalPath(TBI);
926 updateDepth(TBI,
UseMI, RegUnits);
945 if (!
Reg.isPhysical())
953 for (MCRegUnit Unit :
TRI->regunits(
Reg.asMCReg())) {
955 if (
I == RegUnits.
end())
957 unsigned DepHeight =
I->Cycle;
958 if (!
MI.isTransient()) {
964 Height = std::max(Height, DepHeight);
971 for (
unsigned Op : ReadOps) {
973 for (MCRegUnit Unit :
TRI->regunits(
Reg)) {
976 if (LRU.
Cycle <= Height && LRU.
MI != &
MI) {
1003 std::tie(
I, New) = Heights.
insert(std::make_pair(Dep.DefMI, UseHeight));
1008 if (
I->second < UseHeight)
1009 I->second = UseHeight;
1016void MachineTraceMetrics::Ensemble::
1017addLiveIns(
const MachineInstr *
DefMI,
unsigned DefOp,
1019 assert(!
Trace.empty() &&
"Trace should contain at least one block");
1030 TBI.
LiveIns.emplace_back(VirtRegOrUnit(
Reg));
1037void MachineTraceMetrics::Ensemble::
1038computeInstrHeights(
const MachineBasicBlock *
MBB) {
1044 assert(TBI.hasValidHeight() &&
"Incomplete trace");
1045 if (TBI.HasValidInstrHeights)
1048 TBI.LiveIns.clear();
1067 if (LI.VRegOrUnit.isVirtualReg()) {
1070 Heights[MTM.MRI->getVRegDef(LI.VRegOrUnit.asVirtualReg())];
1071 if (Height < LI.Height)
1076 RegUnits[LI.VRegOrUnit.asMCRegUnit()].Cycle = LI.Height;
1088 TBI.CriticalPath = 0;
1091 dbgs() <<
format(
"%7u Instructions\n", TBI.InstrHeight);
1092 ArrayRef<unsigned> PRHeights = getProcResourceHeights(
MBB->
getNumber());
1093 for (
unsigned K = 0;
K != PRHeights.
size(); ++
K)
1095 unsigned Factor = MTM.SchedModel.getResourceFactor(K);
1096 dbgs() <<
format(
"%6uc @ ", MTM.getCycles(PRHeights[K]))
1097 << MTM.SchedModel.getProcResource(K)->Name <<
" ("
1098 << PRHeights[
K]/Factor <<
" ops x" << Factor <<
")\n";
1103 const MachineBasicBlock *Succ = TBI.Succ;
1108 if (
const MachineLoop *Loop = getLoopFor(
MBB))
1110 Succ = Loop->getHeader();
1113 for (
const auto &
PHI : *Succ) {
1118 if (!Deps.
empty()) {
1120 unsigned Height = TBI.Succ ? Cycles.lookup(&
PHI).Height : 0;
1135 if (HeightI != Heights.
end()) {
1136 Cycle = HeightI->second;
1138 Heights.
erase(HeightI);
1152 for (
const DataDep &Dep : Deps)
1158 if (!TBI.HasValidInstrDepths) {
1163 TBI.CriticalPath = std::max(TBI.CriticalPath,
Cycle + MICycles.Depth);
1172 const MachineInstr *
DefMI = MTM.MRI->getVRegDef(
Reg);
1178 for (
const LiveRegUnit &RU : RegUnits) {
1179 TBI.LiveIns.emplace_back(VirtRegOrUnit(RU.RegUnit), RU.Cycle);
1185 if (!TBI.HasValidInstrDepths)
1188 TBI.CriticalPath = std::max(TBI.CriticalPath,
1189 computeCrossBlockCriticalPath(TBI));
1190 LLVM_DEBUG(
dbgs() <<
"Critical path: " << TBI.CriticalPath <<
'\n');
1201 computeInstrDepths(
MBB);
1203 computeInstrHeights(
MBB);
1205 return Trace(*
this, TBI);
1210 assert(getBlockNum() ==
unsigned(
MI.getParent()->getNumber()) &&
1211 "MI must be in the trace center block");
1221 assert(Deps.
size() == 1 &&
"PHI doesn't have MBB as a predecessor");
1222 DataDep &Dep = Deps.
front();
1226 DepCycle += TE.MTM.SchedModel.computeOperandLatency(Dep.DefMI, Dep.DefOp,
1239 for (
unsigned K = 0; K != PRDepths.
size(); ++K)
1240 PRMax = std::max(PRMax, PRDepths[K] + PRCycles[K]);
1242 for (
unsigned PRD : PRDepths)
1243 PRMax = std::max(PRMax, PRD);
1246 PRMax = TE.MTM.getCycles(PRMax);
1249 unsigned Instrs = TBI.InstrDepth;
1252 Instrs += TE.MTM.BlockInfo[getBlockNum()].InstrCount;
1253 if (
unsigned IW = TE.MTM.SchedModel.getIssueWidth())
1256 return std::max(Instrs, PRMax);
1270 unsigned ResourceIdx)
1272 unsigned Cycles = 0;
1277 PI = TE.MTM.SchedModel.getWriteProcResBegin(SC),
1278 PE = TE.MTM.SchedModel.getWriteProcResEnd(SC);
1280 if (PI->ProcResourceIdx != ResourceIdx)
1282 Cycles += (PI->ReleaseAtCycle *
1283 TE.MTM.SchedModel.getResourceFactor(ResourceIdx));
1289 for (
unsigned K = 0; K != PRDepths.
size(); ++K) {
1290 unsigned PRCycles = PRDepths[K] + PRHeights[K];
1292 PRCycles += TE.MTM.getProcReleaseAtCycles(
MBB->getNumber())[K];
1293 PRCycles += extraCycles(ExtraInstrs, K);
1294 PRCycles -= extraCycles(RemoveInstrs, K);
1295 PRMax = std::max(PRMax, PRCycles);
1298 PRMax = TE.MTM.getCycles(PRMax);
1301 unsigned Instrs = TBI.InstrDepth + TBI.InstrHeight;
1304 Instrs += TE.MTM.getResources(
MBB)->InstrCount;
1305 Instrs += ExtraInstrs.
size();
1306 Instrs -= RemoveInstrs.
size();
1307 if (
unsigned IW = TE.MTM.SchedModel.getIssueWidth())
1310 return std::max(Instrs, PRMax);
1325 OS <<
getName() <<
" ensemble:\n";
1326 for (
unsigned i = 0, e = BlockInfo.size(); i != e; ++i) {
1327 OS <<
" %bb." << i <<
'\t';
1328 BlockInfo[i].print(OS);
1340 OS <<
" head=%bb." <<
Head;
1344 OS <<
"depth invalid";
1352 OS <<
" tail=%bb." <<
Tail;
1356 OS <<
"height invalid";
1362 unsigned MBBNum = &TBI - &TE.BlockInfo[0];
1364 OS << TE.getName() <<
" trace %bb." << TBI.Head <<
" --> %bb." << MBBNum
1365 <<
" --> %bb." << TBI.Tail <<
':';
1366 if (TBI.hasValidHeight() && TBI.hasValidDepth())
1368 if (TBI.HasValidInstrDepths && TBI.HasValidInstrHeights)
1369 OS <<
' ' << TBI.CriticalPath <<
" cycles.";
1372 OS <<
"\n%bb." << MBBNum;
1373 while (
Block->hasValidDepth() &&
Block->Pred) {
1374 unsigned Num =
Block->Pred->getNumber();
1376 Block = &TE.BlockInfo[Num];
1381 while (
Block->hasValidHeight() &&
Block->Succ) {
1382 unsigned Num =
Block->Succ->getNumber();
1384 Block = &TE.BlockInfo[Num];
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
bbsections Prepares for basic block by splitting functions into clusters of basic blocks
static unsigned InstrCount
This file defines the DenseMap class.
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
static bool pushDepHeight(const DataDep &Dep, const MachineInstr &UseMI, unsigned UseHeight, MIHeightMap &Heights, const TargetSchedModel &SchedModel, const TargetInstrInfo *TII)
static void getPHIDeps(const MachineInstr &UseMI, SmallVectorImpl< DataDep > &Deps, const MachineBasicBlock *Pred, const MachineRegisterInfo *MRI)
static bool getDataDeps(const MachineInstr &UseMI, SmallVectorImpl< DataDep > &Deps, const MachineRegisterInfo *MRI)
DenseMap< const MachineInstr *, unsigned > MIHeightMap
static bool isExitingLoop(const MachineLoop *From, const MachineLoop *To)
static unsigned updatePhysDepsUpwards(const MachineInstr &MI, unsigned Height, LiveRegUnitSet &RegUnits, const TargetSchedModel &SchedModel, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI)
static void updatePhysDepsDownwards(const MachineInstr *UseMI, SmallVectorImpl< DataDep > &Deps, LiveRegUnitSet &RegUnits, const TargetRegisterInfo *TRI)
Promote Memory to Register
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
static StringRef getName(Value *V)
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the SparseSet class derived from the version described in Briggs,...
LoopBoundsPostOrderTraversal(const MachineBasicBlock *Start, LoopBounds &LB)
bool insertEdge(std::optional< const MachineBasicBlock * > From, const MachineBasicBlock *To)
This templated class represents "all analyses that operate over <aparticular IR unit>" (e....
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Represents analyses that only rely on functions' control flow.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
BlockT * getHeader() const
Represents a single loop in the control flow graph.
Wrapper class representing physical registers. Should be passed by value.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
LLVM_ABI bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
iterator_range< succ_iterator > successors()
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
iterator_range< pred_iterator > predecessors()
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass(char &ID)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
bool isTransient() const
Return true if this is a transient instruction that is either very likely to be eliminated during reg...
const MachineOperand & getOperand(unsigned i) const
Analysis pass that exposes the MachineLoopInfo for a machine function.
MachineOperand class - Representation of each machine instruction operand.
LLVM_ABI unsigned getOperandNo() const
Returns the index of this operand in the instruction that it belongs to.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
MachineOperand * getOneDef(Register Reg) const
Returns the defining operand if there is exactly one operand defining the specified register,...
Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
MachineTraceMetrics Result
void getAnalysisUsage(AnalysisUsage &) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
bool runOnMachineFunction(MachineFunction &) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
MachineTraceMetricsWrapperPass()
void invalidate(const MachineBasicBlock *MBB)
Invalidate traces through BadMBB.
ArrayRef< unsigned > getProcResourceHeights(unsigned MBBNum) const
Get an array of processor resource heights for MBB.
void updateDepth(TraceBlockInfo &TBI, const MachineInstr &, LiveRegUnitSet &RegUnits)
Updates the depth of an machine instruction, given RegUnits.
const MachineLoop * getLoopFor(const MachineBasicBlock *) const
void updateDepths(MachineBasicBlock::iterator Start, MachineBasicBlock::iterator End, LiveRegUnitSet &RegUnits)
Updates the depth of the instructions from Start to End.
const TraceBlockInfo * getHeightResources(const MachineBasicBlock *) const
const TraceBlockInfo * getDepthResources(const MachineBasicBlock *) const
ArrayRef< unsigned > getProcResourceDepths(unsigned MBBNum) const
Get an array of processor resource depths for MBB.
Ensemble(MachineTraceMetrics *)
MachineTraceMetrics & MTM
void print(raw_ostream &) const
Trace getTrace(const MachineBasicBlock *MBB)
Get the trace that passes through MBB.
A trace represents a plausible sequence of executed basic blocks that passes through the current basi...
unsigned getInstrCount() const
Compute the total number of instructions in the trace.
unsigned getResourceLength(ArrayRef< const MachineBasicBlock * > Extrablocks={}, ArrayRef< const MCSchedClassDesc * > ExtraInstrs={}, ArrayRef< const MCSchedClassDesc * > RemoveInstrs={}) const
Return the resource length of the trace.
InstrCycles getInstrCycles(const MachineInstr &MI) const
Return the depth and height of MI.
unsigned getInstrSlack(const MachineInstr &MI) const
Return the slack of MI.
bool isDepInTrace(const MachineInstr &DefMI, const MachineInstr &UseMI) const
A dependence is useful if the basic block of the defining instruction is part of the trace of the use...
unsigned getCriticalPath() const
Return the length of the (data dependency) critical path through the trace.
unsigned getPHIDepth(const MachineInstr &PHI) const
Return the Depth of a PHI instruction in a trace center block successor.
void print(raw_ostream &) const
unsigned getResourceDepth(bool Bottom) const
Return the resource depth of the top/bottom of the trace center block.
MachineTraceMetrics()=default
Ensemble * getEnsemble(MachineTraceStrategy)
Get the trace ensemble representing the given trace selection strategy.
void verifyAnalysis() const
void invalidate(const MachineBasicBlock *MBB)
Invalidate cached information about MBB.
const FixedBlockInfo * getResources(const MachineBasicBlock *)
Get the fixed resource information about MBB. Compute it on demand.
ArrayRef< unsigned > getProcReleaseAtCycles(unsigned MBBNum) const
Get the scaled number of cycles used per processor resource in MBB.
void init(MachineFunction &Func, const MachineLoopInfo &LI)
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
PostOrderTraversalBase()=default
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.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
iterator erase(iterator I)
erase - Erases an existing element identified by a valid iterator.
const_iterator end() const
typename DenseT::iterator iterator
iterator find(const KeyT &Key)
find - Find an element by its key.
void setUniverse(unsigned U)
setUniverse - Set the universe size which determines the largest key the set can hold.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Provide an instruction scheduling machine model to CodeGen passes.
const MCWriteProcResEntry * ProcResIter
LLVM_ABI unsigned computeOperandLatency(const MachineInstr *DefMI, unsigned DefOperIdx, const MachineInstr *UseMI, unsigned UseOperIdx) const
Compute operand latency based on the available machine model.
TargetSubtargetInfo - Generic base class for all target subtargets.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
MachineTraceStrategy
Strategies for selecting traces.
@ TS_MinInstrCount
Select the trace through a block that has the fewest instructions.
@ TS_Local
Select the trace that contains only the current basic block.
@ Kill
The last use of a register.
LLVM_ABI Printable printRegUnit(MCRegUnit Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
SparseSet< LiveRegUnit, MCRegUnit, MCRegUnitToIndex > LiveRegUnitSet
LLVM_ABI char & MachineTraceMetricsID
MachineTraceMetrics - This pass computes critical path and CPU resource usage in an ensemble of trace...
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
void addLiveIns(MachineBasicBlock &MBB, const LivePhysRegs &LiveRegs)
Adds registers contained in LiveRegs to the block live-in list of MBB.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Summarize the scheduling resources required for an instruction of a particular scheduling class.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Per-basic block information that doesn't depend on the trace through the block.
bool hasResources() const
Returns true when resource information for this block has been computed.
unsigned InstrCount
The number of non-trivial instructions in the block.
bool HasCalls
True when the block contains calls.
InstrCycles represents the cycle height and depth of an instruction in a trace.
unsigned Height
Minimum number of cycles from this instruction is issued to the of the trace, as determined by data d...
unsigned Depth
Earliest issue cycle as determined by data dependencies and instruction latencies from the beginning ...
A virtual register or regunit required by a basic block or its trace successors.
Per-basic block information that relates to a specific trace through the block.
unsigned InstrDepth
Accumulated number of instructions in the trace above this block.
void invalidateDepth()
Invalidate depth resources when some block above this one has changed.
const MachineBasicBlock * Pred
Trace predecessor, or NULL for the first block in the trace.
unsigned InstrHeight
Accumulated number of instructions in the trace below this block.
SmallVector< LiveInReg, 4 > LiveIns
Live-in registers.
const MachineBasicBlock * Succ
Trace successor, or NULL for the last block in the trace.
bool hasValidDepth() const
Returns true if the depth resources have been computed from the trace above this block.
bool isUsefulDominator(const TraceBlockInfo &TBI) const
Assuming that this is a dominator of TBI, determine if it contains useful instruction depths.
void invalidateHeight()
Invalidate height resources when a block below this one has changed.
unsigned CriticalPath
Critical path length.
void print(raw_ostream &) const
unsigned Head
The block number of the head of the trace. (When hasValidDepth()).
bool HasValidInstrDepths
Instruction depths have been computed. This implies hasValidDepth().
bool hasValidHeight() const
Returns true if the height resources have been computed from the trace below this block.
unsigned Tail
The block number of the tail of the trace. (When hasValidHeight()).
bool HasValidInstrHeights
Instruction heights have been computed. This implies hasValidHeight().