LLVM API Documentation

MCAsmBackend.h
Go to the documentation of this file.
00001 //===-- llvm/MC/MCAsmBackend.h - MC Asm Backend -----------------*- 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_MC_MCASMBACKEND_H
00011 #define LLVM_MC_MCASMBACKEND_H
00012 
00013 #include "llvm/ADT/ArrayRef.h"
00014 #include "llvm/MC/MCDirectives.h"
00015 #include "llvm/MC/MCDwarf.h"
00016 #include "llvm/MC/MCFixup.h"
00017 #include "llvm/Support/DataTypes.h"
00018 #include "llvm/Support/ErrorHandling.h"
00019 
00020 namespace llvm {
00021 class MCAsmLayout;
00022 class MCAssembler;
00023 class MCELFObjectTargetWriter;
00024 struct MCFixupKindInfo;
00025 class MCFragment;
00026 class MCInst;
00027 class MCRelaxableFragment;
00028 class MCObjectWriter;
00029 class MCSection;
00030 class MCValue;
00031 class raw_ostream;
00032 
00033 /// MCAsmBackend - Generic interface to target specific assembler backends.
00034 class MCAsmBackend {
00035   MCAsmBackend(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
00036   void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
00037 
00038 protected: // Can only create subclasses.
00039   MCAsmBackend();
00040 
00041   unsigned HasDataInCodeSupport : 1;
00042 
00043 public:
00044   virtual ~MCAsmBackend();
00045 
00046   /// lifetime management
00047   virtual void reset() {}
00048 
00049   /// createObjectWriter - Create a new MCObjectWriter instance for use by the
00050   /// assembler backend to emit the final object file.
00051   virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
00052 
00053   /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
00054   /// non-standard ELFObjectWriters.
00055   virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
00056     llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
00057                      "backend");
00058   }
00059 
00060   /// hasDataInCodeSupport - Check whether this target implements data-in-code
00061   /// markers. If not, data region directives will be ignored.
00062   bool hasDataInCodeSupport() const { return HasDataInCodeSupport; }
00063 
00064   /// doesSectionRequireSymbols - Check whether the given section requires that
00065   /// all symbols (even temporaries) have symbol table entries.
00066   virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
00067     return false;
00068   }
00069 
00070   /// isSectionAtomizable - Check whether the given section can be split into
00071   /// atoms.
00072   ///
00073   /// \see MCAssembler::isSymbolLinkerVisible().
00074   virtual bool isSectionAtomizable(const MCSection &Section) const {
00075     return true;
00076   }
00077 
00078   /// @name Target Fixup Interfaces
00079   /// @{
00080 
00081   /// getNumFixupKinds - Get the number of target specific fixup kinds.
00082   virtual unsigned getNumFixupKinds() const = 0;
00083 
00084   /// getFixupKindInfo - Get information on a fixup kind.
00085   virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
00086 
00087   /// processFixupValue - Target hook to adjust the literal value of a fixup
00088   /// if necessary. IsResolved signals whether the caller believes a relocation
00089   /// is needed; the target can modify the value. The default does nothing.
00090   virtual void processFixupValue(const MCAssembler &Asm,
00091                                  const MCAsmLayout &Layout,
00092                                  const MCFixup &Fixup, const MCFragment *DF,
00093                                  const MCValue &Target, uint64_t &Value,
00094                                  bool &IsResolved) {}
00095 
00096   /// applyFixup - Apply the \p Value for given \p Fixup into the provided
00097   /// data fragment, at the offset specified by the fixup and following the
00098   /// fixup kind as appropriate.
00099   virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
00100                           uint64_t Value, bool IsPCRel) const = 0;
00101 
00102   /// @}
00103 
00104   /// @name Target Relaxation Interfaces
00105   /// @{
00106 
00107   /// mayNeedRelaxation - Check whether the given instruction may need
00108   /// relaxation.
00109   ///
00110   /// \param Inst - The instruction to test.
00111   virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
00112 
00113   /// fixupNeedsRelaxation - Target specific predicate for whether a given
00114   /// fixup requires the associated instruction to be relaxed.
00115   virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
00116                                     const MCRelaxableFragment *DF,
00117                                     const MCAsmLayout &Layout) const = 0;
00118 
00119   /// RelaxInstruction - Relax the instruction in the given fragment to the next
00120   /// wider instruction.
00121   ///
00122   /// \param Inst The instruction to relax, which may be the same as the
00123   /// output.
00124   /// \param [out] Res On return, the relaxed instruction.
00125   virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
00126 
00127   /// @}
00128 
00129   /// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
00130   /// target. The assembler will use this to emit excess padding in situations
00131   /// where the padding required for simple alignment would be less than the
00132   /// minimum nop size.
00133   ///
00134   virtual unsigned getMinimumNopSize() const { return 1; }
00135 
00136   /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
00137   /// output. If the target cannot generate such a sequence, it should return an
00138   /// error.
00139   ///
00140   /// \return - True on success.
00141   virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
00142 
00143   /// handleAssemblerFlag - Handle any target-specific assembler flags.
00144   /// By default, do nothing.
00145   virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
00146 
00147   /// \brief Generate the compact unwind encoding for the CFI instructions.
00148   virtual uint32_t
00149       generateCompactUnwindEncoding(ArrayRef<MCCFIInstruction>) const {
00150     return 0;
00151   }
00152 };
00153 
00154 } // End llvm namespace
00155 
00156 #endif