1//===-- TargetMachine.cpp - General Target Information ---------------------==// 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 7//===----------------------------------------------------------------------===// 9// This file describes the general parts of a Target machine. 11//===----------------------------------------------------------------------===// 29//--------------------------------------------------------------------------- 36 : TheTarget(
T),
DL(DataLayoutString), TargetTriple(TT),
38MRI(nullptr), MII(nullptr), STI(nullptr), RequireStructuredCFG(
false),
47// Remaining logic below is ELF-specific. For other object file formats where 48// the large code model is mostly used for JIT compilation, just look at the 55// Be conservative if we can't find an underlying GlobalObject. 59auto *GV = dyn_cast<GlobalVariable>(GO);
62returnName.consume_front(Prefix) && (
Name.empty() ||
Name[0] ==
'.');
65// Functions/GlobalIFuncs are only large under the large code model. 67// Handle explicit sections as we do for GlobalVariables with an explicit 68// section, see comments below. 69if (GO->hasSection()) {
71return IsPrefix(
Name,
".ltext");
76if (GV->isThreadLocal())
79// For x86-64, we treat an explicit GlobalVariable small code model to mean 80// that the global should be placed in a small section, and ditto for large. 81if (
auto CM = GV->getCodeModel()) {
88// Treat all globals in explicit sections as small, except for the standard 89// large sections of .lbss, .ldata, .lrodata. This reduces the risk of linking 90// together small and large sections, resulting in small references to large 91// data sections. The code model attribute overrides this above. 92if (GV->hasSection()) {
94return IsPrefix(
Name,
".lbss") || IsPrefix(
Name,
".ldata") ||
95 IsPrefix(
Name,
".lrodata");
98// Respect large data threshold for medium and large code models. 101if (!GV->getValueType()->isSized())
103// Linker defined start/stop symbols can point to arbitrary points in the 104// binary, so treat them as large. 105if (GV->isDeclaration() && (GV->getName() ==
"__ehdr_start" ||
106 GV->getName().starts_with(
"__start_") ||
107 GV->getName().starts_with(
"__stop_")))
121/// Reset the target options based on the function's attributes. 122/// setFunctionAttributes should have made the raw attribute value consistent 123/// with the command line flag if used. 125// FIXME: This function needs to go away for a number of reasons: 126// a) global state on the TargetMachine is terrible in general, 127// b) these target options should be passed only on the function 128// and not on the TargetMachine (via TargetOptions) at all. 130#define RESET_OPTION(X, Y) \ 132 Options.X = F.getFnAttribute(Y).getValueAsBool(); \ 138RESET_OPTION(NoSignedZerosFPMath,
"no-signed-zeros-fp-math");
142/// Returns the code generation relocation model. The choices are static, PIC, 143/// and dynamic-no-pic. 160/// Get the IR-specified TLS model for Var. 182// According to the llvm language reference, we should be able to 183// just return false in here if we have a GV, as we know it is 184// dso_preemptable. At this point in time, the various IR producers 185// have not been transitioned to always produce a dso_local when it 186// is possible to do so. 188// As a result we still have some logic in here to improve the quality of the 193// If the IR producer requested that this GV be treated as dso local, obey. 197if (TT.isOSBinFormatCOFF()) {
198// DLLImport explicitly marks the GV as external. 202// On MinGW, variables that haven't been declared with DLLImport may still 203// end up automatically imported by the linker. To make this feasible, 204// don't assume the variables to be DSO local unless we actually know 205// that for sure. This only has to be done for variables; for functions 206// the linker can insert thunks for calling functions from another DLL. 208 isa<GlobalVariable>(GV))
211// Don't mark 'extern_weak' symbols as DSO local. If these symbols remain 212// unresolved in the link, they can be resolved to zero, which is outside 217// Every other GV is local on COFF. 221if (TT.isOSBinFormatGOFF())
224if (TT.isOSBinFormatMachO()) {
230assert(TT.isOSBinFormatELF() || TT.isOSBinFormatWasm() ||
231 TT.isOSBinFormatXCOFF());
245if (IsSharedLibrary) {
257// If the user specified a more specific model, use that. 259if (SelectedModel > Model)
272bool MayAlwaysUsePrivate)
const{
274// Simple case: If GV is not private, it is not important to find out if 275// private labels are legal in this case or not. 285// XCOFF symbols could have special naming convention. 295// Since Analysis can't depend on Target, use a std::function to invert the 303return {INT_MAX, INT_MAX};
// Make binutilsIsAtLeast() return true. 304 std::pair<int, int> Ret;
305if (!
Version.consumeInteger(10, Ret.first) &&
Version.consume_front(
"."))
306Version.consumeInteger(10, Ret.second);
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static TLSModel::Model getSelectedTLSModel(const GlobalValue *GV)
Get the IR-specified TLS model for Var.
#define RESET_OPTION(X, Y)
This pass exposes codegen information to IR-level passes.
A parsed version of the target data layout string in and methods for querying it.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
bool hasPrivateLinkage() const
bool hasExternalWeakLinkage() const
ThreadLocalMode getThreadLocalMode() const
bool hasDLLImportStorageClass() const
bool isDeclarationForLinker() const
Module * getParent()
Get the module that this global value is contained inside of...
const GlobalObject * getAliaseeObject() const
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
MCContext & getContext() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Analysis pass providing the TargetTransformInfo.
virtual void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const
Mangler & getMangler() const
virtual MCSymbol * getTargetSymbol(const GlobalValue *GV, const TargetMachine &TM) const
Targets that have a special convention for their symbols could use this hook to return a specialized ...
TLSModel::Model getTLSModel(const GlobalValue *GV) const
Returns the TLS model which should be used for the given global variable.
bool isPositionIndependent() const
uint64_t getMaxCodeSize() const
Returns the maximum code size possible under the code model.
const Triple & getTargetTriple() const
bool useTLSDESC() const
Returns true if this target uses TLS Descriptors.
uint64_t LargeDataThreshold
bool useEmulatedTLS() const
Returns true if this target uses emulated TLS.
virtual TargetLoweringObjectFile * getObjFileLowering() const
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
virtual TargetTransformInfo getTargetTransformInfo(const Function &F) const
Return a TargetTransformInfo for a given function.
const DataLayout DL
DataLayout for the target: keep ABI type size and alignment.
bool shouldAssumeDSOLocal(const GlobalValue *GV) const
static std::pair< int, int > parseBinutilsVersion(StringRef Version)
TargetIRAnalysis getTargetIRAnalysis() const
Get a TargetIRAnalysis appropriate for the target.
MCSymbol * getSymbol(const GlobalValue *GV) const
CodeModel::Model getCodeModel() const
Returns the code model.
bool isLargeGlobalValue(const GlobalValue *GV) const
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
TargetMachine(const Target &T, StringRef DataLayoutString, const Triple &TargetTriple, StringRef CPU, StringRef FS, const TargetOptions &Options)
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV, Mangler &Mang, bool MayAlwaysUsePrivate=false) const
unsigned EnableTLSDESC
EnableTLSDESC - This flag enables TLS Descriptors.
unsigned EmulatedTLS
EmulatedTLS - This flag enables emulated TLS model, using emutls function in the runtime library.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
uint64_t maxUIntN(uint64_t N)
Gets the maximum value for a N-bit unsigned integer.
Implement std::hash so that hash_code can be used in STL containers.