Skip to main content

heads

Function heads 

Source
pub fn heads(func: &Func) -> Vec<Block> ⓘ
Expand description

The heads of the loops, which are the blocks a jump inside a loop runs backwards to, in the order they are laid out.

Read off the layout rather than off a loop tree, because what the padding is for is where the jump lands and the layout is what says that. A loop the layout rotated has its test at the bottom and its body at the top, and the top of the body is the head here, since it is where the back edge goes every time round. A block that jumps to itself is its own head.

A jump that runs backwards is not always a loop. The trace can lay a cold arm out after the block it rejoins, and the jump back from it runs once. What makes it a loop is that the block it lands on can get back to the jump, which is both ends being on one cycle of the graph.

Never the first block. The front of a function is already on the boundary a function is given, and anything put between the function’s name and its first instruction would be in the room a patcher was promised or ahead of the landing pad an indirect call has to find first.

Nor a loop that hardly runs. spec/optimizer/38-scheduling-and-layout.md section 38.5 takes gcc’s align-threshold: padding is size, so it goes in front of a head that runs at least a hundredth as often as the hottest block of the function and nowhere else. A function with no weights has every block at the same one, and then every loop is hot enough.

Run after blocks, and after anything else that adds or takes out a block.