Require the two-argument MI::addOperand(MF, MO) for dangling instructions.

Instructions that are inserted in a basic block can still be decorated
with addOperand(MO).

Make the two-argument addOperand() function contain the actual
implementation. This function will now always have a valid MF reference
that it can use for memory allocation.

llvm-svn: 170798
This commit is contained in:
Jakob Stoklund Olesen 2012-12-20 22:54:05 +00:00
parent 33f5d1492d
commit 2455b58551
2 changed files with 25 additions and 12 deletions

View File

@ -940,19 +940,24 @@ public:
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// Accessors used to build up machine instructions. // Accessors used to build up machine instructions.
/// addOperand - Add the specified operand to the instruction. If it is an /// Add the specified operand to the instruction. If it is an implicit
/// implicit operand, it is added to the end of the operand list. If it is /// operand, it is added to the end of the operand list. If it is an
/// an explicit operand it is added at the end of the explicit operand list /// explicit operand it is added at the end of the explicit operand list
/// (before the first implicit operand). /// (before the first implicit operand).
void addOperand(const MachineOperand &Op); ///
/// MF must be the machine function that was used to allocate this
/// instruction.
///
/// MachineInstrBuilder provides a more convenient interface for creating
/// instructions and adding operands.
void addOperand(MachineFunction &MF, const MachineOperand &Op);
// Add an operand while providing a context pointer. This will replace the /// Add an operand without providing an MF reference. This only works for
// single-argument function shortly. /// instructions that are inserted in a basic block.
// ///
// MF must be the machine function that was used to allocate this instruction. /// MachineInstrBuilder and the two-argument addOperand(MF, MO) should be
void addOperand(MachineFunction &MF, const MachineOperand &Op) { /// preferred.
addOperand(Op); void addOperand(const MachineOperand &Op);
}
/// setDesc - Replace the instruction descriptor (thus opcode) of /// setDesc - Replace the instruction descriptor (thus opcode) of
/// the current instruction with a new one. /// the current instruction with a new one.

View File

@ -603,11 +603,19 @@ void MachineInstr::AddRegOperandsToUseLists(MachineRegisterInfo &MRI) {
MRI.addRegOperandToUseList(&Operands[i]); MRI.addRegOperandToUseList(&Operands[i]);
} }
void MachineInstr::addOperand(const MachineOperand &Op) {
MachineBasicBlock *MBB = getParent();
assert(MBB && "Use MachineInstrBuilder to add operands to dangling instrs");
MachineFunction *MF = MBB->getParent();
assert(MF && "Use MachineInstrBuilder to add operands to dangling instrs");
addOperand(*MF, Op);
}
/// addOperand - Add the specified operand to the instruction. If it is an /// addOperand - Add the specified operand to the instruction. If it is an
/// implicit operand, it is added to the end of the operand list. If it is /// implicit operand, it is added to the end of the operand list. If it is
/// an explicit operand it is added at the end of the explicit operand list /// an explicit operand it is added at the end of the explicit operand list
/// (before the first implicit operand). /// (before the first implicit operand).
void MachineInstr::addOperand(const MachineOperand &Op) { void MachineInstr::addOperand(MachineFunction &MF, const MachineOperand &Op) {
assert(MCID && "Cannot add operands before providing an instr descriptor"); assert(MCID && "Cannot add operands before providing an instr descriptor");
bool isImpReg = Op.isReg() && Op.isImplicit(); bool isImpReg = Op.isReg() && Op.isImplicit();
MachineRegisterInfo *RegInfo = getRegInfo(); MachineRegisterInfo *RegInfo = getRegInfo();