blob: 7fb8b4569e27308d9ae1e5a5fff4587846551780 [file] [log] [blame]
Chris Lattner035dfbe2002-08-09 20:08:06 +00001//===-- MachineInstr.cpp --------------------------------------------------===//
Vikram S. Adve70bc4b52001-07-21 12:41:50 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner035dfbe2002-08-09 20:08:06 +000010//===----------------------------------------------------------------------===//
Vikram S. Adve70bc4b52001-07-21 12:41:50 +000011
Chris Lattner822b4fb2001-09-07 17:18:30 +000012#include "llvm/CodeGen/MachineInstr.h"
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000013#include "llvm/CodeGen/MachineBasicBlock.h"
Chris Lattner3801f6d2002-02-03 07:46:01 +000014#include "llvm/Value.h"
Chris Lattner10491642002-10-30 00:48:05 +000015#include "llvm/Target/TargetMachine.h"
Chris Lattner3501fea2003-01-14 22:00:31 +000016#include "llvm/Target/TargetInstrInfo.h"
Chris Lattner2a79a092002-10-30 00:58:19 +000017#include "llvm/Target/MRegisterInfo.h"
Chris Lattner8d95ef42003-01-13 00:23:24 +000018
Chris Lattnerf1757c42002-10-29 17:40:30 +000019// Global variable holding an array of descriptors for machine instructions.
20// The actual object needs to be created separately for each target machine.
Chris Lattner3501fea2003-01-14 22:00:31 +000021// This variable is initialized and reset by class TargetInstrInfo.
Chris Lattnerf1757c42002-10-29 17:40:30 +000022//
23// FIXME: This should be a property of the target so that more than one target
24// at a time can be active...
25//
Chris Lattner3501fea2003-01-14 22:00:31 +000026extern const TargetInstrDescriptor *TargetInstrDescriptors;
Ruchira Sasanka69917e22001-10-18 22:40:02 +000027
Vikram S. Adve1885da42001-07-31 21:49:28 +000028// Constructor for instructions with variable #operands
Chris Lattnerb98a53f2002-10-28 21:02:40 +000029MachineInstr::MachineInstr(MachineOpCode OpCode, unsigned numOperands)
Vikram S. Advea2bae302002-10-29 19:41:18 +000030 : opCode(OpCode),
Vikram S. Adve34977822003-05-31 07:39:06 +000031 opCodeFlags(0),
Vikram S. Advea2bae302002-10-29 19:41:18 +000032 operands(numOperands, MachineOperand()),
33 numImplicitRefs(0)
34{
Vikram S. Adve70bc4b52001-07-21 12:41:50 +000035}
36
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000037/// MachineInstr ctor - This constructor only does a _reserve_ of the operands,
38/// not a resize for them. It is expected that if you use this that you call
39/// add* methods below to fill up the operands, instead of the Set methods.
40/// Eventually, the "resizing" ctors will be phased out.
41///
Chris Lattner72791222002-10-28 20:59:49 +000042MachineInstr::MachineInstr(MachineOpCode Opcode, unsigned numOperands,
Vikram S. Advea2bae302002-10-29 19:41:18 +000043 bool XX, bool YY)
44 : opCode(Opcode),
Vikram S. Adve34977822003-05-31 07:39:06 +000045 opCodeFlags(0),
Vikram S. Advea2bae302002-10-29 19:41:18 +000046 numImplicitRefs(0)
47{
Chris Lattner72791222002-10-28 20:59:49 +000048 operands.reserve(numOperands);
49}
50
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000051/// MachineInstr ctor - Work exactly the same as the ctor above, except that the
52/// MachineInstr is created and added to the end of the specified basic block.
53///
54MachineInstr::MachineInstr(MachineBasicBlock *MBB, MachineOpCode Opcode,
55 unsigned numOperands)
56 : opCode(Opcode),
Vikram S. Adve34977822003-05-31 07:39:06 +000057 opCodeFlags(0),
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000058 numImplicitRefs(0)
59{
60 assert(MBB && "Cannot use inserting ctor with null basic block!");
61 operands.reserve(numOperands);
62 MBB->push_back(this); // Add instruction to end of basic block!
63}
64
65
Chris Lattner413746e2002-10-28 20:48:39 +000066// OperandComplete - Return true if it's illegal to add a new operand
Vikram S. Advea2bae302002-10-29 19:41:18 +000067bool MachineInstr::OperandsComplete() const
68{
Chris Lattner413746e2002-10-28 20:48:39 +000069 int NumOperands = TargetInstrDescriptors[opCode].numOperands;
Vikram S. Advea2bae302002-10-29 19:41:18 +000070 if (NumOperands >= 0 && getNumOperands() >= (unsigned)NumOperands)
Vikram S. Adve34977822003-05-31 07:39:06 +000071 return true; // Broken: we have all the operands of this instruction!
Chris Lattner413746e2002-10-28 20:48:39 +000072 return false;
73}
74
75
Vikram S. Advee8b57ef2002-09-20 00:47:49 +000076//
77// Support for replacing opcode and operands of a MachineInstr in place.
78// This only resets the size of the operand vector and initializes it.
79// The new operands must be set explicitly later.
80//
Vikram S. Advea2bae302002-10-29 19:41:18 +000081void MachineInstr::replace(MachineOpCode Opcode, unsigned numOperands)
82{
83 assert(getNumImplicitRefs() == 0 &&
84 "This is probably broken because implicit refs are going to be lost.");
Chris Lattner413746e2002-10-28 20:48:39 +000085 opCode = Opcode;
Vikram S. Advee8b57ef2002-09-20 00:47:49 +000086 operands.clear();
Chris Lattner413746e2002-10-28 20:48:39 +000087 operands.resize(numOperands, MachineOperand());
Vikram S. Advee8b57ef2002-09-20 00:47:49 +000088}
89
Chris Lattnera2dd7452003-08-05 16:58:46 +000090void MachineInstr::SetMachineOperandVal(unsigned i,
91 MachineOperand::MachineOperandType opTy,
92 Value* V) {
Vikram S. Advea2bae302002-10-29 19:41:18 +000093 assert(i < operands.size()); // may be explicit or implicit op
Chris Lattnera2dd7452003-08-05 16:58:46 +000094 operands[i].opType = opTy;
Chris Lattner572f5c82002-10-28 04:24:49 +000095 operands[i].value = V;
96 operands[i].regNum = -1;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +000097}
98
99void
Chris Lattner572f5c82002-10-28 04:24:49 +0000100MachineInstr::SetMachineOperandConst(unsigned i,
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000101 MachineOperand::MachineOperandType operandType,
Vikram S. Advec356e562002-03-18 03:35:24 +0000102 int64_t intValue)
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000103{
Vikram S. Advea2bae302002-10-29 19:41:18 +0000104 assert(i < getNumOperands()); // must be explicit op
Vikram S. Advec356e562002-03-18 03:35:24 +0000105 assert(TargetInstrDescriptors[opCode].resultPos != (int) i &&
106 "immed. constant cannot be defined");
Chris Lattner572f5c82002-10-28 04:24:49 +0000107
108 operands[i].opType = operandType;
109 operands[i].value = NULL;
110 operands[i].immedVal = intValue;
111 operands[i].regNum = -1;
112 operands[i].flags = 0;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000113}
114
Chris Lattnera2dd7452003-08-05 16:58:46 +0000115void MachineInstr::SetMachineOperandReg(unsigned i, int regNum) {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000116 assert(i < getNumOperands()); // must be explicit op
Chris Lattner572f5c82002-10-28 04:24:49 +0000117
Chris Lattner2f305982002-10-28 19:46:59 +0000118 operands[i].opType = MachineOperand::MO_MachineRegister;
Chris Lattner572f5c82002-10-28 04:24:49 +0000119 operands[i].value = NULL;
120 operands[i].regNum = regNum;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000121}
122
123void
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000124MachineInstr::SetRegForOperand(unsigned i, int regNum)
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000125{
Vikram S. Advea2bae302002-10-29 19:41:18 +0000126 assert(i < getNumOperands()); // must be explicit op
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000127 operands[i].setRegForValue(regNum);
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000128}
129
Vikram S. Adve34977822003-05-31 07:39:06 +0000130void
131MachineInstr::SetRegForImplicitRef(unsigned i, int regNum)
132{
133 getImplicitOp(i).setRegForValue(regNum);
Vikram S. Adve34977822003-05-31 07:39:06 +0000134}
135
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000136
Misha Brukman6eba07a2003-09-17 21:34:23 +0000137// Substitute all occurrences of Value* oldVal with newVal in all operands
Vikram S. Adve627eb312003-07-10 19:45:07 +0000138// and all implicit refs.
139// If defsOnly == true, substitute defs only.
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000140unsigned
Vikram S. Adve627eb312003-07-10 19:45:07 +0000141MachineInstr::substituteValue(const Value* oldVal, Value* newVal,
142 bool defsOnly, bool notDefsAndUses,
143 bool& someArgsWereIgnored)
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000144{
Vikram S. Adve2010f7b2003-08-07 15:01:48 +0000145 assert((!defsOnly || !notDefsAndUses) &&
146 "notDefsAndUses is irrelevant if defsOnly == true.");
Vikram S. Adve627eb312003-07-10 19:45:07 +0000147
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000148 unsigned numSubst = 0;
149
Misha Brukman6eba07a2003-09-17 21:34:23 +0000150 // Substitute operands
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000151 for (MachineInstr::val_op_iterator O = begin(), E = end(); O != E; ++O)
152 if (*O == oldVal)
Vikram S. Adve627eb312003-07-10 19:45:07 +0000153 if (!defsOnly ||
154 notDefsAndUses && O.isDefOnly() ||
155 !notDefsAndUses && !O.isUseOnly())
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000156 {
157 O.getMachineOperand().value = newVal;
158 ++numSubst;
159 }
Vikram S. Adve627eb312003-07-10 19:45:07 +0000160 else
161 someArgsWereIgnored = true;
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000162
Misha Brukman6eba07a2003-09-17 21:34:23 +0000163 // Substitute implicit refs
Vikram S. Advea2bae302002-10-29 19:41:18 +0000164 for (unsigned i=0, N=getNumImplicitRefs(); i < N; ++i)
Chris Lattner27a08932002-10-22 23:16:21 +0000165 if (getImplicitRef(i) == oldVal)
Vikram S. Adve627eb312003-07-10 19:45:07 +0000166 if (!defsOnly ||
167 notDefsAndUses && getImplicitOp(i).opIsDefOnly() ||
168 !notDefsAndUses && !getImplicitOp(i).opIsUse())
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000169 {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000170 getImplicitOp(i).value = newVal;
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000171 ++numSubst;
172 }
Vikram S. Adve627eb312003-07-10 19:45:07 +0000173 else
174 someArgsWereIgnored = true;
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000175
176 return numSubst;
177}
178
179
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000180void
181MachineInstr::dump() const
182{
Chris Lattner925b7712003-08-03 20:24:29 +0000183 std::cerr << " " << *this;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000184}
185
Vikram S. Adve8c6936a2002-09-16 15:18:53 +0000186static inline std::ostream&
187OutputValue(std::ostream &os, const Value* val)
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000188{
189 os << "(val ";
Vikram S. Adve627eb312003-07-10 19:45:07 +0000190 os << (void*) val; // print address always
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000191 if (val && val->hasName())
Vikram S. Adve627eb312003-07-10 19:45:07 +0000192 os << " " << val->getName() << ")"; // print name also, if available
193 return os;
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000194}
195
Chris Lattner2a79a092002-10-30 00:58:19 +0000196static inline void OutputReg(std::ostream &os, unsigned RegNo,
197 const MRegisterInfo *MRI = 0) {
198 if (MRI) {
199 if (RegNo < MRegisterInfo::FirstVirtualRegister)
200 os << "%" << MRI->get(RegNo).Name;
201 else
202 os << "%reg" << RegNo;
203 } else
204 os << "%mreg(" << RegNo << ")";
Vikram S. Adve8c6936a2002-09-16 15:18:53 +0000205}
206
Chris Lattner10491642002-10-30 00:48:05 +0000207static void print(const MachineOperand &MO, std::ostream &OS,
208 const TargetMachine &TM) {
Chris Lattner2a79a092002-10-30 00:58:19 +0000209 const MRegisterInfo *MRI = TM.getRegisterInfo();
Chris Lattner10491642002-10-30 00:48:05 +0000210 bool CloseParen = true;
211 if (MO.opHiBits32())
212 OS << "%lm(";
213 else if (MO.opLoBits32())
214 OS << "%lo(";
215 else if (MO.opHiBits64())
216 OS << "%hh(";
217 else if (MO.opLoBits64())
218 OS << "%hm(";
219 else
220 CloseParen = false;
221
222 switch (MO.getType()) {
223 case MachineOperand::MO_VirtualRegister:
224 if (MO.getVRegValue()) {
225 OS << "%reg";
226 OutputValue(OS, MO.getVRegValue());
227 if (MO.hasAllocatedReg())
228 OS << "==";
229 }
230 if (MO.hasAllocatedReg())
Chris Lattner2a79a092002-10-30 00:58:19 +0000231 OutputReg(OS, MO.getAllocatedRegNum(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000232 break;
233 case MachineOperand::MO_CCRegister:
234 OS << "%ccreg";
235 OutputValue(OS, MO.getVRegValue());
236 if (MO.hasAllocatedReg()) {
237 OS << "==";
Chris Lattner2a79a092002-10-30 00:58:19 +0000238 OutputReg(OS, MO.getAllocatedRegNum(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000239 }
240 break;
241 case MachineOperand::MO_MachineRegister:
Chris Lattner2a79a092002-10-30 00:58:19 +0000242 OutputReg(OS, MO.getMachineRegNum(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000243 break;
244 case MachineOperand::MO_SignExtendedImmed:
245 OS << (long)MO.getImmedValue();
246 break;
247 case MachineOperand::MO_UnextendedImmed:
248 OS << (long)MO.getImmedValue();
249 break;
250 case MachineOperand::MO_PCRelativeDisp: {
251 const Value* opVal = MO.getVRegValue();
252 bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
253 OS << "%disp(" << (isLabel? "label " : "addr-of-val ");
254 if (opVal->hasName())
255 OS << opVal->getName();
256 else
257 OS << (const void*) opVal;
258 OS << ")";
259 break;
260 }
Chris Lattner2109f502002-12-15 20:35:25 +0000261 case MachineOperand::MO_MachineBasicBlock:
262 OS << "bb<"
263 << ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
264 << "," << (void*)MO.getMachineBasicBlock()->getBasicBlock() << ">";
265 break;
Chris Lattner10cb79b2002-12-28 20:37:37 +0000266 case MachineOperand::MO_FrameIndex:
267 OS << "<fi#" << MO.getFrameIndex() << ">";
268 break;
Chris Lattner8d95ef42003-01-13 00:23:24 +0000269 case MachineOperand::MO_ConstantPoolIndex:
270 OS << "<cp#" << MO.getConstantPoolIndex() << ">";
271 break;
272 case MachineOperand::MO_GlobalAddress:
273 OS << "<ga:" << ((Value*)MO.getGlobal())->getName() << ">";
274 break;
275 case MachineOperand::MO_ExternalSymbol:
276 OS << "<es:" << MO.getSymbolName() << ">";
277 break;
Chris Lattner10491642002-10-30 00:48:05 +0000278 default:
279 assert(0 && "Unrecognized operand type");
280 }
281
282 if (CloseParen)
283 OS << ")";
284}
285
Chris Lattneraf55be12002-11-17 23:22:13 +0000286void MachineInstr::print(std::ostream &OS, const TargetMachine &TM) const {
Chris Lattner6a592272002-10-30 01:55:38 +0000287 unsigned StartOp = 0;
Chris Lattner10491642002-10-30 00:48:05 +0000288
Chris Lattner6a592272002-10-30 01:55:38 +0000289 // Specialize printing if op#0 is definition
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000290 if (getNumOperands() &&
291 (getOperand(0).opIsDefOnly() || getOperand(0).opIsDefAndUse())) {
Chris Lattner6a592272002-10-30 01:55:38 +0000292 ::print(getOperand(0), OS, TM);
293 OS << " = ";
294 ++StartOp; // Don't print this operand again!
295 }
296 OS << TM.getInstrInfo().getName(getOpcode());
297
298 for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000299 const MachineOperand& mop = getOperand(i);
Chris Lattner6a592272002-10-30 01:55:38 +0000300 if (i != StartOp)
301 OS << ",";
302 OS << " ";
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000303 ::print(mop, OS, TM);
Chris Lattner6a592272002-10-30 01:55:38 +0000304
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000305 if (mop.opIsDefAndUse())
Chris Lattner10491642002-10-30 00:48:05 +0000306 OS << "<def&use>";
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000307 else if (mop.opIsDefOnly())
Chris Lattner10491642002-10-30 00:48:05 +0000308 OS << "<def>";
309 }
Chris Lattner6a592272002-10-30 01:55:38 +0000310
Misha Brukman6eba07a2003-09-17 21:34:23 +0000311 // code for printing implicit references
Chris Lattner10491642002-10-30 00:48:05 +0000312 if (getNumImplicitRefs()) {
313 OS << "\tImplicitRefs: ";
314 for(unsigned i = 0, e = getNumImplicitRefs(); i != e; ++i) {
315 OS << "\t";
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000316 OutputValue(OS, getImplicitRef(i));
317 if (getImplicitOp(i).opIsDefAndUse())
Chris Lattner10491642002-10-30 00:48:05 +0000318 OS << "<def&use>";
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000319 else if (getImplicitOp(i).opIsDefOnly())
Chris Lattner10491642002-10-30 00:48:05 +0000320 OS << "<def>";
321 }
322 }
323
324 OS << "\n";
325}
326
327
Chris Lattner8d95ef42003-01-13 00:23:24 +0000328std::ostream &operator<<(std::ostream& os, const MachineInstr& MI)
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000329{
Chris Lattner8d95ef42003-01-13 00:23:24 +0000330 os << TargetInstrDescriptors[MI.opCode].Name;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000331
Chris Lattner8d95ef42003-01-13 00:23:24 +0000332 for (unsigned i=0, N=MI.getNumOperands(); i < N; i++) {
333 os << "\t" << MI.getOperand(i);
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000334 if (MI.getOperand(i).opIsDefOnly())
Chris Lattner8d95ef42003-01-13 00:23:24 +0000335 os << "<d>";
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000336 if (MI.getOperand(i).opIsDefAndUse())
Chris Lattner8d95ef42003-01-13 00:23:24 +0000337 os << "<d&u>";
Ruchira Sasanka8d243372001-11-14 20:05:23 +0000338 }
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000339
Misha Brukman6eba07a2003-09-17 21:34:23 +0000340 // code for printing implicit references
Chris Lattner8d95ef42003-01-13 00:23:24 +0000341 unsigned NumOfImpRefs = MI.getNumImplicitRefs();
342 if (NumOfImpRefs > 0) {
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000343 os << "\tImplicit: ";
Chris Lattner8d95ef42003-01-13 00:23:24 +0000344 for (unsigned z=0; z < NumOfImpRefs; z++) {
345 OutputValue(os, MI.getImplicitRef(z));
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000346 if (MI.getImplicitOp(z).opIsDefOnly()) os << "<d>";
347 if (MI.getImplicitOp(z).opIsDefAndUse()) os << "<d&u>";
Ruchira Sasanka07c70862001-11-15 20:46:40 +0000348 os << "\t";
Ruchira Sasanka69917e22001-10-18 22:40:02 +0000349 }
350 }
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000351
Chris Lattner697954c2002-01-20 22:54:45 +0000352 return os << "\n";
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000353}
354
Chris Lattner10cb79b2002-12-28 20:37:37 +0000355std::ostream &operator<<(std::ostream &OS, const MachineOperand &MO)
Vikram S. Adve6e447182001-09-18 12:56:28 +0000356{
Chris Lattner2109f502002-12-15 20:35:25 +0000357 if (MO.opHiBits32())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000358 OS << "%lm(";
Chris Lattner2109f502002-12-15 20:35:25 +0000359 else if (MO.opLoBits32())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000360 OS << "%lo(";
Chris Lattner2109f502002-12-15 20:35:25 +0000361 else if (MO.opHiBits64())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000362 OS << "%hh(";
Chris Lattner2109f502002-12-15 20:35:25 +0000363 else if (MO.opLoBits64())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000364 OS << "%hm(";
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000365
Chris Lattner2109f502002-12-15 20:35:25 +0000366 switch (MO.getType())
Vikram S. Adve6e447182001-09-18 12:56:28 +0000367 {
368 case MachineOperand::MO_VirtualRegister:
Chris Lattner8d95ef42003-01-13 00:23:24 +0000369 if (MO.hasAllocatedReg())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000370 OutputReg(OS, MO.getAllocatedRegNum());
Chris Lattner8d95ef42003-01-13 00:23:24 +0000371
372 if (MO.getVRegValue()) {
373 if (MO.hasAllocatedReg()) OS << "==";
374 OS << "%vreg";
375 OutputValue(OS, MO.getVRegValue());
Chris Lattner10491642002-10-30 00:48:05 +0000376 }
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000377 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000378 case MachineOperand::MO_CCRegister:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000379 OS << "%ccreg";
380 OutputValue(OS, MO.getVRegValue());
Chris Lattner2109f502002-12-15 20:35:25 +0000381 if (MO.hasAllocatedReg()) {
Chris Lattner10cb79b2002-12-28 20:37:37 +0000382 OS << "==";
383 OutputReg(OS, MO.getAllocatedRegNum());
Chris Lattner10491642002-10-30 00:48:05 +0000384 }
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000385 break;
386 case MachineOperand::MO_MachineRegister:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000387 OutputReg(OS, MO.getMachineRegNum());
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000388 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000389 case MachineOperand::MO_SignExtendedImmed:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000390 OS << (long)MO.getImmedValue();
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000391 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000392 case MachineOperand::MO_UnextendedImmed:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000393 OS << (long)MO.getImmedValue();
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000394 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000395 case MachineOperand::MO_PCRelativeDisp:
Vikram S. Advee949da52001-09-30 23:44:19 +0000396 {
Chris Lattner2109f502002-12-15 20:35:25 +0000397 const Value* opVal = MO.getVRegValue();
Chris Lattner4d669b52002-04-08 22:01:15 +0000398 bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
Chris Lattner10cb79b2002-12-28 20:37:37 +0000399 OS << "%disp(" << (isLabel? "label " : "addr-of-val ");
Vikram S. Adved9beb972001-11-12 14:19:47 +0000400 if (opVal->hasName())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000401 OS << opVal->getName();
Vikram S. Adved9beb972001-11-12 14:19:47 +0000402 else
Chris Lattner10cb79b2002-12-28 20:37:37 +0000403 OS << (const void*) opVal;
404 OS << ")";
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000405 break;
Vikram S. Advee949da52001-09-30 23:44:19 +0000406 }
Chris Lattner2109f502002-12-15 20:35:25 +0000407 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000408 OS << "bb<"
Chris Lattner2109f502002-12-15 20:35:25 +0000409 << ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
410 << "," << (void*)MO.getMachineBasicBlock()->getBasicBlock() << ">";
411 break;
Chris Lattner10cb79b2002-12-28 20:37:37 +0000412 case MachineOperand::MO_FrameIndex:
413 OS << "<fi#" << MO.getFrameIndex() << ">";
414 break;
Chris Lattner8d95ef42003-01-13 00:23:24 +0000415 case MachineOperand::MO_ConstantPoolIndex:
416 OS << "<cp#" << MO.getConstantPoolIndex() << ">";
417 break;
418 case MachineOperand::MO_GlobalAddress:
419 OS << "<ga:" << ((Value*)MO.getGlobal())->getName() << ">";
420 break;
421 case MachineOperand::MO_ExternalSymbol:
422 OS << "<es:" << MO.getSymbolName() << ">";
423 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000424 default:
425 assert(0 && "Unrecognized operand type");
426 break;
427 }
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000428
Chris Lattner2109f502002-12-15 20:35:25 +0000429 if (MO.flags &
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000430 (MachineOperand::HIFLAG32 | MachineOperand::LOFLAG32 |
431 MachineOperand::HIFLAG64 | MachineOperand::LOFLAG64))
Chris Lattner10cb79b2002-12-28 20:37:37 +0000432 OS << ")";
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000433
Chris Lattner10cb79b2002-12-28 20:37:37 +0000434 return OS;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000435}