1 //===-- ARMAsmPrinter.h - ARM implementation of AsmPrinter ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
11 #define LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
13 #include "ARMSubtarget.h"
14 #include "llvm/CodeGen/AsmPrinter.h"
15 #include "llvm/Target/TargetMachine.h"
19 class ARMFunctionInfo;
21 class MachineConstantPool;
32 class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
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;
38 /// AFI - Keep a pointer to ARMFunctionInfo for the current
42 /// MCP - Keep a pointer to constantpool entries of the current
44 const MachineConstantPool *MCP;
46 /// InConstantPool - Maintain state when emitting a sequence of constant
47 /// pool entries so we can properly mark them as data regions.
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;
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;
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.
63 SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;
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;
70 explicit ARMAsmPrinter(TargetMachine &TM,
71 std::unique_ptr<MCStreamer> Streamer);
73 StringRef getPassName() const override {
74 return "ARM Assembly Printer";
77 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
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;
86 void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
87 const MCSubtargetInfo *EndInfo) const override;
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;
95 void EmitConstantPool() override {
96 // we emit constant pools customly!
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;
105 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
106 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
108 //===------------------------------------------------------------------===//
109 // XRay implementation
110 //===------------------------------------------------------------------===//
112 // XRay-specific lowering for ARM.
113 void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
114 void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
115 void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
118 void EmitSled(const MachineInstr &MI, SledKind Kind);
120 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
121 void emitAttributes();
123 // Generic helper used to emit e.g. ARMv5 mul pseudos
124 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
126 void EmitUnwindingInstruction(const MachineInstr *MI);
128 // emitPseudoExpansionLowering - tblgen'erated.
129 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
130 const MachineInstr *MI);
133 unsigned getISAEncoding() override {
134 // ARM/Darwin adds ISA to the DWARF info for each function.
135 const Triple &TT = TM.getTargetTriple();
136 if (!TT.isOSBinFormatMachO())
138 bool isThumb = TT.isThumb() ||
139 TT.getSubArch() == Triple::ARMSubArch_v7m ||
140 TT.getSubArch() == Triple::ARMSubArch_v6m;
141 return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
145 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
146 MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;
148 MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
151 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
153 void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
155 } // end namespace llvm