#include "llvm/CodeGen/MachineInstr.h" using namespace llvm; MachineInstr *MI = ...; // create machine instruction unsigned Opcode = MI->getOpcode(); // extract opcode
#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineBasicBlock.h" using namespace llvm; MachineFunction *MF = ...; // create machine function MachineBasicBlock *MBB = MF->getBlockList().begin(); // get first block for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); I != E; ++I) { MachineInstr *MI = &*I; // do something with instruction }This code iterates over all instructions in the first basic block of a machine function. It uses the begin() and end() methods of the block list to get an iterator range, and then uses a for loop to iterate over the range. The dereference operator (*) is used to convert the iterator to a MachineInstr pointer. Package Library: LLVM Core Libraries.