LLVM: lib/CodeGen/LatencyPriorityQueue.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

16#include "llvm/Config/llvm-config.h"

19using namespace llvm;

20

21#define DEBUG_TYPE "scheduler"

22

24

25

26

27 if (LHS->isScheduleHigh && !RHS->isScheduleHigh)

28 return false;

29 if (!LHS->isScheduleHigh && RHS->isScheduleHigh)

30 return true;

31

32 unsigned LHSNum = LHS->NodeNum;

33 unsigned RHSNum = RHS->NodeNum;

34

35

36 unsigned LHSLatency = PQ->getLatency(LHSNum);

37 unsigned RHSLatency = PQ->getLatency(RHSNum);

38 if (LHSLatency < RHSLatency) return true;

39 if (LHSLatency > RHSLatency) return false;

40

41

42

43 unsigned LHSBlocked = PQ->getNumSolelyBlockNodes(LHSNum);

44 unsigned RHSBlocked = PQ->getNumSolelyBlockNodes(RHSNum);

45 if (LHSBlocked < RHSBlocked) return true;

46 if (LHSBlocked > RHSBlocked) return false;

47

48

49

50 return RHSNum < LHSNum;

51}

52

53

54

55

56SUnit *LatencyPriorityQueue::getSingleUnscheduledPred(SUnit *SU) {

57 SUnit *OnlyAvailablePred = nullptr;

59 SUnit &Pred = *P.getSUnit();

60 if (!Pred.isScheduled) {

61

62

63 if (OnlyAvailablePred && OnlyAvailablePred != &Pred)

64 return nullptr;

65 OnlyAvailablePred = &Pred;

66 }

67 }

68

69 return OnlyAvailablePred;

70}

71

73

74

75 unsigned NumNodesBlocking = 0;

76 for (const SDep &Succ : SU->Succs)

77 if (getSingleUnscheduledPred(Succ.getSUnit()) == SU)

78 ++NumNodesBlocking;

79 NumNodesSolelyBlocking[SU->NodeNum] = NumNodesBlocking;

80

81 Queue.push_back(SU);

82}

83

84

85

86

87

88

90 for (const SDep &Succ : SU->Succs)

91 AdjustPriorityOfUnscheduledPreds(Succ.getSUnit());

92}

93

94

95

96

97

98

99

100void LatencyPriorityQueue::AdjustPriorityOfUnscheduledPreds(SUnit *SU) {

101 if (SU->isAvailable) return;

102

103 SUnit *OnlyAvailablePred = getSingleUnscheduledPred(SU);

104 if (!OnlyAvailablePred || !OnlyAvailablePred->isAvailable) return;

105

106

107

108 remove(OnlyAvailablePred);

109

110

111

112 push(OnlyAvailablePred);

113}

114

116 if (empty()) return nullptr;

117 std::vector<SUnit *>::iterator Best = Queue.begin();

118 for (std::vector<SUnit *>::iterator I = std::next(Queue.begin()),

119 E = Queue.end(); I != E; ++I)

120 if (Picker(*Best, *I))

121 Best = I;

122 SUnit *V = *Best;

123 if (Best != std::prev(Queue.end()))

125 Queue.pop_back();

126 return V;

127}

128

130 assert(!Queue.empty() && "Queue is empty!");

131 std::vector<SUnit *>::iterator I = find(Queue, SU);

132 assert(I != Queue.end() && "Queue doesn't contain the SU being removed!");

133 if (I != std::prev(Queue.end()))

135 Queue.pop_back();

136}

137

138#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

140 dbgs() << "Latency Priority Queue\n";

141 dbgs() << " Number of Queue Entries: " << Queue.size() << "\n";

142 for (const SUnit *SU : Queue) {

143 dbgs() << " ";

145 }

146}

147#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

#define LLVM_DUMP_METHOD

Mark debug helper function definitions like dump() that should not be stripped from debug builds.

void push(SUnit *U) override

Definition LatencyPriorityQueue.cpp:72

SUnit * pop() override

Definition LatencyPriorityQueue.cpp:115

LLVM_DUMP_METHOD void dump(ScheduleDAG *DAG) const override

Definition LatencyPriorityQueue.cpp:139

void remove(SUnit *SU) override

Definition LatencyPriorityQueue.cpp:129

void scheduledNode(SUnit *SU) override

As each node is scheduled, this method is invoked.

Definition LatencyPriorityQueue.cpp:89

bool empty() const override

Scheduling unit. This is a node in the scheduling DAG.

unsigned NodeNum

Entry # of node in the node vector.

bool isAvailable

True once available.

SmallVector< SDep, 4 > Succs

All sunit successors.

SmallVector< SDep, 4 > Preds

All sunit predecessors.

virtual void dumpNode(const SUnit &SU) const =0

This is an optimization pass for GlobalISel generic memory operations.

auto find(R &&Range, const T &Val)

Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)

Implement std::swap in terms of BitVector swap.

LatencyPriorityQueue * PQ

bool operator()(const SUnit *LHS, const SUnit *RHS) const

Definition LatencyPriorityQueue.cpp:23