2002-08-09 22:08:06 +02:00
|
|
|
//===-- MachineInstr.cpp --------------------------------------------------===//
|
2001-07-21 14:41:50 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02: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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2002-08-09 22:08:06 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-21 14:41:50 +02:00
|
|
|
|
2001-09-07 19:18:30 +02:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2002-10-30 00:19:00 +01:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2002-02-03 08:46:01 +01:00
|
|
|
#include "llvm/Value.h"
|
2002-10-30 01:48:05 +01:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2003-01-14 23:00:31 +01:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2002-10-30 01:58:19 +01:00
|
|
|
#include "llvm/Target/MRegisterInfo.h"
|
2003-01-13 01:23:24 +01:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2002-10-29 18:40:30 +01: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 23:00:31 +01:00
|
|
|
// This variable is initialized and reset by class TargetInstrInfo.
|
2002-10-29 18:40:30 +01:00
|
|
|
//
|
|
|
|
// FIXME: This should be a property of the target so that more than one target
|
|
|
|
// at a time can be active...
|
|
|
|
//
|
2003-01-14 23:00:31 +01:00
|
|
|
extern const TargetInstrDescriptor *TargetInstrDescriptors;
|
2001-10-19 00:40:02 +02:00
|
|
|
|
2001-07-31 23:49:28 +02:00
|
|
|
// Constructor for instructions with variable #operands
|
2002-10-28 22:02:40 +01:00
|
|
|
MachineInstr::MachineInstr(MachineOpCode OpCode, unsigned numOperands)
|
2002-10-29 20:41:18 +01:00
|
|
|
: opCode(OpCode),
|
2003-05-31 09:39:06 +02:00
|
|
|
opCodeFlags(0),
|
2002-10-29 20:41:18 +01:00
|
|
|
operands(numOperands, MachineOperand()),
|
|
|
|
numImplicitRefs(0)
|
|
|
|
{
|
2002-10-28 21:48:39 +01:00
|
|
|
}
|
|
|
|
|
2002-10-30 00:19:00 +01: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.
|
|
|
|
///
|
2002-10-28 21:59:49 +01:00
|
|
|
MachineInstr::MachineInstr(MachineOpCode Opcode, unsigned numOperands,
|
2002-10-29 20:41:18 +01:00
|
|
|
bool XX, bool YY)
|
|
|
|
: opCode(Opcode),
|
2003-05-31 09:39:06 +02:00
|
|
|
opCodeFlags(0),
|
2002-10-29 20:41:18 +01:00
|
|
|
numImplicitRefs(0)
|
|
|
|
{
|
2002-10-28 21:59:49 +01:00
|
|
|
operands.reserve(numOperands);
|
|
|
|
}
|
|
|
|
|
2002-10-30 00:19:00 +01: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.
|
|
|
|
///
|
|
|
|
MachineInstr::MachineInstr(MachineBasicBlock *MBB, MachineOpCode Opcode,
|
|
|
|
unsigned numOperands)
|
|
|
|
: opCode(Opcode),
|
2003-05-31 09:39:06 +02:00
|
|
|
opCodeFlags(0),
|
2002-10-30 00:19:00 +01:00
|
|
|
numImplicitRefs(0)
|
|
|
|
{
|
|
|
|
assert(MBB && "Cannot use inserting ctor with null basic block!");
|
|
|
|
operands.reserve(numOperands);
|
|
|
|
MBB->push_back(this); // Add instruction to end of basic block!
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-28 21:48:39 +01:00
|
|
|
// OperandComplete - Return true if it's illegal to add a new operand
|
2002-10-29 20:41:18 +01:00
|
|
|
bool MachineInstr::OperandsComplete() const
|
|
|
|
{
|
2002-10-28 21:48:39 +01:00
|
|
|
int NumOperands = TargetInstrDescriptors[opCode].numOperands;
|
2002-10-29 20:41:18 +01:00
|
|
|
if (NumOperands >= 0 && getNumOperands() >= (unsigned)NumOperands)
|
2003-05-31 09:39:06 +02:00
|
|
|
return true; // Broken: we have all the operands of this instruction!
|
2002-10-28 21:48:39 +01:00
|
|
|
return false;
|
2001-07-21 14:41:50 +02:00
|
|
|
}
|
|
|
|
|
2002-10-28 21:48:39 +01:00
|
|
|
|
2002-09-20 02:47:49 +02:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
2002-10-29 20:41:18 +01:00
|
|
|
void MachineInstr::replace(MachineOpCode Opcode, unsigned numOperands)
|
|
|
|
{
|
|
|
|
assert(getNumImplicitRefs() == 0 &&
|
|
|
|
"This is probably broken because implicit refs are going to be lost.");
|
2002-10-28 21:48:39 +01:00
|
|
|
opCode = Opcode;
|
2002-09-20 02:47:49 +02:00
|
|
|
operands.clear();
|
2002-10-28 21:48:39 +01:00
|
|
|
operands.resize(numOperands, MachineOperand());
|
2002-09-20 02:47:49 +02:00
|
|
|
}
|
|
|
|
|
2003-08-05 18:58:46 +02:00
|
|
|
void MachineInstr::SetMachineOperandVal(unsigned i,
|
|
|
|
MachineOperand::MachineOperandType opTy,
|
|
|
|
Value* V) {
|
2002-10-29 20:41:18 +01:00
|
|
|
assert(i < operands.size()); // may be explicit or implicit op
|
2003-08-05 18:58:46 +02:00
|
|
|
operands[i].opType = opTy;
|
2002-10-28 05:24:49 +01:00
|
|
|
operands[i].value = V;
|
|
|
|
operands[i].regNum = -1;
|
2001-07-21 14:41:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-28 05:24:49 +01:00
|
|
|
MachineInstr::SetMachineOperandConst(unsigned i,
|
2001-07-21 14:41:50 +02:00
|
|
|
MachineOperand::MachineOperandType operandType,
|
2002-03-18 04:35:24 +01:00
|
|
|
int64_t intValue)
|
2001-07-21 14:41:50 +02:00
|
|
|
{
|
2002-10-29 20:41:18 +01:00
|
|
|
assert(i < getNumOperands()); // must be explicit op
|
2002-03-18 04:35:24 +01:00
|
|
|
assert(TargetInstrDescriptors[opCode].resultPos != (int) i &&
|
|
|
|
"immed. constant cannot be defined");
|
2002-10-28 05:24:49 +01:00
|
|
|
|
|
|
|
operands[i].opType = operandType;
|
|
|
|
operands[i].value = NULL;
|
|
|
|
operands[i].immedVal = intValue;
|
|
|
|
operands[i].regNum = -1;
|
|
|
|
operands[i].flags = 0;
|
2001-07-21 14:41:50 +02:00
|
|
|
}
|
|
|
|
|
2003-08-05 18:58:46 +02:00
|
|
|
void MachineInstr::SetMachineOperandReg(unsigned i, int regNum) {
|
2002-10-29 20:41:18 +01:00
|
|
|
assert(i < getNumOperands()); // must be explicit op
|
2002-10-28 05:24:49 +01:00
|
|
|
|
2002-10-28 20:46:59 +01:00
|
|
|
operands[i].opType = MachineOperand::MO_MachineRegister;
|
2002-10-28 05:24:49 +01:00
|
|
|
operands[i].value = NULL;
|
|
|
|
operands[i].regNum = regNum;
|
2001-07-21 14:41:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-09 00:38:45 +02:00
|
|
|
MachineInstr::SetRegForOperand(unsigned i, int regNum)
|
2001-07-21 14:41:50 +02:00
|
|
|
{
|
2002-10-29 20:41:18 +01:00
|
|
|
assert(i < getNumOperands()); // must be explicit op
|
2002-07-09 00:38:45 +02:00
|
|
|
operands[i].setRegForValue(regNum);
|
|
|
|
}
|
|
|
|
|
2003-05-31 09:39:06 +02:00
|
|
|
void
|
|
|
|
MachineInstr::SetRegForImplicitRef(unsigned i, int regNum)
|
|
|
|
{
|
|
|
|
getImplicitOp(i).setRegForValue(regNum);
|
|
|
|
}
|
|
|
|
|
2002-07-09 00:38:45 +02:00
|
|
|
|
2003-09-17 23:34:23 +02:00
|
|
|
// Substitute all occurrences of Value* oldVal with newVal in all operands
|
2003-07-10 21:45:07 +02:00
|
|
|
// and all implicit refs.
|
|
|
|
// If defsOnly == true, substitute defs only.
|
2002-08-14 18:52:58 +02:00
|
|
|
unsigned
|
2003-07-10 21:45:07 +02:00
|
|
|
MachineInstr::substituteValue(const Value* oldVal, Value* newVal,
|
|
|
|
bool defsOnly, bool notDefsAndUses,
|
|
|
|
bool& someArgsWereIgnored)
|
2002-08-14 18:52:58 +02:00
|
|
|
{
|
2003-08-07 17:01:48 +02:00
|
|
|
assert((!defsOnly || !notDefsAndUses) &&
|
|
|
|
"notDefsAndUses is irrelevant if defsOnly == true.");
|
2003-07-10 21:45:07 +02:00
|
|
|
|
2002-08-14 18:52:58 +02:00
|
|
|
unsigned numSubst = 0;
|
|
|
|
|
2003-09-17 23:34:23 +02:00
|
|
|
// Substitute operands
|
2002-08-14 18:52:58 +02:00
|
|
|
for (MachineInstr::val_op_iterator O = begin(), E = end(); O != E; ++O)
|
|
|
|
if (*O == oldVal)
|
2003-07-10 21:45:07 +02:00
|
|
|
if (!defsOnly ||
|
2003-12-14 14:24:17 +01:00
|
|
|
notDefsAndUses && (O.isDef() && !O.isUse()) ||
|
|
|
|
!notDefsAndUses && O.isDef())
|
2002-08-14 18:52:58 +02:00
|
|
|
{
|
|
|
|
O.getMachineOperand().value = newVal;
|
|
|
|
++numSubst;
|
|
|
|
}
|
2003-07-10 21:45:07 +02:00
|
|
|
else
|
|
|
|
someArgsWereIgnored = true;
|
2002-08-14 18:52:58 +02:00
|
|
|
|
2003-09-17 23:34:23 +02:00
|
|
|
// Substitute implicit refs
|
2002-10-29 20:41:18 +01:00
|
|
|
for (unsigned i=0, N=getNumImplicitRefs(); i < N; ++i)
|
2002-10-23 01:16:21 +02:00
|
|
|
if (getImplicitRef(i) == oldVal)
|
2003-07-10 21:45:07 +02:00
|
|
|
if (!defsOnly ||
|
2003-12-14 14:24:17 +01:00
|
|
|
notDefsAndUses && (getImplicitOp(i).isDef() && !getImplicitOp(i).isUse()) ||
|
|
|
|
!notDefsAndUses && getImplicitOp(i).isDef())
|
2002-08-14 18:52:58 +02:00
|
|
|
{
|
2002-10-29 20:41:18 +01:00
|
|
|
getImplicitOp(i).value = newVal;
|
2002-08-14 18:52:58 +02:00
|
|
|
++numSubst;
|
|
|
|
}
|
2003-07-10 21:45:07 +02:00
|
|
|
else
|
|
|
|
someArgsWereIgnored = true;
|
2002-08-14 18:52:58 +02:00
|
|
|
|
|
|
|
return numSubst;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-09 00:38:45 +02:00
|
|
|
void
|
|
|
|
MachineInstr::dump() const
|
|
|
|
{
|
2003-08-03 22:24:29 +02:00
|
|
|
std::cerr << " " << *this;
|
2001-07-21 14:41:50 +02:00
|
|
|
}
|
|
|
|
|
2002-09-16 17:18:53 +02:00
|
|
|
static inline std::ostream&
|
|
|
|
OutputValue(std::ostream &os, const Value* val)
|
2002-04-25 06:31:18 +02:00
|
|
|
{
|
|
|
|
os << "(val ";
|
2003-07-10 21:45:07 +02:00
|
|
|
os << (void*) val; // print address always
|
2002-04-25 06:31:18 +02:00
|
|
|
if (val && val->hasName())
|
2003-07-10 21:45:07 +02:00
|
|
|
os << " " << val->getName() << ")"; // print name also, if available
|
|
|
|
return os;
|
2002-04-25 06:31:18 +02:00
|
|
|
}
|
|
|
|
|
2002-10-30 01:58:19 +01:00
|
|
|
static inline void OutputReg(std::ostream &os, unsigned RegNo,
|
|
|
|
const MRegisterInfo *MRI = 0) {
|
|
|
|
if (MRI) {
|
|
|
|
if (RegNo < MRegisterInfo::FirstVirtualRegister)
|
|
|
|
os << "%" << MRI->get(RegNo).Name;
|
|
|
|
else
|
|
|
|
os << "%reg" << RegNo;
|
|
|
|
} else
|
|
|
|
os << "%mreg(" << RegNo << ")";
|
2002-09-16 17:18:53 +02:00
|
|
|
}
|
|
|
|
|
2002-10-30 01:48:05 +01:00
|
|
|
static void print(const MachineOperand &MO, std::ostream &OS,
|
|
|
|
const TargetMachine &TM) {
|
2002-10-30 01:58:19 +01:00
|
|
|
const MRegisterInfo *MRI = TM.getRegisterInfo();
|
2002-10-30 01:48:05 +01:00
|
|
|
bool CloseParen = true;
|
2003-12-14 14:24:17 +01:00
|
|
|
if (MO.isHiBits32())
|
2002-10-30 01:48:05 +01:00
|
|
|
OS << "%lm(";
|
2003-12-14 14:24:17 +01:00
|
|
|
else if (MO.isLoBits32())
|
2002-10-30 01:48:05 +01:00
|
|
|
OS << "%lo(";
|
2003-12-14 14:24:17 +01:00
|
|
|
else if (MO.isHiBits64())
|
2002-10-30 01:48:05 +01:00
|
|
|
OS << "%hh(";
|
2003-12-14 14:24:17 +01:00
|
|
|
else if (MO.isLoBits64())
|
2002-10-30 01:48:05 +01: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())
|
2002-10-30 01:58:19 +01:00
|
|
|
OutputReg(OS, MO.getAllocatedRegNum(), MRI);
|
2002-10-30 01:48:05 +01:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_CCRegister:
|
|
|
|
OS << "%ccreg";
|
|
|
|
OutputValue(OS, MO.getVRegValue());
|
|
|
|
if (MO.hasAllocatedReg()) {
|
|
|
|
OS << "==";
|
2002-10-30 01:58:19 +01:00
|
|
|
OutputReg(OS, MO.getAllocatedRegNum(), MRI);
|
2002-10-30 01:48:05 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_MachineRegister:
|
2002-10-30 01:58:19 +01:00
|
|
|
OutputReg(OS, MO.getMachineRegNum(), MRI);
|
2002-10-30 01:48:05 +01: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 21:35:25 +01:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
OS << "bb<"
|
|
|
|
<< ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
|
|
|
|
<< "," << (void*)MO.getMachineBasicBlock()->getBasicBlock() << ">";
|
|
|
|
break;
|
2002-12-28 21:37:37 +01:00
|
|
|
case MachineOperand::MO_FrameIndex:
|
|
|
|
OS << "<fi#" << MO.getFrameIndex() << ">";
|
|
|
|
break;
|
2003-01-13 01:23:24 +01: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 01:48:05 +01:00
|
|
|
default:
|
|
|
|
assert(0 && "Unrecognized operand type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CloseParen)
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
|
2002-11-18 00:22:13 +01:00
|
|
|
void MachineInstr::print(std::ostream &OS, const TargetMachine &TM) const {
|
2002-10-30 02:55:38 +01:00
|
|
|
unsigned StartOp = 0;
|
|
|
|
|
|
|
|
// Specialize printing if op#0 is definition
|
2003-12-14 14:24:17 +01:00
|
|
|
if (getNumOperands() && getOperand(0).isDef() && !getOperand(0).isUse()) {
|
2003-11-11 23:41:34 +01:00
|
|
|
llvm::print(getOperand(0), OS, TM);
|
2002-10-30 02:55:38 +01:00
|
|
|
OS << " = ";
|
|
|
|
++StartOp; // Don't print this operand again!
|
|
|
|
}
|
2002-10-30 01:48:05 +01:00
|
|
|
OS << TM.getInstrInfo().getName(getOpcode());
|
2002-10-30 02:55:38 +01:00
|
|
|
|
|
|
|
for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
|
2003-05-27 02:05:23 +02:00
|
|
|
const MachineOperand& mop = getOperand(i);
|
2002-10-30 02:55:38 +01:00
|
|
|
if (i != StartOp)
|
|
|
|
OS << ",";
|
|
|
|
OS << " ";
|
2003-11-11 23:41:34 +01:00
|
|
|
llvm::print(mop, OS, TM);
|
2002-10-30 02:55:38 +01:00
|
|
|
|
2003-12-14 14:24:17 +01:00
|
|
|
if (mop.isDef())
|
|
|
|
if (mop.isUse())
|
|
|
|
OS << "<def&use>";
|
|
|
|
else
|
|
|
|
OS << "<def>";
|
2002-10-30 01:48:05 +01:00
|
|
|
}
|
2002-10-30 02:55:38 +01:00
|
|
|
|
2003-09-17 23:34:23 +02:00
|
|
|
// code for printing implicit references
|
2002-10-30 01:48:05 +01:00
|
|
|
if (getNumImplicitRefs()) {
|
|
|
|
OS << "\tImplicitRefs: ";
|
|
|
|
for(unsigned i = 0, e = getNumImplicitRefs(); i != e; ++i) {
|
|
|
|
OS << "\t";
|
2003-05-27 02:05:23 +02:00
|
|
|
OutputValue(OS, getImplicitRef(i));
|
2003-12-14 14:24:17 +01:00
|
|
|
if (getImplicitOp(i).isDef())
|
|
|
|
if (getImplicitOp(i).isUse())
|
|
|
|
OS << "<def&use>";
|
|
|
|
else
|
|
|
|
OS << "<def>";
|
2002-10-30 01:48:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-13 01:23:24 +01:00
|
|
|
std::ostream &operator<<(std::ostream& os, const MachineInstr& MI)
|
2001-07-21 14:41:50 +02:00
|
|
|
{
|
2003-01-13 01:23:24 +01:00
|
|
|
os << TargetInstrDescriptors[MI.opCode].Name;
|
2001-07-21 14:41:50 +02:00
|
|
|
|
2003-01-13 01:23:24 +01:00
|
|
|
for (unsigned i=0, N=MI.getNumOperands(); i < N; i++) {
|
|
|
|
os << "\t" << MI.getOperand(i);
|
2003-12-14 14:24:17 +01:00
|
|
|
if (MI.getOperand(i).isDef())
|
|
|
|
if (MI.getOperand(i).isUse())
|
|
|
|
os << "<d&u>";
|
|
|
|
else
|
|
|
|
os << "<d>";
|
2001-11-14 21:05:23 +01:00
|
|
|
}
|
2001-07-21 14:41:50 +02:00
|
|
|
|
2003-09-17 23:34:23 +02:00
|
|
|
// code for printing implicit references
|
2003-01-13 01:23:24 +01:00
|
|
|
unsigned NumOfImpRefs = MI.getNumImplicitRefs();
|
|
|
|
if (NumOfImpRefs > 0) {
|
2002-04-25 06:31:18 +02:00
|
|
|
os << "\tImplicit: ";
|
2003-01-13 01:23:24 +01:00
|
|
|
for (unsigned z=0; z < NumOfImpRefs; z++) {
|
|
|
|
OutputValue(os, MI.getImplicitRef(z));
|
2003-12-14 14:24:17 +01:00
|
|
|
if (MI.getImplicitOp(z).isDef())
|
|
|
|
if (MI.getImplicitOp(z).isUse())
|
|
|
|
os << "<d&u>";
|
|
|
|
else
|
|
|
|
os << "<d>";
|
2001-11-15 21:46:40 +01:00
|
|
|
os << "\t";
|
2001-10-19 00:40:02 +02:00
|
|
|
}
|
|
|
|
}
|
2002-04-25 06:31:18 +02:00
|
|
|
|
2002-01-20 23:54:45 +01:00
|
|
|
return os << "\n";
|
2001-07-21 14:41:50 +02:00
|
|
|
}
|
|
|
|
|
2002-12-28 21:37:37 +01:00
|
|
|
std::ostream &operator<<(std::ostream &OS, const MachineOperand &MO)
|
2001-09-18 14:56:28 +02:00
|
|
|
{
|
2003-12-14 14:24:17 +01:00
|
|
|
if (MO.isHiBits32())
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << "%lm(";
|
2003-12-14 14:24:17 +01:00
|
|
|
else if (MO.isLoBits32())
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << "%lo(";
|
2003-12-14 14:24:17 +01:00
|
|
|
else if (MO.isHiBits64())
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << "%hh(";
|
2003-12-14 14:24:17 +01:00
|
|
|
else if (MO.isLoBits64())
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << "%hm(";
|
2002-07-10 23:45:04 +02:00
|
|
|
|
2002-12-15 21:35:25 +01:00
|
|
|
switch (MO.getType())
|
2001-09-18 14:56:28 +02:00
|
|
|
{
|
|
|
|
case MachineOperand::MO_VirtualRegister:
|
2003-01-13 01:23:24 +01:00
|
|
|
if (MO.hasAllocatedReg())
|
2002-12-28 21:37:37 +01:00
|
|
|
OutputReg(OS, MO.getAllocatedRegNum());
|
2003-01-13 01:23:24 +01:00
|
|
|
|
|
|
|
if (MO.getVRegValue()) {
|
|
|
|
if (MO.hasAllocatedReg()) OS << "==";
|
|
|
|
OS << "%vreg";
|
|
|
|
OutputValue(OS, MO.getVRegValue());
|
2002-10-30 01:48:05 +01:00
|
|
|
}
|
2002-07-10 23:45:04 +02:00
|
|
|
break;
|
2001-09-18 14:56:28 +02:00
|
|
|
case MachineOperand::MO_CCRegister:
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << "%ccreg";
|
|
|
|
OutputValue(OS, MO.getVRegValue());
|
2002-12-15 21:35:25 +01:00
|
|
|
if (MO.hasAllocatedReg()) {
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << "==";
|
|
|
|
OutputReg(OS, MO.getAllocatedRegNum());
|
2002-10-30 01:48:05 +01:00
|
|
|
}
|
2002-07-10 23:45:04 +02:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_MachineRegister:
|
2002-12-28 21:37:37 +01:00
|
|
|
OutputReg(OS, MO.getMachineRegNum());
|
2002-07-10 23:45:04 +02:00
|
|
|
break;
|
2001-09-18 14:56:28 +02:00
|
|
|
case MachineOperand::MO_SignExtendedImmed:
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << (long)MO.getImmedValue();
|
2002-07-10 23:45:04 +02:00
|
|
|
break;
|
2001-09-18 14:56:28 +02:00
|
|
|
case MachineOperand::MO_UnextendedImmed:
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << (long)MO.getImmedValue();
|
2002-07-10 23:45:04 +02:00
|
|
|
break;
|
2001-09-18 14:56:28 +02:00
|
|
|
case MachineOperand::MO_PCRelativeDisp:
|
2001-10-01 01:44:19 +02:00
|
|
|
{
|
2002-12-15 21:35:25 +01:00
|
|
|
const Value* opVal = MO.getVRegValue();
|
2002-04-09 00:01:15 +02:00
|
|
|
bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << "%disp(" << (isLabel? "label " : "addr-of-val ");
|
2001-11-12 15:19:47 +01:00
|
|
|
if (opVal->hasName())
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << opVal->getName();
|
2001-11-12 15:19:47 +01:00
|
|
|
else
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << (const void*) opVal;
|
|
|
|
OS << ")";
|
2002-07-10 23:45:04 +02:00
|
|
|
break;
|
2001-10-01 01:44:19 +02:00
|
|
|
}
|
2002-12-15 21:35:25 +01:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << "bb<"
|
2002-12-15 21:35:25 +01:00
|
|
|
<< ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
|
|
|
|
<< "," << (void*)MO.getMachineBasicBlock()->getBasicBlock() << ">";
|
|
|
|
break;
|
2002-12-28 21:37:37 +01:00
|
|
|
case MachineOperand::MO_FrameIndex:
|
|
|
|
OS << "<fi#" << MO.getFrameIndex() << ">";
|
|
|
|
break;
|
2003-01-13 01:23:24 +01: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 14:56:28 +02:00
|
|
|
default:
|
|
|
|
assert(0 && "Unrecognized operand type");
|
|
|
|
break;
|
|
|
|
}
|
2001-09-10 00:26:29 +02:00
|
|
|
|
2002-12-15 21:35:25 +01:00
|
|
|
if (MO.flags &
|
2002-07-10 23:45:04 +02:00
|
|
|
(MachineOperand::HIFLAG32 | MachineOperand::LOFLAG32 |
|
|
|
|
MachineOperand::HIFLAG64 | MachineOperand::LOFLAG64))
|
2002-12-28 21:37:37 +01:00
|
|
|
OS << ")";
|
2002-07-10 23:45:04 +02:00
|
|
|
|
2002-12-28 21:37:37 +01:00
|
|
|
return OS;
|
2001-07-21 14:41:50 +02:00
|
|
|
}
|
2003-11-11 23:41:34 +01:00
|
|
|
|
|
|
|
} // End llvm namespace
|