#define DEBUG_TYPE "pre-RA-sched"
#include "llvm/CodeGen/ScheduleDAG.h"
+#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include <climits>
using namespace llvm;
-ScheduleDAG::ScheduleDAG(SelectionDAG *dag, MachineBasicBlock *bb,
- const TargetMachine &tm)
- : DAG(dag), BB(bb), TM(tm), MRI(BB->getParent()->getRegInfo()) {
- TII = TM.getInstrInfo();
- MF = BB->getParent();
- TRI = TM.getRegisterInfo();
- TLI = TM.getTargetLowering();
- ConstPool = MF->getConstantPool();
+ScheduleDAG::ScheduleDAG(MachineFunction &mf)
+ : TM(mf.getTarget()),
+ TII(TM.getInstrInfo()),
+ TRI(TM.getRegisterInfo()),
+ TLI(TM.getTargetLowering()),
+ MF(mf), MRI(mf.getRegInfo()),
+ ConstPool(MF.getConstantPool()),
+ EntrySU(), ExitSU() {
}
ScheduleDAG::~ScheduleDAG() {}
/// Run - perform scheduling.
///
-void ScheduleDAG::Run() {
+void ScheduleDAG::Run(MachineBasicBlock *bb,
+ MachineBasicBlock::iterator insertPos) {
+ BB = bb;
+ InsertPos = insertPos;
+
+ SUnits.clear();
+ Sequence.clear();
+ EntrySU = SUnit();
+ ExitSU = SUnit();
+
Schedule();
-
+
DOUT << "*** Final schedule ***\n";
DEBUG(dumpSchedule());
DOUT << "\n";
/// specified node.
void SUnit::addPred(const SDep &D) {
// If this node already has this depenence, don't add a redundant one.
- for (unsigned i = 0, e = (unsigned)Preds.size(); i != e; ++i)
- if (Preds[i] == D)
+ for (SmallVector<SDep, 4>::const_iterator I = Preds.begin(), E = Preds.end();
+ I != E; ++I)
+ if (*I == D)
return;
// Now add a corresponding succ to N.
SDep P = D;
++NumPredsLeft;
if (!isScheduled)
++N->NumSuccsLeft;
- N->Succs.push_back(P);
Preds.push_back(D);
- this->setDepthDirty();
- N->setHeightDirty();
+ N->Succs.push_back(P);
+ if (P.getLatency() != 0) {
+ this->setDepthDirty();
+ N->setHeightDirty();
+ }
}
/// removePred - This removes the specified edge as a pred of the current
}
assert(FoundSucc && "Mismatching preds / succs lists!");
Preds.erase(I);
- // Update the bookkeeping;
- if (D.getKind() == SDep::Data) {
+ // Update the bookkeeping.
+ if (P.getKind() == SDep::Data) {
--NumPreds;
--N->NumSuccs;
}
--NumPredsLeft;
if (!isScheduled)
--N->NumSuccsLeft;
- this->setDepthDirty();
- N->setHeightDirty();
+ if (P.getLatency() != 0) {
+ this->setDepthDirty();
+ N->setHeightDirty();
+ }
return;
}
}
void SUnit::ComputeDepth() {
SmallVector<SUnit*, 8> WorkList;
WorkList.push_back(this);
- while (!WorkList.empty()) {
+ do {
SUnit *Cur = WorkList.back();
bool Done = true;
}
Cur->isDepthCurrent = true;
}
- }
+ } while (!WorkList.empty());
}
/// ComputeHeight - Calculate the maximal path from the node to the entry.
void SUnit::ComputeHeight() {
SmallVector<SUnit*, 8> WorkList;
WorkList.push_back(this);
- while (!WorkList.empty()) {
+ do {
SUnit *Cur = WorkList.back();
bool Done = true;
}
Cur->isHeightCurrent = true;
}
- }
+ } while (!WorkList.empty());
}
/// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
WorkList.reserve(SUnits.size());
WorkList.push_back(SU);
- while (!WorkList.empty()) {
+ do {
SU = WorkList.back();
WorkList.pop_back();
Visited.set(SU->NodeNum);
WorkList.push_back(SU->Succs[I].getSUnit());
}
}
- }
+ } while (!WorkList.empty());
}
/// Shift - Renumber the nodes so that the topological ordering is
ScheduleDAGTopologicalSort::ScheduleDAGTopologicalSort(
std::vector<SUnit> &sunits)
: SUnits(sunits) {}
+
+ScheduleHazardRecognizer::~ScheduleHazardRecognizer() {}