LLVM  15.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 
28 FunctionPass *createAVRISelDag(AVRTargetMachine &TM,
29  CodeGenOpt::Level OptLevel);
30 FunctionPass *createAVRExpandPseudoPass();
31 FunctionPass *createAVRFrameAnalyzerPass();
32 FunctionPass *createAVRBranchSelectionPass();
33 
34 void initializeAVRShiftExpandPass(PassRegistry &);
35 void initializeAVRExpandPseudoPass(PassRegistry &);
36 
37 /// Contains the AVR backend.
38 namespace AVR {
39 
40 /// An integer that identifies all of the supported AVR address spaces.
50 };
51 
52 /// Checks if a given type is a pointer to program memory.
53 template <typename T> bool isProgramMemoryAddress(T *V) {
54  auto *PT = cast<PointerType>(V->getType());
55  assert(PT != nullptr && "unexpected MemSDNode");
56  return PT->getAddressSpace() == ProgramMemory ||
57  PT->getAddressSpace() == ProgramMemory1 ||
58  PT->getAddressSpace() == ProgramMemory2 ||
59  PT->getAddressSpace() == ProgramMemory3 ||
60  PT->getAddressSpace() == ProgramMemory4 ||
61  PT->getAddressSpace() == ProgramMemory5;
62 }
63 
64 template <typename T> AddressSpace getAddressSpace(T *V) {
65  auto *PT = cast<PointerType>(V->getType());
66  assert(PT != nullptr && "unexpected MemSDNode");
67  unsigned AS = PT->getAddressSpace();
68  if (AS < NumAddrSpaces)
69  return static_cast<AddressSpace>(AS);
70  return NumAddrSpaces;
71 }
72 
73 inline bool isProgramMemoryAccess(MemSDNode const *N) {
74  auto *V = N->getMemOperand()->getValue();
75  if (V != nullptr && isProgramMemoryAddress(V))
76  return true;
77  return false;
78 }
79 
80 // Get the index of the program memory bank.
81 // -1: not program memory
82 // 0: ordinary program memory
83 // 1~5: extended program memory
84 inline int getProgramMemoryBank(MemSDNode const *N) {
85  auto *V = N->getMemOperand()->getValue();
86  if (V == nullptr || !isProgramMemoryAddress(V))
87  return -1;
89  assert(ProgramMemory <= AS && AS <= ProgramMemory5);
90  return static_cast<int>(AS - ProgramMemory);
91 }
92 
93 } // end of namespace AVR
94 
95 } // end namespace llvm
96 
97 #endif // LLVM_AVR_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
Pass
print lazy value Lazy Value Info Printer Pass
Definition: LazyValueInfo.cpp:1978
llvm::createAVRBranchSelectionPass
FunctionPass * createAVRBranchSelectionPass()
Pass.h
llvm::AVR::ProgramMemory
@ ProgramMemory
Definition: AVR.h:43
llvm::AVR::ProgramMemory2
@ ProgramMemory2
Definition: AVR.h:45
llvm::MemSDNode
This is an abstract virtual class for memory operations.
Definition: SelectionDAGNodes.h:1259
llvm::AVR::ProgramMemory3
@ ProgramMemory3
Definition: AVR.h:46
PassRegistry.h
llvm::AVR::NumAddrSpaces
@ NumAddrSpaces
Definition: AVR.h:49
llvm::AVR::getAddressSpace
AddressSpace getAddressSpace(T *V)
Definition: AVR.h:64
llvm::AVR::ProgramMemory1
@ ProgramMemory1
Definition: AVR.h:44
llvm::AVR::DataMemory
@ DataMemory
Definition: AVR.h:42
TargetMachine.h
SelectionDAGNodes.h
llvm::AVR::ProgramMemory5
@ ProgramMemory5
Definition: AVR.h:48
llvm::initializeAVRExpandPseudoPass
void initializeAVRExpandPseudoPass(PassRegistry &)
llvm::AVR::ProgramMemory4
@ ProgramMemory4
Definition: AVR.h:47
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:53
llvm::initializeAVRShiftExpandPass
void initializeAVRShiftExpandPass(PassRegistry &)
llvm::createAVRISelDag
FunctionPass * createAVRISelDag(AVRTargetMachine &TM, CodeGenOpt::Level OptLevel)
Definition: AVRISelDAGToDAG.cpp:578
llvm::CodeGenOpt::Level
Level
Definition: CodeGen.h:52
llvm::AVR::getProgramMemoryBank
int getProgramMemoryBank(MemSDNode const *N)
Definition: AVR.h:84
llvm::AVR::AddressSpace
AddressSpace
An integer that identifies all of the supported AVR address spaces.
Definition: AVR.h:41
llvm::createAVRFrameAnalyzerPass
FunctionPass * createAVRFrameAnalyzerPass()
Creates instance of the frame analyzer pass.
Definition: AVRFrameLowering.cpp:476
N
#define N
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::createAVRShiftExpandPass
Pass * createAVRShiftExpandPass()
llvm::createAVRExpandPseudoPass
FunctionPass * createAVRExpandPseudoPass()
llvm::AVR::isProgramMemoryAccess
bool isProgramMemoryAccess(MemSDNode const *N)
Definition: AVR.h:73