blob: 904a412add72cdf1400f31264f90bc6db911e6eb [file] [log] [blame]
Chris Lattner035dfbe2002-08-09 20:08:06 +00001//===-- MachineInstr.cpp --------------------------------------------------===//
Vikram S. Adve70bc4b52001-07-21 12:41:50 +00002//
Chris Lattner035dfbe2002-08-09 20:08:06 +00003//===----------------------------------------------------------------------===//
Vikram S. Adve70bc4b52001-07-21 12:41:50 +00004
Chris Lattner822b4fb2001-09-07 17:18:30 +00005#include "llvm/CodeGen/MachineInstr.h"
Chris Lattnerddd7fcb2002-10-29 23:19:00 +00006#include "llvm/CodeGen/MachineBasicBlock.h"
Chris Lattner3801f6d2002-02-03 07:46:01 +00007#include "llvm/Value.h"
Chris Lattner10491642002-10-30 00:48:05 +00008#include "llvm/Target/TargetMachine.h"
Chris Lattner3501fea2003-01-14 22:00:31 +00009#include "llvm/Target/TargetInstrInfo.h"
Chris Lattner2a79a092002-10-30 00:58:19 +000010#include "llvm/Target/MRegisterInfo.h"
Chris Lattner8d95ef42003-01-13 00:23:24 +000011
Chris Lattnerf1757c42002-10-29 17:40:30 +000012// Global variable holding an array of descriptors for machine instructions.
13// The actual object needs to be created separately for each target machine.
Chris Lattner3501fea2003-01-14 22:00:31 +000014// This variable is initialized and reset by class TargetInstrInfo.
Chris Lattnerf1757c42002-10-29 17:40:30 +000015//
16// FIXME: This should be a property of the target so that more than one target
17// at a time can be active...
18//
Chris Lattner3501fea2003-01-14 22:00:31 +000019extern const TargetInstrDescriptor *TargetInstrDescriptors;
Ruchira Sasanka69917e22001-10-18 22:40:02 +000020
Vikram S. Adve1885da42001-07-31 21:49:28 +000021// Constructor for instructions with variable #operands
Chris Lattnerb98a53f2002-10-28 21:02:40 +000022MachineInstr::MachineInstr(MachineOpCode OpCode, unsigned numOperands)
Vikram S. Advea2bae302002-10-29 19:41:18 +000023 : opCode(OpCode),
Vikram S. Adve34977822003-05-31 07:39:06 +000024 opCodeFlags(0),
Vikram S. Advea2bae302002-10-29 19:41:18 +000025 operands(numOperands, MachineOperand()),
26 numImplicitRefs(0)
27{
Vikram S. Adve70bc4b52001-07-21 12:41:50 +000028}
29
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000030/// MachineInstr ctor - This constructor only does a _reserve_ of the operands,
31/// not a resize for them. It is expected that if you use this that you call
32/// add* methods below to fill up the operands, instead of the Set methods.
33/// Eventually, the "resizing" ctors will be phased out.
34///
Chris Lattner72791222002-10-28 20:59:49 +000035MachineInstr::MachineInstr(MachineOpCode Opcode, unsigned numOperands,
Vikram S. Advea2bae302002-10-29 19:41:18 +000036 bool XX, bool YY)
37 : opCode(Opcode),
Vikram S. Adve34977822003-05-31 07:39:06 +000038 opCodeFlags(0),
Vikram S. Advea2bae302002-10-29 19:41:18 +000039 numImplicitRefs(0)
40{
Chris Lattner72791222002-10-28 20:59:49 +000041 operands.reserve(numOperands);
42}
43
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000044/// MachineInstr ctor - Work exactly the same as the ctor above, except that the
45/// MachineInstr is created and added to the end of the specified basic block.
46///
47MachineInstr::MachineInstr(MachineBasicBlock *MBB, MachineOpCode Opcode,
48 unsigned numOperands)
49 : opCode(Opcode),
Vikram S. Adve34977822003-05-31 07:39:06 +000050 opCodeFlags(0),
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000051 numImplicitRefs(0)
52{
53 assert(MBB && "Cannot use inserting ctor with null basic block!");
54 operands.reserve(numOperands);
55 MBB->push_back(this); // Add instruction to end of basic block!
56}
57
58
Chris Lattner413746e2002-10-28 20:48:39 +000059// OperandComplete - Return true if it's illegal to add a new operand
Vikram S. Advea2bae302002-10-29 19:41:18 +000060bool MachineInstr::OperandsComplete() const
61{
Chris Lattner413746e2002-10-28 20:48:39 +000062 int NumOperands = TargetInstrDescriptors[opCode].numOperands;
Vikram S. Advea2bae302002-10-29 19:41:18 +000063 if (NumOperands >= 0 && getNumOperands() >= (unsigned)NumOperands)
Vikram S. Adve34977822003-05-31 07:39:06 +000064 return true; // Broken: we have all the operands of this instruction!
Chris Lattner413746e2002-10-28 20:48:39 +000065 return false;
66}
67
68
Vikram S. Advee8b57ef2002-09-20 00:47:49 +000069//
70// Support for replacing opcode and operands of a MachineInstr in place.
71// This only resets the size of the operand vector and initializes it.
72// The new operands must be set explicitly later.
73//
Vikram S. Advea2bae302002-10-29 19:41:18 +000074void MachineInstr::replace(MachineOpCode Opcode, unsigned numOperands)
75{
76 assert(getNumImplicitRefs() == 0 &&
77 "This is probably broken because implicit refs are going to be lost.");
Chris Lattner413746e2002-10-28 20:48:39 +000078 opCode = Opcode;
Vikram S. Advee8b57ef2002-09-20 00:47:49 +000079 operands.clear();
Chris Lattner413746e2002-10-28 20:48:39 +000080 operands.resize(numOperands, MachineOperand());
Vikram S. Advee8b57ef2002-09-20 00:47:49 +000081}
82
Chris Lattnera2dd7452003-08-05 16:58:46 +000083void MachineInstr::SetMachineOperandVal(unsigned i,
84 MachineOperand::MachineOperandType opTy,
85 Value* V) {
Vikram S. Advea2bae302002-10-29 19:41:18 +000086 assert(i < operands.size()); // may be explicit or implicit op
Chris Lattnera2dd7452003-08-05 16:58:46 +000087 operands[i].opType = opTy;
Chris Lattner572f5c82002-10-28 04:24:49 +000088 operands[i].value = V;
89 operands[i].regNum = -1;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +000090}
91
92void
Chris Lattner572f5c82002-10-28 04:24:49 +000093MachineInstr::SetMachineOperandConst(unsigned i,
Vikram S. Adve70bc4b52001-07-21 12:41:50 +000094 MachineOperand::MachineOperandType operandType,
Vikram S. Advec356e562002-03-18 03:35:24 +000095 int64_t intValue)
Vikram S. Adve70bc4b52001-07-21 12:41:50 +000096{
Vikram S. Advea2bae302002-10-29 19:41:18 +000097 assert(i < getNumOperands()); // must be explicit op
Vikram S. Advec356e562002-03-18 03:35:24 +000098 assert(TargetInstrDescriptors[opCode].resultPos != (int) i &&
99 "immed. constant cannot be defined");
Chris Lattner572f5c82002-10-28 04:24:49 +0000100
101 operands[i].opType = operandType;
102 operands[i].value = NULL;
103 operands[i].immedVal = intValue;
104 operands[i].regNum = -1;
105 operands[i].flags = 0;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000106}
107
Chris Lattnera2dd7452003-08-05 16:58:46 +0000108void MachineInstr::SetMachineOperandReg(unsigned i, int regNum) {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000109 assert(i < getNumOperands()); // must be explicit op
Chris Lattner572f5c82002-10-28 04:24:49 +0000110
Chris Lattner2f305982002-10-28 19:46:59 +0000111 operands[i].opType = MachineOperand::MO_MachineRegister;
Chris Lattner572f5c82002-10-28 04:24:49 +0000112 operands[i].value = NULL;
113 operands[i].regNum = regNum;
Chris Lattner27a08932002-10-22 23:16:21 +0000114 insertUsedReg(regNum);
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000115}
116
117void
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000118MachineInstr::SetRegForOperand(unsigned i, int regNum)
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000119{
Vikram S. Advea2bae302002-10-29 19:41:18 +0000120 assert(i < getNumOperands()); // must be explicit op
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000121 operands[i].setRegForValue(regNum);
Chris Lattner27a08932002-10-22 23:16:21 +0000122 insertUsedReg(regNum);
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000123}
124
Vikram S. Adve34977822003-05-31 07:39:06 +0000125void
126MachineInstr::SetRegForImplicitRef(unsigned i, int regNum)
127{
128 getImplicitOp(i).setRegForValue(regNum);
129 insertUsedReg(regNum);
130}
131
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000132
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000133// Subsitute all occurrences of Value* oldVal with newVal in all operands
Vikram S. Adve627eb312003-07-10 19:45:07 +0000134// and all implicit refs.
135// If defsOnly == true, substitute defs only.
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000136unsigned
Vikram S. Adve627eb312003-07-10 19:45:07 +0000137MachineInstr::substituteValue(const Value* oldVal, Value* newVal,
138 bool defsOnly, bool notDefsAndUses,
139 bool& someArgsWereIgnored)
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000140{
Vikram S. Adve627eb312003-07-10 19:45:07 +0000141 assert((defsOnly || !notDefsAndUses) &&
142 "notDefsAndUses is irrelevant if defsOnly == false.");
143
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000144 unsigned numSubst = 0;
145
146 // Subsitute operands
147 for (MachineInstr::val_op_iterator O = begin(), E = end(); O != E; ++O)
148 if (*O == oldVal)
Vikram S. Adve627eb312003-07-10 19:45:07 +0000149 if (!defsOnly ||
150 notDefsAndUses && O.isDefOnly() ||
151 !notDefsAndUses && !O.isUseOnly())
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000152 {
153 O.getMachineOperand().value = newVal;
154 ++numSubst;
155 }
Vikram S. Adve627eb312003-07-10 19:45:07 +0000156 else
157 someArgsWereIgnored = true;
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000158
159 // Subsitute implicit refs
Vikram S. Advea2bae302002-10-29 19:41:18 +0000160 for (unsigned i=0, N=getNumImplicitRefs(); i < N; ++i)
Chris Lattner27a08932002-10-22 23:16:21 +0000161 if (getImplicitRef(i) == oldVal)
Vikram S. Adve627eb312003-07-10 19:45:07 +0000162 if (!defsOnly ||
163 notDefsAndUses && getImplicitOp(i).opIsDefOnly() ||
164 !notDefsAndUses && !getImplicitOp(i).opIsUse())
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000165 {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000166 getImplicitOp(i).value = newVal;
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000167 ++numSubst;
168 }
Vikram S. Adve627eb312003-07-10 19:45:07 +0000169 else
170 someArgsWereIgnored = true;
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000171
172 return numSubst;
173}
174
175
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000176void
177MachineInstr::dump() const
178{
Chris Lattner925b7712003-08-03 20:24:29 +0000179 std::cerr << " " << *this;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000180}
181
Vikram S. Adve8c6936a2002-09-16 15:18:53 +0000182static inline std::ostream&
183OutputValue(std::ostream &os, const Value* val)
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000184{
185 os << "(val ";
Vikram S. Adve627eb312003-07-10 19:45:07 +0000186 os << (void*) val; // print address always
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000187 if (val && val->hasName())
Vikram S. Adve627eb312003-07-10 19:45:07 +0000188 os << " " << val->getName() << ")"; // print name also, if available
189 return os;
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000190}
191
Chris Lattner2a79a092002-10-30 00:58:19 +0000192static inline void OutputReg(std::ostream &os, unsigned RegNo,
193 const MRegisterInfo *MRI = 0) {
194 if (MRI) {
195 if (RegNo < MRegisterInfo::FirstVirtualRegister)
196 os << "%" << MRI->get(RegNo).Name;
197 else
198 os << "%reg" << RegNo;
199 } else
200 os << "%mreg(" << RegNo << ")";
Vikram S. Adve8c6936a2002-09-16 15:18:53 +0000201}
202
Chris Lattner10491642002-10-30 00:48:05 +0000203static void print(const MachineOperand &MO, std::ostream &OS,
204 const TargetMachine &TM) {
Chris Lattner2a79a092002-10-30 00:58:19 +0000205 const MRegisterInfo *MRI = TM.getRegisterInfo();
Chris Lattner10491642002-10-30 00:48:05 +0000206 bool CloseParen = true;
207 if (MO.opHiBits32())
208 OS << "%lm(";
209 else if (MO.opLoBits32())
210 OS << "%lo(";
211 else if (MO.opHiBits64())
212 OS << "%hh(";
213 else if (MO.opLoBits64())
214 OS << "%hm(";
215 else
216 CloseParen = false;
217
218 switch (MO.getType()) {
219 case MachineOperand::MO_VirtualRegister:
220 if (MO.getVRegValue()) {
221 OS << "%reg";
222 OutputValue(OS, MO.getVRegValue());
223 if (MO.hasAllocatedReg())
224 OS << "==";
225 }
226 if (MO.hasAllocatedReg())
Chris Lattner2a79a092002-10-30 00:58:19 +0000227 OutputReg(OS, MO.getAllocatedRegNum(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000228 break;
229 case MachineOperand::MO_CCRegister:
230 OS << "%ccreg";
231 OutputValue(OS, MO.getVRegValue());
232 if (MO.hasAllocatedReg()) {
233 OS << "==";
Chris Lattner2a79a092002-10-30 00:58:19 +0000234 OutputReg(OS, MO.getAllocatedRegNum(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000235 }
236 break;
237 case MachineOperand::MO_MachineRegister:
Chris Lattner2a79a092002-10-30 00:58:19 +0000238 OutputReg(OS, MO.getMachineRegNum(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000239 break;
240 case MachineOperand::MO_SignExtendedImmed:
241 OS << (long)MO.getImmedValue();
242 break;
243 case MachineOperand::MO_UnextendedImmed:
244 OS << (long)MO.getImmedValue();
245 break;
246 case MachineOperand::MO_PCRelativeDisp: {
247 const Value* opVal = MO.getVRegValue();
248 bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
249 OS << "%disp(" << (isLabel? "label " : "addr-of-val ");
250 if (opVal->hasName())
251 OS << opVal->getName();
252 else
253 OS << (const void*) opVal;
254 OS << ")";
255 break;
256 }
Chris Lattner2109f502002-12-15 20:35:25 +0000257 case MachineOperand::MO_MachineBasicBlock:
258 OS << "bb<"
259 << ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
260 << "," << (void*)MO.getMachineBasicBlock()->getBasicBlock() << ">";
261 break;
Chris Lattner10cb79b2002-12-28 20:37:37 +0000262 case MachineOperand::MO_FrameIndex:
263 OS << "<fi#" << MO.getFrameIndex() << ">";
264 break;
Chris Lattner8d95ef42003-01-13 00:23:24 +0000265 case MachineOperand::MO_ConstantPoolIndex:
266 OS << "<cp#" << MO.getConstantPoolIndex() << ">";
267 break;
268 case MachineOperand::MO_GlobalAddress:
269 OS << "<ga:" << ((Value*)MO.getGlobal())->getName() << ">";
270 break;
271 case MachineOperand::MO_ExternalSymbol:
272 OS << "<es:" << MO.getSymbolName() << ">";
273 break;
Chris Lattner10491642002-10-30 00:48:05 +0000274 default:
275 assert(0 && "Unrecognized operand type");
276 }
277
278 if (CloseParen)
279 OS << ")";
280}
281
Chris Lattneraf55be12002-11-17 23:22:13 +0000282void MachineInstr::print(std::ostream &OS, const TargetMachine &TM) const {
Chris Lattner6a592272002-10-30 01:55:38 +0000283 unsigned StartOp = 0;
Chris Lattner10491642002-10-30 00:48:05 +0000284
Chris Lattner6a592272002-10-30 01:55:38 +0000285 // Specialize printing if op#0 is definition
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000286 if (getNumOperands() &&
287 (getOperand(0).opIsDefOnly() || getOperand(0).opIsDefAndUse())) {
Chris Lattner6a592272002-10-30 01:55:38 +0000288 ::print(getOperand(0), OS, TM);
289 OS << " = ";
290 ++StartOp; // Don't print this operand again!
291 }
292 OS << TM.getInstrInfo().getName(getOpcode());
293
294 for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000295 const MachineOperand& mop = getOperand(i);
Chris Lattner6a592272002-10-30 01:55:38 +0000296 if (i != StartOp)
297 OS << ",";
298 OS << " ";
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000299 ::print(mop, OS, TM);
Chris Lattner6a592272002-10-30 01:55:38 +0000300
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000301 if (mop.opIsDefAndUse())
Chris Lattner10491642002-10-30 00:48:05 +0000302 OS << "<def&use>";
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000303 else if (mop.opIsDefOnly())
Chris Lattner10491642002-10-30 00:48:05 +0000304 OS << "<def>";
305 }
Chris Lattner6a592272002-10-30 01:55:38 +0000306
Chris Lattner10491642002-10-30 00:48:05 +0000307 // code for printing implict references
308 if (getNumImplicitRefs()) {
309 OS << "\tImplicitRefs: ";
310 for(unsigned i = 0, e = getNumImplicitRefs(); i != e; ++i) {
311 OS << "\t";
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000312 OutputValue(OS, getImplicitRef(i));
313 if (getImplicitOp(i).opIsDefAndUse())
Chris Lattner10491642002-10-30 00:48:05 +0000314 OS << "<def&use>";
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000315 else if (getImplicitOp(i).opIsDefOnly())
Chris Lattner10491642002-10-30 00:48:05 +0000316 OS << "<def>";
317 }
318 }
319
320 OS << "\n";
321}
322
323
Chris Lattner8d95ef42003-01-13 00:23:24 +0000324std::ostream &operator<<(std::ostream& os, const MachineInstr& MI)
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000325{
Chris Lattner8d95ef42003-01-13 00:23:24 +0000326 os << TargetInstrDescriptors[MI.opCode].Name;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000327
Chris Lattner8d95ef42003-01-13 00:23:24 +0000328 for (unsigned i=0, N=MI.getNumOperands(); i < N; i++) {
329 os << "\t" << MI.getOperand(i);
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000330 if (MI.getOperand(i).opIsDefOnly())
Chris Lattner8d95ef42003-01-13 00:23:24 +0000331 os << "<d>";
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000332 if (MI.getOperand(i).opIsDefAndUse())
Chris Lattner8d95ef42003-01-13 00:23:24 +0000333 os << "<d&u>";
Ruchira Sasanka8d243372001-11-14 20:05:23 +0000334 }
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000335
Ruchira Sasanka69917e22001-10-18 22:40:02 +0000336 // code for printing implict references
Chris Lattner8d95ef42003-01-13 00:23:24 +0000337 unsigned NumOfImpRefs = MI.getNumImplicitRefs();
338 if (NumOfImpRefs > 0) {
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000339 os << "\tImplicit: ";
Chris Lattner8d95ef42003-01-13 00:23:24 +0000340 for (unsigned z=0; z < NumOfImpRefs; z++) {
341 OutputValue(os, MI.getImplicitRef(z));
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000342 if (MI.getImplicitOp(z).opIsDefOnly()) os << "<d>";
343 if (MI.getImplicitOp(z).opIsDefAndUse()) os << "<d&u>";
Ruchira Sasanka07c70862001-11-15 20:46:40 +0000344 os << "\t";
Ruchira Sasanka69917e22001-10-18 22:40:02 +0000345 }
346 }
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000347
Chris Lattner697954c2002-01-20 22:54:45 +0000348 return os << "\n";
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000349}
350
Chris Lattner10cb79b2002-12-28 20:37:37 +0000351std::ostream &operator<<(std::ostream &OS, const MachineOperand &MO)
Vikram S. Adve6e447182001-09-18 12:56:28 +0000352{
Chris Lattner2109f502002-12-15 20:35:25 +0000353 if (MO.opHiBits32())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000354 OS << "%lm(";
Chris Lattner2109f502002-12-15 20:35:25 +0000355 else if (MO.opLoBits32())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000356 OS << "%lo(";
Chris Lattner2109f502002-12-15 20:35:25 +0000357 else if (MO.opHiBits64())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000358 OS << "%hh(";
Chris Lattner2109f502002-12-15 20:35:25 +0000359 else if (MO.opLoBits64())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000360 OS << "%hm(";
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000361
Chris Lattner2109f502002-12-15 20:35:25 +0000362 switch (MO.getType())
Vikram S. Adve6e447182001-09-18 12:56:28 +0000363 {
364 case MachineOperand::MO_VirtualRegister:
Chris Lattner8d95ef42003-01-13 00:23:24 +0000365 if (MO.hasAllocatedReg())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000366 OutputReg(OS, MO.getAllocatedRegNum());
Chris Lattner8d95ef42003-01-13 00:23:24 +0000367
368 if (MO.getVRegValue()) {
369 if (MO.hasAllocatedReg()) OS << "==";
370 OS << "%vreg";
371 OutputValue(OS, MO.getVRegValue());
Chris Lattner10491642002-10-30 00:48:05 +0000372 }
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000373 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000374 case MachineOperand::MO_CCRegister:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000375 OS << "%ccreg";
376 OutputValue(OS, MO.getVRegValue());
Chris Lattner2109f502002-12-15 20:35:25 +0000377 if (MO.hasAllocatedReg()) {
Chris Lattner10cb79b2002-12-28 20:37:37 +0000378 OS << "==";
379 OutputReg(OS, MO.getAllocatedRegNum());
Chris Lattner10491642002-10-30 00:48:05 +0000380 }
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000381 break;
382 case MachineOperand::MO_MachineRegister:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000383 OutputReg(OS, MO.getMachineRegNum());
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000384 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000385 case MachineOperand::MO_SignExtendedImmed:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000386 OS << (long)MO.getImmedValue();
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000387 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000388 case MachineOperand::MO_UnextendedImmed:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000389 OS << (long)MO.getImmedValue();
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000390 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000391 case MachineOperand::MO_PCRelativeDisp:
Vikram S. Advee949da52001-09-30 23:44:19 +0000392 {
Chris Lattner2109f502002-12-15 20:35:25 +0000393 const Value* opVal = MO.getVRegValue();
Chris Lattner4d669b52002-04-08 22:01:15 +0000394 bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
Chris Lattner10cb79b2002-12-28 20:37:37 +0000395 OS << "%disp(" << (isLabel? "label " : "addr-of-val ");
Vikram S. Adved9beb972001-11-12 14:19:47 +0000396 if (opVal->hasName())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000397 OS << opVal->getName();
Vikram S. Adved9beb972001-11-12 14:19:47 +0000398 else
Chris Lattner10cb79b2002-12-28 20:37:37 +0000399 OS << (const void*) opVal;
400 OS << ")";
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000401 break;
Vikram S. Advee949da52001-09-30 23:44:19 +0000402 }
Chris Lattner2109f502002-12-15 20:35:25 +0000403 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000404 OS << "bb<"
Chris Lattner2109f502002-12-15 20:35:25 +0000405 << ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
406 << "," << (void*)MO.getMachineBasicBlock()->getBasicBlock() << ">";
407 break;
Chris Lattner10cb79b2002-12-28 20:37:37 +0000408 case MachineOperand::MO_FrameIndex:
409 OS << "<fi#" << MO.getFrameIndex() << ">";
410 break;
Chris Lattner8d95ef42003-01-13 00:23:24 +0000411 case MachineOperand::MO_ConstantPoolIndex:
412 OS << "<cp#" << MO.getConstantPoolIndex() << ">";
413 break;
414 case MachineOperand::MO_GlobalAddress:
415 OS << "<ga:" << ((Value*)MO.getGlobal())->getName() << ">";
416 break;
417 case MachineOperand::MO_ExternalSymbol:
418 OS << "<es:" << MO.getSymbolName() << ">";
419 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000420 default:
421 assert(0 && "Unrecognized operand type");
422 break;
423 }
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000424
Chris Lattner2109f502002-12-15 20:35:25 +0000425 if (MO.flags &
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000426 (MachineOperand::HIFLAG32 | MachineOperand::LOFLAG32 |
427 MachineOperand::HIFLAG64 | MachineOperand::LOFLAG64))
Chris Lattner10cb79b2002-12-28 20:37:37 +0000428 OS << ")";
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000429
Chris Lattner10cb79b2002-12-28 20:37:37 +0000430 return OS;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000431}