Loops
Loops are important structures to identify in the CFGs in order to generate efficient code. Indeed, most programs spend most of their time in loops, which means that the code generated in loops is especially critical to get right for performance.
We are sure you are already familiar with the concepts of loop, loop nest, inner loop, outer loop, and the like. However, it is less likely that you are familiar with some terminologies used in compilers and, especially, LLVM.
This section focuses on concepts that are likely new to you and, hence, does not reintroduce all of them. You can find a complete refresher on loops at https://llvm.org/docs/LoopTerminology.html.
Terminology
Let us first start with a diagram representing the different elements of a canonical loop in LLVM, Figure 4.6, and we will define these terms one by one:
Figure 4.6: A canonical loop in LLVM
Preheader
The preheader of a loop is a basic block that is not part of the loop but...