ARMAsmPrinter.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //===-- ARMAsmPrinter.h - ARM implementation of AsmPrinter ------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
  9. #define LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
  10. #include "ARMSubtarget.h"
  11. #include "llvm/CodeGen/AsmPrinter.h"
  12. #include "llvm/Target/TargetMachine.h"
  13. namespace llvm {
  14. class ARMFunctionInfo;
  15. class MCOperand;
  16. class MachineConstantPool;
  17. class MachineOperand;
  18. class MCSymbol;
  19. namespace ARM {
  20. enum DW_ISA {
  21. DW_ISA_ARM_thumb = 1,
  22. DW_ISA_ARM_arm = 2
  23. };
  24. }
  25. class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
  26. /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
  27. /// make the right decision when printing asm code for different targets.
  28. const ARMSubtarget *Subtarget;
  29. /// AFI - Keep a pointer to ARMFunctionInfo for the current
  30. /// MachineFunction.
  31. ARMFunctionInfo *AFI;
  32. /// MCP - Keep a pointer to constantpool entries of the current
  33. /// MachineFunction.
  34. const MachineConstantPool *MCP;
  35. /// InConstantPool - Maintain state when emitting a sequence of constant
  36. /// pool entries so we can properly mark them as data regions.
  37. bool InConstantPool;
  38. /// ThumbIndirectPads - These maintain a per-function list of jump pad
  39. /// labels used for ARMv4t thumb code to make register indirect calls.
  40. SmallVector<std::pair<unsigned, MCSymbol*>, 4> ThumbIndirectPads;
  41. /// OptimizationGoals - Maintain a combined optimization goal for all
  42. /// functions in a module: one of Tag_ABI_optimization_goals values,
  43. /// -1 if uninitialized, 0 if conflicting goals
  44. int OptimizationGoals;
  45. /// List of globals that have had their storage promoted to a constant
  46. /// pool. This lives between calls to runOnMachineFunction and collects
  47. /// data from every MachineFunction. It is used during doFinalization
  48. /// when all non-function globals are emitted.
  49. SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;
  50. /// Set of globals in PromotedGlobals that we've emitted labels for.
  51. /// We need to emit labels even for promoted globals so that DWARF
  52. /// debug info can link properly.
  53. SmallPtrSet<const GlobalVariable*,2> EmittedPromotedGlobalLabels;
  54. public:
  55. explicit ARMAsmPrinter(TargetMachine &TM,
  56. std::unique_ptr<MCStreamer> Streamer);
  57. StringRef getPassName() const override {
  58. return "ARM Assembly Printer";
  59. }
  60. void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
  61. void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &O) override;
  62. bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
  63. const char *ExtraCode, raw_ostream &O) override;
  64. bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
  65. const char *ExtraCode, raw_ostream &O) override;
  66. void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
  67. const MCSubtargetInfo *EndInfo) const override;
  68. void emitJumpTableAddrs(const MachineInstr *MI);
  69. void emitJumpTableInsts(const MachineInstr *MI);
  70. void emitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth);
  71. void emitInstruction(const MachineInstr *MI) override;
  72. bool runOnMachineFunction(MachineFunction &F) override;
  73. void emitConstantPool() override {
  74. // we emit constant pools customly!
  75. }
  76. void emitFunctionBodyEnd() override;
  77. void emitFunctionEntryLabel() override;
  78. void emitStartOfAsmFile(Module &M) override;
  79. void emitEndOfAsmFile(Module &M) override;
  80. void emitXXStructor(const DataLayout &DL, const Constant *CV) override;
  81. void emitGlobalVariable(const GlobalVariable *GV) override;
  82. MCSymbol *GetCPISymbol(unsigned CPID) const override;
  83. // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
  84. bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
  85. //===------------------------------------------------------------------===//
  86. // XRay implementation
  87. //===------------------------------------------------------------------===//
  88. public:
  89. // XRay-specific lowering for ARM.
  90. void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
  91. void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
  92. void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
  93. private:
  94. void EmitSled(const MachineInstr &MI, SledKind Kind);
  95. // Helpers for emitStartOfAsmFile() and emitEndOfAsmFile()
  96. void emitAttributes();
  97. // Generic helper used to emit e.g. ARMv5 mul pseudos
  98. void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
  99. void EmitUnwindingInstruction(const MachineInstr *MI);
  100. // emitPseudoExpansionLowering - tblgen'erated.
  101. bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
  102. const MachineInstr *MI);
  103. public:
  104. unsigned getISAEncoding() override {
  105. // ARM/Darwin adds ISA to the DWARF info for each function.
  106. const Triple &TT = TM.getTargetTriple();
  107. if (!TT.isOSBinFormatMachO())
  108. return 0;
  109. bool isThumb = TT.isThumb() ||
  110. TT.getSubArch() == Triple::ARMSubArch_v7m ||
  111. TT.getSubArch() == Triple::ARMSubArch_v6m;
  112. return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
  113. }
  114. private:
  115. MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
  116. MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;
  117. MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
  118. public:
  119. /// EmitMachineConstantPoolValue - Print a machine constantpool value to
  120. /// the .s file.
  121. void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
  122. };
  123. } // end namespace llvm
  124. #endif