Using the generic Machine optimizations
Although the default Machine pass pipeline comes with a lot of optimizations, some of them may not do a whole lot out of the box.
Indeed, like the LLVM IR passes that rely on the TargetTransformInfo class to be able to do their job, some Machine IR passes need the help of the TargetInstrInfo, TargetRegisterInfo, or TargetLowering class, as well as some properties on the instruction themselves to perform their job.
For instance, the MachineSink optimization, which pushes down the control flow graph (CFG) instructions and can be moved in less frequently executed program points, relies on some of the properties that are attached to the MachineInstr instances to check whether it’s safe to move the instructions (for instance, the memory operations, meaning the instructions with the mayStore or mayLoad properties are deemed unsafe to move in this pass) and use hooks from the TargetInstrInfo class (which you can override) to drive the...