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
22namespace llvm {
23
24class AVRTargetMachine;
25class FunctionPass;
26class PassRegistry;
27
28Pass *createAVRShiftExpandPass();
29FunctionPass *createAVRISelDag(AVRTargetMachine &TM, CodeGenOptLevel OptLevel);
30FunctionPass *createAVRExpandPseudoPass();
31FunctionPass *createAVRFrameAnalyzerPass();
32FunctionPass *createAVRBranchSelectionPass();
33
34void initializeAVRDAGToDAGISelPass(PassRegistry &);
35void initializeAVRExpandPseudoPass(PassRegistry &);
36void initializeAVRShiftExpandPass(PassRegistry &);
37
38/// Contains the AVR backend.
39namespace AVR {
40
41/// An integer that identifies all of the supported AVR address spaces.
42enum 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.
54template <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
65template <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
74inline 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
85inline 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

source code of llvm/lib/Target/AVR/AVR.h