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