43 #define DEBUG_NAME "compiler2/MachineInstructionSchedulingPass"
59 struct UpdatePhiOperand :
public std::unary_function<MachinePhiInst*,void> {
63 UpdatePhiOperand(InstMapTy &
inst_map) : inst_map(inst_map) {}
65 virtual void operator()(MachinePhiInst* phi)
const {
66 PHIInst* phi_inst = phi->get_PHIInst();
71 e = phi->end();
i !=
e; ++
i) {
72 Instruction *
I = (*op)->to_Instruction();
74 InstMapTy::const_iterator it =
inst_map.find(I);
88 unsigned users(Instruction *I)
const {
91 e = I->user_end();
i !=
e; ++
i) {
92 Instruction *user = *
i;
101 MyComparator(
const GlobalSchedule*
sched) : sched(sched) {}
102 bool operator() (Instruction* lhs, Instruction* rhs)
const {
103 if (lhs->get_opcode() != rhs->get_opcode()) {
105 if (lhs->to_BeginInst())
return false;
106 if (rhs->to_BeginInst())
return true;
108 if (rhs->to_EndInst())
return false;
109 if (lhs->to_EndInst())
return true;
111 if (lhs->to_PHIInst())
return false;
112 if (rhs->to_PHIInst())
return true;
114 if (lhs->to_LOADInst())
return false;
115 if (rhs->to_LOADInst())
return true;
118 unsigned lhs_user = users(lhs);
119 unsigned rhs_user = users(rhs);
120 if (lhs_user == rhs_user) {
121 return InstPtrLess()(rhs,lhs);
123 return lhs_user > rhs_user;
127 typedef alloc::priority_queue<Instruction*,alloc::deque<Instruction*>::type,MyComparator>::type PriorityQueueTy;
129 struct FindLeader2 :
public std::unary_function<Value*,void> {
131 GlobalSchedule *
sched;
136 : scheduled(scheduled), sched(sched), I(I), leader(leader) {}
138 void operator()(
Value *value) {
139 Instruction *op = value->to_Instruction();
147 struct FindLeader :
public std::unary_function<Instruction*,void> {
149 GlobalSchedule *
sched;
154 : scheduled(scheduled), sched(sched), ready(ready), BI(BI) {}
157 void operator()(Instruction* I) {
164 std::for_each(I->op_begin(), I->op_end(), FindLeader2(
scheduled,
sched, I, leader));
166 std::for_each(I->dep_begin(), I->dep_end(), FindLeader2(
scheduled,
sched, I, leader));
168 LOG(
"leader: " << I <<
nl);
180 #if !PATTERN_MATCHING
209 #if !PATTERN_MATCHING
210 LOG2(
"lowering for BB using list sched " << BI <<
nl);
212 e = IS->inst_end(BI);
i !=
e; ++
i) {
214 LOG2(
"lower: " << *I <<
nl);
218 LOG2(
"Lowering with Pattern Matching " << BI <<
nl);
227 assert(it != map.end());
235 LOG2(
"MBB: " << *MBB <<
nl);
237 UpdatePhiOperand functor(inst_map);
249 LOG2(
"new MBB: " << *new_MBB <<
nl);
261 #if !PATTERN_MATCHING
269 if(MBB->
size() == 0) {
270 ERROR_MSG(
"verification failed",
"MachineBasicBlock ("
271 << *MBB <<
") empty");
277 ERROR_MSG(
"verification failed",
"first Instruction ("
278 << *front <<
") not a label");
284 ERROR_MSG(
"verification failed",
"last Instruction ("
285 << *back <<
") not a control flow transfer instruction");
294 if (phi->
op_size() != num_pred) {
295 ERROR_MSG(
"verification failed",
"Machine basic block (" << *MBB <<
") has "
296 << num_pred <<
" predecessors but phi node (" << *phi <<
") has " << phi->
op_size());
336 MyComparator comp = MyComparator(
sched);
337 PriorityQueueTy
ready(comp);
347 LOG3(
"Instruction: " << I <<
nl);
351 LOG3(
"schedule(initial leader): " << I <<
" #op " << I->
op_size() <<
" #dep " << I->
dep_size() <<
nl);
358 LOG(
"initial leader: " << I <<
nl);
363 while (!ready.empty()) {
366 if (scheduled.find(I) != scheduled.end()){
369 inst_list.push_back(I);
370 LOG(
"insert: " << I <<
nl);
377 #if defined(ENABLE_LOGGING)
390 LOG(
"ListScheduling: " << BI <<
nl);
393 #if defined(ENABLE_LOGGING)
394 LOG(
"Schedule:" <<
nl);
412 if (std::find(inst_begin(BI),inst_end(BI),I) != inst_end(BI)) {
417 ERROR_MSG(
"Instruction not Scheduled!",
"Instruction: " << I);
alloc::ordered_list< MachineBasicBlock * >::type list
const_inst_iterator inst_end(const BeginInst *BI) const
std::set< Instruction *, std::less< Instruction * >, Allocator< Instruction * > > type
GlobalSchedule TODO: more info.
virtual bool verify() const
const_phi_iterator phi_end() const
returns an const iterator to the phi instructions
const_dep_iterator rdep_begin() const
UserListTy::const_iterator user_begin() const
virtual bool is_jump() const
const_inst_iterator inst_begin(const BeginInst *BI) const
BBListTy::const_iterator const_bb_iterator
PredecessorListTy::const_iterator const_pred_iterator
const GlobalSchedule * sched
PhiListTy::const_iterator const_phi_iterator
virtual bool is_end() const
This Instruction mark the start of a basic block.
A basic block of (scheduled) machine instructions.
virtual void accept(InstructionVisitor &v, bool copyOperands)=0
Visitor.
const_dep_iterator dep_begin() const
_Base::const_iterator const_iterator
MBBIterator self_iterator() const
get self iterator
void move_instructions(InputIterator first, InputIterator last, MachineBasicBlock &from, MachineBasicBlock &to)
Move instructions to another basic block.
iterator end()
returns an iterator to the end
virtual bool is_label() const
reference back()
access the last element
#define ERROR_MSG(EXPR_SHORT, EXPR_LONG)
iterator begin()
returns an iterator to the beginning
virtual PassUsage & get_PassUsage(PassUsage &PA) const
Set the requirements for the pass.
const_pred_iterator pred_begin() const
std::size_t size() const
returns the number of elements
UserListTy::const_iterator user_end() const
iterator end()
returns an iterator to the end
const_phi_iterator phi_begin() const
returns an const iterator to the phi instructions
OperandListTy::const_iterator const_op_iterator
const_reference front() const
access the first element
const_inst_iterator inst_begin(const BeginInst *BI) const
const_reference back() const
access the last element
iterator begin()
returns an iterator to the beginning
virtual void initialize()
Initialize the Pass.
void schedule(BeginInst *BI)
schedule one basic block
std::size_t op_size() const
reference front()
access the first element
Stores the interdependencies of a pass.
std::size_t pred_size() const
returns the number of predecessor nodes
const_bb_iterator bb_end() const
void push_front(MachineInstruction *value)
inserts value to the beginning
shared_ptr< ListSchedulingPass > IS
const_dep_iterator rdep_end() const
MachineInstructionSchedule::iterator insert_after(iterator pos, const MBBBuilder &value)
inserts value after the element pointed to by pos
const_bb_iterator bb_begin() const
InstructionListTy::const_iterator const_iterator
const_op_iterator op_begin() const
#define LOG(STMT)
Analogous to DEBUG.
Proxy to encode explicit and implicit successors.
operand_list::iterator operand_iterator
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
virtual bool verify() const
Verify the Result.
virtual bool run(JITData &JD)
const_pred_iterator pred_end() const
BasicBlockListTy::const_iterator const_bb_iterator
const_dep_iterator dep_end() const
alloc::set< Instruction * >::type & scheduled
alloc::vector< Instruction * >::type InstructionListTy
BasicBlockSchedulingPass TODO: more info.
virtual BeginInst * to_BeginInst()
void insert_pred(MachineBasicBlock *value)
Appends the given element value to the list of predecessors.
const_inst_iterator inst_end(const BeginInst *BI) const
static PassRegistry< BasicBlockSchedulingPass > X("BasicBlockSchedulingPass")
InstructionListTy::const_iterator const_inst_iterator
BasicBlockSchedule TODO: more info.
MachineInstructionSchedule::iterator push_back(const MBBBuilder &value)
Appends the given element value to the end of the container.
const_op_iterator op_end() const
void add_requires()
PassName is required.
MachineBasicBlock * get_block() const
virtual bool run(JITData &JD)
Run the Pass.
InstructionSchedule TODO: more info.
virtual BeginInst * get_BeginInst() const
Get the corresponding BeginInst.