Add method MachineInstr::replace to rewrite a machine instruction in place.
authorVikram S. Adve <vadve@cs.uiuc.edu>
Fri, 20 Sep 2002 00:47:49 +0000 (00:47 +0000)
committerVikram S. Adve <vadve@cs.uiuc.edu>
Fri, 20 Sep 2002 00:47:49 +0000 (00:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3843 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineInstr.h
lib/CodeGen/MachineInstr.cpp

index a2190d829d3b645f3a9e76a094eb769d8ed43b2f..106af9e5bfd2a035b9977bcf994f8974d70fd886 100644 (file)
@@ -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; }
 
   //
index e12922e4c87547468f054d97e3207c7612c09b52..02c25fdd7fbc08382d029ddacbed5b7d41ad933b 100644 (file)
@@ -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,