blob: 32436efa2edac9e82f5a34236179ec6562de398e [file] [log] [blame]
Akira Hatanakae2489122011-04-15 21:51:11 +00001//===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- C++ -*-=//
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +00007//
Akira Hatanakae2489122011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +00009//
10// This file declares the Mips specific subclass of MachineFunctionInfo.
11//
Akira Hatanakae2489122011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000013
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_MIPS_MIPSMACHINEFUNCTION_H
15#define LLVM_LIB_TARGET_MIPS_MIPSMACHINEFUNCTION_H
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000016
Reed Kotler4cdaa7d2014-02-14 19:16:39 +000017#include "Mips16HardFloatInfo.h"
Akira Hatanakae0657b22013-09-27 22:30:36 +000018#include "llvm/ADT/StringMap.h"
Bruno Cardoso Lopesf55a7852007-08-28 05:04:41 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000020#include "llvm/CodeGen/MachineFunction.h"
Akira Hatanakae0657b22013-09-27 22:30:36 +000021#include "llvm/CodeGen/MachineMemOperand.h"
22#include "llvm/CodeGen/PseudoSourceValue.h"
23#include "llvm/IR/GlobalValue.h"
Chandler Carrutha4ea2692014-03-04 11:26:31 +000024#include "llvm/IR/ValueMap.h"
Akira Hatanaka51c70c62012-06-14 01:15:36 +000025#include "llvm/Target/TargetFrameLowering.h"
26#include "llvm/Target/TargetMachine.h"
Reed Kotler4cdaa7d2014-02-14 19:16:39 +000027#include <map>
28#include <string>
Craig Topperb25fda92012-03-17 18:46:09 +000029#include <utility>
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000030
31namespace llvm {
32
Akira Hatanakae0657b22013-09-27 22:30:36 +000033/// \brief A class derived from PseudoSourceValue that represents a GOT entry
34/// resolved by lazy-binding.
35class MipsCallEntry : public PseudoSourceValue {
36public:
Craig Topper6dc4a8bc2014-08-30 16:48:02 +000037 explicit MipsCallEntry(StringRef N);
Akira Hatanakae0657b22013-09-27 22:30:36 +000038 explicit MipsCallEntry(const GlobalValue *V);
Craig Topper56c590a2014-04-29 07:58:02 +000039 bool isConstant(const MachineFrameInfo *) const override;
40 bool isAliased(const MachineFrameInfo *) const override;
41 bool mayAlias(const MachineFrameInfo *) const override;
Akira Hatanakae0657b22013-09-27 22:30:36 +000042
43private:
Craig Topper56c590a2014-04-29 07:58:02 +000044 void printCustom(raw_ostream &O) const override;
Akira Hatanakae0657b22013-09-27 22:30:36 +000045#ifndef NDEBUG
46 std::string Name;
47 const GlobalValue *Val;
48#endif
49};
50
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000051/// MipsFunctionInfo - This class is derived from MachineFunction private
52/// Mips target-specific information for each MachineFunction.
53class MipsFunctionInfo : public MachineFunctionInfo {
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000054public:
Reed Kotler4cdaa7d2014-02-14 19:16:39 +000055 MipsFunctionInfo(MachineFunction &MF)
56 : MF(MF), SRetReturnReg(0), GlobalBaseReg(0), Mips16SPAliasReg(0),
Sasa Stankovicb976fee2014-07-14 09:40:29 +000057 VarArgsFrameIndex(0), CallsEhReturn(false), SaveS2(false),
Daniel Sanders7ddb0ab2014-07-14 13:08:14 +000058 MoveF64ViaSpillFI(-1) {}
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000059
Akira Hatanakae0657b22013-09-27 22:30:36 +000060 ~MipsFunctionInfo();
61
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000062 unsigned getSRetReturnReg() const { return SRetReturnReg; }
63 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
Dan Gohmand5ca70642009-06-03 20:30:14 +000064
Akira Hatanakab049aef2012-02-24 22:34:47 +000065 bool globalBaseRegSet() const;
66 unsigned getGlobalBaseReg();
Dan Gohman31ae5862010-04-17 14:41:14 +000067
Reed Kotler3589dd72012-10-28 06:02:37 +000068 bool mips16SPAliasRegSet() const;
69 unsigned getMips16SPAliasReg();
70
Dan Gohman31ae5862010-04-17 14:41:14 +000071 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
72 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
Akira Hatanakad738c0f2011-05-20 01:17:58 +000073
Akira Hatanaka4866fe12012-10-30 19:37:25 +000074 bool hasByvalArg() const { return HasByvalArg; }
Akira Hatanaka40f2d302012-11-07 19:04:26 +000075 void setFormalArgInfo(unsigned Size, bool HasByval) {
76 IncomingArgSize = Size;
Akira Hatanaka4866fe12012-10-30 19:37:25 +000077 HasByvalArg = HasByval;
78 }
Akira Hatanaka719df282012-11-02 21:03:58 +000079
80 unsigned getIncomingArgSize() const { return IncomingArgSize; }
Akira Hatanakac0b02062013-01-30 00:26:49 +000081
82 bool callsEhReturn() const { return CallsEhReturn; }
83 void setCallsEhReturn() { CallsEhReturn = true; }
84
85 void createEhDataRegsFI();
86 int getEhDataRegFI(unsigned Reg) const { return EhDataRegFI[Reg]; }
87 bool isEhDataRegFI(int FI) const;
88
Akira Hatanakae0657b22013-09-27 22:30:36 +000089 /// \brief Create a MachinePointerInfo that has a MipsCallEntr object
90 /// representing a GOT entry for an external function.
Craig Topper6dc4a8bc2014-08-30 16:48:02 +000091 MachinePointerInfo callPtrInfo(StringRef Name);
Akira Hatanakae0657b22013-09-27 22:30:36 +000092
93 /// \brief Create a MachinePointerInfo that has a MipsCallEntr object
94 /// representing a GOT entry for a global function.
95 MachinePointerInfo callPtrInfo(const GlobalValue *Val);
96
Reed Kotler4cdaa7d2014-02-14 19:16:39 +000097 void setSaveS2() { SaveS2 = true; }
98 bool hasSaveS2() const { return SaveS2; }
99
Daniel Sanders7ddb0ab2014-07-14 13:08:14 +0000100 int getMoveF64ViaSpillFI(const TargetRegisterClass *RC);
Sasa Stankovicb976fee2014-07-14 09:40:29 +0000101
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000102 std::map<const char *, const llvm::Mips16HardFloatInfo::FuncSignature *>
103 StubsNeeded;
104
Akira Hatanakaf215e072013-09-25 00:34:42 +0000105private:
106 virtual void anchor();
107
108 MachineFunction& MF;
109 /// SRetReturnReg - Some subtargets require that sret lowering includes
110 /// returning the value of the returned struct in a register. This field
111 /// holds the virtual register into which the sret argument is passed.
112 unsigned SRetReturnReg;
113
114 /// GlobalBaseReg - keeps track of the virtual register initialized for
115 /// use as the global base register. This is used for PIC in some PIC
116 /// relocation models.
117 unsigned GlobalBaseReg;
118
119 /// Mips16SPAliasReg - keeps track of the virtual register initialized for
120 /// use as an alias for SP for use in load/store of halfword/byte from/to
121 /// the stack
122 unsigned Mips16SPAliasReg;
123
124 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
125 int VarArgsFrameIndex;
126
127 /// True if function has a byval argument.
128 bool HasByvalArg;
129
130 /// Size of incoming argument area.
131 unsigned IncomingArgSize;
132
133 /// CallsEhReturn - Whether the function calls llvm.eh.return.
134 bool CallsEhReturn;
135
136 /// Frame objects for spilling eh data registers.
137 int EhDataRegFI[4];
Akira Hatanakae0657b22013-09-27 22:30:36 +0000138
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000139 // saveS2
140 bool SaveS2;
141
Sasa Stankovicb976fee2014-07-14 09:40:29 +0000142 /// FrameIndex for expanding BuildPairF64 nodes to spill and reload when the
143 /// O32 FPXX ABI is enabled. -1 is used to denote invalid index.
Daniel Sanders7ddb0ab2014-07-14 13:08:14 +0000144 int MoveF64ViaSpillFI;
Sasa Stankovicb976fee2014-07-14 09:40:29 +0000145
Akira Hatanakae0657b22013-09-27 22:30:36 +0000146 /// MipsCallEntry maps.
Benjamin Kramer727b5052015-04-16 12:43:33 +0000147 StringMap<std::unique_ptr<const MipsCallEntry>> ExternalCallEntries;
148 ValueMap<const GlobalValue *, std::unique_ptr<const MipsCallEntry>>
149 GlobalCallEntries;
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +0000150};
151
152} // end of namespace llvm
153
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000154#endif