blob: affde0ec6a49afba82326ef0979693a7f0c27b54 [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//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// 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//
Chris Lattner035dfbe2002-08-09 20:08:06 +000012//===----------------------------------------------------------------------===//
Vikram S. Adve70bc4b52001-07-21 12:41:50 +000013
Chris Lattner822b4fb2001-09-07 17:18:30 +000014#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner8517e1f2004-02-19 16:17:08 +000015#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner10491642002-10-30 00:48:05 +000016#include "llvm/Target/TargetMachine.h"
Chris Lattner3501fea2003-01-14 22:00:31 +000017#include "llvm/Target/TargetInstrInfo.h"
Chris Lattner2a79a092002-10-30 00:58:19 +000018#include "llvm/Target/MRegisterInfo.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000019#include "llvm/Support/LeakDetector.h"
Bill Wendlinga09362e2006-11-28 22:48:48 +000020#include "llvm/Support/Streams.h"
Jeff Cohenc21c5ee2006-12-15 22:57:14 +000021#include <ostream>
Chris Lattner0742b592004-02-23 18:38:20 +000022using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000023
Evan Chengc0f64ff2006-11-27 23:37:22 +000024/// MachineInstr ctor - This constructor creates a dummy MachineInstr with
Evan Cheng67f660c2006-11-30 07:08:44 +000025/// TID NULL and no operands.
Evan Chengc0f64ff2006-11-27 23:37:22 +000026MachineInstr::MachineInstr()
Evan Cheng67f660c2006-11-30 07:08:44 +000027 : TID(0), NumImplicitOps(0), parent(0) {
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000028 // Make sure that we get added to a machine basicblock
29 LeakDetector::addGarbageObject(this);
Chris Lattner72791222002-10-28 20:59:49 +000030}
31
Evan Cheng67f660c2006-11-30 07:08:44 +000032void MachineInstr::addImplicitDefUseOperands() {
33 if (TID->ImplicitDefs)
Chris Lattnera4161ee2007-12-30 00:12:25 +000034 for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs)
Chris Lattner8019f412007-12-30 00:41:17 +000035 addOperand(MachineOperand::CreateReg(*ImpDefs, true, true));
Evan Cheng67f660c2006-11-30 07:08:44 +000036 if (TID->ImplicitUses)
Chris Lattnera4161ee2007-12-30 00:12:25 +000037 for (const unsigned *ImpUses = TID->ImplicitUses; *ImpUses; ++ImpUses)
Chris Lattner8019f412007-12-30 00:41:17 +000038 addOperand(MachineOperand::CreateReg(*ImpUses, false, true));
Evan Chengd7de4962006-11-13 23:34:06 +000039}
40
41/// MachineInstr ctor - This constructor create a MachineInstr and add the
Evan Chengc0f64ff2006-11-27 23:37:22 +000042/// implicit operands. It reserves space for number of operands specified by
43/// TargetInstrDescriptor or the numOperands if it is not zero. (for
44/// instructions with variable number of operands).
Evan Chengfa945722007-10-13 02:23:01 +000045MachineInstr::MachineInstr(const TargetInstrDescriptor &tid, bool NoImp)
Evan Cheng67f660c2006-11-30 07:08:44 +000046 : TID(&tid), NumImplicitOps(0), parent(0) {
Evan Chengfa945722007-10-13 02:23:01 +000047 if (!NoImp && TID->ImplicitDefs)
Evan Cheng67f660c2006-11-30 07:08:44 +000048 for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs)
Evan Chengd7de4962006-11-13 23:34:06 +000049 NumImplicitOps++;
Evan Chengfa945722007-10-13 02:23:01 +000050 if (!NoImp && TID->ImplicitUses)
Evan Cheng67f660c2006-11-30 07:08:44 +000051 for (const unsigned *ImpUses = TID->ImplicitUses; *ImpUses; ++ImpUses)
Evan Chengd7de4962006-11-13 23:34:06 +000052 NumImplicitOps++;
Evan Cheng67f660c2006-11-30 07:08:44 +000053 Operands.reserve(NumImplicitOps + TID->numOperands);
Evan Chengfa945722007-10-13 02:23:01 +000054 if (!NoImp)
55 addImplicitDefUseOperands();
Evan Chengd7de4962006-11-13 23:34:06 +000056 // Make sure that we get added to a machine basicblock
57 LeakDetector::addGarbageObject(this);
58}
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///
Evan Chengc0f64ff2006-11-27 23:37:22 +000063MachineInstr::MachineInstr(MachineBasicBlock *MBB,
Evan Cheng67f660c2006-11-30 07:08:44 +000064 const TargetInstrDescriptor &tid)
65 : TID(&tid), NumImplicitOps(0), parent(0) {
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000066 assert(MBB && "Cannot use inserting ctor with null basic block!");
Evan Cheng67f660c2006-11-30 07:08:44 +000067 if (TID->ImplicitDefs)
68 for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs)
Evan Chengd7de4962006-11-13 23:34:06 +000069 NumImplicitOps++;
Evan Cheng67f660c2006-11-30 07:08:44 +000070 if (TID->ImplicitUses)
71 for (const unsigned *ImpUses = TID->ImplicitUses; *ImpUses; ++ImpUses)
Evan Chengd7de4962006-11-13 23:34:06 +000072 NumImplicitOps++;
Evan Cheng67f660c2006-11-30 07:08:44 +000073 Operands.reserve(NumImplicitOps + TID->numOperands);
74 addImplicitDefUseOperands();
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +000075 // Make sure that we get added to a machine basicblock
76 LeakDetector::addGarbageObject(this);
Chris Lattnerddd7fcb2002-10-29 23:19:00 +000077 MBB->push_back(this); // Add instruction to end of basic block!
78}
79
Misha Brukmance22e762004-07-09 14:45:17 +000080/// MachineInstr ctor - Copies MachineInstr arg exactly
81///
Tanya Lattner466b5342004-05-23 19:35:12 +000082MachineInstr::MachineInstr(const MachineInstr &MI) {
Evan Cheng67f660c2006-11-30 07:08:44 +000083 TID = MI.getInstrDescriptor();
Evan Cheng6b2c05f2006-11-15 20:54:29 +000084 NumImplicitOps = MI.NumImplicitOps;
Chris Lattner943b5e12006-05-04 19:14:44 +000085 Operands.reserve(MI.getNumOperands());
Tanya Lattnerb5159ed2004-05-23 20:58:02 +000086
Misha Brukmance22e762004-07-09 14:45:17 +000087 // Add operands
Chris Lattnere12d6ab2007-12-30 06:11:04 +000088 for (unsigned i = 0; i != MI.getNumOperands(); ++i) {
Chris Lattner943b5e12006-05-04 19:14:44 +000089 Operands.push_back(MI.getOperand(i));
Chris Lattnere12d6ab2007-12-30 06:11:04 +000090 Operands.back().ParentMI = this;
91 }
Tanya Lattner0c63e032004-05-24 03:14:18 +000092
Misha Brukmance22e762004-07-09 14:45:17 +000093 // Set parent, next, and prev to null
Tanya Lattner0c63e032004-05-24 03:14:18 +000094 parent = 0;
95 prev = 0;
96 next = 0;
Tanya Lattner466b5342004-05-23 19:35:12 +000097}
98
99
Misha Brukmance22e762004-07-09 14:45:17 +0000100MachineInstr::~MachineInstr() {
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +0000101 LeakDetector::removeGarbageObject(this);
Chris Lattnere12d6ab2007-12-30 06:11:04 +0000102#ifndef NDEBUG
103 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
104 assert(Operands[i].ParentMI == this && "ParentMI mismatch!");
105#endif
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +0000106}
107
Evan Cheng67f660c2006-11-30 07:08:44 +0000108/// getOpcode - Returns the opcode of this MachineInstr.
109///
Dan Gohmancb648f92007-09-14 20:08:19 +0000110int MachineInstr::getOpcode() const {
Evan Cheng67f660c2006-11-30 07:08:44 +0000111 return TID->Opcode;
112}
113
Chris Lattner48d7c062006-04-17 21:35:41 +0000114/// removeFromParent - This method unlinks 'this' from the containing basic
115/// block, and returns it, but does not delete it.
116MachineInstr *MachineInstr::removeFromParent() {
117 assert(getParent() && "Not embedded in a basic block!");
118 getParent()->remove(this);
119 return this;
120}
121
122
Brian Gaeke21326fc2004-02-13 04:39:32 +0000123/// OperandComplete - Return true if it's illegal to add a new operand
124///
Chris Lattner2a90ba62004-02-12 16:09:53 +0000125bool MachineInstr::OperandsComplete() const {
Evan Cheng67f660c2006-11-30 07:08:44 +0000126 unsigned short NumOperands = TID->numOperands;
127 if ((TID->Flags & M_VARIABLE_OPS) == 0 &&
Evan Cheng8bcb0422006-11-28 02:25:34 +0000128 getNumOperands()-NumImplicitOps >= NumOperands)
Vikram S. Adve34977822003-05-31 07:39:06 +0000129 return true; // Broken: we have all the operands of this instruction!
Chris Lattner413746e2002-10-28 20:48:39 +0000130 return false;
131}
132
Evan Cheng19e3f312007-05-15 01:26:09 +0000133/// getNumExplicitOperands - Returns the number of non-implicit operands.
134///
135unsigned MachineInstr::getNumExplicitOperands() const {
136 unsigned NumOperands = TID->numOperands;
137 if ((TID->Flags & M_VARIABLE_OPS) == 0)
138 return NumOperands;
139
140 for (unsigned e = getNumOperands(); NumOperands != e; ++NumOperands) {
141 const MachineOperand &MO = getOperand(NumOperands);
142 if (!MO.isRegister() || !MO.isImplicit())
143 NumOperands++;
144 }
145 return NumOperands;
146}
147
Chris Lattner8ace2cd2006-10-20 22:39:59 +0000148/// isIdenticalTo - Return true if this operand is identical to the specified
149/// operand.
150bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
151 if (getType() != Other.getType()) return false;
152
153 switch (getType()) {
154 default: assert(0 && "Unrecognized operand type");
155 case MachineOperand::MO_Register:
Chris Lattner0974d9a2007-12-30 20:55:08 +0000156 return getReg() == Other.getReg() && isDef() == Other.isDef() &&
157 getSubReg() == Other.getSubReg();
Chris Lattner8ace2cd2006-10-20 22:39:59 +0000158 case MachineOperand::MO_Immediate:
159 return getImm() == Other.getImm();
160 case MachineOperand::MO_MachineBasicBlock:
161 return getMBB() == Other.getMBB();
162 case MachineOperand::MO_FrameIndex:
163 return getFrameIndex() == Other.getFrameIndex();
164 case MachineOperand::MO_ConstantPoolIndex:
165 return getConstantPoolIndex() == Other.getConstantPoolIndex() &&
166 getOffset() == Other.getOffset();
167 case MachineOperand::MO_JumpTableIndex:
168 return getJumpTableIndex() == Other.getJumpTableIndex();
169 case MachineOperand::MO_GlobalAddress:
170 return getGlobal() == Other.getGlobal() && getOffset() == Other.getOffset();
171 case MachineOperand::MO_ExternalSymbol:
Chris Lattner13a04122006-10-25 18:08:14 +0000172 return !strcmp(getSymbolName(), Other.getSymbolName()) &&
Chris Lattner8ace2cd2006-10-20 22:39:59 +0000173 getOffset() == Other.getOffset();
174 }
175}
176
Evan Chengfaa51072007-04-26 19:00:32 +0000177/// findRegisterUseOperandIdx() - Returns the MachineOperand that is a use of
Evan Cheng32eb1f12007-03-26 22:37:45 +0000178/// the specific register or -1 if it is not found. It further tightening
Evan Cheng76d7e762007-02-23 01:04:26 +0000179/// the search criteria to a use that kills the register if isKill is true.
Evan Chengf277ee42007-05-29 18:35:22 +0000180int MachineInstr::findRegisterUseOperandIdx(unsigned Reg, bool isKill) const {
Evan Cheng576d1232006-12-06 08:27:42 +0000181 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
Evan Chengf277ee42007-05-29 18:35:22 +0000182 const MachineOperand &MO = getOperand(i);
Dan Gohman92dfe202007-09-14 20:33:02 +0000183 if (MO.isRegister() && MO.isUse() && MO.getReg() == Reg)
Evan Cheng76d7e762007-02-23 01:04:26 +0000184 if (!isKill || MO.isKill())
Evan Cheng32eb1f12007-03-26 22:37:45 +0000185 return i;
Evan Cheng576d1232006-12-06 08:27:42 +0000186 }
Evan Cheng32eb1f12007-03-26 22:37:45 +0000187 return -1;
Evan Cheng576d1232006-12-06 08:27:42 +0000188}
189
Evan Chengb371f452007-02-19 21:49:54 +0000190/// findRegisterDefOperand() - Returns the MachineOperand that is a def of
191/// the specific register or NULL if it is not found.
192MachineOperand *MachineInstr::findRegisterDefOperand(unsigned Reg) {
193 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
194 MachineOperand &MO = getOperand(i);
Dan Gohman92dfe202007-09-14 20:33:02 +0000195 if (MO.isRegister() && MO.isDef() && MO.getReg() == Reg)
Evan Chengb371f452007-02-19 21:49:54 +0000196 return &MO;
197 }
198 return NULL;
199}
Evan Cheng19e3f312007-05-15 01:26:09 +0000200
Evan Chengf277ee42007-05-29 18:35:22 +0000201/// findFirstPredOperandIdx() - Find the index of the first operand in the
202/// operand list that is used to represent the predicate. It returns -1 if
203/// none is found.
204int MachineInstr::findFirstPredOperandIdx() const {
Evan Cheng19e3f312007-05-15 01:26:09 +0000205 const TargetInstrDescriptor *TID = getInstrDescriptor();
Evan Chengc3a289c2007-05-16 20:56:08 +0000206 if (TID->Flags & M_PREDICABLE) {
Evan Cheng19e3f312007-05-15 01:26:09 +0000207 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
208 if ((TID->OpInfo[i].Flags & M_PREDICATE_OPERAND))
Evan Chengf277ee42007-05-29 18:35:22 +0000209 return i;
Evan Cheng19e3f312007-05-15 01:26:09 +0000210 }
211
Evan Chengf277ee42007-05-29 18:35:22 +0000212 return -1;
Evan Cheng19e3f312007-05-15 01:26:09 +0000213}
Evan Chengb371f452007-02-19 21:49:54 +0000214
Evan Cheng32dfbea2007-10-12 08:50:34 +0000215/// isRegReDefinedByTwoAddr - Returns true if the Reg re-definition is due
216/// to two addr elimination.
217bool MachineInstr::isRegReDefinedByTwoAddr(unsigned Reg) const {
218 const TargetInstrDescriptor *TID = getInstrDescriptor();
219 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
220 const MachineOperand &MO1 = getOperand(i);
221 if (MO1.isRegister() && MO1.isDef() && MO1.getReg() == Reg) {
222 for (unsigned j = i+1; j < e; ++j) {
223 const MachineOperand &MO2 = getOperand(j);
224 if (MO2.isRegister() && MO2.isUse() && MO2.getReg() == Reg &&
225 TID->getOperandConstraint(j, TOI::TIED_TO) == (int)i)
226 return true;
227 }
228 }
229 }
230 return false;
231}
232
Evan Cheng576d1232006-12-06 08:27:42 +0000233/// copyKillDeadInfo - Copies kill / dead operand properties from MI.
234///
235void MachineInstr::copyKillDeadInfo(const MachineInstr *MI) {
236 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
237 const MachineOperand &MO = MI->getOperand(i);
Dan Gohman92dfe202007-09-14 20:33:02 +0000238 if (!MO.isRegister() || (!MO.isKill() && !MO.isDead()))
Evan Cheng576d1232006-12-06 08:27:42 +0000239 continue;
240 for (unsigned j = 0, ee = getNumOperands(); j != ee; ++j) {
241 MachineOperand &MOp = getOperand(j);
242 if (!MOp.isIdenticalTo(MO))
243 continue;
244 if (MO.isKill())
245 MOp.setIsKill();
246 else
247 MOp.setIsDead();
248 break;
249 }
250 }
251}
252
Evan Cheng19e3f312007-05-15 01:26:09 +0000253/// copyPredicates - Copies predicate operand(s) from MI.
254void MachineInstr::copyPredicates(const MachineInstr *MI) {
255 const TargetInstrDescriptor *TID = MI->getInstrDescriptor();
Evan Chengc3a289c2007-05-16 20:56:08 +0000256 if (TID->Flags & M_PREDICABLE) {
Evan Cheng19e3f312007-05-15 01:26:09 +0000257 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
258 if ((TID->OpInfo[i].Flags & M_PREDICATE_OPERAND)) {
Evan Cheng19e3f312007-05-15 01:26:09 +0000259 // Predicated operands must be last operands.
Chris Lattner8019f412007-12-30 00:41:17 +0000260 addOperand(MI->getOperand(i));
Evan Cheng19e3f312007-05-15 01:26:09 +0000261 }
262 }
263 }
264}
265
Brian Gaeke21326fc2004-02-13 04:39:32 +0000266void MachineInstr::dump() const {
Bill Wendlinge8156192006-12-07 01:30:32 +0000267 cerr << " " << *this;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000268}
269
Chris Lattnere3087892007-12-30 21:31:53 +0000270/// print - Print the specified machine operand.
271///
Chris Lattner10491642002-10-30 00:48:05 +0000272static void print(const MachineOperand &MO, std::ostream &OS,
Tanya Lattnerb1407622004-06-25 00:13:11 +0000273 const TargetMachine *TM) {
Chris Lattner10491642002-10-30 00:48:05 +0000274 switch (MO.getType()) {
Chris Lattner2d90ac72006-05-04 18:05:43 +0000275 case MachineOperand::MO_Register:
Chris Lattnere26dcfe2007-12-30 21:08:36 +0000276 if (MO.getReg() == 0 || MRegisterInfo::isVirtualRegister(MO.getReg()))
277 OS << "%reg" << MO.getReg();
Chris Lattnere3087892007-12-30 21:31:53 +0000278 else {
279 // If the instruction is embedded into a basic block, we can find the
280 // target
281 // info for the instruction.
282 if (TM == 0)
283 if (const MachineInstr *MI = MO.getParent())
284 if (const MachineBasicBlock *MBB = MI->getParent())
285 if (const MachineFunction *MF = MBB->getParent())
286 TM = &MF->getTarget();
287
288 if (TM)
289 OS << "%" << TM->getRegisterInfo()->get(MO.getReg()).Name;
290 else
291 OS << "%mreg" << MO.getReg();
292 }
293
294 if (MO.isDef() || MO.isKill() || MO.isDead() || MO.isImplicit()) {
295 OS << "<";
296 bool NeedComma = false;
297 if (MO.isImplicit()) {
298 OS << (MO.isDef() ? "imp-def" : "imp-use");
299 NeedComma = true;
300 } else if (MO.isDef()) {
301 OS << "def";
302 NeedComma = true;
303 }
304 if (MO.isKill() || MO.isDead()) {
305 if (NeedComma) OS << ",";
306 if (MO.isKill()) OS << "kill";
307 if (MO.isDead()) OS << "dead";
308 }
309 OS << ">";
310 }
Chris Lattner10491642002-10-30 00:48:05 +0000311 break;
Chris Lattner63b3d712006-05-04 17:21:20 +0000312 case MachineOperand::MO_Immediate:
Chris Lattner9e330492007-12-30 20:50:28 +0000313 OS << MO.getImm();
Chris Lattner10491642002-10-30 00:48:05 +0000314 break;
Chris Lattner2109f502002-12-15 20:35:25 +0000315 case MachineOperand::MO_MachineBasicBlock:
Brian Gaeke988b7ba2004-06-17 22:26:53 +0000316 OS << "mbb<"
Chris Lattner2109f502002-12-15 20:35:25 +0000317 << ((Value*)MO.getMachineBasicBlock()->getBasicBlock())->getName()
Brian Gaeke988b7ba2004-06-17 22:26:53 +0000318 << "," << (void*)MO.getMachineBasicBlock() << ">";
Chris Lattner2109f502002-12-15 20:35:25 +0000319 break;
Chris Lattner10cb79b2002-12-28 20:37:37 +0000320 case MachineOperand::MO_FrameIndex:
321 OS << "<fi#" << MO.getFrameIndex() << ">";
322 break;
Chris Lattner8d95ef42003-01-13 00:23:24 +0000323 case MachineOperand::MO_ConstantPoolIndex:
Chris Lattner7da53132007-12-30 21:03:30 +0000324 OS << "<cp#" << MO.getConstantPoolIndex();
325 if (MO.getOffset()) OS << "+" << MO.getOffset();
326 OS << ">";
Chris Lattner8d95ef42003-01-13 00:23:24 +0000327 break;
Nate Begeman37efe672006-04-22 18:53:45 +0000328 case MachineOperand::MO_JumpTableIndex:
329 OS << "<jt#" << MO.getJumpTableIndex() << ">";
330 break;
Chris Lattner8d95ef42003-01-13 00:23:24 +0000331 case MachineOperand::MO_GlobalAddress:
Chris Lattnerca4f6eb2004-10-15 04:38:41 +0000332 OS << "<ga:" << ((Value*)MO.getGlobal())->getName();
333 if (MO.getOffset()) OS << "+" << MO.getOffset();
334 OS << ">";
Chris Lattner8d95ef42003-01-13 00:23:24 +0000335 break;
336 case MachineOperand::MO_ExternalSymbol:
Chris Lattnerca4f6eb2004-10-15 04:38:41 +0000337 OS << "<es:" << MO.getSymbolName();
338 if (MO.getOffset()) OS << "+" << MO.getOffset();
339 OS << ">";
Chris Lattner8d95ef42003-01-13 00:23:24 +0000340 break;
Chris Lattner10491642002-10-30 00:48:05 +0000341 default:
342 assert(0 && "Unrecognized operand type");
343 }
Chris Lattner10491642002-10-30 00:48:05 +0000344}
345
Tanya Lattnerb1407622004-06-25 00:13:11 +0000346void MachineInstr::print(std::ostream &OS, const TargetMachine *TM) const {
Chris Lattnere3087892007-12-30 21:31:53 +0000347 // Specialize printing if op#0 is definition
Chris Lattner6a592272002-10-30 01:55:38 +0000348 unsigned StartOp = 0;
Dan Gohman92dfe202007-09-14 20:33:02 +0000349 if (getNumOperands() && getOperand(0).isRegister() && getOperand(0).isDef()) {
Chris Lattner0742b592004-02-23 18:38:20 +0000350 ::print(getOperand(0), OS, TM);
Chris Lattner6a592272002-10-30 01:55:38 +0000351 OS << " = ";
352 ++StartOp; // Don't print this operand again!
353 }
Tanya Lattnerb1407622004-06-25 00:13:11 +0000354
Chris Lattnere3087892007-12-30 21:31:53 +0000355 OS << getInstrDescriptor()->Name;
Misha Brukmanedf128a2005-04-21 22:36:52 +0000356
Chris Lattner6a592272002-10-30 01:55:38 +0000357 for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
358 if (i != StartOp)
359 OS << ",";
360 OS << " ";
Chris Lattnere3087892007-12-30 21:31:53 +0000361 ::print(getOperand(i), OS, TM);
Chris Lattner10491642002-10-30 00:48:05 +0000362 }
Misha Brukmanedf128a2005-04-21 22:36:52 +0000363
Chris Lattner10491642002-10-30 00:48:05 +0000364 OS << "\n";
365}
366
Jeff Cohen4b607742006-12-16 02:15:42 +0000367void MachineOperand::print(std::ostream &OS) const {
Chris Lattner7da53132007-12-30 21:03:30 +0000368 ::print(*this, OS, 0);
Jeff Cohenc21c5ee2006-12-15 22:57:14 +0000369}
370