#include "llvm/CodeGen/MachineTraceMetrics.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SparseSet.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSchedule.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <iterator>
#include <tuple>
#include <utility>
usingnamespacellvm;
#define DEBUG_TYPE …
char MachineTraceMetrics::ID = …;
char &llvm::MachineTraceMetricsID = …;
INITIALIZE_PASS_BEGIN(MachineTraceMetrics, DEBUG_TYPE,
"Machine Trace Metrics", false, true)
INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
INITIALIZE_PASS_END(MachineTraceMetrics, DEBUG_TYPE,
"Machine Trace Metrics", false, true)
MachineTraceMetrics::MachineTraceMetrics() : … { … }
void MachineTraceMetrics::getAnalysisUsage(AnalysisUsage &AU) const { … }
bool MachineTraceMetrics::runOnMachineFunction(MachineFunction &Func) { … }
void MachineTraceMetrics::releaseMemory() { … }
const MachineTraceMetrics::FixedBlockInfo*
MachineTraceMetrics::getResources(const MachineBasicBlock *MBB) { … }
ArrayRef<unsigned>
MachineTraceMetrics::getProcReleaseAtCycles(unsigned MBBNum) const { … }
MachineTraceMetrics::Ensemble::Ensemble(MachineTraceMetrics *ct)
: … { … }
MachineTraceMetrics::Ensemble::~Ensemble() = default;
const MachineLoop*
MachineTraceMetrics::Ensemble::getLoopFor(const MachineBasicBlock *MBB) const { … }
void MachineTraceMetrics::Ensemble::
computeDepthResources(const MachineBasicBlock *MBB) { … }
void MachineTraceMetrics::Ensemble::
computeHeightResources(const MachineBasicBlock *MBB) { … }
const MachineTraceMetrics::TraceBlockInfo*
MachineTraceMetrics::Ensemble::
getDepthResources(const MachineBasicBlock *MBB) const { … }
const MachineTraceMetrics::TraceBlockInfo*
MachineTraceMetrics::Ensemble::
getHeightResources(const MachineBasicBlock *MBB) const { … }
ArrayRef<unsigned>
MachineTraceMetrics::Ensemble::
getProcResourceDepths(unsigned MBBNum) const { … }
ArrayRef<unsigned>
MachineTraceMetrics::Ensemble::
getProcResourceHeights(unsigned MBBNum) const { … }
static bool isExitingLoop(const MachineLoop *From, const MachineLoop *To) { … }
namespace {
class MinInstrCountEnsemble : public MachineTraceMetrics::Ensemble { … };
class LocalEnsemble : public MachineTraceMetrics::Ensemble { … };
}
const MachineBasicBlock*
MinInstrCountEnsemble::pickTracePred(const MachineBasicBlock *MBB) { … }
const MachineBasicBlock*
MinInstrCountEnsemble::pickTraceSucc(const MachineBasicBlock *MBB) { … }
MachineTraceMetrics::Ensemble *
MachineTraceMetrics::getEnsemble(MachineTraceStrategy strategy) { … }
void MachineTraceMetrics::invalidate(const MachineBasicBlock *MBB) { … }
void MachineTraceMetrics::verifyAnalysis() const { … }
namespace {
struct LoopBounds { … };
}
namespace llvm {
template<>
class po_iterator_storage<LoopBounds, true> { … };
}
void MachineTraceMetrics::Ensemble::computeTrace(const MachineBasicBlock *MBB) { … }
void
MachineTraceMetrics::Ensemble::invalidate(const MachineBasicBlock *BadMBB) { … }
void MachineTraceMetrics::Ensemble::verify() const { … }
namespace {
struct DataDep { … };
}
static bool getDataDeps(const MachineInstr &UseMI,
SmallVectorImpl<DataDep> &Deps,
const MachineRegisterInfo *MRI) { … }
static void getPHIDeps(const MachineInstr &UseMI,
SmallVectorImpl<DataDep> &Deps,
const MachineBasicBlock *Pred,
const MachineRegisterInfo *MRI) { … }
static void updatePhysDepsDownwards(const MachineInstr *UseMI,
SmallVectorImpl<DataDep> &Deps,
SparseSet<LiveRegUnit> &RegUnits,
const TargetRegisterInfo *TRI) { … }
unsigned MachineTraceMetrics::Ensemble::
computeCrossBlockCriticalPath(const TraceBlockInfo &TBI) { … }
void MachineTraceMetrics::Ensemble::
updateDepth(MachineTraceMetrics::TraceBlockInfo &TBI, const MachineInstr &UseMI,
SparseSet<LiveRegUnit> &RegUnits) { … }
void MachineTraceMetrics::Ensemble::
updateDepth(const MachineBasicBlock *MBB, const MachineInstr &UseMI,
SparseSet<LiveRegUnit> &RegUnits) { … }
void MachineTraceMetrics::Ensemble::
updateDepths(MachineBasicBlock::iterator Start,
MachineBasicBlock::iterator End,
SparseSet<LiveRegUnit> &RegUnits) { … }
void MachineTraceMetrics::Ensemble::
computeInstrDepths(const MachineBasicBlock *MBB) { … }
static unsigned updatePhysDepsUpwards(const MachineInstr &MI, unsigned Height,
SparseSet<LiveRegUnit> &RegUnits,
const TargetSchedModel &SchedModel,
const TargetInstrInfo *TII,
const TargetRegisterInfo *TRI) { … }
MIHeightMap;
static bool pushDepHeight(const DataDep &Dep, const MachineInstr &UseMI,
unsigned UseHeight, MIHeightMap &Heights,
const TargetSchedModel &SchedModel,
const TargetInstrInfo *TII) { … }
void MachineTraceMetrics::Ensemble::
addLiveIns(const MachineInstr *DefMI, unsigned DefOp,
ArrayRef<const MachineBasicBlock*> Trace) { … }
void MachineTraceMetrics::Ensemble::
computeInstrHeights(const MachineBasicBlock *MBB) { … }
MachineTraceMetrics::Trace
MachineTraceMetrics::Ensemble::getTrace(const MachineBasicBlock *MBB) { … }
unsigned
MachineTraceMetrics::Trace::getInstrSlack(const MachineInstr &MI) const { … }
unsigned
MachineTraceMetrics::Trace::getPHIDepth(const MachineInstr &PHI) const { … }
unsigned MachineTraceMetrics::Trace::getResourceDepth(bool Bottom) const { … }
unsigned MachineTraceMetrics::Trace::getResourceLength(
ArrayRef<const MachineBasicBlock *> Extrablocks,
ArrayRef<const MCSchedClassDesc *> ExtraInstrs,
ArrayRef<const MCSchedClassDesc *> RemoveInstrs) const { … }
bool MachineTraceMetrics::Trace::isDepInTrace(const MachineInstr &DefMI,
const MachineInstr &UseMI) const { … }
void MachineTraceMetrics::Ensemble::print(raw_ostream &OS) const { … }
void MachineTraceMetrics::TraceBlockInfo::print(raw_ostream &OS) const { … }
void MachineTraceMetrics::Trace::print(raw_ostream &OS) const { … }