LLVM 20.0.0git
AVRTargetObjectFile.cpp
Go to the documentation of this file.
1//===-- AVRTargetObjectFile.cpp - AVR Object Files ------------------------===//
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
10#include "AVRTargetMachine.h"
11
13#include "llvm/IR/GlobalValue.h"
14#include "llvm/IR/Mangler.h"
15#include "llvm/MC/MCContext.h"
17
18#include "AVR.h"
19
20namespace llvm {
22 Base::Initialize(Ctx, TM);
23 ProgmemDataSection =
24 Ctx.getELFSection(".progmem.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
25 Progmem1DataSection =
26 Ctx.getELFSection(".progmem1.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
27 Progmem2DataSection =
28 Ctx.getELFSection(".progmem2.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
29 Progmem3DataSection =
30 Ctx.getELFSection(".progmem3.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
31 Progmem4DataSection =
32 Ctx.getELFSection(".progmem4.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
33 Progmem5DataSection =
34 Ctx.getELFSection(".progmem5.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
35}
36
38 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
39 // Global values in flash memory are placed in the progmem*.data section
40 // unless they already have a user assigned section.
41 const auto &AVRTM = static_cast<const AVRTargetMachine &>(TM);
42 if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection() &&
43 Kind.isReadOnly()) {
44 // The AVR subtarget should support LPM to access section '.progmem*.data'.
45 if (!AVRTM.getSubtargetImpl()->hasLPM()) {
46 // TODO: Get the global object's location in source file.
48 SMLoc(),
49 "Current AVR subtarget does not support accessing program memory");
50 return Base::SelectSectionForGlobal(GO, Kind, TM);
51 }
52 // The AVR subtarget should support ELPM to access section
53 // '.progmem[1|2|3|4|5].data'.
54 if (!AVRTM.getSubtargetImpl()->hasELPM() &&
56 // TODO: Get the global object's location in source file.
58 "Current AVR subtarget does not support "
59 "accessing extended program memory");
60 return ProgmemDataSection;
61 }
62 switch (AVR::getAddressSpace(GO)) {
63 case AVR::ProgramMemory: // address space 1
64 return ProgmemDataSection;
65 case AVR::ProgramMemory1: // address space 2
66 return Progmem1DataSection;
67 case AVR::ProgramMemory2: // address space 3
68 return Progmem2DataSection;
69 case AVR::ProgramMemory3: // address space 4
70 return Progmem3DataSection;
71 case AVR::ProgramMemory4: // address space 5
72 return Progmem4DataSection;
73 case AVR::ProgramMemory5: // address space 6
74 return Progmem5DataSection;
75 default:
76 llvm_unreachable("unexpected program memory index");
77 }
78 }
79
80 // Otherwise, we work the same way as ELF.
81 return Base::SelectSectionForGlobal(GO, Kind, TM);
82}
83} // end of namespace llvm
A generic AVR implementation.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
void Initialize(MCContext &ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:109
Context object for machine code objects.
Definition: MCContext.h:83
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:551
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1072
MCContext & getContext() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:36
Represents a location in source code.
Definition: SMLoc.h:23
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
AddressSpace getAddressSpace(T *V)
Definition: AVR.h:65
bool isProgramMemoryAddress(T *V)
Checks if a given type is a pointer to program memory.
Definition: AVR.h:54
@ ProgramMemory
Definition: AVR.h:44
@ ProgramMemory2
Definition: AVR.h:46
@ ProgramMemory4
Definition: AVR.h:48
@ ProgramMemory1
Definition: AVR.h:45
@ ProgramMemory5
Definition: AVR.h:49
@ ProgramMemory3
Definition: AVR.h:47
@ SHT_PROGBITS
Definition: ELF.h:1092
@ SHF_ALLOC
Definition: ELF.h:1190
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18