MachineBasicBlock::iterator I = MBB.getFirstNonPHI(); for (; I != MBB.end(); ++I) { if (I->getOpcode() == TargetOpcode::CALL) { // Do something with the call instruction MachineInstr *MI = &(*I); MachineBasicBlock *MBB = MI->getParent(); MachineFunction *MF = MBB->getParent(); MachineFunction::iterator MFI = MF->iterator(); ... } }
MachineFunction *MF = ...; for (MachineBasicBlock &MBB : *MF) { for (MachineInstr &MI : MBB) { int Opcode = MI.getOpcode(); if (Opcode == TargetOpcode::ADD) { MachineBasicBlock::iterator I = MI.getIterator(); // Do something with the add instruction ... } } }This code iterates over each instruction in a machine function and checks if it is an add instruction. If it is, it gets a pointer to the instruction using the MachineInstr getIterator function and then does something with it. Overall, the MachineInstr getIterator function is part of the LLVM package library.