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;
60 explicit ARMAsmPrinter(TargetMachine &TM,
61 std::unique_ptr<MCStreamer> Streamer);
63 const char *getPassName() const override {
64 return "ARM Assembly / Object Emitter";
67 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
69 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
70 unsigned AsmVariant, const char *ExtraCode,
71 raw_ostream &O) override;
72 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
73 unsigned AsmVariant, const char *ExtraCode,
74 raw_ostream &O) override;
76 void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
77 const MCSubtargetInfo *EndInfo) const override;
79 void EmitJumpTableAddrs(const MachineInstr *MI);
80 void EmitJumpTableInsts(const MachineInstr *MI);
81 void EmitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth);
82 void EmitInstruction(const MachineInstr *MI) override;
83 bool runOnMachineFunction(MachineFunction &F) override;
85 void EmitConstantPool() override {
86 // we emit constant pools customly!
88 void EmitFunctionBodyEnd() override;
89 void EmitFunctionEntryLabel() override;
90 void EmitStartOfAsmFile(Module &M) override;
91 void EmitEndOfAsmFile(Module &M) override;
92 void EmitXXStructor(const DataLayout &DL, const Constant *CV) override;
94 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
95 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
98 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
99 void emitAttributes();
101 // Generic helper used to emit e.g. ARMv5 mul pseudos
102 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
104 void EmitUnwindingInstruction(const MachineInstr *MI);
106 // emitPseudoExpansionLowering - tblgen'erated.
107 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
108 const MachineInstr *MI);
111 unsigned getISAEncoding() override {
112 // ARM/Darwin adds ISA to the DWARF info for each function.
113 const Triple &TT = TM.getTargetTriple();
114 if (!TT.isOSBinFormatMachO())
116 bool isThumb = TT.getArch() == Triple::thumb ||
117 TT.getArch() == Triple::thumbeb ||
118 TT.getSubArch() == Triple::ARMSubArch_v7m ||
119 TT.getSubArch() == Triple::ARMSubArch_v6m;
120 return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
124 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
125 MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;
127 MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
130 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
132 void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
134 } // end namespace llvm