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

58

60

61

62

63 if (getContext().getAsmInfo()->hasLEB128Directives())

66}

67

69

71 return true;

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 uint64_t 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 (uint64_t i = 0; i != NumElts - 1; ++i)

115 if (CDS->getElementAsInteger(i) == 0)

116 return false;

117 return true;

118 }

119

120

123

124 return false;

125}

126

130

133 TM.getNameWithPrefix(NameStr, GV, *Mang);

136}

137

141 return TM.getSymbol(GV);

142}

143

147

152 M.getModuleFlagsMetadata(ModuleFlags);

153

154 MDNode *CGProfile = nullptr;

155

156 for (const auto &MFE : ModuleFlags) {

158 if (Key == "CG Profile") {

160 break;

161 }

162 }

163

164 if (!CGProfile)

165 return;

166

168 if (!MDO)

169 return nullptr;

172 if (F->hasDLLImportStorageClass())

173 return nullptr;

174 return TM->getSymbol(F);

175 };

176

177 for (const auto &Edge : CGProfile->operands()) {

179 const MCSymbol *From = GetSym(E->getOperand(0));

180 const MCSymbol *To = GetSym(E->getOperand(1));

181

182

183 if (!From || !To)

184 continue;

186 ->getValue()

187 ->getUniqueInteger()

188 .getZExtValue();

191 }

192}

193

196 std::function<void(MCStreamer &Streamer)> COMDATSymEmitter) const {

198 if (!FuncInfo)

199 return;

200

201

202

203

204

205

206

208 for (const auto *Operand : FuncInfo->operands()) {

213 auto *S = C.getObjectFileInfo()->getPseudoProbeDescSection(

214 TM->getFunctionSections() ? Name->getString() : StringRef());

215

217

218

219 if (COMDATSymEmitter)

220 COMDATSymEmitter(Streamer);

221

222 Streamer.emitInt64(GUID->getZExtValue());

223 Streamer.emitInt64(Hash->getZExtValue());

225 Streamer.emitBytes(Name->getString());

226 }

227}

228

229

230

231

232

236 "Can only be used for global definitions");

237

238

241

242

245

246

248

249

250 if (GVar->isThreadLocal()) {

252

253

254 if (GVar->hasLocalLinkage()) {

256 }

258 }

260 }

261

262

263 if (GVar->hasCommonLinkage())

265

266

267

269 if (GVar->hasLocalLinkage())

271 else if (GVar->hasExternalLinkage())

274 }

275

276

277

278 if (GVar->hasSection())

279 if (MDNode *MD = GVar->getMetadata(LLVMContext::MD_exclude))

280 if (!MD->getNumOperands())

282

283

284

285 if (GVar->isConstant()) {

286

287

288

289 const Constant *C = GVar->getInitializer();

290 if (C->needsRelocation()) {

291

292

293

294 if (!GVar->hasGlobalUnnamedAddr())

296

297

298

302 if ((ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16 ||

303 ITy->getBitWidth() == 32) &&

305 if (ITy->getBitWidth() == 8)

307 if (ITy->getBitWidth() == 16)

309

310 assert(ITy->getBitWidth() == 32 && "Unknown width");

312 }

313 }

314 }

315

316

317

318

319 switch (

320 GVar->getDataLayout().getTypeAllocSize(C->getType())) {

325 default:

327 }

328

329 } else {

330

331

332

333

334

338 C->needsDynamicRelocation())

340

341

342

344 }

345 }

346

347

349}

350

351

352

353

356

359

361 auto Attrs = GVar->getAttributes();

362 if ((Attrs.hasAttribute("bss-section") && Kind.isBSS()) ||

363 (Attrs.hasAttribute("data-section") && Kind.isData()) ||

364 (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel()) ||

365 (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())) {

367 }

368 }

369

370

372}

373

374

375

376

382

387

391 Align Alignment(1);

394 Alignment);

395}

396

398 bool UsesLabelDifference, const Function &F) const {

399

400

401

402 if (UsesLabelDifference)

403 return true;

404

405

406

407

408

409 return F.isWeakForLinker();

410}

411

412

413

