mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-16 21:30:45 +00:00
Eliminate the use of PriorityQueue and just use a std::vector,
implementing pop with a linear search for a "best" element. The priority queue was a neat idea, but in practice the comparison functions depend on dynamic information. llvm-svn: 104718
This commit is contained in:
parent
b3807452fe
commit
52c2738324
@ -17,7 +17,6 @@
|
|||||||
#define LATENCY_PRIORITY_QUEUE_H
|
#define LATENCY_PRIORITY_QUEUE_H
|
||||||
|
|
||||||
#include "llvm/CodeGen/ScheduleDAG.h"
|
#include "llvm/CodeGen/ScheduleDAG.h"
|
||||||
#include "llvm/ADT/PriorityQueue.h"
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class LatencyPriorityQueue;
|
class LatencyPriorityQueue;
|
||||||
@ -41,10 +40,11 @@ namespace llvm {
|
|||||||
std::vector<unsigned> NumNodesSolelyBlocking;
|
std::vector<unsigned> NumNodesSolelyBlocking;
|
||||||
|
|
||||||
/// Queue - The queue.
|
/// Queue - The queue.
|
||||||
PriorityQueue<SUnit*, std::vector<SUnit*>, latency_sort> Queue;
|
std::vector<SUnit*> Queue;
|
||||||
|
latency_sort Picker;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LatencyPriorityQueue() : Queue(latency_sort(this)) {
|
LatencyPriorityQueue() : Picker(this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void initNodes(std::vector<SUnit> &sunits) {
|
void initNodes(std::vector<SUnit> &sunits) {
|
||||||
@ -77,17 +77,9 @@ namespace llvm {
|
|||||||
|
|
||||||
virtual void push(SUnit *U);
|
virtual void push(SUnit *U);
|
||||||
|
|
||||||
SUnit *pop() {
|
virtual SUnit *pop();
|
||||||
if (empty()) return NULL;
|
|
||||||
SUnit *V = Queue.top();
|
|
||||||
Queue.pop();
|
|
||||||
return V;
|
|
||||||
}
|
|
||||||
|
|
||||||
void remove(SUnit *SU) {
|
virtual void remove(SUnit *SU);
|
||||||
assert(!Queue.empty() && "Not in queue!");
|
|
||||||
Queue.erase_one(SU);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ScheduledNode - As nodes are scheduled, we look to see if there are any
|
// ScheduledNode - As nodes are scheduled, we look to see if there are any
|
||||||
// successor nodes that have a single unscheduled predecessor. If so, that
|
// successor nodes that have a single unscheduled predecessor. If so, that
|
||||||
|
@ -79,7 +79,7 @@ void LatencyPriorityQueue::push(SUnit *SU) {
|
|||||||
}
|
}
|
||||||
NumNodesSolelyBlocking[SU->NodeNum] = NumNodesBlocking;
|
NumNodesSolelyBlocking[SU->NodeNum] = NumNodesBlocking;
|
||||||
|
|
||||||
Queue.push(SU);
|
Queue.push_back(SU);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,3 +114,25 @@ void LatencyPriorityQueue::AdjustPriorityOfUnscheduledPreds(SUnit *SU) {
|
|||||||
// NumNodesSolelyBlocking value.
|
// NumNodesSolelyBlocking value.
|
||||||
push(OnlyAvailablePred);
|
push(OnlyAvailablePred);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SUnit *LatencyPriorityQueue::pop() {
|
||||||
|
if (empty()) return NULL;
|
||||||
|
std::vector<SUnit *>::iterator Best = Queue.begin();
|
||||||
|
for (std::vector<SUnit *>::iterator I = next(Queue.begin()),
|
||||||
|
E = Queue.end(); I != E; ++I)
|
||||||
|
if (Picker(*Best, *I))
|
||||||
|
Best = I;
|
||||||
|
SUnit *V = *Best;
|
||||||
|
if (Best != prior(Queue.end()))
|
||||||
|
std::swap(*Best, Queue.back());
|
||||||
|
Queue.pop_back();
|
||||||
|
return V;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LatencyPriorityQueue::remove(SUnit *SU) {
|
||||||
|
assert(!Queue.empty() && "Queue is empty!");
|
||||||
|
std::vector<SUnit *>::iterator I = std::find(Queue.begin(), Queue.end(), SU);
|
||||||
|
if (I != prior(Queue.end()))
|
||||||
|
std::swap(*I, Queue.back());
|
||||||
|
Queue.pop_back();
|
||||||
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
#include "llvm/Target/TargetInstrInfo.h"
|
#include "llvm/Target/TargetInstrInfo.h"
|
||||||
#include "llvm/ADT/PriorityQueue.h"
|
|
||||||
#include "llvm/ADT/SmallSet.h"
|
#include "llvm/ADT/SmallSet.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
@ -1027,7 +1026,8 @@ CalcNodeSethiUllmanNumber(const SUnit *SU, std::vector<unsigned> &SUNumbers) {
|
|||||||
namespace {
|
namespace {
|
||||||
template<class SF>
|
template<class SF>
|
||||||
class RegReductionPriorityQueue : public SchedulingPriorityQueue {
|
class RegReductionPriorityQueue : public SchedulingPriorityQueue {
|
||||||
PriorityQueue<SUnit*, std::vector<SUnit*>, SF> Queue;
|
std::vector<SUnit*> Queue;
|
||||||
|
SF Picker;
|
||||||
unsigned CurQueueId;
|
unsigned CurQueueId;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -1044,7 +1044,7 @@ namespace {
|
|||||||
public:
|
public:
|
||||||
RegReductionPriorityQueue(const TargetInstrInfo *tii,
|
RegReductionPriorityQueue(const TargetInstrInfo *tii,
|
||||||
const TargetRegisterInfo *tri)
|
const TargetRegisterInfo *tri)
|
||||||
: Queue(SF(this)), CurQueueId(0),
|
: Picker(this), CurQueueId(0),
|
||||||
TII(tii), TRI(tri), scheduleDAG(NULL) {}
|
TII(tii), TRI(tri), scheduleDAG(NULL) {}
|
||||||
|
|
||||||
void initNodes(std::vector<SUnit> &sunits) {
|
void initNodes(std::vector<SUnit> &sunits) {
|
||||||
@ -1110,13 +1110,20 @@ namespace {
|
|||||||
void push(SUnit *U) {
|
void push(SUnit *U) {
|
||||||
assert(!U->NodeQueueId && "Node in the queue already");
|
assert(!U->NodeQueueId && "Node in the queue already");
|
||||||
U->NodeQueueId = ++CurQueueId;
|
U->NodeQueueId = ++CurQueueId;
|
||||||
Queue.push(U);
|
Queue.push_back(U);
|
||||||
}
|
}
|
||||||
|
|
||||||
SUnit *pop() {
|
SUnit *pop() {
|
||||||
if (empty()) return NULL;
|
if (empty()) return NULL;
|
||||||
SUnit *V = Queue.top();
|
std::vector<SUnit *>::iterator Best = Queue.begin();
|
||||||
Queue.pop();
|
for (std::vector<SUnit *>::iterator I = next(Queue.begin()),
|
||||||
|
E = Queue.end(); I != E; ++I)
|
||||||
|
if (Picker(*Best, *I))
|
||||||
|
Best = I;
|
||||||
|
SUnit *V = *Best;
|
||||||
|
if (Best != prior(Queue.end()))
|
||||||
|
std::swap(*Best, Queue.back());
|
||||||
|
Queue.pop_back();
|
||||||
V->NodeQueueId = 0;
|
V->NodeQueueId = 0;
|
||||||
return V;
|
return V;
|
||||||
}
|
}
|
||||||
@ -1124,7 +1131,11 @@ namespace {
|
|||||||
void remove(SUnit *SU) {
|
void remove(SUnit *SU) {
|
||||||
assert(!Queue.empty() && "Queue is empty!");
|
assert(!Queue.empty() && "Queue is empty!");
|
||||||
assert(SU->NodeQueueId != 0 && "Not in queue!");
|
assert(SU->NodeQueueId != 0 && "Not in queue!");
|
||||||
Queue.erase_one(SU);
|
std::vector<SUnit *>::iterator I = std::find(Queue.begin(), Queue.end(),
|
||||||
|
SU);
|
||||||
|
if (I != prior(Queue.end()))
|
||||||
|
std::swap(*I, Queue.back());
|
||||||
|
Queue.pop_back();
|
||||||
SU->NodeQueueId = 0;
|
SU->NodeQueueId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user