blob: 3d251213f5bf0780b38a5fab0fe993a4c5031fb9 [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
Jim Grosbachd0d13292010-12-01 03:45:07 +000054public:
David Blaikie94598322015-01-18 20:29:04 +000055 explicit ARMAsmPrinter(TargetMachine &TM,
56 std::unique_ptr<MCStreamer> Streamer);
Jim Grosbachd0d13292010-12-01 03:45:07 +000057
Craig Topper24e685f2014-03-10 05:29:18 +000058 const char *getPassName() const override {
Eli Bendersky6aa4fc32013-02-19 16:47:59 +000059 return "ARM Assembly / Object Emitter";
Jim Grosbachd0d13292010-12-01 03:45:07 +000060 }
61
Tim Northoverb4c61f82015-05-13 20:28:41 +000062 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
Jim Grosbachd0d13292010-12-01 03:45:07 +000063
Craig Topper24e685f2014-03-10 05:29:18 +000064 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
65 unsigned AsmVariant, const char *ExtraCode,
66 raw_ostream &O) override;
67 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
68 unsigned AsmVariant, const char *ExtraCode,
69 raw_ostream &O) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000070
Craig Topper24e685f2014-03-10 05:29:18 +000071 void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
72 const MCSubtargetInfo *EndInfo) const override;
Rafael Espindola65fd0a82014-01-24 15:47:54 +000073
Tim Northovera603c402015-05-31 19:22:07 +000074 void EmitJumpTableAddrs(const MachineInstr *MI);
75 void EmitJumpTableInsts(const MachineInstr *MI);
76 void EmitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth);
Craig Topper24e685f2014-03-10 05:29:18 +000077 void EmitInstruction(const MachineInstr *MI) override;
78 bool runOnMachineFunction(MachineFunction &F) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000079
Craig Topper24e685f2014-03-10 05:29:18 +000080 void EmitConstantPool() override {
Craig Topperdb092d72012-10-09 04:23:49 +000081 // we emit constant pools customly!
82 }
Craig Topper24e685f2014-03-10 05:29:18 +000083 void EmitFunctionBodyEnd() override;
84 void EmitFunctionEntryLabel() override;
85 void EmitStartOfAsmFile(Module &M) override;
86 void EmitEndOfAsmFile(Module &M) override;
87 void EmitXXStructor(const Constant *CV) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000088
Jim Grosbach95dee402011-07-08 17:40:42 +000089 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
90 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
91
Jim Grosbachd0d13292010-12-01 03:45:07 +000092private:
93 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
94 void emitAttributes();
95
Anton Korobeynikov62acecd2011-01-01 20:38:38 +000096 // Generic helper used to emit e.g. ARMv5 mul pseudos
97 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
98
Anton Korobeynikove7410dd2011-03-05 18:43:32 +000099 void EmitUnwindingInstruction(const MachineInstr *MI);
100
Jim Grosbach95dee402011-07-08 17:40:42 +0000101 // emitPseudoExpansionLowering - tblgen'erated.
102 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
103 const MachineInstr *MI);
104
Jim Grosbachd0d13292010-12-01 03:45:07 +0000105public:
Eric Christophercd53d6e2015-03-21 03:13:01 +0000106 unsigned getISAEncoding() override {
Jim Grosbachd0d13292010-12-01 03:45:07 +0000107 // ARM/Darwin adds ISA to the DWARF info for each function.
Daniel Sandersc81f4502015-06-16 15:44:21 +0000108 const Triple &TT = TM.getTargetTriple();
Eric Christophera49d68e2015-02-17 20:02:32 +0000109 if (!TT.isOSBinFormatMachO())
Jim Grosbachd0d13292010-12-01 03:45:07 +0000110 return 0;
Eric Christophercd53d6e2015-03-21 03:13:01 +0000111 bool isThumb = TT.getArch() == Triple::thumb ||
112 TT.getArch() == Triple::thumbeb ||
113 TT.getSubArch() == Triple::ARMSubArch_v7m ||
114 TT.getSubArch() == Triple::ARMSubArch_v6m;
115 return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000116 }
117
Craig Topperdb092d72012-10-09 04:23:49 +0000118private:
Jim Grosbach95dee402011-07-08 17:40:42 +0000119 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
Tim Northover4998a472015-05-13 20:28:38 +0000120 MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000121
Dmitri Gribenko0011bbf2012-11-15 16:51:49 +0000122 MCSymbol *GetARMSJLJEHLabel() const;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000123
Tim Northoverdb962e2c2013-11-25 16:24:52 +0000124 MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
Jim Grosbach95dee402011-07-08 17:40:42 +0000125
Craig Topperdb092d72012-10-09 04:23:49 +0000126public:
Jim Grosbachd0d13292010-12-01 03:45:07 +0000127 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
128 /// the .s file.
Craig Topper24e685f2014-03-10 05:29:18 +0000129 void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000130};
131} // end namespace llvm
132
133#endif