-// $Id$
-//***************************************************************************
-// File:
-// MachineInstr.cpp
+//===-- MachineInstr.cpp --------------------------------------------------===//
//
-// Purpose:
-//
-//
-// Strategy:
-//
-// History:
-// 7/2/01 - Vikram Adve - Created
-//**************************************************************************/
+//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Value.h"
-#include <iostream>
using std::cerr;
-//************************ Class Implementations **************************/
-
// Constructor for instructions with fixed #operands (nearly all)
MachineInstr::MachineInstr(MachineOpCode _opCode,
OpCodeMask _opCodeMask)
{
}
+//
+// 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,
Value* _val,
- bool isdef=false,
- bool isDefAndUse=false)
+ bool isdef,
+ bool isDefAndUse)
{
assert(i < operands.size());
operands[i].Initialize(opType, _val);
void
MachineInstr::SetMachineOperandReg(unsigned int i,
int regNum,
- bool isdef=false,
- bool isDefAndUse=false,
- bool isCCReg=false)
+ bool isdef,
+ bool isDefAndUse,
+ bool isCCReg)
{
assert(i < operands.size());
operands[i].InitializeReg(regNum, isCCReg);
}
+// Subsitute all occurrences of Value* oldVal with newVal in all operands
+// and all implicit refs. If defsOnly == true, substitute defs only.
+unsigned
+MachineInstr::substituteValue(const Value* oldVal, Value* newVal, bool defsOnly)
+{
+ unsigned numSubst = 0;
+
+ // Subsitute operands
+ for (MachineInstr::val_op_iterator O = begin(), E = end(); O != E; ++O)
+ if (*O == oldVal)
+ if (!defsOnly || O.isDef())
+ {
+ O.getMachineOperand().value = newVal;
+ ++numSubst;
+ }
+
+ // Subsitute implicit refs
+ for (unsigned i=0, N=implicitRefs.size(); i < N; ++i)
+ if (implicitRefs[i] == oldVal)
+ if (!defsOnly || implicitRefIsDefined(i))
+ {
+ implicitRefs[i] = newVal;
+ ++numSubst;
+ }
+
+ return numSubst;
+}
+
+
void
MachineInstr::dump() const
{
cerr << " " << *this;
}
-static inline std::ostream &OutputValue(std::ostream &os,
- const Value* val)
+static inline std::ostream&
+OutputValue(std::ostream &os, const Value* val)
{
os << "(val ";
if (val && val->hasName())
return os << (void*) val << ")"; // print address only
}
+static inline std::ostream&
+OutputReg(std::ostream &os, unsigned int regNum)
+{
+ return os << "%mreg(" << regNum << ")";
+}
+
std::ostream &operator<<(std::ostream& os, const MachineInstr& minstr)
{
os << TargetInstrDescriptors[minstr.opCode].opCodeString;
case MachineOperand::MO_VirtualRegister:
os << "%reg";
OutputValue(os, mop.getVRegValue());
+ if (mop.hasAllocatedReg())
+ os << "==" << OutputReg(os, mop.getAllocatedRegNum());
break;
case MachineOperand::MO_CCRegister:
os << "%ccreg";
OutputValue(os, mop.getVRegValue());
+ if (mop.hasAllocatedReg())
+ os << "==" << OutputReg(os, mop.getAllocatedRegNum());
break;
case MachineOperand::MO_MachineRegister:
- os << "%reg";
- os << "(" << mop.getMachineRegNum() << ")";
+ OutputReg(os, mop.getMachineRegNum());
break;
case MachineOperand::MO_SignExtendedImmed:
os << (long)mop.immedVal;