blob: 0ba4bc05d6f7719f1e65f133e4009d3d9622b485 [file] [log] [blame]
Eli Bendersky6aa4fc32013-02-19 16:47:59 +00001//===-- ARMAsmPrinter.h - ARM implementation of AsmPrinter ------*- C++ -*-===//
Jim Grosbachd0d13292010-12-01 03:45:07 +00002//
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//===----------------------------------------------------------------------===//
Jim Grosbachd0d13292010-12-01 03:45:07 +00009
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
11#define LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
Jim Grosbachd0d13292010-12-01 03:45:07 +000012
Craig Toppera9253262014-03-22 23:51:00 +000013#include "ARMSubtarget.h"
Jim Grosbachd0d13292010-12-01 03:45:07 +000014#include "llvm/CodeGen/AsmPrinter.h"
Craig Toppera9253262014-03-22 23:51:00 +000015#include "llvm/Target/TargetMachine.h"
Jim Grosbachd0d13292010-12-01 03:45:07 +000016
17namespace llvm {
18
Craig Toppera9253262014-03-22 23:51:00 +000019class ARMFunctionInfo;
Jim Grosbach95dee402011-07-08 17:40:42 +000020class MCOperand;
Craig Toppera9253262014-03-22 23:51:00 +000021class MachineConstantPool;
22class MachineOperand;
Jonathan Roelofs300d8ff2014-12-04 19:34:50 +000023class MCSymbol;
Jim Grosbach95dee402011-07-08 17:40:42 +000024
Jim Grosbachd0d13292010-12-01 03:45:07 +000025namespace ARM {
26 enum DW_ISA {
27 DW_ISA_ARM_thumb = 1,
28 DW_ISA_ARM_arm = 2
29 };
30}
31
32class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
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
Jim Grosbach4b63d2a2012-05-18 19:12:01 +000046 /// InConstantPool - Maintain state when emitting a sequence of constant
47 /// pool entries so we can properly mark them as data regions.
48 bool InConstantPool;
Jonathan Roelofs300d8ff2014-12-04 19:34:50 +000049
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
Artyom Skrobove9b3fb82015-12-07 14:22:39 +000054 /// 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
James Molloy9abb2fa2016-09-26 07:26:24 +000059 /// 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;
68
Jim Grosbachd0d13292010-12-01 03:45:07 +000069public:
David Blaikie94598322015-01-18 20:29:04 +000070 explicit ARMAsmPrinter(TargetMachine &TM,
71 std::unique_ptr<MCStreamer> Streamer);
Jim Grosbachd0d13292010-12-01 03:45:07 +000072
Mehdi Amini117296c2016-10-01 02:56:57 +000073 StringRef getPassName() const override {
Davide Italianoa22dddd2016-11-10 18:39:31 +000074 return "ARM Assembly Printer";
Jim Grosbachd0d13292010-12-01 03:45:07 +000075 }
76
Tim Northoverb4c61f82015-05-13 20:28:41 +000077 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
Jim Grosbachd0d13292010-12-01 03:45:07 +000078
Craig Topper24e685f2014-03-10 05:29:18 +000079 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;
Jim Grosbachd0d13292010-12-01 03:45:07 +000085
Craig Topper24e685f2014-03-10 05:29:18 +000086 void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
87 const MCSubtargetInfo *EndInfo) const override;
Rafael Espindola65fd0a82014-01-24 15:47:54 +000088
Tim Northovera603c402015-05-31 19:22:07 +000089 void EmitJumpTableAddrs(const MachineInstr *MI);
90 void EmitJumpTableInsts(const MachineInstr *MI);
91 void EmitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth);
Craig Topper24e685f2014-03-10 05:29:18 +000092 void EmitInstruction(const MachineInstr *MI) override;
93 bool runOnMachineFunction(MachineFunction &F) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000094
Craig Topper24e685f2014-03-10 05:29:18 +000095 void EmitConstantPool() override {
Craig Topperdb092d72012-10-09 04:23:49 +000096 // we emit constant pools customly!
97 }
Craig Topper24e685f2014-03-10 05:29:18 +000098 void EmitFunctionBodyEnd() override;
99 void EmitFunctionEntryLabel() override;
100 void EmitStartOfAsmFile(Module &M) override;
101 void EmitEndOfAsmFile(Module &M) override;
Mehdi Aminibd7287e2015-07-16 06:11:10 +0000102 void EmitXXStructor(const DataLayout &DL, const Constant *CV) override;
James Molloy9abb2fa2016-09-26 07:26:24 +0000103 void EmitGlobalVariable(const GlobalVariable *GV) override;
Martin Storsjod2662c32018-07-25 18:35:31 +0000104
Martin Storsjod78b3942018-07-25 19:01:36 +0000105 MCSymbol *GetCPISymbol(unsigned CPID) const override;
Martin Storsjod2662c32018-07-25 18:35:31 +0000106
Jim Grosbach95dee402011-07-08 17:40:42 +0000107 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
108 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
109
Dean Michael Berris464015442016-09-19 00:54:35 +0000110 //===------------------------------------------------------------------===//
111 // XRay implementation
112 //===------------------------------------------------------------------===//
113public:
114 // XRay-specific lowering for ARM.
115 void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
116 void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
Dean Michael Berris156f6ca2016-10-18 05:54:15 +0000117 void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
Dean Michael Berris464015442016-09-19 00:54:35 +0000118
Jim Grosbachd0d13292010-12-01 03:45:07 +0000119private:
Dean Michael Berris464015442016-09-19 00:54:35 +0000120 void EmitSled(const MachineInstr &MI, SledKind Kind);
Rafael Espindola3d6a1302016-06-21 14:21:53 +0000121
Jim Grosbachd0d13292010-12-01 03:45:07 +0000122 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
123 void emitAttributes();
124
Anton Korobeynikov62acecd2011-01-01 20:38:38 +0000125 // Generic helper used to emit e.g. ARMv5 mul pseudos
126 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
127
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000128 void EmitUnwindingInstruction(const MachineInstr *MI);
129
Jim Grosbach95dee402011-07-08 17:40:42 +0000130 // emitPseudoExpansionLowering - tblgen'erated.
131 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
132 const MachineInstr *MI);
133
Jim Grosbachd0d13292010-12-01 03:45:07 +0000134public:
Eric Christophercd53d6e2015-03-21 03:13:01 +0000135 unsigned getISAEncoding() override {
Jim Grosbachd0d13292010-12-01 03:45:07 +0000136 // ARM/Darwin adds ISA to the DWARF info for each function.
Daniel Sandersc81f4502015-06-16 15:44:21 +0000137 const Triple &TT = TM.getTargetTriple();
Eric Christophera49d68e2015-02-17 20:02:32 +0000138 if (!TT.isOSBinFormatMachO())
Jim Grosbachd0d13292010-12-01 03:45:07 +0000139 return 0;
Florian Hahna5ba4ee2017-08-12 17:40:18 +0000140 bool isThumb = TT.isThumb() ||
Eric Christophercd53d6e2015-03-21 03:13:01 +0000141 TT.getSubArch() == Triple::ARMSubArch_v7m ||
142 TT.getSubArch() == Triple::ARMSubArch_v6m;
143 return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000144 }
145
Craig Topperdb092d72012-10-09 04:23:49 +0000146private:
Jim Grosbach95dee402011-07-08 17:40:42 +0000147 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
Tim Northover4998a472015-05-13 20:28:38 +0000148 MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000149
Tim Northoverdb962e2c2013-11-25 16:24:52 +0000150 MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
Jim Grosbach95dee402011-07-08 17:40:42 +0000151
Craig Topperdb092d72012-10-09 04:23:49 +0000152public:
Jim Grosbachd0d13292010-12-01 03:45:07 +0000153 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
154 /// the .s file.
Craig Topper24e685f2014-03-10 05:29:18 +0000155 void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000156};
157} // end namespace llvm
158
159#endif