NVPTXFrameLowering.cpp 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. MachineBasicBlock::iterator MBBI = MBB.begin();
  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. MBBI = BuildMI(MBB, MBBI, dl,
  51. MF.getSubtarget().getInstrInfo()->get(CvtaLocalOpcode),
  52. NRI->getFrameRegister(MF))
  53. .addReg(NRI->getFrameLocalRegister(MF));
  54. }
  55. BuildMI(MBB, MBBI, dl,
  56. MF.getSubtarget().getInstrInfo()->get(MovDepotOpcode),
  57. NRI->getFrameLocalRegister(MF))
  58. .addImm(MF.getFunctionNumber());
  59. }
  60. }
  61. StackOffset
  62. NVPTXFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
  63. Register &FrameReg) const {
  64. const MachineFrameInfo &MFI = MF.getFrameInfo();
  65. FrameReg = NVPTX::VRDepot;
  66. return StackOffset::getFixed(MFI.getObjectOffset(FI) -
  67. getOffsetOfLocalArea());
  68. }
  69. void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF,
  70. MachineBasicBlock &MBB) const {}
  71. // This function eliminates ADJCALLSTACKDOWN,
  72. // ADJCALLSTACKUP pseudo instructions
  73. MachineBasicBlock::iterator NVPTXFrameLowering::eliminateCallFramePseudoInstr(
  74. MachineFunction &MF, MachineBasicBlock &MBB,
  75. MachineBasicBlock::iterator I) const {
  76. // Simply discard ADJCALLSTACKDOWN,
  77. // ADJCALLSTACKUP instructions.
  78. return MBB.erase(I);
  79. }
  80. TargetFrameLowering::DwarfFrameBase
  81. NVPTXFrameLowering::getDwarfFrameBase(const MachineFunction &MF) const {
  82. return {DwarfFrameBase::CFA, {0}};
  83. }