LLVM API Documentation

ARMAsmPrinter.h
Go to the documentation of this file.
00001 //===-- ARMAsmPrinter.h - ARM implementation of AsmPrinter ------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
00011 #define LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
00012 
00013 #include "ARMSubtarget.h"
00014 #include "llvm/CodeGen/AsmPrinter.h"
00015 #include "llvm/Target/TargetMachine.h"
00016 
00017 namespace llvm {
00018 
00019 class ARMFunctionInfo;
00020 class MCOperand;
00021 class MachineConstantPool;
00022 class MachineOperand;
00023 
00024 namespace ARM {
00025   enum DW_ISA {
00026     DW_ISA_ARM_thumb = 1,
00027     DW_ISA_ARM_arm = 2
00028   };
00029 }
00030 
00031 class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
00032 
00033   /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
00034   /// make the right decision when printing asm code for different targets.
00035   const ARMSubtarget *Subtarget;
00036 
00037   /// AFI - Keep a pointer to ARMFunctionInfo for the current
00038   /// MachineFunction.
00039   ARMFunctionInfo *AFI;
00040 
00041   /// MCP - Keep a pointer to constantpool entries of the current
00042   /// MachineFunction.
00043   const MachineConstantPool *MCP;
00044 
00045   /// InConstantPool - Maintain state when emitting a sequence of constant
00046   /// pool entries so we can properly mark them as data regions.
00047   bool InConstantPool;
00048 public:
00049   explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
00050     : AsmPrinter(TM, Streamer), AFI(nullptr), MCP(nullptr),
00051       InConstantPool(false) {
00052     Subtarget = &TM.getSubtarget<ARMSubtarget>();
00053   }
00054 
00055   const char *getPassName() const override {
00056     return "ARM Assembly / Object Emitter";
00057   }
00058 
00059   void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
00060                     const char *Modifier = nullptr);
00061 
00062   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
00063                        unsigned AsmVariant, const char *ExtraCode,
00064                        raw_ostream &O) override;
00065   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
00066                              unsigned AsmVariant, const char *ExtraCode,
00067                              raw_ostream &O) override;
00068 
00069   void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
00070                         const MCSubtargetInfo *EndInfo) const override;
00071 
00072   void EmitJumpTable(const MachineInstr *MI);
00073   void EmitJump2Table(const MachineInstr *MI);
00074   void EmitInstruction(const MachineInstr *MI) override;
00075   bool runOnMachineFunction(MachineFunction &F) override;
00076 
00077   void EmitConstantPool() override {
00078     // we emit constant pools customly!
00079   }
00080   void EmitFunctionBodyEnd() override;
00081   void EmitFunctionEntryLabel() override;
00082   void EmitStartOfAsmFile(Module &M) override;
00083   void EmitEndOfAsmFile(Module &M) override;
00084   void EmitXXStructor(const Constant *CV) override;
00085 
00086   // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
00087   bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
00088 
00089 private:
00090   // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
00091   void emitAttributes();
00092 
00093   // Generic helper used to emit e.g. ARMv5 mul pseudos
00094   void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
00095 
00096   void EmitUnwindingInstruction(const MachineInstr *MI);
00097 
00098   // emitPseudoExpansionLowering - tblgen'erated.
00099   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
00100                                    const MachineInstr *MI);
00101 
00102 public:
00103   unsigned getISAEncoding() override {
00104     // ARM/Darwin adds ISA to the DWARF info for each function.
00105     if (!Subtarget->isTargetMachO())
00106       return 0;
00107     return Subtarget->isThumb() ?
00108       ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
00109   }
00110 
00111 private:
00112   MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
00113   MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const;
00114 
00115   MCSymbol *GetARMSJLJEHLabel() const;
00116 
00117   MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
00118 
00119 public:
00120   /// EmitMachineConstantPoolValue - Print a machine constantpool value to
00121   /// the .s file.
00122   void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
00123 };
00124 } // end namespace llvm
00125 
00126 #endif