blob: ed7be2de51ca725515297519e892506b1e0b954b [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
Jim Grosbachd0d13292010-12-01 03:45:07 +000059public:
David Blaikie94598322015-01-18 20:29:04 +000060 explicit ARMAsmPrinter(TargetMachine &TM,
61 std::unique_ptr<MCStreamer> Streamer);
Jim Grosbachd0d13292010-12-01 03:45:07 +000062
Craig Topper24e685f2014-03-10 05:29:18 +000063 const char *getPassName() const override {
Eli Bendersky6aa4fc32013-02-19 16:47:59 +000064 return "ARM Assembly / Object Emitter";
Jim Grosbachd0d13292010-12-01 03:45:07 +000065 }
66
Tim Northoverb4c61f82015-05-13 20:28:41 +000067 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
Jim Grosbachd0d13292010-12-01 03:45:07 +000068
Craig Topper24e685f2014-03-10 05:29:18 +000069 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;
Jim Grosbachd0d13292010-12-01 03:45:07 +000075
Craig Topper24e685f2014-03-10 05:29:18 +000076 void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
77 const MCSubtargetInfo *EndInfo) const override;
Rafael Espindola65fd0a82014-01-24 15:47:54 +000078
Tim Northovera603c402015-05-31 19:22:07 +000079 void EmitJumpTableAddrs(const MachineInstr *MI);
80 void EmitJumpTableInsts(const MachineInstr *MI);
81 void EmitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth);
Craig Topper24e685f2014-03-10 05:29:18 +000082 void EmitInstruction(const MachineInstr *MI) override;
83 bool runOnMachineFunction(MachineFunction &F) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000084
Craig Topper24e685f2014-03-10 05:29:18 +000085 void EmitConstantPool() override {
Craig Topperdb092d72012-10-09 04:23:49 +000086 // we emit constant pools customly!
87 }
Craig Topper24e685f2014-03-10 05:29:18 +000088 void EmitFunctionBodyEnd() override;
89 void EmitFunctionEntryLabel() override;
90 void EmitStartOfAsmFile(Module &M) override;
91 void EmitEndOfAsmFile(Module &M) override;
Mehdi Aminibd7287e2015-07-16 06:11:10 +000092 void EmitXXStructor(const DataLayout &DL, const Constant *CV) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000093
Jim Grosbach95dee402011-07-08 17:40:42 +000094 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
95 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
96
Jim Grosbachd0d13292010-12-01 03:45:07 +000097private:
98 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
99 void emitAttributes();
100
Anton Korobeynikov62acecd2011-01-01 20:38:38 +0000101 // Generic helper used to emit e.g. ARMv5 mul pseudos
102 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
103
Anton Korobeynikove7410dd2011-03-05 18:43:32 +0000104 void EmitUnwindingInstruction(const MachineInstr *MI);
105
Jim Grosbach95dee402011-07-08 17:40:42 +0000106 // emitPseudoExpansionLowering - tblgen'erated.
107 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
108 const MachineInstr *MI);
109
Jim Grosbachd0d13292010-12-01 03:45:07 +0000110public:
Eric Christophercd53d6e2015-03-21 03:13:01 +0000111 unsigned getISAEncoding() override {
Jim Grosbachd0d13292010-12-01 03:45:07 +0000112 // ARM/Darwin adds ISA to the DWARF info for each function.
Daniel Sandersc81f4502015-06-16 15:44:21 +0000113 const Triple &TT = TM.getTargetTriple();
Eric Christophera49d68e2015-02-17 20:02:32 +0000114 if (!TT.isOSBinFormatMachO())
Jim Grosbachd0d13292010-12-01 03:45:07 +0000115 return 0;
Eric Christophercd53d6e2015-03-21 03:13:01 +0000116 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;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000121 }
122
Craig Topperdb092d72012-10-09 04:23:49 +0000123private:
Jim Grosbach95dee402011-07-08 17:40:42 +0000124 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
Tim Northover4998a472015-05-13 20:28:38 +0000125 MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000126
Tim Northoverdb962e2c2013-11-25 16:24:52 +0000127 MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
Jim Grosbach95dee402011-07-08 17:40:42 +0000128
Craig Topperdb092d72012-10-09 04:23:49 +0000129public:
Jim Grosbachd0d13292010-12-01 03:45:07 +0000130 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
131 /// the .s file.
Craig Topper24e685f2014-03-10 05:29:18 +0000132 void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000133};
134} // end namespace llvm
135
136#endif