Due to hardware design limitation, it may contain bubbles between instructions when the processor is executing. Bubble means the processor could not execute next instruction and wait for the condition for the next instruction is satisfied. In general, we called the situation as hazard. There are mainly three kinds of hazards, i.e., data hazard, structure hazard, and control hazard.
Instruction scheduling is an important software method to avoid data hazard and structure hazard in computer architecture. Compiler uses instruction scheduling algorithm to rearrange the order of instructions to achieve higher performance of the processor. In this talk, I will introduce the instruction scheduling algorithm and talk about the implementation in LLVM. I will give an example to show how the algorithm works. In addition, I will talk about how to model the pipeline of a simple five-stages in-order processor architecture in LLVM.