MachineOperand RegOperand = MachineOperand::CreateReg(X86::EAX, /*isDef=*/false); // Creating a new register operand // Register ID is passed as the first parameter // isDef parameter indicates if the operand defines the register // In this case, the operand is not a definition of the register MachineInstr *MI = ... // Pointer to an existing machine instruction MI->addOperand(RegOperand); // Adding register operand to the instruction
MachineOperand ImmOperand = MachineOperand::CreateImm(42); // Creating a new immediate operand // Immediate value is passed as the parameter MachineInstr *MI = ... // Pointer to an existing machine instruction MI->addOperand(ImmOperand); // Adding immediate operand to the instructionPackage/library: LLVM Core (llvm/MC/MCInst.h)