blob: f7392fbf3486e45329012ee771b89874610f5295 [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- ARMAsmPrinter.h - Print machine code to an ARM .s file --*- 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//===----------------------------------------------------------------------===//
9//
10// ARM Assembly printer class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef ARMASMPRINTER_H
15#define ARMASMPRINTER_H
16
17#include "ARM.h"
18#include "ARMTargetMachine.h"
19#include "llvm/CodeGen/AsmPrinter.h"
20#include "llvm/Support/Compiler.h"
21
22namespace llvm {
23
Jim Grosbach53e3fc42011-07-08 17:40:42 +000024class MCOperand;
25
Jim Grosbachbaf120f2010-12-01 03:45:07 +000026namespace ARM {
27 enum DW_ISA {
28 DW_ISA_ARM_thumb = 1,
29 DW_ISA_ARM_arm = 2
30 };
31}
32
33class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
34
35 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
36 /// make the right decision when printing asm code for different targets.
37 const ARMSubtarget *Subtarget;
38
39 /// AFI - Keep a pointer to ARMFunctionInfo for the current
40 /// MachineFunction.
41 ARMFunctionInfo *AFI;
42
43 /// MCP - Keep a pointer to constantpool entries of the current
44 /// MachineFunction.
45 const MachineConstantPool *MCP;
46
Jim Grosbach3e965312012-05-18 19:12:01 +000047 /// InConstantPool - Maintain state when emitting a sequence of constant
48 /// pool entries so we can properly mark them as data regions.
49 bool InConstantPool;
Jim Grosbachbaf120f2010-12-01 03:45:07 +000050public:
51 explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
Jim Grosbach3e965312012-05-18 19:12:01 +000052 : AsmPrinter(TM, Streamer), AFI(NULL), MCP(NULL), InConstantPool(false) {
Jim Grosbachbaf120f2010-12-01 03:45:07 +000053 Subtarget = &TM.getSubtarget<ARMSubtarget>();
54 }
55
Craig Topper77474962012-10-09 04:23:49 +000056 virtual const char *getPassName() const LLVM_OVERRIDE {
Jim Grosbachbaf120f2010-12-01 03:45:07 +000057 return "ARM Assembly Printer";
58 }
59
60 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
61 const char *Modifier = 0);
62
63 virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
64 unsigned AsmVariant, const char *ExtraCode,
Craig Topper77474962012-10-09 04:23:49 +000065 raw_ostream &O) LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +000066 virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
Craig Topper77474962012-10-09 04:23:49 +000067 unsigned AsmVariant, const char *ExtraCode,
68 raw_ostream &O) LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +000069
70 void EmitJumpTable(const MachineInstr *MI);
71 void EmitJump2Table(const MachineInstr *MI);
Craig Topper77474962012-10-09 04:23:49 +000072 virtual void EmitInstruction(const MachineInstr *MI) LLVM_OVERRIDE;
73 virtual bool runOnMachineFunction(MachineFunction &F) LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +000074
Craig Topper77474962012-10-09 04:23:49 +000075 virtual void EmitConstantPool() LLVM_OVERRIDE {
76 // we emit constant pools customly!
77 }
78 virtual void EmitFunctionBodyEnd() LLVM_OVERRIDE;
79 virtual void EmitFunctionEntryLabel() LLVM_OVERRIDE;
80 virtual void EmitStartOfAsmFile(Module &M) LLVM_OVERRIDE;
81 virtual void EmitEndOfAsmFile(Module &M) LLVM_OVERRIDE;
82 virtual void EmitXXStructor(const Constant *CV) LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +000083
Jim Grosbach53e3fc42011-07-08 17:40:42 +000084 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
85 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
86
Jim Grosbachbaf120f2010-12-01 03:45:07 +000087private:
88 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
89 void emitAttributes();
90
91 // Helper for ELF .o only
92 void emitARMAttributeSection();
93
Anton Korobeynikov4d728602011-01-01 20:38:38 +000094 // Generic helper used to emit e.g. ARMv5 mul pseudos
95 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
96
Anton Korobeynikov57caad72011-03-05 18:43:32 +000097 void EmitUnwindingInstruction(const MachineInstr *MI);
98
Jim Grosbach53e3fc42011-07-08 17:40:42 +000099 // emitPseudoExpansionLowering - tblgen'erated.
100 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
101 const MachineInstr *MI);
102
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000103public:
104 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
105
Craig Topper77474962012-10-09 04:23:49 +0000106 virtual MachineLocation
107 getDebugValueLocation(const MachineInstr *MI) const LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000108
Devang Patel27f5acb2011-04-21 22:48:26 +0000109 /// EmitDwarfRegOp - Emit dwarf register operation.
Craig Topper77474962012-10-09 04:23:49 +0000110 virtual void EmitDwarfRegOp(const MachineLocation &MLoc) const LLVM_OVERRIDE;
Devang Patel27f5acb2011-04-21 22:48:26 +0000111
Craig Topper77474962012-10-09 04:23:49 +0000112 virtual unsigned getISAEncoding() LLVM_OVERRIDE {
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000113 // ARM/Darwin adds ISA to the DWARF info for each function.
114 if (!Subtarget->isTargetDarwin())
115 return 0;
116 return Subtarget->isThumb() ?
Craig Topperc89c7442012-03-27 07:21:54 +0000117 ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000118 }
119
Craig Topper77474962012-10-09 04:23:49 +0000120private:
Jim Grosbach53e3fc42011-07-08 17:40:42 +0000121 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000122 MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const;
123
Dmitri Gribenko79c07d22012-11-15 16:51:49 +0000124 MCSymbol *GetARMSJLJEHLabel() const;
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000125
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000126 MCSymbol *GetARMGVSymbol(const GlobalValue *GV);
Jim Grosbach53e3fc42011-07-08 17:40:42 +0000127
Craig Topper77474962012-10-09 04:23:49 +0000128public:
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000129 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
130 /// the .s file.
Craig Topper77474962012-10-09 04:23:49 +0000131 virtual void
132 EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) LLVM_OVERRIDE;
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000133};
134} // end namespace llvm
135
136#endif