blob: 0db0a0f5f921c29dc8ae6cd50a5dba104f7b3fa7 [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 Molloy0dc47082016-09-16 10:17:04 +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
Jim Grosbachd0d13292010-12-01 03:45:07 +000065public:
David Blaikie94598322015-01-18 20:29:04 +000066 explicit ARMAsmPrinter(TargetMachine &TM,
67 std::unique_ptr<MCStreamer> Streamer);
Jim Grosbachd0d13292010-12-01 03:45:07 +000068
Craig Topper24e685f2014-03-10 05:29:18 +000069 const char *getPassName() const override {
Eli Bendersky6aa4fc32013-02-19 16:47:59 +000070 return "ARM Assembly / Object Emitter";
Jim Grosbachd0d13292010-12-01 03:45:07 +000071 }
72
Tim Northoverb4c61f82015-05-13 20:28:41 +000073 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
Jim Grosbachd0d13292010-12-01 03:45:07 +000074
Craig Topper24e685f2014-03-10 05:29:18 +000075 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
76 unsigned AsmVariant, const char *ExtraCode,
77 raw_ostream &O) override;
78 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
79 unsigned AsmVariant, const char *ExtraCode,
80 raw_ostream &O) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000081
Craig Topper24e685f2014-03-10 05:29:18 +000082 void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
83 const MCSubtargetInfo *EndInfo) const override;
Rafael Espindola65fd0a82014-01-24 15:47:54 +000084
Tim Northovera603c402015-05-31 19:22:07 +000085 void EmitJumpTableAddrs(const MachineInstr *MI);
86 void EmitJumpTableInsts(const MachineInstr *MI);
87 void EmitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth);
Craig Topper24e685f2014-03-10 05:29:18 +000088 void EmitInstruction(const MachineInstr *MI) override;
89 bool runOnMachineFunction(MachineFunction &F) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000090
Craig Topper24e685f2014-03-10 05:29:18 +000091 void EmitConstantPool() override {
Craig Topperdb092d72012-10-09 04:23:49 +000092 // we emit constant pools customly!
93 }
Craig Topper24e685f2014-03-10 05:29:18 +000094 void EmitFunctionBodyEnd() override;
95 void EmitFunctionEntryLabel() override;
96 void EmitStartOfAsmFile(Module &M) override;
97 void EmitEndOfAsmFile(Module &M) override;
Mehdi Aminibd7287e2015-07-16 06:11:10 +000098 void EmitXXStructor(const DataLayout &DL, const Constant *CV) override;
James Molloy0dc47082016-09-16 10:17:04 +000099 void EmitGlobalVariable(const GlobalVariable *GV) override;
100
Jim Grosbach95dee402011-07-08 17:40:42 +0000101 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
102 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
103
Dean Michael Berris464015442016-09-19 00:54:35 +0000104 //===------------------------------------------------------------------===//
105 // XRay implementation
106 //===------------------------------------------------------------------===//
107public:
108 // XRay-specific lowering for ARM.
109 void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
110 void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
111 // Helper function that emits the XRay sleds we've collected for a particular
112 // function.
113 void EmitXRayTable();
114
Jim Grosbachd0d13292010-12-01 03:45:07 +0000115private:
Dean Michael Berris464015442016-09-19 00:54:35 +0000116 void EmitSled(const MachineInstr &MI, SledKind Kind);
Rafael Espindola3d6a1302016-06-21 14:21:53 +0000117
Jim Grosbachd0d13292010-12-01 03:45:07 +0000118 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
119 void emitAttributes();
120
Anton Korobeynikov62acecd2011-01-01 20:38:38 +0000121 // Generic helper used to emit e.g. ARMv5 mul pseudos
122 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
123
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000124 void EmitUnwindingInstruction(const MachineInstr *MI);
125
Jim Grosbach95dee402011-07-08 17:40:42 +0000126 // emitPseudoExpansionLowering - tblgen'erated.
127 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
128 const MachineInstr *MI);
129
Jim Grosbachd0d13292010-12-01 03:45:07 +0000130public:
Eric Christophercd53d6e2015-03-21 03:13:01 +0000131 unsigned getISAEncoding() override {
Jim Grosbachd0d13292010-12-01 03:45:07 +0000132 // ARM/Darwin adds ISA to the DWARF info for each function.
Daniel Sandersc81f4502015-06-16 15:44:21 +0000133 const Triple &TT = TM.getTargetTriple();
Eric Christophera49d68e2015-02-17 20:02:32 +0000134 if (!TT.isOSBinFormatMachO())
Jim Grosbachd0d13292010-12-01 03:45:07 +0000135 return 0;
Eric Christophercd53d6e2015-03-21 03:13:01 +0000136 bool isThumb = TT.getArch() == Triple::thumb ||
137 TT.getArch() == Triple::thumbeb ||
138 TT.getSubArch() == Triple::ARMSubArch_v7m ||
139 TT.getSubArch() == Triple::ARMSubArch_v6m;
140 return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000141 }
142
Craig Topperdb092d72012-10-09 04:23:49 +0000143private:
Jim Grosbach95dee402011-07-08 17:40:42 +0000144 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
Tim Northover4998a472015-05-13 20:28:38 +0000145 MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000146
Tim Northoverdb962e2c2013-11-25 16:24:52 +0000147 MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
Jim Grosbach95dee402011-07-08 17:40:42 +0000148
Craig Topperdb092d72012-10-09 04:23:49 +0000149public:
Jim Grosbachd0d13292010-12-01 03:45:07 +0000150 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
151 /// the .s file.
Craig Topper24e685f2014-03-10 05:29:18 +0000152 void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000153};
154} // end namespace llvm
155
156#endif