2001-07-21 12:41:50 +00:00
|
|
|
// $Id$
|
|
|
|
//***************************************************************************
|
|
|
|
// File:
|
|
|
|
// MachineInstr.cpp
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Strategy:
|
|
|
|
//
|
|
|
|
// History:
|
|
|
|
// 7/2/01 - Vikram Adve - Created
|
|
|
|
//**************************************************************************/
|
|
|
|
|
2001-09-07 17:18:30 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2002-02-03 07:46:01 +00:00
|
|
|
#include "llvm/Value.h"
|
2002-01-20 22:54:45 +00:00
|
|
|
#include <iostream>
|
|
|
|
using std::cerr;
|
2001-08-28 23:02:39 +00:00
|
|
|
|
2001-10-18 22:40:02 +00:00
|
|
|
|
2001-07-21 12:41:50 +00:00
|
|
|
//************************ Class Implementations **************************/
|
|
|
|
|
2001-07-31 21:49:28 +00:00
|
|
|
// Constructor for instructions with fixed #operands (nearly all)
|
2001-07-21 12:41:50 +00:00
|
|
|
MachineInstr::MachineInstr(MachineOpCode _opCode,
|
|
|
|
OpCodeMask _opCodeMask)
|
|
|
|
: opCode(_opCode),
|
|
|
|
opCodeMask(_opCodeMask),
|
2001-07-28 04:06:37 +00:00
|
|
|
operands(TargetInstrDescriptors[_opCode].numOperands)
|
2001-07-31 21:49:28 +00:00
|
|
|
{
|
|
|
|
assert(TargetInstrDescriptors[_opCode].numOperands >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor for instructions with variable #operands
|
|
|
|
MachineInstr::MachineInstr(MachineOpCode _opCode,
|
|
|
|
unsigned numOperands,
|
|
|
|
OpCodeMask _opCodeMask)
|
|
|
|
: opCode(_opCode),
|
|
|
|
opCodeMask(_opCodeMask),
|
|
|
|
operands(numOperands)
|
2001-07-21 12:41:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-18 03:35:24 +00:00
|
|
|
MachineInstr::SetMachineOperandVal(unsigned int i,
|
2002-07-08 22:38:45 +00:00
|
|
|
MachineOperand::MachineOperandType opType,
|
|
|
|
Value* _val,
|
|
|
|
bool isdef=false,
|
|
|
|
bool isDefAndUse=false)
|
2001-07-21 12:41:50 +00:00
|
|
|
{
|
2001-07-28 04:06:37 +00:00
|
|
|
assert(i < operands.size());
|
2002-07-08 22:38:45 +00:00
|
|
|
operands[i].Initialize(opType, _val);
|
2002-07-10 21:45:04 +00:00
|
|
|
if (isdef || TargetInstrDescriptors[opCode].resultPos == (int) i)
|
|
|
|
operands[i].markDef();
|
|
|
|
if (isDefAndUse)
|
|
|
|
operands[i].markDefAndUse();
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-18 03:35:24 +00:00
|
|
|
MachineInstr::SetMachineOperandConst(unsigned int i,
|
2001-07-21 12:41:50 +00:00
|
|
|
MachineOperand::MachineOperandType operandType,
|
2002-03-18 03:35:24 +00:00
|
|
|
int64_t intValue)
|
2001-07-21 12:41:50 +00:00
|
|
|
{
|
2001-07-28 04:06:37 +00:00
|
|
|
assert(i < operands.size());
|
2002-03-18 03:35:24 +00:00
|
|
|
assert(TargetInstrDescriptors[opCode].resultPos != (int) i &&
|
|
|
|
"immed. constant cannot be defined");
|
2001-07-21 12:41:50 +00:00
|
|
|
operands[i].InitializeConst(operandType, intValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-18 03:35:24 +00:00
|
|
|
MachineInstr::SetMachineOperandReg(unsigned int i,
|
|
|
|
int regNum,
|
|
|
|
bool isdef=false,
|
2002-07-08 22:38:45 +00:00
|
|
|
bool isDefAndUse=false,
|
2002-03-18 03:35:24 +00:00
|
|
|
bool isCCReg=false)
|
2001-07-21 12:41:50 +00:00
|
|
|
{
|
2001-07-28 04:06:37 +00:00
|
|
|
assert(i < operands.size());
|
2002-03-18 03:35:24 +00:00
|
|
|
operands[i].InitializeReg(regNum, isCCReg);
|
2002-07-10 21:45:04 +00:00
|
|
|
if (isdef || TargetInstrDescriptors[opCode].resultPos == (int) i)
|
|
|
|
operands[i].markDef();
|
|
|
|
if (isDefAndUse)
|
|
|
|
operands[i].markDefAndUse();
|
2002-07-08 22:38:45 +00:00
|
|
|
regsUsed.insert(regNum);
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-08 22:38:45 +00:00
|
|
|
MachineInstr::SetRegForOperand(unsigned i, int regNum)
|
2001-07-21 12:41:50 +00:00
|
|
|
{
|
2002-07-08 22:38:45 +00:00
|
|
|
operands[i].setRegForValue(regNum);
|
|
|
|
regsUsed.insert(regNum);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
MachineInstr::dump() const
|
|
|
|
{
|
|
|
|
cerr << " " << *this;
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2002-04-25 04:31:18 +00:00
|
|
|
static inline std::ostream &OutputValue(std::ostream &os,
|
|
|
|
const Value* val)
|
|
|
|
{
|
|
|
|
os << "(val ";
|
|
|
|
if (val && val->hasName())
|
2002-07-10 21:45:04 +00:00
|
|
|
return os << val->getName() << ")";
|
2002-04-25 04:31:18 +00:00
|
|
|
else
|
2002-07-10 21:45:04 +00:00
|
|
|
return os << (void*) val << ")"; // print address only
|
2002-04-25 04:31:18 +00:00
|
|
|
}
|
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
std::ostream &operator<<(std::ostream& os, const MachineInstr& minstr)
|
2001-07-21 12:41:50 +00:00
|
|
|
{
|
2001-07-28 04:06:37 +00:00
|
|
|
os << TargetInstrDescriptors[minstr.opCode].opCodeString;
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2001-11-14 20:05:23 +00:00
|
|
|
for (unsigned i=0, N=minstr.getNumOperands(); i < N; i++) {
|
2001-07-21 12:41:50 +00:00
|
|
|
os << "\t" << minstr.getOperand(i);
|
2002-07-08 22:38:45 +00:00
|
|
|
if( minstr.operandIsDefined(i) )
|
|
|
|
os << "*";
|
|
|
|
if( minstr.operandIsDefinedAndUsed(i) )
|
2001-11-15 20:46:40 +00:00
|
|
|
os << "*";
|
2001-11-14 20:05:23 +00:00
|
|
|
}
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2001-10-18 22:40:02 +00:00
|
|
|
// code for printing implict references
|
|
|
|
unsigned NumOfImpRefs = minstr.getNumImplicitRefs();
|
|
|
|
if( NumOfImpRefs > 0 ) {
|
2002-04-25 04:31:18 +00:00
|
|
|
os << "\tImplicit: ";
|
2001-10-18 22:40:02 +00:00
|
|
|
for(unsigned z=0; z < NumOfImpRefs; z++) {
|
2002-04-25 04:31:18 +00:00
|
|
|
OutputValue(os, minstr.getImplicitRef(z));
|
2001-11-14 20:05:23 +00:00
|
|
|
if( minstr.implicitRefIsDefined(z)) os << "*";
|
2002-07-08 22:38:45 +00:00
|
|
|
if( minstr.implicitRefIsDefinedAndUsed(z)) os << "*";
|
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
|
|
|
}
|
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
std::ostream &operator<<(std::ostream &os, const MachineOperand &mop)
|
2001-09-18 12:56:28 +00:00
|
|
|
{
|
2002-07-10 21:45:04 +00:00
|
|
|
if (mop.opHiBits32())
|
|
|
|
os << "%lm(";
|
|
|
|
else if (mop.opLoBits32())
|
|
|
|
os << "%lo(";
|
|
|
|
else if (mop.opHiBits64())
|
|
|
|
os << "%hh(";
|
|
|
|
else if (mop.opLoBits64())
|
|
|
|
os << "%hm(";
|
|
|
|
|
2001-09-18 12:56:28 +00:00
|
|
|
switch(mop.opType)
|
|
|
|
{
|
|
|
|
case MachineOperand::MO_VirtualRegister:
|
|
|
|
os << "%reg";
|
2002-07-10 21:45:04 +00:00
|
|
|
OutputValue(os, mop.getVRegValue());
|
|
|
|
break;
|
2001-09-18 12:56:28 +00:00
|
|
|
case MachineOperand::MO_CCRegister:
|
|
|
|
os << "%ccreg";
|
2002-07-10 21:45:04 +00:00
|
|
|
OutputValue(os, mop.getVRegValue());
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_MachineRegister:
|
|
|
|
os << "%reg";
|
|
|
|
os << "(" << mop.getMachineRegNum() << ")";
|
|
|
|
break;
|
2001-09-18 12:56:28 +00:00
|
|
|
case MachineOperand::MO_SignExtendedImmed:
|
2002-07-10 21:45:04 +00:00
|
|
|
os << (long)mop.immedVal;
|
|
|
|
break;
|
2001-09-18 12:56:28 +00:00
|
|
|
case MachineOperand::MO_UnextendedImmed:
|
2002-07-10 21:45:04 +00:00
|
|
|
os << (long)mop.immedVal;
|
|
|
|
break;
|
2001-09-18 12:56:28 +00:00
|
|
|
case MachineOperand::MO_PCRelativeDisp:
|
2001-09-30 23:44:19 +00:00
|
|
|
{
|
|
|
|
const Value* opVal = mop.getVRegValue();
|
2002-04-08 22:01:15 +00:00
|
|
|
bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
|
2001-11-12 14:19:47 +00:00
|
|
|
os << "%disp(" << (isLabel? "label " : "addr-of-val ");
|
|
|
|
if (opVal->hasName())
|
2002-01-20 22:54:45 +00:00
|
|
|
os << opVal->getName();
|
2001-11-12 14:19:47 +00:00
|
|
|
else
|
2002-07-08 22:38:45 +00:00
|
|
|
os << (const void*) opVal;
|
2002-07-10 21:45:04 +00:00
|
|
|
os << ")";
|
|
|
|
break;
|
2001-09-30 23:44:19 +00:00
|
|
|
}
|
2001-09-18 12:56:28 +00:00
|
|
|
default:
|
|
|
|
assert(0 && "Unrecognized operand type");
|
|
|
|
break;
|
|
|
|
}
|
2001-09-09 22:26:29 +00:00
|
|
|
|
2002-07-10 21:45:04 +00:00
|
|
|
if (mop.flags &
|
|
|
|
(MachineOperand::HIFLAG32 | MachineOperand::LOFLAG32 |
|
|
|
|
MachineOperand::HIFLAG64 | MachineOperand::LOFLAG64))
|
|
|
|
os << ")";
|
|
|
|
|
2001-07-21 12:41:50 +00:00
|
|
|
return os;
|
|
|
|
}
|