LLVM: include/llvm/CodeGen/AsmPrinter.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_CODEGEN_ASMPRINTER_H

16#define LLVM_CODEGEN_ASMPRINTER_H

17

33#include

34#include

35#include

36#include

37

38namespace llvm {

39

86

90

94

95

97public:

98

100

101

103

104

105

107

108

109

110

112

113

115

116

118

119

121

122

124

125

127

128

130

131

133

134

135

137

138

139

141

142

143

144

146

147

148

149

150

153

154

156

157

159

160

161

165

167

168

169

172

173

179

180private:

181 MCSymbol *CurrentFnEnd = nullptr;

182

183

184

185

187

188

189

190 MCSymbol *CurrentSectionBeginSym = nullptr;

191

192

193

194 std::unique_ptr AddrLabelSymbols;

195

196

198

199

200 bool VerboseAsm;

201

202

203

204 struct FunctionCallGraphInfo {

205

206

208

209

211

213 };

214

215 enum CallGraphSectionFormatVersion : uint8_t {

216 V_0 = 0,

217 };

218

219

220 std::unique_ptr<raw_fd_ostream> StackUsageStream;

221

222

223 DenseMap<const MDNode *, SmallVector<const MCSymbol *>> PCSectionsSymbols;

224

225 static char ID;

226

227protected:

229

230

232

233

234

235

237

238

239

240

243

245

246private:

247

248 std::unique_ptr OwnedMDT;

249

250

251 std::unique_ptr OwnedMLI;

252

253

255

256

257

258 std::unique_ptr PP;

259

260

262

263

264

265

266 bool HasSplitStack = false;

267

268

269

270

271 bool HasNoSplitStack = false;

272

273

274 bool DbgInfoAvailable = false;

275

276protected:

278 char &ID = AsmPrinter::ID);

279

280public:

282

285

286 uint16_t getDwarfVersion() const;

288

289 bool isDwarf64() const;

290

291

292 unsigned int getDwarfOffsetByteSize() const;

293

294

295 unsigned int getUnitLengthFieldByteSize() const;

296

297

299

300 bool isPositionIndependent() const;

301

302

303 bool isVerbose() const { return VerboseAsm; }

304

305

306 unsigned getFunctionNumber() const;

307

308

309

311

314

315

316

318

319

320

321

325

326

327

328

330

331

332

334

335

336

337

338

339 void takeDeletedSymbolsForFunction(const Function *F,

340 std::vector<MCSymbol *> &Result);

341

342

344

345

346 const DataLayout &getDataLayout() const;

347

348

350

351

353

355

356

357 void emitInitialRawDwarfLocDirective(const MachineFunction &MF);

358

359

360 const MCSection *getCurrentSection() const;

361

364

366

367

368

369

371

373 return DwarfUsesRelocationsAcrossSections;

374 }

375

377 DwarfUsesRelocationsAcrossSections = Enable;

378 }

379

380

381

383

384

385

386

387 void handleCallsiteForCallgraph(

388 FunctionCallGraphInfo &FuncCGInfo,

391

392

393

394

395public:

396

405

406

407

408

409

420

421

423

424

427

428

430

432

433

434

435

436

437

439

440

441

443

444

445

447

448

454

455

456

457

458

459

460

462

463

464 void emitFunctionBody();

465

467

469

471

473

475

478

480 FunctionCallGraphInfo &FuncCGInfo);

481

483

485

486

488

489

491

492

493 CFISection getFunctionCFISectionType(const Function &F) const;

494

495

496 CFISection getFunctionCFISectionType(const MachineFunction &MF) const;

497

498

500

501

503

504 bool needsSEHMoves();

505

506

507

508

509

510 bool usesCFIWithoutEH() const;

511

512

513

514

516

517

518

519 virtual void emitJumpTableInfo();

520

521

522 virtual void emitGlobalVariable(const GlobalVariable *GV);

523

524

525

526 bool emitSpecialLLVMGlobal(const GlobalVariable *GV);

