MachineInstrBuilder builder = BuildMI(BB, MI, DL, get(MIPS::ADD)); builder.addReg(Register1); builder.addReg(Register2); builder.addImm(ImmediateValue);
MachineBasicBlock &MBB = *MF.CreateMachineBasicBlock(); MachineFunction::iterator InsertPt = MF.begin(); MBB.addLiveIn(Register); InsertPt = MF.insert(InsertPt, &MBB); DebugLoc DL; DL = MBB.front().getDebugLoc(); unsigned ADD = MIPS::ADD; BuildMI(MBB, InsertPt, DL, TII->get(ADD), Register) .addReg(Register) .addImm(ImmediateValue);In this example, we are creating a new Machine Basic Block (MBB) and adding a single machine-level instruction to it. We are using the `addLiveIn` method to specify the register used as input by the MBB. We are then inserting the MBB into the beginning of the function (`InsertPt`) and using the `BuildMI` and `addReg` methods to add the same type of operands as in the first example. Package Library: LLVM’s Target Independent Code Generator library.