MipsMachineFunction.h revision cd81d94322a39503e4a3e87b6ee03d4fcb3465fb
1//===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- 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// This file declares the Mips specific subclass of MachineFunctionInfo.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MIPS_MACHINE_FUNCTION_INFO_H
15#define MIPS_MACHINE_FUNCTION_INFO_H
16
17#include "Mips16HardFloatInfo.h"
18#include "llvm/ADT/StringMap.h"
19#include "llvm/CodeGen/MachineFrameInfo.h"
20#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/CodeGen/MachineMemOperand.h"
22#include "llvm/CodeGen/PseudoSourceValue.h"
23#include "llvm/IR/GlobalValue.h"
24#include "llvm/IR/ValueMap.h"
25#include "llvm/Target/TargetFrameLowering.h"
26#include "llvm/Target/TargetMachine.h"
27#include <map>
28#include <string>
29#include <utility>
30
31namespace llvm {
32
33/// \brief A class derived from PseudoSourceValue that represents a GOT entry
34/// resolved by lazy-binding.
35class MipsCallEntry : public PseudoSourceValue {
36public:
37  explicit MipsCallEntry(const StringRef &N);
38  explicit MipsCallEntry(const GlobalValue *V);
39  bool isConstant(const MachineFrameInfo *) const override;
40  bool isAliased(const MachineFrameInfo *) const override;
41  bool mayAlias(const MachineFrameInfo *) const override;
42
43private:
44  void printCustom(raw_ostream &O) const override;
45#ifndef NDEBUG
46  std::string Name;
47  const GlobalValue *Val;
48#endif
49};
50
51/// MipsFunctionInfo - This class is derived from MachineFunction private
52/// Mips target-specific information for each MachineFunction.
53class MipsFunctionInfo : public MachineFunctionInfo {
54public:
55  MipsFunctionInfo(MachineFunction &MF)
56      : MF(MF), SRetReturnReg(0), GlobalBaseReg(0), Mips16SPAliasReg(0),
57        VarArgsFrameIndex(0), CallsEhReturn(false), SaveS2(false) {}
58
59  ~MipsFunctionInfo();
60
61  unsigned getSRetReturnReg() const { return SRetReturnReg; }
62  void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
63
64  bool globalBaseRegSet() const;
65  unsigned getGlobalBaseReg();
66
67  bool mips16SPAliasRegSet() const;
68  unsigned getMips16SPAliasReg();
69
70  int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
71  void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
72
73  bool hasByvalArg() const { return HasByvalArg; }
74  void setFormalArgInfo(unsigned Size, bool HasByval) {
75    IncomingArgSize = Size;
76    HasByvalArg = HasByval;
77  }
78
79  unsigned getIncomingArgSize() const { return IncomingArgSize; }
80
81  bool callsEhReturn() const { return CallsEhReturn; }
82  void setCallsEhReturn() { CallsEhReturn = true; }
83
84  void createEhDataRegsFI();
85  int getEhDataRegFI(unsigned Reg) const { return EhDataRegFI[Reg]; }
86  bool isEhDataRegFI(int FI) const;
87
88  /// \brief Create a MachinePointerInfo that has a MipsCallEntr object
89  /// representing a GOT entry for an external function.
90  MachinePointerInfo callPtrInfo(const StringRef &Name);
91
92  /// \brief Create a MachinePointerInfo that has a MipsCallEntr object
93  /// representing a GOT entry for a global function.
94  MachinePointerInfo callPtrInfo(const GlobalValue *Val);
95
96  void setSaveS2() { SaveS2 = true; }
97  bool hasSaveS2() const { return SaveS2; }
98
99  std::map<const char *, const llvm::Mips16HardFloatInfo::FuncSignature *>
100  StubsNeeded;
101
102private:
103  virtual void anchor();
104
105  MachineFunction& MF;
106  /// SRetReturnReg - Some subtargets require that sret lowering includes
107  /// returning the value of the returned struct in a register. This field
108  /// holds the virtual register into which the sret argument is passed.
109  unsigned SRetReturnReg;
110
111  /// GlobalBaseReg - keeps track of the virtual register initialized for
112  /// use as the global base register. This is used for PIC in some PIC
113  /// relocation models.
114  unsigned GlobalBaseReg;
115
116  /// Mips16SPAliasReg - keeps track of the virtual register initialized for
117  /// use as an alias for SP for use in load/store of halfword/byte from/to
118  /// the stack
119  unsigned Mips16SPAliasReg;
120
121  /// VarArgsFrameIndex - FrameIndex for start of varargs area.
122  int VarArgsFrameIndex;
123
124  /// True if function has a byval argument.
125  bool HasByvalArg;
126
127  /// Size of incoming argument area.
128  unsigned IncomingArgSize;
129
130  /// CallsEhReturn - Whether the function calls llvm.eh.return.
131  bool CallsEhReturn;
132
133  /// Frame objects for spilling eh data registers.
134  int EhDataRegFI[4];
135
136  // saveS2
137  bool SaveS2;
138
139  /// MipsCallEntry maps.
140  StringMap<const MipsCallEntry *> ExternalCallEntries;
141  ValueMap<const GlobalValue *, const MipsCallEntry *> GlobalCallEntries;
142};
143
144} // end of namespace llvm
145
146#endif // MIPS_MACHINE_FUNCTION_INFO_H
147