527

528

529

530

531

532

533

541

542

543

544

545

546

549

550

552 bool IsCtor);

553

554

555

556

557

559 unsigned MaxBytesToEmit = 0) const;

560

561

562

564 const Constant *BaseCV = nullptr,

566

567

568

569

573

574

575

576

577

578

579

580

581

583

584

585

586

588

589

591

592

593

594

595

597

598

599

600

601

602

604

605

606

608

609

610

612

613

614

616

617

618

619

620

622

623

625

626

630

631

632 virtual MCSymbol *GetCPISymbol(unsigned CPID) const;

633

634 virtual void emitFunctionEntryLabel();

635

639

641

642

643

647

651

652

653 virtual const MCExpr *lowerBlockAddressConstant(const BlockAddress &BA);

654

655

656

657

658 virtual bool

660

661

662

663 virtual void emitImplicitDef(const MachineInstr *MI) const;

664

665

666

667

668

670 return nullptr;

671 }

672

676 "Mach-O IFunc lowering is not yet supported on this target");

677 }

678

682 "Mach-O IFunc lowering is not yet supported on this target");

683 }

684

685

686 void emitNops(unsigned N);

687

688

689

690

691

692 MCSymbol *createTempSymbol(const Twine &Name) const;

693

694

695

698

699

700 MCSymbol *GetExternalSymbolSymbol(const Twine &Sym) const;

701

702

703 MCSymbol *GetJTISymbol(unsigned JTID, bool isLinkerPrivate = false) const;

704

705

706

707 MCSymbol *GetJTSetSymbol(unsigned UID, unsigned MBBID) const;

708

709

710

713

714

715

716

717

718

720

721

722 void emitInt8(int Value) const;

723

724

725 void emitInt16(int Value) const;

726

727

728 void emitInt32(int Value) const;

729

730

732

733

734 void emitSLEB128(int64_t Value, const char *Desc = nullptr) const;

735

736

738 unsigned PadTo = 0) const;

739

740

741

742

744 unsigned Size) const;

745

746

747 void emitLabelDifferenceAsULEB128(const MCSymbol *Hi,

749

750

751

752

754 unsigned Size, bool IsSectionRelative = false) const;

755

756

757

759 bool IsSectionRelative = false) const {

761 }

762

763

764

765

766

767

768

769

771

772

773 unsigned GetSizeOfEncodedValue(unsigned Encoding) const;

774

775

776 virtual void emitTTypeReference(const GlobalValue *GV, unsigned Encoding);

777

778

779

780

781 void emitDwarfSymbolReference(const MCSymbol *Label,

782 bool ForceOffset = false) const;

783

784

785

786

787

788

789

790

792

793

797

798

799

801

802

803 void emitDwarfLengthOrOffset(uint64_t Value) const;

804

805

806

808

809

810

811

812 MCSymbol *emitDwarfUnitLength(const Twine &Prefix,

813 const Twine &Comment) const;

814

815

817 unsigned Encoding) const;

818

819 void emitCallSiteValue(uint64_t Value, unsigned Encoding) const;

820

821

823

824

825

826

827

828 virtual void emitDebugValue(const MCExpr *Value, unsigned Size) const;

829

830

831

832

833

834

836

837

839

840 for (const auto &Abbrev : Abbrevs)

842

843

845 }

846

847 void emitDwarfAbbrev(const DIEAbbrev &Abbrev) const;

848

849

850 void emitDwarfDIE(const DIE &Die) const;

851

852

853

854

855

856

857

858

861 getCodeViewJumpTableInfo(int JTI, const MachineInstr *BranchInstr,

862 const MCSymbol *BranchLabel) const;

863

864

865

866

867

868

869

870 void emitCOFFReplaceableFunctionData(Module &M);

871

872

873 void emitCOFFFeatureSymbol(Module &M);

874

875

876

877

878

879

880

881

882

883

884

885

886

887

890

891

892

894

895

896

897

898 virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,

