LLVM: lib/Target/TargetLoweringObjectFile.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
31using namespace llvm;
32
33
34
35
36
37
38
39
42
43 delete Mang;
47
48
51
52 this->TM = &TM;
53}
54
56 delete Mang;
57}
58
60
61
62
63 if (().getAsmInfo()->hasLEB128Directives())
66}
67
69
70 if (C->isNullValue() || isa(C))
71 return true;
72 if (!isa(C))
73 return false;
74 for (const auto *Operand : C->operand_values()) {
76 return false;
77 }
78 return true;
79}
80
83
84
86 return false;
87
88
90 return false;
91
92
94 return false;
95
96
97 return true;
98}
99
100
101
102
103
105
107 unsigned NumElts = CDS->getNumElements();
108 assert(NumElts != 0 && "Can't have an empty CDS");
109
110 if (CDS->getElementAsInteger(NumElts-1) != 0)
111 return false;
112
113
114 for (unsigned i = 0; i != NumElts-1; ++i)
115 if (CDS->getElementAsInteger(i) == 0)
116 return false;
117 return true;
118 }
119
120
121 if (isa(C))
122 return cast(C->getType())->getNumElements() == 1;
123
124 return false;
125}
126
130
136}
137
142}
143
147
152 M.getModuleFlagsMetadata(ModuleFlags);
153
154 MDNode *CFGProfile = nullptr;
155
156 for (const auto &MFE : ModuleFlags) {
157 StringRef Key = MFE.Key->getString();
158 if (Key == "CG Profile") {
159 CFGProfile = cast(MFE.Val);
160 break;
161 }
162 }
163
164 if (!CFGProfile)
165 return;
166
168 if (!MDO)
169 return nullptr;
170 auto *V = cast(MDO);
171 const Function *F = cast(V->getValue()->stripPointerCasts());
172 if (F->hasDLLImportStorageClass())
173 return nullptr;
175 };
176
177 for (const auto &Edge : CFGProfile->operands()) {
178 MDNode *E = cast(Edge);
181
182
183 if ( || !To)
184 continue;
186 ->getValue()
187 ->getUniqueInteger()
188 .getZExtValue();
192 }
193}
194
195
196
197
198
202 "Can only be used for global definitions");
203
204
205 if (isa(GO))
207
208
209 if (isa(GO))
211
212
213 const auto *GVar = cast(GO);
214
215
216 if (GVar->isThreadLocal()) {
218
219
220 if (GVar->hasLocalLinkage()) {
222 }
224 }
226 }
227
228
229 if (GVar->hasCommonLinkage())
231
232
233
235 if (GVar->hasLocalLinkage())
237 else if (GVar->hasExternalLinkage())
240 }
241
242
243
244 if (GVar->hasSection())
245 if (MDNode *MD = GVar->getMetadata(LLVMContext::MD_exclude))
246 if (!MD->getNumOperands())
248
249
250
251 if (GVar->isConstant()) {
252
253
254
255 const Constant *C = GVar->getInitializer();
256 if (->needsRelocation()) {
257
258
259
260 if (!GVar->hasGlobalUnnamedAddr())
262
263
264
265 if (ArrayType *ATy = dyn_cast(C->getType())) {
267 dyn_cast(ATy->getElementType())) {
268 if ((ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16 ||
269 ITy->getBitWidth() == 32) &&
271 if (ITy->getBitWidth() == 8)
273 if (ITy->getBitWidth() == 16)
275
276 assert(ITy->getBitWidth() == 32 && "Unknown width");
278 }
279 }
280 }
281
282
283
284
285 switch (
286 GVar->getDataLayout().getTypeAllocSize(C->getType())) {
291 default:
293 }
294
295 } else {
296
297
298
299
300
304 ->needsDynamicRelocation())
306
307
308
310 }
311 }
312
313
315}
316
317
318
319
322
325
326 if (auto *GVar = dyn_cast(GO)) {
327 auto Attrs = GVar->getAttributes();
328 if ((Attrs.hasAttribute("bss-section") && Kind.isBSS()) ||
329 (Attrs.hasAttribute("data-section") && Kind.isData()) ||
330 (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel()) ||
331 (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())) {
333 }
334 }
335
336
338}
339
340
341
342
347}
348
351 Align Alignment(1);
354 Alignment);
355}
356
358 bool UsesLabelDifference, const Function &F) const {
359
360
361
362 if (UsesLabelDifference)
363 return true;
364
365
366
367
368
369 return F.isWeakForLinker();
370}
371
372
373
376 Align &Alignment) const {
379
381}
382
386 return nullptr;
387}
388
391 return nullptr;
392}
393
394
395
396
402
404}
405
409 switch (Encoding & 0x70) {
410 default:
413
414 return Sym;
416
417
422 }
423 }
424}
425
427
428
430}
431
435 Mang->getNameWithPrefix(OutName, GV, false);
436}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
BlockVerifier::State From
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isNullOrUndef(const Constant *C)
static bool IsNullTerminatedString(const Constant *C)
IsNullTerminatedString - Return true if the specified constant (which is known to have a type that is...
static bool isSuitableForBSS(const GlobalVariable *GV)
Class to represent array types.
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
StringRef getPrivateGlobalPrefix() const
bool hasSection() const
Check if this global has a custom object file section.
bool isDeclarationForLinker() const
const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
Class to represent integer types.
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Context object for machine code objects.
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Base class for the full range of assembler expressions which are needed for parsing.
void initMCObjectFileInfo(MCContext &MCCtx, bool PIC, bool LargeCodeModel=false)
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
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.
Streaming machine code generation interface.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
virtual void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count)
Represent a reference to a symbol from inside an expression.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
const MDOperand & getOperand(unsigned I) const
ArrayRef< MDOperand > operands() const
Tracking metadata reference owned by Metadata.
This class contains meta information specific to a module.
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
A Module instance is used to store all the information related to an LLVM module.
SectionKind - This is a simple POD value that classifies the properties of a section.
static SectionKind getThreadData()
static SectionKind getBSSExtern()
static SectionKind getMergeable2ByteCString()
static SectionKind getExclude()
static SectionKind getBSSLocal()
static SectionKind getMergeableConst4()
static SectionKind getCommon()
static SectionKind getText()
static SectionKind getThreadBSSLocal()
static SectionKind getReadOnlyWithRel()
static SectionKind getData()
static SectionKind getMergeableConst8()
static SectionKind getBSS()
static SectionKind getThreadBSS()
static SectionKind getMergeableConst16()
static SectionKind getMergeable4ByteCString()
static SectionKind getMergeable1ByteCString()
static SectionKind getReadOnly()
static SectionKind getMergeableConst32()
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
void emitCGProfileMetadata(MCStreamer &Streamer, Module &M) const
Emit Call Graph Profile metadata.
virtual void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const
unsigned PersonalityEncoding
PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values for EH.
unsigned getCallSiteEncoding() const
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
virtual MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const
virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const
virtual MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
virtual MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const =0
virtual MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const
Given a constant with the SectionKind, return a section that it should be placed in.
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
virtual MCSection * getSectionForMachineBasicBlock(const Function &F, const MachineBasicBlock &MBB, const TargetMachine &TM) const
virtual ~TargetLoweringObjectFile()
virtual const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const
Create a symbol reference to describe the given TLS variable when emitting the address in debug info.
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const
Return an MCExpr to use for a reference to the specified global variable from exception handling info...
unsigned CallSiteEncoding
virtual MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const =0
Targets should implement this method to assign a section to globals with an explicit section specfied...
const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const
virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM, const MCSymbol *Sym, const MachineModuleInfo *MMI) const
virtual MCSection * getUniqueSectionForFunction(const Function &F, const TargetMachine &TM) const
MCSection * SectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
Primary interface to the complete machine description for the target machine.
bool isPositionIndependent() const
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
MCSymbol * getSymbol(const GlobalValue *GV) const
CodeModel::Model getCodeModel() const
Returns the code model.
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV, Mangler &Mang, bool MayAlwaysUsePrivate=false) const
unsigned NoZerosInBSS
NoZerosInBSS - By default some codegens place zero-initialized data to .bss section.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
@ Ref
The access may reference the value stored in memory.
This struct is a compact representation of a valid (non-zero power of two) alignment.