416 Align &Alignment) const {

419

421}

422

426

427

428 if (SectionPrefix.empty())

431 "TargetLoweringObjectFile::getSectionForConstant that "

432 "accepts SectionPrefix is not implemented for the object file format");

433}

434

440

445

446

447

448

457

461 switch (Encoding & 0x70) {

462 default:

465

466 return Sym;

468

469

474 }

475 }

476}

477

483

487 Mang->getNameWithPrefix(OutName, GV, false);

488}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

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.

static bool isNullOrUndef(const Constant *C)

Definition TargetLoweringObjectFile.cpp:68

static bool IsNullTerminatedString(const Constant *C)

IsNullTerminatedString - Return true if the specified constant (which is known to have a type that is...

Definition TargetLoweringObjectFile.cpp:104

static bool isSuitableForBSS(const GlobalVariable *GV)

Definition TargetLoweringObjectFile.cpp:81

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

LLVM_ABI 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.

LLVM_ABI MCSymbol * createTempSymbol()

Create a temporary symbol with a unique name.

LLVM_ABI 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)

unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)

Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...

void emitInt64(uint64_t Value)

virtual void switchSection(MCSection *Section, uint32_t Subsec=0)

Set the current section where code is being emitted to Section.

virtual void emitBytes(StringRef Data)

Emit the bytes in Data into the output.

Represent a reference to a symbol from inside an expression.

static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())

MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...

ArrayRef< MDOperand > operands() const

Tracking metadata reference owned by Metadata.

This class contains meta information specific to a module.

A Module instance is used to store all the information related to an LLVM module.

iterator_range< op_iterator > operands()

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.

Definition TargetLoweringObjectFile.cpp:148

virtual void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const

Definition TargetLoweringObjectFile.cpp:484

unsigned PersonalityEncoding

PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values for EH.

unsigned getCallSiteEncoding() const

Definition TargetLoweringObjectFile.cpp:59

static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)

Classify the specified global variable into a set of target independent categories embodied in Sectio...

Definition TargetLoweringObjectFile.cpp:233

virtual MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const

Definition TargetLoweringObjectFile.cpp:383

virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const

Definition TargetLoweringObjectFile.cpp:397

virtual MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const

Definition TargetLoweringObjectFile.cpp:138

virtual void Initialize(MCContext &ctx, const TargetMachine &TM)

This method must be called before any actual lowering is done.

Definition TargetLoweringObjectFile.cpp:40

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.

Definition TargetLoweringObjectFile.cpp:414

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...

Definition TargetLoweringObjectFile.cpp:127

virtual MCSection * getSectionForMachineBasicBlock(const Function &F, const MachineBasicBlock &MBB, const TargetMachine &TM) const

Definition TargetLoweringObjectFile.cpp:435

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.

Definition TargetLoweringObjectFile.cpp:478

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...

Definition TargetLoweringObjectFile.cpp:449

~TargetLoweringObjectFile() override

Definition TargetLoweringObjectFile.cpp:55

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...

void emitPseudoProbeDescMetadata(MCStreamer &Streamer, Module &M, std::function< void(MCStreamer &Streamer)> COMDATSymEmitter=nullptr) const

Emit pseudo_probe_desc metadata.

Definition TargetLoweringObjectFile.cpp:194

const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const

Definition TargetLoweringObjectFile.cpp:459

virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM, const MCSymbol *Sym, const MachineModuleInfo *MMI) const

Definition TargetLoweringObjectFile.cpp:144

virtual MCSection * getUniqueSectionForFunction(const Function &F, const TargetMachine &TM) const

Definition TargetLoweringObjectFile.cpp:441

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...

Definition TargetLoweringObjectFile.cpp:354

Primary interface to the complete machine description for the target machine.

@ C

The default llvm calling convention, compatible with C.

std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)

Extract a Value from Metadata.

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)

FunctionAddr VTableAddr Count

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key

@ Ref

The access may reference the value stored in memory.

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

constexpr const char * PseudoProbeDescMetadataName

This struct is a compact representation of a valid (non-zero power of two) alignment.

MachineJumpTableEntry - One jump table in the jump table info.