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