2002-08-09 20:08:06 +00:00
|
|
|
//===-- MachineInstr.cpp --------------------------------------------------===//
|
2005-04-21 22:36:52 +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.
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
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-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/LeakDetector.h"
|
2004-07-04 12:19:56 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
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.
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
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-07-09 14:45:17 +00:00
|
|
|
/// MachineInstr ctor - Copies MachineInstr arg exactly
|
|
|
|
///
|
2004-05-23 19:35:12 +00:00
|
|
|
MachineInstr::MachineInstr(const MachineInstr &MI) {
|
|
|
|
Opcode = MI.getOpcode();
|
|
|
|
numImplicitRefs = MI.getNumImplicitRefs();
|
2004-05-23 20:58:02 +00:00
|
|
|
operands.reserve(MI.getNumOperands());
|
|
|
|
|
2004-07-09 14:45:17 +00:00
|
|
|
// Add operands
|
|
|
|
for (unsigned i = 0; i < MI.getNumOperands(); ++i)
|
2004-05-23 19:35:12 +00:00
|
|
|
operands.push_back(MachineOperand(MI.getOperand(i)));
|
2004-05-24 03:14:18 +00:00
|
|
|
|
2004-07-09 14:45:17 +00:00
|
|
|
// Set parent, next, and prev to null
|
2004-05-24 03:14:18 +00:00
|
|
|
parent = 0;
|
|
|
|
prev = 0;
|
|
|
|
next = 0;
|
2004-05-23 19:35:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-09 14:45:17 +00:00
|
|
|
MachineInstr::~MachineInstr() {
|
2004-02-16 07:17:43 +00:00
|
|
|
LeakDetector::removeGarbageObject(this);
|
|
|
|
}
|
|
|
|
|
2004-07-09 14:45:17 +00:00
|
|
|
/// clone - Create a copy of 'this' instruction that is identical in all ways
|
|
|
|
/// except the following: the new instruction has no parent and it has no name
|
|
|
|
///
|
2004-05-24 03:14:18 +00:00
|
|
|
MachineInstr* MachineInstr::clone() const {
|
2004-05-23 20:58:02 +00:00
|
|
|
return new MachineInstr(*this);
|
2004-05-23 19:35:12 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2005-04-21 22:36:52 +00:00
|
|
|
///
|
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;
|
2004-10-15 04:38:41 +00:00
|
|
|
operands[i].extra.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;
|
2004-10-15 04:38:41 +00:00
|
|
|
operands[i].extra.regNum = -1;
|
2002-10-28 04:24:49 +00:00
|
|
|
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;
|
2004-10-15 04:38:41 +00:00
|
|
|
operands[i].extra.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.");
|
2005-04-21 22:36:52 +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())
|
2004-07-09 14:45:17 +00:00
|
|
|
{
|
|
|
|
O.getMachineOperand().contents.value = newVal;
|
|
|
|
++numSubst;
|
|
|
|
} else
|
2003-07-10 19:45:07 +00:00
|
|
|
someArgsWereIgnored = true;
|
2002-08-14 16:52:58 +00:00
|
|
|
|
2003-09-17 21:34:23 +00:00
|
|
|
// Substitute implicit refs
|
2004-07-09 14:45:17 +00:00
|
|
|
for (unsigned i = 0, N = getNumImplicitRefs(); i < N; ++i)
|
|
|
|
if (getImplicitRef(i) == oldVal) {
|
|
|
|
MachineOperand Op = getImplicitOp(i);
|
2003-07-10 19:45:07 +00:00
|
|
|
if (!defsOnly ||
|
2004-07-09 14:45:17 +00:00
|
|
|
notDefsAndUses && (Op.isDef() && !Op.isUse()) ||
|
|
|
|
!notDefsAndUses && Op.isDef())
|
|
|
|
{
|
|
|
|
Op.contents.value = newVal;
|
|
|
|
++numSubst;
|
|
|
|
} else
|
2003-07-10 19:45:07 +00:00
|
|
|
someArgsWereIgnored = true;
|
2004-07-09 14:45:17 +00:00
|
|
|
}
|
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 ";
|
2004-07-09 14:45:17 +00:00
|
|
|
os << (void*) val; // print address always
|
2002-04-25 04:31:18 +00:00
|
|
|
if (val && val->hasName())
|
2004-07-09 14:45:17 +00:00
|
|
|
os << " " << val->getName(); // print name also, if available
|
2004-02-13 04:39:32 +00:00
|
|
|
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,
|
2004-06-25 00:13:11 +00:00
|
|
|
const TargetMachine *TM) {
|
2004-07-09 14:45:17 +00:00
|
|
|
const MRegisterInfo *MRI = 0;
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2004-07-09 14:45:17 +00:00
|
|
|
if (TM) MRI = TM->getRegisterInfo();
|
2004-06-25 00:13:11 +00:00
|
|
|
|
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;
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2002-10-30 00:48:05 +00:00
|
|
|
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:
|
2004-06-17 22:26:53 +00:00
|
|
|
OS << "mbb<"
|
2002-12-15 20:35:25 +00:00
|
|
|
<< ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
|
2004-06-17 22:26:53 +00:00
|
|
|
<< "," << (void*)MO.getMachineBasicBlock() << ">";
|
2002-12-15 20:35:25 +00:00
|
|
|
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:
|
2004-10-15 04:38:41 +00:00
|
|
|
OS << "<ga:" << ((Value*)MO.getGlobal())->getName();
|
|
|
|
if (MO.getOffset()) OS << "+" << MO.getOffset();
|
|
|
|
OS << ">";
|
2003-01-13 00:23:24 +00:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
2004-10-15 04:38:41 +00:00
|
|
|
OS << "<es:" << MO.getSymbolName();
|
|
|
|
if (MO.getOffset()) OS << "+" << MO.getOffset();
|
|
|
|
OS << ">";
|
2003-01-13 00:23:24 +00:00
|
|
|
break;
|
2002-10-30 00:48:05 +00:00
|
|
|
default:
|
|
|
|
assert(0 && "Unrecognized operand type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CloseParen)
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2004-06-25 00:13:11 +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!
|
|
|
|
}
|
2004-06-25 00:13:11 +00:00
|
|
|
|
2004-07-09 14:45:17 +00:00
|
|
|
// Must check if Target machine is not null because machine BB could not
|
|
|
|
// be attached to a Machine function yet
|
|
|
|
if (TM)
|
2004-06-25 00:13:11 +00:00
|
|
|
OS << TM->getInstrInfo()->getName(getOpcode());
|
2005-04-21 22:36:52 +00:00
|
|
|
|
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);
|
2005-04-21 22:36:52 +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
|
|
|
}
|
2005-04-21 22:36:52 +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: ";
|
2004-07-09 14:45:17 +00:00
|
|
|
for (unsigned i = 0, e = getNumImplicitRefs(); i != e; ++i) {
|
2002-10-30 00:48:05 +00:00
|
|
|
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())
|
2004-07-09 14:45:17 +00:00
|
|
|
if (getImplicitOp(i).isUse())
|
|
|
|
OS << "<def&use>";
|
|
|
|
else
|
|
|
|
OS << "<def>";
|
2002-10-30 00:48:05 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-21 22:36:52 +00:00
|
|
|
|
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();
|
2004-07-09 14:45:17 +00:00
|
|
|
if (MF)
|
2004-06-25 00:13:11 +00:00
|
|
|
MI.print(os, &MF->getTarget());
|
|
|
|
else
|
|
|
|
MI.print(os, 0);
|
2004-02-19 16:17:08 +00:00
|
|
|
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;
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2004-07-09 14:45:17 +00:00
|
|
|
for (unsigned i = 0, N = MI.getNumOperands(); i < N; i++) {
|
2003-01-13 00:23:24 +00:00
|
|
|
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
|
|
|
}
|
2005-04-21 22:36:52 +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: ";
|
2004-07-09 14:45:17 +00:00
|
|
|
for (unsigned z = 0; z < NumOfImpRefs; z++) {
|
2005-04-21 22:36:52 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2005-04-21 22:36:52 +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(";
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2004-07-09 14:45:17 +00:00
|
|
|
switch (MO.getType()) {
|
|
|
|
case MachineOperand::MO_VirtualRegister:
|
|
|
|
if (MO.hasAllocatedReg())
|
|
|
|
OutputReg(OS, MO.getReg());
|
|
|
|
|
|
|
|
if (MO.getVRegValue()) {
|
|
|
|
if (MO.hasAllocatedReg()) OS << "==";
|
|
|
|
OS << "%vreg";
|
2002-12-28 20:37:37 +00:00
|
|
|
OutputValue(OS, MO.getVRegValue());
|
2001-09-18 12:56:28 +00:00
|
|
|
}
|
2004-07-09 14:45:17 +00:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_CCRegister:
|
|
|
|
OS << "%ccreg";
|
|
|
|
OutputValue(OS, MO.getVRegValue());
|
|
|
|
if (MO.hasAllocatedReg()) {
|
|
|
|
OS << "==";
|
|
|
|
OutputReg(OS, MO.getReg());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_MachineRegister:
|
|
|
|
OutputReg(OS, MO.getMachineRegNum());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
OS << "<mbb:"
|
|
|
|
<< ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
|
|
|
|
<< "@" << (void*)MO.getMachineBasicBlock() << ">";
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_FrameIndex:
|
|
|
|
OS << "<fi#" << MO.getFrameIndex() << ">";
|
|
|
|
break;
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
assert(0 && "Unrecognized operand type");
|
|
|
|
break;
|
|
|
|
}
|
2005-04-21 22:36:52 +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 << ")";
|
2005-04-21 22:36:52 +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
|
|
|
}
|