1 //===- llvm/CodeGen/AsmPrinter.h - AsmPrinter Framework ---------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file contains a class to be used as the base class for target specific 11 // asm writers. This class primarily handles common functionality used by 12 // all asm writers. 13 // 14 //===----------------------------------------------------------------------===// 15 16 #ifndef LLVM_CODEGEN_ASMPRINTER_H 17 #define LLVM_CODEGEN_ASMPRINTER_H 18 19 #include "llvm/ADT/MapVector.h" 20 #include "llvm/ADT/SmallVector.h" 21 #include "llvm/ADT/StringRef.h" 22 #include "llvm/ADT/Twine.h" 23 #include "llvm/CodeGen/DwarfStringPoolEntry.h" 24 #include "llvm/CodeGen/MachineFunctionPass.h" 25 #include "llvm/IR/InlineAsm.h" 26 #include "llvm/IR/LLVMContext.h" 27 #include "llvm/Support/ErrorHandling.h" 28 #include "llvm/Support/SourceMgr.h" 29 #include <cstdint> 30 #include <memory> 31 #include <utility> 32 #include <vector> 33 34 namespace llvm { 35 36 class AsmPrinterHandler; 37 class BasicBlock; 38 class BlockAddress; 39 class Constant; 40 class ConstantArray; 41 class DataLayout; 42 class DIE; 43 class DIEAbbrev; 44 class DwarfDebug; 45 class GCMetadataPrinter; 46 class GCStrategy; 47 class GlobalIndirectSymbol; 48 class GlobalObject; 49 class GlobalValue; 50 class GlobalVariable; 51 class MachineBasicBlock; 52 class MachineConstantPoolValue; 53 class MachineDominatorTree; 54 class MachineFunction; 55 class MachineInstr; 56 class MachineJumpTableInfo; 57 class MachineLoopInfo; 58 class MachineModuleInfo; 59 class MachineOptimizationRemarkEmitter; 60 class MCAsmInfo; 61 class MCCFIInstruction; 62 struct MCCodePaddingContext; 63 class MCContext; 64 class MCExpr; 65 class MCInst; 66 class MCSection; 67 class MCStreamer; 68 class MCSubtargetInfo; 69 class MCSymbol; 70 class MCTargetOptions; 71 class MDNode; 72 class Module; 73 class raw_ostream; 74 class StackMaps; 75 class TargetLoweringObjectFile; 76 class TargetMachine; 77 78 /// This class is intended to be used as a driving class for all asm writers. 79 class AsmPrinter : public MachineFunctionPass { 80 public: 81 /// Target machine description. 82 TargetMachine &TM; 83 84 /// Target Asm Printer information. 85 const MCAsmInfo *MAI; 86 87 /// This is the context for the output file that we are streaming. This owns 88 /// all of the global MC-related objects for the generated translation unit. 89 MCContext &OutContext; 90 91 /// This is the MCStreamer object for the file we are generating. This 92 /// contains the transient state for the current translation unit that we are 93 /// generating (such as the current section etc). 94 std::unique_ptr<MCStreamer> OutStreamer; 95 96 /// The current machine function. 97 MachineFunction *MF = nullptr; 98 99 /// This is a pointer to the current MachineModuleInfo. 100 MachineModuleInfo *MMI = nullptr; 101 102 /// This is a pointer to the current MachineLoopInfo. 103 MachineDominatorTree *MDT = nullptr; 104 105 /// This is a pointer to the current MachineLoopInfo. 106 MachineLoopInfo *MLI = nullptr; 107 108 /// Optimization remark emitter. 109 MachineOptimizationRemarkEmitter *ORE; 110 111 /// The symbol for the current function. This is recalculated at the beginning 112 /// of each call to runOnMachineFunction(). 113 MCSymbol *CurrentFnSym = nullptr; 114 115 /// The symbol used to represent the start of the current function for the 116 /// purpose of calculating its size (e.g. using the .size directive). By 117 /// default, this is equal to CurrentFnSym. 118 MCSymbol *CurrentFnSymForSize = nullptr; 119 120 /// Map global GOT equivalent MCSymbols to GlobalVariables and keep track of 121 /// its number of uses by other globals. 122 using GOTEquivUsePair = std::pair<const GlobalVariable *, unsigned>; 123 MapVector<const MCSymbol *, GOTEquivUsePair> GlobalGOTEquivs; 124 125 /// Enable print [latency:throughput] in output. 126 bool EnablePrintSchedInfo = false; 127 128 private: 129 MCSymbol *CurrentFnBegin = nullptr; 130 MCSymbol *CurrentFnEnd = nullptr; 131 MCSymbol *CurExceptionSym = nullptr; 132 133 // The garbage collection metadata printer table. 134 void *GCMetadataPrinters = nullptr; // Really a DenseMap. 135 136 /// Emit comments in assembly output if this is true. 137 bool VerboseAsm; 138 139 static char ID; 140 141 protected: 142 /// Protected struct HandlerInfo and Handlers permit target extended 143 /// AsmPrinter adds their own handlers. 144 struct HandlerInfo { 145 AsmPrinterHandler *Handler; 146 const char *TimerName; 147 const char *TimerDescription; 148 const char *TimerGroupName; 149 const char *TimerGroupDescription; 150 HandlerInfoHandlerInfo151 HandlerInfo(AsmPrinterHandler *Handler, const char *TimerName, 152 const char *TimerDescription, const char *TimerGroupName, 153 const char *TimerGroupDescription) 154 : Handler(Handler), TimerName(TimerName), 155 TimerDescription(TimerDescription), TimerGroupName(TimerGroupName), 156 TimerGroupDescription(TimerGroupDescription) {} 157 }; 158 159 /// A vector of all debug/EH info emitters we should use. This vector 160 /// maintains ownership of the emitters. 161 SmallVector<HandlerInfo, 1> Handlers; 162 163 public: 164 struct SrcMgrDiagInfo { 165 SourceMgr SrcMgr; 166 std::vector<const MDNode *> LocInfos; 167 LLVMContext::InlineAsmDiagHandlerTy DiagHandler; 168 void *DiagContext; 169 }; 170 171 private: 172 /// If generated on the fly this own the instance. 173 std::unique_ptr<MachineDominatorTree> OwnedMDT; 174 175 /// If generated on the fly this own the instance. 176 std::unique_ptr<MachineLoopInfo> OwnedMLI; 177 178 /// Structure for generating diagnostics for inline assembly. Only initialised 179 /// when necessary. 180 mutable std::unique_ptr<SrcMgrDiagInfo> DiagInfo; 181 182 /// If the target supports dwarf debug info, this pointer is non-null. 183 DwarfDebug *DD = nullptr; 184 185 /// If the current module uses dwarf CFI annotations strictly for debugging. 186 bool isCFIMoveForDebugging = false; 187 188 protected: 189 explicit AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer); 190 191 public: 192 ~AsmPrinter() override; 193 getDwarfDebug()194 DwarfDebug *getDwarfDebug() { return DD; } getDwarfDebug()195 DwarfDebug *getDwarfDebug() const { return DD; } 196 197 uint16_t getDwarfVersion() const; 198 void setDwarfVersion(uint16_t Version); 199 200 bool isPositionIndependent() const; 201 202 /// Return true if assembly output should contain comments. isVerbose()203 bool isVerbose() const { return VerboseAsm; } 204 205 /// Return a unique ID for the current function. 206 unsigned getFunctionNumber() const; 207 208 /// Return symbol for the function pseudo stack if the stack frame is not a 209 /// register based. getFunctionFrameSymbol()210 virtual const MCSymbol *getFunctionFrameSymbol() const { return nullptr; } 211 getFunctionBegin()212 MCSymbol *getFunctionBegin() const { return CurrentFnBegin; } getFunctionEnd()213 MCSymbol *getFunctionEnd() const { return CurrentFnEnd; } 214 MCSymbol *getCurExceptionSym(); 215 216 /// Return information about object file lowering. 217 const TargetLoweringObjectFile &getObjFileLowering() const; 218 219 /// Return information about data layout. 220 const DataLayout &getDataLayout() const; 221 222 /// Return the pointer size from the TargetMachine 223 unsigned getPointerSize() const; 224 225 /// Return information about subtarget. 226 const MCSubtargetInfo &getSubtargetInfo() const; 227 228 void EmitToStreamer(MCStreamer &S, const MCInst &Inst); 229 230 /// Return the current section we are emitting to. 231 const MCSection *getCurrentSection() const; 232 233 void getNameWithPrefix(SmallVectorImpl<char> &Name, 234 const GlobalValue *GV) const; 235 236 MCSymbol *getSymbol(const GlobalValue *GV) const; 237 238 //===------------------------------------------------------------------===// 239 // XRay instrumentation implementation. 240 //===------------------------------------------------------------------===// 241 public: 242 // This describes the kind of sled we're storing in the XRay table. 243 enum class SledKind : uint8_t { 244 FUNCTION_ENTER = 0, 245 FUNCTION_EXIT = 1, 246 TAIL_CALL = 2, 247 LOG_ARGS_ENTER = 3, 248 CUSTOM_EVENT = 4, 249 TYPED_EVENT = 5, 250 }; 251 252 // The table will contain these structs that point to the sled, the function 253 // containing the sled, and what kind of sled (and whether they should always 254 // be instrumented). We also use a version identifier that the runtime can use 255 // to decide what to do with the sled, depending on the version of the sled. 256 struct XRayFunctionEntry { 257 const MCSymbol *Sled; 258 const MCSymbol *Function; 259 SledKind Kind; 260 bool AlwaysInstrument; 261 const class Function *Fn; 262 uint8_t Version; 263 264 void emit(int, MCStreamer *, const MCSymbol *) const; 265 }; 266 267 // All the sleds to be emitted. 268 SmallVector<XRayFunctionEntry, 4> Sleds; 269 270 // A unique ID used for ELF sections associated with a particular function. 271 unsigned XRayFnUniqueID = 0; 272 273 // Helper function to record a given XRay sled. 274 void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, 275 uint8_t Version = 0); 276 277 /// Emit a table with all XRay instrumentation points. 278 void emitXRayTable(); 279 280 //===------------------------------------------------------------------===// 281 // MachineFunctionPass Implementation. 282 //===------------------------------------------------------------------===// 283 284 /// Record analysis usage. 285 void getAnalysisUsage(AnalysisUsage &AU) const override; 286 287 /// Set up the AsmPrinter when we are working on a new module. If your pass 288 /// overrides this, it must make sure to explicitly call this implementation. 289 bool doInitialization(Module &M) override; 290 291 /// Shut down the asmprinter. If you override this in your pass, you must make 292 /// sure to call it explicitly. 293 bool doFinalization(Module &M) override; 294 295 /// Emit the specified function out to the OutStreamer. runOnMachineFunction(MachineFunction & MF)296 bool runOnMachineFunction(MachineFunction &MF) override { 297 SetupMachineFunction(MF); 298 EmitFunctionBody(); 299 return false; 300 } 301 302 //===------------------------------------------------------------------===// 303 // Coarse grained IR lowering routines. 304 //===------------------------------------------------------------------===// 305 306 /// This should be called when a new MachineFunction is being processed from 307 /// runOnMachineFunction. 308 void SetupMachineFunction(MachineFunction &MF); 309 310 /// This method emits the body and trailer for a function. 311 void EmitFunctionBody(); 312 313 void emitCFIInstruction(const MachineInstr &MI); 314 315 void emitFrameAlloc(const MachineInstr &MI); 316 317 void emitStackSizeSection(const MachineFunction &MF); 318 319 enum CFIMoveType { CFI_M_None, CFI_M_EH, CFI_M_Debug }; 320 CFIMoveType needsCFIMoves() const; 321 322 /// Returns false if needsCFIMoves() == CFI_M_EH for any function 323 /// in the module. needsOnlyDebugCFIMoves()324 bool needsOnlyDebugCFIMoves() const { return isCFIMoveForDebugging; } 325 326 bool needsSEHMoves(); 327 328 /// Print to the current output stream assembly representations of the 329 /// constants in the constant pool MCP. This is used to print out constants 330 /// which have been "spilled to memory" by the code generator. 331 virtual void EmitConstantPool(); 332 333 /// Print assembly representations of the jump tables used by the current 334 /// function to the current output stream. 335 virtual void EmitJumpTableInfo(); 336 337 /// Emit the specified global variable to the .s file. 338 virtual void EmitGlobalVariable(const GlobalVariable *GV); 339 340 /// Check to see if the specified global is a special global used by LLVM. If 341 /// so, emit it and return true, otherwise do nothing and return false. 342 bool EmitSpecialLLVMGlobal(const GlobalVariable *GV); 343 344 /// Emit an alignment directive to the specified power of two boundary. For 345 /// example, if you pass in 3 here, you will get an 8 byte alignment. If a 346 /// global value is specified, and if that global has an explicit alignment 347 /// requested, it will override the alignment request if required for 348 /// correctness. 349 void EmitAlignment(unsigned NumBits, const GlobalObject *GV = nullptr) const; 350 351 /// Lower the specified LLVM Constant to an MCExpr. 352 virtual const MCExpr *lowerConstant(const Constant *CV); 353 354 /// Print a general LLVM constant to the .s file. 355 void EmitGlobalConstant(const DataLayout &DL, const Constant *CV); 356 357 /// Unnamed constant global variables solely contaning a pointer to 358 /// another globals variable act like a global variable "proxy", or GOT 359 /// equivalents, i.e., it's only used to hold the address of the latter. One 360 /// optimization is to replace accesses to these proxies by using the GOT 361 /// entry for the final global instead. Hence, we select GOT equivalent 362 /// candidates among all the module global variables, avoid emitting them 363 /// unnecessarily and finally replace references to them by pc relative 364 /// accesses to GOT entries. 365 void computeGlobalGOTEquivs(Module &M); 366 367 /// Constant expressions using GOT equivalent globals may not be 368 /// eligible for PC relative GOT entry conversion, in such cases we need to 369 /// emit the proxies we previously omitted in EmitGlobalVariable. 370 void emitGlobalGOTEquivs(); 371 372 /// Emit the stack maps. 373 void emitStackMaps(StackMaps &SM); 374 375 //===------------------------------------------------------------------===// 376 // Overridable Hooks 377 //===------------------------------------------------------------------===// 378 379 // Targets can, or in the case of EmitInstruction, must implement these to 380 // customize output. 381 382 /// This virtual method can be overridden by targets that want to emit 383 /// something at the start of their file. EmitStartOfAsmFile(Module &)384 virtual void EmitStartOfAsmFile(Module &) {} 385 386 /// This virtual method can be overridden by targets that want to emit 387 /// something at the end of their file. EmitEndOfAsmFile(Module &)388 virtual void EmitEndOfAsmFile(Module &) {} 389 390 /// Targets can override this to emit stuff before the first basic block in 391 /// the function. EmitFunctionBodyStart()392 virtual void EmitFunctionBodyStart() {} 393 394 /// Targets can override this to emit stuff after the last basic block in the 395 /// function. EmitFunctionBodyEnd()396 virtual void EmitFunctionBodyEnd() {} 397 398 /// Targets can override this to emit stuff at the start of a basic block. 399 /// By default, this method prints the label for the specified 400 /// MachineBasicBlock, an alignment (if present) and a comment describing it 401 /// if appropriate. 402 virtual void EmitBasicBlockStart(const MachineBasicBlock &MBB) const; 403 404 /// Targets can override this to emit stuff at the end of a basic block. 405 virtual void EmitBasicBlockEnd(const MachineBasicBlock &MBB); 406 407 /// Targets should implement this to emit instructions. EmitInstruction(const MachineInstr *)408 virtual void EmitInstruction(const MachineInstr *) { 409 llvm_unreachable("EmitInstruction not implemented"); 410 } 411 412 /// Return the symbol for the specified constant pool entry. 413 virtual MCSymbol *GetCPISymbol(unsigned CPID) const; 414 415 virtual void EmitFunctionEntryLabel(); 416 417 virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV); 418 419 /// Targets can override this to change how global constants that are part of 420 /// a C++ static/global constructor list are emitted. EmitXXStructor(const DataLayout & DL,const Constant * CV)421 virtual void EmitXXStructor(const DataLayout &DL, const Constant *CV) { 422 EmitGlobalConstant(DL, CV); 423 } 424 425 /// Return true if the basic block has exactly one predecessor and the control 426 /// transfer mechanism between the predecessor and this block is a 427 /// fall-through. 428 virtual bool 429 isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const; 430 431 /// Targets can override this to customize the output of IMPLICIT_DEF 432 /// instructions in verbose mode. 433 virtual void emitImplicitDef(const MachineInstr *MI) const; 434 435 //===------------------------------------------------------------------===// 436 // Symbol Lowering Routines. 437 //===------------------------------------------------------------------===// 438 439 MCSymbol *createTempSymbol(const Twine &Name) const; 440 441 /// Return the MCSymbol for a private symbol with global value name as its 442 /// base, with the specified suffix. 443 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV, 444 StringRef Suffix) const; 445 446 /// Return the MCSymbol for the specified ExternalSymbol. 447 MCSymbol *GetExternalSymbolSymbol(StringRef Sym) const; 448 449 /// Return the symbol for the specified jump table entry. 450 MCSymbol *GetJTISymbol(unsigned JTID, bool isLinkerPrivate = false) const; 451 452 /// Return the symbol for the specified jump table .set 453 /// FIXME: privatize to AsmPrinter. 454 MCSymbol *GetJTSetSymbol(unsigned UID, unsigned MBBID) const; 455 456 /// Return the MCSymbol used to satisfy BlockAddress uses of the specified 457 /// basic block. 458 MCSymbol *GetBlockAddressSymbol(const BlockAddress *BA) const; 459 MCSymbol *GetBlockAddressSymbol(const BasicBlock *BB) const; 460 461 //===------------------------------------------------------------------===// 462 // Emission Helper Routines. 463 //===------------------------------------------------------------------===// 464 465 /// This is just convenient handler for printing offsets. 466 void printOffset(int64_t Offset, raw_ostream &OS) const; 467 468 /// Emit a byte directive and value. 469 void emitInt8(int Value) const; 470 471 /// Emit a short directive and value. 472 void emitInt16(int Value) const; 473 474 /// Emit a long directive and value. 475 void emitInt32(int Value) const; 476 477 /// Emit a long long directive and value. 478 void emitInt64(uint64_t Value) const; 479 480 /// Emit something like ".long Hi-Lo" where the size in bytes of the directive 481 /// is specified by Size and Hi/Lo specify the labels. This implicitly uses 482 /// .set if it is available. 483 void EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, 484 unsigned Size) const; 485 486 /// Emit something like ".uleb128 Hi-Lo". 487 void EmitLabelDifferenceAsULEB128(const MCSymbol *Hi, 488 const MCSymbol *Lo) const; 489 490 /// Emit something like ".long Label+Offset" where the size in bytes of the 491 /// directive is specified by Size and Label specifies the label. This 492 /// implicitly uses .set if it is available. 493 void EmitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset, 494 unsigned Size, bool IsSectionRelative = false) const; 495 496 /// Emit something like ".long Label" where the size in bytes of the directive 497 /// is specified by Size and Label specifies the label. 498 void EmitLabelReference(const MCSymbol *Label, unsigned Size, 499 bool IsSectionRelative = false) const { 500 EmitLabelPlusOffset(Label, 0, Size, IsSectionRelative); 501 } 502 503 /// Emit something like ".long Label + Offset". 504 void EmitDwarfOffset(const MCSymbol *Label, uint64_t Offset) const; 505 506 //===------------------------------------------------------------------===// 507 // Dwarf Emission Helper Routines 508 //===------------------------------------------------------------------===// 509 510 /// Emit the specified signed leb128 value. 511 void EmitSLEB128(int64_t Value, const char *Desc = nullptr) const; 512 513 /// Emit the specified unsigned leb128 value. 514 void EmitULEB128(uint64_t Value, const char *Desc = nullptr) const; 515 516 /// Emit a .byte 42 directive that corresponds to an encoding. If verbose 517 /// assembly output is enabled, we output comments describing the encoding. 518 /// Desc is a string saying what the encoding is specifying (e.g. "LSDA"). 519 void EmitEncodingByte(unsigned Val, const char *Desc = nullptr) const; 520 521 /// Return the size of the encoding in bytes. 522 unsigned GetSizeOfEncodedValue(unsigned Encoding) const; 523 524 /// Emit reference to a ttype global with a specified encoding. 525 void EmitTTypeReference(const GlobalValue *GV, unsigned Encoding) const; 526 527 /// Emit a reference to a symbol for use in dwarf. Different object formats 528 /// represent this in different ways. Some use a relocation others encode 529 /// the label offset in its section. 530 void emitDwarfSymbolReference(const MCSymbol *Label, 531 bool ForceOffset = false) const; 532 533 /// Emit the 4-byte offset of a string from the start of its section. 534 /// 535 /// When possible, emit a DwarfStringPool section offset without any 536 /// relocations, and without using the symbol. Otherwise, defers to \a 537 /// emitDwarfSymbolReference(). 538 void emitDwarfStringOffset(DwarfStringPoolEntry S) const; 539 540 /// Emit the 4-byte offset of a string from the start of its section. emitDwarfStringOffset(DwarfStringPoolEntryRef S)541 void emitDwarfStringOffset(DwarfStringPoolEntryRef S) const { 542 emitDwarfStringOffset(S.getEntry()); 543 } 544 545 /// Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified. getISAEncoding()546 virtual unsigned getISAEncoding() { return 0; } 547 548 /// Emit the directive and value for debug thread local expression 549 /// 550 /// \p Value - The value to emit. 551 /// \p Size - The size of the integer (in bytes) to emit. 552 virtual void EmitDebugValue(const MCExpr *Value, unsigned Size) const; 553 554 //===------------------------------------------------------------------===// 555 // Dwarf Lowering Routines 556 //===------------------------------------------------------------------===// 557 558 /// Emit frame instruction to describe the layout of the frame. 559 void emitCFIInstruction(const MCCFIInstruction &Inst) const; 560 561 /// Emit Dwarf abbreviation table. emitDwarfAbbrevs(const T & Abbrevs)562 template <typename T> void emitDwarfAbbrevs(const T &Abbrevs) const { 563 // For each abbreviation. 564 for (const auto &Abbrev : Abbrevs) 565 emitDwarfAbbrev(*Abbrev); 566 567 // Mark end of abbreviations. 568 EmitULEB128(0, "EOM(3)"); 569 } 570 571 void emitDwarfAbbrev(const DIEAbbrev &Abbrev) const; 572 573 /// Recursively emit Dwarf DIE tree. 574 void emitDwarfDIE(const DIE &Die) const; 575 576 //===------------------------------------------------------------------===// 577 // Inline Asm Support 578 //===------------------------------------------------------------------===// 579 580 // These are hooks that targets can override to implement inline asm 581 // support. These should probably be moved out of AsmPrinter someday. 582 583 /// Print information related to the specified machine instr that is 584 /// independent of the operand, and may be independent of the instr itself. 585 /// This can be useful for portably encoding the comment character or other 586 /// bits of target-specific knowledge into the asmstrings. The syntax used is 587 /// ${:comment}. Targets can override this to add support for their own 588 /// strange codes. 589 virtual void PrintSpecial(const MachineInstr *MI, raw_ostream &OS, 590 const char *Code) const; 591 592 /// Print the specified operand of MI, an INLINEASM instruction, using the 593 /// specified assembler variant. Targets should override this to format as 594 /// appropriate. This method can return true if the operand is erroneous. 595 virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, 596 unsigned AsmVariant, const char *ExtraCode, 597 raw_ostream &OS); 598 599 /// Print the specified operand of MI, an INLINEASM instruction, using the 600 /// specified assembler variant as an address. Targets should override this to 601 /// format as appropriate. This method can return true if the operand is 602 /// erroneous. 603 virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, 604 unsigned AsmVariant, const char *ExtraCode, 605 raw_ostream &OS); 606 607 /// Let the target do anything it needs to do before emitting inlineasm. 608 /// \p StartInfo - the subtarget info before parsing inline asm 609 virtual void emitInlineAsmStart() const; 610 611 /// Let the target do anything it needs to do after emitting inlineasm. 612 /// This callback can be used restore the original mode in case the 613 /// inlineasm contains directives to switch modes. 614 /// \p StartInfo - the original subtarget info before inline asm 615 /// \p EndInfo - the final subtarget info after parsing the inline asm, 616 /// or NULL if the value is unknown. 617 virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, 618 const MCSubtargetInfo *EndInfo) const; 619 620 private: 621 /// Private state for PrintSpecial() 622 // Assign a unique ID to this machine instruction. 623 mutable const MachineInstr *LastMI = nullptr; 624 mutable unsigned LastFn = 0; 625 mutable unsigned Counter = ~0U; 626 627 /// This method emits the header for the current function. 628 virtual void EmitFunctionHeader(); 629 630 /// Emit a blob of inline asm to the output streamer. 631 void 632 EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI, 633 const MCTargetOptions &MCOptions, 634 const MDNode *LocMDNode = nullptr, 635 InlineAsm::AsmDialect AsmDialect = InlineAsm::AD_ATT) const; 636 637 /// This method formats and emits the specified machine instruction that is an 638 /// inline asm. 639 void EmitInlineAsm(const MachineInstr *MI) const; 640 641 /// Add inline assembly info to the diagnostics machinery, so we can 642 /// emit file and position info. Returns SrcMgr memory buffer position. 643 unsigned addInlineAsmDiagBuffer(StringRef AsmStr, 644 const MDNode *LocMDNode) const; 645 646 //===------------------------------------------------------------------===// 647 // Internal Implementation Details 648 //===------------------------------------------------------------------===// 649 650 /// This emits visibility information about symbol, if this is supported by 651 /// the target. 652 void EmitVisibility(MCSymbol *Sym, unsigned Visibility, 653 bool IsDefinition = true) const; 654 655 void EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const; 656 657 void EmitJumpTableEntry(const MachineJumpTableInfo *MJTI, 658 const MachineBasicBlock *MBB, unsigned uid) const; 659 void EmitLLVMUsedList(const ConstantArray *InitList); 660 /// Emit llvm.ident metadata in an '.ident' directive. 661 void EmitModuleIdents(Module &M); 662 /// Emit bytes for llvm.commandline metadata. 663 void EmitModuleCommandLines(Module &M); 664 void EmitXXStructorList(const DataLayout &DL, const Constant *List, 665 bool isCtor); 666 667 GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy &S); 668 /// Emit GlobalAlias or GlobalIFunc. 669 void emitGlobalIndirectSymbol(Module &M, const GlobalIndirectSymbol &GIS); 670 void setupCodePaddingContext(const MachineBasicBlock &MBB, 671 MCCodePaddingContext &Context) const; 672 }; 673 674 } // end namespace llvm 675 676 #endif // LLVM_CODEGEN_ASMPRINTER_H 677