WebAssemblyFrameLowering.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // WebAssemblyFrameLowering.h - TargetFrameLowering for WebAssembly -*- 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. /// \file
  10. /// This class implements WebAssembly-specific bits of
  11. /// TargetFrameLowering class.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
  15. #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
  16. #include "llvm/CodeGen/TargetFrameLowering.h"
  17. namespace llvm {
  18. class WebAssemblyFrameLowering final : public TargetFrameLowering {
  19. public:
  20. /// Size of the red zone for the user stack (leaf functions can use this much
  21. /// space below the stack pointer without writing it back to __stack_pointer
  22. /// global).
  23. // TODO: (ABI) Revisit and decide how large it should be.
  24. static const size_t RedZoneSize = 128;
  25. WebAssemblyFrameLowering()
  26. : TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/Align(16),
  27. /*LocalAreaOffset=*/0,
  28. /*TransientStackAlignment=*/Align(16),
  29. /*StackRealignable=*/true) {}
  30. MachineBasicBlock::iterator
  31. eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
  32. MachineBasicBlock::iterator I) const override;
  33. /// These methods insert prolog and epilog code into the function.
  34. void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
  35. void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
  36. bool hasFP(const MachineFunction &MF) const override;
  37. bool hasReservedCallFrame(const MachineFunction &MF) const override;
  38. bool isSupportedStackID(TargetStackID::Value ID) const override;
  39. DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override;
  40. bool needsPrologForEH(const MachineFunction &MF) const;
  41. /// Write SP back to __stack_pointer global.
  42. void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF,
  43. MachineBasicBlock &MBB,
  44. MachineBasicBlock::iterator &InsertStore,
  45. const DebugLoc &DL) const;
  46. // Returns the index of the WebAssembly local to which the stack object
  47. // FrameIndex in MF should be allocated, or std::nullopt.
  48. static std::optional<unsigned> getLocalForStackObject(MachineFunction &MF,
  49. int FrameIndex);
  50. static unsigned getSPReg(const MachineFunction &MF);
  51. static unsigned getFPReg(const MachineFunction &MF);
  52. static unsigned getOpcConst(const MachineFunction &MF);
  53. static unsigned getOpcAdd(const MachineFunction &MF);
  54. static unsigned getOpcSub(const MachineFunction &MF);
  55. static unsigned getOpcAnd(const MachineFunction &MF);
  56. static unsigned getOpcGlobGet(const MachineFunction &MF);
  57. static unsigned getOpcGlobSet(const MachineFunction &MF);
  58. private:
  59. bool hasBP(const MachineFunction &MF) const;
  60. bool needsSPForLocalFrame(const MachineFunction &MF) const;
  61. bool needsSP(const MachineFunction &MF) const;
  62. bool needsSPWriteback(const MachineFunction &MF) const;
  63. };
  64. } // end namespace llvm
  65. #endif