LLVM  13.0.0git
RISCVTargetObjectFile.cpp
Go to the documentation of this file.
1 //===-- RISCVTargetObjectFile.cpp - RISCV Object Info -----------------===//
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 "RISCVTargetMachine.h"
11 #include "llvm/BinaryFormat/ELF.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCSectionELF.h"
14 
15 using namespace llvm;
16 
18  const TargetMachine &TM) {
20 
21  SmallDataSection = getContext().getELFSection(
23  SmallBSSSection = getContext().getELFSection(".sbss", ELF::SHT_NOBITS,
25 }
26 
27 // A address must be loaded from a small section if its size is less than the
28 // small section size threshold. Data in this section could be addressed by
29 // using gp_rel operator.
31  // gcc has traditionally not treated zero-sized objects as small data, so this
32  // is effectively part of the ABI.
33  return Size > 0 && Size <= SSThreshold;
34 }
35 
36 // Return true if this global address should be placed into small data/bss
37 // section.
39  const GlobalObject *GO, const TargetMachine &TM) const {
40  // Only global variables, not functions.
41  const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GO);
42  if (!GVA)
43  return false;
44 
45  // If the variable has an explicit section, it is placed in that section.
46  if (GVA->hasSection()) {
47  StringRef Section = GVA->getSection();
48 
49  // Explicitly placing any variable in the small data section overrides
50  // the global -G value.
51  if (Section == ".sdata" || Section == ".sbss")
52  return true;
53 
54  // Otherwise reject putting the variable to small section if it has an
55  // explicit section name.
56  return false;
57  }
58 
59  if (((GVA->hasExternalLinkage() && GVA->isDeclaration()) ||
60  GVA->hasCommonLinkage()))
61  return false;
62 
63  Type *Ty = GVA->getValueType();
64  // It is possible that the type of the global is unsized, i.e. a declaration
65  // of a extern struct. In this case don't presume it is in the small data
66  // section. This happens e.g. when building the FreeBSD kernel.
67  if (!Ty->isSized())
68  return false;
69 
70  return isInSmallSection(
72 }
73 
75  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
76  // Handle Small Section classification here.
77  if (Kind.isBSS() && isGlobalInSmallSection(GO, TM))
78  return SmallBSSSection;
79  if (Kind.isData() && isGlobalInSmallSection(GO, TM))
80  return SmallDataSection;
81 
82  // Otherwise, we work the same as ELF.
84 }
85 
89  M.getModuleFlagsMetadata(ModuleFlags);
90 
91  for (const auto &MFE : ModuleFlags) {
92  StringRef Key = MFE.Key->getString();
93  if (Key == "SmallDataLimit") {
94  SSThreshold = mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue();
95  break;
96  }
97  }
98 }
99 
100 /// Return true if this constant should be placed into small data section.
102  const DataLayout &DL, const Constant *CN) const {
103  return isInSmallSection(DL.getTypeAllocSize(CN->getType()));
104 }
105 
107  const DataLayout &DL, SectionKind Kind, const Constant *C,
108  Align &Alignment) const {
110  return SmallDataSection;
111 
112  // Otherwise, we work the same as ELF.
114  Alignment);
115 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::EngineKind::Kind
Kind
Definition: ExecutionEngine.h:524
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:272
llvm
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::SystemZISD::TM
@ TM
Definition: SystemZISelLowering.h:65
llvm::GlobalValue::hasCommonLinkage
bool hasCommonLinkage() const
Definition: GlobalValue.h:449
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::TargetLoweringObjectFileELF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:839
llvm::GlobalValue::hasExternalLinkage
bool hasExternalLinkage() const
Definition: GlobalValue.h:431
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:71
llvm::RISCVELFTargetObjectFile::getModuleMetadata
void getModuleMetadata(Module &M) override
Get the module-level metadata that the platform cares about.
Definition: RISCVTargetObjectFile.cpp:86
llvm::RISCVELFTargetObjectFile::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition: RISCVTargetObjectFile.cpp:17
llvm::GlobalObject::getSection
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:114
MCSectionELF.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:981
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:903
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::RISCVELFTargetObjectFile::isGlobalInSmallSection
bool isGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM) const
Return true if this global address should be placed into small data/bss section.
Definition: RISCVTargetObjectFile.cpp:38
llvm::MCObjectFileInfo::getContext
MCContext & getContext() const
Definition: MCObjectFileInfo.h:232
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
ELF.h
llvm::GlobalValue::isDeclaration
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:228
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::GlobalObject
Definition: GlobalObject.h:30
MCContext.h
RISCVTargetObjectFile.h
llvm::MCContext::getELFSection
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:521
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::TargetLoweringObjectFileELF::getModuleMetadata
void getModuleMetadata(Module &M) override
Get the module-level metadata that the platform cares about.
Definition: TargetLoweringObjectFileImpl.cpp:296
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition: ELF.h:910
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::TargetLoweringObjectFile::TM
const TargetMachine * TM
Definition: TargetLoweringObjectFile.h:66
llvm::GlobalObject::hasSection
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:106
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::RISCVELFTargetObjectFile::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: RISCVTargetObjectFile.cpp:74
llvm::RISCVELFTargetObjectFile::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: RISCVTargetObjectFile.cpp:106
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:572
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::TargetLoweringObjectFileELF::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: TargetLoweringObjectFileImpl.cpp:924
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::ELF::SHF_WRITE
@ SHF_WRITE
Definition: ELF.h:978
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:114
llvm::Module::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:397
llvm::GlobalValue::getValueType
Type * getValueType() const
Definition: GlobalValue.h:273
llvm::RISCVELFTargetObjectFile::isInSmallSection
bool isInSmallSection(uint64_t Size) const
Definition: RISCVTargetObjectFile.cpp:30
llvm::RISCVELFTargetObjectFile::isConstantInSmallSection
bool isConstantInSmallSection(const DataLayout &DL, const Constant *CN) const
Return true if this constant should be placed into small data section.
Definition: RISCVTargetObjectFile.cpp:101
llvm::DataLayout::getTypeAllocSize
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:498
RISCVTargetMachine.h