LLVM 19.0.0git
Go to the documentation of this file.
1//===-- XCoreTargetObjectFile.cpp - XCore object files --------------------===//
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
10#include "XCoreSubtarget.h"
12#include "llvm/IR/DataLayout.h"
13#include "llvm/MC/MCContext.h"
17using namespace llvm;
26 BSSSectionLarge = Ctx.getELFSection(".dp.bss.large", ELF::SHT_NOBITS,
32 DataSectionLarge = Ctx.getELFSection(".dp.data.large", ELF::SHT_PROGBITS,
38 DataRelROSectionLarge = Ctx.getELFSection(
39 ".dp.rodata.large", ELF::SHT_PROGBITS,
42 Ctx.getELFSection(".cp.rodata", ELF::SHT_PROGBITS,
44 ReadOnlySectionLarge =
45 Ctx.getELFSection(".cp.rodata.large", ELF::SHT_PROGBITS,
48 ".cp.rodata.cst4", ELF::SHT_PROGBITS,
51 ".cp.rodata.cst8", ELF::SHT_PROGBITS,
54 ".cp.rodata.cst16", ELF::SHT_PROGBITS,
57 Ctx.getELFSection(".cp.rodata.string", ELF::SHT_PROGBITS,
60 // TextSection - see MObjectFileInfo.cpp
61 // StaticCtorSection - see MObjectFileInfo.cpp
62 // StaticDtorSection - see MObjectFileInfo.cpp
63 }
65static unsigned getXCoreSectionType(SectionKind K) {
66 if (K.isBSS())
67 return ELF::SHT_NOBITS;
68 return ELF::SHT_PROGBITS;
71static unsigned getXCoreSectionFlags(SectionKind K, bool IsCPRel) {
72 unsigned Flags = 0;
74 if (!K.isMetadata())
75 Flags |= ELF::SHF_ALLOC;
77 if (K.isText())
79 else if (IsCPRel)
81 else
84 if (K.isWriteable())
85 Flags |= ELF::SHF_WRITE;
87 if (K.isMergeableCString() || K.isMergeableConst4() ||
88 K.isMergeableConst8() || K.isMergeableConst16())
89 Flags |= ELF::SHF_MERGE;
91 if (K.isMergeableCString())
92 Flags |= ELF::SHF_STRINGS;
94 return Flags;
98 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
100 // Infer section flags from the section name if we can.
101 bool IsCPRel = SectionName.starts_with(".cp.");
102 if (IsCPRel && !Kind.isReadOnly())
103 report_fatal_error("Using .cp. section for writeable object.");
105 getXCoreSectionFlags(Kind, IsCPRel));
109 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
111 bool UseCPRel = GO->hasLocalLinkage();
113 if (Kind.isText()) return TextSection;
114 if (UseCPRel) {
115 if (Kind.isMergeable1ByteCString()) return CStringSection;
116 if (Kind.isMergeableConst4()) return MergeableConst4Section;
117 if (Kind.isMergeableConst8()) return MergeableConst8Section;
118 if (Kind.isMergeableConst16()) return MergeableConst16Section;
119 }
120 Type *ObjType = GO->getValueType();
121 auto &DL = GO->getParent()->getDataLayout();
122 if (TM.getCodeModel() == CodeModel::Small || !ObjType->isSized() ||
123 DL.getTypeAllocSize(ObjType) < CodeModelLargeSize) {
124 if (Kind.isReadOnly()) return UseCPRel? ReadOnlySection
126 if (Kind.isBSS() || Kind.isCommon())return BSSSection;
127 if (Kind.isData())
128 return DataSection;
129 if (Kind.isReadOnlyWithRel()) return DataRelROSection;
130 } else {
131 if (Kind.isReadOnly()) return UseCPRel? ReadOnlySectionLarge
132 : DataRelROSectionLarge;
133 if (Kind.isBSS() || Kind.isCommon())return BSSSectionLarge;
134 if (Kind.isData())
135 return DataSectionLarge;
136 if (Kind.isReadOnlyWithRel()) return DataRelROSectionLarge;
137 }
139 assert((Kind.isThreadLocal() || Kind.isCommon()) && "Unknown section kind");
140 report_fatal_error("Target does not support TLS or Common sections");
144 const DataLayout &DL, SectionKind Kind, const Constant *C,
145 Align &Alignment) const {
146 if (Kind.isMergeableConst4()) return MergeableConst4Section;
147 if (Kind.isMergeableConst8()) return MergeableConst8Section;
148 if (Kind.isMergeableConst16()) return MergeableConst16Section;
149 assert((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.
153 return ReadOnlySection;
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned getXCoreSectionType(SectionKind K)
static unsigned getXCoreSectionFlags(SectionKind K, bool IsCPRel)
This is an important base class in LLVM.
Definition: Constant.h:41
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:118
bool hasLocalLinkage() const
Definition: GlobalValue.h:527
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:655
Type * getValueType() const
Definition: GlobalValue.h:295
Context object for machine code objects.
Definition: MCContext.h:82
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:543
MCSection * MergeableConst16Section
MCSection * MergeableConst4Section
MCSection * TextSection
Section directive for standard text.
MCSection * MergeableConst8Section
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
MCSection * BSSSection
Section that is default initialized to zero.
MCContext & getContext() const
MCSection * DataSection
Section directive for standard data.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:35
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.h:293
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
CodeModel::Model getCodeModel() const
Returns the code model.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:302
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
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...
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.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
Definition: ELF.h:1067
Definition: ELF.h:1074
All sections with the "d" flag are grouped together by the linker to form the data section and the dp...
Definition: ELF.h:1210
Definition: ELF.h:1167
Definition: ELF.h:1170
All sections with the "c" flag are grouped together by the linker to form the constant pool and the c...
Definition: ELF.h:1215
Definition: ELF.h:1161
Definition: ELF.h:1158
Definition: ELF.h:1164
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
static const unsigned CodeModelLargeSize
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39