LLVM  9.0.0svn
ARMAsmPrinter.h
Go to the documentation of this file.
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 
9 #ifndef LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
10 #define LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
11 
12 #include "ARMSubtarget.h"
15 
16 namespace llvm {
17 
18 class ARMFunctionInfo;
19 class MCOperand;
20 class MachineConstantPool;
21 class MachineOperand;
22 class MCSymbol;
23 
24 namespace ARM {
25  enum DW_ISA {
28  };
29 }
30 
32 
33  /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
34  /// make the right decision when printing asm code for different targets.
35  const ARMSubtarget *Subtarget;
36 
37  /// AFI - Keep a pointer to ARMFunctionInfo for the current
38  /// MachineFunction.
39  ARMFunctionInfo *AFI;
40 
41  /// MCP - Keep a pointer to constantpool entries of the current
42  /// MachineFunction.
43  const MachineConstantPool *MCP;
44 
45  /// InConstantPool - Maintain state when emitting a sequence of constant
46  /// pool entries so we can properly mark them as data regions.
47  bool InConstantPool;
48 
49  /// ThumbIndirectPads - These maintain a per-function list of jump pad
50  /// labels used for ARMv4t thumb code to make register indirect calls.
51  SmallVector<std::pair<unsigned, MCSymbol*>, 4> ThumbIndirectPads;
52 
53  /// OptimizationGoals - Maintain a combined optimization goal for all
54  /// functions in a module: one of Tag_ABI_optimization_goals values,
55  /// -1 if uninitialized, 0 if conflicting goals
56  int OptimizationGoals;
57 
58  /// List of globals that have had their storage promoted to a constant
59  /// pool. This lives between calls to runOnMachineFunction and collects
60  /// data from every MachineFunction. It is used during doFinalization
61  /// when all non-function globals are emitted.
63  /// Set of globals in PromotedGlobals that we've emitted labels for.
64  /// We need to emit labels even for promoted globals so that DWARF
65  /// debug info can link properly.
66  SmallPtrSet<const GlobalVariable*,2> EmittedPromotedGlobalLabels;
67 
68 public:
69  explicit ARMAsmPrinter(TargetMachine &TM,
70  std::unique_ptr<MCStreamer> Streamer);
71 
72  StringRef getPassName() const override {
73  return "ARM Assembly Printer";
74  }
75 
76  void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
77 
78  bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
79  unsigned AsmVariant, const char *ExtraCode,
80  raw_ostream &O) override;
81  bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
82  unsigned AsmVariant, const char *ExtraCode,
83  raw_ostream &O) override;
84 
85  void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
86  const MCSubtargetInfo *EndInfo) const override;
87 
88  void EmitJumpTableAddrs(const MachineInstr *MI);
89  void EmitJumpTableInsts(const MachineInstr *MI);
90  void EmitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth);
91  void EmitInstruction(const MachineInstr *MI) override;
92  bool runOnMachineFunction(MachineFunction &F) override;
93 
94  void EmitConstantPool() override {
95  // we emit constant pools customly!
96  }
97  void EmitFunctionBodyEnd() override;
98  void EmitFunctionEntryLabel() override;
99  void EmitStartOfAsmFile(Module &M) override;
100  void EmitEndOfAsmFile(Module &M) override;
101  void EmitXXStructor(const DataLayout &DL, const Constant *CV) override;
102  void EmitGlobalVariable(const GlobalVariable *GV) override;
103 
104  MCSymbol *GetCPISymbol(unsigned CPID) const override;
105 
106  // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
107  bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
108 
109  //===------------------------------------------------------------------===//
110  // XRay implementation
111  //===------------------------------------------------------------------===//
112 public:
113  // XRay-specific lowering for ARM.
114  void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
115  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
116  void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
117 
118 private:
119  void EmitSled(const MachineInstr &MI, SledKind Kind);
120 
121  // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
122  void emitAttributes();
123 
124  // Generic helper used to emit e.g. ARMv5 mul pseudos
125  void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
126 
127  void EmitUnwindingInstruction(const MachineInstr *MI);
128 
129  // emitPseudoExpansionLowering - tblgen'erated.
130  bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
131  const MachineInstr *MI);
132 
133 public:
134  unsigned getISAEncoding() override {
135  // ARM/Darwin adds ISA to the DWARF info for each function.
136  const Triple &TT = TM.getTargetTriple();
137  if (!TT.isOSBinFormatMachO())
138  return 0;
139  bool isThumb = TT.isThumb() ||
142  return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
143  }
144 
145 private:
147  MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;
148 
149  MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
150 
151 public:
152  /// EmitMachineConstantPoolValue - Print a machine constantpool value to
153  /// the .s file.
154  void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
155 };
156 } // end namespace llvm
157 
158 #endif
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:110
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
void EmitConstantPool() override
Print to the current output stream assembly representations of the constants in the constant pool MCP...
Definition: ARMAsmPrinter.h:94
unsigned getISAEncoding() override
Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
F(f)
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: ARMAsmPrinter.h:72
static bool isThumb(const MCSubtargetInfo &STI)
SubArchType getSubArch() const
getSubArch - get the parsed subarchitecture type for this triple.
Definition: Triple.h:293
Streaming machine code generation interface.
Definition: MCStreamer.h:188
This is an important base class in LLVM.
Definition: Constant.h:41
static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol, HexagonAsmPrinter &Printer, bool MustExtend)
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
const Triple & getTargetTriple() const
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
Definition: Compiler.h:107
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:618
Abstract base class for all machine specific constantpool value subclasses.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:417
MachineOperand class - Representation of each machine instruction operand.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:841
Representation of each machine instruction.
Definition: MachineInstr.h:63
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
bool isThumb() const
Tests whether the target is Thumb (little and big endian).
Definition: Triple.h:674
ARMFunctionInfo - This class is derived from MachineFunctionInfo and contains private ARM-specific in...
Generic base class for all target subtargets.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:34