blob: 030cb7ef0cf162510be7e66f2fb72f84474ce8e6 [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//===----------------------------------------------------------------------===//
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"
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000023#include "Support/LeakDetector.h"
Chris Lattner0742b592004-02-23 18:38:20 +000024using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000025
Chris Lattnerf1757c42002-10-29 17:40:30 +000026// Global variable holding an array of descriptors for machine instructions.
27// The actual object needs to be created separately for each target machine.
Chris Lattner3501fea2003-01-14 22:00:31 +000028// This variable is initialized and reset by class TargetInstrInfo.
Chris Lattnerf1757c42002-10-29 17:40:30 +000029//
30// FIXME: This should be a property of the target so that more than one target
31// at a time can be active...
32//
Chris Lattner11d1f212004-02-23 18:40:08 +000033namespace llvm {
Chris Lattner0742b592004-02-23 18:38:20 +000034 extern const TargetInstrDescriptor *TargetInstrDescriptors;
35}
Ruchira Sasanka69917e22001-10-18 22:40:02 +000036
Vikram S. Adve1885da42001-07-31 21:49:28 +000037// Constructor for instructions with variable #operands
Alkis Evlogimenosab8672c2004-02-12 18:49:07 +000038MachineInstr::MachineInstr(short opcode, unsigned numOperands)
39 : Opcode(opcode),
40 numImplicitRefs(0),
41 operands(numOperands, MachineOperand()),
42 parent(0) {
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000043 // Make sure that we get added to a machine basicblock
44 LeakDetector::addGarbageObject(this);
Vikram S. Adve70bc4b52001-07-21 12:41:50 +000045}
46
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000047/// MachineInstr ctor - This constructor only does a _reserve_ of the operands,
48/// not a resize for them. It is expected that if you use this that you call
49/// add* methods below to fill up the operands, instead of the Set methods.
50/// Eventually, the "resizing" ctors will be phased out.
51///
Brian Gaeke21326fc2004-02-13 04:39:32 +000052MachineInstr::MachineInstr(short opcode, unsigned numOperands, bool XX, bool YY)
53 : Opcode(opcode), numImplicitRefs(0), parent(0) {
Chris Lattner72791222002-10-28 20:59:49 +000054 operands.reserve(numOperands);
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000055 // Make sure that we get added to a machine basicblock
56 LeakDetector::addGarbageObject(this);
Chris Lattner72791222002-10-28 20:59:49 +000057}
58
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000059/// MachineInstr ctor - Work exactly the same as the ctor above, except that the
60/// MachineInstr is created and added to the end of the specified basic block.
61///
Alkis Evlogimenosab8672c2004-02-12 18:49:07 +000062MachineInstr::MachineInstr(MachineBasicBlock *MBB, short opcode,
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000063 unsigned numOperands)
Brian Gaeke21326fc2004-02-13 04:39:32 +000064 : Opcode(opcode), numImplicitRefs(0), parent(0) {
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000065 assert(MBB && "Cannot use inserting ctor with null basic block!");
66 operands.reserve(numOperands);
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000067 // Make sure that we get added to a machine basicblock
68 LeakDetector::addGarbageObject(this);
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000069 MBB->push_back(this); // Add instruction to end of basic block!
70}
71
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000072MachineInstr::~MachineInstr()
73{
74 LeakDetector::removeGarbageObject(this);
75}
76
Brian Gaeke21326fc2004-02-13 04:39:32 +000077/// OperandComplete - Return true if it's illegal to add a new operand
78///
Chris Lattner2a90ba62004-02-12 16:09:53 +000079bool MachineInstr::OperandsComplete() const {
80 int NumOperands = TargetInstrDescriptors[Opcode].numOperands;
Vikram S. Advea2bae302002-10-29 19:41:18 +000081 if (NumOperands >= 0 && getNumOperands() >= (unsigned)NumOperands)
Vikram S. Adve34977822003-05-31 07:39:06 +000082 return true; // Broken: we have all the operands of this instruction!
Chris Lattner413746e2002-10-28 20:48:39 +000083 return false;
84}
85
Brian Gaeke21326fc2004-02-13 04:39:32 +000086/// replace - Support for replacing opcode and operands of a MachineInstr in
87/// place. This only resets the size of the operand vector and initializes it.
88/// The new operands must be set explicitly later.
89///
Alkis Evlogimenosab8672c2004-02-12 18:49:07 +000090void MachineInstr::replace(short opcode, unsigned numOperands) {
Vikram S. Advea2bae302002-10-29 19:41:18 +000091 assert(getNumImplicitRefs() == 0 &&
92 "This is probably broken because implicit refs are going to be lost.");
Chris Lattner2a90ba62004-02-12 16:09:53 +000093 Opcode = opcode;
Vikram S. Advee8b57ef2002-09-20 00:47:49 +000094 operands.clear();
Chris Lattner413746e2002-10-28 20:48:39 +000095 operands.resize(numOperands, MachineOperand());
Vikram S. Advee8b57ef2002-09-20 00:47:49 +000096}
97
Chris Lattnera2dd7452003-08-05 16:58:46 +000098void MachineInstr::SetMachineOperandVal(unsigned i,
99 MachineOperand::MachineOperandType opTy,
100 Value* V) {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000101 assert(i < operands.size()); // may be explicit or implicit op
Chris Lattnera2dd7452003-08-05 16:58:46 +0000102 operands[i].opType = opTy;
Chris Lattner572f5c82002-10-28 04:24:49 +0000103 operands[i].value = V;
104 operands[i].regNum = -1;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000105}
106
107void
Chris Lattner572f5c82002-10-28 04:24:49 +0000108MachineInstr::SetMachineOperandConst(unsigned i,
Brian Gaeke21326fc2004-02-13 04:39:32 +0000109 MachineOperand::MachineOperandType opTy,
Chris Lattner2a90ba62004-02-12 16:09:53 +0000110 int64_t intValue) {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000111 assert(i < getNumOperands()); // must be explicit op
Chris Lattner2a90ba62004-02-12 16:09:53 +0000112 assert(TargetInstrDescriptors[Opcode].resultPos != (int) i &&
Vikram S. Advec356e562002-03-18 03:35:24 +0000113 "immed. constant cannot be defined");
Chris Lattner572f5c82002-10-28 04:24:49 +0000114
Brian Gaeke21326fc2004-02-13 04:39:32 +0000115 operands[i].opType = opTy;
Chris Lattner572f5c82002-10-28 04:24:49 +0000116 operands[i].value = NULL;
117 operands[i].immedVal = intValue;
118 operands[i].regNum = -1;
119 operands[i].flags = 0;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000120}
121
Chris Lattnera2dd7452003-08-05 16:58:46 +0000122void MachineInstr::SetMachineOperandReg(unsigned i, int regNum) {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000123 assert(i < getNumOperands()); // must be explicit op
Chris Lattner572f5c82002-10-28 04:24:49 +0000124
Chris Lattner2f305982002-10-28 19:46:59 +0000125 operands[i].opType = MachineOperand::MO_MachineRegister;
Chris Lattner572f5c82002-10-28 04:24:49 +0000126 operands[i].value = NULL;
127 operands[i].regNum = regNum;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000128}
129
Brian Gaeke21326fc2004-02-13 04:39:32 +0000130// Used only by the SPARC back-end.
Chris Lattner2a90ba62004-02-12 16:09:53 +0000131void MachineInstr::SetRegForOperand(unsigned i, int regNum) {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000132 assert(i < getNumOperands()); // must be explicit op
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000133 operands[i].setRegForValue(regNum);
Vikram S. Adve7a4be952002-07-08 22:38:45 +0000134}
135
Brian Gaeke21326fc2004-02-13 04:39:32 +0000136// Used only by the SPARC back-end.
Chris Lattner2a90ba62004-02-12 16:09:53 +0000137void MachineInstr::SetRegForImplicitRef(unsigned i, int regNum) {
Vikram S. Adve34977822003-05-31 07:39:06 +0000138 getImplicitOp(i).setRegForValue(regNum);
Vikram S. Adve34977822003-05-31 07:39:06 +0000139}
140
Brian Gaeke21326fc2004-02-13 04:39:32 +0000141/// substituteValue - Substitute all occurrences of Value* oldVal with newVal
142/// in all operands and all implicit refs. If defsOnly == true, substitute defs
143/// only.
144///
145/// FIXME: Fold this into its single caller, at SparcInstrSelection.cpp:2865,
146/// or make it a static function in that file.
147///
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000148unsigned
Vikram S. Adve627eb312003-07-10 19:45:07 +0000149MachineInstr::substituteValue(const Value* oldVal, Value* newVal,
150 bool defsOnly, bool notDefsAndUses,
151 bool& someArgsWereIgnored)
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000152{
Vikram S. Adve2010f7b2003-08-07 15:01:48 +0000153 assert((!defsOnly || !notDefsAndUses) &&
154 "notDefsAndUses is irrelevant if defsOnly == true.");
Vikram S. Adve627eb312003-07-10 19:45:07 +0000155
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000156 unsigned numSubst = 0;
157
Misha Brukman6eba07a2003-09-17 21:34:23 +0000158 // Substitute operands
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000159 for (MachineInstr::val_op_iterator O = begin(), E = end(); O != E; ++O)
160 if (*O == oldVal)
Vikram S. Adve627eb312003-07-10 19:45:07 +0000161 if (!defsOnly ||
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000162 notDefsAndUses && (O.isDef() && !O.isUse()) ||
163 !notDefsAndUses && O.isDef())
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000164 {
165 O.getMachineOperand().value = newVal;
166 ++numSubst;
167 }
Vikram S. Adve627eb312003-07-10 19:45:07 +0000168 else
169 someArgsWereIgnored = true;
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000170
Misha Brukman6eba07a2003-09-17 21:34:23 +0000171 // Substitute implicit refs
Vikram S. Advea2bae302002-10-29 19:41:18 +0000172 for (unsigned i=0, N=getNumImplicitRefs(); i < N; ++i)
Chris Lattner27a08932002-10-22 23:16:21 +0000173 if (getImplicitRef(i) == oldVal)
Vikram S. Adve627eb312003-07-10 19:45:07 +0000174 if (!defsOnly ||
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000175 notDefsAndUses && (getImplicitOp(i).isDef() && !getImplicitOp(i).isUse()) ||
176 !notDefsAndUses && getImplicitOp(i).isDef())
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000177 {
Vikram S. Advea2bae302002-10-29 19:41:18 +0000178 getImplicitOp(i).value = newVal;
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000179 ++numSubst;
180 }
Vikram S. Adve627eb312003-07-10 19:45:07 +0000181 else
182 someArgsWereIgnored = true;
Vikram S. Advee2a78e32002-08-14 16:52:58 +0000183
184 return numSubst;
185}
186
Brian Gaeke21326fc2004-02-13 04:39:32 +0000187void MachineInstr::dump() const {
Chris Lattner925b7712003-08-03 20:24:29 +0000188 std::cerr << " " << *this;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000189}
190
Brian Gaeke21326fc2004-02-13 04:39:32 +0000191static inline std::ostream& OutputValue(std::ostream &os, const Value* val) {
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000192 os << "(val ";
Vikram S. Adve627eb312003-07-10 19:45:07 +0000193 os << (void*) val; // print address always
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000194 if (val && val->hasName())
Brian Gaeke21326fc2004-02-13 04:39:32 +0000195 os << " " << val->getName(); // print name also, if available
196 os << ")";
Vikram S. Adve627eb312003-07-10 19:45:07 +0000197 return os;
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000198}
199
Chris Lattner2a79a092002-10-30 00:58:19 +0000200static inline void OutputReg(std::ostream &os, unsigned RegNo,
201 const MRegisterInfo *MRI = 0) {
Chris Lattner8517e1f2004-02-19 16:17:08 +0000202 if (MRegisterInfo::isPhysicalRegister(RegNo)) {
203 if (MRI)
Chris Lattner2a79a092002-10-30 00:58:19 +0000204 os << "%" << MRI->get(RegNo).Name;
205 else
Chris Lattner8517e1f2004-02-19 16:17:08 +0000206 os << "%mreg(" << RegNo << ")";
Chris Lattner2a79a092002-10-30 00:58:19 +0000207 } else
Chris Lattner8517e1f2004-02-19 16:17:08 +0000208 os << "%reg" << RegNo;
Vikram S. Adve8c6936a2002-09-16 15:18:53 +0000209}
210
Chris Lattner10491642002-10-30 00:48:05 +0000211static void print(const MachineOperand &MO, std::ostream &OS,
212 const TargetMachine &TM) {
Chris Lattner2a79a092002-10-30 00:58:19 +0000213 const MRegisterInfo *MRI = TM.getRegisterInfo();
Chris Lattner10491642002-10-30 00:48:05 +0000214 bool CloseParen = true;
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000215 if (MO.isHiBits32())
Chris Lattner10491642002-10-30 00:48:05 +0000216 OS << "%lm(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000217 else if (MO.isLoBits32())
Chris Lattner10491642002-10-30 00:48:05 +0000218 OS << "%lo(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000219 else if (MO.isHiBits64())
Chris Lattner10491642002-10-30 00:48:05 +0000220 OS << "%hh(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000221 else if (MO.isLoBits64())
Chris Lattner10491642002-10-30 00:48:05 +0000222 OS << "%hm(";
223 else
224 CloseParen = false;
225
226 switch (MO.getType()) {
227 case MachineOperand::MO_VirtualRegister:
228 if (MO.getVRegValue()) {
229 OS << "%reg";
230 OutputValue(OS, MO.getVRegValue());
231 if (MO.hasAllocatedReg())
232 OS << "==";
233 }
234 if (MO.hasAllocatedReg())
Alkis Evlogimenosbe766c72004-02-13 21:01:20 +0000235 OutputReg(OS, MO.getReg(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000236 break;
237 case MachineOperand::MO_CCRegister:
238 OS << "%ccreg";
239 OutputValue(OS, MO.getVRegValue());
240 if (MO.hasAllocatedReg()) {
241 OS << "==";
Alkis Evlogimenosbe766c72004-02-13 21:01:20 +0000242 OutputReg(OS, MO.getReg(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000243 }
244 break;
245 case MachineOperand::MO_MachineRegister:
Chris Lattner2a79a092002-10-30 00:58:19 +0000246 OutputReg(OS, MO.getMachineRegNum(), MRI);
Chris Lattner10491642002-10-30 00:48:05 +0000247 break;
248 case MachineOperand::MO_SignExtendedImmed:
249 OS << (long)MO.getImmedValue();
250 break;
251 case MachineOperand::MO_UnextendedImmed:
252 OS << (long)MO.getImmedValue();
253 break;
254 case MachineOperand::MO_PCRelativeDisp: {
255 const Value* opVal = MO.getVRegValue();
256 bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
257 OS << "%disp(" << (isLabel? "label " : "addr-of-val ");
258 if (opVal->hasName())
259 OS << opVal->getName();
260 else
261 OS << (const void*) opVal;
262 OS << ")";
263 break;
264 }
Chris Lattner2109f502002-12-15 20:35:25 +0000265 case MachineOperand::MO_MachineBasicBlock:
266 OS << "bb<"
267 << ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
268 << "," << (void*)MO.getMachineBasicBlock()->getBasicBlock() << ">";
269 break;
Chris Lattner10cb79b2002-12-28 20:37:37 +0000270 case MachineOperand::MO_FrameIndex:
271 OS << "<fi#" << MO.getFrameIndex() << ">";
272 break;
Chris Lattner8d95ef42003-01-13 00:23:24 +0000273 case MachineOperand::MO_ConstantPoolIndex:
274 OS << "<cp#" << MO.getConstantPoolIndex() << ">";
275 break;
276 case MachineOperand::MO_GlobalAddress:
277 OS << "<ga:" << ((Value*)MO.getGlobal())->getName() << ">";
278 break;
279 case MachineOperand::MO_ExternalSymbol:
280 OS << "<es:" << MO.getSymbolName() << ">";
281 break;
Chris Lattner10491642002-10-30 00:48:05 +0000282 default:
283 assert(0 && "Unrecognized operand type");
284 }
285
286 if (CloseParen)
287 OS << ")";
288}
289
Chris Lattneraf55be12002-11-17 23:22:13 +0000290void MachineInstr::print(std::ostream &OS, const TargetMachine &TM) const {
Chris Lattner6a592272002-10-30 01:55:38 +0000291 unsigned StartOp = 0;
Chris Lattner10491642002-10-30 00:48:05 +0000292
Chris Lattner6a592272002-10-30 01:55:38 +0000293 // Specialize printing if op#0 is definition
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000294 if (getNumOperands() && getOperand(0).isDef() && !getOperand(0).isUse()) {
Chris Lattner0742b592004-02-23 18:38:20 +0000295 ::print(getOperand(0), OS, TM);
Chris Lattner6a592272002-10-30 01:55:38 +0000296 OS << " = ";
297 ++StartOp; // Don't print this operand again!
298 }
299 OS << TM.getInstrInfo().getName(getOpcode());
300
301 for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000302 const MachineOperand& mop = getOperand(i);
Chris Lattner6a592272002-10-30 01:55:38 +0000303 if (i != StartOp)
304 OS << ",";
305 OS << " ";
Chris Lattner0742b592004-02-23 18:38:20 +0000306 ::print(mop, OS, TM);
Chris Lattner6a592272002-10-30 01:55:38 +0000307
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000308 if (mop.isDef())
309 if (mop.isUse())
310 OS << "<def&use>";
311 else
312 OS << "<def>";
Chris Lattner10491642002-10-30 00:48:05 +0000313 }
Chris Lattner6a592272002-10-30 01:55:38 +0000314
Misha Brukman6eba07a2003-09-17 21:34:23 +0000315 // code for printing implicit references
Chris Lattner10491642002-10-30 00:48:05 +0000316 if (getNumImplicitRefs()) {
317 OS << "\tImplicitRefs: ";
318 for(unsigned i = 0, e = getNumImplicitRefs(); i != e; ++i) {
319 OS << "\t";
Vikram S. Adve5f2180c2003-05-27 00:05:23 +0000320 OutputValue(OS, getImplicitRef(i));
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000321 if (getImplicitOp(i).isDef())
322 if (getImplicitOp(i).isUse())
323 OS << "<def&use>";
324 else
325 OS << "<def>";
Chris Lattner10491642002-10-30 00:48:05 +0000326 }
327 }
328
329 OS << "\n";
330}
331
Chris Lattner11d1f212004-02-23 18:40:08 +0000332namespace llvm {
Chris Lattner8517e1f2004-02-19 16:17:08 +0000333std::ostream &operator<<(std::ostream &os, const MachineInstr &MI) {
334 // If the instruction is embedded into a basic block, we can find the target
335 // info for the instruction.
336 if (const MachineBasicBlock *MBB = MI.getParent()) {
337 const MachineFunction *MF = MBB->getParent();
338 MI.print(os, MF->getTarget());
339 return os;
340 }
341
342 // Otherwise, print it out in the "raw" format without symbolic register names
343 // and such.
Chris Lattner2a90ba62004-02-12 16:09:53 +0000344 os << TargetInstrDescriptors[MI.getOpcode()].Name;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000345
Chris Lattner8d95ef42003-01-13 00:23:24 +0000346 for (unsigned i=0, N=MI.getNumOperands(); i < N; i++) {
347 os << "\t" << MI.getOperand(i);
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000348 if (MI.getOperand(i).isDef())
349 if (MI.getOperand(i).isUse())
350 os << "<d&u>";
351 else
352 os << "<d>";
Ruchira Sasanka8d243372001-11-14 20:05:23 +0000353 }
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000354
Misha Brukman6eba07a2003-09-17 21:34:23 +0000355 // code for printing implicit references
Chris Lattner8d95ef42003-01-13 00:23:24 +0000356 unsigned NumOfImpRefs = MI.getNumImplicitRefs();
357 if (NumOfImpRefs > 0) {
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000358 os << "\tImplicit: ";
Chris Lattner8d95ef42003-01-13 00:23:24 +0000359 for (unsigned z=0; z < NumOfImpRefs; z++) {
360 OutputValue(os, MI.getImplicitRef(z));
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000361 if (MI.getImplicitOp(z).isDef())
362 if (MI.getImplicitOp(z).isUse())
363 os << "<d&u>";
364 else
365 os << "<d>";
Ruchira Sasanka07c70862001-11-15 20:46:40 +0000366 os << "\t";
Ruchira Sasanka69917e22001-10-18 22:40:02 +0000367 }
368 }
Vikram S. Adve93240fe2002-04-25 04:31:18 +0000369
Chris Lattner697954c2002-01-20 22:54:45 +0000370 return os << "\n";
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000371}
372
Brian Gaeke21326fc2004-02-13 04:39:32 +0000373std::ostream &operator<<(std::ostream &OS, const MachineOperand &MO) {
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000374 if (MO.isHiBits32())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000375 OS << "%lm(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000376 else if (MO.isLoBits32())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000377 OS << "%lo(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000378 else if (MO.isHiBits64())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000379 OS << "%hh(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000380 else if (MO.isLoBits64())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000381 OS << "%hm(";
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000382
Chris Lattner2109f502002-12-15 20:35:25 +0000383 switch (MO.getType())
Vikram S. Adve6e447182001-09-18 12:56:28 +0000384 {
385 case MachineOperand::MO_VirtualRegister:
Chris Lattner8d95ef42003-01-13 00:23:24 +0000386 if (MO.hasAllocatedReg())
Alkis Evlogimenosbe766c72004-02-13 21:01:20 +0000387 OutputReg(OS, MO.getReg());
Chris Lattner8d95ef42003-01-13 00:23:24 +0000388
389 if (MO.getVRegValue()) {
390 if (MO.hasAllocatedReg()) OS << "==";
391 OS << "%vreg";
392 OutputValue(OS, MO.getVRegValue());
Chris Lattner10491642002-10-30 00:48:05 +0000393 }
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000394 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000395 case MachineOperand::MO_CCRegister:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000396 OS << "%ccreg";
397 OutputValue(OS, MO.getVRegValue());
Chris Lattner2109f502002-12-15 20:35:25 +0000398 if (MO.hasAllocatedReg()) {
Chris Lattner10cb79b2002-12-28 20:37:37 +0000399 OS << "==";
Alkis Evlogimenosbe766c72004-02-13 21:01:20 +0000400 OutputReg(OS, MO.getReg());
Chris Lattner10491642002-10-30 00:48:05 +0000401 }
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000402 break;
403 case MachineOperand::MO_MachineRegister:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000404 OutputReg(OS, MO.getMachineRegNum());
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000405 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000406 case MachineOperand::MO_SignExtendedImmed:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000407 OS << (long)MO.getImmedValue();
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000408 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000409 case MachineOperand::MO_UnextendedImmed:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000410 OS << (long)MO.getImmedValue();
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000411 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000412 case MachineOperand::MO_PCRelativeDisp:
Vikram S. Advee949da52001-09-30 23:44:19 +0000413 {
Chris Lattner2109f502002-12-15 20:35:25 +0000414 const Value* opVal = MO.getVRegValue();
Chris Lattner4d669b52002-04-08 22:01:15 +0000415 bool isLabel = isa<Function>(opVal) || isa<BasicBlock>(opVal);
Chris Lattner10cb79b2002-12-28 20:37:37 +0000416 OS << "%disp(" << (isLabel? "label " : "addr-of-val ");
Vikram S. Adved9beb972001-11-12 14:19:47 +0000417 if (opVal->hasName())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000418 OS << opVal->getName();
Vikram S. Adved9beb972001-11-12 14:19:47 +0000419 else
Chris Lattner10cb79b2002-12-28 20:37:37 +0000420 OS << (const void*) opVal;
421 OS << ")";
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000422 break;
Vikram S. Advee949da52001-09-30 23:44:19 +0000423 }
Chris Lattner2109f502002-12-15 20:35:25 +0000424 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner10cb79b2002-12-28 20:37:37 +0000425 OS << "bb<"
Chris Lattner2109f502002-12-15 20:35:25 +0000426 << ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
427 << "," << (void*)MO.getMachineBasicBlock()->getBasicBlock() << ">";
428 break;
Chris Lattner10cb79b2002-12-28 20:37:37 +0000429 case MachineOperand::MO_FrameIndex:
430 OS << "<fi#" << MO.getFrameIndex() << ">";
431 break;
Chris Lattner8d95ef42003-01-13 00:23:24 +0000432 case MachineOperand::MO_ConstantPoolIndex:
433 OS << "<cp#" << MO.getConstantPoolIndex() << ">";
434 break;
435 case MachineOperand::MO_GlobalAddress:
436 OS << "<ga:" << ((Value*)MO.getGlobal())->getName() << ">";
437 break;
438 case MachineOperand::MO_ExternalSymbol:
439 OS << "<es:" << MO.getSymbolName() << ">";
440 break;
Vikram S. Adve6e447182001-09-18 12:56:28 +0000441 default:
442 assert(0 && "Unrecognized operand type");
443 break;
444 }
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000445
Chris Lattner0742b592004-02-23 18:38:20 +0000446 if (MO.isHiBits32() || MO.isLoBits32() || MO.isHiBits64() || MO.isLoBits64())
Chris Lattner10cb79b2002-12-28 20:37:37 +0000447 OS << ")";
Vikram S. Adve3bc9ef92002-07-10 21:45:04 +0000448
Chris Lattner10cb79b2002-12-28 20:37:37 +0000449 return OS;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000450}
Brian Gaeked0fde302003-11-11 22:41:34 +0000451
Chris Lattner11d1f212004-02-23 18:40:08 +0000452}