MachineBasicBlock* MBB; // assume MBB is a valid machine basic block MachineInstr* LastInstr = MBB->getLastNonDebugInstr(); if (LastInstr != nullptr) { unsigned Opcode = LastInstr->getOpcode(); errs() << "Last instruction in MBB has opcode " << Opcode << "\n"; }
bool MyOptPass::runOnMachineFunction(MachineFunction &MF) { bool Changed = false; for (auto &MBB : MF) { MachineInstr* LastInstr = MBB.getLastNonDebugInstr(); if (LastInstr != nullptr) { unsigned Opcode = LastInstr->getOpcode(); if (Opcode == MyRedundantOpcode) { // remove redundant code MBB.erase(LastInstr); Changed = true; } } } return Changed; }In both examples, we can see that getLastNonDebugInstr is called on a MachineBasicBlock object. Therefore, we can determine that this function is part of the LLVM package library.