Thumb1InstrInfo.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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::
  68. storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
  69. Register SrcReg, bool isKill, int FI,
  70. const TargetRegisterClass *RC,
  71. const TargetRegisterInfo *TRI) const {
  72. assert((RC == &ARM::tGPRRegClass ||
  73. (Register::isPhysicalRegister(SrcReg) && isARMLowRegister(SrcReg))) &&
  74. "Unknown regclass!");
  75. if (RC == &ARM::tGPRRegClass ||
  76. (Register::isPhysicalRegister(SrcReg) && isARMLowRegister(SrcReg))) {
  77. DebugLoc DL;
  78. if (I != MBB.end()) DL = I->getDebugLoc();
  79. MachineFunction &MF = *MBB.getParent();
  80. MachineFrameInfo &MFI = MF.getFrameInfo();
  81. MachineMemOperand *MMO = MF.getMachineMemOperand(
  82. MachinePointerInfo::getFixedStack(MF, FI), MachineMemOperand::MOStore,
  83. MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
  84. BuildMI(MBB, I, DL, get(ARM::tSTRspi))
  85. .addReg(SrcReg, getKillRegState(isKill))
  86. .addFrameIndex(FI)
  87. .addImm(0)
  88. .addMemOperand(MMO)
  89. .add(predOps(ARMCC::AL));
  90. }
  91. }
  92. void Thumb1InstrInfo::
  93. loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
  94. Register DestReg, int FI,
  95. const TargetRegisterClass *RC,
  96. const TargetRegisterInfo *TRI) const {
  97. assert(
  98. (RC->hasSuperClassEq(&ARM::tGPRRegClass) ||
  99. (Register::isPhysicalRegister(DestReg) && isARMLowRegister(DestReg))) &&
  100. "Unknown regclass!");
  101. if (RC->hasSuperClassEq(&ARM::tGPRRegClass) ||
  102. (Register::isPhysicalRegister(DestReg) && isARMLowRegister(DestReg))) {
  103. DebugLoc DL;
  104. if (I != MBB.end()) DL = I->getDebugLoc();
  105. MachineFunction &MF = *MBB.getParent();
  106. MachineFrameInfo &MFI = MF.getFrameInfo();
  107. MachineMemOperand *MMO = MF.getMachineMemOperand(
  108. MachinePointerInfo::getFixedStack(MF, FI), MachineMemOperand::MOLoad,
  109. MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
  110. BuildMI(MBB, I, DL, get(ARM::tLDRspi), DestReg)
  111. .addFrameIndex(FI)
  112. .addImm(0)
  113. .addMemOperand(MMO)
  114. .add(predOps(ARMCC::AL));
  115. }
  116. }
  117. void Thumb1InstrInfo::expandLoadStackGuard(
  118. MachineBasicBlock::iterator MI) const {
  119. MachineFunction &MF = *MI->getParent()->getParent();
  120. const TargetMachine &TM = MF.getTarget();
  121. assert(MF.getFunction().getParent()->getStackProtectorGuard() != "tls" &&
  122. "TLS stack protector not supported for Thumb1 targets");
  123. if (TM.isPositionIndependent())
  124. expandLoadStackGuardBase(MI, ARM::tLDRLIT_ga_pcrel, ARM::tLDRi);
  125. else
  126. expandLoadStackGuardBase(MI, ARM::tLDRLIT_ga_abs, ARM::tLDRi);
  127. }
  128. bool Thumb1InstrInfo::canCopyGluedNodeDuringSchedule(SDNode *N) const {
  129. // In Thumb1 the scheduler may need to schedule a cross-copy between GPRS and CPSR
  130. // but this is not always possible there, so allow the Scheduler to clone tADCS and tSBCS
  131. // even if they have glue.
  132. // FIXME. Actually implement the cross-copy where it is possible (post v6)
  133. // because these copies entail more spilling.
  134. unsigned Opcode = N->getMachineOpcode();
  135. if (Opcode == ARM::tADCS || Opcode == ARM::tSBCS)
  136. return true;
  137. return false;
  138. }