xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Mips/MCTargetDesc/MipsABIInfo.h (revision 77a1348b3c1cfe8547be49a121b56299a1e18b69)
1 //===---- MipsABIInfo.h - Information about MIPS ABI's --------------------===//
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 #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIINFO_H
10 #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIINFO_H
11 
12 #include "llvm/ADT/Triple.h"
13 #include "llvm/IR/CallingConv.h"
14 #include "llvm/MC/MCRegisterInfo.h"
15 
16 namespace llvm {
17 
18 template <typename T> class ArrayRef;
19 class MCTargetOptions;
20 class StringRef;
21 class TargetRegisterClass;
22 
23 class MipsABIInfo {
24 public:
25   enum class ABI { Unknown, O32, N32, N64 };
26 
27 protected:
28   ABI ThisABI;
29 
30 public:
31   MipsABIInfo(ABI ThisABI) : ThisABI(ThisABI) {}
32 
33   static MipsABIInfo Unknown() { return MipsABIInfo(ABI::Unknown); }
34   static MipsABIInfo O32() { return MipsABIInfo(ABI::O32); }
35   static MipsABIInfo N32() { return MipsABIInfo(ABI::N32); }
36   static MipsABIInfo N64() { return MipsABIInfo(ABI::N64); }
37   static MipsABIInfo computeTargetABI(const Triple &TT, StringRef CPU,
38                                       const MCTargetOptions &Options);
39 
40   bool IsKnown() const { return ThisABI != ABI::Unknown; }
41   bool IsO32() const { return ThisABI == ABI::O32; }
42   bool IsN32() const { return ThisABI == ABI::N32; }
43   bool IsN64() const { return ThisABI == ABI::N64; }
44   ABI GetEnumValue() const { return ThisABI; }
45 
46   /// The registers to use for byval arguments.
47   ArrayRef<MCPhysReg> GetByValArgRegs() const;
48 
49   /// The registers to use for the variable argument list.
50   ArrayRef<MCPhysReg> GetVarArgRegs() const;
51 
52   /// Obtain the size of the area allocated by the callee for arguments.
53   /// CallingConv::FastCall affects the value for O32.
54   unsigned GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const;
55 
56   /// Ordering of ABI's
57   /// MipsGenSubtargetInfo.inc will use this to resolve conflicts when given
58   /// multiple ABI options.
59   bool operator<(const MipsABIInfo Other) const {
60     return ThisABI < Other.GetEnumValue();
61   }
62 
63   unsigned GetStackPtr() const;
64   unsigned GetFramePtr() const;
65   unsigned GetBasePtr() const;
66   unsigned GetGlobalPtr() const;
67   unsigned GetNullPtr() const;
68   unsigned GetZeroReg() const;
69   unsigned GetPtrAdduOp() const;
70   unsigned GetPtrAddiuOp() const;
71   unsigned GetPtrSubuOp() const;
72   unsigned GetPtrAndOp() const;
73   unsigned GetGPRMoveOp() const;
74   inline bool ArePtrs64bit() const { return IsN64(); }
75   inline bool AreGprs64bit() const { return IsN32() || IsN64(); }
76 
77   unsigned GetEhDataReg(unsigned I) const;
78 };
79 }
80 
81 #endif
82