900

901

902

903

904

905 virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,

907

908

909

910 virtual void emitInlineAsmStart() const;

911

912

913

914

915

916

917

918 virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,

920

921

922

923 void emitVisibility(MCSymbol *Sym, unsigned Visibility,

924 bool IsDefinition = true) const;

925

926

927

929

930

933

934private:

935

936

937 mutable const MachineInstr *LastMI = nullptr;

938 mutable unsigned LastFn = 0;

939 mutable unsigned Counter = ~0U;

940

941 bool DwarfUsesRelocationsAcrossSections = false;

942

943

944 virtual void emitFunctionHeader();

945

946

947 virtual void emitFunctionHeaderComment();

948

949

951

952

953 void

956 const MDNode *LocMDNode = nullptr,

958

959

960

962

963

964

965 unsigned addInlineAsmDiagBuffer(StringRef AsmStr,

966 const MDNode *LocMDNode) const;

967

968

969

970

971

974

977

978 void emitLLVMUsedList(const ConstantArray *InitList);

979

980 void emitModuleIdents(Module &M);

981

982 virtual void emitModuleCommandLines(Module &M);

983

986

987

989

990protected:

993 unsigned uid) const;

994 virtual void emitGlobalAlias(const Module &M, const GlobalAlias &GA);

998};

999

1000}

1001

1002#endif

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

static void emitConstantPool(MCStreamer &Streamer, MCSection *Section, ConstantPool &CP)

static std::optional< TypeSize > getPointerSize(const Value *V, const DataLayout &DL, const TargetLibraryInfo &TLI, const Function *F)

This file defines the DenseMap class.

This file contains constants used for implementing Dwarf debug support.

This file defines the RefCountedBase, ThreadSafeRefCountedBase, and IntrusiveRefCntPtr classes.

static void emitEncodingByte(MCObjectStreamer &Streamer, unsigned Encoding)

This file implements a map that provides insertion order iteration.

static void emitInlineAsm(LLVMContext &C, BasicBlock *BB, StringRef AsmText)

static SDValue lowerConstant(SDValue Op, SelectionDAG &DAG, const RISCVSubtarget &Subtarget)

This file implements a set that has insertion order iteration characteristics.

This file defines the SmallVector class.

Represent the analysis usage information of a pass.

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

Collects and handles AsmPrinter objects required to build debug or EH information.

virtual void emitInstruction(const MachineInstr *)

Targets should implement this to emit instructions.

Definition AsmPrinter.h:627

void emitULEB128(uint64_t Value, const char *Desc=nullptr, unsigned PadTo=0) const

Emit the specified unsigned leb128 value.

SmallVector< XRayFunctionEntry, 4 > Sleds

Definition AsmPrinter.h:422

MapVector< MBBSectionID, MBBSectionRange > MBBSectionRanges

Definition AsmPrinter.h:166

CFISection getModuleCFISectionType() const

Get the CFISection type for the module.

Definition AsmPrinter.h:499

MCSymbol * CurrentFnBegin

Definition AsmPrinter.h:228

MachineLoopInfo * MLI

This is a pointer to the current MachineLoopInfo.

Definition AsmPrinter.h:126

DwarfDebug * getDwarfDebug()

Definition AsmPrinter.h:283

IntrusiveRefCntPtr< vfs::FileSystem > VFS

The VFS to resolve asm include directives.

Definition AsmPrinter.h:114

virtual const MCExpr * lowerConstantPtrAuth(const ConstantPtrAuth &CPA)

Definition AsmPrinter.h:648

void emitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset, unsigned Size, bool IsSectionRelative=false) const

Emit something like ".long Label+Offset" where the size in bytes of the directive is specified by Siz...

TargetMachine & TM

Target machine description.

Definition AsmPrinter.h:99

void emitXRayTable()

Emit a table with all XRay instrumentation points.

DenseMap< const MachineBasicBlock *, SmallVector< MCSymbol *, 1 > > CurrentFnCallsiteEndSymbols

