xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AVR/AVR.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric //===-- AVR.h - Top-level interface for AVR representation ------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file contains the entry points for global functions defined in the LLVM
100b57cec5SDimitry Andric // AVR back-end.
110b57cec5SDimitry Andric //
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #ifndef LLVM_AVR_H
150b57cec5SDimitry Andric #define LLVM_AVR_H
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric #include "llvm/CodeGen/SelectionDAGNodes.h"
1881ad6265SDimitry Andric #include "llvm/Pass.h"
1981ad6265SDimitry Andric #include "llvm/PassRegistry.h"
200b57cec5SDimitry Andric #include "llvm/Target/TargetMachine.h"
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric namespace llvm {
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric class AVRTargetMachine;
250b57cec5SDimitry Andric class FunctionPass;
26bdd1243dSDimitry Andric class PassRegistry;
270b57cec5SDimitry Andric 
28fe6060f1SDimitry Andric Pass *createAVRShiftExpandPass();
29*5f757f3fSDimitry Andric FunctionPass *createAVRISelDag(AVRTargetMachine &TM, CodeGenOptLevel OptLevel);
300b57cec5SDimitry Andric FunctionPass *createAVRExpandPseudoPass();
310b57cec5SDimitry Andric FunctionPass *createAVRFrameAnalyzerPass();
320b57cec5SDimitry Andric FunctionPass *createAVRBranchSelectionPass();
330b57cec5SDimitry Andric 
34bdd1243dSDimitry Andric void initializeAVRDAGToDAGISelPass(PassRegistry &);
350b57cec5SDimitry Andric void initializeAVRExpandPseudoPass(PassRegistry &);
36bdd1243dSDimitry Andric void initializeAVRShiftExpandPass(PassRegistry &);
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric /// Contains the AVR backend.
390b57cec5SDimitry Andric namespace AVR {
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric /// An integer that identifies all of the supported AVR address spaces.
4204eeddc0SDimitry Andric enum AddressSpace {
4304eeddc0SDimitry Andric   DataMemory,
4404eeddc0SDimitry Andric   ProgramMemory,
4504eeddc0SDimitry Andric   ProgramMemory1,
4604eeddc0SDimitry Andric   ProgramMemory2,
4704eeddc0SDimitry Andric   ProgramMemory3,
4804eeddc0SDimitry Andric   ProgramMemory4,
4904eeddc0SDimitry Andric   ProgramMemory5,
5004eeddc0SDimitry Andric   NumAddrSpaces,
5104eeddc0SDimitry Andric };
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric /// Checks if a given type is a pointer to program memory.
540b57cec5SDimitry Andric template <typename T> bool isProgramMemoryAddress(T *V) {
5504eeddc0SDimitry Andric   auto *PT = cast<PointerType>(V->getType());
5604eeddc0SDimitry Andric   assert(PT != nullptr && "unexpected MemSDNode");
5704eeddc0SDimitry Andric   return PT->getAddressSpace() == ProgramMemory ||
5804eeddc0SDimitry Andric          PT->getAddressSpace() == ProgramMemory1 ||
5904eeddc0SDimitry Andric          PT->getAddressSpace() == ProgramMemory2 ||
6004eeddc0SDimitry Andric          PT->getAddressSpace() == ProgramMemory3 ||
6104eeddc0SDimitry Andric          PT->getAddressSpace() == ProgramMemory4 ||
6204eeddc0SDimitry Andric          PT->getAddressSpace() == ProgramMemory5;
6304eeddc0SDimitry Andric }
6404eeddc0SDimitry Andric 
6504eeddc0SDimitry Andric template <typename T> AddressSpace getAddressSpace(T *V) {
6604eeddc0SDimitry Andric   auto *PT = cast<PointerType>(V->getType());
6704eeddc0SDimitry Andric   assert(PT != nullptr && "unexpected MemSDNode");
6804eeddc0SDimitry Andric   unsigned AS = PT->getAddressSpace();
6904eeddc0SDimitry Andric   if (AS < NumAddrSpaces)
7004eeddc0SDimitry Andric     return static_cast<AddressSpace>(AS);
7104eeddc0SDimitry Andric   return NumAddrSpaces;
720b57cec5SDimitry Andric }
730b57cec5SDimitry Andric 
740b57cec5SDimitry Andric inline bool isProgramMemoryAccess(MemSDNode const *N) {
7504eeddc0SDimitry Andric   auto *V = N->getMemOperand()->getValue();
7604eeddc0SDimitry Andric   if (V != nullptr && isProgramMemoryAddress(V))
7704eeddc0SDimitry Andric     return true;
7804eeddc0SDimitry Andric   return false;
7904eeddc0SDimitry Andric }
800b57cec5SDimitry Andric 
8104eeddc0SDimitry Andric // Get the index of the program memory bank.
8204eeddc0SDimitry Andric //  -1: not program memory
8304eeddc0SDimitry Andric //   0: ordinary program memory
8404eeddc0SDimitry Andric // 1~5: extended program memory
8504eeddc0SDimitry Andric inline int getProgramMemoryBank(MemSDNode const *N) {
8604eeddc0SDimitry Andric   auto *V = N->getMemOperand()->getValue();
8704eeddc0SDimitry Andric   if (V == nullptr || !isProgramMemoryAddress(V))
8804eeddc0SDimitry Andric     return -1;
8904eeddc0SDimitry Andric   AddressSpace AS = getAddressSpace(V);
9004eeddc0SDimitry Andric   assert(ProgramMemory <= AS && AS <= ProgramMemory5);
9104eeddc0SDimitry Andric   return static_cast<int>(AS - ProgramMemory);
920b57cec5SDimitry Andric }
930b57cec5SDimitry Andric 
940b57cec5SDimitry Andric } // end of namespace AVR
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric } // end namespace llvm
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric #endif // LLVM_AVR_H
99