[Hexagon] Overhaul of stack object allocation
[oota-llvm.git] / lib / Target / Hexagon / HexagonFrameLowering.h
1 //=- HexagonFrameLowering.h - Define frame lowering for Hexagon --*- C++ -*--=//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H
11 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H
12
13 #include "Hexagon.h"
14 #include "llvm/Target/TargetFrameLowering.h"
15
16 namespace llvm {
17
18 class HexagonInstrInfo;
19
20 class HexagonFrameLowering : public TargetFrameLowering {
21 private:
22   void expandAlloca(MachineInstr *AI, const HexagonInstrInfo &TII,
23                     unsigned SP, unsigned CF) const;
24
25 public:
26   explicit HexagonFrameLowering()
27       : TargetFrameLowering(StackGrowsDown, 8, 0, 1, true) {}
28
29   void emitPrologue(MachineFunction &MF) const override;
30   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
31   bool targetHandlesStackFrameRounding() const override {
32     return true;
33   }
34   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
35                                  MachineBasicBlock::iterator MI,
36                                  const std::vector<CalleeSavedInfo> &CSI,
37                                  const TargetRegisterInfo *TRI) const override;
38
39   void
40   eliminateCallFramePseudoInstr(MachineFunction &MF,
41                                 MachineBasicBlock &MBB,
42                                 MachineBasicBlock::iterator I) const override;
43
44   bool
45   restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
46                               MachineBasicBlock::iterator MI,
47                               const std::vector<CalleeSavedInfo> &CSI,
48                               const TargetRegisterInfo *TRI) const override;
49   void processFunctionBeforeFrameFinalized(MachineFunction &MF,
50         RegScavenger *RS = NULL) const override;
51   void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
52                                             RegScavenger *RS) const override;
53   int getFrameIndexOffset(const MachineFunction &MF, int FI) const override;
54   bool hasFP(const MachineFunction &MF) const override;
55   bool hasTailCall(MachineBasicBlock &MBB) const;
56   void adjustForCalleeSavedRegsSpillCall(MachineFunction &MF) const;
57   bool replacePredRegPseudoSpillCode(MachineFunction &MF) const;
58
59   const SpillSlot *getCalleeSavedSpillSlots(unsigned &NumEntries)
60         const override {
61     static const SpillSlot Offsets[] = {
62       { Hexagon::R17, -4 }, { Hexagon::R16, -8 }, { Hexagon::D8, -8 },
63       { Hexagon::R19, -12 }, { Hexagon::R18, -16 }, { Hexagon::D9, -16 },
64       { Hexagon::R21, -20 }, { Hexagon::R20, -24 }, { Hexagon::D10, -24 },
65       { Hexagon::R23, -28 }, { Hexagon::R22, -32 }, { Hexagon::D11, -32 },
66       { Hexagon::R25, -36 }, { Hexagon::R24, -40 }, { Hexagon::D12, -40 },
67       { Hexagon::R27, -44 }, { Hexagon::R26, -48 }, { Hexagon::D13, -48 }
68     };
69
70     NumEntries = array_lengthof(Offsets);
71     return Offsets;
72   }
73
74   bool assignCalleeSavedSpillSlots(MachineFunction &MF,
75         const TargetRegisterInfo *TRI,
76         std::vector<CalleeSavedInfo> &CSI) const override;
77
78   bool needsAligna(const MachineFunction &MF) const;
79   MachineInstr *getAlignaInstr(MachineFunction &MF) const;
80 };
81
82 } // End llvm namespace
83
84 #endif