diff options
author | Stephen Hines <srhines@google.com> | 2014-04-23 16:57:46 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-04-24 15:53:16 -0700 |
commit | 36b56886974eae4f9c5ebc96befd3e7bfe5de338 (patch) | |
tree | e6cfb69fbbd937f450eeb83bfb83b9da3b01275a /include/llvm/MC/MCAssembler.h | |
parent | 69a8640022b04415ae9fac62f8ab090601d8f889 (diff) | |
download | external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.zip external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.gz external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.bz2 |
Update to LLVM 3.5a.
Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
Diffstat (limited to 'include/llvm/MC/MCAssembler.h')
-rw-r--r-- | include/llvm/MC/MCAssembler.h | 169 |
1 files changed, 117 insertions, 52 deletions
diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index 0cf2b1d..34b760c 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -15,17 +15,16 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/ilist.h" #include "llvm/ADT/ilist_node.h" +#include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCFixup.h" #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCLinkerOptimizationHint.h" +#include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Support/Casting.h" #include "llvm/Support/DataTypes.h" #include <algorithm> #include <vector> // FIXME: Shouldn't be needed. -namespace mcld { -class Layout; -} - namespace llvm { class raw_ostream; class MCAsmLayout; @@ -37,6 +36,7 @@ class MCFragment; class MCObjectWriter; class MCSection; class MCSectionData; +class MCSubtargetInfo; class MCSymbol; class MCSymbolData; class MCValue; @@ -44,7 +44,6 @@ class MCAsmBackend; class MCFragment : public ilist_node<MCFragment> { friend class MCAsmLayout; - friend class mcld::Layout; MCFragment(const MCFragment&) LLVM_DELETED_FUNCTION; void operator=(const MCFragment&) LLVM_DELETED_FUNCTION; @@ -53,16 +52,14 @@ public: enum FragmentType { FT_Align, FT_Data, + FT_Compressed, FT_CompactEncodedInst, FT_Fill, FT_Relaxable, FT_Org, FT_Dwarf, FT_DwarfFrame, - FT_LEB, - FT_Region, - FT_Reloc, - FT_Target + FT_LEB }; private: @@ -72,8 +69,7 @@ private: MCSectionData *Parent; /// Atom - The atom this fragment is in, as represented by it's defining - /// symbol. Atom's are only used by backends which set - /// \see MCAsmBackend::hasReliableSymbolDifference(). + /// symbol. MCSymbolData *Atom; /// @name Assembler Backend Data @@ -151,11 +147,11 @@ public: virtual SmallVectorImpl<char> &getContents() = 0; virtual const SmallVectorImpl<char> &getContents() const = 0; - virtual uint8_t getBundlePadding() const { + uint8_t getBundlePadding() const override { return BundlePadding; } - virtual void setBundlePadding(uint8_t N) { + void setBundlePadding(uint8_t N) override { BundlePadding = N; } @@ -166,6 +162,7 @@ public: return false; case MCFragment::FT_Relaxable: case MCFragment::FT_CompactEncodedInst: + case MCFragment::FT_Compressed: case MCFragment::FT_Data: return true; } @@ -176,7 +173,7 @@ public: /// data and also have fixups registered. /// class MCEncodedFragmentWithFixups : public MCEncodedFragment { - virtual void anchor(); + void anchor() override; public: MCEncodedFragmentWithFixups(MCFragment::FragmentType FType, @@ -200,14 +197,15 @@ public: static bool classof(const MCFragment *F) { MCFragment::FragmentType Kind = F->getKind(); - return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data; + return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data || + Kind == MCFragment::FT_Compressed; } }; /// Fragment for data and encoded instructions. /// class MCDataFragment : public MCEncodedFragmentWithFixups { - virtual void anchor(); + void anchor() override; /// \brief Does this fragment contain encoded instructions anywhere in it? bool HasInstructions; @@ -219,6 +217,11 @@ class MCDataFragment : public MCEncodedFragmentWithFixups { /// Fixups - The list of fixups in this fragment. SmallVector<MCFixup, 4> Fixups; +protected: + MCDataFragment(MCFragment::FragmentType FType, MCSectionData *SD = 0) + : MCEncodedFragmentWithFixups(FType, SD), HasInstructions(false), + AlignToBundleEnd(false) {} + public: MCDataFragment(MCSectionData *SD = 0) : MCEncodedFragmentWithFixups(FT_Data, SD), @@ -226,41 +229,54 @@ public: { } - virtual SmallVectorImpl<char> &getContents() { return Contents; } - virtual const SmallVectorImpl<char> &getContents() const { return Contents; } + SmallVectorImpl<char> &getContents() override { return Contents; } + const SmallVectorImpl<char> &getContents() const override { + return Contents; + } - SmallVectorImpl<MCFixup> &getFixups() { + SmallVectorImpl<MCFixup> &getFixups() override { return Fixups; } - const SmallVectorImpl<MCFixup> &getFixups() const { + const SmallVectorImpl<MCFixup> &getFixups() const override { return Fixups; } - virtual bool hasInstructions() const { return HasInstructions; } + bool hasInstructions() const override { return HasInstructions; } virtual void setHasInstructions(bool V) { HasInstructions = V; } - virtual bool alignToBundleEnd() const { return AlignToBundleEnd; } - virtual void setAlignToBundleEnd(bool V) { AlignToBundleEnd = V; } + bool alignToBundleEnd() const override { return AlignToBundleEnd; } + void setAlignToBundleEnd(bool V) override { AlignToBundleEnd = V; } - fixup_iterator fixup_begin() { return Fixups.begin(); } - const_fixup_iterator fixup_begin() const { return Fixups.begin(); } + fixup_iterator fixup_begin() override { return Fixups.begin(); } + const_fixup_iterator fixup_begin() const override { return Fixups.begin(); } - fixup_iterator fixup_end() {return Fixups.end();} - const_fixup_iterator fixup_end() const {return Fixups.end();} + fixup_iterator fixup_end() override {return Fixups.end();} + const_fixup_iterator fixup_end() const override {return Fixups.end();} static bool classof(const MCFragment *F) { - return F->getKind() == MCFragment::FT_Data; + return F->getKind() == MCFragment::FT_Data || + F->getKind() == MCFragment::FT_Compressed; } }; +class MCCompressedFragment: public MCDataFragment { + mutable SmallVector<char, 32> CompressedContents; +public: + MCCompressedFragment(MCSectionData *SD = nullptr) + : MCDataFragment(FT_Compressed, SD) {} + const SmallVectorImpl<char> &getCompressedContents() const; + using MCDataFragment::getContents; + SmallVectorImpl<char> &getContents() override; +}; + /// This is a compact (memory-size-wise) fragment for holding an encoded /// instruction (non-relaxable) that has no fixups registered. When applicable, /// it can be used instead of MCDataFragment and lead to lower memory /// consumption. /// class MCCompactEncodedInstFragment : public MCEncodedFragment { - virtual void anchor(); + void anchor() override; /// \brief Should this fragment be aligned to the end of a bundle? bool AlignToBundleEnd; @@ -272,15 +288,15 @@ public: { } - virtual bool hasInstructions() const { + bool hasInstructions() const override { return true; } - virtual SmallVectorImpl<char> &getContents() { return Contents; } - virtual const SmallVectorImpl<char> &getContents() const { return Contents; } + SmallVectorImpl<char> &getContents() override { return Contents; } + const SmallVectorImpl<char> &getContents() const override { return Contents; } - virtual bool alignToBundleEnd() const { return AlignToBundleEnd; } - virtual void setAlignToBundleEnd(bool V) { AlignToBundleEnd = V; } + bool alignToBundleEnd() const override { return AlignToBundleEnd; } + void setAlignToBundleEnd(bool V) override { AlignToBundleEnd = V; } static bool classof(const MCFragment *F) { return F->getKind() == MCFragment::FT_CompactEncodedInst; @@ -291,11 +307,16 @@ public: /// relaxed during the assembler layout and relaxation stage. /// class MCRelaxableFragment : public MCEncodedFragmentWithFixups { - virtual void anchor(); + void anchor() override; /// Inst - The instruction this is a fragment for. MCInst Inst; + /// STI - The MCSubtargetInfo in effect when the instruction was encoded. + /// Keep a copy instead of a reference to make sure that updates to STI + /// in the assembler are not seen here. + const MCSubtargetInfo STI; + /// Contents - Binary data for the currently encoded instruction. SmallVector<char, 8> Contents; @@ -303,31 +324,35 @@ class MCRelaxableFragment : public MCEncodedFragmentWithFixups { SmallVector<MCFixup, 1> Fixups; public: - MCRelaxableFragment(const MCInst &_Inst, MCSectionData *SD = 0) - : MCEncodedFragmentWithFixups(FT_Relaxable, SD), Inst(_Inst) { + MCRelaxableFragment(const MCInst &_Inst, + const MCSubtargetInfo &_STI, + MCSectionData *SD = 0) + : MCEncodedFragmentWithFixups(FT_Relaxable, SD), Inst(_Inst), STI(_STI) { } - virtual SmallVectorImpl<char> &getContents() { return Contents; } - virtual const SmallVectorImpl<char> &getContents() const { return Contents; } + SmallVectorImpl<char> &getContents() override { return Contents; } + const SmallVectorImpl<char> &getContents() const override { return Contents; } const MCInst &getInst() const { return Inst; } void setInst(const MCInst& Value) { Inst = Value; } - SmallVectorImpl<MCFixup> &getFixups() { + const MCSubtargetInfo &getSubtargetInfo() { return STI; } + + SmallVectorImpl<MCFixup> &getFixups() override { return Fixups; } - const SmallVectorImpl<MCFixup> &getFixups() const { + const SmallVectorImpl<MCFixup> &getFixups() const override { return Fixups; } - virtual bool hasInstructions() const { return true; } + bool hasInstructions() const override { return true; } - fixup_iterator fixup_begin() { return Fixups.begin(); } - const_fixup_iterator fixup_begin() const { return Fixups.begin(); } + fixup_iterator fixup_begin() override { return Fixups.begin(); } + const_fixup_iterator fixup_begin() const override { return Fixups.begin(); } - fixup_iterator fixup_end() {return Fixups.end();} - const_fixup_iterator fixup_end() const {return Fixups.end();} + fixup_iterator fixup_end() override {return Fixups.end();} + const_fixup_iterator fixup_end() const override {return Fixups.end();} static bool classof(const MCFragment *F) { return F->getKind() == MCFragment::FT_Relaxable; @@ -836,6 +861,15 @@ public: const_data_region_iterator; typedef std::vector<DataRegionData>::iterator data_region_iterator; + /// MachO specific deployment target version info. + // A Major version of 0 indicates that no version information was supplied + // and so the corresponding load command should not be emitted. + typedef struct { + MCVersionMinType Kind; + unsigned Major; + unsigned Minor; + unsigned Update; + } VersionMinInfoType; private: MCAssembler(const MCAssembler&) LLVM_DELETED_FUNCTION; void operator=(const MCAssembler&) LLVM_DELETED_FUNCTION; @@ -846,7 +880,7 @@ private: MCCodeEmitter &Emitter; - MCObjectWriter *Writer; + MCObjectWriter &Writer; raw_ostream &OS; @@ -898,6 +932,12 @@ private: // Access to the flags is necessary in cases where assembler directives affect // which flags to be set. unsigned ELFHeaderEFlags; + + /// Used to communicate Linker Optimization Hint information between + /// the Streamer and the .o writer + MCLOHContainer LOHContainer; + + VersionMinInfoType VersionMinInfo; private: /// Evaluate a fixup to a relocatable expression and the value which should be /// placed into the fixup. @@ -944,8 +984,8 @@ private: /// finishLayout - Finalize a layout, including fragment lowering. void finishLayout(MCAsmLayout &Layout); - uint64_t handleFixup(const MCAsmLayout &Layout, - MCFragment &F, const MCFixup &Fixup); + std::pair<uint64_t, bool> handleFixup(const MCAsmLayout &Layout, + MCFragment &F, const MCFixup &Fixup); public: /// Compute the effective fragment size assuming it is laid out at the given @@ -979,6 +1019,16 @@ public: unsigned getELFHeaderEFlags() const {return ELFHeaderEFlags;} void setELFHeaderEFlags(unsigned Flags) { ELFHeaderEFlags = Flags;} + /// MachO deployment target version information. + const VersionMinInfoType &getVersionMinInfo() const { return VersionMinInfo; } + void setVersionMinInfo(MCVersionMinType Kind, unsigned Major, unsigned Minor, + unsigned Update) { + VersionMinInfo.Kind = Kind; + VersionMinInfo.Major = Major; + VersionMinInfo.Minor = Minor; + VersionMinInfo.Update = Update; + } + public: /// Construct a new assembler instance. /// @@ -1003,9 +1053,7 @@ public: MCCodeEmitter &getEmitter() const { return Emitter; } - MCObjectWriter &getWriter() const { return *Writer; } - - void setWriter(MCObjectWriter &ObjectWriter); + MCObjectWriter &getWriter() const { return Writer; } /// Finish - Do final processing and write the object to the output stream. /// \p Writer is used for custom object writer (as the MCJIT does), @@ -1132,6 +1180,19 @@ public: size_t data_region_size() const { return DataRegions.size(); } /// @} + /// @name Data Region List Access + /// @{ + + // FIXME: This is a total hack, this should not be here. Once things are + // factored so that the streamer has direct access to the .o writer, it can + // disappear. + MCLOHContainer & getLOHContainer() { + return LOHContainer; + } + const MCLOHContainer & getLOHContainer() const { + return const_cast<MCAssembler *>(this)->getLOHContainer(); + } + /// @} /// @name Backend Data Access /// @{ @@ -1152,6 +1213,10 @@ public: return *Entry; } + bool hasSymbolData(const MCSymbol &Symbol) const { + return SymbolMap.lookup(&Symbol) != 0; + } + MCSymbolData &getSymbolData(const MCSymbol &Symbol) const { MCSymbolData *Entry = SymbolMap.lookup(&Symbol); assert(Entry && "Missing symbol data!"); |