xref: /aosp_15_r20/external/llvm/lib/Target/ARM/ARMAsmPrinter.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- ARMAsmPrinter.h - ARM implementation of AsmPrinter ------*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker 
10*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
11*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
12*9880d681SAndroid Build Coastguard Worker 
13*9880d681SAndroid Build Coastguard Worker #include "ARMSubtarget.h"
14*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/AsmPrinter.h"
15*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetMachine.h"
16*9880d681SAndroid Build Coastguard Worker 
17*9880d681SAndroid Build Coastguard Worker namespace llvm {
18*9880d681SAndroid Build Coastguard Worker 
19*9880d681SAndroid Build Coastguard Worker class ARMFunctionInfo;
20*9880d681SAndroid Build Coastguard Worker class MCOperand;
21*9880d681SAndroid Build Coastguard Worker class MachineConstantPool;
22*9880d681SAndroid Build Coastguard Worker class MachineOperand;
23*9880d681SAndroid Build Coastguard Worker class MCSymbol;
24*9880d681SAndroid Build Coastguard Worker 
25*9880d681SAndroid Build Coastguard Worker namespace ARM {
26*9880d681SAndroid Build Coastguard Worker   enum DW_ISA {
27*9880d681SAndroid Build Coastguard Worker     DW_ISA_ARM_thumb = 1,
28*9880d681SAndroid Build Coastguard Worker     DW_ISA_ARM_arm = 2
29*9880d681SAndroid Build Coastguard Worker   };
30*9880d681SAndroid Build Coastguard Worker }
31*9880d681SAndroid Build Coastguard Worker 
32*9880d681SAndroid Build Coastguard Worker class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
33*9880d681SAndroid Build Coastguard Worker 
34*9880d681SAndroid Build Coastguard Worker   /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
35*9880d681SAndroid Build Coastguard Worker   /// make the right decision when printing asm code for different targets.
36*9880d681SAndroid Build Coastguard Worker   const ARMSubtarget *Subtarget;
37*9880d681SAndroid Build Coastguard Worker 
38*9880d681SAndroid Build Coastguard Worker   /// AFI - Keep a pointer to ARMFunctionInfo for the current
39*9880d681SAndroid Build Coastguard Worker   /// MachineFunction.
40*9880d681SAndroid Build Coastguard Worker   ARMFunctionInfo *AFI;
41*9880d681SAndroid Build Coastguard Worker 
42*9880d681SAndroid Build Coastguard Worker   /// MCP - Keep a pointer to constantpool entries of the current
43*9880d681SAndroid Build Coastguard Worker   /// MachineFunction.
44*9880d681SAndroid Build Coastguard Worker   const MachineConstantPool *MCP;
45*9880d681SAndroid Build Coastguard Worker 
46*9880d681SAndroid Build Coastguard Worker   /// InConstantPool - Maintain state when emitting a sequence of constant
47*9880d681SAndroid Build Coastguard Worker   /// pool entries so we can properly mark them as data regions.
48*9880d681SAndroid Build Coastguard Worker   bool InConstantPool;
49*9880d681SAndroid Build Coastguard Worker 
50*9880d681SAndroid Build Coastguard Worker   /// ThumbIndirectPads - These maintain a per-function list of jump pad
51*9880d681SAndroid Build Coastguard Worker   /// labels used for ARMv4t thumb code to make register indirect calls.
52*9880d681SAndroid Build Coastguard Worker   SmallVector<std::pair<unsigned, MCSymbol*>, 4> ThumbIndirectPads;
53*9880d681SAndroid Build Coastguard Worker 
54*9880d681SAndroid Build Coastguard Worker   /// OptimizationGoals - Maintain a combined optimization goal for all
55*9880d681SAndroid Build Coastguard Worker   /// functions in a module: one of Tag_ABI_optimization_goals values,
56*9880d681SAndroid Build Coastguard Worker   /// -1 if uninitialized, 0 if conflicting goals
57*9880d681SAndroid Build Coastguard Worker   int OptimizationGoals;
58*9880d681SAndroid Build Coastguard Worker 
59*9880d681SAndroid Build Coastguard Worker public:
60*9880d681SAndroid Build Coastguard Worker   explicit ARMAsmPrinter(TargetMachine &TM,
61*9880d681SAndroid Build Coastguard Worker                          std::unique_ptr<MCStreamer> Streamer);
62*9880d681SAndroid Build Coastguard Worker 
getPassName()63*9880d681SAndroid Build Coastguard Worker   const char *getPassName() const override {
64*9880d681SAndroid Build Coastguard Worker     return "ARM Assembly / Object Emitter";
65*9880d681SAndroid Build Coastguard Worker   }
66*9880d681SAndroid Build Coastguard Worker 
67*9880d681SAndroid Build Coastguard Worker   void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
68*9880d681SAndroid Build Coastguard Worker 
69*9880d681SAndroid Build Coastguard Worker   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
70*9880d681SAndroid Build Coastguard Worker                        unsigned AsmVariant, const char *ExtraCode,
71*9880d681SAndroid Build Coastguard Worker                        raw_ostream &O) override;
72*9880d681SAndroid Build Coastguard Worker   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
73*9880d681SAndroid Build Coastguard Worker                              unsigned AsmVariant, const char *ExtraCode,
74*9880d681SAndroid Build Coastguard Worker                              raw_ostream &O) override;
75*9880d681SAndroid Build Coastguard Worker 
76*9880d681SAndroid Build Coastguard Worker   void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
77*9880d681SAndroid Build Coastguard Worker                         const MCSubtargetInfo *EndInfo) const override;
78*9880d681SAndroid Build Coastguard Worker 
79*9880d681SAndroid Build Coastguard Worker   void EmitJumpTableAddrs(const MachineInstr *MI);
80*9880d681SAndroid Build Coastguard Worker   void EmitJumpTableInsts(const MachineInstr *MI);
81*9880d681SAndroid Build Coastguard Worker   void EmitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth);
82*9880d681SAndroid Build Coastguard Worker   void EmitInstruction(const MachineInstr *MI) override;
83*9880d681SAndroid Build Coastguard Worker   bool runOnMachineFunction(MachineFunction &F) override;
84*9880d681SAndroid Build Coastguard Worker 
EmitConstantPool()85*9880d681SAndroid Build Coastguard Worker   void EmitConstantPool() override {
86*9880d681SAndroid Build Coastguard Worker     // we emit constant pools customly!
87*9880d681SAndroid Build Coastguard Worker   }
88*9880d681SAndroid Build Coastguard Worker   void EmitFunctionBodyEnd() override;
89*9880d681SAndroid Build Coastguard Worker   void EmitFunctionEntryLabel() override;
90*9880d681SAndroid Build Coastguard Worker   void EmitStartOfAsmFile(Module &M) override;
91*9880d681SAndroid Build Coastguard Worker   void EmitEndOfAsmFile(Module &M) override;
92*9880d681SAndroid Build Coastguard Worker   void EmitXXStructor(const DataLayout &DL, const Constant *CV) override;
93*9880d681SAndroid Build Coastguard Worker 
94*9880d681SAndroid Build Coastguard Worker   // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
95*9880d681SAndroid Build Coastguard Worker   bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
96*9880d681SAndroid Build Coastguard Worker 
97*9880d681SAndroid Build Coastguard Worker private:
98*9880d681SAndroid Build Coastguard Worker 
99*9880d681SAndroid Build Coastguard Worker   // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
100*9880d681SAndroid Build Coastguard Worker   void emitAttributes();
101*9880d681SAndroid Build Coastguard Worker 
102*9880d681SAndroid Build Coastguard Worker   // Generic helper used to emit e.g. ARMv5 mul pseudos
103*9880d681SAndroid Build Coastguard Worker   void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
104*9880d681SAndroid Build Coastguard Worker 
105*9880d681SAndroid Build Coastguard Worker   void EmitUnwindingInstruction(const MachineInstr *MI);
106*9880d681SAndroid Build Coastguard Worker 
107*9880d681SAndroid Build Coastguard Worker   // emitPseudoExpansionLowering - tblgen'erated.
108*9880d681SAndroid Build Coastguard Worker   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
109*9880d681SAndroid Build Coastguard Worker                                    const MachineInstr *MI);
110*9880d681SAndroid Build Coastguard Worker 
111*9880d681SAndroid Build Coastguard Worker public:
getISAEncoding()112*9880d681SAndroid Build Coastguard Worker   unsigned getISAEncoding() override {
113*9880d681SAndroid Build Coastguard Worker     // ARM/Darwin adds ISA to the DWARF info for each function.
114*9880d681SAndroid Build Coastguard Worker     const Triple &TT = TM.getTargetTriple();
115*9880d681SAndroid Build Coastguard Worker     if (!TT.isOSBinFormatMachO())
116*9880d681SAndroid Build Coastguard Worker       return 0;
117*9880d681SAndroid Build Coastguard Worker     bool isThumb = TT.getArch() == Triple::thumb ||
118*9880d681SAndroid Build Coastguard Worker                    TT.getArch() == Triple::thumbeb ||
119*9880d681SAndroid Build Coastguard Worker                    TT.getSubArch() == Triple::ARMSubArch_v7m ||
120*9880d681SAndroid Build Coastguard Worker                    TT.getSubArch() == Triple::ARMSubArch_v6m;
121*9880d681SAndroid Build Coastguard Worker     return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
122*9880d681SAndroid Build Coastguard Worker   }
123*9880d681SAndroid Build Coastguard Worker 
124*9880d681SAndroid Build Coastguard Worker private:
125*9880d681SAndroid Build Coastguard Worker   MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
126*9880d681SAndroid Build Coastguard Worker   MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;
127*9880d681SAndroid Build Coastguard Worker 
128*9880d681SAndroid Build Coastguard Worker   MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
129*9880d681SAndroid Build Coastguard Worker 
130*9880d681SAndroid Build Coastguard Worker public:
131*9880d681SAndroid Build Coastguard Worker   /// EmitMachineConstantPoolValue - Print a machine constantpool value to
132*9880d681SAndroid Build Coastguard Worker   /// the .s file.
133*9880d681SAndroid Build Coastguard Worker   void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
134*9880d681SAndroid Build Coastguard Worker };
135*9880d681SAndroid Build Coastguard Worker } // end namespace llvm
136*9880d681SAndroid Build Coastguard Worker 
137*9880d681SAndroid Build Coastguard Worker #endif
138