brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 68ec927 Raw
100 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file contains the entry points for global functions defined in the LLVM10// AVR back-end.11//12//===----------------------------------------------------------------------===//13 14#ifndef LLVM_AVR_H15#define LLVM_AVR_H16 17#include "llvm/CodeGen/SelectionDAGNodes.h"18#include "llvm/Pass.h"19#include "llvm/PassRegistry.h"20#include "llvm/Target/TargetMachine.h"21 22namespace llvm {23 24class AVRTargetMachine;25class FunctionPass;26class PassRegistry;27 28Pass *createAVRShiftExpandPass();29FunctionPass *createAVRISelDag(AVRTargetMachine &TM, CodeGenOptLevel OptLevel);30FunctionPass *createAVRExpandPseudoPass();31FunctionPass *createAVRFrameAnalyzerPass();32FunctionPass *createAVRBranchSelectionPass();33 34void initializeAVRAsmPrinterPass(PassRegistry &);35void initializeAVRDAGToDAGISelLegacyPass(PassRegistry &);36void initializeAVRExpandPseudoPass(PassRegistry &);37void initializeAVRShiftExpandPass(PassRegistry &);38 39/// Contains the AVR backend.40namespace AVR {41 42/// An integer that identifies all of the supported AVR address spaces.43enum AddressSpace {44  DataMemory,45  ProgramMemory,46  ProgramMemory1,47  ProgramMemory2,48  ProgramMemory3,49  ProgramMemory4,50  ProgramMemory5,51  NumAddrSpaces,52};53 54/// Checks if a given type is a pointer to program memory.55template <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 66template <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 75inline 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 memory84//   0: ordinary program memory85// 1~5: extended program memory86inline int getProgramMemoryBank(MemSDNode const *N) {87  auto *V = N->getMemOperand()->getValue();88  if (V == nullptr || !isProgramMemoryAddress(V))89    return -1;90  AddressSpace AS = getAddressSpace(V);91  assert(ProgramMemory <= AS && AS <= ProgramMemory5);92  return static_cast<int>(AS - ProgramMemory);93}94 95} // end of namespace AVR96 97} // end namespace llvm98 99#endif // LLVM_AVR_H100