Add AArch64 as an experimental target.
[oota-llvm.git] / lib / Target / AArch64 / AArch64FrameLowering.h
1 //==- AArch64FrameLowering.h - Define frame lowering for AArch64 -*- 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 //
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_AARCH64_FRAMEINFO_H
15 #define LLVM_AARCH64_FRAMEINFO_H
16
17 #include "AArch64Subtarget.h"
18 #include "llvm/Target/TargetFrameLowering.h"
19
20 namespace llvm {
21 class AArch64Subtarget;
22
23 class AArch64FrameLowering : public TargetFrameLowering {
24 private:
25   // In order to unify the spilling and restoring of callee-saved registers into
26   // emitFrameMemOps, we need to be able to specify which instructions to use
27   // for the relevant memory operations on each register class. An array of the
28   // following struct is populated and passed in to achieve this.
29   struct LoadStoreMethod {
30     const TargetRegisterClass *RegClass; // E.g. GPR64RegClass
31
32     // The preferred instruction. 
33     unsigned PairOpcode; // E.g. LSPair64_STR
34
35     // Sometimes only a single register can be handled at once.
36     unsigned SingleOpcode; // E.g. LS64_STR
37   };
38 protected:
39   const AArch64Subtarget &STI;
40
41 public:
42   explicit AArch64FrameLowering(const AArch64Subtarget &sti)
43     : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, 16, 0, 16),
44       STI(sti) {
45   }
46
47   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
48   /// the function.
49   virtual void emitPrologue(MachineFunction &MF) const;
50   virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
51
52   /// Decides how much stack adjustment to perform in each phase of the prologue
53   /// and epilogue.
54   void splitSPAdjustments(uint64_t Total, uint64_t &Initial,
55                           uint64_t &Residual) const;
56
57   int64_t resolveFrameIndexReference(MachineFunction &MF, int FrameIndex,
58                                      unsigned &FrameReg, int SPAdj,
59                                      bool IsCalleeSaveOp) const;
60
61   virtual void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
62                                                     RegScavenger *RS) const;
63
64   virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
65                                         MachineBasicBlock::iterator MI,
66                                         const std::vector<CalleeSavedInfo> &CSI,
67                                         const TargetRegisterInfo *TRI) const;
68   virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
69                                         MachineBasicBlock::iterator MI,
70                                         const std::vector<CalleeSavedInfo> &CSI,
71                                         const TargetRegisterInfo *TRI) const;
72
73   /// If the register is X30 (i.e. LR) and the return address is used in the
74   /// function then the callee-save store doesn't actually kill the register,
75   /// otherwise it does.
76   bool determinePrologueDeath(MachineBasicBlock &MBB, unsigned Reg) const;
77
78   /// This function emits the loads or stores required during prologue and
79   /// epilogue as efficiently as possible.
80   ///
81   /// The operations involved in setting up and tearing down the frame are
82   /// similar enough to warrant a shared function, particularly as discrepancies
83   /// between the two would be disastrous.
84   void emitFrameMemOps(bool isStore, MachineBasicBlock &MBB,
85                        MachineBasicBlock::iterator MI,
86                        const std::vector<CalleeSavedInfo> &CSI,
87                        const TargetRegisterInfo *TRI,
88                        LoadStoreMethod PossibleClasses[],
89                        unsigned NumClasses) const;
90
91
92   virtual bool hasFP(const MachineFunction &MF) const;
93
94   virtual bool useFPForAddressing(const MachineFunction &MF) const;
95
96   /// On AA
97   virtual bool hasReservedCallFrame(const MachineFunction &MF) const;
98
99 };
100
101 } // End llvm namespace
102
103 #endif