2006-01-25 17:14:32 +08:00
|
|
|
//===---- ScheduleDAGList.cpp - Implement a list scheduler for isel DAG ---===//
|
2006-01-23 16:26:10 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-01-23 16:26:10 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-05-12 07:55:42 +08: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-07 01:58:04 +08: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 16:26:10 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-07-14 01:13:54 +08:00
|
|
|
#define DEBUG_TYPE "pre-RA-sched"
|
2009-02-07 01:22:58 +08:00
|
|
|
#include "ScheduleDAGSDNodes.h"
|
2008-11-20 07:18:57 +08:00
|
|
|
#include "llvm/CodeGen/LatencyPriorityQueue.h"
|
2009-01-16 06:18:12 +08:00
|
|
|
#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
|
2006-08-02 20:30:23 +08:00
|
|
|
#include "llvm/CodeGen/SchedulerRegistry.h"
|
2006-08-02 02:29:48 +08:00
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
2008-02-11 02:45:23 +08:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2006-05-12 14:33:49 +08:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2006-01-23 16:26:10 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2006-01-25 17:14:32 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2006-08-27 20:54:02 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2009-07-12 04:10:48 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-23 14:35:02 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-06-24 07:40:09 +08:00
|
|
|
#include "llvm/ADT/PriorityQueue.h"
|
2006-03-06 07:13:56 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2006-01-25 17:14:32 +08:00
|
|
|
#include <climits>
|
2006-01-23 16:26:10 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2006-12-20 06:41:21 +08:00
|
|
|
STATISTIC(NumNoops , "Number of noops inserted");
|
|
|
|
STATISTIC(NumStalls, "Number of pipeline stalls");
|
2006-03-08 13:18:27 +08:00
|
|
|
|
2006-08-01 22:21:23 +08:00
|
|
|
static RegisterScheduler
|
2008-10-15 04:25:08 +08:00
|
|
|
tdListDAGScheduler("list-td", "Top-down list scheduler",
|
2006-08-01 22:21:23 +08:00
|
|
|
createTDListDAGScheduler);
|
|
|
|
|
2006-03-08 12:37:58 +08:00
|
|
|
namespace {
|
2006-03-09 14:37:29 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// ScheduleDAGList - The actual list scheduler implementation. This supports
|
2006-05-12 07:55:42 +08:00
|
|
|
/// top-down scheduling.
|
2006-03-09 14:37:29 +08:00
|
|
|
///
|
2008-11-20 07:18:57 +08:00
|
|
|
class VISIBILITY_HIDDEN ScheduleDAGList : public ScheduleDAGSDNodes {
|
2006-01-23 16:26:10 +08:00
|
|
|
private:
|
2006-03-12 06:44:37 +08:00
|
|
|
/// AvailableQueue - The priority queue to use for the available SUnits.
|
|
|
|
///
|
|
|
|
SchedulingPriorityQueue *AvailableQueue;
|
2006-03-09 14:35:14 +08: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
llvm-svn: 26716
2006-03-12 08:38:57 +08: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
|
2008-11-18 10:50:01 +08:00
|
|
|
/// the operation). Once the operands become available, the instruction is
|
2008-11-18 03:45:19 +08:00
|
|
|
/// added to the AvailableQueue.
|
|
|
|
std::vector<SUnit*> PendingQueue;
|
2006-05-05 03:16:39 +08:00
|
|
|
|
2006-03-06 06:45:01 +08:00
|
|
|
/// HazardRec - The hazard recognizer to use.
|
2009-01-16 06:18:12 +08:00
|
|
|
ScheduleHazardRecognizer *HazardRec;
|
2006-05-05 03:16:39 +08:00
|
|
|
|
2006-01-23 16:26:10 +08:00
|
|
|
public:
|
2009-01-16 03:20:50 +08:00
|
|
|
ScheduleDAGList(MachineFunction &mf,
|
2006-03-12 06:44:37 +08:00
|
|
|
SchedulingPriorityQueue *availqueue,
|
2009-01-16 06:18:12 +08:00
|
|
|
ScheduleHazardRecognizer *HR)
|
2009-01-16 03:20:50 +08:00
|
|
|
: ScheduleDAGSDNodes(mf),
|
2006-03-12 06:44:37 +08:00
|
|
|
AvailableQueue(availqueue), HazardRec(HR) {
|
2006-03-06 06:45:01 +08:00
|
|
|
}
|
2006-01-25 17:14:32 +08:00
|
|
|
|
|
|
|
~ScheduleDAGList() {
|
2006-03-08 12:25:59 +08:00
|
|
|
delete HazardRec;
|
2006-03-12 06:44:37 +08:00
|
|
|
delete AvailableQueue;
|
2006-01-25 17:14:32 +08:00
|
|
|
}
|
2006-01-23 16:26:10 +08:00
|
|
|
|
|
|
|
void Schedule();
|
2006-01-25 17:14:32 +08:00
|
|
|
|
|
|
|
private:
|
2008-12-10 06:54:47 +08:00
|
|
|
void ReleaseSucc(SUnit *SU, const SDep &D);
|
2009-02-11 07:27:53 +08:00
|
|
|
void ReleaseSuccessors(SUnit *SU);
|
2006-03-12 06:34:41 +08:00
|
|
|
void ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle);
|
2006-03-09 14:48:37 +08:00
|
|
|
void ListScheduleTopDown();
|
2006-01-23 16:26:10 +08:00
|
|
|
};
|
2006-03-08 12:37:58 +08:00
|
|
|
} // end anonymous namespace
|
2006-01-25 17:14:32 +08:00
|
|
|
|
2006-03-12 06:28:35 +08:00
|
|
|
/// Schedule - Schedule the DAG using list scheduling.
|
|
|
|
void ScheduleDAGList::Schedule() {
|
2009-08-23 14:35:02 +08:00
|
|
|
DEBUG(errs() << "********** List Scheduling **********\n");
|
2006-03-12 06:28:35 +08:00
|
|
|
|
2008-12-24 02:36:58 +08:00
|
|
|
// Build the scheduling graph.
|
|
|
|
BuildSchedGraph();
|
2006-05-09 15:13:34 +08:00
|
|
|
|
2008-06-22 03:18:17 +08:00
|
|
|
AvailableQueue->initNodes(SUnits);
|
2006-03-12 06:28:35 +08:00
|
|
|
|
2006-05-12 07:55:42 +08:00
|
|
|
ListScheduleTopDown();
|
2006-03-12 06:28:35 +08:00
|
|
|
|
2006-03-12 06:44:37 +08:00
|
|
|
AvailableQueue->releaseState();
|
2006-03-12 06:28:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Top-Down Scheduling
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to
|
2008-11-18 08:38:59 +08:00
|
|
|
/// the PendingQueue if the count reaches zero. Also update its cycle bound.
|
2008-12-10 06:54:47 +08:00
|
|
|
void ScheduleDAGList::ReleaseSucc(SUnit *SU, const SDep &D) {
|
|
|
|
SUnit *SuccSU = D.getSUnit();
|
2009-10-01 04:15:38 +08:00
|
|
|
|
2008-11-18 08:38:59 +08:00
|
|
|
#ifndef NDEBUG
|
2009-10-01 04:15:38 +08:00
|
|
|
if (SuccSU->NumPredsLeft == 0) {
|
2009-08-23 15:05:07 +08:00
|
|
|
errs() << "*** Scheduling failed! ***\n";
|
2008-11-18 10:06:40 +08:00
|
|
|
SuccSU->dump(this);
|
2009-08-23 15:05:07 +08:00
|
|
|
errs() << " has been released too many times!\n";
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable(0);
|
2008-11-18 08:38:59 +08:00
|
|
|
}
|
|
|
|
#endif
|
2009-10-01 04:15:38 +08:00
|
|
|
--SuccSU->NumPredsLeft;
|
|
|
|
|
2008-12-16 11:25:46 +08:00
|
|
|
SuccSU->setDepthToAtLeast(SU->getDepth() + D.getLatency());
|
2006-03-12 06:28:35 +08:00
|
|
|
|
2009-02-11 07:27:53 +08:00
|
|
|
// If all the node's predecessors are scheduled, this node is ready
|
|
|
|
// to be scheduled. Ignore the special ExitSU node.
|
|
|
|
if (SuccSU->NumPredsLeft == 0 && SuccSU != &ExitSU)
|
2008-11-18 03:45:19 +08:00
|
|
|
PendingQueue.push_back(SuccSU);
|
2009-02-11 07:27:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScheduleDAGList::ReleaseSuccessors(SUnit *SU) {
|
|
|
|
// Top down: release successors.
|
|
|
|
for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
assert(!I->isAssignedRegDep() &&
|
|
|
|
"The list-td scheduler doesn't yet support physreg dependencies!");
|
|
|
|
|
|
|
|
ReleaseSucc(SU, *I);
|
2006-03-12 06:28:35 +08: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-12 06:44:37 +08:00
|
|
|
void ScheduleDAGList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) {
|
2009-08-23 14:35:02 +08:00
|
|
|
DEBUG(errs() << "*** Scheduling [" << CurCycle << "]: ");
|
2008-11-18 10:06:40 +08:00
|
|
|
DEBUG(SU->dump(this));
|
2006-03-12 06:28:35 +08:00
|
|
|
|
|
|
|
Sequence.push_back(SU);
|
2008-12-16 11:25:46 +08:00
|
|
|
assert(CurCycle >= SU->getDepth() && "Node scheduled above its depth!");
|
|
|
|
SU->setDepthToAtLeast(CurCycle);
|
2008-11-18 05:31:02 +08:00
|
|
|
|
2009-02-11 07:27:53 +08:00
|
|
|
ReleaseSuccessors(SU);
|
2008-11-18 05:31:02 +08:00
|
|
|
SU->isScheduled = true;
|
|
|
|
AvailableQueue->ScheduledNode(SU);
|
2006-03-12 06:28:35 +08:00
|
|
|
}
|
|
|
|
|
2006-03-06 05:10:33 +08:00
|
|
|
/// ListScheduleTopDown - The main loop of list scheduling for top-down
|
|
|
|
/// schedulers.
|
2006-03-09 14:48:37 +08: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
llvm-svn: 26716
2006-03-12 08:38:57 +08:00
|
|
|
unsigned CurCycle = 0;
|
|
|
|
|
2009-02-11 07:27:53 +08:00
|
|
|
// Release any successors of the special Entry node.
|
|
|
|
ReleaseSuccessors(&EntrySU);
|
|
|
|
|
2006-03-06 05:10:33 +08:00
|
|
|
// All leaves to Available queue.
|
2006-03-08 12:54:34 +08:00
|
|
|
for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
|
2006-03-06 05:10:33 +08:00
|
|
|
// It is available if it has no predecessors.
|
2008-04-15 09:22:18 +08:00
|
|
|
if (SUnits[i].Preds.empty()) {
|
2006-03-12 06:44:37 +08:00
|
|
|
AvailableQueue->push(&SUnits[i]);
|
2008-11-18 00:37:30 +08:00
|
|
|
SUnits[i].isAvailable = true;
|
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
llvm-svn: 26716
2006-03-12 08:38:57 +08:00
|
|
|
}
|
2006-03-06 05:10:33 +08: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;
|
2008-06-21 23:52:51 +08:00
|
|
|
Sequence.reserve(SUnits.size());
|
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
llvm-svn: 26716
2006-03-12 08:38:57 +08: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 17:01:41 +08:00
|
|
|
for (unsigned i = 0, e = PendingQueue.size(); i != e; ++i) {
|
2008-12-16 11:25:46 +08:00
|
|
|
if (PendingQueue[i]->getDepth() == CurCycle) {
|
2008-11-18 03:45:19 +08:00
|
|
|
AvailableQueue->push(PendingQueue[i]);
|
|
|
|
PendingQueue[i]->isAvailable = true;
|
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
llvm-svn: 26716
2006-03-12 08:38:57 +08:00
|
|
|
PendingQueue[i] = PendingQueue.back();
|
|
|
|
PendingQueue.pop_back();
|
|
|
|
--i; --e;
|
|
|
|
} else {
|
2008-12-16 11:25:46 +08:00
|
|
|
assert(PendingQueue[i]->getDepth() > CurCycle && "Negative latency?");
|
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
llvm-svn: 26716
2006-03-12 08:38:57 +08:00
|
|
|
}
|
2006-03-12 17:01:41 +08: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
llvm-svn: 26716
2006-03-12 08:38:57 +08:00
|
|
|
|
2006-03-12 17:01:41 +08: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 17:14:32 +08:00
|
|
|
|
2006-03-12 17:01:41 +08:00
|
|
|
SUnit *FoundSUnit = 0;
|
|
|
|
|
2006-03-06 06:45:01 +08: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
llvm-svn: 26716
2006-03-12 08:38:57 +08:00
|
|
|
while (!AvailableQueue->empty()) {
|
2006-03-12 17:01:41 +08:00
|
|
|
SUnit *CurSUnit = AvailableQueue->pop();
|
2006-03-07 13:40:43 +08:00
|
|
|
|
2009-01-16 06:18:12 +08:00
|
|
|
ScheduleHazardRecognizer::HazardType HT =
|
|
|
|
HazardRec->getHazardType(CurSUnit);
|
|
|
|
if (HT == ScheduleHazardRecognizer::NoHazard) {
|
2006-03-12 17:01:41 +08:00
|
|
|
FoundSUnit = CurSUnit;
|
2006-03-06 06:45:01 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-11-20 07:18:57 +08:00
|
|
|
|
2006-03-06 06:45:01 +08:00
|
|
|
// Remember if this is a noop hazard.
|
2009-01-16 06:18:12 +08:00
|
|
|
HasNoopHazards |= HT == ScheduleHazardRecognizer::NoopHazard;
|
2006-03-06 06:45:01 +08:00
|
|
|
|
2006-03-12 17:01:41 +08: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
llvm-svn: 26716
2006-03-12 08:38:57 +08:00
|
|
|
}
|
2006-03-06 06:45:01 +08:00
|
|
|
|
2006-03-06 05:10:33 +08:00
|
|
|
// Add the nodes that aren't ready back onto the available list.
|
2006-03-12 17:01:41 +08:00
|
|
|
if (!NotReady.empty()) {
|
|
|
|
AvailableQueue->push_all(NotReady);
|
|
|
|
NotReady.clear();
|
|
|
|
}
|
2006-03-06 06:45:01 +08:00
|
|
|
|
|
|
|
// If we found a node to schedule, do it now.
|
2006-03-12 17:01:41 +08:00
|
|
|
if (FoundSUnit) {
|
|
|
|
ScheduleNodeTopDown(FoundSUnit, CurCycle);
|
2009-01-16 06:18:12 +08:00
|
|
|
HazardRec->EmitInstruction(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
llvm-svn: 26716
2006-03-12 08:38:57 +08:00
|
|
|
|
|
|
|
// If this is a pseudo-op node, we don't want to increment the current
|
|
|
|
// cycle.
|
2006-03-12 17:01:41 +08:00
|
|
|
if (FoundSUnit->Latency) // Don't increment CurCycle for pseudo-ops!
|
|
|
|
++CurCycle;
|
2006-03-06 06:45:01 +08:00
|
|
|
} else if (!HasNoopHazards) {
|
|
|
|
// Otherwise, we have a pipeline stall, but no other problem, just advance
|
|
|
|
// the current cycle and try again.
|
2009-08-23 14:35:02 +08:00
|
|
|
DEBUG(errs() << "*** Advancing cycle, no work to do\n");
|
2006-03-08 12:25:59 +08:00
|
|
|
HazardRec->AdvanceCycle();
|
2006-03-06 07:13:56 +08:00
|
|
|
++NumStalls;
|
2006-03-12 17:01:41 +08:00
|
|
|
++CurCycle;
|
2006-03-06 06:45:01 +08: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.
|
2009-08-23 14:35:02 +08:00
|
|
|
DEBUG(errs() << "*** Emitting noop\n");
|
2006-03-08 12:25:59 +08:00
|
|
|
HazardRec->EmitNoop();
|
2009-01-16 09:33:36 +08:00
|
|
|
Sequence.push_back(0); // NULL here means noop
|
2006-03-06 07:13:56 +08:00
|
|
|
++NumNoops;
|
2006-03-12 17:01:41 +08:00
|
|
|
++CurCycle;
|
2006-03-06 06:45:01 +08:00
|
|
|
}
|
2006-03-06 05:10:33 +08:00
|
|
|
}
|
2006-01-23 16:26:10 +08:00
|
|
|
|
2006-03-06 05:10:33 +08:00
|
|
|
#ifndef NDEBUG
|
2008-11-20 09:26:25 +08:00
|
|
|
VerifySchedule(/*isBottomUp=*/false);
|
2006-03-06 05:10:33 +08:00
|
|
|
#endif
|
2006-01-25 17:14:32 +08:00
|
|
|
}
|
|
|
|
|
2006-03-09 14:35:14 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Public Constructor Functions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-08-01 22:21:23 +08: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.
|
2009-02-11 12:27:20 +08:00
|
|
|
ScheduleDAGSDNodes *
|
2009-04-30 07:29:43 +08:00
|
|
|
llvm::createTDListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level) {
|
2009-01-16 03:20:50 +08:00
|
|
|
return new ScheduleDAGList(*IS->MF,
|
2006-03-09 15:38:27 +08:00
|
|
|
new LatencyPriorityQueue(),
|
2006-08-02 02:29:48 +08:00
|
|
|
IS->CreateTargetHazardRecognizer());
|
2006-01-23 16:26:10 +08:00
|
|
|
}
|