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