Vector of symbols marking the end of the callsites in the current function, keyed by their containing...

Definition AsmPrinter.h:152

DwarfDebug * getDwarfDebug() const

Definition AsmPrinter.h:284

MCSymbol * CurrentFnDescSym

The symbol for the current function descriptor on AIX.

Definition AsmPrinter.h:140

MCSymbol * CurrentFnBeginLocal

For dso_local functions, the current $local alias for the function.

Definition AsmPrinter.h:231

MapVector< const MCSymbol *, GOTEquivUsePair > GlobalGOTEquivs

Definition AsmPrinter.h:171

void emitDwarfStringOffset(DwarfStringPoolEntry S) const

Emit the 4- or 8-byte offset of a string from the start of its section.

void emitGlobalGOTEquivs()

Constant expressions using GOT equivalent globals may not be eligible for PC relative GOT entry conve...

MCSymbol * getFunctionBegin() const

Definition AsmPrinter.h:312

virtual void emitMachOIFuncStubHelperBody(Module &M, const GlobalIFunc &GI, MCSymbol *LazyPointer)

Definition AsmPrinter.h:679

MCSymbol * getAddrLabelSymbol(const BasicBlock *BB)

Return the symbol to be used for the specified basic block when its address is taken.

Definition AsmPrinter.h:322

const MCAsmInfo * MAI

Target Asm Printer information.

Definition AsmPrinter.h:102

SmallVector< std::unique_ptr< AsmPrinterHandler >, 2 > Handlers

Definition AsmPrinter.h:241

MachineFunction * MF

The current machine function.

Definition AsmPrinter.h:117

void computeGlobalGOTEquivs(Module &M)

Unnamed constant global variables solely contaning a pointer to another globals variable act like a g...

virtual void SetupMachineFunction(MachineFunction &MF)

This should be called when a new MachineFunction is being processed from runOnMachineFunction.

void emitFunctionBody()

This method emits the body and trailer for a function.

MachineDominatorTree * MDT

This is a pointer to the current MachineDominatorTree.

Definition AsmPrinter.h:123

virtual void emitStartOfAsmFile(Module &)

This virtual method can be overridden by targets that want to emit something at the start of their fi...

Definition AsmPrinter.h:603

void emitStackMaps()

Emit the stack maps.

bool hasDebugInfo() const

Returns true if valid debug info is present.

Definition AsmPrinter.h:502

virtual void emitFunctionBodyStart()

Targets can override this to emit stuff before the first basic block in the function.

Definition AsmPrinter.h:611

std::pair< const GlobalVariable *, unsigned > GOTEquivUsePair

Map global GOT equivalent MCSymbols to GlobalVariables and keep track of its number of uses by other ...

Definition AsmPrinter.h:170

void emitPatchableFunctionEntries()

void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version=0)

virtual void emitEndOfAsmFile(Module &)

This virtual method can be overridden by targets that want to emit something at the end of their file...

Definition AsmPrinter.h:607

bool doInitialization(Module &M) override

Set up the AsmPrinter when we are working on a new module.

virtual void emitMachOIFuncStubBody(Module &M, const GlobalIFunc &GI, MCSymbol *LazyPointer)

Definition AsmPrinter.h:673

void getAnalysisUsage(AnalysisUsage &AU) const override

Record analysis usage.

MachineOptimizationRemarkEmitter * ORE

Optimization remark emitter.

Definition AsmPrinter.h:129

DenseMap< uint64_t, SmallVector< const GlobalAlias *, 1 > > AliasMapTy

Print a general LLVM constant to the .s file.

Definition AsmPrinter.h:570

virtual bool shouldEmitWeakSwiftAsyncExtendedFramePointerFlags() const

Definition AsmPrinter.h:995

AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer, char &ID=AsmPrinter::ID)

void emitGlobalConstant(const DataLayout &DL, const Constant *CV, AliasMapTy *AliasList=nullptr)

