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