LLVM  17.0.0git
AVR.h
Go to the documentation of this file.
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 
18 #include "llvm/Pass.h"
19 #include "llvm/PassRegistry.h"
21 
22 namespace llvm {
23 
24 class AVRTargetMachine;
25 class FunctionPass;
26 class PassRegistry;
27 
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.
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;
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
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Pass
print lazy value Lazy Value Info Printer Pass
Definition: LazyValueInfo.cpp:2066
llvm::createAVRBranchSelectionPass
FunctionPass * createAVRBranchSelectionPass()
Pass.h
llvm::AVR::ProgramMemory
@ ProgramMemory
Definition: AVR.h:45
llvm::AVR::ProgramMemory2
@ ProgramMemory2
Definition: AVR.h:47
llvm::MemSDNode
This is an abstract virtual class for memory operations.
Definition: SelectionDAGNodes.h:1275
llvm::AVR::ProgramMemory3
@ ProgramMemory3
Definition: AVR.h:48
PassRegistry.h
llvm::AVR::NumAddrSpaces
@ NumAddrSpaces
Definition: AVR.h:51
llvm::AVR::getAddressSpace
AddressSpace getAddressSpace(T *V)
Definition: AVR.h:66
llvm::AVR::ProgramMemory1
@ ProgramMemory1
Definition: AVR.h:46
llvm::AVR::DataMemory
@ DataMemory
Definition: AVR.h:44
TargetMachine.h
SelectionDAGNodes.h
llvm::AVR::ProgramMemory5
@ ProgramMemory5
Definition: AVR.h:50
llvm::initializeAVRExpandPseudoPass
void initializeAVRExpandPseudoPass(PassRegistry &)
llvm::initializeAVRDAGToDAGISelPass
void initializeAVRDAGToDAGISelPass(PassRegistry &)
llvm::AVR::ProgramMemory4
@ ProgramMemory4
Definition: AVR.h:49
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AVR::isProgramMemoryAddress
bool isProgramMemoryAddress(T *V)
Checks if a given type is a pointer to program memory.
Definition: AVR.h:55
llvm::initializeAVRShiftExpandPass
void initializeAVRShiftExpandPass(PassRegistry &)
llvm::createAVRISelDag
FunctionPass * createAVRISelDag(AVRTargetMachine &TM, CodeGenOpt::Level OptLevel)
Definition: AVRISelDAGToDAG.cpp:583
llvm::AVR::getProgramMemoryBank
int getProgramMemoryBank(MemSDNode const *N)
Definition: AVR.h:86
llvm::AVR::AddressSpace
AddressSpace
An integer that identifies all of the supported AVR address spaces.
Definition: AVR.h:43
llvm::createAVRFrameAnalyzerPass
FunctionPass * createAVRFrameAnalyzerPass()
Creates instance of the frame analyzer pass.
Definition: AVRFrameLowering.cpp:488
N
#define N
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::createAVRShiftExpandPass
Pass * createAVRShiftExpandPass()
llvm::CodeGenOpt::Level
Level
Code generation optimization level.
Definition: CodeGen.h:57
llvm::createAVRExpandPseudoPass
FunctionPass * createAVRExpandPseudoPass()
llvm::AVR::isProgramMemoryAccess
bool isProgramMemoryAccess(MemSDNode const *N)
Definition: AVR.h:75