| Eli Bendersky | 6aa4fc3 | 2013-02-19 16:47:59 +0000 | [diff] [blame] | 1 | //===-- ARMAsmPrinter.h - ARM implementation of AsmPrinter ------*- C++ -*-===// | 
| Jim Grosbach | d0d1329 | 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 | //===----------------------------------------------------------------------===// | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 9 |  | 
| Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 10 | #ifndef LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H | 
|  | 11 | #define LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 12 |  | 
| Craig Topper | a925326 | 2014-03-22 23:51:00 +0000 | [diff] [blame] | 13 | #include "ARMSubtarget.h" | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/AsmPrinter.h" | 
| Craig Topper | a925326 | 2014-03-22 23:51:00 +0000 | [diff] [blame] | 15 | #include "llvm/Target/TargetMachine.h" | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 16 |  | 
|  | 17 | namespace llvm { | 
|  | 18 |  | 
| Craig Topper | a925326 | 2014-03-22 23:51:00 +0000 | [diff] [blame] | 19 | class ARMFunctionInfo; | 
| Jim Grosbach | 95dee40 | 2011-07-08 17:40:42 +0000 | [diff] [blame] | 20 | class MCOperand; | 
| Craig Topper | a925326 | 2014-03-22 23:51:00 +0000 | [diff] [blame] | 21 | class MachineConstantPool; | 
|  | 22 | class MachineOperand; | 
| Jonathan Roelofs | 300d8ff | 2014-12-04 19:34:50 +0000 | [diff] [blame] | 23 | class MCSymbol; | 
| Jim Grosbach | 95dee40 | 2011-07-08 17:40:42 +0000 | [diff] [blame] | 24 |  | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 25 | namespace ARM { | 
|  | 26 | enum DW_ISA { | 
|  | 27 | DW_ISA_ARM_thumb = 1, | 
|  | 28 | DW_ISA_ARM_arm = 2 | 
|  | 29 | }; | 
|  | 30 | } | 
|  | 31 |  | 
|  | 32 | class 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 Grosbach | 4b63d2a | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 46 | /// 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 Roelofs | 300d8ff | 2014-12-04 19:34:50 +0000 | [diff] [blame] | 49 |  | 
|  | 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 |  | 
| Artyom Skrobov | e9b3fb8 | 2015-12-07 14:22:39 +0000 | [diff] [blame] | 54 | /// OptimizationGoals - Maintain a combined optimization goal for all | 
|  | 55 | /// functions in a module: one of Tag_ABI_optimization_goals values, | 
|  | 56 | /// -1 if uninitialized, 0 if conflicting goals | 
|  | 57 | int OptimizationGoals; | 
|  | 58 |  | 
| James Molloy | fe7fd87 | 2016-09-15 12:30:27 +0000 | [diff] [blame] | 59 | /// List of globals that have had their storage promoted to a constant | 
|  | 60 | /// pool. This lives between calls to runOnMachineFunction and collects | 
|  | 61 | /// data from every MachineFunction. It is used during doFinalization | 
|  | 62 | /// when all non-function globals are emitted. | 
|  | 63 | SmallPtrSet<const GlobalVariable*,2> PromotedGlobals; | 
|  | 64 |  | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 65 | public: | 
| David Blaikie | 9459832 | 2015-01-18 20:29:04 +0000 | [diff] [blame] | 66 | explicit ARMAsmPrinter(TargetMachine &TM, | 
|  | 67 | std::unique_ptr<MCStreamer> Streamer); | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 68 |  | 
| Craig Topper | 24e685f | 2014-03-10 05:29:18 +0000 | [diff] [blame] | 69 | const char *getPassName() const override { | 
| Eli Bendersky | 6aa4fc3 | 2013-02-19 16:47:59 +0000 | [diff] [blame] | 70 | return "ARM Assembly / Object Emitter"; | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 71 | } | 
|  | 72 |  | 
| Tim Northover | b4c61f8 | 2015-05-13 20:28:41 +0000 | [diff] [blame] | 73 | void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O); | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 74 |  | 
| Craig Topper | 24e685f | 2014-03-10 05:29:18 +0000 | [diff] [blame] | 75 | bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum, | 
|  | 76 | unsigned AsmVariant, const char *ExtraCode, | 
|  | 77 | raw_ostream &O) override; | 
|  | 78 | bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, | 
|  | 79 | unsigned AsmVariant, const char *ExtraCode, | 
|  | 80 | raw_ostream &O) override; | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 81 |  | 
| Craig Topper | 24e685f | 2014-03-10 05:29:18 +0000 | [diff] [blame] | 82 | void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, | 
|  | 83 | const MCSubtargetInfo *EndInfo) const override; | 
| Rafael Espindola | 65fd0a8 | 2014-01-24 15:47:54 +0000 | [diff] [blame] | 84 |  | 
| Tim Northover | a603c40 | 2015-05-31 19:22:07 +0000 | [diff] [blame] | 85 | void EmitJumpTableAddrs(const MachineInstr *MI); | 
|  | 86 | void EmitJumpTableInsts(const MachineInstr *MI); | 
|  | 87 | void EmitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth); | 
| Craig Topper | 24e685f | 2014-03-10 05:29:18 +0000 | [diff] [blame] | 88 | void EmitInstruction(const MachineInstr *MI) override; | 
|  | 89 | bool runOnMachineFunction(MachineFunction &F) override; | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 90 |  | 
| Craig Topper | 24e685f | 2014-03-10 05:29:18 +0000 | [diff] [blame] | 91 | void EmitConstantPool() override { | 
| Craig Topper | db092d7 | 2012-10-09 04:23:49 +0000 | [diff] [blame] | 92 | // we emit constant pools customly! | 
|  | 93 | } | 
| Craig Topper | 24e685f | 2014-03-10 05:29:18 +0000 | [diff] [blame] | 94 | void EmitFunctionBodyEnd() override; | 
|  | 95 | void EmitFunctionEntryLabel() override; | 
|  | 96 | void EmitStartOfAsmFile(Module &M) override; | 
|  | 97 | void EmitEndOfAsmFile(Module &M) override; | 
| Mehdi Amini | bd7287e | 2015-07-16 06:11:10 +0000 | [diff] [blame] | 98 | void EmitXXStructor(const DataLayout &DL, const Constant *CV) override; | 
| James Molloy | fe7fd87 | 2016-09-15 12:30:27 +0000 | [diff] [blame] | 99 | void EmitGlobalVariable(const GlobalVariable *GV) override; | 
|  | 100 |  | 
| Jim Grosbach | 95dee40 | 2011-07-08 17:40:42 +0000 | [diff] [blame] | 101 | // lowerOperand - Convert a MachineOperand into the equivalent MCOperand. | 
|  | 102 | bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp); | 
|  | 103 |  | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 104 | private: | 
| Rafael Espindola | 3d6a130 | 2016-06-21 14:21:53 +0000 | [diff] [blame] | 105 |  | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 106 | // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile() | 
|  | 107 | void emitAttributes(); | 
|  | 108 |  | 
| Anton Korobeynikov | 62acecd | 2011-01-01 20:38:38 +0000 | [diff] [blame] | 109 | // Generic helper used to emit e.g. ARMv5 mul pseudos | 
|  | 110 | void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc); | 
|  | 111 |  | 
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 112 | void EmitUnwindingInstruction(const MachineInstr *MI); | 
|  | 113 |  | 
| Jim Grosbach | 95dee40 | 2011-07-08 17:40:42 +0000 | [diff] [blame] | 114 | // emitPseudoExpansionLowering - tblgen'erated. | 
|  | 115 | bool emitPseudoExpansionLowering(MCStreamer &OutStreamer, | 
|  | 116 | const MachineInstr *MI); | 
|  | 117 |  | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 118 | public: | 
| Eric Christopher | cd53d6e | 2015-03-21 03:13:01 +0000 | [diff] [blame] | 119 | unsigned getISAEncoding() override { | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 120 | // ARM/Darwin adds ISA to the DWARF info for each function. | 
| Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 121 | const Triple &TT = TM.getTargetTriple(); | 
| Eric Christopher | a49d68e | 2015-02-17 20:02:32 +0000 | [diff] [blame] | 122 | if (!TT.isOSBinFormatMachO()) | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 123 | return 0; | 
| Eric Christopher | cd53d6e | 2015-03-21 03:13:01 +0000 | [diff] [blame] | 124 | bool isThumb = TT.getArch() == Triple::thumb || | 
|  | 125 | TT.getArch() == Triple::thumbeb || | 
|  | 126 | TT.getSubArch() == Triple::ARMSubArch_v7m || | 
|  | 127 | TT.getSubArch() == Triple::ARMSubArch_v6m; | 
|  | 128 | return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm; | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 129 | } | 
|  | 130 |  | 
| Craig Topper | db092d7 | 2012-10-09 04:23:49 +0000 | [diff] [blame] | 131 | private: | 
| Jim Grosbach | 95dee40 | 2011-07-08 17:40:42 +0000 | [diff] [blame] | 132 | MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol); | 
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 133 | MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const; | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 134 |  | 
| Tim Northover | db962e2c | 2013-11-25 16:24:52 +0000 | [diff] [blame] | 135 | MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags); | 
| Jim Grosbach | 95dee40 | 2011-07-08 17:40:42 +0000 | [diff] [blame] | 136 |  | 
| Craig Topper | db092d7 | 2012-10-09 04:23:49 +0000 | [diff] [blame] | 137 | public: | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 138 | /// EmitMachineConstantPoolValue - Print a machine constantpool value to | 
|  | 139 | /// the .s file. | 
| Craig Topper | 24e685f | 2014-03-10 05:29:18 +0000 | [diff] [blame] | 140 | void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override; | 
| Jim Grosbach | d0d1329 | 2010-12-01 03:45:07 +0000 | [diff] [blame] | 141 | }; | 
|  | 142 | } // end namespace llvm | 
|  | 143 |  | 
|  | 144 | #endif |