38#define DEBUG_TYPE "machine-trace-metrics"
60 "Machine Trace Metrics",
false,
true)
78 TII = ST.getInstrInfo();
79 TRI = ST.getRegisterInfo();
80 MRI = &MF->getRegInfo();
83 BlockInfo.resize(MF->getNumBlockIDs());
84 ProcReleaseAtCycles.resize(MF->getNumBlockIDs() *
85 SchedModel.getNumProcResourceKinds());
98 for (
auto &E : Ensembles)
122 unsigned PRKinds = SchedModel.getNumProcResourceKinds();
125 for (
const auto &
MI : *
MBB) {
126 if (
MI.isTransient())
133 if (!SchedModel.hasInstrSchedModel())
140 PI = SchedModel.getWriteProcResBegin(SC),
141 PE = SchedModel.getWriteProcResEnd(SC); PI != PE; ++PI) {
142 assert(PI->ProcResourceIdx < PRKinds &&
"Bad processor resource kind");
143 PRCycles[PI->ProcResourceIdx] += PI->ReleaseAtCycle;
149 unsigned PROffset =
MBB->getNumber() * PRKinds;
150 for (
unsigned K = 0; K != PRKinds; ++K)
151 ProcReleaseAtCycles[PROffset + K] =
152 PRCycles[K] * SchedModel.getResourceFactor(K);
159 assert(BlockInfo[MBBNum].hasResources() &&
160 "getResources() must be called before getProcReleaseAtCycles()");
161 unsigned PRKinds = SchedModel.getNumProcResourceKinds();
162 assert((MBBNum+1) * PRKinds <= ProcReleaseAtCycles.size());
163 return ArrayRef(ProcReleaseAtCycles.data() + MBBNum * PRKinds, PRKinds);
172 BlockInfo.resize(
MTM.BlockInfo.size());
173 unsigned PRKinds =
MTM.SchedModel.getNumProcResourceKinds();
174 ProcResourceDepths.resize(
MTM.BlockInfo.size() * PRKinds);
175 ProcResourceHeights.resize(
MTM.BlockInfo.size() * PRKinds);
183 return MTM.Loops->getLoopFor(
MBB);
188void MachineTraceMetrics::Ensemble::
191 unsigned PRKinds = MTM.SchedModel.getNumProcResourceKinds();
192 unsigned PROffset =
MBB->getNumber() * PRKinds;
198 std::fill(ProcResourceDepths.begin() + PROffset,
199 ProcResourceDepths.begin() + PROffset + PRKinds, 0);
206 TraceBlockInfo *PredTBI = &BlockInfo[PredNum];
207 assert(PredTBI->hasValidDepth() &&
"Trace above has not been computed yet");
208 const FixedBlockInfo *PredFBI = MTM.getResources(TBI->
Pred);
209 TBI->
InstrDepth = PredTBI->InstrDepth + PredFBI->InstrCount;
210 TBI->
Head = PredTBI->Head;
215 for (
unsigned K = 0; K != PRKinds; ++K)
216 ProcResourceDepths[PROffset + K] = PredPRDepths[K] + PredPRCycles[K];
221void MachineTraceMetrics::Ensemble::
223 TraceBlockInfo *TBI = &BlockInfo[
MBB->getNumber()];
224 unsigned PRKinds = MTM.SchedModel.getNumProcResourceKinds();
225 unsigned PROffset =
MBB->getNumber() * PRKinds;
228 TBI->InstrHeight = MTM.getResources(
MBB)->InstrCount;
233 TBI->Tail =
MBB->getNumber();
234 llvm::copy(PRCycles, ProcResourceHeights.begin() + PROffset);
240 unsigned SuccNum = TBI->Succ->getNumber();
242 assert(SuccTBI->hasValidHeight() &&
"Trace below has not been computed yet");
243 TBI->InstrHeight += SuccTBI->InstrHeight;
244 TBI->Tail = SuccTBI->Tail;
247 ArrayRef<unsigned> SuccPRHeights = getProcResourceHeights(SuccNum);
248 for (
unsigned K = 0;
K != PRKinds; ++
K)
249 ProcResourceHeights[PROffset + K] = SuccPRHeights[K] + PRCycles[K];
254const MachineTraceMetrics::TraceBlockInfo*
279 unsigned PRKinds =
MTM.SchedModel.getNumProcResourceKinds();
280 assert((MBBNum+1) * PRKinds <= ProcResourceDepths.size());
281 return ArrayRef(ProcResourceDepths.data() + MBBNum * PRKinds, PRKinds);
292 unsigned PRKinds =
MTM.SchedModel.getNumProcResourceKinds();
293 assert((MBBNum+1) * PRKinds <= ProcResourceHeights.size());
294 return ArrayRef(ProcResourceHeights.data() + MBBNum * PRKinds, PRKinds);
326 const char *
getName()
const override {
return "MinInstr"; }
327 const MachineBasicBlock *pickTracePred(
const MachineBasicBlock*)
override;
328 const MachineBasicBlock *pickTraceSucc(
const MachineBasicBlock*)
override;
331 MinInstrCountEnsemble(MachineTraceMetrics *mtm)
332 : MachineTraceMetrics::Ensemble(mtm) {}
338 const char *
getName()
const override {
return "Local"; }
339 const MachineBasicBlock *pickTracePred(
const MachineBasicBlock *)
override {
342 const MachineBasicBlock *pickTraceSucc(
const MachineBasicBlock *)
override {
347 LocalEnsemble(MachineTraceMetrics *MTM)
348 : MachineTraceMetrics::Ensemble(MTM) {}
353const MachineBasicBlock*
354MinInstrCountEnsemble::pickTracePred(
const MachineBasicBlock *
MBB) {
357 const MachineLoop *CurLoop = getLoopFor(
MBB);
361 unsigned CurCount = MTM.getResources(
MBB)->InstrCount;
362 const MachineBasicBlock *Best =
nullptr;
363 unsigned BestDepth = 0;
365 const MachineTraceMetrics::TraceBlockInfo *PredTBI =
366 getDepthResources(Pred);
372 if (!Best ||
Depth < BestDepth) {
381const MachineBasicBlock*
382MinInstrCountEnsemble::pickTraceSucc(
const MachineBasicBlock *
MBB) {
385 const MachineLoop *CurLoop = getLoopFor(
MBB);
386 const MachineBasicBlock *Best =
nullptr;
387 unsigned BestHeight = 0;
390 if (CurLoop && Succ == CurLoop->
getHeader())
395 const MachineTraceMetrics::TraceBlockInfo *SuccTBI =
396 getHeightResources(Succ);
402 if (!Best || Height < BestHeight) {
414 "Invalid trace strategy enum");
415 std::unique_ptr<MachineTraceMetrics::Ensemble> &E =
416 Ensembles[
static_cast<size_t>(strategy)];
423 E = std::make_unique<MinInstrCountEnsemble>(MinInstrCountEnsemble(
this));
426 E = std::make_unique<LocalEnsemble>(LocalEnsemble(
this));
436 BlockInfo[
MBB->getNumber()].invalidate();
437 for (
auto &E : Ensembles)
444 MachineFunctionAnalysisManager::Invalidator &) {
448 return !PAC.preserved() &&
457 assert(BlockInfo.size() == MF->getNumBlockIDs() &&
"Outdated BlockInfo size");
458 for (
auto &E : Ensembles)
478 bool Downward =
false;
496 bool insertEdge(std::optional<const MachineBasicBlock *> From,
504 if (
const MachineLoop *FromLoop = LB.Loops->getLoopFor(*From)) {
506 if ((LB.Downward ? To : *From) == FromLoop->getHeader())
515 return LB.Visited.insert(To).second;
524 LoopBounds Bounds(BlockInfo, MTM.Loops);
527 Bounds.Downward =
false;
528 Bounds.Visited.clear();
531 TraceBlockInfo &TBI = BlockInfo[
I->getNumber()];
533 TBI.Pred = pickTracePred(
I);
541 computeDepthResources(
I);
545 Bounds.Downward =
true;
546 Bounds.Visited.clear();
551 TBI.
Succ = pickTraceSucc(
I);
559 computeHeightResources(
I);
591 }
while (!WorkList.
empty());
616 }
while (!WorkList.
empty());
624 for (
const auto &
I : *BadMBB)
630 assert(BlockInfo.size() ==
MTM.MF->getNumBlockIDs() &&
631 "Outdated BlockInfo size");
632 for (
unsigned Num = 0, e = BlockInfo.size(); Num != e; ++Num) {
636 assert(
MBB->isPredecessor(TBI.
Pred) &&
"CFG doesn't match trace");
638 "Trace is broken, depth should have been invalidated.");
644 assert(
MBB->isSuccessor(TBI.
Succ) &&
"CFG doesn't match trace");
646 "Trace is broken, height should have been invalidated.");
650 "Trace contains backedge");
682 assert(DefMO &&
"Register does not have unique def");
696 if (
UseMI.isDebugInstr())
699 bool HasPhysRegs =
false;
706 if (
Reg.isPhysical()) {
728 for (
unsigned i = 1; i !=
UseMI.getNumOperands(); i += 2) {
729 if (
UseMI.getOperand(i + 1).getMBB() == Pred) {
747 if (!MO.isReg() || !MO.getReg().isPhysical())
756 }
else if (MO.isKill())
763 if (
I == RegUnits.
end())
765 Deps.
push_back(DataDep(
I->MI,
I->Op, MO.getOperandNo()));
774 RegUnits.
erase(Unit);
777 for (
unsigned DefOp : LiveDefOps) {
779 TRI->regunits(
UseMI->getOperand(DefOp).getReg().asMCReg())) {
798unsigned MachineTraceMetrics::Ensemble::
800 assert(TBI.HasValidInstrDepths &&
"Missing depth info");
801 assert(TBI.HasValidInstrHeights &&
"Missing height info");
803 for (
const LiveInReg &LIR : TBI.LiveIns) {
804 if (!LIR.Reg.isVirtual())
806 const MachineInstr *
DefMI = MTM.MRI->getVRegDef(LIR.Reg);
809 if (!DefTBI.isUsefulDominator(TBI))
811 unsigned Len = LIR.Height + Cycles[
DefMI].Depth;
812 MaxLen = std::max(MaxLen, Len);
829 for (
const DataDep &Dep : Deps) {
831 BlockInfo[Dep.DefMI->getParent()->getNumber()];
836 unsigned DepCycle = Cycles.lookup(Dep.DefMI).Depth;
838 if (!Dep.DefMI->isTransient())
839 DepCycle +=
MTM.SchedModel
840 .computeOperandLatency(Dep.DefMI, Dep.DefOp, &
UseMI, Dep.UseOp);
866 for (; Start != End; Start++)
872void MachineTraceMetrics::Ensemble::
883 Stack.push_back(
MBB);
895 while (!Stack.empty()) {
896 MBB = Stack.pop_back_val();
898 TraceBlockInfo &TBI = BlockInfo[
MBB->getNumber()];
900 TBI.CriticalPath = 0;
904 dbgs() <<
format(
"%7u Instructions\n", TBI.InstrDepth);
906 for (
unsigned K = 0; K != PRDepths.
size(); ++K)
908 unsigned Factor = MTM.SchedModel.getResourceFactor(K);
909 dbgs() <<
format(
"%6uc @ ", MTM.getCycles(PRDepths[K]))
910 << MTM.SchedModel.getProcResource(K)->Name <<
" ("
911 << PRDepths[K]/Factor <<
" ops x" << Factor <<
")\n";
916 if (TBI.HasValidInstrHeights)
917 TBI.CriticalPath = computeCrossBlockCriticalPath(TBI);
920 updateDepth(TBI,
UseMI, RegUnits);
939 if (!
Reg.isPhysical())
949 if (
I == RegUnits.
end())
951 unsigned DepHeight =
I->Cycle;
952 if (!
MI.isTransient()) {
958 Height = std::max(Height, DepHeight);
965 for (
unsigned Op : ReadOps) {
970 if (LRU.
Cycle <= Height && LRU.
MI != &
MI) {
997 std::tie(
I, New) = Heights.
insert(std::make_pair(Dep.DefMI, UseHeight));
1002 if (
I->second < UseHeight)
1003 I->second = UseHeight;
1010void MachineTraceMetrics::Ensemble::
1011addLiveIns(
const MachineInstr *
DefMI,
unsigned DefOp,
1013 assert(!
Trace.empty() &&
"Trace should contain at least one block");
1031void MachineTraceMetrics::Ensemble::
1032computeInstrHeights(
const MachineBasicBlock *
MBB) {
1038 assert(TBI.hasValidHeight() &&
"Incomplete trace");
1039 if (TBI.HasValidInstrHeights)
1042 TBI.LiveIns.clear();
1052 SparseSet<LiveRegUnit> RegUnits;
1061 if (LI.Reg.isVirtual()) {
1063 unsigned &Height = Heights[MTM.MRI->getVRegDef(LI.Reg)];
1064 if (Height < LI.Height)
1069 RegUnits[LI.Reg.id()].Cycle = LI.Height;
1081 TBI.CriticalPath = 0;
1084 dbgs() <<
format(
"%7u Instructions\n", TBI.InstrHeight);
1085 ArrayRef<unsigned> PRHeights = getProcResourceHeights(
MBB->
getNumber());
1086 for (
unsigned K = 0;
K != PRHeights.
size(); ++
K)
1088 unsigned Factor = MTM.SchedModel.getResourceFactor(K);
1089 dbgs() <<
format(
"%6uc @ ", MTM.getCycles(PRHeights[K]))
1090 << MTM.SchedModel.getProcResource(K)->Name <<
" ("
1091 << PRHeights[
K]/Factor <<
" ops x" << Factor <<
")\n";
1096 const MachineBasicBlock *Succ = TBI.Succ;
1101 if (
const MachineLoop *Loop = getLoopFor(
MBB))
1103 Succ = Loop->getHeader();
1106 for (
const auto &
PHI : *Succ) {
1111 if (!Deps.
empty()) {
1113 unsigned Height = TBI.Succ ? Cycles.lookup(&
PHI).Height : 0;
1128 if (HeightI != Heights.
end()) {
1129 Cycle = HeightI->second;
1131 Heights.
erase(HeightI);
1145 for (
const DataDep &Dep : Deps)
1151 if (!TBI.HasValidInstrDepths) {
1156 TBI.CriticalPath = std::max(TBI.CriticalPath,
Cycle + MICycles.Depth);
1164 const MachineInstr *
DefMI = MTM.MRI->getVRegDef(LIR.Reg);
1170 for (
const LiveRegUnit &RU : RegUnits) {
1171 TBI.LiveIns.push_back(
LiveInReg(RU.RegUnit, RU.Cycle));
1177 if (!TBI.HasValidInstrDepths)
1180 TBI.CriticalPath = std::max(TBI.CriticalPath,
1181 computeCrossBlockCriticalPath(TBI));
1182 LLVM_DEBUG(
dbgs() <<
"Critical path: " << TBI.CriticalPath <<
'\n');
1193 computeInstrDepths(
MBB);
1195 computeInstrHeights(
MBB);
1197 return Trace(*
this, TBI);
1202 assert(getBlockNum() ==
unsigned(
MI.getParent()->getNumber()) &&
1203 "MI must be in the trace center block");
1213 assert(Deps.
size() == 1 &&
"PHI doesn't have MBB as a predecessor");
1214 DataDep &Dep = Deps.
front();
1218 DepCycle += TE.MTM.SchedModel.computeOperandLatency(Dep.DefMI, Dep.DefOp,
1231 for (
unsigned K = 0; K != PRDepths.
size(); ++K)
1232 PRMax = std::max(PRMax, PRDepths[K] + PRCycles[K]);
1234 for (
unsigned PRD : PRDepths)
1235 PRMax = std::max(PRMax, PRD);
1238 PRMax = TE.MTM.getCycles(PRMax);
1241 unsigned Instrs = TBI.InstrDepth;
1244 Instrs += TE.MTM.BlockInfo[getBlockNum()].InstrCount;
1245 if (
unsigned IW = TE.MTM.SchedModel.getIssueWidth())
1248 return std::max(Instrs, PRMax);
1262 unsigned ResourceIdx)
1264 unsigned Cycles = 0;
1269 PI = TE.MTM.SchedModel.getWriteProcResBegin(SC),
1270 PE = TE.MTM.SchedModel.getWriteProcResEnd(SC);
1272 if (PI->ProcResourceIdx != ResourceIdx)
1274 Cycles += (PI->ReleaseAtCycle *
1275 TE.MTM.SchedModel.getResourceFactor(ResourceIdx));
1281 for (
unsigned K = 0; K != PRDepths.
size(); ++K) {
1282 unsigned PRCycles = PRDepths[K] + PRHeights[K];
1284 PRCycles += TE.MTM.getProcReleaseAtCycles(
MBB->getNumber())[K];
1285 PRCycles += extraCycles(ExtraInstrs, K);
1286 PRCycles -= extraCycles(RemoveInstrs, K);
1287 PRMax = std::max(PRMax, PRCycles);
1290 PRMax = TE.MTM.getCycles(PRMax);
1293 unsigned Instrs = TBI.InstrDepth + TBI.InstrHeight;
1296 Instrs += TE.MTM.getResources(
MBB)->InstrCount;
1297 Instrs += ExtraInstrs.
size();
1298 Instrs -= RemoveInstrs.
size();
1299 if (
unsigned IW = TE.MTM.SchedModel.getIssueWidth())
1302 return std::max(Instrs, PRMax);
1317 OS <<
getName() <<
" ensemble:\n";
1318 for (
unsigned i = 0, e = BlockInfo.size(); i != e; ++i) {
1319 OS <<
" %bb." << i <<
'\t';
1320 BlockInfo[i].print(OS);
1332 OS <<
" head=%bb." <<
Head;
1336 OS <<
"depth invalid";
1344 OS <<
" tail=%bb." <<
Tail;
1348 OS <<
"height invalid";
1354 unsigned MBBNum = &TBI - &TE.BlockInfo[0];
1356 OS << TE.getName() <<
" trace %bb." << TBI.Head <<
" --> %bb." << MBBNum
1357 <<
" --> %bb." << TBI.Tail <<
':';
1358 if (TBI.hasValidHeight() && TBI.hasValidDepth())
1360 if (TBI.HasValidInstrDepths && TBI.HasValidInstrHeights)
1361 OS <<
' ' << TBI.CriticalPath <<
" cycles.";
1364 OS <<
"\n%bb." << MBBNum;
1365 while (
Block->hasValidDepth() &&
Block->Pred) {
1366 unsigned Num =
Block->Pred->getNumber();
1368 Block = &TE.BlockInfo[Num];
1373 while (
Block->hasValidHeight() &&
Block->Succ) {
1374 unsigned Num =
Block->Succ->getNumber();
1376 Block = &TE.BlockInfo[Num];
unsigned const MachineRegisterInfo * MRI
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)
static void updatePhysDepsDownwards(const MachineInstr *UseMI, SmallVectorImpl< DataDep > &Deps, SparseSet< LiveRegUnit > &RegUnits, const TargetRegisterInfo *TRI)
static unsigned updatePhysDepsUpwards(const MachineInstr &MI, unsigned Height, SparseSet< LiveRegUnit > &RegUnits, const TargetSchedModel &SchedModel, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI)
DenseMap< const MachineInstr *, unsigned > MIHeightMap
static bool isExitingLoop(const MachineLoop *From, const MachineLoop *To)
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,...
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,...
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 &, SparseSet< LiveRegUnit > &RegUnits)
Updates the depth of an machine instruction, given RegUnits.
const MachineLoop * getLoopFor(const MachineBasicBlock *) const
const TraceBlockInfo * getHeightResources(const MachineBasicBlock *) const
void updateDepths(MachineBasicBlock::iterator Start, MachineBasicBlock::iterator End, SparseSet< LiveRegUnit > &RegUnits)
Updates the depth of the instructions from Start to End.
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 ...
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.
SparseSet - Fast set implementation for objects that can be identified by small unsigned keys.
iterator erase(iterator I)
erase - Erases an existing element identified by a valid iterator.
typename DenseT::iterator iterator
const_iterator end() const
void setUniverse(unsigned U)
setUniverse - Set the universe size which determines the largest key the set can hold.
iterator find(const KeyT &Key)
find - Find an element by its key.
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.
bool insertEdge(std::optional< const MachineBasicBlock * > From, const MachineBasicBlock *To)
void finishPostorder(const MachineBasicBlock *)
po_iterator_storage(LoopBounds &lb)
Default po_iterator_storage implementation with an internal set object.
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.
iterator_range< po_ext_iterator< T, SetType > > post_order_ext(const T &G, SetType &S)
iterator_range< ipo_ext_iterator< T, SetType > > inverse_post_order_ext(const T &G, SetType &S)
LLVM_ABI Printable printRegUnit(unsigned 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.
unsigned MCRegUnit
Register units are used to compute register aliasing.
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.
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().