MachineInstr* mi = // some machine instruction const MCInstrDesc& desc = mi->getDesc(); int opCount = desc.NumOperands;
for (MachineInstr& mi : function) { const MCInstrDesc& desc = mi.getDesc(); if (desc.isBranch()) { // instruction is a branch } }In this example, we iterate over all instructions in a function and test if each instruction is a branching instruction by calling the isBranch() method of its description. The MachineInstr class is part of the LLVM package, which is a compiler infrastructure toolkit that is designed for optimizing and analyzing code.