blob: db4cbd3c4783231f02871c3b0381d785b75a32f9 [file] [log] [blame]
Chris Lattner035dfbe2002-08-09 20:08:06 +00001//===-- MachineInstr.cpp --------------------------------------------------===//
Misha Brukmanedf128a2005-04-21 22:36:52 +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.
Misha Brukmanedf128a2005-04-21 22:36:52 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Brian Gaeke21326fc2004-02-13 04:39:32 +00009//
10// Methods common to all machine instructions.
11//
12// FIXME: Now that MachineInstrs have parent pointers, they should always
13// print themselves using their MachineFunction's TargetMachine.
14//
Chris Lattner035dfbe2002-08-09 20:08:06 +000015//===----------------------------------------------------------------------===//
Vikram S. Adve70bc4b52001-07-21 12:41:50 +000016
Chris Lattner822b4fb2001-09-07 17:18:30 +000017#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner8517e1f2004-02-19 16:17:08 +000018#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner3801f6d2002-02-03 07:46:01 +000019#include "llvm/Value.h"
Chris Lattner10491642002-10-30 00:48:05 +000020#include "llvm/Target/TargetMachine.h"
Chris Lattner3501fea2003-01-14 22:00:31 +000021#include "llvm/Target/TargetInstrInfo.h"
Chris Lattner2a79a092002-10-30 00:58:19 +000022#include "llvm/Target/MRegisterInfo.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000023#include "llvm/Support/LeakDetector.h"
Reid Spencer954da372004-07-04 12:19:56 +000024#include <iostream>
25
Chris Lattner0742b592004-02-23 18:38:20 +000026using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000027
Chris Lattnerf1757c42002-10-29 17:40:30 +000028// Global variable holding an array of descriptors for machine instructions.
29// The actual object needs to be created separately for each target machine.
Chris Lattner3501fea2003-01-14 22:00:31 +000030// This variable is initialized and reset by class TargetInstrInfo.
Misha Brukmanedf128a2005-04-21 22:36:52 +000031//
Chris Lattnerf1757c42002-10-29 17:40:30 +000032// FIXME: This should be a property of the target so that more than one target
33// at a time can be active...
34//
Chris Lattner11d1f212004-02-23 18:40:08 +000035namespace llvm {
Chris Lattner0742b592004-02-23 18:38:20 +000036 extern const TargetInstrDescriptor *TargetInstrDescriptors;
37}
Ruchira Sasanka69917e22001-10-18 22:40:02 +000038
Vikram S. Adve1885da42001-07-31 21:49:28 +000039// Constructor for instructions with variable #operands
Alkis Evlogimenosab8672c2004-02-12 18:49:07 +000040MachineInstr::MachineInstr(short opcode, unsigned numOperands)
41 : Opcode(opcode),
Alkis Evlogimenosab8672c2004-02-12 18:49:07 +000042 operands(numOperands, MachineOperand()),
43 parent(0) {
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000044 // Make sure that we get added to a machine basicblock
45 LeakDetector::addGarbageObject(this);
Vikram S. Adve70bc4b52001-07-21 12:41:50 +000046}
47
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000048/// MachineInstr ctor - This constructor only does a _reserve_ of the operands,
49/// not a resize for them. It is expected that if you use this that you call
50/// add* methods below to fill up the operands, instead of the Set methods.
51/// Eventually, the "resizing" ctors will be phased out.
52///
Brian Gaeke21326fc2004-02-13 04:39:32 +000053MachineInstr::MachineInstr(short opcode, unsigned numOperands, bool XX, bool YY)
Chris Lattner02e5f8d2006-04-20 18:08:53 +000054 : Opcode(opcode), parent(0) {
Chris Lattner72791222002-10-28 20:59:49 +000055 operands.reserve(numOperands);
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000056 // Make sure that we get added to a machine basicblock
57 LeakDetector::addGarbageObject(this);
Chris Lattner72791222002-10-28 20:59:49 +000058}
59
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000060/// MachineInstr ctor - Work exactly the same as the ctor above, except that the
61/// MachineInstr is created and added to the end of the specified basic block.
62///
Alkis Evlogimenosab8672c2004-02-12 18:49:07 +000063MachineInstr::MachineInstr(MachineBasicBlock *MBB, short opcode,
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000064 unsigned numOperands)
Chris Lattner02e5f8d2006-04-20 18:08:53 +000065 : Opcode(opcode), parent(0) {
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000066 assert(MBB && "Cannot use inserting ctor with null basic block!");
67 operands.reserve(numOperands);
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000068 // Make sure that we get added to a machine basicblock
69 LeakDetector::addGarbageObject(this);
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000070 MBB->push_back(this); // Add instruction to end of basic block!
71}
72
Misha Brukmance22e762004-07-09 14:45:17 +000073/// MachineInstr ctor - Copies MachineInstr arg exactly
74///
Tanya Lattner466b5342004-05-23 19:35:12 +000075MachineInstr::MachineInstr(const MachineInstr &MI) {
76 Opcode = MI.getOpcode();
Tanya Lattnerb5159ed2004-05-23 20:58:02 +000077 operands.reserve(MI.getNumOperands());
78
Misha Brukmance22e762004-07-09 14:45:17 +000079 // Add operands
80 for (unsigned i = 0; i < MI.getNumOperands(); ++i)
Tanya Lattner466b5342004-05-23 19:35:12 +000081 operands.push_back(MachineOperand(MI.getOperand(i)));
Tanya Lattner0c63e032004-05-24 03:14:18 +000082
Misha Brukmance22e762004-07-09 14:45:17 +000083 // Set parent, next, and prev to null
Tanya Lattner0c63e032004-05-24 03:14:18 +000084 parent = 0;
85 prev = 0;
86 next = 0;
Tanya Lattner466b5342004-05-23 19:35:12 +000087}
88
89
Misha Brukmance22e762004-07-09 14:45:17 +000090MachineInstr::~MachineInstr() {
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000091 LeakDetector::removeGarbageObject(this);
92}
93
Misha Brukmance22e762004-07-09 14:45:17 +000094/// clone - Create a copy of 'this' instruction that is identical in all ways
95/// except the following: the new instruction has no parent and it has no name
96///
Tanya Lattner0c63e032004-05-24 03:14:18 +000097MachineInstr* MachineInstr::clone() const {
Tanya Lattnerb5159ed2004-05-23 20:58:02 +000098 return new MachineInstr(*this);
Tanya Lattner466b5342004-05-23 19:35:12 +000099}
100
Chris Lattner48d7c062006-04-17 21:35:41 +0000101/// removeFromParent - This method unlinks 'this' from the containing basic
102/// block, and returns it, but does not delete it.
103MachineInstr *MachineInstr::removeFromParent() {
104 assert(getParent() && "Not embedded in a basic block!");
105 getParent()->remove(this);
106 return this;
107}
108
109
Brian Gaeke21326fc2004-02-13 04:39:32 +0000110/// OperandComplete - Return true if it's illegal to add a new operand
111///
Chris Lattner2a90ba62004-02-12 16:09:53 +0000112bool MachineInstr::OperandsComplete() const {
113 int NumOperands = TargetInstrDescriptors[Opcode].numOperands;
Vikram S. Advea2bae302002-10-29 19:41:18 +0000114 if (NumOperands >= 0 && getNumOperands() >= (unsigned)NumOperands)
Vikram S. Adve34977822003-05-31 07:39:06 +0000115 return true; // Broken: we have all the operands of this instruction!
Chris Lattner413746e2002-10-28 20:48:39 +0000116 return false;
117}
118
Chris Lattnera2dd7452003-08-05 16:58:46 +0000119void MachineInstr::SetMachineOperandVal(unsigned i,
120 MachineOperand::MachineOperandType opTy,
121 Value* V) {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000122 assert(i < operands.size()); // may be explicit or implicit op
Chris Lattnera2dd7452003-08-05 16:58:46 +0000123 operands[i].opType = opTy;
Brian Gaekec5483952004-03-03 19:07:27 +0000124 operands[i].contents.value = V;
Chris Lattnerca4f6eb2004-10-15 04:38:41 +0000125 operands[i].extra.regNum = -1;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000126}
127
128void
Chris Lattner572f5c82002-10-28 04:24:49 +0000129MachineInstr::SetMachineOperandConst(unsigned i,
Brian Gaeke21326fc2004-02-13 04:39:32 +0000130 MachineOperand::MachineOperandType opTy,
Chris Lattner561c0102004-02-29 05:07:02 +0000131 int intValue) {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000132 assert(i < getNumOperands()); // must be explicit op
Chris Lattner2a90ba62004-02-12 16:09:53 +0000133 assert(TargetInstrDescriptors[Opcode].resultPos != (int) i &&
Vikram S. Advec356e562002-03-18 03:35:24 +0000134 "immed. constant cannot be defined");
Chris Lattner572f5c82002-10-28 04:24:49 +0000135
Brian Gaeke21326fc2004-02-13 04:39:32 +0000136 operands[i].opType = opTy;
Brian Gaekec5483952004-03-03 19:07:27 +0000137 operands[i].contents.value = NULL;
138 operands[i].contents.immedVal = intValue;
Chris Lattnerca4f6eb2004-10-15 04:38:41 +0000139 operands[i].extra.regNum = -1;
Chris Lattner572f5c82002-10-28 04:24:49 +0000140 operands[i].flags = 0;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000141}
142
Chris Lattnera2dd7452003-08-05 16:58:46 +0000143void MachineInstr::SetMachineOperandReg(unsigned i, int regNum) {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000144 assert(i < getNumOperands()); // must be explicit op
Chris Lattner572f5c82002-10-28 04:24:49 +0000145
Chris Lattner2f305982002-10-28 19:46:59 +0000146 operands[i].opType = MachineOperand::MO_MachineRegister;
Brian Gaekec5483952004-03-03 19:07:27 +0000147 operands[i].contents.value = NULL;
Chris Lattnerca4f6eb2004-10-15 04:38:41 +0000148 operands[i].extra.regNum = regNum;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000149}
150
Brian Gaeke21326fc2004-02-13 04:39:32 +0000151void MachineInstr::dump() const {
Chris Lattner925b7712003-08-03 20:24:29 +0000152 std::cerr << " " << *this;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000153}
154
Brian Gaeke21326fc2004-02-13 04:39:32 +0000155static inline std::ostream& OutputValue(std::ostream &os, const Value* val) {
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000156 os << "(val ";
Misha Brukmance22e762004-07-09 14:45:17 +0000157 os << (void*) val; // print address always
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000158 if (val && val->hasName())
Misha Brukmance22e762004-07-09 14:45:17 +0000159 os << " " << val->getName(); // print name also, if available
Brian Gaeke21326fc2004-02-13 04:39:32 +0000160 os << ")";
Vikram S. Adve627eb312003-07-10 19:45:07 +0000161 return os;
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000162}
163
Chris Lattner2a79a092002-10-30 00:58:19 +0000164static inline void OutputReg(std::ostream &os, unsigned RegNo,
165 const MRegisterInfo *MRI = 0) {
Alkis Evlogimenosddcfd9e2004-02-27 01:52:34 +0000166 if (!RegNo || MRegisterInfo::isPhysicalRegister(RegNo)) {
Chris Lattner8517e1f2004-02-19 16:17:08 +0000167 if (MRI)
Chris Lattner2a79a092002-10-30 00:58:19 +0000168 os << "%" << MRI->get(RegNo).Name;
169 else
Chris Lattner8517e1f2004-02-19 16:17:08 +0000170 os << "%mreg(" << RegNo << ")";
Chris Lattner2a79a092002-10-30 00:58:19 +0000171 } else
Chris Lattner8517e1f2004-02-19 16:17:08 +0000172 os << "%reg" << RegNo;
Vikram S. Adve8c6936a2002-09-16 15:18:53 +0000173}
174
Chris Lattner10491642002-10-30 00:48:05 +0000175static void print(const MachineOperand &MO, std::ostream &OS,
Tanya Lattnerb1407622004-06-25 00:13:11 +0000176 const TargetMachine *TM) {
Misha Brukmance22e762004-07-09 14:45:17 +0000177 const MRegisterInfo *MRI = 0;
Misha Brukmanedf128a2005-04-21 22:36:52 +0000178
Misha Brukmance22e762004-07-09 14:45:17 +0000179 if (TM) MRI = TM->getRegisterInfo();
Tanya Lattnerb1407622004-06-25 00:13:11 +0000180
Chris Lattner10491642002-10-30 00:48:05 +0000181 bool CloseParen = true;
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000182 if (MO.isHiBits32())
Chris Lattner10491642002-10-30 00:48:05 +0000183 OS << "%lm(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000184 else if (MO.isLoBits32())
Chris Lattner10491642002-10-30 00:48:05 +0000185 OS << "%lo(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000186 else if (MO.isHiBits64())
Chris Lattner10491642002-10-30 00:48:05 +0000187 OS << "%hh(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000188 else if (MO.isLoBits64())
Chris Lattner10491642002-10-30 00:48:05 +0000189 OS << "%hm(";
190 else
191 CloseParen = false;
Misha Brukmanedf128a2005-04-21 22:36:52 +0000192
Chris Lattner10491642002-10-30 00:48:05 +0000193 switch (MO.getType()) {
194 case MachineOperand::MO_VirtualRegister:
195 if (MO.getVRegValue()) {
196 OS << "%reg";
197 OutputValue(OS, MO.getVRegValue());
198 if (MO.hasAllocatedReg())
199 OS << "==";
200 }
201 if (MO.hasAllocatedReg())
Alkis Evlogimenosbe766c72004-02-13 21:01:20 +0000202 OutputReg(OS, MO.getReg(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000203 break;
204 case MachineOperand::MO_CCRegister:
205 OS << "%ccreg";
206 OutputValue(OS, MO.getVRegValue());
207 if (MO.hasAllocatedReg()) {
208 OS << "==";
Alkis Evlogimenosbe766c72004-02-13 21:01:20 +0000209 OutputReg(OS, MO.getReg(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000210 }
211 break;
212 case MachineOperand::MO_MachineRegister:
Chris Lattner2a79a092002-10-30 00:58:19 +0000213 OutputReg(OS, MO.getMachineRegNum(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000214 break;
215 case MachineOperand::MO_SignExtendedImmed:
216 OS << (long)MO.getImmedValue();
217 break;
218 case MachineOperand::MO_UnextendedImmed:
219 OS << (long)MO.getImmedValue();
220 break;
221 case MachineOperand::MO_PCRelativeDisp: {
222 const Value* opVal = MO.getVRegValue();
223 bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
224 OS << "%disp(" << (isLabel? "label " : "addr-of-val ");
225 if (opVal->hasName())
226 OS << opVal->getName();
227 else
228 OS << (const void*) opVal;
229 OS << ")";
230 break;
231 }
Chris Lattner2109f502002-12-15 20:35:25 +0000232 case MachineOperand::MO_MachineBasicBlock:
Brian Gaeke988b7ba2004-06-17 22:26:53 +0000233 OS << "mbb<"
Chris Lattner2109f502002-12-15 20:35:25 +0000234 << ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
Brian Gaeke988b7ba2004-06-17 22:26:53 +0000235 << "," << (void*)MO.getMachineBasicBlock() << ">";
Chris Lattner2109f502002-12-15 20:35:25 +0000236 break;
Chris Lattner10cb79b2002-12-28 20:37:37 +0000237 case MachineOperand::MO_FrameIndex:
238 OS << "<fi#" << MO.getFrameIndex() << ">";
239 break;
Chris Lattner8d95ef42003-01-13 00:23:24 +0000240 case MachineOperand::MO_ConstantPoolIndex:
241 OS << "<cp#" << MO.getConstantPoolIndex() << ">";
242 break;
243 case MachineOperand::MO_GlobalAddress:
Chris Lattnerca4f6eb2004-10-15 04:38:41 +0000244 OS << "<ga:" << ((Value*)MO.getGlobal())->getName();
245 if (MO.getOffset()) OS << "+" << MO.getOffset();
246 OS << ">";
Chris Lattner8d95ef42003-01-13 00:23:24 +0000247 break;
248 case MachineOperand::MO_ExternalSymbol:
Chris Lattnerca4f6eb2004-10-15 04:38:41 +0000249 OS << "<es:" << MO.getSymbolName();
250 if (MO.getOffset()) OS << "+" << MO.getOffset();
251 OS << ">";
Chris Lattner8d95ef42003-01-13 00:23:24 +0000252 break;
Chris Lattner10491642002-10-30 00:48:05 +0000253 default:
254 assert(0 && "Unrecognized operand type");
255 }
256
257 if (CloseParen)
258 OS << ")";
259}
260
Tanya Lattnerb1407622004-06-25 00:13:11 +0000261void MachineInstr::print(std::ostream &OS, const TargetMachine *TM) const {
Chris Lattner6a592272002-10-30 01:55:38 +0000262 unsigned StartOp = 0;
Chris Lattner10491642002-10-30 00:48:05 +0000263
Chris Lattner6a592272002-10-30 01:55:38 +0000264 // Specialize printing if op#0 is definition
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000265 if (getNumOperands() && getOperand(0).isDef() && !getOperand(0).isUse()) {
Chris Lattner0742b592004-02-23 18:38:20 +0000266 ::print(getOperand(0), OS, TM);
Chris Lattner6a592272002-10-30 01:55:38 +0000267 OS << " = ";
268 ++StartOp; // Don't print this operand again!
269 }
Tanya Lattnerb1407622004-06-25 00:13:11 +0000270
Misha Brukmance22e762004-07-09 14:45:17 +0000271 // Must check if Target machine is not null because machine BB could not
272 // be attached to a Machine function yet
273 if (TM)
Tanya Lattnerb1407622004-06-25 00:13:11 +0000274 OS << TM->getInstrInfo()->getName(getOpcode());
Misha Brukmanedf128a2005-04-21 22:36:52 +0000275
Chris Lattner6a592272002-10-30 01:55:38 +0000276 for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000277 const MachineOperand& mop = getOperand(i);
Chris Lattner6a592272002-10-30 01:55:38 +0000278 if (i != StartOp)
279 OS << ",";
280 OS << " ";
Chris Lattner0742b592004-02-23 18:38:20 +0000281 ::print(mop, OS, TM);
Misha Brukmanedf128a2005-04-21 22:36:52 +0000282
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000283 if (mop.isDef())
284 if (mop.isUse())
285 OS << "<def&use>";
286 else
287 OS << "<def>";
Chris Lattner10491642002-10-30 00:48:05 +0000288 }
Misha Brukmanedf128a2005-04-21 22:36:52 +0000289
Chris Lattner10491642002-10-30 00:48:05 +0000290 OS << "\n";
291}
292
Chris Lattner11d1f212004-02-23 18:40:08 +0000293namespace llvm {
Chris Lattner8517e1f2004-02-19 16:17:08 +0000294std::ostream &operator<<(std::ostream &os, const MachineInstr &MI) {
295 // If the instruction is embedded into a basic block, we can find the target
296 // info for the instruction.
297 if (const MachineBasicBlock *MBB = MI.getParent()) {
298 const MachineFunction *MF = MBB->getParent();
Misha Brukmance22e762004-07-09 14:45:17 +0000299 if (MF)
Tanya Lattnerb1407622004-06-25 00:13:11 +0000300 MI.print(os, &MF->getTarget());
301 else
302 MI.print(os, 0);
Chris Lattner8517e1f2004-02-19 16:17:08 +0000303 return os;
304 }
305
306 // Otherwise, print it out in the "raw" format without symbolic register names
307 // and such.
Chris Lattner2a90ba62004-02-12 16:09:53 +0000308 os << TargetInstrDescriptors[MI.getOpcode()].Name;
Misha Brukmanedf128a2005-04-21 22:36:52 +0000309
Misha Brukmance22e762004-07-09 14:45:17 +0000310 for (unsigned i = 0, N = MI.getNumOperands(); i < N; i++) {
Chris Lattner8d95ef42003-01-13 00:23:24 +0000311 os << "\t" << MI.getOperand(i);
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000312 if (MI.getOperand(i).isDef())
313 if (MI.getOperand(i).isUse())
314 os << "<d&u>";
315 else
316 os << "<d>";
Ruchira Sasanka8d243372001-11-14 20:05:23 +0000317 }
Misha Brukmanedf128a2005-04-21 22:36:52 +0000318
Chris Lattner697954c2002-01-20 22:54:45 +0000319 return os << "\n";
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000320}
321
Brian Gaeke21326fc2004-02-13 04:39:32 +0000322std::ostream &operator<<(std::ostream &OS, const MachineOperand &MO) {
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000323 if (MO.isHiBits32())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000324 OS << "%lm(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000325 else if (MO.isLoBits32())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000326 OS << "%lo(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000327 else if (MO.isHiBits64())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000328 OS << "%hh(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000329 else if (MO.isLoBits64())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000330 OS << "%hm(";
Misha Brukmanedf128a2005-04-21 22:36:52 +0000331
Misha Brukmance22e762004-07-09 14:45:17 +0000332 switch (MO.getType()) {
333 case MachineOperand::MO_VirtualRegister:
334 if (MO.hasAllocatedReg())
335 OutputReg(OS, MO.getReg());
Chris Lattner8d95ef42003-01-13 00:23:24 +0000336
Misha Brukmance22e762004-07-09 14:45:17 +0000337 if (MO.getVRegValue()) {
338 if (MO.hasAllocatedReg()) OS << "==";
339 OS << "%vreg";
Chris Lattner10cb79b2002-12-28 20:37:37 +0000340 OutputValue(OS, MO.getVRegValue());
Vikram S. Adve6e447182001-09-18 12:56:28 +0000341 }
Misha Brukmance22e762004-07-09 14:45:17 +0000342 break;
343 case MachineOperand::MO_CCRegister:
344 OS << "%ccreg";
345 OutputValue(OS, MO.getVRegValue());
346 if (MO.hasAllocatedReg()) {
347 OS << "==";
348 OutputReg(OS, MO.getReg());
349 }
350 break;
351 case MachineOperand::MO_MachineRegister:
352 OutputReg(OS, MO.getMachineRegNum());
353 break;
354 case MachineOperand::MO_SignExtendedImmed:
355 OS << (long)MO.getImmedValue();
356 break;
357 case MachineOperand::MO_UnextendedImmed:
358 OS << (long)MO.getImmedValue();
359 break;
360 case MachineOperand::MO_PCRelativeDisp: {
361 const Value* opVal = MO.getVRegValue();
362 bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
363 OS << "%disp(" << (isLabel? "label " : "addr-of-val ");
364 if (opVal->hasName())
365 OS << opVal->getName();
366 else
367 OS << (const void*) opVal;
368 OS << ")";
369 break;
370 }
371 case MachineOperand::MO_MachineBasicBlock:
372 OS << "<mbb:"
373 << ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
374 << "@" << (void*)MO.getMachineBasicBlock() << ">";
375 break;
376 case MachineOperand::MO_FrameIndex:
377 OS << "<fi#" << MO.getFrameIndex() << ">";
378 break;
379 case MachineOperand::MO_ConstantPoolIndex:
380 OS << "<cp#" << MO.getConstantPoolIndex() << ">";
381 break;
382 case MachineOperand::MO_GlobalAddress:
383 OS << "<ga:" << ((Value*)MO.getGlobal())->getName() << ">";
384 break;
385 case MachineOperand::MO_ExternalSymbol:
386 OS << "<es:" << MO.getSymbolName() << ">";
387 break;
388 default:
389 assert(0 && "Unrecognized operand type");
390 break;
391 }
Misha Brukmanedf128a2005-04-21 22:36:52 +0000392
Chris Lattner0742b592004-02-23 18:38:20 +0000393 if (MO.isHiBits32() || MO.isLoBits32() || MO.isHiBits64() || MO.isLoBits64())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000394 OS << ")";
Misha Brukmanedf128a2005-04-21 22:36:52 +0000395
Chris Lattner10cb79b2002-12-28 20:37:37 +0000396 return OS;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000397}
Brian Gaeked0fde302003-11-11 22:41:34 +0000398
Chris Lattner11d1f212004-02-23 18:40:08 +0000399}