EmitGlobalConstant - Print a general LLVM constant to the .s file.

virtual const MCSymbol * getFunctionFrameSymbol() const

Return symbol for the function pseudo stack if the stack frame is not a register based.

Definition AsmPrinter.h:310

void emitDwarfStringOffset(DwarfStringPoolEntryRef S) const

Emit the 4-or 8-byte offset of a string from the start of its section.

Definition AsmPrinter.h:794

MCSymbol * CurrentFnSym

The symbol for the current function.

Definition AsmPrinter.h:136

MachineModuleInfo * MMI

This is a pointer to the current MachineModuleInfo.

Definition AsmPrinter.h:120

void emitDwarfAbbrevs(const T &Abbrevs) const

Emit Dwarf abbreviation table.

Definition AsmPrinter.h:838

void emitAlignment(Align Alignment, const GlobalObject *GV=nullptr, unsigned MaxBytesToEmit=0) const

Emit an alignment directive to the specified power of two boundary.

MCContext & OutContext

This is the context for the output file that we are streaming.

Definition AsmPrinter.h:106

const StaticDataProfileInfo * SDPI

Provides the profile information for constants.

Definition AsmPrinter.h:155

bool doFinalization(Module &M) override

Shut down the asmprinter.

virtual const MCSubtargetInfo * getIFuncMCSubtargetInfo() const

getSubtargetInfo() cannot be used where this is needed because we don't have a MachineFunction when w...

Definition AsmPrinter.h:669

virtual void emitXXStructorList(const DataLayout &DL, const Constant *List, bool IsCtor)

This method emits llvm.global_ctors or llvm.global_dtors list.

MCSymbol * CurrentPatchableFunctionEntrySym

The symbol for the entry in __patchable_function_entires.

Definition AsmPrinter.h:132

bool runOnMachineFunction(MachineFunction &MF) override

Emit the specified function out to the OutStreamer.

Definition AsmPrinter.h:449

void emitDwarfAbbrev(const DIEAbbrev &Abbrev) const

void setDwarfUsesRelocationsAcrossSections(bool Enable)

Definition AsmPrinter.h:376

std::unique_ptr< MCStreamer > OutStreamer

This is the MCStreamer object for the file we are generating.

Definition AsmPrinter.h:111

const ProfileSummaryInfo * PSI

The profile summary information.

Definition AsmPrinter.h:158

SledKind

Definition AsmPrinter.h:397

@ LOG_ARGS_ENTER

Definition AsmPrinter.h:401

@ TAIL_CALL

Definition AsmPrinter.h:400

@ CUSTOM_EVENT

Definition AsmPrinter.h:402

@ FUNCTION_EXIT

Definition AsmPrinter.h:399

@ FUNCTION_ENTER

Definition AsmPrinter.h:398

@ TYPED_EVENT

Definition AsmPrinter.h:403

void emitLabelReference(const MCSymbol *Label, unsigned Size, bool IsSectionRelative=false) const

Emit something like ".long Label" where the size in bytes of the directive is specified by Size and L...

Definition AsmPrinter.h:758

virtual void emitFunctionDescriptor()

Definition AsmPrinter.h:636

size_t NumUserHandlers

Definition AsmPrinter.h:242

MCSymbol * CurrentFnSymForSize

The symbol used to represent the start of the current function for the purpose of calculating its siz...

Definition AsmPrinter.h:145

virtual unsigned getISAEncoding()

Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.

Definition AsmPrinter.h:822

bool isVerbose() const

Return true if assembly output should contain comments.

Definition AsmPrinter.h:303

MCSymbol * getFunctionEnd() const

Definition AsmPrinter.h:313

virtual void emitXXStructor(const DataLayout &DL, const Constant *CV)

Targets can override this to change how global constants that are part of a C++ static/global constru...

Definition AsmPrinter.h:644

void preprocessXXStructorList(const DataLayout &DL, const Constant *List, SmallVector< Structor, 8 > &Structors)

