10b57cec5SDimitry Andric //===-- AVRSubtarget.h - Define Subtarget for the AVR -----------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file declares the AVR specific subclass of TargetSubtargetInfo. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #ifndef LLVM_AVR_SUBTARGET_H 140b57cec5SDimitry Andric #define LLVM_AVR_SUBTARGET_H 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric #include "llvm/CodeGen/TargetSubtargetInfo.h" 170b57cec5SDimitry Andric #include "llvm/IR/DataLayout.h" 180b57cec5SDimitry Andric #include "llvm/Target/TargetMachine.h" 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric #include "AVRFrameLowering.h" 210b57cec5SDimitry Andric #include "AVRISelLowering.h" 220b57cec5SDimitry Andric #include "AVRInstrInfo.h" 230b57cec5SDimitry Andric #include "AVRSelectionDAGInfo.h" 24bdd1243dSDimitry Andric #include "MCTargetDesc/AVRMCTargetDesc.h" 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric #define GET_SUBTARGETINFO_HEADER 270b57cec5SDimitry Andric #include "AVRGenSubtargetInfo.inc" 280b57cec5SDimitry Andric 290b57cec5SDimitry Andric namespace llvm { 300b57cec5SDimitry Andric 310b57cec5SDimitry Andric /// A specific AVR target MCU. 320b57cec5SDimitry Andric class AVRSubtarget : public AVRGenSubtargetInfo { 330b57cec5SDimitry Andric public: 340b57cec5SDimitry Andric //! Creates an AVR subtarget. 350b57cec5SDimitry Andric //! \param TT The target triple. 360b57cec5SDimitry Andric //! \param CPU The CPU to target. 370b57cec5SDimitry Andric //! \param FS The feature string. 380b57cec5SDimitry Andric //! \param TM The target machine. 390b57cec5SDimitry Andric AVRSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, 400b57cec5SDimitry Andric const AVRTargetMachine &TM); 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric const AVRInstrInfo *getInstrInfo() const override { return &InstrInfo; } 43349cc55cSDimitry Andric const TargetFrameLowering *getFrameLowering() const override { 44349cc55cSDimitry Andric return &FrameLowering; 45349cc55cSDimitry Andric } 46349cc55cSDimitry Andric const AVRTargetLowering *getTargetLowering() const override { 47349cc55cSDimitry Andric return &TLInfo; 48349cc55cSDimitry Andric } 49349cc55cSDimitry Andric const AVRSelectionDAGInfo *getSelectionDAGInfo() const override { 50349cc55cSDimitry Andric return &TSInfo; 51349cc55cSDimitry Andric } 52349cc55cSDimitry Andric const AVRRegisterInfo *getRegisterInfo() const override { 53349cc55cSDimitry Andric return &InstrInfo.getRegisterInfo(); 54349cc55cSDimitry Andric } 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric /// Parses a subtarget feature string, setting appropriate options. 570b57cec5SDimitry Andric /// \note Definition of function is auto generated by `tblgen`. 58e8d8bef9SDimitry Andric void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS); 590b57cec5SDimitry Andric 600b57cec5SDimitry Andric AVRSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS, 610b57cec5SDimitry Andric const TargetMachine &TM); 620b57cec5SDimitry Andric 630b57cec5SDimitry Andric // Subtarget feature getters. 64*5f757f3fSDimitry Andric #define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \ 65*5f757f3fSDimitry Andric bool GETTER() const { return ATTRIBUTE; } 66*5f757f3fSDimitry Andric #include "AVRGenSubtargetInfo.inc" 675ffd83dbSDimitry Andric 685ffd83dbSDimitry Andric uint8_t getIORegisterOffset() const { return hasMemMappedGPR() ? 0x20 : 0x0; } 690b57cec5SDimitry Andric 7006c3fb27SDimitry Andric bool enableSubRegLiveness() const override { return true; } 7106c3fb27SDimitry Andric 720b57cec5SDimitry Andric /// Gets the ELF architecture for the e_flags field 730b57cec5SDimitry Andric /// of an ELF object file. 740b57cec5SDimitry Andric unsigned getELFArch() const { 750b57cec5SDimitry Andric assert(ELFArch != 0 && 760b57cec5SDimitry Andric "every device must have an associate ELF architecture"); 770b57cec5SDimitry Andric return ELFArch; 780b57cec5SDimitry Andric } 790b57cec5SDimitry Andric 8081ad6265SDimitry Andric /// Get I/O register addresses. 81fcaf7f86SDimitry Andric int getIORegRAMPZ() const { return hasELPM() ? 0x3b : -1; } 82fcaf7f86SDimitry Andric int getIORegEIND() const { return hasEIJMPCALL() ? 0x3c : -1; } 83fcaf7f86SDimitry Andric int getIORegSPL() const { return 0x3d; } 84fcaf7f86SDimitry Andric int getIORegSPH() const { return hasSmallStack() ? -1 : 0x3e; } 85fcaf7f86SDimitry Andric int getIORegSREG() const { return 0x3f; } 8681ad6265SDimitry Andric 8781ad6265SDimitry Andric /// Get GPR aliases. 88fcaf7f86SDimitry Andric int getRegTmpIndex() const { return hasTinyEncoding() ? 16 : 0; } 89fcaf7f86SDimitry Andric int getRegZeroIndex() const { return hasTinyEncoding() ? 17 : 1; } 9004eeddc0SDimitry Andric 91bdd1243dSDimitry Andric Register getTmpRegister() const { 92bdd1243dSDimitry Andric return hasTinyEncoding() ? AVR::R16 : AVR::R0; 93bdd1243dSDimitry Andric } 94bdd1243dSDimitry Andric Register getZeroRegister() const { 95bdd1243dSDimitry Andric return hasTinyEncoding() ? AVR::R17 : AVR::R1; 96bdd1243dSDimitry Andric } 97bdd1243dSDimitry Andric 980b57cec5SDimitry Andric private: 995ffd83dbSDimitry Andric /// The ELF e_flags architecture. 100bdd1243dSDimitry Andric unsigned ELFArch = 0; 1010b57cec5SDimitry Andric 1020b57cec5SDimitry Andric // Subtarget feature settings 103*5f757f3fSDimitry Andric #define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \ 104*5f757f3fSDimitry Andric bool ATTRIBUTE = DEFAULT; 105*5f757f3fSDimitry Andric #include "AVRGenSubtargetInfo.inc" 1065ffd83dbSDimitry Andric 1075ffd83dbSDimitry Andric AVRInstrInfo InstrInfo; 1085ffd83dbSDimitry Andric AVRFrameLowering FrameLowering; 1095ffd83dbSDimitry Andric AVRTargetLowering TLInfo; 1105ffd83dbSDimitry Andric AVRSelectionDAGInfo TSInfo; 1110b57cec5SDimitry Andric }; 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andric } // end namespace llvm 1140b57cec5SDimitry Andric 1150b57cec5SDimitry Andric #endif // LLVM_AVR_SUBTARGET_H 116