blob: f9c3d0417505957b0d41dabfe3542d59edbf6158 [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///
Mon P Wang5ca6bd12008-10-10 01:43:55 +0000186void MachineOperand::print(raw_ostream &OS, const TargetMachine *TM) const {
Chris Lattnerf7382302007-12-30 21:56:09 +0000187 switch (getType()) {
188 case MachineOperand::MO_Register:
Dan Gohman6f0d0242008-02-10 18:45:23 +0000189 if (getReg() == 0 || TargetRegisterInfo::isVirtualRegister(getReg())) {
Chris Lattnerf7382302007-12-30 21:56:09 +0000190 OS << "%reg" << getReg();
191 } else {
192 // If the instruction is embedded into a basic block, we can find the
Chris Lattner62ed6b92008-01-01 01:12:31 +0000193 // target info for the instruction.
Chris Lattnerf7382302007-12-30 21:56:09 +0000194 if (TM == 0)
195 if (const MachineInstr *MI = getParent())
196 if (const MachineBasicBlock *MBB = MI->getParent())
197 if (const MachineFunction *MF = MBB->getParent())
198 TM = &MF->getTarget();
199
200 if (TM)
Bill Wendlinge6d088a2008-02-26 21:47:57 +0000201 OS << "%" << TM->getRegisterInfo()->get(getReg()).Name;
Chris Lattnerf7382302007-12-30 21:56:09 +0000202 else
203 OS << "%mreg" << getReg();
204 }
Dan Gohman2ccc8392008-12-18 21:51:27 +0000205
Evan Cheng4784f1f2009-06-30 08:49:04 +0000206 if (getSubReg() != 0)
Chris Lattner31530612009-06-24 17:54:48 +0000207 OS << ':' << getSubReg();
Dan Gohman2ccc8392008-12-18 21:51:27 +0000208
Evan Cheng4784f1f2009-06-30 08:49:04 +0000209 if (isDef() || isKill() || isDead() || isImplicit() || isUndef() ||
210 isEarlyClobber()) {
Chris Lattner31530612009-06-24 17:54:48 +0000211 OS << '<';
Chris Lattnerf7382302007-12-30 21:56:09 +0000212 bool NeedComma = false;
213 if (isImplicit()) {
Chris Lattner31530612009-06-24 17:54:48 +0000214 if (NeedComma) OS << ',';
Chris Lattnerf7382302007-12-30 21:56:09 +0000215 OS << (isDef() ? "imp-def" : "imp-use");
216 NeedComma = true;
217 } else if (isDef()) {
Chris Lattner31530612009-06-24 17:54:48 +0000218 if (NeedComma) OS << ',';
Dale Johannesen913d3df2008-09-12 17:49:03 +0000219 if (isEarlyClobber())
220 OS << "earlyclobber,";
Chris Lattnerf7382302007-12-30 21:56:09 +0000221 OS << "def";
222 NeedComma = true;
223 }
Evan Cheng4784f1f2009-06-30 08:49:04 +0000224 if (isKill() || isDead() || isUndef()) {
Chris Lattner31530612009-06-24 17:54:48 +0000225 if (NeedComma) OS << ',';
Bill Wendling181eb732008-02-24 00:56:13 +0000226 if (isKill()) OS << "kill";
227 if (isDead()) OS << "dead";
Evan Cheng4784f1f2009-06-30 08:49:04 +0000228 if (isUndef()) {
229 if (isKill() || isDead())
230 OS << ',';
231 OS << "undef";
232 }
Chris Lattnerf7382302007-12-30 21:56:09 +0000233 }
Chris Lattner31530612009-06-24 17:54:48 +0000234 OS << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000235 }
236 break;
237 case MachineOperand::MO_Immediate:
238 OS << getImm();
239 break;
Nate Begemane8b7ccf2008-02-14 07:39:30 +0000240 case MachineOperand::MO_FPImmediate:
Owen Anderson1d0be152009-08-13 21:58:54 +0000241 if (getFPImm()->getType() == Type::getFloatTy(getFPImm()->getContext()))
Nate Begemane8b7ccf2008-02-14 07:39:30 +0000242 OS << getFPImm()->getValueAPF().convertToFloat();
Chris Lattner31530612009-06-24 17:54:48 +0000243 else
Nate Begemane8b7ccf2008-02-14 07:39:30 +0000244 OS << getFPImm()->getValueAPF().convertToDouble();
Nate Begemane8b7ccf2008-02-14 07:39:30 +0000245 break;
Chris Lattnerf7382302007-12-30 21:56:09 +0000246 case MachineOperand::MO_MachineBasicBlock:
247 OS << "mbb<"
Chris Lattner8aa797a2007-12-30 23:10:15 +0000248 << ((Value*)getMBB()->getBasicBlock())->getName()
Chris Lattner31530612009-06-24 17:54:48 +0000249 << "," << (void*)getMBB() << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000250 break;
251 case MachineOperand::MO_FrameIndex:
Chris Lattner31530612009-06-24 17:54:48 +0000252 OS << "<fi#" << getIndex() << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000253 break;
254 case MachineOperand::MO_ConstantPoolIndex:
Chris Lattner8aa797a2007-12-30 23:10:15 +0000255 OS << "<cp#" << getIndex();
Chris Lattnerf7382302007-12-30 21:56:09 +0000256 if (getOffset()) OS << "+" << getOffset();
Chris Lattner31530612009-06-24 17:54:48 +0000257 OS << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000258 break;
259 case MachineOperand::MO_JumpTableIndex:
Chris Lattner31530612009-06-24 17:54:48 +0000260 OS << "<jt#" << getIndex() << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000261 break;
262 case MachineOperand::MO_GlobalAddress:
263 OS << "<ga:" << ((Value*)getGlobal())->getName();
264 if (getOffset()) OS << "+" << getOffset();
Chris Lattner31530612009-06-24 17:54:48 +0000265 OS << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000266 break;
267 case MachineOperand::MO_ExternalSymbol:
268 OS << "<es:" << getSymbolName();
269 if (getOffset()) OS << "+" << getOffset();
Chris Lattner31530612009-06-24 17:54:48 +0000270 OS << '>';
Chris Lattnerf7382302007-12-30 21:56:09 +0000271 break;
272 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000273 llvm_unreachable("Unrecognized operand type");
Chris Lattnerf7382302007-12-30 21:56:09 +0000274 }
Chris Lattner31530612009-06-24 17:54:48 +0000275
276 if (unsigned TF = getTargetFlags())
277 OS << "[TF=" << TF << ']';
Chris Lattnerf7382302007-12-30 21:56:09 +0000278}
279
280//===----------------------------------------------------------------------===//
Dan Gohmance42e402008-07-07 20:32:02 +0000281// MachineMemOperand Implementation
282//===----------------------------------------------------------------------===//
283
284MachineMemOperand::MachineMemOperand(const Value *v, unsigned int f,
285 int64_t o, uint64_t s, unsigned int a)
286 : Offset(o), Size(s), V(v),
287 Flags((f & 7) | ((Log2_32(a) + 1) << 3)) {
Dan Gohmanf1bf29e2008-07-08 23:47:04 +0000288 assert(isPowerOf2_32(a) && "Alignment is not a power of 2!");
Dan Gohmanc5e1f982008-07-16 15:56:42 +0000289 assert((isLoad() || isStore()) && "Not a load/store!");
Dan Gohmance42e402008-07-07 20:32:02 +0000290}
291
Dan Gohmanb8d2f552008-08-20 15:58:01 +0000292/// Profile - Gather unique data for the object.
293///
294void MachineMemOperand::Profile(FoldingSetNodeID &ID) const {
295 ID.AddInteger(Offset);
296 ID.AddInteger(Size);
297 ID.AddPointer(V);
298 ID.AddInteger(Flags);
299}
300
Dan Gohmance42e402008-07-07 20:32:02 +0000301//===----------------------------------------------------------------------===//
Chris Lattnerf7382302007-12-30 21:56:09 +0000302// MachineInstr Implementation
303//===----------------------------------------------------------------------===//
304
Evan Chengc0f64ff2006-11-27 23:37:22 +0000305/// MachineInstr ctor - This constructor creates a dummy MachineInstr with
Evan Cheng67f660c2006-11-30 07:08:44 +0000306/// TID NULL and no operands.
Evan Chengc0f64ff2006-11-27 23:37:22 +0000307MachineInstr::MachineInstr()
Dale Johannesen06efc022009-01-27 23:20:29 +0000308 : TID(0), NumImplicitOps(0), Parent(0), debugLoc(DebugLoc::getUnknownLoc()) {
Dan Gohman2c3f7ae2008-07-17 23:49:46 +0000309 // Make sure that we get added to a machine basicblock
310 LeakDetector::addGarbageObject(this);
Chris Lattner72791222002-10-28 20:59:49 +0000311}
312
Evan Cheng67f660c2006-11-30 07:08:44 +0000313void MachineInstr::addImplicitDefUseOperands() {
314 if (TID->ImplicitDefs)
Chris Lattnera4161ee2007-12-30 00:12:25 +0000315 for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs)
Chris Lattner8019f412007-12-30 00:41:17 +0000316 addOperand(MachineOperand::CreateReg(*ImpDefs, true, true));
Evan Cheng67f660c2006-11-30 07:08:44 +0000317 if (TID->ImplicitUses)
Chris Lattnera4161ee2007-12-30 00:12:25 +0000318 for (const unsigned *ImpUses = TID->ImplicitUses; *ImpUses; ++ImpUses)
Chris Lattner8019f412007-12-30 00:41:17 +0000319 addOperand(MachineOperand::CreateReg(*ImpUses, false, true));
Evan Chengd7de4962006-11-13 23:34:06 +0000320}
321
322/// MachineInstr ctor - This constructor create a MachineInstr and add the
Evan Chengc0f64ff2006-11-27 23:37:22 +0000323/// implicit operands. It reserves space for number of operands specified by
Chris Lattner749c6f62008-01-07 07:27:27 +0000324/// TargetInstrDesc or the numOperands if it is not zero. (for
Evan Chengc0f64ff2006-11-27 23:37:22 +0000325/// instructions with variable number of operands).
Chris Lattner749c6f62008-01-07 07:27:27 +0000326MachineInstr::MachineInstr(const TargetInstrDesc &tid, bool NoImp)
Dale Johannesen06efc022009-01-27 23:20:29 +0000327 : TID(&tid), NumImplicitOps(0), Parent(0),
328 debugLoc(DebugLoc::getUnknownLoc()) {
Chris Lattner349c4952008-01-07 03:13:06 +0000329 if (!NoImp && TID->getImplicitDefs())
330 for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
Evan Chengd7de4962006-11-13 23:34:06 +0000331 NumImplicitOps++;
Chris Lattner349c4952008-01-07 03:13:06 +0000332 if (!NoImp && TID->getImplicitUses())
333 for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
Evan Chengd7de4962006-11-13 23:34:06 +0000334 NumImplicitOps++;
Chris Lattner349c4952008-01-07 03:13:06 +0000335 Operands.reserve(NumImplicitOps + TID->getNumOperands());
Evan Chengfa945722007-10-13 02:23:01 +0000336 if (!NoImp)
337 addImplicitDefUseOperands();
Dan Gohman2c3f7ae2008-07-17 23:49:46 +0000338 // Make sure that we get added to a machine basicblock
339 LeakDetector::addGarbageObject(this);
Evan Chengd7de4962006-11-13 23:34:06 +0000340}
341
Dale Johannesen06efc022009-01-27 23:20:29 +0000342/// MachineInstr ctor - As above, but with a DebugLoc.
343MachineInstr::MachineInstr(const TargetInstrDesc &tid, const DebugLoc dl,
344 bool NoImp)
345 : TID(&tid), NumImplicitOps(0), Parent(0), debugLoc(dl) {
346 if (!NoImp && TID->getImplicitDefs())
347 for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
348 NumImplicitOps++;
349 if (!NoImp && TID->getImplicitUses())
350 for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
351 NumImplicitOps++;
352 Operands.reserve(NumImplicitOps + TID->getNumOperands());
353 if (!NoImp)
354 addImplicitDefUseOperands();
355 // Make sure that we get added to a machine basicblock
356 LeakDetector::addGarbageObject(this);
357}
358
359/// MachineInstr ctor - Work exactly the same as the ctor two above, except
360/// that the MachineInstr is created and added to the end of the specified
361/// basic block.
Chris Lattnerddd7fcb2002-10-29 23:19:00 +0000362///
Dale Johannesen06efc022009-01-27 23:20:29 +0000363MachineInstr::MachineInstr(MachineBasicBlock *MBB, const TargetInstrDesc &tid)
364 : TID(&tid), NumImplicitOps(0), Parent(0),
365 debugLoc(DebugLoc::getUnknownLoc()) {
366 assert(MBB && "Cannot use inserting ctor with null basic block!");
367 if (TID->ImplicitDefs)
368 for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
369 NumImplicitOps++;
370 if (TID->ImplicitUses)
371 for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
372 NumImplicitOps++;
373 Operands.reserve(NumImplicitOps + TID->getNumOperands());
374 addImplicitDefUseOperands();
375 // Make sure that we get added to a machine basicblock
376 LeakDetector::addGarbageObject(this);
377 MBB->push_back(this); // Add instruction to end of basic block!
378}
379
380/// MachineInstr ctor - As above, but with a DebugLoc.
381///
382MachineInstr::MachineInstr(MachineBasicBlock *MBB, const DebugLoc dl,
Chris Lattner749c6f62008-01-07 07:27:27 +0000383 const TargetInstrDesc &tid)
Dale Johannesen06efc022009-01-27 23:20:29 +0000384 : TID(&tid), NumImplicitOps(0), Parent(0), debugLoc(dl) {
Chris Lattnerddd7fcb2002-10-29 23:19:00 +0000385 assert(MBB && "Cannot use inserting ctor with null basic block!");
Evan Cheng67f660c2006-11-30 07:08:44 +0000386 if (TID->ImplicitDefs)
Chris Lattner349c4952008-01-07 03:13:06 +0000387 for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
Evan Chengd7de4962006-11-13 23:34:06 +0000388 NumImplicitOps++;
Evan Cheng67f660c2006-11-30 07:08:44 +0000389 if (TID->ImplicitUses)
Chris Lattner349c4952008-01-07 03:13:06 +0000390 for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
Evan Chengd7de4962006-11-13 23:34:06 +0000391 NumImplicitOps++;
Chris Lattner349c4952008-01-07 03:13:06 +0000392 Operands.reserve(NumImplicitOps + TID->getNumOperands());
Evan Cheng67f660c2006-11-30 07:08:44 +0000393 addImplicitDefUseOperands();
Dan Gohman2c3f7ae2008-07-17 23:49:46 +0000394 // Make sure that we get added to a machine basicblock
395 LeakDetector::addGarbageObject(this);
Chris Lattnerddd7fcb2002-10-29 23:19:00 +0000396 MBB->push_back(this); // Add instruction to end of basic block!
397}
398
Misha Brukmance22e762004-07-09 14:45:17 +0000399/// MachineInstr ctor - Copies MachineInstr arg exactly
400///
Evan Cheng1ed99222008-07-19 00:37:25 +0000401MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI)
Dale Johannesen06efc022009-01-27 23:20:29 +0000402 : TID(&MI.getDesc()), NumImplicitOps(0), Parent(0),
403 debugLoc(MI.getDebugLoc()) {
Chris Lattner943b5e12006-05-04 19:14:44 +0000404 Operands.reserve(MI.getNumOperands());
Tanya Lattnerb5159ed2004-05-23 20:58:02 +0000405
Misha Brukmance22e762004-07-09 14:45:17 +0000406 // Add operands
Evan Cheng1ed99222008-07-19 00:37:25 +0000407 for (unsigned i = 0; i != MI.getNumOperands(); ++i)
408 addOperand(MI.getOperand(i));
409 NumImplicitOps = MI.NumImplicitOps;
Tanya Lattner0c63e032004-05-24 03:14:18 +0000410
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000411 // Add memory operands.
Dan Gohmanfed90b62008-07-28 21:51:04 +0000412 for (std::list<MachineMemOperand>::const_iterator i = MI.memoperands_begin(),
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000413 j = MI.memoperands_end(); i != j; ++i)
414 addMemOperand(MF, *i);
415
416 // Set parent to null.
Chris Lattnerf20c1a42007-12-31 04:56:33 +0000417 Parent = 0;
Dan Gohman6116a732008-07-21 18:47:29 +0000418
419 LeakDetector::addGarbageObject(this);
Tanya Lattner466b5342004-05-23 19:35:12 +0000420}
421
Misha Brukmance22e762004-07-09 14:45:17 +0000422MachineInstr::~MachineInstr() {
Dan Gohman2c3f7ae2008-07-17 23:49:46 +0000423 LeakDetector::removeGarbageObject(this);
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000424 assert(MemOperands.empty() &&
425 "MachineInstr being deleted with live memoperands!");
Chris Lattnere12d6ab2007-12-30 06:11:04 +0000426#ifndef NDEBUG
Chris Lattner62ed6b92008-01-01 01:12:31 +0000427 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
Chris Lattnere12d6ab2007-12-30 06:11:04 +0000428 assert(Operands[i].ParentMI == this && "ParentMI mismatch!");
Dan Gohmand735b802008-10-03 15:45:36 +0000429 assert((!Operands[i].isReg() || !Operands[i].isOnRegUseList()) &&
Chris Lattner62ed6b92008-01-01 01:12:31 +0000430 "Reg operand def/use list corrupted");
431 }
Chris Lattnere12d6ab2007-12-30 06:11:04 +0000432#endif
Alkis Evlogimenosaad5c052004-02-16 07:17:43 +0000433}
434
Chris Lattner62ed6b92008-01-01 01:12:31 +0000435/// getRegInfo - If this instruction is embedded into a MachineFunction,
436/// return the MachineRegisterInfo object for the current function, otherwise
437/// return null.
438MachineRegisterInfo *MachineInstr::getRegInfo() {
439 if (MachineBasicBlock *MBB = getParent())
Dan Gohman4e526b92008-07-08 23:59:09 +0000440 return &MBB->getParent()->getRegInfo();
Chris Lattner62ed6b92008-01-01 01:12:31 +0000441 return 0;
442}
443
444/// RemoveRegOperandsFromUseLists - Unlink all of the register operands in
445/// this instruction from their respective use lists. This requires that the
446/// operands already be on their use lists.
447void MachineInstr::RemoveRegOperandsFromUseLists() {
448 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000449 if (Operands[i].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000450 Operands[i].RemoveRegOperandFromRegInfo();
451 }
452}
453
454/// AddRegOperandsToUseLists - Add all of the register operands in
455/// this instruction from their respective use lists. This requires that the
456/// operands not be on their use lists yet.
457void MachineInstr::AddRegOperandsToUseLists(MachineRegisterInfo &RegInfo) {
458 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000459 if (Operands[i].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000460 Operands[i].AddRegOperandToRegInfo(&RegInfo);
461 }
462}
463
464
465/// addOperand - Add the specified operand to the instruction. If it is an
466/// implicit operand, it is added to the end of the operand list. If it is
467/// an explicit operand it is added at the end of the explicit operand list
468/// (before the first implicit operand).
469void MachineInstr::addOperand(const MachineOperand &Op) {
Dan Gohmand735b802008-10-03 15:45:36 +0000470 bool isImpReg = Op.isReg() && Op.isImplicit();
Chris Lattner62ed6b92008-01-01 01:12:31 +0000471 assert((isImpReg || !OperandsComplete()) &&
472 "Trying to add an operand to a machine instr that is already done!");
473
Dan Gohmanbcf28c02008-12-09 22:45:08 +0000474 MachineRegisterInfo *RegInfo = getRegInfo();
475
Chris Lattner62ed6b92008-01-01 01:12:31 +0000476 // If we are adding the operand to the end of the list, our job is simpler.
477 // This is true most of the time, so this is a reasonable optimization.
478 if (isImpReg || NumImplicitOps == 0) {
479 // We can only do this optimization if we know that the operand list won't
480 // reallocate.
481 if (Operands.empty() || Operands.size()+1 <= Operands.capacity()) {
482 Operands.push_back(Op);
483
484 // Set the parent of the operand.
485 Operands.back().ParentMI = this;
486
487 // If the operand is a register, update the operand's use list.
Dan Gohmand735b802008-10-03 15:45:36 +0000488 if (Op.isReg())
Dan Gohmanbcf28c02008-12-09 22:45:08 +0000489 Operands.back().AddRegOperandToRegInfo(RegInfo);
Chris Lattner62ed6b92008-01-01 01:12:31 +0000490 return;
491 }
492 }
493
494 // Otherwise, we have to insert a real operand before any implicit ones.
495 unsigned OpNo = Operands.size()-NumImplicitOps;
496
Chris Lattner62ed6b92008-01-01 01:12:31 +0000497 // If this instruction isn't embedded into a function, then we don't need to
498 // update any operand lists.
499 if (RegInfo == 0) {
500 // Simple insertion, no reginfo update needed for other register operands.
501 Operands.insert(Operands.begin()+OpNo, Op);
502 Operands[OpNo].ParentMI = this;
503
504 // Do explicitly set the reginfo for this operand though, to ensure the
505 // next/prev fields are properly nulled out.
Dan Gohmand735b802008-10-03 15:45:36 +0000506 if (Operands[OpNo].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000507 Operands[OpNo].AddRegOperandToRegInfo(0);
508
509 } else if (Operands.size()+1 <= Operands.capacity()) {
510 // Otherwise, we have to remove register operands from their register use
511 // list, add the operand, then add the register operands back to their use
512 // list. This also must handle the case when the operand list reallocates
513 // to somewhere else.
514
515 // If insertion of this operand won't cause reallocation of the operand
516 // list, just remove the implicit operands, add the operand, then re-add all
517 // the rest of the operands.
518 for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000519 assert(Operands[i].isReg() && "Should only be an implicit reg!");
Chris Lattner62ed6b92008-01-01 01:12:31 +0000520 Operands[i].RemoveRegOperandFromRegInfo();
521 }
522
523 // Add the operand. If it is a register, add it to the reg list.
524 Operands.insert(Operands.begin()+OpNo, Op);
525 Operands[OpNo].ParentMI = this;
526
Dan Gohmand735b802008-10-03 15:45:36 +0000527 if (Operands[OpNo].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000528 Operands[OpNo].AddRegOperandToRegInfo(RegInfo);
529
530 // Re-add all the implicit ops.
531 for (unsigned i = OpNo+1, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000532 assert(Operands[i].isReg() && "Should only be an implicit reg!");
Chris Lattner62ed6b92008-01-01 01:12:31 +0000533 Operands[i].AddRegOperandToRegInfo(RegInfo);
534 }
535 } else {
536 // Otherwise, we will be reallocating the operand list. Remove all reg
537 // operands from their list, then readd them after the operand list is
538 // reallocated.
539 RemoveRegOperandsFromUseLists();
540
541 Operands.insert(Operands.begin()+OpNo, Op);
542 Operands[OpNo].ParentMI = this;
543
544 // Re-add all the operands.
545 AddRegOperandsToUseLists(*RegInfo);
546 }
547}
548
549/// RemoveOperand - Erase an operand from an instruction, leaving it with one
550/// fewer operand than it started with.
551///
552void MachineInstr::RemoveOperand(unsigned OpNo) {
553 assert(OpNo < Operands.size() && "Invalid operand number");
554
555 // Special case removing the last one.
556 if (OpNo == Operands.size()-1) {
557 // If needed, remove from the reg def/use list.
Dan Gohmand735b802008-10-03 15:45:36 +0000558 if (Operands.back().isReg() && Operands.back().isOnRegUseList())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000559 Operands.back().RemoveRegOperandFromRegInfo();
560
561 Operands.pop_back();
562 return;
563 }
564
565 // Otherwise, we are removing an interior operand. If we have reginfo to
566 // update, remove all operands that will be shifted down from their reg lists,
567 // move everything down, then re-add them.
568 MachineRegisterInfo *RegInfo = getRegInfo();
569 if (RegInfo) {
570 for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000571 if (Operands[i].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000572 Operands[i].RemoveRegOperandFromRegInfo();
573 }
574 }
575
576 Operands.erase(Operands.begin()+OpNo);
577
578 if (RegInfo) {
579 for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
Dan Gohmand735b802008-10-03 15:45:36 +0000580 if (Operands[i].isReg())
Chris Lattner62ed6b92008-01-01 01:12:31 +0000581 Operands[i].AddRegOperandToRegInfo(RegInfo);
582 }
583 }
584}
585
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000586/// addMemOperand - Add a MachineMemOperand to the machine instruction,
587/// referencing arbitrary storage.
588void MachineInstr::addMemOperand(MachineFunction &MF,
589 const MachineMemOperand &MO) {
Dan Gohmanfed90b62008-07-28 21:51:04 +0000590 MemOperands.push_back(MO);
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000591}
592
593/// clearMemOperands - Erase all of this MachineInstr's MachineMemOperands.
594void MachineInstr::clearMemOperands(MachineFunction &MF) {
Dan Gohmanfed90b62008-07-28 21:51:04 +0000595 MemOperands.clear();
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000596}
597
Chris Lattner62ed6b92008-01-01 01:12:31 +0000598
Chris Lattner48d7c062006-04-17 21:35:41 +0000599/// removeFromParent - This method unlinks 'this' from the containing basic
600/// block, and returns it, but does not delete it.
601MachineInstr *MachineInstr::removeFromParent() {
602 assert(getParent() && "Not embedded in a basic block!");
603 getParent()->remove(this);
604 return this;
605}
606
607
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000608/// eraseFromParent - This method unlinks 'this' from the containing basic
609/// block, and deletes it.
610void MachineInstr::eraseFromParent() {
611 assert(getParent() && "Not embedded in a basic block!");
612 getParent()->erase(this);
613}
614
615
Brian Gaeke21326fc2004-02-13 04:39:32 +0000616/// OperandComplete - Return true if it's illegal to add a new operand
617///
Chris Lattner2a90ba62004-02-12 16:09:53 +0000618bool MachineInstr::OperandsComplete() const {
Chris Lattner349c4952008-01-07 03:13:06 +0000619 unsigned short NumOperands = TID->getNumOperands();
Chris Lattner8f707e12008-01-07 05:19:29 +0000620 if (!TID->isVariadic() && getNumOperands()-NumImplicitOps >= NumOperands)
Vikram S. Adve34977822003-05-31 07:39:06 +0000621 return true; // Broken: we have all the operands of this instruction!
Chris Lattner413746e2002-10-28 20:48:39 +0000622 return false;
623}
624
Evan Cheng19e3f312007-05-15 01:26:09 +0000625/// getNumExplicitOperands - Returns the number of non-implicit operands.
626///
627unsigned MachineInstr::getNumExplicitOperands() const {
Chris Lattner349c4952008-01-07 03:13:06 +0000628 unsigned NumOperands = TID->getNumOperands();
Chris Lattner8f707e12008-01-07 05:19:29 +0000629 if (!TID->isVariadic())
Evan Cheng19e3f312007-05-15 01:26:09 +0000630 return NumOperands;
631
Dan Gohman9407cd42009-04-15 17:59:11 +0000632 for (unsigned i = NumOperands, e = getNumOperands(); i != e; ++i) {
633 const MachineOperand &MO = getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +0000634 if (!MO.isReg() || !MO.isImplicit())
Evan Cheng19e3f312007-05-15 01:26:09 +0000635 NumOperands++;
636 }
637 return NumOperands;
638}
639
Chris Lattner8ace2cd2006-10-20 22:39:59 +0000640
Dan Gohman44066042008-07-01 00:05:16 +0000641/// isLabel - Returns true if the MachineInstr represents a label.
642///
643bool MachineInstr::isLabel() const {
644 return getOpcode() == TargetInstrInfo::DBG_LABEL ||
645 getOpcode() == TargetInstrInfo::EH_LABEL ||
646 getOpcode() == TargetInstrInfo::GC_LABEL;
647}
648
Evan Chengbb81d972008-01-31 09:59:15 +0000649/// isDebugLabel - Returns true if the MachineInstr represents a debug label.
650///
651bool MachineInstr::isDebugLabel() const {
Dan Gohman44066042008-07-01 00:05:16 +0000652 return getOpcode() == TargetInstrInfo::DBG_LABEL;
Evan Chengbb81d972008-01-31 09:59:15 +0000653}
654
Evan Chengfaa51072007-04-26 19:00:32 +0000655/// findRegisterUseOperandIdx() - Returns the MachineOperand that is a use of
Evan Cheng32eb1f12007-03-26 22:37:45 +0000656/// the specific register or -1 if it is not found. It further tightening
Evan Cheng76d7e762007-02-23 01:04:26 +0000657/// the search criteria to a use that kills the register if isKill is true.
Evan Cheng6130f662008-03-05 00:59:57 +0000658int MachineInstr::findRegisterUseOperandIdx(unsigned Reg, bool isKill,
659 const TargetRegisterInfo *TRI) const {
Evan Cheng576d1232006-12-06 08:27:42 +0000660 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
Evan Chengf277ee42007-05-29 18:35:22 +0000661 const MachineOperand &MO = getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +0000662 if (!MO.isReg() || !MO.isUse())
Evan Cheng6130f662008-03-05 00:59:57 +0000663 continue;
664 unsigned MOReg = MO.getReg();
665 if (!MOReg)
666 continue;
667 if (MOReg == Reg ||
668 (TRI &&
669 TargetRegisterInfo::isPhysicalRegister(MOReg) &&
670 TargetRegisterInfo::isPhysicalRegister(Reg) &&
671 TRI->isSubRegister(MOReg, Reg)))
Evan Cheng76d7e762007-02-23 01:04:26 +0000672 if (!isKill || MO.isKill())
Evan Cheng32eb1f12007-03-26 22:37:45 +0000673 return i;
Evan Cheng576d1232006-12-06 08:27:42 +0000674 }
Evan Cheng32eb1f12007-03-26 22:37:45 +0000675 return -1;
Evan Cheng576d1232006-12-06 08:27:42 +0000676}
677
Evan Cheng6130f662008-03-05 00:59:57 +0000678/// findRegisterDefOperandIdx() - Returns the operand index that is a def of
Dan Gohman703bfe62008-05-06 00:20:10 +0000679/// the specified register or -1 if it is not found. If isDead is true, defs
680/// that are not dead are skipped. If TargetRegisterInfo is non-null, then it
681/// also checks if there is a def of a super-register.
Evan Cheng6130f662008-03-05 00:59:57 +0000682int MachineInstr::findRegisterDefOperandIdx(unsigned Reg, bool isDead,
683 const TargetRegisterInfo *TRI) const {
Evan Chengb371f452007-02-19 21:49:54 +0000684 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
Evan Cheng6130f662008-03-05 00:59:57 +0000685 const MachineOperand &MO = getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +0000686 if (!MO.isReg() || !MO.isDef())
Evan Cheng6130f662008-03-05 00:59:57 +0000687 continue;
688 unsigned MOReg = MO.getReg();
689 if (MOReg == Reg ||
690 (TRI &&
691 TargetRegisterInfo::isPhysicalRegister(MOReg) &&
692 TargetRegisterInfo::isPhysicalRegister(Reg) &&
693 TRI->isSubRegister(MOReg, Reg)))
694 if (!isDead || MO.isDead())
695 return i;
Evan Chengb371f452007-02-19 21:49:54 +0000696 }
Evan Cheng6130f662008-03-05 00:59:57 +0000697 return -1;
Evan Chengb371f452007-02-19 21:49:54 +0000698}
Evan Cheng19e3f312007-05-15 01:26:09 +0000699
Evan Chengf277ee42007-05-29 18:35:22 +0000700/// findFirstPredOperandIdx() - Find the index of the first operand in the
701/// operand list that is used to represent the predicate. It returns -1 if
702/// none is found.
703int MachineInstr::findFirstPredOperandIdx() const {
Chris Lattner749c6f62008-01-07 07:27:27 +0000704 const TargetInstrDesc &TID = getDesc();
705 if (TID.isPredicable()) {
Evan Cheng19e3f312007-05-15 01:26:09 +0000706 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
Chris Lattner749c6f62008-01-07 07:27:27 +0000707 if (TID.OpInfo[i].isPredicate())
Evan Chengf277ee42007-05-29 18:35:22 +0000708 return i;
Evan Cheng19e3f312007-05-15 01:26:09 +0000709 }
710
Evan Chengf277ee42007-05-29 18:35:22 +0000711 return -1;
Evan Cheng19e3f312007-05-15 01:26:09 +0000712}
Evan Chengb371f452007-02-19 21:49:54 +0000713
Bob Wilsond9df5012009-04-09 17:16:43 +0000714/// isRegTiedToUseOperand - Given the index of a register def operand,
715/// check if the register def is tied to a source operand, due to either
716/// two-address elimination or inline assembly constraints. Returns the
717/// first tied use operand index by reference is UseOpIdx is not null.
Jakob Stoklund Olesence9be2c2009-04-29 20:57:16 +0000718bool MachineInstr::
719isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx) const {
Evan Chengfb112882009-03-23 08:01:15 +0000720 if (getOpcode() == TargetInstrInfo::INLINEASM) {
Bob Wilsond9df5012009-04-09 17:16:43 +0000721 assert(DefOpIdx >= 2);
722 const MachineOperand &MO = getOperand(DefOpIdx);
Chris Lattnerc30aa7b2009-04-09 23:33:34 +0000723 if (!MO.isReg() || !MO.isDef() || MO.getReg() == 0)
Evan Chengfb112882009-03-23 08:01:15 +0000724 return false;
Evan Chengef5d0702009-06-24 02:05:51 +0000725 // Determine the actual operand index that corresponds to this index.
Evan Chengfb112882009-03-23 08:01:15 +0000726 unsigned DefNo = 0;
Evan Chengef5d0702009-06-24 02:05:51 +0000727 unsigned DefPart = 0;
Evan Chengfb112882009-03-23 08:01:15 +0000728 for (unsigned i = 1, e = getNumOperands(); i < e; ) {
729 const MachineOperand &FMO = getOperand(i);
Jakob Stoklund Olesen45d34fe2009-07-19 19:09:59 +0000730 // After the normal asm operands there may be additional imp-def regs.
731 if (!FMO.isImm())
732 return false;
Evan Chengfb112882009-03-23 08:01:15 +0000733 // Skip over this def.
Evan Chengef5d0702009-06-24 02:05:51 +0000734 unsigned NumOps = InlineAsm::getNumOperandRegisters(FMO.getImm());
735 unsigned PrevDef = i + 1;
736 i = PrevDef + NumOps;
737 if (i > DefOpIdx) {
738 DefPart = DefOpIdx - PrevDef;
Evan Chengfb112882009-03-23 08:01:15 +0000739 break;
Evan Chengef5d0702009-06-24 02:05:51 +0000740 }
Evan Chengfb112882009-03-23 08:01:15 +0000741 ++DefNo;
742 }
Evan Chengef5d0702009-06-24 02:05:51 +0000743 for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
Evan Chengfb112882009-03-23 08:01:15 +0000744 const MachineOperand &FMO = getOperand(i);
745 if (!FMO.isImm())
746 continue;
747 if (i+1 >= e || !getOperand(i+1).isReg() || !getOperand(i+1).isUse())
748 continue;
749 unsigned Idx;
Evan Chengef5d0702009-06-24 02:05:51 +0000750 if (InlineAsm::isUseOperandTiedToDef(FMO.getImm(), Idx) &&
Bob Wilsond9df5012009-04-09 17:16:43 +0000751 Idx == DefNo) {
752 if (UseOpIdx)
Evan Chengef5d0702009-06-24 02:05:51 +0000753 *UseOpIdx = (unsigned)i + 1 + DefPart;
Evan Chengfb112882009-03-23 08:01:15 +0000754 return true;
Bob Wilsond9df5012009-04-09 17:16:43 +0000755 }
Evan Chengfb112882009-03-23 08:01:15 +0000756 }
Evan Chengef5d0702009-06-24 02:05:51 +0000757 return false;
Evan Chengfb112882009-03-23 08:01:15 +0000758 }
759
Bob Wilsond9df5012009-04-09 17:16:43 +0000760 assert(getOperand(DefOpIdx).isDef() && "DefOpIdx is not a def!");
Chris Lattner749c6f62008-01-07 07:27:27 +0000761 const TargetInstrDesc &TID = getDesc();
Evan Chengef0732d2008-07-10 07:35:43 +0000762 for (unsigned i = 0, e = TID.getNumOperands(); i != e; ++i) {
763 const MachineOperand &MO = getOperand(i);
Dan Gohman2ce7f202008-12-05 05:45:42 +0000764 if (MO.isReg() && MO.isUse() &&
Bob Wilsond9df5012009-04-09 17:16:43 +0000765 TID.getOperandConstraint(i, TOI::TIED_TO) == (int)DefOpIdx) {
766 if (UseOpIdx)
767 *UseOpIdx = (unsigned)i;
Evan Chengef0732d2008-07-10 07:35:43 +0000768 return true;
Bob Wilsond9df5012009-04-09 17:16:43 +0000769 }
Evan Cheng32dfbea2007-10-12 08:50:34 +0000770 }
771 return false;
772}
773
Evan Chenga24752f2009-03-19 20:30:06 +0000774/// isRegTiedToDefOperand - Return true if the operand of the specified index
775/// is a register use and it is tied to an def operand. It also returns the def
776/// operand index by reference.
Jakob Stoklund Olesence9be2c2009-04-29 20:57:16 +0000777bool MachineInstr::
778isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx) const {
Evan Chengfb112882009-03-23 08:01:15 +0000779 if (getOpcode() == TargetInstrInfo::INLINEASM) {
780 const MachineOperand &MO = getOperand(UseOpIdx);
Chris Lattner0c8382c2009-04-09 16:50:43 +0000781 if (!MO.isReg() || !MO.isUse() || MO.getReg() == 0)
Evan Chengfb112882009-03-23 08:01:15 +0000782 return false;
Jakob Stoklund Olesen57e599a2009-07-16 20:58:34 +0000783
784 // Find the flag operand corresponding to UseOpIdx
785 unsigned FlagIdx, NumOps=0;
786 for (FlagIdx = 1; FlagIdx < UseOpIdx; FlagIdx += NumOps+1) {
787 const MachineOperand &UFMO = getOperand(FlagIdx);
Jakob Stoklund Olesen45d34fe2009-07-19 19:09:59 +0000788 // After the normal asm operands there may be additional imp-def regs.
789 if (!UFMO.isImm())
790 return false;
Jakob Stoklund Olesen57e599a2009-07-16 20:58:34 +0000791 NumOps = InlineAsm::getNumOperandRegisters(UFMO.getImm());
792 assert(NumOps < getNumOperands() && "Invalid inline asm flag");
793 if (UseOpIdx < FlagIdx+NumOps+1)
794 break;
Evan Chengef5d0702009-06-24 02:05:51 +0000795 }
Jakob Stoklund Olesen57e599a2009-07-16 20:58:34 +0000796 if (FlagIdx >= UseOpIdx)
Evan Chengef5d0702009-06-24 02:05:51 +0000797 return false;
Jakob Stoklund Olesen57e599a2009-07-16 20:58:34 +0000798 const MachineOperand &UFMO = getOperand(FlagIdx);
Evan Chengfb112882009-03-23 08:01:15 +0000799 unsigned DefNo;
800 if (InlineAsm::isUseOperandTiedToDef(UFMO.getImm(), DefNo)) {
801 if (!DefOpIdx)
802 return true;
803
804 unsigned DefIdx = 1;
805 // Remember to adjust the index. First operand is asm string, then there
806 // is a flag for each.
807 while (DefNo) {
808 const MachineOperand &FMO = getOperand(DefIdx);
809 assert(FMO.isImm());
810 // Skip over this def.
811 DefIdx += InlineAsm::getNumOperandRegisters(FMO.getImm()) + 1;
812 --DefNo;
813 }
Evan Chengef5d0702009-06-24 02:05:51 +0000814 *DefOpIdx = DefIdx + UseOpIdx - FlagIdx;
Evan Chengfb112882009-03-23 08:01:15 +0000815 return true;
816 }
817 return false;
818 }
819
Evan Chenga24752f2009-03-19 20:30:06 +0000820 const TargetInstrDesc &TID = getDesc();
821 if (UseOpIdx >= TID.getNumOperands())
822 return false;
823 const MachineOperand &MO = getOperand(UseOpIdx);
824 if (!MO.isReg() || !MO.isUse())
825 return false;
826 int DefIdx = TID.getOperandConstraint(UseOpIdx, TOI::TIED_TO);
827 if (DefIdx == -1)
828 return false;
829 if (DefOpIdx)
830 *DefOpIdx = (unsigned)DefIdx;
831 return true;
832}
833
Evan Cheng576d1232006-12-06 08:27:42 +0000834/// copyKillDeadInfo - Copies kill / dead operand properties from MI.
835///
836void MachineInstr::copyKillDeadInfo(const MachineInstr *MI) {
837 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
838 const MachineOperand &MO = MI->getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +0000839 if (!MO.isReg() || (!MO.isKill() && !MO.isDead()))
Evan Cheng576d1232006-12-06 08:27:42 +0000840 continue;
841 for (unsigned j = 0, ee = getNumOperands(); j != ee; ++j) {
842 MachineOperand &MOp = getOperand(j);
843 if (!MOp.isIdenticalTo(MO))
844 continue;
845 if (MO.isKill())
846 MOp.setIsKill();
847 else
848 MOp.setIsDead();
849 break;
850 }
851 }
852}
853
Evan Cheng19e3f312007-05-15 01:26:09 +0000854/// copyPredicates - Copies predicate operand(s) from MI.
855void MachineInstr::copyPredicates(const MachineInstr *MI) {
Chris Lattner749c6f62008-01-07 07:27:27 +0000856 const TargetInstrDesc &TID = MI->getDesc();
Evan Chengb27087f2008-03-13 00:44:09 +0000857 if (!TID.isPredicable())
858 return;
859 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
860 if (TID.OpInfo[i].isPredicate()) {
861 // Predicated operands must be last operands.
862 addOperand(MI->getOperand(i));
Evan Cheng19e3f312007-05-15 01:26:09 +0000863 }
864 }
865}
866
Evan Cheng9f1c8312008-07-03 09:09:37 +0000867/// isSafeToMove - Return true if it is safe to move this instruction. If
868/// SawStore is set to true, it means that there is a store (or call) between
869/// the instruction's location and its intended destination.
Dan Gohmanb3b930a2008-11-18 19:04:29 +0000870bool MachineInstr::isSafeToMove(const TargetInstrInfo *TII,
871 bool &SawStore) const {
Evan Chengb27087f2008-03-13 00:44:09 +0000872 // Ignore stuff that we obviously can't move.
873 if (TID->mayStore() || TID->isCall()) {
874 SawStore = true;
875 return false;
876 }
Dan Gohman237dee12008-12-23 17:28:50 +0000877 if (TID->isTerminator() || TID->hasUnmodeledSideEffects())
Evan Chengb27087f2008-03-13 00:44:09 +0000878 return false;
879
880 // See if this instruction does a load. If so, we have to guarantee that the
881 // loaded value doesn't change between the load and the its intended
882 // destination. The check for isInvariantLoad gives the targe the chance to
883 // classify the load as always returning a constant, e.g. a constant pool
884 // load.
Dan Gohman3e4fb702008-09-24 00:06:15 +0000885 if (TID->mayLoad() && !TII->isInvariantLoad(this))
Evan Chengb27087f2008-03-13 00:44:09 +0000886 // Otherwise, this is a real load. If there is a store between the load and
Evan Cheng7cc2c402009-07-28 21:49:18 +0000887 // end of block, or if the load is volatile, we can't move it.
Dan Gohmand790a5c2008-10-02 15:04:30 +0000888 return !SawStore && !hasVolatileMemoryRef();
Dan Gohman3e4fb702008-09-24 00:06:15 +0000889
Evan Chengb27087f2008-03-13 00:44:09 +0000890 return true;
891}
892
Evan Chengdf3b9932008-08-27 20:33:50 +0000893/// isSafeToReMat - Return true if it's safe to rematerialize the specified
894/// instruction which defined the specified register instead of copying it.
Dan Gohmanb3b930a2008-11-18 19:04:29 +0000895bool MachineInstr::isSafeToReMat(const TargetInstrInfo *TII,
896 unsigned DstReg) const {
Evan Chengdf3b9932008-08-27 20:33:50 +0000897 bool SawStore = false;
Evan Cheng3689ff42008-08-30 09:07:18 +0000898 if (!getDesc().isRematerializable() ||
899 !TII->isTriviallyReMaterializable(this) ||
900 !isSafeToMove(TII, SawStore))
Evan Chengdf3b9932008-08-27 20:33:50 +0000901 return false;
902 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
Dan Gohmancbad42c2008-11-18 19:49:32 +0000903 const MachineOperand &MO = getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +0000904 if (!MO.isReg())
Evan Chengdf3b9932008-08-27 20:33:50 +0000905 continue;
906 // FIXME: For now, do not remat any instruction with register operands.
907 // Later on, we can loosen the restriction is the register operands have
908 // not been modified between the def and use. Note, this is different from
Evan Cheng8763c1c2008-08-27 20:58:54 +0000909 // MachineSink because the code is no longer in two-address form (at least
Evan Chengdf3b9932008-08-27 20:33:50 +0000910 // partially).
911 if (MO.isUse())
912 return false;
913 else if (!MO.isDead() && MO.getReg() != DstReg)
914 return false;
915 }
916 return true;
917}
918
Dan Gohman3e4fb702008-09-24 00:06:15 +0000919/// hasVolatileMemoryRef - Return true if this instruction may have a
920/// volatile memory reference, or if the information describing the
921/// memory reference is not available. Return false if it is known to
922/// have no volatile memory references.
923bool MachineInstr::hasVolatileMemoryRef() const {
924 // An instruction known never to access memory won't have a volatile access.
925 if (!TID->mayStore() &&
926 !TID->mayLoad() &&
927 !TID->isCall() &&
928 !TID->hasUnmodeledSideEffects())
929 return false;
930
931 // Otherwise, if the instruction has no memory reference information,
932 // conservatively assume it wasn't preserved.
933 if (memoperands_empty())
934 return true;
935
936 // Check the memory reference information for volatile references.
937 for (std::list<MachineMemOperand>::const_iterator I = memoperands_begin(),
938 E = memoperands_end(); I != E; ++I)
939 if (I->isVolatile())
940 return true;
941
942 return false;
943}
944
Brian Gaeke21326fc2004-02-13 04:39:32 +0000945void MachineInstr::dump() const {
Chris Lattner705e07f2009-08-23 03:41:05 +0000946 errs() << " " << *this;
Mon P Wang5ca6bd12008-10-10 01:43:55 +0000947}
948
949void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM) const {
Chris Lattnere3087892007-12-30 21:31:53 +0000950 // Specialize printing if op#0 is definition
Chris Lattner6a592272002-10-30 01:55:38 +0000951 unsigned StartOp = 0;
Dan Gohmand735b802008-10-03 15:45:36 +0000952 if (getNumOperands() && getOperand(0).isReg() && getOperand(0).isDef()) {
Chris Lattnerf7382302007-12-30 21:56:09 +0000953 getOperand(0).print(OS, TM);
Chris Lattner6a592272002-10-30 01:55:38 +0000954 OS << " = ";
955 ++StartOp; // Don't print this operand again!
956 }
Tanya Lattnerb1407622004-06-25 00:13:11 +0000957
Chris Lattner749c6f62008-01-07 07:27:27 +0000958 OS << getDesc().getName();
Misha Brukmanedf128a2005-04-21 22:36:52 +0000959
Chris Lattner6a592272002-10-30 01:55:38 +0000960 for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
961 if (i != StartOp)
962 OS << ",";
963 OS << " ";
Chris Lattnerf7382302007-12-30 21:56:09 +0000964 getOperand(i).print(OS, TM);
Chris Lattner10491642002-10-30 00:48:05 +0000965 }
Misha Brukmanedf128a2005-04-21 22:36:52 +0000966
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000967 if (!memoperands_empty()) {
Dan Gohman2bfe6ff2008-02-07 16:18:00 +0000968 OS << ", Mem:";
Dan Gohmanfed90b62008-07-28 21:51:04 +0000969 for (std::list<MachineMemOperand>::const_iterator i = memoperands_begin(),
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000970 e = memoperands_end(); i != e; ++i) {
971 const MachineMemOperand &MRO = *i;
Dan Gohman69de1932008-02-06 22:27:42 +0000972 const Value *V = MRO.getValue();
973
Dan Gohman69de1932008-02-06 22:27:42 +0000974 assert((MRO.isLoad() || MRO.isStore()) &&
975 "SV has to be a load, store or both.");
976
977 if (MRO.isVolatile())
978 OS << "Volatile ";
Dan Gohman2bfe6ff2008-02-07 16:18:00 +0000979
Dan Gohman69de1932008-02-06 22:27:42 +0000980 if (MRO.isLoad())
Dan Gohman2bfe6ff2008-02-07 16:18:00 +0000981 OS << "LD";
Dan Gohman69de1932008-02-06 22:27:42 +0000982 if (MRO.isStore())
Dan Gohman2bfe6ff2008-02-07 16:18:00 +0000983 OS << "ST";
Dan Gohman69de1932008-02-06 22:27:42 +0000984
Evan Chengbbd83222008-02-08 22:05:07 +0000985 OS << "(" << MRO.getSize() << "," << MRO.getAlignment() << ") [";
Dan Gohman69de1932008-02-06 22:27:42 +0000986
Dan Gohman2bfe6ff2008-02-07 16:18:00 +0000987 if (!V)
988 OS << "<unknown>";
989 else if (!V->getName().empty())
990 OS << V->getName();
Chris Lattneredfb72c2008-08-24 20:37:32 +0000991 else if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) {
Mon P Wang5ca6bd12008-10-10 01:43:55 +0000992 PSV->print(OS);
Chris Lattneredfb72c2008-08-24 20:37:32 +0000993 } else
Dan Gohman2bfe6ff2008-02-07 16:18:00 +0000994 OS << V;
995
996 OS << " + " << MRO.getOffset() << "]";
Dan Gohman69de1932008-02-06 22:27:42 +0000997 }
998 }
999
Bill Wendlingb5ef2732009-02-19 21:44:55 +00001000 if (!debugLoc.isUnknown()) {
1001 const MachineFunction *MF = getParent()->getParent();
1002 DebugLocTuple DLT = MF->getDebugLocTuple(debugLoc);
Argyrios Kyrtzidisa26eae62009-04-30 23:22:31 +00001003 DICompileUnit CU(DLT.CompileUnit);
1004 std::string Dir, Fn;
Bill Wendlingb5ef2732009-02-19 21:44:55 +00001005 OS << " [dbg: "
Argyrios Kyrtzidisa26eae62009-04-30 23:22:31 +00001006 << CU.getDirectory(Dir) << '/' << CU.getFilename(Fn) << ","
Bill Wendlingb5ef2732009-02-19 21:44:55 +00001007 << DLT.Line << ","
1008 << DLT.Col << "]";
1009 }
1010
Chris Lattner10491642002-10-30 00:48:05 +00001011 OS << "\n";
1012}
1013
Owen Andersonb487e722008-01-24 01:10:07 +00001014bool MachineInstr::addRegisterKilled(unsigned IncomingReg,
Dan Gohman6f0d0242008-02-10 18:45:23 +00001015 const TargetRegisterInfo *RegInfo,
Owen Andersonb487e722008-01-24 01:10:07 +00001016 bool AddIfNotFound) {
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001017 bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
Dan Gohman2ebc11a2008-07-03 01:18:51 +00001018 bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
Dan Gohman3f629402008-09-03 15:56:16 +00001019 bool Found = false;
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001020 SmallVector<unsigned,4> DeadOps;
Bill Wendling4a23d722008-03-03 22:14:33 +00001021 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
1022 MachineOperand &MO = getOperand(i);
Jakob Stoklund Olesenefb8e3e2009-08-04 20:09:25 +00001023 if (!MO.isReg() || !MO.isUse() || MO.isUndef())
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001024 continue;
1025 unsigned Reg = MO.getReg();
1026 if (!Reg)
1027 continue;
Bill Wendling4a23d722008-03-03 22:14:33 +00001028
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001029 if (Reg == IncomingReg) {
Dan Gohman3f629402008-09-03 15:56:16 +00001030 if (!Found) {
1031 if (MO.isKill())
1032 // The register is already marked kill.
1033 return true;
Jakob Stoklund Olesenece48182009-08-02 19:13:03 +00001034 if (isPhysReg && isRegTiedToDefOperand(i))
1035 // Two-address uses of physregs must not be marked kill.
1036 return true;
Dan Gohman3f629402008-09-03 15:56:16 +00001037 MO.setIsKill();
1038 Found = true;
1039 }
1040 } else if (hasAliases && MO.isKill() &&
1041 TargetRegisterInfo::isPhysicalRegister(Reg)) {
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001042 // A super-register kill already exists.
1043 if (RegInfo->isSuperRegister(IncomingReg, Reg))
Dan Gohman2ebc11a2008-07-03 01:18:51 +00001044 return true;
1045 if (RegInfo->isSubRegister(IncomingReg, Reg))
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001046 DeadOps.push_back(i);
Bill Wendling4a23d722008-03-03 22:14:33 +00001047 }
1048 }
1049
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001050 // Trim unneeded kill operands.
1051 while (!DeadOps.empty()) {
1052 unsigned OpIdx = DeadOps.back();
1053 if (getOperand(OpIdx).isImplicit())
1054 RemoveOperand(OpIdx);
1055 else
1056 getOperand(OpIdx).setIsKill(false);
1057 DeadOps.pop_back();
1058 }
1059
Bill Wendling4a23d722008-03-03 22:14:33 +00001060 // If not found, this means an alias of one of the operands is killed. Add a
Owen Andersonb487e722008-01-24 01:10:07 +00001061 // new implicit operand if required.
Dan Gohman3f629402008-09-03 15:56:16 +00001062 if (!Found && AddIfNotFound) {
Bill Wendling4a23d722008-03-03 22:14:33 +00001063 addOperand(MachineOperand::CreateReg(IncomingReg,
1064 false /*IsDef*/,
1065 true /*IsImp*/,
1066 true /*IsKill*/));
Owen Andersonb487e722008-01-24 01:10:07 +00001067 return true;
1068 }
Dan Gohman3f629402008-09-03 15:56:16 +00001069 return Found;
Owen Andersonb487e722008-01-24 01:10:07 +00001070}
1071
1072bool MachineInstr::addRegisterDead(unsigned IncomingReg,
Dan Gohman6f0d0242008-02-10 18:45:23 +00001073 const TargetRegisterInfo *RegInfo,
Owen Andersonb487e722008-01-24 01:10:07 +00001074 bool AddIfNotFound) {
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001075 bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
Evan Cheng01b2e232008-06-27 22:11:49 +00001076 bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
Dan Gohman3f629402008-09-03 15:56:16 +00001077 bool Found = false;
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001078 SmallVector<unsigned,4> DeadOps;
Owen Andersonb487e722008-01-24 01:10:07 +00001079 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
1080 MachineOperand &MO = getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +00001081 if (!MO.isReg() || !MO.isDef())
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001082 continue;
1083 unsigned Reg = MO.getReg();
Dan Gohman3f629402008-09-03 15:56:16 +00001084 if (!Reg)
1085 continue;
1086
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001087 if (Reg == IncomingReg) {
Dan Gohman3f629402008-09-03 15:56:16 +00001088 if (!Found) {
1089 if (MO.isDead())
1090 // The register is already marked dead.
1091 return true;
1092 MO.setIsDead();
1093 Found = true;
1094 }
1095 } else if (hasAliases && MO.isDead() &&
1096 TargetRegisterInfo::isPhysicalRegister(Reg)) {
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001097 // There exists a super-register that's marked dead.
1098 if (RegInfo->isSuperRegister(IncomingReg, Reg))
Dan Gohman2ebc11a2008-07-03 01:18:51 +00001099 return true;
Owen Anderson22ae9992008-08-14 18:34:18 +00001100 if (RegInfo->getSubRegisters(IncomingReg) &&
1101 RegInfo->getSuperRegisters(Reg) &&
1102 RegInfo->isSubRegister(IncomingReg, Reg))
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001103 DeadOps.push_back(i);
Owen Andersonb487e722008-01-24 01:10:07 +00001104 }
1105 }
1106
Evan Cheng9b6d7b92008-04-16 09:41:59 +00001107 // Trim unneeded dead operands.
1108 while (!DeadOps.empty()) {
1109 unsigned OpIdx = DeadOps.back();
1110 if (getOperand(OpIdx).isImplicit())
1111 RemoveOperand(OpIdx);
1112 else
1113 getOperand(OpIdx).setIsDead(false);
1114 DeadOps.pop_back();
1115 }
1116
Dan Gohman3f629402008-09-03 15:56:16 +00001117 // If not found, this means an alias of one of the operands is dead. Add a
1118 // new implicit operand if required.
Chris Lattner31530612009-06-24 17:54:48 +00001119 if (Found || !AddIfNotFound)
1120 return Found;
1121
1122 addOperand(MachineOperand::CreateReg(IncomingReg,
1123 true /*IsDef*/,
1124 true /*IsImp*/,
1125 false /*IsKill*/,
1126 true /*IsDead*/));
1127 return true;
Owen Andersonb487e722008-01-24 01:10:07 +00001128}