blob: c945e4f28699ee6f391e1a4ce18d64f8b73a0e54 [file] [log] [blame]
Eli Bendersky26a5c4d2013-02-19 16:47:59 +00001//===-- ARMAsmPrinter.h - ARM implementation of AsmPrinter ------*- C++ -*-===//
Jim Grosbachbaf120f2010-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 Grosbachbaf120f2010-12-01 03:45:07 +00009
10#ifndef ARMASMPRINTER_H
11#define ARMASMPRINTER_H
12
13#include "ARM.h"
14#include "ARMTargetMachine.h"
15#include "llvm/CodeGen/AsmPrinter.h"
16#include "llvm/Support/Compiler.h"
17
18namespace llvm {
19
Jim Grosbach53e3fc42011-07-08 17:40:42 +000020class MCOperand;
21
Jim Grosbachbaf120f2010-12-01 03:45:07 +000022namespace ARM {
23 enum DW_ISA {
24 DW_ISA_ARM_thumb = 1,
25 DW_ISA_ARM_arm = 2
26 };
27}
28
29class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
30
31 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
32 /// make the right decision when printing asm code for different targets.
33 const ARMSubtarget *Subtarget;
34
35 /// AFI - Keep a pointer to ARMFunctionInfo for the current
36 /// MachineFunction.
37 ARMFunctionInfo *AFI;
38
39 /// MCP - Keep a pointer to constantpool entries of the current
40 /// MachineFunction.
41 const MachineConstantPool *MCP;
42
Jim Grosbach3e965312012-05-18 19:12:01 +000043 /// InConstantPool - Maintain state when emitting a sequence of constant
44 /// pool entries so we can properly mark them as data regions.
45 bool InConstantPool;
Jim Grosbachbaf120f2010-12-01 03:45:07 +000046public:
47 explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
Jim Grosbach3e965312012-05-18 19:12:01 +000048 : AsmPrinter(TM, Streamer), AFI(NULL), MCP(NULL), InConstantPool(false) {
Jim Grosbachbaf120f2010-12-01 03:45:07 +000049 Subtarget = &TM.getSubtarget<ARMSubtarget>();
50 }
51
Craig Topper77474962012-10-09 04:23:49 +000052 virtual const char *getPassName() const LLVM_OVERRIDE {
Eli Bendersky26a5c4d2013-02-19 16:47:59 +000053 return "ARM Assembly / Object Emitter";
Jim Grosbachbaf120f2010-12-01 03:45:07 +000054 }
55
56 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
57 const char *Modifier = 0);
58
59 virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
60 unsigned AsmVariant, const char *ExtraCode,
Craig Topper77474962012-10-09 04:23:49 +000061 raw_ostream &O) LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +000062 virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
Craig Topper77474962012-10-09 04:23:49 +000063 unsigned AsmVariant, const char *ExtraCode,
64 raw_ostream &O) LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +000065
66 void EmitJumpTable(const MachineInstr *MI);
67 void EmitJump2Table(const MachineInstr *MI);
Craig Topper77474962012-10-09 04:23:49 +000068 virtual void EmitInstruction(const MachineInstr *MI) LLVM_OVERRIDE;
69 virtual bool runOnMachineFunction(MachineFunction &F) LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +000070
Craig Topper77474962012-10-09 04:23:49 +000071 virtual void EmitConstantPool() LLVM_OVERRIDE {
72 // we emit constant pools customly!
73 }
74 virtual void EmitFunctionBodyEnd() LLVM_OVERRIDE;
75 virtual void EmitFunctionEntryLabel() LLVM_OVERRIDE;
76 virtual void EmitStartOfAsmFile(Module &M) LLVM_OVERRIDE;
77 virtual void EmitEndOfAsmFile(Module &M) LLVM_OVERRIDE;
78 virtual void EmitXXStructor(const Constant *CV) LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +000079
Jim Grosbach53e3fc42011-07-08 17:40:42 +000080 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
81 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
82
Jim Grosbachbaf120f2010-12-01 03:45:07 +000083private:
84 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
85 void emitAttributes();
86
87 // Helper for ELF .o only
88 void emitARMAttributeSection();
89
Anton Korobeynikov4d728602011-01-01 20:38:38 +000090 // Generic helper used to emit e.g. ARMv5 mul pseudos
91 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
92
Anton Korobeynikov57caad72011-03-05 18:43:32 +000093 void EmitUnwindingInstruction(const MachineInstr *MI);
94
Jim Grosbach53e3fc42011-07-08 17:40:42 +000095 // emitPseudoExpansionLowering - tblgen'erated.
96 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
97 const MachineInstr *MI);
98
Jim Grosbachbaf120f2010-12-01 03:45:07 +000099public:
100 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
101
Craig Topper77474962012-10-09 04:23:49 +0000102 virtual MachineLocation
103 getDebugValueLocation(const MachineInstr *MI) const LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000104
Devang Patel27f5acb2011-04-21 22:48:26 +0000105 /// EmitDwarfRegOp - Emit dwarf register operation.
Craig Topper77474962012-10-09 04:23:49 +0000106 virtual void EmitDwarfRegOp(const MachineLocation &MLoc) const LLVM_OVERRIDE;
Devang Patel27f5acb2011-04-21 22:48:26 +0000107
Craig Topper77474962012-10-09 04:23:49 +0000108 virtual unsigned getISAEncoding() LLVM_OVERRIDE {
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000109 // ARM/Darwin adds ISA to the DWARF info for each function.
110 if (!Subtarget->isTargetDarwin())
111 return 0;
112 return Subtarget->isThumb() ?
Craig Topperc89c7442012-03-27 07:21:54 +0000113 ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000114 }
115
Craig Topper77474962012-10-09 04:23:49 +0000116private:
Jim Grosbach53e3fc42011-07-08 17:40:42 +0000117 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000118 MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const;
119
Dmitri Gribenko79c07d22012-11-15 16:51:49 +0000120 MCSymbol *GetARMSJLJEHLabel() const;
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000121
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000122 MCSymbol *GetARMGVSymbol(const GlobalValue *GV);
Jim Grosbach53e3fc42011-07-08 17:40:42 +0000123
Craig Topper77474962012-10-09 04:23:49 +0000124public:
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000125 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
126 /// the .s file.
Craig Topper77474962012-10-09 04:23:49 +0000127 virtual void
128 EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000129};
130} // end namespace llvm
131
132#endif