1 //===-- AVR.h - Top-level interface for AVR representation ------*- 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 contains the entry points for global functions defined in the LLVM 10 // AVR back-end. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_AVR_H 15 #define LLVM_AVR_H 16 17 #include "llvm/CodeGen/SelectionDAGNodes.h" 18 #include "llvm/Pass.h" 19 #include "llvm/PassRegistry.h" 20 #include "llvm/Target/TargetMachine.h" 21 22 namespace llvm { 23 24 class AVRTargetMachine; 25 class FunctionPass; 26 class PassRegistry; 27 28 Pass *createAVRShiftExpandPass(); 29 FunctionPass *createAVRISelDag(AVRTargetMachine &TM, CodeGenOptLevel OptLevel); 30 FunctionPass *createAVRExpandPseudoPass(); 31 FunctionPass *createAVRFrameAnalyzerPass(); 32 FunctionPass *createAVRBranchSelectionPass(); 33 34 void initializeAVRDAGToDAGISelLegacyPass(PassRegistry &); 35 void initializeAVRExpandPseudoPass(PassRegistry &); 36 void initializeAVRShiftExpandPass(PassRegistry &); 37 38 /// Contains the AVR backend. 39 namespace AVR { 40 41 /// An integer that identifies all of the supported AVR address spaces. 42 enum AddressSpace { 43 DataMemory, 44 ProgramMemory, 45 ProgramMemory1, 46 ProgramMemory2, 47 ProgramMemory3, 48 ProgramMemory4, 49 ProgramMemory5, 50 NumAddrSpaces, 51 }; 52 53 /// Checks if a given type is a pointer to program memory. 54 template <typename T> bool isProgramMemoryAddress(T *V) { 55 auto *PT = cast<PointerType>(V->getType()); 56 assert(PT != nullptr && "unexpected MemSDNode"); 57 return PT->getAddressSpace() == ProgramMemory || 58 PT->getAddressSpace() == ProgramMemory1 || 59 PT->getAddressSpace() == ProgramMemory2 || 60 PT->getAddressSpace() == ProgramMemory3 || 61 PT->getAddressSpace() == ProgramMemory4 || 62 PT->getAddressSpace() == ProgramMemory5; 63 } 64 65 template <typename T> AddressSpace getAddressSpace(T *V) { 66 auto *PT = cast<PointerType>(V->getType()); 67 assert(PT != nullptr && "unexpected MemSDNode"); 68 unsigned AS = PT->getAddressSpace(); 69 if (AS < NumAddrSpaces) 70 return static_cast<AddressSpace>(AS); 71 return NumAddrSpaces; 72 } 73 74 inline bool isProgramMemoryAccess(MemSDNode const *N) { 75 auto *V = N->getMemOperand()->getValue(); 76 if (V != nullptr && isProgramMemoryAddress(V)) 77 return true; 78 return false; 79 } 80 81 // Get the index of the program memory bank. 82 // -1: not program memory 83 // 0: ordinary program memory 84 // 1~5: extended program memory 85 inline int getProgramMemoryBank(MemSDNode const *N) { 86 auto *V = N->getMemOperand()->getValue(); 87 if (V == nullptr || !isProgramMemoryAddress(V)) 88 return -1; 89 AddressSpace AS = getAddressSpace(V); 90 assert(ProgramMemory <= AS && AS <= ProgramMemory5); 91 return static_cast<int>(AS - ProgramMemory); 92 } 93 94 } // end of namespace AVR 95 96 } // end namespace llvm 97 98 #endif // LLVM_AVR_H 99