1 //===-- AVR.h - Top-level interface for AVR representation ------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains the entry points for global functions defined in the LLVM
12 //===----------------------------------------------------------------------===//
17 #include "llvm/CodeGen/SelectionDAGNodes.h"
18 #include "llvm/Pass.h"
19 #include "llvm/PassRegistry.h"
20 #include "llvm/Target/TargetMachine.h"
24 class AVRTargetMachine
;
28 Pass
*createAVRShiftExpandPass();
29 FunctionPass
*createAVRISelDag(AVRTargetMachine
&TM
, CodeGenOptLevel OptLevel
);
30 FunctionPass
*createAVRExpandPseudoPass();
31 FunctionPass
*createAVRFrameAnalyzerPass();
32 FunctionPass
*createAVRBranchSelectionPass();
34 void initializeAVRDAGToDAGISelLegacyPass(PassRegistry
&);
35 void initializeAVRExpandPseudoPass(PassRegistry
&);
36 void initializeAVRShiftExpandPass(PassRegistry
&);
38 /// Contains the AVR backend.
41 /// An integer that identifies all of the supported AVR address spaces.
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
;
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
);
74 inline bool isProgramMemoryAccess(MemSDNode
const *N
) {
75 auto *V
= N
->getMemOperand()->getValue();
76 if (V
!= nullptr && isProgramMemoryAddress(V
))
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
))
89 AddressSpace AS
= getAddressSpace(V
);
90 assert(ProgramMemory
<= AS
&& AS
<= ProgramMemory5
);
91 return static_cast<int>(AS
- ProgramMemory
);
94 } // end of namespace AVR
96 } // end namespace llvm