aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/CodeGen/MachineInstr.h12
-rw-r--r--lib/CodeGen/MachineInstr.cpp16
2 files changed, 28 insertions, 0 deletions
diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h
index a2190d829d..106af9e5bf 100644
--- a/include/llvm/CodeGen/MachineInstr.h
+++ b/include/llvm/CodeGen/MachineInstr.h
@@ -295,6 +295,18 @@ public:
unsigned numOperands,
OpCodeMask _opCodeMask = 0x0);
inline ~MachineInstr () {}
+
+ //
+ // Support to rewrite a machine instruction in place: for now, simply
+ // replace() and then set new operands with Set.*Operand methods below.
+ //
+ void replace (MachineOpCode _opCode,
+ unsigned numOperands,
+ OpCodeMask _opCodeMask = 0x0);
+
+ //
+ // The op code. Note that MachineOpCode is a target-specific type.
+ //
const MachineOpCode getOpCode () const { return opCode; }
//
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp
index e12922e4c8..02c25fdd7f 100644
--- a/lib/CodeGen/MachineInstr.cpp
+++ b/lib/CodeGen/MachineInstr.cpp
@@ -27,6 +27,22 @@ MachineInstr::MachineInstr(MachineOpCode _opCode,
{
}
+//
+// Support for replacing opcode and operands of a MachineInstr in place.
+// This only resets the size of the operand vector and initializes it.
+// The new operands must be set explicitly later.
+//
+void
+MachineInstr::replace(MachineOpCode _opCode,
+ unsigned numOperands,
+ OpCodeMask _opCodeMask)
+{
+ opCode = _opCode;
+ opCodeMask = _opCodeMask;
+ operands.clear();
+ operands.resize(numOperands);
+}
+
void
MachineInstr::SetMachineOperandVal(unsigned int i,
MachineOperand::MachineOperandType opType,