Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
XCoreTargetObjectFile.cpp
Go to the documentation of this file.
1//===-- XCoreTargetObjectFile.cpp - XCore 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 "XCoreTargetObjectFile.h"
10#include "XCoreSubtarget.h"
11#include "llvm/BinaryFormat/ELF.h"
12#include "llvm/IR/DataLayout.h"
13#include "llvm/MC/MCContext.h"
14#include "llvm/MC/MCSectionELF.h"
15#include "llvm/Target/TargetMachine.h"
16
17using namespacellvm;
18
19
20voidXCoreTargetObjectFile::Initialize(MCContext &Ctx,constTargetMachine &TM){
21TargetLoweringObjectFileELF::Initialize(Ctx,TM);
22
23BSSSection = Ctx.getELFSection(".dp.bss",ELF::SHT_NOBITS,
24ELF::SHF_ALLOC |ELF::SHF_WRITE |
25ELF::XCORE_SHF_DP_SECTION);
26 BSSSectionLarge = Ctx.getELFSection(".dp.bss.large",ELF::SHT_NOBITS,
27ELF::SHF_ALLOC |ELF::SHF_WRITE |
28ELF::XCORE_SHF_DP_SECTION);
29DataSection = Ctx.getELFSection(".dp.data",ELF::SHT_PROGBITS,
30ELF::SHF_ALLOC |ELF::SHF_WRITE |
31ELF::XCORE_SHF_DP_SECTION);
32 DataSectionLarge = Ctx.getELFSection(".dp.data.large",ELF::SHT_PROGBITS,
33ELF::SHF_ALLOC |ELF::SHF_WRITE |
34ELF::XCORE_SHF_DP_SECTION);
35DataRelROSection = Ctx.getELFSection(".dp.rodata",ELF::SHT_PROGBITS,
36ELF::SHF_ALLOC |ELF::SHF_WRITE |
37ELF::XCORE_SHF_DP_SECTION);
38 DataRelROSectionLarge = Ctx.getELFSection(
39".dp.rodata.large",ELF::SHT_PROGBITS,
40ELF::SHF_ALLOC |ELF::SHF_WRITE |ELF::XCORE_SHF_DP_SECTION);
41ReadOnlySection =
42 Ctx.getELFSection(".cp.rodata",ELF::SHT_PROGBITS,
43ELF::SHF_ALLOC |ELF::XCORE_SHF_CP_SECTION);
44 ReadOnlySectionLarge =
45 Ctx.getELFSection(".cp.rodata.large",ELF::SHT_PROGBITS,
46ELF::SHF_ALLOC |ELF::XCORE_SHF_CP_SECTION);
47MergeableConst4Section = Ctx.getELFSection(
48".cp.rodata.cst4",ELF::SHT_PROGBITS,
49ELF::SHF_ALLOC |ELF::SHF_MERGE |ELF::XCORE_SHF_CP_SECTION, 4);
50MergeableConst8Section = Ctx.getELFSection(
51".cp.rodata.cst8",ELF::SHT_PROGBITS,
52ELF::SHF_ALLOC |ELF::SHF_MERGE |ELF::XCORE_SHF_CP_SECTION, 8);
53MergeableConst16Section = Ctx.getELFSection(
54".cp.rodata.cst16",ELF::SHT_PROGBITS,
55ELF::SHF_ALLOC |ELF::SHF_MERGE |ELF::XCORE_SHF_CP_SECTION, 16);
56CStringSection =
57 Ctx.getELFSection(".cp.rodata.string",ELF::SHT_PROGBITS,
58ELF::SHF_ALLOC |ELF::SHF_MERGE |ELF::SHF_STRINGS |
59ELF::XCORE_SHF_CP_SECTION);
60// TextSection - see MObjectFileInfo.cpp
61// StaticCtorSection - see MObjectFileInfo.cpp
62// StaticDtorSection - see MObjectFileInfo.cpp
63 }
64
65staticunsignedgetXCoreSectionType(SectionKind K) {
66if (K.isBSS())
67returnELF::SHT_NOBITS;
68returnELF::SHT_PROGBITS;
69}
70
71staticunsignedgetXCoreSectionFlags(SectionKind K,bool IsCPRel) {
72unsigned Flags = 0;
73
74if (!K.isMetadata())
75 Flags |=ELF::SHF_ALLOC;
76
77if (K.isText())
78 Flags |=ELF::SHF_EXECINSTR;
79elseif (IsCPRel)
80 Flags |=ELF::XCORE_SHF_CP_SECTION;
81else
82 Flags |=ELF::XCORE_SHF_DP_SECTION;
83
84if (K.isWriteable())
85 Flags |=ELF::SHF_WRITE;
86
87if (K.isMergeableCString() || K.isMergeableConst4() ||
88 K.isMergeableConst8() || K.isMergeableConst16())
89 Flags |=ELF::SHF_MERGE;
90
91if (K.isMergeableCString())
92 Flags |=ELF::SHF_STRINGS;
93
94return Flags;
95}
96
97MCSection *XCoreTargetObjectFile::getExplicitSectionGlobal(
98constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
99StringRefSectionName = GO->getSection();
100// Infer section flags from the section name if we can.
101bool IsCPRel =SectionName.starts_with(".cp.");
102if (IsCPRel && !Kind.isReadOnly())
103report_fatal_error("Using .cp. section for writeable object.");
104returngetContext().getELFSection(SectionName,getXCoreSectionType(Kind),
105getXCoreSectionFlags(Kind, IsCPRel));
106}
107
108MCSection *XCoreTargetObjectFile::SelectSectionForGlobal(
109constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
110
111bool UseCPRel = GO->hasLocalLinkage();
112
113if (Kind.isText())returnTextSection;
114if (UseCPRel) {
115if (Kind.isMergeable1ByteCString())returnCStringSection;
116if (Kind.isMergeableConst4())returnMergeableConst4Section;
117if (Kind.isMergeableConst8())returnMergeableConst8Section;
118if (Kind.isMergeableConst16())returnMergeableConst16Section;
119 }
120Type *ObjType = GO->getValueType();
121auto &DL = GO->getDataLayout();
122if (TM.getCodeModel() ==CodeModel::Small || !ObjType->isSized() ||
123DL.getTypeAllocSize(ObjType) <CodeModelLargeSize) {
124if (Kind.isReadOnly())return UseCPRel?ReadOnlySection
125 :DataRelROSection;
126if (Kind.isBSS() || Kind.isCommon())returnBSSSection;
127if (Kind.isData())
128returnDataSection;
129if (Kind.isReadOnlyWithRel())returnDataRelROSection;
130 }else {
131if (Kind.isReadOnly())return UseCPRel? ReadOnlySectionLarge
132 : DataRelROSectionLarge;
133if (Kind.isBSS() || Kind.isCommon())return BSSSectionLarge;
134if (Kind.isData())
135return DataSectionLarge;
136if (Kind.isReadOnlyWithRel())return DataRelROSectionLarge;
137 }
138
139assert((Kind.isThreadLocal() || Kind.isCommon()) &&"Unknown section kind");
140report_fatal_error("Target does not support TLS or Common sections");
141}
142
143MCSection *XCoreTargetObjectFile::getSectionForConstant(
144constDataLayout &DL,SectionKind Kind,constConstant *C,
145Align &Alignment) const{
146if (Kind.isMergeableConst4())returnMergeableConst4Section;
147if (Kind.isMergeableConst8())returnMergeableConst8Section;
148if (Kind.isMergeableConst16())returnMergeableConst16Section;
149assert((Kind.isReadOnly() || Kind.isReadOnlyWithRel()) &&
150"Unknown section kind");
151// We assume the size of the object is never greater than CodeModelLargeSize.
152// To handle CodeModelLargeSize changes to AsmPrinter would be required.
153returnReadOnlySection;
154}
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
ELF.h
DataLayout.h
MCContext.h
MCSectionELF.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
XCoreSubtarget.h
getXCoreSectionType
static unsigned getXCoreSectionType(SectionKind K)
Definition:XCoreTargetObjectFile.cpp:65
getXCoreSectionFlags
static unsigned getXCoreSectionFlags(SectionKind K, bool IsCPRel)
Definition:XCoreTargetObjectFile.cpp:71
XCoreTargetObjectFile.h
llvm::Constant
This is an important base class in LLVM.
Definition:Constant.h:42
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition:DataLayout.h:63
llvm::GlobalObject
Definition:GlobalObject.h:27
llvm::GlobalObject::getSection
StringRef getSection() const
Get the custom section of this global if it has one.
Definition:GlobalObject.h:117
llvm::GlobalValue::hasLocalLinkage
bool hasLocalLinkage() const
Definition:GlobalValue.h:529
llvm::GlobalValue::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition:Globals.cpp:130
llvm::GlobalValue::getValueType
Type * getValueType() const
Definition:GlobalValue.h:297
llvm::MCContext
Context object for machine code objects.
Definition:MCContext.h:83
llvm::MCContext::getELFSection
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition:MCContext.h:551
llvm::MCObjectFileInfo::MergeableConst16Section
MCSection * MergeableConst16Section
Definition:MCObjectFileInfo.h:190
llvm::MCObjectFileInfo::MergeableConst4Section
MCSection * MergeableConst4Section
Definition:MCObjectFileInfo.h:188
llvm::MCObjectFileInfo::TextSection
MCSection * TextSection
Section directive for standard text.
Definition:MCObjectFileInfo.h:53
llvm::MCObjectFileInfo::MergeableConst8Section
MCSection * MergeableConst8Section
Definition:MCObjectFileInfo.h:189
llvm::MCObjectFileInfo::DataRelROSection
MCSection * DataRelROSection
Definition:MCObjectFileInfo.h:187
llvm::MCObjectFileInfo::CStringSection
MCSection * CStringSection
Definition:MCObjectFileInfo.h:205
llvm::MCObjectFileInfo::ReadOnlySection
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
Definition:MCObjectFileInfo.h:65
llvm::MCObjectFileInfo::BSSSection
MCSection * BSSSection
Section that is default initialized to zero.
Definition:MCObjectFileInfo.h:59
llvm::MCObjectFileInfo::getContext
MCContext & getContext() const
Definition:MCObjectFileInfo.h:252
llvm::MCObjectFileInfo::DataSection
MCSection * DataSection
Section directive for standard data.
Definition:MCObjectFileInfo.h:56
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition:MCSection.h:36
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition:SectionKind.h:22
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
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:121
llvm::TargetLoweringObjectFile::TM
const TargetMachine * TM
Definition:TargetLoweringObjectFile.h:68
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition:TargetMachine.h:77
llvm::TargetMachine::getCodeModel
CodeModel::Model getCodeModel() const
Returns the code model.
Definition:TargetMachine.h:232
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::Type::isSized
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition:Type.h:310
llvm::XCoreTargetObjectFile::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition:XCoreTargetObjectFile.cpp:20
llvm::XCoreTargetObjectFile::getExplicitSectionGlobal
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
Definition:XCoreTargetObjectFile.cpp:97
llvm::XCoreTargetObjectFile::getSectionForConstant
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
Definition:XCoreTargetObjectFile.cpp:143
llvm::XCoreTargetObjectFile::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition:XCoreTargetObjectFile.cpp:108
TargetMachine.h
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::CodeModel::Small
@ Small
Definition:CodeGen.h:31
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition:ELF.h:1098
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition:ELF.h:1105
llvm::ELF::XCORE_SHF_DP_SECTION
@ XCORE_SHF_DP_SECTION
All sections with the "d" flag are grouped together by the linker to form the data section and the dp...
Definition:ELF.h:1247
llvm::ELF::SHF_MERGE
@ SHF_MERGE
Definition:ELF.h:1204
llvm::ELF::SHF_STRINGS
@ SHF_STRINGS
Definition:ELF.h:1207
llvm::ELF::XCORE_SHF_CP_SECTION
@ XCORE_SHF_CP_SECTION
All sections with the "c" flag are grouped together by the linker to form the constant pool and the c...
Definition:ELF.h:1252
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition:ELF.h:1198
llvm::ELF::SHF_WRITE
@ SHF_WRITE
Definition:ELF.h:1195
llvm::ELF::SHF_EXECINSTR
@ SHF_EXECINSTR
Definition:ELF.h:1201
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::CodeModelLargeSize
static const unsigned CodeModelLargeSize
Definition:XCoreTargetObjectFile.h:16
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::SectionName
Definition:DWARFSection.h:21

Generated on Fri Jul 18 2025 15:09:56 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp