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