MachineInstr.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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::getFloatTy(getFPImm()->getContext()))
  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. // After the normal asm operands there may be additional imp-def regs.
  652. if (!FMO.isImm())
  653. return false;
  654. // Skip over this def.
  655. unsigned NumOps = InlineAsm::getNumOperandRegisters(FMO.getImm());
  656. unsigned PrevDef = i + 1;
  657. i = PrevDef + NumOps;
  658. if (i > DefOpIdx) {
  659. DefPart = DefOpIdx - PrevDef;
  660. break;
  661. }
  662. ++DefNo;
  663. }
  664. for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
  665. const MachineOperand &FMO = getOperand(i);
  666. if (!FMO.isImm())
  667. continue;
  668. if (i+1 >= e || !getOperand(i+1).isReg() || !getOperand(i+1).isUse())
  669. continue;
  670. unsigned Idx;
  671. if (InlineAsm::isUseOperandTiedToDef(FMO.getImm(), Idx) &&
  672. Idx == DefNo) {
  673. if (UseOpIdx)
  674. *UseOpIdx = (unsigned)i + 1 + DefPart;
  675. return true;
  676. }
  677. }
  678. return false;
  679. }
  680. assert(getOperand(DefOpIdx).isDef() && "DefOpIdx is not a def!");
  681. const TargetInstrDesc &TID = getDesc();
  682. for (unsigned i = 0, e = TID.getNumOperands(); i != e; ++i) {
  683. const MachineOperand &MO = getOperand(i);
  684. if (MO.isReg() && MO.isUse() &&
  685. TID.getOperandConstraint(i, TOI::TIED_TO) == (int)DefOpIdx) {
  686. if (UseOpIdx)
  687. *UseOpIdx = (unsigned)i;
  688. return true;
  689. }
  690. }
  691. return false;
  692. }
  693. /// isRegTiedToDefOperand - Return true if the operand of the specified index
  694. /// is a register use and it is tied to an def operand. It also returns the def
  695. /// operand index by reference.
  696. bool MachineInstr::
  697. isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx) const {
  698. if (getOpcode() == TargetInstrInfo::INLINEASM) {
  699. const MachineOperand &MO = getOperand(UseOpIdx);
  700. if (!MO.isReg() || !MO.isUse() || MO.getReg() == 0)
  701. return false;
  702. // Find the flag operand corresponding to UseOpIdx
  703. unsigned FlagIdx, NumOps=0;
  704. for (FlagIdx = 1; FlagIdx < UseOpIdx; FlagIdx += NumOps+1) {
  705. const MachineOperand &UFMO = getOperand(FlagIdx);
  706. // After the normal asm operands there may be additional imp-def regs.
  707. if (!UFMO.isImm())
  708. return false;
  709. NumOps = InlineAsm::getNumOperandRegisters(UFMO.getImm());
  710. assert(NumOps < getNumOperands() && "Invalid inline asm flag");
  711. if (UseOpIdx < FlagIdx+NumOps+1)
  712. break;
  713. }
  714. if (FlagIdx >= UseOpIdx)
  715. return false;
  716. const MachineOperand &UFMO = getOperand(FlagIdx);
  717. unsigned DefNo;
  718. if (InlineAsm::isUseOperandTiedToDef(UFMO.getImm(), DefNo)) {
  719. if (!DefOpIdx)
  720. return true;
  721. unsigned DefIdx = 1;
  722. // Remember to adjust the index. First operand is asm string, then there
  723. // is a flag for each.
  724. while (DefNo) {
  725. const MachineOperand &FMO = getOperand(DefIdx);
  726. assert(FMO.isImm());
  727. // Skip over this def.
  728. DefIdx += InlineAsm::getNumOperandRegisters(FMO.getImm()) + 1;
  729. --DefNo;
  730. }
  731. *DefOpIdx = DefIdx + UseOpIdx - FlagIdx;
  732. return true;
  733. }
  734. return false;
  735. }
  736. const TargetInstrDesc &TID = getDesc();
  737. if (UseOpIdx >= TID.getNumOperands())
  738. return false;
  739. const MachineOperand &MO = getOperand(UseOpIdx);
  740. if (!MO.isReg() || !MO.isUse())
  741. return false;
  742. int DefIdx = TID.getOperandConstraint(UseOpIdx, TOI::TIED_TO);
  743. if (DefIdx == -1)
  744. return false;
  745. if (DefOpIdx)
  746. *DefOpIdx = (unsigned)DefIdx;
  747. return true;
  748. }
  749. /// copyKillDeadInfo - Copies kill / dead operand properties from MI.
  750. ///
  751. void MachineInstr::copyKillDeadInfo(const MachineInstr *MI) {
  752. for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
  753. const MachineOperand &MO = MI->getOperand(i);
  754. if (!MO.isReg() || (!MO.isKill() && !MO.isDead()))
  755. continue;
  756. for (unsigned j = 0, ee = getNumOperands(); j != ee; ++j) {
  757. MachineOperand &MOp = getOperand(j);
  758. if (!MOp.isIdenticalTo(MO))
  759. continue;
  760. if (MO.isKill())
  761. MOp.setIsKill();
  762. else
  763. MOp.setIsDead();
  764. break;
  765. }
  766. }
  767. }
  768. /// copyPredicates - Copies predicate operand(s) from MI.
  769. void MachineInstr::copyPredicates(const MachineInstr *MI) {
  770. const TargetInstrDesc &TID = MI->getDesc();
  771. if (!TID.isPredicable())
  772. return;
  773. for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
  774. if (TID.OpInfo[i].isPredicate()) {
  775. // Predicated operands must be last operands.
  776. addOperand(MI->getOperand(i));
  777. }
  778. }
  779. }
  780. /// isSafeToMove - Return true if it is safe to move this instruction. If
  781. /// SawStore is set to true, it means that there is a store (or call) between
  782. /// the instruction's location and its intended destination.
  783. bool MachineInstr::isSafeToMove(const TargetInstrInfo *TII,
  784. bool &SawStore) const {
  785. // Ignore stuff that we obviously can't move.
  786. if (TID->mayStore() || TID->isCall()) {
  787. SawStore = true;
  788. return false;
  789. }
  790. if (TID->isTerminator() || TID->hasUnmodeledSideEffects())
  791. return false;
  792. // See if this instruction does a load. If so, we have to guarantee that the
  793. // loaded value doesn't change between the load and the its intended
  794. // destination. The check for isInvariantLoad gives the targe the chance to
  795. // classify the load as always returning a constant, e.g. a constant pool
  796. // load.
  797. if (TID->mayLoad() && !TII->isInvariantLoad(this))
  798. // Otherwise, this is a real load. If there is a store between the load and
  799. // end of block, or if the load is volatile, we can't move it.
  800. return !SawStore && !hasVolatileMemoryRef();
  801. return true;
  802. }
  803. /// isSafeToReMat - Return true if it's safe to rematerialize the specified
  804. /// instruction which defined the specified register instead of copying it.
  805. bool MachineInstr::isSafeToReMat(const TargetInstrInfo *TII,
  806. unsigned DstReg) const {
  807. bool SawStore = false;
  808. if (!getDesc().isRematerializable() ||
  809. !TII->isTriviallyReMaterializable(this) ||
  810. !isSafeToMove(TII, SawStore))
  811. return false;
  812. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  813. const MachineOperand &MO = getOperand(i);
  814. if (!MO.isReg())
  815. continue;
  816. // FIXME: For now, do not remat any instruction with register operands.
  817. // Later on, we can loosen the restriction is the register operands have
  818. // not been modified between the def and use. Note, this is different from
  819. // MachineSink because the code is no longer in two-address form (at least
  820. // partially).
  821. if (MO.isUse())
  822. return false;
  823. else if (!MO.isDead() && MO.getReg() != DstReg)
  824. return false;
  825. }
  826. return true;
  827. }
  828. /// hasVolatileMemoryRef - Return true if this instruction may have a
  829. /// volatile memory reference, or if the information describing the
  830. /// memory reference is not available. Return false if it is known to
  831. /// have no volatile memory references.
  832. bool MachineInstr::hasVolatileMemoryRef() const {
  833. // An instruction known never to access memory won't have a volatile access.
  834. if (!TID->mayStore() &&
  835. !TID->mayLoad() &&
  836. !TID->isCall() &&
  837. !TID->hasUnmodeledSideEffects())
  838. return false;
  839. // Otherwise, if the instruction has no memory reference information,
  840. // conservatively assume it wasn't preserved.
  841. if (memoperands_empty())
  842. return true;
  843. // Check the memory reference information for volatile references.
  844. for (std::list<MachineMemOperand>::const_iterator I = memoperands_begin(),
  845. E = memoperands_end(); I != E; ++I)
  846. if (I->isVolatile())
  847. return true;
  848. return false;
  849. }
  850. void MachineInstr::dump() const {
  851. cerr << " " << *this;
  852. }
  853. void MachineInstr::print(std::ostream &OS, const TargetMachine *TM) const {
  854. raw_os_ostream RawOS(OS);
  855. print(RawOS, TM);
  856. }
  857. void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM) const {
  858. // Specialize printing if op#0 is definition
  859. unsigned StartOp = 0;
  860. if (getNumOperands() && getOperand(0).isReg() && getOperand(0).isDef()) {
  861. getOperand(0).print(OS, TM);
  862. OS << " = ";
  863. ++StartOp; // Don't print this operand again!
  864. }
  865. OS << getDesc().getName();
  866. for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) {
  867. if (i != StartOp)
  868. OS << ",";
  869. OS << " ";
  870. getOperand(i).print(OS, TM);
  871. }
  872. if (!memoperands_empty()) {
  873. OS << ", Mem:";
  874. for (std::list<MachineMemOperand>::const_iterator i = memoperands_begin(),
  875. e = memoperands_end(); i != e; ++i) {
  876. const MachineMemOperand &MRO = *i;
  877. const Value *V = MRO.getValue();
  878. assert((MRO.isLoad() || MRO.isStore()) &&
  879. "SV has to be a load, store or both.");
  880. if (MRO.isVolatile())
  881. OS << "Volatile ";
  882. if (MRO.isLoad())
  883. OS << "LD";
  884. if (MRO.isStore())
  885. OS << "ST";
  886. OS << "(" << MRO.getSize() << "," << MRO.getAlignment() << ") [";
  887. if (!V)
  888. OS << "<unknown>";
  889. else if (!V->getName().empty())
  890. OS << V->getName();
  891. else if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) {
  892. PSV->print(OS);
  893. } else
  894. OS << V;
  895. OS << " + " << MRO.getOffset() << "]";
  896. }
  897. }
  898. if (!debugLoc.isUnknown()) {
  899. const MachineFunction *MF = getParent()->getParent();
  900. DebugLocTuple DLT = MF->getDebugLocTuple(debugLoc);
  901. DICompileUnit CU(DLT.CompileUnit);
  902. std::string Dir, Fn;
  903. OS << " [dbg: "
  904. << CU.getDirectory(Dir) << '/' << CU.getFilename(Fn) << ","
  905. << DLT.Line << ","
  906. << DLT.Col << "]";
  907. }
  908. OS << "\n";
  909. }
  910. bool MachineInstr::addRegisterKilled(unsigned IncomingReg,
  911. const TargetRegisterInfo *RegInfo,
  912. bool AddIfNotFound) {
  913. bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
  914. bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
  915. bool Found = false;
  916. SmallVector<unsigned,4> DeadOps;
  917. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  918. MachineOperand &MO = getOperand(i);
  919. if (!MO.isReg() || !MO.isUse() || MO.isUndef())
  920. continue;
  921. unsigned Reg = MO.getReg();
  922. if (!Reg)
  923. continue;
  924. if (Reg == IncomingReg) {
  925. if (!Found) {
  926. if (MO.isKill())
  927. // The register is already marked kill.
  928. return true;
  929. if (isPhysReg && isRegTiedToDefOperand(i))
  930. // Two-address uses of physregs must not be marked kill.
  931. return true;
  932. MO.setIsKill();
  933. Found = true;
  934. }
  935. } else if (hasAliases && MO.isKill() &&
  936. TargetRegisterInfo::isPhysicalRegister(Reg)) {
  937. // A super-register kill already exists.
  938. if (RegInfo->isSuperRegister(IncomingReg, Reg))
  939. return true;
  940. if (RegInfo->isSubRegister(IncomingReg, Reg))
  941. DeadOps.push_back(i);
  942. }
  943. }
  944. // Trim unneeded kill operands.
  945. while (!DeadOps.empty()) {
  946. unsigned OpIdx = DeadOps.back();
  947. if (getOperand(OpIdx).isImplicit())
  948. RemoveOperand(OpIdx);
  949. else
  950. getOperand(OpIdx).setIsKill(false);
  951. DeadOps.pop_back();
  952. }
  953. // If not found, this means an alias of one of the operands is killed. Add a
  954. // new implicit operand if required.
  955. if (!Found && AddIfNotFound) {
  956. addOperand(MachineOperand::CreateReg(IncomingReg,
  957. false /*IsDef*/,
  958. true /*IsImp*/,
  959. true /*IsKill*/));
  960. return true;
  961. }
  962. return Found;
  963. }
  964. bool MachineInstr::addRegisterDead(unsigned IncomingReg,
  965. const TargetRegisterInfo *RegInfo,
  966. bool AddIfNotFound) {
  967. bool isPhysReg = TargetRegisterInfo::isPhysicalRegister(IncomingReg);
  968. bool hasAliases = isPhysReg && RegInfo->getAliasSet(IncomingReg);
  969. bool Found = false;
  970. SmallVector<unsigned,4> DeadOps;
  971. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  972. MachineOperand &MO = getOperand(i);
  973. if (!MO.isReg() || !MO.isDef())
  974. continue;
  975. unsigned Reg = MO.getReg();
  976. if (!Reg)
  977. continue;
  978. if (Reg == IncomingReg) {
  979. if (!Found) {
  980. if (MO.isDead())
  981. // The register is already marked dead.
  982. return true;
  983. MO.setIsDead();
  984. Found = true;
  985. }
  986. } else if (hasAliases && MO.isDead() &&
  987. TargetRegisterInfo::isPhysicalRegister(Reg)) {
  988. // There exists a super-register that's marked dead.
  989. if (RegInfo->isSuperRegister(IncomingReg, Reg))
  990. return true;
  991. if (RegInfo->getSubRegisters(IncomingReg) &&
  992. RegInfo->getSuperRegisters(Reg) &&
  993. RegInfo->isSubRegister(IncomingReg, Reg))
  994. DeadOps.push_back(i);
  995. }
  996. }
  997. // Trim unneeded dead operands.
  998. while (!DeadOps.empty()) {
  999. unsigned OpIdx = DeadOps.back();
  1000. if (getOperand(OpIdx).isImplicit())
  1001. RemoveOperand(OpIdx);
  1002. else
  1003. getOperand(OpIdx).setIsDead(false);
  1004. DeadOps.pop_back();
  1005. }
  1006. // If not found, this means an alias of one of the operands is dead. Add a
  1007. // new implicit operand if required.
  1008. if (Found || !AddIfNotFound)
  1009. return Found;
  1010. addOperand(MachineOperand::CreateReg(IncomingReg,
  1011. true /*IsDef*/,
  1012. true /*IsImp*/,
  1013. false /*IsKill*/,
  1014. true /*IsDead*/));
  1015. return true;
  1016. }