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.
|
|
|
|
//
|
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-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"
|
2006-11-28 22:48:48 +00:00
|
|
|
#include "llvm/Support/Streams.h"
|
2006-12-15 22:57:14 +00:00
|
|
|
#include <ostream>
|
2004-02-23 18:38:20 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2006-11-27 23:37:22 +00:00
|
|
|
/// MachineInstr ctor - This constructor creates a dummy MachineInstr with
|
2006-11-30 07:08:44 +00:00
|
|
|
/// TID NULL and no operands.
|
2006-11-27 23:37:22 +00:00
|
|
|
MachineInstr::MachineInstr()
|
2006-11-30 07:08:44 +00:00
|
|
|
: TID(0), NumImplicitOps(0), 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:59:49 +00:00
|
|
|
}
|
|
|
|
|
2006-11-30 07:08:44 +00:00
|
|
|
void MachineInstr::addImplicitDefUseOperands() {
|
|
|
|
if (TID->ImplicitDefs)
|
|
|
|
for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs) {
|
2006-11-13 23:34:06 +00:00
|
|
|
MachineOperand Op;
|
|
|
|
Op.opType = MachineOperand::MO_Register;
|
|
|
|
Op.IsDef = true;
|
|
|
|
Op.IsImp = true;
|
|
|
|
Op.IsKill = false;
|
|
|
|
Op.IsDead = false;
|
|
|
|
Op.contents.RegNo = *ImpDefs;
|
2007-05-01 05:57:02 +00:00
|
|
|
Op.auxInfo.subReg = 0;
|
2006-11-13 23:34:06 +00:00
|
|
|
Operands.push_back(Op);
|
|
|
|
}
|
2006-11-30 07:08:44 +00:00
|
|
|
if (TID->ImplicitUses)
|
|
|
|
for (const unsigned *ImpUses = TID->ImplicitUses; *ImpUses; ++ImpUses) {
|
2006-11-13 23:34:06 +00:00
|
|
|
MachineOperand Op;
|
|
|
|
Op.opType = MachineOperand::MO_Register;
|
|
|
|
Op.IsDef = false;
|
|
|
|
Op.IsImp = true;
|
|
|
|
Op.IsKill = false;
|
|
|
|
Op.IsDead = false;
|
|
|
|
Op.contents.RegNo = *ImpUses;
|
2007-05-01 05:57:02 +00:00
|
|
|
Op.auxInfo.subReg = 0;
|
2006-11-13 23:34:06 +00:00
|
|
|
Operands.push_back(Op);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// MachineInstr ctor - This constructor create a MachineInstr and add the
|
2006-11-27 23:37:22 +00:00
|
|
|
/// implicit operands. It reserves space for number of operands specified by
|
|
|
|
/// TargetInstrDescriptor or the numOperands if it is not zero. (for
|
|
|
|
/// instructions with variable number of operands).
|
2006-11-30 07:08:44 +00:00
|
|
|
MachineInstr::MachineInstr(const TargetInstrDescriptor &tid)
|
|
|
|
: TID(&tid), NumImplicitOps(0), parent(0) {
|
|
|
|
if (TID->ImplicitDefs)
|
|
|
|
for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs)
|
2006-11-13 23:34:06 +00:00
|
|
|
NumImplicitOps++;
|
2006-11-30 07:08:44 +00:00
|
|
|
if (TID->ImplicitUses)
|
|
|
|
for (const unsigned *ImpUses = TID->ImplicitUses; *ImpUses; ++ImpUses)
|
2006-11-13 23:34:06 +00:00
|
|
|
NumImplicitOps++;
|
2006-11-30 07:08:44 +00:00
|
|
|
Operands.reserve(NumImplicitOps + TID->numOperands);
|
|
|
|
addImplicitDefUseOperands();
|
2006-11-13 23:34:06 +00:00
|
|
|
// Make sure that we get added to a machine basicblock
|
|
|
|
LeakDetector::addGarbageObject(this);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
///
|
2006-11-27 23:37:22 +00:00
|
|
|
MachineInstr::MachineInstr(MachineBasicBlock *MBB,
|
2006-11-30 07:08:44 +00:00
|
|
|
const TargetInstrDescriptor &tid)
|
|
|
|
: TID(&tid), NumImplicitOps(0), parent(0) {
|
2002-10-29 23:19:00 +00:00
|
|
|
assert(MBB && "Cannot use inserting ctor with null basic block!");
|
2006-11-30 07:08:44 +00:00
|
|
|
if (TID->ImplicitDefs)
|
|
|
|
for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs)
|
2006-11-13 23:34:06 +00:00
|
|
|
NumImplicitOps++;
|
2006-11-30 07:08:44 +00:00
|
|
|
if (TID->ImplicitUses)
|
|
|
|
for (const unsigned *ImpUses = TID->ImplicitUses; *ImpUses; ++ImpUses)
|
2006-11-13 23:34:06 +00:00
|
|
|
NumImplicitOps++;
|
2006-11-30 07:08:44 +00:00
|
|
|
Operands.reserve(NumImplicitOps + TID->numOperands);
|
|
|
|
addImplicitDefUseOperands();
|
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) {
|
2006-11-30 07:08:44 +00:00
|
|
|
TID = MI.getInstrDescriptor();
|
2006-11-15 20:54:29 +00:00
|
|
|
NumImplicitOps = MI.NumImplicitOps;
|
2006-05-04 19:14:44 +00:00
|
|
|
Operands.reserve(MI.getNumOperands());
|
2004-05-23 20:58:02 +00:00
|
|
|
|
2004-07-09 14:45:17 +00:00
|
|
|
// Add operands
|
2006-05-04 19:14:44 +00:00
|
|
|
for (unsigned i = 0; i != MI.getNumOperands(); ++i)
|
|
|
|
Operands.push_back(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);
|
|
|
|
}
|
|
|
|
|
2006-11-30 07:08:44 +00:00
|
|
|
/// getOpcode - Returns the opcode of this MachineInstr.
|
|
|
|
///
|
|
|
|
const int MachineInstr::getOpcode() const {
|
|
|
|
return TID->Opcode;
|
|
|
|
}
|
|
|
|
|
2006-04-17 21:35:41 +00:00
|
|
|
/// removeFromParent - This method unlinks 'this' from the containing basic
|
|
|
|
/// block, and returns it, but does not delete it.
|
|
|
|
MachineInstr *MachineInstr::removeFromParent() {
|
|
|
|
assert(getParent() && "Not embedded in a basic block!");
|
|
|
|
getParent()->remove(this);
|
|
|
|
return 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 {
|
2006-11-30 07:08:44 +00:00
|
|
|
unsigned short NumOperands = TID->numOperands;
|
|
|
|
if ((TID->Flags & M_VARIABLE_OPS) == 0 &&
|
2006-11-28 02:25:34 +00:00
|
|
|
getNumOperands()-NumImplicitOps >= 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
|
|
|
}
|
|
|
|
|
2007-05-15 01:26:09 +00:00
|
|
|
/// getNumExplicitOperands - Returns the number of non-implicit operands.
|
|
|
|
///
|
|
|
|
unsigned MachineInstr::getNumExplicitOperands() const {
|
|
|
|
unsigned NumOperands = TID->numOperands;
|
|
|
|
if ((TID->Flags & M_VARIABLE_OPS) == 0)
|
|
|
|
return NumOperands;
|
|
|
|
|
|
|
|
for (unsigned e = getNumOperands(); NumOperands != e; ++NumOperands) {
|
|
|
|
const MachineOperand &MO = getOperand(NumOperands);
|
|
|
|
if (!MO.isRegister() || !MO.isImplicit())
|
|
|
|
NumOperands++;
|
|
|
|
}
|
|
|
|
return NumOperands;
|
|
|
|
}
|
|
|
|
|
2006-10-20 22:39:59 +00:00
|
|
|
/// isIdenticalTo - Return true if this operand is identical to the specified
|
|
|
|
/// operand.
|
|
|
|
bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
|
|
|
|
if (getType() != Other.getType()) return false;
|
|
|
|
|
|
|
|
switch (getType()) {
|
|
|
|
default: assert(0 && "Unrecognized operand type");
|
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
return getReg() == Other.getReg() && isDef() == Other.isDef();
|
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
return getImm() == Other.getImm();
|
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
return getMBB() == Other.getMBB();
|
|
|
|
case MachineOperand::MO_FrameIndex:
|
|
|
|
return getFrameIndex() == Other.getFrameIndex();
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
return getConstantPoolIndex() == Other.getConstantPoolIndex() &&
|
|
|
|
getOffset() == Other.getOffset();
|
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
return getJumpTableIndex() == Other.getJumpTableIndex();
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
return getGlobal() == Other.getGlobal() && getOffset() == Other.getOffset();
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
2006-10-25 18:08:14 +00:00
|
|
|
return !strcmp(getSymbolName(), Other.getSymbolName()) &&
|
2006-10-20 22:39:59 +00:00
|
|
|
getOffset() == Other.getOffset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-16 20:56:08 +00:00
|
|
|
bool MachineInstr::isPredicable() const {
|
|
|
|
return TID->Flags & M_PREDICABLE;
|
|
|
|
}
|
|
|
|
|
2007-04-26 19:00:32 +00:00
|
|
|
/// findRegisterUseOperandIdx() - Returns the MachineOperand that is a use of
|
2007-03-26 22:37:45 +00:00
|
|
|
/// the specific register or -1 if it is not found. It further tightening
|
2007-02-23 01:04:26 +00:00
|
|
|
/// the search criteria to a use that kills the register if isKill is true.
|
2007-05-29 18:35:22 +00:00
|
|
|
int MachineInstr::findRegisterUseOperandIdx(unsigned Reg, bool isKill) const {
|
2006-12-06 08:27:42 +00:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
2007-05-29 18:35:22 +00:00
|
|
|
const MachineOperand &MO = getOperand(i);
|
2006-12-06 08:27:42 +00:00
|
|
|
if (MO.isReg() && MO.isUse() && MO.getReg() == Reg)
|
2007-02-23 01:04:26 +00:00
|
|
|
if (!isKill || MO.isKill())
|
2007-03-26 22:37:45 +00:00
|
|
|
return i;
|
2007-02-19 21:49:54 +00:00
|
|
|
}
|
2007-03-26 22:37:45 +00:00
|
|
|
return -1;
|
2007-02-19 21:49:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// findRegisterDefOperand() - Returns the MachineOperand that is a def of
|
|
|
|
/// the specific register or NULL if it is not found.
|
|
|
|
MachineOperand *MachineInstr::findRegisterDefOperand(unsigned Reg) {
|
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = getOperand(i);
|
|
|
|
if (MO.isReg() && MO.isDef() && MO.getReg() == Reg)
|
2006-12-06 08:27:42 +00:00
|
|
|
return &MO;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-05-15 01:26:09 +00:00
|
|
|
|
2007-05-29 18:35:22 +00:00
|
|
|
/// findFirstPredOperandIdx() - Find the index of the first operand in the
|
|
|
|
/// operand list that is used to represent the predicate. It returns -1 if
|
|
|
|
/// none is found.
|
|
|
|
int MachineInstr::findFirstPredOperandIdx() const {
|
2007-05-15 01:26:09 +00:00
|
|
|
const TargetInstrDescriptor *TID = getInstrDescriptor();
|
2007-05-16 20:56:08 +00:00
|
|
|
if (TID->Flags & M_PREDICABLE) {
|
2007-05-15 01:26:09 +00:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
|
|
|
if ((TID->OpInfo[i].Flags & M_PREDICATE_OPERAND))
|
2007-05-29 18:35:22 +00:00
|
|
|
return i;
|
2007-05-15 01:26:09 +00:00
|
|
|
}
|
|
|
|
|
2007-05-29 18:35:22 +00:00
|
|
|
return -1;
|
2007-05-15 01:26:09 +00:00
|
|
|
}
|
2006-12-06 08:27:42 +00:00
|
|
|
|
|
|
|
/// copyKillDeadInfo - Copies kill / dead operand properties from MI.
|
|
|
|
///
|
|
|
|
void MachineInstr::copyKillDeadInfo(const MachineInstr *MI) {
|
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(i);
|
|
|
|
if (!MO.isReg() || (!MO.isKill() && !MO.isDead()))
|
|
|
|
continue;
|
|
|
|
for (unsigned j = 0, ee = getNumOperands(); j != ee; ++j) {
|
|
|
|
MachineOperand &MOp = getOperand(j);
|
|
|
|
if (!MOp.isIdenticalTo(MO))
|
|
|
|
continue;
|
|
|
|
if (MO.isKill())
|
|
|
|
MOp.setIsKill();
|
|
|
|
else
|
|
|
|
MOp.setIsDead();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-15 01:26:09 +00:00
|
|
|
/// copyPredicates - Copies predicate operand(s) from MI.
|
|
|
|
void MachineInstr::copyPredicates(const MachineInstr *MI) {
|
|
|
|
const TargetInstrDescriptor *TID = MI->getInstrDescriptor();
|
2007-05-16 20:56:08 +00:00
|
|
|
if (TID->Flags & M_PREDICABLE) {
|
2007-05-15 01:26:09 +00:00
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
|
|
|
if ((TID->OpInfo[i].Flags & M_PREDICATE_OPERAND)) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(i);
|
|
|
|
// Predicated operands must be last operands.
|
|
|
|
if (MO.isReg())
|
|
|
|
addRegOperand(MO.getReg(), false);
|
|
|
|
else {
|
|
|
|
addImmOperand(MO.getImm());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-13 04:39:32 +00:00
|
|
|
void MachineInstr::dump() const {
|
2006-12-07 01:30:32 +00:00
|
|
|
cerr << " " << *this;
|
2001-07-21 12:41:50 +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
|
|
|
switch (MO.getType()) {
|
2006-05-04 18:05:43 +00:00
|
|
|
case MachineOperand::MO_Register:
|
2006-05-04 01:26:39 +00:00
|
|
|
OutputReg(OS, MO.getReg(), MRI);
|
2002-10-30 00:48:05 +00:00
|
|
|
break;
|
2006-05-04 17:21:20 +00:00
|
|
|
case MachineOperand::MO_Immediate:
|
2006-05-26 08:00:14 +00:00
|
|
|
OS << MO.getImmedValue();
|
2002-10-30 00:48:05 +00:00
|
|
|
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;
|
2006-04-22 18:53:45 +00:00
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
OS << "<jt#" << MO.getJumpTableIndex() << ">";
|
|
|
|
break;
|
2003-01-13 00:23:24 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2006-09-05 20:19:27 +00:00
|
|
|
if (getNumOperands() && getOperand(0).isReg() && getOperand(0).isDef()) {
|
2004-02-23 18:38:20 +00:00
|
|
|
::print(getOperand(0), OS, TM);
|
2007-02-16 09:49:18 +00:00
|
|
|
if (getOperand(0).isDead())
|
|
|
|
OS << "<dead>";
|
2002-10-30 01:55:38 +00:00
|
|
|
OS << " = ";
|
|
|
|
++StartOp; // Don't print this operand again!
|
|
|
|
}
|
2004-06-25 00:13:11 +00:00
|
|
|
|
2006-11-30 07:08:44 +00:00
|
|
|
if (TID)
|
|
|
|
OS << TID->Name;
|
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
|
|
|
|
2006-11-10 08:43:01 +00:00
|
|
|
if (mop.isReg()) {
|
2006-11-13 23:34:06 +00:00
|
|
|
if (mop.isDef() || mop.isKill() || mop.isDead() || mop.isImplicit()) {
|
|
|
|
OS << "<";
|
|
|
|
bool NeedComma = false;
|
|
|
|
if (mop.isImplicit()) {
|
|
|
|
OS << (mop.isDef() ? "imp-def" : "imp-use");
|
|
|
|
NeedComma = true;
|
|
|
|
} else if (mop.isDef()) {
|
|
|
|
OS << "def";
|
|
|
|
NeedComma = true;
|
|
|
|
}
|
|
|
|
if (mop.isKill() || mop.isDead()) {
|
|
|
|
if (NeedComma)
|
|
|
|
OS << ",";
|
|
|
|
if (mop.isKill())
|
|
|
|
OS << "kill";
|
|
|
|
if (mop.isDead())
|
|
|
|
OS << "dead";
|
|
|
|
}
|
|
|
|
OS << ">";
|
|
|
|
}
|
2006-11-10 08:43:01 +00:00
|
|
|
}
|
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";
|
|
|
|
}
|
|
|
|
|
2006-12-16 02:15:42 +00:00
|
|
|
void MachineInstr::print(std::ostream &os) const {
|
2004-02-19 16:17:08 +00:00
|
|
|
// If the instruction is embedded into a basic block, we can find the target
|
|
|
|
// info for the instruction.
|
2006-12-16 02:15:42 +00:00
|
|
|
if (const MachineBasicBlock *MBB = getParent()) {
|
2004-02-19 16:17:08 +00:00
|
|
|
const MachineFunction *MF = MBB->getParent();
|
2004-07-09 14:45:17 +00:00
|
|
|
if (MF)
|
2006-12-16 02:15:42 +00:00
|
|
|
print(os, &MF->getTarget());
|
2004-06-25 00:13:11 +00:00
|
|
|
else
|
2006-12-16 02:15:42 +00:00
|
|
|
print(os, 0);
|
2004-02-19 16:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, print it out in the "raw" format without symbolic register names
|
|
|
|
// and such.
|
2006-12-16 02:15:42 +00:00
|
|
|
os << getInstrDescriptor()->Name;
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2006-12-16 02:15:42 +00:00
|
|
|
for (unsigned i = 0, N = getNumOperands(); i < N; i++) {
|
|
|
|
os << "\t" << getOperand(i);
|
|
|
|
if (getOperand(i).isReg() && getOperand(i).isDef())
|
2006-09-05 20:19:27 +00:00
|
|
|
os << "<d>";
|
2001-11-14 20:05:23 +00:00
|
|
|
}
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2006-12-16 02:15:42 +00:00
|
|
|
os << "\n";
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2006-12-16 02:15:42 +00:00
|
|
|
void MachineOperand::print(std::ostream &OS) const {
|
|
|
|
switch (getType()) {
|
|
|
|
case MO_Register:
|
|
|
|
OutputReg(OS, getReg());
|
2004-07-09 14:45:17 +00:00
|
|
|
break;
|
2006-12-16 02:15:42 +00:00
|
|
|
case MO_Immediate:
|
|
|
|
OS << (long)getImmedValue();
|
2004-07-09 14:45:17 +00:00
|
|
|
break;
|
2006-12-16 02:15:42 +00:00
|
|
|
case MO_MachineBasicBlock:
|
2004-07-09 14:45:17 +00:00
|
|
|
OS << "<mbb:"
|
2006-12-16 02:15:42 +00:00
|
|
|
<< ((Value*)getMachineBasicBlock()->getBasicBlock())->getName()
|
|
|
|
<< "@" << (void*)getMachineBasicBlock() << ">";
|
2004-07-09 14:45:17 +00:00
|
|
|
break;
|
2006-12-16 02:15:42 +00:00
|
|
|
case MO_FrameIndex:
|
|
|
|
OS << "<fi#" << getFrameIndex() << ">";
|
2004-07-09 14:45:17 +00:00
|
|
|
break;
|
2006-12-16 02:15:42 +00:00
|
|
|
case MO_ConstantPoolIndex:
|
|
|
|
OS << "<cp#" << getConstantPoolIndex() << ">";
|
2004-07-09 14:45:17 +00:00
|
|
|
break;
|
2006-12-16 02:15:42 +00:00
|
|
|
case MO_JumpTableIndex:
|
|
|
|
OS << "<jt#" << getJumpTableIndex() << ">";
|
2006-04-22 18:53:45 +00:00
|
|
|
break;
|
2006-12-16 02:15:42 +00:00
|
|
|
case MO_GlobalAddress:
|
|
|
|
OS << "<ga:" << ((Value*)getGlobal())->getName() << ">";
|
2004-07-09 14:45:17 +00:00
|
|
|
break;
|
2006-12-16 02:15:42 +00:00
|
|
|
case MO_ExternalSymbol:
|
|
|
|
OS << "<es:" << getSymbolName() << ">";
|
2004-07-09 14:45:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Unrecognized operand type");
|
|
|
|
break;
|
|
|
|
}
|
2006-12-15 22:57:14 +00:00
|
|
|
}
|
|
|
|
|