BasicBlockIterator itr = function.BeginBasicBlockIterator(); while (itr != function.EndBasicBlockIterator()){ BasicBlock * bb = itr->Get(); InstructionIterator itrbb(bb); while (itrbb != bb->Instruction_End()){ Instruction * i = itrbb->Get(); if (i->isPHI()){ //do something with PHI instruction } ++itrbb; } ++itr; }
bool isPhiFound = false; BasicBlockIterator itr = function.BeginBasicBlockIterator(); while (itr != function.EndBasicBlockIterator()){ BasicBlock * bb = itr->Get(); InstructionIterator itrbb(bb); while (itrbb != bb->Instruction_End()){ Instruction * i = itrbb->Get(); if (i->isPHI()){ isPhiFound = true; break; } ++itrbb; } if (isPhiFound) break; ++itr; }This code example uses the isPHI function to detect whether any instruction in the basic blocks is a PHI instruction. If a PHI instruction is found, the code exits the loop. Package/Library: The examples provided are part of the LLVM (Low Level Virtual Machine) package/library, specifically the MachineBasicBlock and Instruction classes within the LLVM IR (Intermediate Representation) category.