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 ARMASMPRINTER_H
11#define ARMASMPRINTER_H
12
13#include "ARMSubtarget.h"
14#include "llvm/CodeGen/AsmPrinter.h"
15#include "llvm/Target/TargetMachine.h"
16
17namespace llvm {
18
19class ARMFunctionInfo;
20class MCOperand;
21class MachineConstantPool;
22class MachineOperand;
23
24namespace ARM {
25  enum DW_ISA {
26    DW_ISA_ARM_thumb = 1,
27    DW_ISA_ARM_arm = 2
28  };
29}
30
31class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
32
33  /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
34  /// make the right decision when printing asm code for different targets.
35  const ARMSubtarget *Subtarget;
36
37  /// AFI - Keep a pointer to ARMFunctionInfo for the current
38  /// MachineFunction.
39  ARMFunctionInfo *AFI;
40
41  /// MCP - Keep a pointer to constantpool entries of the current
42  /// MachineFunction.
43  const MachineConstantPool *MCP;
44
45  /// InConstantPool - Maintain state when emitting a sequence of constant
46  /// pool entries so we can properly mark them as data regions.
47  bool InConstantPool;
48public:
49  explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
50    : AsmPrinter(TM, Streamer), AFI(nullptr), MCP(nullptr),
51      InConstantPool(false) {
52    Subtarget = &TM.getSubtarget<ARMSubtarget>();
53  }
54
55  const char *getPassName() const override {
56    return "ARM Assembly / Object Emitter";
57  }
58
59  void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
60                    const char *Modifier = nullptr);
61
62  bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
63                       unsigned AsmVariant, const char *ExtraCode,
64                       raw_ostream &O) override;
65  bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
66                             unsigned AsmVariant, const char *ExtraCode,
67                             raw_ostream &O) override;
68
69  void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
70                        const MCSubtargetInfo *EndInfo) const override;
71
72  void EmitJumpTable(const MachineInstr *MI);
73  void EmitJump2Table(const MachineInstr *MI);
74  void EmitInstruction(const MachineInstr *MI) override;
75  bool runOnMachineFunction(MachineFunction &F) override;
76
77  void EmitConstantPool() override {
78    // we emit constant pools customly!
79  }
80  void EmitFunctionBodyEnd() override;
81  void EmitFunctionEntryLabel() override;
82  void EmitStartOfAsmFile(Module &M) override;
83  void EmitEndOfAsmFile(Module &M) override;
84  void EmitXXStructor(const Constant *CV) override;
85
86  // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
87  bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
88
89private:
90  // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
91  void emitAttributes();
92
93  // Generic helper used to emit e.g. ARMv5 mul pseudos
94  void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
95
96  void EmitUnwindingInstruction(const MachineInstr *MI);
97
98  // emitPseudoExpansionLowering - tblgen'erated.
99  bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
100                                   const MachineInstr *MI);
101
102public:
103  unsigned getISAEncoding() override {
104    // ARM/Darwin adds ISA to the DWARF info for each function.
105    if (!Subtarget->isTargetMachO())
106      return 0;
107    return Subtarget->isThumb() ?
108      ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
109  }
110
111private:
112  MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
113  MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const;
114
115  MCSymbol *GetARMSJLJEHLabel() const;
116
117  MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
118
119public:
120  /// EmitMachineConstantPoolValue - Print a machine constantpool value to
121  /// the .s file.
122  void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
123};
124} // end namespace llvm
125
126#endif
127