NVPTXFrameLowering.cpp 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //=======- NVPTXFrameLowering.cpp - NVPTX Frame Information ---*- C++ -*-=====//
  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 NVPTX implementation of TargetFrameLowering class.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "NVPTXFrameLowering.h"
  13. #include "NVPTX.h"
  14. #include "NVPTXRegisterInfo.h"
  15. #include "NVPTXSubtarget.h"
  16. #include "NVPTXTargetMachine.h"
  17. #include "llvm/CodeGen/MachineFrameInfo.h"
  18. #include "llvm/CodeGen/MachineFunction.h"
  19. #include "llvm/CodeGen/MachineInstrBuilder.h"
  20. #include "llvm/CodeGen/MachineRegisterInfo.h"
  21. #include "llvm/CodeGen/TargetInstrInfo.h"
  22. #include "llvm/MC/MachineLocation.h"
  23. using namespace llvm;
  24. NVPTXFrameLowering::NVPTXFrameLowering()
  25. : TargetFrameLowering(TargetFrameLowering::StackGrowsUp, Align(8), 0) {}
  26. bool NVPTXFrameLowering::hasFP(const MachineFunction &MF) const { return true; }
  27. void NVPTXFrameLowering::emitPrologue(MachineFunction &MF,
  28. MachineBasicBlock &MBB) const {
  29. if (MF.getFrameInfo().hasStackObjects()) {
  30. assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
  31. MachineInstr *MI = &MBB.front();
  32. MachineRegisterInfo &MR = MF.getRegInfo();
  33. const NVPTXRegisterInfo *NRI =
  34. MF.getSubtarget<NVPTXSubtarget>().getRegisterInfo();
  35. // This instruction really occurs before first instruction
  36. // in the BB, so giving it no debug location.
  37. DebugLoc dl = DebugLoc();
  38. // Emits
  39. // mov %SPL, %depot;
  40. // cvta.local %SP, %SPL;
  41. // for local address accesses in MF.
  42. bool Is64Bit =
  43. static_cast<const NVPTXTargetMachine &>(MF.getTarget()).is64Bit();
  44. unsigned CvtaLocalOpcode =
  45. (Is64Bit ? NVPTX::cvta_local_yes_64 : NVPTX::cvta_local_yes);
  46. unsigned MovDepotOpcode =
  47. (Is64Bit ? NVPTX::MOV_DEPOT_ADDR_64 : NVPTX::MOV_DEPOT_ADDR);
  48. if (!MR.use_empty(NRI->getFrameRegister(MF))) {
  49. // If %SP is not used, do not bother emitting "cvta.local %SP, %SPL".
  50. MI = BuildMI(MBB, MI, dl,
  51. MF.getSubtarget().getInstrInfo()->get(CvtaLocalOpcode),
  52. NRI->getFrameRegister(MF))
  53. .addReg(NRI->getFrameLocalRegister(MF));
  54. }
  55. BuildMI(MBB, MI, dl, MF.getSubtarget().getInstrInfo()->get(MovDepotOpcode),
  56. NRI->getFrameLocalRegister(MF))
  57. .addImm(MF.getFunctionNumber());
  58. }
  59. }
  60. StackOffset
  61. NVPTXFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
  62. Register &FrameReg) const {
  63. const MachineFrameInfo &MFI = MF.getFrameInfo();
  64. FrameReg = NVPTX::VRDepot;
  65. return StackOffset::getFixed(MFI.getObjectOffset(FI) -
  66. getOffsetOfLocalArea());
  67. }
  68. void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF,
  69. MachineBasicBlock &MBB) const {}
  70. // This function eliminates ADJCALLSTACKDOWN,
  71. // ADJCALLSTACKUP pseudo instructions
  72. MachineBasicBlock::iterator NVPTXFrameLowering::eliminateCallFramePseudoInstr(
  73. MachineFunction &MF, MachineBasicBlock &MBB,
  74. MachineBasicBlock::iterator I) const {
  75. // Simply discard ADJCALLSTACKDOWN,
  76. // ADJCALLSTACKUP instructions.
  77. return MBB.erase(I);
  78. }
  79. TargetFrameLowering::DwarfFrameBase
  80. NVPTXFrameLowering::getDwarfFrameBase(const MachineFunction &MF) const {
  81. return {DwarfFrameBase::CFA, {0}};
  82. }