xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AVR/AVR.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
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;
26*bdd1243dSDimitry Andric class PassRegistry;
270b57cec5SDimitry Andric 
28fe6060f1SDimitry Andric Pass *createAVRShiftExpandPass();
290b57cec5SDimitry Andric FunctionPass *createAVRISelDag(AVRTargetMachine &TM,
300b57cec5SDimitry Andric                                CodeGenOpt::Level OptLevel);
310b57cec5SDimitry Andric FunctionPass *createAVRExpandPseudoPass();
320b57cec5SDimitry Andric FunctionPass *createAVRFrameAnalyzerPass();
330b57cec5SDimitry Andric FunctionPass *createAVRBranchSelectionPass();
340b57cec5SDimitry Andric 
35*bdd1243dSDimitry Andric void initializeAVRDAGToDAGISelPass(PassRegistry &);
360b57cec5SDimitry Andric void initializeAVRExpandPseudoPass(PassRegistry &);
37*bdd1243dSDimitry Andric void initializeAVRShiftExpandPass(PassRegistry &);
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric /// Contains the AVR backend.
400b57cec5SDimitry Andric namespace AVR {
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric /// An integer that identifies all of the supported AVR address spaces.
4304eeddc0SDimitry Andric enum AddressSpace {
4404eeddc0SDimitry Andric   DataMemory,
4504eeddc0SDimitry Andric   ProgramMemory,
4604eeddc0SDimitry Andric   ProgramMemory1,
4704eeddc0SDimitry Andric   ProgramMemory2,
4804eeddc0SDimitry Andric   ProgramMemory3,
4904eeddc0SDimitry Andric   ProgramMemory4,
5004eeddc0SDimitry Andric   ProgramMemory5,
5104eeddc0SDimitry Andric   NumAddrSpaces,
5204eeddc0SDimitry Andric };
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric /// Checks if a given type is a pointer to program memory.
550b57cec5SDimitry Andric template <typename T> bool isProgramMemoryAddress(T *V) {
5604eeddc0SDimitry Andric   auto *PT = cast<PointerType>(V->getType());
5704eeddc0SDimitry Andric   assert(PT != nullptr && "unexpected MemSDNode");
5804eeddc0SDimitry Andric   return PT->getAddressSpace() == ProgramMemory ||
5904eeddc0SDimitry Andric          PT->getAddressSpace() == ProgramMemory1 ||
6004eeddc0SDimitry Andric          PT->getAddressSpace() == ProgramMemory2 ||
6104eeddc0SDimitry Andric          PT->getAddressSpace() == ProgramMemory3 ||
6204eeddc0SDimitry Andric          PT->getAddressSpace() == ProgramMemory4 ||
6304eeddc0SDimitry Andric          PT->getAddressSpace() == ProgramMemory5;
6404eeddc0SDimitry Andric }
6504eeddc0SDimitry Andric 
6604eeddc0SDimitry Andric template <typename T> AddressSpace getAddressSpace(T *V) {
6704eeddc0SDimitry Andric   auto *PT = cast<PointerType>(V->getType());
6804eeddc0SDimitry Andric   assert(PT != nullptr && "unexpected MemSDNode");
6904eeddc0SDimitry Andric   unsigned AS = PT->getAddressSpace();
7004eeddc0SDimitry Andric   if (AS < NumAddrSpaces)
7104eeddc0SDimitry Andric     return static_cast<AddressSpace>(AS);
7204eeddc0SDimitry Andric   return NumAddrSpaces;
730b57cec5SDimitry Andric }
740b57cec5SDimitry Andric 
750b57cec5SDimitry Andric inline bool isProgramMemoryAccess(MemSDNode const *N) {
7604eeddc0SDimitry Andric   auto *V = N->getMemOperand()->getValue();
7704eeddc0SDimitry Andric   if (V != nullptr && isProgramMemoryAddress(V))
7804eeddc0SDimitry Andric     return true;
7904eeddc0SDimitry Andric   return false;
8004eeddc0SDimitry Andric }
810b57cec5SDimitry Andric 
8204eeddc0SDimitry Andric // Get the index of the program memory bank.
8304eeddc0SDimitry Andric //  -1: not program memory
8404eeddc0SDimitry Andric //   0: ordinary program memory
8504eeddc0SDimitry Andric // 1~5: extended program memory
8604eeddc0SDimitry Andric inline int getProgramMemoryBank(MemSDNode const *N) {
8704eeddc0SDimitry Andric   auto *V = N->getMemOperand()->getValue();
8804eeddc0SDimitry Andric   if (V == nullptr || !isProgramMemoryAddress(V))
8904eeddc0SDimitry Andric     return -1;
9004eeddc0SDimitry Andric   AddressSpace AS = getAddressSpace(V);
9104eeddc0SDimitry Andric   assert(ProgramMemory <= AS && AS <= ProgramMemory5);
9204eeddc0SDimitry Andric   return static_cast<int>(AS - ProgramMemory);
930b57cec5SDimitry Andric }
940b57cec5SDimitry Andric 
950b57cec5SDimitry Andric } // end of namespace AVR
960b57cec5SDimitry Andric 
970b57cec5SDimitry Andric } // end namespace llvm
980b57cec5SDimitry Andric 
990b57cec5SDimitry Andric #endif // LLVM_AVR_H
100