blob: 4b276c5b716264e7f78630503c127c736e7c1c17 [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
47public:
48 explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
49 : AsmPrinter(TM, Streamer), AFI(NULL), MCP(NULL) {
50 Subtarget = &TM.getSubtarget<ARMSubtarget>();
51 }
52
53 virtual const char *getPassName() const {
54 return "ARM Assembly Printer";
55 }
56
57 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
58 const char *Modifier = 0);
59
60 virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
61 unsigned AsmVariant, const char *ExtraCode,
62 raw_ostream &O);
63 virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
64 unsigned AsmVariant,
65 const char *ExtraCode, raw_ostream &O);
66
67 void EmitJumpTable(const MachineInstr *MI);
68 void EmitJump2Table(const MachineInstr *MI);
69 virtual void EmitInstruction(const MachineInstr *MI);
70 bool runOnMachineFunction(MachineFunction &F);
71
72 virtual void EmitConstantPool() {} // we emit constant pools customly!
73 virtual void EmitFunctionEntryLabel();
74 void EmitStartOfAsmFile(Module &M);
75 void EmitEndOfAsmFile(Module &M);
James Molloy34982572012-01-26 09:25:43 +000076 void EmitXXStructor(const Constant *CV);
Jim Grosbachbaf120f2010-12-01 03:45:07 +000077
Jim Grosbach53e3fc42011-07-08 17:40:42 +000078 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
79 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
80
Jim Grosbachbaf120f2010-12-01 03:45:07 +000081private:
82 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
83 void emitAttributes();
84
85 // Helper for ELF .o only
86 void emitARMAttributeSection();
87
Anton Korobeynikov4d728602011-01-01 20:38:38 +000088 // Generic helper used to emit e.g. ARMv5 mul pseudos
89 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
90
Anton Korobeynikov57caad72011-03-05 18:43:32 +000091 void EmitUnwindingInstruction(const MachineInstr *MI);
92
Jim Grosbach53e3fc42011-07-08 17:40:42 +000093 // emitPseudoExpansionLowering - tblgen'erated.
94 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
95 const MachineInstr *MI);
96
Jim Grosbachbaf120f2010-12-01 03:45:07 +000097public:
98 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
99
100 MachineLocation getDebugValueLocation(const MachineInstr *MI) const;
101
Devang Patel27f5acb2011-04-21 22:48:26 +0000102 /// EmitDwarfRegOp - Emit dwarf register operation.
Devang Patel0be77df2011-04-27 20:29:27 +0000103 virtual void EmitDwarfRegOp(const MachineLocation &MLoc) const;
Devang Patel27f5acb2011-04-21 22:48:26 +0000104
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000105 virtual unsigned getISAEncoding() {
106 // ARM/Darwin adds ISA to the DWARF info for each function.
107 if (!Subtarget->isTargetDarwin())
108 return 0;
109 return Subtarget->isThumb() ?
110 llvm::ARM::DW_ISA_ARM_thumb : llvm::ARM::DW_ISA_ARM_arm;
111 }
112
Jim Grosbach53e3fc42011-07-08 17:40:42 +0000113 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000114 MCSymbol *GetARMSetPICJumpTableLabel2(unsigned uid, unsigned uid2,
115 const MachineBasicBlock *MBB) const;
116 MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const;
117
118 MCSymbol *GetARMSJLJEHLabel(void) const;
119
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000120 MCSymbol *GetARMGVSymbol(const GlobalValue *GV);
Jim Grosbach53e3fc42011-07-08 17:40:42 +0000121
Jim Grosbachbaf120f2010-12-01 03:45:07 +0000122 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
123 /// the .s file.
124 virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV);
125};
126} // end namespace llvm
127
128#endif