blob: a4b37fa2331f62e5e37d94e239e270cbe59f06ca [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//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Jim Grosbachd0d13292010-12-01 03:45:07 +00006//
7//===----------------------------------------------------------------------===//
Jim Grosbachd0d13292010-12-01 03:45:07 +00008
Benjamin Kramera7c40ef2014-08-13 16:26:38 +00009#ifndef LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
10#define LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
Jim Grosbachd0d13292010-12-01 03:45:07 +000011
Craig Toppera9253262014-03-22 23:51:00 +000012#include "ARMSubtarget.h"
Jim Grosbachd0d13292010-12-01 03:45:07 +000013#include "llvm/CodeGen/AsmPrinter.h"
Craig Toppera9253262014-03-22 23:51:00 +000014#include "llvm/Target/TargetMachine.h"
Jim Grosbachd0d13292010-12-01 03:45:07 +000015
16namespace llvm {
17
Craig Toppera9253262014-03-22 23:51:00 +000018class ARMFunctionInfo;
Jim Grosbach95dee402011-07-08 17:40:42 +000019class MCOperand;
Craig Toppera9253262014-03-22 23:51:00 +000020class MachineConstantPool;
21class MachineOperand;
Jonathan Roelofs300d8ff2014-12-04 19:34:50 +000022class MCSymbol;
Jim Grosbach95dee402011-07-08 17:40:42 +000023
Jim Grosbachd0d13292010-12-01 03:45:07 +000024namespace ARM {
25 enum DW_ISA {
26 DW_ISA_ARM_thumb = 1,
27 DW_ISA_ARM_arm = 2
28 };
29}
30
31class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
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
Jim Grosbach4b63d2a2012-05-18 19:12:01 +000045 /// InConstantPool - Maintain state when emitting a sequence of constant
46 /// pool entries so we can properly mark them as data regions.
47 bool InConstantPool;
Jonathan Roelofs300d8ff2014-12-04 19:34:50 +000048
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
Artyom Skrobove9b3fb82015-12-07 14:22:39 +000053 /// 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
James Molloy9abb2fa2016-09-26 07:26:24 +000058 /// 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.
62 SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;
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
Jim Grosbachd0d13292010-12-01 03:45:07 +000068public:
David Blaikie94598322015-01-18 20:29:04 +000069 explicit ARMAsmPrinter(TargetMachine &TM,
70 std::unique_ptr<MCStreamer> Streamer);
Jim Grosbachd0d13292010-12-01 03:45:07 +000071
Mehdi Amini117296c2016-10-01 02:56:57 +000072 StringRef getPassName() const override {
Davide Italianoa22dddd2016-11-10 18:39:31 +000073 return "ARM Assembly Printer";
Jim Grosbachd0d13292010-12-01 03:45:07 +000074 }
75
Tim Northoverb4c61f82015-05-13 20:28:41 +000076 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
Jim Grosbachd0d13292010-12-01 03:45:07 +000077
Nick Desaulniers7ab164c2019-04-26 18:45:04 +000078 void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &O) override;
Craig Topper24e685f2014-03-10 05:29:18 +000079 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
Nick Desaulniers5277b3f2019-04-10 16:38:43 +000080 const char *ExtraCode, raw_ostream &O) override;
Craig Topper24e685f2014-03-10 05:29:18 +000081 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
Nick Desaulniers5277b3f2019-04-10 16:38:43 +000082 const char *ExtraCode, raw_ostream &O) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000083
Craig Topper24e685f2014-03-10 05:29:18 +000084 void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
85 const MCSubtargetInfo *EndInfo) const override;
Rafael Espindola65fd0a82014-01-24 15:47:54 +000086
Tim Northovera603c402015-05-31 19:22:07 +000087 void EmitJumpTableAddrs(const MachineInstr *MI);
88 void EmitJumpTableInsts(const MachineInstr *MI);
89 void EmitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth);
Craig Topper24e685f2014-03-10 05:29:18 +000090 void EmitInstruction(const MachineInstr *MI) override;
91 bool runOnMachineFunction(MachineFunction &F) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000092
Craig Topper24e685f2014-03-10 05:29:18 +000093 void EmitConstantPool() override {
Craig Topperdb092d72012-10-09 04:23:49 +000094 // we emit constant pools customly!
95 }
Craig Topper24e685f2014-03-10 05:29:18 +000096 void EmitFunctionBodyEnd() override;
97 void EmitFunctionEntryLabel() override;
98 void EmitStartOfAsmFile(Module &M) override;
99 void EmitEndOfAsmFile(Module &M) override;
Mehdi Aminibd7287e2015-07-16 06:11:10 +0000100 void EmitXXStructor(const DataLayout &DL, const Constant *CV) override;
James Molloy9abb2fa2016-09-26 07:26:24 +0000101 void EmitGlobalVariable(const GlobalVariable *GV) override;
Martin Storsjod2662c32018-07-25 18:35:31 +0000102
Martin Storsjod78b3942018-07-25 19:01:36 +0000103 MCSymbol *GetCPISymbol(unsigned CPID) const override;
Martin Storsjod2662c32018-07-25 18:35:31 +0000104
Jim Grosbach95dee402011-07-08 17:40:42 +0000105 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
106 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
107
Dean Michael Berris464015442016-09-19 00:54:35 +0000108 //===------------------------------------------------------------------===//
109 // XRay implementation
110 //===------------------------------------------------------------------===//
111public:
112 // XRay-specific lowering for ARM.
113 void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
114 void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
Dean Michael Berris156f6ca2016-10-18 05:54:15 +0000115 void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
Dean Michael Berris464015442016-09-19 00:54:35 +0000116
Jim Grosbachd0d13292010-12-01 03:45:07 +0000117private:
Dean Michael Berris464015442016-09-19 00:54:35 +0000118 void EmitSled(const MachineInstr &MI, SledKind Kind);
Rafael Espindola3d6a1302016-06-21 14:21:53 +0000119
Jim Grosbachd0d13292010-12-01 03:45:07 +0000120 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
121 void emitAttributes();
122
Anton Korobeynikov62acecd2011-01-01 20:38:38 +0000123 // Generic helper used to emit e.g. ARMv5 mul pseudos
124 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
125
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000126 void EmitUnwindingInstruction(const MachineInstr *MI);
127
Jim Grosbach95dee402011-07-08 17:40:42 +0000128 // emitPseudoExpansionLowering - tblgen'erated.
129 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
130 const MachineInstr *MI);
131
Jim Grosbachd0d13292010-12-01 03:45:07 +0000132public:
Eric Christophercd53d6e2015-03-21 03:13:01 +0000133 unsigned getISAEncoding() override {
Jim Grosbachd0d13292010-12-01 03:45:07 +0000134 // ARM/Darwin adds ISA to the DWARF info for each function.
Daniel Sandersc81f4502015-06-16 15:44:21 +0000135 const Triple &TT = TM.getTargetTriple();
Eric Christophera49d68e2015-02-17 20:02:32 +0000136 if (!TT.isOSBinFormatMachO())
Jim Grosbachd0d13292010-12-01 03:45:07 +0000137 return 0;
Florian Hahna5ba4ee2017-08-12 17:40:18 +0000138 bool isThumb = TT.isThumb() ||
Eric Christophercd53d6e2015-03-21 03:13:01 +0000139 TT.getSubArch() == Triple::ARMSubArch_v7m ||
140 TT.getSubArch() == Triple::ARMSubArch_v6m;
141 return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000142 }
143
Craig Topperdb092d72012-10-09 04:23:49 +0000144private:
Jim Grosbach95dee402011-07-08 17:40:42 +0000145 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
Tim Northover4998a472015-05-13 20:28:38 +0000146 MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000147
Tim Northoverdb962e2c2013-11-25 16:24:52 +0000148 MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
Jim Grosbach95dee402011-07-08 17:40:42 +0000149
Craig Topperdb092d72012-10-09 04:23:49 +0000150public:
Jim Grosbachd0d13292010-12-01 03:45:07 +0000151 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
152 /// the .s file.
Craig Topper24e685f2014-03-10 05:29:18 +0000153 void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000154};
155} // end namespace llvm
156
157#endif