Path: blob/main/contrib/llvm-project/llvm/lib/Target/AVR/AVR.h
35266 views
//===-- AVR.h - Top-level interface for AVR representation ------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains the entry points for global functions defined in the LLVM9// AVR back-end.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_AVR_H14#define LLVM_AVR_H1516#include "llvm/CodeGen/SelectionDAGNodes.h"17#include "llvm/Pass.h"18#include "llvm/PassRegistry.h"19#include "llvm/Target/TargetMachine.h"2021namespace llvm {2223class AVRTargetMachine;24class FunctionPass;25class PassRegistry;2627Pass *createAVRShiftExpandPass();28FunctionPass *createAVRISelDag(AVRTargetMachine &TM, CodeGenOptLevel OptLevel);29FunctionPass *createAVRExpandPseudoPass();30FunctionPass *createAVRFrameAnalyzerPass();31FunctionPass *createAVRBranchSelectionPass();3233void initializeAVRDAGToDAGISelLegacyPass(PassRegistry &);34void initializeAVRExpandPseudoPass(PassRegistry &);35void initializeAVRShiftExpandPass(PassRegistry &);3637/// Contains the AVR backend.38namespace AVR {3940/// An integer that identifies all of the supported AVR address spaces.41enum AddressSpace {42DataMemory,43ProgramMemory,44ProgramMemory1,45ProgramMemory2,46ProgramMemory3,47ProgramMemory4,48ProgramMemory5,49NumAddrSpaces,50};5152/// Checks if a given type is a pointer to program memory.53template <typename T> bool isProgramMemoryAddress(T *V) {54auto *PT = cast<PointerType>(V->getType());55assert(PT != nullptr && "unexpected MemSDNode");56return PT->getAddressSpace() == ProgramMemory ||57PT->getAddressSpace() == ProgramMemory1 ||58PT->getAddressSpace() == ProgramMemory2 ||59PT->getAddressSpace() == ProgramMemory3 ||60PT->getAddressSpace() == ProgramMemory4 ||61PT->getAddressSpace() == ProgramMemory5;62}6364template <typename T> AddressSpace getAddressSpace(T *V) {65auto *PT = cast<PointerType>(V->getType());66assert(PT != nullptr && "unexpected MemSDNode");67unsigned AS = PT->getAddressSpace();68if (AS < NumAddrSpaces)69return static_cast<AddressSpace>(AS);70return NumAddrSpaces;71}7273inline bool isProgramMemoryAccess(MemSDNode const *N) {74auto *V = N->getMemOperand()->getValue();75if (V != nullptr && isProgramMemoryAddress(V))76return true;77return false;78}7980// Get the index of the program memory bank.81// -1: not program memory82// 0: ordinary program memory83// 1~5: extended program memory84inline int getProgramMemoryBank(MemSDNode const *N) {85auto *V = N->getMemOperand()->getValue();86if (V == nullptr || !isProgramMemoryAddress(V))87return -1;88AddressSpace AS = getAddressSpace(V);89assert(ProgramMemory <= AS && AS <= ProgramMemory5);90return static_cast<int>(AS - ProgramMemory);91}9293} // end of namespace AVR9495} // end namespace llvm9697#endif // LLVM_AVR_H9899100