39 #define DEBUG_NAME "compiler2/ListSchedulingPass"
50 const GlobalSchedule*
GS;
52 unsigned users(Instruction *
I)
const {
54 for (Instruction::UserListTy::const_iterator
i = I->user_begin(),
55 e = I->user_end();
i !=
e; ++
i) {
56 Instruction *user = *
i;
58 if (
GS->get(user) ==
GS->get(I)) {
67 MyComparator(
const GlobalSchedule*
GS) : GS(GS) {}
69 bool operator() (Instruction* lhs, Instruction* rhs)
const {
70 if (lhs->get_opcode() != rhs->get_opcode()) {
72 if (lhs->to_BeginInst())
return false;
73 if (rhs->to_BeginInst())
return true;
75 if (rhs->to_EndInst())
return false;
76 if (lhs->to_EndInst())
return true;
78 if (lhs->to_PHIInst())
return false;
79 if (rhs->to_PHIInst())
return true;
81 if (lhs->to_LOADInst())
return false;
82 if (rhs->to_LOADInst())
return true;
85 unsigned lhs_user = users(lhs);
86 unsigned rhs_user = users(rhs);
87 if (lhs_user == rhs_user) {
88 return InstPtrLess()(rhs,lhs);
90 return lhs_user > rhs_user;
94 typedef alloc::priority_queue<Instruction*,alloc::deque<Instruction*>::type,MyComparator>::type PriorityQueueTy;
96 struct FindLeader2 :
public std::unary_function<Value*,void> {
103 : scheduled(scheduled), GS(GS), I(I), leader(leader) {}
105 void operator()(
Value *value) {
106 Instruction *
op = value->to_Instruction();
114 struct FindLeader :
public std::unary_function<Instruction*,void> {
121 : scheduled(scheduled), GS(GS), ready(ready), BI(BI) {}
124 void operator()(Instruction*
I) {
126 if (
GS->get(I) !=
GS->get(
BI)) {
131 std::for_each(I->op_begin(), I->op_end(), FindLeader2(
scheduled,
GS, I, leader));
133 std::for_each(I->dep_begin(), I->dep_end(), FindLeader2(
scheduled,
GS, I, leader));
135 LOG(
"leader: " << I <<
nl);
149 MyComparator comp = MyComparator(
GS);
150 PriorityQueueTy
ready(comp);
160 LOG3(
"Instruction: " << I <<
nl);
164 LOG3(
"schedule(initial leader): " << I <<
" #op " << I->
op_size() <<
" #dep " << I->
dep_size() <<
nl);
166 std::for_each(I->
op_begin(), I->
op_end(), FindLeader2(scheduled,
GS, I, leader));
171 LOG(
"initial leader: " << I <<
nl);
176 while (!ready.empty()) {
179 if (scheduled.find(I) != scheduled.end()){
182 inst_list.push_back(I);
183 LOG(
"insert: " << I <<
nl);
190 #if defined(ENABLE_LOGGING)
201 GS = get_Pass<ScheduleClickPass>();
205 LOG(
"ListScheduling: " << BI <<
nl);
208 #if defined(ENABLE_LOGGING)
209 LOG(
"Schedule:" <<
nl);
232 ERROR_MSG(
"Instruction not Scheduled!",
"Instruction: " << I);
const_inst_iterator inst_end(const BeginInst *BI) const
std::set< Instruction *, std::less< Instruction * >, Allocator< Instruction * > > type
const_dep_iterator rdep_begin() const
virtual bool run(JITData &JD)
Run the Pass.
void schedule(BeginInst *begin)
Schedule the instructions within the block that starts at begin.
UserListTy::const_iterator user_begin() const
const_inst_iterator inst_begin(const BeginInst *BI) const
BBListTy::const_iterator const_bb_iterator
const_bb_iterator bb_end() const
This Instruction marks the start of a basic block.
Method * M
The Method to process.
const_dep_iterator dep_begin() const
#define ERROR_MSG(EXPR_SHORT, EXPR_LONG)
UserListTy::const_iterator user_end() const
GlobalSchedule * GS
The current GlobalSchedule of the processed Method.
const_inst_iterator inst_begin(const BeginInst *BI) const
alloc::set< Instruction * >::type & scheduled
Stores the interdependencies of a pass.
virtual bool verify() const
Verify the Result.
const_dep_iterator rdep_end() const
InstructionListTy::const_iterator const_iterator
const_iterator end() const
const_op_iterator op_begin() const
#define LOG(STMT)
Analogous to DEBUG.
alloc::unordered_set< Instruction * >::type::const_iterator const_inst_iterator
Represents the result of the addition of a certain IR-variable with a certain constant.
jmethodID jint const void jint const jvmtiAddrLocationMap * map
const GlobalSchedule * GS
const_iterator begin() const
const_dep_iterator dep_end() const
alloc::vector< Instruction * >::type InstructionListTy
virtual BeginInst * to_BeginInst()
virtual PassUsage & get_PassUsage(PassUsage &PU) const
Set the requirements for the pass.
const_inst_iterator inst_end(const BeginInst *BI) const
static PassRegistry< BasicBlockSchedulingPass > X("BasicBlockSchedulingPass")
InstructionListTy::const_iterator const_inst_iterator
const_op_iterator op_end() const
void add_requires()
PassName is required.
const_bb_iterator bb_begin() const