Thumb1InstrInfo.cpp 6.0 KB

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