10b57cec5SDimitry Andric //===-- AVR.h - Top-level interface for AVR representation ------*- 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 contains the entry points for global functions defined in the LLVM 100b57cec5SDimitry Andric // AVR back-end. 110b57cec5SDimitry Andric // 120b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric #ifndef LLVM_AVR_H 150b57cec5SDimitry Andric #define LLVM_AVR_H 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric #include "llvm/CodeGen/SelectionDAGNodes.h" 180b57cec5SDimitry Andric #include "llvm/Target/TargetMachine.h" 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric namespace llvm { 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric class AVRTargetMachine; 230b57cec5SDimitry Andric class FunctionPass; 240b57cec5SDimitry Andric 25fe6060f1SDimitry Andric Pass *createAVRShiftExpandPass(); 260b57cec5SDimitry Andric FunctionPass *createAVRISelDag(AVRTargetMachine &TM, 270b57cec5SDimitry Andric CodeGenOpt::Level OptLevel); 280b57cec5SDimitry Andric FunctionPass *createAVRExpandPseudoPass(); 290b57cec5SDimitry Andric FunctionPass *createAVRFrameAnalyzerPass(); 300b57cec5SDimitry Andric FunctionPass *createAVRRelaxMemPass(); 310b57cec5SDimitry Andric FunctionPass *createAVRBranchSelectionPass(); 320b57cec5SDimitry Andric 33fe6060f1SDimitry Andric void initializeAVRShiftExpandPass(PassRegistry &); 340b57cec5SDimitry Andric void initializeAVRExpandPseudoPass(PassRegistry &); 350b57cec5SDimitry Andric void initializeAVRRelaxMemPass(PassRegistry &); 360b57cec5SDimitry Andric 370b57cec5SDimitry Andric /// Contains the AVR backend. 380b57cec5SDimitry Andric namespace AVR { 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric /// An integer that identifies all of the supported AVR address spaces. 41*04eeddc0SDimitry Andric enum AddressSpace { 42*04eeddc0SDimitry Andric DataMemory, 43*04eeddc0SDimitry Andric ProgramMemory, 44*04eeddc0SDimitry Andric ProgramMemory1, 45*04eeddc0SDimitry Andric ProgramMemory2, 46*04eeddc0SDimitry Andric ProgramMemory3, 47*04eeddc0SDimitry Andric ProgramMemory4, 48*04eeddc0SDimitry Andric ProgramMemory5, 49*04eeddc0SDimitry Andric NumAddrSpaces, 50*04eeddc0SDimitry Andric }; 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric /// Checks if a given type is a pointer to program memory. 530b57cec5SDimitry Andric template <typename T> bool isProgramMemoryAddress(T *V) { 54*04eeddc0SDimitry Andric auto *PT = cast<PointerType>(V->getType()); 55*04eeddc0SDimitry Andric assert(PT != nullptr && "unexpected MemSDNode"); 56*04eeddc0SDimitry Andric return PT->getAddressSpace() == ProgramMemory || 57*04eeddc0SDimitry Andric PT->getAddressSpace() == ProgramMemory1 || 58*04eeddc0SDimitry Andric PT->getAddressSpace() == ProgramMemory2 || 59*04eeddc0SDimitry Andric PT->getAddressSpace() == ProgramMemory3 || 60*04eeddc0SDimitry Andric PT->getAddressSpace() == ProgramMemory4 || 61*04eeddc0SDimitry Andric PT->getAddressSpace() == ProgramMemory5; 62*04eeddc0SDimitry Andric } 63*04eeddc0SDimitry Andric 64*04eeddc0SDimitry Andric template <typename T> AddressSpace getAddressSpace(T *V) { 65*04eeddc0SDimitry Andric auto *PT = cast<PointerType>(V->getType()); 66*04eeddc0SDimitry Andric assert(PT != nullptr && "unexpected MemSDNode"); 67*04eeddc0SDimitry Andric unsigned AS = PT->getAddressSpace(); 68*04eeddc0SDimitry Andric if (AS < NumAddrSpaces) 69*04eeddc0SDimitry Andric return static_cast<AddressSpace>(AS); 70*04eeddc0SDimitry Andric return NumAddrSpaces; 710b57cec5SDimitry Andric } 720b57cec5SDimitry Andric 730b57cec5SDimitry Andric inline bool isProgramMemoryAccess(MemSDNode const *N) { 74*04eeddc0SDimitry Andric auto *V = N->getMemOperand()->getValue(); 75*04eeddc0SDimitry Andric if (V != nullptr && isProgramMemoryAddress(V)) 76*04eeddc0SDimitry Andric return true; 77*04eeddc0SDimitry Andric return false; 78*04eeddc0SDimitry Andric } 790b57cec5SDimitry Andric 80*04eeddc0SDimitry Andric // Get the index of the program memory bank. 81*04eeddc0SDimitry Andric // -1: not program memory 82*04eeddc0SDimitry Andric // 0: ordinary program memory 83*04eeddc0SDimitry Andric // 1~5: extended program memory 84*04eeddc0SDimitry Andric inline int getProgramMemoryBank(MemSDNode const *N) { 85*04eeddc0SDimitry Andric auto *V = N->getMemOperand()->getValue(); 86*04eeddc0SDimitry Andric if (V == nullptr || !isProgramMemoryAddress(V)) 87*04eeddc0SDimitry Andric return -1; 88*04eeddc0SDimitry Andric AddressSpace AS = getAddressSpace(V); 89*04eeddc0SDimitry Andric assert(ProgramMemory <= AS && AS <= ProgramMemory5); 90*04eeddc0SDimitry Andric return static_cast<int>(AS - ProgramMemory); 910b57cec5SDimitry Andric } 920b57cec5SDimitry Andric 930b57cec5SDimitry Andric } // end of namespace AVR 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric } // end namespace llvm 960b57cec5SDimitry Andric 970b57cec5SDimitry Andric #endif // LLVM_AVR_H 98