2002-08-09 20:08:06 +00:00
|
|
|
//===-- MachineInstr.cpp --------------------------------------------------===//
|
2001-07-21 12:41:50 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2004-02-13 04:39:32 +00:00
|
|
|
//
|
|
|
|
// Methods common to all machine instructions.
|
|
|
|
//
|
|
|
|
// FIXME: Now that MachineInstrs have parent pointers, they should always
|
|
|
|
// print themselves using their MachineFunction's TargetMachine.
|
|
|
|
//
|
2002-08-09 20:08:06 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2001-09-07 17:18:30 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2004-02-19 16:17:08 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2002-02-03 07:46:01 +00:00
|
|
|
#include "llvm/Value.h"
|
2002-10-30 00:48:05 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2003-01-14 22:00:31 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2002-10-30 00:58:19 +00:00
|
|
|
#include "llvm/Target/MRegisterInfo.h"
|
2004-02-16 07:17:43 +00:00
|
|
|
#include "Support/LeakDetector.h"
|
2004-02-23 18:38:20 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2002-10-29 17:40:30 +00:00
|
|
|
// Global variable holding an array of descriptors for machine instructions.
|
|
|
|
// The actual object needs to be created separately for each target machine.
|
2003-01-14 22:00:31 +00:00
|
|
|
// This variable is initialized and reset by class TargetInstrInfo.
|
2002-10-29 17:40:30 +00:00
|
|
|
//
|
|
|
|
// FIXME: This should be a property of the target so that more than one target
|
|
|
|
// at a time can be active...
|
|
|
|
//
|
2004-02-23 18:40:08 +00:00
|
|
|
namespace llvm {
|
2004-02-23 18:38:20 +00:00
|
|
|
extern const TargetInstrDescriptor *TargetInstrDescriptors;
|
|
|
|
}
|
2001-10-18 22:40:02 +00:00
|
|
|
|
2001-07-31 21:49:28 +00:00
|
|
|
// Constructor for instructions with variable #operands
|
2004-02-12 18:49:07 +00:00
|
|
|
MachineInstr::MachineInstr(short opcode, unsigned numOperands)
|
|
|
|
: Opcode(opcode),
|
|
|
|
numImplicitRefs(0),
|
|
|
|
operands(numOperands, MachineOperand()),
|
|
|
|
parent(0) {
|
2004-02-16 07:17:43 +00:00
|
|
|
// Make sure that we get added to a machine basicblock
|
|
|
|
LeakDetector::addGarbageObject(this);
|
2002-10-28 20:48:39 +00:00
|
|
|
}
|
|
|
|
|
2002-10-29 23:19:00 +00:00
|
|
|
/// MachineInstr ctor - This constructor only does a _reserve_ of the operands,
|
|
|
|
/// not a resize for them. It is expected that if you use this that you call
|
|
|
|
/// add* methods below to fill up the operands, instead of the Set methods.
|
|
|
|
/// Eventually, the "resizing" ctors will be phased out.
|
|
|
|
///
|
2004-02-13 04:39:32 +00:00
|
|
|
MachineInstr::MachineInstr(short opcode, unsigned numOperands, bool XX, bool YY)
|
|
|
|
: Opcode(opcode), numImplicitRefs(0), parent(0) {
|
2002-10-28 20:59:49 +00:00
|
|
|
operands.reserve(numOperands);
|
2004-02-16 07:17:43 +00:00
|
|
|
// Make sure that we get added to a machine basicblock
|
|
|
|
LeakDetector::addGarbageObject(this);
|
2002-10-28 20:59:49 +00:00
|
|
|
}
|
|
|
|
|
2002-10-29 23:19:00 +00:00
|
|
|
/// MachineInstr ctor - Work exactly the same as the ctor above, except that the
|
|
|
|
/// MachineInstr is created and added to the end of the specified basic block.
|
|
|
|
///
|
2004-02-12 18:49:07 +00:00
|
|
|
MachineInstr::MachineInstr(MachineBasicBlock *MBB, short opcode,
|
2002-10-29 23:19:00 +00:00
|
|
|
unsigned numOperands)
|
2004-02-13 04:39:32 +00:00
|
|
|
: Opcode(opcode), numImplicitRefs(0), parent(0) {
|
2002-10-29 23:19:00 +00:00
|
|
|
assert(MBB && "Cannot use inserting ctor with null basic block!");
|
|
|
|
operands.reserve(numOperands);
|
2004-02-16 07:17:43 +00:00
|
|
|
// Make sure that we get added to a machine basicblock
|
|
|
|
LeakDetector::addGarbageObject(this);
|
2002-10-29 23:19:00 +00:00
|
|
|
MBB->push_back(this); // Add instruction to end of basic block!
|
|
|
|
}
|
|
|
|
|
2004-02-16 07:17:43 +00:00
|
|
|
MachineInstr::~MachineInstr()
|
|
|
|
{
|
|
|
|
LeakDetector::removeGarbageObject(this);
|
|
|
|
}
|
|
|
|
|
2004-02-13 04:39:32 +00:00
|
|
|
/// OperandComplete - Return true if it's illegal to add a new operand
|
|
|
|
///
|
2004-02-12 16:09:53 +00:00
|
|
|
bool MachineInstr::OperandsComplete() const {
|
|
|
|
int NumOperands = TargetInstrDescriptors[Opcode].numOperands;
|
2002-10-29 19:41:18 +00:00
|
|
|
if (NumOperands >= 0 && getNumOperands() >= (unsigned)NumOperands)
|
2003-05-31 07:39:06 +00:00
|
|
|
return true; // Broken: we have all the operands of this instruction!
|
2002-10-28 20:48:39 +00:00
|
|
|
return false;
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2004-02-13 04:39:32 +00:00
|
|
|
/// replace - 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.
|
|
|
|
///
|
2004-02-12 18:49:07 +00:00
|
|
|
void MachineInstr::replace(short opcode, unsigned numOperands) {
|
2002-10-29 19:41:18 +00:00
|
|
|
assert(getNumImplicitRefs() == 0 &&
|
|
|
|
"This is probably broken because implicit refs are going to be lost.");
|
2004-02-12 16:09:53 +00:00
|
|
|
Opcode = opcode;
|
2002-09-20 00:47:49 +00:00
|
|
|
operands.clear();
|
2002-10-28 20:48:39 +00:00
|
|
|
operands.resize(numOperands, MachineOperand());
|
2002-09-20 00:47:49 +00:00
|
|
|
}
|
|
|
|
|
2003-08-05 16:58:46 +00:00
|
|
|
void MachineInstr::SetMachineOperandVal(unsigned i,
|
|
|
|
MachineOperand::MachineOperandType opTy,
|
|
|
|
Value* V) {
|
2002-10-29 19:41:18 +00:00
|
|
|
assert(i < operands.size()); // may be explicit or implicit op
|
2003-08-05 16:58:46 +00:00
|
|
|
operands[i].opType = opTy;
|
2004-03-03 19:07:27 +00:00
|
|
|
operands[i].contents.value = V;
|
2002-10-28 04:24:49 +00:00
|
|
|
operands[i].regNum = -1;
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-28 04:24:49 +00:00
|
|
|
MachineInstr::SetMachineOperandConst(unsigned i,
|
2004-02-13 04:39:32 +00:00
|
|
|
MachineOperand::MachineOperandType opTy,
|
2004-02-29 05:07:02 +00:00
|
|
|
int intValue) {
|
2002-10-29 19:41:18 +00:00
|
|
|
assert(i < getNumOperands()); // must be explicit op
|
2004-02-12 16:09:53 +00:00
|
|
|
assert(TargetInstrDescriptors[Opcode].resultPos != (int) i &&
|
2002-03-18 03:35:24 +00:00
|
|
|
"immed. constant cannot be defined");
|
2002-10-28 04:24:49 +00:00
|
|
|
|
2004-02-13 04:39:32 +00:00
|
|
|
operands[i].opType = opTy;
|
2004-03-03 19:07:27 +00:00
|
|
|
operands[i].contents.value = NULL;
|
|
|
|
operands[i].contents.immedVal = intValue;
|
2002-10-28 04:24:49 +00:00
|
|
|
operands[i].regNum = -1;
|
|
|
|
operands[i].flags = 0;
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2003-08-05 16:58:46 +00:00
|
|
|
void MachineInstr::SetMachineOperandReg(unsigned i, int regNum) {
|
2002-10-29 19:41:18 +00:00
|
|
|
assert(i < getNumOperands()); // must be explicit op
|
2002-10-28 04:24:49 +00:00
|
|
|
|
2002-10-28 19:46:59 +00:00
|
|
|
operands[i].opType = MachineOperand::MO_MachineRegister;
|
2004-03-03 19:07:27 +00:00
|
|
|
operands[i].contents.value = NULL;
|
2002-10-28 04:24:49 +00:00
|
|
|
operands[i].regNum = regNum;
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2004-02-13 04:39:32 +00:00
|
|
|
// Used only by the SPARC back-end.
|
2004-02-12 16:09:53 +00:00
|
|
|
void MachineInstr::SetRegForOperand(unsigned i, int regNum) {
|
2002-10-29 19:41:18 +00:00
|
|
|
assert(i < getNumOperands()); // must be explicit op
|
2002-07-08 22:38:45 +00:00
|
|
|
operands[i].setRegForValue(regNum);
|
|
|
|
}
|
|
|
|
|
2004-02-13 04:39:32 +00:00
|
|
|
// Used only by the SPARC back-end.
|
2004-02-12 16:09:53 +00:00
|
|
|
void MachineInstr::SetRegForImplicitRef(unsigned i, int regNum) {
|
2003-05-31 07:39:06 +00:00
|
|
|
getImplicitOp(i).setRegForValue(regNum);
|
|
|
|
}
|
|
|
|
|
2004-02-13 04:39:32 +00:00
|
|
|
/// substituteValue - Substitute all occurrences of Value* oldVal with newVal
|
|
|
|
/// in all operands and all implicit refs. If defsOnly == true, substitute defs
|
|
|
|
/// only.
|
|
|
|
///
|
|
|
|
/// FIXME: Fold this into its single caller, at SparcInstrSelection.cpp:2865,
|
|
|
|
/// or make it a static function in that file.
|
|
|
|
///
|
2002-08-14 16:52:58 +00:00
|
|
|
unsigned
|
2003-07-10 19:45:07 +00:00
|
|
|
MachineInstr::substituteValue(const Value* oldVal, Value* newVal,
|
|
|
|
bool defsOnly, bool notDefsAndUses,
|
|
|
|
bool& someArgsWereIgnored)
|
2002-08-14 16:52:58 +00:00
|
|
|
{
|
2003-08-07 15:01:48 +00:00
|
|
|
assert((!defsOnly || !notDefsAndUses) &&
|
|
|
|
"notDefsAndUses is irrelevant if defsOnly == true.");
|
2003-07-10 19:45:07 +00:00
|
|
|
|
2002-08-14 16:52:58 +00:00
|
|
|
unsigned numSubst = 0;
|
|
|
|
|
2003-09-17 21:34:23 +00:00
|
|
|
// Substitute operands
|
2002-08-14 16:52:58 +00:00
|
|
|
for (MachineInstr::val_op_iterator O = begin(), E = end(); O != E; ++O)
|
|
|
|
if (*O == oldVal)
|
2003-07-10 19:45:07 +00:00
|
|
|
if (!defsOnly ||
|
2003-12-14 13:24:17 +00:00
|
|
|
notDefsAndUses && (O.isDef() && !O.isUse()) ||
|
|
|
|
!notDefsAndUses && O.isDef())
|
2002-08-14 16:52:58 +00:00
|
|
|
{
|
2004-03-03 19:07:27 +00:00
|
|
|
O.getMachineOperand().contents.value = newVal;
|
2002-08-14 16:52:58 +00:00
|
|
|
++numSubst;
|
|
|
|
}
|
2003-07-10 19:45:07 +00:00
|
|
|
else
|
|
|
|
someArgsWereIgnored = true;
|
2002-08-14 16:52:58 +00:00
|
|
|
|
2003-09-17 21:34:23 +00:00
|
|
|
// Substitute implicit refs
|
2002-10-29 19:41:18 +00:00
|
|
|
for (unsigned i=0, N=getNumImplicitRefs(); i < N; ++i)
|
2002-10-22 23:16:21 +00:00
|
|
|
if (getImplicitRef(i) == oldVal)
|
2003-07-10 19:45:07 +00:00
|
|
|
if (!defsOnly ||
|
2003-12-14 13:24:17 +00:00
|
|
|
notDefsAndUses && (getImplicitOp(i).isDef() && !getImplicitOp(i).isUse()) ||
|
|
|
|
!notDefsAndUses && getImplicitOp(i).isDef())
|
2002-08-14 16:52:58 +00:00
|
|
|
{
|
2004-03-03 19:07:27 +00:00
|
|
|
getImplicitOp(i).contents.value = newVal;
|
2002-08-14 16:52:58 +00:00
|
|
|
++numSubst;
|
|
|
|
}
|
2003-07-10 19:45:07 +00:00
|
|
|
else
|
|
|
|
someArgsWereIgnored = true;
|
2002-08-14 16:52:58 +00:00
|
|
|
|
|
|
|
return numSubst;
|
|
|
|
}
|
|
|
|
|
2004-02-13 04:39:32 +00:00
|
|
|
void MachineInstr::dump() const {
|
2003-08-03 20:24:29 +00:00
|
|
|
std::cerr << " " << *this;
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2004-02-13 04:39:32 +00:00
|
|
|
static inline std::ostream& OutputValue(std::ostream &os, const Value* val) {
|
2002-04-25 04:31:18 +00:00
|
|
|
os << "(val ";
|
2003-07-10 19:45:07 +00:00
|
|
|
os << (void*) val; // print address always
|
2002-04-25 04:31:18 +00:00
|
|
|
if (val && val->hasName())
|
2004-02-13 04:39:32 +00:00
|
|
|
os << " " << val->getName(); // print name also, if available
|
|
|
|
os << ")";
|
2003-07-10 19:45:07 +00:00
|
|
|
return os;
|
2002-04-25 04:31:18 +00:00
|
|
|
}
|
|
|
|
|
2002-10-30 00:58:19 +00:00
|
|
|
static inline void OutputReg(std::ostream &os, unsigned RegNo,
|
|
|
|
const MRegisterInfo *MRI = 0) {
|
2004-02-27 01:52:34 +00:00
|
|
|
if (!RegNo || MRegisterInfo::isPhysicalRegister(RegNo)) {
|
2004-02-19 16:17:08 +00:00
|
|
|
if (MRI)
|
2002-10-30 00:58:19 +00:00
|
|
|
os << "%" << MRI->get(RegNo).Name;
|
|
|
|
else
|
2004-02-19 16:17:08 +00:00
|
|
|
os << "%mreg(" << RegNo << ")";
|
2002-10-30 00:58:19 +00:00
|
|
|
} else
|
2004-02-19 16:17:08 +00:00
|
|
|
os << "%reg" << RegNo;
|
2002-09-16 15:18:53 +00:00
|
|
|
}
|
|
|
|
|
2002-10-30 00:48:05 +00:00
|
|
|
static void print(const MachineOperand &MO, std::ostream &OS,
|
|
|
|
const TargetMachine &TM) {
|
2002-10-30 00:58:19 +00:00
|
|
|
const MRegisterInfo *MRI = TM.getRegisterInfo();
|
2002-10-30 00:48:05 +00:00
|
|
|
bool CloseParen = true;
|
2003-12-14 13:24:17 +00:00
|
|
|
if (MO.isHiBits32())
|
2002-10-30 00:48:05 +00:00
|
|
|
OS << "%lm(";
|
2003-12-14 13:24:17 +00:00
|
|
|
else if (MO.isLoBits32())
|
2002-10-30 00:48:05 +00:00
|
|
|
OS << "%lo(";
|
2003-12-14 13:24:17 +00:00
|
|
|
else if (MO.isHiBits64())
|
2002-10-30 00:48:05 +00:00
|
|
|
OS << "%hh(";
|
2003-12-14 13:24:17 +00:00
|
|
|
else if (MO.isLoBits64())
|
2002-10-30 00:48:05 +00:00
|
|
|
OS << "%hm(";
|
|
|
|
else
|
|
|
|
CloseParen = false;
|
|
|
|
|
|
|
|
switch (MO.getType()) {
|
|
|
|
case MachineOperand::MO_VirtualRegister:
|
|
|
|
if (MO.getVRegValue()) {
|
|
|
|
OS << "%reg";
|
|
|
|
OutputValue(OS, MO.getVRegValue());
|
|
|
|
if (MO.hasAllocatedReg())
|
|
|
|
OS << "==";
|
|
|
|
}
|
|
|
|
if (MO.hasAllocatedReg())
|
2004-02-13 21:01:20 +00:00
|
|
|
OutputReg(OS, MO.getReg(), MRI);
|
2002-10-30 00:48:05 +00:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_CCRegister:
|
|
|
|
OS << "%ccreg";
|
|
|
|
OutputValue(OS, MO.getVRegValue());
|
|
|
|
if (MO.hasAllocatedReg()) {
|
|
|
|
OS << "==";
|
2004-02-13 21:01:20 +00:00
|
|
|
OutputReg(OS, MO.getReg(), MRI);
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_MachineRegister:
|
2002-10-30 00:58:19 +00:00
|
|
|
OutputReg(OS, MO.getMachineRegNum(), MRI);
|
2002-10-30 00:48:05 +00:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_SignExtendedImmed:
|
|
|
|
OS << (long)MO.getImmedValue();
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_UnextendedImmed:
|
|
|
|
OS << (long)MO.getImmedValue();
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_PCRelativeDisp: {
|
|
|
|
const Value* opVal = MO.getVRegValue();
|
|
|
|
bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
|
|
|
|
OS << "%disp(" << (isLabel? "label " : "addr-of-val ");
|
|
|
|
if (opVal->hasName())
|
|
|
|
OS << opVal->getName();
|
|
|
|
else
|
|
|
|
OS << (const void*) opVal;
|
|
|
|
OS << ")";
|
|
|
|
break;
|
|
|
|
}
|
2002-12-15 20:35:25 +00:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
OS << "bb<"
|
|
|
|
<< ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
|
|
|
|
<< "," << (void*)MO.getMachineBasicBlock()->getBasicBlock() << ">";
|
|
|
|
break;
|
2002-12-28 20:37:37 +00:00
|
|
|
case MachineOperand::MO_FrameIndex:
|
|
|
|
OS << "<fi#" << MO.getFrameIndex() << ">";
|
|
|
|
break;
|
2003-01-13 00:23:24 +00:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
OS << "<cp#" << MO.getConstantPoolIndex() << ">";
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
OS << "<ga:" << ((Value*)MO.getGlobal())->getName() << ">";
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
OS << "<es:" << MO.getSymbolName() << ">";
|
|
|
|
break;
|
2002-10-30 00:48:05 +00:00
|
|
|
default:
|
|
|
|
assert(0 && "Unrecognized operand type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CloseParen)
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2002-11-17 23:22:13 +00:00
|
|
|
void MachineInstr::print(std::ostream &OS, const TargetMachine &TM) const {
|
2002-10-30 01:55:38 +00:00
|
|
|
unsigned StartOp = 0;
|
|
|
|
|
|
|
|
// Specialize printing if op#0 is definition
|
2003-12-14 13:24:17 +00:00
|
|
|
if (getNumOperands() && getOperand(0).isDef() && !getOperand(0).isUse()) {
|
2004-02-23 18:38:20 +00:00
|
|
|
::print(getOperand(0), OS, TM);
|
2002-10-30 01:55:38 +00:00
|
|
|
OS << " = ";
|
|
|
|
++StartOp; // Don't print this operand again!
|
|
|
|
}
|
2002-10-30 00:48:05 +00:00
|
|
|
OS << TM.getInstrInfo().getName(getOpcode());
|
2002-10-30 01:55:38 +00:00
|
|
|
|
|
|
|
for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
|
2003-05-27 00:05:23 +00:00
|
|
|
const MachineOperand& mop = getOperand(i);
|
2002-10-30 01:55:38 +00:00
|
|
|
if (i != StartOp)
|
|
|
|
OS << ",";
|
|
|
|
OS << " ";
|
2004-02-23 18:38:20 +00:00
|
|
|
::print(mop, OS, TM);
|
2002-10-30 01:55:38 +00:00
|
|
|
|
2003-12-14 13:24:17 +00:00
|
|
|
if (mop.isDef())
|
|
|
|
if (mop.isUse())
|
|
|
|
OS << "<def&use>";
|
|
|
|
else
|
|
|
|
OS << "<def>";
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
2002-10-30 01:55:38 +00:00
|
|
|
|
2003-09-17 21:34:23 +00:00
|
|
|
// code for printing implicit references
|
2002-10-30 00:48:05 +00:00
|
|
|
if (getNumImplicitRefs()) {
|
|
|
|
OS << "\tImplicitRefs: ";
|
|
|
|
for(unsigned i = 0, e = getNumImplicitRefs(); i != e; ++i) {
|
|
|
|
OS << "\t";
|
2003-05-27 00:05:23 +00:00
|
|
|
OutputValue(OS, getImplicitRef(i));
|
2003-12-14 13:24:17 +00:00
|
|
|
if (getImplicitOp(i).isDef())
|
|
|
|
if (getImplicitOp(i).isUse())
|
|
|
|
OS << "<def&use>";
|
|
|
|
else
|
|
|
|
OS << "<def>";
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2004-02-23 18:40:08 +00:00
|
|
|
namespace llvm {
|
2004-02-19 16:17:08 +00:00
|
|
|
std::ostream &operator<<(std::ostream &os, const MachineInstr &MI) {
|
|
|
|
// If the instruction is embedded into a basic block, we can find the target
|
|
|
|
// info for the instruction.
|
|
|
|
if (const MachineBasicBlock *MBB = MI.getParent()) {
|
|
|
|
const MachineFunction *MF = MBB->getParent();
|
|
|
|
MI.print(os, MF->getTarget());
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, print it out in the "raw" format without symbolic register names
|
|
|
|
// and such.
|
2004-02-12 16:09:53 +00:00
|
|
|
os << TargetInstrDescriptors[MI.getOpcode()].Name;
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2003-01-13 00:23:24 +00:00
|
|
|
for (unsigned i=0, N=MI.getNumOperands(); i < N; i++) {
|
|
|
|
os << "\t" << MI.getOperand(i);
|
2003-12-14 13:24:17 +00:00
|
|
|
if (MI.getOperand(i).isDef())
|
|
|
|
if (MI.getOperand(i).isUse())
|
|
|
|
os << "<d&u>";
|
|
|
|
else
|
|
|
|
os << "<d>";
|
2001-11-14 20:05:23 +00:00
|
|
|
}
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2003-09-17 21:34:23 +00:00
|
|
|
// code for printing implicit references
|
2003-01-13 00:23:24 +00:00
|
|
|
unsigned NumOfImpRefs = MI.getNumImplicitRefs();
|
|
|
|
if (NumOfImpRefs > 0) {
|
2002-04-25 04:31:18 +00:00
|
|
|
os << "\tImplicit: ";
|
2003-01-13 00:23:24 +00:00
|
|
|
for (unsigned z=0; z < NumOfImpRefs; z++) {
|
|
|
|
OutputValue(os, MI.getImplicitRef(z));
|
2003-12-14 13:24:17 +00:00
|
|
|
if (MI.getImplicitOp(z).isDef())
|
|
|
|
if (MI.getImplicitOp(z).isUse())
|
|
|
|
os << "<d&u>";
|
|
|
|
else
|
|
|
|
os << "<d>";
|
2001-11-15 20:46:40 +00:00
|
|
|
os << "\t";
|
2001-10-18 22:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-25 04:31:18 +00:00
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
return os << "\n";
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2004-02-13 04:39:32 +00:00
|
|
|
std::ostream &operator<<(std::ostream &OS, const MachineOperand &MO) {
|
2003-12-14 13:24:17 +00:00
|
|
|
if (MO.isHiBits32())
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << "%lm(";
|
2003-12-14 13:24:17 +00:00
|
|
|
else if (MO.isLoBits32())
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << "%lo(";
|
2003-12-14 13:24:17 +00:00
|
|
|
else if (MO.isHiBits64())
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << "%hh(";
|
2003-12-14 13:24:17 +00:00
|
|
|
else if (MO.isLoBits64())
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << "%hm(";
|
2002-07-10 21:45:04 +00:00
|
|
|
|
2002-12-15 20:35:25 +00:00
|
|
|
switch (MO.getType())
|
2001-09-18 12:56:28 +00:00
|
|
|
{
|
|
|
|
case MachineOperand::MO_VirtualRegister:
|
2003-01-13 00:23:24 +00:00
|
|
|
if (MO.hasAllocatedReg())
|
2004-02-13 21:01:20 +00:00
|
|
|
OutputReg(OS, MO.getReg());
|
2003-01-13 00:23:24 +00:00
|
|
|
|
|
|
|
if (MO.getVRegValue()) {
|
|
|
|
if (MO.hasAllocatedReg()) OS << "==";
|
|
|
|
OS << "%vreg";
|
|
|
|
OutputValue(OS, MO.getVRegValue());
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
2002-07-10 21:45:04 +00:00
|
|
|
break;
|
2001-09-18 12:56:28 +00:00
|
|
|
case MachineOperand::MO_CCRegister:
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << "%ccreg";
|
|
|
|
OutputValue(OS, MO.getVRegValue());
|
2002-12-15 20:35:25 +00:00
|
|
|
if (MO.hasAllocatedReg()) {
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << "==";
|
2004-02-13 21:01:20 +00:00
|
|
|
OutputReg(OS, MO.getReg());
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
2002-07-10 21:45:04 +00:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_MachineRegister:
|
2002-12-28 20:37:37 +00:00
|
|
|
OutputReg(OS, MO.getMachineRegNum());
|
2002-07-10 21:45:04 +00:00
|
|
|
break;
|
2001-09-18 12:56:28 +00:00
|
|
|
case MachineOperand::MO_SignExtendedImmed:
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << (long)MO.getImmedValue();
|
2002-07-10 21:45:04 +00:00
|
|
|
break;
|
2001-09-18 12:56:28 +00:00
|
|
|
case MachineOperand::MO_UnextendedImmed:
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << (long)MO.getImmedValue();
|
2002-07-10 21:45:04 +00:00
|
|
|
break;
|
2001-09-18 12:56:28 +00:00
|
|
|
case MachineOperand::MO_PCRelativeDisp:
|
2001-09-30 23:44:19 +00:00
|
|
|
{
|
2002-12-15 20:35:25 +00:00
|
|
|
const Value* opVal = MO.getVRegValue();
|
2002-04-08 22:01:15 +00:00
|
|
|
bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << "%disp(" << (isLabel? "label " : "addr-of-val ");
|
2001-11-12 14:19:47 +00:00
|
|
|
if (opVal->hasName())
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << opVal->getName();
|
2001-11-12 14:19:47 +00:00
|
|
|
else
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << (const void*) opVal;
|
|
|
|
OS << ")";
|
2002-07-10 21:45:04 +00:00
|
|
|
break;
|
2001-09-30 23:44:19 +00:00
|
|
|
}
|
2002-12-15 20:35:25 +00:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << "bb<"
|
2002-12-15 20:35:25 +00:00
|
|
|
<< ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
|
|
|
|
<< "," << (void*)MO.getMachineBasicBlock()->getBasicBlock() << ">";
|
|
|
|
break;
|
2002-12-28 20:37:37 +00:00
|
|
|
case MachineOperand::MO_FrameIndex:
|
|
|
|
OS << "<fi#" << MO.getFrameIndex() << ">";
|
|
|
|
break;
|
2003-01-13 00:23:24 +00:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
OS << "<cp#" << MO.getConstantPoolIndex() << ">";
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
OS << "<ga:" << ((Value*)MO.getGlobal())->getName() << ">";
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
OS << "<es:" << MO.getSymbolName() << ">";
|
|
|
|
break;
|
2001-09-18 12:56:28 +00:00
|
|
|
default:
|
|
|
|
assert(0 && "Unrecognized operand type");
|
|
|
|
break;
|
|
|
|
}
|
2001-09-09 22:26:29 +00:00
|
|
|
|
2004-02-23 18:38:20 +00:00
|
|
|
if (MO.isHiBits32() || MO.isLoBits32() || MO.isHiBits64() || MO.isLoBits64())
|
2002-12-28 20:37:37 +00:00
|
|
|
OS << ")";
|
2002-07-10 21:45:04 +00:00
|
|
|
|
2002-12-28 20:37:37 +00:00
|
|
|
return OS;
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2004-02-23 18:40:08 +00:00
|
|
|
}
|