LLVM  17.0.0git
AVRSubtarget.h
Go to the documentation of this file.
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 
17 #include "llvm/IR/DataLayout.h"
19 
20 #include "AVRFrameLowering.h"
21 #include "AVRISelLowering.h"
22 #include "AVRInstrInfo.h"
23 #include "AVRSelectionDAGInfo.h"
25 
26 #define GET_SUBTARGETINFO_HEADER
27 #include "AVRGenSubtargetInfo.inc"
28 
29 namespace llvm {
30 
31 /// A specific AVR target MCU.
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`.
59 
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 hasPROGMEM() const { return m_hasPROGMEM; }
77  bool hasSPM() const { return m_hasSPM; }
78  bool hasSPMX() const { return m_hasSPMX; }
79  bool hasDES() const { return m_hasDES; }
80  bool supportsRMW() const { return m_supportsRMW; }
81  bool supportsMultiplication() const { return m_supportsMultiplication; }
82  bool hasBREAK() const { return m_hasBREAK; }
83  bool hasTinyEncoding() const { return m_hasTinyEncoding; }
84  bool hasMemMappedGPR() const { return m_hasMemMappedGPR; }
85 
86  uint8_t getIORegisterOffset() const { return hasMemMappedGPR() ? 0x20 : 0x0; }
87 
88  /// Gets the ELF architecture for the e_flags field
89  /// of an ELF object file.
90  unsigned getELFArch() const {
91  assert(ELFArch != 0 &&
92  "every device must have an associate ELF architecture");
93  return ELFArch;
94  }
95 
96  /// Get I/O register addresses.
97  int getIORegRAMPZ() const { return hasELPM() ? 0x3b : -1; }
98  int getIORegEIND() const { return hasEIJMPCALL() ? 0x3c : -1; }
99  int getIORegSPL() const { return 0x3d; }
100  int getIORegSPH() const { return hasSmallStack() ? -1 : 0x3e; }
101  int getIORegSREG() const { return 0x3f; }
102 
103  /// Get GPR aliases.
104  int getRegTmpIndex() const { return hasTinyEncoding() ? 16 : 0; }
105  int getRegZeroIndex() const { return hasTinyEncoding() ? 17 : 1; }
106 
108  return hasTinyEncoding() ? AVR::R16 : AVR::R0;
109  }
111  return hasTinyEncoding() ? AVR::R17 : AVR::R1;
112  }
113 
114 private:
115  /// The ELF e_flags architecture.
116  unsigned ELFArch = 0;
117 
118  // Subtarget feature settings
119  // See AVR.td for details.
120  bool m_hasSRAM = false;
121  bool m_hasJMPCALL = false;
122  bool m_hasIJMPCALL = false;
123  bool m_hasEIJMPCALL = false;
124  bool m_hasADDSUBIW = false;
125  bool m_hasSmallStack = false;
126  bool m_hasMOVW = false;
127  bool m_hasLPM = false;
128  bool m_hasLPMX = false;
129  bool m_hasELPM = false;
130  bool m_hasELPMX = false;
131  bool m_hasPROGMEM = false;
132  bool m_hasSPM = false;
133  bool m_hasSPMX = false;
134  bool m_hasDES = false;
135  bool m_supportsRMW = false;
136  bool m_supportsMultiplication = false;
137  bool m_hasBREAK = false;
138  bool m_hasTinyEncoding = false;
139  bool m_hasMemMappedGPR = false;
140 
141  // Dummy member, used by FeatureSet's. We cannot have a SubtargetFeature with
142  // no variable, so we instead bind pseudo features to this variable.
143  bool m_FeatureSetDummy = false;
144 
145  AVRInstrInfo InstrInfo;
146  AVRFrameLowering FrameLowering;
147  AVRTargetLowering TLInfo;
148  AVRSelectionDAGInfo TSInfo;
149 };
150 
151 } // end namespace llvm
152 
153 #endif // LLVM_AVR_SUBTARGET_H
llvm::AVRSubtarget::getRegZeroIndex
int getRegZeroIndex() const
Definition: AVRSubtarget.h:105
llvm::AVRSubtarget::hasLPMX
bool hasLPMX() const
Definition: AVRSubtarget.h:73
llvm::AVRSubtarget::initializeSubtargetDependencies
AVRSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS, const TargetMachine &TM)
Definition: AVRSubtarget.cpp:39
llvm::AVRSubtarget::hasBREAK
bool hasBREAK() const
Definition: AVRSubtarget.h:82
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition: TargetFrameLowering.h:43
llvm::AVRSubtarget::hasTinyEncoding
bool hasTinyEncoding() const
Definition: AVRSubtarget.h:83
llvm::AVRTargetMachine
A generic AVR implementation.
Definition: AVRTargetMachine.h:30
llvm::AVRSubtarget::hasDES
bool hasDES() const
Definition: AVRSubtarget.h:79
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::AVRSubtarget::hasMOVW
bool hasMOVW() const
Definition: AVRSubtarget.h:71
llvm::X86AS::FS
@ FS
Definition: X86.h:201
llvm::AVRSubtarget::getIORegisterOffset
uint8_t getIORegisterOffset() const
Definition: AVRSubtarget.h:86
llvm::AVRSubtarget::getSelectionDAGInfo
const AVRSelectionDAGInfo * getSelectionDAGInfo() const override
Definition: AVRSubtarget.h:49
llvm::AVRSubtarget::getIORegSPH
int getIORegSPH() const
Definition: AVRSubtarget.h:100
llvm::AVRSubtarget::getIORegRAMPZ
int getIORegRAMPZ() const
Get I/O register addresses.
Definition: AVRSubtarget.h:97
llvm::AVRSubtarget::hasLPM
bool hasLPM() const
Definition: AVRSubtarget.h:72
llvm::AVRSubtarget::hasSPM
bool hasSPM() const
Definition: AVRSubtarget.h:77
AVRGenSubtargetInfo
llvm::AVRSubtarget::hasMemMappedGPR
bool hasMemMappedGPR() const
Definition: AVRSubtarget.h:84
TargetMachine.h
llvm::AVRSubtarget::hasSRAM
bool hasSRAM() const
Definition: AVRSubtarget.h:65
llvm::AVRSubtarget::getTmpRegister
Register getTmpRegister() const
Definition: AVRSubtarget.h:107
llvm::AVRSubtarget
A specific AVR target MCU.
Definition: AVRSubtarget.h:32
llvm::AVRSubtarget::hasEIJMPCALL
bool hasEIJMPCALL() const
Definition: AVRSubtarget.h:68
llvm::AVRSubtarget::AVRSubtarget
AVRSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const AVRTargetMachine &TM)
Creates an AVR subtarget.
Definition: AVRSubtarget.cpp:30
llvm::AVRSubtarget::getTargetLowering
const AVRTargetLowering * getTargetLowering() const override
Definition: AVRSubtarget.h:46
llvm::AVRSubtarget::hasELPMX
bool hasELPMX() const
Definition: AVRSubtarget.h:75
llvm::AVRSubtarget::getInstrInfo
const AVRInstrInfo * getInstrInfo() const override
Definition: AVRSubtarget.h:42
llvm::AVRSubtarget::supportsRMW
bool supportsRMW() const
Definition: AVRSubtarget.h:80
llvm::AVRSubtarget::getZeroRegister
Register getZeroRegister() const
Definition: AVRSubtarget.h:110
llvm::AVRSubtarget::hasADDSUBIW
bool hasADDSUBIW() const
Definition: AVRSubtarget.h:69
llvm::AVRSubtarget::hasJMPCALL
bool hasJMPCALL() const
Definition: AVRSubtarget.h:66
llvm::AVRSubtarget::hasPROGMEM
bool hasPROGMEM() const
Definition: AVRSubtarget.h:76
llvm::AVRRegisterInfo
Utilities relating to AVR registers.
Definition: AVRRegisterInfo.h:24
AVRFrameLowering.h
llvm::AVRTargetLowering
Performs target lowering for the AVR.
Definition: AVRISelLowering.h:84
llvm::AVRSubtarget::hasSmallStack
bool hasSmallStack() const
Definition: AVRSubtarget.h:70
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:78
llvm::AVRSubtarget::supportsMultiplication
bool supportsMultiplication() const
Definition: AVRSubtarget.h:81
AVRMCTargetDesc.h
llvm::AVRSubtarget::getRegTmpIndex
int getRegTmpIndex() const
Get GPR aliases.
Definition: AVRSubtarget.h:104
llvm::AVRSubtarget::hasELPM
bool hasELPM() const
Definition: AVRSubtarget.h:74
DataLayout.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
TargetSubtargetInfo.h
llvm::AVRSubtarget::hasIJMPCALL
bool hasIJMPCALL() const
Definition: AVRSubtarget.h:67
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
AVRSelectionDAGInfo.h
llvm::AVRSubtarget::getFrameLowering
const TargetFrameLowering * getFrameLowering() const override
Definition: AVRSubtarget.h:43
llvm::AVRInstrInfo::getRegisterInfo
const AVRRegisterInfo & getRegisterInfo() const
Definition: AVRInstrInfo.h:68
llvm::AVRSubtarget::ParseSubtargetFeatures
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
Parses a subtarget feature string, setting appropriate options.
llvm::AVRSubtarget::getIORegSPL
int getIORegSPL() const
Definition: AVRSubtarget.h:99
llvm::AVRSubtarget::getELFArch
unsigned getELFArch() const
Gets the ELF architecture for the e_flags field of an ELF object file.
Definition: AVRSubtarget.h:90
llvm::AVRFrameLowering
Utilities for creating function call frames.
Definition: AVRFrameLowering.h:17
llvm::AVRSubtarget::getRegisterInfo
const AVRRegisterInfo * getRegisterInfo() const override
Definition: AVRSubtarget.h:52
llvm::AVRSubtarget::hasSPMX
bool hasSPMX() const
Definition: AVRSubtarget.h:78
llvm::AVRInstrInfo
Utilities related to the AVR instruction set.
Definition: AVRInstrInfo.h:64
AVRInstrInfo.h
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::AVRSubtarget::getIORegEIND
int getIORegEIND() const
Definition: AVRSubtarget.h:98
llvm::AVRSubtarget::getIORegSREG
int getIORegSREG() const
Definition: AVRSubtarget.h:101
AVRISelLowering.h
llvm::AVRSelectionDAGInfo
Holds information about the AVR instruction selection DAG.
Definition: AVRSelectionDAGInfo.h:21