// 7/2/01 - Vikram Adve - Created
//**************************************************************************/
-
#include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Target/MachineRegInfo.h"
-#include "llvm/Method.h"
-#include "llvm/Instruction.h"
-
+#include "llvm/Value.h"
+#include <iostream>
+using std::cerr;
//************************ Class Implementations **************************/
}
void
-MachineInstr::SetMachineOperand(unsigned int i,
+MachineInstr::SetMachineOperandVal(unsigned int i,
MachineOperand::MachineOperandType operandType,
Value* _val, bool isdef=false)
{
}
void
-MachineInstr::SetMachineOperand(unsigned int i,
+MachineInstr::SetMachineOperandConst(unsigned int i,
MachineOperand::MachineOperandType operandType,
- int64_t intValue, bool isdef=false)
+ int64_t intValue)
{
assert(i < operands.size());
+ assert(TargetInstrDescriptors[opCode].resultPos != (int) i &&
+ "immed. constant cannot be defined");
operands[i].InitializeConst(operandType, intValue);
- operands[i].isDef = isdef ||
- TargetInstrDescriptors[opCode].resultPos == (int) i;
+ operands[i].isDef = false;
}
void
-MachineInstr::SetMachineOperand(unsigned int i,
- unsigned int regNum, bool isdef=false)
+MachineInstr::SetMachineOperandReg(unsigned int i,
+ int regNum,
+ bool isdef=false,
+ bool isCCReg=false)
{
assert(i < operands.size());
- operands[i].InitializeReg(regNum);
+ operands[i].InitializeReg(regNum, isCCReg);
operands[i].isDef = isdef ||
TargetInstrDescriptors[opCode].resultPos == (int) i;
}
MachineInstr::dump(unsigned int indent) const
{
for (unsigned i=0; i < indent; i++)
- cout << " ";
+ cerr << " ";
- cout << *this;
+ cerr << *this;
}
-ostream&
-operator<< (ostream& os, const MachineInstr& minstr)
+static inline std::ostream &OutputValue(std::ostream &os,
+ const Value* val)
+{
+ os << "(val ";
+ if (val && val->hasName())
+ return os << val->getName();
+ else
+ return os << (void*) val; // print address only
+ os << ")";
+}
+
+std::ostream &operator<<(std::ostream& os, const MachineInstr& minstr)
{
os << TargetInstrDescriptors[minstr.opCode].opCodeString;
- for (unsigned i=0, N=minstr.getNumOperands(); i < N; i++)
+ for (unsigned i=0, N=minstr.getNumOperands(); i < N; i++) {
os << "\t" << minstr.getOperand(i);
+ if( minstr.getOperand(i).opIsDef() )
+ os << "*";
+ }
-#undef DEBUG_VAL_OP_ITERATOR
-#ifdef DEBUG_VAL_OP_ITERATOR
- os << endl << "\tValue operands are: ";
- for (MachineInstr::val_op_const_iterator vo(&minstr); ! vo.done(); ++vo)
- {
- const Value* val = *vo;
- os << val << (vo.isDef()? "(def), " : ", ");
- }
-#endif
-
-
-
-#if 1
// code for printing implict references
-
unsigned NumOfImpRefs = minstr.getNumImplicitRefs();
if( NumOfImpRefs > 0 ) {
-
- os << "\tImplicit:";
-
+ os << "\tImplicit: ";
for(unsigned z=0; z < NumOfImpRefs; z++) {
- os << minstr.getImplicitRef(z);
- cout << "\t";
+ OutputValue(os, minstr.getImplicitRef(z));
+ if( minstr.implicitRefIsDefined(z)) os << "*";
+ os << "\t";
}
}
-
-#endif
-
-
- os << endl;
- return os;
+ return os << "\n";
}
-static inline ostream&
-OutputOperand(ostream &os, const MachineOperand &mop)
+static inline std::ostream &OutputOperand(std::ostream &os,
+ const MachineOperand &mop)
{
+ Value* val;
switch (mop.getOperandType())
{
case MachineOperand::MO_CCRegister:
case MachineOperand::MO_VirtualRegister:
- return os << "(val " << mop.getVRegValue() << ")";
+ return OutputValue(os, mop.getVRegValue());
case MachineOperand::MO_MachineRegister:
- return os << "(" << mop.getMachineRegNum() << ")";
+ return os << "(" << mop.getMachineRegNum() << ")";
default:
assert(0 && "Unknown operand type");
return os;
}
-ostream&
-operator<<(ostream &os, const MachineOperand &mop)
+std::ostream &operator<<(std::ostream &os, const MachineOperand &mop)
{
switch(mop.opType)
{
os << "%ccreg";
return OutputOperand(os, mop);
case MachineOperand::MO_SignExtendedImmed:
- return os << mop.immedVal;
+ return os << (long)mop.immedVal;
case MachineOperand::MO_UnextendedImmed:
- return os << mop.immedVal;
+ return os << (long)mop.immedVal;
case MachineOperand::MO_PCRelativeDisp:
{
const Value* opVal = mop.getVRegValue();
- bool isLabel = isa<Method>(opVal) || isa<BasicBlock>(opVal);
- return os << "%disp("
- << (isLabel? "label " : "addr-of-val ")
- << opVal << ")";
+ bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
+ os << "%disp(" << (isLabel? "label " : "addr-of-val ");
+ if (opVal->hasName())
+ os << opVal->getName();
+ else
+ os << opVal;
+ return os << ")";
}
default:
assert(0 && "Unrecognized operand type");
return os;
}
-
-
-void
-MachineCodeForMethod::putLocalVarAtOffsetFromFP(const Value* local,
- int offset,
- unsigned int size)
-{
- offsetsFromFP[local] = offset;
- incrementAutomaticVarsSize(size);
-}
-
-
-void
-MachineCodeForMethod::putLocalVarAtOffsetFromSP(const Value* local,
- int offset,
- unsigned int size)
-{
- offsetsFromSP[local] = offset;
- incrementAutomaticVarsSize(size);
-}
-
-
-int
-MachineCodeForMethod::getOffsetFromFP(const Value* local) const
-{
- hash_map<const Value*, int>::const_iterator pair = offsetsFromFP.find(local);
- assert(pair != offsetsFromFP.end() && "Offset from FP unknown for Value");
- return (*pair).second;
-}
-
-
-int
-MachineCodeForMethod::getOffsetFromSP(const Value* local) const
-{
- hash_map<const Value*, int>::const_iterator pair = offsetsFromSP.find(local);
- assert(pair != offsetsFromSP.end() && "Offset from SP unknown for Value");
- return (*pair).second;
-}
-
-
-void
-MachineCodeForMethod::dump() const
-{
- cout << "\n" << method->getReturnType()
- << " \"" << method->getName() << "\"" << endl;
-
- for (Method::const_iterator BI = method->begin(); BI != method->end(); ++BI)
- {
- BasicBlock* bb = *BI;
- cout << "\n"
- << (bb->hasName()? bb->getName() : "Label")
- << " (" << bb << ")" << ":"
- << endl;
-
- MachineCodeForBasicBlock& mvec = bb->getMachineInstrVec();
- for (unsigned i=0; i < mvec.size(); i++)
- cout << "\t" << *mvec[i];
- }
- cout << endl << "End method \"" << method->getName() << "\""
- << endl << endl;
-}