blob: 006a10a0ce69110b40d0529ec8d68e4276140efa [file] [log] [blame]
Chris Lattnere138b3d2008-01-01 20:36:19 +00001//===-- lib/CodeGen/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"
Evan Chengfb112882009-03-23 08:01:15 +000015#include "llvm/Constants.h"
16#include "llvm/InlineAsm.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000017#include "llvm/Value.h"
Chris Lattner8517e1f2004-02-19 16:17:08 +000018#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner62ed6b92008-01-01 01:12:31 +000019#include "llvm/CodeGen/MachineRegisterInfo.h"
Dan Gohman69de1932008-02-06 22:27:42 +000020#include "llvm/CodeGen/PseudoSourceValue.h"
Chris Lattner10491642002-10-30 00:48:05 +000021#include "llvm/Target/TargetMachine.h"
Evan Chengbb81d972008-01-31 09:59:15 +000022#include "llvm/Target/TargetInstrInfo.h"
Chris Lattnerf14cf852008-01-07 07:42:25 +000023#include "llvm/Target/TargetInstrDesc.h"
Dan Gohman6f0d0242008-02-10 18:45:23 +000024#include "llvm/Target/TargetRegisterInfo.h"
Argyrios Kyrtzidisa26eae62009-04-30 23:22:31 +000025#include "llvm/Analysis/DebugInfo.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000026#include "llvm/Support/ErrorHandling.h"
Dan Gohman2c3f7ae2008-07-17 23:49:46 +000027#include "llvm/Support/LeakDetector.h"
Dan Gohmance42e402008-07-07 20:32:02 +000028#include "llvm/Support/MathExtras.h"
Bill Wendlinga09362e2006-11-28 22:48:48 +000029#include "llvm/Support/Streams.h"
Chris Lattneredfb72c2008-08-24 20:37:32 +000030#include "llvm/Support/raw_ostream.h"
Dan Gohmanb8d2f552008-08-20 15:58:01 +000031#include "llvm/ADT/FoldingSet.h"
Chris Lattner0742b592004-02-23 18:38:20 +000032using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000033
Chris Lattnerf7382302007-12-30 21:56:09 +000034//===----------------------------------------------------------------------===//
35// MachineOperand Implementation
36//===----------------------------------------------------------------------===//
37
Chris Lattner62ed6b92008-01-01 01:12:31 +000038/// AddRegOperandToRegInfo - Add this register operand to the specified
39/// MachineRegisterInfo. If it is null, then the next/prev fields should be
40/// explicitly nulled out.
41void MachineOperand::AddRegOperandToRegInfo(MachineRegisterInfo *RegInfo) {
Dan Gohmand735b802008-10-03 15:45:36 +000042 assert(isReg() && "Can only add reg operand to use lists");
Chris Lattner62ed6b92008-01-01 01:12:31 +000043
44 // If the reginfo pointer is null, just explicitly null out or next/prev
45 // pointers, to ensure they are not garbage.
46 if (RegInfo == 0) {
47 Contents.Reg.Prev = 0;
48 Contents.Reg.Next = 0;
49 return;
50 }
51
52 // Otherwise, add this operand to the head of the registers use/def list.
Chris Lattner80fe5312008-01-01 21:08:22 +000053 MachineOperand **Head = &RegInfo->getRegUseDefListHead(getReg());
Chris Lattner62ed6b92008-01-01 01:12:31 +000054
Chris Lattner80fe5312008-01-01 21:08:22 +000055 // For SSA values, we prefer to keep the definition at the start of the list.
56 // we do this by skipping over the definition if it is at the head of the
57 // list.
58 if (*Head && (*Head)->isDef())
59 Head = &(*Head)->Contents.Reg.Next;
60
61 Contents.Reg.Next = *Head;
Chris Lattner62ed6b92008-01-01 01:12:31 +000062 if (Contents.Reg.Next) {
63 assert(getReg() == Contents.Reg.Next->getReg() &&
64 "Different regs on the same list!");
65 Contents.Reg.Next->Contents.Reg.Prev = &Contents.Reg.Next;
66 }
67
Chris Lattner80fe5312008-01-01 21:08:22 +000068 Contents.Reg.Prev = Head;
69 *Head = this;
Chris Lattner62ed6b92008-01-01 01:12:31 +000070}
71
Dan Gohman3bc1a372009-04-15 01:17:37 +000072/// RemoveRegOperandFromRegInfo - Remove this register operand from the
73/// MachineRegisterInfo it is linked with.
74void MachineOperand::RemoveRegOperandFromRegInfo() {
75 assert(isOnRegUseList() && "Reg operand is not on a use list");
76 // Unlink this from the doubly linked list of operands.
77 MachineOperand *NextOp = Contents.Reg.Next;
78 *Contents.Reg.Prev = NextOp;
79 if (NextOp) {
80 assert(NextOp->getReg() == getReg() && "Corrupt reg use/def chain!");
81 NextOp->Contents.Reg.Prev = Contents.Reg.Prev;
82 }
83 Contents.Reg.Prev = 0;
84 Contents.Reg.Next = 0;
85}
86
Chris Lattner62ed6b92008-01-01 01:12:31 +000087void MachineOperand::setReg(unsigned Reg) {
88 if (getReg() == Reg) return; // No change.
89
90 // Otherwise, we have to change the register. If this operand is embedded
91 // into a machine function, we need to update the old and new register's
92 // use/def lists.
93 if (MachineInstr *MI = getParent())
94 if (MachineBasicBlock *MBB = MI->getParent())
95 if (MachineFunction *MF = MBB->getParent()) {
96 RemoveRegOperandFromRegInfo();
97 Contents.Reg.RegNo = Reg;
98 AddRegOperandToRegInfo(&MF->getRegInfo());
99 return;
100 }
101
102 // Otherwise, just change the register, no problem. :)
103 Contents.Reg.RegNo = Reg;
104}
105
106/// ChangeToImmediate - Replace this operand with a new immediate operand of
107/// the specified value. If an operand is known to be an immediate already,
108/// the setImm method should be used.
109void MachineOperand::ChangeToImmediate(int64_t ImmVal) {
110 // If this operand is currently a register operand, and if this is in a
111 // function, deregister the operand from the register's use/def list.
Dan Gohmand735b802008-10-03 15:45:36 +0000112 if (isReg() && getParent() && getParent()->getParent() &&
Chris Lattner62ed6b92008-01-01 01:12:31 +0000113 getParent()->getParent()->getParent())
114 RemoveRegOperandFromRegInfo();
115
116 OpKind = MO_Immediate;
117 Contents.ImmVal = ImmVal;
118}
119
120/// ChangeToRegister - Replace this operand with a new register operand of
121/// the specified value. If an operand is known to be an register already,
122/// the setReg method should be used.
123void MachineOperand::ChangeToRegister(unsigned Reg, bool isDef, bool isImp,
Evan Cheng4784f1f2009-06-30 08:49:04 +0000124 bool isKill, bool isDead, bool isUndef) {
Chris Lattner62ed6b92008-01-01 01:12:31 +0000125 // If this operand is already a register operand, use setReg to update the
126 // register's use/def lists.
Dan Gohmand735b802008-10-03 15:45:36 +0000127 if (isReg()) {
Dale Johannesene0091802008-09-14 01:44:36 +0000128 assert(!isEarlyClobber());
Chris Lattner62ed6b92008-01-01 01:12:31 +0000129 setReg(Reg);
130 } else {
131 // Otherwise, change this to a register and set the reg#.
132 OpKind = MO_Register;
133 Contents.Reg.RegNo = Reg;
134
135 // If this operand is embedded in a function, add the operand to the
136 // register's use/def list.
137 if (MachineInstr *MI = getParent())
138 if (MachineBasicBlock *MBB = MI->getParent())
139 if (MachineFunction *MF = MBB->getParent())
140 AddRegOperandToRegInfo(&MF->getRegInfo());
141 }
142
143 IsDef = isDef;
144 IsImp = isImp;
145 IsKill = isKill;
146 IsDead = isDead;
Evan Cheng4784f1f2009-06-30 08:49:04 +0000147 IsUndef = isUndef;
Dale Johannesene0091802008-09-14 01:44:36 +0000148 IsEarlyClobber = false;
Chris Lattner62ed6b92008-01-01 01:12:31 +0000149 SubReg = 0;
150}
151
Chris Lattnerf7382302007-12-30 21:56:09 +0000152/// isIdenticalTo - Return true if this operand is identical to the specified
153/// operand.
154bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
Chris Lattner31530612009-06-24 17:54:48 +0000155 if (getType() != Other.getType() ||
156 getTargetFlags() != Other.getTargetFlags())
157 return false;
Chris Lattnerf7382302007-12-30 21:56:09 +0000158
159 switch (getType()) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000160 default: llvm_unreachable("Unrecognized operand type");
Chris Lattnerf7382302007-12-30 21:56:09 +0000161 case MachineOperand::MO_Register:
162 return getReg() == Other.getReg() && isDef() == Other.isDef() &&
163 getSubReg() == Other.getSubReg();
164 case MachineOperand::MO_Immediate:
165 return getImm() == Other.getImm();
Nate Begemane8b7ccf2008-02-14 07:39:30 +0000166 case MachineOperand::MO_FPImmediate:
167 return getFPImm() == Other.getFPImm();
Chris Lattnerf7382302007-12-30 21:56:09 +0000168 case MachineOperand::MO_MachineBasicBlock:
169 return getMBB() == Other.getMBB();
170 case MachineOperand::MO_FrameIndex:
Chris Lattner8aa797a2007-12-30 23:10:15 +0000171 return getIndex() == Other.getIndex();
Chris Lattnerf7382302007-12-30 21:56:09 +0000172 case MachineOperand::MO_ConstantPoolIndex:
Chris Lattner8aa797a2007-12-30 23:10:15 +0000173 return getIndex() == Other.getIndex() && getOffset() == Other.getOffset();
Chris Lattnerf7382302007-12-30 21:56:09 +0000174 case MachineOperand::MO_JumpTableIndex:
Chris Lattner8aa797a2007-12-30 23:10:15 +0000175 return getIndex() == Other.getIndex();
Chris Lattnerf7382302007-12-30 21:56:09 +0000176 case MachineOperand::MO_GlobalAddress:
177 return getGlobal() == Other.getGlobal() && getOffset() == Other.getOffset();
178 case MachineOperand::MO_ExternalSymbol:
179 return !strcmp(getSymbolName(), Other.getSymbolName()) &&
180 getOffset() == Other.getOffset();
181 }
182}
183
184/// print - Print the specified machine operand.
185///
186void MachineOperand::print(std::ostream &OS, const TargetMachine *TM) const {
Mon P Wang5ca6bd12008-10-10 01:43:55 +0000187 raw_os_ostream RawOS(OS);
188 print(RawOS, TM);
189}
190
191void MachineOperand::print(raw_ostream &OS, const TargetMachine *TM) const {
Chris Lattnerf7382302007-12-30 21:56:09 +0000192 switch (getType()) {
193 case MachineOperand::MO_Register:
Dan Gohman6f0d0242008-02-10 18:45:23 +0000194 if (getReg() == 0 || TargetRegisterInfo::isVirtualRegister(getReg())) {
Chris Lattnerf7382302007-12-30 21:56:09 +0000195 OS << "%reg" << getReg();
196 } else {
197 // If the instruction is embedded into a basic block, we can find the
Chris Lattner62ed6b92008-01-01 01:12:31 +0000198 // target info for the instruction.
Chris Lattnerf7382302007-12-30 21:56:09 +0000199 if (TM == 0)
200 if (const MachineInstr *MI = getParent())
201 if (const MachineBasicBlock *MBB = MI->getParent())
202 if (const MachineFunction *MF = MBB->getParent())
203 TM = &MF->getTarget();
204
205 if (TM)
Bill Wendlinge6d088a2008-02-26 21:47:57 +0000206 OS << "%" << TM->getRegisterInfo()->get(getReg()).Name;
Chris Lattnerf7382302007-12-30 21:56:09 +0000207 else
208 OS << "%mreg" << getReg();
209 }
Dan Gohman2ccc8392008-12-18 21:51:27 +0000210
Evan Cheng4784f1f2009-06-30 08:49:04 +0000211 if (getSubReg() != 0)
Chris Lattner31530612009-06-24 17:54:48 +0000212 OS << ':' << getSubReg();
Dan Gohman2ccc8392008-12-18 21:51:27 +0000213
Evan Cheng4784f1f2009-06-30 08:49:04 +0000214 if (isDef() || isKill() || isDead() || isImplicit() || isUndef() ||
215 isEarlyClobber()) {
Chris Lattner31530612009-06-24 17:54:48 +0000216 OS << '<';
Chris Lattnerf7382302007-12-30 21:56:09 +0000217 bool NeedComma = false;
218 if (isImplicit()) {
Chris Lattner31530612009-06-24 17:54:48 +0000219 if (NeedComma) OS << ',';
Chris Lattnerf7382302007-12-30 21:56:09 +0000220 OS << (isDef() ? "imp-def" : "imp-use");
221 NeedComma = true;
222 } else if (isDef()) {
Chris Lattner31530612009-06-24 17:54:48 +0000223 if (NeedComma) OS << ',';
Dale Johannesen913d3df2008-09-12 17:49:03 +0000224 if (isEarlyClobber())
225 OS << "earlyclobber,";
Chris Lattnerf7382302007-12-30 21:56:09 +0000226 OS << "def";
227 NeedComma = true;
228 }
Evan Cheng4784f1f2009-06-30 08:49:04 +0000229 if (isKill() || isDead() || isUndef()) {
Chris Lattner31530612009-06-24 17:54:48 +0000230 if (NeedComma) OS << ',';
Bill Wendling181eb732008-02-24 00:56:13 +0000231 if (isKill()) OS << "kill";
232 if (isDead()) OS << "dead";
Evan Cheng4784f1f2009-06-30 08:49:04 +0000233 if (isUndef()) {
234 if (isKill() || isDead())
235 OS << ',';
236 OS << "undef";
237 }
Chris Lattnerf7382302007-12-30 21:56:09 +0000238 }
Chris Lattner31530612009-06-24 17:54:48 +0000239 OS << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000240 }
241 break;
242 case MachineOperand::MO_Immediate:
243 OS << getImm();
244 break;
Nate Begemane8b7ccf2008-02-14 07:39:30 +0000245 case MachineOperand::MO_FPImmediate:
Chris Lattner31530612009-06-24 17:54:48 +0000246 if (getFPImm()->getType() == Type::FloatTy)
Nate Begemane8b7ccf2008-02-14 07:39:30 +0000247 OS << getFPImm()->getValueAPF().convertToFloat();
Chris Lattner31530612009-06-24 17:54:48 +0000248 else
Nate Begemane8b7ccf2008-02-14 07:39:30 +0000249 OS << getFPImm()->getValueAPF().convertToDouble();
Nate Begemane8b7ccf2008-02-14 07:39:30 +0000250 break;
Chris Lattnerf7382302007-12-30 21:56:09 +0000251 case MachineOperand::MO_MachineBasicBlock:
252 OS << "mbb<"
Chris Lattner8aa797a2007-12-30 23:10:15 +0000253 << ((Value*)getMBB()->getBasicBlock())->getName()
Chris Lattner31530612009-06-24 17:54:48 +0000254 << "," << (void*)getMBB() << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000255 break;
256 case MachineOperand::MO_FrameIndex:
Chris Lattner31530612009-06-24 17:54:48 +0000257 OS << "<fi#" << getIndex() << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000258 break;
259 case MachineOperand::MO_ConstantPoolIndex:
Chris Lattner8aa797a2007-12-30 23:10:15 +0000260 OS << "<cp#" << getIndex();
Chris Lattnerf7382302007-12-30 21:56:09 +0000261 if (getOffset()) OS << "+" << getOffset();
Chris Lattner31530612009-06-24 17:54:48 +0000262 OS << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000263 break;
264 case MachineOperand::MO_JumpTableIndex:
Chris Lattner31530612009-06-24 17:54:48 +0000265 OS << "<jt#" << getIndex() << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000266 break;
267 case MachineOperand::MO_GlobalAddress:
268 OS << "<ga:" << ((Value*)getGlobal())->getName();
269 if (getOffset()) OS << "+" << getOffset();
Chris Lattner31530612009-06-24 17:54:48 +0000270 OS << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000271 break;
272 case MachineOperand::MO_ExternalSymbol:
273 OS << "<es:" << getSymbolName();
274 if (getOffset()) OS << "+" << getOffset();
Chris Lattner31530612009-06-24 17:54:48 +0000275 OS << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000276 break;
277 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000278 llvm_unreachable("Unrecognized operand type");
Chris Lattnerf7382302007-12-30 21:56:09 +0000279 }
Chris Lattner31530612009-06-24 17:54:48 +0000280
281 if (unsigned TF = getTargetFlags())
282 OS << "[TF=" << TF << ']';
Chris Lattnerf7382302007-12-30 21:56:09 +0000283}
284
285//===----------------------------------------------------------------------===//
Dan Gohmance42e402008-07-07 20:32:02 +0000286// MachineMemOperand Implementation
287//===----------------------------------------------------------------------===//
288
289MachineMemOperand::MachineMemOperand(const Value *v, unsigned int f,
290 int64_t o, uint64_t s, unsigned int a)
291 : Offset(o), Size(s), V(v),
292 Flags((f & 7) | ((Log2_32(a) + 1) << 3)) {
Dan Gohmanf1bf29e2008-07-08 23:47:04 +0000293 assert(isPowerOf2_32(a) && "Alignment is not a power of 2!");
Dan Gohmanc5e1f982008-07-16 15:56:42 +0000294 assert((isLoad() || isStore()) && "Not a load/store!");
Dan Gohmance42e402008-07-07 20:32:02 +0000295}
296
Dan Gohmanb8d2f552008-08-20 15:58:01 +0000297/// Profile - Gather unique data for the object.
298///
299void MachineMemOperand::Profile(FoldingSetNodeID &ID) const {
300 ID.AddInteger(Offset);
301 ID.AddInteger(Size);
302 ID.AddPointer(V);
303 ID.AddInteger(Flags);
304}
305
Dan Gohmance42e402008-07-07 20:32:02 +0000306//===----------------------------------------------------------------------===//
Chris Lattnerf7382302007-12-30 21:56:09 +0000307// MachineInstr Implementation
308//===----------------------------------------------------------------------===//
309
Evan Chengc0f64ff2006-11-27 23:37:22 +0000310/// MachineInstr ctor - This constructor creates a dummy MachineInstr with
Evan Cheng67f660c2006-11-30 07:08:44 +0000311/// TID NULL and no operands.
Evan Chengc0f64ff2006-11-27 23:37:22 +0000312MachineInstr::MachineInstr()
Dale Johannesen06efc022009-01-27 23:20:29 +0000313 : TID(0), NumImplicitOps(0), Parent(0), debugLoc(DebugLoc::getUnknownLoc()) {
Dan Gohman2c3f7ae2008-07-17 23:49:46 +0000314 // Make sure that we get added to a machine basicblock
315 LeakDetector::addGarbageObject(this);
Chris Lattner72791222002-10-28 20:59:49 +0000316}
317
Evan Cheng67f660c2006-11-30 07:08:44 +0000318void MachineInstr::addImplicitDefUseOperands() {
319 if (TID->ImplicitDefs)
Chris Lattnera4161ee2007-12-30 00:12:25 +0000320 for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs)
Chris Lattner8019f412007-12-30 00:41:17 +0000321 addOperand(MachineOperand::CreateReg(*ImpDefs, true, true));
Evan Cheng67f660c2006-11-30 07:08:44 +0000322 if (TID->ImplicitUses)
Chris Lattnera4161ee2007-12-30 00:12:25 +0000323 for (const unsigned *ImpUses = TID->ImplicitUses; *ImpUses; ++ImpUses)
Chris Lattner8019f412007-12-30 00:41:17 +0000324 addOperand(MachineOperand::CreateReg(*ImpUses, false, true));
Evan Chengd7de4962006-11-13 23:34:06 +0000325}
326
327/// MachineInstr ctor - This constructor create a MachineInstr and add the
Evan Chengc0f64ff2006-11-27 23:37:22 +0000328/// implicit operands. It reserves space for number of operands specified by
Chris Lattner749c6f62008-01-07 07:27:27 +0000329/// TargetInstrDesc or the numOperands if it is not zero. (for
Evan Chengc0f64ff2006-11-27 23:37:22 +0000330/// instructions with variable number of operands).
Chris Lattner749c6f62008-01-07 07:27:27 +0000331MachineInstr::MachineInstr(const TargetInstrDesc &tid, bool NoImp)
Dale Johannesen06efc022009-01-27 23:20:29 +0000332 : TID(&tid), NumImplicitOps(0), Parent(0),
333 debugLoc(DebugLoc::getUnknownLoc()) {
Chris Lattner349c4952008-01-07 03:13:06 +0000334 if (!NoImp && TID->getImplicitDefs())
335 for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
Evan Chengd7de4962006-11-13 23:34:06 +0000336 NumImplicitOps++;
Chris Lattner349c4952008-01-07 03:13:06 +0000337 if (!NoImp && TID->getImplicitUses())
338 for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
Evan Chengd7de4962006-11-13 23:34:06 +0000339 NumImplicitOps++;
Chris Lattner349c4952008-01-07 03:13:06 +0000340 Operands.reserve(NumImplicitOps + TID->getNumOperands());
Evan Chengfa945722007-10-13 02:23:01 +0000341 if (!NoImp)
342 addImplicitDefUseOperands();
Dan Gohman2c3f7ae2008-07-17 23:49:46 +0000343 // Make sure that we get added to a machine basicblock
344 LeakDetector::addGarbageObject(this);
Evan Chengd7de4962006-11-13 23:34:06 +0000345}
346
Dale Johannesen06efc022009-01-27 23:20:29 +0000347/// MachineInstr ctor - As above, but with a DebugLoc.
348MachineInstr::MachineInstr(const TargetInstrDesc &tid, const DebugLoc dl,
349 bool NoImp)
350 : TID(&tid), NumImplicitOps(0), Parent(0), debugLoc(dl) {
351 if (!NoImp && TID->getImplicitDefs())
352 for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
353 NumImplicitOps++;
354 if (!NoImp && TID->getImplicitUses())
355 for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
356 NumImplicitOps++;
357 Operands.reserve(NumImplicitOps + TID->getNumOperands());
358 if (!NoImp)
359 addImplicitDefUseOperands();
360 // Make sure that we get added to a machine basicblock
361 LeakDetector::addGarbageObject(this);
362}
363
364/// MachineInstr ctor - Work exactly the same as the ctor two above, except
365/// that the MachineInstr is created and added to the end of the specified
366/// basic block.
Chris Lattnerddd7fcb2002-10-29 23:19:00 +0000367///
Dale Johannesen06efc022009-01-27 23:20:29 +0000368MachineInstr::MachineInstr(MachineBasicBlock *MBB, const TargetInstrDesc &tid)
369 : TID(&tid), NumImplicitOps(0), Parent(0),
370 debugLoc(DebugLoc::getUnknownLoc()) {
371 assert(MBB && "Cannot use inserting ctor with null basic block!");
372 if (TID->ImplicitDefs)
373 for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
374 NumImplicitOps++;
375 if (TID->ImplicitUses)
376 for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
377 NumImplicitOps++;
378 Operands.reserve(NumImplicitOps + TID->getNumOperands());
379 addImplicitDefUseOperands();
380 // Make sure that we get added to a machine basicblock
381 LeakDetector::addGarbageObject(this);
382 MBB->push_back(this); // Add instruction to end of basic block!
383}
384
385/// MachineInstr ctor - As above, but with a DebugLoc.
386///
387MachineInstr::MachineInstr(MachineBasicBlock *MBB, const DebugLoc dl,
Chris Lattner749c6f62008-01-07 07:27:27 +0000388 const TargetInstrDesc &tid)
Dale Johannesen06efc022009-01-27 23:20:29 +0000389 : TID(&tid), NumImplicitOps(0), Parent(0), debugLoc(dl) {
Chris Lattnerddd7fcb2002-10-29 23:19:00 +0000390 assert(MBB && "Cannot use inserting ctor with null basic block!");
Evan Cheng67f660c2006-11-30 07:08:44 +0000391 if (TID->ImplicitDefs)
Chris Lattner349c4952008-01-07 03:13:06 +0000392 for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
Evan Chengd7de4962006-11-13 23:34:06 +0000393 NumImplicitOps++;
Evan Cheng67f660c2006-11-30 07:08:44 +0000394 if (TID->ImplicitUses)
Chris Lattner349c4952008-01-07 03:13:06 +0000395 for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
Evan Chengd7de4962006-11-13 23:34:06 +0000396 NumImplicitOps++;
Chris Lattner349c4952008-01-07 03:13:06 +0000397 Operands.reserve(NumImplicitOps + TID->getNumOperands());
Evan Cheng67f660c2006-11-30 07:08:44 +0000398 addImplicitDefUseOperands();
Dan Gohman2c3f7ae2008-07-17 23:49:46 +0000399 // Make sure that we get added to a machine basicblock
400 LeakDetector::addGarbageObject(this);
Chris Lattnerddd7fcb2002-10-29 23:19:00 +0000401 MBB->push_back(this); // Add instruction to end of basic block!
402}
403
Misha Brukmance22e762004-07-09 14:45:17 +0000404/// MachineInstr ctor - Copies MachineInstr arg exactly
405///
Evan Cheng1ed99222008-07-19 00:37:25 +0000406MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI)
Dale Johannesen06efc022009-01-27 23:20:29 +0000407 : TID(&MI.getDesc()), NumImplicitOps(0), Parent(0),
408 debugLoc(MI.getDebugLoc()) {
Chris Lattner943b5e12006-05-04 19:14:44 +0000409 Operands.reserve(MI.getNumOperands());
Tanya Lattnerb5159ed2004-05-23 20:58:02 +0000410
Misha Brukmance22e762004-07-09 14:45:17 +0000411 // Add operands
Evan Cheng1ed99222008-07-19 00:37:25 +0000412 for (unsigned i = 0; i != MI.getNumOperands(); ++i)
413 addOperand(MI.getOperand(i));
414 NumImplicitOps = MI.NumImplicitOps;
Tanya Lattner0c63e032004-05-24 03:14:18 +0000415
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000416 // Add memory operands.
Dan Gohmanfed90b62008-07-28 21:51:04 +0000417 for (std::list<MachineMemOperand>::const_iterator i = MI.memoperands_begin(),
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000418 j = MI.memoperands_end(); i != j; ++i)
419 addMemOperand(MF, *i);
420
421 // Set parent to null.
Chris Lattnerf20c1a42007-12-31 04:56:33 +0000422 Parent = 0;
Dan Gohman6116a732008-07-21 18:47:29 +0000423
424 LeakDetector::addGarbageObject(this);
Tanya Lattner466b5342004-05-23 19:35:12 +0000425}
426
Misha Brukmance22e762004-07-09 14:45:17 +0000427MachineInstr::~MachineInstr() {
Dan Gohman2c3f7ae2008-07-17 23:49:46 +0000428 LeakDetector::removeGarbageObject(this);
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000429 assert(MemOperands.empty() &&
430 "MachineInstr being deleted with live memoperands!");
Chris Lattnere12d6ab2007-12-30 06:11:04 +0000431#ifndef NDEBUG
Chris Lattner62ed6b92008-01-01 01:12:31 +0000432 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
Chris Lattnere12d6ab2007-12-30 06:11:04 +0000433 assert(Operands[i].ParentMI == this && "ParentMI mismatch!");
Dan Gohmand735b802008-10-03 15:45:36 +0000434 assert((!Operands[i].isReg() || !Operands[i].isOnRegUseList()) &&
Chris Lattner62ed6b92008-01-01 01:12:31 +0000435 "Reg operand def/use list corrupted");
436 }
Chris Lattnere12d6ab2007-12-30 06:11:04 +0000437#endif
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +0000438}
439
Chris Lattner62ed6b92008-01-01 01:12:31 +0000440/// getRegInfo - If this instruction is embedded into a MachineFunction,
441/// return the MachineRegisterInfo object for the current function, otherwise
442/// return null.
443MachineRegisterInfo *MachineInstr::getRegInfo() {
444 if (MachineBasicBlock *MBB = getParent())
Dan Gohman4e526b92008-07-08 23:59:09 +0000445 return &MBB->getParent()->getRegInfo();
Chris Lattner62ed6b92008-01-01 01:12:31 +0000446 return 0;
447}
448
449/// RemoveRegOperandsFromUseLists - Unlink all of the register operands in
450/// this instruction from their respective use lists. This requires that the
451/// operands already be on their use lists.
452void MachineInstr::RemoveRegOperandsFromUseLists() {
453 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000454 if (Operands[i].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000455 Operands[i].RemoveRegOperandFromRegInfo();
456 }
457}
458
459/// AddRegOperandsToUseLists - Add all of the register operands in
460/// this instruction from their respective use lists. This requires that the
461/// operands not be on their use lists yet.
462void MachineInstr::AddRegOperandsToUseLists(MachineRegisterInfo &RegInfo) {
463 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000464 if (Operands[i].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000465 Operands[i].AddRegOperandToRegInfo(&RegInfo);
466 }
467}
468
469
470/// addOperand - Add the specified operand to the instruction. If it is an
471/// implicit operand, it is added to the end of the operand list. If it is
472/// an explicit operand it is added at the end of the explicit operand list
473/// (before the first implicit operand).
474void MachineInstr::addOperand(const MachineOperand &Op) {
Dan Gohmand735b802008-10-03 15:45:36 +0000475 bool isImpReg = Op.isReg() && Op.isImplicit();
Chris Lattner62ed6b92008-01-01 01:12:31 +0000476 assert((isImpReg || !OperandsComplete()) &&
477 "Trying to add an operand to a machine instr that is already done!");
478
Dan Gohmanbcf28c02008-12-09 22:45:08 +0000479 MachineRegisterInfo *RegInfo = getRegInfo();
480
Chris Lattner62ed6b92008-01-01 01:12:31 +0000481 // If we are adding the operand to the end of the list, our job is simpler.
482 // This is true most of the time, so this is a reasonable optimization.
483 if (isImpReg || NumImplicitOps == 0) {
484 // We can only do this optimization if we know that the operand list won't
485 // reallocate.
486 if (Operands.empty() || Operands.size()+1 <= Operands.capacity()) {
487 Operands.push_back(Op);
488
489 // Set the parent of the operand.
490 Operands.back().ParentMI = this;
491
492 // If the operand is a register, update the operand's use list.
Dan Gohmand735b802008-10-03 15:45:36 +0000493 if (Op.isReg())
Dan Gohmanbcf28c02008-12-09 22:45:08 +0000494 Operands.back().AddRegOperandToRegInfo(RegInfo);
Chris Lattner62ed6b92008-01-01 01:12:31 +0000495 return;
496 }
497 }
498
499 // Otherwise, we have to insert a real operand before any implicit ones.
500 unsigned OpNo = Operands.size()-NumImplicitOps;
501
Chris Lattner62ed6b92008-01-01 01:12:31 +0000502 // If this instruction isn't embedded into a function, then we don't need to
503 // update any operand lists.
504 if (RegInfo == 0) {
505 // Simple insertion, no reginfo update needed for other register operands.
506 Operands.insert(Operands.begin()+OpNo, Op);
507 Operands[OpNo].ParentMI = this;
508
509 // Do explicitly set the reginfo for this operand though, to ensure the
510 // next/prev fields are properly nulled out.
Dan Gohmand735b802008-10-03 15:45:36 +0000511 if (Operands[OpNo].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000512 Operands[OpNo].AddRegOperandToRegInfo(0);
513
514 } else if (Operands.size()+1 <= Operands.capacity()) {
515 // Otherwise, we have to remove register operands from their register use
516 // list, add the operand, then add the register operands back to their use
517 // list. This also must handle the case when the operand list reallocates
518 // to somewhere else.
519
520 // If insertion of this operand won't cause reallocation of the operand
521 // list, just remove the implicit operands, add the operand, then re-add all
522 // the rest of the operands.
523 for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000524 assert(Operands[i].isReg() && "Should only be an implicit reg!");
Chris Lattner62ed6b92008-01-01 01:12:31 +0000525 Operands[i].RemoveRegOperandFromRegInfo();
526 }
527
528 // Add the operand. If it is a register, add it to the reg list.
529 Operands.insert(Operands.begin()+OpNo, Op);
530 Operands[OpNo].ParentMI = this;
531
Dan Gohmand735b802008-10-03 15:45:36 +0000532 if (Operands[OpNo].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000533 Operands[OpNo].AddRegOperandToRegInfo(RegInfo);
534
535 // Re-add all the implicit ops.
536 for (unsigned i = OpNo+1, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000537 assert(Operands[i].isReg() && "Should only be an implicit reg!");
Chris Lattner62ed6b92008-01-01 01:12:31 +0000538 Operands[i].AddRegOperandToRegInfo(RegInfo);
539 }
540 } else {
541 // Otherwise, we will be reallocating the operand list. Remove all reg
542 // operands from their list, then readd them after the operand list is
543 // reallocated.
544 RemoveRegOperandsFromUseLists();
545
546 Operands.insert(Operands.begin()+OpNo, Op);
547 Operands[OpNo].ParentMI = this;
548
549 // Re-add all the operands.
550 AddRegOperandsToUseLists(*RegInfo);
551 }
552}
553
554/// RemoveOperand - Erase an operand from an instruction, leaving it with one
555/// fewer operand than it started with.
556///
557void MachineInstr::RemoveOperand(unsigned OpNo) {
558 assert(OpNo < Operands.size() && "Invalid operand number");
559
560 // Special case removing the last one.
561 if (OpNo == Operands.size()-1) {
562 // If needed, remove from the reg def/use list.
Dan Gohmand735b802008-10-03 15:45:36 +0000563 if (Operands.back().isReg() && Operands.back().isOnRegUseList())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000564 Operands.back().RemoveRegOperandFromRegInfo();
565
566 Operands.pop_back();
567 return;
568 }
569
570 // Otherwise, we are removing an interior operand. If we have reginfo to
571 // update, remove all operands that will be shifted down from their reg lists,
572 // move everything down, then re-add them.
573 MachineRegisterInfo *RegInfo = getRegInfo();
574 if (RegInfo) {
575 for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000576 if (Operands[i].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000577 Operands[i].RemoveRegOperandFromRegInfo();
578 }
579 }
580
581 Operands.erase(Operands.begin()+OpNo);
582
583 if (RegInfo) {
584 for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000585 if (Operands[i].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000586 Operands[i].AddRegOperandToRegInfo(RegInfo);
587 }
588 }
589}
590
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000591/// addMemOperand - Add a MachineMemOperand to the machine instruction,
592/// referencing arbitrary storage.
593void MachineInstr::addMemOperand(MachineFunction &MF,
594 const MachineMemOperand &MO) {
Dan Gohmanfed90b62008-07-28 21:51:04 +0000595 MemOperands.push_back(MO);
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000596}
597
598/// clearMemOperands - Erase all of this MachineInstr's MachineMemOperands.
599void MachineInstr::clearMemOperands(MachineFunction &MF) {
Dan Gohmanfed90b62008-07-28 21:51:04 +0000600 MemOperands.clear();
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000601}
602
Chris Lattner62ed6b92008-01-01 01:12:31 +0000603
Chris Lattner48d7c062006-04-17 21:35:41 +0000604/// removeFromParent - This method unlinks 'this' from the containing basic
605/// block, and returns it, but does not delete it.
606MachineInstr *MachineInstr::removeFromParent() {
607 assert(getParent() && "Not embedded in a basic block!");
608 getParent()->remove(this);
609 return this;
610}
611
612
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000613/// eraseFromParent - This method unlinks 'this' from the containing basic
614/// block, and deletes it.
615void MachineInstr::eraseFromParent() {
616 assert(getParent() && "Not embedded in a basic block!");
617 getParent()->erase(this);
618}
619
620
Brian Gaeke21326fc2004-02-13 04:39:32 +0000621/// OperandComplete - Return true if it's illegal to add a new operand
622///
Chris Lattner2a90ba62004-02-12 16:09:53 +0000623bool MachineInstr::OperandsComplete() const {
Chris Lattner349c4952008-01-07 03:13:06 +0000624 unsigned short NumOperands = TID->getNumOperands();
Chris Lattner8f707e12008-01-07 05:19:29 +0000625 if (!TID->isVariadic() && getNumOperands()-NumImplicitOps >= NumOperands)
Vikram S. Adve34977822003-05-31 07:39:06 +0000626 return true; // Broken: we have all the operands of this instruction!
Chris Lattner413746e2002-10-28 20:48:39 +0000627 return false;
628}
629
Evan Cheng19e3f312007-05-15 01:26:09 +0000630/// getNumExplicitOperands - Returns the number of non-implicit operands.
631///
632unsigned MachineInstr::getNumExplicitOperands() const {
Chris Lattner349c4952008-01-07 03:13:06 +0000633 unsigned NumOperands = TID->getNumOperands();
Chris Lattner8f707e12008-01-07 05:19:29 +0000634 if (!TID->isVariadic())
Evan Cheng19e3f312007-05-15 01:26:09 +0000635 return NumOperands;
636
Dan Gohman9407cd42009-04-15 17:59:11 +0000637 for (unsigned i = NumOperands, e = getNumOperands(); i != e; ++i) {
638 const MachineOperand &MO = getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +0000639 if (!MO.isReg() || !MO.isImplicit())
Evan Cheng19e3f312007-05-15 01:26:09 +0000640 NumOperands++;
641 }
642 return NumOperands;
643}
644
Chris Lattner8ace2cd2006-10-20 22:39:59 +0000645
Dan Gohman44066042008-07-01 00:05:16 +0000646/// isLabel - Returns true if the MachineInstr represents a label.
647///
648bool MachineInstr::isLabel() const {
649 return getOpcode() == TargetInstrInfo::DBG_LABEL ||
650 getOpcode() == TargetInstrInfo::EH_LABEL ||
651 getOpcode() == TargetInstrInfo::GC_LABEL;
652}
653
Evan Chengbb81d972008-01-31 09:59:15 +0000654/// isDebugLabel - Returns true if the MachineInstr represents a debug label.
655///
656bool MachineInstr::isDebugLabel() const {
Dan Gohman44066042008-07-01 00:05:16 +0000657 return getOpcode() == TargetInstrInfo::DBG_LABEL;
Evan Chengbb81d972008-01-31 09:59:15 +0000658}
659
Evan Chengfaa51072007-04-26 19:00:32 +0000660/// findRegisterUseOperandIdx() - Returns the MachineOperand that is a use of
Evan Cheng32eb1f12007-03-26 22:37:45 +0000661/// the specific register or -1 if it is not found. It further tightening
Evan Cheng76d7e762007-02-23 01:04:26 +0000662/// the search criteria to a use that kills the register if isKill is true.
Evan Cheng6130f662008-03-05 00:59:57 +0000663int MachineInstr::findRegisterUseOperandIdx(unsigned Reg, bool isKill,
664 const TargetRegisterInfo *TRI) const {
Evan Cheng576d1232006-12-06 08:27:42 +0000665 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
Evan Chengf277ee42007-05-29 18:35:22 +0000666 const MachineOperand &MO = getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +0000667 if (!MO.isReg() || !MO.isUse())
Evan Cheng6130f662008-03-05 00:59:57 +0000668 continue;
669 unsigned MOReg = MO.getReg();
670 if (!MOReg)
671 continue;
672 if (MOReg == Reg ||
673 (TRI &&
674 TargetRegisterInfo::isPhysicalRegister(MOReg) &&
675 TargetRegisterInfo::isPhysicalRegister(Reg) &&
676 TRI->isSubRegister(MOReg, Reg)))
Evan Cheng76d7e762007-02-23 01:04:26 +0000677 if (!isKill || MO.isKill())
Evan Cheng32eb1f12007-03-26 22:37:45 +0000678 return i;
Evan Cheng576d1232006-12-06 08:27:42 +0000679 }
Evan Cheng32eb1f12007-03-26 22:37:45 +0000680 return -1;
Evan Cheng576d1232006-12-06 08:27:42 +0000681}
682
Evan Cheng6130f662008-03-05 00:59:57 +0000683/// findRegisterDefOperandIdx() - Returns the operand index that is a def of
Dan Gohman703bfe62008-05-06 00:20:10 +0000684/// the specified register or -1 if it is not found. If isDead is true, defs
685/// that are not dead are skipped. If TargetRegisterInfo is non-null, then it
686/// also checks if there is a def of a super-register.
Evan Cheng6130f662008-03-05 00:59:57 +0000687int MachineInstr::findRegisterDefOperandIdx(unsigned Reg, bool isDead,
688 const TargetRegisterInfo *TRI) const {
Evan Chengb371f452007-02-19 21:49:54 +0000689 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
Evan Cheng6130f662008-03-05 00:59:57 +0000690 const MachineOperand &MO = getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +0000691 if (!MO.isReg() || !MO.isDef())
Evan Cheng6130f662008-03-05 00:59:57 +0000692 continue;
693 unsigned MOReg = MO.getReg();
694 if (MOReg == Reg ||
695 (TRI &&
696 TargetRegisterInfo::isPhysicalRegister(MOReg) &&
697 TargetRegisterInfo::isPhysicalRegister(Reg) &&
698 TRI->isSubRegister(MOReg, Reg)))
699 if (!isDead || MO.isDead())
700 return i;
Evan Chengb371f452007-02-19 21:49:54 +0000701 }
Evan Cheng6130f662008-03-05 00:59:57 +0000702 return -1;
Evan Chengb371f452007-02-19 21:49:54 +0000703}
Evan Cheng19e3f312007-05-15 01:26:09 +0000704
Evan Chengf277ee42007-05-29 18:35:22 +0000705/// findFirstPredOperandIdx() - Find the index of the first operand in the
706/// operand list that is used to represent the predicate. It returns -1 if
707/// none is found.
708int MachineInstr::findFirstPredOperandIdx() const {
Chris Lattner749c6f62008-01-07 07:27:27 +0000709 const TargetInstrDesc &TID = getDesc();
710 if (TID.isPredicable()) {
Evan Cheng19e3f312007-05-15 01:26:09 +0000711 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
Chris Lattner749c6f62008-01-07 07:27:27 +0000712 if (TID.OpInfo[i].isPredicate())
Evan Chengf277ee42007-05-29 18:35:22 +0000713 return i;
Evan Cheng19e3f312007-05-15 01:26:09 +0000714 }
715
Evan Chengf277ee42007-05-29 18:35:22 +0000716 return -1;
Evan Cheng19e3f312007-05-15 01:26:09 +0000717}
Evan Chengb371f452007-02-19 21:49:54 +0000718
Bob Wilsond9df5012009-04-09 17:16:43 +0000719/// isRegTiedToUseOperand - Given the index of a register def operand,
720/// check if the register def is tied to a source operand, due to either
721/// two-address elimination or inline assembly constraints. Returns the
722/// first tied use operand index by reference is UseOpIdx is not null.
Jakob Stoklund Olesence9be2c2009-04-29 20:57:16 +0000723bool MachineInstr::
724isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx) const {
Evan Chengfb112882009-03-23 08:01:15 +0000725 if (getOpcode() == TargetInstrInfo::INLINEASM) {
Bob Wilsond9df5012009-04-09 17:16:43 +0000726 assert(DefOpIdx >= 2);
727 const MachineOperand &MO = getOperand(DefOpIdx);
Chris Lattnerc30aa7b2009-04-09 23:33:34 +0000728 if (!MO.isReg() || !MO.isDef() || MO.getReg() == 0)
Evan Chengfb112882009-03-23 08:01:15 +0000729 return false;
Evan Chengef5d0702009-06-24 02:05:51 +0000730 // Determine the actual operand index that corresponds to this index.
Evan Chengfb112882009-03-23 08:01:15 +0000731 unsigned DefNo = 0;
Evan Chengef5d0702009-06-24 02:05:51 +0000732 unsigned DefPart = 0;
Evan Chengfb112882009-03-23 08:01:15 +0000733 for (unsigned i = 1, e = getNumOperands(); i < e; ) {
734 const MachineOperand &FMO = getOperand(i);
Jakob Stoklund Olesen45d34fe2009-07-19 19:09:59 +0000735 // After the normal asm operands there may be additional imp-def regs.
736 if (!FMO.isImm())
737 return false;
Evan Chengfb112882009-03-23 08:01:15 +0000738 // Skip over this def.
Evan Chengef5d0702009-06-24 02:05:51 +0000739 unsigned NumOps = InlineAsm::getNumOperandRegisters(FMO.getImm());
740 unsigned PrevDef = i + 1;
741 i = PrevDef + NumOps;
742 if (i > DefOpIdx) {
743 DefPart = DefOpIdx - PrevDef;
Evan Chengfb112882009-03-23 08:01:15 +0000744 break;
Evan Chengef5d0702009-06-24 02:05:51 +0000745 }
Evan Chengfb112882009-03-23 08:01:15 +0000746 ++DefNo;
747 }
Evan Chengef5d0702009-06-24 02:05:51 +0000748 for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
Evan Chengfb112882009-03-23 08:01:15 +0000749 const MachineOperand &FMO = getOperand(i);
750 if (!FMO.isImm())
751 continue;
752 if (i+1 >= e || !getOperand(i+1).isReg() || !getOperand(i+1).isUse())
753 continue;
754 unsigned Idx;
Evan Chengef5d0702009-06-24 02:05:51 +0000755 if (InlineAsm::isUseOperandTiedToDef(FMO.getImm(), Idx) &&
Bob Wilsond9df5012009-04-09 17:16:43 +0000756 Idx == DefNo) {
757 if (UseOpIdx)
Evan Chengef5d0702009-06-24 02:05:51 +0000758 *UseOpIdx = (unsigned)i + 1 + DefPart;
Evan Chengfb112882009-03-23 08:01:15 +0000759 return true;
Bob Wilsond9df5012009-04-09 17:16:43 +0000760 }
Evan Chengfb112882009-03-23 08:01:15 +0000761 }
Evan Chengef5d0702009-06-24 02:05:51 +0000762 return false;
Evan Chengfb112882009-03-23 08:01:15 +0000763 }
764
Bob Wilsond9df5012009-04-09 17:16:43 +0000765 assert(getOperand(DefOpIdx).isDef() && "DefOpIdx is not a def!");
Chris Lattner749c6f62008-01-07 07:27:27 +0000766 const TargetInstrDesc &TID = getDesc();
Evan Chengef0732d2008-07-10 07:35:43 +0000767 for (unsigned i = 0, e = TID.getNumOperands(); i != e; ++i) {
768 const MachineOperand &MO = getOperand(i);
Dan Gohman2ce7f202008-12-05 05:45:42 +0000769 if (MO.isReg() && MO.isUse() &&
Bob Wilsond9df5012009-04-09 17:16:43 +0000770 TID.getOperandConstraint(i, TOI::TIED_TO) == (int)DefOpIdx) {
771 if (UseOpIdx)
772 *UseOpIdx = (unsigned)i;
Evan Chengef0732d2008-07-10 07:35:43 +0000773 return true;
Bob Wilsond9df5012009-04-09 17:16:43 +0000774 }
Evan Cheng32dfbea2007-10-12 08:50:34 +0000775 }
776 return false;
777}
778
Evan Chenga24752f2009-03-19 20:30:06 +0000779/// isRegTiedToDefOperand - Return true if the operand of the specified index
780/// is a register use and it is tied to an def operand. It also returns the def
781/// operand index by reference.
Jakob Stoklund Olesence9be2c2009-04-29 20:57:16 +0000782bool MachineInstr::
783isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx) const {
Evan Chengfb112882009-03-23 08:01:15 +0000784 if (getOpcode() == TargetInstrInfo::INLINEASM) {
785 const MachineOperand &MO = getOperand(UseOpIdx);
Chris Lattner0c8382c2009-04-09 16:50:43 +0000786 if (!MO.isReg() || !MO.isUse() || MO.getReg() == 0)
Evan Chengfb112882009-03-23 08:01:15 +0000787 return false;
Jakob Stoklund Olesen57e599a2009-07-16 20:58:34 +0000788
789 // Find the flag operand corresponding to UseOpIdx
790 unsigned FlagIdx, NumOps=0;
791 for (FlagIdx = 1; FlagIdx < UseOpIdx; FlagIdx += NumOps+1) {
792 const MachineOperand &UFMO = getOperand(FlagIdx);
Jakob Stoklund Olesen45d34fe2009-07-19 19:09:59 +0000793 // After the normal asm operands there may be additional imp-def regs.
794 if (!UFMO.isImm())
795 return false;
Jakob Stoklund Olesen57e599a2009-07-16 20:58:34 +0000796 NumOps = InlineAsm::getNumOperandRegisters(UFMO.getImm());
797 assert(NumOps < getNumOperands() && "Invalid inline asm flag");
798 if (UseOpIdx < FlagIdx+NumOps+1)
799 break;
Evan Chengef5d0702009-06-24 02:05:51 +0000800 }
Jakob Stoklund Olesen57e599a2009-07-16 20:58:34 +0000801 if (FlagIdx >= UseOpIdx)
Evan Chengef5d0702009-06-24 02:05:51 +0000802 return false;
Jakob Stoklund Olesen57e599a2009-07-16 20:58:34 +0000803 const MachineOperand &UFMO = getOperand(FlagIdx);
Evan Chengfb112882009-03-23 08:01:15 +0000804 unsigned DefNo;
805 if (InlineAsm::isUseOperandTiedToDef(UFMO.getImm(), DefNo)) {
806 if (!DefOpIdx)
807 return true;
808
809 unsigned DefIdx = 1;
810 // Remember to adjust the index. First operand is asm string, then there
811 // is a flag for each.
812 while (DefNo) {
813 const MachineOperand &FMO = getOperand(DefIdx);
814 assert(FMO.isImm());
815 // Skip over this def.
816 DefIdx += InlineAsm::getNumOperandRegisters(FMO.getImm()) + 1;
817 --DefNo;
818 }
Evan Chengef5d0702009-06-24 02:05:51 +0000819 *DefOpIdx = DefIdx + UseOpIdx - FlagIdx;
Evan Chengfb112882009-03-23 08:01:15 +0000820 return true;
821 }
822 return false;
823 }
824
Evan Chenga24752f2009-03-19 20:30:06 +0000825 const TargetInstrDesc &TID = getDesc();
826 if (UseOpIdx >= TID.getNumOperands())
827 return false;
828 const MachineOperand &MO = getOperand(UseOpIdx);
829 if (!MO.isReg() || !MO.isUse())
830 return false;
831 int DefIdx = TID.getOperandConstraint(UseOpIdx, TOI::TIED_TO);
832 if (DefIdx == -1)
833 return false;
834 if (DefOpIdx)
835 *DefOpIdx = (unsigned)DefIdx;
836 return true;
837}
838
Evan Cheng576d1232006-12-06 08:27:42 +0000839/// copyKillDeadInfo - Copies kill / dead operand properties from MI.
840///
841void MachineInstr::copyKillDeadInfo(const MachineInstr *MI) {
842 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
843 const MachineOperand &MO = MI->getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +0000844 if (!MO.isReg() || (!MO.isKill() && !MO.isDead()))
Evan Cheng576d1232006-12-06 08:27:42 +0000845 continue;
846 for (unsigned j = 0, ee = getNumOperands(); j != ee; ++j) {
847 MachineOperand &MOp = getOperand(j);
848 if (!MOp.isIdenticalTo(MO))
849 continue;
850 if (MO.isKill())
851 MOp.setIsKill();
852 else
853 MOp.setIsDead();
854 break;
855 }
856 }
857}
858
Evan Cheng19e3f312007-05-15 01:26:09 +0000859/// copyPredicates - Copies predicate operand(s) from MI.
860void MachineInstr::copyPredicates(const MachineInstr *MI) {
Chris Lattner749c6f62008-01-07 07:27:27 +0000861 const TargetInstrDesc &TID = MI->getDesc();
Evan Chengb27087f2008-03-13 00:44:09 +0000862 if (!TID.isPredicable())
863 return;
864 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
865 if (TID.OpInfo[i].isPredicate()) {
866 // Predicated operands must be last operands.
867 addOperand(MI->getOperand(i));
Evan Cheng19e3f312007-05-15 01:26:09 +0000868 }
869 }
870}
871
Evan Cheng9f1c8312008-07-03 09:09:37 +0000872/// isSafeToMove - Return true if it is safe to move this instruction. If
873/// SawStore is set to true, it means that there is a store (or call) between
874/// the instruction's location and its intended destination.
Dan Gohmanb3b930a2008-11-18 19:04:29 +0000875bool MachineInstr::isSafeToMove(const TargetInstrInfo *TII,
876 bool &SawStore) const {
Evan Chengb27087f2008-03-13 00:44:09 +0000877 // Ignore stuff that we obviously can't move.
878 if (TID->mayStore() || TID->isCall()) {
879 SawStore = true;
880 return false;
881 }
Dan Gohman237dee12008-12-23 17:28:50 +0000882 if (TID->isTerminator() || TID->hasUnmodeledSideEffects())
Evan Chengb27087f2008-03-13 00:44:09 +0000883 return false;
884
885 // See if this instruction does a load. If so, we have to guarantee that the
886 // loaded value doesn't change between the load and the its intended
887 // destination. The check for isInvariantLoad gives the targe the chance to
888 // classify the load as always returning a constant, e.g. a constant pool
889 // load.
Dan Gohman3e4fb702008-09-24 00:06:15 +0000890 if (TID->mayLoad() && !TII->isInvariantLoad(this))
Evan Chengb27087f2008-03-13 00:44:09 +0000891 // Otherwise, this is a real load. If there is a store between the load and
Evan Cheng7cc2c402009-07-28 21:49:18 +0000892 // end of block, or if the load is volatile, we can't move it.
Dan Gohmand790a5c2008-10-02 15:04:30 +0000893 return !SawStore && !hasVolatileMemoryRef();
Dan Gohman3e4fb702008-09-24 00:06:15 +0000894
Evan Chengb27087f2008-03-13 00:44:09 +0000895 return true;
896}
897
Evan Chengdf3b9932008-08-27 20:33:50 +0000898/// isSafeToReMat - Return true if it's safe to rematerialize the specified
899/// instruction which defined the specified register instead of copying it.
Dan Gohmanb3b930a2008-11-18 19:04:29 +0000900bool MachineInstr::isSafeToReMat(const TargetInstrInfo *TII,
901 unsigned DstReg) const {
Evan Chengdf3b9932008-08-27 20:33:50 +0000902 bool SawStore = false;
Evan Cheng3689ff42008-08-30 09:07:18 +0000903 if (!getDesc().isRematerializable() ||
904 !TII->isTriviallyReMaterializable(this) ||
905 !isSafeToMove(TII, SawStore))
Evan Chengdf3b9932008-08-27 20:33:50 +0000906 return false;
907 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
Dan Gohmancbad42c2008-11-18 19:49:32 +0000908 const MachineOperand &MO = getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +0000909 if (!MO.isReg())
Evan Chengdf3b9932008-08-27 20:33:50 +0000910 continue;
911 // FIXME: For now, do not remat any instruction with register operands.
912 // Later on, we can loosen the restriction is the register operands have
913 // not been modified between the def and use. Note, this is different from
Evan Cheng8763c1c2008-08-27 20:58:54 +0000914 // MachineSink because the code is no longer in two-address form (at least
Evan Chengdf3b9932008-08-27 20:33:50 +0000915 // partially).
916 if (MO.isUse())
917 return false;
918 else if (!MO.isDead() && MO.getReg() != DstReg)
919 return false;
920 }
921 return true;
922}
923
Dan Gohman3e4fb702008-09-24 00:06:15 +0000924/// hasVolatileMemoryRef - Return true if this instruction may have a
925/// volatile memory reference, or if the information describing the
926/// memory reference is not available. Return false if it is known to
927/// have no volatile memory references.
928bool MachineInstr::hasVolatileMemoryRef() const {
929 // An instruction known never to access memory won't have a volatile access.
930 if (!TID->mayStore() &&
931 !TID->mayLoad() &&
932 !TID->isCall() &&
933 !TID->hasUnmodeledSideEffects())
934 return false;
935
936 // Otherwise, if the instruction has no memory reference information,
937 // conservatively assume it wasn't preserved.
938 if (memoperands_empty())
939 return true;
940
941 // Check the memory reference information for volatile references.
942 for (std::list<MachineMemOperand>::const_iterator I = memoperands_begin(),
943 E = memoperands_end(); I != E; ++I)
944 if (I->isVolatile())
945 return true;
946
947 return false;
948}
949
Brian Gaeke21326fc2004-02-13 04:39:32 +0000950void MachineInstr::dump() const {
Bill Wendlinge8156192006-12-07 01:30:32 +0000951 cerr << " " << *this;
Vikram S. Adve70bc4b52001-07-21 12:41:50 +0000952}
953
Tanya Lattnerb1407622004-06-25 00:13:11 +0000954void MachineInstr::print(std::ostream &OS, const TargetMachine *TM) const {
Mon P Wang5ca6bd12008-10-10 01:43:55 +0000955 raw_os_ostream RawOS(OS);
956 print(RawOS, TM);
957}
958
959void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM) const {
Chris Lattnere3087892007-12-30 21:31:53 +0000960 // Specialize printing if op#0 is definition
Chris Lattner6a592272002-10-30 01:55:38 +0000961 unsigned StartOp = 0;
Dan Gohmand735b802008-10-03 15:45:36 +0000962 if (getNumOperands() && getOperand(0).isReg() && getOperand(0).isDef()) {
Chris Lattnerf7382302007-12-30 21:56:09 +0000963 getOperand(0).print(OS, TM);
Chris Lattner6a592272002-10-30 01:55:38 +0000964 OS << " = ";
965 ++StartOp; // Don't print this operand again!
966 }
Tanya Lattnerb1407622004-06-25 00:13:11 +0000967
Chris Lattner749c6f62008-01-07 07:27:27 +0000968 OS << getDesc().getName();
Misha Brukmanedf128a2005-04-21 22:36:52 +0000969
Chris Lattner6a592272002-10-30 01:55:38 +0000970 for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
971 if (i != StartOp)
972 OS << ",";
973 OS << " ";
Chris Lattnerf7382302007-12-30 21:56:09 +0000974 getOperand(i).print(OS, TM);
Chris Lattner10491642002-10-30 00:48:05 +0000975 }
Misha Brukmanedf128a2005-04-21 22:36:52 +0000976
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000977 if (!memoperands_empty()) {
Dan Gohman2bfe6ff2008-02-07 16:18:00 +0000978 OS << ", Mem:";
Dan Gohmanfed90b62008-07-28 21:51:04 +0000979 for (std::list<MachineMemOperand>::const_iterator i = memoperands_begin(),
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000980 e = memoperands_end(); i != e; ++i) {
981 const MachineMemOperand &MRO = *i;
Dan Gohman69de1932008-02-06 22:27:42 +0000982 const Value *V = MRO.getValue();
983
Dan Gohman69de1932008-02-06 22:27:42 +0000984 assert((MRO.isLoad() || MRO.isStore()) &&
985 "SV has to be a load, store or both.");
986
987 if (MRO.isVolatile())
988 OS << "Volatile ";
Dan Gohman2bfe6ff2008-02-07 16:18:00 +0000989
Dan Gohman69de1932008-02-06 22:27:42 +0000990 if (MRO.isLoad())
Dan Gohman2bfe6ff2008-02-07 16:18:00 +0000991 OS << "LD";
Dan Gohman69de1932008-02-06 22:27:42 +0000992 if (MRO.isStore())
Dan Gohman2bfe6ff2008-02-07 16:18:00 +0000993 OS << "ST";
Dan Gohman69de1932008-02-06 22:27:42 +0000994
Evan Chengbbd83222008-02-08 22:05:07 +0000995 OS << "(" << MRO.getSize() << "," << MRO.getAlignment() << ") [";
Dan Gohman69de1932008-02-06 22:27:42 +0000996
Dan Gohman2bfe6ff2008-02-07 16:18:00 +0000997 if (!V)
998 OS << "<unknown>";
999 else if (!V->getName().empty())
1000 OS << V->getName();
Chris Lattneredfb72c2008-08-24 20:37:32 +00001001 else if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) {
Mon P Wang5ca6bd12008-10-10 01:43:55 +00001002 PSV->print(OS);
Chris Lattneredfb72c2008-08-24 20:37:32 +00001003 } else
Dan Gohman2bfe6ff2008-02-07 16:18:00 +00001004 OS << V;
1005
1006 OS << " + " << MRO.getOffset() << "]";
Dan Gohman69de1932008-02-06 22:27:42 +00001007 }
1008 }
1009
Bill Wendlingb5ef2732009-02-19 21:44:55 +00001010 if (!debugLoc.isUnknown()) {
1011 const MachineFunction *MF = getParent()->getParent();
1012 DebugLocTuple DLT = MF->getDebugLocTuple(debugLoc);
Argyrios Kyrtzidisa26eae62009-04-30 23:22:31 +00001013 DICompileUnit CU(DLT.CompileUnit);
1014 std::string Dir, Fn;
Bill Wendlingb5ef2732009-02-19 21:44:55 +00001015 OS << " [dbg: "
Argyrios Kyrtzidisa26eae62009-04-30 23:22:31 +00001016 << CU.getDirectory(Dir) << '/' << CU.getFilename(Fn) << ","
Bill Wendlingb5ef2732009-02-19 21:44:55 +00001017 << DLT.Line << ","
1018 << DLT.Col << "]";
1019 }
1020
Chris Lattner10491642002-10-30 00:48:05 +00001021 OS << "\n";
1022}
1023
Owen Andersonb487e722008-01-24 01:10:07 +00001024bool MachineInstr::addRegisterKilled(unsigned IncomingReg,
Dan Gohman6f0d0242008-02-10 18:45:23 +00001025 const TargetRegisterInfo *RegInfo,
Owen Andersonb487e722008-01-24 01:10:07 +00001026 bool AddIfNotFound) {
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001027 bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
Dan Gohman2ebc11a2008-07-03 01:18:51 +00001028 bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
Dan Gohman3f629402008-09-03 15:56:16 +00001029 bool Found = false;
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001030 SmallVector<unsigned,4> DeadOps;
Bill Wendling4a23d722008-03-03 22:14:33 +00001031 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
1032 MachineOperand &MO = getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +00001033 if (!MO.isReg() || !MO.isUse())
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001034 continue;
1035 unsigned Reg = MO.getReg();
1036 if (!Reg)
1037 continue;
Bill Wendling4a23d722008-03-03 22:14:33 +00001038
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001039 if (Reg == IncomingReg) {
Dan Gohman3f629402008-09-03 15:56:16 +00001040 if (!Found) {
1041 if (MO.isKill())
1042 // The register is already marked kill.
1043 return true;
Jakob Stoklund Olesenece48182009-08-02 19:13:03 +00001044 if (isPhysReg && isRegTiedToDefOperand(i))
1045 // Two-address uses of physregs must not be marked kill.
1046 return true;
Dan Gohman3f629402008-09-03 15:56:16 +00001047 MO.setIsKill();
1048 Found = true;
1049 }
1050 } else if (hasAliases && MO.isKill() &&
1051 TargetRegisterInfo::isPhysicalRegister(Reg)) {
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001052 // A super-register kill already exists.
1053 if (RegInfo->isSuperRegister(IncomingReg, Reg))
Dan Gohman2ebc11a2008-07-03 01:18:51 +00001054 return true;
1055 if (RegInfo->isSubRegister(IncomingReg, Reg))
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001056 DeadOps.push_back(i);
Bill Wendling4a23d722008-03-03 22:14:33 +00001057 }
1058 }
1059
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001060 // Trim unneeded kill operands.
1061 while (!DeadOps.empty()) {
1062 unsigned OpIdx = DeadOps.back();
1063 if (getOperand(OpIdx).isImplicit())
1064 RemoveOperand(OpIdx);
1065 else
1066 getOperand(OpIdx).setIsKill(false);
1067 DeadOps.pop_back();
1068 }
1069
Bill Wendling4a23d722008-03-03 22:14:33 +00001070 // If not found, this means an alias of one of the operands is killed. Add a
Owen Andersonb487e722008-01-24 01:10:07 +00001071 // new implicit operand if required.
Dan Gohman3f629402008-09-03 15:56:16 +00001072 if (!Found && AddIfNotFound) {
Bill Wendling4a23d722008-03-03 22:14:33 +00001073 addOperand(MachineOperand::CreateReg(IncomingReg,
1074 false /*IsDef*/,
1075 true /*IsImp*/,
1076 true /*IsKill*/));
Owen Andersonb487e722008-01-24 01:10:07 +00001077 return true;
1078 }
Dan Gohman3f629402008-09-03 15:56:16 +00001079 return Found;
Owen Andersonb487e722008-01-24 01:10:07 +00001080}
1081
1082bool MachineInstr::addRegisterDead(unsigned IncomingReg,
Dan Gohman6f0d0242008-02-10 18:45:23 +00001083 const TargetRegisterInfo *RegInfo,
Owen Andersonb487e722008-01-24 01:10:07 +00001084 bool AddIfNotFound) {
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001085 bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
Evan Cheng01b2e232008-06-27 22:11:49 +00001086 bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
Dan Gohman3f629402008-09-03 15:56:16 +00001087 bool Found = false;
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001088 SmallVector<unsigned,4> DeadOps;
Owen Andersonb487e722008-01-24 01:10:07 +00001089 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
1090 MachineOperand &MO = getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +00001091 if (!MO.isReg() || !MO.isDef())
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001092 continue;
1093 unsigned Reg = MO.getReg();
Dan Gohman3f629402008-09-03 15:56:16 +00001094 if (!Reg)
1095 continue;
1096
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001097 if (Reg == IncomingReg) {
Dan Gohman3f629402008-09-03 15:56:16 +00001098 if (!Found) {
1099 if (MO.isDead())
1100 // The register is already marked dead.
1101 return true;
1102 MO.setIsDead();
1103 Found = true;
1104 }
1105 } else if (hasAliases && MO.isDead() &&
1106 TargetRegisterInfo::isPhysicalRegister(Reg)) {
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001107 // There exists a super-register that's marked dead.
1108 if (RegInfo->isSuperRegister(IncomingReg, Reg))
Dan Gohman2ebc11a2008-07-03 01:18:51 +00001109 return true;
Owen Anderson22ae9992008-08-14 18:34:18 +00001110 if (RegInfo->getSubRegisters(IncomingReg) &&
1111 RegInfo->getSuperRegisters(Reg) &&
1112 RegInfo->isSubRegister(IncomingReg, Reg))
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001113 DeadOps.push_back(i);
Owen Andersonb487e722008-01-24 01:10:07 +00001114 }
1115 }
1116
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001117 // Trim unneeded dead operands.
1118 while (!DeadOps.empty()) {
1119 unsigned OpIdx = DeadOps.back();
1120 if (getOperand(OpIdx).isImplicit())
1121 RemoveOperand(OpIdx);
1122 else
1123 getOperand(OpIdx).setIsDead(false);
1124 DeadOps.pop_back();
1125 }
1126
Dan Gohman3f629402008-09-03 15:56:16 +00001127 // If not found, this means an alias of one of the operands is dead. Add a
1128 // new implicit operand if required.
Chris Lattner31530612009-06-24 17:54:48 +00001129 if (Found || !AddIfNotFound)
1130 return Found;
1131
1132 addOperand(MachineOperand::CreateReg(IncomingReg,
1133 true /*IsDef*/,
1134 true /*IsImp*/,
1135 false /*IsKill*/,
1136 true /*IsDead*/));
1137 return true;
Owen Andersonb487e722008-01-24 01:10:07 +00001138}