This method gathers an array of Structors and then sorts them out by Priority.

SmallVector< std::unique_ptr< AsmPrinterHandler >, 1 > EHHandlers

A handle to the EH info emitter (if present).

Definition AsmPrinter.h:236

StackMaps SM

Definition AsmPrinter.h:244

ArrayRef< MCSymbol * > getAddrLabelSymbolToEmit(const BasicBlock *BB)

Return the symbol to be used for the specified basic block when its address is taken.

virtual void emitFunctionBodyEnd()

Targets can override this to emit stuff after the last basic block in the function.

Definition AsmPrinter.h:615

bool doesDwarfUseRelocationsAcrossSections() const

Definition AsmPrinter.h:372

CFISection

Definition AsmPrinter.h:174

@ EH

Emit .eh_frame.

Definition AsmPrinter.h:176

@ None

Do not emit either .eh_frame or .debug_frame.

Definition AsmPrinter.h:175

@ Debug

Emit .debug_frame.

Definition AsmPrinter.h:177

void addAsmPrinterHandler(std::unique_ptr< AsmPrinterHandler > Handler)

LLVM Basic Block Representation.

The address of a basic block.

ConstantArray - Constant Array Declarations.

A signed pointer, in the ptrauth sense.

This is an important base class in LLVM.

Dwarf abbreviation, describes the organization of a debug information object.

A structured debug information entry.

A parsed version of the target data layout string in and methods for querying it.

Base class for debug information backends.

Collects and handles dwarf debug information.

DwarfStringPoolEntryRef: Dwarf string pool entry reference.

const DwarfStringPoolEntry & getEntry() const

Emits exception handling directives.

GCStrategy describes a garbage collector algorithm's code generation requirements,...

A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...

This class is intended to be used as a base class for asm properties and features specific to the tar...

Context object for machine code objects.

Base class for the full range of assembler expressions which are needed for parsing.

Instances of this class represent a single low-level machine instruction.

Instances of this class represent a uniqued identifier for a section in the current translation unit.

Streaming machine code generation interface.

Generic base class for all target subtargets.

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

Abstract base class for all machine specific constantpool value subclasses.

DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...

MachineFunctionPass(char &ID)

DenseMap< const MachineInstr *, CallSiteInfo > CallSiteInfoMap

Representation of each machine instruction.

This class contains meta information specific to a module.

MachineOperand class - Representation of each machine instruction operand.

This class implements a map that also provides access to all stored values in a deterministic order.

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

Analysis providing profile information.

A SetVector that performs no allocations if smaller than a certain size.

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.

A class that holds the constants that represent static data and their profile information and provide...

StringRef - Represent a constant reference to a string, i.e.

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

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

LLVM Value Representation.

This class implements an extremely fast bulk output stream that can only output to a stream.

The virtual file system interface.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

@ C

The default llvm calling convention, compatible with C.

Definition AsmPrinter.h:91

This is an optimization pass for GlobalISel generic memory operations.

FunctionAddr VTableAddr uintptr_t uintptr_t Version

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

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

Map a basic block section ID to the begin and end symbols of that section which determine the section...

Definition AsmPrinter.h:162

MCSymbol * BeginLabel

Definition AsmPrinter.h:163

MCSymbol * EndLabel

Definition AsmPrinter.h:163

Constant * Func

Definition AsmPrinter.h:536

GlobalValue * ComdatKey

Definition AsmPrinter.h:537

int Priority

Definition AsmPrinter.h:535

Definition AsmPrinter.h:410

const MCSymbol * Function

Definition AsmPrinter.h:412

SledKind Kind

Definition AsmPrinter.h:413

uint8_t Version

Definition AsmPrinter.h:416

const class Function * Fn

Definition AsmPrinter.h:415

LLVM_ABI void emit(int, MCStreamer *) const

bool AlwaysInstrument

Definition AsmPrinter.h:414

const MCSymbol * Sled

Definition AsmPrinter.h:411

Data for a string pool entry.

A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...