xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AVR/AVRSubtarget.h (revision c8e7f78a3d28ff6e6223ed136ada8e1e2f34965e)
1 //===-- AVRSubtarget.h - Define Subtarget for the AVR -----------*- 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 // This file declares the AVR specific subclass of TargetSubtargetInfo.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_AVR_SUBTARGET_H
14 #define LLVM_AVR_SUBTARGET_H
15 
16 #include "llvm/CodeGen/TargetSubtargetInfo.h"
17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/Target/TargetMachine.h"
19 
20 #include "AVRFrameLowering.h"
21 #include "AVRISelLowering.h"
22 #include "AVRInstrInfo.h"
23 #include "AVRSelectionDAGInfo.h"
24 #include "MCTargetDesc/AVRMCTargetDesc.h"
25 
26 #define GET_SUBTARGETINFO_HEADER
27 #include "AVRGenSubtargetInfo.inc"
28 
29 namespace llvm {
30 
31 /// A specific AVR target MCU.
32 class AVRSubtarget : public AVRGenSubtargetInfo {
33 public:
34   //! Creates an AVR subtarget.
35   //! \param TT  The target triple.
36   //! \param CPU The CPU to target.
37   //! \param FS  The feature string.
38   //! \param TM  The target machine.
39   AVRSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS,
40                const AVRTargetMachine &TM);
41 
42   const AVRInstrInfo *getInstrInfo() const override { return &InstrInfo; }
43   const TargetFrameLowering *getFrameLowering() const override {
44     return &FrameLowering;
45   }
46   const AVRTargetLowering *getTargetLowering() const override {
47     return &TLInfo;
48   }
49   const AVRSelectionDAGInfo *getSelectionDAGInfo() const override {
50     return &TSInfo;
51   }
52   const AVRRegisterInfo *getRegisterInfo() const override {
53     return &InstrInfo.getRegisterInfo();
54   }
55 
56   /// Parses a subtarget feature string, setting appropriate options.
57   /// \note Definition of function is auto generated by `tblgen`.
58   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
59 
60   AVRSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS,
61                                                 const TargetMachine &TM);
62 
63   // Subtarget feature getters.
64   // See AVR.td for details.
65   bool hasSRAM() const { return m_hasSRAM; }
66   bool hasJMPCALL() const { return m_hasJMPCALL; }
67   bool hasIJMPCALL() const { return m_hasIJMPCALL; }
68   bool hasEIJMPCALL() const { return m_hasEIJMPCALL; }
69   bool hasADDSUBIW() const { return m_hasADDSUBIW; }
70   bool hasSmallStack() const { return m_hasSmallStack; }
71   bool hasMOVW() const { return m_hasMOVW; }
72   bool hasLPM() const { return m_hasLPM; }
73   bool hasLPMX() const { return m_hasLPMX; }
74   bool hasELPM() const { return m_hasELPM; }
75   bool hasELPMX() const { return m_hasELPMX; }
76   bool hasSPM() const { return m_hasSPM; }
77   bool hasSPMX() const { return m_hasSPMX; }
78   bool hasDES() const { return m_hasDES; }
79   bool supportsRMW() const { return m_supportsRMW; }
80   bool supportsMultiplication() const { return m_supportsMultiplication; }
81   bool hasBREAK() const { return m_hasBREAK; }
82   bool hasTinyEncoding() const { return m_hasTinyEncoding; }
83   bool hasMemMappedGPR() const { return m_hasMemMappedGPR; }
84   bool hasLowByteFirst() const { return m_hasLowByteFirst; }
85 
86   uint8_t getIORegisterOffset() const { return hasMemMappedGPR() ? 0x20 : 0x0; }
87 
88   bool enableSubRegLiveness() const override { return true; }
89 
90   /// Gets the ELF architecture for the e_flags field
91   /// of an ELF object file.
92   unsigned getELFArch() const {
93     assert(ELFArch != 0 &&
94            "every device must have an associate ELF architecture");
95     return ELFArch;
96   }
97 
98   /// Get I/O register addresses.
99   int getIORegRAMPZ() const { return hasELPM() ? 0x3b : -1; }
100   int getIORegEIND() const { return hasEIJMPCALL() ? 0x3c : -1; }
101   int getIORegSPL() const { return 0x3d; }
102   int getIORegSPH() const { return hasSmallStack() ? -1 : 0x3e; }
103   int getIORegSREG() const { return 0x3f; }
104 
105   /// Get GPR aliases.
106   int getRegTmpIndex() const { return hasTinyEncoding() ? 16 : 0; }
107   int getRegZeroIndex() const { return hasTinyEncoding() ? 17 : 1; }
108 
109   Register getTmpRegister() const {
110     return hasTinyEncoding() ? AVR::R16 : AVR::R0;
111   }
112   Register getZeroRegister() const {
113     return hasTinyEncoding() ? AVR::R17 : AVR::R1;
114   }
115 
116 private:
117   /// The ELF e_flags architecture.
118   unsigned ELFArch = 0;
119 
120   // Subtarget feature settings
121   // See AVR.td for details.
122   bool m_hasSRAM = false;
123   bool m_hasJMPCALL = false;
124   bool m_hasIJMPCALL = false;
125   bool m_hasEIJMPCALL = false;
126   bool m_hasADDSUBIW = false;
127   bool m_hasSmallStack = false;
128   bool m_hasMOVW = false;
129   bool m_hasLPM = false;
130   bool m_hasLPMX = false;
131   bool m_hasELPM = false;
132   bool m_hasELPMX = false;
133   bool m_hasSPM = false;
134   bool m_hasSPMX = false;
135   bool m_hasDES = false;
136   bool m_supportsRMW = false;
137   bool m_supportsMultiplication = false;
138   bool m_hasBREAK = false;
139   bool m_hasTinyEncoding = false;
140   bool m_hasLowByteFirst = false;
141   bool m_hasMemMappedGPR = false;
142 
143   // Dummy member, used by FeatureSet's. We cannot have a SubtargetFeature with
144   // no variable, so we instead bind pseudo features to this variable.
145   bool m_FeatureSetDummy = false;
146 
147   AVRInstrInfo InstrInfo;
148   AVRFrameLowering FrameLowering;
149   AVRTargetLowering TLInfo;
150   AVRSelectionDAGInfo TSInfo;
151 };
152 
153 } // end namespace llvm
154 
155 #endif // LLVM_AVR_SUBTARGET_H
156