Jia Liu | 31d157a | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- ARMAsmPrinter.h - Print machine code to an ARM .s file --*- C++ -*-===// |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 2 | // |
| 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 | |
| 22 | namespace llvm { |
| 23 | |
Jim Grosbach | 53e3fc4 | 2011-07-08 17:40:42 +0000 | [diff] [blame] | 24 | class MCOperand; |
| 25 | |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 26 | namespace ARM { |
| 27 | enum DW_ISA { |
| 28 | DW_ISA_ARM_thumb = 1, |
| 29 | DW_ISA_ARM_arm = 2 |
| 30 | }; |
| 31 | } |
| 32 | |
| 33 | class 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 Grosbach | 3e96531 | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 47 | /// 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 Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 50 | public: |
| 51 | explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) |
Jim Grosbach | 3e96531 | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 52 | : AsmPrinter(TM, Streamer), AFI(NULL), MCP(NULL), InConstantPool(false) { |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 53 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
| 54 | } |
| 55 | |
| 56 | virtual const char *getPassName() const { |
| 57 | 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, |
| 65 | raw_ostream &O); |
| 66 | virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, |
| 67 | unsigned AsmVariant, |
| 68 | const char *ExtraCode, raw_ostream &O); |
| 69 | |
| 70 | void EmitJumpTable(const MachineInstr *MI); |
| 71 | void EmitJump2Table(const MachineInstr *MI); |
| 72 | virtual void EmitInstruction(const MachineInstr *MI); |
| 73 | bool runOnMachineFunction(MachineFunction &F); |
| 74 | |
| 75 | virtual void EmitConstantPool() {} // we emit constant pools customly! |
Jim Grosbach | 3e96531 | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 76 | virtual void EmitFunctionBodyEnd(); |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 77 | virtual void EmitFunctionEntryLabel(); |
| 78 | void EmitStartOfAsmFile(Module &M); |
| 79 | void EmitEndOfAsmFile(Module &M); |
James Molloy | 3498257 | 2012-01-26 09:25:43 +0000 | [diff] [blame] | 80 | void EmitXXStructor(const Constant *CV); |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 81 | |
Jim Grosbach | 53e3fc4 | 2011-07-08 17:40:42 +0000 | [diff] [blame] | 82 | // lowerOperand - Convert a MachineOperand into the equivalent MCOperand. |
| 83 | bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp); |
| 84 | |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 85 | private: |
| 86 | // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile() |
| 87 | void emitAttributes(); |
| 88 | |
| 89 | // Helper for ELF .o only |
| 90 | void emitARMAttributeSection(); |
| 91 | |
Anton Korobeynikov | 4d72860 | 2011-01-01 20:38:38 +0000 | [diff] [blame] | 92 | // Generic helper used to emit e.g. ARMv5 mul pseudos |
| 93 | void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc); |
| 94 | |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 95 | void EmitUnwindingInstruction(const MachineInstr *MI); |
| 96 | |
Jim Grosbach | 53e3fc4 | 2011-07-08 17:40:42 +0000 | [diff] [blame] | 97 | // emitPseudoExpansionLowering - tblgen'erated. |
| 98 | bool emitPseudoExpansionLowering(MCStreamer &OutStreamer, |
| 99 | const MachineInstr *MI); |
| 100 | |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 101 | public: |
| 102 | void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS); |
| 103 | |
| 104 | MachineLocation getDebugValueLocation(const MachineInstr *MI) const; |
| 105 | |
Devang Patel | 27f5acb | 2011-04-21 22:48:26 +0000 | [diff] [blame] | 106 | /// EmitDwarfRegOp - Emit dwarf register operation. |
Devang Patel | 0be77df | 2011-04-27 20:29:27 +0000 | [diff] [blame] | 107 | virtual void EmitDwarfRegOp(const MachineLocation &MLoc) const; |
Devang Patel | 27f5acb | 2011-04-21 22:48:26 +0000 | [diff] [blame] | 108 | |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 109 | virtual unsigned getISAEncoding() { |
| 110 | // ARM/Darwin adds ISA to the DWARF info for each function. |
| 111 | if (!Subtarget->isTargetDarwin()) |
| 112 | return 0; |
| 113 | return Subtarget->isThumb() ? |
Craig Topper | c89c744 | 2012-03-27 07:21:54 +0000 | [diff] [blame] | 114 | ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm; |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Jim Grosbach | 53e3fc4 | 2011-07-08 17:40:42 +0000 | [diff] [blame] | 117 | MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol); |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 118 | MCSymbol *GetARMSetPICJumpTableLabel2(unsigned uid, unsigned uid2, |
| 119 | const MachineBasicBlock *MBB) const; |
| 120 | MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const; |
| 121 | |
| 122 | MCSymbol *GetARMSJLJEHLabel(void) const; |
| 123 | |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 124 | MCSymbol *GetARMGVSymbol(const GlobalValue *GV); |
Jim Grosbach | 53e3fc4 | 2011-07-08 17:40:42 +0000 | [diff] [blame] | 125 | |
Jim Grosbach | baf120f | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 126 | /// EmitMachineConstantPoolValue - Print a machine constantpool value to |
| 127 | /// the .s file. |
| 128 | virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV); |
| 129 | }; |
| 130 | } // end namespace llvm |
| 131 | |
| 132 | #endif |