xref: /freebsd/contrib/llvm-project/llvm/lib/Target/M68k/M68kSubtarget.h (revision 734e82fe33aa764367791a7d603b383996c6b40b)
1 //===-- M68kSubtarget.h - Define Subtarget for the M68k ---------*- C++ -*-===//
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 /// \file
10 /// This file declares the M68k specific subclass of TargetSubtargetInfo.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_M68K_M68KSUBTARGET_H
15 #define LLVM_LIB_TARGET_M68K_M68KSUBTARGET_H
16 
17 #include "M68kFrameLowering.h"
18 #include "M68kISelLowering.h"
19 #include "M68kInstrInfo.h"
20 
21 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
22 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
23 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
24 #include "llvm/CodeGen/RegisterBankInfo.h"
25 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
26 #include "llvm/CodeGen/TargetSubtargetInfo.h"
27 #include "llvm/IR/DataLayout.h"
28 #include "llvm/MC/MCInstrItineraries.h"
29 #include "llvm/Support/Alignment.h"
30 
31 #include <string>
32 
33 #define GET_SUBTARGETINFO_HEADER
34 #include "M68kGenSubtargetInfo.inc"
35 
36 extern bool M68kReserveGP;
37 extern bool M68kNoCpload;
38 
39 namespace llvm {
40 class StringRef;
41 
42 class M68kTargetMachine;
43 
44 class M68kSubtarget : public M68kGenSubtargetInfo {
45   virtual void anchor();
46 
47 protected:
48   // These define which ISA is supported. Since each Motorola M68k ISA is
49   // built on top of the previous one whenever an ISA is selected the previous
50   // selected as well.
51   enum SubtargetEnum { M00, M10, M20, M30, M40, M60 };
52   SubtargetEnum SubtargetKind = M00;
53 
54   std::bitset<M68k::NUM_TARGET_REGS> UserReservedRegister;
55 
56   InstrItineraryData InstrItins;
57 
58   /// Small section is used.
59   bool UseSmallSection = true;
60 
61   const M68kTargetMachine &TM;
62 
63   SelectionDAGTargetInfo TSInfo;
64   M68kInstrInfo InstrInfo;
65   M68kFrameLowering FrameLowering;
66   M68kTargetLowering TLInfo;
67 
68   /// The minimum alignment known to hold of the stack frame on
69   /// entry to the function and which must be maintained by every function.
70   unsigned stackAlignment = 8;
71 
72   Triple TargetTriple;
73 
74 public:
75   /// This constructor initializes the data members to match that
76   /// of the specified triple.
77   M68kSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
78                 const M68kTargetMachine &_TM);
79 
80   /// Parses features string setting specified subtarget options.  Definition
81   /// of function is auto generated by tblgen.
82   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
83 
84   bool atLeastM68000() const { return SubtargetKind >= M00; }
85   bool atLeastM68010() const { return SubtargetKind >= M10; }
86   bool atLeastM68020() const { return SubtargetKind >= M20; }
87   bool atLeastM68030() const { return SubtargetKind >= M30; }
88   bool atLeastM68040() const { return SubtargetKind >= M40; }
89   bool atLeastM68060() const { return SubtargetKind >= M60; }
90 
91   bool useSmallSection() const { return UseSmallSection; }
92 
93   bool abiUsesSoftFloat() const;
94 
95   const Triple &getTargetTriple() const { return TargetTriple; }
96 
97   bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
98 
99   /// Return true if the subtarget allows calls to immediate address.
100   bool isLegalToCallImmediateAddr() const;
101 
102   bool isPositionIndependent() const;
103 
104   bool isRegisterReservedByUser(Register R) const {
105     assert(R < M68k::NUM_TARGET_REGS && "Register out of range");
106     return UserReservedRegister[R];
107   }
108 
109   /// Classify a global variable reference for the current subtarget according
110   /// to how we should reference it in a non-pcrel context.
111   unsigned char classifyLocalReference(const GlobalValue *GV) const;
112 
113   /// Classify a global variable reference for the current subtarget according
114   /// to how we should reference it in a non-pcrel context.
115   unsigned char classifyGlobalReference(const GlobalValue *GV,
116                                         const Module &M) const;
117   unsigned char classifyGlobalReference(const GlobalValue *GV) const;
118 
119   /// Classify a external variable reference for the current subtarget according
120   /// to how we should reference it in a non-pcrel context.
121   unsigned char classifyExternalReference(const Module &M) const;
122 
123   /// Classify a global function reference for the current subtarget.
124   unsigned char classifyGlobalFunctionReference(const GlobalValue *GV,
125                                                 const Module &M) const;
126   unsigned char
127   classifyGlobalFunctionReference(const GlobalValue *GV) const override;
128 
129   /// Classify a blockaddress reference for the current subtarget according to
130   /// how we should reference it in a non-pcrel context.
131   unsigned char classifyBlockAddressReference() const;
132 
133   unsigned getJumpTableEncoding() const;
134 
135   /// TODO this must be controlled by options like -malign-int and -mshort
136   Align getStackAlignment() const { return Align(stackAlignment); }
137 
138   /// getSlotSize - Stack slot size in bytes.
139   unsigned getSlotSize() const { return 4; }
140 
141   M68kSubtarget &initializeSubtargetDependencies(StringRef CPU, Triple TT,
142                                                  StringRef FS,
143                                                  const M68kTargetMachine &TM);
144 
145   const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
146     return &TSInfo;
147   }
148 
149   const M68kInstrInfo *getInstrInfo() const override { return &InstrInfo; }
150 
151   const M68kFrameLowering *getFrameLowering() const override {
152     return &FrameLowering;
153   }
154 
155   const M68kRegisterInfo *getRegisterInfo() const override {
156     return &InstrInfo.getRegisterInfo();
157   }
158 
159   const M68kTargetLowering *getTargetLowering() const override {
160     return &TLInfo;
161   }
162 
163   const InstrItineraryData *getInstrItineraryData() const override {
164     return &InstrItins;
165   }
166 
167 protected:
168   // GlobalISel related APIs.
169   std::unique_ptr<CallLowering> CallLoweringInfo;
170   std::unique_ptr<InstructionSelector> InstSelector;
171   std::unique_ptr<LegalizerInfo> Legalizer;
172   std::unique_ptr<RegisterBankInfo> RegBankInfo;
173 
174 public:
175   const CallLowering *getCallLowering() const override;
176   InstructionSelector *getInstructionSelector() const override;
177   const LegalizerInfo *getLegalizerInfo() const override;
178   const RegisterBankInfo *getRegBankInfo() const override;
179 };
180 } // namespace llvm
181 
182 #endif // LLVM_LIB_TARGET_M68K_M68KSUBTARGET_H
183