xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AVR/AVR.h (revision 19fae0f66023a97a9b464b3beeeabb2081f575b3)
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,
30                                CodeGenOpt::Level OptLevel);
31 FunctionPass *createAVRExpandPseudoPass();
32 FunctionPass *createAVRFrameAnalyzerPass();
33 FunctionPass *createAVRBranchSelectionPass();
34 
35 void initializeAVRDAGToDAGISelPass(PassRegistry &);
36 void initializeAVRExpandPseudoPass(PassRegistry &);
37 void initializeAVRShiftExpandPass(PassRegistry &);
38 
39 /// Contains the AVR backend.
40 namespace AVR {
41 
42 /// An integer that identifies all of the supported AVR address spaces.
43 enum AddressSpace {
44   DataMemory,
45   ProgramMemory,
46   ProgramMemory1,
47   ProgramMemory2,
48   ProgramMemory3,
49   ProgramMemory4,
50   ProgramMemory5,
51   NumAddrSpaces,
52 };
53 
54 /// Checks if a given type is a pointer to program memory.
55 template <typename T> bool isProgramMemoryAddress(T *V) {
56   auto *PT = cast<PointerType>(V->getType());
57   assert(PT != nullptr && "unexpected MemSDNode");
58   return PT->getAddressSpace() == ProgramMemory ||
59          PT->getAddressSpace() == ProgramMemory1 ||
60          PT->getAddressSpace() == ProgramMemory2 ||
61          PT->getAddressSpace() == ProgramMemory3 ||
62          PT->getAddressSpace() == ProgramMemory4 ||
63          PT->getAddressSpace() == ProgramMemory5;
64 }
65 
66 template <typename T> AddressSpace getAddressSpace(T *V) {
67   auto *PT = cast<PointerType>(V->getType());
68   assert(PT != nullptr && "unexpected MemSDNode");
69   unsigned AS = PT->getAddressSpace();
70   if (AS < NumAddrSpaces)
71     return static_cast<AddressSpace>(AS);
72   return NumAddrSpaces;
73 }
74 
75 inline bool isProgramMemoryAccess(MemSDNode const *N) {
76   auto *V = N->getMemOperand()->getValue();
77   if (V != nullptr && isProgramMemoryAddress(V))
78     return true;
79   return false;
80 }
81 
82 // Get the index of the program memory bank.
83 //  -1: not program memory
84 //   0: ordinary program memory
85 // 1~5: extended program memory
86 inline int getProgramMemoryBank(MemSDNode const *N) {
87   auto *V = N->getMemOperand()->getValue();
88   if (V == nullptr || !isProgramMemoryAddress(V))
89     return -1;
90   AddressSpace AS = getAddressSpace(V);
91   assert(ProgramMemory <= AS && AS <= ProgramMemory5);
92   return static_cast<int>(AS - ProgramMemory);
93 }
94 
95 } // end of namespace AVR
96 
97 } // end namespace llvm
98 
99 #endif // LLVM_AVR_H
100