MachineInstr.cpp 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  1. //===-- lib/CodeGen/MachineInstr.cpp --------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // Methods common to all machine instructions.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/CodeGen/MachineInstr.h"
  14. #include "llvm/Constants.h"
  15. #include "llvm/InlineAsm.h"
  16. #include "llvm/Value.h"
  17. #include "llvm/CodeGen/MachineFunction.h"
  18. #include "llvm/CodeGen/MachineRegisterInfo.h"
  19. #include "llvm/CodeGen/PseudoSourceValue.h"
  20. #include "llvm/Target/TargetMachine.h"
  21. #include "llvm/Target/TargetInstrInfo.h"
  22. #include "llvm/Target/TargetInstrDesc.h"
  23. #include "llvm/Target/TargetRegisterInfo.h"
  24. #include "llvm/Analysis/DebugInfo.h"
  25. #include "llvm/Support/ErrorHandling.h"
  26. #include "llvm/Support/LeakDetector.h"
  27. #include "llvm/Support/MathExtras.h"
  28. #include "llvm/Support/Streams.h"
  29. #include "llvm/Support/raw_ostream.h"
  30. #include "llvm/ADT/FoldingSet.h"
  31. using namespace llvm;
  32. //===----------------------------------------------------------------------===//
  33. // MachineOperand Implementation
  34. //===----------------------------------------------------------------------===//
  35. /// AddRegOperandToRegInfo - Add this register operand to the specified
  36. /// MachineRegisterInfo. If it is null, then the next/prev fields should be
  37. /// explicitly nulled out.
  38. void MachineOperand::AddRegOperandToRegInfo(MachineRegisterInfo *RegInfo) {
  39. assert(isReg() && "Can only add reg operand to use lists");
  40. // If the reginfo pointer is null, just explicitly null out or next/prev
  41. // pointers, to ensure they are not garbage.
  42. if (RegInfo == 0) {
  43. Contents.Reg.Prev = 0;
  44. Contents.Reg.Next = 0;
  45. return;
  46. }
  47. // Otherwise, add this operand to the head of the registers use/def list.
  48. MachineOperand **Head = &RegInfo->getRegUseDefListHead(getReg());
  49. // For SSA values, we prefer to keep the definition at the start of the list.
  50. // we do this by skipping over the definition if it is at the head of the
  51. // list.
  52. if (*Head && (*Head)->isDef())
  53. Head = &(*Head)->Contents.Reg.Next;
  54. Contents.Reg.Next = *Head;
  55. if (Contents.Reg.Next) {
  56. assert(getReg() == Contents.Reg.Next->getReg() &&
  57. "Different regs on the same list!");
  58. Contents.Reg.Next->Contents.Reg.Prev = &Contents.Reg.Next;
  59. }
  60. Contents.Reg.Prev = Head;
  61. *Head = this;
  62. }
  63. /// RemoveRegOperandFromRegInfo - Remove this register operand from the
  64. /// MachineRegisterInfo it is linked with.
  65. void MachineOperand::RemoveRegOperandFromRegInfo() {
  66. assert(isOnRegUseList() && "Reg operand is not on a use list");
  67. // Unlink this from the doubly linked list of operands.
  68. MachineOperand *NextOp = Contents.Reg.Next;
  69. *Contents.Reg.Prev = NextOp;
  70. if (NextOp) {
  71. assert(NextOp->getReg() == getReg() && "Corrupt reg use/def chain!");
  72. NextOp->Contents.Reg.Prev = Contents.Reg.Prev;
  73. }
  74. Contents.Reg.Prev = 0;
  75. Contents.Reg.Next = 0;
  76. }
  77. void MachineOperand::setReg(unsigned Reg) {
  78. if (getReg() == Reg) return; // No change.
  79. // Otherwise, we have to change the register. If this operand is embedded
  80. // into a machine function, we need to update the old and new register's
  81. // use/def lists.
  82. if (MachineInstr *MI = getParent())
  83. if (MachineBasicBlock *MBB = MI->getParent())
  84. if (MachineFunction *MF = MBB->getParent()) {
  85. RemoveRegOperandFromRegInfo();
  86. Contents.Reg.RegNo = Reg;
  87. AddRegOperandToRegInfo(&MF->getRegInfo());
  88. return;
  89. }
  90. // Otherwise, just change the register, no problem. :)
  91. Contents.Reg.RegNo = Reg;
  92. }
  93. /// ChangeToImmediate - Replace this operand with a new immediate operand of
  94. /// the specified value. If an operand is known to be an immediate already,
  95. /// the setImm method should be used.
  96. void MachineOperand::ChangeToImmediate(int64_t ImmVal) {
  97. // If this operand is currently a register operand, and if this is in a
  98. // function, deregister the operand from the register's use/def list.
  99. if (isReg() && getParent() && getParent()->getParent() &&
  100. getParent()->getParent()->getParent())
  101. RemoveRegOperandFromRegInfo();
  102. OpKind = MO_Immediate;
  103. Contents.ImmVal = ImmVal;
  104. }
  105. /// ChangeToRegister - Replace this operand with a new register operand of
  106. /// the specified value. If an operand is known to be an register already,
  107. /// the setReg method should be used.
  108. void MachineOperand::ChangeToRegister(unsigned Reg, bool isDef, bool isImp,
  109. bool isKill, bool isDead, bool isUndef) {
  110. // If this operand is already a register operand, use setReg to update the
  111. // register's use/def lists.
  112. if (isReg()) {
  113. assert(!isEarlyClobber());
  114. setReg(Reg);
  115. } else {
  116. // Otherwise, change this to a register and set the reg#.
  117. OpKind = MO_Register;
  118. Contents.Reg.RegNo = Reg;
  119. // If this operand is embedded in a function, add the operand to the
  120. // register's use/def list.
  121. if (MachineInstr *MI = getParent())
  122. if (MachineBasicBlock *MBB = MI->getParent())
  123. if (MachineFunction *MF = MBB->getParent())
  124. AddRegOperandToRegInfo(&MF->getRegInfo());
  125. }
  126. IsDef = isDef;
  127. IsImp = isImp;
  128. IsKill = isKill;
  129. IsDead = isDead;
  130. IsUndef = isUndef;
  131. IsEarlyClobber = false;
  132. SubReg = 0;
  133. }
  134. /// isIdenticalTo - Return true if this operand is identical to the specified
  135. /// operand.
  136. bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
  137. if (getType() != Other.getType() ||
  138. getTargetFlags() != Other.getTargetFlags())
  139. return false;
  140. switch (getType()) {
  141. default: LLVM_UNREACHABLE("Unrecognized operand type");
  142. case MachineOperand::MO_Register:
  143. return getReg() == Other.getReg() && isDef() == Other.isDef() &&
  144. getSubReg() == Other.getSubReg();
  145. case MachineOperand::MO_Immediate:
  146. return getImm() == Other.getImm();
  147. case MachineOperand::MO_FPImmediate:
  148. return getFPImm() == Other.getFPImm();
  149. case MachineOperand::MO_MachineBasicBlock:
  150. return getMBB() == Other.getMBB();
  151. case MachineOperand::MO_FrameIndex:
  152. return getIndex() == Other.getIndex();
  153. case MachineOperand::MO_ConstantPoolIndex:
  154. return getIndex() == Other.getIndex() && getOffset() == Other.getOffset();
  155. case MachineOperand::MO_JumpTableIndex:
  156. return getIndex() == Other.getIndex();
  157. case MachineOperand::MO_GlobalAddress:
  158. return getGlobal() == Other.getGlobal() && getOffset() == Other.getOffset();
  159. case MachineOperand::MO_ExternalSymbol:
  160. return !strcmp(getSymbolName(), Other.getSymbolName()) &&
  161. getOffset() == Other.getOffset();
  162. }
  163. }
  164. /// print - Print the specified machine operand.
  165. ///
  166. void MachineOperand::print(std::ostream &OS, const TargetMachine *TM) const {
  167. raw_os_ostream RawOS(OS);
  168. print(RawOS, TM);
  169. }
  170. void MachineOperand::print(raw_ostream &OS, const TargetMachine *TM) const {
  171. switch (getType()) {
  172. case MachineOperand::MO_Register:
  173. if (getReg() == 0 || TargetRegisterInfo::isVirtualRegister(getReg())) {
  174. OS << "%reg" << getReg();
  175. } else {
  176. // If the instruction is embedded into a basic block, we can find the
  177. // target info for the instruction.
  178. if (TM == 0)
  179. if (const MachineInstr *MI = getParent())
  180. if (const MachineBasicBlock *MBB = MI->getParent())
  181. if (const MachineFunction *MF = MBB->getParent())
  182. TM = &MF->getTarget();
  183. if (TM)
  184. OS << "%" << TM->getRegisterInfo()->get(getReg()).Name;
  185. else
  186. OS << "%mreg" << getReg();
  187. }
  188. if (getSubReg() != 0)
  189. OS << ':' << getSubReg();
  190. if (isDef() || isKill() || isDead() || isImplicit() || isUndef() ||
  191. isEarlyClobber()) {
  192. OS << '<';
  193. bool NeedComma = false;
  194. if (isImplicit()) {
  195. if (NeedComma) OS << ',';
  196. OS << (isDef() ? "imp-def" : "imp-use");
  197. NeedComma = true;
  198. } else if (isDef()) {
  199. if (NeedComma) OS << ',';
  200. if (isEarlyClobber())
  201. OS << "earlyclobber,";
  202. OS << "def";
  203. NeedComma = true;
  204. }
  205. if (isKill() || isDead() || isUndef()) {
  206. if (NeedComma) OS << ',';
  207. if (isKill()) OS << "kill";
  208. if (isDead()) OS << "dead";
  209. if (isUndef()) {
  210. if (isKill() || isDead())
  211. OS << ',';
  212. OS << "undef";
  213. }
  214. }
  215. OS << '>';
  216. }
  217. break;
  218. case MachineOperand::MO_Immediate:
  219. OS << getImm();
  220. break;
  221. case MachineOperand::MO_FPImmediate:
  222. if (getFPImm()->getType() == Type::FloatTy)
  223. OS << getFPImm()->getValueAPF().convertToFloat();
  224. else
  225. OS << getFPImm()->getValueAPF().convertToDouble();
  226. break;
  227. case MachineOperand::MO_MachineBasicBlock:
  228. OS << "mbb<"
  229. << ((Value*)getMBB()->getBasicBlock())->getName()
  230. << "," << (void*)getMBB() << '>';
  231. break;
  232. case MachineOperand::MO_FrameIndex:
  233. OS << "<fi#" << getIndex() << '>';
  234. break;
  235. case MachineOperand::MO_ConstantPoolIndex:
  236. OS << "<cp#" << getIndex();
  237. if (getOffset()) OS << "+" << getOffset();
  238. OS << '>';
  239. break;
  240. case MachineOperand::MO_JumpTableIndex:
  241. OS << "<jt#" << getIndex() << '>';
  242. break;
  243. case MachineOperand::MO_GlobalAddress:
  244. OS << "<ga:" << ((Value*)getGlobal())->getName();
  245. if (getOffset()) OS << "+" << getOffset();
  246. OS << '>';
  247. break;
  248. case MachineOperand::MO_ExternalSymbol:
  249. OS << "<es:" << getSymbolName();
  250. if (getOffset()) OS << "+" << getOffset();
  251. OS << '>';
  252. break;
  253. default:
  254. LLVM_UNREACHABLE("Unrecognized operand type");
  255. }
  256. if (unsigned TF = getTargetFlags())
  257. OS << "[TF=" << TF << ']';
  258. }
  259. //===----------------------------------------------------------------------===//
  260. // MachineMemOperand Implementation
  261. //===----------------------------------------------------------------------===//
  262. MachineMemOperand::MachineMemOperand(const Value *v, unsigned int f,
  263. int64_t o, uint64_t s, unsigned int a)
  264. : Offset(o), Size(s), V(v),
  265. Flags((f & 7) | ((Log2_32(a) + 1) << 3)) {
  266. assert(isPowerOf2_32(a) && "Alignment is not a power of 2!");
  267. assert((isLoad() || isStore()) && "Not a load/store!");
  268. }
  269. /// Profile - Gather unique data for the object.
  270. ///
  271. void MachineMemOperand::Profile(FoldingSetNodeID &ID) const {
  272. ID.AddInteger(Offset);
  273. ID.AddInteger(Size);
  274. ID.AddPointer(V);
  275. ID.AddInteger(Flags);
  276. }
  277. //===----------------------------------------------------------------------===//
  278. // MachineInstr Implementation
  279. //===----------------------------------------------------------------------===//
  280. /// MachineInstr ctor - This constructor creates a dummy MachineInstr with
  281. /// TID NULL and no operands.
  282. MachineInstr::MachineInstr()
  283. : TID(0), NumImplicitOps(0), Parent(0), debugLoc(DebugLoc::getUnknownLoc()) {
  284. // Make sure that we get added to a machine basicblock
  285. LeakDetector::addGarbageObject(this);
  286. }
  287. void MachineInstr::addImplicitDefUseOperands() {
  288. if (TID->ImplicitDefs)
  289. for (const unsigned *ImpDefs = TID->ImplicitDefs; *ImpDefs; ++ImpDefs)
  290. addOperand(MachineOperand::CreateReg(*ImpDefs, true, true));
  291. if (TID->ImplicitUses)
  292. for (const unsigned *ImpUses = TID->ImplicitUses; *ImpUses; ++ImpUses)
  293. addOperand(MachineOperand::CreateReg(*ImpUses, false, true));
  294. }
  295. /// MachineInstr ctor - This constructor create a MachineInstr and add the
  296. /// implicit operands. It reserves space for number of operands specified by
  297. /// TargetInstrDesc or the numOperands if it is not zero. (for
  298. /// instructions with variable number of operands).
  299. MachineInstr::MachineInstr(const TargetInstrDesc &tid, bool NoImp)
  300. : TID(&tid), NumImplicitOps(0), Parent(0),
  301. debugLoc(DebugLoc::getUnknownLoc()) {
  302. if (!NoImp && TID->getImplicitDefs())
  303. for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
  304. NumImplicitOps++;
  305. if (!NoImp && TID->getImplicitUses())
  306. for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
  307. NumImplicitOps++;
  308. Operands.reserve(NumImplicitOps + TID->getNumOperands());
  309. if (!NoImp)
  310. addImplicitDefUseOperands();
  311. // Make sure that we get added to a machine basicblock
  312. LeakDetector::addGarbageObject(this);
  313. }
  314. /// MachineInstr ctor - As above, but with a DebugLoc.
  315. MachineInstr::MachineInstr(const TargetInstrDesc &tid, const DebugLoc dl,
  316. bool NoImp)
  317. : TID(&tid), NumImplicitOps(0), Parent(0), debugLoc(dl) {
  318. if (!NoImp && TID->getImplicitDefs())
  319. for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
  320. NumImplicitOps++;
  321. if (!NoImp && TID->getImplicitUses())
  322. for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
  323. NumImplicitOps++;
  324. Operands.reserve(NumImplicitOps + TID->getNumOperands());
  325. if (!NoImp)
  326. addImplicitDefUseOperands();
  327. // Make sure that we get added to a machine basicblock
  328. LeakDetector::addGarbageObject(this);
  329. }
  330. /// MachineInstr ctor - Work exactly the same as the ctor two above, except
  331. /// that the MachineInstr is created and added to the end of the specified
  332. /// basic block.
  333. ///
  334. MachineInstr::MachineInstr(MachineBasicBlock *MBB, const TargetInstrDesc &tid)
  335. : TID(&tid), NumImplicitOps(0), Parent(0),
  336. debugLoc(DebugLoc::getUnknownLoc()) {
  337. assert(MBB && "Cannot use inserting ctor with null basic block!");
  338. if (TID->ImplicitDefs)
  339. for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
  340. NumImplicitOps++;
  341. if (TID->ImplicitUses)
  342. for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
  343. NumImplicitOps++;
  344. Operands.reserve(NumImplicitOps + TID->getNumOperands());
  345. addImplicitDefUseOperands();
  346. // Make sure that we get added to a machine basicblock
  347. LeakDetector::addGarbageObject(this);
  348. MBB->push_back(this); // Add instruction to end of basic block!
  349. }
  350. /// MachineInstr ctor - As above, but with a DebugLoc.
  351. ///
  352. MachineInstr::MachineInstr(MachineBasicBlock *MBB, const DebugLoc dl,
  353. const TargetInstrDesc &tid)
  354. : TID(&tid), NumImplicitOps(0), Parent(0), debugLoc(dl) {
  355. assert(MBB && "Cannot use inserting ctor with null basic block!");
  356. if (TID->ImplicitDefs)
  357. for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)
  358. NumImplicitOps++;
  359. if (TID->ImplicitUses)
  360. for (const unsigned *ImpUses = TID->getImplicitUses(); *ImpUses; ++ImpUses)
  361. NumImplicitOps++;
  362. Operands.reserve(NumImplicitOps + TID->getNumOperands());
  363. addImplicitDefUseOperands();
  364. // Make sure that we get added to a machine basicblock
  365. LeakDetector::addGarbageObject(this);
  366. MBB->push_back(this); // Add instruction to end of basic block!
  367. }
  368. /// MachineInstr ctor - Copies MachineInstr arg exactly
  369. ///
  370. MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI)
  371. : TID(&MI.getDesc()), NumImplicitOps(0), Parent(0),
  372. debugLoc(MI.getDebugLoc()) {
  373. Operands.reserve(MI.getNumOperands());
  374. // Add operands
  375. for (unsigned i = 0; i != MI.getNumOperands(); ++i)
  376. addOperand(MI.getOperand(i));
  377. NumImplicitOps = MI.NumImplicitOps;
  378. // Add memory operands.
  379. for (std::list<MachineMemOperand>::const_iterator i = MI.memoperands_begin(),
  380. j = MI.memoperands_end(); i != j; ++i)
  381. addMemOperand(MF, *i);
  382. // Set parent to null.
  383. Parent = 0;
  384. LeakDetector::addGarbageObject(this);
  385. }
  386. MachineInstr::~MachineInstr() {
  387. LeakDetector::removeGarbageObject(this);
  388. assert(MemOperands.empty() &&
  389. "MachineInstr being deleted with live memoperands!");
  390. #ifndef NDEBUG
  391. for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
  392. assert(Operands[i].ParentMI == this && "ParentMI mismatch!");
  393. assert((!Operands[i].isReg() || !Operands[i].isOnRegUseList()) &&
  394. "Reg operand def/use list corrupted");
  395. }
  396. #endif
  397. }
  398. /// getRegInfo - If this instruction is embedded into a MachineFunction,
  399. /// return the MachineRegisterInfo object for the current function, otherwise
  400. /// return null.
  401. MachineRegisterInfo *MachineInstr::getRegInfo() {
  402. if (MachineBasicBlock *MBB = getParent())
  403. return &MBB->getParent()->getRegInfo();
  404. return 0;
  405. }
  406. /// RemoveRegOperandsFromUseLists - Unlink all of the register operands in
  407. /// this instruction from their respective use lists. This requires that the
  408. /// operands already be on their use lists.
  409. void MachineInstr::RemoveRegOperandsFromUseLists() {
  410. for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
  411. if (Operands[i].isReg())
  412. Operands[i].RemoveRegOperandFromRegInfo();
  413. }
  414. }
  415. /// AddRegOperandsToUseLists - Add all of the register operands in
  416. /// this instruction from their respective use lists. This requires that the
  417. /// operands not be on their use lists yet.
  418. void MachineInstr::AddRegOperandsToUseLists(MachineRegisterInfo &RegInfo) {
  419. for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
  420. if (Operands[i].isReg())
  421. Operands[i].AddRegOperandToRegInfo(&RegInfo);
  422. }
  423. }
  424. /// addOperand - Add the specified operand to the instruction. If it is an
  425. /// implicit operand, it is added to the end of the operand list. If it is
  426. /// an explicit operand it is added at the end of the explicit operand list
  427. /// (before the first implicit operand).
  428. void MachineInstr::addOperand(const MachineOperand &Op) {
  429. bool isImpReg = Op.isReg() && Op.isImplicit();
  430. assert((isImpReg || !OperandsComplete()) &&
  431. "Trying to add an operand to a machine instr that is already done!");
  432. MachineRegisterInfo *RegInfo = getRegInfo();
  433. // If we are adding the operand to the end of the list, our job is simpler.
  434. // This is true most of the time, so this is a reasonable optimization.
  435. if (isImpReg || NumImplicitOps == 0) {
  436. // We can only do this optimization if we know that the operand list won't
  437. // reallocate.
  438. if (Operands.empty() || Operands.size()+1 <= Operands.capacity()) {
  439. Operands.push_back(Op);
  440. // Set the parent of the operand.
  441. Operands.back().ParentMI = this;
  442. // If the operand is a register, update the operand's use list.
  443. if (Op.isReg())
  444. Operands.back().AddRegOperandToRegInfo(RegInfo);
  445. return;
  446. }
  447. }
  448. // Otherwise, we have to insert a real operand before any implicit ones.
  449. unsigned OpNo = Operands.size()-NumImplicitOps;
  450. // If this instruction isn't embedded into a function, then we don't need to
  451. // update any operand lists.
  452. if (RegInfo == 0) {
  453. // Simple insertion, no reginfo update needed for other register operands.
  454. Operands.insert(Operands.begin()+OpNo, Op);
  455. Operands[OpNo].ParentMI = this;
  456. // Do explicitly set the reginfo for this operand though, to ensure the
  457. // next/prev fields are properly nulled out.
  458. if (Operands[OpNo].isReg())
  459. Operands[OpNo].AddRegOperandToRegInfo(0);
  460. } else if (Operands.size()+1 <= Operands.capacity()) {
  461. // Otherwise, we have to remove register operands from their register use
  462. // list, add the operand, then add the register operands back to their use
  463. // list. This also must handle the case when the operand list reallocates
  464. // to somewhere else.
  465. // If insertion of this operand won't cause reallocation of the operand
  466. // list, just remove the implicit operands, add the operand, then re-add all
  467. // the rest of the operands.
  468. for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
  469. assert(Operands[i].isReg() && "Should only be an implicit reg!");
  470. Operands[i].RemoveRegOperandFromRegInfo();
  471. }
  472. // Add the operand. If it is a register, add it to the reg list.
  473. Operands.insert(Operands.begin()+OpNo, Op);
  474. Operands[OpNo].ParentMI = this;
  475. if (Operands[OpNo].isReg())
  476. Operands[OpNo].AddRegOperandToRegInfo(RegInfo);
  477. // Re-add all the implicit ops.
  478. for (unsigned i = OpNo+1, e = Operands.size(); i != e; ++i) {
  479. assert(Operands[i].isReg() && "Should only be an implicit reg!");
  480. Operands[i].AddRegOperandToRegInfo(RegInfo);
  481. }
  482. } else {
  483. // Otherwise, we will be reallocating the operand list. Remove all reg
  484. // operands from their list, then readd them after the operand list is
  485. // reallocated.
  486. RemoveRegOperandsFromUseLists();
  487. Operands.insert(Operands.begin()+OpNo, Op);
  488. Operands[OpNo].ParentMI = this;
  489. // Re-add all the operands.
  490. AddRegOperandsToUseLists(*RegInfo);
  491. }
  492. }
  493. /// RemoveOperand - Erase an operand from an instruction, leaving it with one
  494. /// fewer operand than it started with.
  495. ///
  496. void MachineInstr::RemoveOperand(unsigned OpNo) {
  497. assert(OpNo < Operands.size() && "Invalid operand number");
  498. // Special case removing the last one.
  499. if (OpNo == Operands.size()-1) {
  500. // If needed, remove from the reg def/use list.
  501. if (Operands.back().isReg() && Operands.back().isOnRegUseList())
  502. Operands.back().RemoveRegOperandFromRegInfo();
  503. Operands.pop_back();
  504. return;
  505. }
  506. // Otherwise, we are removing an interior operand. If we have reginfo to
  507. // update, remove all operands that will be shifted down from their reg lists,
  508. // move everything down, then re-add them.
  509. MachineRegisterInfo *RegInfo = getRegInfo();
  510. if (RegInfo) {
  511. for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
  512. if (Operands[i].isReg())
  513. Operands[i].RemoveRegOperandFromRegInfo();
  514. }
  515. }
  516. Operands.erase(Operands.begin()+OpNo);
  517. if (RegInfo) {
  518. for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
  519. if (Operands[i].isReg())
  520. Operands[i].AddRegOperandToRegInfo(RegInfo);
  521. }
  522. }
  523. }
  524. /// addMemOperand - Add a MachineMemOperand to the machine instruction,
  525. /// referencing arbitrary storage.
  526. void MachineInstr::addMemOperand(MachineFunction &MF,
  527. const MachineMemOperand &MO) {
  528. MemOperands.push_back(MO);
  529. }
  530. /// clearMemOperands - Erase all of this MachineInstr's MachineMemOperands.
  531. void MachineInstr::clearMemOperands(MachineFunction &MF) {
  532. MemOperands.clear();
  533. }
  534. /// removeFromParent - This method unlinks 'this' from the containing basic
  535. /// block, and returns it, but does not delete it.
  536. MachineInstr *MachineInstr::removeFromParent() {
  537. assert(getParent() && "Not embedded in a basic block!");
  538. getParent()->remove(this);
  539. return this;
  540. }
  541. /// eraseFromParent - This method unlinks 'this' from the containing basic
  542. /// block, and deletes it.
  543. void MachineInstr::eraseFromParent() {
  544. assert(getParent() && "Not embedded in a basic block!");
  545. getParent()->erase(this);
  546. }
  547. /// OperandComplete - Return true if it's illegal to add a new operand
  548. ///
  549. bool MachineInstr::OperandsComplete() const {
  550. unsigned short NumOperands = TID->getNumOperands();
  551. if (!TID->isVariadic() && getNumOperands()-NumImplicitOps >= NumOperands)
  552. return true; // Broken: we have all the operands of this instruction!
  553. return false;
  554. }
  555. /// getNumExplicitOperands - Returns the number of non-implicit operands.
  556. ///
  557. unsigned MachineInstr::getNumExplicitOperands() const {
  558. unsigned NumOperands = TID->getNumOperands();
  559. if (!TID->isVariadic())
  560. return NumOperands;
  561. for (unsigned i = NumOperands, e = getNumOperands(); i != e; ++i) {
  562. const MachineOperand &MO = getOperand(i);
  563. if (!MO.isReg() || !MO.isImplicit())
  564. NumOperands++;
  565. }
  566. return NumOperands;
  567. }
  568. /// isLabel - Returns true if the MachineInstr represents a label.
  569. ///
  570. bool MachineInstr::isLabel() const {
  571. return getOpcode() == TargetInstrInfo::DBG_LABEL ||
  572. getOpcode() == TargetInstrInfo::EH_LABEL ||
  573. getOpcode() == TargetInstrInfo::GC_LABEL;
  574. }
  575. /// isDebugLabel - Returns true if the MachineInstr represents a debug label.
  576. ///
  577. bool MachineInstr::isDebugLabel() const {
  578. return getOpcode() == TargetInstrInfo::DBG_LABEL;
  579. }
  580. /// findRegisterUseOperandIdx() - Returns the MachineOperand that is a use of
  581. /// the specific register or -1 if it is not found. It further tightening
  582. /// the search criteria to a use that kills the register if isKill is true.
  583. int MachineInstr::findRegisterUseOperandIdx(unsigned Reg, bool isKill,
  584. const TargetRegisterInfo *TRI) const {
  585. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  586. const MachineOperand &MO = getOperand(i);
  587. if (!MO.isReg() || !MO.isUse())
  588. continue;
  589. unsigned MOReg = MO.getReg();
  590. if (!MOReg)
  591. continue;
  592. if (MOReg == Reg ||
  593. (TRI &&
  594. TargetRegisterInfo::isPhysicalRegister(MOReg) &&
  595. TargetRegisterInfo::isPhysicalRegister(Reg) &&
  596. TRI->isSubRegister(MOReg, Reg)))
  597. if (!isKill || MO.isKill())
  598. return i;
  599. }
  600. return -1;
  601. }
  602. /// findRegisterDefOperandIdx() - Returns the operand index that is a def of
  603. /// the specified register or -1 if it is not found. If isDead is true, defs
  604. /// that are not dead are skipped. If TargetRegisterInfo is non-null, then it
  605. /// also checks if there is a def of a super-register.
  606. int MachineInstr::findRegisterDefOperandIdx(unsigned Reg, bool isDead,
  607. const TargetRegisterInfo *TRI) const {
  608. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  609. const MachineOperand &MO = getOperand(i);
  610. if (!MO.isReg() || !MO.isDef())
  611. continue;
  612. unsigned MOReg = MO.getReg();
  613. if (MOReg == Reg ||
  614. (TRI &&
  615. TargetRegisterInfo::isPhysicalRegister(MOReg) &&
  616. TargetRegisterInfo::isPhysicalRegister(Reg) &&
  617. TRI->isSubRegister(MOReg, Reg)))
  618. if (!isDead || MO.isDead())
  619. return i;
  620. }
  621. return -1;
  622. }
  623. /// findFirstPredOperandIdx() - Find the index of the first operand in the
  624. /// operand list that is used to represent the predicate. It returns -1 if
  625. /// none is found.
  626. int MachineInstr::findFirstPredOperandIdx() const {
  627. const TargetInstrDesc &TID = getDesc();
  628. if (TID.isPredicable()) {
  629. for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
  630. if (TID.OpInfo[i].isPredicate())
  631. return i;
  632. }
  633. return -1;
  634. }
  635. /// isRegTiedToUseOperand - Given the index of a register def operand,
  636. /// check if the register def is tied to a source operand, due to either
  637. /// two-address elimination or inline assembly constraints. Returns the
  638. /// first tied use operand index by reference is UseOpIdx is not null.
  639. bool MachineInstr::
  640. isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx) const {
  641. if (getOpcode() == TargetInstrInfo::INLINEASM) {
  642. assert(DefOpIdx >= 2);
  643. const MachineOperand &MO = getOperand(DefOpIdx);
  644. if (!MO.isReg() || !MO.isDef() || MO.getReg() == 0)
  645. return false;
  646. // Determine the actual operand index that corresponds to this index.
  647. unsigned DefNo = 0;
  648. unsigned DefPart = 0;
  649. for (unsigned i = 1, e = getNumOperands(); i < e; ) {
  650. const MachineOperand &FMO = getOperand(i);
  651. assert(FMO.isImm());
  652. // Skip over this def.
  653. unsigned NumOps = InlineAsm::getNumOperandRegisters(FMO.getImm());
  654. unsigned PrevDef = i + 1;
  655. i = PrevDef + NumOps;
  656. if (i > DefOpIdx) {
  657. DefPart = DefOpIdx - PrevDef;
  658. break;
  659. }
  660. ++DefNo;
  661. }
  662. for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
  663. const MachineOperand &FMO = getOperand(i);
  664. if (!FMO.isImm())
  665. continue;
  666. if (i+1 >= e || !getOperand(i+1).isReg() || !getOperand(i+1).isUse())
  667. continue;
  668. unsigned Idx;
  669. if (InlineAsm::isUseOperandTiedToDef(FMO.getImm(), Idx) &&
  670. Idx == DefNo) {
  671. if (UseOpIdx)
  672. *UseOpIdx = (unsigned)i + 1 + DefPart;
  673. return true;
  674. }
  675. }
  676. return false;
  677. }
  678. assert(getOperand(DefOpIdx).isDef() && "DefOpIdx is not a def!");
  679. const TargetInstrDesc &TID = getDesc();
  680. for (unsigned i = 0, e = TID.getNumOperands(); i != e; ++i) {
  681. const MachineOperand &MO = getOperand(i);
  682. if (MO.isReg() && MO.isUse() &&
  683. TID.getOperandConstraint(i, TOI::TIED_TO) == (int)DefOpIdx) {
  684. if (UseOpIdx)
  685. *UseOpIdx = (unsigned)i;
  686. return true;
  687. }
  688. }
  689. return false;
  690. }
  691. /// isRegTiedToDefOperand - Return true if the operand of the specified index
  692. /// is a register use and it is tied to an def operand. It also returns the def
  693. /// operand index by reference.
  694. bool MachineInstr::
  695. isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx) const {
  696. if (getOpcode() == TargetInstrInfo::INLINEASM) {
  697. const MachineOperand &MO = getOperand(UseOpIdx);
  698. if (!MO.isReg() || !MO.isUse() || MO.getReg() == 0)
  699. return false;
  700. int FlagIdx = UseOpIdx - 1;
  701. if (FlagIdx < 1)
  702. return false;
  703. while (!getOperand(FlagIdx).isImm()) {
  704. if (--FlagIdx == 0)
  705. return false;
  706. }
  707. const MachineOperand &UFMO = getOperand(FlagIdx);
  708. if (FlagIdx + InlineAsm::getNumOperandRegisters(UFMO.getImm()) < UseOpIdx)
  709. return false;
  710. unsigned DefNo;
  711. if (InlineAsm::isUseOperandTiedToDef(UFMO.getImm(), DefNo)) {
  712. if (!DefOpIdx)
  713. return true;
  714. unsigned DefIdx = 1;
  715. // Remember to adjust the index. First operand is asm string, then there
  716. // is a flag for each.
  717. while (DefNo) {
  718. const MachineOperand &FMO = getOperand(DefIdx);
  719. assert(FMO.isImm());
  720. // Skip over this def.
  721. DefIdx += InlineAsm::getNumOperandRegisters(FMO.getImm()) + 1;
  722. --DefNo;
  723. }
  724. *DefOpIdx = DefIdx + UseOpIdx - FlagIdx;
  725. return true;
  726. }
  727. return false;
  728. }
  729. const TargetInstrDesc &TID = getDesc();
  730. if (UseOpIdx >= TID.getNumOperands())
  731. return false;
  732. const MachineOperand &MO = getOperand(UseOpIdx);
  733. if (!MO.isReg() || !MO.isUse())
  734. return false;
  735. int DefIdx = TID.getOperandConstraint(UseOpIdx, TOI::TIED_TO);
  736. if (DefIdx == -1)
  737. return false;
  738. if (DefOpIdx)
  739. *DefOpIdx = (unsigned)DefIdx;
  740. return true;
  741. }
  742. /// copyKillDeadInfo - Copies kill / dead operand properties from MI.
  743. ///
  744. void MachineInstr::copyKillDeadInfo(const MachineInstr *MI) {
  745. for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
  746. const MachineOperand &MO = MI->getOperand(i);
  747. if (!MO.isReg() || (!MO.isKill() && !MO.isDead()))
  748. continue;
  749. for (unsigned j = 0, ee = getNumOperands(); j != ee; ++j) {
  750. MachineOperand &MOp = getOperand(j);
  751. if (!MOp.isIdenticalTo(MO))
  752. continue;
  753. if (MO.isKill())
  754. MOp.setIsKill();
  755. else
  756. MOp.setIsDead();
  757. break;
  758. }
  759. }
  760. }
  761. /// copyPredicates - Copies predicate operand(s) from MI.
  762. void MachineInstr::copyPredicates(const MachineInstr *MI) {
  763. const TargetInstrDesc &TID = MI->getDesc();
  764. if (!TID.isPredicable())
  765. return;
  766. for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
  767. if (TID.OpInfo[i].isPredicate()) {
  768. // Predicated operands must be last operands.
  769. addOperand(MI->getOperand(i));
  770. }
  771. }
  772. }
  773. /// isSafeToMove - Return true if it is safe to move this instruction. If
  774. /// SawStore is set to true, it means that there is a store (or call) between
  775. /// the instruction's location and its intended destination.
  776. bool MachineInstr::isSafeToMove(const TargetInstrInfo *TII,
  777. bool &SawStore) const {
  778. // Ignore stuff that we obviously can't move.
  779. if (TID->mayStore() || TID->isCall()) {
  780. SawStore = true;
  781. return false;
  782. }
  783. if (TID->isTerminator() || TID->hasUnmodeledSideEffects())
  784. return false;
  785. // See if this instruction does a load. If so, we have to guarantee that the
  786. // loaded value doesn't change between the load and the its intended
  787. // destination. The check for isInvariantLoad gives the targe the chance to
  788. // classify the load as always returning a constant, e.g. a constant pool
  789. // load.
  790. if (TID->mayLoad() && !TII->isInvariantLoad(this))
  791. // Otherwise, this is a real load. If there is a store between the load and
  792. // end of block, or if the laod is volatile, we can't move it.
  793. return !SawStore && !hasVolatileMemoryRef();
  794. return true;
  795. }
  796. /// isSafeToReMat - Return true if it's safe to rematerialize the specified
  797. /// instruction which defined the specified register instead of copying it.
  798. bool MachineInstr::isSafeToReMat(const TargetInstrInfo *TII,
  799. unsigned DstReg) const {
  800. bool SawStore = false;
  801. if (!getDesc().isRematerializable() ||
  802. !TII->isTriviallyReMaterializable(this) ||
  803. !isSafeToMove(TII, SawStore))
  804. return false;
  805. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  806. const MachineOperand &MO = getOperand(i);
  807. if (!MO.isReg())
  808. continue;
  809. // FIXME: For now, do not remat any instruction with register operands.
  810. // Later on, we can loosen the restriction is the register operands have
  811. // not been modified between the def and use. Note, this is different from
  812. // MachineSink because the code is no longer in two-address form (at least
  813. // partially).
  814. if (MO.isUse())
  815. return false;
  816. else if (!MO.isDead() && MO.getReg() != DstReg)
  817. return false;
  818. }
  819. return true;
  820. }
  821. /// hasVolatileMemoryRef - Return true if this instruction may have a
  822. /// volatile memory reference, or if the information describing the
  823. /// memory reference is not available. Return false if it is known to
  824. /// have no volatile memory references.
  825. bool MachineInstr::hasVolatileMemoryRef() const {
  826. // An instruction known never to access memory won't have a volatile access.
  827. if (!TID->mayStore() &&
  828. !TID->mayLoad() &&
  829. !TID->isCall() &&
  830. !TID->hasUnmodeledSideEffects())
  831. return false;
  832. // Otherwise, if the instruction has no memory reference information,
  833. // conservatively assume it wasn't preserved.
  834. if (memoperands_empty())
  835. return true;
  836. // Check the memory reference information for volatile references.
  837. for (std::list<MachineMemOperand>::const_iterator I = memoperands_begin(),
  838. E = memoperands_end(); I != E; ++I)
  839. if (I->isVolatile())
  840. return true;
  841. return false;
  842. }
  843. void MachineInstr::dump() const {
  844. cerr << " " << *this;
  845. }
  846. void MachineInstr::print(std::ostream &OS, const TargetMachine *TM) const {
  847. raw_os_ostream RawOS(OS);
  848. print(RawOS, TM);
  849. }
  850. void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM) const {
  851. // Specialize printing if op#0 is definition
  852. unsigned StartOp = 0;
  853. if (getNumOperands() && getOperand(0).isReg() && getOperand(0).isDef()) {
  854. getOperand(0).print(OS, TM);
  855. OS << " = ";
  856. ++StartOp; // Don't print this operand again!
  857. }
  858. OS << getDesc().getName();
  859. for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
  860. if (i != StartOp)
  861. OS << ",";
  862. OS << " ";
  863. getOperand(i).print(OS, TM);
  864. }
  865. if (!memoperands_empty()) {
  866. OS << ", Mem:";
  867. for (std::list<MachineMemOperand>::const_iterator i = memoperands_begin(),
  868. e = memoperands_end(); i != e; ++i) {
  869. const MachineMemOperand &MRO = *i;
  870. const Value *V = MRO.getValue();
  871. assert((MRO.isLoad() || MRO.isStore()) &&
  872. "SV has to be a load, store or both.");
  873. if (MRO.isVolatile())
  874. OS << "Volatile ";
  875. if (MRO.isLoad())
  876. OS << "LD";
  877. if (MRO.isStore())
  878. OS << "ST";
  879. OS << "(" << MRO.getSize() << "," << MRO.getAlignment() << ") [";
  880. if (!V)
  881. OS << "<unknown>";
  882. else if (!V->getName().empty())
  883. OS << V->getName();
  884. else if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) {
  885. PSV->print(OS);
  886. } else
  887. OS << V;
  888. OS << " + " << MRO.getOffset() << "]";
  889. }
  890. }
  891. if (!debugLoc.isUnknown()) {
  892. const MachineFunction *MF = getParent()->getParent();
  893. DebugLocTuple DLT = MF->getDebugLocTuple(debugLoc);
  894. DICompileUnit CU(DLT.CompileUnit);
  895. std::string Dir, Fn;
  896. OS << " [dbg: "
  897. << CU.getDirectory(Dir) << '/' << CU.getFilename(Fn) << ","
  898. << DLT.Line << ","
  899. << DLT.Col << "]";
  900. }
  901. OS << "\n";
  902. }
  903. bool MachineInstr::addRegisterKilled(unsigned IncomingReg,
  904. const TargetRegisterInfo *RegInfo,
  905. bool AddIfNotFound) {
  906. bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
  907. bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
  908. bool Found = false;
  909. SmallVector<unsigned,4> DeadOps;
  910. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  911. MachineOperand &MO = getOperand(i);
  912. if (!MO.isReg() || !MO.isUse())
  913. continue;
  914. unsigned Reg = MO.getReg();
  915. if (!Reg)
  916. continue;
  917. if (Reg == IncomingReg) {
  918. if (!Found) {
  919. if (MO.isKill())
  920. // The register is already marked kill.
  921. return true;
  922. MO.setIsKill();
  923. Found = true;
  924. }
  925. } else if (hasAliases && MO.isKill() &&
  926. TargetRegisterInfo::isPhysicalRegister(Reg)) {
  927. // A super-register kill already exists.
  928. if (RegInfo->isSuperRegister(IncomingReg, Reg))
  929. return true;
  930. if (RegInfo->isSubRegister(IncomingReg, Reg))
  931. DeadOps.push_back(i);
  932. }
  933. }
  934. // Trim unneeded kill operands.
  935. while (!DeadOps.empty()) {
  936. unsigned OpIdx = DeadOps.back();
  937. if (getOperand(OpIdx).isImplicit())
  938. RemoveOperand(OpIdx);
  939. else
  940. getOperand(OpIdx).setIsKill(false);
  941. DeadOps.pop_back();
  942. }
  943. // If not found, this means an alias of one of the operands is killed. Add a
  944. // new implicit operand if required.
  945. if (!Found && AddIfNotFound) {
  946. addOperand(MachineOperand::CreateReg(IncomingReg,
  947. false /*IsDef*/,
  948. true /*IsImp*/,
  949. true /*IsKill*/));
  950. return true;
  951. }
  952. return Found;
  953. }
  954. bool MachineInstr::addRegisterDead(unsigned IncomingReg,
  955. const TargetRegisterInfo *RegInfo,
  956. bool AddIfNotFound) {
  957. bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
  958. bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
  959. bool Found = false;
  960. SmallVector<unsigned,4> DeadOps;
  961. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  962. MachineOperand &MO = getOperand(i);
  963. if (!MO.isReg() || !MO.isDef())
  964. continue;
  965. unsigned Reg = MO.getReg();
  966. if (!Reg)
  967. continue;
  968. if (Reg == IncomingReg) {
  969. if (!Found) {
  970. if (MO.isDead())
  971. // The register is already marked dead.
  972. return true;
  973. MO.setIsDead();
  974. Found = true;
  975. }
  976. } else if (hasAliases && MO.isDead() &&
  977. TargetRegisterInfo::isPhysicalRegister(Reg)) {
  978. // There exists a super-register that's marked dead.
  979. if (RegInfo->isSuperRegister(IncomingReg, Reg))
  980. return true;
  981. if (RegInfo->getSubRegisters(IncomingReg) &&
  982. RegInfo->getSuperRegisters(Reg) &&
  983. RegInfo->isSubRegister(IncomingReg, Reg))
  984. DeadOps.push_back(i);
  985. }
  986. }
  987. // Trim unneeded dead operands.
  988. while (!DeadOps.empty()) {
  989. unsigned OpIdx = DeadOps.back();
  990. if (getOperand(OpIdx).isImplicit())
  991. RemoveOperand(OpIdx);
  992. else
  993. getOperand(OpIdx).setIsDead(false);
  994. DeadOps.pop_back();
  995. }
  996. // If not found, this means an alias of one of the operands is dead. Add a
  997. // new implicit operand if required.
  998. if (Found || !AddIfNotFound)
  999. return Found;
  1000. addOperand(MachineOperand::CreateReg(IncomingReg,
  1001. true /*IsDef*/,
  1002. true /*IsImp*/,
  1003. false /*IsKill*/,
  1004. true /*IsDead*/));
  1005. return true;
  1006. }