OSDN Git Service

[ARM] Promote small global constants to constant pools
[android-x86/external-llvm.git] / lib / Target / ARM / ARMAsmPrinter.h
1 //===-- ARMAsmPrinter.h - ARM implementation of AsmPrinter ------*- C++ -*-===//
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 #ifndef LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
11 #define LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
12
13 #include "ARMSubtarget.h"
14 #include "llvm/CodeGen/AsmPrinter.h"
15 #include "llvm/Target/TargetMachine.h"
16
17 namespace llvm {
18
19 class ARMFunctionInfo;
20 class MCOperand;
21 class MachineConstantPool;
22 class MachineOperand;
23 class MCSymbol;
24
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
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;
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
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
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
65 public:
66   explicit ARMAsmPrinter(TargetMachine &TM,
67                          std::unique_ptr<MCStreamer> Streamer);
68
69   const char *getPassName() const override {
70     return "ARM Assembly / Object Emitter";
71   }
72
73   void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
74
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;
81
82   void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
83                         const MCSubtargetInfo *EndInfo) const override;
84
85   void EmitJumpTableAddrs(const MachineInstr *MI);
86   void EmitJumpTableInsts(const MachineInstr *MI);
87   void EmitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth);
88   void EmitInstruction(const MachineInstr *MI) override;
89   bool runOnMachineFunction(MachineFunction &F) override;
90
91   void EmitConstantPool() override {
92     // we emit constant pools customly!
93   }
94   void EmitFunctionBodyEnd() override;
95   void EmitFunctionEntryLabel() override;
96   void EmitStartOfAsmFile(Module &M) override;
97   void EmitEndOfAsmFile(Module &M) override;
98   void EmitXXStructor(const DataLayout &DL, const Constant *CV) override;
99   void EmitGlobalVariable(const GlobalVariable *GV) override;
100   
101   // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
102   bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
103
104 private:
105
106   // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
107   void emitAttributes();
108
109   // Generic helper used to emit e.g. ARMv5 mul pseudos
110   void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
111
112   void EmitUnwindingInstruction(const MachineInstr *MI);
113
114   // emitPseudoExpansionLowering - tblgen'erated.
115   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
116                                    const MachineInstr *MI);
117
118 public:
119   unsigned getISAEncoding() override {
120     // ARM/Darwin adds ISA to the DWARF info for each function.
121     const Triple &TT = TM.getTargetTriple();
122     if (!TT.isOSBinFormatMachO())
123       return 0;
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;
129   }
130
131 private:
132   MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
133   MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;
134
135   MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
136
137 public:
138   /// EmitMachineConstantPoolValue - Print a machine constantpool value to
139   /// the .s file.
140   void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
141 };
142 } // end namespace llvm
143
144 #endif