Thumb1InstrInfo.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //===-- Thumb1InstrInfo.cpp - Thumb-1 Instruction Information -------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file contains the Thumb-1 implementation of the TargetInstrInfo class.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "Thumb1InstrInfo.h"
  13. #include "ARMSubtarget.h"
  14. #include "llvm/CodeGen/MachineFrameInfo.h"
  15. #include "llvm/CodeGen/MachineInstrBuilder.h"
  16. #include "llvm/CodeGen/MachineMemOperand.h"
  17. #include "llvm/MC/MCInst.h"
  18. using namespace llvm;
  19. Thumb1InstrInfo::Thumb1InstrInfo(const ARMSubtarget &STI)
  20. : ARMBaseInstrInfo(STI), RI() {}
  21. /// Return the noop instruction to use for a noop.
  22. void Thumb1InstrInfo::getNoop(MCInst &NopInst) const {
  23. NopInst.setOpcode(ARM::tMOVr);
  24. NopInst.addOperand(MCOperand::createReg(ARM::R8));
  25. NopInst.addOperand(MCOperand::createReg(ARM::R8));
  26. NopInst.addOperand(MCOperand::createImm(ARMCC::AL));
  27. NopInst.addOperand(MCOperand::createReg(0));
  28. }
  29. unsigned Thumb1InstrInfo::getUnindexedOpcode(unsigned Opc) const {
  30. return 0;
  31. }
  32. void Thumb1InstrInfo::copyPhysReg(MachineBasicBlock &MBB,
  33. MachineBasicBlock::iterator I,
  34. const DebugLoc &DL, MCRegister DestReg,
  35. MCRegister SrcReg, bool KillSrc) const {
  36. // Need to check the arch.
  37. MachineFunction &MF = *MBB.getParent();
  38. const ARMSubtarget &st = MF.getSubtarget<ARMSubtarget>();
  39. assert(ARM::GPRRegClass.contains(DestReg, SrcReg) &&
  40. "Thumb1 can only copy GPR registers");
  41. if (st.hasV6Ops() || ARM::hGPRRegClass.contains(SrcReg)
  42. || !ARM::tGPRRegClass.contains(DestReg))
  43. BuildMI(MBB, I, DL, get(ARM::tMOVr), DestReg)
  44. .addReg(SrcReg, getKillRegState(KillSrc))
  45. .add(predOps(ARMCC::AL));
  46. else {
  47. // FIXME: Can also use 'mov hi, $src; mov $dst, hi',
  48. // with hi as either r10 or r11.
  49. const TargetRegisterInfo *RegInfo = st.getRegisterInfo();
  50. if (MBB.computeRegisterLiveness(RegInfo, ARM::CPSR, I)
  51. == MachineBasicBlock::LQR_Dead) {
  52. BuildMI(MBB, I, DL, get(ARM::tMOVSr), DestReg)
  53. .addReg(SrcReg, getKillRegState(KillSrc))
  54. ->addRegisterDead(ARM::CPSR, RegInfo);
  55. return;
  56. }
  57. // 'MOV lo, lo' is unpredictable on < v6, so use the stack to do it
  58. BuildMI(MBB, I, DL, get(ARM::tPUSH))
  59. .add(predOps(ARMCC::AL))
  60. .addReg(SrcReg, getKillRegState(KillSrc));
  61. BuildMI(MBB, I, DL, get(ARM::tPOP))
  62. .add(predOps(ARMCC::AL))
  63. .addReg(DestReg, getDefRegState(true));
  64. }
  65. }
  66. void Thumb1InstrInfo::
  67. storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
  68. Register SrcReg, bool isKill, int FI,
  69. const TargetRegisterClass *RC,
  70. const TargetRegisterInfo *TRI) const {
  71. assert((RC == &ARM::tGPRRegClass ||
  72. (Register::isPhysicalRegister(SrcReg) && isARMLowRegister(SrcReg))) &&
  73. "Unknown regclass!");
  74. if (RC == &ARM::tGPRRegClass ||
  75. (Register::isPhysicalRegister(SrcReg) && isARMLowRegister(SrcReg))) {
  76. DebugLoc DL;
  77. if (I != MBB.end()) DL = I->getDebugLoc();
  78. MachineFunction &MF = *MBB.getParent();
  79. MachineFrameInfo &MFI = MF.getFrameInfo();
  80. MachineMemOperand *MMO = MF.getMachineMemOperand(
  81. MachinePointerInfo::getFixedStack(MF, FI), MachineMemOperand::MOStore,
  82. MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
  83. BuildMI(MBB, I, DL, get(ARM::tSTRspi))
  84. .addReg(SrcReg, getKillRegState(isKill))
  85. .addFrameIndex(FI)
  86. .addImm(0)
  87. .addMemOperand(MMO)
  88. .add(predOps(ARMCC::AL));
  89. }
  90. }
  91. void Thumb1InstrInfo::
  92. loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
  93. Register DestReg, int FI,
  94. const TargetRegisterClass *RC,
  95. const TargetRegisterInfo *TRI) const {
  96. assert(
  97. (RC->hasSuperClassEq(&ARM::tGPRRegClass) ||
  98. (Register::isPhysicalRegister(DestReg) && isARMLowRegister(DestReg))) &&
  99. "Unknown regclass!");
  100. if (RC->hasSuperClassEq(&ARM::tGPRRegClass) ||
  101. (Register::isPhysicalRegister(DestReg) && isARMLowRegister(DestReg))) {
  102. DebugLoc DL;
  103. if (I != MBB.end()) DL = I->getDebugLoc();
  104. MachineFunction &MF = *MBB.getParent();
  105. MachineFrameInfo &MFI = MF.getFrameInfo();
  106. MachineMemOperand *MMO = MF.getMachineMemOperand(
  107. MachinePointerInfo::getFixedStack(MF, FI), MachineMemOperand::MOLoad,
  108. MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
  109. BuildMI(MBB, I, DL, get(ARM::tLDRspi), DestReg)
  110. .addFrameIndex(FI)
  111. .addImm(0)
  112. .addMemOperand(MMO)
  113. .add(predOps(ARMCC::AL));
  114. }
  115. }
  116. void Thumb1InstrInfo::expandLoadStackGuard(
  117. MachineBasicBlock::iterator MI) const {
  118. MachineFunction &MF = *MI->getParent()->getParent();
  119. const TargetMachine &TM = MF.getTarget();
  120. if (TM.isPositionIndependent())
  121. expandLoadStackGuardBase(MI, ARM::tLDRLIT_ga_pcrel, ARM::tLDRi);
  122. else
  123. expandLoadStackGuardBase(MI, ARM::tLDRLIT_ga_abs, ARM::tLDRi);
  124. }
  125. bool Thumb1InstrInfo::canCopyGluedNodeDuringSchedule(SDNode *N) const {
  126. // In Thumb1 the scheduler may need to schedule a cross-copy between GPRS and CPSR
  127. // but this is not always possible there, so allow the Scheduler to clone tADCS and tSBCS
  128. // even if they have glue.
  129. // FIXME. Actually implement the cross-copy where it is possible (post v6)
  130. // because these copies entail more spilling.
  131. unsigned Opcode = N->getMachineOpcode();
  132. if (Opcode == ARM::tADCS || Opcode == ARM::tSBCS)
  133. return true;
  134. return false;
  135. }