2006-01-25 09:14:32 +00:00
|
|
|
//===---- ScheduleDAGList.cpp - Implement a list scheduler for isel DAG ---===//
|
2006-01-23 08:26:10 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-01-23 08:26:10 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-05-11 23:55:42 +00:00
|
|
|
// This implements a top-down list scheduler, using standard algorithms.
|
|
|
|
// The basic approach uses a priority queue of available nodes to schedule.
|
|
|
|
// One at a time, nodes are taken from the priority queue (thus in priority
|
|
|
|
// order), checked for legality to schedule, and emitted if legal.
|
2006-03-06 17:58:04 +00:00
|
|
|
//
|
|
|
|
// Nodes may not be legal to schedule either due to structural hazards (e.g.
|
|
|
|
// pipeline or resource constraints) or because an input to the instruction has
|
|
|
|
// not completed execution.
|
2006-01-23 08:26:10 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-07-13 17:13:54 +00:00
|
|
|
#define DEBUG_TYPE "pre-RA-sched"
|
2006-01-23 08:26:10 +00:00
|
|
|
#include "llvm/CodeGen/ScheduleDAG.h"
|
2006-08-02 12:30:23 +00:00
|
|
|
#include "llvm/CodeGen/SchedulerRegistry.h"
|
2006-08-01 18:29:48 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
2008-02-10 18:45:23 +00:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2006-05-12 06:33:49 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2006-01-23 08:26:10 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2006-01-25 09:14:32 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2006-08-27 12:54:02 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2006-03-05 23:13:56 +00:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2006-01-25 09:14:32 +00:00
|
|
|
#include <climits>
|
2006-01-23 08:26:10 +00:00
|
|
|
#include <queue>
|
|
|
|
using namespace llvm;
|
|
|
|
|
2006-12-19 22:41:21 +00:00
|
|
|
STATISTIC(NumNoops , "Number of noops inserted");
|
|
|
|
STATISTIC(NumStalls, "Number of pipeline stalls");
|
2006-03-08 05:18:27 +00:00
|
|
|
|
2006-08-01 14:21:23 +00:00
|
|
|
static RegisterScheduler
|
|
|
|
tdListDAGScheduler("list-td", " Top-down list scheduler",
|
|
|
|
createTDListDAGScheduler);
|
|
|
|
|
2006-03-08 04:37:58 +00:00
|
|
|
namespace {
|
2006-03-09 06:37:29 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// ScheduleDAGList - The actual list scheduler implementation. This supports
|
2006-05-11 23:55:42 +00:00
|
|
|
/// top-down scheduling.
|
2006-03-09 06:37:29 +00:00
|
|
|
///
|
2006-06-28 22:17:39 +00:00
|
|
|
class VISIBILITY_HIDDEN ScheduleDAGList : public ScheduleDAG {
|
2006-01-23 08:26:10 +00:00
|
|
|
private:
|
2006-03-11 22:44:37 +00:00
|
|
|
/// AvailableQueue - The priority queue to use for the available SUnits.
|
|
|
|
///
|
|
|
|
SchedulingPriorityQueue *AvailableQueue;
|
2006-03-09 06:35:14 +00:00
|
|
|
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
/// PendingQueue - This contains all of the instructions whose operands have
|
|
|
|
/// been issued, but their results are not ready yet (due to the latency of
|
|
|
|
/// the operation). Once the operands becomes available, the instruction is
|
|
|
|
/// added to the AvailableQueue. This keeps track of each SUnit and the
|
|
|
|
/// number of cycles left to execute before the operation is available.
|
|
|
|
std::vector<std::pair<unsigned, SUnit*> > PendingQueue;
|
2006-05-04 19:16:39 +00:00
|
|
|
|
2006-03-05 22:45:01 +00:00
|
|
|
/// HazardRec - The hazard recognizer to use.
|
2006-03-08 04:25:59 +00:00
|
|
|
HazardRecognizer *HazardRec;
|
2006-05-04 19:16:39 +00:00
|
|
|
|
2006-01-23 08:26:10 +00:00
|
|
|
public:
|
|
|
|
ScheduleDAGList(SelectionDAG &dag, MachineBasicBlock *bb,
|
2006-05-11 23:55:42 +00:00
|
|
|
const TargetMachine &tm,
|
2006-03-11 22:44:37 +00:00
|
|
|
SchedulingPriorityQueue *availqueue,
|
2006-03-08 04:25:59 +00:00
|
|
|
HazardRecognizer *HR)
|
2006-05-11 23:55:42 +00:00
|
|
|
: ScheduleDAG(dag, bb, tm),
|
2006-03-11 22:44:37 +00:00
|
|
|
AvailableQueue(availqueue), HazardRec(HR) {
|
2006-03-05 22:45:01 +00:00
|
|
|
}
|
2006-01-25 09:14:32 +00:00
|
|
|
|
|
|
|
~ScheduleDAGList() {
|
2006-03-08 04:25:59 +00:00
|
|
|
delete HazardRec;
|
2006-03-11 22:44:37 +00:00
|
|
|
delete AvailableQueue;
|
2006-01-25 09:14:32 +00:00
|
|
|
}
|
2006-01-23 08:26:10 +00:00
|
|
|
|
|
|
|
void Schedule();
|
2006-01-25 09:14:32 +00:00
|
|
|
|
|
|
|
private:
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
void ReleaseSucc(SUnit *SuccSU, bool isChain);
|
2006-03-11 22:34:41 +00:00
|
|
|
void ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle);
|
2006-03-09 06:48:37 +00:00
|
|
|
void ListScheduleTopDown();
|
2006-01-23 08:26:10 +00:00
|
|
|
};
|
2006-03-08 04:37:58 +00:00
|
|
|
} // end anonymous namespace
|
2006-01-25 09:14:32 +00:00
|
|
|
|
2006-03-06 00:22:00 +00:00
|
|
|
HazardRecognizer::~HazardRecognizer() {}
|
|
|
|
|
2006-01-26 00:30:29 +00:00
|
|
|
|
2006-03-11 22:28:35 +00:00
|
|
|
/// Schedule - Schedule the DAG using list scheduling.
|
|
|
|
void ScheduleDAGList::Schedule() {
|
2006-12-07 20:04:42 +00:00
|
|
|
DOUT << "********** List Scheduling **********\n";
|
2006-03-11 22:28:35 +00:00
|
|
|
|
|
|
|
// Build scheduling units.
|
|
|
|
BuildSchedUnits();
|
2006-05-09 07:13:34 +00:00
|
|
|
|
2006-11-04 09:44:31 +00:00
|
|
|
AvailableQueue->initNodes(SUnitMap, SUnits);
|
2006-03-11 22:28:35 +00:00
|
|
|
|
2006-05-11 23:55:42 +00:00
|
|
|
ListScheduleTopDown();
|
2006-03-11 22:28:35 +00:00
|
|
|
|
2006-03-11 22:44:37 +00:00
|
|
|
AvailableQueue->releaseState();
|
2006-03-11 22:28:35 +00:00
|
|
|
|
2006-12-07 20:04:42 +00:00
|
|
|
DOUT << "*** Final schedule ***\n";
|
2006-03-11 22:28:35 +00:00
|
|
|
DEBUG(dumpSchedule());
|
2006-12-07 20:04:42 +00:00
|
|
|
DOUT << "\n";
|
2006-03-11 22:28:35 +00:00
|
|
|
|
|
|
|
// Emit in scheduled order
|
|
|
|
EmitSchedule();
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Top-Down Scheduling
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
/// the PendingQueue if the count reaches zero.
|
|
|
|
void ScheduleDAGList::ReleaseSucc(SUnit *SuccSU, bool isChain) {
|
2007-09-28 19:24:24 +00:00
|
|
|
SuccSU->NumPredsLeft--;
|
2006-03-11 22:28:35 +00:00
|
|
|
|
2007-09-28 19:24:24 +00:00
|
|
|
assert(SuccSU->NumPredsLeft >= 0 &&
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
"List scheduling internal error");
|
2006-03-11 22:28:35 +00:00
|
|
|
|
2007-09-28 19:24:24 +00:00
|
|
|
if (SuccSU->NumPredsLeft == 0) {
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
// Compute how many cycles it will be before this actually becomes
|
|
|
|
// available. This is the max of the start time of all predecessors plus
|
|
|
|
// their latencies.
|
|
|
|
unsigned AvailableCycle = 0;
|
2006-08-17 00:09:56 +00:00
|
|
|
for (SUnit::pred_iterator I = SuccSU->Preds.begin(),
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
E = SuccSU->Preds.end(); I != E; ++I) {
|
2006-03-12 09:01:41 +00:00
|
|
|
// If this is a token edge, we don't need to wait for the latency of the
|
|
|
|
// preceeding instruction (e.g. a long-latency load) unless there is also
|
|
|
|
// some other data dependence.
|
2007-09-19 01:38:40 +00:00
|
|
|
SUnit &Pred = *I->Dep;
|
2006-08-17 00:09:56 +00:00
|
|
|
unsigned PredDoneCycle = Pred.Cycle;
|
2007-09-19 01:38:40 +00:00
|
|
|
if (!I->isCtrl)
|
2006-08-17 00:09:56 +00:00
|
|
|
PredDoneCycle += Pred.Latency;
|
|
|
|
else if (Pred.Latency)
|
2006-03-12 09:01:41 +00:00
|
|
|
PredDoneCycle += 1;
|
2006-03-12 03:52:09 +00:00
|
|
|
|
|
|
|
AvailableCycle = std::max(AvailableCycle, PredDoneCycle);
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PendingQueue.push_back(std::make_pair(AvailableCycle, SuccSU));
|
2006-03-11 22:28:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending
|
|
|
|
/// count of its successors. If a successor pending count is zero, add it to
|
|
|
|
/// the Available queue.
|
2006-03-11 22:44:37 +00:00
|
|
|
void ScheduleDAGList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) {
|
2006-12-07 20:04:42 +00:00
|
|
|
DOUT << "*** Scheduling [" << CurCycle << "]: ";
|
2006-03-11 22:28:35 +00:00
|
|
|
DEBUG(SU->dump(&DAG));
|
|
|
|
|
|
|
|
Sequence.push_back(SU);
|
2006-03-11 22:44:37 +00:00
|
|
|
SU->Cycle = CurCycle;
|
2006-03-11 22:28:35 +00:00
|
|
|
|
|
|
|
// Bottom up: release successors.
|
2006-08-17 00:09:56 +00:00
|
|
|
for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
|
|
|
|
I != E; ++I)
|
2007-09-19 01:38:40 +00:00
|
|
|
ReleaseSucc(I->Dep, I->isCtrl);
|
2006-03-11 22:28:35 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 21:10:33 +00:00
|
|
|
/// ListScheduleTopDown - The main loop of list scheduling for top-down
|
|
|
|
/// schedulers.
|
2006-03-09 06:48:37 +00:00
|
|
|
void ScheduleDAGList::ListScheduleTopDown() {
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
unsigned CurCycle = 0;
|
|
|
|
|
2006-03-05 21:10:33 +00:00
|
|
|
// All leaves to Available queue.
|
2006-03-08 04:54:34 +00:00
|
|
|
for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
|
2006-03-05 21:10:33 +00:00
|
|
|
// It is available if it has no predecessors.
|
2008-04-15 01:22:18 +00:00
|
|
|
if (SUnits[i].Preds.empty()) {
|
2006-03-11 22:44:37 +00:00
|
|
|
AvailableQueue->push(&SUnits[i]);
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
SUnits[i].isAvailable = SUnits[i].isPending = true;
|
|
|
|
}
|
2006-03-05 21:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// While Available queue is not empty, grab the node with the highest
|
|
|
|
// priority. If it is not ready put it back. Schedule the node.
|
|
|
|
std::vector<SUnit*> NotReady;
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
while (!AvailableQueue->empty() || !PendingQueue.empty()) {
|
|
|
|
// Check to see if any of the pending instructions are ready to issue. If
|
|
|
|
// so, add them to the available queue.
|
2006-03-12 09:01:41 +00:00
|
|
|
for (unsigned i = 0, e = PendingQueue.size(); i != e; ++i) {
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
if (PendingQueue[i].first == CurCycle) {
|
|
|
|
AvailableQueue->push(PendingQueue[i].second);
|
|
|
|
PendingQueue[i].second->isAvailable = true;
|
|
|
|
PendingQueue[i] = PendingQueue.back();
|
|
|
|
PendingQueue.pop_back();
|
|
|
|
--i; --e;
|
|
|
|
} else {
|
|
|
|
assert(PendingQueue[i].first > CurCycle && "Negative latency?");
|
|
|
|
}
|
2006-03-12 09:01:41 +00:00
|
|
|
}
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
|
2006-03-12 09:01:41 +00:00
|
|
|
// If there are no instructions available, don't try to issue anything, and
|
|
|
|
// don't advance the hazard recognizer.
|
|
|
|
if (AvailableQueue->empty()) {
|
|
|
|
++CurCycle;
|
|
|
|
continue;
|
|
|
|
}
|
2006-01-25 09:14:32 +00:00
|
|
|
|
2006-03-12 09:01:41 +00:00
|
|
|
SUnit *FoundSUnit = 0;
|
|
|
|
SDNode *FoundNode = 0;
|
|
|
|
|
2006-03-05 22:45:01 +00:00
|
|
|
bool HasNoopHazards = false;
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
while (!AvailableQueue->empty()) {
|
2006-03-12 09:01:41 +00:00
|
|
|
SUnit *CurSUnit = AvailableQueue->pop();
|
2006-03-07 05:40:43 +00:00
|
|
|
|
|
|
|
// Get the node represented by this SUnit.
|
2006-03-12 09:01:41 +00:00
|
|
|
FoundNode = CurSUnit->Node;
|
|
|
|
|
2006-03-07 05:40:43 +00:00
|
|
|
// If this is a pseudo op, like copyfromreg, look to see if there is a
|
|
|
|
// real target node flagged to it. If so, use the target node.
|
2006-03-12 09:01:41 +00:00
|
|
|
for (unsigned i = 0, e = CurSUnit->FlaggedNodes.size();
|
|
|
|
FoundNode->getOpcode() < ISD::BUILTIN_OP_END && i != e; ++i)
|
|
|
|
FoundNode = CurSUnit->FlaggedNodes[i];
|
2006-03-07 05:40:43 +00:00
|
|
|
|
2006-03-12 09:01:41 +00:00
|
|
|
HazardRecognizer::HazardType HT = HazardRec->getHazardType(FoundNode);
|
2006-03-05 22:45:01 +00:00
|
|
|
if (HT == HazardRecognizer::NoHazard) {
|
2006-03-12 09:01:41 +00:00
|
|
|
FoundSUnit = CurSUnit;
|
2006-03-05 22:45:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember if this is a noop hazard.
|
|
|
|
HasNoopHazards |= HT == HazardRecognizer::NoopHazard;
|
|
|
|
|
2006-03-12 09:01:41 +00:00
|
|
|
NotReady.push_back(CurSUnit);
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
}
|
2006-03-05 22:45:01 +00:00
|
|
|
|
2006-03-05 21:10:33 +00:00
|
|
|
// Add the nodes that aren't ready back onto the available list.
|
2006-03-12 09:01:41 +00:00
|
|
|
if (!NotReady.empty()) {
|
|
|
|
AvailableQueue->push_all(NotReady);
|
|
|
|
NotReady.clear();
|
|
|
|
}
|
2006-03-05 22:45:01 +00:00
|
|
|
|
|
|
|
// If we found a node to schedule, do it now.
|
2006-03-12 09:01:41 +00:00
|
|
|
if (FoundSUnit) {
|
|
|
|
ScheduleNodeTopDown(FoundSUnit, CurCycle);
|
|
|
|
HazardRec->EmitInstruction(FoundNode);
|
|
|
|
FoundSUnit->isScheduled = true;
|
|
|
|
AvailableQueue->ScheduledNode(FoundSUnit);
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
|
|
|
|
// If this is a pseudo-op node, we don't want to increment the current
|
|
|
|
// cycle.
|
2006-03-12 09:01:41 +00:00
|
|
|
if (FoundSUnit->Latency) // Don't increment CurCycle for pseudo-ops!
|
|
|
|
++CurCycle;
|
2006-03-05 22:45:01 +00:00
|
|
|
} else if (!HasNoopHazards) {
|
|
|
|
// Otherwise, we have a pipeline stall, but no other problem, just advance
|
|
|
|
// the current cycle and try again.
|
2006-12-07 20:04:42 +00:00
|
|
|
DOUT << "*** Advancing cycle, no work to do\n";
|
2006-03-08 04:25:59 +00:00
|
|
|
HazardRec->AdvanceCycle();
|
2006-03-05 23:13:56 +00:00
|
|
|
++NumStalls;
|
2006-03-12 09:01:41 +00:00
|
|
|
++CurCycle;
|
2006-03-05 22:45:01 +00:00
|
|
|
} else {
|
|
|
|
// Otherwise, we have no instructions to issue and we have instructions
|
|
|
|
// that will fault if we don't do this right. This is the case for
|
|
|
|
// processors without pipeline interlocks and other cases.
|
2006-12-07 20:04:42 +00:00
|
|
|
DOUT << "*** Emitting noop\n";
|
2006-03-08 04:25:59 +00:00
|
|
|
HazardRec->EmitNoop();
|
2006-03-05 23:59:20 +00:00
|
|
|
Sequence.push_back(0); // NULL SUnit* -> noop
|
2006-03-05 23:13:56 +00:00
|
|
|
++NumNoops;
|
2006-03-12 09:01:41 +00:00
|
|
|
++CurCycle;
|
2006-03-05 22:45:01 +00:00
|
|
|
}
|
2006-03-05 21:10:33 +00:00
|
|
|
}
|
2006-01-23 08:26:10 +00:00
|
|
|
|
2006-03-05 21:10:33 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// Verify that all SUnits were scheduled.
|
|
|
|
bool AnyNotSched = false;
|
2006-03-08 04:54:34 +00:00
|
|
|
for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
|
2007-09-28 19:24:24 +00:00
|
|
|
if (SUnits[i].NumPredsLeft != 0) {
|
2006-03-05 21:10:33 +00:00
|
|
|
if (!AnyNotSched)
|
2006-12-07 20:04:42 +00:00
|
|
|
cerr << "*** List scheduling failed! ***\n";
|
2006-03-08 04:54:34 +00:00
|
|
|
SUnits[i].dump(&DAG);
|
2006-12-07 20:04:42 +00:00
|
|
|
cerr << "has not been scheduled!\n";
|
2006-03-05 21:10:33 +00:00
|
|
|
AnyNotSched = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(!AnyNotSched);
|
|
|
|
#endif
|
2006-01-25 09:14:32 +00:00
|
|
|
}
|
|
|
|
|
2006-03-09 07:38:27 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// LatencyPriorityQueue Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is a SchedulingPriorityQueue that schedules using latency information to
|
|
|
|
// reduce the length of the critical path through the basic block.
|
|
|
|
//
|
|
|
|
namespace {
|
|
|
|
class LatencyPriorityQueue;
|
|
|
|
|
|
|
|
/// Sorting functions for the Available queue.
|
|
|
|
struct latency_sort : public std::binary_function<SUnit*, SUnit*, bool> {
|
|
|
|
LatencyPriorityQueue *PQ;
|
|
|
|
latency_sort(LatencyPriorityQueue *pq) : PQ(pq) {}
|
|
|
|
latency_sort(const latency_sort &RHS) : PQ(RHS.PQ) {}
|
|
|
|
|
|
|
|
bool operator()(const SUnit* left, const SUnit* right) const;
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class LatencyPriorityQueue : public SchedulingPriorityQueue {
|
|
|
|
// SUnits - The SUnits for the current graph.
|
2006-08-17 00:09:56 +00:00
|
|
|
std::vector<SUnit> *SUnits;
|
2006-03-09 07:38:27 +00:00
|
|
|
|
|
|
|
// Latencies - The latency (max of latency from this node to the bb exit)
|
|
|
|
// for each node.
|
|
|
|
std::vector<int> Latencies;
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
|
|
|
|
/// NumNodesSolelyBlocking - This vector contains, for every node in the
|
|
|
|
/// Queue, the number of nodes that the node is the sole unscheduled
|
|
|
|
/// predecessor for. This is used as a tie-breaker heuristic for better
|
|
|
|
/// mobility.
|
|
|
|
std::vector<unsigned> NumNodesSolelyBlocking;
|
|
|
|
|
2006-03-09 07:38:27 +00:00
|
|
|
std::priority_queue<SUnit*, std::vector<SUnit*>, latency_sort> Queue;
|
|
|
|
public:
|
|
|
|
LatencyPriorityQueue() : Queue(latency_sort(this)) {
|
|
|
|
}
|
|
|
|
|
2007-09-25 01:54:36 +00:00
|
|
|
void initNodes(DenseMap<SDNode*, std::vector<SUnit*> > &sumap,
|
2006-11-04 09:44:31 +00:00
|
|
|
std::vector<SUnit> &sunits) {
|
2006-03-09 07:38:27 +00:00
|
|
|
SUnits = &sunits;
|
|
|
|
// Calculate node priorities.
|
|
|
|
CalculatePriorities();
|
|
|
|
}
|
2007-09-25 01:54:36 +00:00
|
|
|
|
|
|
|
void addNode(const SUnit *SU) {
|
|
|
|
Latencies.resize(SUnits->size(), -1);
|
|
|
|
NumNodesSolelyBlocking.resize(SUnits->size(), 0);
|
|
|
|
CalcLatency(*SU);
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateNode(const SUnit *SU) {
|
|
|
|
Latencies[SU->NodeNum] = -1;
|
|
|
|
CalcLatency(*SU);
|
|
|
|
}
|
|
|
|
|
2006-03-09 07:38:27 +00:00
|
|
|
void releaseState() {
|
|
|
|
SUnits = 0;
|
|
|
|
Latencies.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getLatency(unsigned NodeNum) const {
|
|
|
|
assert(NodeNum < Latencies.size());
|
|
|
|
return Latencies[NodeNum];
|
|
|
|
}
|
|
|
|
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
unsigned getNumSolelyBlockNodes(unsigned NodeNum) const {
|
|
|
|
assert(NodeNum < NumNodesSolelyBlocking.size());
|
|
|
|
return NumNodesSolelyBlocking[NodeNum];
|
|
|
|
}
|
|
|
|
|
2007-09-25 01:54:36 +00:00
|
|
|
unsigned size() const { return Queue.size(); }
|
|
|
|
|
2006-03-09 07:38:27 +00:00
|
|
|
bool empty() const { return Queue.empty(); }
|
|
|
|
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
virtual void push(SUnit *U) {
|
|
|
|
push_impl(U);
|
2006-03-09 07:38:27 +00:00
|
|
|
}
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
void push_impl(SUnit *U);
|
|
|
|
|
2006-03-10 04:32:49 +00:00
|
|
|
void push_all(const std::vector<SUnit *> &Nodes) {
|
|
|
|
for (unsigned i = 0, e = Nodes.size(); i != e; ++i)
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
push_impl(Nodes[i]);
|
2006-03-10 04:32:49 +00:00
|
|
|
}
|
|
|
|
|
2006-03-09 07:38:27 +00:00
|
|
|
SUnit *pop() {
|
2006-05-30 18:04:34 +00:00
|
|
|
if (empty()) return NULL;
|
2006-03-09 07:38:27 +00:00
|
|
|
SUnit *V = Queue.top();
|
|
|
|
Queue.pop();
|
|
|
|
return V;
|
|
|
|
}
|
2006-05-09 07:13:34 +00:00
|
|
|
|
2007-09-25 01:54:36 +00:00
|
|
|
/// remove - This is a really inefficient way to remove a node from a
|
|
|
|
/// priority queue. We should roll our own heap to make this better or
|
|
|
|
/// something.
|
|
|
|
void remove(SUnit *SU) {
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
std::vector<SUnit*> Temp;
|
|
|
|
|
|
|
|
assert(!Queue.empty() && "Not in queue!");
|
|
|
|
while (Queue.top() != SU) {
|
|
|
|
Temp.push_back(Queue.top());
|
|
|
|
Queue.pop();
|
|
|
|
assert(!Queue.empty() && "Not in queue!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the node from the PQ.
|
|
|
|
Queue.pop();
|
|
|
|
|
|
|
|
// Add all the other nodes back.
|
|
|
|
for (unsigned i = 0, e = Temp.size(); i != e; ++i)
|
|
|
|
Queue.push(Temp[i]);
|
|
|
|
}
|
2007-09-25 01:54:36 +00:00
|
|
|
|
|
|
|
// ScheduledNode - As nodes are scheduled, we look to see if there are any
|
|
|
|
// successor nodes that have a single unscheduled predecessor. If so, that
|
|
|
|
// single predecessor has a higher priority, since scheduling it will make
|
|
|
|
// the node available.
|
|
|
|
void ScheduledNode(SUnit *Node);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void CalculatePriorities();
|
|
|
|
int CalcLatency(const SUnit &SU);
|
|
|
|
void AdjustPriorityOfUnscheduledPreds(SUnit *SU);
|
|
|
|
SUnit *getSingleUnscheduledPred(SUnit *SU);
|
2006-03-09 07:38:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool latency_sort::operator()(const SUnit *LHS, const SUnit *RHS) const {
|
|
|
|
unsigned LHSNum = LHS->NodeNum;
|
|
|
|
unsigned RHSNum = RHS->NodeNum;
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
|
|
|
|
// The most important heuristic is scheduling the critical path.
|
|
|
|
unsigned LHSLatency = PQ->getLatency(LHSNum);
|
|
|
|
unsigned RHSLatency = PQ->getLatency(RHSNum);
|
|
|
|
if (LHSLatency < RHSLatency) return true;
|
|
|
|
if (LHSLatency > RHSLatency) return false;
|
|
|
|
|
|
|
|
// After that, if two nodes have identical latencies, look to see if one will
|
|
|
|
// unblock more other nodes than the other.
|
|
|
|
unsigned LHSBlocked = PQ->getNumSolelyBlockNodes(LHSNum);
|
|
|
|
unsigned RHSBlocked = PQ->getNumSolelyBlockNodes(RHSNum);
|
|
|
|
if (LHSBlocked < RHSBlocked) return true;
|
|
|
|
if (LHSBlocked > RHSBlocked) return false;
|
2006-03-09 07:38:27 +00:00
|
|
|
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
// Finally, just to provide a stable ordering, use the node number as a
|
|
|
|
// deciding factor.
|
|
|
|
return LHSNum < RHSNum;
|
2006-03-09 07:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// CalcNodePriority - Calculate the maximal path from the node to the exit.
|
|
|
|
///
|
|
|
|
int LatencyPriorityQueue::CalcLatency(const SUnit &SU) {
|
|
|
|
int &Latency = Latencies[SU.NodeNum];
|
|
|
|
if (Latency != -1)
|
|
|
|
return Latency;
|
|
|
|
|
2007-10-15 21:33:22 +00:00
|
|
|
std::vector<const SUnit*> WorkList;
|
|
|
|
WorkList.push_back(&SU);
|
|
|
|
while (!WorkList.empty()) {
|
|
|
|
const SUnit *Cur = WorkList.back();
|
|
|
|
bool AllDone = true;
|
|
|
|
int MaxSuccLatency = 0;
|
|
|
|
for (SUnit::const_succ_iterator I = Cur->Succs.begin(),E = Cur->Succs.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
int SuccLatency = Latencies[I->Dep->NodeNum];
|
|
|
|
if (SuccLatency == -1) {
|
|
|
|
AllDone = false;
|
|
|
|
WorkList.push_back(I->Dep);
|
|
|
|
} else {
|
|
|
|
MaxSuccLatency = std::max(MaxSuccLatency, SuccLatency);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (AllDone) {
|
|
|
|
Latencies[Cur->NodeNum] = MaxSuccLatency + Cur->Latency;
|
|
|
|
WorkList.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Latency;
|
2006-03-09 07:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// CalculatePriorities - Calculate priorities of all scheduling units.
|
|
|
|
void LatencyPriorityQueue::CalculatePriorities() {
|
|
|
|
Latencies.assign(SUnits->size(), -1);
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
NumNodesSolelyBlocking.assign(SUnits->size(), 0);
|
2007-10-15 21:33:22 +00:00
|
|
|
|
|
|
|
// For each node, calculate the maximal path from the node to the exit.
|
|
|
|
std::vector<std::pair<const SUnit*, unsigned> > WorkList;
|
|
|
|
for (unsigned i = 0, e = SUnits->size(); i != e; ++i) {
|
|
|
|
const SUnit *SU = &(*SUnits)[i];
|
2008-01-29 13:02:09 +00:00
|
|
|
if (SU->Succs.empty())
|
2007-10-15 21:33:22 +00:00
|
|
|
WorkList.push_back(std::make_pair(SU, 0U));
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!WorkList.empty()) {
|
|
|
|
const SUnit *SU = WorkList.back().first;
|
|
|
|
unsigned SuccLat = WorkList.back().second;
|
|
|
|
WorkList.pop_back();
|
|
|
|
int &Latency = Latencies[SU->NodeNum];
|
|
|
|
if (Latency == -1 || (SU->Latency + SuccLat) > (unsigned)Latency) {
|
|
|
|
Latency = SU->Latency + SuccLat;
|
|
|
|
for (SUnit::const_pred_iterator I = SU->Preds.begin(),E = SU->Preds.end();
|
|
|
|
I != E; ++I)
|
|
|
|
WorkList.push_back(std::make_pair(I->Dep, Latency));
|
|
|
|
}
|
|
|
|
}
|
2006-03-09 07:38:27 +00:00
|
|
|
}
|
|
|
|
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
/// getSingleUnscheduledPred - If there is exactly one unscheduled predecessor
|
|
|
|
/// of SU, return it, otherwise return null.
|
2006-08-17 00:09:56 +00:00
|
|
|
SUnit *LatencyPriorityQueue::getSingleUnscheduledPred(SUnit *SU) {
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
SUnit *OnlyAvailablePred = 0;
|
2006-08-17 00:09:56 +00:00
|
|
|
for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
|
|
|
|
I != E; ++I) {
|
2007-09-19 01:38:40 +00:00
|
|
|
SUnit &Pred = *I->Dep;
|
2006-08-17 00:09:56 +00:00
|
|
|
if (!Pred.isScheduled) {
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
// We found an available, but not scheduled, predecessor. If it's the
|
|
|
|
// only one we have found, keep track of it... otherwise give up.
|
2006-08-17 00:09:56 +00:00
|
|
|
if (OnlyAvailablePred && OnlyAvailablePred != &Pred)
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
return 0;
|
2006-08-17 00:09:56 +00:00
|
|
|
OnlyAvailablePred = &Pred;
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
}
|
2006-08-17 00:09:56 +00:00
|
|
|
}
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
|
|
|
|
return OnlyAvailablePred;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LatencyPriorityQueue::push_impl(SUnit *SU) {
|
|
|
|
// Look at all of the successors of this node. Count the number of nodes that
|
|
|
|
// this node is the sole unscheduled node for.
|
|
|
|
unsigned NumNodesBlocking = 0;
|
2006-08-17 00:09:56 +00:00
|
|
|
for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
|
|
|
|
I != E; ++I)
|
2007-09-19 01:38:40 +00:00
|
|
|
if (getSingleUnscheduledPred(I->Dep) == SU)
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
++NumNodesBlocking;
|
2006-03-11 22:24:20 +00:00
|
|
|
NumNodesSolelyBlocking[SU->NodeNum] = NumNodesBlocking;
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
|
|
|
|
Queue.push(SU);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ScheduledNode - As nodes are scheduled, we look to see if there are any
|
|
|
|
// successor nodes that have a single unscheduled predecessor. If so, that
|
|
|
|
// single predecessor has a higher priority, since scheduling it will make
|
|
|
|
// the node available.
|
|
|
|
void LatencyPriorityQueue::ScheduledNode(SUnit *SU) {
|
2006-08-17 00:09:56 +00:00
|
|
|
for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
|
|
|
|
I != E; ++I)
|
2007-09-19 01:38:40 +00:00
|
|
|
AdjustPriorityOfUnscheduledPreds(I->Dep);
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// AdjustPriorityOfUnscheduledPreds - One of the predecessors of SU was just
|
|
|
|
/// scheduled. If SU is not itself available, then there is at least one
|
|
|
|
/// predecessor node that has not been scheduled yet. If SU has exactly ONE
|
|
|
|
/// unscheduled predecessor, we want to increase its priority: it getting
|
|
|
|
/// scheduled will make this node available, so it is better than some other
|
|
|
|
/// node of the same priority that will not make a node available.
|
|
|
|
void LatencyPriorityQueue::AdjustPriorityOfUnscheduledPreds(SUnit *SU) {
|
As a pending queue data structure to keep track of instructions whose
operands have all issued, but whose results are not yet available. This
allows us to compile:
int G;
int test(int A, int B, int* P) {
return (G+A)*(B+1);
}
to:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
addi r4, r4, 1
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
instead of this, which has a stall between the lis/lwz:
_test:
lis r2, ha16(L_G$non_lazy_ptr)
lwz r2, lo16(L_G$non_lazy_ptr)(r2)
addi r4, r4, 1
lwz r2, 0(r2)
add r2, r2, r3
mullw r3, r2, r4
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26716 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-12 00:38:57 +00:00
|
|
|
if (SU->isPending) return; // All preds scheduled.
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
|
|
|
|
SUnit *OnlyAvailablePred = getSingleUnscheduledPred(SU);
|
|
|
|
if (OnlyAvailablePred == 0 || !OnlyAvailablePred->isAvailable) return;
|
|
|
|
|
|
|
|
// Okay, we found a single predecessor that is available, but not scheduled.
|
|
|
|
// Since it is available, it must be in the priority queue. First remove it.
|
2007-09-25 01:54:36 +00:00
|
|
|
remove(OnlyAvailablePred);
|
Teach the latency scheduler some new tricks. In particular, to break ties,
keep track of a sense of "mobility", i.e. how many other nodes scheduling one
node will free up. For something like this:
float testadd(float *X, float *Y, float *Z, float *W, float *V) {
return (*X+*Y)*(*Z+*W)+*V;
}
For example, this makes us schedule *X then *Y, not *X then *Z. The former
allows us to issue the add, the later only lets us issue other loads.
This turns the above code from this:
_testadd:
lfs f0, 0(r3)
lfs f1, 0(r6)
lfs f2, 0(r4)
lfs f3, 0(r5)
fadds f0, f0, f2
fadds f1, f3, f1
lfs f2, 0(r7)
fmadds f1, f0, f1, f2
blr
into this:
_testadd:
lfs f0, 0(r6)
lfs f1, 0(r5)
fadds f0, f1, f0
lfs f1, 0(r4)
lfs f2, 0(r3)
fadds f1, f2, f1
lfs f2, 0(r7)
fmadds f1, f1, f0, f2
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26680 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-10 05:51:05 +00:00
|
|
|
|
|
|
|
// Reinsert the node into the priority queue, which recomputes its
|
|
|
|
// NumNodesSolelyBlocking value.
|
|
|
|
push(OnlyAvailablePred);
|
|
|
|
}
|
|
|
|
|
2006-03-09 06:35:14 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Public Constructor Functions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-08-01 14:21:23 +00:00
|
|
|
/// createTDListDAGScheduler - This creates a top-down list scheduler with a
|
|
|
|
/// new hazard recognizer. This scheduler takes ownership of the hazard
|
|
|
|
/// recognizer and deletes it when done.
|
2006-08-01 18:29:48 +00:00
|
|
|
ScheduleDAG* llvm::createTDListDAGScheduler(SelectionDAGISel *IS,
|
|
|
|
SelectionDAG *DAG,
|
2006-08-01 14:21:23 +00:00
|
|
|
MachineBasicBlock *BB) {
|
|
|
|
return new ScheduleDAGList(*DAG, BB, DAG->getTarget(),
|
2006-03-09 07:38:27 +00:00
|
|
|
new LatencyPriorityQueue(),
|
2006-08-01 18:29:48 +00:00
|
|
|
IS->CreateTargetHazardRecognizer());
|
2006-01-23 08:26:10 +00:00
|
|
|
}
|